@superwall/cli 2.5.1 → 2.6.0-beta.1
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/{apple-BSKxY7Gx.js → apple-Bmt_iywx.js} +14 -14
- package/dist/{approve-DbwsYO4s.js → approve-D2UgqaRx.js} +27 -27
- package/dist/{assets-CqpFg5mM.js → assets-B_quADds.js} +3 -3
- package/dist/auth.js +3 -3
- package/dist/{session-DYdxTNZf.js → base-ChTi42M0.js} +35 -35
- package/dist/{billing-BopwIhR3.js → billing-ZIETn0j4.js} +3 -3
- package/dist/{bind-DOF3o3FR.js → bind-ClFjTt0U.js} +4 -4
- package/dist/{build-BF22vVdV.js → build-BWjXurjs.js} +10 -10
- package/dist/{client-DHlsTaP1.js → client-CyrYJzBF.js} +3 -3
- package/dist/create-7HDW3DCl.js +20 -0
- package/dist/{create-CiZzZrru.js → create-BCIgjRHn.js} +6 -6
- package/dist/{create-CboPfAlN.js → create-C3uklw-U.js} +31 -31
- package/dist/{doctor-BqZGaQE5.js → doctor-D2Q1EZe8.js} +6 -6
- package/dist/{drivers-DkboeR1c.js → drivers-BQkO5tHs.js} +3 -3
- package/dist/entry.js +20 -20
- package/dist/{environment-FR3bcq0D.js → environment-BocmdvZ-.js} +1 -1
- package/dist/{existing-C6TTT6c4.js → existing-Cl5x6_5u.js} +2 -2
- package/dist/{selection-CWfI4a0O.js → framework-CLmf4swr.js} +50 -50
- package/dist/{held-C2IjAyg6.js → held-Bykbwy-m.js} +6 -6
- package/dist/held-Chw3BtBV.js +17 -0
- package/dist/{install-DoSYCwLL.js → install-dXZZ79Oe.js} +37 -37
- package/dist/{integrate-BSqd2wgI.js → integrate-DiSjlOjC.js} +23 -23
- package/dist/{types-CB6O_wjy.js → lock-DgSx-p8Y.js} +79 -79
- package/dist/{login-C6FcBQZg.js → login-5sWIKDI2.js} +6 -6
- package/dist/login-DZ8Pipf6.js +17 -0
- package/dist/{login-dRPPnGr7.js → login-Jp6E6d2e.js} +1 -1
- package/dist/{lookup-D23dAOz6.js → lookup-CWzVfPpq.js} +3 -3
- package/dist/{migrate-CDdUCTH3.js → migrate-BKiOUsMY.js} +29 -29
- package/dist/{migration-r9plM7F6.js → migration-Z69tLeHC.js} +9 -9
- package/dist/{notification-url-rdnENCxt.js → notification-url-BDBxbwZq.js} +2 -2
- package/dist/{open-DVdE3HnK.js → open-DNd49kT-.js} +2 -2
- package/dist/{org-DZ41muzA.js → org-Dud1rF9f.js} +3 -3
- package/dist/{organization-DIODPOwO.js → organization-7vJA3uy1.js} +8 -8
- package/dist/{orgs-BxlwcvTu.js → orgs-Z0H9WOs1.js} +1 -1
- package/dist/{paths-BaeoxDze.js → paths-CzTJVpfi.js} +1 -1
- package/dist/{playbook-B-Pdonhg.js → playbook-DJ__edOW.js} +10 -10
- package/dist/{project-DHU5wc3R.js → project-NoMtbMyl.js} +9 -9
- package/dist/{promote-Ca4URuHY.js → promote-DLtPSvmL.js} +23 -23
- package/dist/{pull-CQcTZxW8.js → pull-AoUmaiMK.js} +8 -8
- package/dist/pull-C1xm2zqG.js +36 -0
- package/dist/pull-D-YuT3e0.js +106 -0
- package/dist/push-B42D8fKf.js +22 -0
- package/dist/{push-BlZoIwIj.js → push-BMblzg_6.js} +9 -9
- package/dist/{push-DQE48h_M.js → push-BrzMFd4Z.js} +46 -46
- package/dist/push-Co5jk6Kr.js +30 -0
- package/dist/{registry-FNG-uiIt.js → registry-DDU10_Ix.js} +152 -152
- package/dist/resolve-DpOSDDdr.js +196 -0
- package/dist/{resources-COOEvqqW.js → resources-CptT7HD6.js} +2 -2
- package/dist/{run-DpYDOAw-.js → run-c1O2_8pp.js} +2 -2
- package/dist/{run-Czbb-sHR.js → run-r3foWfhV.js} +65 -65
- package/dist/scan-D86kLtM7.js +4 -0
- package/dist/{scan-BZS2FZeU.js → scan-nVQO7JLx.js} +1 -1
- package/dist/{scope-t_SqFN6W.js → scope-ehZ7L1nj.js} +8 -8
- package/dist/{scope-BJQ-KcQg.js → scope-l1qGLsgz.js} +5 -5
- package/dist/{sdk-CyttTnGf.js → sdk-DEfQttek.js} +7 -7
- package/dist/{series--Wp7TngJ.js → series-D2ZpZ8cx.js} +95 -62
- package/dist/server-BEcsQaPu.js +29 -0
- package/dist/{server-BmmOj7bh.js → server-DLARhh1k.js} +9 -9
- package/dist/session-Csuaw6RU.js +6 -0
- package/dist/{session-BpYpOgaY.js → session-Z0BeaJPf.js} +1 -1
- package/dist/{setup-DW50luOZ.js → setup-C6NFy14d.js} +9 -9
- package/dist/skills/index.json +2 -2
- package/dist/skills/{superwall-workspaces → superwall-artifacts}/SKILL.md +38 -29
- package/dist/skills/{superwall-workspaces → superwall-artifacts}/references/cli.md +31 -28
- package/dist/skills/{superwall-workspaces → superwall-artifacts}/references/slots.md +9 -9
- package/dist/{skills-Cm1j2d1W.js → skills-421SFEyF.js} +4 -4
- package/dist/{skills-Bbtq8V_D.js → skills-CdKwaTRS.js} +8 -8
- package/dist/{git-DqDPnldI.js → source-BccdO4aL.js} +95 -95
- package/dist/{source-push-B3c-VLfe.js → source-push-B4s6r9bB.js} +6 -6
- package/dist/{spinner-025_eqCX.js → spinner-DPdBlZe2.js} +3 -3
- package/dist/{starter-hcwocv_Z.js → starter-0OdVPH4l.js} +27 -27
- package/dist/{status-K1IGp6pe.js → status-Dsc7d3z2.js} +39 -39
- package/dist/{storage-CUMgpcVH.js → storage-DT_wxwJ8.js} +1 -1
- package/dist/{storekit-Cb0TkToV.js → storekit-B9M2raxe.js} +3 -3
- package/dist/storekit-BWZf-fNE.js +17 -0
- package/dist/{telemetry-ekUQuhLJ.js → telemetry-ovPiseFm.js} +1 -1
- package/dist/{token-B2PduqrR.js → token-Bu3FaRkv.js} +1 -1
- package/dist/tools.js +123 -123
- package/dist/{try-BUnhITXS.js → try-B8FYkTvQ.js} +29 -29
- package/dist/{upgrade-CI7K1UZ-.js → upgrade-B7TmvEPP.js} +2 -2
- package/dist/{upgrade-DfZfDljd.js → upgrade-CAHyrWUL.js} +2 -2
- package/package.json +2 -2
- package/dist/create-DAkNdEzt.js +0 -20
- package/dist/held-KVcYIplR.js +0 -17
- package/dist/login-BiwaQkXS.js +0 -17
- package/dist/pull-DRMIxqR8.js +0 -36
- package/dist/pull-_qs90vGA.js +0 -106
- package/dist/push-Cb4g_l1K.js +0 -30
- package/dist/push-DZKsd6Dp.js +0 -22
- package/dist/resolve-DGePiHgL.js +0 -196
- package/dist/scan-2WqHGkjU.js +0 -4
- package/dist/server-BqLPwcy9.js +0 -29
- package/dist/session-BHBIGscL.js +0 -6
- package/dist/storekit-Dewj_5qg.js +0 -17
- /package/dist/{design-lint-CvgcSzVg.js → design-lint-CiFc78aM.js} +0 -0
- /package/dist/{download-F8OtTJze.js → download-DhGd4hOB.js} +0 -0
- /package/dist/{reports-BZfxvenS.js → reports-HYVp169R.js} +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { u as DASHBOARD_ORIGIN_OVERRIDE } from "./environment-BocmdvZ-.js";
|
|
2
|
+
import { a as orgProjects, n as listOrganizations } from "./orgs-Z0H9WOs1.js";
|
|
3
|
+
import { t as ArtifactError } from "./project-NoMtbMyl.js";
|
|
4
|
+
import { n as ARTIFACT_FILE } from "./scope-ehZ7L1nj.js";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/core/artifacts/api.ts
|
|
9
|
+
const artifactPath = (id) => `/v2/artifacts/${encodeURIComponent(String(id))}`;
|
|
10
|
+
const versionPath = (id, version) => `${artifactPath(id)}/versions/${encodeURIComponent(String(version))}`;
|
|
11
|
+
const getMe = (api) => api.get("/v2/me");
|
|
12
|
+
const listMembers = async (api, organizationId) => (await api.get(`/v2/organizations/${encodeURIComponent(String(organizationId))}/access/members`)).data ?? [];
|
|
13
|
+
const getArtifact = (api, id) => api.get(artifactPath(id));
|
|
14
|
+
const listArtifacts = async (api, organizationId, slug) => {
|
|
15
|
+
const search = new URLSearchParams({
|
|
16
|
+
organization_id: organizationId,
|
|
17
|
+
...slug ? { slug } : {}
|
|
18
|
+
});
|
|
19
|
+
return (await api.get(`/v2/artifacts?${search}`)).data;
|
|
20
|
+
};
|
|
21
|
+
const createArtifact = (api, organizationId, name, slug) => api.post("/v2/artifacts", {
|
|
22
|
+
organization_id: Number(organizationId),
|
|
23
|
+
name,
|
|
24
|
+
slug
|
|
25
|
+
});
|
|
26
|
+
const listVersions = async (api, id) => (await api.get(`${artifactPath(id)}/versions`)).data;
|
|
27
|
+
const mintSourceAccess = (api, id) => api.post(`${artifactPath(id)}/source-access`, {});
|
|
28
|
+
const startBuild = (api, id, commitSha, tokenId) => api.post(`${artifactPath(id)}/builds`, {
|
|
29
|
+
commit_sha: commitSha,
|
|
30
|
+
token_id: tokenId
|
|
31
|
+
});
|
|
32
|
+
const getBuild = (api, id, version) => api.get(`${versionPath(id, version)}/build`);
|
|
33
|
+
const requestDeploy = (api, id, version) => api.post(`${versionPath(id, version)}/request-deploy`, {});
|
|
34
|
+
const approveVersion = (api, id, version) => api.post(`${versionPath(id, version)}/approve`, {});
|
|
35
|
+
const listInstallations = async (api, id) => (await api.get(`${artifactPath(id)}/installations`)).data;
|
|
36
|
+
const setInstallation = (api, id, body) => api.put(`${artifactPath(id)}/installations`, body);
|
|
37
|
+
const deleteInstallation = (api, id, entrypoint, application) => {
|
|
38
|
+
const search = new URLSearchParams({
|
|
39
|
+
entrypoint_id: entrypoint,
|
|
40
|
+
...application ? { application_id: application } : {}
|
|
41
|
+
});
|
|
42
|
+
return api.del(`${artifactPath(id)}/installations?${search}`);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/core/artifacts/binding.ts
|
|
47
|
+
function readBinding(root) {
|
|
48
|
+
const file = path.join(root, ARTIFACT_FILE);
|
|
49
|
+
let text;
|
|
50
|
+
try {
|
|
51
|
+
text = fs.readFileSync(file, "utf8");
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(text);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new ArtifactError(`${ARTIFACT_FILE} is not valid JSON: ${error.message}`);
|
|
60
|
+
}
|
|
61
|
+
const { artifact_id: artifactId, organization_id: organizationId, slug, synced_commit: syncedCommit, reviewed_commit: reviewedCommit } = parsed;
|
|
62
|
+
if (typeof artifactId !== "number" || typeof organizationId !== "number" || typeof slug !== "string") throw new ArtifactError(`${ARTIFACT_FILE} needs artifact_id, organization_id and slug.`);
|
|
63
|
+
return {
|
|
64
|
+
artifactId: String(artifactId),
|
|
65
|
+
organizationId: String(organizationId),
|
|
66
|
+
slug,
|
|
67
|
+
...typeof syncedCommit === "string" ? { syncedCommit } : {},
|
|
68
|
+
...typeof reviewedCommit === "string" ? { reviewedCommit } : {}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const formatBinding = (binding, includeSync) => `${JSON.stringify({
|
|
72
|
+
artifact_id: Number(binding.artifactId),
|
|
73
|
+
organization_id: Number(binding.organizationId),
|
|
74
|
+
slug: binding.slug,
|
|
75
|
+
...includeSync && binding.syncedCommit ? { synced_commit: binding.syncedCommit } : {},
|
|
76
|
+
...includeSync && binding.reviewedCommit ? { reviewed_commit: binding.reviewedCommit } : {}
|
|
77
|
+
}, null, 2)}\n`;
|
|
78
|
+
function writeBinding(root, binding) {
|
|
79
|
+
fs.writeFileSync(path.join(root, ARTIFACT_FILE), formatBinding(binding, true));
|
|
80
|
+
}
|
|
81
|
+
function readSourceFile(root, relative$1) {
|
|
82
|
+
const file = path.join(root, relative$1);
|
|
83
|
+
if (relative$1 !== ARTIFACT_FILE) return fs.readFileSync(file);
|
|
84
|
+
const binding = readBinding(root);
|
|
85
|
+
return binding ? Buffer.from(formatBinding(binding, false)) : fs.readFileSync(file);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/core/artifacts/resolve.ts
|
|
90
|
+
const projectRoot = (dir) => path.resolve(dir ?? process.cwd());
|
|
91
|
+
async function resolveArtifact(ctx, ref) {
|
|
92
|
+
if (ref.artifact !== void 0) {
|
|
93
|
+
if (/^\d+$/.test(ref.artifact)) return getArtifact(ctx.api, ref.artifact);
|
|
94
|
+
if (ref.org === void 0) throw new ArtifactError(`A slug needs its organization: add --org <id>, or pass the artifact's id.`);
|
|
95
|
+
const [found] = await listArtifacts(ctx.api, ref.org, ref.artifact);
|
|
96
|
+
if (!found) throw new ArtifactError(`No artifact \`${ref.artifact}\` in organization ${ref.org}.`);
|
|
97
|
+
return found;
|
|
98
|
+
}
|
|
99
|
+
const binding = readBinding(projectRoot(ref.dir));
|
|
100
|
+
if (!binding) throw new ArtifactError("This project isn't linked to an artifact yet. Run `superwall artifacts push`, or say which with --artifact <id>.");
|
|
101
|
+
return getArtifact(ctx.api, binding.artifactId);
|
|
102
|
+
}
|
|
103
|
+
function dashboardOrigin(apiHost) {
|
|
104
|
+
return DASHBOARD_ORIGIN_OVERRIDE() ?? (new URL(apiHost).hostname.endsWith(".dev") ? "https://app.superwall.dev" : "https://app.superwall.com");
|
|
105
|
+
}
|
|
106
|
+
const artifactUrl = (apiHost, artifact) => `${dashboardOrigin(apiHost)}/${artifact.organization_id}/artifacts/${encodeURIComponent(artifact.slug)}`;
|
|
107
|
+
const EMBED_SLOTS = new Set([
|
|
108
|
+
"app.dashboard.widget@1",
|
|
109
|
+
"campaign.tab@1",
|
|
110
|
+
"campaign.metric@1",
|
|
111
|
+
"user.panel@1",
|
|
112
|
+
"user.action@1"
|
|
113
|
+
]);
|
|
114
|
+
const appEntrypointUrl = (apiHost, artifact, applicationId, entrypoint) => {
|
|
115
|
+
const app = `${dashboardOrigin(apiHost)}/${artifact.organization_id}/${applicationId}`;
|
|
116
|
+
if (entrypoint.slot === "chart.source@1") return `${app}/charts?cS=artifacts`;
|
|
117
|
+
if (EMBED_SLOTS.has(entrypoint.slot)) return `${app}/embeds`;
|
|
118
|
+
return `${app}/apps/${artifact.id}/${encodeURIComponent(entrypoint.id)}`;
|
|
119
|
+
};
|
|
120
|
+
const mainEntrypoint = (entrypoints) => entrypoints.find((entrypoint) => entrypoint.slot === "app.page@1") ?? entrypoints.find((entrypoint) => EMBED_SLOTS.has(entrypoint.slot)) ?? entrypoints.find((entrypoint) => entrypoint.slot === "chart.source@1");
|
|
121
|
+
async function openLink(ctx, artifact, manifest) {
|
|
122
|
+
const fallback = { url: artifactUrl(ctx.api.host, artifact) };
|
|
123
|
+
const entrypoints = manifest?.entrypoints ?? [];
|
|
124
|
+
const main = mainEntrypoint(entrypoints);
|
|
125
|
+
if (!main || entrypoints.some((entrypoint) => entrypoint.slot === "org.page@1")) return fallback;
|
|
126
|
+
const apps = (await orgProjects(ctx.api, String(artifact.organization_id)).catch(() => [])).flatMap((project) => project.applications ?? []);
|
|
127
|
+
const [first] = apps;
|
|
128
|
+
if (first === void 0) return fallback;
|
|
129
|
+
return {
|
|
130
|
+
url: appEntrypointUrl(ctx.api.host, artifact, String(first.id), main),
|
|
131
|
+
app: String(first.name ?? first.id),
|
|
132
|
+
otherApps: apps.length > 1
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async function awaitingInstall(api, artifactId, manifest) {
|
|
136
|
+
const entrypoints = manifest?.entrypoints ?? [];
|
|
137
|
+
if (entrypoints.length === 0 || entrypoints.some((entrypoint) => entrypoint.slot === "org.page@1")) return false;
|
|
138
|
+
const installed = await listInstallations(api, artifactId).catch(() => void 0);
|
|
139
|
+
if (installed === void 0) return false;
|
|
140
|
+
return entrypoints.every((entrypoint) => !installed.some((row) => row.entrypoint_id === entrypoint.id));
|
|
141
|
+
}
|
|
142
|
+
const latestManifest = (versions) => newestFirst(versions).find((version) => version.manifest !== null)?.manifest;
|
|
143
|
+
async function visibilityOf(ctx, artifactId, version, manifest) {
|
|
144
|
+
const [artifact, me] = await Promise.all([getArtifact(ctx.api, artifactId).catch(() => void 0), getMe(ctx.api).catch(() => void 0)]);
|
|
145
|
+
if (artifact?.state === "turned_off") return {
|
|
146
|
+
visibleTo: "nobody",
|
|
147
|
+
sentence: `This artifact is turned off, so nobody can see version ${version}.`
|
|
148
|
+
};
|
|
149
|
+
if (artifact?.active_version_id === version) {
|
|
150
|
+
if (await awaitingInstall(ctx.api, artifactId, manifest)) return {
|
|
151
|
+
visibleTo: "its_author",
|
|
152
|
+
sentence: `Version ${version} is approved, but nothing is installed yet, so only its author can see it, marked "Not installed". An admin chooses where it shows with \`superwall artifacts install\`.`
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
visibleTo: "everyone",
|
|
156
|
+
sentence: `Version ${version} is live.`
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (artifact?.author_version_id === version) return {
|
|
160
|
+
visibleTo: "you",
|
|
161
|
+
sentence: `Only you can see version ${version} until an admin approves it.`
|
|
162
|
+
};
|
|
163
|
+
if (me?.role === "SUPERADMIN") return {
|
|
164
|
+
visibleTo: "nobody",
|
|
165
|
+
sentence: `Nobody can see version ${version} until an admin approves it, because a staff account doesn't get a copy of its own.`
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
visibleTo: "its_author",
|
|
169
|
+
sentence: `Only its author can see version ${version} until an admin approves it.`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function roleCanApprove(ctx, artifact) {
|
|
173
|
+
const role = (await listOrganizations(ctx.api).catch(() => [])).find((organization) => String(organization.id) === String(artifact.organization_id))?.role;
|
|
174
|
+
return typeof role !== "string" || role === "OWNER" || role === "ADMIN";
|
|
175
|
+
}
|
|
176
|
+
const newestFirst = (versions) => [...versions].sort((a, b) => b.id - a.id);
|
|
177
|
+
async function pickVersion(ctx, artifact, requested, matches = () => true) {
|
|
178
|
+
const versions = newestFirst(await listVersions(ctx.api, artifact.id));
|
|
179
|
+
if (requested !== void 0) {
|
|
180
|
+
const version$1 = versions.find((candidate) => String(candidate.id) === requested);
|
|
181
|
+
if (!version$1) throw new ArtifactError(`No version ${requested} of \`${artifact.slug}\`.`);
|
|
182
|
+
return {
|
|
183
|
+
version: version$1,
|
|
184
|
+
versions
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const version = versions.find(matches);
|
|
188
|
+
if (!version) throw new ArtifactError(`\`${artifact.slug}\` has no version for this yet. Run \`superwall artifacts push\`.`);
|
|
189
|
+
return {
|
|
190
|
+
version,
|
|
191
|
+
versions
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
export { listVersions as C, startBuild as D, setInstallation as E, listMembers as S, requestDeploy as T, deleteInstallation as _, newestFirst as a, listArtifacts as b, projectRoot as c, visibilityOf as d, readBinding as f, createArtifact as g, approveVersion as h, latestManifest as i, resolveArtifact as l, writeBinding as m, awaitingInstall as n, openLink as o, readSourceFile as p, dashboardOrigin as r, pickVersion as s, appEntrypointUrl as t, roleCanApprove as u, getBuild as v, mintSourceAccess as w, listInstallations as x, getMe as y };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as ApiUnreachableError, t as ApiError } from "./client-
|
|
2
|
-
import { r as listReachableProjects } from "./orgs-
|
|
1
|
+
import { n as ApiUnreachableError, t as ApiError } from "./client-CyrYJzBF.js";
|
|
2
|
+
import { r as listReachableProjects } from "./orgs-Z0H9WOs1.js";
|
|
3
3
|
|
|
4
4
|
//#region src/core/json.ts
|
|
5
5
|
function isRecord(value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as DASHBOARD_URL } from "./environment-
|
|
2
|
-
import { i as packagedDir } from "./paths-
|
|
1
|
+
import { d as DASHBOARD_URL } from "./environment-BocmdvZ-.js";
|
|
2
|
+
import { i as packagedDir } from "./paths-CzTJVpfi.js";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import "./token-
|
|
1
|
+
import "./token-Bu3FaRkv.js";
|
|
2
2
|
import "./output-Ggzq5_-t.js";
|
|
3
|
-
import "./environment-
|
|
4
|
-
import "./storage-
|
|
5
|
-
import { t as ApiError } from "./client-
|
|
3
|
+
import "./environment-BocmdvZ-.js";
|
|
4
|
+
import "./storage-DT_wxwJ8.js";
|
|
5
|
+
import { t as ApiError } from "./client-CyrYJzBF.js";
|
|
6
6
|
import "./config-CGcG7GOt.js";
|
|
7
|
-
import "./spinner-
|
|
7
|
+
import "./spinner-DPdBlZe2.js";
|
|
8
8
|
import "./ui-D_qf3Gvw.js";
|
|
9
|
-
import "./orgs-
|
|
10
|
-
import "./resources-
|
|
11
|
-
import "./lookup-
|
|
12
|
-
import "./
|
|
13
|
-
import
|
|
14
|
-
import "./
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import { i as warnIfSdkBehind } from "./sdk-
|
|
9
|
+
import "./orgs-Z0H9WOs1.js";
|
|
10
|
+
import "./resources-CptT7HD6.js";
|
|
11
|
+
import "./lookup-CWzVfPpq.js";
|
|
12
|
+
import { a as findEntrypoint, o as readManifest, s as readProject, t as ArtifactError } from "./project-NoMtbMyl.js";
|
|
13
|
+
import "./lock-DgSx-p8Y.js";
|
|
14
|
+
import { n as ARTIFACT_FILE } from "./scope-ehZ7L1nj.js";
|
|
15
|
+
import { C as TRIGGER_HEADER, S as READOUT_LIMITS, b as MOUNT_LOAD_TIMEOUT_MS, c as defaultRange, d as resolveWranglerPackage, f as API_HOST, g as CONTEXT_HEADER, h as BRIDGE_PROTOCOL, i as seriesProblem, l as parseContextJson, m as ARTIFACT_HEADER_PREFIX, o as SLOTS, p as ARTIFACT_COMPATIBILITY_DATE, r as readoutProblem, s as buildContext, t as checkMetricQuery, u as bundleArtifact, v as ENTRYPOINT_HEADER, w as isInternalPath, x as PLATFORM_HOST, y as METRIC_LIMITS } from "./series-D2ZpZ8cx.js";
|
|
16
|
+
import { n as resolveOrganization, t as resolveAppScope } from "./organization-7vJA3uy1.js";
|
|
17
|
+
import "./download-DhGd4hOB.js";
|
|
18
|
+
import { i as warnIfSdkBehind } from "./sdk-DEfQttek.js";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
20
|
import * as fs from "node:fs";
|
|
21
21
|
import * as path from "node:path";
|
|
@@ -23,7 +23,7 @@ import { pathToFileURL } from "node:url";
|
|
|
23
23
|
import { randomBytes } from "node:crypto";
|
|
24
24
|
import * as http from "node:http";
|
|
25
25
|
|
|
26
|
-
//#region src/core/
|
|
26
|
+
//#region src/core/artifacts/dev/credential.ts
|
|
27
27
|
const MAX_TOKEN_RENEWALS = 3;
|
|
28
28
|
function createAgentCredential(mint) {
|
|
29
29
|
let latest;
|
|
@@ -45,7 +45,7 @@ function createAgentCredential(mint) {
|
|
|
45
45
|
renew(rejected, { expired = false } = {}) {
|
|
46
46
|
if (renewing) return renewing;
|
|
47
47
|
if (latest !== void 0 && latest !== rejected) return Promise.resolve(latest);
|
|
48
|
-
if (!expired && renewals >= MAX_TOKEN_RENEWALS) return Promise.reject(new
|
|
48
|
+
if (!expired && renewals >= MAX_TOKEN_RENEWALS) return Promise.reject(new ArtifactError(`The API kept refusing dev's token after ${MAX_TOKEN_RENEWALS} new ones, so it stopped making more. Check \`superwall whoami\`, then restart dev.`));
|
|
49
49
|
if (!expired) renewals += 1;
|
|
50
50
|
renewing = start().finally(() => {
|
|
51
51
|
renewing = void 0;
|
|
@@ -56,8 +56,8 @@ function createAgentCredential(mint) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
59
|
-
//#region src/core/
|
|
60
|
-
const
|
|
59
|
+
//#region src/core/artifacts/routes.ts
|
|
60
|
+
const ARTIFACT_ROUTE_REFUSAL = "Artifacts may not call this endpoint.";
|
|
61
61
|
const READ = new Set(["GET", "HEAD"]);
|
|
62
62
|
const WRITE = new Set([
|
|
63
63
|
"POST",
|
|
@@ -244,13 +244,13 @@ const pathSpellings = (target) => {
|
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
246
|
const isAllowedPath = (method, path$1, narrowed) => !DENIED.some((pattern) => pattern.test(path$1)) && ALLOWED.some((rule) => rule.methods.has(method) && rule.path.test(path$1)) && (!narrowed || NARROWED.some((rule) => rule.methods.has(method) && rule.path.test(path$1)));
|
|
247
|
-
const
|
|
247
|
+
const isArtifactRequestAllowed = (method, target, narrowed) => {
|
|
248
248
|
const normalized = method.toUpperCase();
|
|
249
249
|
return pathSpellings(target).every((path$1) => isAllowedPath(normalized, path$1, narrowed));
|
|
250
250
|
};
|
|
251
251
|
|
|
252
252
|
//#endregion
|
|
253
|
-
//#region src/core/
|
|
253
|
+
//#region src/core/artifacts/scopes.ts
|
|
254
254
|
const READ_FAMILIES = [
|
|
255
255
|
[/^\/v2\/organizations\/[^/]+\/query$/, "data:read"],
|
|
256
256
|
[/^\/v2\/projects\/[^/]+\/custom-stores(\/|$)/, "custom_stores:read"],
|
|
@@ -274,7 +274,7 @@ function scopeForRoute(method, pathname) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
//#endregion
|
|
277
|
-
//#region src/core/
|
|
277
|
+
//#region src/core/artifacts/dev/outbound.ts
|
|
278
278
|
const FORWARDED_HEADERS = [
|
|
279
279
|
"accept",
|
|
280
280
|
"accept-encoding",
|
|
@@ -302,7 +302,7 @@ const refuse = (status, message) => new Response(JSON.stringify({ message }), {
|
|
|
302
302
|
const refuseRoute = () => new Response(JSON.stringify({
|
|
303
303
|
type: "permission_error",
|
|
304
304
|
code: "insufficient_permissions",
|
|
305
|
-
message:
|
|
305
|
+
message: ARTIFACT_ROUTE_REFUSAL
|
|
306
306
|
}), {
|
|
307
307
|
status: 403,
|
|
308
308
|
headers: { "content-type": "application/json" }
|
|
@@ -349,16 +349,16 @@ function createOutbound({ apiOrigin, credential, log, declaredScopes, limitedTo,
|
|
|
349
349
|
return async (request, caller) => {
|
|
350
350
|
const url = new URL(request.url);
|
|
351
351
|
if (url.hostname === PLATFORM_HOST) {
|
|
352
|
-
log.warn("
|
|
353
|
-
return refuse(501, "
|
|
352
|
+
log.warn("Artifact storage, jobs and logs aren't available in dev.");
|
|
353
|
+
return refuse(501, "Artifact storage, jobs and logs aren't available in dev.");
|
|
354
354
|
}
|
|
355
355
|
if (url.hostname !== API_HOST) {
|
|
356
356
|
log.warn(`Refused ${request.method} ${url.origin}: dev runs like a draft, with no outside hosts.`);
|
|
357
357
|
return refuse(403, `Dev runs like a draft, with no outside hosts: ${url.hostname} isn't reachable.`);
|
|
358
358
|
}
|
|
359
359
|
const label = `${request.method} ${url.pathname}`;
|
|
360
|
-
if (!
|
|
361
|
-
log.warn(`${label} 403. ${
|
|
360
|
+
if (!isArtifactRequestAllowed(request.method, `${url.pathname}${url.search}`, caller.narrowed)) {
|
|
361
|
+
log.warn(`${label} 403. ${ARTIFACT_ROUTE_REFUSAL} ${routeHint(url.pathname, caller.narrowed)}`);
|
|
362
362
|
return refuseRoute();
|
|
363
363
|
}
|
|
364
364
|
const scope = scopeForRoute(request.method, url.pathname);
|
|
@@ -382,7 +382,7 @@ function createOutbound({ apiOrigin, credential, log, declaredScopes, limitedTo,
|
|
|
382
382
|
if (answer.status === 403) {
|
|
383
383
|
const { message } = await refusalOf(answer);
|
|
384
384
|
const organization = limitedTo?.();
|
|
385
|
-
const reach = organization === void 0 ? "Dev is read-only." : `Dev's token is read-only, limited to organization ${organization} and the routes
|
|
385
|
+
const reach = organization === void 0 ? "Dev is read-only." : `Dev's token is read-only, limited to organization ${organization} and the routes an artifact can read.`;
|
|
386
386
|
log.warn(`${label} ${answer.status} ${took}ms. ${reach} ${String(message ?? "").slice(0, 200)}`.trimEnd());
|
|
387
387
|
} else log.info(`${label} ${answer.status} ${took}ms`);
|
|
388
388
|
const headers = new Headers(answer.headers);
|
|
@@ -392,28 +392,28 @@ function createOutbound({ apiOrigin, credential, log, declaredScopes, limitedTo,
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
//#endregion
|
|
395
|
-
//#region src/core/
|
|
395
|
+
//#region src/core/artifacts/dev/runtime.ts
|
|
396
396
|
const INVOKE_PATH = "/__sw/invoke/";
|
|
397
|
-
const NARROWED_HEADER = "x-superwall-
|
|
397
|
+
const NARROWED_HEADER = "x-superwall-artifact-dev-narrowed";
|
|
398
398
|
const INVOCABLE = ["metric", "readout"];
|
|
399
399
|
const SANDBOX_MODULE = "delete globalThis.caches\n";
|
|
400
400
|
const MAIN_MODULE = `import "./sandbox.mjs"
|
|
401
401
|
import { WorkerEntrypoint } from "cloudflare:workers"
|
|
402
402
|
import handlers from "./worker.mjs"
|
|
403
403
|
export * from "./worker.mjs"
|
|
404
|
-
export default class
|
|
404
|
+
export default class Artifact extends WorkerEntrypoint {
|
|
405
405
|
fetch(request) {
|
|
406
406
|
return handlers.fetch(request)
|
|
407
407
|
}
|
|
408
408
|
metric(request) {
|
|
409
409
|
if (typeof handlers.metric !== "function") {
|
|
410
|
-
throw new Error("This
|
|
410
|
+
throw new Error("This artifact has no metric handler")
|
|
411
411
|
}
|
|
412
412
|
return handlers.metric(request)
|
|
413
413
|
}
|
|
414
414
|
readout(request) {
|
|
415
415
|
if (typeof handlers.readout !== "function") {
|
|
416
|
-
throw new Error("This
|
|
416
|
+
throw new Error("This artifact has no readout handler")
|
|
417
417
|
}
|
|
418
418
|
return handlers.readout(request)
|
|
419
419
|
}
|
|
@@ -444,12 +444,12 @@ export default {
|
|
|
444
444
|
async fetch(request, env, ctx) {
|
|
445
445
|
const narrowed = request.headers.get(${JSON.stringify(NARROWED_HEADER)}) === "1"
|
|
446
446
|
const { pathname } = new URL(request.url)
|
|
447
|
-
const
|
|
447
|
+
const artifact = load(env, ctx.exports, narrowed).getEntrypoint()
|
|
448
448
|
if (pathname.startsWith(${JSON.stringify(INVOKE_PATH)})) {
|
|
449
449
|
const kind = pathname.slice(13)
|
|
450
450
|
if (!${JSON.stringify(INVOCABLE)}.includes(kind)) return json({ error: "Not found." }, 404)
|
|
451
451
|
try {
|
|
452
|
-
return json({ result: await
|
|
452
|
+
return json({ result: await artifact[kind](await request.json()) }, 200)
|
|
453
453
|
} catch (error) {
|
|
454
454
|
return json({ error: String(error?.message ?? error) }, 500)
|
|
455
455
|
}
|
|
@@ -457,7 +457,7 @@ export default {
|
|
|
457
457
|
const headers = new Headers(request.headers)
|
|
458
458
|
headers.delete(${JSON.stringify(NARROWED_HEADER)})
|
|
459
459
|
try {
|
|
460
|
-
return await
|
|
460
|
+
return await artifact.fetch(new Request(request, { headers }))
|
|
461
461
|
} catch (error) {
|
|
462
462
|
return new Response(String(error?.message ?? error), { status: 502 })
|
|
463
463
|
}
|
|
@@ -465,12 +465,12 @@ export default {
|
|
|
465
465
|
}
|
|
466
466
|
`;
|
|
467
467
|
const DEFAULT_COMPATIBILITY = {
|
|
468
|
-
date:
|
|
468
|
+
date: ARTIFACT_COMPATIBILITY_DATE,
|
|
469
469
|
flags: []
|
|
470
470
|
};
|
|
471
471
|
const workerOptions = (module, compatibility = DEFAULT_COMPATIBILITY) => ({
|
|
472
|
-
name: "
|
|
473
|
-
compatibilityDate:
|
|
472
|
+
name: "artifact-host",
|
|
473
|
+
compatibilityDate: ARTIFACT_COMPATIBILITY_DATE,
|
|
474
474
|
modules: [{
|
|
475
475
|
type: "ESModule",
|
|
476
476
|
path: "host.mjs",
|
|
@@ -498,7 +498,7 @@ const startMiniflare = async ({ root, module, compatibility, outbound }) => {
|
|
|
498
498
|
await miniflare.ready;
|
|
499
499
|
} catch (error) {
|
|
500
500
|
await miniflare.dispose().catch(() => {});
|
|
501
|
-
throw new
|
|
501
|
+
throw new ArtifactError(`The artifact didn't start: ${error.message}\nIf the runtime says the compatibility date is too new, update wrangler with \`npm install -D wrangler@latest\`.`);
|
|
502
502
|
}
|
|
503
503
|
return {
|
|
504
504
|
fetch: (url, init, caller) => {
|
|
@@ -516,7 +516,7 @@ const startMiniflare = async ({ root, module, compatibility, outbound }) => {
|
|
|
516
516
|
};
|
|
517
517
|
|
|
518
518
|
//#endregion
|
|
519
|
-
//#region src/core/
|
|
519
|
+
//#region src/core/artifacts/dev/host-page.ts
|
|
520
520
|
const LIGHT_TOKENS = {
|
|
521
521
|
background: "#ffffff",
|
|
522
522
|
foreground: "#14151a",
|
|
@@ -886,12 +886,12 @@ function renderHostPage() {
|
|
|
886
886
|
<html lang="en">
|
|
887
887
|
<head>
|
|
888
888
|
<meta charset="utf-8" />
|
|
889
|
-
<title>
|
|
889
|
+
<title>Artifact dev</title>
|
|
890
890
|
<style>${STYLES}</style>
|
|
891
891
|
</head>
|
|
892
892
|
<body>
|
|
893
893
|
<aside>
|
|
894
|
-
<div class="row"><h1 id="title">
|
|
894
|
+
<div class="row"><h1 id="title">Artifact</h1><button id="theme">Theme</button></div>
|
|
895
895
|
<div id="entrypoints"></div>
|
|
896
896
|
<div id="context"></div>
|
|
897
897
|
</aside>
|
|
@@ -905,7 +905,7 @@ function renderHostPage() {
|
|
|
905
905
|
}
|
|
906
906
|
|
|
907
907
|
//#endregion
|
|
908
|
-
//#region src/core/
|
|
908
|
+
//#region src/core/artifacts/dev/server.ts
|
|
909
909
|
const readBody = (request) => new Promise((resolve$1, reject) => {
|
|
910
910
|
const chunks = [];
|
|
911
911
|
request.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -921,7 +921,7 @@ const sendJson = (response, status, body) => {
|
|
|
921
921
|
};
|
|
922
922
|
const listen = (server, port) => new Promise((resolve$1, reject) => {
|
|
923
923
|
server.once("error", (error) => {
|
|
924
|
-
reject(error.code === "EADDRINUSE" ? new
|
|
924
|
+
reject(error.code === "EADDRINUSE" ? new ArtifactError(`Port ${port} is already in use. Pick another with --port; dev also takes the one after it.`) : error);
|
|
925
925
|
});
|
|
926
926
|
server.listen(port, "127.0.0.1", () => {
|
|
927
927
|
const address = server.address();
|
|
@@ -951,7 +951,7 @@ const headerJson = (value) => JSON.stringify(value).replace(/[\u007f-
|
|
|
951
951
|
const withTimeout = async (work, ms, message) => {
|
|
952
952
|
let timer;
|
|
953
953
|
const timeout = new Promise((_, reject) => {
|
|
954
|
-
timer = setTimeout(() => reject(new
|
|
954
|
+
timer = setTimeout(() => reject(new ArtifactError(message)), ms);
|
|
955
955
|
});
|
|
956
956
|
try {
|
|
957
957
|
return await Promise.race([work, timeout]);
|
|
@@ -993,7 +993,7 @@ async function startDevServer(options) {
|
|
|
993
993
|
headers: { "content-type": "application/json" },
|
|
994
994
|
body: JSON.stringify(payload)
|
|
995
995
|
}), timeoutMs, `The ${kind} handler didn't answer within ${timeoutMs / 1e3} seconds.`)).json();
|
|
996
|
-
if (body.error !== void 0) throw new
|
|
996
|
+
if (body.error !== void 0) throw new ArtifactError(body.error);
|
|
997
997
|
return body.result;
|
|
998
998
|
};
|
|
999
999
|
const contextFor = (slot, input) => {
|
|
@@ -1002,12 +1002,12 @@ async function startDevServer(options) {
|
|
|
1002
1002
|
...input
|
|
1003
1003
|
});
|
|
1004
1004
|
const { organizationId } = context;
|
|
1005
|
-
if (defaults.organizationId !== void 0 && organizationId !== void 0 && String(organizationId) !== defaults.organizationId) throw new
|
|
1005
|
+
if (defaults.organizationId !== void 0 && organizationId !== void 0 && String(organizationId) !== defaults.organizationId) throw new ArtifactError(`This dev is running against organization ${defaults.organizationId}, and its token reaches only that one. Restart dev with --org ${String(organizationId)} to use ${String(organizationId)}.`);
|
|
1006
1006
|
return context;
|
|
1007
1007
|
};
|
|
1008
1008
|
const runMetric = async (call) => {
|
|
1009
1009
|
const entrypoint = findEntrypoint(getManifest(), call.entrypoint);
|
|
1010
|
-
if (entrypoint.slot !== "chart.source@1") throw new
|
|
1010
|
+
if (entrypoint.slot !== "chart.source@1") throw new ArtifactError(`\`${entrypoint.id}\` (${entrypoint.slot}) isn't a metric.`);
|
|
1011
1011
|
const filters = Object.fromEntries(Object.entries(call.filters ?? {}).filter(([, values]) => values.length > 0));
|
|
1012
1012
|
checkMetricQuery(entrypoint.metric, {
|
|
1013
1013
|
breakdown: call.breakdown,
|
|
@@ -1026,7 +1026,7 @@ async function startDevServer(options) {
|
|
|
1026
1026
|
filters
|
|
1027
1027
|
}, METRIC_LIMITS.timeoutMs);
|
|
1028
1028
|
const problem = seriesProblem(series);
|
|
1029
|
-
if (problem) throw new
|
|
1029
|
+
if (problem) throw new ArtifactError(problem);
|
|
1030
1030
|
return {
|
|
1031
1031
|
series,
|
|
1032
1032
|
took_ms: Date.now() - started
|
|
@@ -1034,7 +1034,7 @@ async function startDevServer(options) {
|
|
|
1034
1034
|
};
|
|
1035
1035
|
const runReadout = async (call) => {
|
|
1036
1036
|
const entrypoint = findEntrypoint(getManifest(), call.entrypoint);
|
|
1037
|
-
if (entrypoint.slot !== "campaign.metric@1") throw new
|
|
1037
|
+
if (entrypoint.slot !== "campaign.metric@1") throw new ArtifactError(`\`${entrypoint.id}\` (${entrypoint.slot}) isn't a readout.`);
|
|
1038
1038
|
const context = contextFor(entrypoint.slot, call.input);
|
|
1039
1039
|
const started = Date.now();
|
|
1040
1040
|
const result = await invoke("readout", {
|
|
@@ -1042,7 +1042,7 @@ async function startDevServer(options) {
|
|
|
1042
1042
|
context
|
|
1043
1043
|
}, READOUT_LIMITS.timeoutMs);
|
|
1044
1044
|
const problem = readoutProblem(result, context.variantIds ?? []);
|
|
1045
|
-
if (problem) throw new
|
|
1045
|
+
if (problem) throw new ArtifactError(problem);
|
|
1046
1046
|
return {
|
|
1047
1047
|
result,
|
|
1048
1048
|
took_ms: Date.now() - started
|
|
@@ -1050,7 +1050,7 @@ async function startDevServer(options) {
|
|
|
1050
1050
|
};
|
|
1051
1051
|
const createSession = (call) => {
|
|
1052
1052
|
const entrypoint = findEntrypoint(getManifest(), call.entrypoint);
|
|
1053
|
-
if (entrypoint.path === void 0) throw new
|
|
1053
|
+
if (entrypoint.path === void 0) throw new ArtifactError(`\`${entrypoint.id}\` (${entrypoint.slot}) has no path to open.`);
|
|
1054
1054
|
const context = contextFor(entrypoint.slot, call.input);
|
|
1055
1055
|
const token = randomBytes(24).toString("hex");
|
|
1056
1056
|
const code = randomBytes(24).toString("hex");
|
|
@@ -1132,7 +1132,7 @@ async function startDevServer(options) {
|
|
|
1132
1132
|
if (session === void 0) return sendJson(response, 401, { error: `This frame has no session. Open it from ${hostOrigin}.` });
|
|
1133
1133
|
const headers = new Headers();
|
|
1134
1134
|
for (const [name, value] of Object.entries(request.headers)) {
|
|
1135
|
-
if (name === "cookie" || name === "host" || name.startsWith("mf-") || name.startsWith(
|
|
1135
|
+
if (name === "cookie" || name === "host" || name.startsWith("mf-") || name.startsWith(ARTIFACT_HEADER_PREFIX)) continue;
|
|
1136
1136
|
if (typeof value === "string") headers.set(name, value);
|
|
1137
1137
|
}
|
|
1138
1138
|
headers.set(CONTEXT_HEADER, headerJson(session.context));
|
|
@@ -1190,9 +1190,9 @@ async function startDevServer(options) {
|
|
|
1190
1190
|
}
|
|
1191
1191
|
|
|
1192
1192
|
//#endregion
|
|
1193
|
-
//#region src/core/
|
|
1193
|
+
//#region src/core/artifacts/dev/run.ts
|
|
1194
1194
|
const UNWATCHED_DIRS = new Set(["node_modules", "dist"]);
|
|
1195
|
-
const UNWATCHED_FILES = new Set([
|
|
1195
|
+
const UNWATCHED_FILES = new Set([ARTIFACT_FILE]);
|
|
1196
1196
|
const DEBOUNCE_MS = 150;
|
|
1197
1197
|
const TOKEN_TTL_SECONDS = 3600;
|
|
1198
1198
|
const SOURCE_FILE = /\.(?:tsx?|jsx?|mts|mjs|cts|cjs|css|jsonc?|toml|svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|otf)$/;
|
|
@@ -1226,7 +1226,7 @@ function watchProject(root, onChange) {
|
|
|
1226
1226
|
};
|
|
1227
1227
|
}
|
|
1228
1228
|
function mintRefusal(error) {
|
|
1229
|
-
return /WorkOS access token/i.test(error.message) ? "`superwall
|
|
1229
|
+
return /WorkOS access token/i.test(error.message) ? "`superwall artifacts dev` needs a browser login: it makes its read-only token from your session, and an API key can't. Run `superwall login`." : error.message;
|
|
1230
1230
|
}
|
|
1231
1231
|
function agentCredential(ctx, organizationId) {
|
|
1232
1232
|
let limited = true;
|
|
@@ -1243,7 +1243,7 @@ function agentCredential(ctx, organizationId) {
|
|
|
1243
1243
|
}
|
|
1244
1244
|
return minted.token;
|
|
1245
1245
|
} catch (error) {
|
|
1246
|
-
if (error instanceof ApiError && error.status === 403) throw new
|
|
1246
|
+
if (error instanceof ApiError && error.status === 403) throw new ArtifactError(mintRefusal(error));
|
|
1247
1247
|
throw error;
|
|
1248
1248
|
}
|
|
1249
1249
|
}),
|
|
@@ -1274,22 +1274,22 @@ async function resolveDefaults(ctx, input) {
|
|
|
1274
1274
|
const named = input.context === void 0 ? void 0 : parseContextJson(input.context).organizationId;
|
|
1275
1275
|
const scope = input.app === void 0 ? { organizationId: input.org ?? (named === void 0 ? await resolveOrganization(ctx, void 0) : String(named)) } : await resolveAppScope(ctx.api, input.app, input.org);
|
|
1276
1276
|
const { organizationId } = scope;
|
|
1277
|
-
if (organizationId === void 0) throw new
|
|
1278
|
-
if (!/^[1-9]\d*$/.test(organizationId)) throw new
|
|
1277
|
+
if (organizationId === void 0) throw new ArtifactError(`Couldn't find the organization of app ${input.app}. Say which with --org <id>.`);
|
|
1278
|
+
if (!/^[1-9]\d*$/.test(organizationId)) throw new ArtifactError(`--org takes an organization's id, a number. Got ${organizationId}.`);
|
|
1279
1279
|
return {
|
|
1280
1280
|
...context,
|
|
1281
1281
|
...scope,
|
|
1282
1282
|
organizationId
|
|
1283
1283
|
};
|
|
1284
1284
|
}
|
|
1285
|
-
async function
|
|
1285
|
+
async function runArtifactDev(ctx, input, seams = {}) {
|
|
1286
1286
|
const { root } = readProject(input.dir);
|
|
1287
|
-
ctx.ui.intro("
|
|
1287
|
+
ctx.ui.intro("Artifact dev");
|
|
1288
1288
|
warnIfSdkBehind(ctx.ui, root);
|
|
1289
1289
|
const defaults = await resolveDefaults(ctx, input);
|
|
1290
1290
|
const { credential, limitedTo } = agentCredential(ctx, defaults.organizationId);
|
|
1291
1291
|
await credential.current();
|
|
1292
|
-
const first = await
|
|
1292
|
+
const first = await bundleArtifact(root, seams.wrangler);
|
|
1293
1293
|
const log = {
|
|
1294
1294
|
info: (text) => ctx.ui.step(text),
|
|
1295
1295
|
warn: (text) => ctx.ui.warn(text)
|
|
@@ -1334,7 +1334,7 @@ async function runWorkspaceDev(ctx, input, seams = {}) {
|
|
|
1334
1334
|
rebuilding = rebuilding.then(async () => {
|
|
1335
1335
|
try {
|
|
1336
1336
|
const nextManifest = readManifest(root);
|
|
1337
|
-
const next = await
|
|
1337
|
+
const next = await bundleArtifact(root, seams.wrangler);
|
|
1338
1338
|
await runtime.update(next.module, next.compatibility);
|
|
1339
1339
|
manifest = nextManifest;
|
|
1340
1340
|
ctx.ui.step(`Rebuilt, ${next.bytes} bytes`);
|
|
@@ -1365,4 +1365,4 @@ async function runWorkspaceDev(ctx, input, seams = {}) {
|
|
|
1365
1365
|
}
|
|
1366
1366
|
|
|
1367
1367
|
//#endregion
|
|
1368
|
-
export {
|
|
1368
|
+
export { runArtifactDev, watchProject };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as Integration } from "./environment-
|
|
1
|
+
import { h as Integration } from "./environment-BocmdvZ-.js";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, sep } from "node:path";
|
|
4
4
|
import fg from "fast-glob";
|