weaver-work-cli 0.1.29 → 0.1.32
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/chunks/archive-UMGX72K6.js +2537 -0
- package/dist/chunks/archive-oa-N2IYBLF3.js +1317 -0
- package/dist/chunks/asset-GLEGKFG5.js +2109 -0
- package/dist/chunks/attachment-content-AQNX5N3S.js +23 -0
- package/dist/chunks/blog-E44OTVDA.js +2157 -0
- package/dist/chunks/caizhilian-DQUFZXZL.js +10087 -0
- package/dist/chunks/calendar-JKPIRKFD.js +1195 -0
- package/dist/chunks/chunk-2GA5ZIQL.js +1615 -0
- package/dist/chunks/chunk-4YC43QQ4.js +403 -0
- package/dist/chunks/chunk-6EFWDL7Y.js +161 -0
- package/dist/chunks/chunk-6RKD4DRZ.js +5556 -0
- package/dist/chunks/chunk-AJ62BGAW.js +29 -0
- package/dist/chunks/chunk-BUSC6UAE.js +43 -0
- package/dist/chunks/chunk-C6R3B2ML.js +358 -0
- package/dist/chunks/chunk-CVZ2JOSW.js +62 -0
- package/dist/chunks/chunk-DW6AUUKS.js +508 -0
- package/dist/chunks/chunk-E4Z23GHM.js +6962 -0
- package/dist/chunks/chunk-EG6ZU444.js +654 -0
- package/dist/chunks/chunk-EZALDOQH.js +383 -0
- package/dist/chunks/chunk-FMPJJYYI.js +106 -0
- package/dist/chunks/chunk-G2JSIUWF.js +769 -0
- package/dist/chunks/chunk-G3QJULO2.js +387 -0
- package/dist/chunks/chunk-GCG2NMWR.js +703 -0
- package/dist/chunks/chunk-GPMFD4RD.js +75 -0
- package/dist/chunks/chunk-H6XSTSLM.js +2357 -0
- package/dist/chunks/chunk-H7J4DC5R.js +464 -0
- package/dist/chunks/chunk-IURUFGZK.js +477 -0
- package/dist/chunks/chunk-LUSPKZKY.js +53 -0
- package/dist/chunks/chunk-NIAJ5ZCG.js +73 -0
- package/dist/chunks/chunk-NOODWMCL.js +584 -0
- package/dist/chunks/chunk-OOUTBLZ4.js +51 -0
- package/dist/chunks/chunk-P26ZWSKU.js +73 -0
- package/dist/chunks/chunk-QWY6PGL6.js +3472 -0
- package/dist/chunks/chunk-WKI2FBIQ.js +15606 -0
- package/dist/chunks/chunk-WSKBSQ2U.js +231 -0
- package/dist/chunks/chunk-YLCYX7LE.js +371 -0
- package/dist/chunks/chunk-YRVDW4WN.js +205 -0
- package/dist/chunks/chunk-ZEDWSH32.js +68 -0
- package/dist/chunks/continuation-2CKSBLA6.js +11 -0
- package/dist/chunks/continuation-HZIZRZBX.js +13 -0
- package/dist/chunks/continuation-NLECEJPX.js +11 -0
- package/dist/chunks/ebuilder-form-V5FG2EHC.js +2276 -0
- package/dist/chunks/ehr-HMFY6VIL.js +5241 -0
- package/dist/chunks/employee-SAK2QYXX.js +11 -0
- package/dist/chunks/esb-ZYSVB7SG.js +141 -0
- package/dist/chunks/fna-B7RKPAZD.js +1444 -0
- package/dist/chunks/host-45WED2KK.js +21 -0
- package/dist/chunks/host-I4Z6BFYX.js +23 -0
- package/dist/chunks/host-KNZ52LJZ.js +17 -0
- package/dist/chunks/host-OCH2BCCV.js +19 -0
- package/dist/chunks/hrm-2KAZGUHI.js +244 -0
- package/dist/chunks/im-ACJJWH4U.js +252 -0
- package/dist/chunks/invoice-ZK3WCX2U.js +5179 -0
- package/dist/chunks/jiuchuanhui-5PQD3IL2.js +1940 -0
- package/dist/chunks/lazy-dispatch-JQXBW3GM.js +28 -0
- package/dist/chunks/mail-S2HDDXO2.js +2695 -0
- package/dist/chunks/meeting-QVN3I37L.js +504 -0
- package/dist/chunks/msg-parse-4GSQ2WTO.js +41 -0
- package/dist/chunks/okr-QNG4VC2Q.js +2482 -0
- package/dist/chunks/plan-A25EMW6U.js +2025 -0
- package/dist/chunks/project-G6XV66DZ.js +1361 -0
- package/dist/chunks/registry-2VLUAESA.js +14 -0
- package/dist/chunks/registry-7C5UMIPL.js +19 -0
- package/dist/chunks/registry-DC6KR3NH.js +18 -0
- package/dist/chunks/registry-NYPYMZXG.js +16 -0
- package/dist/chunks/registry-TI3CIUXF.js +19 -0
- package/dist/chunks/room-recommend-WRTHO6Y2.js +20 -0
- package/dist/chunks/schedule-KFIITGSK.js +24 -0
- package/dist/chunks/state-Y2XBP6YE.js +15 -0
- package/dist/chunks/workflow-DJ7SYWAF.js +245 -0
- package/dist/cmd/argv.js +45 -0
- package/dist/cmd/docs/index.js +3 -3
- package/dist/cmd/lazy-dispatch.js +20 -0
- package/dist/cmd/root.js +2 -4
- package/dist/cmd/setup/index.js +2 -2
- package/dist/cmd/skills/index.js +2 -2
- package/dist/core/package-paths.js +61 -0
- package/dist/index.js +163 -7
- package/dist/internal/e10/auth/xiaoe.js +3 -3
- package/dist/internal/e10/request-runtime.js +18 -62
- package/dist/internal/skills/detector.js +2 -2
- package/dist/shortcuts/contract/data/performance-catalog.js +1306 -0
- package/dist/shortcuts/contract/host.js +91 -35
- package/dist/shortcuts/contract/index.js +213 -0
- package/dist/shortcuts/contract/manifest.js +928 -0
- package/dist/shortcuts/contract/ooxml/docx.js +295 -0
- package/dist/shortcuts/contract/ooxml/xlsx.js +221 -0
- package/dist/shortcuts/contract/ooxml/zip.js +158 -0
- package/dist/shortcuts/contract/operations/assistant.js +1156 -0
- package/dist/shortcuts/contract/operations/clause-library.js +522 -0
- package/dist/shortcuts/contract/operations/compare.js +193 -0
- package/dist/shortcuts/contract/operations/credit-page.js +34 -0
- package/dist/shortcuts/contract/operations/flow.js +98 -0
- package/dist/shortcuts/contract/operations/page.js +66 -0
- package/dist/shortcuts/contract/operations/performance.js +733 -0
- package/dist/shortcuts/contract/operations/quote.js +557 -0
- package/dist/shortcuts/contract/operations/recommend.js +78 -0
- package/dist/shortcuts/contract/operations/registry.js +18 -0
- package/dist/shortcuts/contract/operations/review.js +83 -0
- package/dist/shortcuts/contract/operations/shared.js +37 -0
- package/dist/shortcuts/contract/operations/upload.js +108 -0
- package/dist/shortcuts/contract/operations/write.js +3 -2
- package/dist/shortcuts/index.js +140 -40
- package/dist/shortcuts/invoice/manifest.js +34 -11
- package/dist/shortcuts/invoice/operations/reim-auto.js +9 -0
- package/dist/shortcuts/invoice/operations/reim.js +81 -5
- package/dist/shortcuts/invoice/operations/shared.js +12 -5
- package/dist/shortcuts/meeting/host.js +45 -3
- package/dist/shortcuts/meeting/invitation/docx.js +442 -0
- package/dist/shortcuts/meeting/operations/attachment-content.js +418 -0
- package/dist/shortcuts/meeting/operations/attachment.js +442 -0
- package/dist/shortcuts/meeting/operations/eb/cache.js +57 -0
- package/dist/shortcuts/meeting/operations/eb/catalog.js +343 -28
- package/dist/shortcuts/meeting/operations/eb/conflict.js +372 -11
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +710 -0
- package/dist/shortcuts/meeting/operations/eb/decision.js +47 -1
- package/dist/shortcuts/meeting/operations/eb/factory.js +129 -11
- package/dist/shortcuts/meeting/operations/eb/index.js +122 -2
- package/dist/shortcuts/meeting/operations/eb/room-recommend.js +378 -0
- package/dist/shortcuts/meeting/operations/eb/room-summary.js +84 -0
- package/dist/shortcuts/meeting/operations/eb/schedule.js +450 -0
- package/dist/shortcuts/meeting/operations/from-group-chat.js +576 -0
- package/dist/shortcuts/meeting/operations/invitation.js +458 -0
- package/dist/shortcuts/meeting/operations/minute-content.js +266 -0
- package/dist/shortcuts/meeting/operations/pipeline.js +489 -0
- package/dist/shortcuts/meeting/operations/qrcode.js +131 -0
- package/dist/shortcuts/meeting/operations/receipts.js +1 -1
- package/dist/shortcuts/meeting/operations/registry.js +18 -0
- package/dist/shortcuts/meeting/operations/summary.js +276 -0
- package/dist/shortcuts/meeting/operations/task-notify.js +325 -0
- package/dist/shortcuts/meeting/operations.js +42 -1
- package/dist/shortcuts/meeting/qr/encoder.js +427 -0
- package/dist/shortcuts/meeting/qr/render.js +103 -0
- package/dist/shortcuts/workflow/operations/form.js +17 -5
- package/docs/contract.md +39 -4
- package/docs/invoice.md +5 -5
- package/package.json +3 -2
- package/scripts/bundle.mjs +63 -0
- package/skill-template/business-info.json +25 -4
- package/skill-template/domains/jinchengda.md +16 -3
- package/skill-template/domains/yepiaotong.md +1 -1
- package/skills/weaver-e10-jinchengda/SKILL.md +111 -31
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +7 -13
- package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +150 -0
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +87 -0
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +111 -0
- package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +0 -15
- package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +0 -13
- package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +50 -0
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +4 -2
- package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +74 -0
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +84 -0
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +29 -0
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +28 -0
- package/skills/weaver-e10-jinchengda/references/contract-request-status.md +2 -21
- package/skills/weaver-e10-jinchengda/references/contract-request-write.md +0 -24
- package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +0 -15
- package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +0 -17
- package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +70 -0
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +0 -15
- package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +0 -15
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +1168 -152
- package/skills/weaver-e10-meeting/SKILL.md +493 -17
- package/skills/weaver-e10-meeting/references/meeting-change.md +4 -4
- package/skills/weaver-e10-meeting/references/meeting-create.md +6 -6
- package/skills/weaver-e10-meeting/references/meeting-eb.md +503 -27
- package/skills/weaver-e10-meeting/references/meeting-invitation.md +113 -0
- package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +6 -6
- package/skills/weaver-e10-meeting/references/meeting-minute-file.md +425 -0
- package/skills/weaver-e10-meeting/references/meeting-queries.md +4 -4
- package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +15 -15
- package/skills/weaver-e10-meeting/references/meeting-verification.md +19 -11
- package/skills/weaver-e10-meeting.zip +0 -0
- package/skills/weaver-e10-yepiaotong/SKILL.md +9 -5
- package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +1 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +6 -5
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +14 -11
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +97 -56
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +84 -60
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +142 -105
- package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +53 -194
- package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +7 -7
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +164 -72
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +6 -0
- package/templates/meeting/invitation.docx +0 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { createRequire as __esbuildCreateRequire } from 'node:module';
|
|
2
|
+
const require = __esbuildCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
createE10RequestRuntime,
|
|
5
|
+
requireE10Session
|
|
6
|
+
} from "./chunk-DW6AUUKS.js";
|
|
7
|
+
import {
|
|
8
|
+
E10_REAUTH_GUIDANCE,
|
|
9
|
+
E10_SESSION_EXPIRED_MESSAGE,
|
|
10
|
+
getActiveProfile
|
|
11
|
+
} from "./chunk-2GA5ZIQL.js";
|
|
12
|
+
import {
|
|
13
|
+
CliError
|
|
14
|
+
} from "./chunk-LUSPKZKY.js";
|
|
15
|
+
|
|
16
|
+
// src/shortcuts/invoice/errors.ts
|
|
17
|
+
var InvoiceCliError = class extends CliError {
|
|
18
|
+
type;
|
|
19
|
+
subtype;
|
|
20
|
+
code;
|
|
21
|
+
retryable;
|
|
22
|
+
stage;
|
|
23
|
+
details;
|
|
24
|
+
partialData;
|
|
25
|
+
constructor(type, subtype, message, options = {}) {
|
|
26
|
+
super(message, options.exitCode ?? 5 /* InternalError */);
|
|
27
|
+
this.name = "InvoiceCliError";
|
|
28
|
+
this.type = type;
|
|
29
|
+
this.subtype = subtype;
|
|
30
|
+
this.code = options.code;
|
|
31
|
+
this.retryable = options.retryable ?? false;
|
|
32
|
+
this.stage = options.stage;
|
|
33
|
+
this.details = options.details;
|
|
34
|
+
this.partialData = options.partialData;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function invoiceValidationError(subtype, message, details) {
|
|
38
|
+
return new InvoiceCliError("validation", subtype, message, {
|
|
39
|
+
details,
|
|
40
|
+
exitCode: 2 /* UsageError */
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function invoiceAuthError(subtype, message, details) {
|
|
44
|
+
return new InvoiceCliError("authentication", subtype, message, {
|
|
45
|
+
details,
|
|
46
|
+
exitCode: 3 /* AuthError */
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function invoiceNetworkError(subtype, message, options = {}) {
|
|
50
|
+
return new InvoiceCliError("network", subtype, message, {
|
|
51
|
+
...options,
|
|
52
|
+
retryable: options.retryable ?? true,
|
|
53
|
+
exitCode: 4 /* NetworkError */
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function invoiceConfirmationError(action, details) {
|
|
57
|
+
return new InvoiceCliError("confirmation", "required", "\u8BE5\u64CD\u4F5C\u9700\u8981\u660E\u786E\u786E\u8BA4", {
|
|
58
|
+
details: { action, ...details },
|
|
59
|
+
exitCode: 10 /* ConfirmationRequired */
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function invoicePartialError(message, partialData, details) {
|
|
63
|
+
return new InvoiceCliError("partial", "write_uncertain", message, {
|
|
64
|
+
details,
|
|
65
|
+
partialData,
|
|
66
|
+
exitCode: 11 /* Partial */
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function isInvoiceNetworkError(error) {
|
|
70
|
+
return Boolean(
|
|
71
|
+
error && typeof error === "object" && "type" in error && error.type === "network"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/shortcuts/invoice/host.ts
|
|
76
|
+
import { createHash } from "node:crypto";
|
|
77
|
+
import { readFile } from "node:fs/promises";
|
|
78
|
+
var MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024;
|
|
79
|
+
var TOKEN_SERVICE = "cn.weaver.weaver-work-cli.invoice-token";
|
|
80
|
+
var INVOICE_SESSION_EXPIRED_CODE = "-2";
|
|
81
|
+
function assertPath(requestPath) {
|
|
82
|
+
if (typeof requestPath !== "string" || !requestPath.startsWith("/") || requestPath.startsWith("//")) {
|
|
83
|
+
throw invoiceValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u5FC5\u987B\u662F\u76F8\u5BF9\u7EDD\u5BF9\u8DEF\u5F84");
|
|
84
|
+
}
|
|
85
|
+
if (/^https?:/i.test(requestPath) || /[\r\n]/.test(requestPath) || requestPath.includes("/../")) {
|
|
86
|
+
throw invoiceValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u4E0D\u5141\u8BB8\u8DE8\u57DF\u6216\u8DEF\u5F84\u9003\u9038");
|
|
87
|
+
}
|
|
88
|
+
if (!requestPath.startsWith("/api/")) {
|
|
89
|
+
throw invoiceValidationError("path_not_allowed", "\u4E1A\u7968\u901A\u53EA\u80FD\u8C03\u7528 /api/ \u8DEF\u5F84");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function responseRoot(value) {
|
|
93
|
+
return value?.res_base || value?.data?.res_base || value;
|
|
94
|
+
}
|
|
95
|
+
function responseMessage(value) {
|
|
96
|
+
const root = responseRoot(value);
|
|
97
|
+
return typeof root?.message === "string" ? root.message : typeof root?.msg === "string" ? root.msg : "\u6CDB\u5FAE\u63A5\u53E3\u8FD4\u56DE\u4E1A\u52A1\u5931\u8D25";
|
|
98
|
+
}
|
|
99
|
+
function responseCode(value) {
|
|
100
|
+
const root = responseRoot(value);
|
|
101
|
+
return root?.ret ?? root?.code;
|
|
102
|
+
}
|
|
103
|
+
function isInvoiceSessionExpired(value) {
|
|
104
|
+
const code = responseCode(value);
|
|
105
|
+
return code !== void 0 && String(code) === INVOICE_SESSION_EXPIRED_CODE;
|
|
106
|
+
}
|
|
107
|
+
function tokenAccount(session) {
|
|
108
|
+
return createHash("sha256").update(`${session.profile}
|
|
109
|
+
${session.baseUrl}
|
|
110
|
+
${session.userId}`).digest("hex");
|
|
111
|
+
}
|
|
112
|
+
function createInvoiceTokenStore(session) {
|
|
113
|
+
const account = tokenAccount(session);
|
|
114
|
+
let entryPromise = null;
|
|
115
|
+
async function entry() {
|
|
116
|
+
if (!entryPromise) {
|
|
117
|
+
entryPromise = import("@napi-rs/keyring").then(({ Entry }) => new Entry(TOKEN_SERVICE, account));
|
|
118
|
+
}
|
|
119
|
+
return entryPromise;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
async load() {
|
|
123
|
+
try {
|
|
124
|
+
const value = await (await entry()).getPassword();
|
|
125
|
+
return typeof value === "string" && value.trim() ? value : null;
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
async save(token) {
|
|
131
|
+
if (!token.trim()) return false;
|
|
132
|
+
try {
|
|
133
|
+
await (await entry()).setPassword(token);
|
|
134
|
+
return true;
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
async clear() {
|
|
140
|
+
try {
|
|
141
|
+
await (await entry()).deletePassword();
|
|
142
|
+
return true;
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function clearInvoiceTokenForSession(session) {
|
|
150
|
+
return createInvoiceTokenStore(session).clear();
|
|
151
|
+
}
|
|
152
|
+
function inferProfile(ctx) {
|
|
153
|
+
const options = ctx.getGlobalOptions();
|
|
154
|
+
return options.profile || getActiveProfile();
|
|
155
|
+
}
|
|
156
|
+
function trustedInvoiceHeaders(invoiceToken) {
|
|
157
|
+
return invoiceToken ? { token: invoiceToken } : {};
|
|
158
|
+
}
|
|
159
|
+
function createInvoiceHost(ctx, dependencies = {}) {
|
|
160
|
+
let e10Session = null;
|
|
161
|
+
let sessionContext = null;
|
|
162
|
+
let invoiceToken = null;
|
|
163
|
+
let tokenStore = null;
|
|
164
|
+
const requireSession = dependencies.requireSession || requireE10Session;
|
|
165
|
+
const tokenStoreFactory = dependencies.tokenStoreFactory || createInvoiceTokenStore;
|
|
166
|
+
async function ensureSession() {
|
|
167
|
+
if (!e10Session) {
|
|
168
|
+
e10Session = await requireSession(ctx);
|
|
169
|
+
sessionContext = {
|
|
170
|
+
baseUrl: e10Session.getBaseUrl(),
|
|
171
|
+
profile: inferProfile(ctx),
|
|
172
|
+
userId: e10Session.userId
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return e10Session;
|
|
176
|
+
}
|
|
177
|
+
async function getSession() {
|
|
178
|
+
await ensureSession();
|
|
179
|
+
return sessionContext;
|
|
180
|
+
}
|
|
181
|
+
async function ensureInvoiceToken(timeoutMs = 3e4) {
|
|
182
|
+
await ensureSession();
|
|
183
|
+
const context = await getSession();
|
|
184
|
+
tokenStore ||= tokenStoreFactory(context);
|
|
185
|
+
if (invoiceToken) return invoiceToken;
|
|
186
|
+
invoiceToken = await tokenStore.load();
|
|
187
|
+
if (invoiceToken) return invoiceToken;
|
|
188
|
+
const tokenResponse = await invoiceRequest({
|
|
189
|
+
method: "GET",
|
|
190
|
+
path: "/api/inc/proxy/getToken",
|
|
191
|
+
query: { appType: 1 },
|
|
192
|
+
needsInvoiceToken: false,
|
|
193
|
+
timeoutMs
|
|
194
|
+
});
|
|
195
|
+
const token = tokenResponse?.data?.token;
|
|
196
|
+
if (typeof token !== "string" || !token.trim()) {
|
|
197
|
+
throw invoiceAuthError("invoice_token_missing", "\u672A\u53D6\u5F97\u4E1A\u7968\u901A\u4E1A\u52A1 Token");
|
|
198
|
+
}
|
|
199
|
+
await tokenStore.save(token);
|
|
200
|
+
invoiceToken = token;
|
|
201
|
+
return token;
|
|
202
|
+
}
|
|
203
|
+
async function ensureContext(needsInvoiceToken, timeoutMs, path) {
|
|
204
|
+
await ensureSession();
|
|
205
|
+
const tokenEndpoint = path === "/api/inc/proxy/getToken" || path === "/api/app/inc/proxy/getToken";
|
|
206
|
+
if (tokenEndpoint) return void 0;
|
|
207
|
+
if (!needsInvoiceToken) {
|
|
208
|
+
}
|
|
209
|
+
return ensureInvoiceToken(timeoutMs);
|
|
210
|
+
}
|
|
211
|
+
async function clearCachedInvoiceToken() {
|
|
212
|
+
invoiceToken = null;
|
|
213
|
+
await tokenStore?.clear().catch(() => false);
|
|
214
|
+
}
|
|
215
|
+
async function runtime() {
|
|
216
|
+
return createE10RequestRuntime(ctx, await ensureSession(), {
|
|
217
|
+
interceptors: dependencies.interceptors,
|
|
218
|
+
fetch: dependencies.fetch
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function businessError(value) {
|
|
222
|
+
const code = responseCode(value);
|
|
223
|
+
return new InvoiceCliError("api", "business_error", responseMessage(value), {
|
|
224
|
+
code: String(code),
|
|
225
|
+
details: { ret: code },
|
|
226
|
+
exitCode: 1
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async function handleBusinessResponse(value, retry, canRetry) {
|
|
230
|
+
const code = responseCode(value);
|
|
231
|
+
if (code === void 0 || code === 0 || code === 200) return value;
|
|
232
|
+
if (isInvoiceSessionExpired(value)) {
|
|
233
|
+
await clearCachedInvoiceToken();
|
|
234
|
+
if (canRetry) return retry();
|
|
235
|
+
throw invoiceAuthError(
|
|
236
|
+
"invoice_session_expired",
|
|
237
|
+
`\u53D1\u7968\u4E1A\u52A1\u767B\u5F55\u6001\u5DF2\u5931\u6548\uFF0C\u5DF2\u6E05\u7406\u672C\u5730\u53D1\u7968 Token\u3002${E10_REAUTH_GUIDANCE}`,
|
|
238
|
+
{ ret: code }
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
throw businessError(value);
|
|
242
|
+
}
|
|
243
|
+
async function invoiceRequest(request, canRetryExpiredToken = true) {
|
|
244
|
+
const {
|
|
245
|
+
method = "POST",
|
|
246
|
+
path,
|
|
247
|
+
query,
|
|
248
|
+
headers,
|
|
249
|
+
body,
|
|
250
|
+
operation,
|
|
251
|
+
needsInvoiceToken = true,
|
|
252
|
+
timeoutMs = 3e4
|
|
253
|
+
} = request;
|
|
254
|
+
assertPath(path);
|
|
255
|
+
const token = await ensureContext(needsInvoiceToken, timeoutMs, path);
|
|
256
|
+
const response = await (await runtime()).requestJson({
|
|
257
|
+
module: "invoice",
|
|
258
|
+
operation,
|
|
259
|
+
method,
|
|
260
|
+
path,
|
|
261
|
+
query,
|
|
262
|
+
headers,
|
|
263
|
+
body,
|
|
264
|
+
timeoutMs,
|
|
265
|
+
trustedHeaders: trustedInvoiceHeaders(token)
|
|
266
|
+
});
|
|
267
|
+
if (response.status === 401 || response.status === 302) {
|
|
268
|
+
throw invoiceAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
|
|
269
|
+
}
|
|
270
|
+
if (response.parseError) {
|
|
271
|
+
if (response.status < 200 || response.status >= 300) {
|
|
272
|
+
throw new InvoiceCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
|
|
273
|
+
code: response.status,
|
|
274
|
+
details: { status: response.status },
|
|
275
|
+
exitCode: 1
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
throw invoiceNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
|
|
279
|
+
}
|
|
280
|
+
if (response.status < 200 || response.status >= 300) {
|
|
281
|
+
throw new InvoiceCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
|
|
282
|
+
code: response.status,
|
|
283
|
+
details: { status: response.status, message: responseMessage(response.value) },
|
|
284
|
+
exitCode: 1
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
let value = response.value;
|
|
288
|
+
if (request.rewriteJsonText && response.text) {
|
|
289
|
+
try {
|
|
290
|
+
value = JSON.parse(request.rewriteJsonText(response.text));
|
|
291
|
+
} catch {
|
|
292
|
+
value = response.value;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return handleBusinessResponse(value, () => invoiceRequest(request, false), canRetryExpiredToken && Boolean(token));
|
|
296
|
+
}
|
|
297
|
+
async function invoiceMultipartRequest(request, canRetryExpiredToken = true) {
|
|
298
|
+
const {
|
|
299
|
+
method = "POST",
|
|
300
|
+
path,
|
|
301
|
+
query,
|
|
302
|
+
fields = {},
|
|
303
|
+
file,
|
|
304
|
+
headers,
|
|
305
|
+
operation,
|
|
306
|
+
needsInvoiceToken = true,
|
|
307
|
+
timeoutMs = 3e4
|
|
308
|
+
} = request;
|
|
309
|
+
if (!file && !Object.values(fields).some((value) => value !== void 0 && value !== null && value !== "")) {
|
|
310
|
+
throw invoiceValidationError("input_invalid", "multipart \u8BF7\u6C42\u9700\u8981\u6587\u4EF6\u3001URL \u6216\u8868\u5355\u5B57\u6BB5");
|
|
311
|
+
}
|
|
312
|
+
assertPath(path);
|
|
313
|
+
const token = await ensureContext(needsInvoiceToken, timeoutMs, path);
|
|
314
|
+
const form = new FormData();
|
|
315
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
316
|
+
if (value === void 0 || value === null) continue;
|
|
317
|
+
form.append(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
318
|
+
}
|
|
319
|
+
if (file) {
|
|
320
|
+
const content = await readFile(file.path);
|
|
321
|
+
form.append("file", new Blob([content], { type: file.mimeType || "application/octet-stream" }), file.name);
|
|
322
|
+
}
|
|
323
|
+
const response = await (await runtime()).requestJson({
|
|
324
|
+
module: "invoice",
|
|
325
|
+
operation,
|
|
326
|
+
method,
|
|
327
|
+
path,
|
|
328
|
+
query,
|
|
329
|
+
headers,
|
|
330
|
+
formData: form,
|
|
331
|
+
timeoutMs,
|
|
332
|
+
trustedHeaders: trustedInvoiceHeaders(token)
|
|
333
|
+
});
|
|
334
|
+
if (response.status === 401 || response.status === 302) {
|
|
335
|
+
throw invoiceAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
|
|
336
|
+
}
|
|
337
|
+
if (response.parseError) {
|
|
338
|
+
throw invoiceNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
|
|
339
|
+
}
|
|
340
|
+
if (response.status < 200 || response.status >= 300) {
|
|
341
|
+
throw new InvoiceCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
|
|
342
|
+
code: response.status,
|
|
343
|
+
details: { status: response.status, message: responseMessage(response.value) },
|
|
344
|
+
exitCode: 1
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return handleBusinessResponse(response.value, () => invoiceMultipartRequest(request, false), canRetryExpiredToken && Boolean(token));
|
|
348
|
+
}
|
|
349
|
+
async function invoiceFormRequest(request, canRetryExpiredToken = true) {
|
|
350
|
+
const {
|
|
351
|
+
method = "POST",
|
|
352
|
+
path,
|
|
353
|
+
query,
|
|
354
|
+
fields = {},
|
|
355
|
+
operation,
|
|
356
|
+
needsInvoiceToken = true,
|
|
357
|
+
timeoutMs = 3e4
|
|
358
|
+
} = request;
|
|
359
|
+
assertPath(path);
|
|
360
|
+
const token = await ensureContext(needsInvoiceToken, timeoutMs, path);
|
|
361
|
+
const form = new URLSearchParams();
|
|
362
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
363
|
+
if (value === void 0 || value === null) continue;
|
|
364
|
+
form.set(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
365
|
+
}
|
|
366
|
+
const response = await (await runtime()).requestJson({
|
|
367
|
+
module: "invoice",
|
|
368
|
+
operation,
|
|
369
|
+
method,
|
|
370
|
+
path,
|
|
371
|
+
query,
|
|
372
|
+
form,
|
|
373
|
+
timeoutMs,
|
|
374
|
+
trustedHeaders: trustedInvoiceHeaders(token)
|
|
375
|
+
});
|
|
376
|
+
if (response.status === 401 || response.status === 302) {
|
|
377
|
+
throw invoiceAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
|
|
378
|
+
}
|
|
379
|
+
if (response.parseError) {
|
|
380
|
+
throw invoiceNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
|
|
381
|
+
}
|
|
382
|
+
if (response.status < 200 || response.status >= 300) {
|
|
383
|
+
throw new InvoiceCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
|
|
384
|
+
code: response.status,
|
|
385
|
+
details: { status: response.status, message: responseMessage(response.value) },
|
|
386
|
+
exitCode: 1
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return handleBusinessResponse(response.value, () => invoiceFormRequest(request, false), canRetryExpiredToken && Boolean(token));
|
|
390
|
+
}
|
|
391
|
+
async function invoiceDownload({ id, fid, needLog = false, operation, timeoutMs = 3e4 }, canRetryExpiredToken = true) {
|
|
392
|
+
const token = await ensureContext(true, timeoutMs, "/api/inc/file/download");
|
|
393
|
+
const response = await (await runtime()).requestBinary({
|
|
394
|
+
module: "invoice",
|
|
395
|
+
operation,
|
|
396
|
+
method: "GET",
|
|
397
|
+
path: "/api/inc/file/download",
|
|
398
|
+
query: { id, fid, needLog },
|
|
399
|
+
headers: { Accept: "application/octet-stream, application/pdf, */*" },
|
|
400
|
+
timeoutMs,
|
|
401
|
+
trustedHeaders: trustedInvoiceHeaders(token)
|
|
402
|
+
});
|
|
403
|
+
if (response.status === 401 || response.status === 302) {
|
|
404
|
+
throw invoiceAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
|
|
405
|
+
}
|
|
406
|
+
const contentType = response.contentType;
|
|
407
|
+
const declaredLength = Number(response.headers.get("content-length"));
|
|
408
|
+
if (Number.isFinite(declaredLength) && declaredLength > MAX_DOWNLOAD_BYTES) {
|
|
409
|
+
throw invoiceNetworkError("response_too_large", `\u4E0B\u8F7D\u6587\u4EF6\u8D85\u8FC7 ${MAX_DOWNLOAD_BYTES} \u5B57\u8282\u9650\u5236`, { retryable: false });
|
|
410
|
+
}
|
|
411
|
+
const content = response.content;
|
|
412
|
+
const looksLikeJson = /^[\s\r\n]*[\[{]/u.test(content.subarray(0, 64).toString("utf8"));
|
|
413
|
+
if (response.status < 200 || response.status >= 300 || contentType.includes("json") || looksLikeJson) {
|
|
414
|
+
let value = {};
|
|
415
|
+
try {
|
|
416
|
+
value = JSON.parse(content.toString("utf8"));
|
|
417
|
+
} catch {
|
|
418
|
+
value = {};
|
|
419
|
+
}
|
|
420
|
+
if (isInvoiceSessionExpired(value)) {
|
|
421
|
+
await clearCachedInvoiceToken();
|
|
422
|
+
if (canRetryExpiredToken && token) return invoiceDownload({ id, fid, needLog, operation, timeoutMs }, false);
|
|
423
|
+
throw invoiceAuthError(
|
|
424
|
+
"invoice_session_expired",
|
|
425
|
+
`\u53D1\u7968\u4E1A\u52A1\u767B\u5F55\u6001\u5DF2\u5931\u6548\uFF0C\u5DF2\u6E05\u7406\u672C\u5730\u53D1\u7968 Token\u3002${E10_REAUTH_GUIDANCE}`,
|
|
426
|
+
{ ret: responseCode(value), status: response.status }
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
throw new InvoiceCliError("api", "download_failed", responseMessage(value) || `\u4E0B\u8F7D\u5931\u8D25\uFF08HTTP ${response.status}\uFF09`, {
|
|
430
|
+
code: response.status,
|
|
431
|
+
details: { status: response.status, ret: responseCode(value) },
|
|
432
|
+
exitCode: 1
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if (!content.length) {
|
|
436
|
+
throw invoiceNetworkError("protocol", "\u4E0B\u8F7D\u63A5\u53E3\u8FD4\u56DE\u7A7A\u6587\u4EF6", { retryable: false });
|
|
437
|
+
}
|
|
438
|
+
if (content.length > MAX_DOWNLOAD_BYTES) {
|
|
439
|
+
throw invoiceNetworkError("response_too_large", `\u4E0B\u8F7D\u6587\u4EF6\u8D85\u8FC7 ${MAX_DOWNLOAD_BYTES} \u5B57\u8282\u9650\u5236`, { retryable: false });
|
|
440
|
+
}
|
|
441
|
+
return { content, contentType };
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
invoiceRequest,
|
|
445
|
+
invoiceMultipartRequest,
|
|
446
|
+
invoiceFormRequest,
|
|
447
|
+
invoiceDownload,
|
|
448
|
+
getSession,
|
|
449
|
+
invalidateToken() {
|
|
450
|
+
invoiceToken = null;
|
|
451
|
+
void clearCachedInvoiceToken();
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export {
|
|
457
|
+
InvoiceCliError,
|
|
458
|
+
invoiceValidationError,
|
|
459
|
+
invoiceConfirmationError,
|
|
460
|
+
invoicePartialError,
|
|
461
|
+
isInvoiceNetworkError,
|
|
462
|
+
clearInvoiceTokenForSession,
|
|
463
|
+
createInvoiceHost
|
|
464
|
+
};
|