@pakento/cms-sdk 4.3.1 → 4.3.2

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 CHANGED
@@ -193,4 +193,8 @@ El SDK incluye manejo de errores para:
193
193
 
194
194
  MIT
195
195
 
196
- .build
196
+ .build
197
+
198
+ ## EJECUCION DE PREUBAS:
199
+
200
+ npx ts-node -P tsconfig.examples.json examples/testItems.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,42 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ declare class CacheService {
4
+ private redis?;
5
+ private apiKeyHash;
6
+ private defaultTTL;
7
+ constructor(apiKey: string);
8
+ private generateParamsHash;
9
+ buildCacheKey(functionName: string, params?: Record<string, unknown>): string;
10
+ cacheWrap<T>(key: string, fetcher: () => Promise<T>): Promise<T>;
11
+ }
12
+
13
+ declare class ApiClient {
14
+ protected client: AxiosInstance;
15
+ protected cache: CacheService;
16
+ protected baseURL: string;
17
+ protected apiKey: string;
18
+ constructor();
19
+ protected handleApiError(error: unknown, context: string): string;
20
+ protected fetchGraphQL<T>(query: string, variables: any, extractData: (responseData: any) => T): Promise<{
21
+ data: T | null;
22
+ error: boolean;
23
+ errorMessage: string | null;
24
+ }>;
25
+ }
26
+
27
+ interface ApiResponse<T> {
28
+ data: T[] | null;
29
+ totalDocs?: number;
30
+ totalPages?: number;
31
+ prevPage?: number | null;
32
+ nextPage?: number | null;
33
+ error?: boolean;
34
+ errorMessage?: string | null;
35
+ }
36
+ interface WhereClause {
37
+ equals?: string;
38
+ }
39
+
1
40
  interface ItemImage {
2
41
  url: string;
3
42
  thumbnail_url: string;
@@ -21,79 +60,13 @@ interface Item {
21
60
  url_safe_name: string;
22
61
  images: ItemImage[];
23
62
  }
24
- interface Category {
25
- id: number;
26
- name: string;
27
- image_url: string;
28
- }
29
- interface Brand {
30
- id: string;
31
- name: string;
32
- description: string;
33
- items_count: number;
34
- image_url: string;
35
- image_thumbnail_url: string;
36
- image_alt: string;
37
- }
38
- interface Entity {
39
- id: string;
40
- tin: string;
41
- name: string;
42
- web: string;
43
- address: string;
44
- country: string;
45
- city: string;
46
- currency_id: string;
47
- currency_name: string;
48
- currency_prefix: string;
49
- currency_suffix: string;
50
- logo_url: string;
51
- logo_alt: string;
52
- logo_thumbnail_url: string;
53
- logo_sizes_thumbnail_filename: string;
54
- logo_filename: string;
55
- logo_width: string;
56
- logo_height: string;
57
- logo_2_url: string;
58
- logo_2_alt: string;
59
- logo_2_thumbnail_url: string;
60
- logo_2_sizes_thumbnail_filename: string;
61
- logo_2_filename: string;
62
- logo_2_width: string;
63
- logo_2_height: string;
64
- featured_image_url: string;
65
- featured_image_alt: string;
66
- featured_image_thumbnail_url: string;
67
- featured_image_sizes_thumbnail_filename: string;
68
- featured_image_filename: string;
69
- featured_image_width: string;
70
- featured_image_height: string;
71
- }
72
- interface ApiResponse<T> {
73
- data: T[] | null;
74
- totalDocs?: number;
75
- totalPages?: number;
76
- prevPage?: number | null;
77
- nextPage?: number | null;
78
- error?: boolean;
79
- errorMessage?: string | null;
80
- }
81
- interface WhereEquals {
82
- equals?: string;
83
- }
84
63
  interface ItemsWhere {
85
- item_category_id?: WhereEquals;
86
- item_super_category_id?: WhereEquals;
87
- brand_id?: WhereEquals;
88
- id?: WhereEquals;
89
- }
90
- interface CategoriesWhere {
91
- item_super_category_id?: WhereEquals;
92
- brand_id?: WhereEquals;
64
+ item_category_id?: WhereClause;
65
+ item_super_category_id?: WhereClause;
66
+ brand_id?: WhereClause;
67
+ id?: WhereClause;
93
68
  }
94
69
  interface GetItemsParams {
95
- skipCache?: boolean;
96
- cacheTTL?: number;
97
70
  where?: ItemsWhere;
98
71
  onlyOffers?: boolean;
99
72
  limit?: number;
@@ -103,47 +76,6 @@ interface GetItemsParams {
103
76
  minPrice?: number;
104
77
  maxPrice?: number;
105
78
  }
106
- interface GetCategoriesParams {
107
- skipCache?: boolean;
108
- cacheTTL?: number;
109
- where?: CategoriesWhere;
110
- limit?: number;
111
- page?: number;
112
- sort?: string;
113
- }
114
- interface GetBrandsParams {
115
- skipCache?: boolean;
116
- cacheTTL?: number;
117
- limit?: number;
118
- page?: number;
119
- sort?: string;
120
- }
121
- interface GetEntityParams {
122
- skipCache?: boolean;
123
- cacheTTL?: number;
124
- }
125
- interface CreateEcommerceOrderItem {
126
- id: number;
127
- quantity: number;
128
- }
129
- interface CreateEcommerceOrderParams {
130
- name: string;
131
- email: string;
132
- phone?: string;
133
- notes?: string;
134
- tin?: string;
135
- items: CreateEcommerceOrderItem[];
136
- delivery_address?: string;
137
- delivery_instructions?: string;
138
- payment_method?: "cash" | "transfer";
139
- }
140
- interface SendContactUsEmailParams {
141
- name: string;
142
- email: string;
143
- phone?: string;
144
- notes?: string;
145
- subject?: string;
146
- }
147
79
  interface ItemEcommerceRaw {
148
80
  id: string;
149
81
  name: string;
@@ -182,9 +114,58 @@ interface ItemsRawResponse {
182
114
  nextPage: number | null;
183
115
  docs: ItemEcommerceRaw[];
184
116
  }
117
+
118
+ declare class ItemsApi extends ApiClient {
119
+ getItems(params?: GetItemsParams): Promise<ApiResponse<Item>>;
120
+ private fetchItemsFromAPI;
121
+ }
122
+ declare const itemsApi: ItemsApi;
123
+
124
+ interface Category {
125
+ id: number;
126
+ name: string;
127
+ image_url: string;
128
+ }
129
+ interface CategoriesWhere {
130
+ item_super_category_id?: WhereClause;
131
+ brand_id?: WhereClause;
132
+ }
133
+ interface GetCategoriesParams {
134
+ where?: CategoriesWhere;
135
+ limit?: number;
136
+ page?: number;
137
+ sort?: string;
138
+ }
185
139
  interface CategoriesRawResponse {
186
140
  docs: Category[];
187
141
  }
142
+ interface CategoriesApiResponse {
143
+ data: Category[] | null;
144
+ categories: Category[];
145
+ error: boolean;
146
+ errorMessage: string | null;
147
+ }
148
+
149
+ declare class CategoriesApi extends ApiClient {
150
+ getCategories(params?: GetCategoriesParams): Promise<CategoriesApiResponse>;
151
+ private fetchCategoriesFromAPI;
152
+ }
153
+ declare const categoriesApi: CategoriesApi;
154
+
155
+ interface Brand {
156
+ id: string;
157
+ name: string;
158
+ description: string;
159
+ items_count: number;
160
+ image_url: string;
161
+ image_thumbnail_url: string;
162
+ image_alt: string;
163
+ }
164
+ interface GetBrandsParams {
165
+ limit?: number;
166
+ page?: number;
167
+ sort?: string;
168
+ }
188
169
  interface BrandsRawResponse {
189
170
  docs: Brand[];
190
171
  hasNextPage: boolean;
@@ -198,24 +179,6 @@ interface BrandsRawResponse {
198
179
  totalDocs: number;
199
180
  totalPages: number;
200
181
  }
201
- interface EntityRawResponse {
202
- entity: Entity;
203
- }
204
- interface ItemsApiResponse {
205
- data: ItemsRawResponse | null;
206
- totalDocs: number;
207
- totalPages: number;
208
- prevPage: number | null;
209
- nextPage: number | null;
210
- error: boolean;
211
- errorMessage: string | null;
212
- }
213
- interface CategoriesApiResponse {
214
- data: Category[] | null;
215
- categories: Category[];
216
- error: boolean;
217
- errorMessage: string | null;
218
- }
219
182
  interface BrandsApiResponse {
220
183
  data: BrandsRawResponse | null;
221
184
  brands: Brand[];
@@ -232,23 +195,111 @@ interface BrandsApiResponse {
232
195
  error: boolean;
233
196
  errorMessage: string | null;
234
197
  }
198
+
199
+ declare class BrandsApi extends ApiClient {
200
+ getBrands(params?: GetBrandsParams): Promise<BrandsApiResponse>;
201
+ private fetchBrandsFromAPI;
202
+ }
203
+ declare const brandsApi: BrandsApi;
204
+
205
+ interface Entity {
206
+ id: string;
207
+ tin: string;
208
+ name: string;
209
+ web: string;
210
+ address: string;
211
+ country: string;
212
+ city: string;
213
+ currency_id: string;
214
+ currency_name: string;
215
+ currency_prefix: string;
216
+ currency_suffix: string;
217
+ logo_url: string;
218
+ logo_alt: string;
219
+ logo_thumbnail_url: string;
220
+ logo_sizes_thumbnail_filename: string;
221
+ logo_filename: string;
222
+ logo_width: string;
223
+ logo_height: string;
224
+ logo_2_url: string;
225
+ logo_2_alt: string;
226
+ logo_2_thumbnail_url: string;
227
+ logo_2_sizes_thumbnail_filename: string;
228
+ logo_2_filename: string;
229
+ logo_2_width: string;
230
+ logo_2_height: string;
231
+ featured_image_url: string;
232
+ featured_image_alt: string;
233
+ featured_image_thumbnail_url: string;
234
+ featured_image_sizes_thumbnail_filename: string;
235
+ featured_image_filename: string;
236
+ featured_image_width: string;
237
+ featured_image_height: string;
238
+ }
239
+ interface GetEntityParams {
240
+ [key: string]: unknown;
241
+ }
242
+ interface EntityRawResponse {
243
+ GetEntity: Entity;
244
+ }
235
245
  interface EntityApiResponse {
236
246
  data: Entity | null;
237
247
  entity: Entity | null;
238
248
  error: boolean;
239
249
  errorMessage: string | null;
240
250
  }
251
+
252
+ declare class EntityApi extends ApiClient {
253
+ getEntity(params?: GetEntityParams): Promise<EntityApiResponse>;
254
+ private fetchEntityFromAPI;
255
+ }
256
+ declare const entityApi: EntityApi;
257
+
258
+ interface CreateEcommerceOrderItem {
259
+ id: number;
260
+ quantity: number;
261
+ }
262
+ interface CreateEcommerceOrderParams {
263
+ name: string;
264
+ email: string;
265
+ phone?: string;
266
+ notes?: string;
267
+ tin?: string;
268
+ items: CreateEcommerceOrderItem[];
269
+ delivery_address?: string;
270
+ delivery_instructions?: string;
271
+ payment_method?: "cash" | "transfer";
272
+ }
241
273
  interface CreateEcommerceOrderResponse {
242
274
  message: string;
243
275
  order_id?: string;
244
276
  error: boolean;
245
277
  errorMessage: string | null;
246
278
  }
279
+
280
+ declare class OrdersApi extends ApiClient {
281
+ createEcommerceOrder(params: CreateEcommerceOrderParams): Promise<CreateEcommerceOrderResponse>;
282
+ }
283
+ declare const ordersApi: OrdersApi;
284
+
285
+ interface SendContactUsEmailParams {
286
+ name: string;
287
+ email: string;
288
+ phone?: string;
289
+ notes?: string;
290
+ subject?: string;
291
+ }
247
292
  interface SendContactUsEmailResponse {
248
293
  message: string;
249
294
  error: boolean;
250
295
  errorMessage: string | null;
251
296
  }
297
+
298
+ declare class ContactApi extends ApiClient {
299
+ sendContactUsEmail(params: SendContactUsEmailParams): Promise<SendContactUsEmailResponse>;
300
+ }
301
+ declare const contactApi: ContactApi;
302
+
252
303
  interface CustomGraphQLParams {
253
304
  query: string;
254
305
  variables?: Record<string, unknown>;
@@ -257,99 +308,12 @@ interface CustomGraphQLResponse<T> {
257
308
  data: T;
258
309
  error: boolean;
259
310
  errorMessage: string | null;
260
- errors?: T[];
311
+ errors?: any[];
261
312
  }
262
313
 
263
- declare class PakentoCMSAPI {
264
- private client;
265
- private cache;
266
- private defaultTTL;
267
- private baseURL;
268
- private apiKey;
269
- constructor(config?: {
270
- cacheTTL?: number;
271
- });
272
- private handleApiError;
273
- private fetchGraphQL;
274
- getItems(params?: GetItemsParams): Promise<ApiResponse<Item>>;
275
- private fetchItemsFromAPI;
276
- getCategories(params?: GetCategoriesParams): Promise<CategoriesApiResponse>;
277
- private fetchCategoriesFromAPI;
278
- getBrands(params?: GetBrandsParams): Promise<BrandsApiResponse>;
279
- private fetchBrandsFromAPI;
280
- getEntity(params?: GetEntityParams): Promise<EntityApiResponse>;
281
- private fetchEntityFromAPI;
282
- createEcommerceOrder(params: CreateEcommerceOrderParams): Promise<CreateEcommerceOrderResponse>;
314
+ declare class CustomApi extends ApiClient {
283
315
  executeCustomQuery<T>(params: CustomGraphQLParams): Promise<CustomGraphQLResponse<T>>;
284
- sendContactUsEmail(params: SendContactUsEmailParams): Promise<SendContactUsEmailResponse>;
285
- /**
286
- * Verifica si existe cache para una función y parámetros específicos
287
- */
288
- hasCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
289
- /**
290
- * Obtiene la key de cache para una función y parámetros específicos
291
- */
292
- getCacheKey(functionName: string, params?: Record<string, unknown>): string;
293
- /**
294
- * Limpia el cache para una función y parámetros específicos
295
- */
296
- clearCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
297
- /**
298
- * Limpia todo el cache relacionado con este API Key
299
- */
300
- clearAllCache(): Promise<boolean>;
301
- /**
302
- * Obtiene información del cache (útil para debugging)
303
- */
304
- getCacheInfo(functionName: string, params?: Record<string, unknown>): Promise<{
305
- exists: boolean;
306
- key: string;
307
- ttl?: number;
308
- }>;
309
- /**
310
- * Limpia un cache específico que pueda estar corrupto
311
- */
312
- clearCorruptedCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
313
316
  }
314
- declare const pakentoCMSAPI: PakentoCMSAPI;
315
-
316
- declare class CacheService {
317
- private redis?;
318
- private defaultTTL;
319
- private apiKeyHash;
320
- private isCacheEnvelope;
321
- constructor(defaultTTL: number, apiKey: string);
322
- private generateParamsHash;
323
- buildCacheKey(functionName: string, params?: Record<string, unknown>): string;
324
- private safeJsonParse;
325
- private serializeForCache;
326
- getCachedOrFetch<T>(key: string, fetcher: () => Promise<T>, ttl?: number, skipCache?: boolean): Promise<T>;
327
- hasCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
328
- /**
329
- * Limpia un cache específico si está corrupto
330
- */
331
- clearCorruptedCache(key: string): Promise<boolean>;
332
- getCacheKey(functionName: string, params?: Record<string, unknown>): string;
333
- clearCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
334
- clearAllCache(): Promise<boolean>;
335
- getCacheInfo(functionName: string, params?: Record<string, unknown>): Promise<{
336
- exists: boolean;
337
- key: string;
338
- ttl?: number;
339
- }>;
340
- }
341
-
342
- /**
343
- * Parses a raw GraphQL response item to the normalized Item type
344
- * @param rawItem - The raw item from GraphQL response
345
- * @returns Normalized Item object
346
- */
347
- declare function parseRawItemToItem(rawItem: ItemEcommerceRaw): Item;
348
- /**
349
- * Parses an array of raw GraphQL response items to normalized Item types
350
- * @param rawItems - Array of raw items from GraphQL response
351
- * @returns Array of normalized Item objects
352
- */
353
- declare function parseRawItemsToItems(rawItems: ItemEcommerceRaw[]): Item[];
317
+ declare const customApi: CustomApi;
354
318
 
355
- export { type Brand, type BrandsApiResponse, type BrandsRawResponse, CacheService, type CategoriesApiResponse, type CategoriesRawResponse, type CategoriesWhere, type Category, type CreateEcommerceOrderParams, type CreateEcommerceOrderResponse, type CustomGraphQLParams, type CustomGraphQLResponse, type Entity, type EntityApiResponse, type EntityRawResponse, type GetBrandsParams, type GetCategoriesParams, type GetEntityParams, type GetItemsParams, type Item, type ItemImage, type ItemsApiResponse, type ItemsRawResponse, type ItemsWhere, type SendContactUsEmailParams, type SendContactUsEmailResponse, type WhereEquals, pakentoCMSAPI, parseRawItemToItem, parseRawItemsToItems };
319
+ export { ApiClient, type ApiResponse, type Brand, type BrandsApiResponse, type BrandsRawResponse, type CategoriesApiResponse, type CategoriesRawResponse, type CategoriesWhere, type Category, type CreateEcommerceOrderItem, type CreateEcommerceOrderParams, type CreateEcommerceOrderResponse, type CustomGraphQLParams, type CustomGraphQLResponse, type Entity, type EntityApiResponse, type EntityRawResponse, type GetBrandsParams, type GetCategoriesParams, type GetEntityParams, type GetItemsParams, type Item, type ItemEcommerceRaw, type ItemImage, type ItemsRawResponse, type ItemsWhere, type SendContactUsEmailParams, type SendContactUsEmailResponse, type WhereClause, brandsApi, categoriesApi, contactApi, customApi, entityApi, itemsApi, ordersApi };