@betterstore/sdk 0.1.1 → 0.2.1
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +195 -18
- package/dist/index.d.ts +195 -18
- package/dist/index.js +177 -57
- package/dist/index.mjs +167 -59
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,210 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
interface LineItem {
|
|
2
|
+
quantity: number;
|
|
3
|
+
productId?: string;
|
|
4
|
+
variantOptions: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
discountId?: string;
|
|
9
|
+
}
|
|
10
|
+
interface CheckoutCreateParams {
|
|
11
|
+
type: "hosted" | "embed";
|
|
12
|
+
customerId?: string;
|
|
13
|
+
lineItems: LineItem[];
|
|
14
|
+
}
|
|
15
|
+
interface CheckoutUpdateParams {
|
|
16
|
+
email?: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
lineItems?: LineItem[];
|
|
19
|
+
customerId?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ShippingRate {
|
|
22
|
+
id: string;
|
|
23
|
+
rate: number;
|
|
24
|
+
provider: string;
|
|
25
|
+
service: string;
|
|
26
|
+
estimatedDays: number;
|
|
27
|
+
}
|
|
28
|
+
interface Address {
|
|
29
|
+
name: string;
|
|
30
|
+
company?: string;
|
|
31
|
+
address: string;
|
|
32
|
+
city: string;
|
|
33
|
+
state: string;
|
|
34
|
+
country: string;
|
|
35
|
+
apartment?: string;
|
|
36
|
+
postalCode: string;
|
|
37
|
+
phone: string;
|
|
38
|
+
}
|
|
39
|
+
interface CheckoutSession {
|
|
40
|
+
id: string;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
updatedAt: Date;
|
|
43
|
+
email?: string;
|
|
44
|
+
phone?: string;
|
|
45
|
+
clientSecret: string;
|
|
46
|
+
lineItems: {
|
|
47
|
+
quantity: number;
|
|
48
|
+
discount?: any;
|
|
49
|
+
variantOptions: {
|
|
5
50
|
name: string;
|
|
6
51
|
value: string;
|
|
7
52
|
}[];
|
|
8
|
-
|
|
53
|
+
product?: {
|
|
54
|
+
id: string;
|
|
55
|
+
title: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
images: string[];
|
|
58
|
+
category: string;
|
|
59
|
+
tags: string[];
|
|
60
|
+
priceInCents: number;
|
|
61
|
+
};
|
|
9
62
|
}[];
|
|
10
|
-
|
|
63
|
+
total?: number;
|
|
64
|
+
subtotal?: number;
|
|
65
|
+
tax?: number;
|
|
66
|
+
shipping?: number;
|
|
67
|
+
currency: string;
|
|
68
|
+
status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
|
|
69
|
+
customer?: {
|
|
70
|
+
address?: Address;
|
|
71
|
+
email?: string;
|
|
72
|
+
};
|
|
11
73
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
74
|
+
declare class Checkout {
|
|
75
|
+
private apiClient;
|
|
76
|
+
constructor(apiKey: string);
|
|
77
|
+
/**
|
|
78
|
+
* Create a new checkout session
|
|
79
|
+
*/
|
|
80
|
+
create(params: CheckoutCreateParams): Promise<CheckoutSession>;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieve a checkout session by ID or client secret
|
|
83
|
+
*/
|
|
84
|
+
retrieve(idOrSecret: string): Promise<CheckoutSession>;
|
|
85
|
+
/**
|
|
86
|
+
* Update a checkout session
|
|
87
|
+
*/
|
|
88
|
+
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
89
|
+
/**
|
|
90
|
+
* Get shipping rates for a checkout session
|
|
91
|
+
*/
|
|
92
|
+
getShippingRates(checkoutId: string): Promise<ShippingRate[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate payment secret for a checkout session
|
|
95
|
+
*/
|
|
96
|
+
generatePaymentSecret(checkoutId: string): Promise<string>;
|
|
16
97
|
}
|
|
17
|
-
|
|
18
|
-
|
|
98
|
+
|
|
99
|
+
interface CustomerAddress {
|
|
100
|
+
name: string;
|
|
101
|
+
company?: string;
|
|
102
|
+
address: string;
|
|
103
|
+
city: string;
|
|
104
|
+
state: string;
|
|
105
|
+
country: string;
|
|
106
|
+
apartment?: string;
|
|
107
|
+
postalCode: string;
|
|
108
|
+
phone: string;
|
|
19
109
|
}
|
|
20
|
-
|
|
21
|
-
|
|
110
|
+
interface CustomerCreateParams {
|
|
111
|
+
firstName: string;
|
|
112
|
+
lastName: string;
|
|
113
|
+
email: string;
|
|
114
|
+
phone?: string;
|
|
115
|
+
address?: CustomerAddress;
|
|
116
|
+
isSubscribedEmail?: boolean;
|
|
117
|
+
isSubscribedSMS?: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface CustomerUpdateParams {
|
|
120
|
+
firstName?: string;
|
|
121
|
+
lastName?: string;
|
|
122
|
+
email?: string;
|
|
123
|
+
phone?: string;
|
|
124
|
+
address?: CustomerAddress;
|
|
125
|
+
isSubscribedEmail?: boolean;
|
|
126
|
+
isSubscribedSMS?: boolean;
|
|
127
|
+
}
|
|
128
|
+
interface Customer extends CustomerCreateParams {
|
|
129
|
+
id: string;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
updatedAt: string;
|
|
132
|
+
}
|
|
133
|
+
declare class Customer {
|
|
134
|
+
private apiClient;
|
|
135
|
+
constructor(apiKey: string);
|
|
136
|
+
/**
|
|
137
|
+
* Create a new customer
|
|
138
|
+
*/
|
|
139
|
+
create(params: CustomerCreateParams): Promise<Customer>;
|
|
140
|
+
/**
|
|
141
|
+
* Retrieve a customer by ID or email
|
|
142
|
+
*/
|
|
143
|
+
retrieve(idOrEmail: string): Promise<Customer>;
|
|
144
|
+
/**
|
|
145
|
+
* Update a customer
|
|
146
|
+
*/
|
|
147
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<Customer>;
|
|
148
|
+
/**
|
|
149
|
+
* Delete a customer
|
|
150
|
+
*/
|
|
151
|
+
delete(customerId: string): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface VariantOption {
|
|
155
|
+
name: string;
|
|
156
|
+
value: string;
|
|
157
|
+
}
|
|
158
|
+
interface ProductVariant {
|
|
159
|
+
sku: string;
|
|
160
|
+
images: string[];
|
|
161
|
+
stockAvailable: number;
|
|
162
|
+
stockCommited: number;
|
|
163
|
+
stockUnavailable: number;
|
|
164
|
+
priceInCents: number;
|
|
165
|
+
productId: string;
|
|
166
|
+
variantOptions: VariantOption[];
|
|
167
|
+
}
|
|
168
|
+
interface ProductOption {
|
|
169
|
+
name: string;
|
|
170
|
+
values: string[];
|
|
171
|
+
}
|
|
172
|
+
declare enum ProductStatus {
|
|
173
|
+
DRAFT = "DRAFT",
|
|
174
|
+
ACTIVE = "ACTIVE",
|
|
175
|
+
ARCHIVED = "ARCHIVED"
|
|
176
|
+
}
|
|
177
|
+
interface Product {
|
|
178
|
+
id: string;
|
|
179
|
+
title: string;
|
|
180
|
+
description?: string;
|
|
181
|
+
images: string[];
|
|
182
|
+
category: string;
|
|
183
|
+
tags: string[];
|
|
184
|
+
isPhysical: boolean;
|
|
185
|
+
weightInGrams?: number;
|
|
186
|
+
heightInCm?: number;
|
|
187
|
+
widthInCm?: number;
|
|
188
|
+
lengthInCm?: number;
|
|
189
|
+
priceInCents: number;
|
|
190
|
+
stockAvailable: number;
|
|
191
|
+
stockCommited: number;
|
|
192
|
+
stockUnavailable: number;
|
|
193
|
+
status: ProductStatus;
|
|
194
|
+
options: ProductOption[];
|
|
195
|
+
productVariants: ProductVariant[];
|
|
196
|
+
}
|
|
197
|
+
declare class Products {
|
|
198
|
+
private apiClient;
|
|
22
199
|
constructor(apiKey: string);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}>;
|
|
200
|
+
list(): Promise<Omit<Product, "productVariants">[]>;
|
|
201
|
+
retrieve(productId: string): Promise<Product>;
|
|
26
202
|
}
|
|
27
203
|
|
|
28
204
|
declare class BetterStore {
|
|
29
205
|
checkout: Checkout;
|
|
30
|
-
|
|
206
|
+
products: Products;
|
|
207
|
+
customer: Customer;
|
|
31
208
|
constructor(apiKey: string);
|
|
32
209
|
}
|
|
33
210
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,210 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
interface LineItem {
|
|
2
|
+
quantity: number;
|
|
3
|
+
productId?: string;
|
|
4
|
+
variantOptions: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
discountId?: string;
|
|
9
|
+
}
|
|
10
|
+
interface CheckoutCreateParams {
|
|
11
|
+
type: "hosted" | "embed";
|
|
12
|
+
customerId?: string;
|
|
13
|
+
lineItems: LineItem[];
|
|
14
|
+
}
|
|
15
|
+
interface CheckoutUpdateParams {
|
|
16
|
+
email?: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
lineItems?: LineItem[];
|
|
19
|
+
customerId?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ShippingRate {
|
|
22
|
+
id: string;
|
|
23
|
+
rate: number;
|
|
24
|
+
provider: string;
|
|
25
|
+
service: string;
|
|
26
|
+
estimatedDays: number;
|
|
27
|
+
}
|
|
28
|
+
interface Address {
|
|
29
|
+
name: string;
|
|
30
|
+
company?: string;
|
|
31
|
+
address: string;
|
|
32
|
+
city: string;
|
|
33
|
+
state: string;
|
|
34
|
+
country: string;
|
|
35
|
+
apartment?: string;
|
|
36
|
+
postalCode: string;
|
|
37
|
+
phone: string;
|
|
38
|
+
}
|
|
39
|
+
interface CheckoutSession {
|
|
40
|
+
id: string;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
updatedAt: Date;
|
|
43
|
+
email?: string;
|
|
44
|
+
phone?: string;
|
|
45
|
+
clientSecret: string;
|
|
46
|
+
lineItems: {
|
|
47
|
+
quantity: number;
|
|
48
|
+
discount?: any;
|
|
49
|
+
variantOptions: {
|
|
5
50
|
name: string;
|
|
6
51
|
value: string;
|
|
7
52
|
}[];
|
|
8
|
-
|
|
53
|
+
product?: {
|
|
54
|
+
id: string;
|
|
55
|
+
title: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
images: string[];
|
|
58
|
+
category: string;
|
|
59
|
+
tags: string[];
|
|
60
|
+
priceInCents: number;
|
|
61
|
+
};
|
|
9
62
|
}[];
|
|
10
|
-
|
|
63
|
+
total?: number;
|
|
64
|
+
subtotal?: number;
|
|
65
|
+
tax?: number;
|
|
66
|
+
shipping?: number;
|
|
67
|
+
currency: string;
|
|
68
|
+
status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
|
|
69
|
+
customer?: {
|
|
70
|
+
address?: Address;
|
|
71
|
+
email?: string;
|
|
72
|
+
};
|
|
11
73
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
74
|
+
declare class Checkout {
|
|
75
|
+
private apiClient;
|
|
76
|
+
constructor(apiKey: string);
|
|
77
|
+
/**
|
|
78
|
+
* Create a new checkout session
|
|
79
|
+
*/
|
|
80
|
+
create(params: CheckoutCreateParams): Promise<CheckoutSession>;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieve a checkout session by ID or client secret
|
|
83
|
+
*/
|
|
84
|
+
retrieve(idOrSecret: string): Promise<CheckoutSession>;
|
|
85
|
+
/**
|
|
86
|
+
* Update a checkout session
|
|
87
|
+
*/
|
|
88
|
+
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
89
|
+
/**
|
|
90
|
+
* Get shipping rates for a checkout session
|
|
91
|
+
*/
|
|
92
|
+
getShippingRates(checkoutId: string): Promise<ShippingRate[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate payment secret for a checkout session
|
|
95
|
+
*/
|
|
96
|
+
generatePaymentSecret(checkoutId: string): Promise<string>;
|
|
16
97
|
}
|
|
17
|
-
|
|
18
|
-
|
|
98
|
+
|
|
99
|
+
interface CustomerAddress {
|
|
100
|
+
name: string;
|
|
101
|
+
company?: string;
|
|
102
|
+
address: string;
|
|
103
|
+
city: string;
|
|
104
|
+
state: string;
|
|
105
|
+
country: string;
|
|
106
|
+
apartment?: string;
|
|
107
|
+
postalCode: string;
|
|
108
|
+
phone: string;
|
|
19
109
|
}
|
|
20
|
-
|
|
21
|
-
|
|
110
|
+
interface CustomerCreateParams {
|
|
111
|
+
firstName: string;
|
|
112
|
+
lastName: string;
|
|
113
|
+
email: string;
|
|
114
|
+
phone?: string;
|
|
115
|
+
address?: CustomerAddress;
|
|
116
|
+
isSubscribedEmail?: boolean;
|
|
117
|
+
isSubscribedSMS?: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface CustomerUpdateParams {
|
|
120
|
+
firstName?: string;
|
|
121
|
+
lastName?: string;
|
|
122
|
+
email?: string;
|
|
123
|
+
phone?: string;
|
|
124
|
+
address?: CustomerAddress;
|
|
125
|
+
isSubscribedEmail?: boolean;
|
|
126
|
+
isSubscribedSMS?: boolean;
|
|
127
|
+
}
|
|
128
|
+
interface Customer extends CustomerCreateParams {
|
|
129
|
+
id: string;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
updatedAt: string;
|
|
132
|
+
}
|
|
133
|
+
declare class Customer {
|
|
134
|
+
private apiClient;
|
|
135
|
+
constructor(apiKey: string);
|
|
136
|
+
/**
|
|
137
|
+
* Create a new customer
|
|
138
|
+
*/
|
|
139
|
+
create(params: CustomerCreateParams): Promise<Customer>;
|
|
140
|
+
/**
|
|
141
|
+
* Retrieve a customer by ID or email
|
|
142
|
+
*/
|
|
143
|
+
retrieve(idOrEmail: string): Promise<Customer>;
|
|
144
|
+
/**
|
|
145
|
+
* Update a customer
|
|
146
|
+
*/
|
|
147
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<Customer>;
|
|
148
|
+
/**
|
|
149
|
+
* Delete a customer
|
|
150
|
+
*/
|
|
151
|
+
delete(customerId: string): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface VariantOption {
|
|
155
|
+
name: string;
|
|
156
|
+
value: string;
|
|
157
|
+
}
|
|
158
|
+
interface ProductVariant {
|
|
159
|
+
sku: string;
|
|
160
|
+
images: string[];
|
|
161
|
+
stockAvailable: number;
|
|
162
|
+
stockCommited: number;
|
|
163
|
+
stockUnavailable: number;
|
|
164
|
+
priceInCents: number;
|
|
165
|
+
productId: string;
|
|
166
|
+
variantOptions: VariantOption[];
|
|
167
|
+
}
|
|
168
|
+
interface ProductOption {
|
|
169
|
+
name: string;
|
|
170
|
+
values: string[];
|
|
171
|
+
}
|
|
172
|
+
declare enum ProductStatus {
|
|
173
|
+
DRAFT = "DRAFT",
|
|
174
|
+
ACTIVE = "ACTIVE",
|
|
175
|
+
ARCHIVED = "ARCHIVED"
|
|
176
|
+
}
|
|
177
|
+
interface Product {
|
|
178
|
+
id: string;
|
|
179
|
+
title: string;
|
|
180
|
+
description?: string;
|
|
181
|
+
images: string[];
|
|
182
|
+
category: string;
|
|
183
|
+
tags: string[];
|
|
184
|
+
isPhysical: boolean;
|
|
185
|
+
weightInGrams?: number;
|
|
186
|
+
heightInCm?: number;
|
|
187
|
+
widthInCm?: number;
|
|
188
|
+
lengthInCm?: number;
|
|
189
|
+
priceInCents: number;
|
|
190
|
+
stockAvailable: number;
|
|
191
|
+
stockCommited: number;
|
|
192
|
+
stockUnavailable: number;
|
|
193
|
+
status: ProductStatus;
|
|
194
|
+
options: ProductOption[];
|
|
195
|
+
productVariants: ProductVariant[];
|
|
196
|
+
}
|
|
197
|
+
declare class Products {
|
|
198
|
+
private apiClient;
|
|
22
199
|
constructor(apiKey: string);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}>;
|
|
200
|
+
list(): Promise<Omit<Product, "productVariants">[]>;
|
|
201
|
+
retrieve(productId: string): Promise<Product>;
|
|
26
202
|
}
|
|
27
203
|
|
|
28
204
|
declare class BetterStore {
|
|
29
205
|
checkout: Checkout;
|
|
30
|
-
|
|
206
|
+
products: Products;
|
|
207
|
+
customer: Customer;
|
|
31
208
|
constructor(apiKey: string);
|
|
32
209
|
}
|
|
33
210
|
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
8
|
var __export = (target, all) => {
|
|
24
9
|
for (var name in all)
|
|
25
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
17
|
}
|
|
33
18
|
return to;
|
|
34
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
35
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
29
|
var __async = (__this, __arguments, generator) => {
|
|
37
30
|
return new Promise((resolve, reject) => {
|
|
@@ -61,65 +54,192 @@ __export(index_exports, {
|
|
|
61
54
|
});
|
|
62
55
|
module.exports = __toCommonJS(index_exports);
|
|
63
56
|
|
|
57
|
+
// src/utils/axios.ts
|
|
58
|
+
var import_axios = __toESM(require("axios"));
|
|
59
|
+
var API_BASE_URL = "https://api.betterstore.io/api/v1";
|
|
60
|
+
var createApiClient = (apiKey) => {
|
|
61
|
+
const client = import_axios.default.create({
|
|
62
|
+
baseURL: API_BASE_URL,
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
Authorization: `Bearer ${apiKey}`
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
client.interceptors.response.use(
|
|
69
|
+
(response) => response.data,
|
|
70
|
+
(error) => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const apiError = {
|
|
73
|
+
status: 500,
|
|
74
|
+
message: "An unexpected error occurred"
|
|
75
|
+
};
|
|
76
|
+
if (error.response) {
|
|
77
|
+
apiError.status = error.response.status;
|
|
78
|
+
apiError.message = ((_a = error.response.data) == null ? void 0 : _a.error) || "Server error occurred";
|
|
79
|
+
apiError.code = (_b = error.response.data) == null ? void 0 : _b.code;
|
|
80
|
+
apiError.details = error.response.data;
|
|
81
|
+
} else if (error.request) {
|
|
82
|
+
apiError.status = 503;
|
|
83
|
+
apiError.message = "Service unavailable - no response from server";
|
|
84
|
+
apiError.code = "SERVICE_UNAVAILABLE";
|
|
85
|
+
} else {
|
|
86
|
+
apiError.status = 500;
|
|
87
|
+
apiError.message = "Request configuration error";
|
|
88
|
+
apiError.code = "REQUEST_SETUP_ERROR";
|
|
89
|
+
}
|
|
90
|
+
throw apiError;
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
return client;
|
|
94
|
+
};
|
|
95
|
+
|
|
64
96
|
// src/checkout.ts
|
|
65
97
|
var Checkout = class {
|
|
66
98
|
constructor(apiKey) {
|
|
67
|
-
this.
|
|
99
|
+
this.apiClient = createApiClient(apiKey);
|
|
68
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a new checkout session
|
|
103
|
+
*/
|
|
69
104
|
create(params) {
|
|
70
105
|
return __async(this, null, function* () {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
const data = yield this.apiClient.post(
|
|
107
|
+
"/checkout",
|
|
108
|
+
params
|
|
109
|
+
);
|
|
110
|
+
return data;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieve a checkout session by ID or client secret
|
|
115
|
+
*/
|
|
116
|
+
retrieve(idOrSecret) {
|
|
117
|
+
return __async(this, null, function* () {
|
|
118
|
+
const data = yield this.apiClient.get(
|
|
119
|
+
`/checkout/${idOrSecret}`
|
|
120
|
+
);
|
|
121
|
+
return data;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update a checkout session
|
|
126
|
+
*/
|
|
127
|
+
update(checkoutId, params) {
|
|
128
|
+
return __async(this, null, function* () {
|
|
129
|
+
const data = yield this.apiClient.put(
|
|
130
|
+
`/checkout/${checkoutId}`,
|
|
131
|
+
params
|
|
132
|
+
);
|
|
133
|
+
return data;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get shipping rates for a checkout session
|
|
138
|
+
*/
|
|
139
|
+
getShippingRates(checkoutId) {
|
|
140
|
+
return __async(this, null, function* () {
|
|
141
|
+
const data = yield this.apiClient.get(
|
|
142
|
+
`/checkout/shipping/${checkoutId}`
|
|
143
|
+
);
|
|
144
|
+
return data;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Generate payment secret for a checkout session
|
|
149
|
+
*/
|
|
150
|
+
generatePaymentSecret(checkoutId) {
|
|
151
|
+
return __async(this, null, function* () {
|
|
152
|
+
const data = yield this.apiClient.post(
|
|
153
|
+
`/checkout/payment/${checkoutId}`
|
|
154
|
+
);
|
|
155
|
+
return data;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var checkout_default = Checkout;
|
|
160
|
+
|
|
161
|
+
// src/customer.ts
|
|
162
|
+
var Customer = class {
|
|
163
|
+
constructor(apiKey) {
|
|
164
|
+
this.apiClient = createApiClient(apiKey);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a new customer
|
|
168
|
+
*/
|
|
169
|
+
create(params) {
|
|
170
|
+
return __async(this, null, function* () {
|
|
171
|
+
const data = yield this.apiClient.post("/customers", params);
|
|
172
|
+
return data;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Retrieve a customer by ID or email
|
|
177
|
+
*/
|
|
178
|
+
retrieve(idOrEmail) {
|
|
179
|
+
return __async(this, null, function* () {
|
|
180
|
+
const data = yield this.apiClient.get(`/customers/${idOrEmail}`);
|
|
181
|
+
if (!data) {
|
|
182
|
+
throw new Error("Customer not found");
|
|
104
183
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
184
|
+
return data;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Update a customer
|
|
189
|
+
*/
|
|
190
|
+
update(customerId, params) {
|
|
191
|
+
return __async(this, null, function* () {
|
|
192
|
+
const data = yield this.apiClient.put(
|
|
193
|
+
`/customers/${customerId}`,
|
|
194
|
+
params
|
|
195
|
+
);
|
|
196
|
+
return data;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Delete a customer
|
|
201
|
+
*/
|
|
202
|
+
delete(customerId) {
|
|
203
|
+
return __async(this, null, function* () {
|
|
204
|
+
yield this.apiClient.delete(`/customers/${customerId}`);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var customer_default = Customer;
|
|
209
|
+
|
|
210
|
+
// src/products.ts
|
|
211
|
+
var Products = class {
|
|
212
|
+
constructor(apiKey) {
|
|
213
|
+
this.apiClient = createApiClient(apiKey);
|
|
214
|
+
}
|
|
215
|
+
list() {
|
|
216
|
+
return __async(this, null, function* () {
|
|
217
|
+
const data = yield this.apiClient.get("/products");
|
|
218
|
+
return data;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
retrieve(productId) {
|
|
222
|
+
return __async(this, null, function* () {
|
|
223
|
+
const data = yield this.apiClient.get(`/products/${productId}`);
|
|
224
|
+
if (!data) {
|
|
225
|
+
throw new Error("Product not found");
|
|
108
226
|
}
|
|
109
|
-
return
|
|
227
|
+
return data;
|
|
110
228
|
});
|
|
111
229
|
}
|
|
112
230
|
};
|
|
113
|
-
var
|
|
231
|
+
var products_default = Products;
|
|
114
232
|
|
|
115
233
|
// src/index.ts
|
|
116
234
|
var BetterStore = class {
|
|
235
|
+
// private apiKey: string;
|
|
117
236
|
constructor(apiKey) {
|
|
118
237
|
if (!apiKey) {
|
|
119
238
|
throw new Error("API key is required.");
|
|
120
239
|
}
|
|
121
|
-
this.apiKey = apiKey;
|
|
122
240
|
this.checkout = new checkout_default(apiKey);
|
|
241
|
+
this.products = new products_default(apiKey);
|
|
242
|
+
this.customer = new customer_default(apiKey);
|
|
123
243
|
}
|
|
124
244
|
};
|
|
125
245
|
var index_default = BetterStore;
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
1
|
var __async = (__this, __arguments, generator) => {
|
|
21
2
|
return new Promise((resolve, reject) => {
|
|
22
3
|
var fulfilled = (value) => {
|
|
@@ -38,65 +19,192 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
19
|
});
|
|
39
20
|
};
|
|
40
21
|
|
|
22
|
+
// src/utils/axios.ts
|
|
23
|
+
import axios from "axios";
|
|
24
|
+
var API_BASE_URL = "https://api.betterstore.io/api/v1";
|
|
25
|
+
var createApiClient = (apiKey) => {
|
|
26
|
+
const client = axios.create({
|
|
27
|
+
baseURL: API_BASE_URL,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
Authorization: `Bearer ${apiKey}`
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
client.interceptors.response.use(
|
|
34
|
+
(response) => response.data,
|
|
35
|
+
(error) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const apiError = {
|
|
38
|
+
status: 500,
|
|
39
|
+
message: "An unexpected error occurred"
|
|
40
|
+
};
|
|
41
|
+
if (error.response) {
|
|
42
|
+
apiError.status = error.response.status;
|
|
43
|
+
apiError.message = ((_a = error.response.data) == null ? void 0 : _a.error) || "Server error occurred";
|
|
44
|
+
apiError.code = (_b = error.response.data) == null ? void 0 : _b.code;
|
|
45
|
+
apiError.details = error.response.data;
|
|
46
|
+
} else if (error.request) {
|
|
47
|
+
apiError.status = 503;
|
|
48
|
+
apiError.message = "Service unavailable - no response from server";
|
|
49
|
+
apiError.code = "SERVICE_UNAVAILABLE";
|
|
50
|
+
} else {
|
|
51
|
+
apiError.status = 500;
|
|
52
|
+
apiError.message = "Request configuration error";
|
|
53
|
+
apiError.code = "REQUEST_SETUP_ERROR";
|
|
54
|
+
}
|
|
55
|
+
throw apiError;
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
return client;
|
|
59
|
+
};
|
|
60
|
+
|
|
41
61
|
// src/checkout.ts
|
|
42
62
|
var Checkout = class {
|
|
43
63
|
constructor(apiKey) {
|
|
44
|
-
this.
|
|
64
|
+
this.apiClient = createApiClient(apiKey);
|
|
45
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a new checkout session
|
|
68
|
+
*/
|
|
46
69
|
create(params) {
|
|
47
70
|
return __async(this, null, function* () {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
const data = yield this.apiClient.post(
|
|
72
|
+
"/checkout",
|
|
73
|
+
params
|
|
74
|
+
);
|
|
75
|
+
return data;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Retrieve a checkout session by ID or client secret
|
|
80
|
+
*/
|
|
81
|
+
retrieve(idOrSecret) {
|
|
82
|
+
return __async(this, null, function* () {
|
|
83
|
+
const data = yield this.apiClient.get(
|
|
84
|
+
`/checkout/${idOrSecret}`
|
|
85
|
+
);
|
|
86
|
+
return data;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update a checkout session
|
|
91
|
+
*/
|
|
92
|
+
update(checkoutId, params) {
|
|
93
|
+
return __async(this, null, function* () {
|
|
94
|
+
const data = yield this.apiClient.put(
|
|
95
|
+
`/checkout/${checkoutId}`,
|
|
96
|
+
params
|
|
97
|
+
);
|
|
98
|
+
return data;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get shipping rates for a checkout session
|
|
103
|
+
*/
|
|
104
|
+
getShippingRates(checkoutId) {
|
|
105
|
+
return __async(this, null, function* () {
|
|
106
|
+
const data = yield this.apiClient.get(
|
|
107
|
+
`/checkout/shipping/${checkoutId}`
|
|
108
|
+
);
|
|
109
|
+
return data;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Generate payment secret for a checkout session
|
|
114
|
+
*/
|
|
115
|
+
generatePaymentSecret(checkoutId) {
|
|
116
|
+
return __async(this, null, function* () {
|
|
117
|
+
const data = yield this.apiClient.post(
|
|
118
|
+
`/checkout/payment/${checkoutId}`
|
|
119
|
+
);
|
|
120
|
+
return data;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var checkout_default = Checkout;
|
|
125
|
+
|
|
126
|
+
// src/customer.ts
|
|
127
|
+
var Customer = class {
|
|
128
|
+
constructor(apiKey) {
|
|
129
|
+
this.apiClient = createApiClient(apiKey);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a new customer
|
|
133
|
+
*/
|
|
134
|
+
create(params) {
|
|
135
|
+
return __async(this, null, function* () {
|
|
136
|
+
const data = yield this.apiClient.post("/customers", params);
|
|
137
|
+
return data;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Retrieve a customer by ID or email
|
|
142
|
+
*/
|
|
143
|
+
retrieve(idOrEmail) {
|
|
144
|
+
return __async(this, null, function* () {
|
|
145
|
+
const data = yield this.apiClient.get(`/customers/${idOrEmail}`);
|
|
146
|
+
if (!data) {
|
|
147
|
+
throw new Error("Customer not found");
|
|
81
148
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
149
|
+
return data;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Update a customer
|
|
154
|
+
*/
|
|
155
|
+
update(customerId, params) {
|
|
156
|
+
return __async(this, null, function* () {
|
|
157
|
+
const data = yield this.apiClient.put(
|
|
158
|
+
`/customers/${customerId}`,
|
|
159
|
+
params
|
|
160
|
+
);
|
|
161
|
+
return data;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Delete a customer
|
|
166
|
+
*/
|
|
167
|
+
delete(customerId) {
|
|
168
|
+
return __async(this, null, function* () {
|
|
169
|
+
yield this.apiClient.delete(`/customers/${customerId}`);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var customer_default = Customer;
|
|
174
|
+
|
|
175
|
+
// src/products.ts
|
|
176
|
+
var Products = class {
|
|
177
|
+
constructor(apiKey) {
|
|
178
|
+
this.apiClient = createApiClient(apiKey);
|
|
179
|
+
}
|
|
180
|
+
list() {
|
|
181
|
+
return __async(this, null, function* () {
|
|
182
|
+
const data = yield this.apiClient.get("/products");
|
|
183
|
+
return data;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
retrieve(productId) {
|
|
187
|
+
return __async(this, null, function* () {
|
|
188
|
+
const data = yield this.apiClient.get(`/products/${productId}`);
|
|
189
|
+
if (!data) {
|
|
190
|
+
throw new Error("Product not found");
|
|
85
191
|
}
|
|
86
|
-
return
|
|
192
|
+
return data;
|
|
87
193
|
});
|
|
88
194
|
}
|
|
89
195
|
};
|
|
90
|
-
var
|
|
196
|
+
var products_default = Products;
|
|
91
197
|
|
|
92
198
|
// src/index.ts
|
|
93
199
|
var BetterStore = class {
|
|
200
|
+
// private apiKey: string;
|
|
94
201
|
constructor(apiKey) {
|
|
95
202
|
if (!apiKey) {
|
|
96
203
|
throw new Error("API key is required.");
|
|
97
204
|
}
|
|
98
|
-
this.apiKey = apiKey;
|
|
99
205
|
this.checkout = new checkout_default(apiKey);
|
|
206
|
+
this.products = new products_default(apiKey);
|
|
207
|
+
this.customer = new customer_default(apiKey);
|
|
100
208
|
}
|
|
101
209
|
};
|
|
102
210
|
var index_default = BetterStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,10 +19,14 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@changesets/cli": "^2.28.1",
|
|
22
|
+
"@types/axios": "^0.14.4",
|
|
22
23
|
"prettier": "^3.5.3",
|
|
23
24
|
"tsup": "^8.4.0",
|
|
24
25
|
"typescript": "^5.8.2"
|
|
25
26
|
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"axios": "^1.8.1"
|
|
29
|
+
},
|
|
26
30
|
"scripts": {
|
|
27
31
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
28
32
|
"lint": "tsc",
|