@caartzee/theme-sdk 1.2.2 → 1.2.3
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.
|
@@ -5,6 +5,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
6
|
|
|
7
7
|
// src/cli/sdk-client.ts
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
8
9
|
import { readFileSync as readFileSync2, readdirSync } from "node:fs";
|
|
9
10
|
import { join as join2 } from "node:path";
|
|
10
11
|
|
|
@@ -77,7 +78,12 @@ function parseSdkConnection(input) {
|
|
|
77
78
|
if (!value || typeof value !== "object" || !("format" in value) || value.format !== "caartzee-theme-sdk-v1" || !("api" in value) || typeof value.api !== "string" || !("token" in value) || typeof value.token !== "string" || !value.token.trim() || value.token.length > 8192) {
|
|
78
79
|
throw new Error("Copy a new SDK connection from Developer Portal > Theme SDK.");
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
+
const rawRefresh = "refreshToken" in value && typeof value.refreshToken === "string" ? value.refreshToken.trim() : undefined;
|
|
82
|
+
return {
|
|
83
|
+
api: sdkEndpoint(value.api),
|
|
84
|
+
token: value.token.trim(),
|
|
85
|
+
...rawRefresh ? { refreshToken: rawRefresh } : {}
|
|
86
|
+
};
|
|
81
87
|
}
|
|
82
88
|
async function sdkRequest(endpoint, token, query, variables = {}) {
|
|
83
89
|
const response = await fetch(sdkEndpoint(endpoint), {
|
|
@@ -91,7 +97,55 @@ async function sdkRequest(endpoint, token, query, variables = {}) {
|
|
|
91
97
|
throw new Error(result.errors?.map((e) => e.message).join("; ") || `SDK API returned HTTP ${response.status}`);
|
|
92
98
|
return result.data;
|
|
93
99
|
}
|
|
94
|
-
async function
|
|
100
|
+
async function refreshSdkCredentials(credentials) {
|
|
101
|
+
if (!credentials.refreshToken) {
|
|
102
|
+
throw new Error("SDK access token expired and no refresh token is stored. Reconnect via Developer Portal > Theme SDK (`caartzee-theme connect --clipboard`).");
|
|
103
|
+
}
|
|
104
|
+
const response = await fetch(sdkEndpoint(credentials.portalUrl), {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: { "Content-Type": "application/json" },
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
query: "mutation($refreshToken: String!) { refreshThemeSdkToken(refreshToken: $refreshToken) { token refreshToken expiresIn appId } }",
|
|
109
|
+
variables: { refreshToken: credentials.refreshToken }
|
|
110
|
+
}),
|
|
111
|
+
signal: AbortSignal.timeout(30000)
|
|
112
|
+
});
|
|
113
|
+
const result = await response.json();
|
|
114
|
+
const refreshed = result.data?.refreshThemeSdkToken;
|
|
115
|
+
if (!response.ok || result.errors?.length || !refreshed?.token) {
|
|
116
|
+
throw new Error(result.errors?.map((e) => e.message).join("; ") || `Failed to refresh SDK token (HTTP ${response.status}). Copy a new SDK connection from Developer Portal > Theme SDK.`);
|
|
117
|
+
}
|
|
118
|
+
const updated = {
|
|
119
|
+
...credentials,
|
|
120
|
+
accessToken: refreshed.token,
|
|
121
|
+
refreshToken: refreshed.refreshToken || credentials.refreshToken,
|
|
122
|
+
expiresAt: Date.now() + refreshed.expiresIn * 1000,
|
|
123
|
+
savedAt: new Date().toISOString()
|
|
124
|
+
};
|
|
125
|
+
saveDeveloperCredentials(updated);
|
|
126
|
+
return updated;
|
|
127
|
+
}
|
|
128
|
+
var REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
129
|
+
async function sdkRequestWithAutoRefresh(credentials, query, variables = {}) {
|
|
130
|
+
let active = credentials;
|
|
131
|
+
if (typeof active.expiresAt === "number" && active.expiresAt - Date.now() <= REFRESH_BUFFER_MS && active.refreshToken) {
|
|
132
|
+
active = await refreshSdkCredentials(active);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const data = await sdkRequest(active.portalUrl, active.accessToken, query, variables);
|
|
136
|
+
return { data, credentials: active };
|
|
137
|
+
} catch (err) {
|
|
138
|
+
const msg = String(err?.message || "");
|
|
139
|
+
const isAuthExpired = /expired|invalid.*token|unauthorized|401/i.test(msg);
|
|
140
|
+
if (isAuthExpired && active.refreshToken) {
|
|
141
|
+
active = await refreshSdkCredentials(active);
|
|
142
|
+
const data = await sdkRequest(active.portalUrl, active.accessToken, query, variables);
|
|
143
|
+
return { data, credentials: active };
|
|
144
|
+
}
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function connectSdk(endpoint, token, refreshToken) {
|
|
95
149
|
const data = await sdkRequest(endpoint, token, "query { themeSdkWorkspace { appId developerId name expiresAt } }");
|
|
96
150
|
const app = data.themeSdkWorkspace;
|
|
97
151
|
const credentials = {
|
|
@@ -100,6 +154,7 @@ async function connectSdk(endpoint, token) {
|
|
|
100
154
|
email: "",
|
|
101
155
|
name: app.name,
|
|
102
156
|
accessToken: token,
|
|
157
|
+
...refreshToken ? { refreshToken } : {},
|
|
103
158
|
expiresAt: app.expiresAt * 1000,
|
|
104
159
|
scopes: ["theme:read", "theme:write"],
|
|
105
160
|
portalUrl: sdkEndpoint(endpoint),
|
|
@@ -108,6 +163,10 @@ async function connectSdk(endpoint, token) {
|
|
|
108
163
|
saveDeveloperCredentials(credentials);
|
|
109
164
|
return credentials;
|
|
110
165
|
}
|
|
166
|
+
function computeCanonicalPackageChecksum(files) {
|
|
167
|
+
const canonical = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
168
|
+
return createHash("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
169
|
+
}
|
|
111
170
|
function collectThemeSources(root) {
|
|
112
171
|
const files = [];
|
|
113
172
|
let total = 0;
|
|
@@ -1884,7 +1943,7 @@ async function scaffoldCommerceTheme(options) {
|
|
|
1884
1943
|
return { success: true, themeSlug: slug, themeName: name, slug, name, targetDir: target, createdFiles };
|
|
1885
1944
|
}
|
|
1886
1945
|
// src/auth/oauth-client.ts
|
|
1887
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
1946
|
+
import { createHash as createHash2, randomBytes } from "node:crypto";
|
|
1888
1947
|
import { createServer } from "node:http";
|
|
1889
1948
|
var DEFAULT_PORTAL_URL = "https://partners.caartzee.com";
|
|
1890
1949
|
var DEFAULT_CLIENT_ID = "caartzee-theme-cli";
|
|
@@ -1892,7 +1951,7 @@ var DEFAULT_REDIRECT_PORT = 8484;
|
|
|
1892
1951
|
var DEFAULT_SCOPES = ["theme:read", "theme:write", "theme:publish"];
|
|
1893
1952
|
function generatePkcePair() {
|
|
1894
1953
|
const codeVerifier = randomBytes(32).toString("base64url");
|
|
1895
|
-
const codeChallenge =
|
|
1954
|
+
const codeChallenge = createHash2("sha256").update(codeVerifier).digest("base64url");
|
|
1896
1955
|
const state = randomBytes(24).toString("base64url");
|
|
1897
1956
|
return {
|
|
1898
1957
|
codeVerifier,
|
|
@@ -5190,6 +5249,9 @@ function buildCandyContext(options) {
|
|
|
5190
5249
|
const currencySymbol = String(anyCtx.currencyInfo?.symbol || mergedSettings.currencySymbol || "$");
|
|
5191
5250
|
const currencyCode = String(anyCtx.currencyInfo?.code || anyCtx.currencyInfo?.currency || mergedSettings.currency || "USD");
|
|
5192
5251
|
const currencyPosition = anyCtx.currencyInfo?.currencyPosition === "right" ? "right" : "left";
|
|
5252
|
+
const bootstrapPayment = anyCtx.bootstrap?.payment;
|
|
5253
|
+
const bootstrapGateways = Array.isArray(bootstrapPayment?.gateways) ? bootstrapPayment.gateways : [];
|
|
5254
|
+
const magicCheckoutEnabled = Boolean(bootstrapPayment?.magicCheckout === true || bootstrapPayment?.magic_checkout === true || bootstrapGateways.some((gw) => gw && String(gw.name || "").toLowerCase() === "razorpay" && gw.enabled !== false && Boolean(gw.magicCheckout || gw.magic_checkout || gw.config?.magicCheckout || gw.config?.magic_checkout)));
|
|
5193
5255
|
const shop = {
|
|
5194
5256
|
name: storeName,
|
|
5195
5257
|
description: String(anyCtx.siteSettings?.siteTagline || pageContext.seo?.description || ""),
|
|
@@ -5205,7 +5267,13 @@ function buildCandyContext(options) {
|
|
|
5205
5267
|
secure_url: "/",
|
|
5206
5268
|
domain: pageContext.tenantId || "localhost",
|
|
5207
5269
|
permanent_domain: pageContext.tenantId || "localhost",
|
|
5208
|
-
logo_url: anyCtx.siteSettings?.logoUrl || mergedSettings.logoUrl || null
|
|
5270
|
+
logo_url: anyCtx.siteSettings?.logoUrl || mergedSettings.logoUrl || null,
|
|
5271
|
+
magic_checkout_enabled: magicCheckoutEnabled,
|
|
5272
|
+
payment_gateways: bootstrapGateways.filter((gw) => gw && gw.enabled !== false).map((gw) => ({
|
|
5273
|
+
name: String(gw.name || ""),
|
|
5274
|
+
enabled: gw.enabled !== false,
|
|
5275
|
+
magic_checkout: Boolean(gw.magicCheckout || gw.magic_checkout || gw.config?.magicCheckout || gw.config?.magic_checkout)
|
|
5276
|
+
}))
|
|
5209
5277
|
};
|
|
5210
5278
|
const rawProducts = anyCtx.products || anyCtx.featuredProducts || anyCtx.results?.products || (anyCtx.product ? [anyCtx.product] : []);
|
|
5211
5279
|
const normalizedProducts = rawProducts.map(normalizeProductForCandy);
|
|
@@ -8630,7 +8698,7 @@ function validateThemeEditorDirectory(themeDir) {
|
|
|
8630
8698
|
}
|
|
8631
8699
|
|
|
8632
8700
|
// src/cli/mcp/testing-tools.ts
|
|
8633
|
-
import { createHash as
|
|
8701
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
8634
8702
|
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "node:fs";
|
|
8635
8703
|
import { join as join10, resolve as resolve8 } from "node:path";
|
|
8636
8704
|
import { z as z5 } from "zod";
|
|
@@ -8643,11 +8711,11 @@ async function runThemeReadinessAudit(themeDir) {
|
|
|
8643
8711
|
};
|
|
8644
8712
|
let slug = "unknown";
|
|
8645
8713
|
let version = "0.0.0";
|
|
8646
|
-
let packageHash =
|
|
8714
|
+
let packageHash = createHash3("sha256").update(dir).digest("hex");
|
|
8647
8715
|
try {
|
|
8648
8716
|
const files = collectThemeSources(dir);
|
|
8649
8717
|
const canonical = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
8650
|
-
packageHash =
|
|
8718
|
+
packageHash = createHash3("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
8651
8719
|
} catch {}
|
|
8652
8720
|
const pkg = await ThemePackageValidator.validatePackage(dir);
|
|
8653
8721
|
if (pkg.manifest) {
|
|
@@ -8864,9 +8932,9 @@ async function runCli(rawArgs, io = {}) {
|
|
|
8864
8932
|
} else {
|
|
8865
8933
|
throw new Error("Use connect --clipboard on Windows or pipe the copied SDK connection to connect --stdin.");
|
|
8866
8934
|
}
|
|
8867
|
-
const { api, token } = parseSdkConnection(input);
|
|
8868
|
-
const credentials = await connectSdk(api, token);
|
|
8869
|
-
log(`Connected to ${credentials.name || "your theme app"}. SDK access expires in one hour
|
|
8935
|
+
const { api, token, refreshToken } = parseSdkConnection(input);
|
|
8936
|
+
const credentials = await connectSdk(api, token, refreshToken);
|
|
8937
|
+
log(`Connected to ${credentials.name || "your theme app"}.${refreshToken ? " Auto-refresh enabled (30-day session)." : " SDK access expires in one hour."}`);
|
|
8870
8938
|
return 0;
|
|
8871
8939
|
}
|
|
8872
8940
|
case "login":
|
|
@@ -9305,7 +9373,22 @@ async function handlePush(args, log, error) {
|
|
|
9305
9373
|
if (!creds.appId)
|
|
9306
9374
|
throw new Error("Generate app SDK access in the developer portal and login with --token-stdin.");
|
|
9307
9375
|
const files = collectThemeSources(targetDir);
|
|
9308
|
-
const
|
|
9376
|
+
const checksum = computeCanonicalPackageChecksum(files);
|
|
9377
|
+
const { data: result, credentials: freshCreds } = await sdkRequestWithAutoRefresh(creds, "mutation SubmitTheme($files: [ThemeSourceFileInput!]!) { submitDeveloperTheme(files: $files) { version status checksum } }", { files });
|
|
9378
|
+
try {
|
|
9379
|
+
const report = await runThemeReadinessAudit(targetDir);
|
|
9380
|
+
await sdkRequestWithAutoRefresh(freshCreds, "mutation($themeSlug:String!,$themeVersion:String!,$packageHash:String!,$sdkVersion:String,$runtimeVersion:String,$status:String!,$summary:JSON!,$report:JSON!){saveThemeSdkTestReport(themeSlug:$themeSlug,themeVersion:$themeVersion,packageHash:$packageHash,sdkVersion:$sdkVersion,runtimeVersion:$runtimeVersion,status:$status,summary:$summary,report:$report){id status packageHash}}", {
|
|
9381
|
+
themeSlug: report.slug,
|
|
9382
|
+
themeVersion: result.submitDeveloperTheme.version,
|
|
9383
|
+
packageHash: result.submitDeveloperTheme.checksum || checksum,
|
|
9384
|
+
sdkVersion: report.sdkVersion,
|
|
9385
|
+
runtimeVersion: report.runtimeVersion,
|
|
9386
|
+
status: report.status,
|
|
9387
|
+
summary: report.summary,
|
|
9388
|
+
report
|
|
9389
|
+
});
|
|
9390
|
+
log(`✓ Attached local readiness report to checksum ${result.submitDeveloperTheme.checksum}.`);
|
|
9391
|
+
} catch {}
|
|
9309
9392
|
log("Submitted version " + result.submitDeveloperTheme.version + ": " + result.submitDeveloperTheme.status + ". Checksum: " + result.submitDeveloperTheme.checksum);
|
|
9310
9393
|
log(`✓ Security validation passed.`);
|
|
9311
9394
|
log(`✓ Authenticated as ${creds.email} (Developer ID: ${creds.developerId})`);
|
package/dist/lib/index.js
CHANGED
|
@@ -3132,6 +3132,9 @@ function buildCandyContext(options) {
|
|
|
3132
3132
|
const currencySymbol = String(anyCtx.currencyInfo?.symbol || mergedSettings.currencySymbol || "$");
|
|
3133
3133
|
const currencyCode = String(anyCtx.currencyInfo?.code || anyCtx.currencyInfo?.currency || mergedSettings.currency || "USD");
|
|
3134
3134
|
const currencyPosition = anyCtx.currencyInfo?.currencyPosition === "right" ? "right" : "left";
|
|
3135
|
+
const bootstrapPayment = anyCtx.bootstrap?.payment;
|
|
3136
|
+
const bootstrapGateways = Array.isArray(bootstrapPayment?.gateways) ? bootstrapPayment.gateways : [];
|
|
3137
|
+
const magicCheckoutEnabled = Boolean(bootstrapPayment?.magicCheckout === true || bootstrapPayment?.magic_checkout === true || bootstrapGateways.some((gw) => gw && String(gw.name || "").toLowerCase() === "razorpay" && gw.enabled !== false && Boolean(gw.magicCheckout || gw.magic_checkout || gw.config?.magicCheckout || gw.config?.magic_checkout)));
|
|
3135
3138
|
const shop = {
|
|
3136
3139
|
name: storeName,
|
|
3137
3140
|
description: String(anyCtx.siteSettings?.siteTagline || pageContext.seo?.description || ""),
|
|
@@ -3147,7 +3150,13 @@ function buildCandyContext(options) {
|
|
|
3147
3150
|
secure_url: "/",
|
|
3148
3151
|
domain: pageContext.tenantId || "localhost",
|
|
3149
3152
|
permanent_domain: pageContext.tenantId || "localhost",
|
|
3150
|
-
logo_url: anyCtx.siteSettings?.logoUrl || mergedSettings.logoUrl || null
|
|
3153
|
+
logo_url: anyCtx.siteSettings?.logoUrl || mergedSettings.logoUrl || null,
|
|
3154
|
+
magic_checkout_enabled: magicCheckoutEnabled,
|
|
3155
|
+
payment_gateways: bootstrapGateways.filter((gw) => gw && gw.enabled !== false).map((gw) => ({
|
|
3156
|
+
name: String(gw.name || ""),
|
|
3157
|
+
enabled: gw.enabled !== false,
|
|
3158
|
+
magic_checkout: Boolean(gw.magicCheckout || gw.magic_checkout || gw.config?.magicCheckout || gw.config?.magic_checkout)
|
|
3159
|
+
}))
|
|
3151
3160
|
};
|
|
3152
3161
|
const rawProducts = anyCtx.products || anyCtx.featuredProducts || anyCtx.results?.products || (anyCtx.product ? [anyCtx.product] : []);
|
|
3153
3162
|
const normalizedProducts = rawProducts.map(normalizeProductForCandy);
|
|
@@ -10656,6 +10665,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
10656
10665
|
import { execFileSync } from "node:child_process";
|
|
10657
10666
|
|
|
10658
10667
|
// src/cli/sdk-client.ts
|
|
10668
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
10659
10669
|
import { readFileSync as readFileSync8, readdirSync as readdirSync5 } from "node:fs";
|
|
10660
10670
|
import { join as join8 } from "node:path";
|
|
10661
10671
|
function sdkEndpoint(value) {
|
|
@@ -10679,7 +10689,12 @@ function parseSdkConnection(input) {
|
|
|
10679
10689
|
if (!value || typeof value !== "object" || !("format" in value) || value.format !== "caartzee-theme-sdk-v1" || !("api" in value) || typeof value.api !== "string" || !("token" in value) || typeof value.token !== "string" || !value.token.trim() || value.token.length > 8192) {
|
|
10680
10690
|
throw new Error("Copy a new SDK connection from Developer Portal > Theme SDK.");
|
|
10681
10691
|
}
|
|
10682
|
-
|
|
10692
|
+
const rawRefresh = "refreshToken" in value && typeof value.refreshToken === "string" ? value.refreshToken.trim() : undefined;
|
|
10693
|
+
return {
|
|
10694
|
+
api: sdkEndpoint(value.api),
|
|
10695
|
+
token: value.token.trim(),
|
|
10696
|
+
...rawRefresh ? { refreshToken: rawRefresh } : {}
|
|
10697
|
+
};
|
|
10683
10698
|
}
|
|
10684
10699
|
async function sdkRequest(endpoint, token, query, variables = {}) {
|
|
10685
10700
|
const response = await fetch(sdkEndpoint(endpoint), {
|
|
@@ -10693,7 +10708,55 @@ async function sdkRequest(endpoint, token, query, variables = {}) {
|
|
|
10693
10708
|
throw new Error(result.errors?.map((e) => e.message).join("; ") || `SDK API returned HTTP ${response.status}`);
|
|
10694
10709
|
return result.data;
|
|
10695
10710
|
}
|
|
10696
|
-
async function
|
|
10711
|
+
async function refreshSdkCredentials(credentials) {
|
|
10712
|
+
if (!credentials.refreshToken) {
|
|
10713
|
+
throw new Error("SDK access token expired and no refresh token is stored. Reconnect via Developer Portal > Theme SDK (`caartzee-theme connect --clipboard`).");
|
|
10714
|
+
}
|
|
10715
|
+
const response = await fetch(sdkEndpoint(credentials.portalUrl), {
|
|
10716
|
+
method: "POST",
|
|
10717
|
+
headers: { "Content-Type": "application/json" },
|
|
10718
|
+
body: JSON.stringify({
|
|
10719
|
+
query: "mutation($refreshToken: String!) { refreshThemeSdkToken(refreshToken: $refreshToken) { token refreshToken expiresIn appId } }",
|
|
10720
|
+
variables: { refreshToken: credentials.refreshToken }
|
|
10721
|
+
}),
|
|
10722
|
+
signal: AbortSignal.timeout(30000)
|
|
10723
|
+
});
|
|
10724
|
+
const result = await response.json();
|
|
10725
|
+
const refreshed = result.data?.refreshThemeSdkToken;
|
|
10726
|
+
if (!response.ok || result.errors?.length || !refreshed?.token) {
|
|
10727
|
+
throw new Error(result.errors?.map((e) => e.message).join("; ") || `Failed to refresh SDK token (HTTP ${response.status}). Copy a new SDK connection from Developer Portal > Theme SDK.`);
|
|
10728
|
+
}
|
|
10729
|
+
const updated = {
|
|
10730
|
+
...credentials,
|
|
10731
|
+
accessToken: refreshed.token,
|
|
10732
|
+
refreshToken: refreshed.refreshToken || credentials.refreshToken,
|
|
10733
|
+
expiresAt: Date.now() + refreshed.expiresIn * 1000,
|
|
10734
|
+
savedAt: new Date().toISOString()
|
|
10735
|
+
};
|
|
10736
|
+
saveDeveloperCredentials(updated);
|
|
10737
|
+
return updated;
|
|
10738
|
+
}
|
|
10739
|
+
var REFRESH_BUFFER_MS = 5 * 60 * 1000;
|
|
10740
|
+
async function sdkRequestWithAutoRefresh(credentials, query, variables = {}) {
|
|
10741
|
+
let active = credentials;
|
|
10742
|
+
if (typeof active.expiresAt === "number" && active.expiresAt - Date.now() <= REFRESH_BUFFER_MS && active.refreshToken) {
|
|
10743
|
+
active = await refreshSdkCredentials(active);
|
|
10744
|
+
}
|
|
10745
|
+
try {
|
|
10746
|
+
const data = await sdkRequest(active.portalUrl, active.accessToken, query, variables);
|
|
10747
|
+
return { data, credentials: active };
|
|
10748
|
+
} catch (err) {
|
|
10749
|
+
const msg = String(err?.message || "");
|
|
10750
|
+
const isAuthExpired = /expired|invalid.*token|unauthorized|401/i.test(msg);
|
|
10751
|
+
if (isAuthExpired && active.refreshToken) {
|
|
10752
|
+
active = await refreshSdkCredentials(active);
|
|
10753
|
+
const data = await sdkRequest(active.portalUrl, active.accessToken, query, variables);
|
|
10754
|
+
return { data, credentials: active };
|
|
10755
|
+
}
|
|
10756
|
+
throw err;
|
|
10757
|
+
}
|
|
10758
|
+
}
|
|
10759
|
+
async function connectSdk(endpoint, token, refreshToken) {
|
|
10697
10760
|
const data = await sdkRequest(endpoint, token, "query { themeSdkWorkspace { appId developerId name expiresAt } }");
|
|
10698
10761
|
const app = data.themeSdkWorkspace;
|
|
10699
10762
|
const credentials = {
|
|
@@ -10702,6 +10765,7 @@ async function connectSdk(endpoint, token) {
|
|
|
10702
10765
|
email: "",
|
|
10703
10766
|
name: app.name,
|
|
10704
10767
|
accessToken: token,
|
|
10768
|
+
...refreshToken ? { refreshToken } : {},
|
|
10705
10769
|
expiresAt: app.expiresAt * 1000,
|
|
10706
10770
|
scopes: ["theme:read", "theme:write"],
|
|
10707
10771
|
portalUrl: sdkEndpoint(endpoint),
|
|
@@ -10710,6 +10774,10 @@ async function connectSdk(endpoint, token) {
|
|
|
10710
10774
|
saveDeveloperCredentials(credentials);
|
|
10711
10775
|
return credentials;
|
|
10712
10776
|
}
|
|
10777
|
+
function computeCanonicalPackageChecksum(files) {
|
|
10778
|
+
const canonical = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
10779
|
+
return createHash2("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
10780
|
+
}
|
|
10713
10781
|
function collectThemeSources(root) {
|
|
10714
10782
|
const files = [];
|
|
10715
10783
|
let total = 0;
|
|
@@ -10843,7 +10911,7 @@ function validateThemeEditorDirectory(themeDir) {
|
|
|
10843
10911
|
}
|
|
10844
10912
|
|
|
10845
10913
|
// src/cli/mcp/testing-tools.ts
|
|
10846
|
-
import { createHash as
|
|
10914
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
10847
10915
|
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "node:fs";
|
|
10848
10916
|
import { join as join10, resolve as resolve8 } from "node:path";
|
|
10849
10917
|
import { z as z7 } from "zod";
|
|
@@ -10856,11 +10924,11 @@ async function runThemeReadinessAudit(themeDir) {
|
|
|
10856
10924
|
};
|
|
10857
10925
|
let slug = "unknown";
|
|
10858
10926
|
let version = "0.0.0";
|
|
10859
|
-
let packageHash =
|
|
10927
|
+
let packageHash = createHash3("sha256").update(dir).digest("hex");
|
|
10860
10928
|
try {
|
|
10861
10929
|
const files = collectThemeSources(dir);
|
|
10862
10930
|
const canonical = [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
10863
|
-
packageHash =
|
|
10931
|
+
packageHash = createHash3("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
10864
10932
|
} catch {}
|
|
10865
10933
|
const pkg = await ThemePackageValidator.validatePackage(dir);
|
|
10866
10934
|
if (pkg.manifest) {
|
|
@@ -11077,9 +11145,9 @@ async function runCli(rawArgs, io = {}) {
|
|
|
11077
11145
|
} else {
|
|
11078
11146
|
throw new Error("Use connect --clipboard on Windows or pipe the copied SDK connection to connect --stdin.");
|
|
11079
11147
|
}
|
|
11080
|
-
const { api, token } = parseSdkConnection(input);
|
|
11081
|
-
const credentials = await connectSdk(api, token);
|
|
11082
|
-
log(`Connected to ${credentials.name || "your theme app"}. SDK access expires in one hour
|
|
11148
|
+
const { api, token, refreshToken } = parseSdkConnection(input);
|
|
11149
|
+
const credentials = await connectSdk(api, token, refreshToken);
|
|
11150
|
+
log(`Connected to ${credentials.name || "your theme app"}.${refreshToken ? " Auto-refresh enabled (30-day session)." : " SDK access expires in one hour."}`);
|
|
11083
11151
|
return 0;
|
|
11084
11152
|
}
|
|
11085
11153
|
case "login":
|
|
@@ -11518,7 +11586,22 @@ async function handlePush(args, log, error) {
|
|
|
11518
11586
|
if (!creds.appId)
|
|
11519
11587
|
throw new Error("Generate app SDK access in the developer portal and login with --token-stdin.");
|
|
11520
11588
|
const files = collectThemeSources(targetDir);
|
|
11521
|
-
const
|
|
11589
|
+
const checksum = computeCanonicalPackageChecksum(files);
|
|
11590
|
+
const { data: result, credentials: freshCreds } = await sdkRequestWithAutoRefresh(creds, "mutation SubmitTheme($files: [ThemeSourceFileInput!]!) { submitDeveloperTheme(files: $files) { version status checksum } }", { files });
|
|
11591
|
+
try {
|
|
11592
|
+
const report = await runThemeReadinessAudit(targetDir);
|
|
11593
|
+
await sdkRequestWithAutoRefresh(freshCreds, "mutation($themeSlug:String!,$themeVersion:String!,$packageHash:String!,$sdkVersion:String,$runtimeVersion:String,$status:String!,$summary:JSON!,$report:JSON!){saveThemeSdkTestReport(themeSlug:$themeSlug,themeVersion:$themeVersion,packageHash:$packageHash,sdkVersion:$sdkVersion,runtimeVersion:$runtimeVersion,status:$status,summary:$summary,report:$report){id status packageHash}}", {
|
|
11594
|
+
themeSlug: report.slug,
|
|
11595
|
+
themeVersion: result.submitDeveloperTheme.version,
|
|
11596
|
+
packageHash: result.submitDeveloperTheme.checksum || checksum,
|
|
11597
|
+
sdkVersion: report.sdkVersion,
|
|
11598
|
+
runtimeVersion: report.runtimeVersion,
|
|
11599
|
+
status: report.status,
|
|
11600
|
+
summary: report.summary,
|
|
11601
|
+
report
|
|
11602
|
+
});
|
|
11603
|
+
log(`✓ Attached local readiness report to checksum ${result.submitDeveloperTheme.checksum}.`);
|
|
11604
|
+
} catch {}
|
|
11522
11605
|
log("Submitted version " + result.submitDeveloperTheme.version + ": " + result.submitDeveloperTheme.status + ". Checksum: " + result.submitDeveloperTheme.checksum);
|
|
11523
11606
|
log(`✓ Security validation passed.`);
|
|
11524
11607
|
log(`✓ Authenticated as ${creds.email} (Developer ID: ${creds.developerId})`);
|
|
@@ -35,5 +35,6 @@ export interface CandyToolServerOperations extends TestingOperations {
|
|
|
35
35
|
}) => Promise<unknown>;
|
|
36
36
|
workspace?: () => Promise<unknown>;
|
|
37
37
|
themeVersions?: () => Promise<unknown>;
|
|
38
|
+
versionSummary?: () => Promise<unknown>;
|
|
38
39
|
}
|
|
39
40
|
export declare function candyToolServer(operations: CandyToolServerOperations): McpServer;
|
|
@@ -19,4 +19,7 @@ export declare function validateThemeEditorDirectory(themeDir: string): {
|
|
|
19
19
|
warnings: number;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export interface EditorToolsOptions {
|
|
23
|
+
saveTestReport?: ((report: any) => Promise<unknown>) | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare function registerEditorTools(server: McpServer, options?: EditorToolsOptions): void;
|
|
@@ -3,9 +3,19 @@ export declare function sdkEndpoint(value: string): string;
|
|
|
3
3
|
export declare function parseSdkConnection(input: string): {
|
|
4
4
|
api: string;
|
|
5
5
|
token: string;
|
|
6
|
+
refreshToken?: string;
|
|
6
7
|
};
|
|
7
8
|
export declare function sdkRequest<T>(endpoint: string, token: string, query: string, variables?: {}): Promise<T>;
|
|
8
|
-
export declare function
|
|
9
|
+
export declare function refreshSdkCredentials(credentials: DeveloperCredentials): Promise<DeveloperCredentials>;
|
|
10
|
+
export declare function sdkRequestWithAutoRefresh<T>(credentials: DeveloperCredentials, query: string, variables?: Record<string, unknown>): Promise<{
|
|
11
|
+
data: T;
|
|
12
|
+
credentials: DeveloperCredentials;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function connectSdk(endpoint: string, token: string, refreshToken?: string): Promise<DeveloperCredentials>;
|
|
15
|
+
export declare function computeCanonicalPackageChecksum(files: {
|
|
16
|
+
path: string;
|
|
17
|
+
content: string;
|
|
18
|
+
}[]): string;
|
|
9
19
|
export declare function collectThemeSources(root: string): {
|
|
10
20
|
path: string;
|
|
11
21
|
content: string;
|