@whatalo/plugin-sdk 1.0.0

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.
Files changed (55) hide show
  1. package/dist/adapters/express.cjs +87 -0
  2. package/dist/adapters/express.cjs.map +1 -0
  3. package/dist/adapters/express.d.cts +17 -0
  4. package/dist/adapters/express.d.ts +17 -0
  5. package/dist/adapters/express.mjs +60 -0
  6. package/dist/adapters/express.mjs.map +1 -0
  7. package/dist/adapters/hono.cjs +79 -0
  8. package/dist/adapters/hono.cjs.map +1 -0
  9. package/dist/adapters/hono.d.cts +15 -0
  10. package/dist/adapters/hono.d.ts +15 -0
  11. package/dist/adapters/hono.mjs +52 -0
  12. package/dist/adapters/hono.mjs.map +1 -0
  13. package/dist/adapters/nextjs.cjs +79 -0
  14. package/dist/adapters/nextjs.cjs.map +1 -0
  15. package/dist/adapters/nextjs.d.cts +7 -0
  16. package/dist/adapters/nextjs.d.ts +7 -0
  17. package/dist/adapters/nextjs.mjs +52 -0
  18. package/dist/adapters/nextjs.mjs.map +1 -0
  19. package/dist/bridge/index.cjs +290 -0
  20. package/dist/bridge/index.cjs.map +1 -0
  21. package/dist/bridge/index.d.cts +236 -0
  22. package/dist/bridge/index.d.ts +236 -0
  23. package/dist/bridge/index.mjs +260 -0
  24. package/dist/bridge/index.mjs.map +1 -0
  25. package/dist/client/index.cjs +423 -0
  26. package/dist/client/index.cjs.map +1 -0
  27. package/dist/client/index.d.cts +131 -0
  28. package/dist/client/index.d.ts +131 -0
  29. package/dist/client/index.mjs +396 -0
  30. package/dist/client/index.mjs.map +1 -0
  31. package/dist/index.cjs +843 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +57 -0
  34. package/dist/index.d.ts +57 -0
  35. package/dist/index.mjs +801 -0
  36. package/dist/index.mjs.map +1 -0
  37. package/dist/manifest/index.cjs +145 -0
  38. package/dist/manifest/index.cjs.map +1 -0
  39. package/dist/manifest/index.d.cts +78 -0
  40. package/dist/manifest/index.d.ts +78 -0
  41. package/dist/manifest/index.mjs +117 -0
  42. package/dist/manifest/index.mjs.map +1 -0
  43. package/dist/types-D2Efg3EG.d.ts +19 -0
  44. package/dist/types-DZ659i6f.d.ts +68 -0
  45. package/dist/types-Db_BeRCj.d.cts +19 -0
  46. package/dist/types-DdqKKyqX.d.cts +68 -0
  47. package/dist/types-M1eLMz6w.d.cts +279 -0
  48. package/dist/types-M1eLMz6w.d.ts +279 -0
  49. package/dist/webhooks/index.cjs +50 -0
  50. package/dist/webhooks/index.cjs.map +1 -0
  51. package/dist/webhooks/index.d.cts +18 -0
  52. package/dist/webhooks/index.d.ts +18 -0
  53. package/dist/webhooks/index.mjs +23 -0
  54. package/dist/webhooks/index.mjs.map +1 -0
  55. package/package.json +94 -0
@@ -0,0 +1,423 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/client/whatalo-client.ts
21
+ var whatalo_client_exports = {};
22
+ __export(whatalo_client_exports, {
23
+ WhataloClient: () => WhataloClient
24
+ });
25
+ module.exports = __toCommonJS(whatalo_client_exports);
26
+
27
+ // src/client/errors.ts
28
+ var WhataloAPIError = class extends Error {
29
+ statusCode;
30
+ code;
31
+ requestId;
32
+ constructor(message, statusCode, code, requestId) {
33
+ super(message);
34
+ this.name = "WhataloAPIError";
35
+ this.statusCode = statusCode;
36
+ this.code = code;
37
+ this.requestId = requestId;
38
+ }
39
+ };
40
+ var AuthenticationError = class extends WhataloAPIError {
41
+ constructor(message = "Invalid or missing API key", requestId) {
42
+ super(message, 401, "authentication_error", requestId);
43
+ this.name = "AuthenticationError";
44
+ }
45
+ };
46
+ var AuthorizationError = class extends WhataloAPIError {
47
+ requiredScope;
48
+ constructor(message, requiredScope, requestId) {
49
+ super(message, 403, "authorization_error", requestId);
50
+ this.name = "AuthorizationError";
51
+ this.requiredScope = requiredScope;
52
+ }
53
+ };
54
+ var InsufficientScopeError = class extends WhataloAPIError {
55
+ /** The exact scope string missing from the installation's granted_scopes */
56
+ requiredScope;
57
+ /** The scopes currently granted to this installation */
58
+ grantedScopes;
59
+ constructor(message, requiredScope, grantedScopes, requestId) {
60
+ super(message, 403, "insufficient_scope", requestId);
61
+ this.name = "InsufficientScopeError";
62
+ this.requiredScope = requiredScope;
63
+ this.grantedScopes = grantedScopes;
64
+ }
65
+ };
66
+ var NotFoundError = class extends WhataloAPIError {
67
+ resourceType;
68
+ resourceId;
69
+ constructor(resourceType, resourceId, requestId) {
70
+ super(
71
+ `${resourceType} '${resourceId}' not found`,
72
+ 404,
73
+ "not_found",
74
+ requestId
75
+ );
76
+ this.name = "NotFoundError";
77
+ this.resourceType = resourceType;
78
+ this.resourceId = resourceId;
79
+ }
80
+ };
81
+ var ValidationError = class extends WhataloAPIError {
82
+ fieldErrors;
83
+ constructor(fieldErrors, requestId) {
84
+ const message = `Validation failed: ${fieldErrors.map((e) => `${e.field} \u2014 ${e.message}`).join(", ")}`;
85
+ super(message, 422, "validation_error", requestId);
86
+ this.name = "ValidationError";
87
+ this.fieldErrors = fieldErrors;
88
+ }
89
+ };
90
+ var RateLimitError = class extends WhataloAPIError {
91
+ /** Seconds until the rate limit resets */
92
+ retryAfter;
93
+ constructor(retryAfter, requestId) {
94
+ super(
95
+ `Rate limit exceeded. Retry after ${retryAfter} seconds.`,
96
+ 429,
97
+ "rate_limit_exceeded",
98
+ requestId
99
+ );
100
+ this.name = "RateLimitError";
101
+ this.retryAfter = retryAfter;
102
+ }
103
+ };
104
+ var InternalError = class extends WhataloAPIError {
105
+ constructor(message = "An internal error occurred", requestId) {
106
+ super(message, 500, "internal_error", requestId);
107
+ this.name = "InternalError";
108
+ }
109
+ };
110
+
111
+ // src/client/whatalo-client.ts
112
+ var DEFAULT_BASE_URL = "https://api.whatalo.com/v1";
113
+ var DEFAULT_TIMEOUT = 3e4;
114
+ var WhataloClient = class {
115
+ apiKey;
116
+ baseUrl;
117
+ timeout;
118
+ maxRetries;
119
+ fetchFn;
120
+ onRequest;
121
+ onResponse;
122
+ /** Rate limit info from the most recent API response */
123
+ rateLimit = { limit: 0, remaining: 0, reset: 0 };
124
+ /** Product resource methods */
125
+ products;
126
+ /** Order resource methods */
127
+ orders;
128
+ /** Customer resource methods */
129
+ customers;
130
+ /** Category resource methods */
131
+ categories;
132
+ /** Discount resource methods */
133
+ discounts;
134
+ /** Store resource methods */
135
+ store;
136
+ /** Inventory resource methods */
137
+ inventory;
138
+ /** Webhook resource methods */
139
+ webhooks;
140
+ constructor(options) {
141
+ this.apiKey = options.apiKey;
142
+ this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
143
+ this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
144
+ this.maxRetries = Math.min(options.retries ?? 0, 3);
145
+ this.fetchFn = options.fetch ?? globalThis.fetch;
146
+ this.onRequest = options.onRequest;
147
+ this.onResponse = options.onResponse;
148
+ this.products = new ProductResource(this);
149
+ this.orders = new OrderResource(this);
150
+ this.customers = new CustomerResource(this);
151
+ this.categories = new CategoryResource(this);
152
+ this.discounts = new DiscountResource(this);
153
+ this.store = new StoreResource(this);
154
+ this.inventory = new InventoryResource(this);
155
+ this.webhooks = new WebhookResource(this);
156
+ }
157
+ /**
158
+ * Internal request method shared by all resource namespaces.
159
+ * Handles headers, timeout, error parsing, and rate limit extraction.
160
+ */
161
+ async request(method, path, options) {
162
+ let url = `${this.baseUrl}${path}`;
163
+ if (options?.params) {
164
+ const searchParams = new URLSearchParams();
165
+ for (const [key, value] of Object.entries(options.params)) {
166
+ if (value !== void 0) {
167
+ searchParams.set(key, String(value));
168
+ }
169
+ }
170
+ const qs = searchParams.toString();
171
+ if (qs) url += `?${qs}`;
172
+ }
173
+ const headers = {
174
+ "X-API-Key": this.apiKey,
175
+ "Content-Type": "application/json"
176
+ };
177
+ let lastError = null;
178
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
179
+ const controller = new AbortController();
180
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
181
+ const requestInit = {
182
+ method,
183
+ headers,
184
+ body: options?.body ? JSON.stringify(options.body) : void 0,
185
+ signal: controller.signal
186
+ };
187
+ const startedAt = Date.now();
188
+ this.onRequest?.(url, requestInit);
189
+ try {
190
+ const response = await this.fetchFn(url, requestInit);
191
+ clearTimeout(timeoutId);
192
+ this.onResponse?.(response, Date.now() - startedAt);
193
+ this.rateLimit = {
194
+ limit: Number(response.headers.get("X-RateLimit-Limit") ?? 0),
195
+ remaining: Number(
196
+ response.headers.get("X-RateLimit-Remaining") ?? 0
197
+ ),
198
+ reset: Number(response.headers.get("X-RateLimit-Reset") ?? 0)
199
+ };
200
+ const requestId = response.headers.get("X-Request-Id") ?? void 0;
201
+ if (response.ok) {
202
+ return await response.json();
203
+ }
204
+ const errorBody = await response.json().catch(() => ({
205
+ error: { code: "unknown", message: response.statusText }
206
+ }));
207
+ const errData = errorBody.error;
208
+ switch (response.status) {
209
+ case 401:
210
+ throw new AuthenticationError(errData?.message, requestId);
211
+ case 403:
212
+ if (errData?.code === "insufficient_scope") {
213
+ const details = errorBody;
214
+ throw new InsufficientScopeError(
215
+ errData.message ?? "Insufficient scope",
216
+ details.error?.required ?? "",
217
+ details.error?.granted ?? [],
218
+ requestId
219
+ );
220
+ }
221
+ throw new AuthorizationError(
222
+ errData?.message ?? "Forbidden",
223
+ errData?.code ?? "unknown_scope",
224
+ requestId
225
+ );
226
+ case 404:
227
+ throw new NotFoundError("Resource", path, requestId);
228
+ case 422:
229
+ throw new ValidationError(
230
+ errData?.details ?? [
231
+ { field: "unknown", message: errData?.message ?? "Validation failed" }
232
+ ],
233
+ requestId
234
+ );
235
+ case 429: {
236
+ const retryAfter = Number(
237
+ response.headers.get("Retry-After") ?? 60
238
+ );
239
+ throw new RateLimitError(retryAfter, requestId);
240
+ }
241
+ default:
242
+ if (response.status >= 500 && attempt < this.maxRetries) {
243
+ lastError = new InternalError(errData?.message, requestId);
244
+ await this.sleep(Math.pow(2, attempt) * 1e3);
245
+ continue;
246
+ }
247
+ throw new WhataloAPIError(
248
+ errData?.message ?? "API error",
249
+ response.status,
250
+ errData?.code ?? "unknown",
251
+ requestId
252
+ );
253
+ }
254
+ } catch (err) {
255
+ clearTimeout(timeoutId);
256
+ if (err instanceof WhataloAPIError) throw err;
257
+ if (err.name === "AbortError") {
258
+ throw new WhataloAPIError(
259
+ "Request timed out",
260
+ 408,
261
+ "timeout"
262
+ );
263
+ }
264
+ throw err;
265
+ }
266
+ }
267
+ throw lastError ?? new InternalError("Request failed after retries");
268
+ }
269
+ sleep(ms) {
270
+ return new Promise((resolve) => setTimeout(resolve, ms));
271
+ }
272
+ };
273
+ var ProductResource = class {
274
+ constructor(client) {
275
+ this.client = client;
276
+ }
277
+ async list(params) {
278
+ return this.client.request("GET", "/products", {
279
+ params
280
+ });
281
+ }
282
+ async get(id) {
283
+ return this.client.request("GET", `/products/${id}`);
284
+ }
285
+ async create(data) {
286
+ return this.client.request("POST", "/products", { body: data });
287
+ }
288
+ async update(id, data) {
289
+ return this.client.request("PATCH", `/products/${id}`, { body: data });
290
+ }
291
+ async delete(id) {
292
+ return this.client.request("DELETE", `/products/${id}`);
293
+ }
294
+ async count(status) {
295
+ return this.client.request("GET", "/products/count", {
296
+ params: status ? { status } : void 0
297
+ });
298
+ }
299
+ };
300
+ var OrderResource = class {
301
+ constructor(client) {
302
+ this.client = client;
303
+ }
304
+ async list(params) {
305
+ return this.client.request("GET", "/orders", {
306
+ params
307
+ });
308
+ }
309
+ async get(id) {
310
+ return this.client.request("GET", `/orders/${id}`);
311
+ }
312
+ async updateStatus(id, data) {
313
+ return this.client.request("PATCH", `/orders/${id}`, { body: data });
314
+ }
315
+ async count(status) {
316
+ return this.client.request("GET", "/orders/count", {
317
+ params: status ? { status } : void 0
318
+ });
319
+ }
320
+ };
321
+ var CustomerResource = class {
322
+ constructor(client) {
323
+ this.client = client;
324
+ }
325
+ async list(params) {
326
+ return this.client.request("GET", "/customers", {
327
+ params
328
+ });
329
+ }
330
+ async get(id) {
331
+ return this.client.request("GET", `/customers/${id}`);
332
+ }
333
+ };
334
+ var CategoryResource = class {
335
+ constructor(client) {
336
+ this.client = client;
337
+ }
338
+ async list(params) {
339
+ return this.client.request("GET", "/categories", {
340
+ params
341
+ });
342
+ }
343
+ async get(id) {
344
+ return this.client.request("GET", `/categories/${id}`);
345
+ }
346
+ async create(data) {
347
+ return this.client.request("POST", "/categories", { body: data });
348
+ }
349
+ async update(id, data) {
350
+ return this.client.request("PATCH", `/categories/${id}`, { body: data });
351
+ }
352
+ async delete(id) {
353
+ return this.client.request("DELETE", `/categories/${id}`);
354
+ }
355
+ async count() {
356
+ return this.client.request("GET", "/categories/count");
357
+ }
358
+ };
359
+ var DiscountResource = class {
360
+ constructor(client) {
361
+ this.client = client;
362
+ }
363
+ async list(params) {
364
+ return this.client.request("GET", "/discounts", {
365
+ params
366
+ });
367
+ }
368
+ async get(id) {
369
+ return this.client.request("GET", `/discounts/${id}`);
370
+ }
371
+ async create(data) {
372
+ return this.client.request("POST", "/discounts", { body: data });
373
+ }
374
+ async update(id, data) {
375
+ return this.client.request("PATCH", `/discounts/${id}`, { body: data });
376
+ }
377
+ async delete(id) {
378
+ return this.client.request("DELETE", `/discounts/${id}`);
379
+ }
380
+ };
381
+ var StoreResource = class {
382
+ constructor(client) {
383
+ this.client = client;
384
+ }
385
+ async get() {
386
+ return this.client.request("GET", "/store");
387
+ }
388
+ };
389
+ var InventoryResource = class {
390
+ constructor(client) {
391
+ this.client = client;
392
+ }
393
+ async get(productId) {
394
+ return this.client.request("GET", `/products/${productId}/inventory`);
395
+ }
396
+ async adjust(productId, data) {
397
+ return this.client.request("PATCH", `/products/${productId}/inventory`, {
398
+ body: data
399
+ });
400
+ }
401
+ };
402
+ var WebhookResource = class {
403
+ constructor(client) {
404
+ this.client = client;
405
+ }
406
+ async list() {
407
+ return this.client.request("GET", "/webhooks");
408
+ }
409
+ async create(data) {
410
+ return this.client.request("POST", "/webhooks", { body: data });
411
+ }
412
+ async update(id, data) {
413
+ return this.client.request("PATCH", `/webhooks/${id}`, { body: data });
414
+ }
415
+ async delete(id) {
416
+ return this.client.request("DELETE", `/webhooks/${id}`);
417
+ }
418
+ };
419
+ // Annotate the CommonJS export names for ESM import in node:
420
+ 0 && (module.exports = {
421
+ WhataloClient
422
+ });
423
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/whatalo-client.ts","../../src/client/errors.ts"],"sourcesContent":["import type {\n WhataloClientOptions,\n RateLimitInfo,\n PaginatedResponse,\n SingleResponse,\n Product,\n Order,\n Customer,\n Category,\n Discount,\n Store,\n InventoryItem,\n Webhook,\n ListProductsParams,\n CreateProductParams,\n UpdateProductParams,\n ListOrdersParams,\n ListCustomersParams,\n ListCategoriesParams,\n CreateCategoryParams,\n UpdateCategoryParams,\n ListDiscountsParams,\n CreateDiscountParams,\n UpdateDiscountParams,\n UpsertWebhookParams,\n UpdateWebhookParams,\n AdjustInventoryParams,\n} from \"./types.js\";\nimport {\n WhataloAPIError,\n AuthenticationError,\n AuthorizationError,\n InsufficientScopeError,\n RateLimitError,\n InternalError,\n NotFoundError,\n ValidationError,\n} from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.whatalo.com/v1\";\nconst DEFAULT_TIMEOUT = 30_000;\n\n/**\n * Official TypeScript client for the Whatalo REST API.\n * Zero runtime dependencies — uses native fetch.\n */\nexport class WhataloClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n private readonly maxRetries: number;\n private readonly fetchFn: typeof globalThis.fetch;\n private readonly onRequest?: (url: string, init: RequestInit) => void;\n private readonly onResponse?: (response: Response, durationMs: number) => void;\n\n /** Rate limit info from the most recent API response */\n rateLimit: RateLimitInfo = { limit: 0, remaining: 0, reset: 0 };\n\n /** Product resource methods */\n readonly products: ProductResource;\n /** Order resource methods */\n readonly orders: OrderResource;\n /** Customer resource methods */\n readonly customers: CustomerResource;\n /** Category resource methods */\n readonly categories: CategoryResource;\n /** Discount resource methods */\n readonly discounts: DiscountResource;\n /** Store resource methods */\n readonly store: StoreResource;\n /** Inventory resource methods */\n readonly inventory: InventoryResource;\n /** Webhook resource methods */\n readonly webhooks: WebhookResource;\n\n constructor(options: WhataloClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.maxRetries = Math.min(options.retries ?? 0, 3);\n this.fetchFn = options.fetch ?? globalThis.fetch;\n this.onRequest = options.onRequest;\n this.onResponse = options.onResponse;\n\n this.products = new ProductResource(this);\n this.orders = new OrderResource(this);\n this.customers = new CustomerResource(this);\n this.categories = new CategoryResource(this);\n this.discounts = new DiscountResource(this);\n this.store = new StoreResource(this);\n this.inventory = new InventoryResource(this);\n this.webhooks = new WebhookResource(this);\n }\n\n /**\n * Internal request method shared by all resource namespaces.\n * Handles headers, timeout, error parsing, and rate limit extraction.\n */\n async request<T>(\n method: string,\n path: string,\n options?: {\n body?: unknown;\n params?: Record<string, string | number | boolean | undefined>;\n }\n ): Promise<T> {\n let url = `${this.baseUrl}${path}`;\n\n // Add query params\n if (options?.params) {\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(options.params)) {\n if (value !== undefined) {\n searchParams.set(key, String(value));\n }\n }\n const qs = searchParams.toString();\n if (qs) url += `?${qs}`;\n }\n\n const headers: Record<string, string> = {\n \"X-API-Key\": this.apiKey,\n \"Content-Type\": \"application/json\",\n };\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n const requestInit: RequestInit = {\n method,\n headers,\n body: options?.body ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n };\n const startedAt = Date.now();\n this.onRequest?.(url, requestInit);\n\n try {\n const response = await this.fetchFn(url, requestInit);\n\n clearTimeout(timeoutId);\n this.onResponse?.(response, Date.now() - startedAt);\n\n // Extract rate limit headers\n this.rateLimit = {\n limit: Number(response.headers.get(\"X-RateLimit-Limit\") ?? 0),\n remaining: Number(\n response.headers.get(\"X-RateLimit-Remaining\") ?? 0\n ),\n reset: Number(response.headers.get(\"X-RateLimit-Reset\") ?? 0),\n };\n\n const requestId =\n response.headers.get(\"X-Request-Id\") ?? undefined;\n\n if (response.ok) {\n return (await response.json()) as T;\n }\n\n // Handle error responses\n const errorBody = await response.json().catch(() => ({\n error: { code: \"unknown\", message: response.statusText },\n }));\n const errData = (errorBody as { error?: { code?: string; message?: string; details?: Array<{ field: string; message: string }> } }).error;\n\n switch (response.status) {\n case 401:\n throw new AuthenticationError(errData?.message, requestId);\n case 403:\n // Distinguish between a specific scope denial and a generic 403.\n // insufficient_scope means the merchant never granted this permission.\n if (errData?.code === \"insufficient_scope\") {\n const details = errorBody as {\n error?: { required?: string; granted?: string[] };\n };\n throw new InsufficientScopeError(\n errData.message ?? \"Insufficient scope\",\n details.error?.required ?? \"\",\n details.error?.granted ?? [],\n requestId\n );\n }\n throw new AuthorizationError(\n errData?.message ?? \"Forbidden\",\n errData?.code ?? \"unknown_scope\",\n requestId\n );\n case 404:\n throw new NotFoundError(\"Resource\", path, requestId);\n case 422:\n throw new ValidationError(\n errData?.details ?? [\n { field: \"unknown\", message: errData?.message ?? \"Validation failed\" },\n ],\n requestId\n );\n case 429: {\n const retryAfter = Number(\n response.headers.get(\"Retry-After\") ?? 60\n );\n throw new RateLimitError(retryAfter, requestId);\n }\n default:\n if (response.status >= 500 && attempt < this.maxRetries) {\n // Retry on 5xx\n lastError = new InternalError(errData?.message, requestId);\n await this.sleep(Math.pow(2, attempt) * 1000);\n continue;\n }\n throw new WhataloAPIError(\n errData?.message ?? \"API error\",\n response.status,\n errData?.code ?? \"unknown\",\n requestId\n );\n }\n } catch (err) {\n clearTimeout(timeoutId);\n if (err instanceof WhataloAPIError) throw err;\n if ((err as Error).name === \"AbortError\") {\n throw new WhataloAPIError(\n \"Request timed out\",\n 408,\n \"timeout\"\n );\n }\n throw err;\n }\n }\n\n throw lastError ?? new InternalError(\"Request failed after retries\");\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/** Products API namespace */\nclass ProductResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListProductsParams\n ): Promise<PaginatedResponse<Product>> {\n return this.client.request(\"GET\", \"/products\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Product>> {\n return this.client.request(\"GET\", `/products/${id}`);\n }\n\n async create(\n data: CreateProductParams\n ): Promise<SingleResponse<Product>> {\n return this.client.request(\"POST\", \"/products\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateProductParams\n ): Promise<SingleResponse<Product>> {\n return this.client.request(\"PATCH\", `/products/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/products/${id}`);\n }\n\n async count(\n status?: \"active\" | \"inactive\" | \"all\"\n ): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/products/count\", {\n params: status ? { status } : undefined,\n });\n }\n}\n\n/** Orders API namespace */\nclass OrderResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListOrdersParams\n ): Promise<PaginatedResponse<Order>> {\n return this.client.request(\"GET\", \"/orders\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Order>> {\n return this.client.request(\"GET\", `/orders/${id}`);\n }\n\n async updateStatus(\n id: string,\n data: { status: string }\n ): Promise<SingleResponse<Order>> {\n return this.client.request(\"PATCH\", `/orders/${id}`, { body: data });\n }\n\n async count(\n status?: string\n ): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/orders/count\", {\n params: status ? { status } : undefined,\n });\n }\n}\n\n/** Customers API namespace */\nclass CustomerResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(params?: ListCustomersParams): Promise<PaginatedResponse<Customer>> {\n return this.client.request(\"GET\", \"/customers\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Customer>> {\n return this.client.request(\"GET\", `/customers/${id}`);\n }\n}\n\n/** Categories API namespace */\nclass CategoryResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListCategoriesParams\n ): Promise<PaginatedResponse<Category>> {\n return this.client.request(\"GET\", \"/categories\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Category>> {\n return this.client.request(\"GET\", `/categories/${id}`);\n }\n\n async create(\n data: CreateCategoryParams\n ): Promise<SingleResponse<Category>> {\n return this.client.request(\"POST\", \"/categories\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateCategoryParams\n ): Promise<SingleResponse<Category>> {\n return this.client.request(\"PATCH\", `/categories/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/categories/${id}`);\n }\n\n async count(): Promise<SingleResponse<{ count: number }>> {\n return this.client.request(\"GET\", \"/categories/count\");\n }\n}\n\n/** Discounts API namespace */\nclass DiscountResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(\n params?: ListDiscountsParams\n ): Promise<PaginatedResponse<Discount>> {\n return this.client.request(\"GET\", \"/discounts\", {\n params: params as Record<string, string | number | boolean | undefined>,\n });\n }\n\n async get(id: string): Promise<SingleResponse<Discount>> {\n return this.client.request(\"GET\", `/discounts/${id}`);\n }\n\n async create(\n data: CreateDiscountParams\n ): Promise<SingleResponse<Discount>> {\n return this.client.request(\"POST\", \"/discounts\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateDiscountParams\n ): Promise<SingleResponse<Discount>> {\n return this.client.request(\"PATCH\", `/discounts/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/discounts/${id}`);\n }\n}\n\n/** Store API namespace */\nclass StoreResource {\n constructor(private readonly client: WhataloClient) {}\n\n async get(): Promise<SingleResponse<Store>> {\n return this.client.request(\"GET\", \"/store\");\n }\n}\n\n/** Inventory API namespace */\nclass InventoryResource {\n constructor(private readonly client: WhataloClient) {}\n\n async get(productId: string): Promise<SingleResponse<InventoryItem>> {\n return this.client.request(\"GET\", `/products/${productId}/inventory`);\n }\n\n async adjust(\n productId: string,\n data: AdjustInventoryParams\n ): Promise<SingleResponse<InventoryItem>> {\n return this.client.request(\"PATCH\", `/products/${productId}/inventory`, {\n body: data,\n });\n }\n}\n\n/** Webhooks API namespace */\nclass WebhookResource {\n constructor(private readonly client: WhataloClient) {}\n\n async list(): Promise<PaginatedResponse<Webhook>> {\n return this.client.request(\"GET\", \"/webhooks\");\n }\n\n async create(data: UpsertWebhookParams): Promise<SingleResponse<Webhook>> {\n return this.client.request(\"POST\", \"/webhooks\", { body: data });\n }\n\n async update(\n id: string,\n data: UpdateWebhookParams\n ): Promise<SingleResponse<Webhook>> {\n return this.client.request(\"PATCH\", `/webhooks/${id}`, { body: data });\n }\n\n async delete(id: string): Promise<SingleResponse<{ deleted: boolean }>> {\n return this.client.request(\"DELETE\", `/webhooks/${id}`);\n }\n}\n","/**\n * Base error for all SDK errors.\n * Contains the HTTP status code and a machine-readable error code.\n */\nexport class WhataloAPIError extends Error {\n readonly statusCode: number;\n readonly code: string;\n readonly requestId?: string;\n\n constructor(\n message: string,\n statusCode: number,\n code: string,\n requestId?: string\n ) {\n super(message);\n this.name = \"WhataloAPIError\";\n this.statusCode = statusCode;\n this.code = code;\n this.requestId = requestId;\n }\n}\n\n/** 401 — Invalid or missing API key */\nexport class AuthenticationError extends WhataloAPIError {\n constructor(\n message = \"Invalid or missing API key\",\n requestId?: string\n ) {\n super(message, 401, \"authentication_error\", requestId);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** 403 — API key lacks required permission scope */\nexport class AuthorizationError extends WhataloAPIError {\n readonly requiredScope: string;\n\n constructor(\n message: string,\n requiredScope: string,\n requestId?: string\n ) {\n super(message, 403, \"authorization_error\", requestId);\n this.name = \"AuthorizationError\";\n this.requiredScope = requiredScope;\n }\n}\n\n/**\n * 403 — Installation does not have the required permission scope.\n *\n * Thrown when the merchant has not granted a scope that the current\n * API call requires. This is distinct from AuthorizationError:\n * - AuthorizationError = generic 403 (could be any auth reason)\n * - InsufficientScopeError = specific scope missing from granted_scopes\n *\n * The `requiredScope` field tells the developer exactly which scope to add\n * to their plugin manifest so they can request merchant re-consent.\n *\n * Example:\n * try {\n * await client.customers.list()\n * } catch (err) {\n * if (err instanceof InsufficientScopeError) {\n * console.error(`Add \"${err.requiredScope}\" to your manifest.`)\n * }\n * }\n */\nexport class InsufficientScopeError extends WhataloAPIError {\n /** The exact scope string missing from the installation's granted_scopes */\n readonly requiredScope: string;\n /** The scopes currently granted to this installation */\n readonly grantedScopes: string[];\n\n constructor(\n message: string,\n requiredScope: string,\n grantedScopes: string[],\n requestId?: string\n ) {\n super(message, 403, \"insufficient_scope\", requestId);\n this.name = \"InsufficientScopeError\";\n this.requiredScope = requiredScope;\n this.grantedScopes = grantedScopes;\n }\n}\n\n/** 404 — Resource not found */\nexport class NotFoundError extends WhataloAPIError {\n readonly resourceType: string;\n readonly resourceId: string;\n\n constructor(\n resourceType: string,\n resourceId: string,\n requestId?: string\n ) {\n super(\n `${resourceType} '${resourceId}' not found`,\n 404,\n \"not_found\",\n requestId\n );\n this.name = \"NotFoundError\";\n this.resourceType = resourceType;\n this.resourceId = resourceId;\n }\n}\n\n/** 422 — Request body validation failed */\nexport class ValidationError extends WhataloAPIError {\n readonly fieldErrors: Array<{ field: string; message: string }>;\n\n constructor(\n fieldErrors: Array<{ field: string; message: string }>,\n requestId?: string\n ) {\n const message = `Validation failed: ${fieldErrors\n .map((e) => `${e.field} — ${e.message}`)\n .join(\", \")}`;\n super(message, 422, \"validation_error\", requestId);\n this.name = \"ValidationError\";\n this.fieldErrors = fieldErrors;\n }\n}\n\n/** 429 — Rate limit exceeded */\nexport class RateLimitError extends WhataloAPIError {\n /** Seconds until the rate limit resets */\n readonly retryAfter: number;\n\n constructor(retryAfter: number, requestId?: string) {\n super(\n `Rate limit exceeded. Retry after ${retryAfter} seconds.`,\n 429,\n \"rate_limit_exceeded\",\n requestId\n );\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/** 500 — Server-side error */\nexport class InternalError extends WhataloAPIError {\n constructor(\n message = \"An internal error occurred\",\n requestId?: string\n ) {\n super(message, 500, \"internal_error\", requestId);\n this.name = \"InternalError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,YACA,MACA,WACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,OAAO;AACZ,SAAK,YAAY;AAAA,EACnB;AACF;AAGO,IAAM,sBAAN,cAAkC,gBAAgB;AAAA,EACvD,YACE,UAAU,8BACV,WACA;AACA,U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E,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACF;AAGA,IAAM,kBAAN,MAAsB;AAAA,EACpB,YAA6B,QAAuB;AAAvB;AAAA,EAAwB;AAAA,EAErD,MAAM,OAA4C;AAChD,WAAO,KAAK,OAAO,QAAQ,OAAO,WAAW;AAAA,EAC/C;AAAA,EAEA,MAAM,OAAO,MAA6D;AACxE,WAAO,KAAK,OAAO,QAAQ,QAAQ,aAAa,EAAE,MAAM,KAAK,CAAC;AAAA,EAChE;AAAA,EAEA,MAAM,OACJ,IACA,MACkC;AAClC,WAAO,KAAK,OAAO,QAAQ,SAAS,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAAA,EACvE;AAAA,EAEA,MAAM,OAAO,IAA2D;AACtE,WAAO,KAAK,OAAO,QAAQ,UAAU,aAAa,EAAE,EAAE;AAAA,EACxD;AACF;","names":[]}
@@ -0,0 +1,131 @@
1
+ import { R as RateLimitInfo, L as ListProductsParams, P as PaginatedResponse, a as Product, S as SingleResponse, C as CreateProductParams, U as UpdateProductParams, b as ListOrdersParams, O as Order, c as ListCustomersParams, d as Customer, e as ListCategoriesParams, f as Category, g as CreateCategoryParams, h as UpdateCategoryParams, i as ListDiscountsParams, D as Discount, j as CreateDiscountParams, k as UpdateDiscountParams, l as Store, I as InventoryItem, A as AdjustInventoryParams, W as Webhook, m as UpsertWebhookParams, n as UpdateWebhookParams, o as WhataloClientOptions } from '../types-M1eLMz6w.cjs';
2
+
3
+ /**
4
+ * Official TypeScript client for the Whatalo REST API.
5
+ * Zero runtime dependencies — uses native fetch.
6
+ */
7
+ declare class WhataloClient {
8
+ private readonly apiKey;
9
+ private readonly baseUrl;
10
+ private readonly timeout;
11
+ private readonly maxRetries;
12
+ private readonly fetchFn;
13
+ private readonly onRequest?;
14
+ private readonly onResponse?;
15
+ /** Rate limit info from the most recent API response */
16
+ rateLimit: RateLimitInfo;
17
+ /** Product resource methods */
18
+ readonly products: ProductResource;
19
+ /** Order resource methods */
20
+ readonly orders: OrderResource;
21
+ /** Customer resource methods */
22
+ readonly customers: CustomerResource;
23
+ /** Category resource methods */
24
+ readonly categories: CategoryResource;
25
+ /** Discount resource methods */
26
+ readonly discounts: DiscountResource;
27
+ /** Store resource methods */
28
+ readonly store: StoreResource;
29
+ /** Inventory resource methods */
30
+ readonly inventory: InventoryResource;
31
+ /** Webhook resource methods */
32
+ readonly webhooks: WebhookResource;
33
+ constructor(options: WhataloClientOptions);
34
+ /**
35
+ * Internal request method shared by all resource namespaces.
36
+ * Handles headers, timeout, error parsing, and rate limit extraction.
37
+ */
38
+ request<T>(method: string, path: string, options?: {
39
+ body?: unknown;
40
+ params?: Record<string, string | number | boolean | undefined>;
41
+ }): Promise<T>;
42
+ private sleep;
43
+ }
44
+ /** Products API namespace */
45
+ declare class ProductResource {
46
+ private readonly client;
47
+ constructor(client: WhataloClient);
48
+ list(params?: ListProductsParams): Promise<PaginatedResponse<Product>>;
49
+ get(id: string): Promise<SingleResponse<Product>>;
50
+ create(data: CreateProductParams): Promise<SingleResponse<Product>>;
51
+ update(id: string, data: UpdateProductParams): Promise<SingleResponse<Product>>;
52
+ delete(id: string): Promise<SingleResponse<{
53
+ deleted: boolean;
54
+ }>>;
55
+ count(status?: "active" | "inactive" | "all"): Promise<SingleResponse<{
56
+ count: number;
57
+ }>>;
58
+ }
59
+ /** Orders API namespace */
60
+ declare class OrderResource {
61
+ private readonly client;
62
+ constructor(client: WhataloClient);
63
+ list(params?: ListOrdersParams): Promise<PaginatedResponse<Order>>;
64
+ get(id: string): Promise<SingleResponse<Order>>;
65
+ updateStatus(id: string, data: {
66
+ status: string;
67
+ }): Promise<SingleResponse<Order>>;
68
+ count(status?: string): Promise<SingleResponse<{
69
+ count: number;
70
+ }>>;
71
+ }
72
+ /** Customers API namespace */
73
+ declare class CustomerResource {
74
+ private readonly client;
75
+ constructor(client: WhataloClient);
76
+ list(params?: ListCustomersParams): Promise<PaginatedResponse<Customer>>;
77
+ get(id: string): Promise<SingleResponse<Customer>>;
78
+ }
79
+ /** Categories API namespace */
80
+ declare class CategoryResource {
81
+ private readonly client;
82
+ constructor(client: WhataloClient);
83
+ list(params?: ListCategoriesParams): Promise<PaginatedResponse<Category>>;
84
+ get(id: string): Promise<SingleResponse<Category>>;
85
+ create(data: CreateCategoryParams): Promise<SingleResponse<Category>>;
86
+ update(id: string, data: UpdateCategoryParams): Promise<SingleResponse<Category>>;
87
+ delete(id: string): Promise<SingleResponse<{
88
+ deleted: boolean;
89
+ }>>;
90
+ count(): Promise<SingleResponse<{
91
+ count: number;
92
+ }>>;
93
+ }
94
+ /** Discounts API namespace */
95
+ declare class DiscountResource {
96
+ private readonly client;
97
+ constructor(client: WhataloClient);
98
+ list(params?: ListDiscountsParams): Promise<PaginatedResponse<Discount>>;
99
+ get(id: string): Promise<SingleResponse<Discount>>;
100
+ create(data: CreateDiscountParams): Promise<SingleResponse<Discount>>;
101
+ update(id: string, data: UpdateDiscountParams): Promise<SingleResponse<Discount>>;
102
+ delete(id: string): Promise<SingleResponse<{
103
+ deleted: boolean;
104
+ }>>;
105
+ }
106
+ /** Store API namespace */
107
+ declare class StoreResource {
108
+ private readonly client;
109
+ constructor(client: WhataloClient);
110
+ get(): Promise<SingleResponse<Store>>;
111
+ }
112
+ /** Inventory API namespace */
113
+ declare class InventoryResource {
114
+ private readonly client;
115
+ constructor(client: WhataloClient);
116
+ get(productId: string): Promise<SingleResponse<InventoryItem>>;
117
+ adjust(productId: string, data: AdjustInventoryParams): Promise<SingleResponse<InventoryItem>>;
118
+ }
119
+ /** Webhooks API namespace */
120
+ declare class WebhookResource {
121
+ private readonly client;
122
+ constructor(client: WhataloClient);
123
+ list(): Promise<PaginatedResponse<Webhook>>;
124
+ create(data: UpsertWebhookParams): Promise<SingleResponse<Webhook>>;
125
+ update(id: string, data: UpdateWebhookParams): Promise<SingleResponse<Webhook>>;
126
+ delete(id: string): Promise<SingleResponse<{
127
+ deleted: boolean;
128
+ }>>;
129
+ }
130
+
131
+ export { WhataloClient };