@geek-fun/serverlessinsight 0.9.7 → 0.9.8

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.
Files changed (86) hide show
  1. package/AGENTS.md +1 -0
  2. package/CHANGELOG.md +68 -6
  3. package/README.md +51 -10
  4. package/README.zh-CN.md +44 -10
  5. package/dist/package.json +2 -1
  6. package/dist/src/commands/deploy.js +3 -1
  7. package/dist/src/commands/destroy.js +3 -1
  8. package/dist/src/commands/forceUnlock.js +2 -2
  9. package/dist/src/commands/index.js +28 -8
  10. package/dist/src/commands/local.js +3 -2
  11. package/dist/src/commands/login.js +120 -37
  12. package/dist/src/commands/logout.js +3 -5
  13. package/dist/src/commands/migrate.js +17 -10
  14. package/dist/src/commands/plan.js +5 -1
  15. package/dist/src/commands/show.js +3 -1
  16. package/dist/src/commands/whoami.js +24 -6
  17. package/dist/src/common/aliyunClient/cdnOperations.js +64 -29
  18. package/dist/src/common/aliyunClient/dnsOperations.js +10 -0
  19. package/dist/src/common/aliyunClient/fc3Operations.js +36 -7
  20. package/dist/src/common/apiClient.js +1 -0
  21. package/dist/src/common/bindingReconcile.js +182 -0
  22. package/dist/src/common/cdnCapabilities.js +80 -0
  23. package/dist/src/common/certUtils.js +44 -5
  24. package/dist/src/common/consoleLines.js +126 -0
  25. package/dist/src/common/constants.js +4 -2
  26. package/dist/src/common/credentialStore.js +136 -39
  27. package/dist/src/common/domainUtils.js +23 -4
  28. package/dist/src/common/functionDefinition.js +4 -1
  29. package/dist/src/common/functionDomainCapabilities.js +28 -0
  30. package/dist/src/common/functionDomainReconcile.js +197 -0
  31. package/dist/src/common/lineContext.js +164 -0
  32. package/dist/src/common/planCapabilities.js +14 -27
  33. package/dist/src/common/planCompare.js +8 -7
  34. package/dist/src/common/planFormatter.js +71 -37
  35. package/dist/src/common/stateBackend/index.js +24 -16
  36. package/dist/src/common/stateBackend/saasStateBackend.js +46 -53
  37. package/dist/src/common/stateBackend/tosStateBackend.js +100 -0
  38. package/dist/src/common/tencentClient/cdnOperations.js +165 -0
  39. package/dist/src/common/tencentClient/cosOperations.js +18 -2
  40. package/dist/src/common/tencentClient/dnspodOperations.js +12 -0
  41. package/dist/src/common/tencentClient/index.js +16 -0
  42. package/dist/src/common/tencentClient/scfOperations.js +23 -1
  43. package/dist/src/common/tencentClient/sslOperations.js +147 -77
  44. package/dist/src/common/volcengineClient/cdnOperations.js +221 -0
  45. package/dist/src/common/volcengineClient/dnsOperations.js +132 -0
  46. package/dist/src/common/volcengineClient/index.js +28 -0
  47. package/dist/src/common/volcengineClient/tosOperations.js +131 -1
  48. package/dist/src/lang/en.js +89 -10
  49. package/dist/src/lang/zh-CN.js +90 -9
  50. package/dist/src/parser/bucketParser.js +22 -79
  51. package/dist/src/parser/functionParser.js +13 -9
  52. package/dist/src/stack/aliyunStack/apigwResource.js +2 -1
  53. package/dist/src/stack/aliyunStack/fc3Planner.js +32 -12
  54. package/dist/src/stack/aliyunStack/fc3Resource.js +169 -121
  55. package/dist/src/stack/aliyunStack/ossPlanner.js +12 -4
  56. package/dist/src/stack/aliyunStack/ossResource.js +484 -501
  57. package/dist/src/stack/aliyunStack/ossTypes.js +21 -67
  58. package/dist/src/stack/localStack/aliyunFc.js +59 -9
  59. package/dist/src/stack/localStack/bucket.js +75 -28
  60. package/dist/src/stack/localStack/event.js +33 -24
  61. package/dist/src/stack/localStack/httpAdapter.js +1 -13
  62. package/dist/src/stack/localStack/index.js +2 -2
  63. package/dist/src/stack/localStack/localServer.js +85 -7
  64. package/dist/src/stack/scfStack/cosPlanner.js +11 -3
  65. package/dist/src/stack/scfStack/cosResource.js +339 -161
  66. package/dist/src/stack/scfStack/cosTypes.js +25 -34
  67. package/dist/src/stack/scfStack/scfPlanner.js +26 -8
  68. package/dist/src/stack/scfStack/scfResource.js +191 -124
  69. package/dist/src/stack/volcengineStack/tosPlanner.js +13 -1
  70. package/dist/src/stack/volcengineStack/tosResource.js +398 -7
  71. package/dist/src/stack/volcengineStack/tosTypes.js +27 -0
  72. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -1
  73. package/dist/src/types/domains/state.js +6 -0
  74. package/dist/src/validator/bucketSchema.js +35 -113
  75. package/dist/src/validator/cdnSchema.js +30 -0
  76. package/dist/src/validator/eventSchema.js +2 -20
  77. package/dist/src/validator/functionSchema.js +55 -8
  78. package/dist/src/validator/rootSchema.js +3 -3
  79. package/dist/src/validator/semanticValidation.js +504 -1
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +2 -1
  82. package/release-notes.md +82 -6
  83. package/samples/aliyun-poc-api-cdn.yml +1 -1
  84. package/samples/aliyun-poc-bucket-cdn.yml +28 -26
  85. package/samples/aliyun-poc-domain.yml +2 -1
  86. package/samples/volcengine-poc-tos-state.yml +36 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindingToDefinitionEntry = exports.resolveBindingCertificate = exports.shouldDeployBindingCertificate = exports.desiredBindingMode = exports.cdnDeliveryChanged = exports.buildStoredBindings = exports.groupBindingInstances = exports.isBindingCdnEnabled = exports.getBindingCdnOptions = void 0;
4
+ const domainUtils_1 = require("./domainUtils");
5
+ const certUtils_1 = require("./certUtils");
6
+ const logger_1 = require("./logger");
7
+ const lang_1 = require("../lang");
8
+ /** A binding's CDN options as declared: object form, or implied by the boolean shorthand. */
9
+ const getBindingCdnOptions = (binding) => {
10
+ if (binding.cdn == null)
11
+ return undefined;
12
+ if (typeof binding.cdn === 'boolean')
13
+ return binding.cdn ? { enabled: true } : undefined;
14
+ return binding.cdn;
15
+ };
16
+ exports.getBindingCdnOptions = getBindingCdnOptions;
17
+ const isBindingCdnEnabled = (binding) => binding.cdn === true || (typeof binding.cdn === 'object' && binding.cdn?.enabled === true);
18
+ exports.isBindingCdnEnabled = isBindingCdnEnabled;
19
+ const instanceHostname = (instance) => (0, domainUtils_1.normalizeHostname)(String(instance.domainName ?? instance.domain));
20
+ /**
21
+ * Groups a resource's instances by binding hostname. `roleByType` maps each
22
+ * provider's instance type strings onto the shared roles (CDN distribution,
23
+ * CDN CNAME record, direct-binding CNAME record).
24
+ */
25
+ const groupBindingInstances = (instances, roleByType) => {
26
+ const groups = new Map();
27
+ (instances ?? []).forEach((instance) => {
28
+ const role = roleByType[String(instance.type)];
29
+ if (!role)
30
+ return;
31
+ const hostname = instanceHostname(instance);
32
+ const group = groups.get(hostname) ?? {};
33
+ group[role] = instance;
34
+ groups.set(hostname, group);
35
+ });
36
+ return groups;
37
+ };
38
+ exports.groupBindingInstances = groupBindingInstances;
39
+ /**
40
+ * Definition-first stored-binding reconstruction: reads the canonicalized
41
+ * `domains` entries from saved state, migrates legacy single-domain state via
42
+ * `legacyBinding`, and adopts instance-only bindings as a drift repair.
43
+ */
44
+ const buildStoredBindings = (existingState, groups, options) => {
45
+ const stored = new Map();
46
+ const definition = (existingState?.definition ?? {});
47
+ const accelerateEnabled = options.accelerateEnabled === true;
48
+ const domains = Array.isArray(definition.domains)
49
+ ? definition.domains
50
+ : [];
51
+ domains.forEach((entry) => {
52
+ if (typeof entry?.domain_name !== 'string')
53
+ return;
54
+ const hostname = (0, domainUtils_1.normalizeHostname)(entry.domain_name);
55
+ const cdn = typeof entry.cdn === 'object' && entry.cdn !== null ? { ...entry.cdn } : undefined;
56
+ const cdnEnabled = cdn?.enabled === true;
57
+ stored.set(hostname, {
58
+ hostname,
59
+ mode: cdnEnabled ? 'cdn' : accelerateEnabled ? 'accelerate-only' : 'direct',
60
+ ...(cdn ? { cdn: cdn } : {}),
61
+ ...(typeof entry.certificate_id === 'string' && entry.certificate_id
62
+ ? { certId: entry.certificate_id }
63
+ : {}),
64
+ ...(typeof entry.certificate_hash === 'string' && entry.certificate_hash
65
+ ? { certHash: entry.certificate_hash }
66
+ : {}),
67
+ });
68
+ });
69
+ if (options.legacyBinding) {
70
+ const legacy = options.legacyBinding(definition);
71
+ if (legacy && !stored.has(legacy.hostname))
72
+ stored.set(legacy.hostname, legacy);
73
+ }
74
+ // Drift repair: binding instances recorded in state without a definition
75
+ // entry (e.g. hand-edited state) are adopted as stored bindings by hostname.
76
+ groups.forEach((group, hostname) => {
77
+ if (stored.has(hostname))
78
+ return;
79
+ const mode = group.cdn
80
+ ? 'cdn'
81
+ : group.dns
82
+ ? accelerateEnabled
83
+ ? 'accelerate-only'
84
+ : 'direct'
85
+ : 'cdn';
86
+ stored.set(hostname, { hostname, mode });
87
+ });
88
+ return stored;
89
+ };
90
+ exports.buildStoredBindings = buildStoredBindings;
91
+ /** Whether the CDN delivery shape (service type / acceleration area) changed — the distribution-level update both providers apply through their update APIs. */
92
+ const cdnDeliveryChanged = (stored, desired) => (stored?.cdn_type ?? 'web') !== (desired?.cdn_type ?? 'web') ||
93
+ (stored?.scope ?? 'global') !== (desired?.scope ?? 'global');
94
+ exports.cdnDeliveryChanged = cdnDeliveryChanged;
95
+ /** The delivery mode a binding's declared config resolves to. */
96
+ const desiredBindingMode = (cdnEnabled, accelerate) => (cdnEnabled ? 'cdn' : accelerate ? 'accelerate-only' : 'direct');
97
+ exports.desiredBindingMode = desiredBindingMode;
98
+ /** Whether a binding's certificate requires (re)deployment, keyed on pending state, reference id and content hash. */
99
+ const shouldDeployBindingCertificate = (input) => {
100
+ const { pending, certificateId, certificateHash, stored } = input;
101
+ if (pending)
102
+ return true;
103
+ if (certificateId)
104
+ return stored?.certId !== certificateId;
105
+ if (certificateHash)
106
+ return stored?.certHash !== certificateHash;
107
+ return false;
108
+ };
109
+ exports.shouldDeployBindingCertificate = shouldDeployBindingCertificate;
110
+ /**
111
+ * Shared certificate resolution for bucket bindings (issue #283/#294):
112
+ * reference ids pass through, inline PEM pairs are read (fail-loud at deploy
113
+ * time) and hashed downstream. Providers without an upload path must reject
114
+ * inline PEM earlier, in semantic validation.
115
+ */
116
+ const resolveBindingCertificate = (binding) => {
117
+ if (binding.certificate_id) {
118
+ logger_1.logger.info(lang_1.lang.__('CERT_RESOLVING_REFERENCE', {
119
+ reference: binding.certificate_id,
120
+ domain: binding.domain_name,
121
+ }));
122
+ return { mode: 'reference', certificateId: binding.certificate_id };
123
+ }
124
+ if (binding.certificate_body && binding.certificate_private_key) {
125
+ const body = (0, certUtils_1.readPemContent)(binding.certificate_body);
126
+ const key = (0, certUtils_1.readPemContent)(binding.certificate_private_key);
127
+ (0, certUtils_1.warnInlinePem)(binding.certificate_private_key);
128
+ return {
129
+ mode: 'upload',
130
+ certificateName: binding.domain_name.replace(/\./g, '_'),
131
+ certificateBody: body,
132
+ certificatePrivateKey: key,
133
+ };
134
+ }
135
+ return undefined;
136
+ };
137
+ exports.resolveBindingCertificate = resolveBindingCertificate;
138
+ /**
139
+ * Canonicalized definition entry for one binding — the exact shape persisted
140
+ * in state and compared by plan/diff. `certificate_hash` records the
141
+ * content hash of inline PEM (or reference id) so redeploys only happen on
142
+ * change (issue #283).
143
+ */
144
+ const bindingToDefinitionEntry = (binding) => {
145
+ const cdnOptions = (0, exports.getBindingCdnOptions)(binding);
146
+ const cdnEnabled = (0, exports.isBindingCdnEnabled)(binding);
147
+ const certificateHash = (0, certUtils_1.resolveBindingCertificateHash)({
148
+ certificate_id: binding.certificateId,
149
+ certificate_body: binding.certificateBody,
150
+ certificate_private_key: binding.certificatePrivateKey,
151
+ });
152
+ return {
153
+ domain_name: binding.domainName,
154
+ certificate_id: binding.certificateId ?? null,
155
+ certificate_body: binding.certificateBody ?? null,
156
+ certificate_private_key: binding.certificatePrivateKey ? '(managed)' : null,
157
+ certificate_hash: certificateHash ?? null,
158
+ // CDN delivery state is always an explicit object: absence in YAML
159
+ // resolves to `{ enabled: false }` (the documented default). A null would
160
+ // be projected away by the planner's declared-field diff, making a
161
+ // removed `cdn` block invisible to plan/diff (issue #283).
162
+ cdn: {
163
+ enabled: cdnEnabled,
164
+ ...(cdnOptions?.cdn_type != null || cdnEnabled
165
+ ? { cdn_type: cdnOptions?.cdn_type ?? 'web' }
166
+ : {}),
167
+ ...(cdnOptions?.scope != null || cdnEnabled ? { scope: cdnOptions?.scope ?? 'global' } : {}),
168
+ ...(cdnOptions?.cache_ttl != null ? { cache_ttl: cdnOptions.cache_ttl } : {}),
169
+ ...(cdnOptions?.ignore_query_string != null
170
+ ? { ignore_query_string: cdnOptions.ignore_query_string }
171
+ : {}),
172
+ ...(cdnOptions?.origin_protocol != null
173
+ ? { origin_protocol: cdnOptions.origin_protocol }
174
+ : {}),
175
+ ...(cdnOptions?.compression != null ? { compression: cdnOptions.compression } : {}),
176
+ ...(cdnOptions?.force_redirect_https != null
177
+ ? { force_redirect_https: cdnOptions.force_redirect_https }
178
+ : {}),
179
+ },
180
+ };
181
+ };
182
+ exports.bindingToDefinitionEntry = bindingToDefinitionEntry;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapOriginProtocol = exports.mapCdnScope = exports.resolveCdnCapability = void 0;
4
+ // cdn_type union per provider (verified against provider APIs, 2026-11):
5
+ // aliyun web/download/video, tencent web/download/media/hybrid/dynamic,
6
+ // volcengine web/download/video.
7
+ const ALIYUN_CDN_TYPES = ['web', 'download', 'video'];
8
+ const TENCENT_CDN_TYPES = ['web', 'download', 'media', 'hybrid', 'dynamic'];
9
+ const VOLCENGINE_CDN_TYPES = ['web', 'download', 'video'];
10
+ const CDN_CAPABILITIES = {
11
+ aliyun: {
12
+ bucketCdn: true,
13
+ eventCdn: true,
14
+ cdnTypes: ALIYUN_CDN_TYPES,
15
+ scopeMap: {
16
+ chinese_mainland: 'domestic',
17
+ overseas: 'overseas',
18
+ global: 'global',
19
+ },
20
+ originProtocolMap: {
21
+ http: 'http',
22
+ https: 'https',
23
+ follow: 'follow',
24
+ },
25
+ },
26
+ tencent: {
27
+ bucketCdn: true,
28
+ eventCdn: false,
29
+ cdnTypes: TENCENT_CDN_TYPES,
30
+ scopeMap: {
31
+ chinese_mainland: 'mainland',
32
+ overseas: 'overseas',
33
+ global: 'global',
34
+ },
35
+ originProtocolMap: {
36
+ http: 'http',
37
+ https: 'https',
38
+ follow: 'follow',
39
+ },
40
+ },
41
+ volcengine: {
42
+ bucketCdn: true,
43
+ eventCdn: false,
44
+ cdnTypes: VOLCENGINE_CDN_TYPES,
45
+ scopeMap: {
46
+ chinese_mainland: 'chinese_mainland',
47
+ overseas: 'outside_chinese_mainland',
48
+ global: 'global',
49
+ },
50
+ originProtocolMap: {
51
+ http: 'http',
52
+ https: 'https',
53
+ follow: 'followclient',
54
+ },
55
+ },
56
+ };
57
+ const resolveCdnCapability = (providerName) => {
58
+ const provider = providerName;
59
+ return CDN_CAPABILITIES[provider];
60
+ };
61
+ exports.resolveCdnCapability = resolveCdnCapability;
62
+ /**
63
+ * Maps si's neutral `scope` value (defaulting to `global`) onto the provider's
64
+ * API value. Executors call this instead of hardcoding provider vocabulary.
65
+ */
66
+ const mapCdnScope = (provider, scope) => {
67
+ const capability = CDN_CAPABILITIES[provider];
68
+ return capability.scopeMap[(scope ?? 'global')] ?? 'global';
69
+ };
70
+ exports.mapCdnScope = mapCdnScope;
71
+ /**
72
+ * Maps si's `origin_protocol` onto the provider's API value; undefined passes
73
+ * through so executors can keep their "not set → no call" semantics.
74
+ */
75
+ const mapOriginProtocol = (provider, originProtocol) => {
76
+ if (originProtocol == null)
77
+ return undefined;
78
+ return CDN_CAPABILITIES[provider].originProtocolMap[originProtocol];
79
+ };
80
+ exports.mapOriginProtocol = mapOriginProtocol;
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.warnInlinePem = exports.readPemContent = exports.isFilePath = void 0;
6
+ exports.warnInlinePem = exports.readPemContent = exports.resolveBindingCertificateHash = exports.hashResolvedCertificate = exports.isFilePath = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_crypto_1 = require("node:crypto");
9
10
  const logger_1 = require("./logger");
10
11
  const lang_1 = require("../lang");
11
12
  const isFilePath = (value) => {
@@ -14,16 +15,54 @@ const isFilePath = (value) => {
14
15
  return /\.(pem|crt|key)$/.test(value);
15
16
  };
16
17
  exports.isFilePath = isFilePath;
17
- const readPemContent = (value) => {
18
+ /**
19
+ * Stable hash over resolved certificate contents. Recorded in state so
20
+ * executors redeploy a certificate only when it actually changed (issue #283).
21
+ * A `certificate_id` reference hashes the reference itself — the id is the
22
+ * identity of the referenced certificate.
23
+ */
24
+ const hashResolvedCertificate = (certificateBody, certificatePrivateKey) => {
25
+ if (!certificateBody || !certificatePrivateKey)
26
+ return undefined;
27
+ return (0, node_crypto_1.createHash)('sha256').update(`${certificateBody}\n${certificatePrivateKey}`).digest('hex');
28
+ };
29
+ exports.hashResolvedCertificate = hashResolvedCertificate;
30
+ /**
31
+ * Content hash for a binding's certificate without any cloud access: inline
32
+ * PEM resolves through tryReadPemContent (local file or literal), a
33
+ * `certificate_id` reference hashes the reference string. A missing PEM file
34
+ * yields no hash instead of throwing — this runs during plan-time definition
35
+ * extraction (`si diff`), which must not depend on certificate files being
36
+ * present; the executor's `resolveBindingCertificate` keeps the fail-loud
37
+ * read for deploy.
38
+ */
39
+ const resolveBindingCertificateHash = (binding) => {
40
+ if (binding.certificate_id) {
41
+ return (0, node_crypto_1.createHash)('sha256').update(`ref:${binding.certificate_id}`).digest('hex');
42
+ }
43
+ if (binding.certificate_body && binding.certificate_private_key) {
44
+ const body = tryReadPemContent(binding.certificate_body);
45
+ const key = tryReadPemContent(binding.certificate_private_key);
46
+ return (0, exports.hashResolvedCertificate)(body, key);
47
+ }
48
+ return undefined;
49
+ };
50
+ exports.resolveBindingCertificateHash = resolveBindingCertificateHash;
51
+ const tryReadPemContent = (value) => {
18
52
  if (!(0, exports.isFilePath)(value))
19
53
  return value;
20
54
  const filePath = node_path_1.default.resolve(process.cwd(), value);
21
- if (!node_fs_1.default.existsSync(filePath)) {
22
- throw new Error(lang_1.lang.__('CERT_FILE_NOT_FOUND', { filePath }));
23
- }
55
+ if (!node_fs_1.default.existsSync(filePath))
56
+ return undefined;
24
57
  logger_1.logger.info(lang_1.lang.__('CERT_READING_FILE', { filePath }));
25
58
  return node_fs_1.default.readFileSync(filePath, 'utf-8');
26
59
  };
60
+ const readPemContent = (value) => {
61
+ const content = tryReadPemContent(value);
62
+ if (content != null)
63
+ return content;
64
+ throw new Error(lang_1.lang.__('CERT_FILE_NOT_FOUND', { filePath: node_path_1.default.resolve(process.cwd(), value) }));
65
+ };
27
66
  exports.readPemContent = readPemContent;
28
67
  const warnInlinePem = (value) => {
29
68
  if (typeof value === 'string' && (value.includes('BEGIN') || value.includes('PRIVATE KEY'))) {
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidatedOrg = exports.assertOrgMatches = exports.assertValidatedRegion = exports.assertLineFlag = exports.splitProfileKey = exports.toProfileKey = exports.resolveLineFromOrigin = exports.consoleUiOriginFor = exports.consoleOriginFor = exports.normalizeLineName = exports.validateApiKeyFormat = exports.parseApiKeyLine = exports.LINE_NAMES = exports.CONSOLE_LINES = void 0;
4
+ /**
5
+ * ADR-008: built-in registry of console lines. Users pick a line BY NAME
6
+ * (login picker / --line); the console origin is always derived from this
7
+ * table and is never typed, configured or stored by the user.
8
+ */
9
+ const lang_1 = require("../lang");
10
+ exports.CONSOLE_LINES = {
11
+ international: { origin: 'https://console.serverlessinsight.com', keySegment: 'com' },
12
+ china: { origin: 'https://console.serverlessinsight.cn', keySegment: 'cn' },
13
+ };
14
+ exports.LINE_NAMES = Object.keys(exports.CONSOLE_LINES);
15
+ const LINE_BY_SEGMENT = {
16
+ com: 'international',
17
+ cn: 'china',
18
+ };
19
+ /** New-format keys carry the issuing line: `si_<com|cn>_<12>_<32>`. */
20
+ const parseApiKeyLine = (key) => {
21
+ const match = /^si_(com|cn)_[A-Za-z0-9_-]{12}_[A-Za-z0-9_-]{32}$/.exec(key);
22
+ if (!match)
23
+ return null;
24
+ return LINE_BY_SEGMENT[match[1]];
25
+ };
26
+ exports.parseApiKeyLine = parseApiKeyLine;
27
+ /** Both formats are valid: legacy `si_<12>_<32>` and line-stamped `si_<com|cn>_<12>_<32>`. */
28
+ const validateApiKeyFormat = (key) => {
29
+ if ((0, exports.parseApiKeyLine)(key))
30
+ return true;
31
+ return /^si_[A-Za-z0-9_-]{12}_[A-Za-z0-9_-]{32}$/.test(key);
32
+ };
33
+ exports.validateApiKeyFormat = validateApiKeyFormat;
34
+ /** Accepts the registry names and, leniently, the key segments as aliases. */
35
+ const normalizeLineName = (input) => {
36
+ if (!input)
37
+ return null;
38
+ const lower = input.trim().toLowerCase();
39
+ if (exports.LINE_NAMES.includes(lower))
40
+ return lower;
41
+ return lower === 'com' || lower === 'cn' ? LINE_BY_SEGMENT[lower] : null;
42
+ };
43
+ exports.normalizeLineName = normalizeLineName;
44
+ /**
45
+ * Undocumented internal hook: SI_CONSOLE_URL overrides the derived origin so
46
+ * the CLI's own tests and local console development can target localhost.
47
+ * It is not part of the product surface (ADR-008).
48
+ */
49
+ const consoleOriginFor = (line) => {
50
+ return process.env.SI_CONSOLE_URL || exports.CONSOLE_LINES[line].origin;
51
+ };
52
+ exports.consoleOriginFor = consoleOriginFor;
53
+ /** UI origin for browser flows; the local dev API (:3000) maps to the Vite server (:5173). */
54
+ const consoleUiOriginFor = (line) => {
55
+ if (process.env.SI_CONSOLE_UI_URL) {
56
+ return process.env.SI_CONSOLE_UI_URL;
57
+ }
58
+ const origin = (0, exports.consoleOriginFor)(line);
59
+ if (origin.includes('localhost:3000')) {
60
+ return origin.replace('localhost:3000', 'localhost:5173');
61
+ }
62
+ return origin;
63
+ };
64
+ exports.consoleUiOriginFor = consoleUiOriginFor;
65
+ /** Reverse mapping used when healing legacy credentials that still store a consoleUrl. */
66
+ const resolveLineFromOrigin = (origin) => {
67
+ if (!origin)
68
+ return null;
69
+ const normalized = origin.replace(/\/+$/, '');
70
+ const entry = Object.entries(exports.CONSOLE_LINES).find(([, line]) => line.origin === normalized);
71
+ if (entry)
72
+ return entry[0];
73
+ if (normalized.includes('console.serverlessinsight.com'))
74
+ return 'international';
75
+ if (normalized.includes('console.serverlessinsight.cn'))
76
+ return 'china';
77
+ return null;
78
+ };
79
+ exports.resolveLineFromOrigin = resolveLineFromOrigin;
80
+ /** Composite credential-store key: `line/orgSlug`. Slugs are `[a-z0-9-]`, so `/` is unambiguous. */
81
+ const toProfileKey = (line, orgSlug) => `${line}/${orgSlug}`;
82
+ exports.toProfileKey = toProfileKey;
83
+ const splitProfileKey = (key) => {
84
+ const separator = key.indexOf('/');
85
+ if (separator <= 0 || separator === key.length - 1)
86
+ return null;
87
+ const line = (0, exports.normalizeLineName)(key.slice(0, separator));
88
+ if (!line)
89
+ return null;
90
+ return { line, orgSlug: key.slice(separator + 1) };
91
+ };
92
+ exports.splitProfileKey = splitProfileKey;
93
+ const assertLineFlag = (input) => {
94
+ if (input === undefined)
95
+ return undefined;
96
+ const line = (0, exports.normalizeLineName)(input);
97
+ if (!line) {
98
+ throw new Error(lang_1.lang.__('SAAS_LINE_INVALID', { value: input, lines: exports.LINE_NAMES.join(', ') }));
99
+ }
100
+ return line;
101
+ };
102
+ exports.assertLineFlag = assertLineFlag;
103
+ const assertValidatedRegion = (line, region) => {
104
+ const segment = exports.CONSOLE_LINES[line].keySegment;
105
+ if (region && region !== segment) {
106
+ throw new Error(lang_1.lang.__('SAAS_LINE_CONFLICT', {
107
+ source: 'the console validate response',
108
+ line: region,
109
+ resolvedLine: segment,
110
+ }));
111
+ }
112
+ };
113
+ exports.assertValidatedRegion = assertValidatedRegion;
114
+ const assertOrgMatches = (expected, actual) => {
115
+ if (expected && actual && expected !== actual) {
116
+ throw new Error(lang_1.lang.__('SAAS_ORG_MISMATCH', { declared: expected, actual }));
117
+ }
118
+ };
119
+ exports.assertOrgMatches = assertOrgMatches;
120
+ const assertValidatedOrg = (expected, actual) => {
121
+ if (expected && !actual) {
122
+ throw new Error(lang_1.lang.__('SAAS_ORG_UNVERIFIED', { org: expected }));
123
+ }
124
+ (0, exports.assertOrgMatches)(expected, actual);
125
+ };
126
+ exports.assertValidatedOrg = assertValidatedOrg;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REGIONAL_MIGRATION_SUFFIX = exports.CLS_TOPIC_POLL_MAX_ATTEMPTS = exports.CLS_TOPIC_POLL_INTERVAL_MS = exports.SCF_STATUS_POLL_MAX_ATTEMPTS = exports.SCF_STATUS_POLL_INTERVAL_MS = exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DNS_PROPAGATION_DELAY_MS = exports.DNS_PROPAGATION_MAX_ATTEMPTS = exports.DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_QUERY_READ_TIMEOUT_MS = exports.ALIYUN_QUERY_CONNECT_TIMEOUT_MS = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
3
+ exports.REGIONAL_MIGRATION_SUFFIX = exports.CLS_TOPIC_POLL_MAX_ATTEMPTS = exports.CLS_TOPIC_POLL_INTERVAL_MS = exports.SCF_STATUS_POLL_MAX_ATTEMPTS = exports.SCF_STATUS_POLL_INTERVAL_MS = exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DNS_PROPAGATION_DELAY_MS = exports.DNS_PROPAGATION_MAX_ATTEMPTS = exports.DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.TOS_STATE_REQUEST_TIMEOUT_MS = exports.TOS_STATE_CONNECT_TIMEOUT_MS = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_QUERY_READ_TIMEOUT_MS = exports.ALIYUN_QUERY_CONNECT_TIMEOUT_MS = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
4
4
  exports.CODE_ZIP_SIZE_LIMIT = 300 * 1000; // 300 KB - code package size limit for inline deployment
5
5
  exports.OSS_DEPLOYMENT_TIMEOUT = 3000; // in seconds
6
6
  exports.SI_BOOTSTRAP_FC_PREFIX = 'si-bootstrap-api';
@@ -19,9 +19,11 @@ exports.ALIYUN_FC3_READ_TIMEOUT_MS = 600000;
19
19
  exports.ALIYUN_QUERY_CONNECT_TIMEOUT_MS = 10000; // 10 seconds
20
20
  exports.ALIYUN_QUERY_READ_TIMEOUT_MS = 30000; // 30 seconds
21
21
  exports.FC3_CODE_INLINE_SIZE_LIMIT = 70 * 1024 * 1024; // 70MB threshold for OSS upload
22
- // OSS state backend timeouts
22
+ // Bucket Store state backend timeouts (shared by OSS, COS and TOS adapters)
23
23
  exports.OSS_STATE_CONNECT_TIMEOUT_MS = 10000; // 10 seconds
24
24
  exports.OSS_STATE_REQUEST_TIMEOUT_MS = 30000; // 30 seconds
25
+ exports.TOS_STATE_CONNECT_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS;
26
+ exports.TOS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_REQUEST_TIMEOUT_MS;
25
27
  // Lock manager constants
26
28
  exports.LOCK_FILE_SUFFIX = '.si-lock';
27
29
  exports.DEFAULT_LOCK_TIMEOUT = 10 * 60 * 1000; // 10 minutes