@betterstore/sdk 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +2 -2
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -21
- package/dist/index.d.mts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +99 -6
- package/dist/index.mjs +100 -2
- package/package.json +13 -10
package/.prettierignore
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
dist
|
|
1
|
+
node_modules
|
|
2
|
+
dist
|
|
3
3
|
pnpm-lock.yaml
|
package/CHANGELOG.md
ADDED
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Better Store
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Better Store
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
interface BaseCheckoutParams {
|
|
2
|
+
line_items: {
|
|
3
|
+
productId: string;
|
|
4
|
+
variantOptions?: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
quantity: number;
|
|
9
|
+
}[];
|
|
10
|
+
discount: string;
|
|
11
|
+
}
|
|
12
|
+
interface HostedCheckoutParams extends BaseCheckoutParams {
|
|
13
|
+
type: "hosted";
|
|
14
|
+
successUrl: string;
|
|
15
|
+
cancelUrl: string;
|
|
16
|
+
}
|
|
17
|
+
interface EmbedCheckoutParams extends BaseCheckoutParams {
|
|
18
|
+
type: "embed";
|
|
19
|
+
}
|
|
20
|
+
declare class Checkout {
|
|
21
|
+
private apiKey;
|
|
22
|
+
constructor(apiKey: string);
|
|
23
|
+
create(params: HostedCheckoutParams | EmbedCheckoutParams): Promise<string | {
|
|
24
|
+
client_secret: any;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
2
27
|
|
|
3
|
-
|
|
28
|
+
declare class BetterStore {
|
|
29
|
+
checkout: Checkout;
|
|
30
|
+
private apiKey;
|
|
31
|
+
constructor(apiKey: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { BetterStore as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
interface BaseCheckoutParams {
|
|
2
|
+
line_items: {
|
|
3
|
+
productId: string;
|
|
4
|
+
variantOptions?: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
quantity: number;
|
|
9
|
+
}[];
|
|
10
|
+
discount: string;
|
|
11
|
+
}
|
|
12
|
+
interface HostedCheckoutParams extends BaseCheckoutParams {
|
|
13
|
+
type: "hosted";
|
|
14
|
+
successUrl: string;
|
|
15
|
+
cancelUrl: string;
|
|
16
|
+
}
|
|
17
|
+
interface EmbedCheckoutParams extends BaseCheckoutParams {
|
|
18
|
+
type: "embed";
|
|
19
|
+
}
|
|
20
|
+
declare class Checkout {
|
|
21
|
+
private apiKey;
|
|
22
|
+
constructor(apiKey: string);
|
|
23
|
+
create(params: HostedCheckoutParams | EmbedCheckoutParams): Promise<string | {
|
|
24
|
+
client_secret: any;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
2
27
|
|
|
3
|
-
|
|
28
|
+
declare class BetterStore {
|
|
29
|
+
checkout: Checkout;
|
|
30
|
+
private apiKey;
|
|
31
|
+
constructor(apiKey: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { BetterStore as default };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
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));
|
|
6
23
|
var __export = (target, all) => {
|
|
7
24
|
for (var name in all)
|
|
8
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,16 +33,92 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
33
|
return to;
|
|
17
34
|
};
|
|
18
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
19
56
|
|
|
20
57
|
// src/index.ts
|
|
21
58
|
var index_exports = {};
|
|
22
59
|
__export(index_exports, {
|
|
23
|
-
|
|
60
|
+
default: () => index_default
|
|
24
61
|
});
|
|
25
62
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
|
|
63
|
+
|
|
64
|
+
// src/checkout.ts
|
|
65
|
+
var Checkout = class {
|
|
66
|
+
constructor(apiKey) {
|
|
67
|
+
this.apiKey = apiKey;
|
|
68
|
+
}
|
|
69
|
+
create(params) {
|
|
70
|
+
return __async(this, null, function* () {
|
|
71
|
+
const lineItems = params.line_items.map((item) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
74
|
+
variant_options: (_a = item.variantOptions) != null ? _a : []
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const response = yield fetch("https://betterstore.io/api/checkout", {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: JSON.stringify(__spreadValues({
|
|
80
|
+
type: params.type,
|
|
81
|
+
line_items: lineItems,
|
|
82
|
+
discount: params.discount
|
|
83
|
+
}, params.type === "hosted" && {
|
|
84
|
+
success_url: params.successUrl,
|
|
85
|
+
cancel_url: params.cancelUrl
|
|
86
|
+
})),
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const data = yield response.json();
|
|
93
|
+
if (params.type === "hosted") {
|
|
94
|
+
const checkoutId = data.checkoutId;
|
|
95
|
+
if (!checkoutId) {
|
|
96
|
+
throw new Error("Failed to create checkout");
|
|
97
|
+
}
|
|
98
|
+
const searchParams = new URLSearchParams({
|
|
99
|
+
successUrl: params.successUrl,
|
|
100
|
+
cancelUrl: params.cancelUrl
|
|
101
|
+
});
|
|
102
|
+
return `https://checkout.betterstore.io/${checkoutId}?${searchParams.toString()}`;
|
|
103
|
+
}
|
|
104
|
+
const clientSecret = data.clientSecret;
|
|
105
|
+
if (!clientSecret) {
|
|
106
|
+
throw new Error("Failed to create checkout");
|
|
107
|
+
}
|
|
108
|
+
return { client_secret: clientSecret };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
27
111
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
112
|
+
var checkout_default = Checkout;
|
|
113
|
+
|
|
114
|
+
// src/index.ts
|
|
115
|
+
var BetterStore = class {
|
|
116
|
+
constructor(apiKey) {
|
|
117
|
+
if (!apiKey) {
|
|
118
|
+
throw new Error("API key is required.");
|
|
119
|
+
}
|
|
120
|
+
this.apiKey = apiKey;
|
|
121
|
+
this.checkout = new checkout_default(apiKey);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var index_default = BetterStore;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,104 @@
|
|
|
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
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/checkout.ts
|
|
42
|
+
var Checkout = class {
|
|
43
|
+
constructor(apiKey) {
|
|
44
|
+
this.apiKey = apiKey;
|
|
45
|
+
}
|
|
46
|
+
create(params) {
|
|
47
|
+
return __async(this, null, function* () {
|
|
48
|
+
const lineItems = params.line_items.map((item) => {
|
|
49
|
+
var _a;
|
|
50
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
51
|
+
variant_options: (_a = item.variantOptions) != null ? _a : []
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const response = yield fetch("https://betterstore.io/api/checkout", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify(__spreadValues({
|
|
57
|
+
type: params.type,
|
|
58
|
+
line_items: lineItems,
|
|
59
|
+
discount: params.discount
|
|
60
|
+
}, params.type === "hosted" && {
|
|
61
|
+
success_url: params.successUrl,
|
|
62
|
+
cancel_url: params.cancelUrl
|
|
63
|
+
})),
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const data = yield response.json();
|
|
70
|
+
if (params.type === "hosted") {
|
|
71
|
+
const checkoutId = data.checkoutId;
|
|
72
|
+
if (!checkoutId) {
|
|
73
|
+
throw new Error("Failed to create checkout");
|
|
74
|
+
}
|
|
75
|
+
const searchParams = new URLSearchParams({
|
|
76
|
+
successUrl: params.successUrl,
|
|
77
|
+
cancelUrl: params.cancelUrl
|
|
78
|
+
});
|
|
79
|
+
return `https://checkout.betterstore.io/${checkoutId}?${searchParams.toString()}`;
|
|
80
|
+
}
|
|
81
|
+
const clientSecret = data.clientSecret;
|
|
82
|
+
if (!clientSecret) {
|
|
83
|
+
throw new Error("Failed to create checkout");
|
|
84
|
+
}
|
|
85
|
+
return { client_secret: clientSecret };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var checkout_default = Checkout;
|
|
90
|
+
|
|
1
91
|
// src/index.ts
|
|
2
|
-
var
|
|
92
|
+
var BetterStore = class {
|
|
93
|
+
constructor(apiKey) {
|
|
94
|
+
if (!apiKey) {
|
|
95
|
+
throw new Error("API key is required.");
|
|
96
|
+
}
|
|
97
|
+
this.apiKey = apiKey;
|
|
98
|
+
this.checkout = new checkout_default(apiKey);
|
|
99
|
+
}
|
|
3
100
|
};
|
|
101
|
+
var index_default = BetterStore;
|
|
4
102
|
export {
|
|
5
|
-
|
|
103
|
+
index_default as default
|
|
6
104
|
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
6
9
|
"main": "dist/index.js",
|
|
7
10
|
"module": "dist/index.mjs",
|
|
8
11
|
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
11
|
-
"lint": "tsc",
|
|
12
|
-
"format:check": "prettier --check --ignore-path .prettierignore .",
|
|
13
|
-
"format": "prettier --write --ignore-path .prettierignore .",
|
|
14
|
-
"ci": "pnpm run lint && pnpm run format:check && pnpm run build",
|
|
15
|
-
"release": "pnpm run ci && changeset publish"
|
|
16
|
-
},
|
|
17
12
|
"keywords": [
|
|
18
13
|
"betterstore",
|
|
19
14
|
"ecommerce",
|
|
@@ -27,5 +22,13 @@
|
|
|
27
22
|
"prettier": "^3.5.3",
|
|
28
23
|
"tsup": "^8.4.0",
|
|
29
24
|
"typescript": "^5.8.2"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
28
|
+
"lint": "tsc",
|
|
29
|
+
"format:check": "prettier --check --ignore-path .prettierignore .",
|
|
30
|
+
"format": "prettier --write --ignore-path .prettierignore .",
|
|
31
|
+
"ci": "pnpm run lint && pnpm run format:check && pnpm run build",
|
|
32
|
+
"release": "pnpm run ci && changeset publish"
|
|
30
33
|
}
|
|
31
|
-
}
|
|
34
|
+
}
|