@tanqory/partner-cli 0.0.0-stage → 0.1.0-alpha.2
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/LICENSE +21 -0
- package/bin/tanqory-partner.mjs +10 -0
- package/config/mirror-allowlist.json +17 -0
- package/config/theme-licences.json +108 -0
- package/config/third-party-toolchains.json +45 -0
- package/lib/api.mjs +109 -0
- package/lib/auth.mjs +211 -0
- package/lib/check.mjs +66 -0
- package/lib/cli.mjs +217 -0
- package/lib/mcp.mjs +177 -0
- package/lib/ops.mjs +179 -0
- package/lib/theme.mjs +121 -0
- package/lib/vendor/partner-checks.cjs +2420 -0
- package/package.json +59 -4
- package/starter/LICENSE +18 -0
- package/starter/README.md +44 -0
- package/starter/config/settings.json +5 -0
- package/starter/gitignore +3 -0
- package/starter/locales/en.json +22 -0
- package/starter/locales/en.schema.json +69 -0
- package/starter/locales/th.json +22 -0
- package/starter/locales/th.schema.json +69 -0
- package/starter/package.json +29 -0
- package/starter/regions/footer.json +35 -0
- package/starter/regions/header.json +13 -0
- package/starter/scripts/build.mjs +211 -0
- package/starter/scripts/probe.ts +4 -0
- package/starter/src/bundle.ts +15 -0
- package/starter/src/components/parts.tsx +32 -0
- package/starter/src/entry.client.tsx +6 -0
- package/starter/src/entry.server.tsx +13 -0
- package/starter/src/sections/chrome.tsx +132 -0
- package/starter/src/sections/commerce.tsx +242 -0
- package/starter/src/sections/content.tsx +115 -0
- package/starter/src/sections/editorial.tsx +232 -0
- package/starter/src/settings.ts +12 -0
- package/starter/src/styles/theme.css +241 -0
- package/starter/src/templates.ts +14 -0
- package/starter/src/theme.tsx +86 -0
- package/starter/templates/404.json +14 -0
- package/starter/templates/account.json +14 -0
- package/starter/templates/article.json +14 -0
- package/starter/templates/blog.json +14 -0
- package/starter/templates/cart.json +14 -0
- package/starter/templates/collection.json +14 -0
- package/starter/templates/index.json +116 -0
- package/starter/templates/page.contact.json +22 -0
- package/starter/templates/page.json +14 -0
- package/starter/templates/product.json +18 -0
- package/starter/templates/search.json +14 -0
- package/starter/tsconfig.json +17 -0
- package/starter/vite.client.config.ts +17 -0
- package/starter/vite.probe.config.ts +16 -0
- package/starter/vite.server.config.ts +32 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tanqory
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Theme-level packages a ThemeSource may depend on (capability-security-v1.md §5.3: each entry pins a semver range AND the expected integrity per version). PR-reviewed. A lockfile entry is accepted only when its name is listed, its version is one of `versions` (each of which must satisfy `range`), and its resolution.integrity equals the value pinned here. `range` is `X.Y.Z`, `^X.Y.Z` or `~X.Y.Z`. Integrity values are the npm registry's dist.integrity (sha512). Toolchain packages are never listed here — they live in the builder image.",
|
|
3
|
+
"packages": {
|
|
4
|
+
"clsx": {
|
|
5
|
+
"range": "^2.1.1",
|
|
6
|
+
"versions": {
|
|
7
|
+
"2.1.1": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"dedent": {
|
|
11
|
+
"range": "^1.5.3",
|
|
12
|
+
"versions": {
|
|
13
|
+
"1.5.3": "sha512-NHQtfOOW68WD8lgypbLA5oT+Bt0xXJhiYvoR6SmmNXZfpzOGXwdKWmcwG8N7PwVVWV3eF/68nmD9BaJSsTBhyQ=="
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Licences of partner theme components (docs/online-store/PARTNER_THEMES.md \u00a75.2 'Licences and notices'; src/review/static-checks.ts). `allowlist`: SPDX License List identifiers a component's licence expression must be made of: the permissive licences the Blue Oak Council rates (Model, Gold, Silver or Bronze), plus CC-BY-4.0 (Tanqory choice: caniuse-lite's data, in every starter toolchain through @babel/core; an attribution-only Creative Commons licence, not a software licence, so Blue Oak does not rate it). Copyleft licences (GPL, LGPL, AGPL, MPL, EPL, CDDL, EUPL) are not on the list. `packages`: the licence each toolchain package declares (package.json `license`), written by scripts/gen-theme-licences.mjs from the toolchains Dockerfile.builder-3p installs and checked against them at every theme-builder-3p image build (scripts/verify-kit-toolchains.mjs); the two packages of config/mirror-allowlist.json (clsx, dedent: MIT, as their package.json declare) are added by hand and a test (test/review/review-stage.spec.ts) fails when the mirror allowlist names a package this table lacks; keys are `name`, `name@version` (when versions differ), or a `*` family pattern (platform binaries). A component not in the table fails the licence line: a third-party theme builds only with toolchain and mirror-allowlist packages. Reviewed change only (CODEOWNERS config/).",
|
|
3
|
+
"allowlist": [
|
|
4
|
+
"0BSD",
|
|
5
|
+
"Apache-2.0",
|
|
6
|
+
"BlueOak-1.0.0",
|
|
7
|
+
"BSD-2-Clause",
|
|
8
|
+
"BSD-2-Clause-Patent",
|
|
9
|
+
"BSD-3-Clause",
|
|
10
|
+
"BSL-1.0",
|
|
11
|
+
"CC-BY-4.0",
|
|
12
|
+
"CC0-1.0",
|
|
13
|
+
"ISC",
|
|
14
|
+
"MIT",
|
|
15
|
+
"MIT-0",
|
|
16
|
+
"Python-2.0",
|
|
17
|
+
"Unlicense",
|
|
18
|
+
"Zlib"
|
|
19
|
+
],
|
|
20
|
+
"sources": [
|
|
21
|
+
"SPDX License List (identifiers): https://spdx.org/licenses/",
|
|
22
|
+
"SPDX License Expressions (AND, OR, WITH): https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/",
|
|
23
|
+
"Blue Oak Council License List, version 16 (permissive licences, rated): https://blueoakcouncil.org/list",
|
|
24
|
+
"Creative Commons Attribution 4.0: https://creativecommons.org/licenses/by/4.0/",
|
|
25
|
+
"CycloneDX 1.6 components (the SBOM the build writes, capability-security-v1.md \u00a75.6): https://cyclonedx.org/docs/1.6/json/"
|
|
26
|
+
],
|
|
27
|
+
"packages": {
|
|
28
|
+
"@babel/code-frame": "MIT",
|
|
29
|
+
"@babel/compat-data": "MIT",
|
|
30
|
+
"@babel/core": "MIT",
|
|
31
|
+
"@babel/generator": "MIT",
|
|
32
|
+
"@babel/helper-compilation-targets": "MIT",
|
|
33
|
+
"@babel/helper-globals": "MIT",
|
|
34
|
+
"@babel/helper-module-imports": "MIT",
|
|
35
|
+
"@babel/helper-module-transforms": "MIT",
|
|
36
|
+
"@babel/helper-plugin-utils": "MIT",
|
|
37
|
+
"@babel/helper-string-parser": "MIT",
|
|
38
|
+
"@babel/helper-validator-identifier": "MIT",
|
|
39
|
+
"@babel/helper-validator-option": "MIT",
|
|
40
|
+
"@babel/helpers": "MIT",
|
|
41
|
+
"@babel/parser": "MIT",
|
|
42
|
+
"@babel/plugin-transform-react-jsx-self": "MIT",
|
|
43
|
+
"@babel/plugin-transform-react-jsx-source": "MIT",
|
|
44
|
+
"@babel/template": "MIT",
|
|
45
|
+
"@babel/traverse": "MIT",
|
|
46
|
+
"@babel/types": "MIT",
|
|
47
|
+
"@esbuild/*": "MIT",
|
|
48
|
+
"@isaacs/fs-minipass": "ISC",
|
|
49
|
+
"@jridgewell/gen-mapping": "MIT",
|
|
50
|
+
"@jridgewell/remapping": "MIT",
|
|
51
|
+
"@jridgewell/resolve-uri": "MIT",
|
|
52
|
+
"@jridgewell/sourcemap-codec": "MIT",
|
|
53
|
+
"@jridgewell/trace-mapping": "MIT",
|
|
54
|
+
"@rolldown/pluginutils": "MIT",
|
|
55
|
+
"@rollup/rollup-*": "MIT",
|
|
56
|
+
"@tanqory/theme-abi": "MIT",
|
|
57
|
+
"@tanqory/theme-kit": "MIT",
|
|
58
|
+
"@types/babel__core": "MIT",
|
|
59
|
+
"@types/babel__generator": "MIT",
|
|
60
|
+
"@types/babel__template": "MIT",
|
|
61
|
+
"@types/babel__traverse": "MIT",
|
|
62
|
+
"@types/estree": "MIT",
|
|
63
|
+
"@vitejs/plugin-react": "MIT",
|
|
64
|
+
"ajv": "MIT",
|
|
65
|
+
"baseline-browser-mapping": "Apache-2.0",
|
|
66
|
+
"browserslist": "MIT",
|
|
67
|
+
"caniuse-lite": "CC-BY-4.0",
|
|
68
|
+
"chownr": "BlueOak-1.0.0",
|
|
69
|
+
"clsx": "MIT",
|
|
70
|
+
"convert-source-map": "MIT",
|
|
71
|
+
"debug": "MIT",
|
|
72
|
+
"dedent": "MIT",
|
|
73
|
+
"electron-to-chromium": "ISC",
|
|
74
|
+
"esbuild": "MIT",
|
|
75
|
+
"esbuild-wasm": "MIT",
|
|
76
|
+
"escalade": "MIT",
|
|
77
|
+
"fast-deep-equal": "MIT",
|
|
78
|
+
"fast-uri": "BSD-3-Clause",
|
|
79
|
+
"fsevents": "MIT",
|
|
80
|
+
"gensync": "MIT",
|
|
81
|
+
"js-tokens": "MIT",
|
|
82
|
+
"jsesc": "MIT",
|
|
83
|
+
"json-schema-traverse": "MIT",
|
|
84
|
+
"json5": "MIT",
|
|
85
|
+
"loose-envify": "MIT",
|
|
86
|
+
"lru-cache": "ISC",
|
|
87
|
+
"minipass": "BlueOak-1.0.0",
|
|
88
|
+
"minizlib": "MIT",
|
|
89
|
+
"ms": "MIT",
|
|
90
|
+
"nanoid": "MIT",
|
|
91
|
+
"node-releases": "MIT",
|
|
92
|
+
"picocolors": "ISC",
|
|
93
|
+
"postcss": "MIT",
|
|
94
|
+
"react": "MIT",
|
|
95
|
+
"react-dom": "MIT",
|
|
96
|
+
"react-refresh": "MIT",
|
|
97
|
+
"require-from-string": "MIT",
|
|
98
|
+
"rollup": "MIT",
|
|
99
|
+
"scheduler": "MIT",
|
|
100
|
+
"semver": "ISC",
|
|
101
|
+
"source-map-js": "BSD-3-Clause",
|
|
102
|
+
"tar": "BlueOak-1.0.0",
|
|
103
|
+
"update-browserslist-db": "MIT",
|
|
104
|
+
"vite": "MIT",
|
|
105
|
+
"yallist@3.1.1": "ISC",
|
|
106
|
+
"yallist@5.0.0": "BlueOak-1.0.0"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.17 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, whose 2.0.0-alpha.14 has changed since the npmjs tarball): 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`. `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.",
|
|
3
|
+
"kits": [
|
|
4
|
+
{
|
|
5
|
+
"version": "2.0.0-alpha.3",
|
|
6
|
+
"gitHead": "43a1591764bfa4a57926245e61780c39f292bea0",
|
|
7
|
+
"integrity": "sha512-XxH8Y4LUvaahsFp9FZ5ldo2zZPvG5ZMvWRb8FruK6LKVZSFf0hkeTxdza2YBusRLF0G3wEhyUZGbE/NiQO0rvg=="
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"version": "2.0.0-alpha.5",
|
|
11
|
+
"gitHead": "aaa218c6582742086959e60fca8deaecf5f19059",
|
|
12
|
+
"integrity": "sha512-B+MPk8BBhRSnYIKUV+ObGy6jiCrX0IspqS00pl8Ocv+BqZj4RRvERWquvzN0ZYxO3gkdDdJXz7WZqsLWylAhjQ=="
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"version": "2.0.0-alpha.17",
|
|
16
|
+
"pack": "tanqory-theme-kit-2.0.0-alpha.17.tgz"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"starter": {
|
|
20
|
+
"packages": [
|
|
21
|
+
{
|
|
22
|
+
"name": "@tanqory/theme-abi",
|
|
23
|
+
"version": "2.0.0-alpha.14",
|
|
24
|
+
"pack": "tanqory-theme-abi-2.0.0-alpha.14.tgz"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "vite",
|
|
28
|
+
"version": "5.4.21",
|
|
29
|
+
"integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw=="
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "@vitejs/plugin-react",
|
|
33
|
+
"version": "4.7.0",
|
|
34
|
+
"integrity": "sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA=="
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"overrides": [
|
|
38
|
+
{
|
|
39
|
+
"name": "esbuild",
|
|
40
|
+
"version": "0.28.2",
|
|
41
|
+
"integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA=="
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
package/lib/api.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// The Partner GraphQL API (docs/online-store/PARTNER_THEMES.md §7), with the member's own sign-in:
|
|
2
|
+
// https://<api>/partners/<version>/graphql account-wide fields (partnerOrganizations)
|
|
3
|
+
// https://<api>/partners/<version>/organizations/<org>/graphql one organization's operations
|
|
4
|
+
// A version is uploaded as a GraphQL multipart request (multipart request specification v2.1 over RFC 7578):
|
|
5
|
+
// `operations` (the query and variables, with `input.source: null`), `map` ({"0": ["variables.input.source"]}) and the
|
|
6
|
+
// .tgz as part "0".
|
|
7
|
+
import { accessToken, AuthError } from './auth.mjs'
|
|
8
|
+
|
|
9
|
+
export const API_VERSION = '2026-10'
|
|
10
|
+
export const SOURCE_MAX_BYTES = 20 * 1024 * 1024
|
|
11
|
+
|
|
12
|
+
export class ApiError extends Error {
|
|
13
|
+
constructor(message, { code, userErrors } = {}) {
|
|
14
|
+
super(message)
|
|
15
|
+
this.code = code
|
|
16
|
+
this.userErrors = userErrors
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const VERSION_FIELDS = `id themeId version status sequence checksComplete sourceDigest buildId checkedAt createdAt
|
|
21
|
+
checks { key status message errors { path code message } }
|
|
22
|
+
developmentInstalls { id storeId status buildId buildStatus errorCode errorMessage storeThemeId installedAt preview { url expiresAt status } }`
|
|
23
|
+
const THEME_FIELDS = 'id handle name status themeKey latestVersion { id version status }'
|
|
24
|
+
|
|
25
|
+
async function post(api, path, init) {
|
|
26
|
+
const { token } = await accessToken(api)
|
|
27
|
+
const res = await fetch(`${api}${path}`, { ...init, headers: { ...(init.headers ?? {}), authorization: `Bearer ${token}`, 'tanqory-client': '@tanqory/partner-cli' } })
|
|
28
|
+
const text = await res.text()
|
|
29
|
+
if (res.status === 401) throw new AuthError('The Partner API refused the sign-in (401). Run: tanqory-partner login')
|
|
30
|
+
if (res.status === 404) throw new ApiError('Organization not found, or you are not a member of it. List yours with: tanqory-partner orgs', { code: 'not_found' })
|
|
31
|
+
let body
|
|
32
|
+
try {
|
|
33
|
+
body = JSON.parse(text)
|
|
34
|
+
} catch {
|
|
35
|
+
throw new ApiError(`The Partner API answered ${res.status}: ${text.slice(0, 200)}`)
|
|
36
|
+
}
|
|
37
|
+
if (body.errors?.length) {
|
|
38
|
+
const e = body.errors[0]
|
|
39
|
+
throw new ApiError(typeof body.errors === 'string' ? body.errors : e.message, { code: e.extensions?.code })
|
|
40
|
+
}
|
|
41
|
+
return body.data
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const gql = (api, org, query, variables) =>
|
|
45
|
+
post(api, org ? `/partners/${API_VERSION}/organizations/${encodeURIComponent(org)}/graphql` : `/partners/${API_VERSION}/graphql`, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
body: JSON.stringify({ query, variables }),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function payload(p, key) {
|
|
52
|
+
if (p.userErrors?.length) {
|
|
53
|
+
const e = p.userErrors[0]
|
|
54
|
+
throw new ApiError(`${e.message}${e.field ? ` (${e.field.join('.')})` : ''}`, { code: e.code, userErrors: p.userErrors })
|
|
55
|
+
}
|
|
56
|
+
return p[key]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function organizations(api) {
|
|
60
|
+
return (await gql(api, null, 'query { partnerOrganizations { id name } }')).partnerOrganizations
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function themes(api, org) {
|
|
64
|
+
return (await gql(api, org, `query { partnerThemes { ${THEME_FIELDS} } }`)).partnerThemes
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function createTheme(api, org, { name, handle }) {
|
|
68
|
+
const d = await gql(api, org, `mutation($input: PartnerThemeCreateInput!) { partnerThemeCreate(input: $input) { theme { ${THEME_FIELDS} } userErrors { field message code } } }`, { input: { name, handle } })
|
|
69
|
+
return payload(d.partnerThemeCreate, 'theme')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function version(api, org, id) {
|
|
73
|
+
const v = (await gql(api, org, `query($id: ID!) { partnerThemeVersion(id: $id) { ${VERSION_FIELDS} } }`, { id })).partnerThemeVersion
|
|
74
|
+
if (!v) throw new ApiError(`Version ${id} not found in this organization.`, { code: 'not_found' })
|
|
75
|
+
return v
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function versions(api, org, themeId) {
|
|
79
|
+
return (await gql(api, org, 'query($id: ID!) { partnerThemeVersions(themeId: $id) { id version status createdAt } }', { id: themeId })).partnerThemeVersions
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function developmentStores(api, org) {
|
|
83
|
+
return (await gql(api, org, 'query { partnerDevelopmentStores { limit stores { id name subdomain status kind } } }')).partnerDevelopmentStores.stores
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function install(api, org, versionId, storeId) {
|
|
87
|
+
const d = await gql(api, org, `mutation($v: ID!, $s: ID!) { partnerThemeVersionDevelopmentInstall(versionId: $v, storeId: $s) { developmentInstall { id storeId status buildId errorCode errorMessage } userErrors { field message code } } }`, { v: versionId, s: storeId })
|
|
88
|
+
return payload(d.partnerThemeVersionDevelopmentInstall, 'developmentInstall')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function recheck(api, org, id) {
|
|
92
|
+
const d = await gql(api, org, `mutation($id: ID!) { partnerThemeVersionRecheck(id: $id) { version { ${VERSION_FIELDS} } userErrors { field message code } } }`, { id })
|
|
93
|
+
return payload(d.partnerThemeVersionRecheck, 'version')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A new version from the .tgz (multipart) and the manifest the build wrote. */
|
|
97
|
+
export async function createVersion(api, org, themeId, { version: v, releaseNotes, manifest, tgz, filename }) {
|
|
98
|
+
if (tgz.length > SOURCE_MAX_BYTES) throw new ApiError(`The package is ${tgz.length} bytes; a version's source is at most 20 MiB (${SOURCE_MAX_BYTES} bytes).`, { code: 'source_too_large' })
|
|
99
|
+
const operations = {
|
|
100
|
+
query: `mutation($themeId: ID!, $input: PartnerThemeVersionInput!) { partnerThemeVersionCreate(themeId: $themeId, input: $input) { version { ${VERSION_FIELDS} } userErrors { field message code details } } }`,
|
|
101
|
+
variables: { themeId, input: { version: v, releaseNotes, manifest, source: null } },
|
|
102
|
+
}
|
|
103
|
+
const form = new FormData()
|
|
104
|
+
form.append('operations', JSON.stringify(operations))
|
|
105
|
+
form.append('map', JSON.stringify({ 0: ['variables.input.source'] }))
|
|
106
|
+
form.append('0', new Blob([tgz], { type: 'application/gzip' }), filename)
|
|
107
|
+
const d = await post(api, `/partners/${API_VERSION}/organizations/${encodeURIComponent(org)}/graphql`, { method: 'POST', body: form })
|
|
108
|
+
return payload(d.partnerThemeVersionCreate, 'version')
|
|
109
|
+
}
|
package/lib/auth.mjs
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Sign-in for the partner CLI: the OAuth 2.0 Device Authorization Grant (RFC 8628) on Tanqory's authorization server,
|
|
2
|
+
// the way the reference platform's CLI signs a developer in (a code shown in the terminal, approved in the browser).
|
|
3
|
+
// discovery RFC 8414 metadata at <api>/.well-known/oauth-authorization-server (device_authorization_endpoint)
|
|
4
|
+
// client registered once per API with RFC 7591 (a public client, the device grant only), kept with the sign-in
|
|
5
|
+
// sign-in §3.1 device authorization request, §3.2 the user code and verification URI shown, §3.4 polling the
|
|
6
|
+
// token endpoint at `interval` (§3.5: slow_down adds 5 seconds), until approved, denied or expired
|
|
7
|
+
// tokens a member access token (15 minutes) and a rotating refresh token, sent as `Authorization: Bearer`
|
|
8
|
+
// (RFC 6750) to the Partner API; refreshed at the token endpoint (RFC 6749 §6)
|
|
9
|
+
// The sign-in is the member's own: it shows in their account's devices list as this client, and signing out there
|
|
10
|
+
// (or `tanqory-partner logout`) ends it.
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { homedir, hostname } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
import { spawn } from 'node:child_process'
|
|
15
|
+
|
|
16
|
+
const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
17
|
+
const DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'
|
|
18
|
+
|
|
19
|
+
export class AuthError extends Error {}
|
|
20
|
+
|
|
21
|
+
const home = () => process.env.TANQORY_HOME ?? join(homedir(), '.tanqory')
|
|
22
|
+
const credentialsPath = () => join(home(), 'partner-cli', 'credentials.json')
|
|
23
|
+
|
|
24
|
+
function load() {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(credentialsPath(), 'utf8'))
|
|
27
|
+
} catch {
|
|
28
|
+
return {}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function save(all) {
|
|
32
|
+
mkdirSync(join(home(), 'partner-cli'), { recursive: true, mode: 0o700 })
|
|
33
|
+
writeFileSync(credentialsPath(), `${JSON.stringify(all, null, 2)}\n`, { mode: 0o600 })
|
|
34
|
+
chmodSync(credentialsPath(), 0o600)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The API base: --api, else TANQORY_API_URL, else the one the last sign-in used. No built-in address (THEME_MCP.md §7). */
|
|
38
|
+
export function apiBase(flag) {
|
|
39
|
+
const raw = flag ?? process.env.TANQORY_API_URL ?? load()._last
|
|
40
|
+
if (!raw) throw new AuthError('No Tanqory API address. Sign in with: tanqory-partner login --api https://api.<root> , or set TANQORY_API_URL.')
|
|
41
|
+
let u
|
|
42
|
+
try {
|
|
43
|
+
u = new URL(raw)
|
|
44
|
+
} catch {
|
|
45
|
+
throw new AuthError(`${raw} is not a URL. Give the API address, for example https://api.<root>.`)
|
|
46
|
+
}
|
|
47
|
+
if (u.protocol !== 'https:' && !['127.0.0.1', 'localhost'].includes(u.hostname)) throw new AuthError(`${raw} must be an https address.`)
|
|
48
|
+
return `${u.origin}`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function json(res) {
|
|
52
|
+
const text = await res.text()
|
|
53
|
+
try {
|
|
54
|
+
return text ? JSON.parse(text) : {}
|
|
55
|
+
} catch {
|
|
56
|
+
return { error: 'invalid_response', error_description: `${res.status} ${text.slice(0, 200)}` }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function metadata(api) {
|
|
61
|
+
const res = await fetch(`${api}/.well-known/oauth-authorization-server`)
|
|
62
|
+
const m = await json(res)
|
|
63
|
+
if (!res.ok || !m.token_endpoint) throw new AuthError(`${api} did not answer its OAuth metadata (${res.status}).`)
|
|
64
|
+
if (!m.device_authorization_endpoint) throw new AuthError(`${api} does not offer device sign-in yet (no device_authorization_endpoint).`)
|
|
65
|
+
return m
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function register(meta) {
|
|
69
|
+
const res = await fetch(meta.registration_endpoint, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'content-type': 'application/json' },
|
|
72
|
+
body: JSON.stringify({ client_name: 'Tanqory Partner CLI', software_id: '@tanqory/partner-cli', software_version: VERSION, grant_types: [DEVICE_GRANT, 'refresh_token'], scope: 'partners', token_endpoint_auth_method: 'none' }),
|
|
73
|
+
})
|
|
74
|
+
const r = await json(res)
|
|
75
|
+
if (!r.client_id) throw new AuthError(`Client registration failed: ${r.error_description || r.error || res.status}`)
|
|
76
|
+
return r.client_id
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function openBrowser(url) {
|
|
80
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open'
|
|
81
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]
|
|
82
|
+
try {
|
|
83
|
+
spawn(cmd, args, { stdio: 'ignore', detached: true }).on('error', () => {}).unref()
|
|
84
|
+
} catch {
|
|
85
|
+
/* no browser here: the URL is printed */
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Sign in (RFC 8628). `say` prints to the user; `onCode({userCode, verificationUri, verificationUriComplete, expiresIn})`
|
|
93
|
+
* is called once the code exists (the MCP tool returns it to the client instead of waiting).
|
|
94
|
+
*/
|
|
95
|
+
export async function login({ api: flag, browser = true, say = console.error, onCode } = {}) {
|
|
96
|
+
const api = apiBase(flag)
|
|
97
|
+
const meta = await metadata(api)
|
|
98
|
+
const all = load()
|
|
99
|
+
let clientId = all[api]?.clientId
|
|
100
|
+
const start = async () => {
|
|
101
|
+
const res = await fetch(meta.device_authorization_endpoint, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
104
|
+
body: new URLSearchParams({ client_id: clientId, scope: 'partners' }),
|
|
105
|
+
})
|
|
106
|
+
return { res, body: await json(res) }
|
|
107
|
+
}
|
|
108
|
+
if (!clientId) clientId = await register(meta)
|
|
109
|
+
let { res, body } = await start()
|
|
110
|
+
if (body.error === 'invalid_client') {
|
|
111
|
+
// registrations unused for 90 days are removed (central's cleanup): register again once
|
|
112
|
+
clientId = await register(meta)
|
|
113
|
+
;({ res, body } = await start())
|
|
114
|
+
}
|
|
115
|
+
if (!res.ok || !body.device_code) throw new AuthError(`Sign-in could not start: ${body.error_description || body.error || res.status}`)
|
|
116
|
+
const code = { userCode: body.user_code, verificationUri: body.verification_uri, verificationUriComplete: body.verification_uri_complete, expiresIn: body.expires_in }
|
|
117
|
+
say(`To sign in, open ${body.verification_uri} and enter the code ${body.user_code}`)
|
|
118
|
+
say(`(or open ${body.verification_uri_complete})`)
|
|
119
|
+
say(`The code works for ${Math.round(body.expires_in / 60)} minutes. Waiting for you to allow access...`)
|
|
120
|
+
if (browser) openBrowser(body.verification_uri_complete)
|
|
121
|
+
onCode?.(code)
|
|
122
|
+
let interval = Math.max(1, Number(body.interval) || 5) * 1000
|
|
123
|
+
const deadline = Date.now() + (Number(body.expires_in) || 600) * 1000
|
|
124
|
+
while (Date.now() < deadline) {
|
|
125
|
+
await sleep(interval)
|
|
126
|
+
const r = await fetch(meta.token_endpoint, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
129
|
+
body: new URLSearchParams({ grant_type: DEVICE_GRANT, device_code: body.device_code, client_id: clientId }),
|
|
130
|
+
})
|
|
131
|
+
const t = await json(r)
|
|
132
|
+
if (t.access_token) {
|
|
133
|
+
const entry = { clientId, tokenEndpoint: meta.token_endpoint, accessToken: t.access_token, refreshToken: t.refresh_token, expiresAt: Date.now() + (t.expires_in ?? 900) * 1000, signedInAt: new Date().toISOString(), host: hostname() }
|
|
134
|
+
const now = load()
|
|
135
|
+
now[api] = { ...(now[api] ?? {}), ...entry }
|
|
136
|
+
now._last = api
|
|
137
|
+
save(now)
|
|
138
|
+
return { api, ...code }
|
|
139
|
+
}
|
|
140
|
+
if (t.error === 'authorization_pending') continue
|
|
141
|
+
if (t.error === 'slow_down') {
|
|
142
|
+
interval += 5000
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
if (t.error === 'access_denied') throw new AuthError('Access was denied in the browser. Nothing was signed in.')
|
|
146
|
+
if (t.error === 'expired_token') throw new AuthError('The code expired before it was allowed. Run tanqory-partner login again.')
|
|
147
|
+
throw new AuthError(`Sign-in failed: ${t.error_description || t.error || r.status}`)
|
|
148
|
+
}
|
|
149
|
+
throw new AuthError('The code expired before it was allowed. Run tanqory-partner login again.')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A live access token for `api`, refreshed when it ends within a minute. */
|
|
153
|
+
export async function accessToken(flag) {
|
|
154
|
+
const api = apiBase(flag)
|
|
155
|
+
const all = load()
|
|
156
|
+
const e = all[api]
|
|
157
|
+
if (!e?.refreshToken) throw new AuthError(`Not signed in to ${api}. Run: tanqory-partner login --api ${api}`)
|
|
158
|
+
if (e.expiresAt - 60_000 > Date.now()) return { api, token: e.accessToken }
|
|
159
|
+
const r = await fetch(e.tokenEndpoint, {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
162
|
+
body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: e.refreshToken, client_id: e.clientId }),
|
|
163
|
+
})
|
|
164
|
+
const t = await json(r)
|
|
165
|
+
if (!t.access_token) {
|
|
166
|
+
delete all[api].accessToken
|
|
167
|
+
delete all[api].refreshToken
|
|
168
|
+
save(all)
|
|
169
|
+
throw new AuthError(`The sign-in has ended (${t.error_description || t.error || r.status}). Run: tanqory-partner login --api ${api}`)
|
|
170
|
+
}
|
|
171
|
+
all[api] = { ...e, accessToken: t.access_token, refreshToken: t.refresh_token ?? e.refreshToken, expiresAt: Date.now() + (t.expires_in ?? 900) * 1000 }
|
|
172
|
+
save(all)
|
|
173
|
+
return { api, token: t.access_token }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function signedIn(flag) {
|
|
177
|
+
try {
|
|
178
|
+
return !!load()[apiBase(flag)]?.refreshToken
|
|
179
|
+
} catch {
|
|
180
|
+
return false
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Forget the sign-in here and end the session on the server (the account API's logout ends it by its refresh token). */
|
|
185
|
+
export async function logout(flag) {
|
|
186
|
+
const api = apiBase(flag)
|
|
187
|
+
if (load()[api]?.refreshToken) {
|
|
188
|
+
// RFC 7009 is not offered; the account plane's logout ends the session of the access token it is sent with
|
|
189
|
+
const live = await accessToken(api).catch(() => null)
|
|
190
|
+
if (live) await fetch(`${api}/v1/auth/logout`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${live.token}` }, body: '{}' }).catch(() => null)
|
|
191
|
+
}
|
|
192
|
+
const all = load()
|
|
193
|
+
if (all[api]) {
|
|
194
|
+
delete all[api].accessToken
|
|
195
|
+
delete all[api].refreshToken
|
|
196
|
+
save(all)
|
|
197
|
+
}
|
|
198
|
+
return api
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function rememberOrg(api, orgId) {
|
|
202
|
+
const all = load()
|
|
203
|
+
all[api] = { ...(all[api] ?? {}), defaultOrg: orgId }
|
|
204
|
+
save(all)
|
|
205
|
+
}
|
|
206
|
+
export function defaultOrg(api) {
|
|
207
|
+
return load()[api]?.defaultOrg ?? null
|
|
208
|
+
}
|
|
209
|
+
export function credentialsFile() {
|
|
210
|
+
return existsSync(credentialsPath()) ? credentialsPath() : null
|
|
211
|
+
}
|
package/lib/check.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `theme check`: the partner checks that need no sandbox, run here exactly as the platform runs them on an upload
|
|
2
|
+
// (build-service's own code, bundled into lib/vendor by scripts/prepare.mjs):
|
|
3
|
+
// ingest_gate, sandbox_build, source_text, editability on the .tgz `theme package` makes (editability: every
|
|
4
|
+
// word, image, link and list a shopper sees is a setting or a block, labels in
|
|
5
|
+
// English and Thai, and every image address answers; theme-standard EDITABILITY.md)
|
|
6
|
+
// manifest, manifest_brand_term, manifest_emoji, no_eval, licences on the build output (dist/abi)
|
|
7
|
+
// The other six lines (the two sandbox builds and their digests, entry scan, ABI conformance, network allowlist,
|
|
8
|
+
// budgets, accessibility, preview renders) run the theme, in the platform's sandbox, when a version is installed on a
|
|
9
|
+
// development store (`theme install`). `--conformance` also runs the ABI conformance suites here, when
|
|
10
|
+
// @tanqory/theme-conformance is installed in the theme (they need workerd and Chromium).
|
|
11
|
+
import { createRequire } from 'node:module'
|
|
12
|
+
import { existsSync } from 'node:fs'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
import { spawnSync } from 'node:child_process'
|
|
15
|
+
import { buildTheme, packSource, ThemeError } from './theme.mjs'
|
|
16
|
+
|
|
17
|
+
const require = createRequire(import.meta.url)
|
|
18
|
+
|
|
19
|
+
/** The lines that run in the sandbox, with what each checks: shown as `sandbox` so a partner knows they still come. */
|
|
20
|
+
export const SANDBOX_LINES = [
|
|
21
|
+
['sandbox_build', 'two builds in the sandbox give one artifact digest'],
|
|
22
|
+
['entry_scan', 'no imports in server/entry.mjs and preview/entry.mjs'],
|
|
23
|
+
['abi_conformance', 'ABI conformance suites 1 to 9'],
|
|
24
|
+
['network_allowlist', 'no network outside the allowlist'],
|
|
25
|
+
['budgets', 'size and performance budgets, Lighthouse performance average 60 or more'],
|
|
26
|
+
['accessibility', 'axe-core WCAG 2.2 AA (no serious or critical), Lighthouse accessibility average 90 or more'],
|
|
27
|
+
['preview_renders', 'every route and section preview renders on three sample stores, 18 screenshots'],
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
function vendor() {
|
|
31
|
+
const p = join(import.meta.dirname ?? new URL('.', import.meta.url).pathname, 'vendor', 'partner-checks.cjs')
|
|
32
|
+
if (!existsSync(p)) throw new ThemeError('This copy of @tanqory/partner-cli has no bundled checks (lib/vendor). Reinstall it from npm, or run node scripts/prepare.mjs in a checkout.')
|
|
33
|
+
return require(p)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Build, pack and check `dir`. Returns `{ ok, lines, tgzBytes, layout, out }`; never throws for a failed check. */
|
|
37
|
+
export async function checkTheme(dir, { build = true, quiet = false } = {}) {
|
|
38
|
+
const out = build ? buildTheme(dir, { quiet }).out : join(dir, 'dist', 'abi')
|
|
39
|
+
const { bytes } = await packSource(dir)
|
|
40
|
+
const report = await vendor().checkPartnerSource(bytes, out, { imageFetch: globalThis.fetch })
|
|
41
|
+
return { ok: report.lines.every((l) => l.status === 'passed'), lines: report.lines, tgzBytes: report.tgzBytes, layout: report.layout, out }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The ABI conformance suites on dist/abi, when the theme has @tanqory/theme-conformance installed; null when not. */
|
|
45
|
+
export function runConformance(dir, out) {
|
|
46
|
+
let cli
|
|
47
|
+
try {
|
|
48
|
+
const req = createRequire(join(dir, 'package.json'))
|
|
49
|
+
const pkgPath = req.resolve('@tanqory/theme-conformance/package.json')
|
|
50
|
+
cli = join(pkgPath, '..', JSON.parse(require('node:fs').readFileSync(pkgPath, 'utf8')).bin['theme-conformance'])
|
|
51
|
+
} catch {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
const r = spawnSync(process.execPath, [cli, 'run', out, '--out', join(dir, 'dist', 'conformance-report.json')], { cwd: dir, stdio: 'inherit' })
|
|
55
|
+
return { ok: r.status === 0, report: join(dir, 'dist', 'conformance-report.json') }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function formatLines(lines) {
|
|
59
|
+
const rows = []
|
|
60
|
+
for (const l of lines) {
|
|
61
|
+
rows.push(`${l.status === 'passed' ? 'passed' : 'FAILED'} ${l.key}: ${l.message}`)
|
|
62
|
+
// every finding of a failed line as file, rule, message (the first is also the line's message)
|
|
63
|
+
if (l.status !== 'passed') for (const e of l.errors.slice(0, 20)) rows.push(` ${e.path || '(source)'} ${e.code || 'error'} ${e.message}`)
|
|
64
|
+
}
|
|
65
|
+
return rows.join('\n')
|
|
66
|
+
}
|