@hitch42/applet 0.1.1-beta.15 → 0.1.1-beta.17

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 (55) hide show
  1. package/dist/_internal/log-context.d.ts +0 -2
  2. package/dist/_internal/log-context.js +1 -1
  3. package/dist/_internal/server.d.ts +10 -1
  4. package/dist/_internal/server.js +17 -3
  5. package/dist/applet.js +12 -12
  6. package/dist/auth-D3CrCtZq.js +21 -0
  7. package/dist/{build-BkhBHdMs.js → build-XHoa_sJL.js} +1 -1
  8. package/dist/build-ueR7XjZT.js +2 -0
  9. package/dist/{ci-BKw14X2h.js → ci-B5-mH-YW.js} +1 -1
  10. package/dist/client.d.ts +3 -3
  11. package/dist/contract-BbOj5EB7.js +23 -0
  12. package/dist/{contract-CZdT22tB.d.ts → contract-D9wEvxGI.d.ts} +1 -1
  13. package/dist/{deploy-D5SBBd-j.js → deploy-Da93able.js} +28 -4
  14. package/dist/device-BgIfytaR.js +135 -0
  15. package/dist/email-protocol-B9u_dh2p.d.ts +202 -0
  16. package/dist/{generate-MWjUbZnO.js → generate-BV_emZgy.js} +39 -13
  17. package/dist/generate-C9bWqdaB.js +2 -0
  18. package/dist/hitch-file-url-BPKj9zVG.js +25 -0
  19. package/dist/index.d.ts +15 -25
  20. package/dist/index.js +80 -192
  21. package/dist/{init-Dw7GEI5v.js → init-BGQ_bP44.js} +5 -5
  22. package/dist/{manifest-CuY3ICpN.js → load-config-Dkr2VxZN.js} +37 -2
  23. package/dist/{log-context-zu8U9Sjm.js → log-context-DWznGjfz.js} +1 -5
  24. package/dist/{login-CUx3TmFQ.js → login-CceGvlMi.js} +3 -1
  25. package/dist/{logs-BySh9fnH.js → logs-DOkT5ots.js} +3 -3
  26. package/dist/{manifest-ARAy2HP7.d.ts → manifest-BSUtHbu-.d.ts} +1 -4
  27. package/dist/markdown-CwlqzBtP.js +88 -0
  28. package/dist/markdown-DSHOQIOb.d.ts +14 -0
  29. package/dist/markdown-editor-BmEaBzd7.d.ts +27 -0
  30. package/dist/markdown-editor-C5mLHGqu.js +428 -0
  31. package/dist/{project-NcWw8SwL.js → project-CCVqCCgU.js} +3 -2
  32. package/dist/react/markdown-editor.d.ts +2 -0
  33. package/dist/react/markdown-editor.js +2 -0
  34. package/dist/react/markdown.d.ts +2 -0
  35. package/dist/react/markdown.js +2 -0
  36. package/dist/react.d.ts +2 -37
  37. package/dist/react.js +2 -534
  38. package/dist/{schedules-B_p9U-vM.js → schedules-D6-3v-Az.js} +1 -1
  39. package/dist/server.d.ts +3 -3
  40. package/dist/server.js +1 -1
  41. package/dist/store-B8N_8JIN.js +196 -0
  42. package/dist/{upload-DKZzz5kW.d.ts → upload-D_kkmne_.d.ts} +5 -9
  43. package/dist/{variables-D9nEFyOK.js → variables-BSFZnLxY.js} +2 -2
  44. package/dist/vite.d.ts +1 -1
  45. package/dist/vite.js +165 -35
  46. package/dist/workspace-8yqXsvce.js +31 -0
  47. package/package.json +13 -1
  48. package/scaffold/.agents/skills/hitch-applets/references/markdown.md +20 -2
  49. package/dist/build-D7FDW8iC.js +0 -2
  50. package/dist/email-WA4jnzZ0.js +0 -211
  51. package/dist/email-protocol-DqJ6YCiC.d.ts +0 -230
  52. package/dist/generate-WYS-jtPH.js +0 -2
  53. package/dist/load-config-BeQZ2yOa.js +0 -27
  54. package/dist/me-BW7Paary.js +0 -32
  55. package/dist/workspace-D0dnnlxL.js +0 -385
@@ -1,11 +1,15 @@
1
- import { f as resolveInstanceUrl, l as organizationInstanceUrl, n as fetchWithOrgAuth } from "./workspace-D0dnnlxL.js";
2
- import { i as loadGitHubActionsBuildInputs, n as githubActionsContext } from "./ci-BKw14X2h.js";
3
- import { r as prepareAppletProject } from "./project-NcWw8SwL.js";
4
- import { t as loadAppletConfig } from "./load-config-BeQZ2yOa.js";
1
+ import { a as organizationInstanceUrl, c as resolveInstanceUrl } from "./store-B8N_8JIN.js";
2
+ import { t as fetchWithOrgAuth } from "./auth-D3CrCtZq.js";
3
+ import { t as loadAppletConfig } from "./load-config-Dkr2VxZN.js";
4
+ import { i as loadGitHubActionsBuildInputs, n as githubActionsContext } from "./ci-B5-mH-YW.js";
5
+ import { r as prepareAppletProject } from "./project-CCVqCCgU.js";
5
6
  import { createRequire } from "node:module";
7
+ import { isContractProcedure, minifyContractRouter } from "@orpc/contract";
8
+ import { randomUUID } from "node:crypto";
6
9
  import { existsSync } from "node:fs";
7
10
  import { access, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
8
11
  import { dirname, resolve } from "node:path";
12
+ import { pathToFileURL } from "node:url";
9
13
  import { execFile } from "node:child_process";
10
14
  import { promisify } from "node:util";
11
15
  import { createClient } from "@hey-api/openapi-ts";
@@ -361,6 +365,26 @@ async function writeRegisterDeclaration(outDir, catalog) {
361
365
  //#region src/typegen/generate.ts
362
366
  const execFileAsync = promisify(execFile);
363
367
  const require = createRequire(import.meta.url);
368
+ function routesModuleSource(routes) {
369
+ return `// Generated by applet generate — do not edit.\nexport const contract = ${JSON.stringify(routes, null, 2)} as const;\n`;
370
+ }
371
+ function stripRouteData(router) {
372
+ if (isContractProcedure(router)) {
373
+ const { errorMap, meta, route } = router["~orpc"];
374
+ const { method, path, inputStructure, outputStructure } = route;
375
+ return { "~orpc": {
376
+ errorMap,
377
+ meta,
378
+ route: {
379
+ method,
380
+ path,
381
+ inputStructure,
382
+ outputStructure
383
+ }
384
+ } };
385
+ }
386
+ return Object.fromEntries(Object.entries(router).map(([name, child]) => [name, stripRouteData(child)]));
387
+ }
364
388
  async function generateRouteTree(root) {
365
389
  await execFileAsync(process.execPath, [resolve(dirname(require.resolve("@tanstack/router-cli/package.json")), "bin/tsr.cjs"), "generate"], { cwd: root });
366
390
  }
@@ -447,6 +471,8 @@ async function generateContract(spec, outDir) {
447
471
  }
448
472
  const orpcPath = resolve(outDir, "orpc.gen.ts");
449
473
  if (!await fileExists(orpcPath)) await Promise.all([writeFile(orpcPath, "// Generated by applet generate — no operations in spec.\nexport const contract = {} as const;\n"), fileExists(resolve(outDir, "zod.gen.ts")).then((exists) => exists ? void 0 : writeFile(resolve(outDir, "zod.gen.ts"), "// Generated by applet generate — no schemas in spec.\nexport {};\n"))]);
474
+ const { contract } = await import(`${pathToFileURL(orpcPath).href}?${randomUUID()}`);
475
+ await writeFile(resolve(outDir, "routes.gen.ts"), routesModuleSource(stripRouteData(minifyContractRouter(contract))));
450
476
  }
451
477
  async function writeContractFiles(outDir, manifest, spec) {
452
478
  guardManifestForSpec(spec, manifest);
@@ -455,22 +481,22 @@ async function writeContractFiles(outDir, manifest, spec) {
455
481
  await generateContract(preparedSpec, outDir);
456
482
  await writeManifestGen(outDir, manifest);
457
483
  await writeRegisterDeclaration(outDir, catalog);
484
+ const hasBatch = Object.hasOwn(preparedSpec.paths, "/v1/batch");
458
485
  await writeFile(resolve(outDir, "index.ts"), `// Generated by applet generate — do not edit.
459
486
  import { emailContract, filesContract as files, meContract as me, pruneContract, registerHitchContract, teamsContract as teams, telephonyContract as telephony } from "@hitch42/applet";
460
487
  import manifest from "./manifest.gen.ts";
488
+ // The runtime needs only the routes; the zod contract gives the types and stays out of the bundle.
489
+ import type { contract as generated } from "./orpc.gen.ts";
490
+ import { contract as routes } from "./routes.gen.ts";
461
491
 
462
- ${Object.hasOwn(preparedSpec.paths, "/v1/batch") ? `import { contract as generated } from "./orpc.gen.ts";
463
-
464
- const { batch, ...records } = generated;
465
-
466
- export const contract = { records, batch, email: emailContract(manifest.code), files, me, teams, telephony } as const;` : `import { contract as records } from "./orpc.gen.ts";
492
+ const platform = { email: emailContract(manifest.code), files, me, teams, telephony } as const;
493
+ ${hasBatch ? `const { batch, ...records } = routes;
467
494
 
468
- export const contract = { records, email: emailContract(manifest.code), files, me, teams, telephony } as const;`}
469
- registerHitchContract(pruneContract(contract, manifest));
495
+ registerHitchContract(pruneContract({ records, batch, ...platform }, manifest));` : "registerHitchContract(pruneContract({ records: routes, ...platform }, manifest));"}
470
496
 
471
497
  declare module "@hitch42/applet" {
472
498
  interface HitchRegister {
473
- contract: typeof contract;
499
+ contract: ${hasBatch ? "{ records: Omit<typeof generated, \"batch\">; batch: (typeof generated)[\"batch\"] }" : "{ records: typeof generated }"} & typeof platform;
474
500
  }
475
501
  }
476
502
 
@@ -536,4 +562,4 @@ async function runGenerate() {
536
562
  }
537
563
  }
538
564
  //#endregion
539
- export { prepareRecordSpec as a, writeClientEntry as c, writeRegisterDeclaration as i, writeManifestGen as l, runGenerate as n, recordOperation as o, syncContract as r, writeAppletRoot as s, generateContract as t, writeServerEntry as u };
565
+ export { writeRegisterDeclaration as a, writeAppletRoot as c, writeServerEntry as d, syncContract as i, writeClientEntry as l, routesModuleSource as n, prepareRecordSpec as o, runGenerate as r, recordOperation as s, generateContract as t, writeManifestGen as u };
@@ -0,0 +1,2 @@
1
+ import { r as runGenerate } from "./generate-BV_emZgy.js";
2
+ export { runGenerate };
@@ -0,0 +1,25 @@
1
+ //#region src/react/hitch-file-url.ts
2
+ const HITCH_FILE_PREFIX = "hitch-file://";
3
+ const DOWNLOAD_URL_TTL_MS = 3e6;
4
+ const downloadUrlCache = /* @__PURE__ */ new Map();
5
+ function cachedDownloadUrl(files, id) {
6
+ const cached = downloadUrlCache.get(id);
7
+ if (cached !== void 0 && cached.expiresAt > Date.now()) return cached.request;
8
+ const request = files.download(id).then((file) => file.downloadUrl);
9
+ downloadUrlCache.set(id, {
10
+ request,
11
+ expiresAt: Date.now() + DOWNLOAD_URL_TTL_MS
12
+ });
13
+ return request;
14
+ }
15
+ function seedDownloadUrl(id, url) {
16
+ downloadUrlCache.set(id, {
17
+ request: Promise.resolve(url),
18
+ expiresAt: Date.now() + DOWNLOAD_URL_TTL_MS
19
+ });
20
+ }
21
+ function invalidateDownloadUrl(id) {
22
+ downloadUrlCache.delete(id);
23
+ }
24
+ //#endregion
25
+ export { seedDownloadUrl as i, cachedDownloadUrl as n, invalidateDownloadUrl as r, HITCH_FILE_PREFIX as t };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { _ as RegisteredWorkflows, a as AppletSourceDefinition, c as appletManifestSchema, d as RegisteredCatalog, f as RegisteredContract, g as RegisteredVariables, h as RegisteredVariableKeys, i as AppletPackages, l as appletSourceDefinitionSchema, m as RegisteredRouter, n as AppletManifest, o as RegisteredAppletSourceDefinition, p as RegisteredManifest, r as AppletManifestObject, s as appletDefinitionSchema, t as AppletDefinition, u as HitchRegister, v as registerHitchContract } from "./manifest-ARAy2HP7.js";
2
- import { n as pruneContract, t as NarrowContract } from "./contract-CZdT22tB.js";
3
- import { a as UploadedHitchFile, c as createFileOutputSchema, d as getFileOutputSchema, i as UploadProgress, l as fileSchema, n as FilesUpload, r as UploadFileOptions, s as uploadFile, t as FilesClient, u as filesContract } from "./upload-DKZzz5kW.js";
4
- import { A as listEmailTrackersOutputSchema, C as hitchEmailAddressSchema, D as hitchEmailThreadSchema, E as hitchEmailMessageSchema, F as listHitchEmailThreadsOutputSchema, L as markEmailTrackerSentInputSchema, M as listHitchEmailMessagesInputSchema, N as listHitchEmailMessagesOutputSchema, O as hitchMailboxSchema, P as listHitchEmailThreadsInputSchema, R as sendHitchEmailInputSchema, S as getHitchEmailRawOutputSchema, T as hitchEmailIdInputSchema, _ as emailTagKeySchema, a as HitchEmailAddress, b as getEmailTrackerInputSchema, c as HitchEmailThread, d as ListHitchEmailMessagesInput, f as ListHitchEmailThreadsInput, g as emailContract, h as createEmailPixelOutputSchema, i as EmailTracker, j as listHitchEmailMailboxesOutputSchema, k as listEmailTrackersInputSchema, l as HitchMailbox, m as createEmailPixelInputSchema, n as TelephonyMessageReceivedEvent, o as HitchEmailAttachment, p as SendHitchEmailInput, r as EmailContract, s as HitchEmailMessage, t as EmailMessageReceivedEvent, u as ListEmailTrackersOutput, v as emailTagsSchema, w as hitchEmailAttachmentSchema, x as getHitchEmailAttachmentOutputSchema, y as emailTrackerSchema } from "./email-protocol-DqJ6YCiC.js";
5
- import { ContractProcedure, Meta } from "@orpc/contract";
6
- import { z } from "zod";
1
+ import { a as AppletSourceDefinition, c as RegisteredCatalog, d as RegisteredRouter, f as RegisteredVariableKeys, h as registerHitchContract, i as AppletPackages, l as RegisteredContract, m as RegisteredWorkflows, n as AppletManifest, o as RegisteredAppletSourceDefinition, p as RegisteredVariables, r as AppletManifestObject, s as HitchRegister, t as AppletDefinition, u as RegisteredManifest } from "./manifest-BSUtHbu-.js";
2
+ import { n as pruneContract, t as NarrowContract } from "./contract-D9wEvxGI.js";
3
+ import { a as UploadedHitchFile, c as filesContract, i as UploadProgress, n as FilesUpload, r as UploadFileOptions, s as uploadFile, t as FilesClient } from "./upload-D_kkmne_.js";
4
+ import { a as EmailTracker, c as HitchEmailMessage, f as ListEmailTrackersOutput, g as emailContract, h as SendHitchEmailInput, i as EmailContract, l as HitchEmailThread, m as ListHitchEmailThreadsInput, n as TelephonyMessageReceivedEvent, o as HitchEmailAddress, p as ListHitchEmailMessagesInput, s as HitchEmailAttachment, t as EmailMessageReceivedEvent, u as HitchMailbox } from "./email-protocol-B9u_dh2p.js";
5
+ import { ContractProcedure, Meta, Schema } from "@orpc/contract";
7
6
  //#region ../shared/auth/src/workspace.d.mts
8
7
  interface HitchConfig {
9
8
  sdk: string;
@@ -35,9 +34,8 @@ type HitchMe = {
35
34
  } | null;
36
35
  multiOrg: boolean;
37
36
  };
38
- declare const meSchema: z.ZodType<HitchMe, HitchMe>;
39
37
  type MeContract = {
40
- get: ContractProcedure<z.ZodType<void, void>, z.ZodType<HitchMe, HitchMe>, Record<never, never>, Meta>;
38
+ get: ContractProcedure<Schema<void, void>, Schema<HitchMe, HitchMe>, Record<never, never>, Meta>;
41
39
  };
42
40
  declare const meContract: MeContract;
43
41
  //#endregion
@@ -129,24 +127,18 @@ type CallsOutput = {
129
127
  data: HitchCall[];
130
128
  nextCursor: string | null;
131
129
  };
132
- declare const hitchPhoneNumberSchema: z.ZodType<HitchPhoneNumber, HitchPhoneNumber>;
133
- declare const hitchMessageSchema: z.ZodType<HitchMessage, HitchMessage>;
134
- declare const listHitchNumbersOutputSchema: z.ZodType<NumbersOutput, NumbersOutput>;
135
- declare const listHitchMessagesOutputSchema: z.ZodType<MessagesOutput, MessagesOutput>;
136
- declare const listHitchMessagesInputSchema: z.ZodType<ListHitchMessagesInput, ListHitchMessagesInput>;
137
- declare const sendHitchMessageInputSchema: z.ZodType<SendHitchMessageInput, SendHitchMessageInput>;
138
130
  type TelephonyContract = {
139
131
  calls: {
140
- get: ContractProcedure<z.ZodType<MessageIdInput, MessageIdInput>, z.ZodType<HitchCall, HitchCall>, Record<never, never>, Meta>;
141
- list: ContractProcedure<z.ZodType<ListHitchCallsInput, ListHitchCallsInput>, z.ZodType<CallsOutput, CallsOutput>, Record<never, never>, Meta>;
132
+ get: ContractProcedure<Schema<MessageIdInput, MessageIdInput>, Schema<HitchCall, HitchCall>, Record<never, never>, Meta>;
133
+ list: ContractProcedure<Schema<ListHitchCallsInput, ListHitchCallsInput>, Schema<CallsOutput, CallsOutput>, Record<never, never>, Meta>;
142
134
  };
143
135
  numbers: {
144
- list: ContractProcedure<z.ZodType<void, void>, z.ZodType<NumbersOutput, NumbersOutput>, Record<never, never>, Meta>;
136
+ list: ContractProcedure<Schema<void, void>, Schema<NumbersOutput, NumbersOutput>, Record<never, never>, Meta>;
145
137
  };
146
138
  messages: {
147
- get: ContractProcedure<z.ZodType<MessageIdInput, MessageIdInput>, z.ZodType<HitchMessage, HitchMessage>, Record<never, never>, Meta>;
148
- list: ContractProcedure<z.ZodType<ListHitchMessagesInput, ListHitchMessagesInput>, z.ZodType<MessagesOutput, MessagesOutput>, Record<never, never>, Meta>;
149
- send: ContractProcedure<z.ZodType<SendHitchMessageInput, SendHitchMessageInput>, z.ZodType<HitchMessage, HitchMessage>, Record<never, never>, Meta>;
139
+ get: ContractProcedure<Schema<MessageIdInput, MessageIdInput>, Schema<HitchMessage, HitchMessage>, Record<never, never>, Meta>;
140
+ list: ContractProcedure<Schema<ListHitchMessagesInput, ListHitchMessagesInput>, Schema<MessagesOutput, MessagesOutput>, Record<never, never>, Meta>;
141
+ send: ContractProcedure<Schema<SendHitchMessageInput, SendHitchMessageInput>, Schema<HitchMessage, HitchMessage>, Record<never, never>, Meta>;
150
142
  };
151
143
  };
152
144
  declare const telephonyContract: TelephonyContract;
@@ -173,14 +165,12 @@ type TeamsOutput = {
173
165
  type TeamMembersOutput = {
174
166
  data: HitchTeamMember[];
175
167
  };
176
- declare const teamSchema: z.ZodType<HitchTeam, HitchTeam>;
177
- declare const teamMemberSchema: z.ZodType<HitchTeamMember, HitchTeamMember>;
178
168
  type TeamsContract = {
179
- list: ContractProcedure<z.ZodType<void, void>, z.ZodType<TeamsOutput, TeamsOutput>, Record<never, never>, Meta>;
169
+ list: ContractProcedure<Schema<void, void>, Schema<TeamsOutput, TeamsOutput>, Record<never, never>, Meta>;
180
170
  members: {
181
- list: ContractProcedure<z.ZodType<TeamIdInput, TeamIdInput>, z.ZodType<TeamMembersOutput, TeamMembersOutput>, Record<never, never>, Meta>;
171
+ list: ContractProcedure<Schema<TeamIdInput, TeamIdInput>, Schema<TeamMembersOutput, TeamMembersOutput>, Record<never, never>, Meta>;
182
172
  };
183
173
  };
184
174
  declare const teamsContract: TeamsContract;
185
175
  //#endregion
186
- export { type AppletDefinition, type AppletManifest, type AppletManifestObject, type AppletPackages, type AppletSourceDefinition, type EmailContract, type EmailMessageReceivedEvent, type EmailTracker, type FilesClient, type FilesUpload, type HitchConfig, type HitchEmailAddress, type HitchEmailAttachment, type HitchEmailMessage, type HitchEmailThread, type HitchMailbox, type HitchMe, type HitchMessage, type HitchPhoneNumber, type HitchRegister, type HitchTeam, type HitchTeamMember, type ListEmailTrackersOutput, type ListHitchEmailMessagesInput, type ListHitchEmailThreadsInput, type ListHitchMessagesInput, type NarrowContract, type RegisteredAppletSourceDefinition, type RegisteredCatalog, type RegisteredContract, type RegisteredManifest, type RegisteredRouter, type RegisteredVariableKeys, type RegisteredVariables, type RegisteredWorkflows, type SendHitchEmailInput, type SendHitchMessageInput, type TelephonyContract, type TelephonyMessageReceivedEvent, type UploadFileOptions, type UploadProgress, type UploadedHitchFile, appletDefinitionSchema, appletManifestSchema, appletSourceDefinitionSchema, createEmailPixelInputSchema, createEmailPixelOutputSchema, createFileOutputSchema, emailContract, emailTagKeySchema, emailTagsSchema, emailTrackerSchema, fileSchema, filesContract, getEmailTrackerInputSchema, getFileOutputSchema, getHitchEmailAttachmentOutputSchema, getHitchEmailRawOutputSchema, hitchEmailAddressSchema, hitchEmailAttachmentSchema, hitchEmailIdInputSchema, hitchEmailMessageSchema, hitchEmailThreadSchema, hitchMailboxSchema, hitchMessageSchema, hitchPhoneNumberSchema, listEmailTrackersInputSchema, listEmailTrackersOutputSchema, listHitchEmailMailboxesOutputSchema, listHitchEmailMessagesInputSchema, listHitchEmailMessagesOutputSchema, listHitchEmailThreadsInputSchema, listHitchEmailThreadsOutputSchema, listHitchMessagesInputSchema, listHitchMessagesOutputSchema, listHitchNumbersOutputSchema, markEmailTrackerSentInputSchema, meContract, meSchema, pruneContract, registerHitchContract, sendHitchEmailInputSchema, sendHitchMessageInputSchema, teamMemberSchema, teamSchema, teamsContract, telephonyContract, uploadFile };
176
+ export { type AppletDefinition, type AppletManifest, type AppletManifestObject, type AppletPackages, type AppletSourceDefinition, type EmailContract, type EmailMessageReceivedEvent, type EmailTracker, type FilesClient, type FilesUpload, type HitchConfig, type HitchEmailAddress, type HitchEmailAttachment, type HitchEmailMessage, type HitchEmailThread, type HitchMailbox, type HitchMe, type HitchMessage, type HitchPhoneNumber, type HitchRegister, type HitchTeam, type HitchTeamMember, type ListEmailTrackersOutput, type ListHitchEmailMessagesInput, type ListHitchEmailThreadsInput, type ListHitchMessagesInput, type NarrowContract, type RegisteredAppletSourceDefinition, type RegisteredCatalog, type RegisteredContract, type RegisteredManifest, type RegisteredRouter, type RegisteredVariableKeys, type RegisteredVariables, type RegisteredWorkflows, type SendHitchEmailInput, type SendHitchMessageInput, type TelephonyContract, type TelephonyMessageReceivedEvent, type UploadFileOptions, type UploadProgress, type UploadedHitchFile, emailContract, filesContract, meContract, pruneContract, registerHitchContract, teamsContract, telephonyContract, uploadFile };
package/dist/index.js CHANGED
@@ -1,252 +1,140 @@
1
1
  import { i as registerHitchContract, t as uploadFile } from "./upload-DRbVhuDm.js";
2
- import { S as listHitchEmailThreadsOutputSchema, T as sendHitchEmailInputSchema, _ as listEmailTrackersOutputSchema, a as emailTagsSchema, b as listHitchEmailMessagesOutputSchema, c as getHitchEmailAttachmentOutputSchema, d as hitchEmailAttachmentSchema, f as hitchEmailIdInputSchema, g as listEmailTrackersInputSchema, h as hitchMailboxSchema, i as emailTagKeySchema, l as getHitchEmailRawOutputSchema, m as hitchEmailThreadSchema, n as createEmailPixelOutputSchema, o as emailTrackerSchema, p as hitchEmailMessageSchema, r as emailContract, s as getEmailTrackerInputSchema, t as createEmailPixelInputSchema, u as hitchEmailAddressSchema, v as listHitchEmailMailboxesOutputSchema, w as markEmailTrackerSentInputSchema, x as listHitchEmailThreadsInputSchema, y as listHitchEmailMessagesInputSchema } from "./email-WA4jnzZ0.js";
3
- import { n as meSchema, t as meContract } from "./me-BW7Paary.js";
4
- import { n as appletManifestSchema, r as appletSourceDefinitionSchema, t as appletDefinitionSchema } from "./manifest-CuY3ICpN.js";
5
- import { oc } from "@orpc/contract";
6
- import { z } from "zod";
7
- //#region src/hitch/contract.ts
8
- function isObject(value) {
9
- return value !== null && typeof value === "object" && !Array.isArray(value);
10
- }
11
- function pruneContract(contract, manifest) {
12
- if (!isObject(contract) || !isObject(contract.records)) throw new Error("Hitch contract must contain a \"records\" router.");
13
- const contractRecords = contract.records;
14
- const records = Object.fromEntries(manifest.objects.map((manifestObject) => {
15
- const procedures = contractRecords[manifestObject.code];
16
- if (!isObject(procedures)) throw new Error(`Hitch contract object "${manifestObject.code}" is missing.`);
17
- const pruned = { ...procedures };
18
- if (!manifestObject.canCreate) delete pruned.create;
19
- if (!manifestObject.canDelete) delete pruned.delete;
20
- if (manifestObject.readWrite.length === 0) {
21
- delete pruned.update;
22
- delete pruned.updateWhere;
2
+ import { t as pruneContract } from "./contract-BbOj5EB7.js";
3
+ import { oc, type } from "@orpc/contract";
4
+ //#region src/hitch/email.ts
5
+ function emailContract(appletCode) {
6
+ const path = `/v1/applets/${encodeURIComponent(appletCode)}/email/tracking`;
7
+ return {
8
+ mailboxes: { list: oc.route({
9
+ method: "GET",
10
+ path: "/v1/email/mailboxes"
11
+ }).input(type()).output(type()) },
12
+ threads: {
13
+ list: oc.route({
14
+ method: "GET",
15
+ path: "/v1/email/threads"
16
+ }).input(type()).output(type()),
17
+ get: oc.route({
18
+ method: "GET",
19
+ path: "/v1/email/threads/{id}"
20
+ }).input(type()).output(type())
21
+ },
22
+ messages: {
23
+ list: oc.route({
24
+ method: "GET",
25
+ path: "/v1/email/messages"
26
+ }).input(type()).output(type()),
27
+ get: oc.route({
28
+ method: "GET",
29
+ path: "/v1/email/messages/{id}"
30
+ }).input(type()).output(type()),
31
+ send: oc.route({
32
+ method: "POST",
33
+ path: "/v1/email/messages",
34
+ successStatus: 201
35
+ }).input(type()).output(type()),
36
+ raw: oc.route({
37
+ method: "GET",
38
+ path: "/v1/email/messages/{id}/raw"
39
+ }).input(type()).output(type())
40
+ },
41
+ attachments: { get: oc.route({
42
+ method: "GET",
43
+ path: "/v1/email/attachments/{id}"
44
+ }).input(type()).output(type()) },
45
+ tracking: {
46
+ createPixel: oc.route({
47
+ method: "POST",
48
+ path: `${path}/pixels`,
49
+ successStatus: 201
50
+ }).input(type()).output(type()),
51
+ markSent: oc.route({
52
+ method: "POST",
53
+ path: `${path}/{id}/sent`
54
+ }).input(type()).output(type()),
55
+ get: oc.route({
56
+ method: "GET",
57
+ path: `${path}/{id}`
58
+ }).input(type()).output(type()),
59
+ list: oc.route({
60
+ method: "POST",
61
+ path: `${path}/list`
62
+ }).input(type()).output(type())
23
63
  }
24
- return [manifestObject.code, pruned];
25
- }));
26
- return Object.assign({}, contract, { records });
64
+ };
27
65
  }
28
66
  //#endregion
29
67
  //#region src/hitch/files.ts
30
- const fileFields = {
31
- id: z.string(),
32
- organizationId: z.string(),
33
- key: z.string(),
34
- filename: z.string(),
35
- contentType: z.string(),
36
- uploadedBy: z.string().nullable(),
37
- createdAt: z.string(),
38
- updatedAt: z.string()
39
- };
40
- const fileSchema = z.object({
41
- ...fileFields,
42
- sizeBytes: z.number(),
43
- arrivedAt: z.string()
44
- });
45
- const pendingFileSchema = z.object({
46
- ...fileFields,
47
- sizeBytes: z.null(),
48
- arrivedAt: z.null()
49
- });
50
- const createFileInputSchema = z.object({ body: z.object({
51
- filename: z.string().trim().min(1),
52
- contentType: z.string().trim().min(1)
53
- }) });
54
- const createFileOutputSchema = z.object({
55
- data: pendingFileSchema,
56
- uploadUrl: z.string()
57
- });
58
- const fileIdInputSchema = z.object({ params: z.object({ id: z.uuid() }) });
59
- const getFileOutputSchema = z.object({
60
- data: fileSchema,
61
- downloadUrl: z.string()
62
- });
63
68
  const filesContract = {
64
69
  create: oc.route({
65
70
  method: "POST",
66
71
  path: "/v1/files",
67
72
  successStatus: 201,
68
73
  inputStructure: "detailed"
69
- }).input(createFileInputSchema).output(createFileOutputSchema),
74
+ }).input(type()).output(type()),
70
75
  confirm: oc.route({
71
76
  method: "POST",
72
77
  path: "/v1/files/{id}/confirm",
73
78
  successStatus: 200,
74
79
  inputStructure: "detailed"
75
- }).input(fileIdInputSchema).output(getFileOutputSchema),
80
+ }).input(type()).output(type()),
76
81
  get: oc.route({
77
82
  method: "GET",
78
83
  path: "/v1/files/{id}",
79
84
  inputStructure: "detailed"
80
- }).input(fileIdInputSchema).output(getFileOutputSchema)
85
+ }).input(type()).output(type())
81
86
  };
82
87
  //#endregion
88
+ //#region src/hitch/me.ts
89
+ const meContract = { get: oc.route({
90
+ method: "GET",
91
+ path: "/v1/me"
92
+ }).input(type()).output(type()) };
93
+ //#endregion
83
94
  //#region src/hitch/telephony.ts
84
- const hitchPhoneNumberSchema = z.object({
85
- id: z.uuid(),
86
- e164: z.string(),
87
- label: z.string(),
88
- enabled: z.boolean(),
89
- assignedTo: z.uuid().nullable(),
90
- canRead: z.boolean(),
91
- canSend: z.boolean(),
92
- canCall: z.boolean(),
93
- voiceEnabled: z.boolean()
94
- });
95
- const hitchCallSchema = z.object({
96
- id: z.uuid(),
97
- numberId: z.uuid(),
98
- direction: z.enum(["inbound", "outbound"]),
99
- status: z.enum([
100
- "starting",
101
- "ringing",
102
- "active",
103
- "ended",
104
- "missed",
105
- "failed"
106
- ]),
107
- from: z.string(),
108
- to: z.string(),
109
- userId: z.uuid().nullable(),
110
- answeredAt: z.string().nullable(),
111
- endedAt: z.string().nullable(),
112
- durationSeconds: z.number().nullable(),
113
- voicemailSeconds: z.number().nullable(),
114
- hangupCause: z.string().nullable(),
115
- record: z.boolean(),
116
- hasRecording: z.boolean(),
117
- transcriptStatus: z.enum([
118
- "pending",
119
- "done",
120
- "failed"
121
- ]).nullable(),
122
- transcript: z.object({ segments: z.array(z.object({
123
- side: z.enum(["member", "customer"]),
124
- speaker: z.number(),
125
- start: z.number(),
126
- end: z.number(),
127
- text: z.string()
128
- })) }).nullable(),
129
- createdAt: z.string()
130
- });
131
- const hitchMessageSchema = z.object({
132
- id: z.uuid(),
133
- numberId: z.uuid(),
134
- direction: z.enum(["inbound", "outbound"]),
135
- status: z.enum([
136
- "pending",
137
- "unknown",
138
- "accepted",
139
- "sent",
140
- "delivered",
141
- "unconfirmed",
142
- "failed",
143
- "received"
144
- ]),
145
- from: z.string(),
146
- to: z.string(),
147
- body: z.string().nullable(),
148
- redacted: z.boolean(),
149
- userId: z.uuid().nullable(),
150
- appletId: z.uuid().nullable(),
151
- requestId: z.string().nullable(),
152
- errorCode: z.string().nullable(),
153
- errorDetail: z.string().nullable(),
154
- statusAt: z.string().nullable(),
155
- createdAt: z.string()
156
- });
157
- const listHitchNumbersOutputSchema = z.object({ data: z.array(hitchPhoneNumberSchema) });
158
- const listHitchMessagesOutputSchema = z.object({
159
- data: z.array(hitchMessageSchema),
160
- nextCursor: z.string().nullable()
161
- });
162
- const listHitchCallsOutputSchema = z.object({
163
- data: z.array(hitchCallSchema),
164
- nextCursor: z.string().nullable()
165
- });
166
- const idInputSchema = z.object({ id: z.uuid() });
167
- const listInputFields = {
168
- numberId: z.uuid().optional(),
169
- userId: z.uuid().optional(),
170
- direction: z.enum(["inbound", "outbound"]).optional(),
171
- since: z.iso.datetime().optional(),
172
- until: z.iso.datetime().optional(),
173
- cursor: z.string().optional(),
174
- limit: z.number().int().min(1).max(200).optional()
175
- };
176
- const listHitchMessagesInputSchema = z.object(listInputFields);
177
- const listHitchCallsInputSchema = z.object({
178
- ...listInputFields,
179
- status: z.enum([
180
- "starting",
181
- "ringing",
182
- "active",
183
- "ended",
184
- "missed",
185
- "failed"
186
- ]).optional()
187
- });
188
- const sendHitchMessageInputSchema = z.object({
189
- numberId: z.uuid(),
190
- to: z.string(),
191
- body: z.string().min(1).max(1600),
192
- requestId: z.string().min(1).max(200).optional()
193
- });
194
95
  const telephonyContract = {
195
96
  calls: {
196
97
  get: oc.route({
197
98
  method: "GET",
198
99
  path: "/v1/telephony/calls/{id}"
199
- }).input(idInputSchema).output(hitchCallSchema),
100
+ }).input(type()).output(type()),
200
101
  list: oc.route({
201
102
  method: "GET",
202
103
  path: "/v1/telephony/calls"
203
- }).input(listHitchCallsInputSchema).output(listHitchCallsOutputSchema)
104
+ }).input(type()).output(type())
204
105
  },
205
106
  numbers: { list: oc.route({
206
107
  method: "GET",
207
108
  path: "/v1/telephony/numbers"
208
- }).input(z.void()).output(listHitchNumbersOutputSchema) },
109
+ }).input(type()).output(type()) },
209
110
  messages: {
210
111
  get: oc.route({
211
112
  method: "GET",
212
113
  path: "/v1/telephony/messages/{id}"
213
- }).input(idInputSchema).output(hitchMessageSchema),
114
+ }).input(type()).output(type()),
214
115
  list: oc.route({
215
116
  method: "GET",
216
117
  path: "/v1/telephony/messages"
217
- }).input(listHitchMessagesInputSchema).output(listHitchMessagesOutputSchema),
118
+ }).input(type()).output(type()),
218
119
  send: oc.route({
219
120
  method: "POST",
220
121
  path: "/v1/telephony/messages",
221
122
  successStatus: 201
222
- }).input(sendHitchMessageInputSchema).output(hitchMessageSchema)
123
+ }).input(type()).output(type())
223
124
  }
224
125
  };
225
126
  //#endregion
226
127
  //#region src/hitch/teams.ts
227
- const teamSchema = z.object({
228
- id: z.uuid(),
229
- name: z.string()
230
- });
231
- const teamMemberSchema = z.object({
232
- userId: z.uuid(),
233
- firstName: z.string(),
234
- lastName: z.string(),
235
- email: z.email()
236
- });
237
- const teamsOutputSchema = z.object({ data: z.array(teamSchema) });
238
- const teamIdInputSchema = z.object({ params: z.object({ id: z.uuid() }) });
239
- const teamMembersOutputSchema = z.object({ data: z.array(teamMemberSchema) });
240
128
  const teamsContract = {
241
129
  list: oc.route({
242
130
  method: "GET",
243
131
  path: "/v1/teams"
244
- }).input(z.void()).output(teamsOutputSchema),
132
+ }).input(type()).output(type()),
245
133
  members: { list: oc.route({
246
134
  method: "GET",
247
135
  path: "/v1/teams/{id}/members",
248
136
  inputStructure: "detailed"
249
- }).input(teamIdInputSchema).output(teamMembersOutputSchema) }
137
+ }).input(type()).output(type()) }
250
138
  };
251
139
  //#endregion
252
- export { appletDefinitionSchema, appletManifestSchema, appletSourceDefinitionSchema, createEmailPixelInputSchema, createEmailPixelOutputSchema, createFileOutputSchema, emailContract, emailTagKeySchema, emailTagsSchema, emailTrackerSchema, fileSchema, filesContract, getEmailTrackerInputSchema, getFileOutputSchema, getHitchEmailAttachmentOutputSchema, getHitchEmailRawOutputSchema, hitchEmailAddressSchema, hitchEmailAttachmentSchema, hitchEmailIdInputSchema, hitchEmailMessageSchema, hitchEmailThreadSchema, hitchMailboxSchema, hitchMessageSchema, hitchPhoneNumberSchema, listEmailTrackersInputSchema, listEmailTrackersOutputSchema, listHitchEmailMailboxesOutputSchema, listHitchEmailMessagesInputSchema, listHitchEmailMessagesOutputSchema, listHitchEmailThreadsInputSchema, listHitchEmailThreadsOutputSchema, listHitchMessagesInputSchema, listHitchMessagesOutputSchema, listHitchNumbersOutputSchema, markEmailTrackerSentInputSchema, meContract, meSchema, pruneContract, registerHitchContract, sendHitchEmailInputSchema, sendHitchMessageInputSchema, teamMemberSchema, teamSchema, teamsContract, telephonyContract, uploadFile };
140
+ export { emailContract, filesContract, meContract, pruneContract, registerHitchContract, teamsContract, telephonyContract, uploadFile };
@@ -1,8 +1,8 @@
1
- import { a as ORG_CODE_PATTERN, i as APPLET_CODE_PATTERN } from "./manifest-CuY3ICpN.js";
2
- import { d as resolveAuthForOrg, f as resolveInstanceUrl, i as readWorkspaceConfig } from "./workspace-D0dnnlxL.js";
3
- import { n as runGenerate } from "./generate-MWjUbZnO.js";
4
- import { a as writeAppletSupport, n as loadCliManifest, o as writeWorkspaceSupport, t as assertWorkspaceCli } from "./project-NcWw8SwL.js";
5
- import { n as loadAppletSourceDefinition } from "./load-config-BeQZ2yOa.js";
1
+ import { c as resolveInstanceUrl, s as resolveAuthForOrg } from "./store-B8N_8JIN.js";
2
+ import { n as readWorkspaceConfig } from "./workspace-8yqXsvce.js";
3
+ import { r as runGenerate } from "./generate-BV_emZgy.js";
4
+ import { n as loadAppletSourceDefinition, o as APPLET_CODE_PATTERN, s as ORG_CODE_PATTERN } from "./load-config-Dkr2VxZN.js";
5
+ import { a as writeAppletSupport, n as loadCliManifest, o as writeWorkspaceSupport, t as assertWorkspaceCli } from "./project-CCVqCCgU.js";
6
6
  import { access, cp, mkdir, readdir, writeFile } from "node:fs/promises";
7
7
  import { relative, resolve } from "node:path";
8
8
  import { spawn } from "node:child_process";
@@ -1,4 +1,8 @@
1
+ import { n as readWorkspaceConfig } from "./workspace-8yqXsvce.js";
1
2
  import { z } from "zod";
3
+ import { existsSync } from "node:fs";
4
+ import { basename, dirname, resolve } from "node:path";
5
+ import { loadConfigFromFile } from "vite";
2
6
  import { Cron } from "croner";
3
7
  //#region src/manifest-patterns.ts
4
8
  const APPLET_CODE_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
@@ -107,7 +111,7 @@ const checkDuplicateCodes = (manifest, context) => {
107
111
  });
108
112
  };
109
113
  const appletManifestSchema = z.strictObject(appletManifestShape).superRefine(checkDuplicateCodes);
110
- const appletDefinitionSchema = z.strictObject({
114
+ z.strictObject({
111
115
  name: appletManifestShape.name,
112
116
  code: appletManifestShape.code,
113
117
  requiresChangeset: appletManifestShape.requiresChangeset,
@@ -196,4 +200,35 @@ const appletSourceDefinitionSchema = z.strictObject({
196
200
  checkSourcePackages(manifest, context);
197
201
  });
198
202
  //#endregion
199
- export { ORG_CODE_PATTERN as a, APPLET_CODE_PATTERN as i, appletManifestSchema as n, appletSourceDefinitionSchema as r, appletDefinitionSchema as t };
203
+ //#region src/workspace.ts
204
+ function resolveWorkspaceOrg(appletRoot) {
205
+ const appletsDir = dirname(appletRoot);
206
+ if (basename(appletsDir) === "applets") {
207
+ const config = readWorkspaceConfig(dirname(appletsDir));
208
+ if (config !== void 0) return config.org;
209
+ }
210
+ throw new Error(`No Hitch workspace found for ${appletRoot}. An applet must live at <workspace>/applets/<code> with hitch.config.ts in the workspace root.`);
211
+ }
212
+ //#endregion
213
+ //#region src/typegen/load-config.ts
214
+ async function loadAppletSourceDefinition(root) {
215
+ const path = resolve(root, "applet.manifest.ts");
216
+ if (!existsSync(path)) throw new Error(`No applet manifest found at ${path}.`);
217
+ const loaded = await loadConfigFromFile({
218
+ command: "build",
219
+ mode: "production"
220
+ }, path, root);
221
+ if (loaded === null) throw new Error(`No applet manifest found at ${path}.`);
222
+ const parsed = appletSourceDefinitionSchema.safeParse(loaded.config);
223
+ if (!parsed.success) throw new Error(`Invalid applet manifest at ${loaded.path}: ${parsed.error.message}`);
224
+ return parsed.data;
225
+ }
226
+ async function loadAppletConfig(root) {
227
+ const { dependencies: _dependencies, devDependencies: _devDependencies, ...definition } = await loadAppletSourceDefinition(root);
228
+ return {
229
+ org: resolveWorkspaceOrg(root),
230
+ ...definition
231
+ };
232
+ }
233
+ //#endregion
234
+ export { appletSourceDefinitionSchema as a, appletManifestSchema as i, loadAppletSourceDefinition as n, APPLET_CODE_PATTERN as o, resolveWorkspaceOrg as r, ORG_CODE_PATTERN as s, loadAppletConfig as t };
@@ -42,14 +42,10 @@ function cloudflareRequestFields(request) {
42
42
  const cf = Reflect.get(request, "cf");
43
43
  const field = (key) => typeof cf === "object" && cf !== null && key in cf ? Reflect.get(cf, key) : void 0;
44
44
  const colo = field("colo");
45
- const country = field("country");
46
- const asn = field("asn");
47
45
  return {
48
46
  cfRay: request.headers.get("cf-ray") ?? void 0,
49
47
  traceparent: request.headers.get("traceparent") ?? void 0,
50
- colo: typeof colo === "string" ? colo : void 0,
51
- country: typeof country === "string" ? country : void 0,
52
- asn: typeof asn === "number" ? asn : void 0
48
+ colo: typeof colo === "string" ? colo : void 0
53
49
  };
54
50
  }
55
51
  function createNoteLog(initial) {
@@ -1,4 +1,6 @@
1
- import { a as loginWithDevice, f as resolveInstanceUrl, o as AuthenticationError, r as findWorkspaceConfig } from "./workspace-D0dnnlxL.js";
1
+ import { c as resolveInstanceUrl, t as AuthenticationError } from "./store-B8N_8JIN.js";
2
+ import { t as loginWithDevice } from "./device-BgIfytaR.js";
3
+ import { t as findWorkspaceConfig } from "./workspace-8yqXsvce.js";
2
4
  //#region src/login.ts
3
5
  async function runLogin(options) {
4
6
  if (process.env.HITCH_API_KEY !== void 0) throw new AuthenticationError("HITCH_API_KEY is set — unset it to manage stored logins.");
@@ -1,6 +1,6 @@
1
- import { i as APPLET_CODE_PATTERN } from "./manifest-CuY3ICpN.js";
2
- import { i as readWorkspaceConfig, n as fetchWithOrgAuth, t as resolveWorkspaceOrg } from "./workspace-D0dnnlxL.js";
3
- import { t as loadAppletConfig } from "./load-config-BeQZ2yOa.js";
1
+ import { n as readWorkspaceConfig } from "./workspace-8yqXsvce.js";
2
+ import { t as fetchWithOrgAuth } from "./auth-D3CrCtZq.js";
3
+ import { o as APPLET_CODE_PATTERN, r as resolveWorkspaceOrg, t as loadAppletConfig } from "./load-config-Dkr2VxZN.js";
4
4
  import { z } from "zod";
5
5
  //#region src/logs.ts
6
6
  const LOG_LEVELS = [