@pakento/cms-sdk 4.3.1 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/index.d.mts +226 -239
- package/dist/index.d.ts +226 -239
- package/dist/index.js +358 -505
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -501
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -30,25 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
ApiClient: () => ApiClient,
|
|
34
|
+
brandsApi: () => brandsApi,
|
|
35
|
+
categoriesApi: () => categoriesApi,
|
|
36
|
+
contactApi: () => contactApi,
|
|
37
|
+
customApi: () => customApi,
|
|
38
|
+
entityApi: () => entityApi,
|
|
39
|
+
itemsApi: () => itemsApi,
|
|
40
|
+
ordersApi: () => ordersApi
|
|
37
41
|
});
|
|
38
42
|
module.exports = __toCommonJS(index_exports);
|
|
39
43
|
|
|
40
|
-
// src/
|
|
44
|
+
// src/api/core/apiClient.ts
|
|
41
45
|
var import_axios = __toESM(require("axios"));
|
|
46
|
+
var import_zod = require("zod");
|
|
42
47
|
|
|
43
|
-
// src/
|
|
48
|
+
// src/api/core/cache.ts
|
|
44
49
|
var import_redis = require("@upstash/redis");
|
|
45
50
|
var import_crypto = require("crypto");
|
|
46
51
|
var CacheService = class {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
constructor(defaultTTL, apiKey) {
|
|
51
|
-
this.defaultTTL = defaultTTL;
|
|
52
|
+
// 24 hours
|
|
53
|
+
constructor(apiKey) {
|
|
54
|
+
this.defaultTTL = 86400;
|
|
52
55
|
this.apiKeyHash = (0, import_crypto.createHash)("sha256").update(apiKey).digest("hex").substring(0, 8);
|
|
53
56
|
if (process.env.UPSTASH_REDIS_REST_URL && process.env.UPSTASH_REDIS_REST_TOKEN) {
|
|
54
57
|
this.redis = new import_redis.Redis({
|
|
@@ -58,269 +61,51 @@ var CacheService = class {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
generateParamsHash(params) {
|
|
61
|
-
const
|
|
62
|
-
if (value === void 0) return void 0;
|
|
63
|
-
if (value === null) return null;
|
|
64
|
-
if (Array.isArray(value)) {
|
|
65
|
-
return value.map((v) => canonicalize(v));
|
|
66
|
-
}
|
|
67
|
-
if (typeof value === "object") {
|
|
68
|
-
const obj = value;
|
|
69
|
-
const result = {};
|
|
70
|
-
Object.keys(obj).sort().forEach((key) => {
|
|
71
|
-
const canon = canonicalize(obj[key]);
|
|
72
|
-
if (canon !== void 0) {
|
|
73
|
-
result[key] = canon;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
return value;
|
|
79
|
-
};
|
|
80
|
-
const canonicalParams = canonicalize(params);
|
|
81
|
-
const paramsString = JSON.stringify(canonicalParams);
|
|
64
|
+
const paramsString = JSON.stringify(params, Object.keys(params).sort());
|
|
82
65
|
return (0, import_crypto.createHash)("sha256").update(paramsString).digest("hex").substring(0, 16);
|
|
83
66
|
}
|
|
84
67
|
buildCacheKey(functionName, params = {}) {
|
|
85
68
|
const paramsHash = this.generateParamsHash(params);
|
|
86
69
|
return `pakento:${this.apiKeyHash}:${functionName}:${paramsHash}`;
|
|
87
70
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (typeof data === "object" && data !== null) {
|
|
91
|
-
return data;
|
|
92
|
-
}
|
|
93
|
-
if (typeof data === "string") {
|
|
94
|
-
return JSON.parse(data);
|
|
95
|
-
}
|
|
96
|
-
return data;
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.warn("[PakentoSDK] Error en safeJsonParse:", error);
|
|
99
|
-
console.warn("[PakentoSDK] Datos que causaron error:", {
|
|
100
|
-
type: typeof data,
|
|
101
|
-
isArray: Array.isArray(data),
|
|
102
|
-
data
|
|
103
|
-
});
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
serializeForCache(value) {
|
|
108
|
-
try {
|
|
109
|
-
const cacheData = {
|
|
110
|
-
__pakento_cache_version: "2.0",
|
|
111
|
-
__pakento_timestamp: Date.now(),
|
|
112
|
-
data: value
|
|
113
|
-
};
|
|
114
|
-
return JSON.stringify(cacheData);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.warn("[PakentoSDK] Error en serializeForCache:", error);
|
|
117
|
-
return JSON.stringify(value);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
async getCachedOrFetch(key, fetcher, ttl, skipCache = false) {
|
|
121
|
-
if (!this.redis || skipCache) {
|
|
71
|
+
async cacheWrap(key, fetcher) {
|
|
72
|
+
if (!this.redis) {
|
|
122
73
|
return fetcher();
|
|
123
74
|
}
|
|
75
|
+
let cached = null;
|
|
124
76
|
try {
|
|
125
|
-
|
|
126
|
-
if (cached
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
} else {
|
|
134
|
-
console.log("[PakentoSDK] Cache encontrado y devuelto");
|
|
135
|
-
return parsed;
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
console.warn(`[PakentoSDK] \u26A0\uFE0F Error parseando cache para: ${key}`);
|
|
139
|
-
console.warn(`[PakentoSDK] Datos raw del cache:`, {
|
|
140
|
-
type: typeof cached,
|
|
141
|
-
value: cached
|
|
142
|
-
});
|
|
143
|
-
this.clearCorruptedCache(key).catch(
|
|
144
|
-
(err) => console.warn(
|
|
145
|
-
`[PakentoSDK] Error limpiando cache corrupto: ${err}`
|
|
146
|
-
)
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
} catch (parseError) {
|
|
150
|
-
console.warn(
|
|
151
|
-
`[PakentoSDK] \u26A0\uFE0F Excepci\xF3n parseando cache para: ${key}:`,
|
|
152
|
-
parseError
|
|
153
|
-
);
|
|
154
|
-
this.clearCorruptedCache(key).catch(
|
|
155
|
-
(err) => console.warn(`[PakentoSDK] Error limpiando cache corrupto: ${err}`)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
77
|
+
cached = await this.redis.get(key);
|
|
78
|
+
if (typeof cached === "object" && cached !== null) {
|
|
79
|
+
console.log("[Cache] \u2705 Reading from cache:", key);
|
|
80
|
+
return cached;
|
|
81
|
+
}
|
|
82
|
+
if (cached) {
|
|
83
|
+
console.log("[Cache] \u2705 Reading from cache:", key);
|
|
84
|
+
return JSON.parse(cached);
|
|
158
85
|
}
|
|
159
86
|
} catch (err) {
|
|
160
|
-
console.warn("[
|
|
87
|
+
console.warn("[Cache] \u274C Error reading from cache:", err);
|
|
88
|
+
console.log(`[Cache] \u274C Key: ${key}, type: ${typeof cached}`);
|
|
161
89
|
}
|
|
162
90
|
const result = await fetcher();
|
|
163
91
|
try {
|
|
164
|
-
|
|
165
|
-
await this.redis.set(key,
|
|
166
|
-
ex:
|
|
92
|
+
console.log("[Cache] \u2705 Writing to cache:", key);
|
|
93
|
+
await this.redis.set(key, JSON.stringify(result), {
|
|
94
|
+
ex: this.defaultTTL
|
|
167
95
|
});
|
|
168
|
-
console.log(
|
|
169
|
-
"[PakentoSDK] Cache no encontrado, se guarda y se devuelve uno nuevo"
|
|
170
|
-
);
|
|
171
96
|
} catch (err) {
|
|
172
|
-
console.warn("[
|
|
173
|
-
console.warn("[PakentoSDK] Detalles del error:", {
|
|
174
|
-
error: err,
|
|
175
|
-
key,
|
|
176
|
-
resultType: typeof result,
|
|
177
|
-
resultSize: JSON.stringify(result).length
|
|
178
|
-
});
|
|
97
|
+
console.warn("[Cache] \u274C Error writing to cache:", err);
|
|
179
98
|
}
|
|
180
99
|
return result;
|
|
181
100
|
}
|
|
182
|
-
async hasCache(functionName, params = {}) {
|
|
183
|
-
if (!this.redis) {
|
|
184
|
-
console.warn("[PakentoSDK] Redis no configurado");
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
const key = this.buildCacheKey(functionName, params);
|
|
189
|
-
const cached = await this.redis.get(key);
|
|
190
|
-
if (cached === null || cached === void 0) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
const parsed = this.safeJsonParse(cached);
|
|
194
|
-
return parsed !== null;
|
|
195
|
-
} catch (err) {
|
|
196
|
-
console.warn("[PakentoSDK] Error verificando cache", err);
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Limpia un cache específico si está corrupto
|
|
202
|
-
*/
|
|
203
|
-
async clearCorruptedCache(key) {
|
|
204
|
-
if (!this.redis) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
try {
|
|
208
|
-
await this.redis.del(key);
|
|
209
|
-
return true;
|
|
210
|
-
} catch (err) {
|
|
211
|
-
console.warn("[PakentoSDK] Error limpiando cache corrupto", err);
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
getCacheKey(functionName, params = {}) {
|
|
216
|
-
return this.buildCacheKey(functionName, params);
|
|
217
|
-
}
|
|
218
|
-
async clearCache(functionName, params = {}) {
|
|
219
|
-
if (!this.redis) {
|
|
220
|
-
console.warn("[PakentoSDK] Redis no configurado");
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
const key = this.buildCacheKey(functionName, params);
|
|
225
|
-
await this.redis.del(key);
|
|
226
|
-
return true;
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.warn("[PakentoSDK] Error limpiando cache", err);
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async clearAllCache() {
|
|
233
|
-
if (!this.redis) {
|
|
234
|
-
console.warn("[PakentoSDK] Redis no configurado");
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
const pattern = `pakento:${this.apiKeyHash}:*`;
|
|
239
|
-
const keys = await this.redis.keys(pattern);
|
|
240
|
-
if (keys.length > 0) {
|
|
241
|
-
await this.redis.del(...keys);
|
|
242
|
-
}
|
|
243
|
-
return true;
|
|
244
|
-
} catch (err) {
|
|
245
|
-
console.warn("[PakentoSDK] Error limpiando todo el cache", err);
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async getCacheInfo(functionName, params = {}) {
|
|
250
|
-
if (!this.redis) {
|
|
251
|
-
console.warn("[PakentoSDK] Redis no configurado");
|
|
252
|
-
return {
|
|
253
|
-
exists: false,
|
|
254
|
-
key: this.buildCacheKey(functionName, params)
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
const key = this.buildCacheKey(functionName, params);
|
|
259
|
-
const exists = await this.redis.exists(key);
|
|
260
|
-
const ttl = exists ? await this.redis.ttl(key) : void 0;
|
|
261
|
-
return {
|
|
262
|
-
exists: exists === 1,
|
|
263
|
-
key,
|
|
264
|
-
ttl: ttl === -1 ? void 0 : ttl
|
|
265
|
-
};
|
|
266
|
-
} catch (err) {
|
|
267
|
-
console.warn("[PakentoSDK] Error obteniendo info del cache", err);
|
|
268
|
-
return {
|
|
269
|
-
exists: false,
|
|
270
|
-
key: this.buildCacheKey(functionName, params)
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
101
|
};
|
|
275
102
|
|
|
276
|
-
// src/
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
// src/utils/itemParser.ts
|
|
280
|
-
function parseRawItemToItem(rawItem) {
|
|
281
|
-
const firstPrice = rawItem.item_prices.docs[0];
|
|
282
|
-
const images = rawItem.images.map((img) => ({
|
|
283
|
-
url: img.url,
|
|
284
|
-
thumbnail_url: img.thumbnailURL
|
|
285
|
-
}));
|
|
286
|
-
const coverImageUrl = rawItem.coverImage?.url || rawItem.images[0]?.url || "";
|
|
287
|
-
const coverImageThumbnailUrl = rawItem.coverImage?.thumbnailURL || rawItem.images[0]?.thumbnailURL || "";
|
|
288
|
-
return {
|
|
289
|
-
id: rawItem.id,
|
|
290
|
-
name: rawItem.name,
|
|
291
|
-
featured: rawItem.featured,
|
|
292
|
-
url_safe_name: rawItem.url_safe_name,
|
|
293
|
-
currency_prefix: "$",
|
|
294
|
-
// Default currency prefix, could be made configurable
|
|
295
|
-
description: rawItem.description,
|
|
296
|
-
old_price: firstPrice?.old_price || 0,
|
|
297
|
-
item_category_name: rawItem.item_category?.name || "",
|
|
298
|
-
item_category_id: parseInt(rawItem.item_category?.id || "0"),
|
|
299
|
-
price_text: firstPrice?.price_text || "",
|
|
300
|
-
price_notes: firstPrice?.price_notes || "",
|
|
301
|
-
// Not available in raw response
|
|
302
|
-
price: firstPrice?.amount || 0,
|
|
303
|
-
brand_id: parseInt(rawItem.brand?.id || "0"),
|
|
304
|
-
brand_name: rawItem.brand?.name || "",
|
|
305
|
-
cover_image_url: coverImageUrl,
|
|
306
|
-
cover_image_thumbnail_url: coverImageThumbnailUrl,
|
|
307
|
-
images
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
function parseRawItemsToItems(rawItems) {
|
|
311
|
-
return rawItems.map(parseRawItemToItem);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// src/services/api.ts
|
|
315
|
-
var PakentoCMSAPI = class {
|
|
316
|
-
constructor(config) {
|
|
317
|
-
this.defaultTTL = 86400;
|
|
103
|
+
// src/api/core/apiClient.ts
|
|
104
|
+
var ApiClient = class {
|
|
105
|
+
constructor() {
|
|
318
106
|
this.baseURL = process.env.PAKENTO_CMS_BASE_URL || "";
|
|
319
107
|
this.apiKey = process.env.PAKENTO_API_KEY || "";
|
|
320
|
-
|
|
321
|
-
this.defaultTTL = config.cacheTTL;
|
|
322
|
-
}
|
|
323
|
-
this.cache = new CacheService(this.defaultTTL, this.apiKey);
|
|
108
|
+
this.cache = new CacheService(this.apiKey);
|
|
324
109
|
this.client = import_axios.default.create({
|
|
325
110
|
baseURL: this.baseURL,
|
|
326
111
|
headers: {
|
|
@@ -329,17 +114,14 @@ var PakentoCMSAPI = class {
|
|
|
329
114
|
}
|
|
330
115
|
});
|
|
331
116
|
this.client.interceptors.request.use(
|
|
332
|
-
(
|
|
333
|
-
const fullUrl = `${
|
|
334
|
-
console.log(`\u{1F310} API Call: ${
|
|
335
|
-
return
|
|
117
|
+
(config) => {
|
|
118
|
+
const fullUrl = `${config.baseURL}${config.url}`;
|
|
119
|
+
console.log(`\u{1F310} API Call: ${config.method?.toUpperCase()} ${fullUrl}`);
|
|
120
|
+
return config;
|
|
336
121
|
},
|
|
337
|
-
(error) =>
|
|
338
|
-
return Promise.reject(error);
|
|
339
|
-
}
|
|
122
|
+
(error) => Promise.reject(error)
|
|
340
123
|
);
|
|
341
124
|
}
|
|
342
|
-
// Centralized error handler
|
|
343
125
|
handleApiError(error, context) {
|
|
344
126
|
if (error instanceof import_axios.AxiosError) {
|
|
345
127
|
const status = error.response?.status;
|
|
@@ -355,7 +137,6 @@ var PakentoCMSAPI = class {
|
|
|
355
137
|
}
|
|
356
138
|
return "Error desconocido";
|
|
357
139
|
}
|
|
358
|
-
// Generic GraphQL fetcher
|
|
359
140
|
async fetchGraphQL(query, variables, extractData) {
|
|
360
141
|
try {
|
|
361
142
|
const response = await this.client.post("/api/graphql", {
|
|
@@ -373,32 +154,71 @@ var PakentoCMSAPI = class {
|
|
|
373
154
|
return { data: null, error: true, errorMessage };
|
|
374
155
|
}
|
|
375
156
|
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/api/items/parsers.ts
|
|
160
|
+
function parseRawItemToItem(rawItem) {
|
|
161
|
+
const firstPrice = rawItem.item_prices.docs[0];
|
|
162
|
+
const images = rawItem.images.map((img) => ({
|
|
163
|
+
url: img.url,
|
|
164
|
+
thumbnail_url: img.thumbnailURL
|
|
165
|
+
}));
|
|
166
|
+
const coverImageUrl = rawItem.coverImage?.url || rawItem.images[0]?.url || "";
|
|
167
|
+
const coverImageThumbnailUrl = rawItem.coverImage?.thumbnailURL || rawItem.images[0]?.thumbnailURL || "";
|
|
168
|
+
return {
|
|
169
|
+
id: rawItem.id,
|
|
170
|
+
name: rawItem.name,
|
|
171
|
+
featured: rawItem.featured,
|
|
172
|
+
url_safe_name: rawItem.url_safe_name,
|
|
173
|
+
currency_prefix: "$",
|
|
174
|
+
// Default currency prefix, could be made configurable
|
|
175
|
+
description: rawItem.description,
|
|
176
|
+
old_price: firstPrice?.old_price || 0,
|
|
177
|
+
item_category_name: rawItem.item_category?.name || "",
|
|
178
|
+
item_category_id: parseInt(rawItem.item_category?.id || "0"),
|
|
179
|
+
price_text: firstPrice?.price_text || "",
|
|
180
|
+
price_notes: firstPrice?.price_notes || "",
|
|
181
|
+
price: firstPrice?.amount || 0,
|
|
182
|
+
brand_id: parseInt(rawItem.brand?.id || "0"),
|
|
183
|
+
brand_name: rawItem.brand?.name || "",
|
|
184
|
+
cover_image_url: coverImageUrl,
|
|
185
|
+
cover_image_thumbnail_url: coverImageThumbnailUrl,
|
|
186
|
+
images
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function parseRawItemsToItems(rawItems) {
|
|
190
|
+
return rawItems.map(parseRawItemToItem);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/api/items/validators.ts
|
|
194
|
+
var import_zod2 = require("zod");
|
|
195
|
+
var itemsParamsSchema = import_zod2.z.object({
|
|
196
|
+
where: import_zod2.z.object({
|
|
197
|
+
item_category_id: import_zod2.z.object({ equals: import_zod2.z.string().optional() }).optional(),
|
|
198
|
+
item_super_category_id: import_zod2.z.object({ equals: import_zod2.z.string().optional() }).optional(),
|
|
199
|
+
brand_id: import_zod2.z.object({ equals: import_zod2.z.string().optional() }).optional(),
|
|
200
|
+
id: import_zod2.z.object({ equals: import_zod2.z.string().optional() }).optional()
|
|
201
|
+
}).optional(),
|
|
202
|
+
onlyOffers: import_zod2.z.boolean().optional(),
|
|
203
|
+
limit: import_zod2.z.coerce.number().optional(),
|
|
204
|
+
page: import_zod2.z.coerce.number().optional(),
|
|
205
|
+
search: import_zod2.z.string().optional(),
|
|
206
|
+
sort: import_zod2.z.string().optional(),
|
|
207
|
+
minPrice: import_zod2.z.coerce.number().optional(),
|
|
208
|
+
maxPrice: import_zod2.z.coerce.number().optional()
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// src/api/items/api.ts
|
|
212
|
+
var ItemsApi = class extends ApiClient {
|
|
376
213
|
async getItems(params = {}) {
|
|
377
|
-
const
|
|
378
|
-
where: import_zod.z.object({
|
|
379
|
-
item_category_id: import_zod.z.object({ equals: import_zod.z.string().optional() }).optional(),
|
|
380
|
-
item_super_category_id: import_zod.z.object({ equals: import_zod.z.string().optional() }).optional(),
|
|
381
|
-
brand_id: import_zod.z.object({ equals: import_zod.z.string().optional() }).optional(),
|
|
382
|
-
id: import_zod.z.object({ equals: import_zod.z.string().optional() }).optional()
|
|
383
|
-
}).optional(),
|
|
384
|
-
onlyOffers: import_zod.z.boolean().optional(),
|
|
385
|
-
limit: import_zod.z.coerce.number().optional(),
|
|
386
|
-
page: import_zod.z.coerce.number().optional(),
|
|
387
|
-
search: import_zod.z.string().optional(),
|
|
388
|
-
sort: import_zod.z.string().optional(),
|
|
389
|
-
minPrice: import_zod.z.coerce.number().optional(),
|
|
390
|
-
maxPrice: import_zod.z.coerce.number().optional(),
|
|
391
|
-
skipCache: import_zod.z.boolean().optional(),
|
|
392
|
-
cacheTTL: import_zod.z.number().optional()
|
|
393
|
-
});
|
|
394
|
-
const validatedParams = itemsSchema.safeParse(params);
|
|
214
|
+
const validatedParams = itemsParamsSchema.safeParse(params);
|
|
395
215
|
if (!validatedParams.success) {
|
|
396
216
|
const errorMessage = this.handleApiError(
|
|
397
217
|
validatedParams.error,
|
|
398
218
|
"getItems validation"
|
|
399
219
|
);
|
|
400
220
|
return {
|
|
401
|
-
data:
|
|
221
|
+
data: [],
|
|
402
222
|
totalDocs: 0,
|
|
403
223
|
totalPages: 0,
|
|
404
224
|
prevPage: null,
|
|
@@ -407,28 +227,19 @@ var PakentoCMSAPI = class {
|
|
|
407
227
|
errorMessage
|
|
408
228
|
};
|
|
409
229
|
}
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
230
|
+
const cacheKey = this.cache.buildCacheKey(
|
|
231
|
+
"GetEcommerceItems",
|
|
232
|
+
validatedParams.data
|
|
233
|
+
);
|
|
234
|
+
return this.cache.cacheWrap(
|
|
413
235
|
cacheKey,
|
|
414
|
-
() => this.fetchItemsFromAPI(
|
|
415
|
-
cacheTTL,
|
|
416
|
-
skipCache
|
|
236
|
+
() => this.fetchItemsFromAPI(validatedParams.data)
|
|
417
237
|
);
|
|
418
|
-
return {
|
|
419
|
-
data: finalData.data,
|
|
420
|
-
totalDocs: finalData.totalDocs,
|
|
421
|
-
totalPages: finalData.totalPages,
|
|
422
|
-
prevPage: finalData.prevPage,
|
|
423
|
-
nextPage: finalData.nextPage,
|
|
424
|
-
error: false,
|
|
425
|
-
errorMessage: null
|
|
426
|
-
};
|
|
427
238
|
}
|
|
428
|
-
async fetchItemsFromAPI(params
|
|
239
|
+
async fetchItemsFromAPI(params) {
|
|
429
240
|
if (!this.baseURL || !this.apiKey) {
|
|
430
241
|
return {
|
|
431
|
-
data:
|
|
242
|
+
data: [],
|
|
432
243
|
totalDocs: 0,
|
|
433
244
|
totalPages: 0,
|
|
434
245
|
prevPage: null,
|
|
@@ -524,7 +335,7 @@ var PakentoCMSAPI = class {
|
|
|
524
335
|
);
|
|
525
336
|
if (error) {
|
|
526
337
|
return {
|
|
527
|
-
data:
|
|
338
|
+
data: [],
|
|
528
339
|
totalDocs: 0,
|
|
529
340
|
totalPages: 0,
|
|
530
341
|
prevPage: null,
|
|
@@ -543,25 +354,57 @@ var PakentoCMSAPI = class {
|
|
|
543
354
|
errorMessage: null
|
|
544
355
|
};
|
|
545
356
|
}
|
|
357
|
+
};
|
|
358
|
+
var itemsApi = new ItemsApi();
|
|
359
|
+
|
|
360
|
+
// src/api/categories/validators.ts
|
|
361
|
+
var import_zod3 = require("zod");
|
|
362
|
+
var categoriesParamsSchema = import_zod3.z.object({
|
|
363
|
+
where: import_zod3.z.object({
|
|
364
|
+
item_super_category_id: import_zod3.z.object({ equals: import_zod3.z.string().optional() }).optional(),
|
|
365
|
+
brand_id: import_zod3.z.object({ equals: import_zod3.z.string().optional() }).optional()
|
|
366
|
+
}).optional(),
|
|
367
|
+
limit: import_zod3.z.coerce.number().optional(),
|
|
368
|
+
page: import_zod3.z.coerce.number().optional(),
|
|
369
|
+
sort: import_zod3.z.string().optional()
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// src/api/categories/parsers.ts
|
|
373
|
+
function parseRawCategoryToCategory(rawCategory) {
|
|
374
|
+
return {
|
|
375
|
+
id: rawCategory.id,
|
|
376
|
+
name: rawCategory.name,
|
|
377
|
+
image_url: rawCategory.image_url
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function parseRawCategoriesToCategories(rawCategories) {
|
|
381
|
+
return rawCategories.map(parseRawCategoryToCategory);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/api/categories/api.ts
|
|
385
|
+
var CategoriesApi = class extends ApiClient {
|
|
546
386
|
async getCategories(params = {}) {
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
387
|
+
const validatedParams = categoriesParamsSchema.safeParse(params);
|
|
388
|
+
if (!validatedParams.success) {
|
|
389
|
+
const errorMessage = this.handleApiError(
|
|
390
|
+
validatedParams.error,
|
|
391
|
+
"getCategories validation"
|
|
392
|
+
);
|
|
393
|
+
return { data: [], error: true, errorMessage };
|
|
394
|
+
}
|
|
395
|
+
const cacheKey = this.cache.buildCacheKey(
|
|
396
|
+
"GetEcommerceCategories",
|
|
397
|
+
validatedParams.data
|
|
398
|
+
);
|
|
399
|
+
return this.cache.cacheWrap(
|
|
554
400
|
cacheKey,
|
|
555
|
-
() => this.fetchCategoriesFromAPI(
|
|
556
|
-
cacheTTL,
|
|
557
|
-
skipCache
|
|
401
|
+
() => this.fetchCategoriesFromAPI(validatedParams.data)
|
|
558
402
|
);
|
|
559
403
|
}
|
|
560
|
-
async fetchCategoriesFromAPI(params
|
|
404
|
+
async fetchCategoriesFromAPI(params) {
|
|
561
405
|
if (!this.baseURL || !this.apiKey) {
|
|
562
406
|
return {
|
|
563
|
-
data:
|
|
564
|
-
categories: [],
|
|
407
|
+
data: [],
|
|
565
408
|
error: true,
|
|
566
409
|
errorMessage: "SDK no configurado: PAKENTO_CMS_BASE_URL o PAKENTO_API_KEY faltantes."
|
|
567
410
|
};
|
|
@@ -593,45 +436,77 @@ var PakentoCMSAPI = class {
|
|
|
593
436
|
(responseData) => responseData.GetEcommerceCategories
|
|
594
437
|
);
|
|
595
438
|
if (error) {
|
|
596
|
-
return {
|
|
597
|
-
data: null,
|
|
598
|
-
categories: [],
|
|
599
|
-
error: true,
|
|
600
|
-
errorMessage
|
|
601
|
-
};
|
|
439
|
+
return { data: [], error: true, errorMessage };
|
|
602
440
|
}
|
|
603
441
|
return {
|
|
604
|
-
data: data.docs,
|
|
605
|
-
categories: data.docs,
|
|
442
|
+
data: parseRawCategoriesToCategories(data.docs),
|
|
606
443
|
error: false,
|
|
607
444
|
errorMessage: null
|
|
608
445
|
};
|
|
609
446
|
}
|
|
447
|
+
};
|
|
448
|
+
var categoriesApi = new CategoriesApi();
|
|
449
|
+
|
|
450
|
+
// src/api/brands/validators.ts
|
|
451
|
+
var import_zod4 = require("zod");
|
|
452
|
+
var brandsParamsSchema = import_zod4.z.object({
|
|
453
|
+
limit: import_zod4.z.coerce.number().optional(),
|
|
454
|
+
page: import_zod4.z.coerce.number().optional(),
|
|
455
|
+
sort: import_zod4.z.string().optional()
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// src/api/brands/parsers.ts
|
|
459
|
+
function parseRawBrandToBrand(rawBrand) {
|
|
460
|
+
return {
|
|
461
|
+
id: rawBrand.id,
|
|
462
|
+
name: rawBrand.name,
|
|
463
|
+
description: rawBrand.description,
|
|
464
|
+
items_count: rawBrand.items_count,
|
|
465
|
+
image_url: rawBrand.image_url,
|
|
466
|
+
image_thumbnail_url: rawBrand.image_thumbnail_url,
|
|
467
|
+
image_alt: rawBrand.image_alt
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function parseRawBrandsToBrands(rawBrands) {
|
|
471
|
+
return rawBrands.map(parseRawBrandToBrand);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/api/brands/api.ts
|
|
475
|
+
var BrandsApi = class extends ApiClient {
|
|
610
476
|
async getBrands(params = {}) {
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
477
|
+
const validatedParams = brandsParamsSchema.safeParse(params);
|
|
478
|
+
if (!validatedParams.success) {
|
|
479
|
+
const errorMessage = this.handleApiError(
|
|
480
|
+
validatedParams.error,
|
|
481
|
+
"getBrands validation"
|
|
482
|
+
);
|
|
483
|
+
return {
|
|
484
|
+
data: [],
|
|
485
|
+
totalDocs: 0,
|
|
486
|
+
totalPages: 0,
|
|
487
|
+
prevPage: null,
|
|
488
|
+
nextPage: null,
|
|
489
|
+
error: true,
|
|
490
|
+
errorMessage
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
const cacheKey = this.cache.buildCacheKey(
|
|
494
|
+
"GetEcommerceBrands",
|
|
495
|
+
validatedParams.data
|
|
496
|
+
);
|
|
497
|
+
return this.cache.cacheWrap(
|
|
614
498
|
cacheKey,
|
|
615
|
-
() => this.fetchBrandsFromAPI(
|
|
616
|
-
cacheTTL,
|
|
617
|
-
skipCache
|
|
499
|
+
() => this.fetchBrandsFromAPI(validatedParams.data)
|
|
618
500
|
);
|
|
619
501
|
}
|
|
620
|
-
async fetchBrandsFromAPI(params
|
|
502
|
+
async fetchBrandsFromAPI(params) {
|
|
621
503
|
if (!this.baseURL || !this.apiKey) {
|
|
622
504
|
return {
|
|
623
|
-
data:
|
|
624
|
-
brands: [],
|
|
625
|
-
hasNextPage: false,
|
|
626
|
-
hasPrevPage: false,
|
|
627
|
-
limit: 0,
|
|
628
|
-
nextPage: 0,
|
|
629
|
-
offset: 0,
|
|
630
|
-
page: 0,
|
|
631
|
-
pagingCounter: 0,
|
|
632
|
-
prevPage: 0,
|
|
505
|
+
data: [],
|
|
633
506
|
totalDocs: 0,
|
|
634
507
|
totalPages: 0,
|
|
508
|
+
prevPage: null,
|
|
509
|
+
nextPage: null,
|
|
635
510
|
error: true,
|
|
636
511
|
errorMessage: "SDK no configurado: PAKENTO_CMS_BASE_URL o PAKENTO_API_KEY faltantes."
|
|
637
512
|
};
|
|
@@ -647,6 +522,10 @@ var PakentoCMSAPI = class {
|
|
|
647
522
|
page: $page
|
|
648
523
|
sort: $sort
|
|
649
524
|
) {
|
|
525
|
+
totalDocs
|
|
526
|
+
totalPages
|
|
527
|
+
prevPage
|
|
528
|
+
nextPage
|
|
650
529
|
docs {
|
|
651
530
|
id
|
|
652
531
|
name
|
|
@@ -656,16 +535,6 @@ var PakentoCMSAPI = class {
|
|
|
656
535
|
image_thumbnail_url
|
|
657
536
|
image_alt
|
|
658
537
|
}
|
|
659
|
-
hasNextPage
|
|
660
|
-
hasPrevPage
|
|
661
|
-
limit
|
|
662
|
-
nextPage
|
|
663
|
-
offset
|
|
664
|
-
page
|
|
665
|
-
pagingCounter
|
|
666
|
-
prevPage
|
|
667
|
-
totalDocs
|
|
668
|
-
totalPages
|
|
669
538
|
}
|
|
670
539
|
}
|
|
671
540
|
`;
|
|
@@ -676,54 +545,79 @@ var PakentoCMSAPI = class {
|
|
|
676
545
|
);
|
|
677
546
|
if (error) {
|
|
678
547
|
return {
|
|
679
|
-
data:
|
|
680
|
-
brands: [],
|
|
681
|
-
hasNextPage: false,
|
|
682
|
-
hasPrevPage: false,
|
|
683
|
-
limit: 0,
|
|
684
|
-
nextPage: 0,
|
|
685
|
-
offset: 0,
|
|
686
|
-
page: 0,
|
|
687
|
-
pagingCounter: 0,
|
|
688
|
-
prevPage: 0,
|
|
548
|
+
data: [],
|
|
689
549
|
totalDocs: 0,
|
|
690
550
|
totalPages: 0,
|
|
551
|
+
prevPage: null,
|
|
552
|
+
nextPage: null,
|
|
691
553
|
error: true,
|
|
692
554
|
errorMessage
|
|
693
555
|
};
|
|
694
556
|
}
|
|
695
557
|
return {
|
|
696
|
-
data,
|
|
697
|
-
brands: data.docs,
|
|
698
|
-
hasNextPage: data.hasNextPage,
|
|
699
|
-
hasPrevPage: data.hasPrevPage,
|
|
700
|
-
limit: data.limit,
|
|
701
|
-
nextPage: data.nextPage,
|
|
702
|
-
offset: data.offset,
|
|
703
|
-
page: data.page,
|
|
704
|
-
pagingCounter: data.pagingCounter,
|
|
705
|
-
prevPage: data.prevPage,
|
|
558
|
+
data: parseRawBrandsToBrands(data.docs),
|
|
706
559
|
totalDocs: data.totalDocs,
|
|
707
560
|
totalPages: data.totalPages,
|
|
561
|
+
prevPage: data.prevPage,
|
|
562
|
+
nextPage: data.nextPage,
|
|
708
563
|
error: false,
|
|
709
564
|
errorMessage: null
|
|
710
565
|
};
|
|
711
566
|
}
|
|
567
|
+
};
|
|
568
|
+
var brandsApi = new BrandsApi();
|
|
569
|
+
|
|
570
|
+
// src/api/entity/parsers.ts
|
|
571
|
+
function parseRawEntityToEntity(rawEntity) {
|
|
572
|
+
return {
|
|
573
|
+
id: rawEntity.id,
|
|
574
|
+
tin: rawEntity.tin,
|
|
575
|
+
name: rawEntity.name,
|
|
576
|
+
web: rawEntity.web,
|
|
577
|
+
address: rawEntity.address,
|
|
578
|
+
country: rawEntity.country,
|
|
579
|
+
city: rawEntity.city,
|
|
580
|
+
currency_id: rawEntity.currency_id,
|
|
581
|
+
currency_name: rawEntity.currency_name,
|
|
582
|
+
currency_prefix: rawEntity.currency_prefix,
|
|
583
|
+
currency_suffix: rawEntity.currency_suffix,
|
|
584
|
+
logo_url: rawEntity.logo_url,
|
|
585
|
+
logo_alt: rawEntity.logo_alt,
|
|
586
|
+
logo_thumbnail_url: rawEntity.logo_thumbnail_url,
|
|
587
|
+
logo_sizes_thumbnail_filename: rawEntity.logo_sizes_thumbnail_filename,
|
|
588
|
+
logo_filename: rawEntity.logo_filename,
|
|
589
|
+
logo_width: rawEntity.logo_width,
|
|
590
|
+
logo_height: rawEntity.logo_height,
|
|
591
|
+
logo_2_url: rawEntity.logo_2_url,
|
|
592
|
+
logo_2_alt: rawEntity.logo_2_alt,
|
|
593
|
+
logo_2_thumbnail_url: rawEntity.logo_2_thumbnail_url,
|
|
594
|
+
logo_2_sizes_thumbnail_filename: rawEntity.logo_2_sizes_thumbnail_filename,
|
|
595
|
+
logo_2_filename: rawEntity.logo_2_filename,
|
|
596
|
+
logo_2_width: rawEntity.logo_2_width,
|
|
597
|
+
logo_2_height: rawEntity.logo_2_height,
|
|
598
|
+
featured_image_url: rawEntity.featured_image_url,
|
|
599
|
+
featured_image_alt: rawEntity.featured_image_alt,
|
|
600
|
+
featured_image_thumbnail_url: rawEntity.featured_image_thumbnail_url,
|
|
601
|
+
featured_image_sizes_thumbnail_filename: rawEntity.featured_image_sizes_thumbnail_filename,
|
|
602
|
+
featured_image_filename: rawEntity.featured_image_filename,
|
|
603
|
+
featured_image_width: rawEntity.featured_image_width,
|
|
604
|
+
featured_image_height: rawEntity.featured_image_height
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/api/entity/api.ts
|
|
609
|
+
var EntityApi = class extends ApiClient {
|
|
712
610
|
async getEntity(params = {}) {
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
return this.cache.getCachedOrFetch(
|
|
611
|
+
const cacheKey = this.cache.buildCacheKey("GetEntity", params);
|
|
612
|
+
return this.cache.cacheWrap(
|
|
716
613
|
cacheKey,
|
|
717
|
-
() => this.fetchEntityFromAPI(
|
|
718
|
-
cacheTTL,
|
|
719
|
-
skipCache
|
|
614
|
+
() => this.fetchEntityFromAPI(params)
|
|
720
615
|
);
|
|
721
616
|
}
|
|
722
|
-
async fetchEntityFromAPI(params
|
|
617
|
+
async fetchEntityFromAPI(params) {
|
|
723
618
|
if (!this.baseURL || !this.apiKey) {
|
|
724
619
|
return {
|
|
725
620
|
data: null,
|
|
726
|
-
entity: null,
|
|
727
621
|
error: true,
|
|
728
622
|
errorMessage: "SDK no configurado: PAKENTO_CMS_BASE_URL o PAKENTO_API_KEY faltantes."
|
|
729
623
|
};
|
|
@@ -769,23 +663,38 @@ var PakentoCMSAPI = class {
|
|
|
769
663
|
const { data, error, errorMessage } = await this.fetchGraphQL(
|
|
770
664
|
query,
|
|
771
665
|
params,
|
|
772
|
-
(responseData) => responseData
|
|
666
|
+
(responseData) => responseData
|
|
773
667
|
);
|
|
774
668
|
if (error) {
|
|
775
|
-
return {
|
|
776
|
-
data: null,
|
|
777
|
-
entity: null,
|
|
778
|
-
error: true,
|
|
779
|
-
errorMessage
|
|
780
|
-
};
|
|
669
|
+
return { data: null, error: true, errorMessage };
|
|
781
670
|
}
|
|
782
671
|
return {
|
|
783
|
-
data,
|
|
784
|
-
entity: data,
|
|
672
|
+
data: parseRawEntityToEntity(data.GetEntity),
|
|
785
673
|
error: false,
|
|
786
674
|
errorMessage: null
|
|
787
675
|
};
|
|
788
676
|
}
|
|
677
|
+
};
|
|
678
|
+
var entityApi = new EntityApi();
|
|
679
|
+
|
|
680
|
+
// src/api/orders/validators.ts
|
|
681
|
+
var import_zod5 = require("zod");
|
|
682
|
+
var orderSchema = import_zod5.z.object({
|
|
683
|
+
name: import_zod5.z.string().min(1),
|
|
684
|
+
email: import_zod5.z.string().email(),
|
|
685
|
+
phone: import_zod5.z.string().optional(),
|
|
686
|
+
notes: import_zod5.z.string().optional(),
|
|
687
|
+
tin: import_zod5.z.string().optional(),
|
|
688
|
+
items: import_zod5.z.array(
|
|
689
|
+
import_zod5.z.object({ id: import_zod5.z.number().positive(), quantity: import_zod5.z.number().positive() })
|
|
690
|
+
).min(1),
|
|
691
|
+
delivery_address: import_zod5.z.string().optional(),
|
|
692
|
+
delivery_instructions: import_zod5.z.string().optional(),
|
|
693
|
+
payment_method: import_zod5.z.enum(["cash", "transfer"]).optional()
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
// src/api/orders/api.ts
|
|
697
|
+
var OrdersApi = class extends ApiClient {
|
|
789
698
|
async createEcommerceOrder(params) {
|
|
790
699
|
if (!this.baseURL || !this.apiKey) {
|
|
791
700
|
return {
|
|
@@ -794,22 +703,6 @@ var PakentoCMSAPI = class {
|
|
|
794
703
|
errorMessage: "SDK no configurado"
|
|
795
704
|
};
|
|
796
705
|
}
|
|
797
|
-
const orderSchema = import_zod.z.object({
|
|
798
|
-
name: import_zod.z.string().min(1),
|
|
799
|
-
email: import_zod.z.string().email(),
|
|
800
|
-
phone: import_zod.z.string().optional(),
|
|
801
|
-
notes: import_zod.z.string().optional(),
|
|
802
|
-
tin: import_zod.z.string().optional(),
|
|
803
|
-
items: import_zod.z.array(
|
|
804
|
-
import_zod.z.object({
|
|
805
|
-
id: import_zod.z.number().positive(),
|
|
806
|
-
quantity: import_zod.z.number().positive()
|
|
807
|
-
})
|
|
808
|
-
).min(1),
|
|
809
|
-
delivery_address: import_zod.z.string().optional(),
|
|
810
|
-
delivery_instructions: import_zod.z.string().optional(),
|
|
811
|
-
payment_method: import_zod.z.enum(["cash", "transfer"]).optional()
|
|
812
|
-
});
|
|
813
706
|
const validated = orderSchema.safeParse(params);
|
|
814
707
|
if (!validated.success) {
|
|
815
708
|
const errorMessage = this.handleApiError(
|
|
@@ -839,6 +732,62 @@ var PakentoCMSAPI = class {
|
|
|
839
732
|
return { message: errorMessage, error: true, errorMessage };
|
|
840
733
|
}
|
|
841
734
|
}
|
|
735
|
+
};
|
|
736
|
+
var ordersApi = new OrdersApi();
|
|
737
|
+
|
|
738
|
+
// src/api/contact/validators.ts
|
|
739
|
+
var import_zod6 = require("zod");
|
|
740
|
+
var contactUsSchema = import_zod6.z.object({
|
|
741
|
+
name: import_zod6.z.string().min(1),
|
|
742
|
+
email: import_zod6.z.string().email(),
|
|
743
|
+
phone: import_zod6.z.string().optional(),
|
|
744
|
+
subject: import_zod6.z.string().optional(),
|
|
745
|
+
notes: import_zod6.z.string().min(1)
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// src/api/contact/api.ts
|
|
749
|
+
var ContactApi = class extends ApiClient {
|
|
750
|
+
async sendContactUsEmail(params) {
|
|
751
|
+
if (!this.baseURL || !this.apiKey) {
|
|
752
|
+
return {
|
|
753
|
+
message: "SDK no configurado",
|
|
754
|
+
error: true,
|
|
755
|
+
errorMessage: "SDK no configurado"
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
const validated = contactUsSchema.safeParse(params);
|
|
759
|
+
if (!validated.success) {
|
|
760
|
+
const errorMessage = this.handleApiError(
|
|
761
|
+
validated.error,
|
|
762
|
+
"sendContactUsEmail validation"
|
|
763
|
+
);
|
|
764
|
+
return { message: errorMessage, error: true, errorMessage };
|
|
765
|
+
}
|
|
766
|
+
try {
|
|
767
|
+
const response = await this.client.post(
|
|
768
|
+
"/api/entities/send-contact-us-email",
|
|
769
|
+
validated.data
|
|
770
|
+
);
|
|
771
|
+
if (response.status === 200) {
|
|
772
|
+
return {
|
|
773
|
+
message: response.data.message || "Mensaje enviado exitosamente",
|
|
774
|
+
error: false,
|
|
775
|
+
errorMessage: null
|
|
776
|
+
};
|
|
777
|
+
} else {
|
|
778
|
+
const errorMessage = response.data.message || "Error al enviar el mensaje";
|
|
779
|
+
return { message: errorMessage, error: true, errorMessage };
|
|
780
|
+
}
|
|
781
|
+
} catch (error) {
|
|
782
|
+
const errorMessage = this.handleApiError(error, "sendContactUsEmail");
|
|
783
|
+
return { message: errorMessage, error: true, errorMessage };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
var contactApi = new ContactApi();
|
|
788
|
+
|
|
789
|
+
// src/api/custom/api.ts
|
|
790
|
+
var CustomApi = class extends ApiClient {
|
|
842
791
|
async executeCustomQuery(params) {
|
|
843
792
|
if (!this.baseURL || !this.apiKey) {
|
|
844
793
|
return {
|
|
@@ -873,117 +822,21 @@ var PakentoCMSAPI = class {
|
|
|
873
822
|
errorMessage: null
|
|
874
823
|
};
|
|
875
824
|
} catch (error) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
const status = error.response?.status;
|
|
879
|
-
if (status === 401) {
|
|
880
|
-
errorMessage = "API Key inv\xE1lida o expirada";
|
|
881
|
-
} else if (status === 404) {
|
|
882
|
-
errorMessage = "Endpoint GraphQL no encontrado";
|
|
883
|
-
} else if (status === 400) {
|
|
884
|
-
errorMessage = "Query GraphQL inv\xE1lido o malformado";
|
|
885
|
-
} else if (status && status >= 500) {
|
|
886
|
-
errorMessage = "Error del servidor CMS";
|
|
887
|
-
} else {
|
|
888
|
-
errorMessage = `Error de conexi\xF3n: ${error.message}`;
|
|
889
|
-
}
|
|
890
|
-
} else if (error instanceof Error) {
|
|
891
|
-
errorMessage = error.message;
|
|
892
|
-
}
|
|
893
|
-
return {
|
|
894
|
-
data: null,
|
|
895
|
-
error: true,
|
|
896
|
-
errorMessage
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
async sendContactUsEmail(params) {
|
|
901
|
-
if (!this.baseURL || !this.apiKey) {
|
|
902
|
-
return {
|
|
903
|
-
message: "SDK no configurado: PAKENTO_CMS_BASE_URL o PAKENTO_API_KEY faltantes.",
|
|
904
|
-
error: true,
|
|
905
|
-
errorMessage: "SDK no configurado: PAKENTO_CMS_BASE_URL o PAKENTO_API_KEY faltantes."
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
const contactUsSchema = import_zod.z.object({
|
|
909
|
-
name: import_zod.z.string().min(1),
|
|
910
|
-
email: import_zod.z.email(),
|
|
911
|
-
phone: import_zod.z.string().optional(),
|
|
912
|
-
subject: import_zod.z.string().optional(),
|
|
913
|
-
message: import_zod.z.string().min(1)
|
|
914
|
-
});
|
|
915
|
-
const validated = contactUsSchema.safeParse(params);
|
|
916
|
-
if (!validated.success) {
|
|
917
|
-
const errorMessage = this.handleApiError(
|
|
918
|
-
validated.error,
|
|
919
|
-
"sendContactUsEmail validation"
|
|
920
|
-
);
|
|
921
|
-
return { message: errorMessage, error: true, errorMessage };
|
|
922
|
-
}
|
|
923
|
-
try {
|
|
924
|
-
const response = await this.client.post(
|
|
925
|
-
"/api/entities/send-contact-us-email",
|
|
926
|
-
validated.data
|
|
927
|
-
);
|
|
928
|
-
if (response.status === 200) {
|
|
929
|
-
return {
|
|
930
|
-
message: response.data.message || "Mensaje enviado exitosamente",
|
|
931
|
-
error: false,
|
|
932
|
-
errorMessage: null
|
|
933
|
-
};
|
|
934
|
-
} else {
|
|
935
|
-
const errorMessage = response.data.message || "Error al enviar el mensaje";
|
|
936
|
-
return { message: errorMessage, error: true, errorMessage };
|
|
937
|
-
}
|
|
938
|
-
} catch (error) {
|
|
939
|
-
const errorMessage = this.handleApiError(error, "sendContactUsEmail");
|
|
940
|
-
return { message: errorMessage, error: true, errorMessage };
|
|
825
|
+
const errorMessage = this.handleApiError(error, "Custom GraphQL");
|
|
826
|
+
return { data: null, error: true, errorMessage };
|
|
941
827
|
}
|
|
942
828
|
}
|
|
943
|
-
/**
|
|
944
|
-
* Verifica si existe cache para una función y parámetros específicos
|
|
945
|
-
*/
|
|
946
|
-
async hasCache(functionName, params = {}) {
|
|
947
|
-
return this.cache.hasCache(functionName, params);
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Obtiene la key de cache para una función y parámetros específicos
|
|
951
|
-
*/
|
|
952
|
-
getCacheKey(functionName, params = {}) {
|
|
953
|
-
return this.cache.getCacheKey(functionName, params);
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Limpia el cache para una función y parámetros específicos
|
|
957
|
-
*/
|
|
958
|
-
async clearCache(functionName, params = {}) {
|
|
959
|
-
return this.cache.clearCache(functionName, params);
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Limpia todo el cache relacionado con este API Key
|
|
963
|
-
*/
|
|
964
|
-
async clearAllCache() {
|
|
965
|
-
return this.cache.clearAllCache();
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Obtiene información del cache (útil para debugging)
|
|
969
|
-
*/
|
|
970
|
-
async getCacheInfo(functionName, params = {}) {
|
|
971
|
-
return this.cache.getCacheInfo(functionName, params);
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Limpia un cache específico que pueda estar corrupto
|
|
975
|
-
*/
|
|
976
|
-
async clearCorruptedCache(functionName, params = {}) {
|
|
977
|
-
const key = this.cache.getCacheKey(functionName, params);
|
|
978
|
-
return this.cache.clearCorruptedCache(key);
|
|
979
|
-
}
|
|
980
829
|
};
|
|
981
|
-
var
|
|
830
|
+
var customApi = new CustomApi();
|
|
982
831
|
// Annotate the CommonJS export names for ESM import in node:
|
|
983
832
|
0 && (module.exports = {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
833
|
+
ApiClient,
|
|
834
|
+
brandsApi,
|
|
835
|
+
categoriesApi,
|
|
836
|
+
contactApi,
|
|
837
|
+
customApi,
|
|
838
|
+
entityApi,
|
|
839
|
+
itemsApi,
|
|
840
|
+
ordersApi
|
|
988
841
|
});
|
|
989
842
|
//# sourceMappingURL=index.js.map
|