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