@wirecat/zoom-cli 0.69.0 → 0.71.0

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 (177) hide show
  1. package/README.md +1 -1
  2. package/dist/account-removal.d.ts +6 -0
  3. package/dist/account-removal.d.ts.map +1 -0
  4. package/dist/account-removal.js +43 -0
  5. package/dist/account-removal.js.map +1 -0
  6. package/dist/answer-entities.d.ts +2 -0
  7. package/dist/answer-entities.d.ts.map +1 -1
  8. package/dist/bin/zm.js +2 -2
  9. package/dist/bundle/{all-profiles-ZQWPCJEK.js → all-profiles-O4YNVPZX.js} +9 -9
  10. package/dist/bundle/answer-policy-PPSPMCLH.js +104 -0
  11. package/dist/bundle/{anthropic-7FUQ2HYJ.js → anthropic-7GGRX3RX.js} +20 -9
  12. package/dist/bundle/{app-server-DNPE2EQB.js → app-server-CPMKM3HI.js} +50 -50
  13. package/dist/bundle/{bun-ZVQFCFCC.js → bun-POHZKEPV.js} +2 -2
  14. package/dist/bundle/{bun-sqlite-EB2UMUPJ.js → bun-sqlite-PGYMBPEL.js} +4 -4
  15. package/dist/bundle/{chunk-R2ULMWB4.js → chunk-2FV5JUQU.js} +39 -593
  16. package/dist/bundle/{chunk-R3JYPY3J.js → chunk-2KESWII5.js} +2 -2
  17. package/dist/bundle/{chunk-S2EAGDS7.js → chunk-2RUAMDVV.js} +11 -11
  18. package/dist/bundle/{chunk-H3MFBYTQ.js → chunk-2U27KIKU.js} +5 -5
  19. package/dist/bundle/{chunk-KAPJQGHE.js → chunk-2U6SER67.js} +1 -1
  20. package/dist/bundle/chunk-4LAQDZXU.js +1635 -0
  21. package/dist/bundle/{chunk-SQT47CFW.js → chunk-4QPQ7MDA.js} +1 -1
  22. package/dist/bundle/{chunk-MNOVYS43.js → chunk-4QUFFB2U.js} +3 -3
  23. package/dist/bundle/{chunk-V74QFMSL.js → chunk-54YDWBYG.js} +1 -1
  24. package/dist/bundle/{chunk-MSDCZ6GT.js → chunk-5J4AMBMM.js} +4 -4
  25. package/dist/bundle/{chunk-GR3QDHBU.js → chunk-5K7OGPGA.js} +5 -5
  26. package/dist/bundle/{chunk-WY4NYPPS.js → chunk-5LJTU4LY.js} +12 -12
  27. package/dist/bundle/{chunk-MJMVIFSC.js → chunk-633QXP57.js} +10 -8
  28. package/dist/bundle/{chunk-EPPSMCEV.js → chunk-64ZHF6PJ.js} +1 -1
  29. package/dist/bundle/{chunk-ZRHMB3LQ.js → chunk-77TCCHMP.js} +1 -1
  30. package/dist/bundle/{chunk-BOAMDYLY.js → chunk-7QC4M4HS.js} +2 -2
  31. package/dist/bundle/{chunk-O7L44JK2.js → chunk-7ROXXRGG.js} +3933 -1525
  32. package/dist/bundle/{chunk-MVDPZRFE.js → chunk-ALIT5QFT.js} +1 -1
  33. package/dist/bundle/{chunk-6N2D6JGX.js → chunk-BBTQIVFP.js} +1 -1
  34. package/dist/bundle/{chunk-QXM7S3Y3.js → chunk-BGTEVIW4.js} +5 -5
  35. package/dist/bundle/{chunk-JX5JJZC3.js → chunk-CFQF6IGY.js} +2 -2
  36. package/dist/bundle/{chunk-5GOE6PQK.js → chunk-CKPCVEXU.js} +5 -5
  37. package/dist/bundle/{chunk-6KMTQX3D.js → chunk-CRFOGYDG.js} +1 -1
  38. package/dist/bundle/{chunk-5H6VTEEC.js → chunk-CT4WVR4N.js} +2 -2
  39. package/dist/bundle/{chunk-3TPRYZUW.js → chunk-DHWBSXG3.js} +23 -23
  40. package/dist/bundle/{chunk-IPBZKUC3.js → chunk-DIQLXAAZ.js} +3 -3
  41. package/dist/bundle/{chunk-JZ4YOAHA.js → chunk-DK6ICIGL.js} +4558 -1670
  42. package/dist/bundle/{chunk-OSBHEM2A.js → chunk-DRBQDCDU.js} +10 -10
  43. package/dist/bundle/{chunk-G6IX2MD2.js → chunk-DSVZEXYJ.js} +1104 -948
  44. package/dist/bundle/{chunk-B6JMVB6R.js → chunk-EOSVN2ER.js} +1 -1
  45. package/dist/bundle/{chunk-MOTKS7XG.js → chunk-FSHCAWZS.js} +29354 -16490
  46. package/dist/bundle/{chunk-TKXLWFM2.js → chunk-GGS6D4W4.js} +3 -3
  47. package/dist/bundle/{chunk-4APZQYCH.js → chunk-GL3MYFMX.js} +4 -4
  48. package/dist/bundle/{chunk-LDRQ5NAP.js → chunk-GXF5HFFP.js} +3 -3
  49. package/dist/bundle/{chunk-5ZF6QVMC.js → chunk-HB6XJQ3Y.js} +4 -4
  50. package/dist/bundle/{chunk-QW5VPZEH.js → chunk-I4DFFR7F.js} +23 -1
  51. package/dist/bundle/{chunk-DHD25JII.js → chunk-IAV5BG3I.js} +1 -1
  52. package/dist/bundle/{chunk-52DCABMU.js → chunk-IED3NS7G.js} +30 -38
  53. package/dist/bundle/{chunk-LQX74VKG.js → chunk-INVTDIF6.js} +1 -1
  54. package/dist/bundle/{chunk-CKK6JOC4.js → chunk-KMV7GZB6.js} +2 -2
  55. package/dist/bundle/{chunk-XRZDYWF6.js → chunk-LE7MDAQG.js} +2 -2
  56. package/dist/bundle/{chunk-B5D7NZI7.js → chunk-M76MXMLY.js} +1 -1
  57. package/dist/bundle/{chunk-37B7A4RP.js → chunk-MEED7YFG.js} +1 -1
  58. package/dist/bundle/{chunk-LEA4BGK7.js → chunk-MRI6QMZ3.js} +11 -11
  59. package/dist/bundle/{chunk-6TICX3MN.js → chunk-MW4EGDDV.js} +2 -2
  60. package/dist/bundle/{chunk-SZ3Z4ZNO.js → chunk-N2FNMION.js} +1 -1
  61. package/dist/bundle/{chunk-CUZHKYC2.js → chunk-OHWMIUCT.js} +450 -641
  62. package/dist/bundle/{chunk-KNE6VFHZ.js → chunk-OORMSM6O.js} +1 -1
  63. package/dist/bundle/{chunk-Z6TTGTMU.js → chunk-OWEBWDHV.js} +76 -6
  64. package/dist/bundle/{chunk-5ZJXKASF.js → chunk-P3XC6EDU.js} +17 -21
  65. package/dist/bundle/chunk-Q2SUFGSH.js +136 -0
  66. package/dist/bundle/{chunk-TFFEFEG2.js → chunk-Q3XLZIY3.js} +18 -18
  67. package/dist/bundle/{chunk-IEC4E65G.js → chunk-Q5PI72CR.js} +5 -1
  68. package/dist/bundle/{chunk-V4MM6GST.js → chunk-QTHIU7CO.js} +1 -1
  69. package/dist/bundle/{chunk-JHFP3Z5S.js → chunk-QVSLSWAL.js} +8 -8
  70. package/dist/bundle/{chunk-QLGG7S6F.js → chunk-RN4EHCC5.js} +22 -4
  71. package/dist/bundle/{chunk-BL36NSV5.js → chunk-RQG5VOGH.js} +12 -2
  72. package/dist/bundle/{chunk-RPQ3JOD3.js → chunk-SELXER2Q.js} +5 -5
  73. package/dist/bundle/{chunk-KX5MZVPX.js → chunk-TM4JSVGQ.js} +60 -53
  74. package/dist/bundle/{chunk-TN77LX6W.js → chunk-UG447QY2.js} +1 -1
  75. package/dist/bundle/{chunk-HC56J5LB.js → chunk-ULDXZ6LH.js} +66 -59
  76. package/dist/bundle/chunk-USQ23X5V.js +1227 -0
  77. package/dist/bundle/{chunk-UEZ6URJR.js → chunk-VJXHIUFP.js} +19 -19
  78. package/dist/bundle/{chunk-TWIC6JJG.js → chunk-VRH7VRTK.js} +7 -7
  79. package/dist/bundle/{chunk-NRRI37NJ.js → chunk-WOIHSQAL.js} +44 -0
  80. package/dist/bundle/{chunk-L62EJDNZ.js → chunk-X277FBTF.js} +3 -3
  81. package/dist/bundle/{chunk-XITUFTON.js → chunk-X3ZDN3U7.js} +1 -1
  82. package/dist/bundle/{chunk-GXDOTUUO.js → chunk-X4GWR6GO.js} +9 -9
  83. package/dist/bundle/chunk-XI3VIQKW.js +756 -0
  84. package/dist/bundle/{chunk-FBLUKCIR.js → chunk-XRFHQGOD.js} +1 -1
  85. package/dist/bundle/{chunk-HW5QTRFF.js → chunk-YD2RYVMK.js} +36 -36
  86. package/dist/bundle/{chunk-XJBYGMZ4.js → chunk-YPO2U2YB.js} +669 -458
  87. package/dist/bundle/{chunk-C6TEYKXV.js → chunk-ZBFL5JPT.js} +8 -7
  88. package/dist/bundle/{chunk-7AUP2WT3.js → chunk-ZBKWRYRS.js} +2 -2
  89. package/dist/bundle/{chunk-HSI7YOYK.js → chunk-ZVI6TFQR.js} +100 -43
  90. package/dist/bundle/{cli-P3BZUE6S.js → cli-KHMEUXNG.js} +123 -68
  91. package/dist/bundle/command-contract-4K6XXZYE.js +41 -0
  92. package/dist/bundle/config-EEDB632I.js +90 -0
  93. package/dist/bundle/{decode-QWOQXM7M.js → decode-7RP4HSVE.js} +4 -4
  94. package/dist/bundle/{dispatch-5MGDLOK4.js → dispatch-IZCAK47P.js} +1 -1
  95. package/dist/bundle/{dist-OUE4MF37.js → dist-BFT2SUBV.js} +87 -51
  96. package/dist/bundle/{echarts-65IMPY43.js → echarts-T2BSQ2YV.js} +2 -2
  97. package/dist/bundle/{embed-4IULBCKL.js → embed-BAS6YPDT.js} +5 -5
  98. package/dist/bundle/{embedder-JW4W6IZI.js → embedder-5XD5FCAO.js} +8 -8
  99. package/dist/bundle/{failure-CR64C4XA.js → failure-R2OIHCE5.js} +1 -1
  100. package/dist/bundle/{first-run-CH6C674R.js → first-run-23WWZ2PW.js} +8 -8
  101. package/dist/bundle/first-screen-6HFUYVFR.js +39 -0
  102. package/dist/bundle/{folders-VU4IN35Y.js → folders-ZXTOFY4T.js} +3 -3
  103. package/dist/bundle/{instructions-G5QIH2TM.js → instructions-XZPROPKY.js} +1 -1
  104. package/dist/bundle/{main-O4ZJIEWP.js → main-TZXKGL3L.js} +18 -18
  105. package/dist/bundle/{meetings-77CCAVYD.js → meetings-JB2ISPND.js} +6 -4
  106. package/dist/bundle/{node-E6VQHU4Y.js → node-A3B3MJWX.js} +2 -2
  107. package/dist/bundle/{node-sqlite-RJZ4PGLD.js → node-sqlite-QVWDLGDX.js} +5 -5
  108. package/dist/bundle/{oauth-F4JKNRW4.js → oauth-YA6IYV4O.js} +6 -6
  109. package/dist/bundle/{open-NYOGMIAA.js → open-SY7TXJBS.js} +4 -4
  110. package/dist/bundle/{openai-5U6EQTFQ.js → openai-2AU24NRN.js} +10 -10
  111. package/dist/bundle/{output-file-6COFGPUL.js → output-file-YGQYZCBJ.js} +4 -4
  112. package/dist/bundle/{process-OBWUKBMX.js → process-6HNBTJIY.js} +1 -1
  113. package/dist/bundle/{program-MU7DEJTO.js → program-77BUCJ4H.js} +132 -100
  114. package/dist/bundle/{prompt-2QWQTHWT.js → prompt-YDG73YDS.js} +6 -4
  115. package/dist/bundle/{recognize-SNUNTUC3.js → recognize-ECXDGTB7.js} +3 -3
  116. package/dist/bundle/{remote-2CTCIQGF.js → remote-K4JHGBVJ.js} +6 -6
  117. package/dist/bundle/{rerank-XDA7NJNH.js → rerank-IU2YYD4T.js} +6 -6
  118. package/dist/bundle/{run-log-NSG3DJVX.js → run-log-LFEXNZ74.js} +54 -54
  119. package/dist/bundle/{serve-TWQFHOV2.js → serve-3XWIF3HI.js} +8 -8
  120. package/dist/bundle/{server-RIQ6HMH2.js → server-56VYOHWP.js} +42 -42
  121. package/dist/bundle/server-YSTMUZ22.js +72 -0
  122. package/dist/bundle/{services-NKZQJQIV.js → services-X7IPEGQ5.js} +118 -36
  123. package/dist/bundle/{speech-ZOB76SXA.js → speech-E2OBQWYA.js} +12 -12
  124. package/dist/bundle/{state-7YYEIXQ5.js → state-4GMJYK4H.js} +5 -5
  125. package/dist/bundle/{store-OX4HRBLO.js → store-KPI7GB5Y.js} +49 -22
  126. package/dist/bundle/{store-E6RTSSNR.js → store-LA4TV4DM.js} +39 -16
  127. package/dist/bundle/store-connection-AZTIF6IH.js +83 -0
  128. package/dist/bundle/store-maintenance-command-LR572PS4.js +61 -0
  129. package/dist/bundle/{streaming-O53PIORL.js → streaming-EJ3NM2C2.js} +5 -5
  130. package/dist/bundle/{tokens-QKNEP2GJ.js → tokens-BE6CJMR5.js} +5 -5
  131. package/dist/bundle/zm.js +3 -3
  132. package/dist/bundle/{zoom-app-TSI2MGVK.js → zoom-app-QEJBTIJ4.js} +6 -6
  133. package/dist/contract-overrides.d.ts.map +1 -1
  134. package/dist/contract-overrides.js +0 -6
  135. package/dist/contract-overrides.js.map +1 -1
  136. package/dist/first-screen.d.ts.map +1 -1
  137. package/dist/first-screen.js +1 -0
  138. package/dist/first-screen.js.map +1 -1
  139. package/dist/ingestion-search-commands.d.ts.map +1 -1
  140. package/dist/ingestion-search-commands.js +0 -10
  141. package/dist/ingestion-search-commands.js.map +1 -1
  142. package/dist/meeting-integration-commands.d.ts.map +1 -1
  143. package/dist/meeting-integration-commands.js +8 -6
  144. package/dist/meeting-integration-commands.js.map +1 -1
  145. package/dist/meeting-integration.d.ts +3 -1
  146. package/dist/meeting-integration.d.ts.map +1 -1
  147. package/dist/permissions.js +1 -1
  148. package/dist/permissions.js.map +1 -1
  149. package/dist/setup-commands.d.ts.map +1 -1
  150. package/dist/setup-commands.js +11 -0
  151. package/dist/setup-commands.js.map +1 -1
  152. package/dist/store-connection.d.ts.map +1 -1
  153. package/dist/store-connection.js +4 -3
  154. package/dist/store-connection.js.map +1 -1
  155. package/dist/tokens.d.ts +2 -0
  156. package/dist/tokens.d.ts.map +1 -1
  157. package/dist/tokens.js +11 -0
  158. package/dist/tokens.js.map +1 -1
  159. package/dist/unified-search.d.ts +4 -4
  160. package/dist/unified-search.d.ts.map +1 -1
  161. package/dist/unified-search.js +1 -24
  162. package/dist/unified-search.js.map +1 -1
  163. package/dist/version.d.ts +1 -1
  164. package/dist/version.js +1 -1
  165. package/package.json +3 -3
  166. package/skills/zoom-cli/SKILL.md +2 -2
  167. package/dist/bundle/answer-policy-VBDYLUXI.js +0 -104
  168. package/dist/bundle/chunk-2SYWVIQJ.js +0 -33
  169. package/dist/bundle/chunk-6AMMTXEA.js +0 -12473
  170. package/dist/bundle/chunk-F5DYBWH7.js +0 -299
  171. package/dist/bundle/chunk-T5X4LGXE.js +0 -380
  172. package/dist/bundle/command-contract-TOLB32NJ.js +0 -41
  173. package/dist/bundle/config-4KLLIADY.js +0 -90
  174. package/dist/bundle/first-screen-OCAW5ZN6.js +0 -39
  175. package/dist/bundle/server-XO6XQQTJ.js +0 -72
  176. package/dist/bundle/store-connection-55QPNUDS.js +0 -83
  177. package/dist/bundle/store-maintenance-command-Q5MSU6OK.js +0 -62
@@ -0,0 +1,1635 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CATALOG_KINDS,
5
+ CONTRACT_KINDS,
6
+ CONTRACT_STATUSES,
7
+ DEAL_KINDS,
8
+ DEAL_STATUSES,
9
+ INVOICE_DIRECTIONS,
10
+ MONEY_DIRECTIONS,
11
+ ORDER_DIRECTIONS,
12
+ ORDER_PURPOSES,
13
+ ORDER_STATUSES,
14
+ SUBSCRIPTION_STATUSES,
15
+ TRANSACTION_STATUSES,
16
+ WALLET_KINDS
17
+ } from "./chunk-XI3VIQKW.js";
18
+ import {
19
+ holdsCredential,
20
+ secretNamed
21
+ } from "./chunk-QTHIU7CO.js";
22
+ import {
23
+ CliError
24
+ } from "./chunk-FEM2JQN2.js";
25
+ import {
26
+ __name
27
+ } from "./chunk-ZVVMGPBJ.js";
28
+
29
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/record-fields.js
30
+ var DECIMAL_PATTERN = "^[0-9]{1,16}(\\.[0-9]{1,6})?$";
31
+ var SIGNED_DECIMAL = "^-?[0-9]{1,16}(\\.[0-9]{1,6})?$";
32
+ var DAY = "^[0-9]{4}-[0-9]{2}-[0-9]{2}$";
33
+ var INSTANT = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(:[0-9]{2}(\\.[0-9]{1,9})?)?(Z|[+-][0-9]{2}:[0-9]{2})$";
34
+ var text = /* @__PURE__ */ __name((description, maxLength = 2e3) => ({
35
+ type: "string",
36
+ minLength: 1,
37
+ maxLength,
38
+ ...description ? { description } : {}
39
+ }), "text");
40
+ var decimal = /* @__PURE__ */ __name((description) => ({ type: "string", pattern: DECIMAL_PATTERN, description }), "decimal");
41
+ var signedDecimal = /* @__PURE__ */ __name((description) => ({
42
+ type: "string",
43
+ pattern: SIGNED_DECIMAL,
44
+ description
45
+ }), "signedDecimal");
46
+ var day = /* @__PURE__ */ __name((description) => ({ type: "string", pattern: DAY, description }), "day");
47
+ var instant = /* @__PURE__ */ __name((description) => ({ type: "string", pattern: INSTANT, description }), "instant");
48
+ var enumOf = /* @__PURE__ */ __name((values, description) => ({
49
+ type: "string",
50
+ enum: values,
51
+ ...description ? { description } : {}
52
+ }), "enumOf");
53
+ var currency = { type: "string", pattern: "^[A-Za-z]{3}$", description: "ISO 4217 code" };
54
+ var nullable = /* @__PURE__ */ __name((schema) => {
55
+ if (schema.type === void 0)
56
+ return schema;
57
+ const types = typeof schema.type === "string" ? [schema.type] : [...schema.type];
58
+ return {
59
+ ...schema,
60
+ type: types.includes("null") ? types : [...types, "null"],
61
+ ...schema.enum ? { enum: [...schema.enum, null] } : {}
62
+ };
63
+ }, "nullable");
64
+ var objectOf = /* @__PURE__ */ __name((properties, { required, description } = {}) => ({
65
+ type: "object",
66
+ ...description ? { description } : {},
67
+ properties: Object.fromEntries(Object.entries(properties).map(([key, schema]) => [key, required?.includes(key) ? schema : nullable(schema)])),
68
+ ...required?.length ? { required } : {},
69
+ additionalProperties: true
70
+ }), "objectOf");
71
+ var arrayOf = /* @__PURE__ */ __name((item, maxItems, description) => ({
72
+ type: "array",
73
+ items: item,
74
+ maxItems,
75
+ description
76
+ }), "arrayOf");
77
+ var isObject = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isObject");
78
+ var typeOf = /* @__PURE__ */ __name((value) => {
79
+ if (Array.isArray(value))
80
+ return "array";
81
+ if (value === null)
82
+ return "null";
83
+ if (typeof value === "number")
84
+ return Number.isInteger(value) ? "integer" : "number";
85
+ if (typeof value === "string")
86
+ return "string";
87
+ if (typeof value === "boolean")
88
+ return "boolean";
89
+ return typeof value === "object" ? "object" : "other";
90
+ }, "typeOf");
91
+ var WHAT = {
92
+ string: "text",
93
+ integer: "a whole number",
94
+ boolean: "true or false",
95
+ array: "a list",
96
+ object: "an object",
97
+ null: "null"
98
+ };
99
+ var fieldError = /* @__PURE__ */ __name((schema, value, at = []) => {
100
+ const name = at.length ? `fields.${at.join(".")}` : "fields";
101
+ if (schema.type !== void 0) {
102
+ const allowed = typeof schema.type === "string" ? [schema.type] : schema.type;
103
+ if (!allowed.includes(typeOf(value)))
104
+ return { at, message: `${name} is ${allowed.map((one) => WHAT[one]).join(" or ")}` };
105
+ }
106
+ if (schema.enum && !schema.enum.includes(value))
107
+ return { at, message: `${name} is one of ${schema.enum.filter((one) => one !== null).join(", ")}` };
108
+ if (typeof value === "string") {
109
+ const length = [...value].length;
110
+ if (schema.minLength !== void 0 && length < schema.minLength)
111
+ return { at, message: `${name} takes at least ${schema.minLength} characters` };
112
+ if (schema.maxLength !== void 0 && length > schema.maxLength)
113
+ return { at, message: `${name} takes at most ${schema.maxLength} characters` };
114
+ if (schema.pattern !== void 0 && !new RegExp(schema.pattern, "u").test(value))
115
+ return { at, message: `${name} does not have the form ${schema.description ?? schema.pattern}` };
116
+ }
117
+ if (typeof value === "number") {
118
+ if (schema.minimum !== void 0 && value < schema.minimum)
119
+ return { at, message: `${name} is ${schema.minimum} or more` };
120
+ if (schema.maximum !== void 0 && value > schema.maximum)
121
+ return { at, message: `${name} is ${schema.maximum} or less` };
122
+ }
123
+ if (Array.isArray(value)) {
124
+ if (schema.maxItems !== void 0 && value.length > schema.maxItems)
125
+ return { at, message: `${name} holds at most ${schema.maxItems} items` };
126
+ if (schema.items)
127
+ for (const [index, item] of value.entries()) {
128
+ const found = fieldError(schema.items, item, [...at, index]);
129
+ if (found)
130
+ return found;
131
+ }
132
+ }
133
+ if (isObject(value)) {
134
+ for (const key of schema.required ?? [])
135
+ if (!Object.hasOwn(value, key))
136
+ return { at: [...at, key], message: `${name}.${key} is required` };
137
+ for (const [key, property] of Object.entries(schema.properties ?? {})) {
138
+ if (!Object.hasOwn(value, key))
139
+ continue;
140
+ const found = fieldError(property, value[key], [...at, key]);
141
+ if (found)
142
+ return found;
143
+ }
144
+ }
145
+ return void 0;
146
+ }, "fieldError");
147
+
148
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/record-types.js
149
+ var kept = /* @__PURE__ */ __name((description) => ({ description }), "kept");
150
+ var PARTY = ["person", "organization"];
151
+ var ORGANIZATION = ["organization"];
152
+ var lineItem = objectOf({
153
+ description: text("What the line is for; the product's name when left out", 2e3),
154
+ quantity: decimal("A decimal, 1 when left out"),
155
+ unit_price: decimal("A decimal in the parent's currency"),
156
+ amount: decimal("A decimal in the parent's currency: quantity \xD7 unit price"),
157
+ // Untyped: with options.lines text an invoice line's product is data, whatever v1 sent in it.
158
+ product: { description: "The product record's external id in this account, read with options.lines products" },
159
+ product_ref: { type: "string", pattern: "^product:[1-9][0-9]*$", description: "A product: ref of the store" }
160
+ });
161
+ var SMS_DIRECTIONS = ["in", "out"];
162
+ var CALL_DIRECTIONS = ["in", "out", "missed"];
163
+ var phoneFields = {
164
+ phone: text("The other side's number as the phone shows it: read to E.164 with the store's phone_countries", 64),
165
+ name: text("The other side's name as the phone shows it", 200)
166
+ };
167
+ var COUNTERPART = { counterpart: { targets: ["person"], linked: true } };
168
+ var linesIn = /* @__PURE__ */ __name((table, parent) => ({ table, parent, references: { product: "product" }, refs: { product_ref: "product" } }), "linesIn");
169
+ var dealFields = /* @__PURE__ */ __name((kind) => objectOf({
170
+ title: text(`The ${kind}'s title`, 200),
171
+ pipeline: text("The pipeline record's external id in this account", 512),
172
+ stage: text("The stage's external id in that pipeline", 512),
173
+ status: enumOf(DEAL_STATUSES, "Left out, the stage's outcome says it"),
174
+ amount: decimal("A decimal in currency"),
175
+ currency,
176
+ close_date: day("When it is expected to close"),
177
+ closed_date: day("When it was won or lost"),
178
+ closed_reason: text("Why it was won or lost", 2e3),
179
+ url: text("The source's page for it", 2e3)
180
+ }, { required: ["title", "pipeline", "stage"] }), "dealFields");
181
+ var RECORD_TYPES = {
182
+ invoice: {
183
+ table: "invoices",
184
+ review: "proposal",
185
+ update: "flag",
186
+ tombstone: true,
187
+ fields: objectOf({
188
+ direction: enumOf(INVOICE_DIRECTIONS),
189
+ number: text("The invoice's number", 80),
190
+ currency,
191
+ issue_date: day("The day it was issued"),
192
+ due_date: day("The day it is due"),
193
+ total: decimal("The printed total: refused when it is not the sum of the lines"),
194
+ lines: arrayOf(lineItem, 500, "The invoice's lines")
195
+ }),
196
+ roles: {
197
+ issuer: { targets: PARTY, v1: true, column: "issuer", pair: true },
198
+ counterparty: { targets: PARTY, v1: true, column: "counterparty", pair: true },
199
+ project: { targets: ["project"], v1: true, column: "project_id" },
200
+ contract: { targets: ["contract"], column: "contract_id" },
201
+ subscription: { targets: ["subscription"], column: "subscription_id" }
202
+ },
203
+ nested: { lines: linesIn("invoice_lines", "invoice_id") }
204
+ },
205
+ payment: {
206
+ table: "payments",
207
+ review: "proposal",
208
+ update: "re-settle",
209
+ tombstone: true,
210
+ fields: objectOf({
211
+ direction: enumOf(MONEY_DIRECTIONS),
212
+ amount: decimal("A decimal in currency"),
213
+ currency,
214
+ date: day("The day it was paid"),
215
+ reference: text("The payment's reference", 2e3)
216
+ }),
217
+ roles: {
218
+ payer: { targets: PARTY, v1: true, column: "payer", pair: true },
219
+ payee: { targets: PARTY, v1: true, column: "payee", pair: true },
220
+ project: { targets: ["project"], v1: true, column: "project_id" },
221
+ settles: { targets: ["invoice"], many: true, amount: true, v1: true },
222
+ refund_of: { targets: ["payment"], column: "refund_of" },
223
+ subscription: { targets: ["subscription"], column: "subscription_id" }
224
+ }
225
+ },
226
+ person: {
227
+ table: "persons",
228
+ review: "identity",
229
+ update: "in-place",
230
+ tombstone: false,
231
+ fields: objectOf({
232
+ name: kept("The person's name"),
233
+ email: kept("E-mail addresses, one or a list: an exact one links the record to the one person who has it"),
234
+ phone: kept("Phone numbers, one or a list: an exact one, read to E.164, links like an e-mail"),
235
+ position: kept("The job title, kept beside each member-of as its position: never the role")
236
+ }),
237
+ roles: { "member-of": { targets: ORGANIZATION, relationship: "member-of", kept: true } }
238
+ },
239
+ organization: {
240
+ table: "organizations",
241
+ review: "identity",
242
+ update: "in-place",
243
+ tombstone: true,
244
+ fields: objectOf({
245
+ name: kept("The organization's name"),
246
+ identifiers: kept("Strong identifiers, a list of {scheme, value}: scheme email, domain, tax-id:<cc> or registration:<cc>. One that another organization has links the record to it; any other item is kept as data")
247
+ }),
248
+ roles: {
249
+ "customer-of": { targets: ORGANIZATION, relationship: "customer-of", kept: true },
250
+ "partner-of": { targets: ORGANIZATION, relationship: "partner-of", kept: true }
251
+ }
252
+ },
253
+ project: {
254
+ table: "projects",
255
+ review: "identity",
256
+ update: "in-place",
257
+ tombstone: true,
258
+ fields: objectOf({
259
+ name: kept("The project's name"),
260
+ key: kept("The project's key: an existing project with it is this one"),
261
+ description: kept("What the project is")
262
+ }),
263
+ roles: { organization: { targets: ORGANIZATION, column: "organization_id" } }
264
+ },
265
+ order: {
266
+ table: "orders",
267
+ review: "proposal",
268
+ update: "re-propose",
269
+ tombstone: true,
270
+ fields: objectOf({
271
+ number: text("The order's number at the supplier", 80),
272
+ direction: enumOf(ORDER_DIRECTIONS, "purchase when left out; in a sale the owner is the supplier"),
273
+ purpose: enumOf(ORDER_PURPOSES, "business when left out"),
274
+ status: enumOf(ORDER_STATUSES, "placed when left out"),
275
+ supplier_name: text("The shop or supplier as the source names it", 200),
276
+ order_date: day("The day it was ordered"),
277
+ fulfilled_date: day("The day it was delivered"),
278
+ currency,
279
+ total: decimal("With lines, their sum"),
280
+ source_url: text("The order's page at the shop", 2e3),
281
+ lines: arrayOf(lineItem, 500, "The order's lines")
282
+ }),
283
+ roles: {
284
+ customer: { targets: PARTY, column: "customer", pair: true },
285
+ supplier: { targets: PARTY, column: "supplier", pair: true },
286
+ project: { targets: ["project"], column: "project_id" },
287
+ contract: { targets: ["contract"], column: "contract_id" },
288
+ deal: { targets: ["deal"], column: "deal_id" },
289
+ invoice: { targets: ["invoice"], column: "invoice_id" },
290
+ payment: { targets: ["payment"], column: "payment_id" }
291
+ },
292
+ nested: { lines: linesIn("order_lines", "order_id") }
293
+ },
294
+ product: {
295
+ table: "catalog_items",
296
+ review: "direct",
297
+ update: "in-place",
298
+ tombstone: true,
299
+ fields: objectOf({
300
+ kind: enumOf(CATALOG_KINDS, "product when left out"),
301
+ name: text("The product's name", 200),
302
+ sku: text("The supplier's code for it", 80),
303
+ unit: text("hour, pcs, month: free text", 40),
304
+ unit_price: decimal("A decimal in currency"),
305
+ currency,
306
+ description: text("What it is", 2e3),
307
+ archived_date: day("No longer sold from this day")
308
+ }, { required: ["name"] }),
309
+ roles: { supplier: { targets: PARTY, column: "supplier", pair: true } }
310
+ },
311
+ contract: {
312
+ table: "contracts",
313
+ review: "valued-proposal",
314
+ update: "re-propose",
315
+ tombstone: true,
316
+ fields: objectOf({
317
+ name: text("The contract's name", 200),
318
+ number: text("The contract's number", 80),
319
+ kind: enumOf(CONTRACT_KINDS),
320
+ status: enumOf(CONTRACT_STATUSES, "active when left out"),
321
+ signed_date: day("The day it was signed"),
322
+ effective_date: day("The day it starts"),
323
+ expiration_date: day("The day it ends; open-ended when left out"),
324
+ auto_renew: { type: "boolean", description: "Whether it renews itself" },
325
+ renewal: { type: "string", pattern: "^[1-9][0-9]{0,2}-(day|week|month|year)$", description: "1-year" },
326
+ notice_days: { type: "integer", minimum: 0, maximum: 3650, description: "Days of notice before it ends" },
327
+ terms: text("Renewal, cancellation and other terms, as text", 2e4),
328
+ value: decimal("A decimal in currency: the contract is then a proposal"),
329
+ currency
330
+ }, { required: ["name", "kind"] }),
331
+ roles: {
332
+ project: { targets: ["project"], column: "project_id" },
333
+ deal: { targets: ["deal"], column: "deal_id" },
334
+ party: { targets: PARTY, many: true, relationship: "related-to", kept: true },
335
+ document: { targets: ["document"], many: true, kept: true }
336
+ }
337
+ },
338
+ subscription: {
339
+ table: "subscriptions",
340
+ review: "proposal",
341
+ update: "re-propose",
342
+ tombstone: true,
343
+ fields: objectOf({
344
+ name: text("Its name; the product's when left out", 200),
345
+ direction: enumOf(INVOICE_DIRECTIONS, "receivable: the owner bills it; payable: the owner pays it"),
346
+ status: enumOf(SUBSCRIPTION_STATUSES),
347
+ interval: { type: "string", pattern: "^[1-9][0-9]{0,2}-(day|week|month|year)$", description: "1-month" },
348
+ start_date: day("The first day"),
349
+ trial_end_date: day("The trial's last day"),
350
+ next_renewal_date: day("The next renewal"),
351
+ cancelled_date: day("The day it was cancelled"),
352
+ end_date: day("The last day"),
353
+ prices: arrayOf(objectOf({
354
+ amount: decimal("A decimal in currency"),
355
+ currency,
356
+ effective_from: day("The day the price starts; the subscription's start when left out")
357
+ }, { required: ["amount", "currency"] }), 100, "Its prices, each from a day; a price is never overwritten")
358
+ }, { required: ["direction", "interval", "start_date"] }),
359
+ roles: {
360
+ supplier: { targets: PARTY, column: "supplier", pair: true },
361
+ customer: { targets: PARTY, column: "customer", pair: true },
362
+ product: { targets: ["product"], column: "catalog_item_id" },
363
+ contract: { targets: ["contract"], column: "contract_id" },
364
+ project: { targets: ["project"], column: "project_id" }
365
+ },
366
+ nested: { prices: { table: "subscription_prices", parent: "subscription_id" } }
367
+ },
368
+ wallet: {
369
+ table: "financial_accounts",
370
+ review: "direct",
371
+ update: "in-place",
372
+ tombstone: true,
373
+ fields: objectOf({
374
+ name: text("The account's name", 200),
375
+ kind: enumOf(WALLET_KINDS, "bank when left out"),
376
+ currency,
377
+ institution: text("The bank, as text", 200),
378
+ number_hint: text("The last 4 characters of its number; a whole IBAN or card number is refused", 4),
379
+ opening_balance: signedDecimal("Kept in the record only: the owner sets the wallet's opening balance"),
380
+ opening_date: day("The day of that balance")
381
+ }, { required: ["name", "currency"] }),
382
+ roles: { holder: { targets: PARTY, column: "holder", pair: true } }
383
+ },
384
+ transaction: {
385
+ table: "financial_transactions",
386
+ review: "proposal",
387
+ update: "re-propose",
388
+ tombstone: true,
389
+ fields: objectOf({
390
+ direction: enumOf(MONEY_DIRECTIONS),
391
+ amount: decimal("A decimal above 0 in the wallet's currency"),
392
+ currency,
393
+ status: enumOf(TRANSACTION_STATUSES, "booked when left out"),
394
+ date: day("The day the statement shows"),
395
+ booked_date: day("The day it was booked; the statement day when left out"),
396
+ description: text("As the statement says it", 2e3),
397
+ counterparty_name: text("As the statement names the other side", 200),
398
+ reference: text("The statement's reference", 200),
399
+ splits: arrayOf(objectOf({
400
+ amount: decimal("A decimal above 0"),
401
+ category: text("Free text, such as rent", 200),
402
+ note: text("A note", 2e3)
403
+ }, { required: ["amount", "category"] }), 100, "Categories of its amount; what they leave is uncategorized")
404
+ }, { required: ["direction", "amount", "date"] }),
405
+ roles: {
406
+ wallet: { targets: ["wallet"], required: true, column: "financial_account_id" },
407
+ counterparty: { targets: PARTY, column: "counterparty", pair: true },
408
+ payment: { targets: ["payment"], column: "payment_id" },
409
+ project: { targets: ["project"], column: "project_id" }
410
+ },
411
+ nested: { splits: { table: "transaction_splits", parent: "transaction_id" } }
412
+ },
413
+ deal: {
414
+ table: "deals",
415
+ review: "direct",
416
+ update: "in-place",
417
+ tombstone: true,
418
+ fields: dealFields("deal"),
419
+ references: { pipeline: "pipeline" },
420
+ roles: {
421
+ organization: { targets: ORGANIZATION, column: "organization_id" },
422
+ person: { targets: ["person"], many: true, relationship: "related-to", kept: true },
423
+ project: { targets: ["project"], column: "project_id" }
424
+ }
425
+ },
426
+ lead: {
427
+ table: "leads",
428
+ review: "direct",
429
+ update: "in-place",
430
+ tombstone: true,
431
+ fields: dealFields("lead"),
432
+ references: { pipeline: "pipeline" },
433
+ roles: {
434
+ organization: { targets: ORGANIZATION, column: "organization_id" },
435
+ person: { targets: ["person"], many: true, relationship: "related-to", kept: true },
436
+ project: { targets: ["project"], column: "project_id" },
437
+ deal: { targets: ["deal"], column: "deal_id" }
438
+ }
439
+ },
440
+ message: {
441
+ table: "messages",
442
+ review: "direct",
443
+ update: "in-place",
444
+ tombstone: true,
445
+ importOnly: true,
446
+ fields: objectOf({
447
+ kind: enumOf(["sms"], "sms: a text message of the phone"),
448
+ direction: enumOf(SMS_DIRECTIONS, "in: the other side wrote it; out: the owner did"),
449
+ ...phoneFields,
450
+ thread: text("The phone's thread id; the number when left out", 512),
451
+ body: { type: "string", maxLength: 2e4, description: "The text" },
452
+ sent_at: instant("When it was sent"),
453
+ read: { type: "boolean", description: "An incoming message the owner opened" }
454
+ }, { required: ["kind", "direction", "phone", "body", "sent_at"] }),
455
+ roles: COUNTERPART
456
+ },
457
+ event: {
458
+ table: "events",
459
+ review: "direct",
460
+ update: "in-place",
461
+ tombstone: true,
462
+ importOnly: true,
463
+ fields: objectOf({
464
+ kind: enumOf(["call"], "call: a phone call"),
465
+ direction: enumOf(CALL_DIRECTIONS, "in, out, or missed: a call the owner did not take"),
466
+ ...phoneFields,
467
+ started_at: instant("When it rang"),
468
+ duration: { type: "integer", minimum: 0, maximum: 604800, description: "Seconds talked; 0 when missed" }
469
+ }, { required: ["kind", "direction", "phone", "started_at"] }),
470
+ roles: COUNTERPART
471
+ },
472
+ pipeline: {
473
+ table: "pipelines",
474
+ review: "direct",
475
+ update: "in-place",
476
+ tombstone: false,
477
+ fields: objectOf({
478
+ kind: enumOf(DEAL_KINDS, "deal when left out"),
479
+ name: text("The pipeline's name", 80),
480
+ stages: arrayOf(objectOf({
481
+ external_id: text("The stage's id at the source", 512),
482
+ name: text("The stage's name", 80),
483
+ position: { type: "integer", minimum: 0, maximum: 1e3 },
484
+ outcome: enumOf(DEAL_STATUSES, "open when left out")
485
+ }, { required: ["external_id", "name"] }), 30, "The stages in order")
486
+ }, { required: ["name", "stages"] }),
487
+ roles: {},
488
+ nested: { stages: { table: "pipeline_stages", parent: "pipeline_id" } }
489
+ }
490
+ };
491
+ var isRecordType = /* @__PURE__ */ __name((type) => Object.hasOwn(RECORD_TYPES, type), "isRecordType");
492
+ var isBusinessType = /* @__PURE__ */ __name((type) => isRecordType(type) && RECORD_TYPES[type].review !== "identity", "isBusinessType");
493
+ var isIdentityType = /* @__PURE__ */ __name((type) => typeof type === "string" && isRecordType(type) && RECORD_TYPES[type].review === "identity", "isIdentityType");
494
+ var RECORD_ENTITY_TYPES = Object.keys(RECORD_TYPES);
495
+ var RECORD_TABLES = Object.fromEntries(Object.entries(RECORD_TYPES).map(([type, spec]) => [type, spec.table]));
496
+ var decidedOf = /* @__PURE__ */ __name((types) => Object.fromEntries(Object.entries(types).flatMap(([type, spec]) => spec.review === "proposal" || spec.review === "valued-proposal" ? [[type, spec.table]] : [])), "decidedOf");
497
+ var DECIDED_TABLES = {
498
+ ...decidedOf(RECORD_TYPES),
499
+ subscription_price: "subscription_prices"
500
+ };
501
+ var WORD_BODY = "[a-z0-9][a-z0-9_-]{0,62}";
502
+ var TYPE_PATTERN = `^(${RECORD_ENTITY_TYPES.join("|")}|custom:${WORD_BODY})$`;
503
+ var TYPE_RULE = `a type is one of ${RECORD_ENTITY_TYPES.join(", ")} or custom:<name>`;
504
+ var rolesOf = /* @__PURE__ */ __name((type) => Object.entries(RECORD_TYPES[type].roles), "rolesOf");
505
+ var roleOf = /* @__PURE__ */ __name((type, role) => {
506
+ if (!isRecordType(type))
507
+ return void 0;
508
+ const roles = RECORD_TYPES[type].roles;
509
+ return Object.hasOwn(roles, role) ? roles[role] : void 0;
510
+ }, "roleOf");
511
+ var nestedOf = /* @__PURE__ */ __name((type) => Object.entries(RECORD_TYPES[type].nested ?? {}), "nestedOf");
512
+ var referencesOf = /* @__PURE__ */ __name((type) => Object.entries(RECORD_TYPES[type].references ?? {}), "referencesOf");
513
+ var roleNames = /* @__PURE__ */ __name((types, keep) => [
514
+ ...new Set(types.flatMap((type) => rolesOf(type).flatMap(([name, role]) => keep(role) ? [name] : [])))
515
+ ], "roleNames");
516
+ var AMOUNT_ROLES = roleNames(RECORD_ENTITY_TYPES, (role) => role.amount);
517
+ var FIELD_REFERENCE_ROLES = roleNames(RECORD_ENTITY_TYPES, (role) => role.v1 && !role.many);
518
+ var hasV1Roles = /* @__PURE__ */ __name((type) => rolesOf(type).some(([, role]) => role.v1), "hasV1Roles");
519
+ var IDENTITY_TYPES = RECORD_ENTITY_TYPES.filter((type) => RECORD_TYPES[type].review === "identity");
520
+ var article = /* @__PURE__ */ __name((word) => /^[aeiou]/.test(word) ? "an" : "a", "article");
521
+
522
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/counters.js
523
+ var COUNTER_FIELDS = ["views", "reactions", "comments"];
524
+ var validCounter = /* @__PURE__ */ __name((value) => typeof value === "number" && Number.isFinite(value) && value >= 0, "validCounter");
525
+ var counterValue = /* @__PURE__ */ __name((message, field) => {
526
+ const value = field === "reactions" ? message.reactions?.total : message.providerMetadata?.[field];
527
+ return validCounter(value) ? value : null;
528
+ }, "counterValue");
529
+ var counterObservationTime = /* @__PURE__ */ __name((observation, now) => {
530
+ const at = Date.parse(observation.observedAt);
531
+ if (!validCounter(observation.value) || !Number.isSafeInteger(at) || at < 0 || at > now || !["remote_fetch", "remote_update"].includes(observation.source))
532
+ throw new CliError("validation_error", "counter observation needs a valid value, source and nonfuture observation time");
533
+ if (observation.reactions && (!validCounter(observation.reactions.total) || observation.reactions.total !== observation.value))
534
+ throw new CliError("validation_error", "reaction observation payload and total disagree");
535
+ return at;
536
+ }, "counterObservationTime");
537
+ var observedCounters = /* @__PURE__ */ __name((message, observedAt, fields, source = "remote_fetch") => {
538
+ const observations = {};
539
+ for (const field of fields) {
540
+ const value = counterValue(message, field);
541
+ if (value !== null)
542
+ observations[field] = {
543
+ value,
544
+ observedAt,
545
+ source,
546
+ ...field === "reactions" && message.reactions ? { reactions: message.reactions } : {}
547
+ };
548
+ }
549
+ return { ...message, counterObservations: observations };
550
+ }, "observedCounters");
551
+ var counterFreshness = /* @__PURE__ */ __name((states) => {
552
+ if (!states.length || states.every((one) => one.freshness === "unknown"))
553
+ return "unknown";
554
+ if (states.some((one) => one.freshness === "unknown"))
555
+ return "partial";
556
+ return states.some((one) => one.freshness === "stale") ? "stale" : "fresh";
557
+ }, "counterFreshness");
558
+
559
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/addresses.js
560
+ var EMAIL_ADDRESS = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
561
+ var isEmailAddress = /* @__PURE__ */ __name((value) => EMAIL_ADDRESS.test(value), "isEmailAddress");
562
+ var ROLE_ADDRESS_WORDS = {
563
+ noReply: ["noreply", "no-reply", "donotreply", "do-not-reply", "mailer-daemon", "bounce", "bounces"],
564
+ shared: [
565
+ "info",
566
+ "hello",
567
+ "hi",
568
+ "contact",
569
+ "contacts",
570
+ "support",
571
+ "help",
572
+ "helpdesk",
573
+ "service",
574
+ "sales",
575
+ "office",
576
+ "admin",
577
+ "team",
578
+ "billing",
579
+ "accounts",
580
+ "accounting",
581
+ "invoices",
582
+ "finance",
583
+ "hr",
584
+ "jobs",
585
+ "careers",
586
+ "press",
587
+ "media",
588
+ "marketing",
589
+ "partners",
590
+ "legal",
591
+ "privacy",
592
+ "security",
593
+ "abuse",
594
+ "postmaster",
595
+ "webmaster",
596
+ "mail",
597
+ "inbox",
598
+ "enquiries",
599
+ "inquiries",
600
+ "booking",
601
+ "reservations",
602
+ "orders",
603
+ "feedback",
604
+ "newsletter",
605
+ "notifications",
606
+ "alerts"
607
+ ]
608
+ };
609
+ var bare = /* @__PURE__ */ __name((word) => word.replace(/[.\-_]/gu, ""), "bare");
610
+ var NO_REPLY = new Set(ROLE_ADDRESS_WORDS.noReply.map(bare));
611
+ var ROLE = new Set([...ROLE_ADDRESS_WORDS.shared, ...ROLE_ADDRESS_WORDS.noReply].map(bare));
612
+ var localWord = /* @__PURE__ */ __name((address) => {
613
+ const local = address.trim().toLowerCase().split("@")[0] ?? "";
614
+ return bare(local.split("+")[0] ?? "");
615
+ }, "localWord");
616
+ var isRoleAddress = /* @__PURE__ */ __name((address) => ROLE.has(localWord(address)), "isRoleAddress");
617
+ var isNoReplyAddress = /* @__PURE__ */ __name((address) => NO_REPLY.has(localWord(address)), "isNoReplyAddress");
618
+
619
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/rankings-options.js
620
+ var MESSAGE_MEASURES = ["views", "reactions", "forwards", "comments", "replies", "thread-size"];
621
+ var AUTHOR_MEASURES = [
622
+ "messages",
623
+ "words",
624
+ "reactions",
625
+ "replies",
626
+ "answers",
627
+ "answer-time",
628
+ "threads",
629
+ "active-days"
630
+ ];
631
+ var CONTEXT = /* @__PURE__ */ new Set([
632
+ "replies",
633
+ "replies-from-others",
634
+ "replies-from-others-per-message",
635
+ "thread-size",
636
+ "threads",
637
+ "answers",
638
+ "answer-time"
639
+ ]);
640
+ var needsRankingContext = /* @__PURE__ */ __name((options) => options.components.some((name) => CONTEXT.has(name)), "needsRankingContext");
641
+ var presets = {
642
+ helpful: { answers: 0.5, "replies-from-others": 0.25, reactions: 0.25 },
643
+ active: { "active-days": 0.6, messages: 0.4 },
644
+ engaging: { "reactions-per-message": 0.5, "replies-from-others-per-message": 0.5 }
645
+ };
646
+ function invalid(message) {
647
+ throw new CliError("validation_error", message, { reason: "ranking.invalid" });
648
+ }
649
+ __name(invalid, "invalid");
650
+ var rankingOptions = /* @__PURE__ */ __name((target, input) => {
651
+ const measures = target === "messages" ? MESSAGE_MEASURES : AUTHOR_MEASURES;
652
+ const { measure, score, weights: given, minMessages } = input;
653
+ const messageKind = input.messageKind ?? "all";
654
+ if (!["all", "posts", "comments"].includes(messageKind))
655
+ invalid("message_kind takes all, posts or comments");
656
+ if (target === "messages" && minMessages !== void 0)
657
+ invalid("min_messages applies to stats contacts top");
658
+ if (minMessages !== void 0 && (!Number.isSafeInteger(minMessages) || minMessages < 1))
659
+ invalid("min_messages takes a positive integer");
660
+ if (measure !== void 0 && !measures.includes(measure))
661
+ invalid(`--measure takes ${measures.join(", ")}`);
662
+ if (measure !== void 0 && (score !== void 0 || given !== void 0))
663
+ invalid("--measure cannot be combined with --score or --weights");
664
+ if (score !== void 0 && !["helpful", "active", "engaging"].includes(score))
665
+ invalid("--score takes helpful, active or engaging");
666
+ if (target === "messages" && score !== void 0 && score !== "engaging")
667
+ invalid("helpful and active scores apply to authors only");
668
+ const scoring = score !== void 0 || given !== void 0;
669
+ const preset = score;
670
+ let weights = null;
671
+ if (scoring) {
672
+ let raw = given !== void 0 ? given : target === "messages" ? { reactions: 0.5, "replies-from-others": 0.5 } : presets[preset];
673
+ if (typeof raw === "string") {
674
+ try {
675
+ raw = JSON.parse(raw);
676
+ } catch {
677
+ invalid("--weights takes a JSON object of component weights");
678
+ }
679
+ }
680
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
681
+ invalid("--weights takes a JSON object of component weights");
682
+ const allowed = target === "messages" ? [...MESSAGE_MEASURES, "replies-from-others"] : [
683
+ ...AUTHOR_MEASURES.filter((name) => name !== "answer-time"),
684
+ "replies-from-others",
685
+ "reactions-per-message",
686
+ "replies-from-others-per-message"
687
+ ];
688
+ const entries = Object.entries(raw);
689
+ for (const [name, weight] of entries) {
690
+ if (!allowed.includes(name))
691
+ invalid(`unknown ${target} score component: ${name}`);
692
+ if (typeof weight !== "number" || !Number.isFinite(weight) || weight < 0)
693
+ invalid(`weight for ${name} must be a finite nonnegative number`);
694
+ }
695
+ if (!entries.some(([, weight]) => weight > 0))
696
+ invalid("--weights needs at least one positive weight");
697
+ weights = Object.fromEntries(entries);
698
+ }
699
+ const selected = measure ?? (target === "messages" ? "reactions" : "messages");
700
+ return {
701
+ target,
702
+ messageKind,
703
+ minMessages: minMessages ?? (target === "contacts" && score === "engaging" ? 5 : 1),
704
+ measure: scoring ? "score" : selected,
705
+ order: !scoring && selected === "answer-time" ? "ascending" : "descending",
706
+ weights,
707
+ preset: scoring ? preset ?? "custom" : null,
708
+ components: weights === null ? [selected] : Object.entries(weights).filter(([, weight]) => weight > 0).map(([name]) => name)
709
+ };
710
+ }, "rankingOptions");
711
+ var rankingScore = /* @__PURE__ */ __name((raw, maxima, weights) => {
712
+ const entries = Object.entries(weights).filter(([, weight]) => weight > 0);
713
+ const scale = Math.max(...entries.map(([, weight]) => weight));
714
+ const denominator = entries.reduce((sum2, [, weight]) => sum2 + weight / scale, 0);
715
+ if (!Number.isFinite(scale) || scale <= 0 || !Number.isFinite(denominator) || denominator <= 0)
716
+ return null;
717
+ const normalized = {};
718
+ const contributions = {};
719
+ let sum = 0;
720
+ for (const [name, weight] of entries) {
721
+ const value = raw[name];
722
+ const maximum = maxima[name];
723
+ if (value == null || !Number.isFinite(value) || value < 0 || maximum === void 0 || !Number.isFinite(maximum) || maximum < value)
724
+ return null;
725
+ const part = maximum === 0 ? 0 : value / maximum;
726
+ normalized[name] = part;
727
+ contributions[name] = 100 * part * (weight / scale) / denominator;
728
+ sum += contributions[name];
729
+ }
730
+ return { score: Math.min(100, sum), normalized, contributions };
731
+ }, "rankingScore");
732
+ var RANKING_TOKENIZER_VERSION = 1;
733
+ var withoutUrls = /* @__PURE__ */ __name((text2) => text2.replace(/\S+/gu, (token) => {
734
+ for (let offset = 0; ; ) {
735
+ const marker = token.indexOf("://", offset);
736
+ if (marker < 0)
737
+ break;
738
+ let start = marker;
739
+ while (start > 0 && /[a-z0-9+.-]/iu.test(token[start - 1]))
740
+ start--;
741
+ if (/^[a-z][a-z0-9+.-]*$/iu.test(token.slice(start, marker)) && (start === 0 || !/\w/u.test(token[start - 1])))
742
+ return token.slice(0, start);
743
+ offset = marker + 3;
744
+ }
745
+ const folded = token.toLowerCase();
746
+ for (let offset = 0; ; ) {
747
+ const start = folded.indexOf("www.", offset);
748
+ if (start < 0)
749
+ break;
750
+ if (start === 0 || !/\w/u.test(token[start - 1]))
751
+ return token.slice(0, start);
752
+ offset = start + 4;
753
+ }
754
+ return token;
755
+ }), "withoutUrls");
756
+ var rankingWords = /* @__PURE__ */ __name((text2) => withoutUrls(text2).match(/[\p{L}\p{N}]+/gu)?.length ?? 0, "rankingWords");
757
+ var rankingQuestion = /* @__PURE__ */ __name((text2) => withoutUrls(text2).includes("?"), "rankingQuestion");
758
+
759
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/records.js
760
+ import { createHash } from "node:crypto";
761
+
762
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/phone-plans.generated.js
763
+ var PHONE_PLANS = [
764
+ {
765
+ country: "us",
766
+ code: "1",
767
+ trunk: "1",
768
+ lengths: [10],
769
+ valid: "[2-9]\\d{9}|3\\d{6}",
770
+ mobile: null
771
+ },
772
+ {
773
+ country: "ca",
774
+ code: "1",
775
+ trunk: "1",
776
+ lengths: [7, 10],
777
+ valid: "[2-9]\\d{9}|3\\d{6}",
778
+ mobile: null
779
+ },
780
+ {
781
+ country: "gb",
782
+ code: "44",
783
+ trunk: "0|180020",
784
+ lengths: [7, 9, 10],
785
+ valid: "[1-357-9]\\d{9}|[18]\\d{8}|8\\d{6}",
786
+ mobile: "7(?:457[0-57-9]|700[01]|911[028])\\d{5}|7(?:[1-3]\\d\\d|4(?:[0-46-9]\\d|5[0-689])|5(?:0[0-8]|[13-9]\\d|2[0-35-9])|7(?:0[1-9]|[1-7]\\d|8[02-9]|9[0-689])|8(?:[014-9]\\d|[23][0-8])|9(?:[024-9]\\d|1[02-9]|3[0-689]))\\d{6}"
787
+ },
788
+ {
789
+ country: "ie",
790
+ code: "353",
791
+ trunk: "0",
792
+ lengths: [7, 8, 9, 10],
793
+ valid: "(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}",
794
+ mobile: "8(?:22|[35-9]\\d)\\d{6}"
795
+ },
796
+ {
797
+ country: "es",
798
+ code: "34",
799
+ trunk: "",
800
+ lengths: [9],
801
+ valid: "(?:400|[5-9]\\d\\d)\\d{6}",
802
+ mobile: "96906(?:09|10)\\d\\d|(?:590(?:10[0-2]|600)|97390\\d)\\d{3}|(?:6\\d|7[1-48])\\d{7}"
803
+ },
804
+ {
805
+ country: "pt",
806
+ code: "351",
807
+ trunk: "",
808
+ lengths: [9],
809
+ valid: "1693\\d{5}|(?:[26-9]\\d|30)\\d{7}",
810
+ mobile: "6(?:[06]92(?:30|9\\d)|[35]92(?:[049]\\d|3[034]))\\d{3}|(?:(?:16|6[0356])93|9(?:[1-36]\\d\\d|480))\\d{5}"
811
+ },
812
+ {
813
+ country: "fr",
814
+ code: "33",
815
+ trunk: "0",
816
+ lengths: [9],
817
+ valid: "[1-9]\\d{8}",
818
+ mobile: "(?:6(?:[0-24-8]\\d|3[0-8]|9[589])|7[3-9]\\d)\\d{6}"
819
+ },
820
+ {
821
+ country: "be",
822
+ code: "32",
823
+ trunk: "0",
824
+ lengths: [8, 9],
825
+ valid: "4\\d{8}|[1-9]\\d{7}",
826
+ mobile: "4[5-9]\\d{7}"
827
+ },
828
+ {
829
+ country: "nl",
830
+ code: "31",
831
+ trunk: "0",
832
+ lengths: [5, 6, 7, 8, 9, 10, 11],
833
+ valid: "(?:[124-7]\\d\\d|3(?:[02-9]\\d|1[0-8]))\\d{6}|8\\d{6,9}|9\\d{6,10}|1\\d{4,5}",
834
+ mobile: "(?:6[1-58]|970\\d)\\d{7}"
835
+ },
836
+ {
837
+ country: "lu",
838
+ code: "352",
839
+ trunk: "",
840
+ lengths: [4, 5, 6, 7, 8, 9, 10, 11],
841
+ valid: "35[013-9]\\d{4,8}|6\\d{8}|35\\d{2,4}|(?:[2457-9]\\d|3[0-46-9])\\d{2,9}",
842
+ mobile: "6(?:[26][18]|5[1568]|7[189]|81|9[128])\\d{6}"
843
+ },
844
+ {
845
+ country: "de",
846
+ code: "49",
847
+ trunk: "0",
848
+ lengths: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
849
+ valid: "[2579]\\d{5,14}|49(?:[34]0|69|8\\d)\\d\\d?|49(?:37|49|60|7[089]|9\\d)\\d{1,3}|49(?:2[024-9]|3[2-689]|7[1-7])\\d{1,8}|(?:1|[368]\\d|4[0-8])\\d{3,13}|49(?:[015]\\d|2[13]|31|[46][1-8])\\d{1,9}",
850
+ mobile: "1(?:6[023]|7\\d)\\d{7,8}|15(?:[0-25-9]\\d\\d|3(?:10|33))\\d{6}"
851
+ },
852
+ {
853
+ country: "at",
854
+ code: "43",
855
+ trunk: "0",
856
+ lengths: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
857
+ valid: "1\\d{3,12}|2\\d{6,12}|43(?:(?:0\\d|5[02-9])\\d{3,9}|2\\d{4,5}|[3467]\\d{4}|8\\d{4,6}|9\\d{4,7})|5\\d{4,12}|8\\d{7,12}|9\\d{8,12}|(?:[367]\\d|4[0-24-9])\\d{4,11}",
858
+ mobile: "6(?:485|(?:5[0-3579]|6[013-9]|[7-9]\\d)\\d)\\d{3,9}"
859
+ },
860
+ {
861
+ country: "ch",
862
+ code: "41",
863
+ trunk: "0",
864
+ lengths: [9, 12],
865
+ valid: "8\\d{11}|[2-9]\\d{8}",
866
+ mobile: "(?:6[89]|7[235-9])\\d{7}"
867
+ },
868
+ {
869
+ country: "li",
870
+ code: "423",
871
+ trunk: "0",
872
+ lengths: [7, 9],
873
+ valid: "[68]\\d{8}|(?:[2378]\\d|90)\\d{5}",
874
+ mobile: "(?:6(?:(?:4[5-9]|5\\d)\\d|6(?:[024-68]\\d|1[01]|3[7-9]|7[02]))\\d|7(?:[37-9]\\d|42|56))\\d{4}"
875
+ },
876
+ {
877
+ country: "it",
878
+ code: "39",
879
+ trunk: "",
880
+ lengths: [6, 7, 8, 9, 10, 11, 12],
881
+ valid: "0\\d{5,11}|1\\d{8,10}|3(?:[0-8]\\d{7,10}|9\\d{7,8})|(?:43|55|70)\\d{8}|8\\d{5}(?:\\d{2,4})?",
882
+ mobile: "3[2-9]\\d{7,8}|(?:31|43)\\d{8}"
883
+ },
884
+ {
885
+ country: "mt",
886
+ code: "356",
887
+ trunk: "",
888
+ lengths: [8],
889
+ valid: "3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}",
890
+ mobile: "(?:7(?:210|[79]\\d\\d)|9(?:[29]\\d\\d|69[67]|8(?:1[1-3]|89|97)))\\d{4}"
891
+ },
892
+ {
893
+ country: "si",
894
+ code: "386",
895
+ trunk: "0",
896
+ lengths: [5, 6, 7, 8],
897
+ valid: "[1-7]\\d{7}|8\\d{4,7}|90\\d{4,6}",
898
+ mobile: "65(?:[178]\\d|5[56]|6[01])\\d{4}|(?:[37][01]|4[013]|51|6[489])\\d{6}"
899
+ },
900
+ {
901
+ country: "hr",
902
+ code: "385",
903
+ trunk: "0",
904
+ lengths: [7, 8, 9],
905
+ valid: "[2-69]\\d{8}|80\\d{5,7}|[1-79]\\d{7}|6\\d{6}",
906
+ mobile: "9(?:(?:0[1-9]|[12589]\\d)\\d\\d|7(?:[0679]\\d\\d|5(?:[01]\\d|44|55|77|9[5-79])))\\d{4}|98\\d{6}"
907
+ },
908
+ {
909
+ country: "ba",
910
+ code: "387",
911
+ trunk: "0",
912
+ lengths: [8, 9],
913
+ valid: "6\\d{8}|(?:[35689]\\d|49|70)\\d{6}",
914
+ mobile: "6040\\d{5}|6(?:03|[1-356]|44|7\\d)\\d{6}"
915
+ },
916
+ {
917
+ country: "rs",
918
+ code: "381",
919
+ trunk: "0",
920
+ lengths: [6, 7, 8, 9, 10, 11, 12],
921
+ valid: "38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}",
922
+ mobile: "6(?:[0-689]|7\\d)\\d{6,7}"
923
+ },
924
+ {
925
+ country: "me",
926
+ code: "382",
927
+ trunk: "0",
928
+ lengths: [8, 9],
929
+ valid: "(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}",
930
+ mobile: "6(?:[07-9]\\d|3[024]|6[0-25])\\d{5}"
931
+ },
932
+ {
933
+ country: "mk",
934
+ code: "389",
935
+ trunk: "0",
936
+ lengths: [8],
937
+ valid: "[2-578]\\d{7}",
938
+ mobile: "7(?:3555|(?:474|9[019]7)7)\\d{3}|7(?:[0-25-8]\\d\\d|3(?:[1-478]\\d|6[01])|4(?:2\\d|60|7[01578])|9(?:[2-4]\\d|5[01]|7[015]))\\d{4}"
939
+ },
940
+ {
941
+ country: "al",
942
+ code: "355",
943
+ trunk: "0",
944
+ lengths: [6, 7, 8, 9],
945
+ valid: "(?:700\\d\\d|900)\\d{3}|8\\d{5,7}|(?:[2-5]|6\\d)\\d{7}",
946
+ mobile: "6(?:[78][2-9]|9\\d)\\d{6}"
947
+ },
948
+ {
949
+ country: "gr",
950
+ code: "30",
951
+ trunk: "",
952
+ lengths: [10, 11, 12],
953
+ valid: "5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}",
954
+ mobile: "68[57-9]\\d{7}|(?:69|94)\\d{8}"
955
+ },
956
+ {
957
+ country: "cy",
958
+ code: "357",
959
+ trunk: "",
960
+ lengths: [8],
961
+ valid: "(?:[279]\\d|[58]0)\\d{6}",
962
+ mobile: "9(?:10|[4-79]\\d)\\d{5}"
963
+ },
964
+ {
965
+ country: "bg",
966
+ code: "359",
967
+ trunk: "0",
968
+ lengths: [6, 7, 8, 9, 12],
969
+ valid: "00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}",
970
+ mobile: "(?:43[07-9]|99[69]\\d)\\d{5}|(?:8[7-9]|98)\\d{7}"
971
+ },
972
+ {
973
+ country: "ro",
974
+ code: "40",
975
+ trunk: "0",
976
+ lengths: [6, 9],
977
+ valid: "(?:[236-8]\\d|90)\\d{7}|[23]\\d{5}",
978
+ mobile: "(?:630|702)0\\d{5}|(?:6(?:00|2\\d)|7(?:0[013-9]|1[0-3]|[2-7]\\d|8[03-8]|9[0-39]))\\d{6}"
979
+ },
980
+ {
981
+ country: "md",
982
+ code: "373",
983
+ trunk: "0",
984
+ lengths: [8],
985
+ valid: "(?:[235-7]\\d|[89]0)\\d{6}",
986
+ mobile: "562\\d{5}|(?:6\\d|7[16-9])\\d{6}"
987
+ },
988
+ {
989
+ country: "hu",
990
+ code: "36",
991
+ trunk: "06",
992
+ lengths: [8, 9],
993
+ valid: "[235-7]\\d{8}|[1-9]\\d{7}",
994
+ mobile: "(?:[257]0|3[01])\\d{7}"
995
+ },
996
+ {
997
+ country: "sk",
998
+ code: "421",
999
+ trunk: "0",
1000
+ lengths: [6, 7, 9],
1001
+ valid: "[2-689]\\d{8}|[2-59]\\d{6}|[2-5]\\d{5}",
1002
+ mobile: "909[1-9]\\d{5}|9(?:0[1-8]|1[0-24-9]|4[03-57-9]|5\\d)\\d{6}"
1003
+ },
1004
+ {
1005
+ country: "cz",
1006
+ code: "420",
1007
+ trunk: "",
1008
+ lengths: [9, 10, 11, 12],
1009
+ valid: "(?:[2-578]\\d|60)\\d{7}|9\\d{8,11}",
1010
+ mobile: "7060\\d{5}|(?:60[1-8]|7(?:0[2-5]|19|[2379]\\d))\\d{6}"
1011
+ },
1012
+ {
1013
+ country: "pl",
1014
+ code: "48",
1015
+ trunk: "",
1016
+ lengths: [6, 7, 8, 9, 10],
1017
+ valid: "(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}",
1018
+ mobile: "21(?:1[013-5]|2\\d|3[1-9])\\d{5}|(?:45|5[0137]|6[069]|7[2389]|88)\\d{7}"
1019
+ },
1020
+ {
1021
+ country: "lt",
1022
+ code: "370",
1023
+ trunk: "[08]",
1024
+ lengths: [8],
1025
+ valid: "(?:[3469]\\d|52|[78]0)\\d{6}",
1026
+ mobile: "6\\d{7}"
1027
+ },
1028
+ {
1029
+ country: "lv",
1030
+ code: "371",
1031
+ trunk: "",
1032
+ lengths: [8],
1033
+ valid: "(?:[268]\\d|78|90)\\d{6}",
1034
+ mobile: "2333[0-8]\\d{3}|2(?:[0-24-9]\\d\\d|3(?:0[07]|[14-9]\\d|2[02-9]|3[0-24-9]))\\d{4}"
1035
+ },
1036
+ {
1037
+ country: "ee",
1038
+ code: "372",
1039
+ trunk: "",
1040
+ lengths: [7, 8, 10],
1041
+ valid: "8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}",
1042
+ mobile: "(?:5\\d{5}|8(?:1(?:0(?:0(?:00|[178]\\d)|[3-9]\\d\\d)|(?:1(?:0[2-6]|1\\d)|[2-79]\\d\\d)\\d)|2(?:0(?:0(?:00|4\\d)|[1-7]\\d\\d)|(?:(?:[124-69]\\d|3[5-9])\\d|7(?:[0-79]\\d|8[013-9])|8(?:[2-6]\\d|7[01]))\\d)|[349]\\d{4}))\\d\\d|5(?:(?:[02]\\d|5[0-478])\\d|1(?:[0-8]\\d|95)|6(?:4[0-4]|5[1-589]))\\d{3}"
1043
+ },
1044
+ {
1045
+ country: "fi",
1046
+ code: "358",
1047
+ trunk: "0",
1048
+ lengths: [5, 6, 7, 8, 9, 10, 11, 12],
1049
+ valid: "[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}",
1050
+ mobile: "4946\\d{2,6}|(?:4[0-8]|50)\\d{4,8}"
1051
+ },
1052
+ {
1053
+ country: "se",
1054
+ code: "46",
1055
+ trunk: "0",
1056
+ lengths: [6, 7, 8, 9, 10, 12],
1057
+ valid: "(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}",
1058
+ mobile: "7[023689]\\d{7}"
1059
+ },
1060
+ {
1061
+ country: "no",
1062
+ code: "47",
1063
+ trunk: "",
1064
+ lengths: [5, 8],
1065
+ valid: "(?:0|[2-9]\\d{3})\\d{4}",
1066
+ mobile: "45(?:[0-24-9]\\d|3[0-57-9])\\d{4}|(?:4[016-8]|9\\d)\\d{6}"
1067
+ },
1068
+ {
1069
+ country: "dk",
1070
+ code: "45",
1071
+ trunk: "",
1072
+ lengths: [8],
1073
+ valid: "[2-9]\\d{7}",
1074
+ mobile: "(?:2[6-8]|37|6[78]|96)\\d{6}|(?:2[0-59]|3[0-689]|[457]\\d|6[0-69]|8[126-9]|9[1-47-9])[1-9]\\d{5}"
1075
+ },
1076
+ {
1077
+ country: "is",
1078
+ code: "354",
1079
+ trunk: "",
1080
+ lengths: [7, 9],
1081
+ valid: "(?:38\\d|[4-9])\\d{6}",
1082
+ mobile: "(?:38[589]\\d\\d|6(?:1[1-8]|2[0-6]|3[026-9]|4[014679]|5[0159]|6[0-69]|70|8[06-8]|9\\d)|7(?:5[057]|[6-9]\\d)|8(?:2[0-59]|[3-69]\\d|8[238]))\\d{4}"
1083
+ },
1084
+ {
1085
+ country: "ua",
1086
+ code: "380",
1087
+ trunk: "0",
1088
+ lengths: [9, 10],
1089
+ valid: "[89]\\d{9}|[3-9]\\d{8}",
1090
+ mobile: "790\\d{6}|(?:39|50|6[36-8]|7[1-357]|9[1-9])\\d{7}"
1091
+ },
1092
+ {
1093
+ country: "by",
1094
+ code: "375",
1095
+ trunk: "0|80?",
1096
+ lengths: [6, 7, 8, 9, 10, 11],
1097
+ valid: "(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}",
1098
+ mobile: "(?:2(?:5[5-79]|9[1-9])|(?:33|44)\\d)\\d{6}"
1099
+ },
1100
+ {
1101
+ country: "ru",
1102
+ code: "7",
1103
+ trunk: "8",
1104
+ lengths: [10, 14],
1105
+ valid: "8\\d{13}|[347-9]\\d{9}",
1106
+ mobile: "9\\d{9}"
1107
+ },
1108
+ {
1109
+ country: "kz",
1110
+ code: "7",
1111
+ trunk: "8",
1112
+ lengths: [10, 14],
1113
+ valid: "8\\d{13}|[78]\\d{9}",
1114
+ mobile: "7(?:0[0-25-8]|47|6[0-4]|7[15-8]|85)\\d{7}"
1115
+ },
1116
+ {
1117
+ country: "ge",
1118
+ code: "995",
1119
+ trunk: "0",
1120
+ lengths: [9],
1121
+ valid: "(?:[3-57]\\d\\d|800)\\d{6}",
1122
+ mobile: "5(?:(?:(?:0555|1(?:[17]77|555))[5-9]|757(?:7[7-9]|8[01]))\\d|22252[0-4])\\d\\d|5(?:0(?:0(?:1[09]|70)|505)|1(?:0[01]0|1(?:07|33|51))|2(?:0[02]0|2[25]2)|3(?:0[03]0|3[35]3)|4(?:0[04]0|411)|5222|9000)[0-4]\\d{3}|(?:5(?:0(?:0(?:0\\d|1[12]|2[02]|3[0-6]|4[04]|5[05]|77|88|9[09])|(?:[14]\\d|77)\\d|22[02])|1(?:1(?:[03][01]|[124]\\d|5[02-6]|7[0-6])|4\\d\\d)|2(?:228|555)|3555|4(?:4(?:[02-9]\\d|14)|555)|5(?:[0157-9]\\d\\d|200|333|4(?:44|55))|6[89]\\d\\d|7(?:(?:[0147-9]\\d|22)\\d|5(?:00|[57]5))|8(?:0(?:[018]\\d|2[0-4])|5(?:55|8[89])|8(?:55|88))|9(?:090|[1-35-9]\\d\\d))|790\\d\\d)\\d{4}"
1123
+ },
1124
+ {
1125
+ country: "am",
1126
+ code: "374",
1127
+ trunk: "0",
1128
+ lengths: [8],
1129
+ valid: "(?:[1-489]\\d|55|60|77)\\d{6}",
1130
+ mobile: "(?:33|4[1349]|55|77|88|9[13-9])\\d{6}"
1131
+ },
1132
+ {
1133
+ country: "tr",
1134
+ code: "90",
1135
+ trunk: "0",
1136
+ lengths: [7, 10, 12, 13],
1137
+ valid: "4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}",
1138
+ mobile: "5(?:61(?:011|61\\d)|82[2-5]\\d\\d)\\d{4}|5(?:[03-5]\\d|1[06]|24|6[24]|7[245]|9[46])\\d{7}"
1139
+ }
1140
+ ];
1141
+
1142
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/phones.js
1143
+ var PHONE_COUNTRIES = PHONE_PLANS.map((plan) => plan.country);
1144
+ var DEFAULT_PHONE_COUNTRIES = ["ru"];
1145
+ var parsePhoneCountries = /* @__PURE__ */ __name((value) => {
1146
+ const countries = value.split(/[\s,]+/).map((one) => one.trim().toLowerCase()).filter(Boolean);
1147
+ const unknown = countries.filter((one) => !PHONE_COUNTRIES.includes(one));
1148
+ if (countries.length === 0 || unknown.length > 0)
1149
+ throw new CliError("validation_error", `phone_countries takes country codes, ${unknown.length > 0 ? `not ${unknown.join(", ")}` : "at least one"}: ` + PHONE_COUNTRIES.join(", "));
1150
+ return [...new Set(countries)];
1151
+ }, "parsePhoneCountries");
1152
+ var PLANS = new Map(PHONE_PLANS.map((plan) => [
1153
+ plan.country,
1154
+ {
1155
+ code: plan.code,
1156
+ trunk: plan.trunk ? new RegExp(`^(?:${plan.trunk})`) : null,
1157
+ lengths: new Set(plan.lengths),
1158
+ valid: new RegExp(`^(?:${plan.valid})$`),
1159
+ mobile: plan.mobile === null ? null : new RegExp(`^(?:${plan.mobile})$`)
1160
+ }
1161
+ ]));
1162
+ var nationalPhone = /* @__PURE__ */ __name((digits, countries, { anyType }) => {
1163
+ for (const country of countries) {
1164
+ const plan = PLANS.get(country);
1165
+ if (!plan)
1166
+ continue;
1167
+ const readings = [
1168
+ ...plan.trunk?.test(digits) ? [digits.replace(plan.trunk, "")] : [],
1169
+ digits,
1170
+ ...digits.startsWith(plan.code) ? [digits.slice(plan.code.length)] : []
1171
+ ];
1172
+ for (const national of readings) {
1173
+ if (!plan.lengths.has(national.length) || !plan.valid.test(national))
1174
+ continue;
1175
+ const mobile = plan.mobile?.test(national) ?? false;
1176
+ if (anyType || mobile)
1177
+ return { value: `+${plan.code}${national}`, national, mobile };
1178
+ }
1179
+ }
1180
+ return void 0;
1181
+ }, "nationalPhone");
1182
+ var typedPhone = /* @__PURE__ */ __name((typed, { phoneCountries = DEFAULT_PHONE_COUNTRIES } = {}) => {
1183
+ const text2 = typed.trim();
1184
+ if (!/^\+?[\d\s().\-–]+$/.test(text2))
1185
+ return void 0;
1186
+ const digits = text2.replace(/\(0\)/, "").replace(/\D/g, "").replace(/^00/, "");
1187
+ if (digits.length < 7 || digits.length > 15)
1188
+ return void 0;
1189
+ const national = nationalPhone(digits, phoneCountries, { anyType: true });
1190
+ const tail = national?.national ?? digits.replace(/^0+/, "");
1191
+ return {
1192
+ value: text2.startsWith("+") || /^00/.test(text2) ? `+${digits}` : national?.value ?? digits,
1193
+ national: tail.length >= 8 ? tail : null
1194
+ };
1195
+ }, "typedPhone");
1196
+ var e164Of = /* @__PURE__ */ __name((phone, region) => {
1197
+ if (/^\s*(\+|00)/.test(phone))
1198
+ return typedPhone(phone)?.value;
1199
+ if (typedPhone(phone) === void 0)
1200
+ return void 0;
1201
+ if (region === void 0)
1202
+ return null;
1203
+ const digits = phone.replace(/\(0\)/, "").replace(/\D/g, "");
1204
+ return nationalPhone(digits, [region], { anyType: true })?.value;
1205
+ }, "e164Of");
1206
+ var BARE_INTERNATIONAL_PROVIDERS = ["telegram", "max", "whatsapp"];
1207
+ var storedPhone = /* @__PURE__ */ __name((raw, provider) => {
1208
+ if (/^\s*(\+|00)/.test(raw))
1209
+ return typedPhone(raw)?.value;
1210
+ if (!BARE_INTERNATIONAL_PROVIDERS.includes(provider))
1211
+ return void 0;
1212
+ const found = /^([1-9]\d{6,14})$/.exec(raw.trim());
1213
+ return found ? `+${found[1]}` : void 0;
1214
+ }, "storedPhone");
1215
+
1216
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/records.js
1217
+ var RECORDS_SCHEMA_VERSION = 1;
1218
+ var RECORD_OPERATIONS = ["upsert", "delete"];
1219
+ var LINE_OPTIONS = ["text", "products"];
1220
+ var WORD = `^${WORD_BODY}$`;
1221
+ var MAX_ID = 512;
1222
+ var MAX_FIELDS_BYTES = 65536;
1223
+ var MAX_RELATIONS = 100;
1224
+ var DECIMAL = DECIMAL_PATTERN;
1225
+ var REF = "^[a-z]+:[^\\s]{1,500}$";
1226
+ var fieldsDef = /* @__PURE__ */ __name((type) => `fields-${type}`, "fieldsDef");
1227
+ var RECORDS_ENVELOPE_SCHEMA = {
1228
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1229
+ title: "WireCat records envelope, version 1",
1230
+ description: "Records one source sends to the store. JSONL is the same model: the first line holds schema_version, source and options, each further line one record.",
1231
+ type: "object",
1232
+ required: ["schema_version", "source", "records"],
1233
+ additionalProperties: false,
1234
+ properties: {
1235
+ schema_version: { const: RECORDS_SCHEMA_VERSION },
1236
+ source: { $ref: "#/$defs/source" },
1237
+ options: { $ref: "#/$defs/options" },
1238
+ records: { type: "array", items: { $ref: "#/$defs/record" } }
1239
+ },
1240
+ $defs: {
1241
+ source: {
1242
+ type: "object",
1243
+ required: ["provider", "account", "batch_id"],
1244
+ additionalProperties: false,
1245
+ properties: {
1246
+ provider: { type: "string", pattern: WORD, description: "The system the records come from" },
1247
+ account: { type: "string", minLength: 1, maxLength: MAX_ID, description: "The account in that system" },
1248
+ batch_id: { type: "string", minLength: 1, maxLength: MAX_ID, description: "This import, for the receipt" }
1249
+ }
1250
+ },
1251
+ options: {
1252
+ type: "object",
1253
+ additionalProperties: false,
1254
+ properties: {
1255
+ lines: {
1256
+ enum: [...LINE_OPTIONS],
1257
+ description: "products: an invoice line's product (an external id) names its product; text, the default, keeps it as data. Order lines always read it, and product_ref (a product: ref) is read on every line."
1258
+ },
1259
+ phone_region: {
1260
+ type: "string",
1261
+ pattern: "^[A-Za-z]{2}$",
1262
+ description: "The country a person's phone without + is read in. Without it such a number is an identifier only when exactly one country of the store's phone_countries setting reads it as valid"
1263
+ }
1264
+ }
1265
+ },
1266
+ record: {
1267
+ type: "object",
1268
+ required: ["key", "type", "external_id", "operation"],
1269
+ additionalProperties: false,
1270
+ properties: {
1271
+ key: { type: "string", minLength: 1, maxLength: MAX_ID },
1272
+ type: { type: "string", pattern: TYPE_PATTERN },
1273
+ external_id: { type: "string", minLength: 1, maxLength: MAX_ID },
1274
+ operation: { enum: [...RECORD_OPERATIONS] },
1275
+ fields: {
1276
+ type: "object",
1277
+ description: "What the source says, as data: never secrets, never instructions"
1278
+ },
1279
+ revision: { type: "integer", minimum: 0, maximum: Number.MAX_SAFE_INTEGER },
1280
+ relations: { type: "array", maxItems: MAX_RELATIONS, items: { $ref: "#/$defs/relation" } }
1281
+ },
1282
+ allOf: RECORD_ENTITY_TYPES.map((type) => ({
1283
+ if: { properties: { type: { const: type } }, required: ["type"] },
1284
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema's own if/then keyword, never awaited.
1285
+ then: { properties: { fields: { $ref: `#/$defs/${fieldsDef(type)}` } } }
1286
+ }))
1287
+ },
1288
+ relation: {
1289
+ type: "object",
1290
+ required: ["role"],
1291
+ additionalProperties: false,
1292
+ oneOf: [{ required: ["type", "external_id"] }, { required: ["ref"] }],
1293
+ properties: {
1294
+ role: { type: "string", pattern: WORD },
1295
+ type: { type: "string", pattern: TYPE_PATTERN },
1296
+ external_id: { type: "string", minLength: 1, maxLength: MAX_ID },
1297
+ ref: { type: "string", pattern: REF, description: "A store entity, such as organization:12" },
1298
+ as: {
1299
+ type: "string",
1300
+ pattern: WORD,
1301
+ description: "On a relationship role: the part the target plays, such as decision-maker"
1302
+ },
1303
+ amount: {
1304
+ type: "string",
1305
+ pattern: DECIMAL,
1306
+ description: "A settles relation's share of the payment, a decimal in its currency"
1307
+ }
1308
+ }
1309
+ },
1310
+ ...Object.fromEntries(RECORD_ENTITY_TYPES.map((type) => [fieldsDef(type), RECORD_TYPES[type].fields]))
1311
+ }
1312
+ };
1313
+ var wordPattern = new RegExp(WORD);
1314
+ var typePattern = new RegExp(TYPE_PATTERN);
1315
+ var decimalPattern = new RegExp(DECIMAL);
1316
+ var refPattern = new RegExp(REF);
1317
+ var escapePointer = /* @__PURE__ */ __name((segment) => String(segment).replaceAll("~", "~0").replaceAll("/", "~1"), "escapePointer");
1318
+ var pointerOf = /* @__PURE__ */ __name((...segments) => segments.map((s) => `/${escapePointer(s)}`).join(""), "pointerOf");
1319
+ var idText = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim() !== "" && value.length <= MAX_ID && !value.includes("\0"), "idText");
1320
+ var extraKeys = /* @__PURE__ */ __name((value, allowed) => Object.keys(value).filter((key) => !allowed.includes(key)), "extraKeys");
1321
+ var secretIn = /* @__PURE__ */ __name((value, at) => {
1322
+ if (typeof value === "string")
1323
+ return holdsCredential(value) ? at : void 0;
1324
+ if (Array.isArray(value)) {
1325
+ for (const [index, item] of value.entries()) {
1326
+ const found = secretIn(item, [...at, index]);
1327
+ if (found)
1328
+ return found;
1329
+ }
1330
+ return void 0;
1331
+ }
1332
+ if (!isObject(value))
1333
+ return void 0;
1334
+ for (const [key, item] of Object.entries(value)) {
1335
+ if (secretNamed(key))
1336
+ return [...at, key];
1337
+ const found = secretIn(item, [...at, key]);
1338
+ if (found)
1339
+ return found;
1340
+ }
1341
+ return void 0;
1342
+ }, "secretIn");
1343
+ var targetTypeOf = /* @__PURE__ */ __name((relation) => relation.ref === void 0 ? String(relation.type) : relation.ref.slice(0, relation.ref.indexOf(":")), "targetTypeOf");
1344
+ var relationErrors = /* @__PURE__ */ __name((relations, at) => {
1345
+ if (relations === void 0)
1346
+ return [];
1347
+ if (!Array.isArray(relations) || relations.length > MAX_RELATIONS)
1348
+ return [invalid2(at, `relations is a list of at most ${MAX_RELATIONS}`)];
1349
+ return relations.flatMap((relation, index) => {
1350
+ const here = [...at, index];
1351
+ if (!isObject(relation))
1352
+ return [invalid2(here, "a relation is an object")];
1353
+ const extra = extraKeys(relation, ["role", "type", "external_id", "ref", "as", "amount"]);
1354
+ if (extra.length > 0)
1355
+ return [invalid2([...here, extra[0]], "a relation holds role, type, external_id, ref, as and amount")];
1356
+ if (typeof relation.role !== "string" || !wordPattern.test(relation.role))
1357
+ return [invalid2([...here, "role"], "a role is lowercase letters, digits, - and _")];
1358
+ if (relation.ref !== void 0) {
1359
+ if (relation.type !== void 0 || relation.external_id !== void 0)
1360
+ return [invalid2([...here, "ref"], "a relation names its target by ref, or by type and external_id")];
1361
+ if (typeof relation.ref !== "string" || !refPattern.test(relation.ref))
1362
+ return [invalid2([...here, "ref"], "a ref is a store reference, such as organization:12")];
1363
+ } else {
1364
+ if (typeof relation.type !== "string" || !typePattern.test(relation.type))
1365
+ return [invalid2([...here, "type"], TYPE_RULE)];
1366
+ if (!idText(relation.external_id))
1367
+ return [invalid2([...here, "external_id"], `an external id takes 1\u2013${MAX_ID} characters`)];
1368
+ }
1369
+ if (relation.as !== void 0 && (typeof relation.as !== "string" || !wordPattern.test(relation.as)))
1370
+ return [invalid2([...here, "as"], "as is lowercase letters, digits, - and _")];
1371
+ if (relation.amount !== void 0 && (typeof relation.amount !== "string" || !decimalPattern.test(relation.amount)))
1372
+ return [invalid2([...here, "amount"], 'an amount is a decimal string, such as "13000.00"')];
1373
+ if (relation.amount !== void 0 && !AMOUNT_ROLES.includes(relation.role))
1374
+ return [invalid2([...here, "amount"], `only a ${AMOUNT_ROLES.join(" or ")} relation carries an amount`)];
1375
+ return [];
1376
+ });
1377
+ }, "relationErrors");
1378
+ var typeErrors = /* @__PURE__ */ __name((record, at) => {
1379
+ if (record.operation !== "upsert" || !isRecordType(record.type))
1380
+ return [];
1381
+ const { type } = record;
1382
+ const wrong = fieldError(RECORD_TYPES[type].fields, record.fields);
1383
+ if (wrong)
1384
+ return [invalid2([...at, "fields", ...wrong.at], wrong.message)];
1385
+ const relations = record.relations ?? [];
1386
+ for (const [index, relation] of relations.entries()) {
1387
+ const here = [...at, "relations", index];
1388
+ const role = roleOf(type, relation.role);
1389
+ if (relation.as !== void 0 && !role?.relationship)
1390
+ return [
1391
+ invalid2([...here, "as"], `${article(type)} ${type}'s ${relation.role} is not a relationship: it takes no as`)
1392
+ ];
1393
+ if (role === void 0 || role.v1)
1394
+ continue;
1395
+ const target = targetTypeOf(relation);
1396
+ if (!role.targets.includes(target))
1397
+ return [
1398
+ invalid2(here, `${article(type)} ${type}'s ${relation.role} is ${role.targets.map((one) => `${article(one)} ${one}`).join(" or ")}`)
1399
+ ];
1400
+ if (!role.many && relations.some((other, before) => before < index && other.role === relation.role))
1401
+ return [invalid2(here, `${article(type)} ${type} has one ${relation.role}`, "record.relation-ambiguous")];
1402
+ }
1403
+ for (const [name, role] of rolesOf(type))
1404
+ if (role.required && !relations.some((relation) => relation.role === name))
1405
+ return [invalid2([...at, "relations"], `${article(type)} ${type} names its ${name} in relations`)];
1406
+ return [];
1407
+ }, "typeErrors");
1408
+ var invalid2 = /* @__PURE__ */ __name((at, message, code = "record.invalid") => ({
1409
+ pointer: pointerOf(...at),
1410
+ code,
1411
+ message
1412
+ }), "invalid");
1413
+ var recordErrors = /* @__PURE__ */ __name((record, index) => {
1414
+ const at = ["records", index];
1415
+ if (!isObject(record))
1416
+ return [invalid2(at, "a record is an object")];
1417
+ const key = typeof record.key === "string" ? record.key : void 0;
1418
+ const withKey = /* @__PURE__ */ __name((errors) => errors.map((error) => key === void 0 ? error : { ...error, key }), "withKey");
1419
+ const extra = extraKeys(record, ["key", "type", "external_id", "operation", "fields", "revision", "relations"]);
1420
+ if (extra.length > 0)
1421
+ return withKey([invalid2([...at, extra[0]], `a record has no ${extra[0]}`)]);
1422
+ if (!idText(record.key))
1423
+ return [invalid2([...at, "key"], `a key takes 1\u2013${MAX_ID} characters`)];
1424
+ if (typeof record.type !== "string" || !typePattern.test(record.type))
1425
+ return withKey([invalid2([...at, "type"], TYPE_RULE, "record.type")]);
1426
+ if (!idText(record.external_id))
1427
+ return withKey([invalid2([...at, "external_id"], `an external id takes 1\u2013${MAX_ID} characters`)]);
1428
+ if (!RECORD_OPERATIONS.includes(record.operation))
1429
+ return withKey([invalid2([...at, "operation"], "an operation is upsert or delete")]);
1430
+ if (record.revision !== void 0 && (typeof record.revision !== "number" || !Number.isSafeInteger(record.revision) || record.revision < 0))
1431
+ return withKey([invalid2([...at, "revision"], "a revision is a whole number, 0 or more")]);
1432
+ if (record.operation === "upsert" && !isObject(record.fields))
1433
+ return withKey([invalid2([...at, "fields"], "an upsert carries its fields as an object")]);
1434
+ if (record.fields !== void 0 && !isObject(record.fields))
1435
+ return withKey([invalid2([...at, "fields"], "fields is an object")]);
1436
+ if (record.fields !== void 0 && Buffer.byteLength(JSON.stringify(record.fields)) > MAX_FIELDS_BYTES)
1437
+ return withKey([invalid2([...at, "fields"], `fields take at most ${MAX_FIELDS_BYTES} bytes`, "record.too-large")]);
1438
+ const secret = record.fields === void 0 ? void 0 : secretIn(record.fields, [...at, "fields"]);
1439
+ if (secret)
1440
+ return withKey([
1441
+ invalid2(secret, "a secret never goes into the store: drop this field at the source", "record.secret-field")
1442
+ ]);
1443
+ const relations = relationErrors(record.relations, [...at, "relations"]);
1444
+ return withKey(relations.length > 0 ? relations : typeErrors(record, at));
1445
+ }, "recordErrors");
1446
+ var envelopeErrors = /* @__PURE__ */ __name((envelope, account) => {
1447
+ const header = headerErrors(envelope, account, ["records"]);
1448
+ if (header.length > 0)
1449
+ return header;
1450
+ if (!Array.isArray(envelope.records))
1451
+ return [invalid2(["records"], "records is a list", "envelope.invalid")];
1452
+ return [];
1453
+ }, "envelopeErrors");
1454
+ var headerErrors = /* @__PURE__ */ __name((envelope, account, more = []) => {
1455
+ if (!isObject(envelope))
1456
+ return [invalid2([], "an envelope is an object", "envelope.invalid")];
1457
+ const extra = extraKeys(envelope, ["schema_version", "source", "options", ...more]);
1458
+ if (extra.length > 0)
1459
+ return [invalid2([extra[0]], `an envelope has no ${extra[0]}`, "envelope.invalid")];
1460
+ if (envelope.schema_version !== RECORDS_SCHEMA_VERSION)
1461
+ return [
1462
+ invalid2(["schema_version"], `this build reads schema_version ${RECORDS_SCHEMA_VERSION}, not ${JSON.stringify(envelope.schema_version)}`, "envelope.schema-version")
1463
+ ];
1464
+ const { source } = envelope;
1465
+ if (!isObject(source))
1466
+ return [invalid2(["source"], "source is an object", "envelope.invalid")];
1467
+ const sourceExtra = extraKeys(source, ["provider", "account", "batch_id"]);
1468
+ if (sourceExtra.length > 0)
1469
+ return [
1470
+ invalid2(["source", sourceExtra[0]], "source holds provider, account and batch_id", "envelope.invalid")
1471
+ ];
1472
+ if (typeof source.provider !== "string" || !wordPattern.test(source.provider))
1473
+ return [invalid2(["source", "provider"], "a provider is lowercase letters, digits, - and _", "envelope.invalid")];
1474
+ if (!idText(source.account))
1475
+ return [invalid2(["source", "account"], `an account takes 1\u2013${MAX_ID} characters`, "envelope.invalid")];
1476
+ if (!idText(source.batch_id))
1477
+ return [invalid2(["source", "batch_id"], `a batch id takes 1\u2013${MAX_ID} characters`, "envelope.invalid")];
1478
+ if (source.account !== account)
1479
+ return [
1480
+ invalid2(["source", "account"], `the envelope is for account ${JSON.stringify(source.account)}, the import for ${JSON.stringify(account)}`, "envelope.account-mismatch")
1481
+ ];
1482
+ const { options } = envelope;
1483
+ if (options !== void 0) {
1484
+ if (!isObject(options))
1485
+ return [invalid2(["options"], "options is an object", "envelope.invalid")];
1486
+ const unknown = extraKeys(options, ["lines", "phone_region"]);
1487
+ if (unknown.length > 0)
1488
+ return [invalid2(["options", unknown[0]], "options holds lines and phone_region", "envelope.invalid")];
1489
+ if (options.phone_region !== void 0 && (typeof options.phone_region !== "string" || !PHONE_COUNTRIES.includes(options.phone_region.toLowerCase())))
1490
+ return [
1491
+ invalid2(["options", "phone_region"], `options.phone_region is one of ${PHONE_COUNTRIES.join(", ")}`, "envelope.invalid")
1492
+ ];
1493
+ if (options.lines !== void 0 && !LINE_OPTIONS.includes(options.lines))
1494
+ return [invalid2(["options", "lines"], `options.lines is ${LINE_OPTIONS.join(" or ")}`, "envelope.invalid")];
1495
+ }
1496
+ return [];
1497
+ }, "headerErrors");
1498
+ var canonical = /* @__PURE__ */ __name((value) => {
1499
+ if (Array.isArray(value))
1500
+ return value.map(canonical);
1501
+ if (!isObject(value))
1502
+ return value;
1503
+ return Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])]));
1504
+ }, "canonical");
1505
+ var recordFingerprint = /* @__PURE__ */ __name((fields, relations) => createHash("sha256").update(JSON.stringify(canonical({
1506
+ fields,
1507
+ relations: relations.map((relation) => [
1508
+ relation.role,
1509
+ ...relation.ref === void 0 ? [relation.type, relation.external_id] : [`ref=${relation.ref}`],
1510
+ ...relation.amount === void 0 ? [] : [relation.amount],
1511
+ ...relation.as === void 0 ? [] : [`as=${relation.as}`]
1512
+ ]).sort((a, b) => a.join("\0").localeCompare(b.join("\0")))
1513
+ }))).digest("hex"), "recordFingerprint");
1514
+ var BOM = "\uFEFF";
1515
+ var withoutBom = /* @__PURE__ */ __name((text2) => text2.startsWith(BOM) ? text2.slice(1) : text2, "withoutBom");
1516
+ var jsonLine = /* @__PURE__ */ __name((line) => {
1517
+ try {
1518
+ return JSON.parse(withoutBom(line));
1519
+ } catch {
1520
+ return line;
1521
+ }
1522
+ }, "jsonLine");
1523
+ var envelopeOfJsonl = /* @__PURE__ */ __name((text2) => {
1524
+ const lines = withoutBom(text2).split(/\r?\n/);
1525
+ const first = lines.findIndex((line) => line.trim() !== "");
1526
+ if (first < 0)
1527
+ return {};
1528
+ const header = jsonLine(lines[first]);
1529
+ const records = [];
1530
+ for (let at = first + 1; at < lines.length; at++) {
1531
+ const line = lines[at];
1532
+ if (line.trim() !== "")
1533
+ records.push(jsonLine(line));
1534
+ }
1535
+ return isObject(header) ? { ...header, records } : header;
1536
+ }, "envelopeOfJsonl");
1537
+ var envelopeOfText = /* @__PURE__ */ __name((text2) => {
1538
+ const clean = withoutBom(text2);
1539
+ const first = clean.split(/\r?\n/).find((line) => line.trim() !== "");
1540
+ const head = first === void 0 ? void 0 : jsonLine(first);
1541
+ if (isObject(head) && !Object.hasOwn(head, "records"))
1542
+ return envelopeOfJsonl(clean);
1543
+ return jsonLine(clean);
1544
+ }, "envelopeOfText");
1545
+ var fieldReferences = /* @__PURE__ */ __name((record, options = {}) => {
1546
+ if (record.operation !== "upsert" || !isRecordType(record.type))
1547
+ return [];
1548
+ const fields = record.fields ?? {};
1549
+ const found = [];
1550
+ for (const [key, type] of referencesOf(record.type))
1551
+ if (typeof fields[key] === "string")
1552
+ found.push({ role: `fields.${key}`, type, external_id: fields[key] });
1553
+ if (record.type === "invoice" && options.lines !== "products")
1554
+ return found;
1555
+ for (const [list, spec] of nestedOf(record.type)) {
1556
+ const items = fields[list];
1557
+ if (!Array.isArray(items))
1558
+ continue;
1559
+ for (const item of items)
1560
+ for (const [key, type] of Object.entries(spec.references ?? {}))
1561
+ if (isObject(item) && typeof item[key] === "string")
1562
+ found.push({ role: `fields.${list}.${key}`, type, external_id: item[key] });
1563
+ }
1564
+ return found;
1565
+ }, "fieldReferences");
1566
+
1567
+ // node_modules/.pnpm/@wirecat+cli-core@0.620.0_@wirecat+cli-base@0.80.8_commander@15.0.0_esbuild@0.28.2_type_737712cd0065e7e21fd5896a79d0773d/node_modules/@wirecat/cli-core/dist/domain/crm.js
1568
+ var CRM_KINDS = ["organization", "person", "deal", "lead"];
1569
+ var isCrmUserId = /* @__PURE__ */ __name((id) => /^\d{1,20}$/.test(id), "isCrmUserId");
1570
+ var normalCrmUserId = /* @__PURE__ */ __name((id) => {
1571
+ const text2 = id.trim();
1572
+ return /^\d+$/.test(text2) ? text2.replace(/^0+(?=\d)/, "") : text2;
1573
+ }, "normalCrmUserId");
1574
+ var isItemKind = /* @__PURE__ */ __name((kind) => kind === "deal" || kind === "lead", "isItemKind");
1575
+
1576
+ export {
1577
+ isObject,
1578
+ RECORD_TYPES,
1579
+ isRecordType,
1580
+ isBusinessType,
1581
+ isIdentityType,
1582
+ RECORD_ENTITY_TYPES,
1583
+ RECORD_TABLES,
1584
+ DECIDED_TABLES,
1585
+ WORD_BODY,
1586
+ rolesOf,
1587
+ roleOf,
1588
+ nestedOf,
1589
+ AMOUNT_ROLES,
1590
+ FIELD_REFERENCE_ROLES,
1591
+ hasV1Roles,
1592
+ IDENTITY_TYPES,
1593
+ article,
1594
+ DEFAULT_PHONE_COUNTRIES,
1595
+ parsePhoneCountries,
1596
+ nationalPhone,
1597
+ typedPhone,
1598
+ e164Of,
1599
+ BARE_INTERNATIONAL_PROVIDERS,
1600
+ storedPhone,
1601
+ COUNTER_FIELDS,
1602
+ validCounter,
1603
+ counterValue,
1604
+ counterObservationTime,
1605
+ observedCounters,
1606
+ counterFreshness,
1607
+ isEmailAddress,
1608
+ ROLE_ADDRESS_WORDS,
1609
+ isRoleAddress,
1610
+ isNoReplyAddress,
1611
+ MESSAGE_MEASURES,
1612
+ AUTHOR_MEASURES,
1613
+ needsRankingContext,
1614
+ rankingOptions,
1615
+ rankingScore,
1616
+ RANKING_TOKENIZER_VERSION,
1617
+ rankingWords,
1618
+ rankingQuestion,
1619
+ RECORDS_SCHEMA_VERSION,
1620
+ RECORD_OPERATIONS,
1621
+ RECORDS_ENVELOPE_SCHEMA,
1622
+ pointerOf,
1623
+ recordErrors,
1624
+ envelopeErrors,
1625
+ headerErrors,
1626
+ recordFingerprint,
1627
+ jsonLine,
1628
+ envelopeOfJsonl,
1629
+ envelopeOfText,
1630
+ fieldReferences,
1631
+ CRM_KINDS,
1632
+ isCrmUserId,
1633
+ normalCrmUserId,
1634
+ isItemKind
1635
+ };