@selvajs/selva 4.20.1-beta.2 → 4.20.1-beta.3
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/build/adapter-node.js +1 -1
- package/build/client/_app/immutable/chunks/{D-SwRD80.js → D-uUm_OB.js} +43 -43
- package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
- package/build/client/_app/immutable/chunks/{D-SwRD80.js.gz → D-uUm_OB.js.gz} +0 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js +1 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js.br +1 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.hg2qyLJU.js → app.BpT6WkO1.js} +2 -2
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js +1 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/server/.vite/manifest.json +9 -2
- package/build/server/chunks/access.js +0 -3
- package/build/server/chunks/access.js.map +1 -1
- package/build/server/chunks/definitions.js +178 -1
- package/build/server/chunks/definitions.js.map +1 -1
- package/build/server/chunks/handlers.js +4 -5
- package/build/server/chunks/handlers.js.map +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/package.js +1 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +89 -188
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/registry.js +3 -3
- package/build/server/chunks/registry.js.map +1 -1
- package/build/server/chunks/resolve.server.js +1 -1
- package/build/server/chunks/server-config-write.js +13 -1
- package/build/server/chunks/server-config-write.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +30 -48
- package/build/server/entries/endpoints/api/admin/compute/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js +3 -2
- package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +3 -2
- package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +3 -2
- package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/admin/users/_server.ts.js +6 -2
- package/build/server/entries/endpoints/api/admin/users/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js +8 -8
- package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +1 -1
- package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
- package/build/server/entries/hooks.server.js +13 -1
- package/build/server/entries/hooks.server.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +16 -3
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +132 -89
- package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
- package/build/server/manifest-full.js +1 -1
- package/build/server/manifest.js +1 -1
- package/build/server/nodes/21.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +11 -11
- package/build/client/_app/immutable/chunks/D-SwRD80.js.br +0 -0
- package/build/client/_app/immutable/chunks/Dvq2vJj6.js +0 -1
- package/build/client/_app/immutable/chunks/Dvq2vJj6.js.br +0 -1
- package/build/client/_app/immutable/chunks/Dvq2vJj6.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.hg2qyLJU.js.br +0 -0
- package/build/client/_app/immutable/entry/app.hg2qyLJU.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.gGT7QEb1.js +0 -1
- package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.br +0 -1
- package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.gz +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as actorFrom, g as getPermissionStore, h as getOrganizationProvider, r as getAuthProvider, u as getEventSink } from "../../../../../chunks/providers.server.js";
|
|
1
|
+
import { U as actorFrom, g as getPermissionStore, h as getOrganizationProvider, o as getDataProvider, r as getAuthProvider, u as getEventSink } from "../../../../../chunks/providers.server.js";
|
|
2
2
|
import { b as requireManageInstanceUsers, k as ApiErrorCode, r as assertCanGrantPlatformPermissions } from "../../../../../chunks/access.js";
|
|
3
3
|
import { t as SYSTEM_CONTEXT } from "../../../../../chunks/context.js";
|
|
4
4
|
import { R as parseBody } from "../../../../../chunks/api.js";
|
|
@@ -49,7 +49,7 @@ var POST = apiRoute("Failed to create user", async ({ request, locals }) => {
|
|
|
49
49
|
userId: user.id,
|
|
50
50
|
actorId: actorFrom(locals.ctx)
|
|
51
51
|
});
|
|
52
|
-
|
|
52
|
+
await getDataProvider().ensureUser(SYSTEM_CONTEXT, user.id);
|
|
53
53
|
const orgId = locals.ctx?.actingOrgId;
|
|
54
54
|
if (orgId) {
|
|
55
55
|
const joinedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -64,6 +64,10 @@ var POST = apiRoute("Failed to create user", async ({ request, locals }) => {
|
|
|
64
64
|
deletedAt: null
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
if (platform.length > 0) {
|
|
68
|
+
const granted = await setUserPlatformPermissions(locals.ctx, user.id, platform);
|
|
69
|
+
if (granted !== "ok") apiError(500, ApiErrorCode.INTERNAL, `The user was created, but their platform permissions were not granted (${granted}). Grant them from the user list.`);
|
|
70
|
+
}
|
|
67
71
|
return created(user);
|
|
68
72
|
});
|
|
69
73
|
export { GET, POST };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/admin/users/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport { getAuthProvider } from '#lib/server/providers.server.js';\nimport {\n\tgetEventSink,\n\tgetOrganizationProvider,\n\tgetPermissionStore\n} from '#lib/server/providers.server.js';\nimport {\n\tassertCanGrantPlatformPermissions,\n\trequireManageInstanceUsers\n} from '#lib/server/access.server.js';\nimport { listAllOrgMembers } from '@selvajs/server/organizations';\nimport { setUserPlatformPermissions } from '#lib/server/permissions.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, created, parseBody } from '#lib/server/api/http.js';\nimport {\n\tPlatformPermissionSchema,\n\tSYSTEM_CONTEXT,\n\tactorFrom,\n\ttype OrgMember\n} from '@selvajs/platform';\n// `password` is deliberately absent: an admin never sets another user's\n// credential. A stale client may still send one — Zod strips unknown keys, so it\n// is dropped rather than rejected.\n//\n// Platform scope only — a new user joins the active org as a bare `member`, and\n// their org permissions are granted at /team/members under manage_org_members.\nconst CreateUserBody = z.object({\n\temail: z.string().email('Valid email is required'),\n\tpermissions: z.array(PlatformPermissionSchema)\n});\n\n// GET — list all users with their platform permissions and acting-org membership.\nexport const GET: RequestHandler = apiRoute('Failed to list users', async ({ locals }) => {\n\trequireManageInstanceUsers(locals);\n\tconst page = await getAuthProvider().listUsers({ limit: 200 });\n\tif (page === null) {\n\t\tapiError(\n\t\t\t501,\n\t\t\tApiErrorCode.INTERNAL,\n\t\t\t'User management is not supported by the current auth provider. Configure DATA_PATH (local provider) or check your provider wiring.'\n\t\t);\n\t}\n\n\tconst orgId = locals.ctx?.actingOrgId;\n\tconst orgs = getOrganizationProvider();\n\t// Single batch read for platform permissions instead of N round-trips.\n\tconst userIds = page.items.map((u) => u.id);\n\tconst platformByUser = await getPermissionStore().getForBatch(locals.ctx!, userIds);\n\t// One membership listing instead of a getOrgMember round-trip per user.\n\tconst memberByUserId = new Map<string, OrgMember>();\n\tif (orgId) {\n\t\tfor (const m of await listAllOrgMembers(orgs, orgId, locals.log))\n\t\t\tmemberByUserId.set(m.userId, m);\n\t}\n\tconst users = page.items.map((u) => {\n\t\tconst member = memberByUserId.get(u.id);\n\t\treturn {\n\t\t\t...u,\n\t\t\tplatformPermissions: platformByUser.get(u.id) ?? [],\n\t\t\torgRole: member?.role,\n\t\t\torgPermissions: member ? [...member.permissions] : []\n\t\t};\n\t});\n\treturn json({ users });\n});\n\n// POST — create a user + attach to default org with split permissions.\nexport const POST: RequestHandler = apiRoute(\n\t'Failed to create user',\n\tasync ({ request, locals }) => {\n\t\trequireManageInstanceUsers(locals);\n\t\tconst auth = getAuthProvider();\n\n\t\tconst { email, permissions: platform } = await parseBody(request, CreateUserBody);\n\n\t\tassertCanGrantPlatformPermissions(locals.ctx!, platform);\n\n\t\tlet user;\n\t\tif (auth.createUser) {\n\t\t\t// No password branch: a provider that owns credentials admits users by\n\t\t\t// invite, so nobody but the account holder ever chooses the password.\n\t\t\t// `createUser` is the allowlist path — under header-auth it is the only\n\t\t\t// way in, since the IdP holds the credential and Selva never sees one.\n\t\t\tuser = await auth.createUser(email);\n\t\t} else {\n\t\t\tapiError(\n\t\t\t\t501,\n\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t`${auth.name} cannot create a user directly. Send an invite instead — the recipient sets their own password.`\n\t\t\t);\n\t\t}\n\n\t\tawait getEventSink().emit({\n\t\t\ttype: 'user.created',\n\t\t\tuserId: user.id,\n\t\t\tactorId: actorFrom(locals.ctx!)\n\t\t});\n\n\t\t//
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/admin/users/+server.ts"],"sourcesContent":["import { json } from '@sveltejs/kit';\nimport type { RequestHandler } from './$types';\nimport { z } from 'zod';\nimport { getAuthProvider } from '#lib/server/providers.server.js';\nimport {\n\tgetDataProvider,\n\tgetEventSink,\n\tgetOrganizationProvider,\n\tgetPermissionStore\n} from '#lib/server/providers.server.js';\nimport {\n\tassertCanGrantPlatformPermissions,\n\trequireManageInstanceUsers\n} from '#lib/server/access.server.js';\nimport { listAllOrgMembers } from '@selvajs/server/organizations';\nimport { setUserPlatformPermissions } from '#lib/server/permissions.server.js';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport { apiRoute, created, parseBody } from '#lib/server/api/http.js';\nimport {\n\tPlatformPermissionSchema,\n\tSYSTEM_CONTEXT,\n\tactorFrom,\n\ttype OrgMember\n} from '@selvajs/platform';\n// `password` is deliberately absent: an admin never sets another user's\n// credential. A stale client may still send one — Zod strips unknown keys, so it\n// is dropped rather than rejected.\n//\n// Platform scope only — a new user joins the active org as a bare `member`, and\n// their org permissions are granted at /team/members under manage_org_members.\nconst CreateUserBody = z.object({\n\temail: z.string().email('Valid email is required'),\n\tpermissions: z.array(PlatformPermissionSchema)\n});\n\n// GET — list all users with their platform permissions and acting-org membership.\nexport const GET: RequestHandler = apiRoute('Failed to list users', async ({ locals }) => {\n\trequireManageInstanceUsers(locals);\n\tconst page = await getAuthProvider().listUsers({ limit: 200 });\n\tif (page === null) {\n\t\tapiError(\n\t\t\t501,\n\t\t\tApiErrorCode.INTERNAL,\n\t\t\t'User management is not supported by the current auth provider. Configure DATA_PATH (local provider) or check your provider wiring.'\n\t\t);\n\t}\n\n\tconst orgId = locals.ctx?.actingOrgId;\n\tconst orgs = getOrganizationProvider();\n\t// Single batch read for platform permissions instead of N round-trips.\n\tconst userIds = page.items.map((u) => u.id);\n\tconst platformByUser = await getPermissionStore().getForBatch(locals.ctx!, userIds);\n\t// One membership listing instead of a getOrgMember round-trip per user.\n\tconst memberByUserId = new Map<string, OrgMember>();\n\tif (orgId) {\n\t\tfor (const m of await listAllOrgMembers(orgs, orgId, locals.log))\n\t\t\tmemberByUserId.set(m.userId, m);\n\t}\n\tconst users = page.items.map((u) => {\n\t\tconst member = memberByUserId.get(u.id);\n\t\treturn {\n\t\t\t...u,\n\t\t\tplatformPermissions: platformByUser.get(u.id) ?? [],\n\t\t\torgRole: member?.role,\n\t\t\torgPermissions: member ? [...member.permissions] : []\n\t\t};\n\t});\n\treturn json({ users });\n});\n\n// POST — create a user + attach to default org with split permissions.\nexport const POST: RequestHandler = apiRoute(\n\t'Failed to create user',\n\tasync ({ request, locals }) => {\n\t\trequireManageInstanceUsers(locals);\n\t\tconst auth = getAuthProvider();\n\n\t\tconst { email, permissions: platform } = await parseBody(request, CreateUserBody);\n\n\t\tassertCanGrantPlatformPermissions(locals.ctx!, platform);\n\n\t\tlet user;\n\t\tif (auth.createUser) {\n\t\t\t// No password branch: a provider that owns credentials admits users by\n\t\t\t// invite, so nobody but the account holder ever chooses the password.\n\t\t\t// `createUser` is the allowlist path — under header-auth it is the only\n\t\t\t// way in, since the IdP holds the credential and Selva never sees one.\n\t\t\tuser = await auth.createUser(email);\n\t\t} else {\n\t\t\tapiError(\n\t\t\t\t501,\n\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t`${auth.name} cannot create a user directly. Send an invite instead — the recipient sets their own password.`\n\t\t\t);\n\t\t}\n\n\t\tawait getEventSink().emit({\n\t\t\ttype: 'user.created',\n\t\t\tuserId: user.id,\n\t\t\tactorId: actorFrom(locals.ctx!)\n\t\t});\n\n\t\t// The permission store writes to the data-layer row, which the hook seeds\n\t\t// only on the user's first request.\n\t\tawait getDataProvider().ensureUser(SYSTEM_CONTEXT, user.id);\n\n\t\t// Attach to the active org as a bare member. Under header-auth this is the\n\t\t// only way in — the IdP holds the credential, so there is no invite to\n\t\t// accept. Org permissions are granted separately at /team/members.\n\t\tconst orgId = locals.ctx?.actingOrgId;\n\t\tif (orgId) {\n\t\t\tconst joinedAt = new Date().toISOString();\n\t\t\tawait getOrganizationProvider().addOrgMember(SYSTEM_CONTEXT, {\n\t\t\t\torgId,\n\t\t\t\tuserId: user.id,\n\t\t\t\trole: 'member',\n\t\t\t\tpermissions: [],\n\t\t\t\tjoinedAt,\n\t\t\t\tupdatedAt: joinedAt,\n\t\t\t\tupdatedBy: locals.user?.id ?? user.id,\n\t\t\t\tdeletedAt: null\n\t\t\t});\n\t\t}\n\n\t\t// Last, so a refused grant leaves an admitted user the admin can grant again from the list.\n\t\tif (platform.length > 0) {\n\t\t\tconst granted = await setUserPlatformPermissions(locals.ctx!, user.id, platform);\n\t\t\tif (granted !== 'ok') {\n\t\t\t\tapiError(\n\t\t\t\t\t500,\n\t\t\t\t\tApiErrorCode.INTERNAL,\n\t\t\t\t\t`The user was created, but their platform permissions were not granted (${granted}). Grant them from the user list.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn created(user);\n\t}\n);\n"],"mappings":";;;;;;;;;;;;;AA8BA,IAAM,iBAAiB,EAAE,OAAO;CAC/B,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,yBAAyB;CACjD,aAAa,EAAE,MAAM,wBAAwB;AAC9C,CAAC;AAGD,IAAa,MAAsB,SAAS,wBAAwB,OAAO,EAAE,aAAa;CACzF,2BAA2B,MAAM;CACjC,MAAM,OAAO,MAAM,gBAAgB,CAAC,CAAC,UAAU,EAAE,OAAO,IAAI,CAAC;CAC7D,IAAI,SAAS,MACZ,SACC,KACA,aAAa,UACb,oIACD;CAGD,MAAM,QAAQ,OAAO,KAAK;CAC1B,MAAM,OAAO,wBAAwB;CAErC,MAAM,UAAU,KAAK,MAAM,KAAK,MAAM,EAAE,EAAE;CAC1C,MAAM,iBAAiB,MAAM,mBAAmB,CAAC,CAAC,YAAY,OAAO,KAAM,OAAO;CAElF,MAAM,iCAAiB,IAAI,IAAuB;CAClD,IAAI,OACH,KAAK,MAAM,KAAK,MAAM,kBAAkB,MAAM,OAAO,OAAO,GAAG,GAC9D,eAAe,IAAI,EAAE,QAAQ,CAAC;CAEhC,MAAM,QAAQ,KAAK,MAAM,KAAK,MAAM;EACnC,MAAM,SAAS,eAAe,IAAI,EAAE,EAAE;EACtC,OAAO;GACN,GAAG;GACH,qBAAqB,eAAe,IAAI,EAAE,EAAE,KAAK,CAAC;GAClD,SAAS,QAAQ;GACjB,gBAAgB,SAAS,CAAC,GAAG,OAAO,WAAW,IAAI,CAAC;EACrD;CACD,CAAC;CACD,OAAO,KAAK,EAAE,MAAM,CAAC;AACtB,CAAC;AAGD,IAAa,OAAuB,SACnC,yBACA,OAAO,EAAE,SAAS,aAAa;CAC9B,2BAA2B,MAAM;CACjC,MAAM,OAAO,gBAAgB;CAE7B,MAAM,EAAE,OAAO,aAAa,aAAa,MAAM,UAAU,SAAS,cAAc;CAEhF,kCAAkC,OAAO,KAAM,QAAQ;CAEvD,IAAI;CACJ,IAAI,KAAK,YAKR,OAAO,MAAM,KAAK,WAAW,KAAK;MAElC,SACC,KACA,aAAa,UACb,GAAG,KAAK,KAAK,gGACd;CAGD,MAAM,aAAa,CAAC,CAAC,KAAK;EACzB,MAAM;EACN,QAAQ,KAAK;EACb,SAAS,UAAU,OAAO,GAAI;CAC/B,CAAC;CAID,MAAM,gBAAgB,CAAC,CAAC,WAAW,gBAAgB,KAAK,EAAE;CAK1D,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,OAAO;EACV,MAAM,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY;EACxC,MAAM,wBAAwB,CAAC,CAAC,aAAa,gBAAgB;GAC5D;GACA,QAAQ,KAAK;GACb,MAAM;GACN,aAAa,CAAC;GACd;GACA,WAAW;GACX,WAAW,OAAO,MAAM,MAAM,KAAK;GACnC,WAAW;EACZ,CAAC;CACF;CAGA,IAAI,SAAS,SAAS,GAAG;EACxB,MAAM,UAAU,MAAM,2BAA2B,OAAO,KAAM,KAAK,IAAI,QAAQ;EAC/E,IAAI,YAAY,MACf,SACC,KACA,aAAa,UACb,0EAA0E,QAAQ,kCACnF;CAEF;CAEA,OAAO,QAAQ,IAAI;AACpB,CACD"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { B as classifyAssetPath, G as definitionPaths,
|
|
2
|
-
import {
|
|
1
|
+
import { B as classifyAssetPath, G as definitionPaths, x as getStorageProvider } from "../../../../../chunks/providers.server.js";
|
|
2
|
+
import { k as ApiErrorCode, n as accessDepsFromConfig } from "../../../../../chunks/access.js";
|
|
3
3
|
import { t as COVER_IMAGE_CONTENT_TYPES } from "../../../../../chunks/types2.js";
|
|
4
4
|
import { r as GuidSchema } from "../../../../../chunks/schemas.js";
|
|
5
|
+
import { n as getVisibleDefinition } from "../../../../../chunks/visibility.js";
|
|
6
|
+
import "../../../../../chunks/definitions.js";
|
|
5
7
|
import { t as apiError } from "../../../../../chunks/api-errors.js";
|
|
6
|
-
import
|
|
8
|
+
import "../../../../../chunks/access2.server.js";
|
|
7
9
|
// src/routes/api/files/[...path]/+server.ts
|
|
8
10
|
/**
|
|
9
11
|
* Authenticated/public blob proxy. The set of servable paths is the closed
|
|
@@ -14,8 +16,8 @@ import { t as asHttpError } from "../../../../../chunks/access2.server.js";
|
|
|
14
16
|
* - `public` (org branding — logo/favicon): served to anyone, incl.
|
|
15
17
|
* logged-out visitors, with no auth. Cacheable. The bytes are always a
|
|
16
18
|
* rasterized WebP, so there is no XSS surface to gate.
|
|
17
|
-
* - `project` (definition covers):
|
|
18
|
-
*
|
|
19
|
+
* - `project` (definition covers): the caller must be able to view the
|
|
20
|
+
* definition's project, by the same rule as definition reads.
|
|
19
21
|
*
|
|
20
22
|
* Anything that classifies to no asset class 404s. New blob types are opt-in:
|
|
21
23
|
* add a registry entry with the right visibility — never a generic
|
|
@@ -45,9 +47,7 @@ var GET = async ({ params, locals }) => {
|
|
|
45
47
|
const guid = match.scopeId;
|
|
46
48
|
const guidParsed = GuidSchema.safeParse(guid);
|
|
47
49
|
if (!guidParsed.success) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
|
|
48
|
-
|
|
49
|
-
if (!record) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
|
|
50
|
-
await asHttpError(() => requireCanViewProject(scoped(locals), record.projectId));
|
|
50
|
+
if (!await getVisibleDefinition(locals.ctx, guidParsed.data, accessDepsFromConfig(locals.providers))) apiError(404, ApiErrorCode.NOT_FOUND, "File not found");
|
|
51
51
|
canonicalPath = definitionPaths.image(guidParsed.data);
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/files/[...path]/+server.ts"],"sourcesContent":["import type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport {\n\tGuidSchema,\n\tdefinitionPaths,\n\tclassifyAssetPath,\n\tCOVER_IMAGE_CONTENT_TYPES\n} from '@selvajs/platform';\nimport {
|
|
1
|
+
{"version":3,"file":"_server.ts.js","names":[],"sources":["../../../../../../../src/routes/api/files/[...path]/+server.ts"],"sourcesContent":["import type { RequestHandler } from './$types';\nimport { apiError, ApiErrorCode } from '#lib/server/api-errors.js';\nimport {\n\tGuidSchema,\n\tdefinitionPaths,\n\tclassifyAssetPath,\n\tCOVER_IMAGE_CONTENT_TYPES\n} from '@selvajs/platform';\nimport { getVisibleDefinition } from '@selvajs/server/definitions';\nimport { getStorageProvider } from '#lib/server/providers.server.js';\nimport { accessDepsFromConfig } from '#lib/server/access.server.js';\n\n/**\n * Authenticated/public blob proxy. The set of servable paths is the closed\n * asset-class registry (`classifyAssetPath` / `ASSET_CLASSES` in\n * `@selvajs/platform`). Each class declares a visibility; this route maps that\n * visibility to an authorization check:\n *\n * - `public` (org branding — logo/favicon): served to anyone, incl.\n * logged-out visitors, with no auth. Cacheable. The bytes are always a\n * rasterized WebP, so there is no XSS surface to gate.\n * - `project` (definition covers): the caller must be able to view the\n * definition's project, by the same rule as definition reads.\n *\n * Anything that classifies to no asset class 404s. New blob types are opt-in:\n * add a registry entry with the right visibility — never a generic\n * \"is the extension allowed\" fallthrough. Authorization lives here (the route),\n * not in the storage layer, per `IStorageProvider`'s contract.\n *\n * Why a single proxy: with the registry, the route is no longer a\n * pile of per-shape branches — it classifies once and dispatches on visibility,\n * so the cover-only contract that this route used to pin now generalizes\n * without re-opening the M5 hole.\n */\n\n// Content types we set on served blobs. Image types are reused from the\n// canonical `COVER_IMAGE_CONTENT_TYPES` so cover/branding stay in lockstep with\n// the upload validation. Deliberately NO `image/svg+xml`: no\n// registered class serves SVG (branding is always rasterized WebP), and\n// serving raw SVG would reintroduce the XSS surface the transcoder removes.\n// Anything not listed falls back to `application/octet-stream` (download, not\n// inline-render).\nconst CONTENT_TYPE_BY_EXT: Record<string, string> = COVER_IMAGE_CONTENT_TYPES;\n\nfunction contentTypeFor(storagePath: string): string {\n\tconst dot = storagePath.lastIndexOf('.');\n\tconst ext = dot === -1 ? '' : storagePath.slice(dot).toLowerCase();\n\treturn CONTENT_TYPE_BY_EXT[ext] ?? 'application/octet-stream';\n}\n\nexport const GET: RequestHandler = async ({ params, locals }) => {\n\tconst storagePath = params.path;\n\tif (!storagePath) apiError(400, ApiErrorCode.VALIDATION_FAILED, 'Missing path');\n\n\t// 1. Classify against the closed registry. No match → unservable → 404.\n\tconst match = classifyAssetPath(storagePath);\n\tif (!match) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// 2. Authorize per the class's visibility, and resolve the canonical\n\t// storage path to read from. For `project` we re-derive the path from\n\t// `definitionPaths` rather than echoing the request — eliminates any\n\t// chance the matched path resolves to something else after decoding.\n\tlet canonicalPath = storagePath;\n\n\tswitch (match.class.visibility) {\n\t\tcase 'public':\n\t\t\t// No auth — branding is world-readable. The registry's anchored,\n\t\t\t// safe-alphabet pattern is the only gate the path needs.\n\t\t\tbreak;\n\n\t\tcase 'project': {\n\t\t\tif (!locals.ctx) apiError(401, ApiErrorCode.UNAUTHORIZED, 'Unauthorized');\n\t\t\tconst guid = match.scopeId;\n\t\t\tconst guidParsed = GuidSchema.safeParse(guid);\n\t\t\tif (!guidParsed.success) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t\t\t// 404, not 403, for a cover the caller can't view: a 403 would confirm the guid exists.\n\t\t\tconst record = await getVisibleDefinition(\n\t\t\t\tlocals.ctx,\n\t\t\t\tguidParsed.data,\n\t\t\t\taccessDepsFromConfig(locals.providers)\n\t\t\t);\n\t\t\tif (!record) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t\t\tcanonicalPath = definitionPaths.image(guidParsed.data);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 3. Stream the bytes.\n\tconst bytes = await getStorageProvider().get(canonicalPath);\n\tif (!bytes) apiError(404, ApiErrorCode.NOT_FOUND, 'File not found');\n\n\t// Public branding is CDN-cacheable; everything else is per-user private.\n\tconst cacheControl =\n\t\tmatch.class.visibility === 'public' ? 'public, max-age=3600' : 'private, max-age=3600';\n\n\treturn new Response(Buffer.from(bytes), {\n\t\theaders: {\n\t\t\t'Content-Type': contentTypeFor(canonicalPath),\n\t\t\t'Cache-Control': cacheControl\n\t\t}\n\t});\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAM,sBAA8C;AAEpD,SAAS,eAAe,aAA6B;CACpD,MAAM,MAAM,YAAY,YAAY,GAAG;CAEvC,OAAO,oBADK,QAAQ,KAAK,KAAK,YAAY,MAAM,GAAG,CAAC,CAAC,YAAY,MAC9B;AACpC;AAEA,IAAa,MAAsB,OAAO,EAAE,QAAQ,aAAa;CAChE,MAAM,cAAc,OAAO;CAC3B,IAAI,CAAC,aAAa,SAAS,KAAK,aAAa,mBAAmB,cAAc;CAG9E,MAAM,QAAQ,kBAAkB,WAAW;CAC3C,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAMlE,IAAI,gBAAgB;CAEpB,QAAQ,MAAM,MAAM,YAApB;EACC,KAAK,UAGJ;EAED,KAAK,WAAW;GACf,IAAI,CAAC,OAAO,KAAK,SAAS,KAAK,aAAa,cAAc,cAAc;GACxE,MAAM,OAAO,MAAM;GACnB,MAAM,aAAa,WAAW,UAAU,IAAI;GAC5C,IAAI,CAAC,WAAW,SAAS,SAAS,KAAK,aAAa,WAAW,gBAAgB;GAQ/E,IAAI,CAAC,MALgB,qBACpB,OAAO,KACP,WAAW,MACX,qBAAqB,OAAO,SAAS,CACtC,GACa,SAAS,KAAK,aAAa,WAAW,gBAAgB;GAEnE,gBAAgB,gBAAgB,MAAM,WAAW,IAAI;GACrD;EACD;CACD;CAGA,MAAM,QAAQ,MAAM,mBAAmB,CAAC,CAAC,IAAI,aAAa;CAC1D,IAAI,CAAC,OAAO,SAAS,KAAK,aAAa,WAAW,gBAAgB;CAGlE,MAAM,eACL,MAAM,MAAM,eAAe,WAAW,yBAAyB;CAEhE,OAAO,IAAI,SAAS,OAAO,KAAK,KAAK,GAAG,EACvC,SAAS;EACR,gBAAgB,eAAe,aAAa;EAC5C,iBAAiB;CAClB,EACD,CAAC;AACF"}
|
|
@@ -2,7 +2,7 @@ import { k as ApiErrorCode } from "../../../../../chunks/access.js";
|
|
|
2
2
|
import { t as apiError } from "../../../../../chunks/api-errors.js";
|
|
3
3
|
import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../chunks/computeLimits.js";
|
|
4
4
|
import { l as requireMaxBodySize } from "../../../../../chunks/admin-auth.server.js";
|
|
5
|
-
import {
|
|
5
|
+
import { n as tryResolveShareToken } from "../../../../../chunks/resolve.server.js";
|
|
6
6
|
import { n as runSolve, t as mapSolveError } from "../../../../../chunks/solve.server.js";
|
|
7
7
|
// src/routes/api/v1/compute/+server.ts
|
|
8
8
|
var POST = async ({ request, locals, url }) => {
|
|
@@ -3,8 +3,8 @@ import { k as ApiErrorCode } from "../../../../../../../chunks/access.js";
|
|
|
3
3
|
import { C as readIdempotencyKey, H as requireParams, R as parseBody, S as idempotencyCallerId, T as runIdempotent, h as SolveBodySchema, w as requestFingerprint, x as createApiIdempotencyStore } from "../../../../../../../chunks/api.js";
|
|
4
4
|
import { r as withApiRateLimit } from "../../../../../../../chunks/sveltekit.js";
|
|
5
5
|
import { n as handleApiError, t as apiError } from "../../../../../../../chunks/api-errors.js";
|
|
6
|
-
import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../../../chunks/computeLimits.js";
|
|
7
6
|
import { i as requireCaller } from "../../../../../../../chunks/http2.js";
|
|
7
|
+
import { n as COMPUTE_REQUEST_MAX_BYTES } from "../../../../../../../chunks/computeLimits.js";
|
|
8
8
|
import { l as requireMaxBodySize } from "../../../../../../../chunks/admin-auth.server.js";
|
|
9
9
|
import { n as runSolve, t as mapSolveError } from "../../../../../../../chunks/solve.server.js";
|
|
10
10
|
var solveIdempotencyStore = createApiIdempotencyStore(3e5);
|