@betterstore/sdk 0.0.1 → 0.1.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/.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
@@ -0,0 +1,20 @@
1
+ # @betterstore/sdk
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - readme changed, checkout types changed
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 372cbbc: checkout create method added
14
+ - cicd test
15
+
16
+ ### Patch Changes
17
+
18
+ - 6d0e6e4: ci cd test
19
+ - 6769d53: Change sets added, debug
20
+ - fd3f4da: npm ignore 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/README.md CHANGED
@@ -1,38 +1,29 @@
1
1
  # Better Store SDK
2
2
 
3
- 🚀 **Better Store SDK** is a modern, developer-friendly eCommerce toolkit designed to help developers build flexible and powerful online stores with ease.
4
-
5
- ## ✨ Features
6
-
7
- - 🛒 **Custom Checkout** – Build checkout flows that suit your business needs.
8
- - 💳 **Payments** – Integrate with Stripe, PayPal, and custom gateways.
9
- - 📦 **Product & Order Management** – API-driven store management.
10
- - 🎨 **Customizable UI** – Prebuilt components and themes.
11
- - 📡 **Webhooks & API Events** – Extend and automate eCommerce operations.
12
- - 🚀 **Optimized for DX** – Built with TypeScript and fully documented.
3
+ 🚀 **Better Store SDK** is a modern, developer-friendly sdk toolkit designed to help developers build flexible and powerful e-commerce stores with ease.
13
4
 
14
5
  ## 📦 Installation
15
6
 
16
7
  ```sh
17
- npm install better-store-sdk
8
+ npm install @betterstore/sdk
18
9
  ```
19
10
 
20
11
  ## 🚀 Quick Start
21
12
 
22
13
  ```javascript
23
- import { BetterStore } from "better-store-sdk";
14
+ import { BetterStore } from "@betterstore/sdk";
24
15
 
25
- const store = new BetterStore({ apiKey: "YOUR_API_KEY" });
16
+ const betterStore = new BetterStore("YOUR_API_KEY");
26
17
 
27
- store.checkout.start({
28
- cart: [{ id: "prod_1", name: "T-Shirt", price: 20 }],
29
- currency: "USD",
18
+ betterStore.checkout.create({
19
+ type: "hosted",
20
+ lineItems: [{ productId: "example_id", quantity: 1 }],
30
21
  });
31
22
  ```
32
23
 
33
24
  ## 📚 Documentation
34
25
 
35
- Full documentation is available at **[betterstore.dev](https://betterstore.dev)**.
26
+ Full documentation is available at **[betterstore.io](https://betterstore.io)**.
36
27
 
37
28
  ## 🤝 Contributing
38
29
 
package/dist/index.d.mts CHANGED
@@ -1,3 +1,34 @@
1
- declare const hello: () => void;
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
- export { hello };
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
- declare const hello: () => void;
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
- export { hello };
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,93 @@ 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
- hello: () => hello
60
+ default: () => index_default
24
61
  });
25
62
  module.exports = __toCommonJS(index_exports);
26
- var hello = () => {
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, _b;
73
+ return __spreadProps(__spreadValues({}, item), {
74
+ quantity: ((_a = item.quantity) != null ? _a : 1) > 0 ? item.quantity : 1,
75
+ variant_options: (_b = item.variantOptions) != null ? _b : []
76
+ });
77
+ });
78
+ const response = yield fetch("https://betterstore.io/api/checkout", {
79
+ method: "POST",
80
+ body: JSON.stringify(__spreadValues({
81
+ type: params.type,
82
+ line_items: lineItems,
83
+ discount: params.discount
84
+ }, params.type === "hosted" && {
85
+ success_url: params.successUrl,
86
+ cancel_url: params.cancelUrl
87
+ })),
88
+ headers: {
89
+ "Content-Type": "application/json",
90
+ Authorization: `Bearer ${this.apiKey}`
91
+ }
92
+ });
93
+ const data = yield response.json();
94
+ if (params.type === "hosted") {
95
+ const checkoutId = data.checkoutId;
96
+ if (!checkoutId) {
97
+ throw new Error("Failed to create checkout");
98
+ }
99
+ const searchParams = new URLSearchParams({
100
+ successUrl: params.successUrl,
101
+ cancelUrl: params.cancelUrl
102
+ });
103
+ return `https://checkout.betterstore.io/${checkoutId}?${searchParams.toString()}`;
104
+ }
105
+ const clientSecret = data.clientSecret;
106
+ if (!clientSecret) {
107
+ throw new Error("Failed to create checkout");
108
+ }
109
+ return { client_secret: clientSecret };
110
+ });
111
+ }
27
112
  };
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {
30
- hello
31
- });
113
+ var checkout_default = Checkout;
114
+
115
+ // src/index.ts
116
+ var BetterStore = class {
117
+ constructor(apiKey) {
118
+ if (!apiKey) {
119
+ throw new Error("API key is required.");
120
+ }
121
+ this.apiKey = apiKey;
122
+ this.checkout = new checkout_default(apiKey);
123
+ }
124
+ };
125
+ var index_default = BetterStore;
package/dist/index.mjs CHANGED
@@ -1,6 +1,105 @@
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, _b;
50
+ return __spreadProps(__spreadValues({}, item), {
51
+ quantity: ((_a = item.quantity) != null ? _a : 1) > 0 ? item.quantity : 1,
52
+ variant_options: (_b = item.variantOptions) != null ? _b : []
53
+ });
54
+ });
55
+ const response = yield fetch("https://betterstore.io/api/checkout", {
56
+ method: "POST",
57
+ body: JSON.stringify(__spreadValues({
58
+ type: params.type,
59
+ line_items: lineItems,
60
+ discount: params.discount
61
+ }, params.type === "hosted" && {
62
+ success_url: params.successUrl,
63
+ cancel_url: params.cancelUrl
64
+ })),
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ Authorization: `Bearer ${this.apiKey}`
68
+ }
69
+ });
70
+ const data = yield response.json();
71
+ if (params.type === "hosted") {
72
+ const checkoutId = data.checkoutId;
73
+ if (!checkoutId) {
74
+ throw new Error("Failed to create checkout");
75
+ }
76
+ const searchParams = new URLSearchParams({
77
+ successUrl: params.successUrl,
78
+ cancelUrl: params.cancelUrl
79
+ });
80
+ return `https://checkout.betterstore.io/${checkoutId}?${searchParams.toString()}`;
81
+ }
82
+ const clientSecret = data.clientSecret;
83
+ if (!clientSecret) {
84
+ throw new Error("Failed to create checkout");
85
+ }
86
+ return { client_secret: clientSecret };
87
+ });
88
+ }
89
+ };
90
+ var checkout_default = Checkout;
91
+
1
92
  // src/index.ts
2
- var hello = () => {
93
+ var BetterStore = class {
94
+ constructor(apiKey) {
95
+ if (!apiKey) {
96
+ throw new Error("API key is required.");
97
+ }
98
+ this.apiKey = apiKey;
99
+ this.checkout = new checkout_default(apiKey);
100
+ }
3
101
  };
102
+ var index_default = BetterStore;
4
103
  export {
5
- hello
104
+ index_default as default
6
105
  };
package/package.json CHANGED
@@ -1,19 +1,14 @@
1
1
  {
2
2
  "name": "@betterstore/sdk",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
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
+ }