From 3dc430e4e30b08ca79906e5f19bc3a3c324589a2 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Sat, 7 Nov 2026 18:12:53 -0500 Subject: [PATCH] feat(dripzone): unify DripZone tables into almeira database and media_bucket on Appwrite Cloud --- dripzone-app/src/lib/appwrite.ts | 48 ++++++++++++++++++++----- dripzone-app/src/lib/server-appwrite.ts | 46 +++++++++++++++++++++--- 2 files changed, 81 insertions(+), 13 deletions(-) diff --git a/dripzone-app/src/lib/appwrite.ts b/dripzone-app/src/lib/appwrite.ts index 5b20c90..4b927d6 100644 --- a/dripzone-app/src/lib/appwrite.ts +++ b/dripzone-app/src/lib/appwrite.ts @@ -1,7 +1,37 @@ import { Client, Databases, Storage, Account } from 'appwrite'; -const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1'; -const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c'; +const origCall = (Client.prototype as any).call; +if (origCall && !(Client.prototype as any).__tablesDbPatched) { + (Client.prototype as any).__tablesDbPatched = true; + (Client.prototype as any).call = async function (method: string, url: URL, headers: Record = {}, params: Record = {}, responseType = 'json') { + let p = url.pathname; + if (p.includes('/databases/')) { + p = p + .replace('/databases/sneakers_multistore_db/', '/tablesdb/almeira/') + .replace('/databases/', '/tablesdb/') + .replace('/collections/cities', '/tables/dz_cities') + .replace('/collections/payment_methods', '/tables/dz_payment_methods') + .replace('/collections/', '/tables/') + .replace('/documents', '/rows') + .replace('/attributes', '/columns'); + url = new URL(url.toString()); + url.pathname = p; + } else if (p.includes('/buckets/sneakers_media_bucket')) { + p = p.replace('/buckets/sneakers_media_bucket', '/buckets/media_bucket'); + url = new URL(url.toString()); + url.pathname = p; + } + const res = await origCall.call(this, method, url, headers, params, responseType); + if (res && typeof res === 'object') { + if (Array.isArray(res.rows) && !res.documents) res.documents = res.rows; + if (Array.isArray(res.tables) && !res.collections) res.collections = res.tables; + } + return res; + }; +} + +const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://nyc.cloud.appwrite.io/v1'; +const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '6aef63d9002c07371b40'; export const client = new Client(); client.setEndpoint(endpoint).setProject(projectId); @@ -10,17 +40,17 @@ export const databases = new Databases(client); export const storage = new Storage(client); export const account = new Account(client); -// Base de datos y Bucket 100% aislados e independientes -export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID || 'sneakers_multistore_db'; -export const BUCKET_ID = process.env.NEXT_PUBLIC_APPWRITE_MEDIA_BUCKET_ID || 'sneakers_media_bucket'; +// Unificado en la base de datos 'almeira' y bucket 'media_bucket' de Appwrite Cloud (Plan Gratuito) +export const DATABASE_ID = 'almeira'; +export const BUCKET_ID = 'media_bucket'; -// Colecciones independientes +// Colecciones de DripZone dentro de la base de datos 'almeira' export const COLLECTIONS = { PRODUCTS: 'products', - CITIES: 'cities', - PAYMENT_METHODS: 'payment_methods', + CITIES: 'dz_cities', + PAYMENT_METHODS: 'dz_payment_methods', ORDERS: 'orders', - SETTINGS: 'settings', + SETTINGS: 'store_settings', SUPPLIER_POSTS: 'supplier_posts', CUSTOM_REQUESTS: 'custom_requests', }; diff --git a/dripzone-app/src/lib/server-appwrite.ts b/dripzone-app/src/lib/server-appwrite.ts index eb8c83a..975ae11 100644 --- a/dripzone-app/src/lib/server-appwrite.ts +++ b/dripzone-app/src/lib/server-appwrite.ts @@ -16,10 +16,48 @@ import { INITIAL_CITIES, INITIAL_PAYMENT_METHODS, INITIAL_SUPPLIERS, isGroupIgno import { DEFAULT_MESSAGE_TEMPLATES } from './templates-service'; import { sanitizePublicationTitle, sanitizePublicationText } from './sanitizer'; -const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1'; -const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c'; -const apiKey = process.env.APPWRITE_API_KEY || 'standard_cce3cdb866ea6433888d40cedd24dc45987372308fdc3dd0697de08648c0e5c7e04b02c3bcee271403fd656b00a5820f04c08b51631284a6e8a3582d8aed2aa33234f3c29cc777e9b162eb54810b789251b0d006a9a3b081ebc2da53b9baa94614b124b3508ad849fd9a4187cc6094f506d4b57f409b69d9562a74df594f3ec3'; -const databaseId = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID || 'sneakers_multistore_db'; +const origCall = (Client.prototype as any).call; +if (origCall && !(Client.prototype as any).__tablesDbPatched) { + (Client.prototype as any).__tablesDbPatched = true; + (Client.prototype as any).call = async function (method: string, url: URL, headers: Record = {}, params: Record = {}, responseType = 'json') { + let p = url.pathname; + if (p.includes('/databases/')) { + p = p + .replace('/databases/sneakers_multistore_db/', '/tablesdb/almeira/') + .replace('/databases/', '/tablesdb/') + .replace('/collections/cities', '/tables/dz_cities') + .replace('/collections/payment_methods', '/tables/dz_payment_methods') + .replace('/collections/', '/tables/') + .replace('/documents', '/rows') + .replace('/attributes', '/columns'); + url = new URL(url.toString()); + url.pathname = p; + if (params && typeof params === 'object' && !Array.isArray(params) && ('documentId' in params || 'data' in params)) { + const { documentId, data, permissions } = params; + params = { + ...(documentId !== undefined ? { rowId: documentId } : {}), + ...(data !== undefined ? { data } : {}), + ...(permissions !== undefined ? { permissions } : {}), + }; + } + } else if (p.includes('/buckets/sneakers_media_bucket')) { + p = p.replace('/buckets/sneakers_media_bucket', '/buckets/media_bucket'); + url = new URL(url.toString()); + url.pathname = p; + } + const res = await origCall.call(this, method, url, headers, params, responseType); + if (res && typeof res === 'object') { + if (Array.isArray(res.rows) && !res.documents) res.documents = res.rows; + if (Array.isArray(res.tables) && !res.collections) res.collections = res.tables; + } + return res; + }; +} + +const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://nyc.cloud.appwrite.io/v1'; +const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '6aef63d9002c07371b40'; +const apiKey = process.env.APPWRITE_API_KEY || 'standard_79704037e869df69b7efcecdf51370360781c1b335d8a16148639c71382d8c9e94c4d49d27c2da0b8dde8e430084b895cc9756d8bb2cf927a4e96c59e3258d79d1119dac4167cee6b1e737a3444982e16187842cfffde1cc8c07c2f3c48d032ec1c164a802deacf6393bedd815b2868cf7faf374815aebe72777c4616d26db40'; +const databaseId = 'almeira'; const client = new Client() .setEndpoint(endpoint)