@pintahub/shopify-next 0.4.0 → 0.5.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.
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import type { Command } from './Command';
|
|
2
|
+
/**
|
|
3
|
+
* `storeId` accepts a string or any value with `toString()` (e.g. Mongo `ObjectId`) —
|
|
4
|
+
* coerced internally. Services usually pass `store._id` directly.
|
|
5
|
+
*/
|
|
6
|
+
export type StoreId = string | {
|
|
7
|
+
toString(): string;
|
|
8
|
+
};
|
|
2
9
|
export interface ShopifyClientOptions {
|
|
3
|
-
/** Store `_id` from MongoDB. Gateway uses it to look up `admin_access_token` + subdomain. */
|
|
4
|
-
storeId: string;
|
|
5
10
|
/** Shopify Admin API version. Defaults to `2026-04`. Pass a different value (e.g. `unstable`) for new features. */
|
|
6
11
|
apiVersion?: string;
|
|
7
12
|
/**
|
|
8
|
-
* Base URL of shopify-gateway.
|
|
9
|
-
*
|
|
13
|
+
* Base URL of shopify-gateway. Resolution order:
|
|
14
|
+
* 1. `gatewayBase` option
|
|
15
|
+
* 2. `process.env.SHOPIFY_GATEWAY_URL`
|
|
16
|
+
* 3. `http://localhost:6100` (default)
|
|
10
17
|
*/
|
|
11
18
|
gatewayBase?: string;
|
|
12
19
|
/** Middleware wrapping each `send()`. Composed in order (outermost first). */
|
|
13
20
|
middleware?: Middleware[];
|
|
21
|
+
/** Caller identity, sent as `x-app-name` header to shopify-gateway for logging/tracing. */
|
|
22
|
+
appName?: string;
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
16
25
|
* Middleware wrapping `send()`. Same pattern as `koa` / `express`:
|
|
@@ -26,9 +35,10 @@ export declare class ShopifyClient {
|
|
|
26
35
|
readonly storeId: string;
|
|
27
36
|
readonly apiVersion: string;
|
|
28
37
|
readonly gatewayBase: string;
|
|
38
|
+
readonly appName?: string;
|
|
29
39
|
private readonly raw;
|
|
30
40
|
private readonly dispatch;
|
|
31
|
-
constructor(
|
|
41
|
+
constructor(storeId: StoreId, options?: ShopifyClientOptions);
|
|
32
42
|
/** Execute a Command through the gateway. */
|
|
33
43
|
send<I, O>(command: Command<I, O>): Promise<O>;
|
|
34
44
|
}
|
|
@@ -3,27 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ShopifyClient = void 0;
|
|
4
4
|
const admin_api_client_1 = require("@shopify/admin-api-client");
|
|
5
5
|
const DEFAULT_API_VERSION = '2026-04';
|
|
6
|
+
const DEFAULT_GATEWAY_BASE = 'http://localhost:6100';
|
|
6
7
|
class ShopifyClient {
|
|
7
8
|
storeId;
|
|
8
9
|
apiVersion;
|
|
9
10
|
gatewayBase;
|
|
11
|
+
appName;
|
|
10
12
|
raw;
|
|
11
13
|
dispatch;
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.storeId =
|
|
14
|
+
constructor(storeId, options = {}) {
|
|
15
|
+
this.storeId = storeId ? String(storeId) : '';
|
|
14
16
|
this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;
|
|
15
|
-
this.gatewayBase =
|
|
17
|
+
this.gatewayBase =
|
|
18
|
+
options.gatewayBase ?? process.env.SHOPIFY_GATEWAY_URL ?? DEFAULT_GATEWAY_BASE;
|
|
19
|
+
this.appName = options.appName;
|
|
16
20
|
if (!this.storeId) {
|
|
17
21
|
throw new Error('ShopifyClient: storeId is required');
|
|
18
22
|
}
|
|
19
|
-
if (!this.gatewayBase) {
|
|
20
|
-
throw new Error('ShopifyClient: gatewayBase not provided and SHOPIFY_GATEWAY_URL env var not set');
|
|
21
|
-
}
|
|
22
23
|
this.raw = (0, admin_api_client_1.createAdminApiClient)({
|
|
23
24
|
storeDomain: 'placeholder.myshopify.com',
|
|
24
25
|
accessToken: 'placeholder',
|
|
25
26
|
apiVersion: this.apiVersion,
|
|
26
|
-
customFetchApi: (_url, init) =>
|
|
27
|
+
customFetchApi: (_url, init) => {
|
|
28
|
+
const reqInit = (init ?? {});
|
|
29
|
+
const headers = new Headers(reqInit.headers);
|
|
30
|
+
if (this.appName)
|
|
31
|
+
headers.set('x-app-name', this.appName);
|
|
32
|
+
return fetch(`${this.gatewayBase}/stores/${this.storeId}/${this.apiVersion}/graphql.json`, { ...reqInit, headers });
|
|
33
|
+
},
|
|
27
34
|
});
|
|
28
35
|
const base = (command) => command.execute(this.raw);
|
|
29
36
|
this.dispatch = (options.middleware ?? []).reduceRight((next, mw) => mw(next), base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShopifyClient.js","sourceRoot":"","sources":["../../src/client/ShopifyClient.ts"],"names":[],"mappings":";;;AAAA,gEAAmF;AAGnF,MAAM,mBAAmB,GAAG,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"ShopifyClient.js","sourceRoot":"","sources":["../../src/client/ShopifyClient.ts"],"names":[],"mappings":";;;AAAA,gEAAmF;AAGnF,MAAM,mBAAmB,GAAG,SAAS,CAAA;AACrC,MAAM,oBAAoB,GAAG,uBAAuB,CAAA;AAqCpD,MAAa,aAAa;IACR,OAAO,CAAQ;IACf,UAAU,CAAQ;IAClB,WAAW,CAAQ;IACnB,OAAO,CAAS;IACf,GAAG,CAAgB;IACnB,QAAQ,CAA8C;IAEvE,YAAY,OAAgB,EAAE,UAAgC,EAAE;QAC9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAA;QAC3D,IAAI,CAAC,WAAW;YACd,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,oBAAoB,CAAA;QAChF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAE9B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAA,uCAAoB,EAAC;YAC9B,WAAW,EAAE,2BAA2B;YACxC,WAAW,EAAE,aAAa;YAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;gBAC7B,MAAM,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAAgB,CAAA;gBAC3C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC5C,IAAI,IAAI,CAAC,OAAO;oBAAE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;gBACzD,OAAO,KAAK,CACV,GAAG,IAAI,CAAC,WAAW,WAAW,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,UAAU,eAAe,EAC5E,EAAC,GAAG,OAAO,EAAE,OAAO,EAAC,CACtB,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QAEF,MAAM,IAAI,GAAG,CAAO,OAAsB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACxE,IAAI,CAAC,QAAQ,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,WAAW,CAEpD,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,6CAA6C;IAC7C,IAAI,CAAO,OAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;CACF;AA5CD,sCA4CC","sourcesContent":["import {createAdminApiClient, type AdminApiClient} from '@shopify/admin-api-client'\nimport type {Command} from './Command'\n\nconst DEFAULT_API_VERSION = '2026-04'\nconst DEFAULT_GATEWAY_BASE = 'http://localhost:6100'\n\n/**\n * `storeId` accepts a string or any value with `toString()` (e.g. Mongo `ObjectId`) —\n * coerced internally. Services usually pass `store._id` directly.\n */\nexport type StoreId = string | {toString(): string}\n\nexport interface ShopifyClientOptions {\n /** Shopify Admin API version. Defaults to `2026-04`. Pass a different value (e.g. `unstable`) for new features. */\n apiVersion?: string\n /**\n * Base URL of shopify-gateway. Resolution order:\n * 1. `gatewayBase` option\n * 2. `process.env.SHOPIFY_GATEWAY_URL`\n * 3. `http://localhost:6100` (default)\n */\n gatewayBase?: string\n /** Middleware wrapping each `send()`. Composed in order (outermost first). */\n middleware?: Middleware[]\n /** Caller identity, sent as `x-app-name` header to shopify-gateway for logging/tracing. */\n appName?: string\n}\n\n/**\n * Middleware wrapping `send()`. Same pattern as `koa` / `express`:\n * const mw: Middleware = (next) => async (command) => {\n * // before\n * const result = await next(command)\n * // after\n * return result\n * }\n */\nexport type Middleware = (\n next: <I, O>(command: Command<I, O>) => Promise<O>,\n) => <I, O>(command: Command<I, O>) => Promise<O>\n\nexport class ShopifyClient {\n public readonly storeId: string\n public readonly apiVersion: string\n public readonly gatewayBase: string\n public readonly appName?: string\n private readonly raw: AdminApiClient\n private readonly dispatch: <I, O>(command: Command<I, O>) => Promise<O>\n\n constructor(storeId: StoreId, options: ShopifyClientOptions = {}) {\n this.storeId = storeId ? String(storeId) : ''\n this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION\n this.gatewayBase =\n options.gatewayBase ?? process.env.SHOPIFY_GATEWAY_URL ?? DEFAULT_GATEWAY_BASE\n this.appName = options.appName\n\n if (!this.storeId) {\n throw new Error('ShopifyClient: storeId is required')\n }\n\n this.raw = createAdminApiClient({\n storeDomain: 'placeholder.myshopify.com',\n accessToken: 'placeholder',\n apiVersion: this.apiVersion,\n customFetchApi: (_url, init) => {\n const reqInit = (init ?? {}) as RequestInit\n const headers = new Headers(reqInit.headers)\n if (this.appName) headers.set('x-app-name', this.appName)\n return fetch(\n `${this.gatewayBase}/stores/${this.storeId}/${this.apiVersion}/graphql.json`,\n {...reqInit, headers},\n )\n },\n })\n\n const base = <I, O>(command: Command<I, O>) => command.execute(this.raw)\n this.dispatch = (options.middleware ?? []).reduceRight<\n <I, O>(cmd: Command<I, O>) => Promise<O>\n >((next, mw) => mw(next), base)\n }\n\n /** Execute a Command through the gateway. */\n send<I, O>(command: Command<I, O>): Promise<O> {\n return this.dispatch(command)\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ShopifyClient, type ShopifyClientOptions, type Middleware } from './client/ShopifyClient';
|
|
1
|
+
export { ShopifyClient, type ShopifyClientOptions, type StoreId, type Middleware, } from './client/ShopifyClient';
|
|
2
2
|
export { Command } from './client/Command';
|
|
3
3
|
export { handleErrors, assertNoUserErrors, type GraphQLError, type ResponseErrors, type UserError, } from './utils/handleErrors';
|
|
4
4
|
export { getGlobalID, extractIdFromGlobalID } from './utils/globalId';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wDAK+B;AAJ7B,8GAAA,aAAa,OAAA;AAKf,4CAAwC;AAAhC,kGAAA,OAAO,OAAA;AACf,qDAM6B;AAL3B,4GAAA,YAAY,OAAA;AACZ,kHAAA,kBAAkB,OAAA;AAKpB,6CAAmE;AAA3D,uGAAA,WAAW,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAE1C,gCAAgC;AAChC,uDAAoC;AACpC,sDAAmC;AACnC,mDAAgC","sourcesContent":["export {\n ShopifyClient,\n type ShopifyClientOptions,\n type StoreId,\n type Middleware,\n} from './client/ShopifyClient'\nexport {Command} from './client/Command'\nexport {\n handleErrors,\n assertNoUserErrors,\n type GraphQLError,\n type ResponseErrors,\n type UserError,\n} from './utils/handleErrors'\nexport {getGlobalID, extractIdFromGlobalID} from './utils/globalId'\n\n// Commands grouped by namespace\nexport * from './commands/customers'\nexport * from './commands/payments'\nexport * from './commands/menus'\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pintahub/shopify-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Shopify Admin GraphQL client for pintahub services via shopify-gateway",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"build": "tsc -p tsconfig.build.json",
|
|
12
12
|
"dev": "tsc -p tsconfig.build.json --watch",
|
|
13
13
|
"clean": "rm -rf dist",
|
|
14
|
+
"prepack": "yarn clean && yarn build",
|
|
14
15
|
"codegen": "graphql-codegen",
|
|
15
16
|
"typecheck": "tsc --noEmit",
|
|
16
17
|
"test": "vitest run",
|