@xfe-repo/mini-app 2.0.0-beta.1 → 2.0.0-beta.3

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/config.js CHANGED
@@ -1,323 +1,194 @@
1
1
  "use strict";
2
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
- try {
4
- var info = gen[key](arg);
5
- var value = info.value;
6
- } catch (error) {
7
- reject(error);
8
- return;
9
- }
10
- if (info.done) {
11
- resolve(value);
12
- } else {
13
- Promise.resolve(value).then(_next, _throw);
14
- }
15
- }
16
- function _async_to_generator(fn) {
17
- return function() {
18
- var self = this, args = arguments;
19
- return new Promise(function(resolve, reject) {
20
- var gen = fn.apply(self, args);
21
- function _next(value) {
22
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
- }
24
- function _throw(err) {
25
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
- }
27
- _next(undefined);
28
- });
29
- };
30
- }
31
- function _type_of(obj) {
32
- "@swc/helpers - typeof";
33
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
34
- }
35
- function _ts_generator(thisArg, body) {
36
- var f, y, t, _ = {
37
- label: 0,
38
- sent: function() {
39
- if (t[0] & 1) throw t[1];
40
- return t[1];
41
- },
42
- trys: [],
43
- ops: []
44
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
45
- return d(g, "next", {
46
- value: verb(0)
47
- }), d(g, "throw", {
48
- value: verb(1)
49
- }), d(g, "return", {
50
- value: verb(2)
51
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
52
- value: function() {
53
- return this;
54
- }
55
- }), g;
56
- function verb(n) {
57
- return function(v) {
58
- return step([
59
- n,
60
- v
61
- ]);
62
- };
63
- }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [
69
- op[0] & 2,
70
- t.value
71
- ];
72
- switch(op[0]){
73
- case 0:
74
- case 1:
75
- t = op;
76
- break;
77
- case 4:
78
- _.label++;
79
- return {
80
- value: op[1],
81
- done: false
82
- };
83
- case 5:
84
- _.label++;
85
- y = op[1];
86
- op = [
87
- 0
88
- ];
89
- continue;
90
- case 7:
91
- op = _.ops.pop();
92
- _.trys.pop();
93
- continue;
94
- default:
95
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
96
- _ = 0;
97
- continue;
98
- }
99
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
100
- _.label = op[1];
101
- break;
102
- }
103
- if (op[0] === 6 && _.label < t[1]) {
104
- _.label = t[1];
105
- t = op;
106
- break;
107
- }
108
- if (t && _.label < t[2]) {
109
- _.label = t[2];
110
- _.ops.push(op);
111
- break;
112
- }
113
- if (t[2]) _.ops.pop();
114
- _.trys.pop();
115
- continue;
116
- }
117
- op = body.call(thisArg, _);
118
- } catch (e) {
119
- op = [
120
- 6,
121
- e
122
- ];
123
- y = 0;
124
- } finally{
125
- f = t = 0;
126
- }
127
- if (op[0] & 5) throw op[1];
128
- return {
129
- value: op[0] ? op[1] : void 0,
130
- done: true
131
- };
132
- }
133
- }
134
2
  var __create = Object.create;
135
3
  var __defProp = Object.defineProperty;
136
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
137
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
138
6
  var __getProtoOf = Object.getPrototypeOf;
139
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
140
- var __export = function __export(target, all) {
141
- for(var name in all)__defProp(target, name, {
142
- get: all[name],
143
- enumerable: true
144
- });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
145
11
  };
146
- var __copyProps = function __copyProps(to, from, except, desc) {
147
- if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
148
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
149
- try {
150
- var _loop = function() {
151
- var key = _step.value;
152
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
153
- get: function get() {
154
- return from[key];
155
- },
156
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
157
- });
158
- };
159
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
160
- } catch (err) {
161
- _didIteratorError = true;
162
- _iteratorError = err;
163
- } finally{
164
- try {
165
- if (!_iteratorNormalCompletion && _iterator.return != null) {
166
- _iterator.return();
167
- }
168
- } finally{
169
- if (_didIteratorError) {
170
- throw _iteratorError;
171
- }
172
- }
173
- }
174
- }
175
- return to;
176
- };
177
- var __toESM = function __toESM(mod, isNodeMode, target) {
178
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
179
- // file that has been converted to a CommonJS file using a Babel-
180
- // compatible transform (i.e. "__esModule" has not been set), then set
181
- // "default" to the CommonJS "module.exports" for node compatibility.
182
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
183
- value: mod,
184
- enumerable: true
185
- }) : target, mod);
186
- };
187
- var __toCommonJS = function __toCommonJS(mod) {
188
- return __copyProps(__defProp({}, "__esModule", {
189
- value: true
190
- }), mod);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
191
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
192
30
  // src/config.ts
193
31
  var config_exports = {};
194
32
  __export(config_exports, {
195
- configDeploy: function configDeploy1() {
196
- return configDeploy;
197
- },
198
- getJwtEnv: function getJwtEnv1() {
199
- return getJwtEnv;
200
- },
201
- loadXfeConfig: function loadXfeConfig1() {
202
- return loadXfeConfig;
203
- }
33
+ configDeploy: () => configDeploy,
34
+ getJwtEnv: () => getJwtEnv,
35
+ loadXfeConfig: () => loadXfeConfig
204
36
  });
205
37
  module.exports = __toCommonJS(config_exports);
206
- var import_path = __toESM(require("path"));
207
38
  var import_fs = __toESM(require("fs"));
208
- var import_yaml = __toESM(require("yaml"));
209
- var loadXfeConfig = function loadXfeConfig() {
210
- var xfeConfigPath = "./xfe.json";
211
- if (!import_fs.default.existsSync(xfeConfigPath)) {
212
- throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
39
+
40
+ // src/config/deploy.ts
41
+ var import_node_path2 = __toESM(require("path"));
42
+ var import_node_url = require("url");
43
+
44
+ // ../../shared/deploy/config.ts
45
+ var import_node_fs = __toESM(require("fs"));
46
+ var import_node_path = __toESM(require("path"));
47
+ var import_node_module = require("module");
48
+ var DeployEnvironment = /* @__PURE__ */ ((DeployEnvironment2) => {
49
+ DeployEnvironment2["Test"] = "test";
50
+ DeployEnvironment2["Stage"] = "stage";
51
+ DeployEnvironment2["Prod"] = "prod";
52
+ DeployEnvironment2["Stable"] = "stable";
53
+ return DeployEnvironment2;
54
+ })(DeployEnvironment || {});
55
+ var generateDeploy = ({
56
+ deploy,
57
+ frameworkRoot,
58
+ isMini = false
59
+ }) => {
60
+ const yaml = (0, import_node_module.createRequire)(import_node_path.default.join(frameworkRoot, "package.json"))("yaml");
61
+ const supportedFields = ["values", "environments", "pushHelmChart", ...isMini ? ["platforms"] : []];
62
+ if (deploy === void 0) return;
63
+ if (!deploy || typeof deploy !== "object" || Array.isArray(deploy) || Object.keys(deploy).some(
64
+ /** 运行参数只能来自 values,流水线开关保留独立入口。 */
65
+ (key) => !supportedFields.includes(key)
66
+ )) {
67
+ throw new Error(`xfe.json.deploy \u4EC5\u652F\u6301 ${supportedFields.join("\u3001")}\uFF1B\u8FD0\u884C\u53C2\u6570\u8BF7\u653E\u5165 values`);
68
+ }
69
+ const environments = deploy.environments === void 0 ? Object.values(DeployEnvironment) : deploy.environments;
70
+ if (!Array.isArray(environments) || environments.some(
71
+ /** 只接受已知的环境名称,非法值不能误开启发布。 */
72
+ (environment) => !Object.values(DeployEnvironment).includes(environment)
73
+ ))
74
+ throw new Error("deploy.environments \u5FC5\u987B\u662F test\u3001stage\u3001prod\u3001stable \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u90E8\u7F72");
75
+ if (deploy.pushHelmChart !== void 0 && typeof deploy.pushHelmChart !== "boolean") throw new Error("deploy.pushHelmChart \u5FC5\u987B\u662F\u5E03\u5C14\u503C");
76
+ const platforms = deploy.platforms === void 0 ? ["weapp", "h5"] : deploy.platforms;
77
+ if (!Array.isArray(platforms) || platforms.some((platform) => !["weapp", "h5"].includes(platform))) {
78
+ throw new Error("deploy.platforms \u5FC5\u987B\u662F weapp\u3001h5 \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u53D1\u5E03");
79
+ }
80
+ const h5Environments = platforms.includes("h5") ? environments : [];
81
+ const miniEnvironments = platforms.includes("weapp") ? environments : [];
82
+ const pushHelmChart = deploy.pushHelmChart !== false && h5Environments.includes("prod" /* Prod */);
83
+ const source = import_node_path.default.join(frameworkRoot, "deploy");
84
+ const target = import_node_path.default.join(process.cwd(), "deploy");
85
+ let overrides = deploy.values === void 0 ? {} : deploy.values;
86
+ if (typeof overrides === "string") {
87
+ const valuesPath = import_node_fs.default.realpathSync(import_node_path.default.resolve(overrides));
88
+ if (valuesPath.startsWith(target + import_node_path.default.sep) && valuesPath !== import_node_path.default.join(target, "values.yaml")) {
89
+ throw new Error("\u9879\u76EE values \u6587\u4EF6\u4E0D\u80FD\u653E\u5728\u751F\u6210\u5B50\u76EE\u5F55\u4E2D\uFF0C\u8BF7\u4F7F\u7528 deploy/values.yaml \u6216\u9879\u76EE\u6839\u76EE\u5F55\u7684 values.yaml");
213
90
  }
214
- var xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
215
- return JSON.parse(xfeConfigContent);
91
+ overrides = yaml.parse(import_node_fs.default.readFileSync(valuesPath, "utf8"));
92
+ }
93
+ if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) {
94
+ throw new Error("deploy.values \u5FC5\u987B\u662F\u5BF9\u8C61\u6216\u6307\u5411 YAML \u5BF9\u8C61\u6587\u4EF6\u7684\u8DEF\u5F84");
95
+ }
96
+ if (Object.hasOwn(overrides, "environments") || Object.hasOwn(overrides, "pushHelmChart"))
97
+ throw new Error("values \u4E0D\u518D\u652F\u6301 environments \u6216 pushHelmChart\uFF1B\u8BF7\u8FC1\u5165 xfe.json.deploy\uFF0C\u73AF\u5883\u5F00\u5173\u4F7F\u7528\u6570\u7EC4");
98
+ const defaults = yaml.parse(import_node_fs.default.readFileSync(import_node_path.default.join(source, "helm/values.yaml"), "utf8"));
99
+ const values = mergeDeployValues(defaults, overrides);
100
+ if (typeof values.host !== "string" || /[\\/?#@:\s]/.test(values.host)) {
101
+ throw new Error("values.host \u5FC5\u987B\u662F\u4E0D\u542B\u534F\u8BAE\u3001\u7AEF\u53E3\u548C\u8DEF\u5F84\u7684\u4E3B\u673A\u540D\uFF0C\u4F8B\u5982 specdoc.example.com");
102
+ }
103
+ if (!["saas", "infra"].includes(values.targetK8s)) throw new Error("deploy.values.targetK8s \u53EA\u80FD\u4E3A saas \u6216 infra");
104
+ if (target === source) throw new Error("\u90E8\u7F72\u8F93\u51FA\u4E0D\u80FD\u8986\u76D6\u6846\u67B6\u6A21\u677F\u76EE\u5F55");
105
+ if (import_node_fs.default.lstatSync(target, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("deploy \u4E0D\u80FD\u4E3A\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u8986\u76D6\u5916\u90E8\u76EE\u5F55");
106
+ const disabledEvents = "[custom, tag]";
107
+ const drone = import_node_fs.default.readFileSync(import_node_path.default.join(source, ".drone.yml"), "utf8").replaceAll("<<TARGET_K8S>>", values.targetK8s).replaceAll("<<EXCLUDE_EVENTS_deploy>>", h5Environments.length ? "[]" : disabledEvents).replaceAll("<<EXCLUDE_EVENTS_h5>>", h5Environments.length ? "[]" : disabledEvents).replaceAll(
108
+ "<<EXCLUDE_EVENTS_weapp>>",
109
+ miniEnvironments.some((environment) => environment !== "stable" /* Stable */) ? "[]" : disabledEvents
110
+ ).replace(
111
+ /<<EXCLUDE_EVENTS_weapp_(test|stage|prod)>>/g,
112
+ (_placeholder, environment) => miniEnvironments.includes(environment) ? "[]" : disabledEvents
113
+ ).replaceAll("<<EXCLUDE_EVENTS_push_helm_chart>>", pushHelmChart ? "[]" : disabledEvents).replace(
114
+ /<<EXCLUDE_EVENTS_(test|stage|prod|stable)>>/g,
115
+ /** 开启时不排除事件,关闭时由 Drone 原生 when 跳过该步骤。 */
116
+ (_placeholder, environment) => h5Environments.includes(environment) ? "[]" : disabledEvents
117
+ );
118
+ import_node_fs.default.cpSync(source, target, { recursive: true });
119
+ import_node_fs.default.writeFileSync(
120
+ import_node_path.default.join(target, "helm/values.yaml"),
121
+ yaml.stringify(values, {
122
+ defaultStringType: "QUOTE_SINGLE",
123
+ defaultKeyType: "PLAIN"
124
+ })
125
+ );
126
+ import_node_fs.default.writeFileSync(import_node_path.default.join(target, ".drone.yml"), drone);
216
127
  };
217
- var configDeploy = function configDeploy() {
218
- var xfeConfig = loadXfeConfig();
219
- if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
220
- var droneConfigFilePath = import_path.default.resolve(__dirname, "../deploy/.drone.yml");
221
- import_fs.default.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
222
- var valuesYamlFilePath = import_path.default.resolve(__dirname, "../deploy/helm/values.yaml");
223
- var valuesYamlFile = import_fs.default.readFileSync(valuesYamlFilePath, "utf8");
224
- var valuesYaml = import_yaml.default.parse(valuesYamlFile);
225
- if (!valuesYaml.virtualService) valuesYaml.virtualService = {};
226
- if (!valuesYaml.virtualService.hosts) valuesYaml.virtualService.hosts = {
227
- test: [],
228
- stage: [],
229
- prod: []
230
- };
231
- var _xfeConfig_deploy = xfeConfig.deploy, _xfeConfig_deploy_virtualServiceEnabled = _xfeConfig_deploy.virtualServiceEnabled, virtualServiceEnabled = _xfeConfig_deploy_virtualServiceEnabled === void 0 ? true : _xfeConfig_deploy_virtualServiceEnabled, _xfeConfig_deploy_hostsProd = _xfeConfig_deploy.hostsProd, hostsProd = _xfeConfig_deploy_hostsProd === void 0 ? [] : _xfeConfig_deploy_hostsProd, _xfeConfig_deploy_hostsStage = _xfeConfig_deploy.hostsStage, hostsStage = _xfeConfig_deploy_hostsStage === void 0 ? [] : _xfeConfig_deploy_hostsStage, _xfeConfig_deploy_hostsTest = _xfeConfig_deploy.hostsTest, hostsTest = _xfeConfig_deploy_hostsTest === void 0 ? [] : _xfeConfig_deploy_hostsTest, _xfeConfig_deploy_gateways = _xfeConfig_deploy.gateways, gateways = _xfeConfig_deploy_gateways === void 0 ? [
232
- "common-gateway-eshetang"
233
- ] : _xfeConfig_deploy_gateways;
234
- var _xfeConfig_deploy1 = xfeConfig.deploy, _xfeConfig_deploy_targetK8s = _xfeConfig_deploy1.targetK8s, targetK8s = _xfeConfig_deploy_targetK8s === void 0 ? "saas" : _xfeConfig_deploy_targetK8s, _xfeConfig_deploy_targetNamespace = _xfeConfig_deploy1.targetNamespace, targetNamespace = _xfeConfig_deploy_targetNamespace === void 0 ? "" : _xfeConfig_deploy_targetNamespace;
235
- valuesYaml.virtualService.enabled = virtualServiceEnabled;
236
- valuesYaml.virtualService.gateways = gateways;
237
- valuesYaml.virtualService.hosts.prod = hostsProd;
238
- valuesYaml.virtualService.hosts.stage = hostsStage;
239
- valuesYaml.virtualService.hosts.test = hostsTest;
240
- valuesYaml.targetK8s = targetK8s;
241
- valuesYaml.namespace = targetNamespace;
242
- var valuesYamlStr = import_yaml.default.stringify(valuesYaml, {
243
- defaultStringType: "QUOTE_SINGLE",
244
- defaultKeyType: "PLAIN"
245
- });
246
- import_fs.default.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
128
+ function mergeDeployValues(base, overrides) {
129
+ return Object.fromEntries(
130
+ Object.entries({ ...base, ...overrides }).map(
131
+ /** 仅合并普通对象,列表保持声明的顺序。 */
132
+ ([key, value]) => {
133
+ const previous = base[key];
134
+ const previousObject = previous && typeof previous === "object" && !Array.isArray(previous);
135
+ if (value === true && previousObject) {
136
+ return [key, Object.hasOwn(previous, "enabled") ? { ...previous, enabled: true } : previous];
137
+ }
138
+ const mergeable = value && previousObject && typeof value === "object" && !Array.isArray(value);
139
+ if (key === "corsPolicy" && mergeable && Object.hasOwn(value, "allowOrigins") && !Object.hasOwn(value, "allowOrigin")) {
140
+ const { allowOrigin: _legacyAllowOrigin, ...rest } = previous;
141
+ return [key, mergeDeployValues(rest, value)];
142
+ }
143
+ return [key, mergeable ? mergeDeployValues(previous, value) : value];
144
+ }
145
+ )
146
+ );
147
+ }
148
+
149
+ // src/config/deploy.ts
150
+ var import_meta = {};
151
+ var generateDeploy2 = (deploy) => {
152
+ const directory = typeof __dirname === "string" ? __dirname : import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
153
+ generateDeploy({ deploy, frameworkRoot: import_node_path2.default.resolve(directory, ".."), isMini: true });
154
+ };
155
+
156
+ // src/config.ts
157
+ var loadXfeConfig = () => {
158
+ const xfeConfigPath = "./xfe.json";
159
+ if (!import_fs.default.existsSync(xfeConfigPath)) {
160
+ throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
161
+ }
162
+ const xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
163
+ return JSON.parse(xfeConfigContent);
247
164
  };
248
- var getJwtEnv = function getJwtEnv() {
249
- return _async_to_generator(function() {
250
- var xfeConfig, _xfeConfig_jwt, _xfeConfig_jwt_aud, aud, jwkRes, JwkResponseJson, err, _, _1, _2, _ref, keyId, privateKeyPkcs8;
251
- return _ts_generator(this, function(_state) {
252
- switch(_state.label){
253
- case 0:
254
- xfeConfig = loadXfeConfig();
255
- if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.jwt)) return [
256
- 2,
257
- {}
258
- ];
259
- _xfeConfig_jwt = xfeConfig.jwt, _xfeConfig_jwt_aud = _xfeConfig_jwt.aud, aud = _xfeConfig_jwt_aud === void 0 ? "" : _xfeConfig_jwt_aud;
260
- if (!aud) throw new Error("xfe.json \u4E2D\u7684 jwt \u914D\u7F6E\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u786E\u4FDD\u5305\u542B aud \u5B57\u6BB5\u3002");
261
- return [
262
- 4,
263
- fetch("https://app.eshetang.com/jwk?appId=".concat(aud))
264
- ];
265
- case 1:
266
- jwkRes = _state.sent();
267
- if (!jwkRes.ok) {
268
- throw new Error("远程获取密钥失败: ".concat(jwkRes.status, " ").concat(jwkRes.statusText));
269
- }
270
- _state.label = 2;
271
- case 2:
272
- _state.trys.push([
273
- 2,
274
- 4,
275
- ,
276
- 6
277
- ]);
278
- return [
279
- 4,
280
- jwkRes.json()
281
- ];
282
- case 3:
283
- JwkResponseJson = _state.sent();
284
- return [
285
- 3,
286
- 6
287
- ];
288
- case 4:
289
- err = _state.sent();
290
- _ = Error.bind;
291
- _2 = (_1 = "远程获取密钥失败,响应解析错误: ".concat(err.message, ", response text: ")).concat;
292
- return [
293
- 4,
294
- jwkRes.text()
295
- ];
296
- case 5:
297
- throw new (_.apply(Error, [
298
- void 0,
299
- _2.apply(_1, [
300
- _state.sent()
301
- ])
302
- ]));
303
- case 6:
304
- _ref = (JwkResponseJson === null || JwkResponseJson === void 0 ? void 0 : JwkResponseJson.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
305
- if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
306
- return [
307
- 2,
308
- {
309
- XFE_JWT_AUD: aud,
310
- XFE_JWT_KEY_ID: keyId,
311
- XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
312
- }
313
- ];
314
- }
315
- });
316
- })();
165
+ var configDeploy = () => generateDeploy2(loadXfeConfig().deploy);
166
+ var getJwtEnv = async () => {
167
+ const xfeConfig = loadXfeConfig();
168
+ if (!xfeConfig?.jwt) return {};
169
+ const { aud = "" } = xfeConfig.jwt;
170
+ if (!aud) throw new Error("xfe.json \u4E2D\u7684 jwt \u914D\u7F6E\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u786E\u4FDD\u5305\u542B aud \u5B57\u6BB5\u3002");
171
+ const jwkRes = await fetch(`https://app.eshetang.com/jwk?appId=${aud}`);
172
+ if (!jwkRes.ok) {
173
+ throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25: ${jwkRes.status} ${jwkRes.statusText}`);
174
+ }
175
+ let JwkResponseJson;
176
+ try {
177
+ JwkResponseJson = await jwkRes.json();
178
+ } catch (err) {
179
+ throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25\uFF0C\u54CD\u5E94\u89E3\u6790\u9519\u8BEF: ${err.message}, response text: ${await jwkRes.text()}`);
180
+ }
181
+ const { keyId, privateKeyPkcs8 } = JwkResponseJson?.data || {};
182
+ if (!keyId || !privateKeyPkcs8) throw new Error(`\u672A\u83B7\u53D6\u5230\u9879\u76EE\u7B7E\u540D\u5BC6\u94A5, \u8BF7\u68C0\u67E5aud\u662F\u5426\u6B63\u786E: ${aud}`);
183
+ return {
184
+ XFE_JWT_AUD: aud,
185
+ XFE_JWT_KEY_ID: keyId,
186
+ XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
187
+ };
317
188
  };
318
189
  // Annotate the CommonJS export names for ESM import in node:
319
190
  0 && (module.exports = {
320
- configDeploy: configDeploy,
321
- getJwtEnv: getJwtEnv,
322
- loadXfeConfig: loadXfeConfig
191
+ configDeploy,
192
+ getJwtEnv,
193
+ loadXfeConfig
323
194
  });
package/dist/config.mjs CHANGED
@@ -1,3 +1,11 @@
1
- import { configDeploy, getJwtEnv, loadXfeConfig } from "./chunk-UC6ZB6VU.mjs";
1
+ import {
2
+ configDeploy,
3
+ getJwtEnv,
4
+ loadXfeConfig
5
+ } from "./chunk-2XEWB3XZ.mjs";
2
6
  import "./chunk-Y6FXYEAI.mjs";
3
- export { configDeploy, getJwtEnv, loadXfeConfig };
7
+ export {
8
+ configDeploy,
9
+ getJwtEnv,
10
+ loadXfeConfig
11
+ };