@betterstore/sdk 0.7.1 → 0.7.3
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 +5702 -2036
- package/dist/index.d.ts +5702 -2036
- package/dist/index.js +25 -20
- package/dist/index.mjs +25 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26,27 +26,37 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/base-client.ts
|
|
29
|
+
var DEFAULT_BASE_URL = "https://v1.betterstore.io";
|
|
29
30
|
var BaseClient = class {
|
|
30
31
|
constructor(config) {
|
|
31
32
|
this.config = config;
|
|
33
|
+
this.headers = {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
Authorization: `Bearer ${this.config.secret}`
|
|
36
|
+
};
|
|
32
37
|
}
|
|
38
|
+
headers;
|
|
33
39
|
async get(path, params) {
|
|
34
|
-
const url =
|
|
40
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
41
|
+
const searchParams = new URLSearchParams();
|
|
35
42
|
if (params) {
|
|
36
43
|
Object.entries(params).forEach(([key, val]) => {
|
|
37
|
-
if (val !== void 0)
|
|
44
|
+
if (val !== void 0) searchParams.set(key, val);
|
|
38
45
|
});
|
|
39
46
|
}
|
|
40
|
-
const res = await fetch(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
const res = await fetch(
|
|
48
|
+
`${url}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`,
|
|
49
|
+
{
|
|
50
|
+
method: "GET",
|
|
51
|
+
headers: this.headers
|
|
52
|
+
}
|
|
53
|
+
);
|
|
44
54
|
return this.handleResponse(res);
|
|
45
55
|
}
|
|
46
56
|
async post(path, body) {
|
|
47
57
|
const res = await fetch(`${this.config.baseUrl}${path}`, {
|
|
48
58
|
method: "POST",
|
|
49
|
-
headers: this.
|
|
59
|
+
headers: this.headers,
|
|
50
60
|
body: body ? JSON.stringify(body) : void 0
|
|
51
61
|
});
|
|
52
62
|
return this.handleResponse(res);
|
|
@@ -54,13 +64,14 @@ var BaseClient = class {
|
|
|
54
64
|
async delete(path) {
|
|
55
65
|
const res = await fetch(`${this.config.baseUrl}${path}`, {
|
|
56
66
|
method: "DELETE",
|
|
57
|
-
headers: this.
|
|
67
|
+
headers: this.headers
|
|
58
68
|
});
|
|
59
69
|
return this.handleResponse(res);
|
|
60
70
|
}
|
|
61
71
|
async handleResponse(res) {
|
|
62
72
|
if (!res.ok) {
|
|
63
|
-
const error = await res.json().catch(() => ({ message: res.statusText }));
|
|
73
|
+
const error = await res.json().catch(() => ({ message: res.statusText, data: res.body }));
|
|
74
|
+
console.log(error);
|
|
64
75
|
throw new Error(error.message || `HTTP ${res.status}`);
|
|
65
76
|
}
|
|
66
77
|
return res.json();
|
|
@@ -157,13 +168,10 @@ var ClientUtilsNamespace = class {
|
|
|
157
168
|
};
|
|
158
169
|
|
|
159
170
|
// src/client-factory.ts
|
|
160
|
-
function createBetterStoreClient(
|
|
171
|
+
function createBetterStoreClient(checkoutSecret, config) {
|
|
161
172
|
const baseClient = new BaseClient({
|
|
162
|
-
baseUrl: config?.proxy ||
|
|
163
|
-
|
|
164
|
-
Authorization: `Bearer ${clientSecret}`,
|
|
165
|
-
"Content-Type": "application/json"
|
|
166
|
-
}
|
|
173
|
+
baseUrl: config?.proxy || DEFAULT_BASE_URL,
|
|
174
|
+
secret: checkoutSecret
|
|
167
175
|
});
|
|
168
176
|
return {
|
|
169
177
|
checkout: new ClientCheckoutNamespace(baseClient),
|
|
@@ -338,11 +346,8 @@ var UtilsNamespace = class {
|
|
|
338
346
|
// src/main-factory.ts
|
|
339
347
|
function createBetterStore(secret, config) {
|
|
340
348
|
const baseClient = new BaseClient({
|
|
341
|
-
baseUrl: config?.proxy ||
|
|
342
|
-
|
|
343
|
-
Authorization: `Bearer ${secret}`,
|
|
344
|
-
"Content-Type": "application/json"
|
|
345
|
-
}
|
|
349
|
+
baseUrl: config?.proxy || DEFAULT_BASE_URL,
|
|
350
|
+
secret
|
|
346
351
|
});
|
|
347
352
|
return {
|
|
348
353
|
products: new ProductsNamespace(baseClient),
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
// src/base-client.ts
|
|
2
|
+
var DEFAULT_BASE_URL = "https://v1.betterstore.io";
|
|
2
3
|
var BaseClient = class {
|
|
3
4
|
constructor(config) {
|
|
4
5
|
this.config = config;
|
|
6
|
+
this.headers = {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
Authorization: `Bearer ${this.config.secret}`
|
|
9
|
+
};
|
|
5
10
|
}
|
|
11
|
+
headers;
|
|
6
12
|
async get(path, params) {
|
|
7
|
-
const url =
|
|
13
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
14
|
+
const searchParams = new URLSearchParams();
|
|
8
15
|
if (params) {
|
|
9
16
|
Object.entries(params).forEach(([key, val]) => {
|
|
10
|
-
if (val !== void 0)
|
|
17
|
+
if (val !== void 0) searchParams.set(key, val);
|
|
11
18
|
});
|
|
12
19
|
}
|
|
13
|
-
const res = await fetch(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
const res = await fetch(
|
|
21
|
+
`${url}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`,
|
|
22
|
+
{
|
|
23
|
+
method: "GET",
|
|
24
|
+
headers: this.headers
|
|
25
|
+
}
|
|
26
|
+
);
|
|
17
27
|
return this.handleResponse(res);
|
|
18
28
|
}
|
|
19
29
|
async post(path, body) {
|
|
20
30
|
const res = await fetch(`${this.config.baseUrl}${path}`, {
|
|
21
31
|
method: "POST",
|
|
22
|
-
headers: this.
|
|
32
|
+
headers: this.headers,
|
|
23
33
|
body: body ? JSON.stringify(body) : void 0
|
|
24
34
|
});
|
|
25
35
|
return this.handleResponse(res);
|
|
@@ -27,13 +37,14 @@ var BaseClient = class {
|
|
|
27
37
|
async delete(path) {
|
|
28
38
|
const res = await fetch(`${this.config.baseUrl}${path}`, {
|
|
29
39
|
method: "DELETE",
|
|
30
|
-
headers: this.
|
|
40
|
+
headers: this.headers
|
|
31
41
|
});
|
|
32
42
|
return this.handleResponse(res);
|
|
33
43
|
}
|
|
34
44
|
async handleResponse(res) {
|
|
35
45
|
if (!res.ok) {
|
|
36
|
-
const error = await res.json().catch(() => ({ message: res.statusText }));
|
|
46
|
+
const error = await res.json().catch(() => ({ message: res.statusText, data: res.body }));
|
|
47
|
+
console.log(error);
|
|
37
48
|
throw new Error(error.message || `HTTP ${res.status}`);
|
|
38
49
|
}
|
|
39
50
|
return res.json();
|
|
@@ -130,13 +141,10 @@ var ClientUtilsNamespace = class {
|
|
|
130
141
|
};
|
|
131
142
|
|
|
132
143
|
// src/client-factory.ts
|
|
133
|
-
function createBetterStoreClient(
|
|
144
|
+
function createBetterStoreClient(checkoutSecret, config) {
|
|
134
145
|
const baseClient = new BaseClient({
|
|
135
|
-
baseUrl: config?.proxy ||
|
|
136
|
-
|
|
137
|
-
Authorization: `Bearer ${clientSecret}`,
|
|
138
|
-
"Content-Type": "application/json"
|
|
139
|
-
}
|
|
146
|
+
baseUrl: config?.proxy || DEFAULT_BASE_URL,
|
|
147
|
+
secret: checkoutSecret
|
|
140
148
|
});
|
|
141
149
|
return {
|
|
142
150
|
checkout: new ClientCheckoutNamespace(baseClient),
|
|
@@ -311,11 +319,8 @@ var UtilsNamespace = class {
|
|
|
311
319
|
// src/main-factory.ts
|
|
312
320
|
function createBetterStore(secret, config) {
|
|
313
321
|
const baseClient = new BaseClient({
|
|
314
|
-
baseUrl: config?.proxy ||
|
|
315
|
-
|
|
316
|
-
Authorization: `Bearer ${secret}`,
|
|
317
|
-
"Content-Type": "application/json"
|
|
318
|
-
}
|
|
322
|
+
baseUrl: config?.proxy || DEFAULT_BASE_URL,
|
|
323
|
+
secret
|
|
319
324
|
});
|
|
320
325
|
return {
|
|
321
326
|
products: new ProductsNamespace(baseClient),
|