@hitch42/applet 0.1.1-beta.21 → 0.1.1-beta.23

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 (54) hide show
  1. package/dist/_internal/server.d.ts +1 -1
  2. package/dist/applet.js +16 -16
  3. package/dist/{store-E5NhITHl.js → auth-OvyoB6M-.js} +203 -4
  4. package/dist/{batch-CiLZ177G.js → batch-DwyWmiaE.js} +1 -1
  5. package/dist/{build-FAQSHJgm.js → build-CrrTAX6T.js} +1 -1
  6. package/dist/build-YzjhhLw0.js +1 -0
  7. package/dist/{ci-oWlUJKm9.js → ci-B1XyXpHa.js} +2 -2
  8. package/dist/client/hitch/client.d.ts +1 -1
  9. package/dist/client/hitch/client.js +1 -1
  10. package/dist/client/hitch.d.ts +1 -1
  11. package/dist/client/hitch.js +1 -1
  12. package/dist/client/react/markdown-editor.d.ts +1 -1
  13. package/dist/client/react/markdown.d.ts +1 -1
  14. package/dist/client/react/markdown.js +1 -1
  15. package/dist/client/react.d.ts +2 -2
  16. package/dist/client/react.js +1 -1
  17. package/dist/{deploy-BM55ZoSp.js → deploy-WdARFHmA.js} +7 -7
  18. package/dist/{email-protocol-CEqzASSx.d.ts → email-protocol-BWja_v7c.d.ts} +16 -10
  19. package/dist/{generate-48pqFh5M.js → generate-Ct-Rbh0f.js} +11 -11
  20. package/dist/generate-_u-zFzrv.js +1 -0
  21. package/dist/{git-credential-CU7-Erzs.js → git-credential-DuLNowIb.js} +1 -1
  22. package/dist/{git-deploy-C12nMNB6.js → git-deploy-BjSAv5Qm.js} +1 -2
  23. package/dist/git-deploy-CByu_uli.js +1 -0
  24. package/dist/{git-migration-CIq-sN61.js → git-migration-6V31iafL.js} +3 -3
  25. package/dist/{hitch-client-Dph_kzDd.js → hitch-client-CNN-dU6d.js} +2 -2
  26. package/dist/{hitch-client-D33JOEOi.d.ts → hitch-client-k7_jIjPw.d.ts} +1 -1
  27. package/dist/index.d.ts +8 -5
  28. package/dist/index.js +12 -12
  29. package/dist/{init-Bb6WT8UB.js → init-C5HqIRt8.js} +5 -6
  30. package/dist/{load-config-Cffvj-aM.js → load-config-Df-zmfrd.js} +1 -0
  31. package/dist/{login-BWZKo7Ui.js → login-B41-WWtD.js} +1 -2
  32. package/dist/{logs-glCVHI-8.js → logs-DrL2ytmg.js} +2 -2
  33. package/dist/{markdown-BXt65dDo.d.ts → markdown-CnB35mjc.d.ts} +1 -1
  34. package/dist/{markdown-BA_XzFxq.js → markdown-DLdJOJ59.js} +2 -0
  35. package/dist/{markdown-editor-CB_nWLzj.d.ts → markdown-editor-xF3uATBp.d.ts} +1 -1
  36. package/dist/{project-DZGk765E.js → project-BbpU_VN2.js} +2 -2
  37. package/dist/{schedules-CSUb84e2.js → schedules-2Q_fkY_a.js} +1 -1
  38. package/dist/server.d.ts +1 -1
  39. package/dist/server.js +2 -2
  40. package/dist/{upload-DtMavo8Q.js → upload-D1mzpsSk.js} +2 -2
  41. package/dist/{upload-DXZyjZSS.d.ts → upload-wp-Ilsv6.d.ts} +3 -3
  42. package/dist/{variables-CgZstC7I.js → variables-CGwbmUom.js} +2 -2
  43. package/dist/vite.js +3 -3
  44. package/package.json +8 -7
  45. package/scaffold/.agents/skills/hitch-applets/references/email-tracking.md +4 -4
  46. package/scaffold/.agents/skills/hitch-applets/references/files.md +2 -2
  47. package/scaffold/.agents/skills/hitch-applets/references/performance.md +2 -2
  48. package/scaffold/.agents/skills/hitch-applets/references/records.md +7 -7
  49. package/scaffold/.agents/skills/hitch-cli/SKILL.md +21 -21
  50. package/dist/auth-DuMRqSGe.js +0 -49
  51. package/dist/build-C7hi2yg4.js +0 -1
  52. package/dist/device-CZWWckCq.js +0 -155
  53. package/dist/generate-BYK4aNud.js +0 -1
  54. package/dist/git-deploy-CNz6mxiF.js +0 -1
@@ -1,155 +0,0 @@
1
- import { c as normalizeInstanceUrl, d as rejectEnvironmentKey, g as saveOAuthCredentials, l as organizationInstanceUrl, o as credentialStorageMessage, t as AuthenticationError, u as readCredentialStore } from "./store-E5NhITHl.js";
2
- import { spawn } from "node:child_process";
3
- import readline from "node:readline/promises";
4
- // ../shared/auth/src/device.mts
5
- const CLIENT_ID = "hitch-cli-oauth";
6
- const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
7
- function defaultOpenUrl(url) {
8
- try {
9
- const child = spawn(process.platform === "darwin" ? "open" : "xdg-open", [url], {
10
- detached: true,
11
- stdio: "ignore"
12
- });
13
- child.on("error", () => void 0);
14
- child.unref();
15
- } catch {}
16
- }
17
- function requiredObject(value, message) {
18
- if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(message);
19
- return value;
20
- }
21
- async function jsonResponse(response) {
22
- try {
23
- return requiredObject(await response.json(), "Expected a JSON object response.");
24
- } catch (error) {
25
- throw new Error(`Invalid JSON response from ${response.url || "Hitch"}.`, { cause: error });
26
- }
27
- }
28
- async function postJson(fetcher, url, body) {
29
- const response = await fetcher(url, {
30
- method: "POST",
31
- headers: { "content-type": "application/json" },
32
- body: JSON.stringify(body)
33
- });
34
- return {
35
- body: await jsonResponse(response),
36
- response
37
- };
38
- }
39
- function parseDeviceCode(value) {
40
- if (typeof value.device_code !== "string" || typeof value.user_code !== "string" || typeof value.verification_uri !== "string" || typeof value.verification_uri_complete !== "string" || typeof value.expires_in !== "number" || value.interval !== void 0 && typeof value.interval !== "number") throw new AuthenticationError("Hitch returned an invalid device authorization response.");
41
- return value;
42
- }
43
- function parseToken(value) {
44
- return typeof value.access_token === "string" && typeof value.refresh_token === "string" && typeof value.expires_in === "number" && typeof value.token_type === "string" ? value : void 0;
45
- }
46
- function parseMe(input) {
47
- const value = requiredObject(input, "Hitch returned an invalid identity response.");
48
- const person = requiredObject(value.person, "Hitch returned an invalid identity response.");
49
- if (typeof person.id !== "string" || typeof person.firstName !== "string" || typeof person.lastName !== "string" || typeof person.email !== "string" || !Array.isArray(value.memberships)) throw new Error("Hitch returned an invalid identity response.");
50
- const organization = value.organization === void 0 || value.organization === null ? null : requiredObject(value.organization, "Hitch returned an invalid identity response.");
51
- if (organization !== null && (typeof organization.id !== "string" || typeof organization.code !== "string")) throw new Error("Hitch returned an invalid identity response.");
52
- return {
53
- memberships: value.memberships.map((membership) => {
54
- const item = requiredObject(membership, "Hitch returned an invalid membership.");
55
- if (typeof item.orgId !== "string" || typeof item.code !== "string" || typeof item.name !== "string") throw new Error("Hitch returned an invalid membership.");
56
- return item;
57
- }),
58
- organization,
59
- person
60
- };
61
- }
62
- async function fetchMe(fetcher, instanceUrl, auth) {
63
- const response = await fetcher(`${instanceUrl}/api/me/v1`, { headers: { Authorization: `Bearer ${auth.accessToken}` } });
64
- rejectEnvironmentKey(response, auth);
65
- if (auth.credentialType === "apiKey" && response.status === 401) throw new AuthenticationError("API key rejected.");
66
- const body = await jsonResponse(response);
67
- if (!response.ok) throw new AuthenticationError(typeof body.message === "string" ? body.message : `Failed to load the signed-in identity (${response.status}).`);
68
- return parseMe(body);
69
- }
70
- async function pollForToken(fetcher, instanceUrl, resource, device, now, sleep) {
71
- const deadline = now() + device.expires_in * 1e3;
72
- let interval = (device.interval ?? 5) * 1e3;
73
- while (now() < deadline) {
74
- await sleep(Math.min(interval, deadline - now()));
75
- if (now() >= deadline) break;
76
- const response = await fetcher(`${instanceUrl}/api/auth/oauth2/token`, {
77
- method: "POST",
78
- headers: { "content-type": "application/x-www-form-urlencoded" },
79
- body: new URLSearchParams({
80
- grant_type: DEVICE_GRANT,
81
- device_code: device.device_code,
82
- client_id: CLIENT_ID,
83
- resource
84
- })
85
- });
86
- const body = await jsonResponse(response);
87
- const token = parseToken(body);
88
- if (response.ok && token !== void 0) return token;
89
- switch (body.error) {
90
- case "authorization_pending": break;
91
- case "slow_down":
92
- interval += 5e3;
93
- break;
94
- case "expired_token": throw new AuthenticationError("The sign-in request expired. Run hitch login again.");
95
- case "access_denied": throw new AuthenticationError("Sign-in was denied.");
96
- default: throw new AuthenticationError(typeof body.error_description === "string" ? body.error_description : `Sign-in failed (${response.status}).`);
97
- }
98
- }
99
- throw new AuthenticationError("The sign-in request expired. Run hitch login again.");
100
- }
101
- async function loginWithDevice(instanceUrl, options = {}) {
102
- const fetcher = globalThis.fetch;
103
- const now = Date.now;
104
- const storedOrgs = Object.keys((await readCredentialStore()).instances[normalizeInstanceUrl(instanceUrl)] ?? {});
105
- let orgCode = options.expectedOrg ?? process.env.HITCH_DEFAULT_ORG ?? (storedOrgs.length === 1 ? storedOrgs[0] : void 0);
106
- if (orgCode === void 0 && process.stdin.isTTY === true) {
107
- const terminal = readline.createInterface({
108
- input: process.stdin,
109
- output: process.stdout
110
- });
111
- try {
112
- orgCode = (await terminal.question("Organization code: ")).trim();
113
- } finally {
114
- terminal.close();
115
- }
116
- }
117
- if (!orgCode) throw new AuthenticationError("Select an organization with --org or HITCH_DEFAULT_ORG.");
118
- const organizationUrl = organizationInstanceUrl(instanceUrl, orgCode);
119
- const resource = `${organizationUrl}/mcp`;
120
- const { body, response } = await postJson(fetcher, `${instanceUrl}/api/auth/device/code`, {
121
- client_id: CLIENT_ID,
122
- scope: "openid offline_access",
123
- resource
124
- });
125
- if (!response.ok) throw new AuthenticationError(typeof body.error_description === "string" ? body.error_description : `Could not start sign-in (${response.status}).`);
126
- const device = parseDeviceCode(body);
127
- const verificationUrl = device.verification_uri_complete;
128
- console.log(`Open ${verificationUrl} and confirm code ${device.user_code}.`);
129
- if (!options.noBrowser) try {
130
- defaultOpenUrl(verificationUrl);
131
- } catch {}
132
- const token = await pollForToken(fetcher, instanceUrl, resource, device, now, (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
133
- const me = await fetchMe(fetcher, organizationUrl, {
134
- accessToken: token.access_token,
135
- credentialType: "session",
136
- source: "store"
137
- });
138
- const membership = me.memberships.find(({ code }) => code === orgCode);
139
- if (membership === void 0) throw new AuthenticationError(`You are not a member of the Hitch organization "${orgCode}".`);
140
- const credentials = await saveOAuthCredentials(instanceUrl, {
141
- type: "oauth",
142
- accessToken: token.access_token,
143
- expiresAt: now() + token.expires_in * 1e3,
144
- organizationId: membership.orgId,
145
- orgCode
146
- }, token.refresh_token);
147
- const storageMessage = credentialStorageMessage();
148
- if (storageMessage !== void 0) console.log(storageMessage);
149
- return {
150
- credentials,
151
- me,
152
- membership
153
- };
154
- }
155
- export { parseMe as n, loginWithDevice as t };
@@ -1 +0,0 @@
1
- export { r as runGenerate } from "./generate-48pqFh5M.js";
@@ -1 +0,0 @@
1
- export { c as runClone } from "./git-deploy-C12nMNB6.js";