weaver-work-cli 0.1.29 → 0.1.31

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 (185) hide show
  1. package/dist/chunks/archive-U766FTFH.js +2537 -0
  2. package/dist/chunks/archive-oa-DMWEKX3L.js +1317 -0
  3. package/dist/chunks/asset-TCR7VDEV.js +2109 -0
  4. package/dist/chunks/attachment-content-AQNX5N3S.js +23 -0
  5. package/dist/chunks/blog-EVZWGDVM.js +2157 -0
  6. package/dist/chunks/caizhilian-JOWS6SL5.js +10087 -0
  7. package/dist/chunks/calendar-5WNCV66Q.js +1195 -0
  8. package/dist/chunks/chunk-2DUV44UX.js +15606 -0
  9. package/dist/chunks/chunk-324YPTC2.js +1607 -0
  10. package/dist/chunks/chunk-65QMVWHS.js +231 -0
  11. package/dist/chunks/chunk-6V7ZLF34.js +387 -0
  12. package/dist/chunks/chunk-AC7KJWC5.js +358 -0
  13. package/dist/chunks/chunk-AJ62BGAW.js +29 -0
  14. package/dist/chunks/chunk-BUSC6UAE.js +43 -0
  15. package/dist/chunks/chunk-CVZ2JOSW.js +62 -0
  16. package/dist/chunks/chunk-D4LTJSJD.js +477 -0
  17. package/dist/chunks/chunk-EG6ZU444.js +654 -0
  18. package/dist/chunks/chunk-EZALDOQH.js +383 -0
  19. package/dist/chunks/chunk-FMPJJYYI.js +106 -0
  20. package/dist/chunks/chunk-G2JSIUWF.js +769 -0
  21. package/dist/chunks/chunk-GCG2NMWR.js +703 -0
  22. package/dist/chunks/chunk-GPMFD4RD.js +75 -0
  23. package/dist/chunks/chunk-H3WDBYJW.js +508 -0
  24. package/dist/chunks/chunk-H6XSTSLM.js +2357 -0
  25. package/dist/chunks/chunk-J7RJTZSV.js +5556 -0
  26. package/dist/chunks/chunk-LUSPKZKY.js +53 -0
  27. package/dist/chunks/chunk-NIAJ5ZCG.js +73 -0
  28. package/dist/chunks/chunk-NOODWMCL.js +584 -0
  29. package/dist/chunks/chunk-OOUTBLZ4.js +51 -0
  30. package/dist/chunks/chunk-P26ZWSKU.js +73 -0
  31. package/dist/chunks/chunk-QWY6PGL6.js +3472 -0
  32. package/dist/chunks/chunk-R2IJAK7T.js +464 -0
  33. package/dist/chunks/chunk-R7O5PUWO.js +205 -0
  34. package/dist/chunks/chunk-RCGYCOMG.js +6962 -0
  35. package/dist/chunks/chunk-VZTXRG6X.js +403 -0
  36. package/dist/chunks/chunk-WHD4XMRP.js +161 -0
  37. package/dist/chunks/chunk-YLCYX7LE.js +371 -0
  38. package/dist/chunks/chunk-ZEDWSH32.js +68 -0
  39. package/dist/chunks/continuation-2CKSBLA6.js +11 -0
  40. package/dist/chunks/continuation-HZIZRZBX.js +13 -0
  41. package/dist/chunks/continuation-NLECEJPX.js +11 -0
  42. package/dist/chunks/ebuilder-form-NJ4YK6CC.js +2276 -0
  43. package/dist/chunks/ehr-MMYN36VA.js +5241 -0
  44. package/dist/chunks/employee-SAK2QYXX.js +11 -0
  45. package/dist/chunks/esb-HIWHOU7Q.js +141 -0
  46. package/dist/chunks/fna-KBACQTA5.js +1444 -0
  47. package/dist/chunks/host-3OHS5QUX.js +21 -0
  48. package/dist/chunks/host-IG6KEH5Q.js +19 -0
  49. package/dist/chunks/host-KQL5N4HO.js +23 -0
  50. package/dist/chunks/host-LLSZQCWR.js +17 -0
  51. package/dist/chunks/hrm-LYEC67ZQ.js +244 -0
  52. package/dist/chunks/im-RN2UKAEU.js +252 -0
  53. package/dist/chunks/invoice-EEPHLAF6.js +5179 -0
  54. package/dist/chunks/jiuchuanhui-WVVZYSJE.js +1940 -0
  55. package/dist/chunks/lazy-dispatch-MDOFFL2S.js +28 -0
  56. package/dist/chunks/mail-LNQLTF6L.js +2695 -0
  57. package/dist/chunks/meeting-XSD3BDVQ.js +504 -0
  58. package/dist/chunks/msg-parse-4GSQ2WTO.js +41 -0
  59. package/dist/chunks/okr-TMWTIU2K.js +2482 -0
  60. package/dist/chunks/plan-A2FSFA7T.js +2025 -0
  61. package/dist/chunks/project-T26QLBQF.js +1361 -0
  62. package/dist/chunks/registry-2VLUAESA.js +14 -0
  63. package/dist/chunks/registry-JCFEYXOE.js +18 -0
  64. package/dist/chunks/registry-NYPYMZXG.js +16 -0
  65. package/dist/chunks/registry-Q7OQJ3SU.js +19 -0
  66. package/dist/chunks/registry-ZJMJVWFA.js +19 -0
  67. package/dist/chunks/room-recommend-UR4ZDZS6.js +20 -0
  68. package/dist/chunks/schedule-5L2PM4M6.js +24 -0
  69. package/dist/chunks/state-Y2XBP6YE.js +15 -0
  70. package/dist/chunks/workflow-TR6PG2SL.js +245 -0
  71. package/dist/cmd/argv.js +45 -0
  72. package/dist/cmd/docs/index.js +3 -3
  73. package/dist/cmd/lazy-dispatch.js +20 -0
  74. package/dist/cmd/root.js +2 -4
  75. package/dist/cmd/setup/index.js +2 -2
  76. package/dist/cmd/skills/index.js +2 -2
  77. package/dist/core/package-paths.js +47 -0
  78. package/dist/index.js +163 -7
  79. package/dist/internal/e10/auth/xiaoe.js +3 -3
  80. package/dist/internal/e10/request-runtime.js +18 -62
  81. package/dist/internal/skills/detector.js +2 -2
  82. package/dist/shortcuts/contract/data/performance-catalog.js +1306 -0
  83. package/dist/shortcuts/contract/host.js +91 -35
  84. package/dist/shortcuts/contract/index.js +213 -0
  85. package/dist/shortcuts/contract/manifest.js +928 -0
  86. package/dist/shortcuts/contract/ooxml/docx.js +295 -0
  87. package/dist/shortcuts/contract/ooxml/xlsx.js +221 -0
  88. package/dist/shortcuts/contract/ooxml/zip.js +158 -0
  89. package/dist/shortcuts/contract/operations/assistant.js +1156 -0
  90. package/dist/shortcuts/contract/operations/clause-library.js +522 -0
  91. package/dist/shortcuts/contract/operations/compare.js +193 -0
  92. package/dist/shortcuts/contract/operations/credit-page.js +34 -0
  93. package/dist/shortcuts/contract/operations/flow.js +98 -0
  94. package/dist/shortcuts/contract/operations/page.js +66 -0
  95. package/dist/shortcuts/contract/operations/performance.js +733 -0
  96. package/dist/shortcuts/contract/operations/quote.js +557 -0
  97. package/dist/shortcuts/contract/operations/recommend.js +78 -0
  98. package/dist/shortcuts/contract/operations/registry.js +18 -0
  99. package/dist/shortcuts/contract/operations/review.js +83 -0
  100. package/dist/shortcuts/contract/operations/shared.js +37 -0
  101. package/dist/shortcuts/contract/operations/upload.js +108 -0
  102. package/dist/shortcuts/contract/operations/write.js +3 -2
  103. package/dist/shortcuts/index.js +140 -40
  104. package/dist/shortcuts/invoice/manifest.js +34 -11
  105. package/dist/shortcuts/invoice/operations/reim-auto.js +9 -0
  106. package/dist/shortcuts/invoice/operations/reim.js +81 -5
  107. package/dist/shortcuts/invoice/operations/shared.js +12 -5
  108. package/dist/shortcuts/meeting/host.js +45 -3
  109. package/dist/shortcuts/meeting/invitation/docx.js +442 -0
  110. package/dist/shortcuts/meeting/operations/attachment-content.js +418 -0
  111. package/dist/shortcuts/meeting/operations/attachment.js +442 -0
  112. package/dist/shortcuts/meeting/operations/eb/cache.js +57 -0
  113. package/dist/shortcuts/meeting/operations/eb/catalog.js +343 -28
  114. package/dist/shortcuts/meeting/operations/eb/conflict.js +372 -11
  115. package/dist/shortcuts/meeting/operations/eb/create-flow.js +710 -0
  116. package/dist/shortcuts/meeting/operations/eb/decision.js +47 -1
  117. package/dist/shortcuts/meeting/operations/eb/factory.js +129 -11
  118. package/dist/shortcuts/meeting/operations/eb/index.js +122 -2
  119. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +378 -0
  120. package/dist/shortcuts/meeting/operations/eb/room-summary.js +84 -0
  121. package/dist/shortcuts/meeting/operations/eb/schedule.js +450 -0
  122. package/dist/shortcuts/meeting/operations/from-group-chat.js +576 -0
  123. package/dist/shortcuts/meeting/operations/invitation.js +458 -0
  124. package/dist/shortcuts/meeting/operations/minute-content.js +266 -0
  125. package/dist/shortcuts/meeting/operations/pipeline.js +489 -0
  126. package/dist/shortcuts/meeting/operations/qrcode.js +131 -0
  127. package/dist/shortcuts/meeting/operations/receipts.js +1 -1
  128. package/dist/shortcuts/meeting/operations/registry.js +18 -0
  129. package/dist/shortcuts/meeting/operations/summary.js +276 -0
  130. package/dist/shortcuts/meeting/operations/task-notify.js +325 -0
  131. package/dist/shortcuts/meeting/operations.js +42 -1
  132. package/dist/shortcuts/meeting/qr/encoder.js +427 -0
  133. package/dist/shortcuts/meeting/qr/render.js +103 -0
  134. package/dist/shortcuts/workflow/operations/form.js +17 -5
  135. package/docs/contract.md +39 -4
  136. package/docs/invoice.md +5 -5
  137. package/package.json +3 -2
  138. package/scripts/bundle.mjs +63 -0
  139. package/skill-template/business-info.json +25 -4
  140. package/skill-template/domains/jinchengda.md +16 -3
  141. package/skill-template/domains/yepiaotong.md +1 -1
  142. package/skills/weaver-e10-jinchengda/SKILL.md +111 -31
  143. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +7 -13
  144. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +150 -0
  145. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +87 -0
  146. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +111 -0
  147. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +0 -15
  148. package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +0 -13
  149. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +50 -0
  150. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +4 -2
  151. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +74 -0
  152. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +84 -0
  153. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +29 -0
  154. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +28 -0
  155. package/skills/weaver-e10-jinchengda/references/contract-request-status.md +2 -21
  156. package/skills/weaver-e10-jinchengda/references/contract-request-write.md +0 -24
  157. package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +0 -15
  158. package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +0 -17
  159. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +70 -0
  160. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +0 -15
  161. package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +0 -15
  162. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1168 -152
  163. package/skills/weaver-e10-meeting/SKILL.md +493 -17
  164. package/skills/weaver-e10-meeting/references/meeting-change.md +4 -4
  165. package/skills/weaver-e10-meeting/references/meeting-create.md +6 -6
  166. package/skills/weaver-e10-meeting/references/meeting-eb.md +503 -27
  167. package/skills/weaver-e10-meeting/references/meeting-invitation.md +113 -0
  168. package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +6 -6
  169. package/skills/weaver-e10-meeting/references/meeting-minute-file.md +425 -0
  170. package/skills/weaver-e10-meeting/references/meeting-queries.md +4 -4
  171. package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +15 -15
  172. package/skills/weaver-e10-meeting/references/meeting-verification.md +19 -11
  173. package/skills/weaver-e10-meeting.zip +0 -0
  174. package/skills/weaver-e10-yepiaotong/SKILL.md +9 -5
  175. package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +1 -1
  176. package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +6 -5
  177. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +14 -11
  178. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +97 -56
  179. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +84 -60
  180. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +142 -105
  181. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +53 -194
  182. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +7 -7
  183. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +164 -72
  184. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +6 -0
  185. 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-H3WDBYJW.js";
7
+ import {
8
+ E10_REAUTH_GUIDANCE,
9
+ E10_SESSION_EXPIRED_MESSAGE,
10
+ getActiveProfile
11
+ } from "./chunk-324YPTC2.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
+ };
@@ -0,0 +1,205 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ EsbCliError,
5
+ esbApiError,
6
+ esbAuthError,
7
+ esbNetworkError,
8
+ esbPermissionError,
9
+ esbValidationError,
10
+ esbWriteUncertain
11
+ } from "./chunk-GPMFD4RD.js";
12
+ import {
13
+ E10ApiError,
14
+ createE10RequestRuntime,
15
+ requireE10Session
16
+ } from "./chunk-H3WDBYJW.js";
17
+ import {
18
+ E10_SESSION_EXPIRED_MESSAGE,
19
+ getActiveProfile
20
+ } from "./chunk-324YPTC2.js";
21
+
22
+ // src/shortcuts/esb/host.ts
23
+ var ESB_PATHS = {
24
+ inputFormat: "/api/bs/esb/setting/customData/application/copyCustomData",
25
+ trigger: "/api/esb/server/event/triggerActionFlow"
26
+ };
27
+ var TRIGGER_RESULT_CODES = {
28
+ 100: { subtype: "parameter_invalid" },
29
+ 101: { subtype: "batch_key_invalid" },
30
+ 201: { subtype: "flow_not_bound" },
31
+ 202: { subtype: "execute_failed" },
32
+ 203: { subtype: "execute_timeout", retryable: true },
33
+ 204: { subtype: "permission_denied", permission: true },
34
+ 400: { subtype: "license_required" },
35
+ 401: { subtype: "tenant_permission_denied", permission: true },
36
+ 402: { subtype: "flow_disabled" },
37
+ 403: { subtype: "tenant_missing", permission: true },
38
+ 404: { subtype: "flow_not_found" },
39
+ 500: { subtype: "execute_failed" },
40
+ 501: { subtype: "result_fetch_failed", retryable: true },
41
+ 502: { subtype: "result_fetch_timeout", retryable: true },
42
+ 505: { subtype: "flow_running", retryable: true },
43
+ 506: { subtype: "execution_loop_conflict" },
44
+ 507: { subtype: "throttled", retryable: true },
45
+ 508: { subtype: "throttled", retryable: true },
46
+ 509: { subtype: "execution_terminated" },
47
+ 510: { subtype: "memory_exceeded" },
48
+ 511: { subtype: "throttled", retryable: true },
49
+ 512: { subtype: "flow_in_recycle_bin" }
50
+ };
51
+ var TARGET_FATAL_SUBTYPES = /* @__PURE__ */ new Set([
52
+ "flow_not_found",
53
+ "flow_not_bound",
54
+ "flow_disabled",
55
+ "flow_in_recycle_bin",
56
+ "parameter_invalid"
57
+ ]);
58
+ function isEsbFlowUnavailable(error) {
59
+ return error instanceof EsbCliError && TARGET_FATAL_SUBTYPES.has(error.subtype);
60
+ }
61
+ function triggerResultCode(value) {
62
+ if (!value || typeof value !== "object") return void 0;
63
+ const raw = value.resultCode;
64
+ if (raw === void 0 || raw === null || raw === "") return void 0;
65
+ const numeric = Number(raw);
66
+ return Number.isFinite(numeric) ? numeric : void 0;
67
+ }
68
+ function assertPath(requestPath) {
69
+ if (typeof requestPath !== "string" || !requestPath.startsWith("/") || requestPath.startsWith("//")) {
70
+ throw esbValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u5FC5\u987B\u662F\u76F8\u5BF9\u7EDD\u5BF9\u8DEF\u5F84");
71
+ }
72
+ if (/^https?:/i.test(requestPath) || /[\r\n]/.test(requestPath) || requestPath.includes("/../")) {
73
+ throw esbValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u4E0D\u5141\u8BB8\u8DE8\u57DF\u6216\u8DEF\u5F84\u9003\u9038");
74
+ }
75
+ if (!requestPath.startsWith("/api/")) {
76
+ throw esbValidationError("path_not_allowed", "ESB \u52A8\u4F5C\u6D41\u53EA\u80FD\u8C03\u7528 /api/ \u8DEF\u5F84");
77
+ }
78
+ }
79
+ function mapRuntimeNetworkError(error) {
80
+ if (error instanceof E10ApiError && error.type === "network") {
81
+ throw esbNetworkError(error.subtype, error.message, {
82
+ retryable: error.retryable,
83
+ details: error.details
84
+ });
85
+ }
86
+ throw error;
87
+ }
88
+ function createEsbHost(ctx, dependencies = {}) {
89
+ let e10Session = null;
90
+ let sessionContext = null;
91
+ const requireSession = dependencies.requireSession || requireE10Session;
92
+ async function ensureSession() {
93
+ if (!e10Session) {
94
+ e10Session = await requireSession(ctx);
95
+ sessionContext = {
96
+ baseUrl: e10Session.getBaseUrl(),
97
+ profile: ctx.getGlobalOptions().profile || getActiveProfile(),
98
+ userId: e10Session.userId,
99
+ tenantKey: e10Session.tenantKey,
100
+ eteamsId: e10Session.eteamsId
101
+ };
102
+ }
103
+ return e10Session;
104
+ }
105
+ async function getSession() {
106
+ await ensureSession();
107
+ return sessionContext;
108
+ }
109
+ async function runtime() {
110
+ return createE10RequestRuntime(ctx, await ensureSession(), { fetch: dependencies.fetch });
111
+ }
112
+ async function send(operation, path, body) {
113
+ assertPath(path);
114
+ let response;
115
+ try {
116
+ response = await (await runtime()).requestJson({
117
+ module: "esb",
118
+ operation,
119
+ method: "POST",
120
+ path,
121
+ body,
122
+ headers: { "X-Requested-With": "XMLHttpRequest" },
123
+ timeoutMs: 6e4
124
+ });
125
+ } catch (error) {
126
+ mapRuntimeNetworkError(error);
127
+ }
128
+ if (response.status === 401 || response.status === 302) {
129
+ throw esbAuthError(
130
+ "session_expired",
131
+ E10_SESSION_EXPIRED_MESSAGE,
132
+ { httpStatus: response.status }
133
+ );
134
+ }
135
+ if (response.parseError) {
136
+ if (response.status < 200 || response.status >= 300) {
137
+ throw esbApiError("http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
138
+ code: response.status,
139
+ details: { status: response.status }
140
+ });
141
+ }
142
+ throw esbNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
143
+ }
144
+ if (response.status < 200 || response.status >= 300) {
145
+ throw esbApiError("http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
146
+ code: response.status,
147
+ details: { status: response.status }
148
+ });
149
+ }
150
+ return response.value;
151
+ }
152
+ function assertTriggerSuccess(value, operation) {
153
+ const code = triggerResultCode(value);
154
+ const record = value && typeof value === "object" ? value : {};
155
+ const serverMessage = typeof record.resultMsg === "string" ? record.resultMsg.trim() : "";
156
+ if (code === void 0) {
157
+ throw esbNetworkError("protocol", "\u89E6\u53D1\u63A5\u53E3\u672A\u8FD4\u56DE resultCode\uFF0C\u65E0\u6CD5\u5224\u5B9A\u6267\u884C\u7ED3\u679C", {
158
+ retryable: false,
159
+ details: { operation }
160
+ });
161
+ }
162
+ if (code === 200) return value;
163
+ const rule = TRIGGER_RESULT_CODES[code] || { subtype: "business_error" };
164
+ const message = serverMessage || `\u52A8\u4F5C\u6D41\u6267\u884C\u5931\u8D25\uFF08resultCode=${code}\uFF09`;
165
+ const options = {
166
+ code,
167
+ retryable: rule.retryable ?? false,
168
+ details: { operation, resultCode: code, resultMsg: serverMessage }
169
+ };
170
+ if (rule.permission) throw esbPermissionError(rule.subtype, message, options);
171
+ throw esbApiError(rule.subtype, message, options);
172
+ }
173
+ return {
174
+ async inputFormat(applicationId) {
175
+ const value = await send("esb.input-format", ESB_PATHS.inputFormat, { applicationId });
176
+ const code = triggerResultCode(value);
177
+ if (code !== void 0 && code !== 200) assertTriggerSuccess(value, "esb.input-format");
178
+ return value;
179
+ },
180
+ async trigger(payload) {
181
+ let value;
182
+ try {
183
+ value = await send("esb.trigger.apply", ESB_PATHS.trigger, payload);
184
+ } catch (error) {
185
+ if (error instanceof EsbCliError && error.type === "network") {
186
+ throw esbWriteUncertain(
187
+ `\u89E6\u53D1\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u53D6\u5F97\u7ED3\u679C\uFF08${error.subtype}\uFF09\uFF1A\u65E0\u6CD5\u786E\u8BA4\u52A8\u4F5C\u6D41\u662F\u5426\u5DF2\u6267\u884C\uFF0C\u8BF7\u5148\u5728 ESB \u4E2D\u5FC3\u67E5\u770B\u52A8\u4F5C\u6D41\u8FD0\u884C\u65E5\u5FD7\u540E\u518D\u51B3\u5B9A\u662F\u5426\u91CD\u8BD5`,
188
+ { cause: error.message }
189
+ );
190
+ }
191
+ throw error;
192
+ }
193
+ return assertTriggerSuccess(value, "esb.trigger.apply");
194
+ },
195
+ getSession
196
+ };
197
+ }
198
+
199
+ export {
200
+ ESB_PATHS,
201
+ TARGET_FATAL_SUBTYPES,
202
+ isEsbFlowUnavailable,
203
+ triggerResultCode,
204
+ createEsbHost
205
+ };