@pakento/cms-sdk 4.3.0 → 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,70 +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 WhereEquals {
73
- equals?: string;
74
- }
75
63
  interface ItemsWhere {
76
- item_category_id?: WhereEquals;
77
- item_super_category_id?: WhereEquals;
78
- brand_id?: WhereEquals;
79
- id?: WhereEquals;
80
- }
81
- interface CategoriesWhere {
82
- item_super_category_id?: WhereEquals;
83
- brand_id?: WhereEquals;
64
+ item_category_id?: WhereClause;
65
+ item_super_category_id?: WhereClause;
66
+ brand_id?: WhereClause;
67
+ id?: WhereClause;
84
68
  }
85
69
  interface GetItemsParams {
86
- skipCache?: boolean;
87
- cacheTTL?: number;
88
70
  where?: ItemsWhere;
89
71
  onlyOffers?: boolean;
90
72
  limit?: number;
@@ -94,47 +76,6 @@ interface GetItemsParams {
94
76
  minPrice?: number;
95
77
  maxPrice?: number;
96
78
  }
97
- interface GetCategoriesParams {
98
- skipCache?: boolean;
99
- cacheTTL?: number;
100
- where?: CategoriesWhere;
101
- limit?: number;
102
- page?: number;
103
- sort?: string;
104
- }
105
- interface GetBrandsParams {
106
- skipCache?: boolean;
107
- cacheTTL?: number;
108
- limit?: number;
109
- page?: number;
110
- sort?: string;
111
- }
112
- interface GetEntityParams {
113
- skipCache?: boolean;
114
- cacheTTL?: number;
115
- }
116
- interface CreateEcommerceOrderItem {
117
- id: number;
118
- quantity: number;
119
- }
120
- interface CreateEcommerceOrderParams {
121
- name: string;
122
- email: string;
123
- phone?: string;
124
- notes?: string;
125
- tin?: string;
126
- items: CreateEcommerceOrderItem[];
127
- delivery_address?: string;
128
- delivery_instructions?: string;
129
- payment_method?: "cash" | "transfer";
130
- }
131
- interface SendContactUsEmailParams {
132
- name: string;
133
- email: string;
134
- phone?: string;
135
- notes?: string;
136
- subject?: string;
137
- }
138
79
  interface ItemEcommerceRaw {
139
80
  id: string;
140
81
  name: string;
@@ -173,9 +114,58 @@ interface ItemsRawResponse {
173
114
  nextPage: number | null;
174
115
  docs: ItemEcommerceRaw[];
175
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
+ }
176
139
  interface CategoriesRawResponse {
177
140
  docs: Category[];
178
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
+ }
179
169
  interface BrandsRawResponse {
180
170
  docs: Brand[];
181
171
  hasNextPage: boolean;
@@ -189,25 +179,6 @@ interface BrandsRawResponse {
189
179
  totalDocs: number;
190
180
  totalPages: number;
191
181
  }
192
- interface EntityRawResponse {
193
- entity: Entity;
194
- }
195
- interface ItemsApiResponse {
196
- data: ItemsRawResponse | null;
197
- items: Item[];
198
- totalDocs: number;
199
- totalPages: number;
200
- prevPage: number | null;
201
- nextPage: number | null;
202
- error: boolean;
203
- errorMessage: string | null;
204
- }
205
- interface CategoriesApiResponse {
206
- data: Category[] | null;
207
- categories: Category[];
208
- error: boolean;
209
- errorMessage: string | null;
210
- }
211
182
  interface BrandsApiResponse {
212
183
  data: BrandsRawResponse | null;
213
184
  brands: Brand[];
@@ -224,23 +195,111 @@ interface BrandsApiResponse {
224
195
  error: boolean;
225
196
  errorMessage: string | null;
226
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
+ }
227
245
  interface EntityApiResponse {
228
246
  data: Entity | null;
229
247
  entity: Entity | null;
230
248
  error: boolean;
231
249
  errorMessage: string | null;
232
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
+ }
233
273
  interface CreateEcommerceOrderResponse {
234
274
  message: string;
235
275
  order_id?: string;
236
276
  error: boolean;
237
277
  errorMessage: string | null;
238
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
+ }
239
292
  interface SendContactUsEmailResponse {
240
293
  message: string;
241
294
  error: boolean;
242
295
  errorMessage: string | null;
243
296
  }
297
+
298
+ declare class ContactApi extends ApiClient {
299
+ sendContactUsEmail(params: SendContactUsEmailParams): Promise<SendContactUsEmailResponse>;
300
+ }
301
+ declare const contactApi: ContactApi;
302
+
244
303
  interface CustomGraphQLParams {
245
304
  query: string;
246
305
  variables?: Record<string, unknown>;
@@ -249,99 +308,12 @@ interface CustomGraphQLResponse<T> {
249
308
  data: T;
250
309
  error: boolean;
251
310
  errorMessage: string | null;
252
- errors?: T[];
311
+ errors?: any[];
253
312
  }
254
313
 
255
- declare class PakentoCMSAPI {
256
- private client;
257
- private cache;
258
- private defaultTTL;
259
- private baseURL;
260
- private apiKey;
261
- constructor(config?: {
262
- cacheTTL?: number;
263
- });
264
- private handleApiError;
265
- private fetchGraphQL;
266
- getItems(params?: GetItemsParams): Promise<ItemsApiResponse>;
267
- private fetchItemsFromAPI;
268
- getCategories(params?: GetCategoriesParams): Promise<CategoriesApiResponse>;
269
- private fetchCategoriesFromAPI;
270
- getBrands(params?: GetBrandsParams): Promise<BrandsApiResponse>;
271
- private fetchBrandsFromAPI;
272
- getEntity(params?: GetEntityParams): Promise<EntityApiResponse>;
273
- private fetchEntityFromAPI;
274
- createEcommerceOrder(params: CreateEcommerceOrderParams): Promise<CreateEcommerceOrderResponse>;
314
+ declare class CustomApi extends ApiClient {
275
315
  executeCustomQuery<T>(params: CustomGraphQLParams): Promise<CustomGraphQLResponse<T>>;
276
- sendContactUsEmail(params: SendContactUsEmailParams): Promise<SendContactUsEmailResponse>;
277
- /**
278
- * Verifica si existe cache para una función y parámetros específicos
279
- */
280
- hasCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
281
- /**
282
- * Obtiene la key de cache para una función y parámetros específicos
283
- */
284
- getCacheKey(functionName: string, params?: Record<string, unknown>): string;
285
- /**
286
- * Limpia el cache para una función y parámetros específicos
287
- */
288
- clearCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
289
- /**
290
- * Limpia todo el cache relacionado con este API Key
291
- */
292
- clearAllCache(): Promise<boolean>;
293
- /**
294
- * Obtiene información del cache (útil para debugging)
295
- */
296
- getCacheInfo(functionName: string, params?: Record<string, unknown>): Promise<{
297
- exists: boolean;
298
- key: string;
299
- ttl?: number;
300
- }>;
301
- /**
302
- * Limpia un cache específico que pueda estar corrupto
303
- */
304
- clearCorruptedCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
305
- }
306
- declare const pakentoCMSAPI: PakentoCMSAPI;
307
-
308
- declare class CacheService {
309
- private redis?;
310
- private defaultTTL;
311
- private apiKeyHash;
312
- private isCacheEnvelope;
313
- constructor(defaultTTL: number, apiKey: string);
314
- private generateParamsHash;
315
- buildCacheKey(functionName: string, params?: Record<string, unknown>): string;
316
- private safeJsonParse;
317
- private serializeForCache;
318
- getCachedOrFetch<T>(key: string, fetcher: () => Promise<T>, ttl?: number, skipCache?: boolean): Promise<T>;
319
- hasCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
320
- /**
321
- * Limpia un cache específico si está corrupto
322
- */
323
- clearCorruptedCache(key: string): Promise<boolean>;
324
- getCacheKey(functionName: string, params?: Record<string, unknown>): string;
325
- clearCache(functionName: string, params?: Record<string, unknown>): Promise<boolean>;
326
- clearAllCache(): Promise<boolean>;
327
- getCacheInfo(functionName: string, params?: Record<string, unknown>): Promise<{
328
- exists: boolean;
329
- key: string;
330
- ttl?: number;
331
- }>;
332
316
  }
317
+ declare const customApi: CustomApi;
333
318
 
334
- /**
335
- * Parses a raw GraphQL response item to the normalized Item type
336
- * @param rawItem - The raw item from GraphQL response
337
- * @returns Normalized Item object
338
- */
339
- declare function parseRawItemToItem(rawItem: ItemEcommerceRaw): Item;
340
- /**
341
- * Parses an array of raw GraphQL response items to normalized Item types
342
- * @param rawItems - Array of raw items from GraphQL response
343
- * @returns Array of normalized Item objects
344
- */
345
- declare function parseRawItemsToItems(rawItems: ItemEcommerceRaw[]): Item[];
346
-
347
- 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 };