storybooker 0.19.4 → 0.22.0-canary.0
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/README.md +40 -18
- package/dist/adapters/_internal/queue.d.mts +127 -0
- package/dist/aws-dynamodb.d.mts +22 -0
- package/dist/aws-dynamodb.mjs +118 -0
- package/dist/aws-dynamodb.mjs.map +1 -0
- package/dist/aws-s3.d.mts +20 -0
- package/dist/aws-s3.mjs +96 -0
- package/dist/aws-s3.mjs.map +1 -0
- package/dist/azure-blob-storage.d.mts +20 -0
- package/dist/azure-blob-storage.mjs +126 -0
- package/dist/azure-blob-storage.mjs.map +1 -0
- package/dist/azure-cosmos-db.d.mts +23 -0
- package/dist/azure-cosmos-db.mjs +87 -0
- package/dist/azure-cosmos-db.mjs.map +1 -0
- package/dist/azure-data-tables.d.mts +23 -0
- package/dist/azure-data-tables.mjs +127 -0
- package/dist/azure-data-tables.mjs.map +1 -0
- package/dist/azure-easy-auth.d.mts +50 -0
- package/dist/azure-easy-auth.mjs +88 -0
- package/dist/azure-easy-auth.mjs.map +1 -0
- package/dist/azure-functions.d.mts +62 -0
- package/dist/azure-functions.mjs +147 -0
- package/dist/azure-functions.mjs.map +1 -0
- package/dist/fs.d.mts +37 -0
- package/dist/fs.mjs +240 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/gcp-big-table.d.mts +23 -0
- package/dist/gcp-big-table.mjs +92 -0
- package/dist/gcp-big-table.mjs.map +1 -0
- package/dist/gcp-firestore.d.mts +22 -0
- package/dist/gcp-firestore.mjs +87 -0
- package/dist/gcp-firestore.mjs.map +1 -0
- package/dist/gcp-storage.d.mts +20 -0
- package/dist/gcp-storage.mjs +96 -0
- package/dist/gcp-storage.mjs.map +1 -0
- package/dist/handlers/handle-process-zip.mjs +90 -0
- package/dist/handlers/handle-process-zip.mjs.map +1 -0
- package/dist/handlers/handle-purge.d.mts +12 -0
- package/dist/handlers/handle-purge.mjs +36 -0
- package/dist/handlers/handle-purge.mjs.map +1 -0
- package/dist/handlers/handle-serve-storybook.mjs +94 -0
- package/dist/handlers/handle-serve-storybook.mjs.map +1 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +62 -0
- package/dist/index.mjs.map +1 -0
- package/dist/models/builds-model.mjs +248 -0
- package/dist/models/builds-model.mjs.map +1 -0
- package/dist/models/builds-schema.d.mts +171 -0
- package/dist/models/builds-schema.mjs +67 -0
- package/dist/models/builds-schema.mjs.map +1 -0
- package/dist/models/projects-model.mjs +122 -0
- package/dist/models/projects-model.mjs.map +1 -0
- package/dist/models/projects-schema.d.mts +70 -0
- package/dist/models/projects-schema.mjs +37 -0
- package/dist/models/projects-schema.mjs.map +1 -0
- package/dist/models/tags-model.mjs +110 -0
- package/dist/models/tags-model.mjs.map +1 -0
- package/dist/models/tags-schema.d.mts +76 -0
- package/dist/models/tags-schema.mjs +34 -0
- package/dist/models/tags-schema.mjs.map +1 -0
- package/dist/models/~model.mjs +43 -0
- package/dist/models/~model.mjs.map +1 -0
- package/dist/models/~shared-schema.d.mts +1 -0
- package/dist/models/~shared-schema.mjs +20 -0
- package/dist/models/~shared-schema.mjs.map +1 -0
- package/dist/mysql.d.mts +39 -0
- package/dist/mysql.mjs +151 -0
- package/dist/mysql.mjs.map +1 -0
- package/dist/redis.d.mts +33 -0
- package/dist/redis.mjs +118 -0
- package/dist/redis.mjs.map +1 -0
- package/dist/routers/account-router.mjs +91 -0
- package/dist/routers/account-router.mjs.map +1 -0
- package/dist/routers/builds-router.mjs +347 -0
- package/dist/routers/builds-router.mjs.map +1 -0
- package/dist/routers/projects-router.mjs +236 -0
- package/dist/routers/projects-router.mjs.map +1 -0
- package/dist/routers/root-router.mjs +108 -0
- package/dist/routers/root-router.mjs.map +1 -0
- package/dist/routers/tags-router.mjs +269 -0
- package/dist/routers/tags-router.mjs.map +1 -0
- package/dist/routers/tasks-router.mjs +71 -0
- package/dist/routers/tasks-router.mjs.map +1 -0
- package/dist/urls.d.mts +47 -0
- package/dist/urls.mjs +208 -0
- package/dist/urls.mjs.map +1 -0
- package/dist/utils/adapter-utils.d.mts +14 -0
- package/dist/utils/adapter-utils.mjs +14 -0
- package/dist/utils/adapter-utils.mjs.map +1 -0
- package/dist/utils/auth.mjs +25 -0
- package/dist/utils/auth.mjs.map +1 -0
- package/dist/utils/error.d.mts +21 -0
- package/dist/utils/error.mjs +109 -0
- package/dist/utils/error.mjs.map +1 -0
- package/dist/utils/file-utils.mjs +16 -0
- package/dist/utils/file-utils.mjs.map +1 -0
- package/dist/utils/openapi-utils.mjs +45 -0
- package/dist/utils/openapi-utils.mjs.map +1 -0
- package/dist/utils/request.mjs +35 -0
- package/dist/utils/request.mjs.map +1 -0
- package/dist/utils/response.mjs +24 -0
- package/dist/utils/response.mjs.map +1 -0
- package/dist/utils/store.mjs +54 -0
- package/dist/utils/store.mjs.map +1 -0
- package/dist/utils/ui-utils.mjs +38 -0
- package/dist/utils/ui-utils.mjs.map +1 -0
- package/dist/utils/url-utils.d.mts +10 -0
- package/dist/utils/url-utils.mjs +54 -0
- package/dist/utils/url-utils.mjs.map +1 -0
- package/dist/~internal/adapter/auth.d.mts +123 -0
- package/dist/~internal/adapter/auth.mjs +20 -0
- package/dist/~internal/adapter/auth.mjs.map +1 -0
- package/dist/~internal/adapter/database.d.mts +240 -0
- package/dist/~internal/adapter/database.mjs +63 -0
- package/dist/~internal/adapter/database.mjs.map +1 -0
- package/dist/~internal/adapter/logger.d.mts +34 -0
- package/dist/~internal/adapter/logger.mjs +13 -0
- package/dist/~internal/adapter/logger.mjs.map +1 -0
- package/dist/~internal/adapter/storage.d.mts +208 -0
- package/dist/~internal/adapter/storage.mjs +63 -0
- package/dist/~internal/adapter/storage.mjs.map +1 -0
- package/dist/~internal/adapter/ui.d.mts +109 -0
- package/dist/~internal/adapter/ui.mjs +1 -0
- package/dist/~internal/adapter.d.mts +8 -0
- package/dist/~internal/adapter.mjs +6 -0
- package/dist/~internal/constants.d.mts +24 -0
- package/dist/~internal/constants.mjs +32 -0
- package/dist/~internal/constants.mjs.map +1 -0
- package/dist/~internal/mimes.d.mts +449 -0
- package/dist/~internal/mimes.mjs +454 -0
- package/dist/~internal/mimes.mjs.map +1 -0
- package/dist/~internal/router.d.mts +1651 -0
- package/dist/~internal/router.mjs +39 -0
- package/dist/~internal/router.mjs.map +1 -0
- package/dist/~internal/types.d.mts +77 -0
- package/dist/~internal/types.mjs +1 -0
- package/dist/~internal/utils.d.mts +4 -0
- package/dist/~internal/utils.mjs +5 -0
- package/openapi.json +3162 -0
- package/package.json +148 -27
- package/src/adapters/_internal/auth.ts +135 -0
- package/src/adapters/_internal/database.ts +241 -0
- package/src/adapters/_internal/index.ts +8 -0
- package/src/adapters/_internal/logger.ts +41 -0
- package/src/adapters/_internal/queue.ts +151 -0
- package/src/adapters/_internal/storage.ts +197 -0
- package/src/adapters/_internal/ui.ts +103 -0
- package/src/adapters/aws-dynamodb.ts +201 -0
- package/src/adapters/aws-s3.ts +160 -0
- package/src/adapters/azure-blob-storage.ts +223 -0
- package/src/adapters/azure-cosmos-db.ts +158 -0
- package/src/adapters/azure-data-tables.ts +223 -0
- package/src/adapters/azure-easy-auth.ts +174 -0
- package/src/adapters/azure-functions.ts +242 -0
- package/src/adapters/fs.ts +398 -0
- package/src/adapters/gcp-big-table.ts +157 -0
- package/src/adapters/gcp-firestore.ts +146 -0
- package/src/adapters/gcp-storage.ts +141 -0
- package/src/adapters/mysql.ts +296 -0
- package/src/adapters/redis.ts +242 -0
- package/src/handlers/handle-process-zip.ts +117 -0
- package/src/handlers/handle-purge.ts +65 -0
- package/src/handlers/handle-serve-storybook.ts +101 -0
- package/src/index.ts +81 -16
- package/src/mocks/mock-auth-service.ts +51 -0
- package/src/mocks/mock-store.ts +26 -0
- package/src/models/builds-model.ts +373 -0
- package/src/models/builds-schema.ts +84 -0
- package/src/models/projects-model.ts +177 -0
- package/src/models/projects-schema.ts +69 -0
- package/src/models/tags-model.ts +138 -0
- package/src/models/tags-schema.ts +45 -0
- package/src/models/~model.ts +79 -0
- package/src/models/~shared-schema.ts +14 -0
- package/src/routers/_app-router.ts +57 -0
- package/src/routers/account-router.ts +136 -0
- package/src/routers/builds-router.ts +464 -0
- package/src/routers/projects-router.ts +309 -0
- package/src/routers/root-router.ts +127 -0
- package/src/routers/tags-router.ts +339 -0
- package/src/routers/tasks-router.ts +75 -0
- package/src/types.ts +107 -0
- package/src/urls.ts +327 -0
- package/src/utils/adapter-utils.ts +26 -0
- package/src/utils/auth.test.ts +71 -0
- package/src/utils/auth.ts +39 -0
- package/src/utils/constants.ts +31 -0
- package/src/utils/date-utils.ts +10 -0
- package/src/utils/error.test.ts +86 -0
- package/src/utils/error.ts +140 -0
- package/src/utils/file-utils.test.ts +65 -0
- package/src/utils/file-utils.ts +43 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/mime-utils.ts +457 -0
- package/src/utils/openapi-utils.ts +49 -0
- package/src/utils/request.ts +97 -0
- package/src/utils/response.ts +20 -0
- package/src/utils/store.ts +85 -0
- package/src/utils/story-utils.ts +42 -0
- package/src/utils/text-utils.ts +10 -0
- package/src/utils/ui-utils.ts +57 -0
- package/src/utils/url-utils.ts +113 -0
- package/dist/index.js +0 -554
- package/src/commands/create.ts +0 -263
- package/src/commands/purge.ts +0 -70
- package/src/commands/test.ts +0 -42
- package/src/service-schema.d.ts +0 -2023
- package/src/utils/auth-utils.ts +0 -31
- package/src/utils/pkg-utils.ts +0 -37
- package/src/utils/sb-build.ts +0 -55
- package/src/utils/sb-test.ts +0 -115
- package/src/utils/schema-utils.ts +0 -123
- package/src/utils/stream-utils.ts +0 -72
- package/src/utils/types.ts +0 -4
- package/src/utils/zip.ts +0 -77
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { SERVICE_NAME } from "../~internal/constants.mjs";
|
|
2
|
+
import { mimes } from "../~internal/mimes.mjs";
|
|
3
|
+
import { getStore } from "../utils/store.mjs";
|
|
4
|
+
import { UrlBuilder, urlBuilder } from "../urls.mjs";
|
|
5
|
+
import { authenticateOrThrow } from "../utils/auth.mjs";
|
|
6
|
+
import { checkIsHTMLRequest } from "../utils/request.mjs";
|
|
7
|
+
import { createUIResultResponse } from "../utils/ui-utils.mjs";
|
|
8
|
+
import { ProjectsModel } from "../models/projects-model.mjs";
|
|
9
|
+
import { openapiResponsesHtml } from "../utils/openapi-utils.mjs";
|
|
10
|
+
import { handleServeStoryBook } from "../handlers/handle-serve-storybook.mjs";
|
|
11
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
12
|
+
import { z as z$1 } from "zod";
|
|
13
|
+
|
|
14
|
+
//#region src/routers/root-router.ts
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
const rootRouter = new OpenAPIHono().openapi(createRoute({
|
|
19
|
+
summary: "Homepage",
|
|
20
|
+
method: "get",
|
|
21
|
+
path: "/",
|
|
22
|
+
responses: { 200: {
|
|
23
|
+
content: {
|
|
24
|
+
[mimes.json]: { schema: z$1.object({
|
|
25
|
+
name: z$1.string(),
|
|
26
|
+
adapters: z$1.record(z$1.string(), z$1.object({ name: z$1.string() })),
|
|
27
|
+
config: z$1.record(z$1.string(), z$1.unknown()),
|
|
28
|
+
urls: z$1.record(z$1.string(), z$1.string())
|
|
29
|
+
}) },
|
|
30
|
+
...openapiResponsesHtml
|
|
31
|
+
},
|
|
32
|
+
description: "Render homepage or return a list of endpoint-urls."
|
|
33
|
+
} }
|
|
34
|
+
}), async (context) => {
|
|
35
|
+
const { auth, database, logger, storage, ui, config } = getStore();
|
|
36
|
+
if (ui?.renderHomePage && checkIsHTMLRequest(true)) {
|
|
37
|
+
authenticateOrThrow({
|
|
38
|
+
action: "read",
|
|
39
|
+
resource: "project",
|
|
40
|
+
projectId: void 0
|
|
41
|
+
});
|
|
42
|
+
const projects = await new ProjectsModel().list({ limit: 5 });
|
|
43
|
+
return createUIResultResponse(context, ui.renderHomePage, { projects });
|
|
44
|
+
}
|
|
45
|
+
const urls = {};
|
|
46
|
+
for (const urlKey of Object.getOwnPropertyNames(UrlBuilder.prototype)) {
|
|
47
|
+
const func = urlBuilder[urlKey];
|
|
48
|
+
if (urlKey === "constructor" || typeof func !== "function") continue;
|
|
49
|
+
const keyword = "ARG0REMOVE";
|
|
50
|
+
const url = func.call(urlBuilder, keyword);
|
|
51
|
+
if (url.includes(keyword)) continue;
|
|
52
|
+
urls[urlKey] = url;
|
|
53
|
+
}
|
|
54
|
+
return context.json({
|
|
55
|
+
name: SERVICE_NAME,
|
|
56
|
+
adapters: {
|
|
57
|
+
auth: auth?.metadata,
|
|
58
|
+
database: database.metadata,
|
|
59
|
+
logger: logger.metadata,
|
|
60
|
+
storage: storage.metadata,
|
|
61
|
+
ui: ui?.metadata
|
|
62
|
+
},
|
|
63
|
+
config: {
|
|
64
|
+
...config,
|
|
65
|
+
middlewares: config?.middlewares?.map((mw) => mw.name),
|
|
66
|
+
errorParser: void 0
|
|
67
|
+
},
|
|
68
|
+
urls
|
|
69
|
+
});
|
|
70
|
+
}).openapi(createRoute({
|
|
71
|
+
summary: "Health check",
|
|
72
|
+
method: "get",
|
|
73
|
+
path: "/health",
|
|
74
|
+
responses: { 200: { description: "Health check status" } }
|
|
75
|
+
}), (context) => {
|
|
76
|
+
return context.text("Service is healthy.");
|
|
77
|
+
}).openapi(createRoute({
|
|
78
|
+
summary: "Serve build files",
|
|
79
|
+
method: "get",
|
|
80
|
+
path: "_/{projectId}/{buildId}/{filepath{.+}}",
|
|
81
|
+
request: {
|
|
82
|
+
params: z$1.object({
|
|
83
|
+
projectId: z$1.string(),
|
|
84
|
+
buildId: z$1.string(),
|
|
85
|
+
filepath: z$1.string()
|
|
86
|
+
}),
|
|
87
|
+
query: z$1.object({
|
|
88
|
+
id: z$1.string(),
|
|
89
|
+
path: z$1.string(),
|
|
90
|
+
viewMode: z$1.enum(["story"])
|
|
91
|
+
}).partial()
|
|
92
|
+
},
|
|
93
|
+
responses: { 200: {
|
|
94
|
+
description: "Serving the uploaded file",
|
|
95
|
+
content: { "*/*": { schema: z$1.string() } }
|
|
96
|
+
} }
|
|
97
|
+
}), (context) => {
|
|
98
|
+
const { buildId, filepath, projectId } = context.req.param();
|
|
99
|
+
return handleServeStoryBook({
|
|
100
|
+
buildId,
|
|
101
|
+
filepath,
|
|
102
|
+
projectId
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { rootRouter };
|
|
108
|
+
//# sourceMappingURL=root-router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-router.mjs","names":["z","urls: Record<string, string>"],"sources":["../../src/routers/root-router.ts"],"sourcesContent":["import { createRoute, OpenAPIHono } from \"@hono/zod-openapi\";\nimport { z } from \"zod\";\nimport { handleServeStoryBook } from \"../handlers/handle-serve-storybook.ts\";\nimport { ProjectsModel } from \"../models/projects-model.ts\";\nimport { UrlBuilder, urlBuilder } from \"../urls.ts\";\nimport { authenticateOrThrow } from \"../utils/auth.ts\";\nimport { SERVICE_NAME } from \"../utils/constants.ts\";\nimport { mimes } from \"../utils/mime-utils.ts\";\nimport { openapiResponsesHtml } from \"../utils/openapi-utils.ts\";\nimport { checkIsHTMLRequest } from \"../utils/request.ts\";\nimport { getStore } from \"../utils/store.ts\";\nimport { createUIResultResponse } from \"../utils/ui-utils.ts\";\n\n/**\n * @private\n */\nexport const rootRouter = new OpenAPIHono()\n .openapi(\n createRoute({\n summary: \"Homepage\",\n method: \"get\",\n path: \"/\",\n responses: {\n 200: {\n content: {\n [mimes.json]: {\n schema: z.object({\n name: z.string(),\n adapters: z.record(z.string(), z.object({ name: z.string() })),\n config: z.record(z.string(), z.unknown()),\n urls: z.record(z.string(), z.string()),\n }),\n },\n ...openapiResponsesHtml,\n },\n description: \"Render homepage or return a list of endpoint-urls.\",\n },\n },\n }),\n async (context) => {\n const { auth, database, logger, storage, ui, config } = getStore();\n\n if (ui?.renderHomePage && checkIsHTMLRequest(true)) {\n authenticateOrThrow({ action: \"read\", resource: \"project\", projectId: undefined });\n const projects = await new ProjectsModel().list({ limit: 5 });\n\n return createUIResultResponse(context, ui.renderHomePage, { projects });\n }\n\n const urls: Record<string, string> = {};\n for (const urlKey of Object.getOwnPropertyNames(UrlBuilder.prototype)) {\n const func = urlBuilder[urlKey as keyof UrlBuilder];\n if (urlKey === \"constructor\" || typeof func !== \"function\") {\n continue;\n }\n\n const keyword = \"ARG0REMOVE\";\n const url = (func as (...args: string[]) => string).call(urlBuilder, keyword);\n if (url.includes(keyword)) {\n continue;\n }\n\n urls[urlKey] = url;\n }\n\n return context.json({\n name: SERVICE_NAME,\n adapters: {\n auth: auth?.metadata,\n database: database.metadata,\n logger: logger.metadata,\n storage: storage.metadata,\n ui: ui?.metadata,\n },\n config: {\n ...config,\n middlewares: config?.middlewares?.map((mw) => mw.name),\n errorParser: undefined,\n },\n urls,\n });\n },\n )\n .openapi(\n createRoute({\n summary: \"Health check\",\n method: \"get\",\n path: \"/health\",\n responses: {\n 200: { description: \"Health check status\" },\n },\n }),\n (context) => {\n return context.text(\"Service is healthy.\");\n },\n )\n .openapi(\n createRoute({\n summary: \"Serve build files\",\n method: \"get\",\n path: \"_/{projectId}/{buildId}/{filepath{.+}}\",\n request: {\n params: z.object({\n projectId: z.string(),\n buildId: z.string(),\n filepath: z.string(),\n }),\n query: z\n .object({\n id: z.string(),\n path: z.string(),\n viewMode: z.enum([\"story\"]),\n })\n .partial(),\n },\n responses: {\n 200: {\n description: \"Serving the uploaded file\",\n content: { \"*/*\": { schema: z.string() } },\n },\n },\n }),\n (context) => {\n const { buildId, filepath, projectId } = context.req.param();\n return handleServeStoryBook({ buildId, filepath, projectId });\n },\n );\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,aAAa,IAAI,aAAa,CACxC,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,WAAW,EACT,KAAK;EACH,SAAS;IACN,MAAM,OAAO,EACZ,QAAQA,IAAE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M;CACN,WAAW,EACT,KAAK,EAAE,aAAa,uBAAuB,EAC5C;CACF,CAAC,GACD,YAAY;AACX,QAAO,QAAQ,KAAK,sBAAsB;EAE7C,CACA,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,SAAS;EACP,QAAQD,IAAE,OAAO;GACf,WAAWA,IAAE,QAAQ;GACrB,SAASA,IAAE,QAAQ;GACnB,UAAUA,IAAE,QAAQ;GACrB,CAAC;EACF,OAAOA,IACJ,OAAO;GACN,IAAIA,IAAE,QAAQ;GACd,MAAMA,IAAE,QAAQ;GAChB,UAAUA,IAAE,KAAK,CAAC,QAAQ,CAAC;GAC5B,CAAC,CACD,SAAS;EACb;CACD,WAAW,EACT,KAAK;EACH,aAAa;EACb,SAAS,EAAE,OAAO,EAAE,QAAQA,IAAE,QAAQ,EAAE,EAAE;EAC3C,EACF;CACF,CAAC,GACD,YAAY;CACX,MAAM,EAAE,SAAS,UAAU,cAAc,QAAQ,IAAI,OAAO;AAC5D,QAAO,qBAAqB;EAAE;EAAS;EAAU;EAAW,CAAC;EAEhE"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { TagTypes } from "../~internal/constants.mjs";
|
|
2
|
+
import { mimes } from "../~internal/mimes.mjs";
|
|
3
|
+
import { getStore } from "../utils/store.mjs";
|
|
4
|
+
import { urlBuilder } from "../urls.mjs";
|
|
5
|
+
import { authenticateOrThrow } from "../utils/auth.mjs";
|
|
6
|
+
import { ProjectIdSchema, TagIdSchema } from "../models/~shared-schema.mjs";
|
|
7
|
+
import "../models/projects-schema.mjs";
|
|
8
|
+
import { TagCreateSchema, TagUpdateSchema, TagsGetResultSchema, TagsListResultSchema } from "../models/tags-schema.mjs";
|
|
9
|
+
import { checkIsHTMLRequest } from "../utils/request.mjs";
|
|
10
|
+
import { createUIResultResponse } from "../utils/ui-utils.mjs";
|
|
11
|
+
import { TagsModel } from "../models/tags-model.mjs";
|
|
12
|
+
import { ProjectsModel } from "../models/projects-model.mjs";
|
|
13
|
+
import { BuildsModel } from "../models/builds-model.mjs";
|
|
14
|
+
import { openapiCommonErrorResponses, openapiErrorResponseContent, openapiResponseRedirect, openapiResponsesHtml } from "../utils/openapi-utils.mjs";
|
|
15
|
+
import { HTTPException } from "hono/http-exception";
|
|
16
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
17
|
+
import { z as z$1 } from "zod";
|
|
18
|
+
|
|
19
|
+
//#region src/routers/tags-router.ts
|
|
20
|
+
const tagsTag = "Tags";
|
|
21
|
+
const projectIdPathParams = z$1.object({ projectId: ProjectIdSchema });
|
|
22
|
+
const tagIdPathParams = z$1.object({
|
|
23
|
+
projectId: ProjectIdSchema,
|
|
24
|
+
tagId: TagIdSchema
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
const tagsRouter = new OpenAPIHono().openapi(createRoute({
|
|
30
|
+
summary: "List tags",
|
|
31
|
+
method: "get",
|
|
32
|
+
path: "/projects/{projectId}/tags",
|
|
33
|
+
tags: [tagsTag],
|
|
34
|
+
request: {
|
|
35
|
+
params: projectIdPathParams,
|
|
36
|
+
query: z$1.object({ type: z$1.union([z$1.enum(TagTypes), z$1.literal("")]) }).partial()
|
|
37
|
+
},
|
|
38
|
+
responses: {
|
|
39
|
+
200: {
|
|
40
|
+
description: "A list of tags in the project.",
|
|
41
|
+
content: {
|
|
42
|
+
[mimes.json]: { schema: TagsListResultSchema },
|
|
43
|
+
...openapiResponsesHtml
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
...openapiCommonErrorResponses
|
|
47
|
+
}
|
|
48
|
+
}), async (context) => {
|
|
49
|
+
const { ui } = getStore();
|
|
50
|
+
const { projectId } = context.req.valid("param");
|
|
51
|
+
authenticateOrThrow({
|
|
52
|
+
action: "read",
|
|
53
|
+
projectId,
|
|
54
|
+
resource: "tag"
|
|
55
|
+
});
|
|
56
|
+
const { type } = context.req.valid("query");
|
|
57
|
+
const tags = await new TagsModel(projectId).list();
|
|
58
|
+
const filteredTags = type ? tags.filter((tag) => tag.type === type) : tags;
|
|
59
|
+
if (ui?.renderTagsListPage && checkIsHTMLRequest()) {
|
|
60
|
+
const project = await new ProjectsModel().get(projectId);
|
|
61
|
+
return createUIResultResponse(context, ui.renderTagsListPage, {
|
|
62
|
+
project,
|
|
63
|
+
tags: filteredTags,
|
|
64
|
+
defaultType: type
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return context.json({ tags: filteredTags });
|
|
68
|
+
}).openapi(createRoute({
|
|
69
|
+
summary: "Create tag - UI",
|
|
70
|
+
method: "get",
|
|
71
|
+
path: "/projects/{projectId}/tags/create",
|
|
72
|
+
tags: [tagsTag],
|
|
73
|
+
request: { params: projectIdPathParams },
|
|
74
|
+
responses: {
|
|
75
|
+
200: {
|
|
76
|
+
description: "UI to create tag",
|
|
77
|
+
content: openapiResponsesHtml
|
|
78
|
+
},
|
|
79
|
+
...openapiCommonErrorResponses
|
|
80
|
+
}
|
|
81
|
+
}), async (context) => {
|
|
82
|
+
const { ui } = getStore();
|
|
83
|
+
if (!ui?.renderTagCreatePage) throw new HTTPException(405, { message: "UI not available for this route." });
|
|
84
|
+
const { projectId } = context.req.valid("param");
|
|
85
|
+
authenticateOrThrow({
|
|
86
|
+
action: "create",
|
|
87
|
+
projectId,
|
|
88
|
+
resource: "tag"
|
|
89
|
+
});
|
|
90
|
+
const project = await new ProjectsModel().get(projectId);
|
|
91
|
+
return createUIResultResponse(context, ui.renderTagCreatePage, { project });
|
|
92
|
+
}).openapi(createRoute({
|
|
93
|
+
summary: "Create tag - action",
|
|
94
|
+
method: "post",
|
|
95
|
+
path: "/projects/{projectId}/tags/create",
|
|
96
|
+
tags: [tagsTag],
|
|
97
|
+
request: {
|
|
98
|
+
params: projectIdPathParams,
|
|
99
|
+
body: {
|
|
100
|
+
content: { [mimes.formEncoded]: { schema: TagCreateSchema } },
|
|
101
|
+
required: true
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
responses: {
|
|
105
|
+
201: {
|
|
106
|
+
description: "Tag created successfully",
|
|
107
|
+
content: { [mimes.json]: { schema: TagsGetResultSchema } }
|
|
108
|
+
},
|
|
109
|
+
303: openapiResponseRedirect("Redirect to tag."),
|
|
110
|
+
409: {
|
|
111
|
+
content: openapiErrorResponseContent,
|
|
112
|
+
description: "Tag already exists."
|
|
113
|
+
},
|
|
114
|
+
415: {
|
|
115
|
+
content: openapiErrorResponseContent,
|
|
116
|
+
description: "Unsupported Media Type"
|
|
117
|
+
},
|
|
118
|
+
...openapiCommonErrorResponses
|
|
119
|
+
}
|
|
120
|
+
}), async (context) => {
|
|
121
|
+
const { projectId } = context.req.valid("param");
|
|
122
|
+
if (!await new ProjectsModel().id(projectId).has()) throw new HTTPException(404, { message: `The project '${projectId}' does not exist.` });
|
|
123
|
+
authenticateOrThrow({
|
|
124
|
+
action: "create",
|
|
125
|
+
projectId,
|
|
126
|
+
resource: "tag"
|
|
127
|
+
});
|
|
128
|
+
const data = context.req.valid("form");
|
|
129
|
+
const tag = await new TagsModel(projectId).create(data);
|
|
130
|
+
if (checkIsHTMLRequest(true)) return context.redirect(urlBuilder.tagDetails(projectId, tag.id), 303);
|
|
131
|
+
return context.json({ tag }, 201);
|
|
132
|
+
}).openapi(createRoute({
|
|
133
|
+
summary: "Tag details",
|
|
134
|
+
method: "get",
|
|
135
|
+
path: "/projects/{projectId}/tags/{tagId}",
|
|
136
|
+
tags: [tagsTag],
|
|
137
|
+
request: { params: tagIdPathParams },
|
|
138
|
+
responses: {
|
|
139
|
+
200: {
|
|
140
|
+
description: "Details of the tag",
|
|
141
|
+
content: {
|
|
142
|
+
[mimes.json]: { schema: TagsGetResultSchema },
|
|
143
|
+
...openapiResponsesHtml
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
404: {
|
|
147
|
+
description: "Matching tag not found.",
|
|
148
|
+
content: openapiErrorResponseContent
|
|
149
|
+
},
|
|
150
|
+
...openapiCommonErrorResponses
|
|
151
|
+
}
|
|
152
|
+
}), async (context) => {
|
|
153
|
+
const { ui } = getStore();
|
|
154
|
+
const { projectId, tagId } = context.req.valid("param");
|
|
155
|
+
authenticateOrThrow({
|
|
156
|
+
action: "read",
|
|
157
|
+
projectId,
|
|
158
|
+
resource: "tag"
|
|
159
|
+
});
|
|
160
|
+
const tag = await new TagsModel(projectId).get(tagId);
|
|
161
|
+
if (ui?.renderTagDetailsPage && checkIsHTMLRequest()) {
|
|
162
|
+
const project = await new ProjectsModel().get(projectId);
|
|
163
|
+
const builds = await new BuildsModel(projectId).listByTag(tag.id);
|
|
164
|
+
return createUIResultResponse(context, ui.renderTagDetailsPage, {
|
|
165
|
+
builds,
|
|
166
|
+
project,
|
|
167
|
+
tag
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return context.json({ tag });
|
|
171
|
+
}).openapi(createRoute({
|
|
172
|
+
summary: "Delete tag - action",
|
|
173
|
+
method: "post",
|
|
174
|
+
path: "/projects/{projectId}/tags/{tagId}/delete",
|
|
175
|
+
tags: [tagsTag],
|
|
176
|
+
request: { params: tagIdPathParams },
|
|
177
|
+
responses: {
|
|
178
|
+
204: { description: "Tag deleted successfully." },
|
|
179
|
+
303: openapiResponseRedirect("Redirect to tags list."),
|
|
180
|
+
404: {
|
|
181
|
+
description: "Matching tag not found.",
|
|
182
|
+
content: openapiErrorResponseContent
|
|
183
|
+
},
|
|
184
|
+
...openapiCommonErrorResponses
|
|
185
|
+
}
|
|
186
|
+
}), async (context) => {
|
|
187
|
+
const { projectId, tagId } = context.req.valid("param");
|
|
188
|
+
authenticateOrThrow({
|
|
189
|
+
action: "delete",
|
|
190
|
+
projectId,
|
|
191
|
+
resource: "tag"
|
|
192
|
+
});
|
|
193
|
+
await new TagsModel(projectId).delete(tagId);
|
|
194
|
+
if (checkIsHTMLRequest(true)) return context.redirect(urlBuilder.tagsList(projectId), 303);
|
|
195
|
+
return new Response(null, { status: 204 });
|
|
196
|
+
}).openapi(createRoute({
|
|
197
|
+
summary: "Update tag - UI",
|
|
198
|
+
method: "get",
|
|
199
|
+
path: "/projects/{projectId}/tags/{tagId}/update",
|
|
200
|
+
tags: [tagsTag],
|
|
201
|
+
request: { params: tagIdPathParams },
|
|
202
|
+
responses: {
|
|
203
|
+
200: {
|
|
204
|
+
description: "UI to upload tag",
|
|
205
|
+
content: openapiResponsesHtml
|
|
206
|
+
},
|
|
207
|
+
404: {
|
|
208
|
+
description: "Matching tag not found.",
|
|
209
|
+
content: openapiErrorResponseContent
|
|
210
|
+
},
|
|
211
|
+
...openapiCommonErrorResponses
|
|
212
|
+
}
|
|
213
|
+
}), async (context) => {
|
|
214
|
+
const { ui } = getStore();
|
|
215
|
+
if (!ui?.renderTagUpdatePage) throw new HTTPException(405, { message: "UI not available for this route." });
|
|
216
|
+
const { tagId, projectId } = context.req.valid("param");
|
|
217
|
+
authenticateOrThrow({
|
|
218
|
+
action: "update",
|
|
219
|
+
projectId,
|
|
220
|
+
resource: "tag"
|
|
221
|
+
});
|
|
222
|
+
const tag = await new TagsModel(projectId).get(tagId);
|
|
223
|
+
const project = await new ProjectsModel().get(projectId);
|
|
224
|
+
return createUIResultResponse(context, ui.renderTagUpdatePage, {
|
|
225
|
+
project,
|
|
226
|
+
tag
|
|
227
|
+
});
|
|
228
|
+
}).openapi(createRoute({
|
|
229
|
+
summary: "Update tag - action",
|
|
230
|
+
method: "post",
|
|
231
|
+
path: "/projects/{projectId}/tags/{tagId}/update",
|
|
232
|
+
tags: [tagsTag],
|
|
233
|
+
request: {
|
|
234
|
+
params: tagIdPathParams,
|
|
235
|
+
body: {
|
|
236
|
+
content: { [mimes.formEncoded]: { schema: TagUpdateSchema } },
|
|
237
|
+
required: true
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
responses: {
|
|
241
|
+
202: { description: "Tag updated successfully" },
|
|
242
|
+
303: openapiResponseRedirect("Redirect to tag."),
|
|
243
|
+
404: {
|
|
244
|
+
description: "Matching project or tag not found.",
|
|
245
|
+
content: openapiErrorResponseContent
|
|
246
|
+
},
|
|
247
|
+
415: {
|
|
248
|
+
content: openapiErrorResponseContent,
|
|
249
|
+
description: "Unsupported Media Type"
|
|
250
|
+
},
|
|
251
|
+
...openapiCommonErrorResponses
|
|
252
|
+
}
|
|
253
|
+
}), async (context) => {
|
|
254
|
+
const { tagId, projectId } = context.req.valid("param");
|
|
255
|
+
const tagsModel = new TagsModel(projectId);
|
|
256
|
+
authenticateOrThrow({
|
|
257
|
+
action: "update",
|
|
258
|
+
projectId,
|
|
259
|
+
resource: "tag"
|
|
260
|
+
});
|
|
261
|
+
const data = context.req.valid("form");
|
|
262
|
+
await tagsModel.update(tagId, data);
|
|
263
|
+
if (checkIsHTMLRequest(true)) return context.redirect(urlBuilder.tagDetails(projectId, tagId), 303);
|
|
264
|
+
return new Response(null, { status: 202 });
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
export { tagsRouter };
|
|
269
|
+
//# sourceMappingURL=tags-router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags-router.mjs","names":["z"],"sources":["../../src/routers/tags-router.ts"],"sourcesContent":["import { createRoute, OpenAPIHono } from \"@hono/zod-openapi\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { z } from \"zod\";\nimport { BuildsModel } from \"../models/builds-model.ts\";\nimport { ProjectsModel } from \"../models/projects-model.ts\";\nimport { ProjectIdSchema } from \"../models/projects-schema.ts\";\nimport { TagsModel } from \"../models/tags-model.ts\";\nimport {\n TagCreateSchema,\n TagIdSchema,\n TagsGetResultSchema,\n TagsListResultSchema,\n TagTypes,\n TagUpdateSchema,\n} from \"../models/tags-schema.ts\";\nimport { urlBuilder } from \"../urls.ts\";\nimport { authenticateOrThrow } from \"../utils/auth.ts\";\nimport { mimes } from \"../utils/mime-utils.ts\";\nimport {\n openapiCommonErrorResponses,\n openapiErrorResponseContent,\n openapiResponseRedirect,\n openapiResponsesHtml,\n} from \"../utils/openapi-utils.ts\";\nimport { checkIsHTMLRequest } from \"../utils/request.ts\";\nimport { getStore } from \"../utils/store.ts\";\nimport { createUIResultResponse } from \"../utils/ui-utils.ts\";\n\nconst tagsTag = \"Tags\";\nconst projectIdPathParams = z.object({ projectId: ProjectIdSchema });\nconst tagIdPathParams = z.object({\n projectId: ProjectIdSchema,\n tagId: TagIdSchema,\n});\n\n/**\n * @private\n */\nexport const tagsRouter = new OpenAPIHono()\n .openapi(\n createRoute({\n summary: \"List tags\",\n method: \"get\",\n path: \"/projects/{projectId}/tags\",\n tags: [tagsTag],\n request: {\n params: projectIdPathParams,\n query: z.object({ type: z.union([z.enum(TagTypes), z.literal(\"\")]) }).partial(),\n },\n responses: {\n 200: {\n description: \"A list of tags in the project.\",\n content: {\n [mimes.json]: { schema: TagsListResultSchema },\n ...openapiResponsesHtml,\n },\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { ui } = getStore();\n const { projectId } = context.req.valid(\"param\");\n\n authenticateOrThrow({\n action: \"read\",\n projectId,\n resource: \"tag\",\n });\n\n const { type } = context.req.valid(\"query\");\n const tags = await new TagsModel(projectId).list();\n const filteredTags = type ? tags.filter((tag) => tag.type === type) : tags;\n\n if (ui?.renderTagsListPage && checkIsHTMLRequest()) {\n const project = await new ProjectsModel().get(projectId);\n\n return createUIResultResponse(context, ui.renderTagsListPage, {\n project,\n tags: filteredTags,\n defaultType: type,\n });\n }\n\n return context.json({ tags: filteredTags });\n },\n )\n .openapi(\n createRoute({\n summary: \"Create tag - UI\",\n method: \"get\",\n path: \"/projects/{projectId}/tags/create\",\n tags: [tagsTag],\n request: { params: projectIdPathParams },\n responses: {\n 200: {\n description: \"UI to create tag\",\n content: openapiResponsesHtml,\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { ui } = getStore();\n if (!ui?.renderTagCreatePage) {\n throw new HTTPException(405, { message: \"UI not available for this route.\" });\n }\n\n const { projectId } = context.req.valid(\"param\");\n\n authenticateOrThrow({\n action: \"create\",\n projectId,\n resource: \"tag\",\n });\n\n const project = await new ProjectsModel().get(projectId);\n\n return createUIResultResponse(context, ui.renderTagCreatePage, { project });\n },\n )\n .openapi(\n createRoute({\n summary: \"Create tag - action\",\n method: \"post\",\n path: \"/projects/{projectId}/tags/create\",\n tags: [tagsTag],\n request: {\n params: projectIdPathParams,\n body: {\n content: { [mimes.formEncoded]: { schema: TagCreateSchema } },\n required: true,\n },\n },\n responses: {\n 201: {\n description: \"Tag created successfully\",\n content: { [mimes.json]: { schema: TagsGetResultSchema } },\n },\n 303: openapiResponseRedirect(\"Redirect to tag.\"),\n 409: {\n content: openapiErrorResponseContent,\n description: \"Tag already exists.\",\n },\n 415: {\n content: openapiErrorResponseContent,\n description: \"Unsupported Media Type\",\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { projectId } = context.req.valid(\"param\");\n\n const projectModel = new ProjectsModel().id(projectId);\n if (!(await projectModel.has())) {\n throw new HTTPException(404, { message: `The project '${projectId}' does not exist.` });\n }\n\n authenticateOrThrow({\n action: \"create\",\n projectId,\n resource: \"tag\",\n });\n\n const data = context.req.valid(\"form\");\n const tag = await new TagsModel(projectId).create(data);\n\n if (checkIsHTMLRequest(true)) {\n return context.redirect(urlBuilder.tagDetails(projectId, tag.id), 303);\n }\n\n return context.json({ tag }, 201);\n },\n )\n .openapi(\n createRoute({\n summary: \"Tag details\",\n method: \"get\",\n path: \"/projects/{projectId}/tags/{tagId}\",\n tags: [tagsTag],\n request: { params: tagIdPathParams },\n responses: {\n 200: {\n description: \"Details of the tag\",\n content: {\n [mimes.json]: { schema: TagsGetResultSchema },\n ...openapiResponsesHtml,\n },\n },\n 404: {\n description: \"Matching tag not found.\",\n content: openapiErrorResponseContent,\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { ui } = getStore();\n const { projectId, tagId } = context.req.valid(\"param\");\n\n authenticateOrThrow({\n action: \"read\",\n projectId,\n resource: \"tag\",\n });\n\n const tag = await new TagsModel(projectId).get(tagId);\n\n if (ui?.renderTagDetailsPage && checkIsHTMLRequest()) {\n const project = await new ProjectsModel().get(projectId);\n const builds = await new BuildsModel(projectId).listByTag(tag.id);\n\n return createUIResultResponse(context, ui.renderTagDetailsPage, { builds, project, tag });\n }\n\n return context.json({ tag });\n },\n )\n .openapi(\n createRoute({\n summary: \"Delete tag - action\",\n method: \"post\",\n path: \"/projects/{projectId}/tags/{tagId}/delete\",\n tags: [tagsTag],\n request: { params: tagIdPathParams },\n responses: {\n 204: { description: \"Tag deleted successfully.\" },\n 303: openapiResponseRedirect(\"Redirect to tags list.\"),\n 404: {\n description: \"Matching tag not found.\",\n content: openapiErrorResponseContent,\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { projectId, tagId } = context.req.valid(\"param\");\n authenticateOrThrow({\n action: \"delete\",\n projectId,\n resource: \"tag\",\n });\n\n await new TagsModel(projectId).delete(tagId);\n\n if (checkIsHTMLRequest(true)) {\n return context.redirect(urlBuilder.tagsList(projectId), 303);\n }\n\n return new Response(null, { status: 204 });\n },\n )\n .openapi(\n createRoute({\n summary: \"Update tag - UI\",\n method: \"get\",\n path: \"/projects/{projectId}/tags/{tagId}/update\",\n tags: [tagsTag],\n request: { params: tagIdPathParams },\n responses: {\n 200: {\n description: \"UI to upload tag\",\n content: openapiResponsesHtml,\n },\n 404: {\n description: \"Matching tag not found.\",\n content: openapiErrorResponseContent,\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { ui } = getStore();\n if (!ui?.renderTagUpdatePage) {\n throw new HTTPException(405, { message: \"UI not available for this route.\" });\n }\n\n const { tagId, projectId } = context.req.valid(\"param\");\n\n authenticateOrThrow({\n action: \"update\",\n projectId,\n resource: \"tag\",\n });\n\n const tag = await new TagsModel(projectId).get(tagId);\n const project = await new ProjectsModel().get(projectId);\n\n return createUIResultResponse(context, ui.renderTagUpdatePage, { project, tag });\n },\n )\n .openapi(\n createRoute({\n summary: \"Update tag - action\",\n method: \"post\",\n path: \"/projects/{projectId}/tags/{tagId}/update\",\n tags: [tagsTag],\n request: {\n params: tagIdPathParams,\n body: {\n content: { [mimes.formEncoded]: { schema: TagUpdateSchema } },\n required: true,\n },\n },\n responses: {\n 202: { description: \"Tag updated successfully\" },\n 303: openapiResponseRedirect(\"Redirect to tag.\"),\n 404: {\n description: \"Matching project or tag not found.\",\n content: openapiErrorResponseContent,\n },\n 415: {\n content: openapiErrorResponseContent,\n description: \"Unsupported Media Type\",\n },\n ...openapiCommonErrorResponses,\n },\n }),\n async (context) => {\n const { tagId, projectId } = context.req.valid(\"param\");\n\n const tagsModel = new TagsModel(projectId);\n authenticateOrThrow({\n action: \"update\",\n projectId,\n resource: \"tag\",\n });\n\n const data = context.req.valid(\"form\");\n await tagsModel.update(tagId, data);\n\n if (checkIsHTMLRequest(true)) {\n return context.redirect(urlBuilder.tagDetails(projectId, tagId), 303);\n }\n\n return new Response(null, { status: 202 });\n },\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,MAAM,UAAU;AAChB,MAAM,sBAAsBA,IAAE,OAAO,EAAE,WAAW,iBAAiB,CAAC;AACpE,MAAM,kBAAkBA,IAAE,OAAO;CAC/B,WAAW;CACX,OAAO;CACR,CAAC;;;;AAKF,MAAa,aAAa,IAAI,aAAa,CACxC,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,QAAQ;CACf,SAAS;EACP,QAAQ;EACR,OAAOA,IAAE,OAAO,EAAE,MAAMA,IAAE,MAAM,CAACA,IAAE,KAAK,SAAS,EAAEA,IAAE,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS;EAChF;CACD,WAAW;EACT,KAAK;GACH,aAAa;GACb,SAAS;KACN,MAAM,OAAO,EAAE,QAAQ,sBAAsB;IAC9C,GAAG;IACJ;GACF;EACD,GAAG;EACJ;CACF,CAAC,EACF,OAAO,YAAY;CACjB,MA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oCAAoC,CAAC;CAG/E,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI,MAAM,QAAQ;AAEvD,qBAAoB;EAClB,QAAQ;EACR;EACA,UAAU;EACX,CAAC;CAEF,MAAM,MAAM,MAAM,IAAI,UAAU,UAAU,CAAC,IAAI,MAAM;CACrD,MAAM,UAAU,MAAM,IAAI,eAAe,CAAC,IAAI,UAAU;AAExD,QAAO,uBAAuB,SAAS,GAAG,qBAAqB;EAAE;EAAS;EAAK,CAAC;EAEnF,CACA,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,QAAQ;CACf,SAAS;EACP,QAAQ;EACR,MAAM;GACJ,SAAS,GAAG,MAAM,cAAc,EAAE,QAAQ,iBAAiB,EAAE;GAC7D,UAAU;GACX;EACF;CACD,WAAW;EACT,KAAK,EAAE,aAAa,4BAA4B;EAChD,KAAK,wBAAwB,mBAAmB;EAChD,KAAK;GACH,aAAa;GACb,SAAS;GACV;EACD,KAAK;GACH,SAAS;GACT,aAAa;GACd;EACD,GAAG;EACJ;CACF,CAAC,EACF,OAAO,YAAY;CACjB,MAAM,EAAE,OAAO,cAAc,QAAQ,IAAI,MAAM,QAAQ;CAEvD,MAAM,YAAY,IAAI,UAAU,UAAU;AAC1C,qBAAoB;EAClB,QAAQ;EACR;EACA,UAAU;EACX,CAAC;CAEF,MAAM,OAAO,QAAQ,IAAI,MAAM,OAAO;AACtC,OAAM,UAAU,OAAO,OAAO,KAAK;AAEnC,KAAI,mBAAmB,KAAK,CAC1B,QAAO,QAAQ,SAAS,WAAW,WAAW,WAAW,MAAM,EAAE,IAAI;AAGvE,QAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,CAAC;EAE7C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { buildUploadVariants } from "../~internal/constants.mjs";
|
|
2
|
+
import { handleProcessZip } from "../handlers/handle-process-zip.mjs";
|
|
3
|
+
import { urlBuilder } from "../urls.mjs";
|
|
4
|
+
import { authenticateOrThrow } from "../utils/auth.mjs";
|
|
5
|
+
import "../models/builds-schema.mjs";
|
|
6
|
+
import { checkIsHTMLRequest } from "../utils/request.mjs";
|
|
7
|
+
import { handlePurge } from "../handlers/handle-purge.mjs";
|
|
8
|
+
import { HTTPException } from "hono/http-exception";
|
|
9
|
+
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
10
|
+
|
|
11
|
+
//#region src/routers/tasks-router.ts
|
|
12
|
+
const tasksTag = "Tasks";
|
|
13
|
+
const processZipSearchParams = z.object({
|
|
14
|
+
projectId: z.string(),
|
|
15
|
+
buildId: z.string(),
|
|
16
|
+
variant: z.enum(buildUploadVariants)
|
|
17
|
+
}).loose();
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
const tasksRouter = new OpenAPIHono().openapi(createRoute({
|
|
22
|
+
summary: "Purge outdated builds",
|
|
23
|
+
method: "post",
|
|
24
|
+
path: "/purge",
|
|
25
|
+
tags: [tasksTag],
|
|
26
|
+
request: { query: z.object({ projectId: z.string() }).partial().loose() },
|
|
27
|
+
responses: { 204: { description: "Purge complete" } }
|
|
28
|
+
}), async (context) => {
|
|
29
|
+
const { projectId } = context.req.valid("query");
|
|
30
|
+
authenticateOrThrow({
|
|
31
|
+
action: "update",
|
|
32
|
+
projectId,
|
|
33
|
+
resource: "project"
|
|
34
|
+
});
|
|
35
|
+
authenticateOrThrow({
|
|
36
|
+
action: "delete",
|
|
37
|
+
projectId,
|
|
38
|
+
resource: "build"
|
|
39
|
+
});
|
|
40
|
+
authenticateOrThrow({
|
|
41
|
+
action: "delete",
|
|
42
|
+
projectId,
|
|
43
|
+
resource: "tag"
|
|
44
|
+
});
|
|
45
|
+
await handlePurge({ projectId }, { abortSignal: context.req.raw.signal });
|
|
46
|
+
return new Response(null, { status: 204 });
|
|
47
|
+
}).openapi(createRoute({
|
|
48
|
+
summary: "Process uploaded zip files",
|
|
49
|
+
method: "post",
|
|
50
|
+
path: "/process-zip",
|
|
51
|
+
tags: [tasksTag],
|
|
52
|
+
request: { query: processZipSearchParams },
|
|
53
|
+
responses: { 204: { description: "Request to process zip file accepter" } }
|
|
54
|
+
}), async (context) => {
|
|
55
|
+
const { buildId, projectId, variant } = context.req.valid("query");
|
|
56
|
+
try {
|
|
57
|
+
await handleProcessZip(projectId, buildId, variant);
|
|
58
|
+
if (checkIsHTMLRequest(true)) return context.redirect(urlBuilder.buildDetails(projectId, buildId), 303);
|
|
59
|
+
context.status(204);
|
|
60
|
+
return context.res;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new HTTPException(500, {
|
|
63
|
+
cause: error,
|
|
64
|
+
message: "Failed to process uploaded zip file."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { tasksRouter };
|
|
71
|
+
//# sourceMappingURL=tasks-router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks-router.mjs","names":[],"sources":["../../src/routers/tasks-router.ts"],"sourcesContent":["import { createRoute, OpenAPIHono, z } from \"@hono/zod-openapi\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { handleProcessZip } from \"../handlers/handle-process-zip.ts\";\nimport { handlePurge } from \"../handlers/handle-purge.ts\";\nimport { buildUploadVariants } from \"../models/builds-schema.ts\";\nimport { urlBuilder } from \"../urls.ts\";\nimport { authenticateOrThrow } from \"../utils/auth.ts\";\nimport { checkIsHTMLRequest } from \"../utils/request.ts\";\n\nconst tasksTag = \"Tasks\";\n\nconst processZipSearchParams = z\n .object({\n projectId: z.string(),\n buildId: z.string(),\n variant: z.enum(buildUploadVariants),\n })\n .loose();\n\n/**\n * @private\n */\nexport const tasksRouter = new OpenAPIHono()\n .openapi(\n createRoute({\n summary: \"Purge outdated builds\",\n method: \"post\",\n path: \"/purge\",\n tags: [tasksTag],\n request: { query: z.object({ projectId: z.string() }).partial().loose() },\n responses: { 204: { description: \"Purge complete\" } },\n }),\n async (context) => {\n const { projectId } = context.req.valid(\"query\");\n\n authenticateOrThrow({ action: \"update\", projectId, resource: \"project\" });\n authenticateOrThrow({ action: \"delete\", projectId, resource: \"build\" });\n authenticateOrThrow({ action: \"delete\", projectId, resource: \"tag\" });\n\n await handlePurge({ projectId }, { abortSignal: context.req.raw.signal });\n\n return new Response(null, { status: 204 });\n },\n )\n .openapi(\n createRoute({\n summary: \"Process uploaded zip files\",\n method: \"post\",\n path: \"/process-zip\",\n tags: [tasksTag],\n request: { query: processZipSearchParams },\n responses: {\n 204: { description: \"Request to process zip file accepter\" },\n },\n }),\n async (context) => {\n const { buildId, projectId, variant } = context.req.valid(\"query\");\n\n try {\n await handleProcessZip(projectId, buildId, variant);\n\n if (checkIsHTMLRequest(true)) {\n return context.redirect(urlBuilder.buildDetails(projectId, buildId), 303);\n }\n\n context.status(204);\n return context.res;\n } catch (error) {\n throw new HTTPException(500, {\n cause: error,\n message: \"Failed to process uploaded zip file.\",\n });\n }\n },\n );\n"],"mappings":";;;;;;;;;;;AASA,MAAM,WAAW;AAEjB,MAAM,yBAAyB,EAC5B,OAAO;CACN,WAAW,EAAE,QAAQ;CACrB,SAAS,EAAE,QAAQ;CACnB,SAAS,EAAE,KAAK,oBAAoB;CACrC,CAAC,CACD,OAAO;;;;AAKV,MAAa,cAAc,IAAI,aAAa,CACzC,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,SAAS;CAChB,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE;CACzE,WAAW,EAAE,KAAK,EAAE,aAAa,kBAAkB,EAAE;CACtD,CAAC,EACF,OAAO,YAAY;CACjB,MAAM,EAAE,cAAc,QAAQ,IAAI,MAAM,QAAQ;AAEhD,qBAAoB;EAAE,QAAQ;EAAU;EAAW,UAAU;EAAW,CAAC;AACzE,qBAAoB;EAAE,QAAQ;EAAU;EAAW,UAAU;EAAS,CAAC;AACvE,qBAAoB;EAAE,QAAQ;EAAU;EAAW,UAAU;EAAO,CAAC;AAErE,OAAM,YAAY,EAAE,WAAW,EAAE,EAAE,aAAa,QAAQ,IAAI,IAAI,QAAQ,CAAC;AAEzE,QAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,CAAC;EAE7C,CACA,QACC,YAAY;CACV,SAAS;CACT,QAAQ;CACR,MAAM;CACN,MAAM,CAAC,SAAS;CAChB,SAAS,EAAE,OAAO,wBAAwB;CAC1C,WAAW,EACT,KAAK,EAAE,aAAa,wCAAwC,EAC7D;CACF,CAAC,EACF,OAAO,YAAY;CACjB,MAAM,EAAE,SAAS,WAAW,YAAY,QAAQ,IAAI,MAAM,QAAQ;AAElE,KAAI;AACF,QAAM,iBAAiB,WAAW,SAAS,QAAQ;AAEnD,MAAI,mBAAmB,KAAK,CAC1B,QAAO,QAAQ,SAAS,WAAW,aAAa,WAAW,QAAQ,EAAE,IAAI;AAG3E,UAAQ,OAAO,IAAI;AACnB,SAAO,QAAQ;UACR,OAAO;AACd,QAAM,IAAI,cAAc,KAAK;GAC3B,OAAO;GACP,SAAS;GACV,CAAC;;EAGP"}
|
package/dist/urls.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BuildUploadVariant } from "./models/builds-schema.mjs";
|
|
2
|
+
import { TagVariant } from "./models/tags-schema.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/urls.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* URL builder for the Storybooks router.
|
|
8
|
+
*/
|
|
9
|
+
declare class UrlBuilder {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(useStore: boolean);
|
|
12
|
+
homepage(): string;
|
|
13
|
+
openapi(): string;
|
|
14
|
+
staticFile(filepath: string): string;
|
|
15
|
+
account(): string;
|
|
16
|
+
login(redirect?: string): string;
|
|
17
|
+
logout(): string;
|
|
18
|
+
projectsList(): string;
|
|
19
|
+
projectCreate(): string;
|
|
20
|
+
projectDetails(projectId: string): string;
|
|
21
|
+
projectUpdate(projectId: string): string;
|
|
22
|
+
projectDelete(projectId: string): string;
|
|
23
|
+
buildsList(projectId: string): string;
|
|
24
|
+
buildDetails(projectId: string, buildId: string): string;
|
|
25
|
+
buildCreate(projectId: string, tagId?: string): string;
|
|
26
|
+
buildDelete(projectId: string, buildId: string): string;
|
|
27
|
+
buildUpdate(projectId: string, buildId: string): string;
|
|
28
|
+
buildUpload(projectId: string, buildId: string, variant?: BuildUploadVariant): string;
|
|
29
|
+
tagsList(projectId: string, type?: TagVariant): string;
|
|
30
|
+
tagCreate(projectId: string): string;
|
|
31
|
+
tagDetails(projectId: string, tagId: string): string;
|
|
32
|
+
tagDelete(projectId: string, tagId: string): string;
|
|
33
|
+
tagUpdate(projectId: string, tagId: string): string;
|
|
34
|
+
taskPurge(projectId?: string): string;
|
|
35
|
+
taskProcessZip(projectId: string, buildId: string, variant: BuildUploadVariant): string;
|
|
36
|
+
storybookIndexHtml(projectId: string, buildId: string, storyId?: string): string;
|
|
37
|
+
storybookIFrameHtml(projectId: string, buildId: string, storyId: string): string;
|
|
38
|
+
storybookDownload(projectId: string, buildId: string): string;
|
|
39
|
+
storybookTestReport(projectId: string, buildId: string): string;
|
|
40
|
+
storybookCoverage(projectId: string, buildId: string): string;
|
|
41
|
+
storybookScreenshot(projectId: string, buildId: string, ...filename: string[]): string;
|
|
42
|
+
storybookScreenshotsDownload(projectId: string, buildId: string): string;
|
|
43
|
+
gitHub(gitHubRepo: string, ...pathnames: string[]): string;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { UrlBuilder };
|
|
47
|
+
//# sourceMappingURL=urls.d.mts.map
|