@pintahub/shopify-next 0.4.1 → 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.
|
@@ -18,6 +18,8 @@ export interface ShopifyClientOptions {
|
|
|
18
18
|
gatewayBase?: string;
|
|
19
19
|
/** Middleware wrapping each `send()`. Composed in order (outermost first). */
|
|
20
20
|
middleware?: Middleware[];
|
|
21
|
+
/** Caller identity, sent as `x-app-name` header to shopify-gateway for logging/tracing. */
|
|
22
|
+
appName?: string;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Middleware wrapping `send()`. Same pattern as `koa` / `express`:
|
|
@@ -33,6 +35,7 @@ export declare class ShopifyClient {
|
|
|
33
35
|
readonly storeId: string;
|
|
34
36
|
readonly apiVersion: string;
|
|
35
37
|
readonly gatewayBase: string;
|
|
38
|
+
readonly appName?: string;
|
|
36
39
|
private readonly raw;
|
|
37
40
|
private readonly dispatch;
|
|
38
41
|
constructor(storeId: StoreId, options?: ShopifyClientOptions);
|
|
@@ -8,6 +8,7 @@ class ShopifyClient {
|
|
|
8
8
|
storeId;
|
|
9
9
|
apiVersion;
|
|
10
10
|
gatewayBase;
|
|
11
|
+
appName;
|
|
11
12
|
raw;
|
|
12
13
|
dispatch;
|
|
13
14
|
constructor(storeId, options = {}) {
|
|
@@ -15,6 +16,7 @@ class ShopifyClient {
|
|
|
15
16
|
this.apiVersion = options.apiVersion ?? DEFAULT_API_VERSION;
|
|
16
17
|
this.gatewayBase =
|
|
17
18
|
options.gatewayBase ?? process.env.SHOPIFY_GATEWAY_URL ?? DEFAULT_GATEWAY_BASE;
|
|
19
|
+
this.appName = options.appName;
|
|
18
20
|
if (!this.storeId) {
|
|
19
21
|
throw new Error('ShopifyClient: storeId is required');
|
|
20
22
|
}
|
|
@@ -22,7 +24,13 @@ class ShopifyClient {
|
|
|
22
24
|
storeDomain: 'placeholder.myshopify.com',
|
|
23
25
|
accessToken: 'placeholder',
|
|
24
26
|
apiVersion: this.apiVersion,
|
|
25
|
-
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
|
+
},
|
|
26
34
|
});
|
|
27
35
|
const base = (command) => command.execute(this.raw);
|
|
28
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;AACrC,MAAM,oBAAoB,GAAG,uBAAuB,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,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CD,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"]}
|