@superpanel-sdk/runtime 0.2.3 → 0.7.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 (319) hide show
  1. package/README.md +30 -10
  2. package/dist/builder/codegen/emit.d.ts +25 -12
  3. package/dist/builder/codegen/emit.js +339 -78
  4. package/dist/builder/codegen/generate.d.ts +21 -2
  5. package/dist/builder/codegen/generate.js +147 -34
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +29 -0
  9. package/dist/builder/company-imports.js +122 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +61 -8
  11. package/dist/builder/compile/compile-sequence.js +334 -80
  12. package/dist/builder/compile/function-code.d.ts +19 -3
  13. package/dist/builder/compile/function-code.js +123 -45
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +30 -27
  16. package/dist/builder/errors.d.ts +9 -0
  17. package/dist/builder/errors.js +17 -0
  18. package/dist/builder/function-params.d.ts +10 -0
  19. package/dist/builder/function-params.js +203 -0
  20. package/dist/builder/load.d.ts +70 -10
  21. package/dist/builder/load.js +258 -67
  22. package/dist/builder/paths.d.ts +9 -1
  23. package/dist/builder/paths.js +32 -2
  24. package/dist/builder/schedules.d.ts +25 -0
  25. package/dist/builder/schedules.js +101 -0
  26. package/dist/builder/slot-schema-validation.d.ts +4 -0
  27. package/dist/builder/slot-schema-validation.js +10 -0
  28. package/dist/builder/typecheck.d.ts +8 -0
  29. package/dist/builder/typecheck.js +102 -0
  30. package/dist/builder/types.d.ts +127 -19
  31. package/dist/builder/types.js +21 -1
  32. package/dist/cli/auth/auth.d.ts +37 -0
  33. package/dist/cli/auth/auth.js +211 -0
  34. package/dist/cli/auth/backend-url.d.ts +5 -0
  35. package/dist/cli/auth/backend-url.js +25 -0
  36. package/dist/cli/auth/clipboard.d.ts +9 -0
  37. package/dist/cli/auth/clipboard.js +38 -0
  38. package/dist/cli/auth/http.d.ts +20 -0
  39. package/dist/cli/auth/http.js +27 -0
  40. package/dist/cli/auth/index.d.ts +10 -0
  41. package/dist/cli/auth/index.js +27 -0
  42. package/dist/cli/auth/progress.d.ts +12 -0
  43. package/dist/cli/auth/progress.js +15 -0
  44. package/dist/cli/auth/serve-login.d.ts +8 -0
  45. package/dist/cli/auth/serve-login.js +24 -0
  46. package/dist/cli/calls/index.d.ts +177 -0
  47. package/dist/cli/calls/index.js +96 -0
  48. package/dist/cli/compile/index.js +3 -0
  49. package/dist/cli/config.d.ts +10 -0
  50. package/dist/cli/config.js +52 -0
  51. package/dist/cli/debug/index.d.ts +31 -0
  52. package/dist/cli/debug/index.js +119 -0
  53. package/dist/cli/exec/index.d.ts +39 -0
  54. package/dist/cli/exec/index.js +138 -0
  55. package/dist/cli/exec/session.d.ts +48 -0
  56. package/dist/cli/exec/session.js +82 -0
  57. package/dist/cli/exec/trace.d.ts +18 -0
  58. package/dist/cli/exec/trace.js +52 -0
  59. package/dist/cli/index.js +112 -9
  60. package/dist/cli/logs/index.d.ts +47 -0
  61. package/dist/cli/logs/index.js +113 -0
  62. package/dist/cli/mobile/index.d.ts +12 -0
  63. package/dist/cli/mobile/index.js +405 -0
  64. package/dist/cli/serve/index.d.ts +109 -3
  65. package/dist/cli/serve/index.js +506 -118
  66. package/dist/cli/turns/index.d.ts +105 -0
  67. package/dist/cli/turns/index.js +128 -0
  68. package/dist/cli/turns/run.d.ts +13 -0
  69. package/dist/cli/turns/run.js +57 -0
  70. package/dist/cli/turns/shadow.d.ts +112 -0
  71. package/dist/cli/turns/shadow.js +54 -0
  72. package/dist/cli/type-gen/index.js +9 -9
  73. package/dist/compiler.d.ts +7 -0
  74. package/dist/compiler.js +7 -0
  75. package/dist/compute-host/compute-host.d.ts +14 -23
  76. package/dist/compute-host/compute-host.js +18 -30
  77. package/dist/compute-host/index.d.ts +2 -4
  78. package/dist/compute-host/index.js +1 -2
  79. package/dist/compute-host/source-compute-host.d.ts +10 -10
  80. package/dist/compute-host/source-compute-host.js +33 -40
  81. package/dist/core/case-orchestrator/contact-hours.d.ts +70 -0
  82. package/dist/core/case-orchestrator/contact-hours.js +127 -0
  83. package/dist/core/case-orchestrator/index.d.ts +3 -0
  84. package/dist/core/case-orchestrator/index.js +3 -0
  85. package/dist/core/case-orchestrator/render.d.ts +75 -0
  86. package/dist/core/case-orchestrator/render.js +244 -0
  87. package/dist/core/case-orchestrator/time.d.ts +11 -0
  88. package/dist/core/case-orchestrator/time.js +29 -0
  89. package/dist/core/case-orchestrator/types.d.ts +708 -0
  90. package/dist/core/case-orchestrator/types.js +42 -0
  91. package/dist/core/context/call.d.ts +291 -0
  92. package/dist/core/context/call.js +94 -0
  93. package/dist/core/context/channels.d.ts +60 -0
  94. package/dist/core/context/channels.js +35 -0
  95. package/dist/core/context/contact.d.ts +96 -6
  96. package/dist/core/context/contact.js +48 -2
  97. package/dist/core/context/email-message.d.ts +198 -0
  98. package/dist/core/context/email-message.js +86 -0
  99. package/dist/core/context/email.d.ts +109 -0
  100. package/dist/core/context/email.js +90 -0
  101. package/dist/core/context/exchanges.d.ts +167 -0
  102. package/dist/core/context/exchanges.js +81 -0
  103. package/dist/core/context/instances.d.ts +307 -0
  104. package/dist/core/context/instances.js +137 -0
  105. package/dist/core/context/kv.d.ts +113 -0
  106. package/dist/core/context/kv.js +60 -0
  107. package/dist/core/context/platform-registry.d.ts +544 -4
  108. package/dist/core/context/platform-registry.js +14 -2
  109. package/dist/core/context/platform.d.ts +2 -1
  110. package/dist/core/context/sms.d.ts +177 -0
  111. package/dist/core/context/sms.js +77 -0
  112. package/dist/core/context/types.d.ts +79 -48
  113. package/dist/core/context/types.js +1 -7
  114. package/dist/core/conversation/index.d.ts +85 -0
  115. package/dist/core/conversation/index.js +133 -0
  116. package/dist/core/functions/errors.d.ts +74 -0
  117. package/dist/core/functions/errors.js +26 -0
  118. package/dist/core/functions/events.d.ts +192 -0
  119. package/dist/core/functions/events.js +23 -0
  120. package/dist/core/functions/schedules.d.ts +50 -0
  121. package/dist/core/functions/schedules.js +20 -0
  122. package/dist/core/functions/types.d.ts +29 -73
  123. package/dist/core/functions/types.js +1 -4
  124. package/dist/core/office-hours/index.d.ts +39 -0
  125. package/dist/core/office-hours/index.js +187 -0
  126. package/dist/core/page/define.d.ts +904 -0
  127. package/dist/core/page/define.js +518 -0
  128. package/dist/core/page/envelope.d.ts +55 -0
  129. package/dist/core/page/envelope.js +4 -0
  130. package/dist/core/page/fns.d.ts +448 -0
  131. package/dist/core/page/fns.js +539 -0
  132. package/dist/core/page/memory-reader.d.ts +27 -0
  133. package/dist/core/page/memory-reader.js +299 -0
  134. package/dist/core/page/ops.d.ts +58 -0
  135. package/dist/core/page/ops.js +220 -0
  136. package/dist/core/page/page-host.d.ts +20 -0
  137. package/dist/core/page/page-host.js +57 -0
  138. package/dist/core/page/records-query.d.ts +234 -0
  139. package/dist/core/page/records-query.js +780 -0
  140. package/dist/core/page/render.d.ts +295 -0
  141. package/dist/core/page/render.js +1060 -0
  142. package/dist/core/page/sandbox.d.ts +85 -0
  143. package/dist/core/page/sandbox.js +357 -0
  144. package/dist/core/page/time-format.d.ts +46 -0
  145. package/dist/core/page/time-format.js +125 -0
  146. package/dist/core/page/timeline.d.ts +40 -0
  147. package/dist/core/page/timeline.js +2 -0
  148. package/dist/core/page/typed.d.ts +648 -0
  149. package/dist/core/page/typed.js +2 -0
  150. package/dist/core/page/workspace.d.ts +57 -0
  151. package/dist/core/page/workspace.js +266 -0
  152. package/dist/core/party/index.d.ts +3 -0
  153. package/dist/core/party/index.js +3 -0
  154. package/dist/core/party/schema.d.ts +208 -0
  155. package/dist/core/party/schema.js +113 -0
  156. package/dist/core/party/types.d.ts +35 -0
  157. package/dist/core/party/types.js +15 -0
  158. package/dist/core/sequence/define.d.ts +56 -0
  159. package/dist/core/sequence/define.js +10 -0
  160. package/dist/core/sequence/index.d.ts +63 -0
  161. package/dist/core/sequence/index.js +231 -0
  162. package/dist/core/slot/binding.d.ts +40 -0
  163. package/dist/core/slot/binding.js +2 -0
  164. package/dist/core/slot/company-metadata.d.ts +102 -0
  165. package/dist/core/slot/company-metadata.js +536 -0
  166. package/dist/core/slot/compile-schema.d.ts +19 -13
  167. package/dist/core/slot/compile-schema.js +51 -248
  168. package/dist/core/slot/contact-timezone.d.ts +110 -0
  169. package/dist/core/slot/contact-timezone.js +186 -0
  170. package/dist/core/slot/field.d.ts +2 -25
  171. package/dist/core/slot/field.js +0 -71
  172. package/dist/core/slot/id-ref.d.ts +17 -2
  173. package/dist/core/slot/id-ref.js +16 -8
  174. package/dist/core/slot/index.d.ts +12 -13
  175. package/dist/core/slot/index.js +11 -12
  176. package/dist/core/slot/naming.d.ts +15 -0
  177. package/dist/core/slot/naming.js +96 -0
  178. package/dist/core/slot/platform-fields.d.ts +119 -0
  179. package/dist/core/slot/platform-fields.js +121 -0
  180. package/dist/core/slot/ref.d.ts +16 -0
  181. package/dist/core/slot/ref.js +14 -0
  182. package/dist/core/slot/row.d.ts +2 -9
  183. package/dist/core/slot/row.js +13 -23
  184. package/dist/core/slot/schema-compat.d.ts +17 -0
  185. package/dist/core/slot/schema-compat.js +103 -0
  186. package/dist/core/slot/schema.d.ts +353 -76
  187. package/dist/core/slot/schema.js +163 -10
  188. package/dist/core/slot/types.d.ts +30 -103
  189. package/dist/core/slot/value.d.ts +28 -3
  190. package/dist/core/slot/value.js +93 -57
  191. package/dist/dev-overlay/protocol.d.ts +74 -8
  192. package/dist/fn-context/build-context.d.ts +3 -1
  193. package/dist/fn-context/build-context.js +26 -10
  194. package/dist/fn-context/fake/empty-api.js +9 -28
  195. package/dist/fn-context/fake/index.d.ts +13 -4
  196. package/dist/fn-context/fake/index.js +29 -2
  197. package/dist/fn-context/fn-params.d.ts +3 -0
  198. package/dist/fn-context/fn-params.js +10 -0
  199. package/dist/fn-context/index.d.ts +5 -5
  200. package/dist/fn-context/index.js +4 -4
  201. package/dist/fn-context/log.js +2 -2
  202. package/dist/fn-context/make-ctx.d.ts +11 -0
  203. package/dist/fn-context/make-ctx.js +20 -9
  204. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +32 -0
  205. package/dist/fn-context/rpc/case-orchestrator-tools.js +12 -0
  206. package/dist/fn-context/rpc/errors.d.ts +13 -0
  207. package/dist/fn-context/rpc/errors.js +22 -0
  208. package/dist/fn-context/rpc/index.d.ts +4 -2
  209. package/dist/fn-context/rpc/index.js +4 -2
  210. package/dist/fn-context/rpc/integration/index.d.ts +15 -5
  211. package/dist/fn-context/rpc/integration/index.js +1 -1
  212. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  213. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  214. package/dist/fn-context/rpc/log.d.ts +11 -1
  215. package/dist/fn-context/rpc/platform.d.ts +13 -3
  216. package/dist/fn-context/rpc/platform.js +1 -1
  217. package/dist/fn-context/rpc/records.d.ts +85 -0
  218. package/dist/fn-context/rpc/records.js +24 -0
  219. package/dist/fn-context/rpc/trpc-client.d.ts +44 -2
  220. package/dist/fn-context/rpc/trpc-client.js +222 -12
  221. package/dist/fn-context/rpc/trpc-init.d.ts +21 -3
  222. package/dist/fn-context/rpc/trpc-init.js +10 -4
  223. package/dist/fn-context/rpc/trpc-router-factory.d.ts +111 -7
  224. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  225. package/dist/fn-context/run-scope.d.ts +4 -0
  226. package/dist/fn-context/run-scope.js +9 -0
  227. package/dist/fn-context/types.d.ts +52 -5
  228. package/dist/index.d.ts +36 -46
  229. package/dist/index.js +30 -33
  230. package/dist/logger.d.ts +11 -0
  231. package/dist/logger.js +49 -0
  232. package/dist/platform.d.ts +75 -0
  233. package/dist/platform.js +57 -0
  234. package/dist/testing-compile-child.d.ts +2 -0
  235. package/dist/testing-compile-child.js +20 -0
  236. package/dist/testing.d.ts +368 -0
  237. package/dist/testing.js +439 -0
  238. package/dist/voice-service/actions.d.ts +50 -6
  239. package/dist/voice-service/index.d.ts +2 -0
  240. package/dist/voice-service/index.js +2 -0
  241. package/dist/voice-service/protocol.d.ts +604 -0
  242. package/dist/voice-service/protocol.js +67 -0
  243. package/dist/voice-service/types.d.ts +55 -8
  244. package/dist/worker.d.ts +11 -0
  245. package/dist/worker.js +11 -0
  246. package/package.json +38 -15
  247. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  248. package/dist/builder/compile/compile-agenda.js +0 -64
  249. package/dist/builder/merge.d.ts +0 -4
  250. package/dist/builder/merge.js +0 -19
  251. package/dist/compute-host/read-only-cache.d.ts +0 -20
  252. package/dist/compute-host/read-only-cache.js +0 -61
  253. package/dist/core/context/db.d.ts +0 -69
  254. package/dist/core/context/db.js +0 -44
  255. package/dist/core/context/docusign.d.ts +0 -134
  256. package/dist/core/context/docusign.js +0 -108
  257. package/dist/core/context/filevine.d.ts +0 -323
  258. package/dist/core/context/filevine.js +0 -254
  259. package/dist/core/context/http.d.ts +0 -9
  260. package/dist/core/context/http.js +0 -4
  261. package/dist/core/context/hubspot.d.ts +0 -250
  262. package/dist/core/context/hubspot.js +0 -191
  263. package/dist/core/context/twilio.d.ts +0 -50
  264. package/dist/core/context/twilio.js +0 -42
  265. package/dist/core/functions/define/case-context.d.ts +0 -14
  266. package/dist/core/functions/define/case-context.js +0 -15
  267. package/dist/core/functions/define/compute.d.ts +0 -7
  268. package/dist/core/functions/define/compute.js +0 -17
  269. package/dist/core/functions/define/custom.d.ts +0 -4
  270. package/dist/core/functions/define/custom.js +0 -8
  271. package/dist/core/functions/define/system.d.ts +0 -7
  272. package/dist/core/functions/define/system.js +0 -12
  273. package/dist/core/functions/func-ref.d.ts +0 -16
  274. package/dist/core/functions/func-ref.js +0 -20
  275. package/dist/core/slot/deps.d.ts +0 -15
  276. package/dist/core/slot/deps.js +0 -88
  277. package/dist/core/slot/derived.d.ts +0 -32
  278. package/dist/core/slot/derived.js +0 -115
  279. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  280. package/dist/core/slot/platform-session-fields.js +0 -48
  281. package/dist/core/slot/sf-schema.d.ts +0 -23
  282. package/dist/core/slot/sf-schema.js +0 -125
  283. package/dist/core/slot/sf-validate.d.ts +0 -14
  284. package/dist/core/slot/sf-validate.js +0 -132
  285. package/dist/core/slot/snapshot.d.ts +0 -18
  286. package/dist/core/slot/snapshot.js +0 -138
  287. package/dist/core/slot/write.d.ts +0 -48
  288. package/dist/core/slot/write.js +0 -426
  289. package/dist/core/stage/builders.d.ts +0 -54
  290. package/dist/core/stage/builders.js +0 -31
  291. package/dist/core/stage/condition.d.ts +0 -17
  292. package/dist/core/stage/condition.js +0 -198
  293. package/dist/core/stage/drive.d.ts +0 -43
  294. package/dist/core/stage/drive.js +0 -78
  295. package/dist/core/stage/finish-when.d.ts +0 -20
  296. package/dist/core/stage/finish-when.js +0 -82
  297. package/dist/core/stage/flatten.d.ts +0 -27
  298. package/dist/core/stage/flatten.js +0 -466
  299. package/dist/core/stage/index.d.ts +0 -15
  300. package/dist/core/stage/index.js +0 -13
  301. package/dist/core/stage/interrupts.d.ts +0 -28
  302. package/dist/core/stage/interrupts.js +0 -120
  303. package/dist/core/stage/ivr-fields.d.ts +0 -9
  304. package/dist/core/stage/ivr-fields.js +0 -75
  305. package/dist/core/stage/simulate.d.ts +0 -24
  306. package/dist/core/stage/simulate.js +0 -33
  307. package/dist/core/stage/transfer-fields.d.ts +0 -19
  308. package/dist/core/stage/transfer-fields.js +0 -129
  309. package/dist/core/stage/transfer-spec.d.ts +0 -48
  310. package/dist/core/stage/transfer-spec.js +0 -113
  311. package/dist/core/stage/types.d.ts +0 -208
  312. package/dist/core/stage/types.js +0 -2
  313. package/dist/core/stage/validate.d.ts +0 -11
  314. package/dist/core/stage/validate.js +0 -330
  315. package/dist/core/stage/walk.d.ts +0 -39
  316. package/dist/core/stage/walk.js +0 -119
  317. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  318. package/dist/fn-context/system-args.d.ts +0 -6
  319. package/dist/fn-context/system-args.js +0 -14
@@ -1,11 +1,18 @@
1
1
  import { z } from 'zod';
2
+ /** A contact's id, typed as one (25 §16): it goes where `db` takes a contact's id without a cast. */
3
+ const contactId = z.custom((value) => typeof value === 'string' && value.length > 0);
2
4
  export const CONTACT_PAGE_LIMIT_MAX = 100;
5
+ /** A filled slot value as scripts read and write it. */
6
+ export const slotFieldValue = z.union([z.string(), z.number(), z.boolean(), z.array(z.string()), z.null()]);
3
7
  export const contactSummary = z.object({
4
- id: z.string(),
8
+ id: contactId,
9
+ /** `person` or `organization` (the platform field `kind`). */
5
10
  kind: z.string(),
6
- externalIdentifier: z.string().nullable(),
7
11
  phone: z.string().nullable(),
12
+ email: z.string().nullable(),
8
13
  createdAt: z.string(),
14
+ /** The contact's filled fields with a plain value, by name. */
15
+ fields: z.record(z.string(), slotFieldValue),
9
16
  });
10
17
  // Paging is required so a caller can never fetch an unbounded page by omission.
11
18
  export const contactListInput = z.object({
@@ -19,15 +26,54 @@ export const contactListOutput = z.object({
19
26
  offset: z.number().int(),
20
27
  limit: z.number().int(),
21
28
  });
29
+ /** Exactly one identity: an id, a phone or an email. */
30
+ export const contactFindInput = z.union([
31
+ z.strictObject({ id: z.string().min(1) }),
32
+ z.strictObject({ phone: z.string().min(1) }),
33
+ z.strictObject({ email: z.string().min(1) }),
34
+ ]);
35
+ export const contactFindOutput = z.object({ contacts: z.array(contactSummary) });
36
+ export const contactCreateInput = z.strictObject({
37
+ /** Contact fields by name, checked against the sequence's contact schema. */
38
+ fields: z.record(z.string(), slotFieldValue),
39
+ });
40
+ export const contactIdInput = z.strictObject({ contactId: z.string().min(1) });
22
41
  /** Stand-in surface for fake contexts and local runs; never touches the database. */
23
42
  export const contactMockService = {
24
43
  async list(input) {
25
44
  return { contacts: [], offset: input.offset, limit: input.limit };
26
45
  },
46
+ async find() {
47
+ return { contacts: [] };
48
+ },
49
+ async create(input) {
50
+ const fields = Object.fromEntries(Object.entries(input.fields).filter(([, value]) => value !== null));
51
+ return {
52
+ id: 'contact',
53
+ kind: typeof fields.kind === 'string' ? fields.kind : 'person',
54
+ phone: typeof fields.phone === 'string' ? fields.phone : null,
55
+ email: typeof fields.email === 'string' ? fields.email : null,
56
+ createdAt: new Date(0).toISOString(),
57
+ fields,
58
+ };
59
+ },
60
+ async clearContactMethods(input) {
61
+ return {
62
+ id: input.contactId,
63
+ kind: 'person',
64
+ phone: null,
65
+ email: null,
66
+ createdAt: new Date(0).toISOString(),
67
+ fields: {},
68
+ };
69
+ },
27
70
  };
28
71
  export const contactSurface = {
29
72
  methods: {
30
73
  list: { input: contactListInput, output: contactListOutput },
74
+ find: { input: contactFindInput, output: contactFindOutput },
75
+ create: { input: contactCreateInput, output: contactSummary },
76
+ clearContactMethods: { input: contactIdInput, output: contactSummary },
31
77
  },
32
78
  mock: contactMockService,
33
79
  };
@@ -0,0 +1,198 @@
1
+ import { z } from 'zod';
2
+ export declare const EMAIL_PAGE_LIMIT_MAX = 100;
3
+ export declare const emailDirection: z.ZodEnum<{
4
+ inbound: "inbound";
5
+ outbound: "outbound";
6
+ }>;
7
+ export type EmailDirection = z.infer<typeof emailDirection>;
8
+ /** Script-facing email projection (21 §5.9). OAuth data and raw provider payloads stay private. */
9
+ export declare const emailRecord: z.ZodObject<{
10
+ id: z.ZodString;
11
+ emailThreadId: z.ZodString;
12
+ threadId: z.ZodNullable<z.ZodString>;
13
+ instanceId: z.ZodNullable<z.ZodString>;
14
+ contactId: z.ZodNullable<z.ZodString>;
15
+ runId: z.ZodNullable<z.ZodString>;
16
+ direction: z.ZodEnum<{
17
+ inbound: "inbound";
18
+ outbound: "outbound";
19
+ }>;
20
+ from: z.ZodArray<z.ZodString>;
21
+ to: z.ZodArray<z.ZodString>;
22
+ cc: z.ZodArray<z.ZodString>;
23
+ subject: z.ZodNullable<z.ZodString>;
24
+ body: z.ZodNullable<z.ZodString>;
25
+ processing: z.ZodNullable<z.ZodString>;
26
+ delivery: z.ZodNullable<z.ZodString>;
27
+ occurredAt: z.ZodString;
28
+ }, z.core.$strip>;
29
+ export type EmailRecord = z.infer<typeof emailRecord>;
30
+ export declare const emailListInput: z.ZodObject<{
31
+ offset: z.ZodNumber;
32
+ limit: z.ZodNumber;
33
+ instanceId: z.ZodOptional<z.ZodString>;
34
+ contactId: z.ZodOptional<z.ZodString>;
35
+ emailThreadId: z.ZodOptional<z.ZodString>;
36
+ direction: z.ZodOptional<z.ZodEnum<{
37
+ inbound: "inbound";
38
+ outbound: "outbound";
39
+ }>>;
40
+ }, z.core.$strip>;
41
+ export type EmailListParams = z.infer<typeof emailListInput>;
42
+ export declare const emailListOutput: z.ZodObject<{
43
+ emails: z.ZodArray<z.ZodObject<{
44
+ id: z.ZodString;
45
+ emailThreadId: z.ZodString;
46
+ threadId: z.ZodNullable<z.ZodString>;
47
+ instanceId: z.ZodNullable<z.ZodString>;
48
+ contactId: z.ZodNullable<z.ZodString>;
49
+ runId: z.ZodNullable<z.ZodString>;
50
+ direction: z.ZodEnum<{
51
+ inbound: "inbound";
52
+ outbound: "outbound";
53
+ }>;
54
+ from: z.ZodArray<z.ZodString>;
55
+ to: z.ZodArray<z.ZodString>;
56
+ cc: z.ZodArray<z.ZodString>;
57
+ subject: z.ZodNullable<z.ZodString>;
58
+ body: z.ZodNullable<z.ZodString>;
59
+ processing: z.ZodNullable<z.ZodString>;
60
+ delivery: z.ZodNullable<z.ZodString>;
61
+ occurredAt: z.ZodString;
62
+ }, z.core.$strip>>;
63
+ offset: z.ZodNumber;
64
+ limit: z.ZodNumber;
65
+ }, z.core.$strip>;
66
+ export type EmailListResult = z.infer<typeof emailListOutput>;
67
+ export declare const emailGetInput: z.ZodString;
68
+ export declare const emailGetOutput: z.ZodNullable<z.ZodObject<{
69
+ id: z.ZodString;
70
+ emailThreadId: z.ZodString;
71
+ threadId: z.ZodNullable<z.ZodString>;
72
+ instanceId: z.ZodNullable<z.ZodString>;
73
+ contactId: z.ZodNullable<z.ZodString>;
74
+ runId: z.ZodNullable<z.ZodString>;
75
+ direction: z.ZodEnum<{
76
+ inbound: "inbound";
77
+ outbound: "outbound";
78
+ }>;
79
+ from: z.ZodArray<z.ZodString>;
80
+ to: z.ZodArray<z.ZodString>;
81
+ cc: z.ZodArray<z.ZodString>;
82
+ subject: z.ZodNullable<z.ZodString>;
83
+ body: z.ZodNullable<z.ZodString>;
84
+ processing: z.ZodNullable<z.ZodString>;
85
+ delivery: z.ZodNullable<z.ZodString>;
86
+ occurredAt: z.ZodString;
87
+ }, z.core.$strip>>;
88
+ /**
89
+ * An email sent now (64 §15), from any entry, as a text is (`ctx.api.sms.send`): one recipient, no cc or bcc.
90
+ * `to` is a contact's row id, or `{ address }` for someone who is not one (an on-call lawyer, opposing
91
+ * counsel). An address that is a contact's of this environment is sent as to that contact: their opt-outs
92
+ * are checked. `from` names the mailbox (its name in the environment); absent, a contact's own mailbox (one
93
+ * picked at random is remembered on them), else any active one. It goes back in the newest thread with
94
+ * them on that mailbox, else starts one; stored with the run, then sent. The case it is about, and who
95
+ * hears `email.sent`: as for a text. Pause and contact hours are not checked.
96
+ */
97
+ export declare const emailSendInput: z.ZodObject<{
98
+ to: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
99
+ address: z.ZodString;
100
+ }, z.core.$strict>]>;
101
+ body: z.ZodString;
102
+ subject: z.ZodOptional<z.ZodString>;
103
+ instanceId: z.ZodOptional<z.ZodString>;
104
+ from: z.ZodOptional<z.ZodString>;
105
+ }, z.core.$strict>;
106
+ export type EmailSendParams = z.infer<typeof emailSendInput>;
107
+ /** The thread the email went on (`email.sent` on the case's timeline). */
108
+ export declare const emailSendOutput: z.ZodObject<{
109
+ exchangeId: z.ZodString;
110
+ }, z.core.$strip>;
111
+ export type EmailSendResult = z.infer<typeof emailSendOutput>;
112
+ /** Platform email capability, reached from scripts as `ctx.api.email`: the history, and sending one now. */
113
+ export type EmailHistoryApi = {
114
+ list(input: EmailListParams): Promise<EmailListResult>;
115
+ get(id: string): Promise<EmailRecord | null>;
116
+ send(input: EmailSendParams): Promise<EmailSendResult>;
117
+ };
118
+ export declare const emailHistoryMockService: EmailHistoryApi;
119
+ export declare const emailHistorySurface: {
120
+ methods: {
121
+ list: {
122
+ input: z.ZodObject<{
123
+ offset: z.ZodNumber;
124
+ limit: z.ZodNumber;
125
+ instanceId: z.ZodOptional<z.ZodString>;
126
+ contactId: z.ZodOptional<z.ZodString>;
127
+ emailThreadId: z.ZodOptional<z.ZodString>;
128
+ direction: z.ZodOptional<z.ZodEnum<{
129
+ inbound: "inbound";
130
+ outbound: "outbound";
131
+ }>>;
132
+ }, z.core.$strip>;
133
+ output: z.ZodObject<{
134
+ emails: z.ZodArray<z.ZodObject<{
135
+ id: z.ZodString;
136
+ emailThreadId: z.ZodString;
137
+ threadId: z.ZodNullable<z.ZodString>;
138
+ instanceId: z.ZodNullable<z.ZodString>;
139
+ contactId: z.ZodNullable<z.ZodString>;
140
+ runId: z.ZodNullable<z.ZodString>;
141
+ direction: z.ZodEnum<{
142
+ inbound: "inbound";
143
+ outbound: "outbound";
144
+ }>;
145
+ from: z.ZodArray<z.ZodString>;
146
+ to: z.ZodArray<z.ZodString>;
147
+ cc: z.ZodArray<z.ZodString>;
148
+ subject: z.ZodNullable<z.ZodString>;
149
+ body: z.ZodNullable<z.ZodString>;
150
+ processing: z.ZodNullable<z.ZodString>;
151
+ delivery: z.ZodNullable<z.ZodString>;
152
+ occurredAt: z.ZodString;
153
+ }, z.core.$strip>>;
154
+ offset: z.ZodNumber;
155
+ limit: z.ZodNumber;
156
+ }, z.core.$strip>;
157
+ };
158
+ get: {
159
+ input: z.ZodString;
160
+ output: z.ZodNullable<z.ZodObject<{
161
+ id: z.ZodString;
162
+ emailThreadId: z.ZodString;
163
+ threadId: z.ZodNullable<z.ZodString>;
164
+ instanceId: z.ZodNullable<z.ZodString>;
165
+ contactId: z.ZodNullable<z.ZodString>;
166
+ runId: z.ZodNullable<z.ZodString>;
167
+ direction: z.ZodEnum<{
168
+ inbound: "inbound";
169
+ outbound: "outbound";
170
+ }>;
171
+ from: z.ZodArray<z.ZodString>;
172
+ to: z.ZodArray<z.ZodString>;
173
+ cc: z.ZodArray<z.ZodString>;
174
+ subject: z.ZodNullable<z.ZodString>;
175
+ body: z.ZodNullable<z.ZodString>;
176
+ processing: z.ZodNullable<z.ZodString>;
177
+ delivery: z.ZodNullable<z.ZodString>;
178
+ occurredAt: z.ZodString;
179
+ }, z.core.$strip>>;
180
+ };
181
+ send: {
182
+ input: z.ZodObject<{
183
+ to: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
184
+ address: z.ZodString;
185
+ }, z.core.$strict>]>;
186
+ body: z.ZodString;
187
+ subject: z.ZodOptional<z.ZodString>;
188
+ instanceId: z.ZodOptional<z.ZodString>;
189
+ from: z.ZodOptional<z.ZodString>;
190
+ }, z.core.$strict>;
191
+ output: z.ZodObject<{
192
+ exchangeId: z.ZodString;
193
+ }, z.core.$strip>;
194
+ };
195
+ };
196
+ mock: EmailHistoryApi;
197
+ };
198
+ //# sourceMappingURL=email-message.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { z } from 'zod';
2
+ export const EMAIL_PAGE_LIMIT_MAX = 100;
3
+ export const emailDirection = z.enum(['inbound', 'outbound']);
4
+ /** Script-facing email projection (21 §5.9). OAuth data and raw provider payloads stay private. */
5
+ export const emailRecord = z.object({
6
+ id: z.string(),
7
+ /** Our thread (21 §5.9): `ExchangeRef` `{ channel: 'email', emailThreadId }`. */
8
+ emailThreadId: z.string(),
9
+ /** The provider's thread id (null for a thread we started, until its first email went). */
10
+ threadId: z.string().nullable(),
11
+ instanceId: z.string().nullable(),
12
+ /** Inbound: who sent it, as recognized on the thread. */
13
+ contactId: z.string().nullable(),
14
+ /** Inbound: the run that handled it; outbound: the run that sent it (null: the platform did). */
15
+ runId: z.string().nullable(),
16
+ direction: emailDirection,
17
+ from: z.array(z.string()),
18
+ to: z.array(z.string()),
19
+ cc: z.array(z.string()),
20
+ subject: z.string().nullable(),
21
+ /** The new text, without the quoted history. */
22
+ body: z.string().nullable(),
23
+ /** Inbound: pending | claimed | processed | skipped | declined | failed. */
24
+ processing: z.string().nullable(),
25
+ /** Outbound: pending | submitting | sent | failed. */
26
+ delivery: z.string().nullable(),
27
+ occurredAt: z.string(),
28
+ });
29
+ export const emailListInput = z.object({
30
+ offset: z.number().int().min(0),
31
+ limit: z.number().int().min(1).max(EMAIL_PAGE_LIMIT_MAX),
32
+ instanceId: z.string().optional(),
33
+ contactId: z.string().optional(),
34
+ emailThreadId: z.string().optional(),
35
+ direction: emailDirection.optional(),
36
+ });
37
+ export const emailListOutput = z.object({
38
+ emails: z.array(emailRecord),
39
+ offset: z.number().int(),
40
+ limit: z.number().int(),
41
+ });
42
+ export const emailGetInput = z.string().min(1);
43
+ export const emailGetOutput = emailRecord.nullable();
44
+ /**
45
+ * An email sent now (64 §15), from any entry, as a text is (`ctx.api.sms.send`): one recipient, no cc or bcc.
46
+ * `to` is a contact's row id, or `{ address }` for someone who is not one (an on-call lawyer, opposing
47
+ * counsel). An address that is a contact's of this environment is sent as to that contact: their opt-outs
48
+ * are checked. `from` names the mailbox (its name in the environment); absent, a contact's own mailbox (one
49
+ * picked at random is remembered on them), else any active one. It goes back in the newest thread with
50
+ * them on that mailbox, else starts one; stored with the run, then sent. The case it is about, and who
51
+ * hears `email.sent`: as for a text. Pause and contact hours are not checked.
52
+ */
53
+ export const emailSendInput = z
54
+ .object({
55
+ to: z.union([z.string().min(1), z.object({ address: z.string().min(1) }).strict()]),
56
+ body: z.string().min(1),
57
+ /** Absent: a reply to the thread's subject, or a plain one for a new thread. */
58
+ subject: z.string().optional(),
59
+ /** The case the email is about, any of this environment's; absent: the run's own case, if any. */
60
+ instanceId: z.string().min(1).optional(),
61
+ /** The mailbox to send from, by its name in the environment. */
62
+ from: z.string().min(1).optional(),
63
+ })
64
+ .strict();
65
+ /** The thread the email went on (`email.sent` on the case's timeline). */
66
+ export const emailSendOutput = z.object({ exchangeId: z.string() });
67
+ export const emailHistoryMockService = {
68
+ async list(input) {
69
+ return { emails: [], offset: input.offset, limit: input.limit };
70
+ },
71
+ async get() {
72
+ return null;
73
+ },
74
+ async send() {
75
+ return { exchangeId: 'mock-email' };
76
+ },
77
+ };
78
+ export const emailHistorySurface = {
79
+ methods: {
80
+ list: { input: emailListInput, output: emailListOutput },
81
+ get: { input: emailGetInput, output: emailGetOutput },
82
+ send: { input: emailSendInput, output: emailSendOutput },
83
+ },
84
+ mock: emailHistoryMockService,
85
+ };
86
+ //# sourceMappingURL=email-message.js.map
@@ -0,0 +1,109 @@
1
+ import { z } from 'zod';
2
+ import type { IntegrationAccountFields } from './account-fields.js';
3
+ /** `hotmail` covers every Microsoft account (Outlook.com / Hotmail / M365). */
4
+ export declare const emailProvider: z.ZodEnum<{
5
+ gmail: "gmail";
6
+ hotmail: "hotmail";
7
+ }>;
8
+ export type EmailProvider = z.infer<typeof emailProvider>;
9
+ export declare const emailSendEmailInput: z.ZodObject<{
10
+ to: z.ZodArray<z.ZodString>;
11
+ cc: z.ZodOptional<z.ZodArray<z.ZodString>>;
12
+ bcc: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ subject: z.ZodString;
14
+ body: z.ZodString;
15
+ threadId: z.ZodOptional<z.ZodString>;
16
+ inReplyTo: z.ZodOptional<z.ZodString>;
17
+ references: z.ZodOptional<z.ZodString>;
18
+ replyToId: z.ZodOptional<z.ZodString>;
19
+ }, z.core.$strip>;
20
+ export type EmailSendEmailInput = z.infer<typeof emailSendEmailInput>;
21
+ export declare const emailSendEmailOutput: z.ZodObject<{
22
+ id: z.ZodString;
23
+ threadId: z.ZodOptional<z.ZodString>;
24
+ }, z.core.$strip>;
25
+ export type EmailSendEmailOutput = z.infer<typeof emailSendEmailOutput>;
26
+ export declare const emailGetMessageInput: z.ZodObject<{
27
+ id: z.ZodString;
28
+ }, z.core.$strip>;
29
+ export type EmailGetMessageInput = z.infer<typeof emailGetMessageInput>;
30
+ export declare const emailAttachment: z.ZodObject<{
31
+ filename: z.ZodString;
32
+ contentType: z.ZodString;
33
+ attachmentId: z.ZodString;
34
+ isInline: z.ZodBoolean;
35
+ size: z.ZodOptional<z.ZodNumber>;
36
+ }, z.core.$strip>;
37
+ export type EmailAttachment = z.infer<typeof emailAttachment>;
38
+ export declare const emailGetMessageOutput: z.ZodObject<{
39
+ id: z.ZodString;
40
+ threadId: z.ZodString;
41
+ from: z.ZodString;
42
+ to: z.ZodArray<z.ZodString>;
43
+ cc: z.ZodArray<z.ZodString>;
44
+ bcc: z.ZodArray<z.ZodString>;
45
+ subject: z.ZodString;
46
+ text: z.ZodString;
47
+ html: z.ZodString;
48
+ date: z.ZodString;
49
+ messageId: z.ZodString;
50
+ labelIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
51
+ attachments: z.ZodArray<z.ZodObject<{
52
+ filename: z.ZodString;
53
+ contentType: z.ZodString;
54
+ attachmentId: z.ZodString;
55
+ isInline: z.ZodBoolean;
56
+ size: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$strip>>;
58
+ autoHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
59
+ }, z.core.$strip>;
60
+ export type EmailGetMessageOutput = z.infer<typeof emailGetMessageOutput>;
61
+ export declare const emailListMessagesInput: z.ZodObject<{
62
+ maxResults: z.ZodOptional<z.ZodNumber>;
63
+ query: z.ZodOptional<z.ZodString>;
64
+ pageToken: z.ZodOptional<z.ZodString>;
65
+ }, z.core.$strip>;
66
+ export type EmailListMessagesInput = z.infer<typeof emailListMessagesInput>;
67
+ export declare const emailListMessagesOutput: z.ZodObject<{
68
+ messages: z.ZodArray<z.ZodObject<{
69
+ id: z.ZodString;
70
+ threadId: z.ZodString;
71
+ }, z.core.$strip>>;
72
+ nextPageToken: z.ZodOptional<z.ZodString>;
73
+ }, z.core.$strip>;
74
+ export type EmailListMessagesOutput = z.infer<typeof emailListMessagesOutput>;
75
+ export declare const emailGetAttachmentInput: z.ZodObject<{
76
+ messageId: z.ZodString;
77
+ attachmentId: z.ZodString;
78
+ }, z.core.$strip>;
79
+ export type EmailGetAttachmentInput = z.infer<typeof emailGetAttachmentInput>;
80
+ export declare const emailGetAttachmentOutput: z.ZodObject<{
81
+ filename: z.ZodString;
82
+ contentType: z.ZodString;
83
+ data: z.ZodString;
84
+ }, z.core.$strip>;
85
+ export type EmailGetAttachmentOutput = z.infer<typeof emailGetAttachmentOutput>;
86
+ /**
87
+ * A mailbox as company code reaches it (`ctx.api.integration.emails[]`): reading its messages and their
88
+ * attachments. Sending is `ctx.api.email.send` (64 §15): opt-outs checked, stored, threaded, on the case.
89
+ */
90
+ export type EmailService = {
91
+ getMessage(input: EmailGetMessageInput): Promise<EmailGetMessageOutput>;
92
+ listMessages(input: EmailListMessagesInput): Promise<EmailListMessagesOutput>;
93
+ getAttachment(input: EmailGetAttachmentInput): Promise<EmailGetAttachmentOutput>;
94
+ };
95
+ /**
96
+ * The mail provider as the platform drives it: the reads, and handing an email to Gmail / Outlook as is
97
+ * (no opt-out check, no record). The platform's own; company code never reaches `sendEmail`.
98
+ */
99
+ export type EmailProviderService = EmailService & {
100
+ sendEmail(input: EmailSendEmailInput): Promise<EmailSendEmailOutput>;
101
+ };
102
+ /** The provider methods only the platform calls: left out of the company's script surface. */
103
+ export declare const EMAIL_PLATFORM_ONLY_METHODS: readonly ["sendEmail"];
104
+ export declare const emailMockService: EmailService;
105
+ export type EmailApi = IntegrationAccountFields & EmailService & {
106
+ readonly address: string;
107
+ readonly provider: EmailProvider;
108
+ };
109
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1,90 @@
1
+ import { z } from 'zod';
2
+ /** `hotmail` covers every Microsoft account (Outlook.com / Hotmail / M365). */
3
+ export const emailProvider = z.enum(['gmail', 'hotmail']);
4
+ export const emailSendEmailInput = z.object({
5
+ to: z.array(z.string()).min(1),
6
+ cc: z.array(z.string()).optional(),
7
+ bcc: z.array(z.string()).optional(),
8
+ subject: z.string(),
9
+ body: z.string(),
10
+ threadId: z.string().optional(),
11
+ inReplyTo: z.string().optional(),
12
+ references: z.string().optional(),
13
+ replyToId: z.string().optional(),
14
+ });
15
+ export const emailSendEmailOutput = z.object({
16
+ id: z.string(),
17
+ threadId: z.string().optional(),
18
+ });
19
+ export const emailGetMessageInput = z.object({
20
+ id: z.string(),
21
+ });
22
+ export const emailAttachment = z.object({
23
+ filename: z.string(),
24
+ contentType: z.string(),
25
+ attachmentId: z.string(),
26
+ isInline: z.boolean(),
27
+ size: z.number().optional(),
28
+ });
29
+ export const emailGetMessageOutput = z.object({
30
+ id: z.string(),
31
+ threadId: z.string(),
32
+ from: z.string(),
33
+ to: z.array(z.string()),
34
+ cc: z.array(z.string()),
35
+ bcc: z.array(z.string()),
36
+ subject: z.string(),
37
+ text: z.string(),
38
+ html: z.string(),
39
+ date: z.string(),
40
+ messageId: z.string(),
41
+ labelIds: z.array(z.string()).optional(),
42
+ attachments: z.array(emailAttachment),
43
+ /** The headers that mark automatic mail (Auto-Submitted, Precedence, List-Id, X-Autoreply…), lower-cased names. */
44
+ autoHeaders: z.record(z.string(), z.string()).optional(),
45
+ });
46
+ export const emailListMessagesInput = z.object({
47
+ maxResults: z.number().optional(),
48
+ query: z.string().optional(),
49
+ pageToken: z.string().optional(),
50
+ });
51
+ export const emailListMessagesOutput = z.object({
52
+ messages: z.array(z.object({ id: z.string(), threadId: z.string() })),
53
+ nextPageToken: z.string().optional(),
54
+ });
55
+ export const emailGetAttachmentInput = z.object({
56
+ messageId: z.string(),
57
+ attachmentId: z.string(),
58
+ });
59
+ export const emailGetAttachmentOutput = z.object({
60
+ filename: z.string(),
61
+ contentType: z.string(),
62
+ data: z.string(),
63
+ });
64
+ /** The provider methods only the platform calls: left out of the company's script surface. */
65
+ export const EMAIL_PLATFORM_ONLY_METHODS = ['sendEmail'];
66
+ export const emailMockService = {
67
+ async getMessage() {
68
+ return {
69
+ id: 'mock-email-id',
70
+ threadId: 'mock-thread',
71
+ from: 'sender@example.com',
72
+ to: ['intake@example.com'],
73
+ cc: [],
74
+ bcc: [],
75
+ subject: '',
76
+ text: '',
77
+ html: '',
78
+ date: '1970-01-01T00:00:00.000Z',
79
+ messageId: '',
80
+ attachments: [],
81
+ };
82
+ },
83
+ async listMessages() {
84
+ return { messages: [] };
85
+ },
86
+ async getAttachment() {
87
+ return { filename: 'file', contentType: 'application/octet-stream', data: '' };
88
+ },
89
+ };
90
+ //# sourceMappingURL=email.js.map