@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 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,11 +114,70 @@ 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 CategoryEcommerceRaw {
130
+ id: number;
131
+ name: string;
132
+ image_url: string;
133
+ }
134
+ interface CategoriesWhere {
135
+ item_super_category_id?: WhereClause;
136
+ brand_id?: WhereClause;
137
+ }
138
+ interface GetCategoriesParams {
139
+ where?: CategoriesWhere;
140
+ limit?: number;
141
+ page?: number;
142
+ sort?: string;
143
+ [key: string]: unknown;
144
+ }
185
145
  interface CategoriesRawResponse {
186
- docs: Category[];
146
+ docs: CategoryEcommerceRaw[];
147
+ }
148
+
149
+ declare class CategoriesApi extends ApiClient {
150
+ getCategories(params?: GetCategoriesParams): Promise<ApiResponse<Category[]>>;
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 BrandEcommerceRaw {
165
+ id: string;
166
+ name: string;
167
+ description: string;
168
+ items_count: number;
169
+ image_url: string;
170
+ image_thumbnail_url: string;
171
+ image_alt: string;
172
+ }
173
+ interface GetBrandsParams {
174
+ limit?: number;
175
+ page?: number;
176
+ sort?: string;
177
+ [key: string]: unknown;
187
178
  }
188
179
  interface BrandsRawResponse {
189
- docs: Brand[];
180
+ docs: BrandEcommerceRaw[];
190
181
  hasNextPage: boolean;
191
182
  hasPrevPage: boolean;
192
183
  limit: number;
@@ -198,45 +189,108 @@ interface BrandsRawResponse {
198
189
  totalDocs: number;
199
190
  totalPages: number;
200
191
  }
201
- interface EntityRawResponse {
202
- entity: Entity;
192
+
193
+ declare class BrandsApi extends ApiClient {
194
+ getBrands(params?: GetBrandsParams): Promise<ApiResponse<Brand[]>>;
195
+ private fetchBrandsFromAPI;
203
196
  }
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;
197
+ declare const brandsApi: BrandsApi;
198
+
199
+ interface Entity {
200
+ id: string;
201
+ tin: string;
202
+ name: string;
203
+ web: string;
204
+ address: string;
205
+ country: string;
206
+ city: string;
207
+ currency_id: string;
208
+ currency_name: string;
209
+ currency_prefix: string;
210
+ currency_suffix: string;
211
+ logo_url: string;
212
+ logo_alt: string;
213
+ logo_thumbnail_url: string;
214
+ logo_sizes_thumbnail_filename: string;
215
+ logo_filename: string;
216
+ logo_width: string;
217
+ logo_height: string;
218
+ logo_2_url: string;
219
+ logo_2_alt: string;
220
+ logo_2_thumbnail_url: string;
221
+ logo_2_sizes_thumbnail_filename: string;
222
+ logo_2_filename: string;
223
+ logo_2_width: string;
224
+ logo_2_height: string;
225
+ featured_image_url: string;
226
+ featured_image_alt: string;
227
+ featured_image_thumbnail_url: string;
228
+ featured_image_sizes_thumbnail_filename: string;
229
+ featured_image_filename: string;
230
+ featured_image_width: string;
231
+ featured_image_height: string;
212
232
  }
213
- interface CategoriesApiResponse {
214
- data: Category[] | null;
215
- categories: Category[];
216
- error: boolean;
217
- errorMessage: string | null;
233
+ interface EntityEcommerceRaw {
234
+ id: string;
235
+ tin: string;
236
+ name: string;
237
+ web: string;
238
+ address: string;
239
+ country: string;
240
+ city: string;
241
+ currency_id: string;
242
+ currency_name: string;
243
+ currency_prefix: string;
244
+ currency_suffix: string;
245
+ logo_url: string;
246
+ logo_alt: string;
247
+ logo_thumbnail_url: string;
248
+ logo_sizes_thumbnail_filename: string;
249
+ logo_filename: string;
250
+ logo_width: string;
251
+ logo_height: string;
252
+ logo_2_url: string;
253
+ logo_2_alt: string;
254
+ logo_2_thumbnail_url: string;
255
+ logo_2_sizes_thumbnail_filename: string;
256
+ logo_2_filename: string;
257
+ logo_2_width: string;
258
+ logo_2_height: string;
259
+ featured_image_url: string;
260
+ featured_image_alt: string;
261
+ featured_image_thumbnail_url: string;
262
+ featured_image_sizes_thumbnail_filename: string;
263
+ featured_image_filename: string;
264
+ featured_image_width: string;
265
+ featured_image_height: string;
218
266
  }
219
- interface BrandsApiResponse {
220
- data: BrandsRawResponse | null;
221
- brands: Brand[];
222
- hasNextPage: boolean;
223
- hasPrevPage: boolean;
224
- limit: number;
225
- nextPage: number;
226
- offset: number;
227
- page: number;
228
- pagingCounter: number;
229
- prevPage: number;
230
- totalDocs: number;
231
- totalPages: number;
232
- error: boolean;
233
- errorMessage: string | null;
267
+ interface GetEntityParams {
268
+ [key: string]: unknown;
234
269
  }
235
- interface EntityApiResponse {
236
- data: Entity | null;
237
- entity: Entity | null;
238
- error: boolean;
239
- errorMessage: string | null;
270
+ interface EntityRawResponse {
271
+ GetEntity: EntityEcommerceRaw;
272
+ }
273
+
274
+ declare class EntityApi extends ApiClient {
275
+ getEntity(params?: GetEntityParams): Promise<ApiResponse<Entity>>;
276
+ private fetchEntityFromAPI;
277
+ }
278
+ declare const entityApi: EntityApi;
279
+
280
+ interface CreateEcommerceOrderItem {
281
+ id: number;
282
+ quantity: number;
283
+ }
284
+ interface CreateEcommerceOrderParams {
285
+ name: string;
286
+ email: string;
287
+ phone?: string;
288
+ notes?: string;
289
+ tin?: string;
290
+ items: CreateEcommerceOrderItem[];
291
+ delivery_address?: string;
292
+ delivery_instructions?: string;
293
+ payment_method?: "cash" | "transfer";
240
294
  }
241
295
  interface CreateEcommerceOrderResponse {
242
296
  message: string;
@@ -244,11 +298,31 @@ interface CreateEcommerceOrderResponse {
244
298
  error: boolean;
245
299
  errorMessage: string | null;
246
300
  }
301
+
302
+ declare class OrdersApi extends ApiClient {
303
+ createEcommerceOrder(params: CreateEcommerceOrderParams): Promise<CreateEcommerceOrderResponse>;
304
+ }
305
+ declare const ordersApi: OrdersApi;
306
+
307
+ interface SendContactUsEmailParams {
308
+ name: string;
309
+ email: string;
310
+ phone?: string;
311
+ notes?: string;
312
+ subject?: string;
313
+ [key: string]: unknown;
314
+ }
247
315
  interface SendContactUsEmailResponse {
248
316
  message: string;
249
317
  error: boolean;
250
318
  errorMessage: string | null;
251
319
  }
320
+
321
+ declare class ContactApi extends ApiClient {
322
+ sendContactUsEmail(params: SendContactUsEmailParams): Promise<SendContactUsEmailResponse>;
323
+ }
324
+ declare const contactApi: ContactApi;
325
+
252
326
  interface CustomGraphQLParams {
253
327
  query: string;
254
328
  variables?: Record<string, unknown>;
@@ -257,99 +331,12 @@ interface CustomGraphQLResponse<T> {
257
331
  data: T;
258
332
  error: boolean;
259
333
  errorMessage: string | null;
260
- errors?: T[];
334
+ errors?: any[];
261
335
  }
262
336
 
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>;
337
+ declare class CustomApi extends ApiClient {
283
338
  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
339
  }
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[];
340
+ declare const customApi: CustomApi;
354
341
 
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 };
342
+ export { ApiClient, type ApiResponse, type Brand, type BrandEcommerceRaw, type BrandsRawResponse, type CategoriesRawResponse, type CategoriesWhere, type Category, type CategoryEcommerceRaw, type CreateEcommerceOrderItem, type CreateEcommerceOrderParams, type CreateEcommerceOrderResponse, type CustomGraphQLParams, type CustomGraphQLResponse, type Entity, type EntityEcommerceRaw, 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 };