@vercel/sandbox 2.0.0-beta.14 → 2.0.0-beta.18
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/api-client/api-client.cjs +1 -14
- package/dist/api-client/api-client.cjs.map +1 -1
- package/dist/api-client/api-client.d.cts +5509 -76
- package/dist/api-client/api-client.d.ts +5509 -76
- package/dist/api-client/api-client.js +2 -15
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/base-client.cjs +2 -1
- package/dist/api-client/base-client.cjs.map +1 -1
- package/dist/api-client/base-client.js +2 -1
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/index.d.ts +1 -1
- package/dist/api-client/index.js +1 -1
- package/dist/api-client/validators.cjs +60 -16
- package/dist/api-client/validators.cjs.map +1 -1
- package/dist/api-client/validators.d.cts +25546 -130
- package/dist/api-client/validators.d.ts +25546 -130
- package/dist/api-client/validators.js +55 -16
- package/dist/api-client/validators.js.map +1 -1
- package/dist/auth/api.cjs +1 -1
- package/dist/auth/api.cjs.map +1 -1
- package/dist/auth/api.js +1 -1
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/index.cjs +0 -1
- package/dist/auth/index.d.cts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +2 -2
- package/dist/auth/project.cjs +124 -26
- package/dist/auth/project.cjs.map +1 -1
- package/dist/auth/project.d.cts +9 -13
- package/dist/auth/project.d.ts +9 -13
- package/dist/auth/project.js +125 -26
- package/dist/auth/project.js.map +1 -1
- package/dist/filesystem.cjs +499 -0
- package/dist/filesystem.cjs.map +1 -0
- package/dist/filesystem.d.cts +258 -0
- package/dist/filesystem.d.ts +258 -0
- package/dist/filesystem.js +497 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/network-policy.d.cts +58 -2
- package/dist/network-policy.d.ts +58 -2
- package/dist/sandbox.cjs +137 -22
- package/dist/sandbox.cjs.map +1 -1
- package/dist/sandbox.d.cts +2068 -22
- package/dist/sandbox.d.ts +2068 -22
- package/dist/sandbox.js +137 -22
- package/dist/sandbox.js.map +1 -1
- package/dist/session.cjs +10 -7
- package/dist/session.cjs.map +1 -1
- package/dist/session.d.cts +7 -5
- package/dist/session.d.ts +7 -5
- package/dist/session.js +10 -7
- package/dist/session.js.map +1 -1
- package/dist/snapshot.cjs +63 -10
- package/dist/snapshot.cjs.map +1 -1
- package/dist/snapshot.d.cts +41 -9
- package/dist/snapshot.d.ts +41 -9
- package/dist/snapshot.js +62 -10
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/network-policy.cjs +23 -39
- package/dist/utils/network-policy.cjs.map +1 -1
- package/dist/utils/network-policy.js +23 -39
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/paginator.cjs +41 -0
- package/dist/utils/paginator.cjs.map +1 -0
- package/dist/utils/paginator.d.cts +16 -0
- package/dist/utils/paginator.d.ts +16 -0
- package/dist/utils/paginator.js +40 -0
- package/dist/utils/paginator.js.map +1 -0
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
package/dist/auth/project.js
CHANGED
|
@@ -4,24 +4,47 @@ import { readLinkedProject } from "./linked-project.js";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/auth/project.ts
|
|
7
|
-
const
|
|
7
|
+
const UserSchema = z.object({ user: z.object({
|
|
8
|
+
defaultTeamId: z.string().nullable(),
|
|
9
|
+
username: z.string()
|
|
10
|
+
}) });
|
|
11
|
+
const TeamSchema = z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
slug: z.string(),
|
|
14
|
+
updatedAt: z.number(),
|
|
15
|
+
membership: z.object({ role: z.string() }),
|
|
16
|
+
billing: z.object({ plan: z.string() })
|
|
17
|
+
});
|
|
18
|
+
const TeamsSchema = z.object({
|
|
19
|
+
teams: z.array(TeamSchema),
|
|
20
|
+
pagination: z.object({
|
|
21
|
+
count: z.number(),
|
|
22
|
+
next: z.number().nullable()
|
|
23
|
+
})
|
|
24
|
+
});
|
|
8
25
|
const DEFAULT_PROJECT_NAME = "vercel-sandbox-default-project";
|
|
26
|
+
/** Status codes that mean "this team can't be used, try the next one". */
|
|
27
|
+
function isSkippableTeamError(e) {
|
|
28
|
+
return e instanceof NotOk && (e.response.statusCode === 402 || e.response.statusCode === 403);
|
|
29
|
+
}
|
|
9
30
|
/**
|
|
10
31
|
* Resolves the team and project scope for sandbox operations.
|
|
11
32
|
*
|
|
12
33
|
* First checks for a locally linked project in `.vercel/project.json`.
|
|
13
34
|
* If found, uses the `projectId` and `orgId` from there.
|
|
14
35
|
*
|
|
15
|
-
* Otherwise, if `teamId` is not provided,
|
|
16
|
-
*
|
|
36
|
+
* Otherwise, if `teamId` is not provided, builds an ordered list of candidate
|
|
37
|
+
* teams to try: the user's `defaultTeamId` first (if set), then hobby-plan
|
|
38
|
+
* teams where the user has an OWNER role (preferring the personal team matching
|
|
39
|
+
* the username, then the most recently updated). Tries each candidate until one
|
|
40
|
+
* succeeds.
|
|
17
41
|
*
|
|
18
42
|
* @param opts.token - Vercel API authentication token.
|
|
19
|
-
* @param opts.teamId - Optional team slug. If omitted,
|
|
43
|
+
* @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.
|
|
20
44
|
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
21
45
|
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
22
46
|
*
|
|
23
47
|
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
24
|
-
* @throws {ZodError} If no teams exist for the account.
|
|
25
48
|
*
|
|
26
49
|
* @example
|
|
27
50
|
* ```ts
|
|
@@ -31,22 +54,89 @@ const DEFAULT_PROJECT_NAME = "vercel-sandbox-default-project";
|
|
|
31
54
|
*/
|
|
32
55
|
async function inferScope(opts) {
|
|
33
56
|
const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());
|
|
34
|
-
if (linkedProject)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
if (linkedProject) {
|
|
58
|
+
const slugs = await resolveLinkedProjectSlugs(opts.token, linkedProject.teamId, linkedProject.projectId);
|
|
59
|
+
return {
|
|
60
|
+
...linkedProject,
|
|
61
|
+
created: false,
|
|
62
|
+
...slugs
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (opts.teamId) return tryTeam(opts.token, opts.teamId);
|
|
66
|
+
const { defaultTeamId, username } = (await fetchApi({
|
|
67
|
+
token: opts.token,
|
|
68
|
+
endpoint: "/v2/user"
|
|
69
|
+
}).then(UserSchema.parse)).user;
|
|
70
|
+
if (defaultTeamId) try {
|
|
71
|
+
const result = await tryTeam(opts.token, defaultTeamId);
|
|
72
|
+
try {
|
|
73
|
+
const team = await fetchApi({
|
|
74
|
+
token: opts.token,
|
|
75
|
+
endpoint: `/v2/teams/${encodeURIComponent(defaultTeamId)}`
|
|
76
|
+
}).then(z.object({ slug: z.string() }).parse);
|
|
77
|
+
return {
|
|
78
|
+
...result,
|
|
79
|
+
teamSlug: team.slug
|
|
80
|
+
};
|
|
81
|
+
} catch {
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
86
|
+
}
|
|
87
|
+
let next = null;
|
|
88
|
+
do {
|
|
89
|
+
const endpoint = next === null ? "/v2/teams?limit=20" : `/v2/teams?limit=20&until=${next}`;
|
|
90
|
+
const page = await fetchApi({
|
|
91
|
+
token: opts.token,
|
|
92
|
+
endpoint
|
|
93
|
+
}).then(TeamsSchema.parse);
|
|
94
|
+
next = page.pagination.next;
|
|
95
|
+
const hobbyOwnerTeams = page.teams.filter((t) => t.membership.role === "OWNER" && t.billing.plan === "hobby");
|
|
96
|
+
if (hobbyOwnerTeams.length === 0) continue;
|
|
97
|
+
const bestHobbyTeam = hobbyOwnerTeams.find((t) => t.slug === username) ?? hobbyOwnerTeams.sort((a, b) => b.updatedAt - a.updatedAt)[0];
|
|
98
|
+
if (bestHobbyTeam && bestHobbyTeam.id !== defaultTeamId) try {
|
|
99
|
+
return {
|
|
100
|
+
...await tryTeam(opts.token, bestHobbyTeam.id),
|
|
101
|
+
teamSlug: bestHobbyTeam.slug
|
|
102
|
+
};
|
|
103
|
+
} catch (e) {
|
|
104
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
105
|
+
}
|
|
106
|
+
} while (next !== null);
|
|
107
|
+
try {
|
|
108
|
+
return {
|
|
109
|
+
...await tryTeam(opts.token, username),
|
|
110
|
+
teamSlug: username
|
|
111
|
+
};
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
114
|
+
}
|
|
115
|
+
throw new NotOk({
|
|
116
|
+
statusCode: 403,
|
|
117
|
+
responseText: `Authenticated as "${username}" but none of the available teams allow sandbox creation. Specify a team explicitly with --scope <team-id-or-slug>.`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Attempts to use a specific team for sandbox operations by checking for
|
|
122
|
+
* (or creating) the default project within that team.
|
|
123
|
+
*
|
|
124
|
+
* @returns The resolved scope if the team is usable.
|
|
125
|
+
* @throws {NotOk} On authorization or other API errors.
|
|
126
|
+
*/
|
|
127
|
+
async function tryTeam(token, teamId) {
|
|
128
|
+
const teamParam = teamId.startsWith("team_") ? `teamId=${encodeURIComponent(teamId)}` : `slug=${encodeURIComponent(teamId)}`;
|
|
39
129
|
let created = false;
|
|
40
130
|
try {
|
|
41
131
|
await fetchApi({
|
|
42
|
-
token
|
|
43
|
-
endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}
|
|
132
|
+
token,
|
|
133
|
+
endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?${teamParam}`
|
|
44
134
|
});
|
|
45
135
|
} catch (e) {
|
|
46
136
|
if (!(e instanceof NotOk) || e.response.statusCode !== 404) throw e;
|
|
47
137
|
await fetchApi({
|
|
48
|
-
token
|
|
49
|
-
endpoint: `/v11/projects
|
|
138
|
+
token,
|
|
139
|
+
endpoint: `/v11/projects?${teamParam}`,
|
|
50
140
|
method: "POST",
|
|
51
141
|
body: JSON.stringify({ name: DEFAULT_PROJECT_NAME })
|
|
52
142
|
});
|
|
@@ -59,20 +149,29 @@ async function inferScope(opts) {
|
|
|
59
149
|
};
|
|
60
150
|
}
|
|
61
151
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @param token - Authentication token used to call the Vercel API.
|
|
66
|
-
* @returns A promise that resolves to the first team's slug.
|
|
152
|
+
* Best-effort resolution of team slug and project name for a linked project.
|
|
153
|
+
* Both IDs may be opaque (e.g. `team_xxx`, `prj_xxx`), so we fetch the
|
|
154
|
+
* human-readable names from the API in parallel.
|
|
67
155
|
*/
|
|
68
|
-
async function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
156
|
+
async function resolveLinkedProjectSlugs(token, teamId, projectId) {
|
|
157
|
+
try {
|
|
158
|
+
const teamParam = teamId.startsWith("team_") ? `teamId=${encodeURIComponent(teamId)}` : `slug=${encodeURIComponent(teamId)}`;
|
|
159
|
+
const [teamData, projectData] = await Promise.all([fetchApi({
|
|
160
|
+
token,
|
|
161
|
+
endpoint: `/v2/teams/${encodeURIComponent(teamId)}`
|
|
162
|
+
}).then(z.object({ slug: z.string() }).parse), fetchApi({
|
|
163
|
+
token,
|
|
164
|
+
endpoint: `/v2/projects/${encodeURIComponent(projectId)}?${teamParam}`
|
|
165
|
+
}).then(z.object({ name: z.string() }).parse)]);
|
|
166
|
+
return {
|
|
167
|
+
teamSlug: teamData.slug,
|
|
168
|
+
projectSlug: projectData.name
|
|
169
|
+
};
|
|
170
|
+
} catch {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
74
173
|
}
|
|
75
174
|
|
|
76
175
|
//#endregion
|
|
77
|
-
export { inferScope
|
|
176
|
+
export { inferScope };
|
|
78
177
|
//# sourceMappingURL=project.js.map
|
package/dist/auth/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","names":[],"sources":["../../src/auth/project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { fetchApi } from \"./api.js\";\nimport { NotOk } from \"./error.js\";\nimport { readLinkedProject } from \"./linked-project.js\";\n\nconst TeamsSchema = z.object({\n teams: z\n .array(\n z.object({\n slug: z.string(),\n }),\n )\n .min(1, `No teams found. Please create a team first.`),\n});\n\nconst DEFAULT_PROJECT_NAME = \"vercel-sandbox-default-project\";\n\n/**\n * Resolves the team and project scope for sandbox operations.\n *\n * First checks for a locally linked project in `.vercel/project.json`.\n * If found, uses the `projectId` and `orgId` from there.\n *\n * Otherwise, if `teamId` is not provided, selects the first available team for the account.\n * Ensures a default project exists within the team, creating it if necessary.\n *\n * @param opts.token - Vercel API authentication token.\n * @param opts.teamId - Optional team slug. If omitted, the first team is selected.\n * @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.\n * @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.\n *\n * @throws {NotOk} If the API returns an error other than 404 when checking the project.\n * @throws {ZodError} If no teams exist for the account.\n *\n * @example\n * ```ts\n * const scope = await inferScope({ token: \"vercel_...\" });\n * // => { projectId: \"vercel-sandbox-default-project\", teamId: \"my-team\", created: false }\n * ```\n */\nexport async function inferScope(opts: {\n token: string;\n teamId?: string;\n cwd?: string;\n}): Promise<{ projectId: string; teamId: string; created: boolean }> {\n const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());\n if (linkedProject) {\n return { ...linkedProject, created: false };\n }\n\n const teamId = opts.teamId ?? (await selectTeam(opts.token));\n\n let created = false;\n try {\n await fetchApi({\n token: opts.token,\n endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`,\n });\n } catch (e) {\n if (!(e instanceof NotOk) || e.response.statusCode !== 404) {\n throw e;\n }\n\n await fetchApi({\n token: opts.token,\n endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,\n method: \"POST\",\n body: JSON.stringify({\n name: DEFAULT_PROJECT_NAME,\n }),\n });\n created = true;\n }\n\n return { projectId: DEFAULT_PROJECT_NAME, teamId, created };\n}\n\n/**\n * Selects a team for the current token by querying the Teams API and\n * returning the slug of the first team in the result set.\n *\n * @param token - Authentication token used to call the Vercel API.\n * @returns A promise that resolves to the first team's slug.\n */\nexport async function selectTeam(token: string) {\n const {\n teams: [team],\n } = await fetchApi({ token, endpoint: \"/v2/teams?limit=1\" }).then(\n TeamsSchema.parse,\n );\n return team.slug;\n}\n"],"mappings":";;;;;;AAKA,MAAM,cAAc,EAAE,OAAO,EAC3B,OAAO,EACJ,MACC,EAAE,OAAO,EACP,MAAM,EAAE,QAAQ,EACjB,CAAC,CACH,CACA,IAAI,GAAG,8CAA8C,EACzD,CAAC;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;AAyB7B,eAAsB,WAAW,MAIoC;CACnE,MAAM,gBAAgB,MAAM,kBAAkB,KAAK,OAAO,QAAQ,KAAK,CAAC;AACxE,KAAI,cACF,QAAO;EAAE,GAAG;EAAe,SAAS;EAAO;CAG7C,MAAM,SAAS,KAAK,UAAW,MAAM,WAAW,KAAK,MAAM;CAE3D,IAAI,UAAU;AACd,KAAI;AACF,QAAM,SAAS;GACb,OAAO,KAAK;GACZ,UAAU,gBAAgB,mBAAmB,qBAAqB,CAAC,QAAQ,mBAAmB,OAAO;GACtG,CAAC;UACK,GAAG;AACV,MAAI,EAAE,aAAa,UAAU,EAAE,SAAS,eAAe,IACrD,OAAM;AAGR,QAAM,SAAS;GACb,OAAO,KAAK;GACZ,UAAU,sBAAsB,mBAAmB,OAAO;GAC1D,QAAQ;GACR,MAAM,KAAK,UAAU,EACnB,MAAM,sBACP,CAAC;GACH,CAAC;AACF,YAAU;;AAGZ,QAAO;EAAE,WAAW;EAAsB;EAAQ;EAAS;;;;;;;;;AAU7D,eAAsB,WAAW,OAAe;CAC9C,MAAM,EACJ,OAAO,CAAC,UACN,MAAM,SAAS;EAAE;EAAO,UAAU;EAAqB,CAAC,CAAC,KAC3D,YAAY,MACb;AACD,QAAO,KAAK"}
|
|
1
|
+
{"version":3,"file":"project.js","names":["next: number | null","endpoint: string"],"sources":["../../src/auth/project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { fetchApi } from \"./api.js\";\nimport { NotOk } from \"./error.js\";\nimport { readLinkedProject } from \"./linked-project.js\";\n\nconst UserSchema = z.object({\n user: z.object({\n defaultTeamId: z.string().nullable(),\n username: z.string(),\n }),\n});\n\nconst TeamSchema = z.object({\n id: z.string(),\n slug: z.string(),\n updatedAt: z.number(),\n membership: z.object({\n role: z.string(),\n }),\n billing: z.object({\n plan: z.string(),\n }),\n});\n\nconst TeamsSchema = z.object({\n teams: z.array(TeamSchema),\n pagination: z.object({\n count: z.number(),\n next: z.number().nullable(),\n }),\n});\n\nconst DEFAULT_PROJECT_NAME = \"vercel-sandbox-default-project\";\n\n/** Status codes that mean \"this team can't be used, try the next one\". */\nfunction isSkippableTeamError(e: unknown): boolean {\n return e instanceof NotOk && (e.response.statusCode === 402 || e.response.statusCode === 403);\n}\n\n/**\n * Resolves the team and project scope for sandbox operations.\n *\n * First checks for a locally linked project in `.vercel/project.json`.\n * If found, uses the `projectId` and `orgId` from there.\n *\n * Otherwise, if `teamId` is not provided, builds an ordered list of candidate\n * teams to try: the user's `defaultTeamId` first (if set), then hobby-plan\n * teams where the user has an OWNER role (preferring the personal team matching\n * the username, then the most recently updated). Tries each candidate until one\n * succeeds.\n *\n * @param opts.token - Vercel API authentication token.\n * @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.\n * @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.\n * @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.\n *\n * @throws {NotOk} If the API returns an error other than 404 when checking the project.\n *\n * @example\n * ```ts\n * const scope = await inferScope({ token: \"vercel_...\" });\n * // => { projectId: \"vercel-sandbox-default-project\", teamId: \"my-team\", created: false }\n * ```\n */\nexport async function inferScope(opts: {\n token: string;\n teamId?: string;\n cwd?: string;\n}): Promise<{\n projectId: string;\n teamId: string;\n created: boolean;\n teamSlug?: string;\n projectSlug?: string;\n}> {\n const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());\n if (linkedProject) {\n const slugs = await resolveLinkedProjectSlugs(\n opts.token,\n linkedProject.teamId,\n linkedProject.projectId,\n );\n return { ...linkedProject, created: false, ...slugs };\n }\n\n if (opts.teamId) {\n return tryTeam(opts.token, opts.teamId);\n }\n\n const userData = await fetchApi({\n token: opts.token,\n endpoint: \"/v2/user\",\n }).then(UserSchema.parse);\n const { defaultTeamId, username } = userData.user;\n\n // 1. Try defaultTeamId first\n if (defaultTeamId) {\n try {\n const result = await tryTeam(opts.token, defaultTeamId);\n // Resolve team slug (best-effort)\n try {\n const team = await fetchApi({\n token: opts.token,\n endpoint: `/v2/teams/${encodeURIComponent(defaultTeamId)}`,\n }).then(z.object({ slug: z.string() }).parse);\n return { ...result, teamSlug: team.slug };\n } catch {\n return result;\n }\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n }\n\n // 2. Paginate teams in pages of 20, try best hobby team per page\n let next: number | null = null;\n do {\n const endpoint: string =\n next === null\n ? \"/v2/teams?limit=20\"\n : `/v2/teams?limit=20&until=${next}`;\n const page = await fetchApi({ token: opts.token, endpoint }).then(\n TeamsSchema.parse,\n );\n\n next = page.pagination.next;\n\n const hobbyOwnerTeams = page.teams.filter(\n (t) => t.membership.role === \"OWNER\" && t.billing.plan === \"hobby\",\n );\n if (hobbyOwnerTeams.length === 0) {\n continue;\n }\n\n const bestHobbyTeam =\n hobbyOwnerTeams.find((t) => t.slug === username) ??\n hobbyOwnerTeams.sort((a, b) => b.updatedAt - a.updatedAt)[0];\n\n if (bestHobbyTeam && bestHobbyTeam.id !== defaultTeamId) {\n try {\n const result = await tryTeam(opts.token, bestHobbyTeam.id);\n return { ...result, teamSlug: bestHobbyTeam.slug };\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n }\n } while (next !== null);\n\n // 3. Fall back to username as personal team\n try {\n const result = await tryTeam(opts.token, username);\n return { ...result, teamSlug: username };\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n\n throw new NotOk({\n statusCode: 403,\n responseText: `Authenticated as \"${username}\" but none of the available teams allow sandbox creation. Specify a team explicitly with --scope <team-id-or-slug>.`,\n });\n}\n\n/**\n * Attempts to use a specific team for sandbox operations by checking for\n * (or creating) the default project within that team.\n *\n * @returns The resolved scope if the team is usable.\n * @throws {NotOk} On authorization or other API errors.\n */\nasync function tryTeam(\n token: string,\n teamId: string,\n): Promise<{ projectId: string; teamId: string; created: boolean }> {\n const teamParam = teamId.startsWith(\"team_\")\n ? `teamId=${encodeURIComponent(teamId)}`\n : `slug=${encodeURIComponent(teamId)}`;\n\n let created = false;\n try {\n await fetchApi({\n token,\n endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?${teamParam}`,\n });\n } catch (e) {\n if (!(e instanceof NotOk) || e.response.statusCode !== 404) {\n throw e;\n }\n\n await fetchApi({\n token,\n endpoint: `/v11/projects?${teamParam}`,\n method: \"POST\",\n body: JSON.stringify({\n name: DEFAULT_PROJECT_NAME,\n }),\n });\n created = true;\n }\n\n return { projectId: DEFAULT_PROJECT_NAME, teamId, created };\n}\n\n/**\n * Best-effort resolution of team slug and project name for a linked project.\n * Both IDs may be opaque (e.g. `team_xxx`, `prj_xxx`), so we fetch the\n * human-readable names from the API in parallel.\n */\nasync function resolveLinkedProjectSlugs(\n token: string,\n teamId: string,\n projectId: string,\n): Promise<{ teamSlug?: string; projectSlug?: string }> {\n try {\n const teamParam = teamId.startsWith(\"team_\")\n ? `teamId=${encodeURIComponent(teamId)}`\n : `slug=${encodeURIComponent(teamId)}`;\n const [teamData, projectData] = await Promise.all([\n fetchApi({\n token,\n endpoint: `/v2/teams/${encodeURIComponent(teamId)}`,\n }).then(z.object({ slug: z.string() }).parse),\n fetchApi({\n token,\n endpoint: `/v2/projects/${encodeURIComponent(projectId)}?${teamParam}`,\n }).then(z.object({ name: z.string() }).parse),\n ]);\n return { teamSlug: teamData.slug, projectSlug: projectData.name };\n } catch {\n return {};\n }\n}\n"],"mappings":";;;;;;AAKA,MAAM,aAAa,EAAE,OAAO,EAC1B,MAAM,EAAE,OAAO;CACb,eAAe,EAAE,QAAQ,CAAC,UAAU;CACpC,UAAU,EAAE,QAAQ;CACrB,CAAC,EACH,CAAC;AAEF,MAAM,aAAa,EAAE,OAAO;CAC1B,IAAI,EAAE,QAAQ;CACd,MAAM,EAAE,QAAQ;CAChB,WAAW,EAAE,QAAQ;CACrB,YAAY,EAAE,OAAO,EACnB,MAAM,EAAE,QAAQ,EACjB,CAAC;CACF,SAAS,EAAE,OAAO,EAChB,MAAM,EAAE,QAAQ,EACjB,CAAC;CACH,CAAC;AAEF,MAAM,cAAc,EAAE,OAAO;CAC3B,OAAO,EAAE,MAAM,WAAW;CAC1B,YAAY,EAAE,OAAO;EACnB,OAAO,EAAE,QAAQ;EACjB,MAAM,EAAE,QAAQ,CAAC,UAAU;EAC5B,CAAC;CACH,CAAC;AAEF,MAAM,uBAAuB;;AAG7B,SAAS,qBAAqB,GAAqB;AACjD,QAAO,aAAa,UAAU,EAAE,SAAS,eAAe,OAAO,EAAE,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B3F,eAAsB,WAAW,MAU9B;CACD,MAAM,gBAAgB,MAAM,kBAAkB,KAAK,OAAO,QAAQ,KAAK,CAAC;AACxE,KAAI,eAAe;EACjB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