@supersdk/supercli 0.1.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/consoleClient.js +132 -0
- package/dist/api/consoleClient.js.map +1 -0
- package/dist/auth/browserAuth.js +163 -0
- package/dist/auth/browserAuth.js.map +1 -0
- package/dist/auth/refresh.js +32 -0
- package/dist/auth/refresh.js.map +1 -0
- package/dist/cli.js +46 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/accounts.js +46 -0
- package/dist/commands/accounts.js.map +1 -0
- package/dist/commands/createApp.js +225 -0
- package/dist/commands/createApp.js.map +1 -0
- package/dist/commands/login.js +54 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.js +99 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/publishSite.js +361 -0
- package/dist/commands/publishSite.js.map +1 -0
- package/dist/commands/switchaccount.js +35 -0
- package/dist/commands/switchaccount.js.map +1 -0
- package/dist/commands/update.js +95 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config/environments.js +53 -0
- package/dist/config/environments.js.map +1 -0
- package/dist/createApp/copyTemplate.js +237 -0
- package/dist/createApp/copyTemplate.js.map +1 -0
- package/dist/publish/orgResolve.js +30 -0
- package/dist/publish/orgResolve.js.map +1 -0
- package/dist/publish/responseClassifier.js +111 -0
- package/dist/publish/responseClassifier.js.map +1 -0
- package/dist/publish/siteClient.js +113 -0
- package/dist/publish/siteClient.js.map +1 -0
- package/dist/publish/siteConfig.js +190 -0
- package/dist/publish/siteConfig.js.map +1 -0
- package/dist/publish/siteZip.js +172 -0
- package/dist/publish/siteZip.js.map +1 -0
- package/dist/store/accountStore.js +236 -0
- package/dist/store/accountStore.js.map +1 -0
- package/dist/store/backends/encryptedFile.js +162 -0
- package/dist/store/backends/encryptedFile.js.map +1 -0
- package/dist/store/backends/osKeyring.js +283 -0
- package/dist/store/backends/osKeyring.js.map +1 -0
- package/dist/store/credentialStore.js +65 -0
- package/dist/store/credentialStore.js.map +1 -0
- package/dist/template/README.md +144 -0
- package/dist/template/android/.gitkeep +1 -0
- package/dist/template/android/app/build.gradle.kts +122 -0
- package/dist/template/android/app/src/main/AndroidManifest.xml +19 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/MainActivity.java +17 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +22 -0
- package/dist/template/android/app/src/test/java/com/supersdk/simple/AppNameResourceTest.java +19 -0
- package/dist/template/android/build.gradle.kts +3 -0
- package/dist/template/android/gradle/supersdk-config-reader.gradle +61 -0
- package/dist/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/dist/template/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/dist/template/android/gradle.properties +3 -0
- package/dist/template/android/gradlew +251 -0
- package/dist/template/android/settings.gradle.kts +25 -0
- package/dist/template/android/supersdk-default.config.json +17 -0
- package/dist/template/ios/MockSuperSDKPackage/Package.swift +15 -0
- package/dist/template/ios/MockSuperSDKPackage/Sources/SuperSDK/SuperSDK.swift +25 -0
- package/dist/template/ios/Resources/Info.plist +43 -0
- package/dist/template/ios/Sources/App/AppDelegate.swift +20 -0
- package/dist/template/ios/Sources/App/SceneDelegate.swift +14 -0
- package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +7 -0
- package/dist/template/ios/Sources/App/SimpleSDKProbe.swift +26 -0
- package/dist/template/ios/Sources/App/SimpleSDKProvider.swift +4 -0
- package/dist/template/ios/Sources/App/SimpleViewController.swift +20 -0
- package/dist/template/ios/Tests/SimpleAppTests/SimpleSDKInitializationTests.swift +17 -0
- package/dist/template/ios/project.yml +67 -0
- package/dist/template/scripts/android_snapshot_canary.py +136 -0
- package/dist/template/scripts/build_android.sh +240 -0
- package/dist/template/scripts/build_ios.sh +261 -0
- package/dist/template/scripts/build_web.sh +12 -0
- package/dist/template/scripts/serve_web.py +51 -0
- package/dist/template/scripts/super_build_orchestrator.py +400 -0
- package/dist/template/scripts/supersdk_template.py +611 -0
- package/dist/template/scripts/web_host_validator.py +103 -0
- package/dist/template/scripts/web_package.py +202 -0
- package/dist/template/scripts/ws03_shared_schema_merge_guard.py +73 -0
- package/dist/template/super_build.sh +116 -0
- package/dist/template/supersdk.yaml +15 -0
- package/dist/template/web/src/css/style.css +83 -0
- package/dist/template/web/src/index.html +37 -0
- package/dist/template/web/src/js/app.js +99 -0
- package/dist/template/web/src/js/supersdk.js +1848 -0
- package/dist/template/web/src/js/supersdk.provenance.json +6 -0
- package/dist/update/channelResolver.js +183 -0
- package/dist/update/channelResolver.js.map +1 -0
- package/dist/update/installSafety.js +135 -0
- package/dist/update/installSafety.js.map +1 -0
- package/dist/util/fsAtomic.js +294 -0
- package/dist/util/fsAtomic.js.map +1 -0
- package/dist/util/log.js +55 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/origin.js +66 -0
- package/dist/util/origin.js.map +1 -0
- package/dist/util/prompt.js +113 -0
- package/dist/util/prompt.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PLATFORM_DIRS = exports.IGNORE_SUFFIXES = exports.IGNORE_NAMES = exports.APP_ID_PATTERN_SOURCE = void 0;
|
|
37
|
+
exports.isValidAppId = isValidAppId;
|
|
38
|
+
exports.sanitizeAppIdChars = sanitizeAppIdChars;
|
|
39
|
+
exports.deriveAppId = deriveAppId;
|
|
40
|
+
exports.isValidPlatform = isValidPlatform;
|
|
41
|
+
exports.locateDefaultTemplateRoot = locateDefaultTemplateRoot;
|
|
42
|
+
exports.copyTemplateInto = copyTemplateInto;
|
|
43
|
+
exports.replaceAppIdLine = replaceAppIdLine;
|
|
44
|
+
exports.applyAppId = applyAppId;
|
|
45
|
+
// BL-005 create-app: template discovery, app_id derivation, and the
|
|
46
|
+
// exclude/platform-filtered recursive copy into a build directory.
|
|
47
|
+
//
|
|
48
|
+
// The copy step is intentionally a plain byte-for-byte file copy (no
|
|
49
|
+
// templating engine) — the only content edit is the single-line `app_id:`
|
|
50
|
+
// replacement in supersdk.yaml (see replaceAppIdLine / applyAppId), matching
|
|
51
|
+
// TECH.md's decision against a full YAML round-trip for the restricted
|
|
52
|
+
// dialect used by scripts/supersdk_template.py.
|
|
53
|
+
const fs = __importStar(require("node:fs"));
|
|
54
|
+
const path = __importStar(require("node:path"));
|
|
55
|
+
/**
|
|
56
|
+
* Mirrors `APP_ID_PATTERN = r"[A-Za-z][A-Za-z0-9_-]{2,63}"` in
|
|
57
|
+
* supersimples/app_repo_example/scripts/supersdk_template.py (used there via
|
|
58
|
+
* `re.fullmatch`, i.e. anchored) — a leading letter followed by 2-63 more
|
|
59
|
+
* letters/digits/underscore/hyphen (3-64 chars total).
|
|
60
|
+
*/
|
|
61
|
+
exports.APP_ID_PATTERN_SOURCE = '[A-Za-z][A-Za-z0-9_-]{2,63}';
|
|
62
|
+
const APP_ID_PATTERN = new RegExp(`^${exports.APP_ID_PATTERN_SOURCE}$`);
|
|
63
|
+
function isValidAppId(id) {
|
|
64
|
+
return APP_ID_PATTERN.test(id);
|
|
65
|
+
}
|
|
66
|
+
/** Drops every character outside the pattern's allowed alphabet; does not fix up the leading-letter/length rules — callers must still validate the result. */
|
|
67
|
+
function sanitizeAppIdChars(raw) {
|
|
68
|
+
return raw.replace(/[^A-Za-z0-9_-]/g, '');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Derives a valid app_id from a target directory's basename (TC-C02).
|
|
72
|
+
* Returns null when no valid app_id can be derived (caller must then require
|
|
73
|
+
* an explicit --app-id) — e.g. "123-bad" (doesn't start with a letter), "."
|
|
74
|
+
* (sanitizes to empty), "a" (too short after the leading letter).
|
|
75
|
+
*/
|
|
76
|
+
function deriveAppId(dirBasename) {
|
|
77
|
+
const cleaned = sanitizeAppIdChars(dirBasename);
|
|
78
|
+
return isValidAppId(cleaned) ? cleaned : null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Directory/file names excluded at every depth of the copy — mirrors
|
|
82
|
+
* `ignore_generated` in supersimples/tests/e2e/build_orchestration_smoke.py
|
|
83
|
+
* (TC-C06/AC-C4).
|
|
84
|
+
*/
|
|
85
|
+
exports.IGNORE_NAMES = new Set([
|
|
86
|
+
'.supersdk',
|
|
87
|
+
'.gradle',
|
|
88
|
+
'.swiftpm',
|
|
89
|
+
'.build',
|
|
90
|
+
'build',
|
|
91
|
+
'__pycache__',
|
|
92
|
+
'local.properties',
|
|
93
|
+
'Package.resolved',
|
|
94
|
+
]);
|
|
95
|
+
exports.IGNORE_SUFFIXES = ['.pyc', '.xcodeproj', '.xcworkspace'];
|
|
96
|
+
function isIgnoredName(name) {
|
|
97
|
+
if (exports.IGNORE_NAMES.has(name))
|
|
98
|
+
return true;
|
|
99
|
+
return exports.IGNORE_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
100
|
+
}
|
|
101
|
+
exports.PLATFORM_DIRS = ['android', 'ios', 'web'];
|
|
102
|
+
function isValidPlatform(value) {
|
|
103
|
+
return value === 'all' || exports.PLATFORM_DIRS.includes(value);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Locates the create-app template root. Two supported layouts, checked in order:
|
|
107
|
+
*
|
|
108
|
+
* 1. BUNDLED (npm-installed CLI): scripts/postbuild.mjs copies the template
|
|
109
|
+
* into `<package>/dist/template`. From the compiled
|
|
110
|
+
* `dist/createApp/copyTemplate.js` that is `../template` relative to
|
|
111
|
+
* __dirname. This is the ONLY layout available in a published install
|
|
112
|
+
* (package.json `files: ["dist"]` ships dist/ but not supersimples/), so it
|
|
113
|
+
* is tried FIRST (EXT-3/ARCH-4).
|
|
114
|
+
* 2. DEV/MONOREPO: walk up from this module's directory to find the sibling
|
|
115
|
+
* `supersimples/app_repo_example` — the source template used during
|
|
116
|
+
* development and by the real-template smoke test before a build has run.
|
|
117
|
+
*
|
|
118
|
+
* Callers can always override both via an explicit templateRoot.
|
|
119
|
+
*/
|
|
120
|
+
function locateDefaultTemplateRoot() {
|
|
121
|
+
// 1) Bundled template shipped inside dist/ (compiled location: dist/createApp).
|
|
122
|
+
const bundled = path.join(__dirname, '..', 'template');
|
|
123
|
+
if (fs.existsSync(bundled) && fs.statSync(bundled).isDirectory()) {
|
|
124
|
+
return bundled;
|
|
125
|
+
}
|
|
126
|
+
// 2) Dev/monorepo walk-up to supersimples/app_repo_example.
|
|
127
|
+
let dir = __dirname;
|
|
128
|
+
for (let i = 0; i < 10; i++) {
|
|
129
|
+
const candidate = path.join(dir, 'supersimples', 'app_repo_example');
|
|
130
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
|
|
131
|
+
return candidate;
|
|
132
|
+
}
|
|
133
|
+
const parent = path.dirname(dir);
|
|
134
|
+
if (parent === dir)
|
|
135
|
+
break;
|
|
136
|
+
dir = parent;
|
|
137
|
+
}
|
|
138
|
+
throw new Error(`could not locate the create-app template — neither a bundled dist/template (at "${bundled}") ` +
|
|
139
|
+
`nor a supersimples/app_repo_example above "${__dirname}". Run \`npm run build\` to bundle the ` +
|
|
140
|
+
'template, or pass an explicit template root.');
|
|
141
|
+
}
|
|
142
|
+
function copyDirRecursive(src, dest) {
|
|
143
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
144
|
+
let count = 0;
|
|
145
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
if (isIgnoredName(entry.name))
|
|
148
|
+
continue;
|
|
149
|
+
const srcPath = path.join(src, entry.name);
|
|
150
|
+
if (entry.isSymbolicLink()) {
|
|
151
|
+
throw new Error(`template contains an unsupported symlink at "${srcPath}"`);
|
|
152
|
+
}
|
|
153
|
+
const destPath = path.join(dest, entry.name);
|
|
154
|
+
if (entry.isDirectory()) {
|
|
155
|
+
count += copyDirRecursive(srcPath, destPath);
|
|
156
|
+
}
|
|
157
|
+
else if (entry.isFile()) {
|
|
158
|
+
fs.copyFileSync(srcPath, destPath);
|
|
159
|
+
// Preserve the source file's permission bits (notably android/gradlew's
|
|
160
|
+
// executable bit, AC-C4) rather than whatever copyFileSync's default
|
|
161
|
+
// creation mode would be.
|
|
162
|
+
fs.chmodSync(destPath, fs.statSync(srcPath).mode);
|
|
163
|
+
count += 1;
|
|
164
|
+
}
|
|
165
|
+
// Other dirent kinds (fifo/socket/device) are not expected in a template
|
|
166
|
+
// and are silently skipped.
|
|
167
|
+
}
|
|
168
|
+
return count;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Copies templateRoot into destDir (which must already exist, typically an
|
|
172
|
+
* empty build/temp directory), applying the exclude set at every depth and,
|
|
173
|
+
* for platform !== 'all', keeping only the selected platform directory among
|
|
174
|
+
* android/ios/web while always keeping everything else at the template root
|
|
175
|
+
* (the shared root: supersdk.yaml, super_build.sh, README.md, .gitignore,
|
|
176
|
+
* scripts/, ...) — AC-C2/AC-C4.
|
|
177
|
+
*/
|
|
178
|
+
function copyTemplateInto(templateRoot, destDir, platform) {
|
|
179
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
180
|
+
const entries = fs.readdirSync(templateRoot, { withFileTypes: true });
|
|
181
|
+
let fileCount = 0;
|
|
182
|
+
const platforms = [];
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
if (isIgnoredName(entry.name))
|
|
185
|
+
continue;
|
|
186
|
+
const isPlatformDir = exports.PLATFORM_DIRS.includes(entry.name);
|
|
187
|
+
if (isPlatformDir && platform !== 'all' && platform !== entry.name)
|
|
188
|
+
continue;
|
|
189
|
+
const srcPath = path.join(templateRoot, entry.name);
|
|
190
|
+
if (entry.isSymbolicLink()) {
|
|
191
|
+
throw new Error(`template contains an unsupported symlink at "${srcPath}"`);
|
|
192
|
+
}
|
|
193
|
+
const destPath = path.join(destDir, entry.name);
|
|
194
|
+
if (entry.isDirectory()) {
|
|
195
|
+
fileCount += copyDirRecursive(srcPath, destPath);
|
|
196
|
+
if (isPlatformDir)
|
|
197
|
+
platforms.push(entry.name);
|
|
198
|
+
}
|
|
199
|
+
else if (entry.isFile()) {
|
|
200
|
+
fs.copyFileSync(srcPath, destPath);
|
|
201
|
+
fs.chmodSync(destPath, fs.statSync(srcPath).mode);
|
|
202
|
+
fileCount += 1;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return { fileCount, platforms };
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Minimal single-line `app_id:` replacement (not a full YAML round-trip —
|
|
209
|
+
* TECH.md §模块3 rejects a YAML library on purpose since the template uses a
|
|
210
|
+
* restricted, hand-parsed dialect and a round-trip would risk mangling
|
|
211
|
+
* comments/ordering/other keys).
|
|
212
|
+
*/
|
|
213
|
+
function replaceAppIdLine(yamlContent, appId) {
|
|
214
|
+
const lines = yamlContent.split('\n');
|
|
215
|
+
let replaced = false;
|
|
216
|
+
const out = lines.map((line) => {
|
|
217
|
+
if (!replaced && /^app_id:\s*/.test(line)) {
|
|
218
|
+
replaced = true;
|
|
219
|
+
return `app_id: ${appId}`;
|
|
220
|
+
}
|
|
221
|
+
return line;
|
|
222
|
+
});
|
|
223
|
+
if (!replaced) {
|
|
224
|
+
throw new Error('generated supersdk.yaml has no "app_id:" line to replace');
|
|
225
|
+
}
|
|
226
|
+
return out.join('\n');
|
|
227
|
+
}
|
|
228
|
+
/** Applies the app_id edit to `<destDir>/supersdk.yaml` in place. */
|
|
229
|
+
function applyAppId(destDir, appId) {
|
|
230
|
+
const yamlPath = path.join(destDir, 'supersdk.yaml');
|
|
231
|
+
if (!fs.existsSync(yamlPath)) {
|
|
232
|
+
throw new Error(`generated app is missing supersdk.yaml at "${yamlPath}" (template broken?)`);
|
|
233
|
+
}
|
|
234
|
+
const content = fs.readFileSync(yamlPath, 'utf8');
|
|
235
|
+
fs.writeFileSync(yamlPath, replaceAppIdLine(content, appId), 'utf8');
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=copyTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyTemplate.js","sourceRoot":"","sources":["../../src/createApp/copyTemplate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,oCAEC;AAGD,gDAEC;AAQ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ACvE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Org resolution for publish-site (AC-S8). The backend forces X-Org-Id on every
|
|
3
|
+
// site write (org_ctx.rs has no single-org fallback), so the CLI must always
|
|
4
|
+
// send one. Resolution priority:
|
|
5
|
+
// 1. explicit --org (used verbatim, no /me lookup, TC-S18)
|
|
6
|
+
// 2. single-org account (auto from GET /me orgs[], TC-S16)
|
|
7
|
+
// 3. multi-org account (hard error, requires --org — never guesses, TC-S17)
|
|
8
|
+
// Pure function so it is trivially unit-testable without any network.
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.resolveOrgId = resolveOrgId;
|
|
11
|
+
function orgIdToString(id) {
|
|
12
|
+
if (typeof id === 'number' && Number.isFinite(id))
|
|
13
|
+
return String(id);
|
|
14
|
+
if (typeof id === 'string' && id.trim().length > 0)
|
|
15
|
+
return id.trim();
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
function resolveOrgId(orgs, explicitOrg) {
|
|
19
|
+
// 1. Explicit --org wins verbatim — no auto-resolution / validation against /me.
|
|
20
|
+
if (explicitOrg !== undefined && explicitOrg.trim().length > 0) {
|
|
21
|
+
return { kind: 'resolved', orgId: explicitOrg.trim() };
|
|
22
|
+
}
|
|
23
|
+
const ids = (orgs ?? []).map((o) => orgIdToString(o.id)).filter((v) => v !== undefined);
|
|
24
|
+
if (ids.length === 1)
|
|
25
|
+
return { kind: 'resolved', orgId: ids[0] };
|
|
26
|
+
if (ids.length === 0)
|
|
27
|
+
return { kind: 'none' };
|
|
28
|
+
return { kind: 'ambiguous', orgIds: ids };
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=orgResolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orgResolve.js","sourceRoot":"","sources":["../../src/publish/orgResolve.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,6EAA6E;AAC7E,i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|
+
"use strict";
|
|
2
|
+
// SuperSite response classifier (AC-S6). Mirrors the "envelope code three-way"
|
|
3
|
+
// concept of consoleClient.ts but adds the site-specific rules the JSON-only
|
|
4
|
+
// consoleClient cannot express:
|
|
5
|
+
// - 503 is NOT uniformly infra: `503 + code==POINTER_SYNC_PENDING` is a SOFT
|
|
6
|
+
// SUCCESS (the write committed, edge pointer sync is still catching up),
|
|
7
|
+
// while any other 503 (e.g. SITE_DISABLED) is a HARD error (TC-S12/S22).
|
|
8
|
+
// - business errors are HTTP 200 + envelope code != SUCCESS (TC-S09/S10).
|
|
9
|
+
// - DEPLOY_CAPACITY_EXCEEDED (200) and 429 are retryable (TC-S24).
|
|
10
|
+
// - any 3xx redirect is a failure, never followed — a Bearer request must not
|
|
11
|
+
// be silently redirected to another origin (TC-S23, mirrors consoleClient).
|
|
12
|
+
// Only a real 401 may cause the caller to touch local credentials (TC-S13).
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.POINTER_SYNC_PENDING = void 0;
|
|
15
|
+
exports.classifySiteResponse = classifySiteResponse;
|
|
16
|
+
exports.describeSiteError = describeSiteError;
|
|
17
|
+
exports.POINTER_SYNC_PENDING = 'POINTER_SYNC_PENDING';
|
|
18
|
+
function asString(value) {
|
|
19
|
+
return typeof value === 'string' ? value : undefined;
|
|
20
|
+
}
|
|
21
|
+
function extraResource(extra) {
|
|
22
|
+
if (extra && typeof extra === 'object' && 'resource' in extra) {
|
|
23
|
+
return extra.resource;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function extraRetryable(extra) {
|
|
28
|
+
return Boolean(extra && typeof extra === 'object' && extra.retryable === true);
|
|
29
|
+
}
|
|
30
|
+
const RETRYABLE_CODES = new Set(['DEPLOY_CAPACITY_EXCEEDED']);
|
|
31
|
+
function classifySiteResponse(snap) {
|
|
32
|
+
// 1. Redirects are always a failure (never followed) — Bearer-leak guard.
|
|
33
|
+
if (snap.redirected || (snap.status >= 300 && snap.status < 400)) {
|
|
34
|
+
return { kind: 'infra_error', status: snap.status, message: `unexpected redirect (${snap.status}); not followed` };
|
|
35
|
+
}
|
|
36
|
+
// 2. Credential / permission / throttle signals keyed purely on status.
|
|
37
|
+
if (snap.status === 401)
|
|
38
|
+
return { kind: 'auth_invalid' };
|
|
39
|
+
if (snap.status === 403) {
|
|
40
|
+
const message = asString(snap.body?.message) ?? 'you are not an admin of the target org';
|
|
41
|
+
return { kind: 'forbidden', message };
|
|
42
|
+
}
|
|
43
|
+
if (snap.status === 429) {
|
|
44
|
+
const message = asString(snap.body?.message) ?? 'too many requests';
|
|
45
|
+
return { kind: 'rate_limited', message };
|
|
46
|
+
}
|
|
47
|
+
// 3. 503 — split by envelope code (pending soft-success vs hard error).
|
|
48
|
+
if (snap.status === 503) {
|
|
49
|
+
const code = asString(snap.body?.code);
|
|
50
|
+
const message = asString(snap.body?.message) ?? code ?? 'service unavailable';
|
|
51
|
+
if (code === exports.POINTER_SYNC_PENDING) {
|
|
52
|
+
return { kind: 'soft_success', code, message, resource: extraResource(snap.body?.extra) };
|
|
53
|
+
}
|
|
54
|
+
if (code) {
|
|
55
|
+
// e.g. SITE_DISABLED — a hard failure, NOT a soft success.
|
|
56
|
+
return { kind: 'business_error', code, message, retryable: false };
|
|
57
|
+
}
|
|
58
|
+
return { kind: 'infra_error', status: 503, message };
|
|
59
|
+
}
|
|
60
|
+
// 4. Any other 5xx / body read error → infra.
|
|
61
|
+
if (snap.status >= 500) {
|
|
62
|
+
return { kind: 'infra_error', status: snap.status, message: `server error (${snap.status})` };
|
|
63
|
+
}
|
|
64
|
+
if (snap.bodyError) {
|
|
65
|
+
return { kind: 'infra_error', status: snap.status, message: snap.bodyError };
|
|
66
|
+
}
|
|
67
|
+
// 5. 2xx — parse the envelope code.
|
|
68
|
+
if (snap.status >= 200 && snap.status < 300) {
|
|
69
|
+
const code = asString(snap.body?.code);
|
|
70
|
+
if (!code) {
|
|
71
|
+
return { kind: 'infra_error', status: snap.status, message: 'response missing string `code` (unexpected envelope shape)' };
|
|
72
|
+
}
|
|
73
|
+
if (code === 'SUCCESS') {
|
|
74
|
+
return { kind: 'success', data: snap.body?.data };
|
|
75
|
+
}
|
|
76
|
+
const message = asString(snap.body?.message) ?? code;
|
|
77
|
+
const retryable = RETRYABLE_CODES.has(code) || extraRetryable(snap.body?.extra);
|
|
78
|
+
return { kind: 'business_error', code, message, retryable };
|
|
79
|
+
}
|
|
80
|
+
// 6. Anything else (unexpected 4xx that is not 401/403/429).
|
|
81
|
+
const message = asString(snap.body?.message) ?? `unexpected status ${snap.status}`;
|
|
82
|
+
return { kind: 'infra_error', status: snap.status, message };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Turns a business/hard error code into a user-facing, actionable line. Kept
|
|
86
|
+
* here (not in the command) so it is unit-testable against the exact backend
|
|
87
|
+
* codes (TC-S09/S10/S24).
|
|
88
|
+
*/
|
|
89
|
+
function describeSiteError(code, message) {
|
|
90
|
+
switch (code) {
|
|
91
|
+
case 'SLUG_TAKEN':
|
|
92
|
+
return `${message} — 该 slug 已被占用,请改用 --slug <其他 slug> 重试`;
|
|
93
|
+
case 'SITE_QUOTA_EXCEEDED':
|
|
94
|
+
return `${message} — 站点数量已达上限,请前往控制台处理`;
|
|
95
|
+
case 'ENV_QUOTA_EXCEEDED':
|
|
96
|
+
return `${message} — 站点环境数已达上限(≤3),请前往控制台处理`;
|
|
97
|
+
case 'DEPLOY_CAPACITY_EXCEEDED':
|
|
98
|
+
return `${message} — 实例上传繁忙,请稍后重试`;
|
|
99
|
+
case 'INVALID_SLUG':
|
|
100
|
+
return `${message} — slug 需为 1-40 位小写字母/数字/内部连字符,请改用 --slug`;
|
|
101
|
+
case 'RESERVED_SLUG':
|
|
102
|
+
return `${message} — 该 slug 为保留字,请改用 --slug`;
|
|
103
|
+
case 'SITE_DISABLED':
|
|
104
|
+
return `${message} — 站点已被禁用,请前往控制台启用后重试`;
|
|
105
|
+
case 'NOT_FOUND':
|
|
106
|
+
return `${message}`;
|
|
107
|
+
default:
|
|
108
|
+
return message;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=responseClassifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseClassifier.js","sourceRoot":"","sources":["../../src/publish/responseClassifier.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,6EAA6E;AAC7E,gCAAgC;AAChC,+EAA+E;AAC/E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,qEAAqE;AACrE,gFAAgF;AAChF,gFAAgF;AAChF,4EAA4E;;;AAiD5E,oDAwDC;AAOD,8CAqBC;AAnIY,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AA8B3D,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAK,KAAiC,EAAE,CAAC;QAC3F,OAAQ,KAAiC,CAAC,QAAQ,CAAC;IACrD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAK,KAAiC,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9G,CAAC;AAED,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAE9D,SAAgB,oBAAoB,CAAC,IAAkB;IACrD,0EAA0E;IAC1E,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,CA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,EAAE,KAAK,CAAC,CAAC;QAChF,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAC9D,CAAC;IAED,6DAA6D;IAC7D,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC;IACnF,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,OAAe;IAC7D,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY;YACf,OAAO,GAAG,OAAO,wCAAwC,CAAC;QAC5D,KAAK,qBAAqB;YACxB,OAAO,GAAG,OAAO,sBAAsB,CAAC;QAC1C,KAAK,oBAAoB;YACvB,OAAO,GAAG,OAAO,2BAA2B,CAAC;QAC/C,KAAK,0BAA0B;YAC7B,OAAO,GAAG,OAAO,iBAAiB,CAAC;QACrC,KAAK,cAAc;YACjB,OAAO,GAAG,OAAO,2CAA2C,CAAC;QAC/D,KAAK,eAAe;YAClB,OAAO,GAAG,OAAO,2BAA2B,CAAC;QAC/C,KAAK,eAAe;YAClB,OAAO,GAAG,OAAO,uBAAuB,CAAC;QAC3C,KAAK,WAAW;YACd,OAAO,GAAG,OAAO,EAAE,CAAC;QACtB;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SiteClient = void 0;
|
|
4
|
+
// Independent SuperSite HTTP client (AC-S6). A SEPARATE client from
|
|
5
|
+
// consoleClient because:
|
|
6
|
+
// - consoleClient is JSON-only (content-type: application/json, JSON.stringify
|
|
7
|
+
// body) and cannot send the multipart deploy upload;
|
|
8
|
+
// - consoleClient buckets ALL 5xx as infra_error, which would misread the
|
|
9
|
+
// `503 POINTER_SYNC_PENDING` soft-success as an infrastructure failure.
|
|
10
|
+
// It reuses the ENVELOPE-CODE classification *concept* (responseClassifier.ts)
|
|
11
|
+
// but drives its own fetch + FormData, and — like consoleClient — hard-fails on
|
|
12
|
+
// any redirect (redirect:'manual') so a Bearer request is never forwarded to
|
|
13
|
+
// another origin (TC-S23).
|
|
14
|
+
const responseClassifier_1 = require("./responseClassifier");
|
|
15
|
+
// Transport guard (TECH.md §模块4): the zip file part must be <= 50 MiB. This is
|
|
16
|
+
// a fail-fast on the file size only; the backend `inspect_zip` remains the final
|
|
17
|
+
// arbiter of the actual multipart body size.
|
|
18
|
+
const UPLOAD_FILE_LIMIT_BYTES = 50 * 1024 * 1024;
|
|
19
|
+
async function toSnapshot(res) {
|
|
20
|
+
const redirected = res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400);
|
|
21
|
+
if (redirected) {
|
|
22
|
+
return { status: res.status, redirected: true };
|
|
23
|
+
}
|
|
24
|
+
let text;
|
|
25
|
+
try {
|
|
26
|
+
text = await res.text();
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return { status: res.status, bodyError: `failed to read response body: ${err.message}` };
|
|
30
|
+
}
|
|
31
|
+
let body = null;
|
|
32
|
+
if (text.length > 0) {
|
|
33
|
+
try {
|
|
34
|
+
body = JSON.parse(text);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return { status: res.status, bodyError: 'response was not valid JSON' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { status: res.status, body };
|
|
41
|
+
}
|
|
42
|
+
class SiteClient {
|
|
43
|
+
apiOrigin;
|
|
44
|
+
fetchImpl;
|
|
45
|
+
constructor(apiOrigin, fetchImpl) {
|
|
46
|
+
this.apiOrigin = apiOrigin;
|
|
47
|
+
this.fetchImpl = fetchImpl ?? globalThis.fetch;
|
|
48
|
+
}
|
|
49
|
+
headers(ctx, extra) {
|
|
50
|
+
return {
|
|
51
|
+
accept: 'application/json',
|
|
52
|
+
authorization: `Bearer ${ctx.accessToken}`,
|
|
53
|
+
'x-org-id': ctx.orgId,
|
|
54
|
+
...extra,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async send(ctx, method, path, opts = {}) {
|
|
58
|
+
if (!this.fetchImpl) {
|
|
59
|
+
return { kind: 'infra_error', message: 'no fetch implementation available (requires Node >=18)' };
|
|
60
|
+
}
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 60_000);
|
|
63
|
+
let res;
|
|
64
|
+
try {
|
|
65
|
+
const headers = this.headers(ctx, opts.jsonBody !== undefined ? { 'content-type': 'application/json' } : undefined);
|
|
66
|
+
res = await this.fetchImpl(`${this.apiOrigin}${path}`, {
|
|
67
|
+
method,
|
|
68
|
+
headers,
|
|
69
|
+
body: (opts.jsonBody !== undefined ? JSON.stringify(opts.jsonBody) : opts.formBody),
|
|
70
|
+
// NEVER follow a redirect on a Bearer request (Bearer-leak guard).
|
|
71
|
+
redirect: 'manual',
|
|
72
|
+
signal: controller.signal,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return { kind: 'infra_error', message: `network error: ${err.message}` };
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
}
|
|
81
|
+
return (0, responseClassifier_1.classifySiteResponse)(await toSnapshot(res));
|
|
82
|
+
}
|
|
83
|
+
getSite(ctx, slug) {
|
|
84
|
+
return this.send(ctx, 'GET', `/api/console/sites/${encodeURIComponent(slug)}`);
|
|
85
|
+
}
|
|
86
|
+
createSite(ctx, body) {
|
|
87
|
+
return this.send(ctx, 'POST', '/api/console/sites', { jsonBody: body });
|
|
88
|
+
}
|
|
89
|
+
createEnv(ctx, slug, body) {
|
|
90
|
+
return this.send(ctx, 'POST', `/api/console/sites/${encodeURIComponent(slug)}/envs`, { jsonBody: body });
|
|
91
|
+
}
|
|
92
|
+
deploy(ctx, slug, env, input) {
|
|
93
|
+
if (input.zip.length > UPLOAD_FILE_LIMIT_BYTES) {
|
|
94
|
+
return Promise.resolve({
|
|
95
|
+
kind: 'infra_error',
|
|
96
|
+
message: `zip 文件 ${input.zip.length} 字节超出上传上限(50MiB)`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const form = new FormData();
|
|
100
|
+
// A fresh Uint8Array view avoids handing the (possibly pooled) Buffer's
|
|
101
|
+
// underlying ArrayBuffer to Blob.
|
|
102
|
+
const bytes = new Uint8Array(input.zip.byteLength);
|
|
103
|
+
bytes.set(input.zip);
|
|
104
|
+
form.append('file', new Blob([bytes], { type: 'application/zip' }), 'site.zip');
|
|
105
|
+
if (input.version !== undefined)
|
|
106
|
+
form.append('version', input.version);
|
|
107
|
+
if (input.description !== undefined)
|
|
108
|
+
form.append('description', input.description);
|
|
109
|
+
return this.send(ctx, 'POST', `/api/console/sites/${encodeURIComponent(slug)}/envs/${encodeURIComponent(env)}/deploys`, { formBody: form });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.SiteClient = SiteClient;
|
|
113
|
+
//# sourceMappingURL=siteClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siteClient.js","sourceRoot":"","sources":["../../src/publish/siteClient.ts"],"names":[],"mappings":";;;AAAA,oEAAoE;AACpE,yBAAyB;AACzB,iFAAiF;AACjF,yDAAyD;AACzD,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,2BAA2B;AAC3B,6DAAiG;AAmBjG,+EAA+E;AAC/E,iFAAiF;AACjF,6CAA6C;AAC7C,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAQjD,KAAK,UAAU,UAAU,CAAC,GAAa;I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