@hitch42/applet 0.1.0-beta.2 → 0.1.0-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.
- package/dist/_internal/server.d.ts +14 -1
- package/dist/_internal/server.js +23 -74
- package/dist/applet.js +53 -29
- package/dist/build-BfbTbt_r.js +2 -0
- package/dist/{build-BRkmrUcj.js → build-CAb26kMY.js} +30 -14
- package/dist/ci-5qWl7lT3.js +68 -0
- package/dist/client.d.ts +3 -3
- package/dist/{contract-DMrpbaLJ.d.ts → contract-rP_eV9PK.d.ts} +1 -1
- package/dist/{deploy-DKB-Tef7.js → deploy-D_OFJ6-Q.js} +193 -30
- package/dist/email-DBTVhNB_.js +62 -0
- package/dist/generate-BgepN4-b.js +2 -0
- package/dist/{generate-BFmIzHaR.js → generate-CBPnHoqX.js} +40 -18
- package/dist/index.d.ts +122 -11
- package/dist/index.js +141 -26
- package/dist/{init-CQRsnd3i.js → init-tfzwuYnk.js} +12 -8
- package/dist/load-config-BYSxDVAl.js +27 -0
- package/dist/login-C7RKmmTe.js +12 -0
- package/dist/{logs-m00pzr_O.js → logs-DgjgAxj2.js} +3 -3
- package/dist/{manifest-DyoJ1MIL.js → manifest-Bp87Uz0a.js} +6 -0
- package/dist/{manifest-BQCAxATS.d.ts → manifest-DD_SGkS6.d.ts} +5 -0
- package/dist/me-BW7Paary.js +32 -0
- package/dist/{project-CEmDnlKa.js → project-D6XHllmC.js} +32 -20
- package/dist/prompt-ChS-grYO.js +29 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +40 -42
- package/dist/schedules-dhU1yyFr.js +42 -0
- package/dist/server.d.ts +3 -3
- package/dist/telephony-protocol-D-nf3Gca.d.ts +76 -0
- package/dist/telephony.d.ts +77 -0
- package/dist/telephony.js +607 -0
- package/dist/{upload-YbRKEqR6.d.ts → upload-DKZzz5kW.d.ts} +6 -6
- package/dist/{variables-CP7Ce3Np.js → variables-Bwnr7oxf.js} +3 -28
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +464 -30
- package/dist/workflow-engine-MogejNfF.js +117 -0
- package/dist/{auth-DaVK0k5R.js → workspace-XVtM12ZC.js} +44 -4
- package/package.json +7 -1
- package/scaffold/.agents/skills/hitch-applets/SKILL.md +34 -15
- package/scaffold/.agents/skills/hitch-applets/references/email-tracking.md +49 -0
- package/scaffold/.agents/skills/hitch-applets/references/files.md +3 -3
- package/scaffold/.agents/skills/hitch-applets/references/manifest.md +21 -2
- package/scaffold/.agents/skills/hitch-applets/references/performance.md +74 -0
- package/scaffold/.agents/skills/hitch-applets/references/records.md +30 -8
- package/scaffold/.agents/skills/hitch-applets/references/schedules.md +7 -2
- package/scaffold/.agents/skills/hitch-applets/references/server.md +0 -3
- package/scaffold/.agents/skills/hitch-applets/references/workflows.md +11 -3
- package/scaffold/.agents/skills/hitch-cli/SKILL.md +129 -0
- package/scaffold/.agents/skills/hitch-data/SKILL.md +51 -0
- package/scaffold/.agents/skills/hitch-data/references/attributes.md +121 -0
- package/scaffold/.agents/skills/hitch-data/references/limits.md +64 -0
- package/scaffold/.agents/skills/hitch-theory/SKILL.md +150 -0
- package/scaffold/.github/workflows/hitch.yml +15 -0
- package/dist/build-CMluoV6q.js +0 -2
- package/dist/generate-CefnB-bp.js +0 -2
- package/dist/load-config-BnxocLAQ.js +0 -56
|
@@ -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
|
-
|
|
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 };
|
package/dist/_internal/server.js
CHANGED
|
@@ -1,80 +1,16 @@
|
|
|
1
|
+
import { c as listEmailTrackersInputSchema, t as createEmailPixelInputSchema, u as markEmailTrackerSentBodySchema } from "../email-DBTVhNB_.js";
|
|
2
|
+
import { a as workflowOutcomeSchema, c as HITCH_SESSION_HEADER, i as workflowInvocationRequestSchema, l as HITCH_USER_HEADER, n as runWorkflowJournal, o as HITCH_APPLET_HEADER, r as journalEntrySchema, s as HITCH_APPLET_TOKEN_HEADER, t as WorkflowFailedError } from "../workflow-engine-MogejNfF.js";
|
|
1
3
|
import { o as runWithRequestContext, r as toMilliseconds, t as MAX_DURATION_MS } from "../workflow-CTo2kZF1.js";
|
|
2
4
|
import { z } from "zod";
|
|
3
5
|
import { RPCHandler } from "@orpc/server/fetch";
|
|
4
|
-
//#region src/
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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)
|
|
6
|
+
//#region src/server/telephony-protocol.ts
|
|
7
|
+
const telephonyMessageReceivedEventSchema = z.object({
|
|
8
|
+
eventId: z.string(),
|
|
9
|
+
type: z.literal("message.received"),
|
|
10
|
+
messageId: z.string(),
|
|
11
|
+
numberId: z.string(),
|
|
12
|
+
occurredAt: z.iso.datetime()
|
|
40
13
|
});
|
|
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
14
|
//#endregion
|
|
79
15
|
//#region src/server/workflow-run.ts
|
|
80
16
|
const MAX_RESULT_SIZE = 1048576;
|
|
@@ -209,6 +145,19 @@ function createWorkerEntry(server, options) {
|
|
|
209
145
|
}
|
|
210
146
|
}, async () => {
|
|
211
147
|
const pathname = new URL(request.url).pathname;
|
|
148
|
+
if (pathname === "/api/__hitch/telephony/message-received" && request.method === "POST") {
|
|
149
|
+
if (identity.kind !== "applet") return jsonError(403, "applet_identity_required");
|
|
150
|
+
const parsed = await request.json().then((body) => telephonyMessageReceivedEventSchema.safeParse(body)).catch(() => void 0);
|
|
151
|
+
if (!parsed?.success) return jsonError(400, "malformed_request");
|
|
152
|
+
const onMessageReceived = server.telephony?.onMessageReceived;
|
|
153
|
+
if (!onMessageReceived) return jsonError(404, "no_telephony_handler");
|
|
154
|
+
try {
|
|
155
|
+
await onMessageReceived(parsed.data);
|
|
156
|
+
return Response.json({ ok: true });
|
|
157
|
+
} catch (error) {
|
|
158
|
+
return jsonError(500, error instanceof Error ? error.message : String(error));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
212
161
|
if (pathname.startsWith(WORKFLOW_PATH_PREFIX)) {
|
|
213
162
|
const parsed = await request.json().then((body) => workflowInvocationRequestSchema.safeParse(body)).catch(() => void 0);
|
|
214
163
|
if (parsed === void 0 || !parsed.success) return jsonError(400, "malformed_request");
|
|
@@ -229,4 +178,4 @@ function createWorkerEntry(server, options) {
|
|
|
229
178
|
} };
|
|
230
179
|
}
|
|
231
180
|
//#endregion
|
|
232
|
-
export { createWorkerEntry, journalEntrySchema, workflowInvocationRequestSchema, workflowOutcomeSchema };
|
|
181
|
+
export { WorkflowFailedError, createEmailPixelInputSchema, createWorkerEntry, journalEntrySchema, listEmailTrackersInputSchema, markEmailTrackerSentBodySchema, runWorkflowJournal, workflowInvocationRequestSchema, workflowOutcomeSchema };
|
package/dist/applet.js
CHANGED
|
@@ -2,17 +2,22 @@
|
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
//#region bin/applet.ts
|
|
4
4
|
const usage = `Usage:
|
|
5
|
+
applet login [--no-browser]
|
|
5
6
|
applet init <org> [--no-commit | --no-git] [--no-install]
|
|
6
7
|
applet bootstrap [--no-install]
|
|
7
8
|
applet new <code> [--client-only | --server-only] [--no-install]
|
|
8
|
-
applet generate
|
|
9
|
-
applet build
|
|
10
|
-
applet deploy
|
|
9
|
+
applet generate
|
|
10
|
+
applet build
|
|
11
|
+
applet deploy
|
|
11
12
|
applet logs [code] [--since <duration>] [--limit <count>]
|
|
12
13
|
[--search <text>] [--level <level>] [--filter <json>] [--run <id>] [--live]
|
|
13
14
|
applet variables set <KEY> [value] [--secret] [-y | --yes]
|
|
14
15
|
applet variables list
|
|
15
16
|
applet variables delete <KEY> [-y | --yes]
|
|
17
|
+
applet schedules run <code> [-y | --yes]
|
|
18
|
+
|
|
19
|
+
Login options:
|
|
20
|
+
--no-browser Print the sign-in URL without opening a browser.
|
|
16
21
|
|
|
17
22
|
Init options:
|
|
18
23
|
--no-commit Do not create the initial commit
|
|
@@ -27,14 +32,14 @@ New options:
|
|
|
27
32
|
Bootstrap options:
|
|
28
33
|
--no-install Do not run pnpm install
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
Schema changesets:
|
|
36
|
+
Set requiresChangeset in applet.manifest.ts to generate, build, and deploy
|
|
37
|
+
against a pending changeset. The release goes live when the changeset
|
|
38
|
+
applies in Hitch. After it applies, the field uses the live schema.
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
when the changeset applies. Manifest mismatches warn.
|
|
40
|
+
Run applet deploy in the workspace root to deploy every applet. In GitHub
|
|
41
|
+
Actions it skips an applet when neither its folder nor any file outside
|
|
42
|
+
applets/ changed since its current CI release.
|
|
38
43
|
|
|
39
44
|
Logs options:
|
|
40
45
|
--since <duration> Show logs from this period. Default: 1h. Maximum: 7d.
|
|
@@ -51,18 +56,25 @@ Variables options:
|
|
|
51
56
|
--secret Store the value as a secret.
|
|
52
57
|
-y, --yes Skip the live applet confirmation.
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
Schedules options:
|
|
60
|
+
-y, --yes Skip the schedule confirmation.
|
|
61
|
+
|
|
62
|
+
Login: applet login selects the organization from hitch.config.ts and shares
|
|
63
|
+
credentials with hitch login.
|
|
64
|
+
CI: set HITCH_API_KEY (and HITCH_API_URL for a non-default instance).
|
|
65
|
+
GitHub Actions: generate, build, and deploy use the job's OIDC token instead of
|
|
66
|
+
a key. Grant the job id-token: write.`;
|
|
55
67
|
async function main() {
|
|
56
68
|
const { positionals, values } = parseArgs({
|
|
57
69
|
allowPositionals: true,
|
|
58
70
|
options: {
|
|
59
|
-
changeset: { type: "string" },
|
|
60
71
|
"client-only": { type: "boolean" },
|
|
61
72
|
filter: { type: "string" },
|
|
62
73
|
run: { type: "string" },
|
|
63
74
|
level: { type: "string" },
|
|
64
75
|
limit: { type: "string" },
|
|
65
76
|
live: { type: "boolean" },
|
|
77
|
+
"no-browser": { type: "boolean" },
|
|
66
78
|
"no-commit": { type: "boolean" },
|
|
67
79
|
"no-git": { type: "boolean" },
|
|
68
80
|
"no-install": { type: "boolean" },
|
|
@@ -77,36 +89,41 @@ async function main() {
|
|
|
77
89
|
},
|
|
78
90
|
strict: true
|
|
79
91
|
});
|
|
92
|
+
if (positionals.length === 1 && positionals[0] === "login" && Object.keys(values).every((key) => key === "no-browser")) {
|
|
93
|
+
await (await import("./login-C7RKmmTe.js")).runLogin({ noBrowser: values["no-browser"] });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (values["no-browser"] !== void 0) throw new Error(usage);
|
|
80
97
|
const noGitFlags = values["no-commit"] === void 0 && values["no-git"] === void 0;
|
|
81
98
|
const noVariableFlags = values.secret === void 0 && values.yes === void 0;
|
|
82
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;
|
|
83
100
|
const noModeFlags = values["client-only"] === void 0 && values["server-only"] === void 0;
|
|
84
|
-
if (positionals.length === 1 && positionals[0] === "bootstrap" &&
|
|
85
|
-
await (await import("./init-
|
|
101
|
+
if (positionals.length === 1 && positionals[0] === "bootstrap" && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
|
|
102
|
+
await (await import("./init-tfzwuYnk.js")).runBootstrap({ install: values["no-install"] !== true });
|
|
86
103
|
return;
|
|
87
104
|
}
|
|
88
105
|
if (positionals.length === 1 && positionals[0] === "generate" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
|
|
89
|
-
await (await import("./generate-
|
|
106
|
+
await (await import("./generate-BgepN4-b.js")).runGenerate({});
|
|
90
107
|
return;
|
|
91
108
|
}
|
|
92
109
|
if (positionals.length === 1 && positionals[0] === "build" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
|
|
93
|
-
await (await import("./build-
|
|
110
|
+
await (await import("./build-BfbTbt_r.js")).runBuild();
|
|
94
111
|
return;
|
|
95
112
|
}
|
|
96
113
|
if (positionals.length === 1 && positionals[0] === "deploy" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
|
|
97
|
-
await (await import("./deploy-
|
|
114
|
+
await (await import("./deploy-D_OFJ6-Q.js")).runDeploy({});
|
|
98
115
|
return;
|
|
99
116
|
}
|
|
100
|
-
if (positionals.length === 2 && positionals[0] === "init" &&
|
|
101
|
-
await (await import("./init-
|
|
117
|
+
if (positionals.length === 2 && positionals[0] === "init" && noModeFlags && noVariableFlags && noLogFlags) {
|
|
118
|
+
await (await import("./init-tfzwuYnk.js")).runInit(positionals[1], {
|
|
102
119
|
commit: values["no-commit"] !== true,
|
|
103
120
|
git: values["no-git"] !== true,
|
|
104
121
|
install: values["no-install"] !== true
|
|
105
122
|
});
|
|
106
123
|
return;
|
|
107
124
|
}
|
|
108
|
-
if (positionals.length === 2 && positionals[0] === "new" &&
|
|
109
|
-
await (await import("./init-
|
|
125
|
+
if (positionals.length === 2 && positionals[0] === "new" && noGitFlags && noVariableFlags && noLogFlags) {
|
|
126
|
+
await (await import("./init-tfzwuYnk.js")).runNew({
|
|
110
127
|
code: positionals[1],
|
|
111
128
|
clientOnly: values["client-only"],
|
|
112
129
|
install: values["no-install"] !== true,
|
|
@@ -114,8 +131,8 @@ async function main() {
|
|
|
114
131
|
});
|
|
115
132
|
return;
|
|
116
133
|
}
|
|
117
|
-
if ((positionals.length === 1 || positionals.length === 2) && positionals[0] === "logs" && values
|
|
118
|
-
await (await import("./logs-
|
|
134
|
+
if ((positionals.length === 1 || positionals.length === 2) && positionals[0] === "logs" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags) {
|
|
135
|
+
await (await import("./logs-DgjgAxj2.js")).runLogs({
|
|
119
136
|
code: positionals[1],
|
|
120
137
|
filter: values.filter,
|
|
121
138
|
run: values.run,
|
|
@@ -127,8 +144,15 @@ async function main() {
|
|
|
127
144
|
});
|
|
128
145
|
return;
|
|
129
146
|
}
|
|
130
|
-
if (
|
|
131
|
-
await (await import("./
|
|
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-dhU1yyFr.js")).runSchedule({
|
|
149
|
+
code: positionals[2],
|
|
150
|
+
yes: values.yes
|
|
151
|
+
});
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if ((positionals.length === 3 || positionals.length === 4) && positionals[0] === "variables" && positionals[1] === "set" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noLogFlags) {
|
|
155
|
+
await (await import("./variables-Bwnr7oxf.js")).runVariablesSet({
|
|
132
156
|
key: positionals[2],
|
|
133
157
|
secret: values.secret,
|
|
134
158
|
value: positionals[3],
|
|
@@ -136,12 +160,12 @@ async function main() {
|
|
|
136
160
|
});
|
|
137
161
|
return;
|
|
138
162
|
}
|
|
139
|
-
if (positionals.length === 2 && positionals[0] === "variables" &&
|
|
140
|
-
await (await import("./variables-
|
|
163
|
+
if (positionals.length === 2 && positionals[0] === "variables" && positionals[1] === "list" && values["no-install"] === void 0 && noModeFlags && noGitFlags && noVariableFlags && noLogFlags) {
|
|
164
|
+
await (await import("./variables-Bwnr7oxf.js")).runVariablesList({});
|
|
141
165
|
return;
|
|
142
166
|
}
|
|
143
|
-
if (positionals.length === 3 && positionals[0] === "variables" &&
|
|
144
|
-
await (await import("./variables-
|
|
167
|
+
if (positionals.length === 3 && positionals[0] === "variables" && positionals[1] === "delete" && values["no-install"] === void 0 && noModeFlags && noGitFlags && values.secret === void 0 && noLogFlags) {
|
|
168
|
+
await (await import("./variables-Bwnr7oxf.js")).runVariablesDelete({
|
|
145
169
|
key: positionals[2],
|
|
146
170
|
yes: values.yes
|
|
147
171
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { r as prepareAppletProject } from "./project-
|
|
1
|
+
import { i as prepareAppletProjects, r as prepareAppletProject } from "./project-D6XHllmC.js";
|
|
2
2
|
import { rm } from "node:fs/promises";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
+
import { createInterface } from "node:readline";
|
|
5
6
|
//#region src/build.ts
|
|
6
7
|
function isMissingFile(error) {
|
|
7
8
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
@@ -11,7 +12,8 @@ async function runPnpm(args, cwd) {
|
|
|
11
12
|
let finished = false;
|
|
12
13
|
const child = spawn("pnpm", args, {
|
|
13
14
|
cwd,
|
|
14
|
-
stdio: "inherit"
|
|
15
|
+
stdio: "inherit",
|
|
16
|
+
shell: process.platform === "win32"
|
|
15
17
|
});
|
|
16
18
|
child.once("error", (error) => {
|
|
17
19
|
finished = true;
|
|
@@ -28,14 +30,19 @@ async function runPnpm(args, cwd) {
|
|
|
28
30
|
});
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
|
-
async function buildApplet(
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
async function buildApplet(appletRoot, outDir = ".hitch/dist") {
|
|
34
|
+
await runPnpm(["install"], await prepareAppletProject(appletRoot));
|
|
35
|
+
await buildPreparedApplet(appletRoot, outDir);
|
|
36
|
+
}
|
|
37
|
+
async function prepareWorkspaceBuild(workspaceRoot, appletRoots) {
|
|
38
|
+
await prepareAppletProjects(workspaceRoot, appletRoots);
|
|
39
|
+
await runPnpm(["install"], workspaceRoot);
|
|
40
|
+
}
|
|
41
|
+
async function buildPreparedApplet(appletRoot, outDir = ".hitch/dist", logPrefix = "") {
|
|
34
42
|
await rm(resolve(appletRoot, ".hitch"), {
|
|
35
43
|
force: true,
|
|
36
44
|
recursive: true
|
|
37
45
|
});
|
|
38
|
-
await runPnpm(["install"], workspaceRoot);
|
|
39
46
|
await new Promise((resolveBuild, rejectBuild) => {
|
|
40
47
|
let finished = false;
|
|
41
48
|
const child = spawn("pnpm", [
|
|
@@ -46,12 +53,21 @@ async function buildApplet(changesetId, outDir = ".hitch/dist") {
|
|
|
46
53
|
outDir
|
|
47
54
|
], {
|
|
48
55
|
cwd: appletRoot,
|
|
49
|
-
stdio: "inherit"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
stdio: logPrefix === "" ? "inherit" : [
|
|
57
|
+
"ignore",
|
|
58
|
+
"pipe",
|
|
59
|
+
"pipe"
|
|
60
|
+
],
|
|
61
|
+
shell: process.platform === "win32"
|
|
54
62
|
});
|
|
63
|
+
if (child.stdout) createInterface({
|
|
64
|
+
input: child.stdout,
|
|
65
|
+
crlfDelay: Infinity
|
|
66
|
+
}).on("line", (line) => console.log(`${logPrefix}${line}`));
|
|
67
|
+
if (child.stderr) createInterface({
|
|
68
|
+
input: child.stderr,
|
|
69
|
+
crlfDelay: Infinity
|
|
70
|
+
}).on("line", (line) => console.error(`${logPrefix}${line}`));
|
|
55
71
|
child.once("error", (error) => {
|
|
56
72
|
finished = true;
|
|
57
73
|
rejectBuild(isMissingFile(error) ? /* @__PURE__ */ new Error("pnpm was not found. Install pnpm, then run applet build again.") : error);
|
|
@@ -67,8 +83,8 @@ async function buildApplet(changesetId, outDir = ".hitch/dist") {
|
|
|
67
83
|
});
|
|
68
84
|
});
|
|
69
85
|
}
|
|
70
|
-
async function runBuild(
|
|
71
|
-
await buildApplet(
|
|
86
|
+
async function runBuild() {
|
|
87
|
+
await buildApplet(process.cwd());
|
|
72
88
|
}
|
|
73
89
|
//#endregion
|
|
74
|
-
export { runBuild as n, buildApplet as t };
|
|
90
|
+
export { runBuild as i, buildPreparedApplet as n, prepareWorkspaceBuild as r, buildApplet as t };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { d as resolveInstanceUrl } from "./workspace-XVtM12ZC.js";
|
|
2
|
+
//#region src/ci.ts
|
|
3
|
+
function githubActionsContext(env = process.env) {
|
|
4
|
+
if (env.GITHUB_ACTIONS !== "true" || env.HITCH_API_KEY) return void 0;
|
|
5
|
+
const requestUrl = env.ACTIONS_ID_TOKEN_REQUEST_URL;
|
|
6
|
+
const requestToken = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
7
|
+
if (!requestUrl || !requestToken) throw new Error("GitHub Actions did not provide an OIDC token. Grant the job the id-token: write permission, or set HITCH_API_KEY.");
|
|
8
|
+
return {
|
|
9
|
+
requestUrl,
|
|
10
|
+
requestToken
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async function hitchResponseError(response, summary) {
|
|
14
|
+
let details = "";
|
|
15
|
+
try {
|
|
16
|
+
const body = await response.json();
|
|
17
|
+
if (body !== null && typeof body === "object") details = ["code" in body && typeof body.code === "string" ? body.code : void 0, "message" in body && typeof body.message === "string" ? body.message : void 0].filter((value) => value !== void 0).join(": ");
|
|
18
|
+
} catch {
|
|
19
|
+
details = "";
|
|
20
|
+
}
|
|
21
|
+
return /* @__PURE__ */ new Error(`${summary} (${response.status})${details ? `: ${details}` : ""}.`);
|
|
22
|
+
}
|
|
23
|
+
async function githubActionsToken(context, instanceUrl, fetcher) {
|
|
24
|
+
const url = new URL(context.requestUrl);
|
|
25
|
+
url.searchParams.set("audience", new URL(instanceUrl).origin);
|
|
26
|
+
const response = await fetcher(url, { headers: { Authorization: `bearer ${context.requestToken}` } });
|
|
27
|
+
if (!response.ok) throw new Error(`GitHub did not issue an OIDC token (${response.status}).`);
|
|
28
|
+
const body = await response.json();
|
|
29
|
+
if (body === null || typeof body !== "object" || !("value" in body)) throw new Error("GitHub returned an OIDC token response without a value.");
|
|
30
|
+
if (typeof body.value !== "string") throw new Error("GitHub returned an OIDC token response without a value.");
|
|
31
|
+
return body.value;
|
|
32
|
+
}
|
|
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));
|
|
36
|
+
}
|
|
37
|
+
async function loadGitHubActionsBuildInputs(context, options, requiresChangeset) {
|
|
38
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
39
|
+
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
|
+
method: "POST",
|
|
42
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
43
|
+
}));
|
|
44
|
+
if (!response.ok) throw await hitchResponseError(response, "Failed to load the CI build inputs");
|
|
45
|
+
const body = await response.json();
|
|
46
|
+
if (body === null || typeof body !== "object" || !("openapi" in body) || !("theme" in body) || typeof body.theme !== "string") throw new Error("The CI build inputs must contain an openapi document and a theme string.");
|
|
47
|
+
return {
|
|
48
|
+
openapi: body.openapi,
|
|
49
|
+
theme: body.theme
|
|
50
|
+
};
|
|
51
|
+
}
|
|
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}` } }));
|
|
55
|
+
if (!response.ok) throw await hitchResponseError(response, "Failed to load the CI applets");
|
|
56
|
+
const body = await response.json();
|
|
57
|
+
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
|
+
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
|
+
return {
|
|
61
|
+
code: source.code,
|
|
62
|
+
sourceDirectory: source.source_directory,
|
|
63
|
+
gitSha: source.git_sha
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { loadGitHubActionsSources as a, loadGitHubActionsBuildInputs as i, githubActionsContext as n, hitchResponseError as r, fetchWithGitHubActions as t };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { f as RegisteredContract, m as RegisteredRouter, p as RegisteredManifest } from "./manifest-
|
|
2
|
-
import { t as NarrowContract } from "./contract-
|
|
1
|
+
import { f as RegisteredContract, m as RegisteredRouter, p as RegisteredManifest } from "./manifest-DD_SGkS6.js";
|
|
2
|
+
import { t as NarrowContract } from "./contract-rP_eV9PK.js";
|
|
3
3
|
import { t as WithBatchRecorder } from "./batch-Qa4B4-Yp.js";
|
|
4
|
-
import { o as WithFilesUpload } from "./upload-
|
|
4
|
+
import { o as WithFilesUpload } from "./upload-DKZzz5kW.js";
|
|
5
5
|
import { RouterClient } from "@orpc/server";
|
|
6
6
|
import { ContractRouterClient } from "@orpc/contract";
|
|
7
7
|
import { NestedClient } from "@orpc/client";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as AppletManifest } from "./manifest-
|
|
1
|
+
import { n as AppletManifest } from "./manifest-DD_SGkS6.js";
|
|
2
2
|
import { AnyContractRouter } from "@orpc/contract";
|
|
3
3
|
//#region src/hitch/contract.d.ts
|
|
4
4
|
type ManifestObjectFor<Manifest, Code> = Manifest extends {
|