@betterstore/sdk 0.3.106 → 0.5.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/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +357 -438
- package/dist/index.mjs +357 -439
- package/package.json +14 -22
- package/.prettierignore +0 -3
- package/.prettierrc +0 -8
- package/.vscode/settings.json +0 -33
- package/CHANGELOG.md +0 -747
- package/CONTRIBUTING.md +0 -52
- package/LICENSE +0 -21
- package/README.md +0 -34
package/dist/index.js
CHANGED
|
@@ -26,26 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __async = (__this, __arguments, generator) => {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
var fulfilled = (value) => {
|
|
32
|
-
try {
|
|
33
|
-
step(generator.next(value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var rejected = (value) => {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.throw(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
29
|
|
|
50
30
|
// src/index.ts
|
|
51
31
|
var index_exports = {};
|
|
@@ -61,7 +41,7 @@ var import_axios = __toESM(require("axios"));
|
|
|
61
41
|
var API_BASE_URL = "https://api.betterstore.io/v1";
|
|
62
42
|
var createApiClient = (apiKey, proxy) => {
|
|
63
43
|
const client = import_axios.default.create({
|
|
64
|
-
baseURL: proxy
|
|
44
|
+
baseURL: proxy ?? API_BASE_URL,
|
|
65
45
|
headers: {
|
|
66
46
|
"Content-Type": "application/json",
|
|
67
47
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -73,7 +53,6 @@ var createApiClient = (apiKey, proxy) => {
|
|
|
73
53
|
client.interceptors.response.use(
|
|
74
54
|
(response) => response.data,
|
|
75
55
|
(error) => {
|
|
76
|
-
var _a, _b;
|
|
77
56
|
const apiError = {
|
|
78
57
|
isError: true,
|
|
79
58
|
status: 500,
|
|
@@ -81,8 +60,8 @@ var createApiClient = (apiKey, proxy) => {
|
|
|
81
60
|
};
|
|
82
61
|
if (error.response) {
|
|
83
62
|
apiError.status = error.response.status;
|
|
84
|
-
apiError.message =
|
|
85
|
-
apiError.code =
|
|
63
|
+
apiError.message = error.response.data?.error || "Server error occurred";
|
|
64
|
+
apiError.code = error.response.data?.code;
|
|
86
65
|
apiError.details = error.response.data;
|
|
87
66
|
} else if (error.request) {
|
|
88
67
|
apiError.status = 503;
|
|
@@ -107,523 +86,469 @@ var createApiClient = (apiKey, proxy) => {
|
|
|
107
86
|
|
|
108
87
|
// src/auth/providers/otp.ts
|
|
109
88
|
var OTP = class {
|
|
89
|
+
apiClient;
|
|
110
90
|
constructor(apiClient) {
|
|
111
91
|
this.apiClient = apiClient;
|
|
112
92
|
}
|
|
113
|
-
signup(params) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
const data = yield this.apiClient.post(
|
|
134
|
-
"/auth/otp/verify",
|
|
135
|
-
params
|
|
136
|
-
);
|
|
137
|
-
return data;
|
|
138
|
-
});
|
|
93
|
+
async signup(params) {
|
|
94
|
+
const data = await this.apiClient.post(
|
|
95
|
+
"/auth/otp/signup",
|
|
96
|
+
params
|
|
97
|
+
);
|
|
98
|
+
return data;
|
|
99
|
+
}
|
|
100
|
+
async login(params) {
|
|
101
|
+
const data = await this.apiClient.post(
|
|
102
|
+
"/auth/otp/login",
|
|
103
|
+
params
|
|
104
|
+
);
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
async verify(params) {
|
|
108
|
+
const data = await this.apiClient.post(
|
|
109
|
+
"/auth/otp/verify",
|
|
110
|
+
params
|
|
111
|
+
);
|
|
112
|
+
return data;
|
|
139
113
|
}
|
|
140
114
|
};
|
|
141
115
|
|
|
142
116
|
// src/auth/index.ts
|
|
143
117
|
var Auth = class {
|
|
118
|
+
apiClient;
|
|
119
|
+
otp;
|
|
144
120
|
constructor(apiKey, proxy) {
|
|
145
121
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
146
122
|
this.otp = new OTP(this.apiClient);
|
|
147
123
|
}
|
|
148
|
-
retrieveSession(id) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return data;
|
|
158
|
-
});
|
|
124
|
+
async retrieveSession(id) {
|
|
125
|
+
const data = await this.apiClient.get(
|
|
126
|
+
`/auth/session/${id}`
|
|
127
|
+
);
|
|
128
|
+
if ("isError" in data && data.isError || !data || !("token" in data)) {
|
|
129
|
+
console.error(`Customer session with id ${id} not found`);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return data;
|
|
159
133
|
}
|
|
160
134
|
};
|
|
161
135
|
var auth_default = Auth;
|
|
162
136
|
|
|
163
137
|
// src/checkout/index.ts
|
|
164
138
|
var Checkout = class {
|
|
139
|
+
apiClient;
|
|
165
140
|
constructor(apiKey, proxy) {
|
|
166
141
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
167
142
|
}
|
|
168
143
|
/**
|
|
169
144
|
* Create a new checkout session
|
|
170
145
|
*/
|
|
171
|
-
create(params) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return data;
|
|
181
|
-
});
|
|
146
|
+
async create(params) {
|
|
147
|
+
const data = await this.apiClient.post(
|
|
148
|
+
"/checkout",
|
|
149
|
+
params
|
|
150
|
+
);
|
|
151
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
152
|
+
throw new Error("Failed to create checkout session");
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
182
155
|
}
|
|
183
156
|
/**
|
|
184
157
|
* Retrieve a checkout session by ID
|
|
185
158
|
*/
|
|
186
|
-
retrieve(checkoutId) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return data;
|
|
196
|
-
});
|
|
159
|
+
async retrieve(checkoutId) {
|
|
160
|
+
const data = await this.apiClient.get(
|
|
161
|
+
`/checkout/${checkoutId}`
|
|
162
|
+
);
|
|
163
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
164
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return data;
|
|
197
168
|
}
|
|
198
169
|
/**
|
|
199
170
|
* Update a checkout session
|
|
200
171
|
*/
|
|
201
|
-
update(checkoutId, params) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return data;
|
|
212
|
-
});
|
|
172
|
+
async update(checkoutId, params) {
|
|
173
|
+
const data = await this.apiClient.put(
|
|
174
|
+
`/checkout/${checkoutId}`,
|
|
175
|
+
params
|
|
176
|
+
);
|
|
177
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
178
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return data;
|
|
213
182
|
}
|
|
214
183
|
/**
|
|
215
184
|
* Apply a discount code to a checkout session
|
|
216
185
|
*/
|
|
217
|
-
applyDiscountCode(checkoutId, discountCode) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return data;
|
|
227
|
-
});
|
|
186
|
+
async applyDiscountCode(checkoutId, discountCode) {
|
|
187
|
+
const data = await this.apiClient.post(
|
|
188
|
+
`/checkout/${checkoutId}/discounts/apply`,
|
|
189
|
+
{ code: discountCode }
|
|
190
|
+
);
|
|
191
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
192
|
+
throw new Error("Failed to apply discount code");
|
|
193
|
+
}
|
|
194
|
+
return data;
|
|
228
195
|
}
|
|
229
196
|
/**
|
|
230
197
|
* Remove a discount from a checkout session
|
|
231
198
|
*/
|
|
232
|
-
removeDiscount(checkoutId, discountId) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return data;
|
|
242
|
-
});
|
|
199
|
+
async removeDiscount(checkoutId, discountId) {
|
|
200
|
+
const data = await this.apiClient.delete(
|
|
201
|
+
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
202
|
+
);
|
|
203
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
204
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
return data;
|
|
243
208
|
}
|
|
244
209
|
/**
|
|
245
210
|
* Revalidate a checkout session
|
|
246
211
|
*/
|
|
247
|
-
revalidateDiscounts(checkoutId) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return data;
|
|
257
|
-
});
|
|
212
|
+
async revalidateDiscounts(checkoutId) {
|
|
213
|
+
const data = await this.apiClient.get(
|
|
214
|
+
`/checkout/${checkoutId}/discounts/revalidate`
|
|
215
|
+
);
|
|
216
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
217
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
return data;
|
|
258
221
|
}
|
|
259
222
|
/**
|
|
260
223
|
* Get shipping rates for a checkout session
|
|
261
224
|
*/
|
|
262
|
-
getShippingRates(checkoutId) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return data;
|
|
271
|
-
});
|
|
225
|
+
async getShippingRates(checkoutId) {
|
|
226
|
+
const data = await this.apiClient.get(
|
|
227
|
+
`/checkout/shipping/${checkoutId}`
|
|
228
|
+
);
|
|
229
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
return data;
|
|
272
233
|
}
|
|
273
234
|
/**
|
|
274
235
|
* Generate payment secret for a checkout session
|
|
275
236
|
*/
|
|
276
|
-
generatePaymentSecret(checkoutId) {
|
|
277
|
-
|
|
278
|
-
const data = yield this.apiClient.post(`
|
|
237
|
+
async generatePaymentSecret(checkoutId) {
|
|
238
|
+
const data = await this.apiClient.post(`
|
|
279
239
|
/checkout/payment/${checkoutId}`);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
});
|
|
240
|
+
if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
|
|
241
|
+
throw new Error("Failed to generate payment secret");
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
paymentSecret: data.paymentSecret,
|
|
245
|
+
publicKey: data.publicKey,
|
|
246
|
+
checkoutSession: data.checkoutSession
|
|
247
|
+
};
|
|
289
248
|
}
|
|
290
249
|
};
|
|
291
250
|
var checkout_default = Checkout;
|
|
292
251
|
|
|
293
252
|
// src/client/index.ts
|
|
294
253
|
var Client = class {
|
|
254
|
+
proxy;
|
|
295
255
|
constructor(proxy) {
|
|
296
256
|
this.proxy = proxy;
|
|
297
257
|
}
|
|
298
258
|
/**
|
|
299
259
|
* Retrieve a checkout session by ID
|
|
300
260
|
*/
|
|
301
|
-
retrieveCheckout(clientSecret, checkoutId) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return data;
|
|
312
|
-
});
|
|
261
|
+
async retrieveCheckout(clientSecret, checkoutId) {
|
|
262
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
263
|
+
const data = await apiClient.get(
|
|
264
|
+
`/checkout/${checkoutId}`
|
|
265
|
+
);
|
|
266
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
267
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
return data;
|
|
313
271
|
}
|
|
314
272
|
/**
|
|
315
273
|
* Update a checkout session
|
|
316
274
|
*/
|
|
317
|
-
updateCheckout(clientSecret, checkoutId, params) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return data;
|
|
329
|
-
});
|
|
275
|
+
async updateCheckout(clientSecret, checkoutId, params) {
|
|
276
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
277
|
+
const data = await apiClient.put(
|
|
278
|
+
`/checkout/${checkoutId}`,
|
|
279
|
+
params
|
|
280
|
+
);
|
|
281
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
282
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
return data;
|
|
330
286
|
}
|
|
331
287
|
/**
|
|
332
288
|
* Apply a discount code to a checkout session
|
|
333
289
|
*/
|
|
334
|
-
applyDiscountCode(clientSecret, checkoutId, discountCode) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return data;
|
|
345
|
-
});
|
|
290
|
+
async applyDiscountCode(clientSecret, checkoutId, discountCode) {
|
|
291
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
292
|
+
const data = await apiClient.post(
|
|
293
|
+
`/checkout/${checkoutId}/discounts/apply`,
|
|
294
|
+
{ code: discountCode }
|
|
295
|
+
);
|
|
296
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
297
|
+
throw new Error("Failed to apply discount code");
|
|
298
|
+
}
|
|
299
|
+
return data;
|
|
346
300
|
}
|
|
347
301
|
/**
|
|
348
302
|
* Remove a discount code from a checkout session
|
|
349
303
|
*/
|
|
350
|
-
removeDiscount(clientSecret, checkoutId, discountId) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return data;
|
|
360
|
-
});
|
|
304
|
+
async removeDiscount(clientSecret, checkoutId, discountId) {
|
|
305
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
306
|
+
const data = await apiClient.delete(
|
|
307
|
+
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
308
|
+
);
|
|
309
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
310
|
+
throw new Error("Failed to remove discount code");
|
|
311
|
+
}
|
|
312
|
+
return data;
|
|
361
313
|
}
|
|
362
314
|
/**
|
|
363
315
|
* Revalidate a checkout session
|
|
364
316
|
*/
|
|
365
|
-
revalidateDiscounts(clientSecret, checkoutId) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return data;
|
|
376
|
-
});
|
|
317
|
+
async revalidateDiscounts(clientSecret, checkoutId) {
|
|
318
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
319
|
+
const data = await apiClient.get(
|
|
320
|
+
`/checkout/${checkoutId}/discounts/revalidate`
|
|
321
|
+
);
|
|
322
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
323
|
+
console.error(`Checkout session with id ${checkoutId} not found`);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
return data;
|
|
377
327
|
}
|
|
378
328
|
/**
|
|
379
329
|
* Get shipping rates for a checkout session
|
|
380
330
|
*/
|
|
381
|
-
getCheckoutShippingRates(clientSecret, checkoutId) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return data;
|
|
391
|
-
});
|
|
331
|
+
async getCheckoutShippingRates(clientSecret, checkoutId) {
|
|
332
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
333
|
+
const data = await apiClient.get(
|
|
334
|
+
`/checkout/shipping/${checkoutId}`
|
|
335
|
+
);
|
|
336
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
return data;
|
|
392
340
|
}
|
|
393
341
|
/**
|
|
394
342
|
* Generate payment secret for a checkout session
|
|
395
343
|
*/
|
|
396
|
-
generateCheckoutPaymentSecret(clientSecret, checkoutId) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
};
|
|
408
|
-
});
|
|
344
|
+
async generateCheckoutPaymentSecret(clientSecret, checkoutId) {
|
|
345
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
346
|
+
const data = await apiClient.post(`/checkout/payment/${checkoutId}`);
|
|
347
|
+
if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
|
|
348
|
+
throw new Error("Failed to generate payment secret");
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
paymentSecret: data.paymentSecret,
|
|
352
|
+
publicKey: data.publicKey,
|
|
353
|
+
checkoutSession: data.checkoutSession
|
|
354
|
+
};
|
|
409
355
|
}
|
|
410
356
|
/**
|
|
411
357
|
* Create a new customer
|
|
412
358
|
*/
|
|
413
|
-
createCustomer(clientSecret, params) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return data;
|
|
424
|
-
});
|
|
359
|
+
async createCustomer(clientSecret, params) {
|
|
360
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
361
|
+
const data = await apiClient.post(
|
|
362
|
+
"/customer",
|
|
363
|
+
params
|
|
364
|
+
);
|
|
365
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
366
|
+
throw new Error("Failed to create customer");
|
|
367
|
+
}
|
|
368
|
+
return data;
|
|
425
369
|
}
|
|
426
370
|
/**
|
|
427
371
|
* Retrieve a customer by ID or email
|
|
428
372
|
*/
|
|
429
|
-
retrieveCustomer(clientSecret, idOrEmail) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return data;
|
|
440
|
-
});
|
|
373
|
+
async retrieveCustomer(clientSecret, idOrEmail) {
|
|
374
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
375
|
+
const data = await apiClient.get(
|
|
376
|
+
`/customer/${idOrEmail}`
|
|
377
|
+
);
|
|
378
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
379
|
+
console.error(`Customer with id or email ${idOrEmail} not found`);
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
return data;
|
|
441
383
|
}
|
|
442
384
|
/**
|
|
443
385
|
* Update a customer
|
|
444
386
|
*/
|
|
445
|
-
updateCustomer(clientSecret, customerId, params) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
return data;
|
|
457
|
-
});
|
|
387
|
+
async updateCustomer(clientSecret, customerId, params) {
|
|
388
|
+
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
389
|
+
const data = await apiClient.put(
|
|
390
|
+
`/customer/${customerId}`,
|
|
391
|
+
params
|
|
392
|
+
);
|
|
393
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
394
|
+
console.error(`Customer with id ${customerId} not found`);
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
return data;
|
|
458
398
|
}
|
|
459
399
|
};
|
|
460
400
|
var client_default = Client;
|
|
461
401
|
|
|
462
402
|
// src/collections/index.ts
|
|
463
403
|
var Collections = class {
|
|
404
|
+
apiClient;
|
|
464
405
|
constructor(apiKey, proxy) {
|
|
465
406
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
466
407
|
}
|
|
467
|
-
list(params) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
return data;
|
|
480
|
-
});
|
|
408
|
+
async list(params) {
|
|
409
|
+
const queryParams = new URLSearchParams();
|
|
410
|
+
if (params) {
|
|
411
|
+
queryParams.set("params", JSON.stringify(params));
|
|
412
|
+
}
|
|
413
|
+
const data = await this.apiClient.get(
|
|
414
|
+
`/collections?${queryParams.toString()}`
|
|
415
|
+
);
|
|
416
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
return data;
|
|
481
420
|
}
|
|
482
|
-
retrieve(params) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
`/collections/${params.seoHandle}`
|
|
487
|
-
);
|
|
488
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
489
|
-
console.error(
|
|
490
|
-
`Collection with seoHandle ${params.seoHandle} not found`
|
|
491
|
-
);
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
return data2;
|
|
495
|
-
}
|
|
496
|
-
const data = yield this.apiClient.get(
|
|
497
|
-
`/collections/id/${params.id}`
|
|
421
|
+
async retrieve(params) {
|
|
422
|
+
if ("seoHandle" in params) {
|
|
423
|
+
const data2 = await this.apiClient.get(
|
|
424
|
+
`/collections/${params.seoHandle}`
|
|
498
425
|
);
|
|
499
|
-
if ("isError" in
|
|
500
|
-
console.error(
|
|
426
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
427
|
+
console.error(
|
|
428
|
+
`Collection with seoHandle ${params.seoHandle} not found`
|
|
429
|
+
);
|
|
501
430
|
return null;
|
|
502
431
|
}
|
|
503
|
-
return
|
|
504
|
-
}
|
|
432
|
+
return data2;
|
|
433
|
+
}
|
|
434
|
+
const data = await this.apiClient.get(
|
|
435
|
+
`/collections/id/${params.id}`
|
|
436
|
+
);
|
|
437
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
438
|
+
console.error(`Collection with id ${params.id} not found`);
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
return data;
|
|
505
442
|
}
|
|
506
443
|
};
|
|
507
444
|
var collections_default = Collections;
|
|
508
445
|
|
|
509
446
|
// src/customer/index.ts
|
|
510
447
|
var Customer = class {
|
|
448
|
+
apiClient;
|
|
511
449
|
constructor(apiKey, proxy) {
|
|
512
450
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
513
451
|
}
|
|
514
452
|
/**
|
|
515
453
|
* Create a new customer
|
|
516
454
|
*/
|
|
517
|
-
create(params) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
return data;
|
|
527
|
-
});
|
|
455
|
+
async create(params) {
|
|
456
|
+
const data = await this.apiClient.post(
|
|
457
|
+
"/customer",
|
|
458
|
+
params
|
|
459
|
+
);
|
|
460
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
461
|
+
throw new Error("Failed to create customer");
|
|
462
|
+
}
|
|
463
|
+
return data;
|
|
528
464
|
}
|
|
529
465
|
/**
|
|
530
466
|
* Retrieve a customer by ID or email
|
|
531
467
|
*/
|
|
532
|
-
retrieve(idOrEmail) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
return data;
|
|
542
|
-
});
|
|
468
|
+
async retrieve(idOrEmail) {
|
|
469
|
+
const data = await this.apiClient.get(
|
|
470
|
+
`/customer/${idOrEmail}`
|
|
471
|
+
);
|
|
472
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
473
|
+
console.error(`Customer with id or email ${idOrEmail} not found`);
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
return data;
|
|
543
477
|
}
|
|
544
478
|
/**
|
|
545
479
|
* Update a customer
|
|
546
480
|
*/
|
|
547
|
-
update(customerId, params) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
return data;
|
|
558
|
-
});
|
|
481
|
+
async update(customerId, params) {
|
|
482
|
+
const data = await this.apiClient.put(
|
|
483
|
+
`/customer/${customerId}`,
|
|
484
|
+
params
|
|
485
|
+
);
|
|
486
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
487
|
+
console.error(`Customer with id ${customerId} not found`);
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
return data;
|
|
559
491
|
}
|
|
560
492
|
/**
|
|
561
493
|
* Delete a customer
|
|
562
494
|
*/
|
|
563
|
-
delete(customerId) {
|
|
564
|
-
|
|
565
|
-
yield this.apiClient.delete(`/customer/${customerId}`);
|
|
566
|
-
});
|
|
495
|
+
async delete(customerId) {
|
|
496
|
+
await this.apiClient.delete(`/customer/${customerId}`);
|
|
567
497
|
}
|
|
568
498
|
/**
|
|
569
499
|
* Update a customer subscription
|
|
570
500
|
*/
|
|
571
|
-
updateCustomerSubscription(stripeSubscriptionId, params) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
return data;
|
|
581
|
-
});
|
|
501
|
+
async updateCustomerSubscription(stripeSubscriptionId, params) {
|
|
502
|
+
const data = await this.apiClient.put(
|
|
503
|
+
`/customer/subscription/${stripeSubscriptionId}`,
|
|
504
|
+
params
|
|
505
|
+
);
|
|
506
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
return data;
|
|
582
510
|
}
|
|
583
511
|
};
|
|
584
512
|
var customer_default = Customer;
|
|
585
513
|
|
|
586
514
|
// src/discounts/index.ts
|
|
587
515
|
var Discounts = class {
|
|
516
|
+
apiClient;
|
|
588
517
|
constructor(apiKey, proxy) {
|
|
589
518
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
590
519
|
}
|
|
591
|
-
list(params) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return data;
|
|
604
|
-
});
|
|
520
|
+
async list(params) {
|
|
521
|
+
const queryParams = new URLSearchParams();
|
|
522
|
+
if (params) {
|
|
523
|
+
queryParams.set("params", JSON.stringify(params));
|
|
524
|
+
}
|
|
525
|
+
const data = await this.apiClient.get(
|
|
526
|
+
`/discounts?${queryParams.toString()}`
|
|
527
|
+
);
|
|
528
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
531
|
+
return data;
|
|
605
532
|
}
|
|
606
|
-
retrieve(params) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
`/discounts/code/${params.code}`
|
|
611
|
-
);
|
|
612
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
613
|
-
console.error(`Discount with code ${params.code} not found`);
|
|
614
|
-
return null;
|
|
615
|
-
}
|
|
616
|
-
return data2;
|
|
617
|
-
}
|
|
618
|
-
const data = yield this.apiClient.get(
|
|
619
|
-
`/discounts/id/${params.id}`
|
|
533
|
+
async retrieve(params) {
|
|
534
|
+
if ("code" in params) {
|
|
535
|
+
const data2 = await this.apiClient.get(
|
|
536
|
+
`/discounts/code/${params.code}`
|
|
620
537
|
);
|
|
621
|
-
if ("isError" in
|
|
622
|
-
console.error(`Discount with
|
|
538
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
539
|
+
console.error(`Discount with code ${params.code} not found`);
|
|
623
540
|
return null;
|
|
624
541
|
}
|
|
625
|
-
return
|
|
626
|
-
}
|
|
542
|
+
return data2;
|
|
543
|
+
}
|
|
544
|
+
const data = await this.apiClient.get(
|
|
545
|
+
`/discounts/id/${params.id}`
|
|
546
|
+
);
|
|
547
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
548
|
+
console.error(`Discount with id ${params.id} not found`);
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
return data;
|
|
627
552
|
}
|
|
628
553
|
};
|
|
629
554
|
var discounts_default = Discounts;
|
|
@@ -694,12 +619,12 @@ var currencyLocales = {
|
|
|
694
619
|
// Turkish Lira
|
|
695
620
|
};
|
|
696
621
|
var Helpers = class {
|
|
622
|
+
proxy;
|
|
697
623
|
constructor(proxy) {
|
|
698
624
|
this.proxy = proxy;
|
|
699
625
|
}
|
|
700
626
|
formatCurrency(currency) {
|
|
701
|
-
|
|
702
|
-
const locale = (_a = currencyLocales[currency.toUpperCase()]) != null ? _a : void 0;
|
|
627
|
+
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
703
628
|
const formattedCurrency = new Intl.NumberFormat(locale, {
|
|
704
629
|
style: "currency",
|
|
705
630
|
currency,
|
|
@@ -708,10 +633,9 @@ var Helpers = class {
|
|
|
708
633
|
return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
|
|
709
634
|
}
|
|
710
635
|
formatPrice(priceInCents, currency, exchangeRate) {
|
|
711
|
-
|
|
712
|
-
const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
|
|
636
|
+
const amount = priceInCents / 100 * (exchangeRate ?? 1);
|
|
713
637
|
const isWhole = amount % 1 === 0;
|
|
714
|
-
const locale =
|
|
638
|
+
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
715
639
|
const formattedPrice = new Intl.NumberFormat(locale, {
|
|
716
640
|
style: "currency",
|
|
717
641
|
currency,
|
|
@@ -721,64 +645,59 @@ var Helpers = class {
|
|
|
721
645
|
}).format(amount);
|
|
722
646
|
return formattedPrice;
|
|
723
647
|
}
|
|
724
|
-
getExchangeRate(baseCurrency, targetCurrency) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
return rate;
|
|
733
|
-
});
|
|
648
|
+
async getExchangeRate(baseCurrency, targetCurrency) {
|
|
649
|
+
const apiClient = createApiClient("", this.proxy);
|
|
650
|
+
const { data } = await apiClient.get(`/helpers/rates/${baseCurrency}`);
|
|
651
|
+
const rate = data.rates[targetCurrency];
|
|
652
|
+
if (!rate) {
|
|
653
|
+
throw new Error("Could not get exchange rate for target currency");
|
|
654
|
+
}
|
|
655
|
+
return rate;
|
|
734
656
|
}
|
|
735
657
|
};
|
|
736
658
|
var helpers_default = Helpers;
|
|
737
659
|
|
|
738
660
|
// src/products/index.ts
|
|
739
661
|
var Products = class {
|
|
662
|
+
apiClient;
|
|
740
663
|
constructor(apiKey, proxy) {
|
|
741
664
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
742
665
|
}
|
|
743
|
-
list(params) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
666
|
+
async list(params) {
|
|
667
|
+
const queryParams = new URLSearchParams();
|
|
668
|
+
if (params) {
|
|
669
|
+
queryParams.set("params", JSON.stringify(params));
|
|
670
|
+
}
|
|
671
|
+
const data = await this.apiClient.get(
|
|
672
|
+
`/products?${queryParams.toString()}`
|
|
673
|
+
);
|
|
674
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
675
|
+
return [];
|
|
676
|
+
}
|
|
677
|
+
return data;
|
|
678
|
+
}
|
|
679
|
+
async retrieve(params) {
|
|
680
|
+
if ("seoHandle" in params && typeof params?.seoHandle === "string") {
|
|
681
|
+
const data = await this.apiClient.get(
|
|
682
|
+
`/products/${params.seoHandle}`
|
|
751
683
|
);
|
|
752
|
-
if (
|
|
753
|
-
|
|
684
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
685
|
+
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
686
|
+
return null;
|
|
754
687
|
}
|
|
755
688
|
return data;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
765
|
-
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
766
|
-
return null;
|
|
767
|
-
}
|
|
768
|
-
return data;
|
|
769
|
-
}
|
|
770
|
-
if ("id" in params && typeof (params == null ? void 0 : params.id) === "string") {
|
|
771
|
-
const data = yield this.apiClient.get(
|
|
772
|
-
`/products/id/${params.id}`
|
|
773
|
-
);
|
|
774
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
775
|
-
console.error(`Product with id ${params.id} not found`);
|
|
776
|
-
return null;
|
|
777
|
-
}
|
|
778
|
-
return data;
|
|
689
|
+
}
|
|
690
|
+
if ("id" in params && typeof params?.id === "string") {
|
|
691
|
+
const data = await this.apiClient.get(
|
|
692
|
+
`/products/id/${params.id}`
|
|
693
|
+
);
|
|
694
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
695
|
+
console.error(`Product with id ${params.id} not found`);
|
|
696
|
+
return null;
|
|
779
697
|
}
|
|
780
|
-
return
|
|
781
|
-
}
|
|
698
|
+
return data;
|
|
699
|
+
}
|
|
700
|
+
return null;
|
|
782
701
|
}
|
|
783
702
|
};
|
|
784
703
|
var products_default = Products;
|
|
@@ -798,10 +717,10 @@ function createBetterStore(config) {
|
|
|
798
717
|
};
|
|
799
718
|
}
|
|
800
719
|
function createStoreClient(config) {
|
|
801
|
-
return new client_default(config
|
|
720
|
+
return new client_default(config?.proxy);
|
|
802
721
|
}
|
|
803
722
|
function createStoreHelpers(config) {
|
|
804
|
-
return new helpers_default(config
|
|
723
|
+
return new helpers_default(config?.proxy);
|
|
805
724
|
}
|
|
806
725
|
// Annotate the CommonJS export names for ESM import in node:
|
|
807
726
|
0 && (module.exports = {
|