shopify_storefront_sdk 1.0.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/LICENSE +21 -0
- package/README.md +258 -0
- package/dist/cjs/client/client.d.ts +9 -0
- package/dist/cjs/client/client.d.ts.map +1 -0
- package/dist/cjs/client/client.js +38 -0
- package/dist/cjs/client/client.js.map +1 -0
- package/dist/cjs/generated/shopify.d.ts +9612 -0
- package/dist/cjs/generated/shopify.d.ts.map +1 -0
- package/dist/cjs/generated/shopify.js +1003 -0
- package/dist/cjs/generated/shopify.js.map +1 -0
- package/dist/cjs/index.d.ts +34 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +174 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/tests/test.d.ts +34 -0
- package/dist/cjs/tests/test.d.ts.map +1 -0
- package/dist/cjs/tests/test.js +240 -0
- package/dist/cjs/tests/test.js.map +1 -0
- package/dist/cjs/utils/config.d.ts +5 -0
- package/dist/cjs/utils/config.d.ts.map +1 -0
- package/dist/cjs/utils/config.js +3 -0
- package/dist/cjs/utils/config.js.map +1 -0
- package/dist/client/client.d.ts +9 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +33 -0
- package/dist/client/client.js.map +1 -0
- package/dist/generated/shopify.d.ts +9612 -0
- package/dist/generated/shopify.d.ts.map +1 -0
- package/dist/generated/shopify.js +1000 -0
- package/dist/generated/shopify.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/test.d.ts +34 -0
- package/dist/tests/test.d.ts.map +1 -0
- package/dist/tests/test.js +202 -0
- package/dist/tests/test.js.map +1 -0
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +2 -0
- package/dist/utils/config.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Paschal Elechi
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# 📦 Shopify Storefront SDK (Node.js + TypeScript)
|
|
2
|
+
|
|
3
|
+
A fully typed, lightweight, and developer-friendly **Node.js SDK for the Shopify Storefront GraphQL API**.
|
|
4
|
+
Built with TypeScript, GraphQL Codegen, and graphql-request — designed to help developers move faster when building Shopify headless storefronts.
|
|
5
|
+
|
|
6
|
+
✔ Fully typed queries & responses
|
|
7
|
+
✔ Simple, intuitive API
|
|
8
|
+
✔ Pre-built operations (Products, Carts, Customers, Blogs, Articles…)
|
|
9
|
+
✔ Works with Node.js, Next.js, Remix, Cloudflare Workers & more
|
|
10
|
+
✔ Supports custom GraphQL queries
|
|
11
|
+
✔ Automatic code generation
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🔧 Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install shopify-storefront-sdk
|
|
19
|
+
# or
|
|
20
|
+
yarn add shopify-storefront-sdk
|
|
21
|
+
# or
|
|
22
|
+
pnpm add shopify-storefront-sdk
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🚀 Quick Start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { ShopifyStorefront } from "shopify-storefront-sdk";
|
|
30
|
+
|
|
31
|
+
const shopify = new ShopifyStorefront({
|
|
32
|
+
domain: process.env.SHOPIFY_STORE_DOMAIN!,
|
|
33
|
+
token: process.env.SHOPIFY_STOREFRONT_TOKEN!,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Fetch a product
|
|
37
|
+
const product = await shopify.getProductById(
|
|
38
|
+
"gid://shopify/Product/1234567890"
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
console.log(product.title);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 📘 Features
|
|
47
|
+
|
|
48
|
+
- **Typed SDK methods**:
|
|
49
|
+
|
|
50
|
+
- Products (ID, handle, collections)
|
|
51
|
+
- Recommendations
|
|
52
|
+
- Blogs & articles
|
|
53
|
+
- Carts (create/get/update)
|
|
54
|
+
- Customers (create, login, recovery flow)
|
|
55
|
+
|
|
56
|
+
- **GraphQL Codegen built in**
|
|
57
|
+
- **Consistent error handling**
|
|
58
|
+
- **Supports custom queries**
|
|
59
|
+
- **Zero heavy dependencies**
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 🧩 SDK API Overview
|
|
64
|
+
|
|
65
|
+
### Initialize Client
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const shopify = new ShopifyStorefront({
|
|
69
|
+
domain: "yourstore.myshopify.com",
|
|
70
|
+
token: "your-storefront-access-token",
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### Products
|
|
77
|
+
|
|
78
|
+
#### Get product by ID
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await shopify.getProductById(productId);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Get product by handle
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
await shopify.getProductByHandle("my-product");
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Recommendations
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
await shopify.getProductRecommendations(productId);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### Carts
|
|
99
|
+
|
|
100
|
+
#### Create a cart
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
await shopify.createCart({
|
|
104
|
+
lines: [{ merchandiseId: "...", quantity: 1 }],
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Get cart
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
await shopify.getCart(cartId);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### Customers
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
await shopify.createCustomer({ email, password });
|
|
120
|
+
await shopify.sendResetEmail(email);
|
|
121
|
+
await shopify.verifyToken(token);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### Blogs & Articles
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
await shopify.getBlog("news", 10);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 📁 Project Structure
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
/src
|
|
138
|
+
/queries → .graphql operations
|
|
139
|
+
/generated → Auto-generated code
|
|
140
|
+
index.ts → SDK export
|
|
141
|
+
|
|
142
|
+
/codegen.yml → Codegen config
|
|
143
|
+
/schema.graphql → Shopify schema
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 🛠 Development Setup
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git clone https://github.com/YOUR_USERNAME/shopify-storefront-sdk.git
|
|
152
|
+
cd shopify-storefront-sdk
|
|
153
|
+
npm install
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Create a `.env` file:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
SHOPIFY_STORE_DOMAIN=yourstore.myshopify.com
|
|
160
|
+
SHOPIFY_STOREFRONT_TOKEN=xxxx
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 🔨 Build
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
npm run build
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Outputs:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
dist/index.js
|
|
175
|
+
dist/index.cjs
|
|
176
|
+
dist/index.d.ts
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 🧪 Testing
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm run dev
|
|
185
|
+
# after build:
|
|
186
|
+
npm run test
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 🧬 Code Generation
|
|
192
|
+
|
|
193
|
+
Regenerate types & operations:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npm run generate
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Scans:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
src/queries/*.graphql
|
|
203
|
+
schema.graphql
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Generates:
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
src/generated/
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 🌐 Requirements
|
|
215
|
+
|
|
216
|
+
- Node.js 18+
|
|
217
|
+
- Storefront API token
|
|
218
|
+
- Public or development Shopify store
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 🤝 Contributing
|
|
223
|
+
|
|
224
|
+
Pull requests are welcome!
|
|
225
|
+
|
|
226
|
+
1. Fork the repo
|
|
227
|
+
2. Create a branch: `git checkout -b feature/my-feature`
|
|
228
|
+
3. Commit & push
|
|
229
|
+
4. Submit a PR
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 📜 License
|
|
234
|
+
|
|
235
|
+
MIT License — free for commercial and personal use.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## ⭐ Support
|
|
240
|
+
|
|
241
|
+
If this SDK saves you time, please star ⭐ the repository—
|
|
242
|
+
it helps others discover it and motivates future improvements!
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
If you want, I can also generate:
|
|
249
|
+
|
|
250
|
+
✅ Better badges (npm version, downloads, license, TypeScript)
|
|
251
|
+
✅ CONTRIBUTING.md
|
|
252
|
+
✅ API documentation table
|
|
253
|
+
✅ Full GitHub project template (issues, PR templates, workflows)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StoreConfig } from "../utils/config.js";
|
|
2
|
+
declare class ShopifyClient {
|
|
3
|
+
private endpoint;
|
|
4
|
+
private token;
|
|
5
|
+
constructor({ storeUrl, storefrontToken }: StoreConfig);
|
|
6
|
+
query<T = any>(query: string, variables?: {}): Promise<T>;
|
|
7
|
+
}
|
|
8
|
+
export default ShopifyClient;
|
|
9
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,cAAM,aAAa;IACjB,OAAO,CAAC,QAAQ,CAAC;IACjB,OAAO,CAAC,KAAK,CAAC;gBACF,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,WAAW;IAQhD,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC;CAsBhE;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
class ShopifyClient {
|
|
8
|
+
endpoint;
|
|
9
|
+
token;
|
|
10
|
+
constructor({ storeUrl, storefrontToken }) {
|
|
11
|
+
if (!storeUrl?.includes(".myshopify.com")) {
|
|
12
|
+
throw new Error(`The store url ${storeUrl} is not supported by shopify`);
|
|
13
|
+
}
|
|
14
|
+
(this.endpoint = `https://${storeUrl}/api/2025-04/graphql.json`),
|
|
15
|
+
(this.token = storefrontToken);
|
|
16
|
+
}
|
|
17
|
+
async query(query, variables = {}) {
|
|
18
|
+
try {
|
|
19
|
+
const res = await axios_1.default.post(this.endpoint, {
|
|
20
|
+
query,
|
|
21
|
+
variables,
|
|
22
|
+
}, {
|
|
23
|
+
headers: {
|
|
24
|
+
"X-Shopify-Storefront-Access-Token": this.token,
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
if (res.data?.errors)
|
|
29
|
+
throw new Error(JSON.stringify(res.data.errors, null, 2));
|
|
30
|
+
return res.data?.data;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error(`Shopify Error: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.default = ShopifyClient;
|
|
38
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":";;;;;AACA,kDAA0B;AAE1B,MAAM,aAAa;IACT,QAAQ,CAAC;IACT,KAAK,CAAC;IACd,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAe;QACpD,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,iBAAiB,QAAQ,8BAA8B,CAAC,CAAC;QAC3E,CAAC;QACD,CAAC,IAAI,CAAC,QAAQ,GAAG,WAAW,QAAQ,2BAA2B,CAAC;YAC9D,CAAC,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAU,KAAa,EAAE,SAAS,GAAG,EAAE;QAChD,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAC1B,IAAI,CAAC,QAAQ,EACb;gBACE,KAAK;gBACL,SAAS;aACV,EACD;gBACE,OAAO,EAAE;oBACP,mCAAmC,EAAE,IAAI,CAAC,KAAK;oBAC/C,cAAc,EAAE,kBAAkB;iBACnC;aACF,CACF,CAAC;YACF,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM;gBAClB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5D,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;QACxB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF;AAED,kBAAe,aAAa,CAAC"}
|