@tanqory/partner-cli 0.1.0-alpha.2 → 0.1.0-alpha.6
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/config/third-party-toolchains.json +18 -4
- package/lib/api.mjs +56 -0
- package/lib/check.mjs +25 -1
- package/lib/cli.mjs +52 -3
- package/lib/extensions.mjs +188 -0
- package/lib/mcp.mjs +23 -1
- package/lib/ops.mjs +61 -1
- package/lib/theme.mjs +16 -2
- package/lib/vendor/partner-checks.cjs +2528 -310
- package/package.json +3 -6
- package/starter/package.json +2 -2
- package/starter/scripts/build.mjs +13 -2
- package/starter/src/sections/commerce.tsx +12 -2
- package/starter/src/sections/editorial.tsx +7 -2
- package/starter/src/styles/theme.css +6 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$comment": "Third-party build lane (rebuild/_program/theme-dev-mcp/P5-PLAN.md \u00a74): the @tanqory/theme-kit versions the theme-builder-3p image carries, one full toolchain each at /opt/toolchains/kit-<version>/node_modules (the same esbuild-wasm, react, react-dom, @tanqory/theme-abi and tar as the first-party toolchain; only the kit differs). A theme selects one by its exact @tanqory/theme-kit pin; a theme that names none gets the default toolchain (/opt/toolchain/node_modules, the first-party one). A pin not listed here fails the build `kind: theme` naming the versions that are. Every 2.x alpha a hosted build can fetch without a credential (2026-11-14): 2.0.0-alpha.3 and 2.0.0-alpha.5 from npmjs, with the integrity of their registry tarball, and 2.0.0-alpha.
|
|
2
|
+
"$comment": "Third-party build lane (rebuild/_program/theme-dev-mcp/P5-PLAN.md \u00a74): the @tanqory/theme-kit versions the theme-builder-3p image carries, one full toolchain each at /opt/toolchains/kit-<version>/node_modules (the same esbuild-wasm, react, react-dom, @tanqory/theme-abi and tar as the first-party toolchain; only the kit differs). A theme selects one by its exact @tanqory/theme-kit pin; a theme that names none gets the default toolchain (/opt/toolchain/node_modules, the first-party one). A pin not listed here fails the build `kind: theme` naming the versions that are. Every 2.x alpha a hosted build can fetch without a credential (2026-11-14): 2.0.0-alpha.3 and 2.0.0-alpha.5 from npmjs, with the integrity of their registry tarball, and 2.0.0-alpha.19 as `pack`, this repository's packages/theme-kit built and packed in the image (the first-party builder's own kit); the other alphas exist only in GitHub Packages, which this repository's CI cannot read (DECISIONS row 147). Checked inside the image build by scripts/verify-kit-toolchains.mjs. Reviewed change only (CODEOWNERS config/). `starter` (D18, option a): the extra packages a STARTER build runs with \u2014 `npm create tanqory-theme` templates build with their own declared build file (package.json `tanqory.build`) under vite; the image carries one starter toolchain per kit at /opt/starter-toolchains/kit-<version>/node_modules = that kit + these exact versions, integrity-pinned; an entry with `pack` instead of `integrity` is a package of this repository (@tanqory/theme-abi, packages/theme-abi): the image builds and packs it, the same pack the default toolchain installs, and its locked integrity must be that pack's. A theme that pins another @tanqory/theme-abi fails `theme`, except an alias of `starter.abiAliases` (below). `starter.overrides`: transitive packages pinned over what a starter package asks for (pnpm overrides): esbuild 0.28.2 (the BASE toolchain's esbuild-wasm version) instead of vite 5.4.21's esbuild ^0.21.3, whose Go binary carries fixable CRITICALs (CVE-2024-24790, CVE-2025-68121; Trivy, theme-sandbox workflow 2026-11-14), which INFRA_STANDARD 7.2 refuses. Aliases (lane BLD 2026-11-25, E2E2 E2-08): a kit entry with `aliasOf` (no pack, integrity or gitHead) is a pin the image accepts and builds with the toolchain of the kit it names, which must be a `pack` kit of this file; the image makes /opt/toolchains/kit-<alias> and /opt/starter-toolchains/kit-<alias> symbolic links to that kit's directories, so the build runs with exactly that kit. `starter.abiAliases`: a @tanqory/theme-abi pin a starter build accepts in place of the starter toolchain's theme-abi it names (the image writes them to abi-aliases.json beside each starter toolchain's node_modules; build-entry.mjs reads it). Why: npmjs holds @tanqory/theme-kit 2.0.0-alpha.17 and @tanqory/theme-abi 2.0.0-alpha.14 as published on 2026-11-15, and the repository's packages kept changing under those numbers (APP_BLOCKS and dist/app-blocks.* among them); the image always built 2.0.0-alpha.17 from this repository. The versions were bumped (kit 2.0.0-alpha.18, theme-abi 2.0.0-alpha.15, frozen in tools/guards/published-packages.json; kit 2.0.0-alpha.19 on 2026-11-25, lane LOC117, for the store locations and opening hours of storefront-query rev 2.73, with 2.0.0-alpha.18 an alias of it), and partner themes already uploaded pin 2.0.0-alpha.17 / 2.0.0-alpha.14 (one on Prod), so those pins keep building exactly as before: with this repository's current kit and theme-abi. Checked in the image build by scripts/verify-kit-toolchains.mjs (the alias is a link to the named pack kit; abi-aliases.json equals this list; an alias targets the carried theme-abi). Remove an alias only when no stored theme source pins it.",
|
|
3
3
|
"kits": [
|
|
4
4
|
{
|
|
5
5
|
"version": "2.0.0-alpha.3",
|
|
@@ -11,17 +11,25 @@
|
|
|
11
11
|
"gitHead": "aaa218c6582742086959e60fca8deaecf5f19059",
|
|
12
12
|
"integrity": "sha512-B+MPk8BBhRSnYIKUV+ObGy6jiCrX0IspqS00pl8Ocv+BqZj4RRvERWquvzN0ZYxO3gkdDdJXz7WZqsLWylAhjQ=="
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
"version": "2.0.0-alpha.19",
|
|
16
|
+
"pack": "tanqory-theme-kit-2.0.0-alpha.19.tgz"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"version": "2.0.0-alpha.18",
|
|
20
|
+
"aliasOf": "2.0.0-alpha.19"
|
|
21
|
+
},
|
|
14
22
|
{
|
|
15
23
|
"version": "2.0.0-alpha.17",
|
|
16
|
-
"
|
|
24
|
+
"aliasOf": "2.0.0-alpha.19"
|
|
17
25
|
}
|
|
18
26
|
],
|
|
19
27
|
"starter": {
|
|
20
28
|
"packages": [
|
|
21
29
|
{
|
|
22
30
|
"name": "@tanqory/theme-abi",
|
|
23
|
-
"version": "2.0.0-alpha.
|
|
24
|
-
"pack": "tanqory-theme-abi-2.0.0-alpha.
|
|
31
|
+
"version": "2.0.0-alpha.15",
|
|
32
|
+
"pack": "tanqory-theme-abi-2.0.0-alpha.15.tgz"
|
|
25
33
|
},
|
|
26
34
|
{
|
|
27
35
|
"name": "vite",
|
|
@@ -34,6 +42,12 @@
|
|
|
34
42
|
"integrity": "sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA=="
|
|
35
43
|
}
|
|
36
44
|
],
|
|
45
|
+
"abiAliases": [
|
|
46
|
+
{
|
|
47
|
+
"version": "2.0.0-alpha.14",
|
|
48
|
+
"aliasOf": "2.0.0-alpha.15"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
37
51
|
"overrides": [
|
|
38
52
|
{
|
|
39
53
|
"name": "esbuild",
|
package/lib/api.mjs
CHANGED
|
@@ -34,6 +34,12 @@ async function post(api, path, init) {
|
|
|
34
34
|
} catch {
|
|
35
35
|
throw new ApiError(`The Partner API answered ${res.status}: ${text.slice(0, 200)}`)
|
|
36
36
|
}
|
|
37
|
+
if (!res.ok && !Array.isArray(body.errors)) {
|
|
38
|
+
// An RFC 9457 problem (docs/STANDARDS.md API-1): its top-level code and detail, else the legacy `error` object that
|
|
39
|
+
// a server before 2026-11-19 sends.
|
|
40
|
+
const e = body.error && typeof body.error === 'object' ? body.error : {}
|
|
41
|
+
throw new ApiError(body.detail ?? e.message ?? `The Partner API answered ${res.status}.`, { code: body.code ?? e.code })
|
|
42
|
+
}
|
|
37
43
|
if (body.errors?.length) {
|
|
38
44
|
const e = body.errors[0]
|
|
39
45
|
throw new ApiError(typeof body.errors === 'string' ? body.errors : e.message, { code: e.extensions?.code })
|
|
@@ -107,3 +113,53 @@ export async function createVersion(api, org, themeId, { version: v, releaseNote
|
|
|
107
113
|
const d = await post(api, `/partners/${API_VERSION}/organizations/${encodeURIComponent(org)}/graphql`, { method: 'POST', body: form })
|
|
108
114
|
return payload(d.partnerThemeVersionCreate, 'version')
|
|
109
115
|
}
|
|
116
|
+
|
|
117
|
+
// ── apps: app embeds and app blocks (lib/extensions.mjs) ─────────────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
const EXTENSION_FIELDS = `extensions {
|
|
120
|
+
themeAppEmbeds { handle name src placement loading integrity }
|
|
121
|
+
themeAppBlocks { handle name description icon settings { key type label info default options { value label } min max step }
|
|
122
|
+
script { path sha256 bytes } style { path sha256 bytes } targets requires } }`
|
|
123
|
+
|
|
124
|
+
export async function apps(api, org) {
|
|
125
|
+
return (await gql(api, org, 'query { partnerApps { id handle name published } }')).partnerApps
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function appExtensions(api, org, id) {
|
|
129
|
+
const a = (await gql(api, org, `query($id: ID!) { partnerApp(id: $id) { id handle name published ${EXTENSION_FIELDS} } }`, { id })).partnerApp
|
|
130
|
+
if (!a) throw new ApiError(`No app ${id} in this organization. List them with: tanqory-partner app list`, { code: 'not_found' })
|
|
131
|
+
return a
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** A five-minute grant for one block file: `{url, token, expiresAt, path}`. */
|
|
135
|
+
export async function blockAssetUpload(api, org, input) {
|
|
136
|
+
const d = await gql(api, org, 'mutation($input: PartnerAppBlockAssetUploadInput!) { partnerAppBlockAssetUploadCreate(input: $input) { upload { url token expiresAt path } userErrors { field message code } } }', { input })
|
|
137
|
+
return payload(d.partnerAppBlockAssetUploadCreate, 'upload')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The file's bytes to the grant's address; answers `{path, sha256, bytes, integrity, url}`. */
|
|
141
|
+
export async function uploadBlockFile(grant, { kind, bytes }) {
|
|
142
|
+
const res = await fetch(grant.url, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { authorization: `Bearer ${grant.token}`, 'content-type': kind === 'STYLE' ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8', 'tanqory-client': '@tanqory/partner-cli' },
|
|
145
|
+
body: bytes,
|
|
146
|
+
})
|
|
147
|
+
const text = await res.text()
|
|
148
|
+
let body = null
|
|
149
|
+
try {
|
|
150
|
+
body = JSON.parse(text)
|
|
151
|
+
} catch {
|
|
152
|
+
body = null
|
|
153
|
+
}
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
const code = body?.code ?? body?.error?.code
|
|
156
|
+
throw new ApiError(`The upload of ${grant.path} was refused (${res.status}${code ? ` ${code}` : ''}): ${body?.detail ?? body?.error?.message ?? text.slice(0, 200)}`, { code })
|
|
157
|
+
}
|
|
158
|
+
return body
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Replaces the app's embeds and/or blocks (each list given replaces that list): the next app version. */
|
|
162
|
+
export async function updateAppExtensions(api, org, id, input) {
|
|
163
|
+
const d = await gql(api, org, `mutation($id: ID!, $input: PartnerAppConfigInput!) { partnerAppUpdate(id: $id, input: $input) { app { id handle name published ${EXTENSION_FIELDS} } userErrors { field message code } } }`, { id, input })
|
|
164
|
+
return payload(d.partnerAppUpdate, 'app')
|
|
165
|
+
}
|
package/lib/check.mjs
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// development store (`theme install`). `--conformance` also runs the ABI conformance suites here, when
|
|
10
10
|
// @tanqory/theme-conformance is installed in the theme (they need workerd and Chromium).
|
|
11
11
|
import { createRequire } from 'node:module'
|
|
12
|
-
import { existsSync } from 'node:fs'
|
|
12
|
+
import { cpSync, existsSync, mkdtempSync, rmSync } from 'node:fs'
|
|
13
|
+
import { tmpdir } from 'node:os'
|
|
13
14
|
import { join } from 'node:path'
|
|
14
15
|
import { spawnSync } from 'node:child_process'
|
|
15
16
|
import { buildTheme, packSource, ThemeError } from './theme.mjs'
|
|
@@ -33,6 +34,29 @@ function vendor() {
|
|
|
33
34
|
return require(p)
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* What this machine can run of the sandbox lines, with the sandbox lane's own code (build-service local-sandbox.ts):
|
|
39
|
+
* sandbox_build (two builds of the same source are the same tree), entry_scan, budgets (static sizes) and
|
|
40
|
+
* network_allowlist. Each line has `local: true`: the sandbox run on a development install is the verdict.
|
|
41
|
+
*/
|
|
42
|
+
export function localResults(dir, { quiet = true } = {}) {
|
|
43
|
+
const { out } = buildTheme(dir, { quiet })
|
|
44
|
+
const first = mkdtempSync(join(tmpdir(), 'tanqory-first-build-'))
|
|
45
|
+
try {
|
|
46
|
+
cpSync(out, first, { recursive: true })
|
|
47
|
+
buildTheme(dir, { quiet })
|
|
48
|
+
return vendor().localSandboxLines(out, first).map((l) => ({ ...l, local: true }))
|
|
49
|
+
} finally {
|
|
50
|
+
rmSync(first, { recursive: true, force: true })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The source rules (@tanqory/theme-standard/source, as the bundled gate reads them). */
|
|
55
|
+
export const sourceRules = () => {
|
|
56
|
+
const v = vendor()
|
|
57
|
+
return { denyFix: v.denyFix, denyReason: v.denyReason, isStarterIgnoredPath: v.isStarterIgnoredPath, isStarterTree: v.isStarterTree, SOURCE_LIMITS: v.SOURCE_LIMITS, starterPackageProblems: v.starterPackageProblems, withoutPackFolder: v.withoutPackFolder }
|
|
58
|
+
}
|
|
59
|
+
|
|
36
60
|
/** Build, pack and check `dir`. Returns `{ ok, lines, tgzBytes, layout, out }`; never throws for a failed check. */
|
|
37
61
|
export async function checkTheme(dir, { build = true, quiet = false } = {}) {
|
|
38
62
|
const out = build ? buildTheme(dir, { quiet }).out : join(dir, 'dist', 'abi')
|
package/lib/cli.mjs
CHANGED
|
@@ -6,9 +6,10 @@ import { AuthError, login, logout, rememberOrg, apiBase, signedIn } from './auth
|
|
|
6
6
|
import { ApiError, organizations } from './api.mjs'
|
|
7
7
|
import { formatLines, runConformance, SANDBOX_LINES } from './check.mjs'
|
|
8
8
|
import { ThemeError } from './theme.mjs'
|
|
9
|
+
import { ExtensionsError } from './extensions.mjs'
|
|
9
10
|
import * as ops from './ops.mjs'
|
|
10
11
|
|
|
11
|
-
const HELP = `tanqory-partner: build, check and upload Tanqory partner themes.
|
|
12
|
+
const HELP = `tanqory-partner: build, check and upload Tanqory partner themes, and declare an app's app embeds and app blocks.
|
|
12
13
|
|
|
13
14
|
tanqory-partner login [--api <url>] [--no-browser] sign in (a code to allow in the browser)
|
|
14
15
|
tanqory-partner logout
|
|
@@ -27,6 +28,14 @@ const HELP = `tanqory-partner: build, check and upload Tanqory partner themes.
|
|
|
27
28
|
tanqory-partner theme list the organization's themes
|
|
28
29
|
tanqory-partner theme stores the organization's development stores
|
|
29
30
|
|
|
31
|
+
tanqory-partner app list the organization's apps
|
|
32
|
+
tanqory-partner app extensions check [--file <f>] check tanqory.extensions.json here; sends nothing
|
|
33
|
+
tanqory-partner app extensions show [--app <id>] [--file <f>] [--json]
|
|
34
|
+
the app embeds and app blocks the app has now
|
|
35
|
+
tanqory-partner app extensions push [--app <id>] [--file <f>]
|
|
36
|
+
upload each block's files, then replace the app's embeds and
|
|
37
|
+
blocks with the file's lists (the next app version)
|
|
38
|
+
|
|
30
39
|
tanqory-partner mcp the MCP server (stdio) with the same operations
|
|
31
40
|
|
|
32
41
|
Options for every command that calls Tanqory: --api <url> (or TANQORY_API_URL: https://api.<root>, <root> being the platform domain you use), --org <id>.
|
|
@@ -35,7 +44,7 @@ Options for every command that calls Tanqory: --api <url> (or TANQORY_API_URL: h
|
|
|
35
44
|
const OPTIONS = {
|
|
36
45
|
api: { type: 'string' }, org: { type: 'string' }, dir: { type: 'string' }, out: { type: 'string' }, theme: { type: 'string' },
|
|
37
46
|
name: { type: 'string' }, version: { type: 'string' }, notes: { type: 'string' }, store: { type: 'string' }, author: { type: 'string' },
|
|
38
|
-
use: { type: 'string' }, json: { type: 'boolean' }, wait: { type: 'boolean' }, conformance: { type: 'boolean' },
|
|
47
|
+
use: { type: 'string' }, app: { type: 'string' }, file: { type: 'string' }, json: { type: 'boolean' }, wait: { type: 'boolean' }, conformance: { type: 'boolean' },
|
|
39
48
|
'skip-check': { type: 'boolean' }, 'no-browser': { type: 'boolean' }, help: { type: 'boolean', short: 'h' },
|
|
40
49
|
}
|
|
41
50
|
|
|
@@ -145,6 +154,43 @@ async function themeCommand(cmd, args, o) {
|
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
|
|
157
|
+
async function appCommand(cmd, args, o) {
|
|
158
|
+
const common = { api: o.api, org: o.org }
|
|
159
|
+
if (cmd === 'list') {
|
|
160
|
+
const r = await ops.listApps(common)
|
|
161
|
+
for (const a of r.apps) out(`${a.id} ${(a.handle ?? '').padEnd(28)} ${a.published ? 'published' : 'draft '} ${a.name}`)
|
|
162
|
+
if (!r.apps.length) out('No apps yet: create one on the partner dashboard, Apps.')
|
|
163
|
+
return 0
|
|
164
|
+
}
|
|
165
|
+
if (cmd !== 'extensions') {
|
|
166
|
+
err(HELP)
|
|
167
|
+
return 2
|
|
168
|
+
}
|
|
169
|
+
switch (args[0]) {
|
|
170
|
+
case 'check': {
|
|
171
|
+
const r = ops.checkExtensions(o.file)
|
|
172
|
+
out(`${r.file}: ${r.embeds === null ? 'app embeds left as they are' : `${r.embeds} app embed(s)`}, ${r.blocks === null ? 'app blocks left as they are' : `${r.blocks} app block(s)`}. Every check that runs here passed.`)
|
|
173
|
+
return 0
|
|
174
|
+
}
|
|
175
|
+
case 'show': {
|
|
176
|
+
const r = await ops.showExtensions({ ...common, app: o.app, file: o.file })
|
|
177
|
+
out(o.json ? JSON.stringify(r.app.extensions, null, 2) : ops.formatExtensions(r.app))
|
|
178
|
+
return 0
|
|
179
|
+
}
|
|
180
|
+
case 'push': {
|
|
181
|
+
const r = await ops.pushExtensions({ ...common, app: o.app, file: o.file, log: err })
|
|
182
|
+
out(ops.formatExtensions(r.app))
|
|
183
|
+
out(r.published
|
|
184
|
+
? 'The app is published: this change is a new version waiting for review. Merchants keep the current version until it is approved.'
|
|
185
|
+
: 'The app is not published: this version is live for your development stores now.')
|
|
186
|
+
return 0
|
|
187
|
+
}
|
|
188
|
+
default:
|
|
189
|
+
err(HELP)
|
|
190
|
+
return 2
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
148
194
|
async function waitAndShow(versionId, common, json = false) {
|
|
149
195
|
let last = ''
|
|
150
196
|
const r = await ops.waitFor(versionId, {
|
|
@@ -197,6 +243,8 @@ export async function main(argv) {
|
|
|
197
243
|
}
|
|
198
244
|
case 'theme':
|
|
199
245
|
return await themeCommand(rest[0], rest.slice(1), o)
|
|
246
|
+
case 'app':
|
|
247
|
+
return await appCommand(rest[0], rest.slice(1), o)
|
|
200
248
|
case 'mcp': {
|
|
201
249
|
const { serve } = await import('./mcp.mjs')
|
|
202
250
|
await serve({ api: o.api, org: o.org })
|
|
@@ -207,8 +255,9 @@ export async function main(argv) {
|
|
|
207
255
|
return 2
|
|
208
256
|
}
|
|
209
257
|
} catch (e) {
|
|
210
|
-
if (e instanceof ThemeError || e instanceof AuthError || e instanceof ApiError) {
|
|
258
|
+
if (e instanceof ThemeError || e instanceof AuthError || e instanceof ApiError || e instanceof ExtensionsError) {
|
|
211
259
|
err(e.message)
|
|
260
|
+
if (e.problems?.length) err(e.problems.map((p) => ` ${p}`).join('\n'))
|
|
212
261
|
if (e.lines) err(formatLines(e.lines))
|
|
213
262
|
return 1
|
|
214
263
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// App embeds and app blocks of an app, declared in one file next to the app's code and sent through the Partner API
|
|
2
|
+
// (partnerAppBlockAssetUploadCreate for each block file, then partnerAppUpdate with themeAppEmbeds and themeAppBlocks).
|
|
3
|
+
// The bounds below mirror the platform's checks (apps/api support/theme-app-embeds.ts, support/theme-app-blocks.ts),
|
|
4
|
+
// so a mistake shows here before anything is uploaded; the platform checks everything again.
|
|
5
|
+
//
|
|
6
|
+
// tanqory.extensions.json:
|
|
7
|
+
// {
|
|
8
|
+
// "app": "<app id, optional: --app wins>",
|
|
9
|
+
// "themeAppEmbeds": [{ "handle": "chat", "name": "Chat bubble", "src": "https://cdn.example.com/chat.js",
|
|
10
|
+
// "placement": "body-end", "loading": "defer", "integrity": "sha384-..." }], (integrity required)
|
|
11
|
+
// "themeAppBlocks": [{ "handle": "booking", "name": "Booking calendar", "description": "...",
|
|
12
|
+
// "script": "blocks/booking.js", "style": "blocks/booking.css",
|
|
13
|
+
// "settings": [{ "key": "heading", "type": "text", "label": "Heading", "default": "Book a time" }],
|
|
14
|
+
// "targets": ["section"], "requires": ["product"] }]
|
|
15
|
+
// }
|
|
16
|
+
// A block's `script` and `style` are files on this machine, relative to the declaration file. Leaving a list out keeps
|
|
17
|
+
// what the app has; [] removes every entry of that kind.
|
|
18
|
+
import { createHash } from 'node:crypto'
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
20
|
+
import { basename, dirname, extname, resolve } from 'node:path'
|
|
21
|
+
|
|
22
|
+
export const EXTENSIONS_FILE = 'tanqory.extensions.json'
|
|
23
|
+
export const EMBEDS_MAX = 10
|
|
24
|
+
export const BLOCKS_MAX = 30
|
|
25
|
+
export const SETTINGS_MAX = 25
|
|
26
|
+
export const SCRIPT_MAX_BYTES = 64 * 1024
|
|
27
|
+
export const STYLE_MAX_BYTES = 100 * 1024
|
|
28
|
+
export const SETTING_TYPES = ['text', 'textarea', 'richtext', 'url', 'color', 'boolean', 'select', 'range', 'number', 'image', 'product', 'collection']
|
|
29
|
+
export const ROUTE_KINDS = ['home', 'product', 'collection', 'collections', 'page', 'blog', 'article', 'search', 'cart', 'customer', 'policy', 'metaobject', 'not_found']
|
|
30
|
+
const HANDLE = /^[a-z0-9][a-z0-9-]{0,63}$/
|
|
31
|
+
const SETTING_KEY = /^[A-Za-z][A-Za-z0-9_]{0,63}$/
|
|
32
|
+
const INTEGRITY = /^sha(256|384|512)-[A-Za-z0-9+/]+={0,2}$/
|
|
33
|
+
|
|
34
|
+
export class ExtensionsError extends Error {
|
|
35
|
+
constructor(message, problems = []) {
|
|
36
|
+
super(message)
|
|
37
|
+
this.problems = problems
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function httpsUrl(v) {
|
|
42
|
+
if (typeof v !== 'string' || v.length > 2048) return false
|
|
43
|
+
try {
|
|
44
|
+
const u = new URL(v)
|
|
45
|
+
return u.protocol === 'https:' && !u.username && !u.password && !!u.hostname
|
|
46
|
+
} catch {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The name a block file is uploaded under, before its hash: the file's own name, lower-case, 1-48 characters. */
|
|
52
|
+
export function stemOf(file) {
|
|
53
|
+
const s = basename(file, extname(file)).toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^[^a-z0-9]+/, '').slice(0, 48)
|
|
54
|
+
return s || 'block'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function checkEmbeds(list, problems) {
|
|
58
|
+
if (!Array.isArray(list)) return problems.push('themeAppEmbeds must be a list.')
|
|
59
|
+
if (list.length > EMBEDS_MAX) problems.push(`An app can ship at most ${EMBEDS_MAX} app embeds (this file has ${list.length}).`)
|
|
60
|
+
const seen = new Set()
|
|
61
|
+
list.forEach((e, i) => {
|
|
62
|
+
const at = `themeAppEmbeds.${i}`
|
|
63
|
+
if (!e || typeof e !== 'object') return problems.push(`${at}: an object with handle, name, src and placement.`)
|
|
64
|
+
if (!HANDLE.test(e.handle ?? '')) problems.push(`${at}.handle: 1-64 lower-case letters, digits or hyphens, starting with a letter or digit.`)
|
|
65
|
+
else if (seen.has(e.handle)) problems.push(`${at}.handle: ${e.handle} is used twice.`)
|
|
66
|
+
else seen.add(e.handle)
|
|
67
|
+
if (typeof e.name !== 'string' || !e.name.trim() || e.name.length > 100) problems.push(`${at}.name: 1-100 characters.`)
|
|
68
|
+
if (!httpsUrl(e.src)) problems.push(`${at}.src: an https URL of at most 2048 characters, with no user name or password.`)
|
|
69
|
+
if (!['head', 'body-end'].includes(e.placement)) problems.push(`${at}.placement: head or body-end.`)
|
|
70
|
+
if (e.loading !== undefined && !['async', 'defer', 'sync'].includes(e.loading)) problems.push(`${at}.loading: async, defer or sync.`)
|
|
71
|
+
// Pinned (docs/apps/GOVERNANCE.md S5): the platform refuses a new embed without its script's hash.
|
|
72
|
+
if (typeof e.integrity !== 'string' || e.integrity.length > 128 || !INTEGRITY.test(e.integrity)) problems.push(`${at}.integrity: required, the script's Subresource Integrity hash (sha384- recommended): echo "sha384-$(curl -s <src> | openssl dgst -sha384 -binary | openssl base64 -A)".`)
|
|
73
|
+
for (const k of Object.keys(e)) if (!['handle', 'name', 'src', 'placement', 'loading', 'integrity'].includes(k)) problems.push(`${at}.${k}: not a field of an app embed.`)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function checkSetting(s, at, problems) {
|
|
78
|
+
if (!s || typeof s !== 'object') return problems.push(`${at}: an object with key, type and label.`)
|
|
79
|
+
if (!SETTING_KEY.test(s.key ?? '')) problems.push(`${at}.key: a letter, then up to 63 letters, digits or _.`)
|
|
80
|
+
if (!SETTING_TYPES.includes(s.type)) problems.push(`${at}.type: one of ${SETTING_TYPES.join(', ')}.`)
|
|
81
|
+
if (typeof s.label !== 'string' || !s.label.trim() || s.label.length > 100) problems.push(`${at}.label: 1-100 characters.`)
|
|
82
|
+
if (s.info !== undefined && (typeof s.info !== 'string' || s.info.length > 300)) problems.push(`${at}.info: at most 300 characters.`)
|
|
83
|
+
if (typeof s.default === 'string' && s.default.length > 1000) problems.push(`${at}.default: at most 1000 characters.`)
|
|
84
|
+
if (s.default !== undefined && s.default !== null && !['string', 'number', 'boolean'].includes(typeof s.default)) problems.push(`${at}.default: a string, number or boolean.`)
|
|
85
|
+
if (s.type === 'select' && (!Array.isArray(s.options) || s.options.length < 1 || s.options.length > 50)) problems.push(`${at}.options: a select needs 1 to 50 options.`)
|
|
86
|
+
if (s.type === 'range' && (typeof s.min !== 'number' || typeof s.max !== 'number')) problems.push(`${at}: a range needs min and max.`)
|
|
87
|
+
if (typeof s.min === 'number' && typeof s.max === 'number' && s.max < s.min) problems.push(`${at}: max is below min.`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function checkFile(base, rel, at, ext, max, problems) {
|
|
91
|
+
if (typeof rel !== 'string' || !rel) return problems.push(`${at}: the path of a .${ext} file, relative to the declaration file.`)
|
|
92
|
+
if (extname(rel).toLowerCase() !== `.${ext}`) return problems.push(`${at}: ${rel} is not a .${ext} file.`)
|
|
93
|
+
const file = resolve(base, rel)
|
|
94
|
+
if (!existsSync(file)) return problems.push(`${at}: ${rel} does not exist.`)
|
|
95
|
+
const bytes = readFileSync(file)
|
|
96
|
+
if (!bytes.length) return problems.push(`${at}: ${rel} is empty.`)
|
|
97
|
+
if (bytes.length > max) problems.push(`${at}: ${rel} is ${bytes.length} bytes; at most ${max} (${max / 1024} KiB).`)
|
|
98
|
+
if (bytes.includes(0)) problems.push(`${at}: ${rel} holds a NUL byte; block files are UTF-8 text.`)
|
|
99
|
+
if (ext === 'css' && /@import|expression\s*\(|javascript:/i.test(bytes.toString('utf8'))) problems.push(`${at}: ${rel} uses @import, expression( or javascript:, which the platform refuses.`)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function checkBlocks(list, base, problems) {
|
|
103
|
+
if (!Array.isArray(list)) return problems.push('themeAppBlocks must be a list.')
|
|
104
|
+
if (list.length > BLOCKS_MAX) problems.push(`An app can ship at most ${BLOCKS_MAX} app blocks (this file has ${list.length}).`)
|
|
105
|
+
const seen = new Set()
|
|
106
|
+
list.forEach((b, i) => {
|
|
107
|
+
const at = `themeAppBlocks.${i}`
|
|
108
|
+
if (!b || typeof b !== 'object') return problems.push(`${at}: an object with handle, name and script.`)
|
|
109
|
+
if (!HANDLE.test(b.handle ?? '')) problems.push(`${at}.handle: 1-64 lower-case letters, digits or hyphens, starting with a letter or digit.`)
|
|
110
|
+
else if (seen.has(b.handle)) problems.push(`${at}.handle: ${b.handle} is used twice.`)
|
|
111
|
+
else seen.add(b.handle)
|
|
112
|
+
if (typeof b.name !== 'string' || !b.name.trim() || b.name.length > 100) problems.push(`${at}.name: 1-100 characters.`)
|
|
113
|
+
if (b.description !== undefined && (typeof b.description !== 'string' || b.description.length > 500)) problems.push(`${at}.description: at most 500 characters.`)
|
|
114
|
+
if (b.icon !== undefined && !httpsUrl(b.icon)) problems.push(`${at}.icon: an https image URL.`)
|
|
115
|
+
checkFile(base, b.script, `${at}.script`, 'js', SCRIPT_MAX_BYTES, problems)
|
|
116
|
+
if (b.style !== undefined) checkFile(base, b.style, `${at}.style`, 'css', STYLE_MAX_BYTES, problems)
|
|
117
|
+
const settings = b.settings ?? []
|
|
118
|
+
if (!Array.isArray(settings)) problems.push(`${at}.settings: a list.`)
|
|
119
|
+
else {
|
|
120
|
+
if (settings.length > SETTINGS_MAX) problems.push(`${at}.settings: at most ${SETTINGS_MAX}.`)
|
|
121
|
+
const keys = new Set()
|
|
122
|
+
settings.forEach((s, j) => {
|
|
123
|
+
checkSetting(s, `${at}.settings.${j}`, problems)
|
|
124
|
+
if (s?.key && keys.has(s.key)) problems.push(`${at}.settings.${j}.key: ${s.key} is used twice.`)
|
|
125
|
+
if (s?.key) keys.add(s.key)
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
if (b.targets !== undefined && (!Array.isArray(b.targets) || !b.targets.every((t) => t === 'section' || t === 'block'))) problems.push(`${at}.targets: section, block or both.`)
|
|
129
|
+
if (b.requires !== undefined && (!Array.isArray(b.requires) || b.requires.length > ROUTE_KINDS.length || !b.requires.every((r) => ROUTE_KINDS.includes(r)))) problems.push(`${at}.requires: route kinds from ${ROUTE_KINDS.join(', ')}.`)
|
|
130
|
+
for (const k of Object.keys(b)) if (!['handle', 'name', 'description', 'icon', 'settings', 'script', 'style', 'targets', 'requires'].includes(k)) problems.push(`${at}.${k}: not a field of an app block.`)
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Reads and checks the declaration file; throws ExtensionsError naming every problem. */
|
|
135
|
+
export function readExtensions(file = EXTENSIONS_FILE) {
|
|
136
|
+
const path = resolve(file)
|
|
137
|
+
if (!existsSync(path)) throw new ExtensionsError(`${path} does not exist. Declare the app's embeds and blocks there (see https://docs.tanqory.com/apps/extensions/).`)
|
|
138
|
+
let doc
|
|
139
|
+
try {
|
|
140
|
+
doc = JSON.parse(readFileSync(path, 'utf8'))
|
|
141
|
+
} catch (e) {
|
|
142
|
+
throw new ExtensionsError(`${path} is not JSON: ${e.message}`)
|
|
143
|
+
}
|
|
144
|
+
if (!doc || typeof doc !== 'object' || Array.isArray(doc)) throw new ExtensionsError(`${path} must hold one JSON object.`)
|
|
145
|
+
const problems = []
|
|
146
|
+
for (const k of Object.keys(doc)) if (!['$schema', 'app', 'themeAppEmbeds', 'themeAppBlocks'].includes(k)) problems.push(`${k}: not a field of the declaration (app, themeAppEmbeds, themeAppBlocks).`)
|
|
147
|
+
if (doc.themeAppEmbeds === undefined && doc.themeAppBlocks === undefined) problems.push('Declare themeAppEmbeds, themeAppBlocks or both.')
|
|
148
|
+
if (doc.themeAppEmbeds !== undefined) checkEmbeds(doc.themeAppEmbeds, problems)
|
|
149
|
+
if (doc.themeAppBlocks !== undefined) checkBlocks(doc.themeAppBlocks, dirname(path), problems)
|
|
150
|
+
if (problems.length) throw new ExtensionsError(`${path} has ${problems.length} problem${problems.length === 1 ? '' : 's'}:`, problems)
|
|
151
|
+
return { path, base: dirname(path), app: typeof doc.app === 'string' ? doc.app : null, embeds: doc.themeAppEmbeds, blocks: doc.themeAppBlocks }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** One block file as the upload grant asks for it. */
|
|
155
|
+
export function blockFile(base, rel, kind) {
|
|
156
|
+
const bytes = readFileSync(resolve(base, rel))
|
|
157
|
+
return { kind, name: stemOf(rel), sha256: createHash('sha256').update(bytes).digest('hex'), fileSize: bytes.length, bytes }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The partnerAppUpdate input: each block file uploaded first (`upload(file)` answers `{path, sha256, bytes}`), then the
|
|
162
|
+
* lists with the uploaded paths in place of the local ones.
|
|
163
|
+
*/
|
|
164
|
+
export async function extensionsInput(decl, upload) {
|
|
165
|
+
const input = {}
|
|
166
|
+
if (decl.embeds !== undefined) input.themeAppEmbeds = decl.embeds.map((e) => ({ ...e }))
|
|
167
|
+
if (decl.blocks !== undefined) {
|
|
168
|
+
input.themeAppBlocks = []
|
|
169
|
+
for (const b of decl.blocks) {
|
|
170
|
+
const asset = async (rel, kind) => {
|
|
171
|
+
const r = await upload(blockFile(decl.base, rel, kind))
|
|
172
|
+
return { path: r.path, sha256: r.sha256, bytes: r.bytes }
|
|
173
|
+
}
|
|
174
|
+
input.themeAppBlocks.push({
|
|
175
|
+
handle: b.handle,
|
|
176
|
+
name: b.name,
|
|
177
|
+
...(b.description !== undefined ? { description: b.description } : {}),
|
|
178
|
+
...(b.icon !== undefined ? { icon: b.icon } : {}),
|
|
179
|
+
settings: b.settings ?? [],
|
|
180
|
+
script: await asset(b.script, 'SCRIPT'),
|
|
181
|
+
...(b.style !== undefined ? { style: await asset(b.style, 'STYLE') } : {}),
|
|
182
|
+
...(b.targets !== undefined ? { targets: b.targets } : {}),
|
|
183
|
+
...(b.requires !== undefined ? { requires: b.requires } : {}),
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return input
|
|
188
|
+
}
|
package/lib/mcp.mjs
CHANGED
|
@@ -22,11 +22,13 @@ const CONFIRM_MS = 10 * 60_000
|
|
|
22
22
|
export const INSTRUCTIONS = [
|
|
23
23
|
'Build Tanqory partner themes (code themes sold in the Tanqory Theme Store). Start with partner_theme_init, edit src/, run partner_theme_check until every line passes, then partner_theme_push.',
|
|
24
24
|
'partner_theme_push and partner_theme_install change the partner account and take two calls: the first changes nothing and returns what will happen and a confirmationToken; show it to the person, and only after they approve call again with the same arguments and the token.',
|
|
25
|
+
'An app\'s app embeds and app blocks live in tanqory.extensions.json: run partner_app_extensions_check until it passes, then partner_app_extensions_push (two calls, like partner_theme_push). Inline UI on a page is an app block; an app embed is only for floating or sitewide UI.',
|
|
25
26
|
'Tools that call Tanqory need a sign-in once: partner_login returns a code and a link; the person opens the link and allows access, then the tools work. After an install, read partner_theme_status until the install is INSTALLED or FAILED and no check is pending; it gives the preview link.',
|
|
26
27
|
].join(' ')
|
|
27
28
|
|
|
28
29
|
const dir = { type: 'string', description: 'The theme folder on this machine (the one with package.json), relative to the working directory.' }
|
|
29
30
|
const org = { type: 'string', description: 'The partner organization id. Leave out when the person is in one organization, or a default was set with tanqory-partner orgs --use.' }
|
|
31
|
+
const extFile = { type: 'string', description: 'The declaration file, relative to the working directory; default tanqory.extensions.json.' }
|
|
30
32
|
const confirm = { type: 'string', description: 'Leave out on the first call: it changes nothing and returns the change with a confirmationToken. After the person approves that change, call again with the same arguments and this token.' }
|
|
31
33
|
const ann = (readOnly, extra = {}) => ({ readOnlyHint: readOnly, destructiveHint: false, idempotentHint: readOnly, openWorldHint: !readOnly, ...extra })
|
|
32
34
|
const tool = (name, title, description, properties, required, annotations) => ({ name, title, description, inputSchema: { type: 'object', additionalProperties: false, properties, ...(required ? { required } : {}) }, annotations: { title, ...annotations } })
|
|
@@ -50,6 +52,9 @@ export function toolList() {
|
|
|
50
52
|
tool('partner_theme_status', 'Read a version and its checks', 'Shows a version, each of its 15 check lines and its development installs with the preview link. Each read moves the install and the checks on.', { versionId: { type: 'string' }, org }, ['versionId'], ann(true)),
|
|
51
53
|
tool('partner_theme_list', 'List partner themes', "Lists the organization's themes and each one's latest version.", { org }, null, ann(true)),
|
|
52
54
|
tool('partner_development_stores', 'List development stores', "Lists the organization's development stores, to install a version on.", { org }, null, ann(true)),
|
|
55
|
+
tool('partner_app_list', 'List partner apps', "Lists the organization's apps with their ids.", { org }, null, ann(true)),
|
|
56
|
+
tool('partner_app_extensions_check', 'Check app embeds and app blocks', 'Reads tanqory.extensions.json (the app embeds and app blocks of an app) and checks it against the platform bounds, with each block file. Changes nothing.', { file: extFile }, null, ann(true, { openWorldHint: false })),
|
|
57
|
+
tool('partner_app_extensions_push', 'Upload app embeds and app blocks', "Uploads each block's script and stylesheet, then replaces the app's app embeds and app blocks with the file's lists: the app's next version (in review when the app is published). You approve it first.", { file: extFile, app: { type: 'string', description: 'The app id (partner_app_list); leave out when the file names it in "app".' }, org, confirmationToken: confirm }, null, ann(false)),
|
|
53
58
|
]
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -123,6 +128,23 @@ export async function callTool(name, args = {}, defaults = {}) {
|
|
|
123
128
|
if (blocked) return blocked
|
|
124
129
|
return text((await ops.listThemes(common)).themes)
|
|
125
130
|
}
|
|
131
|
+
case 'partner_app_list': {
|
|
132
|
+
const blocked = needSignIn(common.api)
|
|
133
|
+
if (blocked) return blocked
|
|
134
|
+
return text((await ops.listApps(common)).apps)
|
|
135
|
+
}
|
|
136
|
+
case 'partner_app_extensions_check':
|
|
137
|
+
return text(ops.checkExtensions(args.file))
|
|
138
|
+
case 'partner_app_extensions_push': {
|
|
139
|
+
const blocked = needSignIn(common.api)
|
|
140
|
+
if (blocked) return blocked
|
|
141
|
+
if (!confirmed(name, args)) {
|
|
142
|
+
const r = ops.checkExtensions(args.file)
|
|
143
|
+
return text({ confirmationRequired: true, change: `Replace the ${r.embeds === null ? '' : `app embeds (${r.embeds}) `}${r.embeds !== null && r.blocks !== null ? 'and ' : ''}${r.blocks === null ? '' : `app blocks (${r.blocks}, files uploaded first) `}of app ${args.app ?? r.app} on ${apiBase(common.api)} with the lists in ${r.file}: the app's next version.`, confirmationToken: confirmation(name, args) })
|
|
144
|
+
}
|
|
145
|
+
const r = await ops.pushExtensions({ ...common, app: args.app, file: args.file })
|
|
146
|
+
return text({ organization: r.org, app: r.app, sent: r.sent, inReview: r.published })
|
|
147
|
+
}
|
|
126
148
|
case 'partner_development_stores': {
|
|
127
149
|
const blocked = needSignIn(common.api)
|
|
128
150
|
if (blocked) return blocked
|
|
@@ -151,7 +173,7 @@ export async function handle(msg, defaults = {}) {
|
|
|
151
173
|
try {
|
|
152
174
|
return reply(await callTool(name, args ?? {}, defaults))
|
|
153
175
|
} catch (e) {
|
|
154
|
-
return reply(text(`${e.message}${e.lines ? `\n${JSON.stringify(e.lines, null, 2)}` : ''}`, true))
|
|
176
|
+
return reply(text(`${e.message}${e.lines ? `\n${JSON.stringify(e.lines, null, 2)}` : ''}${e.problems?.length ? `\n${e.problems.join('\n')}` : ''}`, true))
|
|
155
177
|
}
|
|
156
178
|
}
|
|
157
179
|
default:
|
package/lib/ops.mjs
CHANGED
|
@@ -4,8 +4,9 @@ import { basename, dirname, join, resolve } from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import * as api from './api.mjs'
|
|
6
6
|
import { apiBase, defaultOrg, rememberOrg } from './auth.mjs'
|
|
7
|
-
import { checkTheme } from './check.mjs'
|
|
7
|
+
import { checkTheme, localResults as localResultsOf } from './check.mjs'
|
|
8
8
|
import { packSource, packageTheme, readPackage, ThemeError } from './theme.mjs'
|
|
9
|
+
import { EXTENSIONS_FILE, extensionsInput, readExtensions } from './extensions.mjs'
|
|
9
10
|
|
|
10
11
|
const STARTER = join(dirname(fileURLToPath(import.meta.url)), '..', 'starter')
|
|
11
12
|
const HANDLE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
@@ -51,6 +52,11 @@ export async function check(dir, opts) {
|
|
|
51
52
|
return checkTheme(resolve(dir ?? '.'), opts)
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
/** What this machine can run of the sandbox lines (two builds compared, entry imports, static budgets, network origins). */
|
|
56
|
+
export function localResults(dir, opts) {
|
|
57
|
+
return localResultsOf(resolve(dir ?? '.'), opts)
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
export async function pkg(dir, opts) {
|
|
55
61
|
return packageTheme(resolve(dir ?? '.'), opts)
|
|
56
62
|
}
|
|
@@ -177,3 +183,57 @@ export function formatVersion(v) {
|
|
|
177
183
|
}
|
|
178
184
|
return rows.join('\n')
|
|
179
185
|
}
|
|
186
|
+
|
|
187
|
+
// ── apps: app embeds and app blocks ──────────────────────────────────────────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
export async function listApps({ api: apiFlag, org } = {}) {
|
|
190
|
+
const where = await resolveOrg(apiFlag, org)
|
|
191
|
+
return { ...where, apps: await api.apps(where.api, where.org) }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** `app extensions check`: the declaration file read and checked here; nothing is sent. */
|
|
195
|
+
export function checkExtensions(file = EXTENSIONS_FILE) {
|
|
196
|
+
const d = readExtensions(file)
|
|
197
|
+
return { file: d.path, app: d.app, embeds: d.embeds?.length ?? null, blocks: d.blocks?.length ?? null }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The app named by --app, else by the declaration's "app". */
|
|
201
|
+
function appOf(app, decl) {
|
|
202
|
+
const id = app ?? decl?.app
|
|
203
|
+
if (!id) throw new ThemeError('Name the app: --app <id>, or "app" in the declaration file (tanqory-partner app list shows the ids).')
|
|
204
|
+
return id
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function showExtensions({ api: apiFlag, org, app, file } = {}) {
|
|
208
|
+
const decl = app ? null : readExtensions(file ?? EXTENSIONS_FILE)
|
|
209
|
+
const where = await resolveOrg(apiFlag, org)
|
|
210
|
+
return { ...where, app: await api.appExtensions(where.api, where.org, appOf(app, decl)) }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* `app extensions push`: the declaration checked, each block file uploaded (stored under its SHA-256, so the same file
|
|
215
|
+
* sent again is the same path), then one partnerAppUpdate with the lists. A published app's change waits for review.
|
|
216
|
+
*/
|
|
217
|
+
export async function pushExtensions({ api: apiFlag, org, app, file, log = () => {} } = {}) {
|
|
218
|
+
const decl = readExtensions(file ?? EXTENSIONS_FILE)
|
|
219
|
+
const id = appOf(app, decl)
|
|
220
|
+
const where = await resolveOrg(apiFlag, org)
|
|
221
|
+
const current = await api.appExtensions(where.api, where.org, id)
|
|
222
|
+
const input = await extensionsInput(decl, async (f) => {
|
|
223
|
+
log(`Uploading ${f.name} (${f.kind === 'SCRIPT' ? 'script' : 'stylesheet'}, ${f.fileSize} bytes)...`)
|
|
224
|
+
const grant = await api.blockAssetUpload(where.api, where.org, { appId: id, kind: f.kind, name: f.name, sha256: f.sha256, fileSize: f.fileSize })
|
|
225
|
+
return api.uploadBlockFile(grant, f)
|
|
226
|
+
})
|
|
227
|
+
const updated = await api.updateAppExtensions(where.api, where.org, id, input)
|
|
228
|
+
return { ...where, app: updated, published: current.published, sent: { embeds: input.themeAppEmbeds?.length ?? null, blocks: input.themeAppBlocks?.length ?? null } }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function formatExtensions(app) {
|
|
232
|
+
const x = app.extensions ?? {}
|
|
233
|
+
const rows = [`${app.name} (${app.id})${app.published ? ', published' : ''}`]
|
|
234
|
+
rows.push(`app embeds: ${x.themeAppEmbeds?.length ?? 0}`)
|
|
235
|
+
for (const e of x.themeAppEmbeds ?? []) rows.push(` ${e.handle.padEnd(24)} ${e.placement.padEnd(8)} ${e.loading.padEnd(5)} ${e.src}`)
|
|
236
|
+
rows.push(`app blocks: ${x.themeAppBlocks?.length ?? 0}`)
|
|
237
|
+
for (const b of x.themeAppBlocks ?? []) rows.push(` ${b.handle.padEnd(24)} ${b.script?.path ?? '(no script)'}${b.style ? ` + ${b.style.path}` : ''}, ${b.settings.length} setting(s)${b.targets.length ? `, in ${b.targets.join('/')}` : ''}`)
|
|
238
|
+
return rows.join('\n')
|
|
239
|
+
}
|
package/lib/theme.mjs
CHANGED
|
@@ -8,10 +8,14 @@
|
|
|
8
8
|
// - never node_modules, dist or .git;
|
|
9
9
|
// - no lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lockb): the builder never installs from one (it
|
|
10
10
|
// uses its own toolchain). (An uploaded lockfile is read for the SBOM only; since DECISIONS row 185 the licences
|
|
11
|
-
// check counts only what it ships, so its developer tools no longer fail it.)
|
|
11
|
+
// check counts only what it ships, so its developer tools no longer fail it.);
|
|
12
|
+
// - none of what the lane leaves out anyway (editor and AI assistant folders, tests, CI, macOS files:
|
|
13
|
+
// @tanqory/theme-standard/source `isStarterIgnoredPath`, bundled in lib/vendor), and no root manifest.json (the
|
|
14
|
+
// manifest goes beside the archive; a stale copy inside it would differ from it).
|
|
12
15
|
import { execFileSync, spawnSync } from 'node:child_process'
|
|
13
16
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync, copyFileSync } from 'node:fs'
|
|
14
17
|
import { dirname, join, resolve } from 'node:path'
|
|
18
|
+
import { createRequire } from 'node:module'
|
|
15
19
|
import * as tar from 'tar'
|
|
16
20
|
|
|
17
21
|
export const LOCKFILES = new Set(['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lockb', 'npm-shrinkwrap.json'])
|
|
@@ -19,6 +23,16 @@ const NEVER = new Set(['node_modules', 'dist', '.git'])
|
|
|
19
23
|
|
|
20
24
|
export class ThemeError extends Error {}
|
|
21
25
|
|
|
26
|
+
const requireHere = createRequire(import.meta.url)
|
|
27
|
+
/** The lane's own rule (bundled); a copy without lib/vendor packs as before. */
|
|
28
|
+
function leftOutByLane(path) {
|
|
29
|
+
try {
|
|
30
|
+
return requireHere('./vendor/partner-checks.cjs').isStarterIgnoredPath(path)
|
|
31
|
+
} catch {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
export function readPackage(dir) {
|
|
23
37
|
const p = join(dir, 'package.json')
|
|
24
38
|
if (!existsSync(p)) throw new ThemeError(`${dir} has no package.json. Run this in a theme folder, or make one with: tanqory-partner theme init <name>`)
|
|
@@ -66,7 +80,7 @@ export function themeFiles(dir) {
|
|
|
66
80
|
walk('')
|
|
67
81
|
}
|
|
68
82
|
return paths
|
|
69
|
-
.filter((p) => !p.split('/').some((seg) => NEVER.has(seg)) && !LOCKFILES.has(p))
|
|
83
|
+
.filter((p) => !p.split('/').some((seg) => NEVER.has(seg)) && !LOCKFILES.has(p) && p !== 'manifest.json' && !leftOutByLane(p))
|
|
70
84
|
.filter((p) => existsSync(join(dir, p)) && statSync(join(dir, p)).isFile())
|
|
71
85
|
.sort()
|
|
72
86
|
}
|