@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,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Console API client: envelope parsing + the three-way credential signal
|
|
3
|
+
// (AC-9 / TC-33 / TC-36), and a hard "never follow a redirect" rule for
|
|
4
|
+
// authenticated calls (AC-10 / TC-35).
|
|
5
|
+
//
|
|
6
|
+
// Contract (TECH.md §错误处理 / PRD §API 契约):
|
|
7
|
+
// 200 + code=="SUCCESS" -> success(data)
|
|
8
|
+
// 200 + code!="SUCCESS" -> business_error (message-worthy, does NOT mean the
|
|
9
|
+
// credential is invalid — callers must not touch
|
|
10
|
+
// local account state on this signal)
|
|
11
|
+
// 401 -> auth_invalid (credential-bearing endpoints only;
|
|
12
|
+
// the ONLY signal callers may act on to mark an
|
|
13
|
+
// account NeedsLogin)
|
|
14
|
+
// 429 -> rate_limited (creation endpoint only)
|
|
15
|
+
// 5xx / network / malformed -> infra_error (never touches local account state)
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ConsoleClient = void 0;
|
|
18
|
+
exports.performRequest = performRequest;
|
|
19
|
+
async function performRequest(apiOrigin, method, path, opts = {}) {
|
|
20
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
21
|
+
if (!fetchImpl) {
|
|
22
|
+
return { kind: 'infra_error', message: 'no fetch implementation available (requires Node >=18)' };
|
|
23
|
+
}
|
|
24
|
+
const url = `${apiOrigin}${path}`;
|
|
25
|
+
const headers = { accept: 'application/json' };
|
|
26
|
+
if (opts.body !== undefined)
|
|
27
|
+
headers['content-type'] = 'application/json';
|
|
28
|
+
if (opts.bearer)
|
|
29
|
+
headers.authorization = `Bearer ${opts.bearer}`;
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 15_000);
|
|
32
|
+
let res;
|
|
33
|
+
try {
|
|
34
|
+
res = await fetchImpl(url, {
|
|
35
|
+
method,
|
|
36
|
+
headers,
|
|
37
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
38
|
+
// Authenticated calls must never silently follow a redirect to another
|
|
39
|
+
// origin (or anywhere) — treat any 3xx as a failure instead (TC-35).
|
|
40
|
+
redirect: 'manual',
|
|
41
|
+
signal: controller.signal,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return { kind: 'infra_error', message: `network error: ${err.message}` };
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
}
|
|
50
|
+
if (res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400)) {
|
|
51
|
+
return { kind: 'infra_error', status: res.status, message: `unexpected redirect (${res.status}); not followed` };
|
|
52
|
+
}
|
|
53
|
+
if (res.status === 401) {
|
|
54
|
+
return { kind: 'auth_invalid' };
|
|
55
|
+
}
|
|
56
|
+
if (res.status === 429) {
|
|
57
|
+
return { kind: 'rate_limited', message: 'too many requests, try again later' };
|
|
58
|
+
}
|
|
59
|
+
if (res.status >= 500) {
|
|
60
|
+
return { kind: 'infra_error', status: res.status, message: `server error (${res.status})` };
|
|
61
|
+
}
|
|
62
|
+
let bodyText;
|
|
63
|
+
try {
|
|
64
|
+
bodyText = await res.text();
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
return { kind: 'infra_error', status: res.status, message: `failed to read response body: ${err.message}` };
|
|
68
|
+
}
|
|
69
|
+
if (res.status < 200 || res.status >= 300) {
|
|
70
|
+
return { kind: 'infra_error', status: res.status, message: `unexpected status ${res.status}` };
|
|
71
|
+
}
|
|
72
|
+
let envelope;
|
|
73
|
+
try {
|
|
74
|
+
envelope = bodyText.length > 0 ? JSON.parse(bodyText) : {};
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { kind: 'infra_error', status: res.status, message: 'response was not valid JSON' };
|
|
78
|
+
}
|
|
79
|
+
if (typeof envelope.code !== 'string') {
|
|
80
|
+
return { kind: 'infra_error', status: res.status, message: 'response missing string `code` (unexpected envelope shape)' };
|
|
81
|
+
}
|
|
82
|
+
if (envelope.code === 'SUCCESS') {
|
|
83
|
+
return { kind: 'success', data: envelope.data };
|
|
84
|
+
}
|
|
85
|
+
return { kind: 'business_error', code: envelope.code, message: envelope.message ?? envelope.code };
|
|
86
|
+
}
|
|
87
|
+
class ConsoleClient {
|
|
88
|
+
apiOrigin;
|
|
89
|
+
fetchImpl;
|
|
90
|
+
constructor(apiOrigin, fetchImpl) {
|
|
91
|
+
this.apiOrigin = apiOrigin;
|
|
92
|
+
this.fetchImpl = fetchImpl;
|
|
93
|
+
}
|
|
94
|
+
createAuthorizeRequest(input) {
|
|
95
|
+
return performRequest(this.apiOrigin, 'POST', '/api/console/auth/cli/authorize/request', { body: input, fetchImpl: this.fetchImpl });
|
|
96
|
+
}
|
|
97
|
+
exchangeCode(input) {
|
|
98
|
+
return performRequest(this.apiOrigin, 'POST', '/api/console/auth/cli/token', {
|
|
99
|
+
body: input,
|
|
100
|
+
fetchImpl: this.fetchImpl,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
refresh(refreshToken) {
|
|
104
|
+
return performRequest(this.apiOrigin, 'POST', '/api/console/auth/cli/refresh', {
|
|
105
|
+
body: { refresh_token: refreshToken },
|
|
106
|
+
fetchImpl: this.fetchImpl,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
logout(input) {
|
|
110
|
+
return performRequest(this.apiOrigin, 'POST', '/api/console/auth/cli/logout', {
|
|
111
|
+
body: input,
|
|
112
|
+
fetchImpl: this.fetchImpl,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
me(accessToken) {
|
|
116
|
+
return performRequest(this.apiOrigin, 'GET', '/api/console/auth/me', {
|
|
117
|
+
bearer: accessToken,
|
|
118
|
+
fetchImpl: this.fetchImpl,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Generic escape hatch for endpoints that are not part of the CLI's own
|
|
123
|
+
* runtime surface (e.g. the CW-facing approve/reject/detail endpoints) but
|
|
124
|
+
* are needed to script AC-11's automated local full-chain e2e path, which
|
|
125
|
+
* drives approval via a session bearer instead of a real browser click.
|
|
126
|
+
*/
|
|
127
|
+
requestRaw(method, path, opts) {
|
|
128
|
+
return performRequest(this.apiOrigin, method, path, { ...opts, fetchImpl: this.fetchImpl });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ConsoleClient = ConsoleClient;
|
|
132
|
+
//# sourceMappingURL=consoleClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleClient.js","sourceRoot":"","sources":["../../src/api/consoleClient.ts"],"names":[],"mappings":";AAAA,yEAAyE;AACzE,wEAAwE;AACxE,uCAAuC;AACvC,EAAE;AACF,0CAA0C;AAC1C,gDAAgD;AAChD,oFAAoF;AACpF,iFAAiF;AACjF,sEAAsE;AACtE,mFAAmF;AACnF,gFAAgF;AAChF,s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});
|
|
3
|
+
exports.defaultOpenBrowser = void 0;
|
|
4
|
+
exports.login = login;
|
|
5
|
+
// Browser-authorized login (AC-2/AC-3/AC-4): create an authorize request,
|
|
6
|
+
// open it in a browser (or print the URL if that fails), accept the pasted
|
|
7
|
+
// one-time code, exchange it, confirm identity via /me, and only THEN persist
|
|
8
|
+
// anything locally. Every failure path after the token exchange best-effort
|
|
9
|
+
// revokes whatever was just issued and leaves local state exactly as it was.
|
|
10
|
+
const node_child_process_1 = require("node:child_process");
|
|
11
|
+
const accountStore_1 = require("../store/accountStore");
|
|
12
|
+
const log_1 = require("../util/log");
|
|
13
|
+
function describeFailure(action, outcome) {
|
|
14
|
+
switch (outcome.kind) {
|
|
15
|
+
case 'auth_invalid':
|
|
16
|
+
return `${action} failed: credential invalid or expired`;
|
|
17
|
+
case 'business_error':
|
|
18
|
+
return `${action} failed: ${outcome.message} (${outcome.code})`;
|
|
19
|
+
case 'rate_limited':
|
|
20
|
+
case 'infra_error':
|
|
21
|
+
return `${action} failed: ${outcome.message}`;
|
|
22
|
+
default:
|
|
23
|
+
return `${action} failed`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function bestEffortRevoke(client, bundle) {
|
|
27
|
+
try {
|
|
28
|
+
const outcome = await client.logout({ refresh_token: bundle.refresh_token, access_token: bundle.access_token });
|
|
29
|
+
if (outcome.kind !== 'success') {
|
|
30
|
+
log_1.log.warn('best-effort revoke did not confirm success (continuing anyway)', { outcomeKind: outcome.kind });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
log_1.log.warn('best-effort revoke threw (continuing anyway)', { error: err.message });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function login(deps) {
|
|
38
|
+
const { client, backend, env } = deps;
|
|
39
|
+
const createOutcome = await client.createAuthorizeRequest({
|
|
40
|
+
client_name: 'supercli',
|
|
41
|
+
cli_version: deps.cliVersion,
|
|
42
|
+
});
|
|
43
|
+
if (createOutcome.kind !== 'success') {
|
|
44
|
+
return { ok: false, message: describeFailure('create authorize request', createOutcome) };
|
|
45
|
+
}
|
|
46
|
+
const { request_id } = createOutcome.data;
|
|
47
|
+
const authorizeUrl = `${env.webOrigin}/cli/authorize?request=${encodeURIComponent(request_id)}`;
|
|
48
|
+
const opened = await deps.openBrowser(authorizeUrl);
|
|
49
|
+
if (!opened) {
|
|
50
|
+
log_1.log.info(`could not open a browser automatically — open this URL to continue: ${authorizeUrl}`);
|
|
51
|
+
}
|
|
52
|
+
const code = deps.promptCode().trim();
|
|
53
|
+
if (!code) {
|
|
54
|
+
return { ok: false, message: 'no authorization code entered' };
|
|
55
|
+
}
|
|
56
|
+
const exchangeOutcome = await client.exchangeCode({ request_id, code });
|
|
57
|
+
if (exchangeOutcome.kind !== 'success') {
|
|
58
|
+
return { ok: false, message: describeFailure('exchange authorization code', exchangeOutcome) };
|
|
59
|
+
}
|
|
60
|
+
const bundle = exchangeOutcome.data;
|
|
61
|
+
const meOutcome = await client.me(bundle.access_token);
|
|
62
|
+
if (meOutcome.kind !== 'success') {
|
|
63
|
+
// AC-3: /me must confirm business success (code=="SUCCESS"), not just
|
|
64
|
+
// HTTP 200, before anything is persisted. On any other outcome, revoke
|
|
65
|
+
// the freshly issued credential and leave local state untouched.
|
|
66
|
+
await bestEffortRevoke(client, bundle);
|
|
67
|
+
return { ok: false, message: `signed-in identity check failed: ${describeFailure('/me', meOutcome)}` };
|
|
68
|
+
}
|
|
69
|
+
const { user } = meOutcome.data;
|
|
70
|
+
const accountKey = (0, accountStore_1.deriveAccountKey)(env.label, env.apiOrigin, user.id);
|
|
71
|
+
const existing = (0, accountStore_1.getAccount)(accountKey);
|
|
72
|
+
// Captured BEFORE any mutation so a failed commit can restore it exactly (TC-12).
|
|
73
|
+
const oldSecret = existing ? backend.get(accountKey) : null;
|
|
74
|
+
const newSecret = {
|
|
75
|
+
accessToken: bundle.access_token,
|
|
76
|
+
accessExpiresAt: bundle.access_expires_at,
|
|
77
|
+
refreshToken: bundle.refresh_token,
|
|
78
|
+
refreshExpiresAt: bundle.refresh_expires_at,
|
|
79
|
+
};
|
|
80
|
+
const record = {
|
|
81
|
+
accountKey,
|
|
82
|
+
envLabel: env.label,
|
|
83
|
+
apiOrigin: env.apiOrigin,
|
|
84
|
+
webOrigin: env.webOrigin,
|
|
85
|
+
userId: user.id,
|
|
86
|
+
email: user.email,
|
|
87
|
+
nickname: user.nickname,
|
|
88
|
+
status: 'active',
|
|
89
|
+
backend: backend.kind,
|
|
90
|
+
createdAt: existing?.createdAt ?? Date.now(),
|
|
91
|
+
updatedAt: Date.now(),
|
|
92
|
+
};
|
|
93
|
+
let credentialCommitted = false;
|
|
94
|
+
try {
|
|
95
|
+
backend.set(accountKey, newSecret);
|
|
96
|
+
credentialCommitted = true;
|
|
97
|
+
(0, accountStore_1.upsertAccountAndSetCurrent)(record);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
log_1.log.error('local commit failed after a successful token exchange — rolling back', {
|
|
101
|
+
accountKey,
|
|
102
|
+
error: err.message,
|
|
103
|
+
});
|
|
104
|
+
if (credentialCommitted) {
|
|
105
|
+
try {
|
|
106
|
+
if (oldSecret) {
|
|
107
|
+
backend.set(accountKey, oldSecret);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
backend.delete(accountKey);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (rollbackErr) {
|
|
114
|
+
log_1.log.error('rollback of credential backend also failed', {
|
|
115
|
+
accountKey,
|
|
116
|
+
error: rollbackErr.message,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
await bestEffortRevoke(client, bundle);
|
|
121
|
+
return { ok: false, message: `failed to save account locally: ${err.message}` };
|
|
122
|
+
}
|
|
123
|
+
// Duplicate login success (AC-4/TC-11): only revoke the OLD credential
|
|
124
|
+
// after the NEW one is durably committed, never before.
|
|
125
|
+
if (existing && oldSecret) {
|
|
126
|
+
await bestEffortRevoke(client, { access_token: oldSecret.accessToken, refresh_token: oldSecret.refreshToken });
|
|
127
|
+
}
|
|
128
|
+
log_1.log.info('login successful', { accountKey, email: (0, log_1.maskEmail)(user.email) });
|
|
129
|
+
return { ok: true, account: record };
|
|
130
|
+
}
|
|
131
|
+
/** Best-effort "open the default browser"; no reliable cross-platform signal that a window actually appeared. */
|
|
132
|
+
const defaultOpenBrowser = async (url) => {
|
|
133
|
+
const platform = process.platform;
|
|
134
|
+
let cmd;
|
|
135
|
+
let args;
|
|
136
|
+
if (platform === 'darwin') {
|
|
137
|
+
cmd = 'open';
|
|
138
|
+
args = [url];
|
|
139
|
+
}
|
|
140
|
+
else if (platform === 'win32') {
|
|
141
|
+
cmd = 'cmd';
|
|
142
|
+
args = ['/c', 'start', '""', url];
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
cmd = 'xdg-open';
|
|
146
|
+
args = [url];
|
|
147
|
+
}
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
let child;
|
|
150
|
+
try {
|
|
151
|
+
child = (0, node_child_process_1.spawn)(cmd, args, { stdio: 'ignore', detached: true });
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
resolve(false);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
child.once('error', () => resolve(false));
|
|
158
|
+
child.unref();
|
|
159
|
+
setImmediate(() => resolve(true));
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
exports.defaultOpenBrowser = defaultOpenBrowser;
|
|
163
|
+
//# sourceMappingURL=browserAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserAuth.js","sourceRoot":"","sources":["../../src/auth/browserAuth.ts"],"names":[],"mappings":";;;AA0DA,sBAoGC;AA9JD,0EAA0E;AAC1E,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,2DAA2C;AAG3C,wDAAqH;AAErH,qCAA6C;AAo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exports, "__esModule", { value: true });
|
|
3
|
+
exports.refreshAccessToken = refreshAccessToken;
|
|
4
|
+
const log_1 = require("../util/log");
|
|
5
|
+
async function refreshAccessToken(client, backend, accountKey) {
|
|
6
|
+
const current = backend.get(accountKey);
|
|
7
|
+
if (!current) {
|
|
8
|
+
return { kind: 'needs_login' };
|
|
9
|
+
}
|
|
10
|
+
const outcome = await client.refresh(current.refreshToken);
|
|
11
|
+
if (outcome.kind === 'success') {
|
|
12
|
+
const secret = {
|
|
13
|
+
accessToken: outcome.data.access_token,
|
|
14
|
+
accessExpiresAt: outcome.data.access_expires_at,
|
|
15
|
+
refreshToken: outcome.data.refresh_token,
|
|
16
|
+
refreshExpiresAt: outcome.data.refresh_expires_at,
|
|
17
|
+
};
|
|
18
|
+
backend.set(accountKey, secret);
|
|
19
|
+
return { kind: 'refreshed', secret };
|
|
20
|
+
}
|
|
21
|
+
if (outcome.kind === 'auth_invalid') {
|
|
22
|
+
// Rotated/expired/pwd_ver mismatch — the ONLY signal that may mark the
|
|
23
|
+
// account needs-login (AC-9); the caller (commands/*) is responsible for
|
|
24
|
+
// actually calling accountStore.markAccountNeedsLogin.
|
|
25
|
+
log_1.log.warn('refresh token invalid, expired, or rotated elsewhere — account needs re-login', { accountKey });
|
|
26
|
+
return { kind: 'needs_login' };
|
|
27
|
+
}
|
|
28
|
+
// business_error / rate_limited / infra_error: never touch local account
|
|
29
|
+
// state on anything but a real 401 (AC-9).
|
|
30
|
+
return { kind: 'infra_error', message: outcome.message };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../src/auth/refresh.ts"],"names":[],"mappings":";;AAqBA,gDAkCC;AA9CD,qCAAkC;AAY3B,KAAK,UAAU,kBAAkB,CACtC,MAA4B,EAC5B,OAA0B,EAC1B,UAAkB;IAElB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,OAAO,GAAoC,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAE5F,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAqB;YAC/B,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY;YACtC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB;YAC/C,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,aAAa;YACxC,gBAAgB,EAAE,OAAO,CAAC,IAAI,CAAC,kBAAkB;SAClD,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACpC,uEAAuE;QACvE,yEAAyE;QACzE,uDAAuD;QACvD,SAAG,CAAC,IAAI,CAAC,+EAA+E,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAC1G,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IACjC,CAAC;IAED,yEAAyE;IACzE,2CAA2C;IAC3C,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.buildProgram = buildProgram;
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const accounts_1 = require("./commands/accounts");
|
|
7
|
+
const createApp_1 = require("./commands/createApp");
|
|
8
|
+
const login_1 = require("./commands/login");
|
|
9
|
+
const logout_1 = require("./commands/logout");
|
|
10
|
+
const publishSite_1 = require("./commands/publishSite");
|
|
11
|
+
const switchaccount_1 = require("./commands/switchaccount");
|
|
12
|
+
const update_1 = require("./commands/update");
|
|
13
|
+
// package.json is always shipped alongside dist/ in an npm package (npm
|
|
14
|
+
// always includes it regardless of the "files" allowlist), so this resolves
|
|
15
|
+
// correctly both in local dev and in an installed/packed tarball.
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
+
const pkg = require('../package.json');
|
|
18
|
+
function buildProgram() {
|
|
19
|
+
const program = new commander_1.Command();
|
|
20
|
+
program
|
|
21
|
+
.name('supercli')
|
|
22
|
+
.description('SuperSDK official command-line tool: browser-authorized login and multi-account context.')
|
|
23
|
+
.version(pkg.version, '--version', 'output the version number');
|
|
24
|
+
(0, login_1.registerLoginCommand)(program);
|
|
25
|
+
(0, accounts_1.registerAccountsCommand)(program);
|
|
26
|
+
(0, switchaccount_1.registerSwitchAccountCommand)(program);
|
|
27
|
+
(0, logout_1.registerLogoutCommand)(program);
|
|
28
|
+
(0, update_1.registerUpdateCommand)(program);
|
|
29
|
+
(0, createApp_1.registerCreateAppCommand)(program);
|
|
30
|
+
(0, publishSite_1.registerPublishSiteCommand)(program);
|
|
31
|
+
return program;
|
|
32
|
+
}
|
|
33
|
+
async function run() {
|
|
34
|
+
const program = buildProgram();
|
|
35
|
+
// Commander's default (no exitOverride()) behavior already satisfies AC-1:
|
|
36
|
+
// --version/--help print to stdout and exit 0; an unknown command prints
|
|
37
|
+
// an error to stderr and exits non-zero.
|
|
38
|
+
await program.parseAsync(process.argv);
|
|
39
|
+
}
|
|
40
|
+
if (require.main === module) {
|
|
41
|
+
run().catch((err) => {
|
|
42
|
+
process.stderr.write(`[error] ${err.message}\n`);
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# s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K,CAAC,CAAC,GAAG,EAAE,EAAE;QAClB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAY,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC;QAC5D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerAccountsCommand = registerAccountsCommand;
|
|
4
|
+
const accountStore_1 = require("../store/accountStore");
|
|
5
|
+
const credentialStore_1 = require("../store/credentialStore");
|
|
6
|
+
const log_1 = require("../util/log");
|
|
7
|
+
function registerAccountsCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command('accounts')
|
|
10
|
+
.description('List saved accounts and show which one is current')
|
|
11
|
+
.action(() => {
|
|
12
|
+
const accounts = (0, accountStore_1.listAccounts)();
|
|
13
|
+
const current = (0, accountStore_1.getCurrentAccount)();
|
|
14
|
+
if (accounts.length === 0) {
|
|
15
|
+
log_1.log.info('no saved accounts — run `supercli login` to add one');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const withHealth = (0, accountStore_1.withCredentialHealth)(accounts, (accountKey) => checkCredential(accounts, accountKey));
|
|
19
|
+
for (const account of withHealth) {
|
|
20
|
+
const marker = current?.accountKey === account.accountKey ? '*' : ' ';
|
|
21
|
+
const statusLabel = account.status === 'needs-login' ? ' (needs login)' : '';
|
|
22
|
+
const healthLabel = account.credentialStatus === 'corrupt' ? ` (${account.credentialError})` : '';
|
|
23
|
+
log_1.log.info(`${marker} ${account.accountKey} ${account.email} [${account.envLabel}]${statusLabel}${healthLabel}`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Best-effort, non-interactive credential health probe consumed via
|
|
29
|
+
* accountStore.withCredentialHealth (the single implementation of this
|
|
30
|
+
* pattern — TC-32 tests it there directly with an injected fake). Never
|
|
31
|
+
* prompts for a passphrase from a plain listing command: encrypted-file
|
|
32
|
+
* accounts are reported "ok" here unconditionally (decrypt-to-verify only
|
|
33
|
+
* happens when a credential is actually used, e.g. during refresh).
|
|
34
|
+
*/
|
|
35
|
+
function checkCredential(accounts, accountKey) {
|
|
36
|
+
const account = accounts.find((a) => a.accountKey === accountKey);
|
|
37
|
+
if (!account)
|
|
38
|
+
return { ok: false, error: 'unknown account' };
|
|
39
|
+
if (account.backend === 'encrypted-file')
|
|
40
|
+
return { ok: true };
|
|
41
|
+
const backend = (0, credentialStore_1.backendForAccount)('os-keyring');
|
|
42
|
+
if (!backend.isAvailable())
|
|
43
|
+
return { ok: false, error: 'OS credential service unavailable' };
|
|
44
|
+
return backend.get(accountKey) ? { ok: true } : { ok: false, error: 'credential missing — re-login' };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/commands/accounts.ts"],"names":[],"mappings":";;AAKA,0DAuBC;AA3BD,wDAAkH;AAClH,8DAA6D;AAC7D,qCAAkC;AAElC,SAAgB,uBAAuB,CAAC,OAAgB;IACtD,OAAO;SACJ,OAAO,CAAC,UAAU,CAAC;SACnB,WAAW,CAAC,mDAAmD,CAAC;SAChE,MAAM,CAAC,GAAG,EAAE;QACX,MAAM,QAAQ,GAAG,IAAA,2BAAY,GAAE,CAAC;QAChC,MAAM,OAAO,GAAG,IAAA,gCAAiB,GAAE,CAAC;QACpC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,SAAG,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;YAChE,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,mCAAoB,EAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAA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