@keystrokehq/shopify 0.0.16-integration-id-canonicalization.0 → 0.0.16
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/dist/credential-sets/index.d.mts +1 -1
- package/dist/credential-sets/index.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/operations/index.d.mts +1 -1
- package/dist/operations/index.mjs +1 -1
- package/dist/{shopify-app.credential-set-DuAYUhzY.d.mts → shopify-app.credential-set-gdNuCDtd.d.mts} +0 -26
- package/dist/shopify.credential-set-C_SrMLjT.mjs +53 -0
- package/dist/{update-shopify-product.operation-Db_kLuJa.d.mts → update-shopify-product.operation-CtjraWjR.d.mts} +0 -1093
- package/dist/{update-shopify-product.operation-ByYhZggW.mjs → update-shopify-product.operation-DsAjcvO8.mjs} +1 -1
- package/package.json +1 -2
- package/dist/shopify.credential-set-CaxST3GP.mjs +0 -205
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as shopifyShopSchema, b as shopifyProductSchema, c as shopifyGlobalIdSchema, d as shopifyInventoryItemSchema, f as shopifyInventoryLevelSchema, i as shopifyConnectionNodesSchema, l as shopifyGraphqlErrorSchema, m as shopifyLocationSchema, n as shopifyBlogSchema, o as shopifyCustomerSchema, p as shopifyJobSchema, r as shopifyCollectionSchema, s as shopifyFulfillmentSchema, t as shopifyArticleSchema, v as shopifyOrderSchema, w as shopifyUserErrorSchema } from "./common-JZyHdK6p.mjs";
|
|
2
|
-
import { t as shopifyCredentialSet } from "./shopify.credential-set-
|
|
2
|
+
import { t as shopifyCredentialSet } from "./shopify.credential-set-C_SrMLjT.mjs";
|
|
3
3
|
import { Operation } from "@keystrokehq/core";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { CredentialRevokedError } from "@keystrokehq/core/errors";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keystrokehq/shopify",
|
|
3
|
-
"version": "0.0.16
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"vitest": "^4.0.18",
|
|
42
42
|
"@keystrokehq/core": "^0.0.12",
|
|
43
43
|
"@keystrokehq/test-utils": "0.0.0",
|
|
44
|
-
"@keystrokehq/credential-connection": "1.0.0",
|
|
45
44
|
"@keystrokehq/typescript-config": "0.0.0",
|
|
46
45
|
"@keystrokehq/integration-authoring": "0.0.9"
|
|
47
46
|
},
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { C as shopifyStoreDomainSchema } from "./common-JZyHdK6p.mjs";
|
|
2
|
-
import { CredentialSet } from "@keystrokehq/core";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
5
|
-
|
|
6
|
-
//#region ../../packages/credential-connection/dist/defaults-YE9AvLIc.mjs
|
|
7
|
-
/**
|
|
8
|
-
* Shared OAuth 2.0 token-response plumbing.
|
|
9
|
-
*
|
|
10
|
-
* `parseOAuthTokenResponse` handles the two common wire formats (JSON and
|
|
11
|
-
* form-urlencoded, the latter used by GitHub unless you explicitly ask for
|
|
12
|
-
* JSON). `normalizeOAuthTokens` pulls the standard fields out of the parsed
|
|
13
|
-
* body in both the flat form and Slack's nested `authed_user.access_token`
|
|
14
|
-
* form. These helpers are exposed so integration authors overriding
|
|
15
|
-
* `exchangeCode` / `refreshToken` do not have to re-implement them.
|
|
16
|
-
*/
|
|
17
|
-
var TokenExchangeError = class extends Error {
|
|
18
|
-
httpStatus;
|
|
19
|
-
constructor(httpStatus) {
|
|
20
|
-
super(`Token exchange failed: HTTP ${httpStatus}`);
|
|
21
|
-
this.name = "TokenExchangeError";
|
|
22
|
-
this.httpStatus = httpStatus;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
async function parseOAuthTokenResponse(response) {
|
|
26
|
-
const contentType = response.headers.get("content-type")?.toLowerCase() ?? "";
|
|
27
|
-
if (contentType.includes("application/json")) return await response.json();
|
|
28
|
-
const text = await response.text();
|
|
29
|
-
if (!text.trim()) return {};
|
|
30
|
-
if (contentType.includes("application/x-www-form-urlencoded") || text.includes("=")) {
|
|
31
|
-
const params = new URLSearchParams(text);
|
|
32
|
-
return Object.fromEntries(params.entries());
|
|
33
|
-
}
|
|
34
|
-
throw new Error(`Unsupported OAuth token response content type: ${contentType || "unknown"}`);
|
|
35
|
-
}
|
|
36
|
-
function normalizeOAuthTokens(tokenData) {
|
|
37
|
-
const authedUser = tokenData.authed_user;
|
|
38
|
-
const rawAccessToken = tokenData.access_token ?? authedUser?.access_token;
|
|
39
|
-
const rawRefreshToken = tokenData.refresh_token;
|
|
40
|
-
const rawExpiresIn = tokenData.expires_in;
|
|
41
|
-
const rawInstanceUrl = tokenData.instance_url;
|
|
42
|
-
return {
|
|
43
|
-
accessToken: typeof rawAccessToken === "string" ? rawAccessToken : void 0,
|
|
44
|
-
refreshToken: typeof rawRefreshToken === "string" ? rawRefreshToken : void 0,
|
|
45
|
-
expiresIn: typeof rawExpiresIn === "number" ? rawExpiresIn : typeof rawExpiresIn === "string" ? Number(rawExpiresIn) || void 0 : void 0,
|
|
46
|
-
instanceUrl: typeof rawInstanceUrl === "string" ? rawInstanceUrl : void 0
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/utils/oauth-connection.ts
|
|
52
|
-
/**
|
|
53
|
-
* Shopify OAuth connection configuration.
|
|
54
|
-
*
|
|
55
|
-
* Shopify's OAuth flow is per-shop: every handshake is scoped to a specific
|
|
56
|
-
* `{shop}.myshopify.com` domain that the user supplies up front. That shop
|
|
57
|
-
* domain shows up in three places that make Shopify different from a plain
|
|
58
|
-
* OAuth 2.0 integration:
|
|
59
|
-
*
|
|
60
|
-
* - `buildAuthUrl` must point at the shop-specific authorize endpoint at
|
|
61
|
-
* `https://{shop}.myshopify.com/admin/oauth/authorize`. The shop domain is
|
|
62
|
-
* threaded in from the initiate-connection request via `initiateInput`.
|
|
63
|
-
* - `exchangeCode` verifies the Shopify HMAC signature on the callback query
|
|
64
|
-
* string before trusting any of it, and POSTs to the same shop-specific
|
|
65
|
-
* token endpoint. HMAC verification uses `timingSafeEqual` to avoid leaking
|
|
66
|
-
* bytes through timing side channels.
|
|
67
|
-
* - `refreshToken` reads the shop domain out of `oauthClient.metadata` (set
|
|
68
|
-
* during the initial exchange) so proactive refreshes still target the
|
|
69
|
-
* right store, and the `vault` mapping promotes the shop domain into
|
|
70
|
-
* `SHOPIFY_STORE_DOMAIN` so the vault has both the access token and the
|
|
71
|
-
* store it belongs to.
|
|
72
|
-
*
|
|
73
|
-
* Shopify responds with JSON, so we reuse `parseOAuthTokenResponse` +
|
|
74
|
-
* `normalizeOAuthTokens` from `@keystrokehq/credential-connection` to avoid reimplementing
|
|
75
|
-
* the token-response plumbing.
|
|
76
|
-
*/
|
|
77
|
-
function normalizeShopifyShopDomain(raw) {
|
|
78
|
-
const trimmed = raw?.trim().toLowerCase();
|
|
79
|
-
if (!trimmed) throw new Error("Shopify requires a store domain.");
|
|
80
|
-
const normalized = trimmed.endsWith(".myshopify.com") ? trimmed : `${trimmed}.myshopify.com`;
|
|
81
|
-
if (!/^[a-z0-9][a-z0-9-]*\.myshopify\.com$/i.test(normalized)) throw new Error("Invalid Shopify store domain.");
|
|
82
|
-
return normalized;
|
|
83
|
-
}
|
|
84
|
-
function verifyShopifyCallbackHmac(queryParams, clientSecret) {
|
|
85
|
-
const receivedHmac = queryParams.hmac;
|
|
86
|
-
if (!receivedHmac) return false;
|
|
87
|
-
const canonical = Object.entries(queryParams).filter(([key]) => key !== "hmac" && key !== "signature").sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${key}=${value}`).join("&");
|
|
88
|
-
const expected = createHmac("sha256", clientSecret).update(canonical).digest("hex");
|
|
89
|
-
const received = Buffer.from(receivedHmac, "utf8");
|
|
90
|
-
const expectedBuffer = Buffer.from(expected, "utf8");
|
|
91
|
-
if (received.length !== expectedBuffer.length) return false;
|
|
92
|
-
return timingSafeEqual(received, expectedBuffer);
|
|
93
|
-
}
|
|
94
|
-
function resolveShopifyTokenUrl(shopDomain) {
|
|
95
|
-
return `https://${shopDomain}/admin/oauth/access_token`;
|
|
96
|
-
}
|
|
97
|
-
async function shopifyTokenPost(shopDomain, body, missingTokenError) {
|
|
98
|
-
const response = await fetch(resolveShopifyTokenUrl(shopDomain), {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: {
|
|
101
|
-
Accept: "application/json",
|
|
102
|
-
"Content-Type": "application/json"
|
|
103
|
-
},
|
|
104
|
-
body: JSON.stringify(body)
|
|
105
|
-
});
|
|
106
|
-
if (!response.ok) throw new TokenExchangeError(response.status);
|
|
107
|
-
const raw = await parseOAuthTokenResponse(response);
|
|
108
|
-
raw._shopifyShopDomain = shopDomain;
|
|
109
|
-
const { accessToken, refreshToken, expiresIn } = normalizeOAuthTokens(raw);
|
|
110
|
-
if (!accessToken) throw new Error(missingTokenError);
|
|
111
|
-
return {
|
|
112
|
-
accessToken,
|
|
113
|
-
refreshToken,
|
|
114
|
-
expiresIn,
|
|
115
|
-
raw
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
const shopifyOAuthConnection = {
|
|
119
|
-
kind: "oauth",
|
|
120
|
-
tokenType: "refreshable",
|
|
121
|
-
authUrl: "https://{shop}.myshopify.com/admin/oauth/authorize",
|
|
122
|
-
tokenUrl: "https://{shop}.myshopify.com/admin/oauth/access_token",
|
|
123
|
-
revokeUrl: null,
|
|
124
|
-
scopes: [
|
|
125
|
-
"read_products",
|
|
126
|
-
"write_products",
|
|
127
|
-
"read_orders",
|
|
128
|
-
"write_orders",
|
|
129
|
-
"read_customers",
|
|
130
|
-
"write_customers",
|
|
131
|
-
"read_inventory",
|
|
132
|
-
"write_inventory",
|
|
133
|
-
"read_locations",
|
|
134
|
-
"read_fulfillments",
|
|
135
|
-
"write_fulfillments",
|
|
136
|
-
"read_content",
|
|
137
|
-
"write_content",
|
|
138
|
-
"read_webhooks",
|
|
139
|
-
"write_webhooks"
|
|
140
|
-
],
|
|
141
|
-
vault: {
|
|
142
|
-
accessToken: "SHOPIFY_ACCESS_TOKEN",
|
|
143
|
-
raw: { SHOPIFY_STORE_DOMAIN: "_shopifyShopDomain" }
|
|
144
|
-
},
|
|
145
|
-
buildAuthUrl({ oauthClient, redirectUri, state, connection, initiateInput, requestedScopes }) {
|
|
146
|
-
const rawShopDomain = initiateInput?.shopDomain;
|
|
147
|
-
if (typeof rawShopDomain !== "string") throw new Error("Shopify requires a store domain.");
|
|
148
|
-
const scopes = requestedScopes ?? connection.scopes;
|
|
149
|
-
const shopDomain = normalizeShopifyShopDomain(rawShopDomain);
|
|
150
|
-
const url = new URL(`https://${shopDomain}/admin/oauth/authorize`);
|
|
151
|
-
url.searchParams.set("client_id", oauthClient.clientId);
|
|
152
|
-
url.searchParams.set("scope", scopes.join(","));
|
|
153
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
154
|
-
url.searchParams.set("state", state);
|
|
155
|
-
return url.toString();
|
|
156
|
-
},
|
|
157
|
-
async exchangeCode({ oauthClient, code, queryParams }) {
|
|
158
|
-
if (!code) throw new Error("Missing authorization code");
|
|
159
|
-
const shopDomain = normalizeShopifyShopDomain(queryParams.shop);
|
|
160
|
-
if (!verifyShopifyCallbackHmac(queryParams, oauthClient.clientSecret)) throw new Error("Invalid Shopify OAuth callback signature");
|
|
161
|
-
return shopifyTokenPost(shopDomain, {
|
|
162
|
-
client_id: oauthClient.clientId,
|
|
163
|
-
client_secret: oauthClient.clientSecret,
|
|
164
|
-
code
|
|
165
|
-
}, "No access token in Shopify response");
|
|
166
|
-
},
|
|
167
|
-
async refreshToken({ oauthClient, refreshToken }) {
|
|
168
|
-
const rawShopDomain = oauthClient.metadata?.shopDomain;
|
|
169
|
-
if (typeof rawShopDomain !== "string") throw new Error("Missing Shopify store domain for token refresh.");
|
|
170
|
-
return shopifyTokenPost(normalizeShopifyShopDomain(rawShopDomain), {
|
|
171
|
-
grant_type: "refresh_token",
|
|
172
|
-
refresh_token: refreshToken,
|
|
173
|
-
client_id: oauthClient.clientId,
|
|
174
|
-
client_secret: oauthClient.clientSecret
|
|
175
|
-
}, "No access token in Shopify refresh response");
|
|
176
|
-
},
|
|
177
|
-
extractInstallationInfo({ tokenResult }) {
|
|
178
|
-
const shopDomain = typeof tokenResult.raw._shopifyShopDomain === "string" ? tokenResult.raw._shopifyShopDomain : void 0;
|
|
179
|
-
return {
|
|
180
|
-
externalInstallationId: shopDomain,
|
|
181
|
-
externalWorkspaceId: shopDomain,
|
|
182
|
-
metadata: shopDomain ? { shopDomain } : void 0
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/credential-sets/shopify.credential-set.ts
|
|
189
|
-
const shopifyAuthSchema = z.object({
|
|
190
|
-
SHOPIFY_STORE_DOMAIN: shopifyStoreDomainSchema,
|
|
191
|
-
SHOPIFY_ACCESS_TOKEN: z.string().min(1)
|
|
192
|
-
});
|
|
193
|
-
const shopifyCredentialSet = new CredentialSet({
|
|
194
|
-
id: "shopify",
|
|
195
|
-
name: "Shopify",
|
|
196
|
-
description: "Shopify Admin API — stores, products, orders, customers, and webhooks",
|
|
197
|
-
auth: shopifyAuthSchema,
|
|
198
|
-
connections: [{
|
|
199
|
-
id: "oauth",
|
|
200
|
-
...shopifyOAuthConnection
|
|
201
|
-
}]
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
export { shopifyCredentialSet as t };
|