@hitch42/applet 0.1.1-beta.7 → 0.1.1-beta.9

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/dist/_internal/client.js +120 -11
  2. package/dist/_internal/log-context.d.ts +34 -0
  3. package/dist/_internal/log-context.js +2 -0
  4. package/dist/_internal/server.d.ts +14 -1
  5. package/dist/_internal/server.js +122 -118
  6. package/dist/applet.js +22 -11
  7. package/dist/build-Bh_S5BUv.js +2 -0
  8. package/dist/{build-DauirTcY.js → build-CEfFoIZZ.js} +1 -1
  9. package/dist/{ci-gPrwo6C0.js → ci-BKw14X2h.js} +14 -13
  10. package/dist/client.d.ts +3 -3
  11. package/dist/{contract-DB9QQhD9.d.ts → contract-CsUpTBe0.d.ts} +1 -1
  12. package/dist/{deploy-CqrtNJ1x.js → deploy-wGYjwXrx.js} +139 -88
  13. package/dist/email-DBTVhNB_.js +62 -0
  14. package/dist/{generate-BIifT6PK.js → generate-BEIYs17x.js} +70 -32
  15. package/dist/generate-Dox-OYt6.js +2 -0
  16. package/dist/headers-DkNr9MLJ.js +17 -0
  17. package/dist/index.d.ts +122 -10
  18. package/dist/index.js +142 -26
  19. package/dist/{init-Wu6XmyVc.js → init-6oGPM46R.js} +15 -17
  20. package/dist/{load-config-BknBkdRs.js → load-config-xEdTXs0y.js} +2 -2
  21. package/dist/log-context-zu8U9Sjm.js +73 -0
  22. package/dist/{login-iT9MRuaw.js → login-CUx3TmFQ.js} +1 -1
  23. package/dist/{logs-B-qZGXSK.js → logs-DSjuEN0Q.js} +20 -22
  24. package/dist/{manifest-C489nYUy.d.ts → manifest-C6_F4bL8.d.ts} +7 -0
  25. package/dist/{manifest-Bd04cWhu.js → manifest-CJSL9GuC.js} +22 -3
  26. package/dist/me-BW7Paary.js +32 -0
  27. package/dist/{project-C_rtpjp8.js → project-BRZGd6xq.js} +202 -20
  28. package/dist/prompt-ChS-grYO.js +29 -0
  29. package/dist/query-cache-CXmAyLv3.js +82 -0
  30. package/dist/react.d.ts +3 -2
  31. package/dist/react.js +98 -80
  32. package/dist/schedules-C8_Svr4h.js +42 -0
  33. package/dist/server.d.ts +9 -4
  34. package/dist/server.js +29 -8
  35. package/dist/telephony-protocol-D-nf3Gca.d.ts +76 -0
  36. package/dist/telephony.d.ts +97 -0
  37. package/dist/telephony.js +726 -0
  38. package/dist/{upload-YbRKEqR6.d.ts → upload-DKZzz5kW.d.ts} +6 -6
  39. package/dist/{variables-DcwMeIau.js → variables-DT5RyHdH.js} +14 -39
  40. package/dist/vite.d.ts +3 -60
  41. package/dist/vite.js +497 -27
  42. package/dist/workflow-engine-BOTzURKM.js +111 -0
  43. package/dist/{workspace-B6lenAS5.js → workspace-D0dnnlxL.js} +37 -39
  44. package/package.json +18 -5
  45. package/scaffold/.agents/skills/hitch-applets/SKILL.md +50 -18
  46. package/scaffold/.agents/skills/hitch-applets/references/email-tracking.md +49 -0
  47. package/scaffold/.agents/skills/hitch-applets/references/files.md +3 -3
  48. package/scaffold/.agents/skills/hitch-applets/references/manifest.md +12 -2
  49. package/scaffold/.agents/skills/hitch-applets/references/markdown.md +2 -0
  50. package/scaffold/.agents/skills/hitch-applets/references/performance.md +1 -1
  51. package/scaffold/.agents/skills/hitch-applets/references/records.md +27 -4
  52. package/scaffold/.agents/skills/hitch-applets/references/schedules.md +7 -2
  53. package/scaffold/.agents/skills/hitch-applets/references/server.md +0 -3
  54. package/scaffold/.agents/skills/hitch-applets/references/workflows.md +11 -3
  55. package/scaffold/.agents/skills/hitch-cli/SKILL.md +20 -20
  56. package/scaffold/.agents/skills/hitch-data/SKILL.md +3 -2
  57. package/scaffold/.agents/skills/hitch-data/references/attributes.md +7 -1
  58. package/scaffold/.agents/skills/hitch-data/references/limits.md +23 -23
  59. package/scaffold/.agents/skills/hitch-theory/SKILL.md +151 -0
  60. package/scaffold/.agents/skills/react-best-practices/SKILL.md +127 -0
  61. package/scaffold/.agents/skills/react-best-practices/rules/advanced-effect-event-deps.md +50 -0
  62. package/scaffold/.agents/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  63. package/scaffold/.agents/skills/react-best-practices/rules/advanced-init-once.md +42 -0
  64. package/scaffold/.agents/skills/react-best-practices/rules/advanced-use-latest.md +39 -0
  65. package/scaffold/.agents/skills/react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
  66. package/scaffold/.agents/skills/react-best-practices/rules/async-defer-await.md +82 -0
  67. package/scaffold/.agents/skills/react-best-practices/rules/async-dependencies.md +48 -0
  68. package/scaffold/.agents/skills/react-best-practices/rules/async-parallel.md +24 -0
  69. package/scaffold/.agents/skills/react-best-practices/rules/bundle-analyzable-paths.md +42 -0
  70. package/scaffold/.agents/skills/react-best-practices/rules/bundle-barrel-imports.md +39 -0
  71. package/scaffold/.agents/skills/react-best-practices/rules/bundle-conditional.md +35 -0
  72. package/scaffold/.agents/skills/react-best-practices/rules/bundle-defer-third-party.md +46 -0
  73. package/scaffold/.agents/skills/react-best-practices/rules/bundle-dynamic-imports.md +38 -0
  74. package/scaffold/.agents/skills/react-best-practices/rules/bundle-preload.md +40 -0
  75. package/scaffold/.agents/skills/react-best-practices/rules/client-event-listeners.md +78 -0
  76. package/scaffold/.agents/skills/react-best-practices/rules/client-localstorage-schema.md +74 -0
  77. package/scaffold/.agents/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
  78. package/scaffold/.agents/skills/react-best-practices/rules/js-batch-dom-css.md +110 -0
  79. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-function-results.md +58 -0
  80. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
  81. package/scaffold/.agents/skills/react-best-practices/rules/js-cache-storage.md +56 -0
  82. package/scaffold/.agents/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
  83. package/scaffold/.agents/skills/react-best-practices/rules/js-early-exit.md +50 -0
  84. package/scaffold/.agents/skills/react-best-practices/rules/js-flatmap-filter.md +51 -0
  85. package/scaffold/.agents/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
  86. package/scaffold/.agents/skills/react-best-practices/rules/js-index-maps.md +37 -0
  87. package/scaffold/.agents/skills/react-best-practices/rules/js-length-check-first.md +50 -0
  88. package/scaffold/.agents/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
  89. package/scaffold/.agents/skills/react-best-practices/rules/js-request-idle-callback.md +104 -0
  90. package/scaffold/.agents/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
  91. package/scaffold/.agents/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
  92. package/scaffold/.agents/skills/react-best-practices/rules/rendering-activity.md +26 -0
  93. package/scaffold/.agents/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +38 -0
  94. package/scaffold/.agents/skills/react-best-practices/rules/rendering-conditional-render.md +32 -0
  95. package/scaffold/.agents/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
  96. package/scaffold/.agents/skills/react-best-practices/rules/rendering-hoist-jsx.md +36 -0
  97. package/scaffold/.agents/skills/react-best-practices/rules/rendering-resource-hints.md +81 -0
  98. package/scaffold/.agents/skills/react-best-practices/rules/rendering-script-defer-async.md +36 -0
  99. package/scaffold/.agents/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
  100. package/scaffold/.agents/skills/react-best-practices/rules/rendering-usetransition-loading.md +43 -0
  101. package/scaffold/.agents/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
  102. package/scaffold/.agents/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
  103. package/scaffold/.agents/skills/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  104. package/scaffold/.agents/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
  105. package/scaffold/.agents/skills/react-best-practices/rules/rerender-functional-setstate.md +77 -0
  106. package/scaffold/.agents/skills/react-best-practices/rules/rerender-lazy-state-init.md +56 -0
  107. package/scaffold/.agents/skills/react-best-practices/rules/rerender-memo-with-default-value.md +36 -0
  108. package/scaffold/.agents/skills/react-best-practices/rules/rerender-memo.md +44 -0
  109. package/scaffold/.agents/skills/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  110. package/scaffold/.agents/skills/react-best-practices/rules/rerender-no-inline-components.md +75 -0
  111. package/scaffold/.agents/skills/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  112. package/scaffold/.agents/skills/react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
  113. package/scaffold/.agents/skills/react-best-practices/rules/rerender-transitions.md +40 -0
  114. package/scaffold/.agents/skills/react-best-practices/rules/rerender-use-deferred-value.md +59 -0
  115. package/scaffold/.agents/skills/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  116. package/scaffold/.agents/skills/tanstack-query/SKILL.md +136 -0
  117. package/scaffold/.agents/skills/tanstack-query/references/compositions/automatic-invalidation-after-mutations.md +124 -0
  118. package/scaffold/.agents/skills/tanstack-query/references/compositions/broadcast-realtime-and-multi-tab-synchronization.md +150 -0
  119. package/scaffold/.agents/skills/tanstack-query/references/compositions/compose-query-with-tanstack-router-and-start.md +248 -0
  120. package/scaffold/.agents/skills/tanstack-query/references/compositions/enforce-query-best-practices-with-eslint.md +167 -0
  121. package/scaffold/.agents/skills/tanstack-query/references/compositions/persist-offline-and-restore-caches.md +181 -0
  122. package/scaffold/.agents/skills/tanstack-query/references/compositions/query-data-and-forms.md +156 -0
  123. package/scaffold/.agents/skills/tanstack-query/references/core/build-query-abstractions.md +130 -0
  124. package/scaffold/.agents/skills/tanstack-query/references/core/cancel-queries-and-consume-abort-signals.md +176 -0
  125. package/scaffold/.agents/skills/tanstack-query/references/core/concurrent-optimistic-updates.md +135 -0
  126. package/scaffold/.agents/skills/tanstack-query/references/core/coordinate-query-execution.md +188 -0
  127. package/scaffold/.agents/skills/tanstack-query/references/core/design-query-keys-and-options.md +182 -0
  128. package/scaffold/.agents/skills/tanstack-query/references/core/fetch-and-observe-queries.md +193 -0
  129. package/scaffold/.agents/skills/tanstack-query/references/core/implement-optimistic-updates-and-cache-writes.md +168 -0
  130. package/scaffold/.agents/skills/tanstack-query/references/core/paginate-and-build-infinite-queries.md +188 -0
  131. package/scaffold/.agents/skills/tanstack-query/references/core/seed-placeholder-select-and-transform-data.md +188 -0
  132. package/scaffold/.agents/skills/tanstack-query/references/core/selectors-and-derived-state.md +145 -0
  133. package/scaffold/.agents/skills/tanstack-query/references/core/tune-defaults-freshness-retries-and-refetching.md +172 -0
  134. package/scaffold/.agents/skills/tanstack-query/references/core/understand-query-internals-and-observers.md +104 -0
  135. package/scaffold/.agents/skills/tanstack-query/references/core/write-mutations-and-invalidate-related-queries.md +183 -0
  136. package/scaffold/.agents/skills/tanstack-query/references/framework/debug-with-devtools.md +169 -0
  137. package/scaffold/.agents/skills/tanstack-query/references/framework/handle-status-and-errors.md +119 -0
  138. package/scaffold/.agents/skills/tanstack-query/references/framework/shape-data-and-render-efficiently.md +184 -0
  139. package/scaffold/.agents/skills/tanstack-query/references/framework/use-framework-adapter-reactivity.md +185 -0
  140. package/scaffold/.agents/skills/tanstack-query/references/framework/use-suspense-and-error-boundaries.md +208 -0
  141. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/migrate-major-versions-and-codemods.md +169 -0
  142. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/prefetch-and-remove-request-waterfalls.md +228 -0
  143. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/setup-query-client-and-providers.md +161 -0
  144. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/ssr-hydration-and-streaming.md +209 -0
  145. package/scaffold/.agents/skills/tanstack-query/references/lifecycle/test-query-code.md +160 -0
  146. package/scaffold/.agents/skills/tanstack-router/SKILL.md +134 -0
  147. package/scaffold/.agents/skills/tanstack-router/references/compositions/router-query.md +412 -0
  148. package/scaffold/.agents/skills/tanstack-router/references/react-router.md +495 -0
  149. package/scaffold/.agents/skills/tanstack-router/references/router-core/auth-and-guards.md +495 -0
  150. package/scaffold/.agents/skills/tanstack-router/references/router-core/code-splitting.md +318 -0
  151. package/scaffold/.agents/skills/tanstack-router/references/router-core/data-loading.md +490 -0
  152. package/scaffold/.agents/skills/tanstack-router/references/router-core/index.md +158 -0
  153. package/scaffold/.agents/skills/tanstack-router/references/router-core/navigation.md +433 -0
  154. package/scaffold/.agents/skills/tanstack-router/references/router-core/not-found-and-errors.md +436 -0
  155. package/scaffold/.agents/skills/tanstack-router/references/router-core/path-params.md +383 -0
  156. package/scaffold/.agents/skills/tanstack-router/references/router-core/search-params.md +343 -0
  157. package/scaffold/.agents/skills/tanstack-router/references/router-core/ssr.md +462 -0
  158. package/scaffold/.agents/skills/tanstack-router/references/router-core/type-safety.md +493 -0
  159. package/scaffold/.agents/skills/tanstack-router/references/router-plugin.md +250 -0
  160. package/scaffold/.agents/skills/tanstack-router/references/virtual-file-routes.md +215 -0
  161. package/scaffold/.agents/skills/web-design-guidelines/SKILL.md +184 -0
  162. package/scaffold/.github/workflows/hitch.yml +1 -1
  163. package/scaffold/AGENTS.md +2 -2
  164. package/scaffold/applet/src/client/components/ui/alert.tsx +1 -1
  165. package/scaffold/applet/src/client/components/ui/button.tsx +1 -1
  166. package/scaffold/applet/src/client/components/ui/checkbox.tsx +1 -1
  167. package/scaffold/applet/src/client/components/ui/dialog.tsx +2 -2
  168. package/scaffold/applet/src/client/components/ui/dropdown-menu.tsx +2 -2
  169. package/scaffold/applet/src/client/components/ui/input-group.tsx +2 -2
  170. package/scaffold/applet/src/client/components/ui/select.tsx +2 -2
  171. package/scaffold/applet/src/client/components/ui/sheet.tsx +2 -2
  172. package/scaffold/applet/src/client/components/ui/spinner.tsx +2 -1
  173. package/scaffold/applet/src/client/components/ui/tabs.tsx +1 -1
  174. package/scaffold/applet/src/client/lib/utils.ts +1 -6
  175. package/scaffold/applet/src/client/styles/globals.css +2 -0
  176. package/dist/build-DhNDp7ji.js +0 -2
  177. package/dist/generate-DSk8ihsC.js +0 -2
@@ -1,15 +1,112 @@
1
- import { createAsyncStoragePersister } from "@tanstack/query-async-storage-persister";
1
+ import { i as openCacheDatabase, n as clearAppletQueryCaches, o as sweepExpiredQueryCaches, r as indexedDbPersister, t as cacheTabId } from "../query-cache-CXmAyLv3.js";
2
2
  import { QueryClientProvider } from "@tanstack/react-query";
3
3
  import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
4
4
  import { RouterProvider } from "@tanstack/react-router";
5
- import { createElement } from "react";
5
+ import { createElement, useEffect } from "react";
6
6
  import { createRoot } from "react-dom/client";
7
+ import { RotateCcw } from "lucide-react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ //#region src/internal/error-page.tsx
10
+ const STYLES = `
11
+ .hitch-error {
12
+ position: relative;
13
+ display: flex;
14
+ min-height: 100dvh;
15
+ align-items: center;
16
+ justify-content: center;
17
+ overflow: hidden;
18
+ padding: 3rem 1.5rem;
19
+ background:
20
+ radial-gradient(ellipse 80% 50% at 50% -20%, color-mix(in oklch, var(--primary) 12%, transparent), transparent),
21
+ var(--background);
22
+ color: var(--foreground);
23
+ font-family: "Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif;
24
+ }
25
+ .hitch-error__content { width: 100%; max-width: 28rem; text-align: center; }
26
+ .hitch-error__title { margin: 0 0 0.75rem; font-size: 1.875rem; font-weight: 600; letter-spacing: -0.025em; }
27
+ .hitch-error__text { margin: 0 0 2rem; color: var(--muted-foreground); line-height: 1.625; text-wrap: balance; }
28
+ .hitch-error__button {
29
+ display: inline-flex;
30
+ width: 100%;
31
+ align-items: center;
32
+ justify-content: center;
33
+ gap: 0.5rem;
34
+ border: 0;
35
+ border-radius: calc(var(--radius, 0.625rem) + 4px);
36
+ padding: 0.75rem 1.5rem;
37
+ background: var(--primary);
38
+ color: var(--primary-foreground);
39
+ font: inherit;
40
+ font-weight: 500;
41
+ cursor: pointer;
42
+ transition: background 150ms;
43
+ }
44
+ .hitch-error__button:hover { background: color-mix(in oklch, var(--primary) 90%, transparent); }
45
+ .hitch-error__button:focus-visible { outline: 2px solid var(--ring, var(--primary)); outline-offset: 2px; }
46
+ .hitch-error__hint { margin: 1rem 0 0; color: var(--muted-foreground); font-size: 0.875rem; }
47
+ .hitch-error__details { margin-top: 1.5rem; color: var(--muted-foreground); font-size: 0.875rem; text-align: left; }
48
+ .hitch-error__details summary { cursor: pointer; text-align: center; }
49
+ .hitch-error__details pre {
50
+ max-height: 12rem;
51
+ margin: 0.75rem 0 0;
52
+ padding: 1rem;
53
+ overflow: auto;
54
+ border: 1px solid var(--border);
55
+ border-radius: var(--radius, 0.625rem);
56
+ font: 0.75rem/1.5 ui-monospace, monospace;
57
+ white-space: pre;
58
+ }
59
+ `;
60
+ function AppletErrorPage({ error, onReload }) {
61
+ useEffect(() => {
62
+ console.error("The applet failed to render.", error);
63
+ }, [error]);
64
+ return /* @__PURE__ */ jsxs("div", {
65
+ className: "hitch-error",
66
+ role: "alert",
67
+ children: [/* @__PURE__ */ jsx("style", { children: STYLES }), /* @__PURE__ */ jsxs("div", {
68
+ className: "hitch-error__content",
69
+ children: [
70
+ /* @__PURE__ */ jsx("h1", {
71
+ className: "hitch-error__title",
72
+ children: "We hit a snag"
73
+ }),
74
+ /* @__PURE__ */ jsx("p", {
75
+ className: "hitch-error__text",
76
+ children: "This applet ran into an unexpected error. Reload to try again."
77
+ }),
78
+ /* @__PURE__ */ jsxs("button", {
79
+ type: "button",
80
+ className: "hitch-error__button",
81
+ onClick: onReload,
82
+ children: [/* @__PURE__ */ jsx(RotateCcw, {
83
+ size: 16,
84
+ "aria-hidden": true
85
+ }), "Reload applet"]
86
+ }),
87
+ /* @__PURE__ */ jsx("p", {
88
+ className: "hitch-error__hint",
89
+ children: "If this keeps happening, let your admin know."
90
+ }),
91
+ import.meta.env.DEV && /* @__PURE__ */ jsxs("details", {
92
+ className: "hitch-error__details",
93
+ children: [/* @__PURE__ */ jsx("summary", { children: "Error details" }), /* @__PURE__ */ jsx("pre", { children: error instanceof Error ? error.stack ?? error.message : String(error) })]
94
+ })
95
+ ]
96
+ })]
97
+ });
98
+ }
99
+ //#endregion
7
100
  //#region src/internal/client.ts
8
101
  const CACHE_MAX_AGE = 3e5;
9
102
  const CACHE_SCOPE_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
103
  async function appletQueryPersistence(appletCode) {
11
104
  const contextPromise = window.__hitchCacheContext;
12
105
  if (!contextPromise) return void 0;
106
+ const databaseReady = openCacheDatabase().then(() => true, (error) => {
107
+ console.error("Could not open the applet query cache.", error);
108
+ return false;
109
+ });
13
110
  let context;
14
111
  try {
15
112
  context = await contextPromise;
@@ -20,16 +117,10 @@ async function appletQueryPersistence(appletCode) {
20
117
  const cacheScope = typeof context === "object" && context !== null && "cacheScope" in context && typeof context.cacheScope === "string" ? context.cacheScope.trim() : void 0;
21
118
  const cacheBuster = typeof context === "object" && context !== null && "cacheBuster" in context && typeof context.cacheBuster === "string" ? context.cacheBuster.trim() : void 0;
22
119
  if (!cacheScope || !CACHE_SCOPE_PATTERN.test(cacheScope) || !cacheBuster || !CACHE_SCOPE_PATTERN.test(cacheBuster)) return;
120
+ if (!await databaseReady) return void 0;
23
121
  try {
24
122
  return {
25
- persister: createAsyncStoragePersister({
26
- storage: window.sessionStorage,
27
- key: `hitch:query:${appletCode}:${cacheScope}`,
28
- throttleTime: 100,
29
- retry: ({ error }) => {
30
- console.error("Could not persist the applet query cache.", error);
31
- }
32
- }),
123
+ persister: indexedDbPersister(`${appletCode}:${cacheScope}:${cacheTabId()}`),
33
124
  maxAge: CACHE_MAX_AGE,
34
125
  buster: cacheBuster,
35
126
  dehydrateOptions: { shouldDehydrateMutation: () => false }
@@ -44,12 +135,30 @@ function mountApplet(router, appletCode) {
44
135
  if (!queryClient) throw new Error("getRouter must provide a QueryClient via createRouter({ context: { queryClient } }).");
45
136
  const root = document.getElementById("root");
46
137
  if (root === null) throw new Error("Missing #root element in index.html.");
138
+ router.options.defaultErrorComponent ??= ({ error }) => createElement(AppletErrorPage, {
139
+ error,
140
+ onReload: () => {
141
+ queryClient.clear();
142
+ clearAppletQueryCaches(appletCode).catch((error) => console.error("Could not clear the applet query cache.", error)).finally(() => window.location.reload());
143
+ }
144
+ });
47
145
  const applet = createElement(RouterProvider, { router });
146
+ const sweepWhenIdle = () => {
147
+ const sweep = () => {
148
+ sweepExpiredQueryCaches(CACHE_MAX_AGE).catch((error) => console.error("Could not clear expired applet query caches.", error));
149
+ };
150
+ if ("requestIdleCallback" in window) requestIdleCallback(sweep);
151
+ else setTimeout(sweep, 1e3);
152
+ };
48
153
  appletQueryPersistence(appletCode).then((persistence) => {
49
154
  createRoot(root).render(persistence ? createElement(PersistQueryClientProvider, {
50
155
  client: queryClient,
51
156
  persistOptions: persistence,
52
- onError: () => console.error("Could not restore the applet query cache.")
157
+ onSuccess: sweepWhenIdle,
158
+ onError: () => {
159
+ console.error("Could not restore the applet query cache.");
160
+ sweepWhenIdle();
161
+ }
53
162
  }, applet) : createElement(QueryClientProvider, { client: queryClient }, applet));
54
163
  }).catch((error) => {
55
164
  console.error("Could not initialize the applet query cache.", error);
@@ -0,0 +1,34 @@
1
+ //#region src/server/log-context.d.ts
2
+ declare const REQUEST_CONTEXT_CHANNEL = "hitch.request.context";
3
+ declare const APP_CONTEXT_CHANNEL = "hitch.request.app";
4
+ declare const isUuid: (value: string | null | undefined) => value is string;
5
+ declare function requestIdFrom(headers: Headers): string;
6
+ declare function publishNote(requestId: string, fields: Record<string, unknown>, channelName?: string): void;
7
+ declare function errorNote(error: unknown): {
8
+ error: {
9
+ name: string;
10
+ message: string;
11
+ stack?: string;
12
+ cause?: {
13
+ name: string;
14
+ message: string;
15
+ };
16
+ };
17
+ };
18
+ declare function cloudflareRequestFields(request: Request): {
19
+ cfRay: string | undefined;
20
+ traceparent: string | undefined;
21
+ colo: string | undefined;
22
+ country: string | undefined;
23
+ asn: number | undefined;
24
+ };
25
+ type NoteLog = {
26
+ set(fields: Record<string, unknown>): void;
27
+ error(error: unknown): void;
28
+ getContext(): Record<string, unknown>;
29
+ };
30
+ declare function createNoteLog(initial: {
31
+ requestId: string;
32
+ } & Record<string, unknown>): NoteLog;
33
+ //#endregion
34
+ export { APP_CONTEXT_CHANNEL, NoteLog, REQUEST_CONTEXT_CHANNEL, cloudflareRequestFields, createNoteLog, errorNote, isUuid, publishNote, requestIdFrom };
@@ -0,0 +1,2 @@
1
+ import { a as errorNote, c as requestIdFrom, i as createNoteLog, n as REQUEST_CONTEXT_CHANNEL, o as isUuid, r as cloudflareRequestFields, s as publishNote, t as APP_CONTEXT_CHANNEL } from "../log-context-zu8U9Sjm.js";
2
+ export { APP_CONTEXT_CHANNEL, REQUEST_CONTEXT_CHANNEL, cloudflareRequestFields, createNoteLog, errorNote, isUuid, publishNote, requestIdFrom };
@@ -1,9 +1,13 @@
1
1
  import { t as AnyWorkflowDefinition } from "../workflow-DurM6Fwx.js";
2
+ import { d as listEmailTrackersInputSchema, i as createEmailPixelInputSchema, p as markEmailTrackerSentBodySchema, t as TelephonyMessageReceivedEvent } from "../telephony-protocol-D-nf3Gca.js";
2
3
  import { z } from "zod";
3
4
  //#region src/server/entry.d.ts
4
5
  declare function createWorkerEntry(server: {
5
6
  router: object;
6
7
  workflows?: Record<string, AnyWorkflowDefinition>;
8
+ telephony?: {
9
+ onMessageReceived?: (event: TelephonyMessageReceivedEvent) => void | Promise<void>;
10
+ };
7
11
  }, options: {
8
12
  code: string;
9
13
  }): {
@@ -76,4 +80,13 @@ type ErrorOutcome = {
76
80
  declare const workflowOutcomeSchema: z.ZodType<StepOutcome | SleepOutcome | StepErrorOutcome | DoneOutcome | ErrorOutcome>;
77
81
  type WorkflowOutcome = z.infer<typeof workflowOutcomeSchema>;
78
82
  //#endregion
79
- export { type JournalEntry, type WorkflowInvocationRequest, type WorkflowOutcome, createWorkerEntry, journalEntrySchema, workflowInvocationRequestSchema, workflowOutcomeSchema };
83
+ //#region src/server/workflow-engine.d.ts
84
+ type Engine = {
85
+ invoke<T>(name: string, fn: () => Promise<T>): Promise<T>;
86
+ sleepUntil(name: string, until: Date): Promise<void>;
87
+ sleep(name: string, milliseconds: number): Promise<void>;
88
+ };
89
+ declare class WorkflowFailedError extends Error {}
90
+ declare function runWorkflowJournal(engine: Engine, invoke: (journal: JournalEntry[]) => Promise<WorkflowOutcome>): Promise<unknown>;
91
+ //#endregion
92
+ export { type Engine, type JournalEntry, WorkflowFailedError, type WorkflowInvocationRequest, type WorkflowOutcome, createEmailPixelInputSchema, createWorkerEntry, journalEntrySchema, listEmailTrackersInputSchema, markEmailTrackerSentBodySchema, runWorkflowJournal, workflowInvocationRequestSchema, workflowOutcomeSchema };
@@ -1,80 +1,18 @@
1
- import { o as runWithRequestContext, r as toMilliseconds, t as MAX_DURATION_MS } from "../workflow-CTo2kZF1.js";
1
+ import { c as listEmailTrackersInputSchema, t as createEmailPixelInputSchema, u as markEmailTrackerSentBodySchema } from "../email-DBTVhNB_.js";
2
+ import { a as HITCH_ORG_CODE_HEADER, c as HITCH_SCHEDULE_HEADER, d as HITCH_USER_HEADER, f as HITCH_WORKFLOW_HEADER, i as HITCH_ORGANIZATION_HEADER, l as HITCH_SCHEDULE_RUN_HEADER, m as HITCH_WORKFLOW_RUN_HEADER, n as HITCH_APPLET_HEADER, o as HITCH_RELEASE_HEADER, p as HITCH_WORKFLOW_INVOCATION_HEADER, r as HITCH_APPLET_TOKEN_HEADER, u as HITCH_SESSION_HEADER } from "../headers-DkNr9MLJ.js";
3
+ import { a as getRequestContext, o as runWithRequestContext, r as toMilliseconds, t as MAX_DURATION_MS } from "../workflow-CTo2kZF1.js";
4
+ import { a as errorNote, c as requestIdFrom, i as createNoteLog, r as cloudflareRequestFields, s as publishNote, t as APP_CONTEXT_CHANNEL } from "../log-context-zu8U9Sjm.js";
5
+ import { a as workflowOutcomeSchema, i as workflowInvocationRequestSchema, n as runWorkflowJournal, r as journalEntrySchema, t as WorkflowFailedError } from "../workflow-engine-BOTzURKM.js";
2
6
  import { z } from "zod";
3
7
  import { RPCHandler } from "@orpc/server/fetch";
4
- //#region src/headers.ts
5
- const HITCH_USER_HEADER = "x-hitch-user";
6
- const HITCH_SESSION_HEADER = "x-hitch-session";
7
- const HITCH_APPLET_HEADER = "x-hitch-applet";
8
- const HITCH_APPLET_TOKEN_HEADER = "x-hitch-applet-token";
9
- //#endregion
10
- //#region src/server/workflow-protocol.ts
11
- const journalEntrySchema = z.discriminatedUnion("kind", [
12
- z.object({
13
- kind: z.literal("step"),
14
- id: z.string(),
15
- name: z.string(),
16
- result: z.unknown()
17
- }),
18
- z.object({
19
- kind: z.literal("sleep"),
20
- id: z.string(),
21
- name: z.string(),
22
- until: z.number()
23
- }),
24
- z.object({
25
- kind: z.literal("attempt"),
26
- id: z.string(),
27
- name: z.string(),
28
- error: z.string()
29
- }),
30
- z.object({
31
- kind: z.literal("failed"),
32
- id: z.string(),
33
- name: z.string(),
34
- error: z.string()
35
- })
36
- ]);
37
- const workflowInvocationRequestSchema = z.object({
38
- payload: z.unknown(),
39
- journal: z.array(journalEntrySchema)
8
+ //#region src/server/telephony-protocol.ts
9
+ const telephonyMessageReceivedEventSchema = z.object({
10
+ eventId: z.string(),
11
+ type: z.literal("message.received"),
12
+ messageId: z.string(),
13
+ numberId: z.string(),
14
+ occurredAt: z.iso.datetime()
40
15
  });
41
- const workflowOutcomeSchema = z.discriminatedUnion("kind", [
42
- z.object({
43
- kind: z.literal("step"),
44
- id: z.string(),
45
- name: z.string(),
46
- result: z.unknown()
47
- }),
48
- z.object({
49
- kind: z.literal("sleep"),
50
- id: z.string(),
51
- name: z.string(),
52
- until: z.number()
53
- }),
54
- z.object({
55
- kind: z.literal("step_error"),
56
- id: z.string(),
57
- name: z.string(),
58
- message: z.string(),
59
- retries: z.object({
60
- limit: z.number(),
61
- delayMs: z.number(),
62
- backoff: z.enum([
63
- "constant",
64
- "linear",
65
- "exponential"
66
- ])
67
- })
68
- }),
69
- z.object({
70
- kind: z.literal("done"),
71
- result: z.unknown()
72
- }),
73
- z.object({
74
- kind: z.literal("error"),
75
- message: z.string()
76
- })
77
- ]);
78
16
  //#endregion
79
17
  //#region src/server/workflow-run.ts
80
18
  const MAX_RESULT_SIZE = 1048576;
@@ -180,53 +118,119 @@ function jsonError(status, error) {
180
118
  function createWorkerEntry(server, options) {
181
119
  const candidate = server;
182
120
  if (typeof candidate !== "object" || candidate === null || !("router" in candidate)) throw new Error(SERVER_EXPORT_ERROR);
183
- const handler = new RPCHandler(server.router);
121
+ const handler = new RPCHandler(server.router, { clientInterceptors: [async (options) => {
122
+ getRequestContext().log.set({
123
+ route: `/api/${options.path.join("/")}`,
124
+ procedure: options.path.join("/")
125
+ });
126
+ try {
127
+ return await options.next();
128
+ } catch (error) {
129
+ publishNote(getRequestContext().requestId, errorNote(error), APP_CONTEXT_CHANNEL);
130
+ throw error;
131
+ }
132
+ }] });
184
133
  return { async fetch(request, env) {
185
- const userId = request.headers.get(HITCH_USER_HEADER);
186
- const sessionToken = request.headers.get(HITCH_SESSION_HEADER);
187
- const appletId = request.headers.get(HITCH_APPLET_HEADER);
188
- const token = request.headers.get(HITCH_APPLET_TOKEN_HEADER);
189
- const identity = userId !== null && sessionToken !== null ? {
190
- kind: "user",
191
- userId,
192
- sessionToken
193
- } : appletId !== null && token !== null ? {
194
- kind: "applet",
195
- appletId,
196
- token
197
- } : void 0;
198
- if (identity === void 0) return jsonError(401, "missing_identity");
199
- const bindings = typeof env === "object" && env !== null ? env : {};
200
- if (typeof bindings.HITCH_API_URL !== "string") return jsonError(500, "missing_api_binding");
201
- const service = typeof bindings.HITCH === "object" && bindings.HITCH !== null ? bindings.HITCH : void 0;
202
- const apiFetch = typeof service?.fetch === "function" ? service.fetch.bind(bindings.HITCH) : globalThis.fetch.bind(globalThis);
203
- return runWithRequestContext({
204
- identity,
134
+ const url = new URL(request.url);
135
+ const requestId = requestIdFrom(request.headers);
136
+ const log = createNoteLog({
137
+ requestId,
138
+ service: "hitch-applet",
139
+ operation: "http.request",
140
+ callerType: "anonymous",
205
141
  appletCode: options.code,
206
- api: {
207
- baseUrl: bindings.HITCH_API_URL,
208
- fetch: apiFetch
209
- }
210
- }, async () => {
211
- const pathname = new URL(request.url).pathname;
212
- if (pathname.startsWith(WORKFLOW_PATH_PREFIX)) {
213
- const parsed = await request.json().then((body) => workflowInvocationRequestSchema.safeParse(body)).catch(() => void 0);
214
- if (parsed === void 0 || !parsed.success) return jsonError(400, "malformed_request");
215
- const code = decodeURIComponent(pathname.slice(23));
216
- const workflows = server.workflows ?? {};
217
- const definition = Object.hasOwn(workflows, code) ? workflows[code] : void 0;
218
- return Response.json(definition === void 0 ? {
219
- kind: "error",
220
- message: `Unknown workflow "${code}".`
221
- } : await runWorkflowInvocation(definition, parsed.data));
222
- }
223
- const result = await handler.handle(request, {
224
- context: {},
225
- prefix: "/api"
226
- });
227
- return result.matched ? result.response : new Response(null, { status: 404 });
142
+ host: request.headers.get("x-hitch-request-host") ?? url.host,
143
+ orgCode: request.headers.get(HITCH_ORG_CODE_HEADER),
144
+ hitchOrganization: request.headers.get(HITCH_ORGANIZATION_HEADER),
145
+ hitchApplet: request.headers.get(HITCH_APPLET_HEADER),
146
+ hitchRelease: request.headers.get(HITCH_RELEASE_HEADER),
147
+ scheduleCode: request.headers.get(HITCH_SCHEDULE_HEADER),
148
+ hitchRun: request.headers.get(HITCH_WORKFLOW_RUN_HEADER),
149
+ workflowCode: request.headers.get(HITCH_WORKFLOW_HEADER),
150
+ workflowInvocation: request.headers.get(HITCH_WORKFLOW_INVOCATION_HEADER),
151
+ userAgent: request.headers.get("user-agent"),
152
+ contentType: request.headers.get("content-type"),
153
+ method: request.method,
154
+ ...cloudflareRequestFields(request)
228
155
  });
156
+ try {
157
+ const userId = request.headers.get(HITCH_USER_HEADER);
158
+ const sessionToken = request.headers.get(HITCH_SESSION_HEADER);
159
+ const appletId = request.headers.get(HITCH_APPLET_HEADER);
160
+ const token = request.headers.get(HITCH_APPLET_TOKEN_HEADER);
161
+ const identity = userId !== null && sessionToken !== null ? {
162
+ kind: "user",
163
+ userId,
164
+ sessionToken
165
+ } : appletId !== null && token !== null ? {
166
+ kind: "applet",
167
+ appletId,
168
+ token
169
+ } : void 0;
170
+ if (identity === void 0) return jsonError(401, "missing_identity");
171
+ log.set({
172
+ callerType: identity.kind,
173
+ callerId: identity.kind === "user" ? `user:${identity.userId}` : `applet:${identity.appletId}`
174
+ });
175
+ const bindings = typeof env === "object" && env !== null ? env : {};
176
+ if (typeof bindings.HITCH_API_URL !== "string") return jsonError(500, "missing_api_binding");
177
+ const service = typeof bindings.HITCH === "object" && bindings.HITCH !== null ? bindings.HITCH : void 0;
178
+ const apiFetch = typeof service?.fetch === "function" ? service.fetch.bind(bindings.HITCH) : globalThis.fetch.bind(globalThis);
179
+ const invocationId = identity.kind === "applet" ? request.headers.get(HITCH_SCHEDULE_RUN_HEADER) : null;
180
+ if (invocationId) log.set({
181
+ operation: "applet.schedule.procedure",
182
+ hitchType: "schedule",
183
+ hitchInvocation: invocationId
184
+ });
185
+ return await runWithRequestContext({
186
+ identity,
187
+ appletCode: options.code,
188
+ api: {
189
+ baseUrl: bindings.HITCH_API_URL,
190
+ fetch: apiFetch
191
+ },
192
+ log,
193
+ requestId
194
+ }, async () => {
195
+ const pathname = new URL(request.url).pathname;
196
+ if (pathname === "/api/__hitch/telephony/message-received" && request.method === "POST") {
197
+ log.set({ route: "/api/__hitch/telephony/message-received" });
198
+ if (identity.kind !== "applet") return jsonError(403, "applet_identity_required");
199
+ const parsed = await request.json().then((body) => telephonyMessageReceivedEventSchema.safeParse(body)).catch(() => void 0);
200
+ if (!parsed?.success) return jsonError(400, "malformed_request");
201
+ const onMessageReceived = server.telephony?.onMessageReceived;
202
+ if (!onMessageReceived) return jsonError(404, "no_telephony_handler");
203
+ try {
204
+ await onMessageReceived(parsed.data);
205
+ return Response.json({ ok: true });
206
+ } catch (error) {
207
+ publishNote(requestId, errorNote(error), APP_CONTEXT_CHANNEL);
208
+ return jsonError(500, error instanceof Error ? error.message : String(error));
209
+ }
210
+ }
211
+ if (pathname.startsWith(WORKFLOW_PATH_PREFIX)) {
212
+ log.set({ route: `${WORKFLOW_PATH_PREFIX}:code` });
213
+ const parsed = await request.json().then((body) => workflowInvocationRequestSchema.safeParse(body)).catch(() => void 0);
214
+ if (parsed === void 0 || !parsed.success) return jsonError(400, "malformed_request");
215
+ const code = decodeURIComponent(pathname.slice(23));
216
+ const workflows = server.workflows ?? {};
217
+ const definition = Object.hasOwn(workflows, code) ? workflows[code] : void 0;
218
+ return Response.json(definition === void 0 ? {
219
+ kind: "error",
220
+ message: `Unknown workflow "${code}".`
221
+ } : await runWorkflowInvocation(definition, parsed.data));
222
+ }
223
+ const result = await handler.handle(request, {
224
+ context: {},
225
+ prefix: "/api"
226
+ });
227
+ return result.matched ? result.response : new Response(null, { status: 404 });
228
+ });
229
+ } catch (error) {
230
+ publishNote(requestId, errorNote(error), APP_CONTEXT_CHANNEL);
231
+ throw error;
232
+ }
229
233
  } };
230
234
  }
231
235
  //#endregion
232
- export { createWorkerEntry, journalEntrySchema, workflowInvocationRequestSchema, workflowOutcomeSchema };
236
+ export { WorkflowFailedError, createEmailPixelInputSchema, createWorkerEntry, journalEntrySchema, listEmailTrackersInputSchema, markEmailTrackerSentBodySchema, runWorkflowJournal, workflowInvocationRequestSchema, workflowOutcomeSchema };
package/dist/applet.js CHANGED
@@ -14,6 +14,7 @@ const usage = `Usage:
14
14
  applet variables set <KEY> [value] [--secret] [-y | --yes]
15
15
  applet variables list
16
16
  applet variables delete <KEY> [-y | --yes]
17
+ applet schedules run <code> [-y | --yes]
17
18
 
18
19
  Login options:
19
20
  --no-browser Print the sign-in URL without opening a browser.
@@ -55,6 +56,9 @@ Variables options:
55
56
  --secret Store the value as a secret.
56
57
  -y, --yes Skip the live applet confirmation.
57
58
 
59
+ Schedules options:
60
+ -y, --yes Skip the schedule confirmation.
61
+
58
62
  Login: applet login selects the organization from hitch.config.ts and shares
59
63
  credentials with hitch login.
60
64
  CI: set HITCH_API_KEY (and HITCH_API_URL for a non-default instance).
@@ -86,7 +90,7 @@ async function main() {
86
90
  strict: true
87
91
  });
88
92
  if (positionals.length === 1 && positionals[0] === "login" && Object.keys(values).every((key) => key === "no-browser")) {
89
- await (await import("./login-iT9MRuaw.js")).runLogin({ noBrowser: values["no-browser"] });
93
+ await (await import("./login-CUx3TmFQ.js")).runLogin({ noBrowser: values["no-browser"] });
90
94
  return;
91
95
  }
92
96
  if (values["no-browser"] !== void 0) throw new Error(usage);
@@ -95,23 +99,23 @@ async function main() {
95
99
  const noLogFlags = values.run === void 0 && values.filter === void 0 && values.level === void 0 && values.limit === void 0 && values.live === void 0 && values.search === void 0 && values.since === void 0;
96
100
  const noModeFlags = values["client-only"] === void 0 && values["server-only"] === void 0;
97
101
  if (positionals.length === 1 && positionals[0] === "bootstrap" && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
98
- await (await import("./init-Wu6XmyVc.js")).runBootstrap({ install: values["no-install"] !== true });
102
+ await (await import("./init-6oGPM46R.js")).runBootstrap({ install: values["no-install"] !== true });
99
103
  return;
100
104
  }
101
105
  if (positionals.length === 1 && positionals[0] === "generate" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
102
- await (await import("./generate-DSk8ihsC.js")).runGenerate({});
106
+ await (await import("./generate-Dox-OYt6.js")).runGenerate();
103
107
  return;
104
108
  }
105
109
  if (positionals.length === 1 && positionals[0] === "build" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
106
- await (await import("./build-DhNDp7ji.js")).runBuild();
110
+ await (await import("./build-Bh_S5BUv.js")).runBuild();
107
111
  return;
108
112
  }
109
113
  if (positionals.length === 1 && positionals[0] === "deploy" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
110
- await (await import("./deploy-CqrtNJ1x.js")).runDeploy({});
114
+ await (await import("./deploy-wGYjwXrx.js")).runDeploy({});
111
115
  return;
112
116
  }
113
117
  if (positionals.length === 2 && positionals[0] === "init" && noModeFlags && noVariableFlags && noLogFlags) {
114
- await (await import("./init-Wu6XmyVc.js")).runInit(positionals[1], {
118
+ await (await import("./init-6oGPM46R.js")).runInit(positionals[1], {
115
119
  commit: values["no-commit"] !== true,
116
120
  git: values["no-git"] !== true,
117
121
  install: values["no-install"] !== true
@@ -119,7 +123,7 @@ async function main() {
119
123
  return;
120
124
  }
121
125
  if (positionals.length === 2 && positionals[0] === "new" && noGitFlags && noVariableFlags && noLogFlags) {
122
- await (await import("./init-Wu6XmyVc.js")).runNew({
126
+ await (await import("./init-6oGPM46R.js")).runNew({
123
127
  code: positionals[1],
124
128
  clientOnly: values["client-only"],
125
129
  install: values["no-install"] !== true,
@@ -128,7 +132,7 @@ async function main() {
128
132
  return;
129
133
  }
130
134
  if ((positionals.length === 1 || positionals.length === 2) && positionals[0] === "logs" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags) {
131
- await (await import("./logs-B-qZGXSK.js")).runLogs({
135
+ await (await import("./logs-DSjuEN0Q.js")).runLogs({
132
136
  code: positionals[1],
133
137
  filter: values.filter,
134
138
  run: values.run,
@@ -140,8 +144,15 @@ async function main() {
140
144
  });
141
145
  return;
142
146
  }
147
+ if (positionals.length === 3 && positionals[0] === "schedules" && positionals[1] === "run" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noLogFlags && values.secret === void 0) {
148
+ await (await import("./schedules-C8_Svr4h.js")).runSchedule({
149
+ code: positionals[2],
150
+ yes: values.yes
151
+ });
152
+ return;
153
+ }
143
154
  if ((positionals.length === 3 || positionals.length === 4) && positionals[0] === "variables" && positionals[1] === "set" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noLogFlags) {
144
- await (await import("./variables-DcwMeIau.js")).runVariablesSet({
155
+ await (await import("./variables-DT5RyHdH.js")).runVariablesSet({
145
156
  key: positionals[2],
146
157
  secret: values.secret,
147
158
  value: positionals[3],
@@ -150,11 +161,11 @@ async function main() {
150
161
  return;
151
162
  }
152
163
  if (positionals.length === 2 && positionals[0] === "variables" && positionals[1] === "list" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
153
- await (await import("./variables-DcwMeIau.js")).runVariablesList({});
164
+ await (await import("./variables-DT5RyHdH.js")).runVariablesList();
154
165
  return;
155
166
  }
156
167
  if (positionals.length === 3 && positionals[0] === "variables" && positionals[1] === "delete" && values["no-install"] === void 0 && noModeFlags && noGitFlags && values.secret === void 0 && noLogFlags) {
157
- await (await import("./variables-DcwMeIau.js")).runVariablesDelete({
168
+ await (await import("./variables-DT5RyHdH.js")).runVariablesDelete({
158
169
  key: positionals[2],
159
170
  yes: values.yes
160
171
  });
@@ -0,0 +1,2 @@
1
+ import { i as runBuild } from "./build-CEfFoIZZ.js";
2
+ export { runBuild };
@@ -1,4 +1,4 @@
1
- import { i as prepareAppletProjects, r as prepareAppletProject } from "./project-C_rtpjp8.js";
1
+ import { i as prepareAppletProjects, r as prepareAppletProject } from "./project-BRZGd6xq.js";
2
2
  import { rm } from "node:fs/promises";
3
3
  import { resolve } from "node:path";
4
4
  import { spawn } from "node:child_process";
@@ -1,6 +1,7 @@
1
- import { l as resolveInstanceUrl } from "./workspace-B6lenAS5.js";
1
+ import { f as resolveInstanceUrl } from "./workspace-D0dnnlxL.js";
2
2
  //#region src/ci.ts
3
- function githubActionsContext(env = process.env) {
3
+ function githubActionsContext() {
4
+ const env = process.env;
4
5
  if (env.GITHUB_ACTIONS !== "true" || env.HITCH_API_KEY) return void 0;
5
6
  const requestUrl = env.ACTIONS_ID_TOKEN_REQUEST_URL;
6
7
  const requestToken = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
@@ -30,14 +31,14 @@ async function githubActionsToken(context, instanceUrl, fetcher) {
30
31
  if (typeof body.value !== "string") throw new Error("GitHub returned an OIDC token response without a value.");
31
32
  return body.value;
32
33
  }
33
- async function fetchWithGitHubActions(context, options, request) {
34
- const instanceUrl = await resolveInstanceUrl(void 0, options.store);
35
- return request(instanceUrl, await githubActionsToken(context, instanceUrl, options.fetch ?? globalThis.fetch));
34
+ async function fetchWithGitHubActions(context, request) {
35
+ const instanceUrl = await resolveInstanceUrl();
36
+ return request(instanceUrl, await githubActionsToken(context, instanceUrl, globalThis.fetch));
36
37
  }
37
- async function loadGitHubActionsBuildInputs(context, options, requiresChangeset) {
38
- const fetcher = options.fetch ?? globalThis.fetch;
38
+ async function loadGitHubActionsBuildInputs(context, requiresChangeset) {
39
+ const fetcher = globalThis.fetch;
39
40
  const query = requiresChangeset === void 0 ? "" : `?changeset_id=${encodeURIComponent(requiresChangeset)}`;
40
- const response = await fetchWithGitHubActions(context, options, (instanceUrl, accessToken) => fetcher(`${instanceUrl}/api/ci/v1/build-inputs${query}`, {
41
+ const response = await fetchWithGitHubActions(context, (instanceUrl, accessToken) => fetcher(`${instanceUrl}/api/ci/v1/build-inputs${query}`, {
41
42
  method: "POST",
42
43
  headers: { Authorization: `Bearer ${accessToken}` }
43
44
  }));
@@ -49,18 +50,18 @@ async function loadGitHubActionsBuildInputs(context, options, requiresChangeset)
49
50
  theme: body.theme
50
51
  };
51
52
  }
52
- async function loadGitHubActionsSources(context, options) {
53
- const fetcher = options.fetch ?? globalThis.fetch;
54
- const response = await fetchWithGitHubActions(context, options, (instanceUrl, accessToken) => fetcher(`${instanceUrl}/api/ci/v1/applets`, { headers: { Authorization: `Bearer ${accessToken}` } }));
53
+ async function loadGitHubActionsSources(context) {
54
+ const fetcher = globalThis.fetch;
55
+ const response = await fetchWithGitHubActions(context, (instanceUrl, accessToken) => fetcher(`${instanceUrl}/api/ci/v1/applets`, { headers: { Authorization: `Bearer ${accessToken}` } }));
55
56
  if (!response.ok) throw await hitchResponseError(response, "Failed to load the CI applets");
56
57
  const body = await response.json();
57
58
  if (body === null || typeof body !== "object" || !("data" in body) || !Array.isArray(body.data)) throw new Error("The CI applets response must contain a data array.");
58
59
  return body.data.map((source) => {
59
- if (source === null || typeof source !== "object" || !("code" in source) || typeof source.code !== "string" || !("source_directory" in source) || typeof source.source_directory !== "string" || !("git_sha" in source) || source.git_sha !== null && typeof source.git_sha !== "string") throw new Error("Each CI applet must contain code, source_directory, and git_sha fields.");
60
+ if (source === null || typeof source !== "object" || !("code" in source) || typeof source.code !== "string" || !("source_directory" in source) || typeof source.source_directory !== "string" || !("source_hash" in source) || source.source_hash !== null && typeof source.source_hash !== "string") throw new Error("Each CI applet must contain code, source_directory, and source_hash fields.");
60
61
  return {
61
62
  code: source.code,
62
63
  sourceDirectory: source.source_directory,
63
- gitSha: source.git_sha
64
+ sourceHash: source.source_hash
64
65
  };
65
66
  });
66
67
  }