shopify_storefront_sdk 1.0.3 → 2.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/README.md +136 -70
- package/dist/cjs/client/client.js +110 -23
- package/dist/cjs/generated/shopify.js +25 -50
- package/dist/cjs/helpers/CartManager.js +55 -0
- package/dist/cjs/helpers/CustomerSession.js +41 -0
- package/dist/cjs/index.js +210 -25
- package/dist/cjs/tests/integration/sdk.test.js +266 -0
- package/dist/cjs/tests/unit/cache.test.js +86 -0
- package/dist/cjs/tests/unit/cartManager.test.js +43 -0
- package/dist/cjs/tests/unit/client.test.js +134 -0
- package/dist/cjs/tests/unit/customerSession.test.js +50 -0
- package/dist/cjs/tests/unit/pagination.test.js +41 -0
- package/dist/cjs/tests/unit/webhooks.test.js +41 -0
- package/dist/cjs/utils/cache.js +29 -0
- package/dist/cjs/utils/config.js +0 -1
- package/dist/cjs/utils/errors.js +53 -0
- package/dist/cjs/utils/pagination.js +30 -0
- package/dist/cjs/utils/webhooks.js +33 -0
- package/dist/client/client.d.ts +12 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +111 -21
- package/dist/client/client.js.map +1 -1
- package/dist/generated/shopify.d.ts +4048 -2764
- package/dist/generated/shopify.d.ts.map +1 -1
- package/dist/generated/shopify.js +26 -50
- package/dist/generated/shopify.js.map +1 -1
- package/dist/helpers/CartManager.d.ts +32 -0
- package/dist/helpers/CartManager.d.ts.map +1 -0
- package/dist/helpers/CartManager.js +53 -0
- package/dist/helpers/CartManager.js.map +1 -0
- package/dist/helpers/CustomerSession.d.ts +27 -0
- package/dist/helpers/CustomerSession.d.ts.map +1 -0
- package/dist/helpers/CustomerSession.js +40 -0
- package/dist/helpers/CustomerSession.js.map +1 -0
- package/dist/index.d.ts +179 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +204 -25
- package/dist/index.js.map +1 -1
- package/dist/tests/integration/sdk.test.d.ts +2 -0
- package/dist/tests/integration/sdk.test.d.ts.map +1 -0
- package/dist/tests/integration/sdk.test.js +245 -0
- package/dist/tests/integration/sdk.test.js.map +1 -0
- package/dist/tests/unit/cache.test.d.ts +2 -0
- package/dist/tests/unit/cache.test.d.ts.map +1 -0
- package/dist/tests/unit/cache.test.js +85 -0
- package/dist/tests/unit/cache.test.js.map +1 -0
- package/dist/tests/unit/cartManager.test.d.ts +2 -0
- package/dist/tests/unit/cartManager.test.d.ts.map +1 -0
- package/dist/tests/unit/cartManager.test.js +43 -0
- package/dist/tests/unit/cartManager.test.js.map +1 -0
- package/dist/tests/unit/client.test.d.ts +2 -0
- package/dist/tests/unit/client.test.d.ts.map +1 -0
- package/dist/tests/unit/client.test.js +133 -0
- package/dist/tests/unit/client.test.js.map +1 -0
- package/dist/tests/unit/customerSession.test.d.ts +2 -0
- package/dist/tests/unit/customerSession.test.d.ts.map +1 -0
- package/dist/tests/unit/customerSession.test.js +49 -0
- package/dist/tests/unit/customerSession.test.js.map +1 -0
- package/dist/tests/unit/pagination.test.d.ts +2 -0
- package/dist/tests/unit/pagination.test.d.ts.map +1 -0
- package/dist/tests/unit/pagination.test.js +40 -0
- package/dist/tests/unit/pagination.test.js.map +1 -0
- package/dist/tests/unit/webhooks.test.d.ts +2 -0
- package/dist/tests/unit/webhooks.test.d.ts.map +1 -0
- package/dist/tests/unit/webhooks.test.js +40 -0
- package/dist/tests/unit/webhooks.test.js.map +1 -0
- package/dist/utils/cache.d.ts +14 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +24 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/config.d.ts +6 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +30 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +48 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/pagination.d.ts +20 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +28 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/webhooks.d.ts +10 -0
- package/dist/utils/webhooks.d.ts.map +1 -0
- package/dist/utils/webhooks.js +31 -0
- package/dist/utils/webhooks.js.map +1 -0
- package/package.json +11 -7
- package/dist/cjs/client/client.d.ts +0 -9
- package/dist/cjs/client/client.d.ts.map +0 -1
- package/dist/cjs/client/client.js.map +0 -1
- package/dist/cjs/generated/shopify.d.ts +0 -9612
- package/dist/cjs/generated/shopify.d.ts.map +0 -1
- package/dist/cjs/generated/shopify.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -34
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/tests/test.d.ts +0 -34
- package/dist/cjs/tests/test.d.ts.map +0 -1
- package/dist/cjs/tests/test.js +0 -202
- package/dist/cjs/tests/test.js.map +0 -1
- package/dist/cjs/utils/config.d.ts +0 -5
- package/dist/cjs/utils/config.d.ts.map +0 -1
- package/dist/cjs/utils/config.js.map +0 -1
- package/dist/tests/test.d.ts +0 -34
- package/dist/tests/test.d.ts.map +0 -1
- package/dist/tests/test.js +0 -202
- package/dist/tests/test.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PageInfo {
|
|
2
|
+
hasNextPage: boolean;
|
|
3
|
+
endCursor?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface Edge<TNode> {
|
|
6
|
+
node: TNode;
|
|
7
|
+
}
|
|
8
|
+
export interface Connection<TNode> {
|
|
9
|
+
edges: Edge<TNode>[];
|
|
10
|
+
pageInfo: PageInfo;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Automatically fetches all pages of a Shopify GraphQL Connection and flattens the nodes into an array.
|
|
14
|
+
*
|
|
15
|
+
* @param fetchPage A function that takes an optional cursor and returns a promise of the API response.
|
|
16
|
+
* @param getConnection A selector function that extracts the Connection object from the API response.
|
|
17
|
+
* @returns A flat array of all nodes across all pages.
|
|
18
|
+
*/
|
|
19
|
+
export declare function autoPaginate<TResponse, TNode>(fetchPage: (cursor?: string) => Promise<TResponse>, getConnection: (response: TResponse) => Connection<TNode> | undefined | null): Promise<TNode[]>;
|
|
20
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/utils/pagination.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,IAAI,CAAC,KAAK;IACzB,IAAI,EAAE,KAAK,CAAC;CACb;AAED,MAAM,WAAW,UAAU,CAAC,KAAK;IAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,SAAS,EAAE,KAAK,EACjD,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,EAClD,aAAa,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,UAAU,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,IAAI,GAC3E,OAAO,CAAC,KAAK,EAAE,CAAC,CAwBlB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically fetches all pages of a Shopify GraphQL Connection and flattens the nodes into an array.
|
|
3
|
+
*
|
|
4
|
+
* @param fetchPage A function that takes an optional cursor and returns a promise of the API response.
|
|
5
|
+
* @param getConnection A selector function that extracts the Connection object from the API response.
|
|
6
|
+
* @returns A flat array of all nodes across all pages.
|
|
7
|
+
*/
|
|
8
|
+
export async function autoPaginate(fetchPage, getConnection) {
|
|
9
|
+
const results = [];
|
|
10
|
+
let hasNextPage = true;
|
|
11
|
+
let cursor = undefined;
|
|
12
|
+
while (hasNextPage) {
|
|
13
|
+
const response = await fetchPage(cursor);
|
|
14
|
+
const connection = getConnection(response);
|
|
15
|
+
if (!connection || !connection.edges || !connection.pageInfo) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
for (const edge of connection.edges) {
|
|
19
|
+
if (edge && edge.node) {
|
|
20
|
+
results.push(edge.node);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
hasNextPage = connection.pageInfo.hasNextPage;
|
|
24
|
+
cursor = connection.pageInfo.endCursor || undefined;
|
|
25
|
+
}
|
|
26
|
+
return results;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/utils/pagination.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,SAAkD,EAClD,aAA4E;IAE5E,MAAM,OAAO,GAAY,EAAE,CAAC;IAC5B,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,MAAM,GAAuB,SAAS,CAAC;IAE3C,OAAO,WAAW,EAAE,CAAC;QACnB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAE3C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC7D,MAAM;QACR,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACpC,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,WAAW,GAAG,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC9C,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,IAAI,SAAS,CAAC;IACtD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies a Shopify webhook's HMAC signature.
|
|
3
|
+
*
|
|
4
|
+
* @param rawBody The raw, unparsed request body string or buffer.
|
|
5
|
+
* @param hmacHeader The `x-shopify-hmac-sha256` header provided by Shopify.
|
|
6
|
+
* @param secret Your Shopify app or storefront webhook API secret.
|
|
7
|
+
* @returns A boolean indicating whether the webhook signature is valid.
|
|
8
|
+
*/
|
|
9
|
+
export declare function verifyWebhook(rawBody: string | Buffer, hmacHeader: string, secret: string): boolean;
|
|
10
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/utils/webhooks.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAuBnG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Verifies a Shopify webhook's HMAC signature.
|
|
4
|
+
*
|
|
5
|
+
* @param rawBody The raw, unparsed request body string or buffer.
|
|
6
|
+
* @param hmacHeader The `x-shopify-hmac-sha256` header provided by Shopify.
|
|
7
|
+
* @param secret Your Shopify app or storefront webhook API secret.
|
|
8
|
+
* @returns A boolean indicating whether the webhook signature is valid.
|
|
9
|
+
*/
|
|
10
|
+
export function verifyWebhook(rawBody, hmacHeader, secret) {
|
|
11
|
+
if (!rawBody || !hmacHeader || !secret) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const generatedHash = crypto
|
|
16
|
+
.createHmac("sha256", secret)
|
|
17
|
+
.update(rawBody)
|
|
18
|
+
.digest("base64");
|
|
19
|
+
const generatedBuffer = Buffer.from(generatedHash);
|
|
20
|
+
const hmacBuffer = Buffer.from(hmacHeader);
|
|
21
|
+
// Use timingSafeEqual to prevent timing attacks
|
|
22
|
+
if (generatedBuffer.length !== hmacBuffer.length) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return crypto.timingSafeEqual(generatedBuffer, hmacBuffer);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/utils/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAwB,EAAE,UAAkB,EAAE,MAAc;IACxF,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM;aACzB,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;aAC5B,MAAM,CAAC,OAAO,CAAC;aACf,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEpB,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACnD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE3C,gDAAgD;QAChD,IAAI,eAAe,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,MAAM,CAAC,eAAe,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shopify_storefront_sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "cjs-wrapper.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"scripts": {
|
|
24
24
|
"clean": "rimraf dist",
|
|
25
|
-
"dev": "node --loader ts-node/esm src/tests/test.ts",
|
|
25
|
+
"dev": "node --loader ts-node/esm src/tests/integration/sdk.test.ts",
|
|
26
26
|
"build": "rimraf dist && npm run build:esm && npm run build:cjs",
|
|
27
27
|
"build:esm": "tsc --project tsconfig.json",
|
|
28
28
|
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
29
|
-
"
|
|
30
|
-
"test": "
|
|
29
|
+
"build:docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:unit": "vitest run src/tests/unit",
|
|
32
|
+
"test:integration": "vitest run src/tests/integration",
|
|
31
33
|
"codegen": "graphql-codegen --config codegen.yml",
|
|
32
34
|
"prepare": "npm run build"
|
|
33
35
|
},
|
|
@@ -58,10 +60,12 @@
|
|
|
58
60
|
"@graphql-codegen/typescript": "^5.0.5",
|
|
59
61
|
"@graphql-codegen/typescript-graphql-request": "^6.3.0",
|
|
60
62
|
"@graphql-codegen/typescript-operations": "^5.0.5",
|
|
61
|
-
"@types/node": "^24.
|
|
62
|
-
"axios": "^1.13.2",
|
|
63
|
+
"@types/node": "^24.13.3",
|
|
63
64
|
"ts-node": "^10.9.2",
|
|
64
|
-
"
|
|
65
|
+
"typedoc": "^0.28.20",
|
|
66
|
+
"typedoc-plugin-markdown": "^4.13.0",
|
|
67
|
+
"typescript": "^5.9.3",
|
|
68
|
+
"vitest": "^4.1.11"
|
|
65
69
|
},
|
|
66
70
|
"dependencies": {
|
|
67
71
|
"dotenv": "^17.2.3",
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/client.ts"],"names":[],"mappings":";;AACA,iCAA0B;AAE1B,MAAM,aAAa;IAGjB,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAe;QACpD,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAA,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,MAAA,GAAG,CAAC,IAAI,0CAAE,MAAM;gBAClB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5D,OAAO,MAAA,GAAG,CAAC,IAAI,0CAAE,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"}
|