@panneau/protocol 5.0.0-alpha.17 → 5.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/compound.d.ts +20 -0
  2. package/dist/compound.d.ts.map +1 -0
  3. package/dist/compound.js +27 -0
  4. package/dist/compound.js.map +1 -0
  5. package/dist/conformance/index.d.ts.map +1 -1
  6. package/dist/conformance/index.js +94 -0
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/constants.d.ts +5 -0
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/constants.js +6 -1
  11. package/dist/constants.js.map +1 -1
  12. package/dist/index.js +8 -5
  13. package/dist/libraries.d.ts +10 -0
  14. package/dist/libraries.d.ts.map +1 -1
  15. package/dist/libraries.js +8 -1
  16. package/dist/libraries.js.map +1 -1
  17. package/dist/lint.d.ts.map +1 -1
  18. package/dist/lint.js +59 -0
  19. package/dist/lint.js.map +1 -1
  20. package/dist/mock/index.d.ts +28 -1
  21. package/dist/mock/index.d.ts.map +1 -1
  22. package/dist/mock/index.js +65 -6
  23. package/dist/mock/index.js.map +1 -1
  24. package/dist/openapi.d.ts.map +1 -1
  25. package/dist/openapi.js +13 -6
  26. package/dist/openapi.js.map +1 -1
  27. package/dist/rules.d.ts.map +1 -1
  28. package/dist/rules.js +4 -2
  29. package/dist/rules.js.map +1 -1
  30. package/dist/runtime/index.d.ts +3 -1
  31. package/dist/runtime/index.d.ts.map +1 -1
  32. package/dist/runtime/index.js +6 -4
  33. package/dist/schemas/action.d.ts +1 -0
  34. package/dist/schemas/action.d.ts.map +1 -1
  35. package/dist/schemas/action.js +1 -0
  36. package/dist/schemas/action.js.map +1 -1
  37. package/dist/schemas/api.d.ts +15 -0
  38. package/dist/schemas/api.d.ts.map +1 -1
  39. package/dist/schemas/api.js +7 -2
  40. package/dist/schemas/api.js.map +1 -1
  41. package/dist/schemas/common.js +1 -1
  42. package/dist/schemas/common.js.map +1 -1
  43. package/dist/schemas/definition.d.ts +5 -9
  44. package/dist/schemas/definition.d.ts.map +1 -1
  45. package/dist/schemas/definition.js +3 -9
  46. package/dist/schemas/definition.js.map +1 -1
  47. package/dist/schemas/field.js +2 -2
  48. package/dist/schemas/field.js.map +1 -1
  49. package/dist/schemas/index.d.ts +81 -2
  50. package/dist/schemas/index.d.ts.map +1 -1
  51. package/dist/schemas/index.js +11 -3
  52. package/dist/schemas/index.js.map +1 -1
  53. package/dist/schemas/resource.d.ts +1 -0
  54. package/dist/schemas/resource.d.ts.map +1 -1
  55. package/dist/schemas/resource.js +1 -1
  56. package/dist/schemas/resource.js.map +1 -1
  57. package/dist/schemas/widget.d.ts +109 -0
  58. package/dist/schemas/widget.d.ts.map +1 -0
  59. package/dist/schemas/widget.js +74 -0
  60. package/dist/schemas/widget.js.map +1 -0
  61. package/dist/widgets.d.ts +42 -0
  62. package/dist/widgets.d.ts.map +1 -0
  63. package/dist/widgets.js +130 -0
  64. package/dist/widgets.js.map +1 -0
  65. package/package.json +1 -1
  66. package/schema/boot.schema.json +41 -5
  67. package/schema/definition.schema.json +41 -5
  68. package/schema/openapi.json +297 -15
@@ -1 +1 @@
1
- {"version":3,"file":"openapi.js","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport {\n AUTH_PAGE_PATHS,\n CONTEXT_HEADER,\n CONTEXT_PROBLEM_TYPE,\n EMAIL_UNVERIFIED_PROBLEM_TYPE,\n PASSWORD_CONFIRMATION_PROBLEM_TYPE,\n TWO_FACTOR_REQUIRED_PROBLEM_TYPE,\n} from './constants';\nimport { createSchemaRegistry } from './schemas';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport { Theme } from './schemas/theme';\nimport {\n SEARCH_DEFAULT_LIMIT,\n SEARCH_MAX_LENGTH,\n SEARCH_MAX_LIMIT,\n SEARCH_MIN_LENGTH,\n} from './search';\nimport { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from './version';\n\ntype JsonObject = Record<string, unknown>;\n\nconst ref = (id: string): JsonObject => ({ $ref: `#/components/schemas/${id}` });\n\nconst json = (schema: JsonObject): JsonObject => ({ 'application/json': { schema } });\n\nconst ok = (description: string, schema?: JsonObject, headers?: JsonObject): JsonObject => ({\n description,\n ...(schema !== undefined ? { content: json(schema) } : {}),\n ...(headers !== undefined ? { headers } : {}),\n});\n\nconst PROBLEMS: Record<number, string> = {\n 400: 'Bad request, such as a dry run of an action that does not declare `dryRun`.',\n 401: 'Not authenticated.',\n 403: `Not allowed. A value of \\`${CONTEXT_HEADER}\\` that the user can't use is a problem of type \\`${CONTEXT_PROBLEM_TYPE}\\`, with its \\`param\\`. With \\`auth.emailVerification\\`, a user whose email address isn't verified gets a problem of type \\`${EMAIL_UNVERIFIED_PROBLEM_TYPE}\\` on every operation but those of the auth. A user who must have two-factor authentication and hasn't set it up gets a problem of type \\`${TWO_FACTOR_REQUIRED_PROBLEM_TYPE}\\` on every operation but those of the auth and of \\`/account/two-factor\\`.`,\n 404: 'Not found.',\n 409: 'Conflict with a business rule.',\n 412: 'Version conflict: `If-Match` does not match the current version, which is in `current`.',\n 422: 'Invalid values: messages are in `errors`, keyed by dot path.',\n 423: `The password must be confirmed first (\\`POST /auth/password/confirm\\`): a problem of type \\`${PASSWORD_CONFIRMATION_PROBLEM_TYPE}\\`.`,\n 429: 'Too many requests: `Retry-After` gives the seconds to wait.',\n};\n\nfunction problems(...statuses: number[]): JsonObject {\n return Object.fromEntries(\n statuses.map((status) => [\n String(status),\n {\n description: PROBLEMS[status],\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n ]),\n );\n}\n\nconst etag = { ETag: { description: 'The version of the item.', schema: { type: 'string' } } };\n\nconst pathParameter = (name: string, description: string): JsonObject => ({\n name,\n in: 'path',\n required: true,\n description,\n schema: { type: 'string' },\n});\n\nconst queryParameter = (name: string, description: string, schema: JsonObject): JsonObject => ({\n name,\n in: 'query',\n required: false,\n description,\n schema,\n});\n\nconst listParameters = [\n queryParameter('page', 'Page number, from 1.', { type: 'integer', minimum: 1 }),\n queryParameter('perPage', 'Items per page.', { type: 'integer', minimum: 1 }),\n queryParameter(\n 'cursor',\n 'Lists whose `pagination` is `cursor`: the `nextCursor` (or `previousCursor`) of a page, instead of `page`.',\n { type: 'string' },\n ),\n queryParameter('sort', 'Comma-separated fields; a `-` prefix sorts descending.', {\n type: 'string',\n }),\n {\n name: 'filter',\n in: 'query',\n required: false,\n style: 'deepObject',\n explode: true,\n description:\n '`filter[status]=published`; `filter[tags][]=a&filter[tags][]=b` for any of several values; `filter[published_at][from]=2026-01-01&filter[published_at][to]=2026-01-31` for the inclusive bounds of a range filter (`date-range`), without the open end.',\n schema: { type: 'object', additionalProperties: true },\n },\n queryParameter('q', 'Search.', { type: 'string' }),\n queryParameter('fields', 'Comma-separated fields to include in each item.', { type: 'string' }),\n];\n\nconst resource = pathParameter('resource', 'Resource id.');\nconst id = pathParameter('id', 'Item id.');\nconst values = { type: 'object', additionalProperties: true };\n\n/** Component schemas, generated from the protocol's Zod schemas. */\nexport function createComponentSchemas(): Record<string, JsonObject> {\n const { schemas } = z.toJSONSchema(createSchemaRegistry(), {\n io: 'input',\n uri: (schemaId) => `#/components/schemas/${schemaId}`,\n });\n return Object.fromEntries(\n Object.entries(schemas).map(([schemaId, schema]) => {\n const { $schema: _schema, $id: _id, ...rest } = schema as JsonObject;\n return [schemaId, rest];\n }),\n );\n}\n\n/** The JSON Schema of the definition (`GET /definition`). */\nexport function createDefinitionJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/definition.schema.json',\n ...(z.toJSONSchema(Definition, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of a theme, for themes written as JSON files. */\nexport function createThemeJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/theme.schema.json',\n ...(z.toJSONSchema(Theme, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of the boot config, which a server writes in the page of the app. */\nexport function createBootConfigJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/boot.schema.json',\n ...(z.toJSONSchema(BootConfig, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The `Panneau-Context` header, which every operation takes (decision 0045). */\nconst contextHeader: JsonObject = {\n name: CONTEXT_HEADER,\n in: 'header',\n required: false,\n description:\n 'The values of the current context, when the definition has `context`: the format of a query string, in the order of its params (`client=4&contest=12`). Responses vary with it.',\n schema: { type: 'string' },\n};\n\nconst METHODS = ['get', 'post', 'put', 'patch', 'delete'];\n\n/**\n * Adds the `Panneau-Context` header to the parameters of every path, and its `403` problem to\n * every operation that doesn't have one: a value the user can't use is refused everywhere.\n */\nfunction withContextHeader(paths: Record<string, JsonObject>): Record<string, JsonObject> {\n const parameter = { $ref: '#/components/parameters/Context' };\n return Object.fromEntries(\n Object.entries(paths).map(([path, item]) => [\n path,\n {\n ...Object.fromEntries(\n Object.entries(item).map(([key, operation]) => {\n if (!METHODS.includes(key)) {\n return [key, operation];\n }\n const { responses = {}, ...rest } = operation as JsonObject;\n return [\n key,\n {\n ...rest,\n responses: { ...problems(403), ...(responses as JsonObject) },\n },\n ];\n }),\n ),\n parameters: [...((item.parameters as JsonObject[] | undefined) ?? []), parameter],\n },\n ]),\n );\n}\n\n/** The OpenAPI 3.1 document of the Panneau HTTP API. */\nexport function createOpenApiDocument(): JsonObject {\n return {\n openapi: '3.1.0',\n info: {\n title: 'Panneau protocol',\n version: String(PROTOCOL_VERSION),\n description:\n 'The HTTP API between a Panneau frontend and its backend. Paths are relative to `api.baseUrl` of the definition. Authentication is up to the backend (session cookie or bearer token). Errors use `application/problem+json`.',\n },\n paths: withContextHeader({\n '/definition': {\n get: {\n operationId: 'getDefinition',\n summary:\n 'The definition for the current user, in the current locale, and for the values of `Panneau-Context`.',\n responses: {\n 200: ok('The definition.', ref('Definition')),\n ...problems(401, 403),\n },\n },\n },\n '/context/{param}/options': {\n parameters: [pathParameter('param', 'The name of a param of the context.')],\n get: {\n operationId: 'getContextOptions',\n summary:\n 'The choices of a param of the context without inline `options`, for the values of the params before it in `Panneau-Context`.',\n parameters: [queryParameter('q', 'Search terms.', { type: 'string' })],\n responses: {\n 200: ok(\n 'The first choices that match `q`, in the order to show them.',\n ref('ContextOptionsResponse'),\n ),\n ...problems(401, 403, 404),\n },\n },\n },\n '/resources/{resource}': {\n parameters: [resource],\n get: {\n operationId: 'listItems',\n parameters: listParameters,\n responses: {\n 200: ok('A page of items.', ref('ListResponse')),\n // A `cursor` the backend can't read (decision 0039)\n ...problems(401, 403, 404, 422),\n },\n },\n post: {\n operationId: 'createItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 201: ok('The created item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/{id}': {\n parameters: [resource, id],\n get: {\n operationId: 'getItem',\n responses: {\n 200: ok('The item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n },\n },\n patch: {\n operationId: 'updateItem',\n description: 'Partial update: only the values sent are changed.',\n parameters: [\n {\n name: 'If-Match',\n in: 'header',\n required: false,\n description: 'The version the client edited.',\n schema: { type: 'string' },\n },\n ],\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 412, 422),\n },\n },\n delete: {\n operationId: 'deleteItem',\n responses: { 204: ok('Deleted.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/resources/{resource}/{id}/duplicate': {\n parameters: [resource, id],\n post: {\n operationId: 'duplicateItem',\n description:\n 'Copies an item, for the built-in `duplicate` (decision 0040). Allowed on the items whose `abilities.duplicate` is `true`.',\n responses: {\n 201: ok('The copy, a new item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n 409: {\n description:\n 'The copy conflicts with another item, such as a unique value.',\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n },\n },\n },\n '/resources/{resource}/{id}/preview': {\n parameters: [resource, id],\n post: {\n operationId: 'previewItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('A short-lived preview URL.', ref('PreviewResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/resources/{resource}/actions/{action}': {\n parameters: [resource, pathParameter('action', 'Action id.')],\n post: {\n operationId: 'runAction',\n requestBody: {\n required: true,\n content: {\n ...json(ref('ActionRequest')),\n 'multipart/form-data': { schema: ref('ActionRequest') },\n },\n },\n responses: {\n 200: ok('The result.', ref('ActionResult')),\n 202: ok('The action runs in the background.', ref('ActionRunResponse')),\n ...problems(400, 401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/fields/{field}/check': {\n parameters: [resource, pathParameter('field', 'Name of a field with `check`.')],\n post: {\n operationId: 'checkField',\n summary:\n 'Checks a value as it is typed: whether a slug is available, and its URL. With the permission to create, or to update the item `id`.',\n requestBody: { required: true, content: json(ref('FieldCheckRequest')) },\n responses: {\n 200: ok(\n 'What the backend says about the value.',\n ref('FieldCheckResponse'),\n ),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/actions/runs': {\n get: {\n operationId: 'listActionRuns',\n summary: \"The current user's recent runs.\",\n responses: {\n 200: ok('Runs, newest first.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('ActionRun') } },\n }),\n ...problems(401),\n },\n },\n },\n '/actions/runs/{run}': {\n parameters: [pathParameter('run', 'Run id.')],\n get: {\n operationId: 'getActionRun',\n responses: {\n 200: ok('The run.', ref('ActionRunResponse')),\n ...problems(401, 403, 404),\n },\n },\n delete: {\n operationId: 'cancelActionRun',\n responses: { 204: ok('Cancelled.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/uploads/sign': {\n post: {\n operationId: 'signUpload',\n summary:\n \"Signs a request of the browser's S3 client. The first request of a file creates its upload.\",\n requestBody: { required: true, content: json(ref('UploadSignRequest')) },\n responses: {\n 200: ok('The presigned request.', ref('UploadSignResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/uploads/{upload}/complete': {\n parameters: [pathParameter('upload', 'Upload id: `upl_…`.')],\n post: {\n operationId: 'completeUpload',\n summary:\n 'Once the browser completed the upload in storage, checks the object and gives the upload, which values reference.',\n requestBody: {\n required: false,\n content: json({\n type: 'object',\n properties: {\n name: {\n type: 'string',\n description:\n \"The file's name, which the key doesn't keep, since the backend chose it.\",\n },\n },\n }),\n },\n responses: {\n 200: ok('The upload.', ref('UploadResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/auth/session': {\n get: {\n operationId: 'getSession',\n responses: { 200: ok('The current user.', ref('Session')), ...problems(401) },\n },\n },\n '/auth/login': {\n post: {\n operationId: 'login',\n requestBody: {\n required: true,\n content: json({\n description:\n 'An email and a password, or the single secret of `auth.token`.',\n oneOf: [\n {\n type: 'object',\n required: ['email', 'password'],\n properties: {\n email: { type: 'string' },\n password: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n {\n type: 'object',\n required: ['token'],\n properties: {\n token: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n ],\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n 202: ok(\n 'A second factor is required: answer `/auth/two-factor/challenge`.',\n ref('TwoFactorChallenge'),\n ),\n ...problems(422, 429),\n },\n },\n },\n '/auth/logout': {\n post: {\n operationId: 'logout',\n description:\n '`panneau` auth mode. In `external` mode, the browser goes to `auth.logoutUrl` instead.',\n responses: { 204: ok('Logged out.') },\n },\n },\n '/auth/providers/{provider}/redirect': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'redirectToProvider',\n summary:\n \"Starts the login with an OAuth provider of `auth.providers`. The callback is the backend's: it goes to `next`, or to the base path of the app with `authError` when it fails.\",\n parameters: [\n queryParameter(\n 'next',\n 'Where to go after the login: a local path under the base path of the app. Another one is ignored.',\n {\n type: 'string',\n },\n ),\n ],\n responses: {\n 302: { description: 'Redirect to the provider.' },\n ...problems(404),\n },\n },\n },\n '/auth/providers/{provider}/callback': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'providerCallback',\n summary:\n \"Optional: the callback of the provider, when the backend has it here. Its URL is the backend's, registered with the provider; the app never calls it.\",\n responses: {\n 302: {\n description:\n 'To `next`, or to the base path of the app with `authError` when the login failed.',\n },\n ...problems(404),\n },\n },\n },\n '/auth/password/forgot': {\n post: {\n operationId: 'forgotPassword',\n summary: `With \\`auth.passwordReset\\`: emails a link to the page of the app at \\`{basePath}/${AUTH_PAGE_PATHS.resetPassword}?token=…&email=…\\`.`,\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['email'],\n properties: { email: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok(\n \"A reset link was sent, if the address has an account. The answer is the same when it hasn't, or when a link was sent recently.\",\n ),\n ...problems(422, 429),\n },\n },\n },\n '/auth/password/reset': {\n post: {\n operationId: 'resetPassword',\n summary:\n 'With `auth.passwordReset`: sets a new password, with the token and the email of the link. It does not log in.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token', 'email', 'password'],\n properties: {\n token: { type: 'string' },\n email: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: {\n 204: ok('The password was reset.'),\n ...problems(422, 429),\n },\n },\n },\n '/auth/email/verification': {\n post: {\n operationId: 'sendEmailVerification',\n summary: `With \\`auth.emailVerification\\`: emails the current user a link to the page of the app at \\`{basePath}/${AUTH_PAGE_PATHS.verifyEmail}?token=…\\`.`,\n responses: {\n 204: ok('A link was sent, or the address is already verified.'),\n ...problems(401, 429),\n },\n },\n },\n '/auth/email/verify': {\n post: {\n operationId: 'verifyEmail',\n summary:\n 'With `auth.emailVerification`: verifies the address of the token of a link. The user does not need to be logged in.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token'],\n properties: { token: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('The address is verified.'),\n ...problems(422, 429),\n },\n },\n },\n '/auth/two-factor/challenge': {\n post: {\n operationId: 'twoFactorChallenge',\n summary:\n 'Ends a login that answered `202`, with a code of the authenticator app or a recovery code. A login that is no longer pending is a `422`.',\n requestBody: {\n required: true,\n content: json({\n oneOf: [\n {\n type: 'object',\n required: ['code'],\n properties: { code: { type: 'string' } },\n },\n {\n type: 'object',\n required: ['recoveryCode'],\n properties: { recoveryCode: { type: 'string' } },\n },\n ],\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n ...problems(422, 429),\n },\n },\n },\n '/auth/password/confirm': {\n post: {\n operationId: 'confirmPassword',\n summary:\n 'Confirms the password of the current user, for the operations that answer `423`.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['password'],\n properties: { password: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('The password is confirmed.'),\n ...problems(401, 422, 429),\n },\n },\n },\n '/account/two-factor': {\n get: {\n operationId: 'getTwoFactor',\n summary: 'With `auth.twoFactor`: the two-factor authentication of the user.',\n responses: {\n 200: ok('Its status.', ref('TwoFactorStatus')),\n ...problems(401, 403),\n },\n },\n post: {\n operationId: 'enableTwoFactor',\n summary:\n 'Starts setting it up: a new secret, `pending` until `POST /account/two-factor/confirm`.',\n responses: {\n 200: ok(\n 'The secret to add to an authenticator app.',\n ref('TwoFactorSetup'),\n ),\n ...problems(401, 403, 409, 423),\n },\n },\n delete: {\n operationId: 'disableTwoFactor',\n summary: 'Turns it off. A `409` when the backend requires it for the user.',\n responses: {\n 204: ok('Turned off.'),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/account/two-factor/confirm': {\n post: {\n operationId: 'confirmTwoFactor',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['code'],\n properties: { code: { type: 'string' } },\n }),\n },\n responses: {\n 200: ok('Turned on, with its recovery codes.', ref('RecoveryCodes')),\n ...problems(401, 403, 409, 422, 423),\n },\n },\n },\n '/account/two-factor/recovery-codes': {\n post: {\n operationId: 'regenerateRecoveryCodes',\n summary: 'New recovery codes, in place of the old ones.',\n responses: {\n 200: ok('The new codes.', ref('RecoveryCodes')),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/auth/passkeys/options': {\n post: {\n operationId: 'passkeyLoginOptions',\n summary:\n 'With `auth.passkeys`: the options of `navigator.credentials.get()`, for any passkey of the site.',\n responses: {\n 200: ok('The options.', ref('WebAuthnOptions')),\n ...problems(429),\n },\n },\n },\n '/auth/passkeys/login': {\n post: {\n operationId: 'passkeyLogin',\n summary:\n 'Logs in with the credential of a passkey, in the JSON form of the WebAuthn spec. It does not ask for a second factor.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['credential'],\n properties: {\n credential: { type: 'object', additionalProperties: true },\n remember: { type: 'boolean' },\n },\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n ...problems(422, 429),\n },\n },\n },\n '/account/passkeys': {\n get: {\n operationId: 'listPasskeys',\n responses: {\n 200: ok('The passkeys of the current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('Passkey') } },\n }),\n ...problems(401, 403),\n },\n },\n post: {\n operationId: 'addPasskey',\n summary:\n 'Adds a passkey, with the credential of `navigator.credentials.create()` for the options of `POST /account/passkeys/options`.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['name', 'credential'],\n properties: {\n name: { type: 'string' },\n credential: { type: 'object', additionalProperties: true },\n },\n }),\n },\n responses: {\n 201: ok('The passkey.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('Passkey') },\n }),\n ...problems(401, 403, 409, 422, 423),\n },\n },\n },\n '/account/passkeys/options': {\n post: {\n operationId: 'passkeyRegistrationOptions',\n summary:\n \"The options of `navigator.credentials.create()`, for the current user. A `409` for a user who can't have passkeys.\",\n responses: {\n 200: ok('The options.', ref('WebAuthnOptions')),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/account/passkeys/{passkey}': {\n parameters: [pathParameter('passkey', 'The id of the passkey.')],\n delete: {\n operationId: 'deletePasskey',\n responses: {\n 204: ok('Removed.'),\n ...problems(401, 403, 404, 423),\n },\n },\n },\n '/account': {\n get: {\n operationId: 'getAccount',\n summary: 'With `auth.account`: the current user.',\n responses: {\n 200: ok('The current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 403),\n },\n },\n patch: {\n operationId: 'updateAccount',\n summary:\n 'Saves the name and the email of the current user. With `auth.emailVerification`, a new email is unverified, and gets a link.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n properties: { name: { type: 'string' }, email: { type: 'string' } },\n }),\n },\n responses: {\n 200: ok('The updated user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 403, 422),\n },\n },\n },\n '/account/password': {\n put: {\n operationId: 'updatePassword',\n summary: 'Changes the password of the current user, with the current one.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['currentPassword', 'password'],\n properties: {\n currentPassword: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: {\n 204: ok('The password was changed.'),\n ...problems(401, 403, 422, 429),\n },\n },\n },\n '/search': {\n get: {\n operationId: 'search',\n parameters: [\n {\n ...queryParameter('q', 'Search terms, trimmed.', {\n type: 'string',\n minLength: SEARCH_MIN_LENGTH,\n maxLength: SEARCH_MAX_LENGTH,\n }),\n required: true,\n },\n queryParameter('limit', 'Items per resource.', {\n type: 'integer',\n minimum: 1,\n maximum: SEARCH_MAX_LIMIT,\n default: SEARCH_DEFAULT_LIMIT,\n }),\n queryParameter(\n 'resources',\n 'Comma-separated ids of the searchable resources to search. Defaults to every one.',\n { type: 'string' },\n ),\n ],\n responses: {\n 200: ok(\n `Results grouped by resource, in the order of the definition: at most \\`limit\\` items per resource, and ${SEARCH_MAX_LIMIT} in all.`,\n ref('SearchResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/embeds': {\n get: {\n operationId: 'resolveEmbed',\n parameters: [\n {\n ...queryParameter('url', 'The URL to embed.', { type: 'string' }),\n required: true,\n },\n ],\n responses: {\n 200: ok(\n \"The value of an `embed` field for the URL, from its provider's oEmbed.\",\n ref('EmbedResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/dashboard/widgets/{widget}': {\n parameters: [pathParameter('widget', 'Widget id.')],\n get: {\n operationId: 'getWidgetData',\n responses: {\n 200: ok(\"The widget's data. Its shape depends on the widget type.\", {\n type: 'object',\n additionalProperties: true,\n }),\n ...problems(401, 403, 404),\n },\n },\n },\n }),\n components: {\n schemas: createComponentSchemas(),\n parameters: { Context: contextHeader },\n },\n };\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,OAAO,QAA4B,EAAE,MAAM,wBAAwB,KAAK;AAE9E,IAAM,QAAQ,YAAoC,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAEnF,IAAM,MAAM,aAAqB,QAAqB,aAAsC;CACxF;CACA,GAAI,WAAW,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,EAAE,IAAI,CAAC;CACxD,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;AAC/C;AAEA,IAAM,WAAmC;CACrC,KAAK;CACL,KAAK;CACL,KAAK,6BAA6B,eAAe,oDAAoD,qBAAqB,8HAA8H,8BAA8B,4IAA4I,iCAAiC;CACnc,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK,+FAA+F,mCAAmC;CACvI,KAAK;AACT;AAEA,SAAS,SAAS,GAAG,UAAgC;CACjD,OAAO,OAAO,YACV,SAAS,KAAK,WAAW,CACrB,OAAO,MAAM,GACb;EACI,aAAa,SAAS;EACtB,SAAS,GAAG,uBAAuB,EAAE,QAAQ,IAAI,SAAS,EAAE,EAAE;CAClE,CACJ,CAAC,CACL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MACI,GAAG,eAAe,KAAK,0BAA0B;OAC7C,MAAM;OACN,WAAA;OACA,WAAA;MACJ,CAAC;MACD,UAAU;KACd;KACA,eAAe,SAAS,uBAAuB;MAC3C,MAAM;MACN,SAAS;MACT,SAAA;MACA,SAAA;KACJ,CAAC;KACD,eACI,aACA,qFACA,EAAE,MAAM,SAAS,CACrB;IACJ;IACA,WAAW;KACP,KAAK,GACD,qHACA,IAAI,gBAAgB,CACxB;KACA,GAAG,SAAS,KAAK,KAAK,GAAG;IAC7B;GACJ,EACJ;GACA,WAAW,EACP,KAAK;IACD,aAAa;IACb,YAAY,CACR;KACI,GAAG,eAAe,OAAO,qBAAqB,EAAE,MAAM,SAAS,CAAC;KAChE,UAAU;IACd,CACJ;IACA,WAAW;KACP,KAAK,GACD,0EACA,IAAI,eAAe,CACvB;KACA,GAAG,SAAS,KAAK,KAAK,GAAG;IAC7B;GACJ,EACJ;GACA,+BAA+B;IAC3B,YAAY,CAAC,cAAc,UAAU,YAAY,CAAC;IAClD,KAAK;KACD,aAAa;KACb,WAAW;MACP,KAAK,GAAG,4DAA4D;OAChE,MAAM;OACN,sBAAsB;MAC1B,CAAC;MACD,GAAG,SAAS,KAAK,KAAK,GAAG;KAC7B;IACJ;GACJ;EACJ,CAAC;EACD,YAAY;GACR,SAAS,uBAAuB;GAChC,YAAY,EAAE,SAAS,cAAc;EACzC;CACJ;AACJ"}
1
+ {"version":3,"file":"openapi.js","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport {\n AUTH_PAGE_PATHS,\n CONTEXT_HEADER,\n CONTEXT_PROBLEM_TYPE,\n EMAIL_UNVERIFIED_PROBLEM_TYPE,\n PASSWORD_CONFIRMATION_PROBLEM_TYPE,\n TWO_FACTOR_REQUIRED_PROBLEM_TYPE,\n} from './constants';\nimport { createSchemaRegistry } from './schemas';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport { Theme } from './schemas/theme';\nimport {\n SEARCH_DEFAULT_LIMIT,\n SEARCH_MAX_LENGTH,\n SEARCH_MAX_LIMIT,\n SEARCH_MIN_LENGTH,\n} from './search';\nimport { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from './version';\n\ntype JsonObject = Record<string, unknown>;\n\nconst ref = (id: string): JsonObject => ({ $ref: `#/components/schemas/${id}` });\n\nconst json = (schema: JsonObject): JsonObject => ({ 'application/json': { schema } });\n\nconst ok = (description: string, schema?: JsonObject, headers?: JsonObject): JsonObject => ({\n description,\n ...(schema !== undefined ? { content: json(schema) } : {}),\n ...(headers !== undefined ? { headers } : {}),\n});\n\nconst PROBLEMS: Record<number, string> = {\n 400: 'Bad request, such as a dry run of an action that does not declare `dryRun`.',\n 401: 'Not authenticated.',\n 403: `Not allowed. A value of \\`${CONTEXT_HEADER}\\` that the user can't use is a problem of type \\`${CONTEXT_PROBLEM_TYPE}\\`, with its \\`param\\`. With \\`auth.emailVerification\\`, a user whose email address isn't verified gets a problem of type \\`${EMAIL_UNVERIFIED_PROBLEM_TYPE}\\` on every operation but those of the auth. A user who must have two-factor authentication and hasn't set it up gets a problem of type \\`${TWO_FACTOR_REQUIRED_PROBLEM_TYPE}\\` on every operation but those of the auth and of \\`/account/two-factor\\`.`,\n 404: 'Not found.',\n 409: 'Conflict with a business rule.',\n 412: 'Version conflict: `If-Match` does not match the current version, which is in `current`.',\n 422: 'Invalid values: messages are in `errors`, keyed by dot path.',\n 423: `The password must be confirmed first (\\`POST /auth/password/confirm\\`): a problem of type \\`${PASSWORD_CONFIRMATION_PROBLEM_TYPE}\\`.`,\n 429: 'Too many requests: `Retry-After` gives the seconds to wait.',\n 500: 'Server error, such as a widget whose data does not have the shape of its type.',\n};\n\nfunction problems(...statuses: number[]): JsonObject {\n return Object.fromEntries(\n statuses.map((status) => [\n String(status),\n {\n description: PROBLEMS[status],\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n ]),\n );\n}\n\nconst etag = { ETag: { description: 'The version of the item.', schema: { type: 'string' } } };\n\nconst pathParameter = (name: string, description: string): JsonObject => ({\n name,\n in: 'path',\n required: true,\n description,\n schema: { type: 'string' },\n});\n\nconst queryParameter = (name: string, description: string, schema: JsonObject): JsonObject => ({\n name,\n in: 'query',\n required: false,\n description,\n schema,\n});\n\nconst listParameters = [\n queryParameter('page', 'Page number, from 1.', { type: 'integer', minimum: 1 }),\n queryParameter('perPage', 'Items per page.', { type: 'integer', minimum: 1 }),\n queryParameter(\n 'cursor',\n 'Lists whose `pagination` is `cursor`: the `nextCursor` (or `previousCursor`) of a page, instead of `page`.',\n { type: 'string' },\n ),\n queryParameter('sort', 'Comma-separated fields; a `-` prefix sorts descending.', {\n type: 'string',\n }),\n {\n name: 'filter',\n in: 'query',\n required: false,\n style: 'deepObject',\n explode: true,\n description:\n '`filter[status]=published`; `filter[tags][]=a&filter[tags][]=b` for any of several values; `filter[published_at][from]=2026-01-01&filter[published_at][to]=2026-01-31` for the inclusive bounds of a range filter (`date-range`), without the open end.',\n schema: { type: 'object', additionalProperties: true },\n },\n queryParameter('q', 'Search.', { type: 'string' }),\n queryParameter('fields', 'Comma-separated fields to include in each item.', { type: 'string' }),\n];\n\nconst resource = pathParameter('resource', 'Resource id.');\nconst id = pathParameter('id', 'Item id.');\nconst values = { type: 'object', additionalProperties: true };\n\n/** Component schemas, generated from the protocol's Zod schemas. */\nexport function createComponentSchemas(): Record<string, JsonObject> {\n const { schemas } = z.toJSONSchema(createSchemaRegistry(), {\n io: 'input',\n uri: (schemaId) => `#/components/schemas/${schemaId}`,\n });\n return Object.fromEntries(\n Object.entries(schemas).map(([schemaId, schema]) => {\n const { $schema: _schema, $id: _id, ...rest } = schema as JsonObject;\n return [schemaId, rest];\n }),\n );\n}\n\n/** The JSON Schema of the definition (`GET /definition`). */\nexport function createDefinitionJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/definition.schema.json',\n ...(z.toJSONSchema(Definition, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of a theme, for themes written as JSON files. */\nexport function createThemeJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/theme.schema.json',\n ...(z.toJSONSchema(Theme, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The JSON Schema of the boot config, which a server writes in the page of the app. */\nexport function createBootConfigJsonSchema(): JsonObject {\n return {\n $id: 'https://github.com/folkloreinc/panneau-js/blob/v5.x/packages/protocol/schema/boot.schema.json',\n ...(z.toJSONSchema(BootConfig, {\n io: 'input',\n metadata: createSchemaRegistry(),\n }) as JsonObject),\n };\n}\n\n/** The `Panneau-Context` header, which every operation takes (decision 0045). */\nconst contextHeader: JsonObject = {\n name: CONTEXT_HEADER,\n in: 'header',\n required: false,\n description:\n 'The values of the current context, when the definition has `context`: the format of a query string, in the order of its params (`client=4&contest=12`). Responses vary with it.',\n schema: { type: 'string' },\n};\n\nconst METHODS = ['get', 'post', 'put', 'patch', 'delete'];\n\n/**\n * Adds the `Panneau-Context` header to the parameters of every path, and its `403` problem to\n * every operation that doesn't have one: a value the user can't use is refused everywhere.\n */\nfunction withContextHeader(paths: Record<string, JsonObject>): Record<string, JsonObject> {\n const parameter = { $ref: '#/components/parameters/Context' };\n return Object.fromEntries(\n Object.entries(paths).map(([path, item]) => [\n path,\n {\n ...Object.fromEntries(\n Object.entries(item).map(([key, operation]) => {\n if (!METHODS.includes(key)) {\n return [key, operation];\n }\n const { responses = {}, ...rest } = operation as JsonObject;\n return [\n key,\n {\n ...rest,\n responses: { ...problems(403), ...(responses as JsonObject) },\n },\n ];\n }),\n ),\n parameters: [...((item.parameters as JsonObject[] | undefined) ?? []), parameter],\n },\n ]),\n );\n}\n\n/** The OpenAPI 3.1 document of the Panneau HTTP API. */\nexport function createOpenApiDocument(): JsonObject {\n return {\n openapi: '3.1.0',\n info: {\n title: 'Panneau protocol',\n version: String(PROTOCOL_VERSION),\n description:\n 'The HTTP API between a Panneau frontend and its backend. Paths are relative to `api.baseUrl` of the definition. Authentication is up to the backend (session cookie or bearer token). Errors use `application/problem+json`.',\n },\n paths: withContextHeader({\n '/definition': {\n get: {\n operationId: 'getDefinition',\n summary:\n 'The definition for the current user, in the current locale, and for the values of `Panneau-Context`.',\n responses: {\n 200: ok('The definition.', ref('Definition')),\n ...problems(401, 403),\n },\n },\n },\n '/context/{param}/options': {\n parameters: [pathParameter('param', 'The name of a param of the context.')],\n get: {\n operationId: 'getContextOptions',\n summary:\n 'The choices of a param of the context without inline `options`, for the values of the params before it in `Panneau-Context`.',\n parameters: [queryParameter('q', 'Search terms.', { type: 'string' })],\n responses: {\n 200: ok(\n 'The first choices that match `q`, in the order to show them.',\n ref('ContextOptionsResponse'),\n ),\n ...problems(401, 403, 404),\n },\n },\n },\n '/resources/{resource}': {\n parameters: [resource],\n get: {\n operationId: 'listItems',\n parameters: listParameters,\n responses: {\n 200: ok('A page of items.', ref('ListResponse')),\n // A `cursor` the backend can't read (decision 0039)\n ...problems(401, 403, 404, 422),\n },\n },\n post: {\n operationId: 'createItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 201: ok('The created item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/{id}': {\n parameters: [resource, id],\n get: {\n operationId: 'getItem',\n responses: {\n 200: ok('The item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n },\n },\n patch: {\n operationId: 'updateItem',\n description: 'Partial update: only the values sent are changed.',\n parameters: [\n {\n name: 'If-Match',\n in: 'header',\n required: false,\n description: 'The version the client edited.',\n schema: { type: 'string' },\n },\n ],\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('The updated item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404, 409, 412, 422),\n },\n },\n delete: {\n operationId: 'deleteItem',\n responses: { 204: ok('Deleted.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/resources/{resource}/{id}/duplicate': {\n parameters: [resource, id],\n post: {\n operationId: 'duplicateItem',\n description:\n 'Copies an item, for the built-in `duplicate` (decision 0040). Allowed on the items whose `abilities.duplicate` is `true`.',\n responses: {\n 201: ok('The copy, a new item.', ref('ItemResponse'), etag),\n ...problems(401, 403, 404),\n 409: {\n description:\n 'The copy conflicts with another item, such as a unique value.',\n content: { [PROBLEM_CONTENT_TYPE]: { schema: ref('Problem') } },\n },\n },\n },\n },\n '/resources/{resource}/{id}/preview': {\n parameters: [resource, id],\n post: {\n operationId: 'previewItem',\n requestBody: { required: true, content: json(values) },\n responses: {\n 200: ok('A short-lived preview URL.', ref('PreviewResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/resources/{resource}/actions/{action}': {\n parameters: [resource, pathParameter('action', 'Action id.')],\n post: {\n operationId: 'runAction',\n requestBody: {\n required: true,\n content: {\n ...json(ref('ActionRequest')),\n 'multipart/form-data': { schema: ref('ActionRequest') },\n },\n },\n responses: {\n 200: ok('The result.', ref('ActionResult')),\n 202: ok('The action runs in the background.', ref('ActionRunResponse')),\n ...problems(400, 401, 403, 404, 409, 422),\n },\n },\n },\n '/resources/{resource}/fields/{field}/check': {\n parameters: [resource, pathParameter('field', 'Name of a field with `check`.')],\n post: {\n operationId: 'checkField',\n summary:\n 'Checks a value as it is typed: whether a slug is available, and its URL. With the permission to create, or to update the item `id`.',\n requestBody: { required: true, content: json(ref('FieldCheckRequest')) },\n responses: {\n 200: ok(\n 'What the backend says about the value.',\n ref('FieldCheckResponse'),\n ),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/actions/runs': {\n get: {\n operationId: 'listActionRuns',\n summary: \"The current user's recent runs.\",\n responses: {\n 200: ok('Runs, newest first.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('ActionRun') } },\n }),\n ...problems(401),\n },\n },\n },\n '/actions/runs/{run}': {\n parameters: [pathParameter('run', 'Run id.')],\n get: {\n operationId: 'getActionRun',\n responses: {\n 200: ok('The run.', ref('ActionRunResponse')),\n ...problems(401, 403, 404),\n },\n },\n delete: {\n operationId: 'cancelActionRun',\n responses: { 204: ok('Cancelled.'), ...problems(401, 403, 404, 409) },\n },\n },\n '/uploads/sign': {\n post: {\n operationId: 'signUpload',\n summary:\n \"Signs a request of the browser's S3 client. The first request of a file creates its upload.\",\n requestBody: { required: true, content: json(ref('UploadSignRequest')) },\n responses: {\n 200: ok('The presigned request.', ref('UploadSignResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/uploads/{upload}/complete': {\n parameters: [pathParameter('upload', 'Upload id: `upl_…`.')],\n post: {\n operationId: 'completeUpload',\n summary:\n 'Once the browser completed the upload in storage, checks the object and gives the upload, which values reference.',\n requestBody: {\n required: false,\n content: json({\n type: 'object',\n properties: {\n name: {\n type: 'string',\n description:\n \"The file's name, which the key doesn't keep, since the backend chose it.\",\n },\n },\n }),\n },\n responses: {\n 200: ok('The upload.', ref('UploadResponse')),\n ...problems(401, 403, 404, 422),\n },\n },\n },\n '/auth/session': {\n get: {\n operationId: 'getSession',\n responses: { 200: ok('The current user.', ref('Session')), ...problems(401) },\n },\n },\n '/auth/login': {\n post: {\n operationId: 'login',\n requestBody: {\n required: true,\n content: json({\n description:\n 'An email and a password, or the single secret of `auth.token`.',\n oneOf: [\n {\n type: 'object',\n required: ['email', 'password'],\n properties: {\n email: { type: 'string' },\n password: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n {\n type: 'object',\n required: ['token'],\n properties: {\n token: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n ],\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n 202: ok(\n 'A second factor is required: answer `/auth/two-factor/challenge`.',\n ref('TwoFactorChallenge'),\n ),\n ...problems(422, 429),\n },\n },\n },\n '/auth/logout': {\n post: {\n operationId: 'logout',\n description:\n '`panneau` auth mode. In `external` mode, the browser goes to `auth.logoutUrl` instead.',\n responses: { 204: ok('Logged out.') },\n },\n },\n '/auth/providers/{provider}/redirect': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'redirectToProvider',\n summary:\n \"Starts the login with an OAuth provider of `auth.providers`. The callback is the backend's: it goes to `next`, or to the base path of the app with `authError` when it fails.\",\n parameters: [\n queryParameter(\n 'next',\n 'Where to go after the login: a local path under the base path of the app. Another one is ignored.',\n {\n type: 'string',\n },\n ),\n ],\n responses: {\n 302: { description: 'Redirect to the provider.' },\n ...problems(404),\n },\n },\n },\n '/auth/providers/{provider}/callback': {\n parameters: [pathParameter('provider', 'Provider id.')],\n get: {\n operationId: 'providerCallback',\n summary:\n \"Optional: the callback of the provider, when the backend has it here. Its URL is the backend's, registered with the provider; the app never calls it.\",\n responses: {\n 302: {\n description:\n 'To `next`, or to the base path of the app with `authError` when the login failed.',\n },\n ...problems(404),\n },\n },\n },\n '/auth/password/forgot': {\n post: {\n operationId: 'forgotPassword',\n summary: `With \\`auth.passwordReset\\`: emails a link to the page of the app at \\`{basePath}/${AUTH_PAGE_PATHS.resetPassword}?token=…&email=…\\`.`,\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['email'],\n properties: { email: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok(\n \"A reset link was sent, if the address has an account. The answer is the same when it hasn't, or when a link was sent recently.\",\n ),\n ...problems(422, 429),\n },\n },\n },\n '/auth/password/reset': {\n post: {\n operationId: 'resetPassword',\n summary:\n 'With `auth.passwordReset`: sets a new password, with the token and the email of the link. It does not log in.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token', 'email', 'password'],\n properties: {\n token: { type: 'string' },\n email: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: {\n 204: ok('The password was reset.'),\n ...problems(422, 429),\n },\n },\n },\n '/auth/email/verification': {\n post: {\n operationId: 'sendEmailVerification',\n summary: `With \\`auth.emailVerification\\`: emails the current user a link to the page of the app at \\`{basePath}/${AUTH_PAGE_PATHS.verifyEmail}?token=…\\`.`,\n responses: {\n 204: ok('A link was sent, or the address is already verified.'),\n ...problems(401, 429),\n },\n },\n },\n '/auth/email/verify': {\n post: {\n operationId: 'verifyEmail',\n summary:\n 'With `auth.emailVerification`: verifies the address of the token of a link. The user does not need to be logged in.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['token'],\n properties: { token: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('The address is verified.'),\n ...problems(422, 429),\n },\n },\n },\n '/auth/two-factor/challenge': {\n post: {\n operationId: 'twoFactorChallenge',\n summary:\n 'Ends a login that answered `202`, with a code of the authenticator app or a recovery code. A login that is no longer pending is a `422`.',\n requestBody: {\n required: true,\n content: json({\n oneOf: [\n {\n type: 'object',\n required: ['code'],\n properties: { code: { type: 'string' } },\n },\n {\n type: 'object',\n required: ['recoveryCode'],\n properties: { recoveryCode: { type: 'string' } },\n },\n ],\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n ...problems(422, 429),\n },\n },\n },\n '/auth/password/confirm': {\n post: {\n operationId: 'confirmPassword',\n summary:\n 'Confirms the password of the current user, for the operations that answer `423`.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['password'],\n properties: { password: { type: 'string' } },\n }),\n },\n responses: {\n 204: ok('The password is confirmed.'),\n ...problems(401, 422, 429),\n },\n },\n },\n '/account/two-factor': {\n get: {\n operationId: 'getTwoFactor',\n summary: 'With `auth.twoFactor`: the two-factor authentication of the user.',\n responses: {\n 200: ok('Its status.', ref('TwoFactorStatus')),\n ...problems(401, 403),\n },\n },\n post: {\n operationId: 'enableTwoFactor',\n summary:\n 'Starts setting it up: a new secret, `pending` until `POST /account/two-factor/confirm`.',\n responses: {\n 200: ok(\n 'The secret to add to an authenticator app.',\n ref('TwoFactorSetup'),\n ),\n ...problems(401, 403, 409, 423),\n },\n },\n delete: {\n operationId: 'disableTwoFactor',\n summary: 'Turns it off. A `409` when the backend requires it for the user.',\n responses: {\n 204: ok('Turned off.'),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/account/two-factor/confirm': {\n post: {\n operationId: 'confirmTwoFactor',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['code'],\n properties: { code: { type: 'string' } },\n }),\n },\n responses: {\n 200: ok('Turned on, with its recovery codes.', ref('RecoveryCodes')),\n ...problems(401, 403, 409, 422, 423),\n },\n },\n },\n '/account/two-factor/recovery-codes': {\n post: {\n operationId: 'regenerateRecoveryCodes',\n summary: 'New recovery codes, in place of the old ones.',\n responses: {\n 200: ok('The new codes.', ref('RecoveryCodes')),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/auth/passkeys/options': {\n post: {\n operationId: 'passkeyLoginOptions',\n summary:\n 'With `auth.passkeys`: the options of `navigator.credentials.get()`, for any passkey of the site.',\n responses: {\n 200: ok('The options.', ref('WebAuthnOptions')),\n ...problems(429),\n },\n },\n },\n '/auth/passkeys/login': {\n post: {\n operationId: 'passkeyLogin',\n summary:\n 'Logs in with the credential of a passkey, in the JSON form of the WebAuthn spec. It does not ask for a second factor.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['credential'],\n properties: {\n credential: { type: 'object', additionalProperties: true },\n remember: { type: 'boolean' },\n },\n }),\n },\n responses: {\n 200: ok('Logged in.', ref('Session')),\n ...problems(422, 429),\n },\n },\n },\n '/account/passkeys': {\n get: {\n operationId: 'listPasskeys',\n responses: {\n 200: ok('The passkeys of the current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: { type: 'array', items: ref('Passkey') } },\n }),\n ...problems(401, 403),\n },\n },\n post: {\n operationId: 'addPasskey',\n summary:\n 'Adds a passkey, with the credential of `navigator.credentials.create()` for the options of `POST /account/passkeys/options`.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['name', 'credential'],\n properties: {\n name: { type: 'string' },\n credential: { type: 'object', additionalProperties: true },\n },\n }),\n },\n responses: {\n 201: ok('The passkey.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('Passkey') },\n }),\n ...problems(401, 403, 409, 422, 423),\n },\n },\n },\n '/account/passkeys/options': {\n post: {\n operationId: 'passkeyRegistrationOptions',\n summary:\n \"The options of `navigator.credentials.create()`, for the current user. A `409` for a user who can't have passkeys.\",\n responses: {\n 200: ok('The options.', ref('WebAuthnOptions')),\n ...problems(401, 403, 409, 423),\n },\n },\n },\n '/account/passkeys/{passkey}': {\n parameters: [pathParameter('passkey', 'The id of the passkey.')],\n delete: {\n operationId: 'deletePasskey',\n responses: {\n 204: ok('Removed.'),\n ...problems(401, 403, 404, 423),\n },\n },\n },\n '/account': {\n get: {\n operationId: 'getAccount',\n summary: 'With `auth.account`: the current user.',\n responses: {\n 200: ok('The current user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 403),\n },\n },\n patch: {\n operationId: 'updateAccount',\n summary:\n 'Saves the name and the email of the current user. With `auth.emailVerification`, a new email is unverified, and gets a link.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n properties: { name: { type: 'string' }, email: { type: 'string' } },\n }),\n },\n responses: {\n 200: ok('The updated user.', {\n type: 'object',\n required: ['data'],\n properties: { data: ref('User') },\n }),\n ...problems(401, 403, 422),\n },\n },\n },\n '/account/password': {\n put: {\n operationId: 'updatePassword',\n summary: 'Changes the password of the current user, with the current one.',\n requestBody: {\n required: true,\n content: json({\n type: 'object',\n required: ['currentPassword', 'password'],\n properties: {\n currentPassword: { type: 'string' },\n password: { type: 'string' },\n },\n }),\n },\n responses: {\n 204: ok('The password was changed.'),\n ...problems(401, 403, 422, 429),\n },\n },\n },\n '/search': {\n get: {\n operationId: 'search',\n parameters: [\n {\n ...queryParameter('q', 'Search terms, trimmed.', {\n type: 'string',\n minLength: SEARCH_MIN_LENGTH,\n maxLength: SEARCH_MAX_LENGTH,\n }),\n required: true,\n },\n queryParameter('limit', 'Items per resource.', {\n type: 'integer',\n minimum: 1,\n maximum: SEARCH_MAX_LIMIT,\n default: SEARCH_DEFAULT_LIMIT,\n }),\n queryParameter(\n 'resources',\n 'Comma-separated ids of the searchable resources to search. Defaults to every one.',\n { type: 'string' },\n ),\n ],\n responses: {\n 200: ok(\n `Results grouped by resource, in the order of the definition: at most \\`limit\\` items per resource, and ${SEARCH_MAX_LIMIT} in all.`,\n ref('SearchResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/embeds': {\n get: {\n operationId: 'resolveEmbed',\n parameters: [\n {\n ...queryParameter('url', 'The URL to embed.', { type: 'string' }),\n required: true,\n },\n ],\n responses: {\n 200: ok(\n \"The value of an `embed` field for the URL, from its provider's oEmbed.\",\n ref('EmbedResponse'),\n ),\n ...problems(401, 422, 429),\n },\n },\n },\n '/dashboard/widgets/{widget}': {\n parameters: [pathParameter('widget', 'Widget id.')],\n get: {\n operationId: 'getWidgetData',\n description:\n 'The data of a widget of the dashboard of the user, read as the user (decision 0064). The built-in `stat` and `list` on a resource (`settings.resource`) have none: clients read the list of the resource. A widget that is not in the dashboard of the user is a `404`; a `403` hides the widget.',\n responses: {\n 200: ok(\n \"The widget's data, in the shape of its type: `StatWidgetData`, `SeriesWidgetData` and `ListWidgetData` for the built-in types, the plugin's own object for others.\",\n {\n anyOf: [\n ref('StatWidgetData'),\n ref('SeriesWidgetData'),\n ref('ListWidgetData'),\n { type: 'object', additionalProperties: true },\n ],\n },\n ),\n ...problems(401, 403, 404, 500),\n },\n },\n },\n }),\n components: {\n schemas: createComponentSchemas(),\n parameters: { Context: contextHeader },\n },\n };\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,OAAO,QAA4B,EAAE,MAAM,wBAAwB,KAAK;AAE9E,IAAM,QAAQ,YAAoC,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAEnF,IAAM,MAAM,aAAqB,QAAqB,aAAsC;CACxF;CACA,GAAI,WAAW,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,EAAE,IAAI,CAAC;CACxD,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ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oot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAInD,2CAA2C;AAC3C,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAuKD;;;GAGG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,IAAI,EAAE,EACb,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,GAC5B,WAAW,EAAE,CA8Gf;AAuOD;;;;GAIG;AACH,wBAAgB,WAAW,CACvB,MAAM,EAAE,KAAK,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,YAAiB,GAC3B,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAQ/B"}
package/dist/rules.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PORTABLE_RULES } from "./constants.js";
2
2
  import { isCurrencyCode } from "./currencies.js";
3
3
  import { getAddressRequiredParts, isPostalCode } from "./addresses.js";
4
+ import { getNestedShape } from "./compound.js";
4
5
  import { getValue, isFilled, isRecord } from "./values.js";
5
6
  import { evaluateCondition } from "./conditions.js";
6
7
  import { getLinkTypes } from "./links.js";
@@ -317,8 +318,9 @@ function checkFieldValue(field, value, path, context) {
317
318
  }
318
319
  addFailures(context, path, checkRules(rules, value, context.root, context.mode));
319
320
  checkParts(field, value, path, context);
320
- if (field.type === "group" && field.fields !== void 0 && isRecord(value)) checkFields(field.fields, value, `${path}.`, context);
321
- if (field.type === "repeater" && Array.isArray(value)) value.forEach((item, index) => {
321
+ const shape = getNestedShape(field);
322
+ if (shape === "group" && field.fields !== void 0 && isRecord(value)) checkFields(field.fields, value, `${path}.`, context);
323
+ if (shape === "repeater" && Array.isArray(value)) value.forEach((item, index) => {
322
324
  if (!isRecord(item)) return;
323
325
  const blockFields = field.types !== void 0 ? field.types.find((type) => type.id === item.type)?.fields : field.fields;
324
326
  if (blockFields !== void 0) checkFields(blockFields, item, `${path}.${index}.`, context);
package/dist/rules.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","names":[],"sources":["../src/rules.ts"],"sourcesContent":["import { getAddressRequiredParts, isPostalCode } from './addresses';\nimport { evaluateCondition } from './conditions';\nimport { PORTABLE_RULES } from './constants';\nimport { isCurrencyCode } from './currencies';\nimport { getLinkTypes } from './links';\nimport type { Field, Rule } from './schemas/field';\nimport { matchesRatio, renderedCropSize } from './transforms';\nimport { getValue, isFilled, isRecord } from './values';\n\n/** A rule that a value doesn't satisfy. */\nexport interface RuleFailure {\n rule: string;\n /**\n * The rule's parameter (`max: 120` gives `120`). For `daterange`, what fails: `start` or `end`\n * (a bound missing where the range isn't open), or `order` (the end is before the start).\n */\n value?: unknown;\n /** The message set on the rule, if any. */\n message?: string;\n}\n\nexport interface CheckOptions {\n /**\n * Locales a `required` localized field must be filled in. Without it, one filled locale is\n * enough.\n */\n locales?: string[];\n /** `create` skips `updateOnly` fields; `update` skips `createOnly` fields. */\n mode?: 'create' | 'update';\n /** Only check the fields present in the values (partial updates). */\n partial?: boolean;\n /**\n * The values of the item being updated. With `partial`, conditions (`visibleWhen`) and rules\n * that read other fields read them for the fields that aren't in the values: a field shown\n * when `status` is `published`, sent alone, is checked on a published item (decision 0043).\n */\n item?: Record<string, unknown>;\n}\n\ninterface Context extends CheckOptions {\n /** The whole form, for `visibleWhen` and date rules that reference other fields. */\n root: Record<string, unknown>;\n failures: Record<string, RuleFailure[]>;\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n/** An international phone number in E.164: `+`, then 7 to 15 digits, without a leading zero. */\nconst TEL = /^\\+[1-9]\\d{6,14}$/;\n/** The same number, with an optional extension after `;ext=` (RFC 3966): `+15145550199;ext=123`. */\nconst TEL_EXTENSION = /^\\+[1-9]\\d{6,14}(?:;ext=\\d{1,10})?$/;\n\nfunction isKnownRule(rule: Rule): boolean {\n return (PORTABLE_RULES as readonly string[]).includes(rule.rule);\n}\n\n/**\n * Whether a rule applies in a mode: a rule with a `mode` applies only in that mode, and not when the\n * mode isn't known.\n */\nfunction appliesIn(rule: Rule, mode: CheckOptions['mode']): boolean {\n return rule.mode === undefined || rule.mode === mode;\n}\n\nfunction failure(rule: Rule): RuleFailure {\n const result: RuleFailure = { rule: rule.rule };\n if ('value' in rule && rule.value !== undefined) {\n result.value = rule.value;\n }\n if (rule.message !== undefined) {\n result.message = rule.message;\n }\n return result;\n}\n\nfunction sizeOf(value: unknown): number | null {\n if (typeof value === 'number') {\n return value;\n }\n // A `money` value: `min` and `max` apply to its amount, in minor units (decision 0053).\n if (isRecord(value) && 'currency' in value && typeof value.amount === 'number') {\n return value.amount;\n }\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length;\n }\n return null;\n}\n\nfunction matchesMime(mime: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n if (pattern.endsWith('/*')) {\n return mime.startsWith(pattern.slice(0, -1));\n }\n return mime === pattern;\n });\n}\n\n/** The files of a value, with their MIME type and size: stored files, or chosen ones (`File`). */\nfunction mediaList(value: unknown): Record<string, unknown>[] {\n const list = Array.isArray(value) ? value : [value];\n return list\n .filter(isRecord)\n .map((media) =>\n typeof Blob !== 'undefined' && media instanceof Blob\n ? { mime: media.type === '' ? undefined : media.type, size: media.size }\n : media,\n );\n}\n\n/**\n * Whether each image of a value has the crop the `crop` rule asks for (decision 0031): a crop when\n * it is required, and one of the ratios once rendered. An id alone has no crop.\n */\nfunction hasCrop(value: unknown, rule: { ratios?: string[]; required?: boolean }): boolean {\n const entries = Array.isArray(value) ? value : [value];\n return entries.every((entry) => {\n const transform = isRecord(entry) && isRecord(entry.transform) ? entry.transform : {};\n const size = renderedCropSize(transform);\n if (size === null) {\n return rule.required !== true;\n }\n const ratios = rule.ratios ?? [];\n return (\n ratios.length === 0 ||\n ratios.some((ratio) => matchesRatio(size.width, size.height, ratio))\n );\n });\n}\n\n/**\n * Whether an `embed` value comes from one of the providers, compared without case (decision 0058).\n * A value without a `provider` (an app without `GET /embeds`) is left to the backend.\n */\nfunction hasProvider(value: unknown, providers: readonly string[]): boolean {\n if (!isRecord(value) || typeof value.provider !== 'string') {\n return true;\n }\n const provider = value.provider.toLowerCase();\n return providers.some(\n (allowed) => typeof allowed === 'string' && allowed.toLowerCase() === provider,\n );\n}\n\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst DATE_TIME = /^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}/;\n\n/** A bound of a `daterange`: a day or a date-time, `null` when empty, `undefined` when invalid. */\nfunction rangeBound(value: unknown): string | null | undefined {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n if (typeof value !== 'string' || !(DAY.test(value) || DATE_TIME.test(value))) {\n return undefined;\n }\n return toTime(value) !== null ? value : undefined;\n}\n\n/**\n * What a `daterange` value fails (decision 0053): a bound that is missing or invalid where the range\n * isn't open (`start`, `end`), or an end before the start (`order`). `null` when it is valid.\n */\nfunction checkDateRange(value: unknown, open: unknown): 'start' | 'end' | 'order' | null {\n if (!isRecord(value)) {\n return 'start';\n }\n const start = rangeBound(value.start);\n const end = rangeBound(value.end);\n const openStart = open === 'start' || open === 'both';\n const openEnd = open === 'end' || open === 'both';\n if (start === undefined || (start === null && !openStart)) {\n return 'start';\n }\n if (end === undefined || (end === null && !openEnd)) {\n return 'end';\n }\n if (start === null || end === null) {\n return null;\n }\n // Days compare as days; a date-time compares as its instant.\n const before =\n DAY.test(start) && DAY.test(end)\n ? end < start\n : (toTime(end) as number) < (toTime(start) as number);\n return before ? 'order' : null;\n}\n\n/** Whether a `money` value has an integer amount, and a currency that the rule allows. */\nfunction isMoney(value: unknown, currencies: unknown): boolean {\n if (!isRecord(value) || !Number.isSafeInteger(value.amount)) {\n return false;\n }\n return Array.isArray(currencies) && currencies.length > 0\n ? currencies.includes(value.currency)\n : isCurrencyCode(value.currency);\n}\n\nfunction toTime(value: unknown): number | null {\n if (typeof value !== 'string' && typeof value !== 'number') {\n return null;\n }\n const time = new Date(value).getTime();\n return Number.isNaN(time) ? null : time;\n}\n\n/**\n * Checks one value against a field's rules. Returns the rules that fail. Rules limited to a `mode`\n * only apply when it is given.\n */\nexport function checkRules(\n rules: Rule[],\n value: unknown,\n root: Record<string, unknown> = {},\n mode?: CheckOptions['mode'],\n): RuleFailure[] {\n const failures: RuleFailure[] = [];\n const filled = isFilled(value);\n const applying = rules.filter((rule) => isKnownRule(rule) && appliesIn(rule, mode));\n applying.forEach((rule) => {\n if (rule.rule === 'required') {\n if (!filled) {\n failures.push(failure(rule));\n }\n return;\n }\n if (!filled) {\n return;\n }\n let valid = true;\n // What fails, when the rule says more than its parameter (`daterange`).\n let detail: string | null = null;\n switch (rule.rule) {\n case 'min':\n case 'max': {\n const size = sizeOf(value);\n const limit = rule.value as number;\n valid = size === null || (rule.rule === 'min' ? size >= limit : size <= limit);\n break;\n }\n case 'pattern':\n valid =\n typeof value !== 'string' ||\n new RegExp(rule.value as string, (rule as { flags?: string }).flags).test(\n value,\n );\n break;\n case 'email':\n valid = typeof value !== 'string' || EMAIL.test(value);\n break;\n case 'url':\n valid = typeof value !== 'string' || URL.canParse(value);\n break;\n case 'json':\n // Text that doesn't parse stays a string in the form: only objects and arrays pass\n valid = isRecord(value) || Array.isArray(value);\n break;\n case 'tel':\n valid =\n typeof value !== 'string' ||\n ((rule as { extension?: boolean }).extension === true\n ? TEL_EXTENSION\n : TEL\n ).test(value);\n break;\n case 'postalCode': {\n // The country is a code, or another field of the form (decision 0054)\n const country = isRecord(rule.value)\n ? getValue(root, String(rule.value.field))\n : rule.value;\n valid =\n typeof value !== 'string' ||\n isPostalCode(value, typeof country === 'string' ? country : null);\n break;\n }\n case 'daterange':\n detail = checkDateRange(value, (rule as { open?: unknown }).open);\n valid = detail === null;\n break;\n case 'money':\n valid = isMoney(value, (rule as { currencies?: unknown }).currencies);\n break;\n case 'in': {\n const allowed = rule.value as unknown[];\n const values = Array.isArray(value) ? value : [value];\n valid = values.every((item) => allowed.includes(item));\n break;\n }\n case 'accept':\n valid = mediaList(value).every(\n (media) =>\n typeof media.mime !== 'string' ||\n matchesMime(media.mime, rule.value as string[]),\n );\n break;\n case 'maxSize':\n valid = mediaList(value).every(\n (media) =>\n typeof media.size !== 'number' || media.size <= (rule.value as number),\n );\n break;\n case 'crop':\n valid = !isRecord(rule.value) || hasCrop(value, rule.value);\n break;\n case 'providers':\n valid = hasProvider(value, rule.value as string[]);\n break;\n case 'before':\n case 'after': {\n const bound = rule.value as string | { field: string };\n const boundTime = toTime(\n typeof bound === 'string' ? bound : getValue(root, bound.field),\n );\n const time = toTime(value);\n if (boundTime !== null && time !== null) {\n valid = rule.rule === 'before' ? time < boundTime : time > boundTime;\n }\n break;\n }\n }\n if (!valid) {\n failures.push(detail !== null ? { ...failure(rule), value: detail } : failure(rule));\n }\n });\n return failures;\n}\n\nfunction addFailures(context: Context, path: string, failures: RuleFailure[]) {\n if (failures.length > 0) {\n context.failures[path] = [...(context.failures[path] ?? []), ...failures];\n }\n}\n\n/** A string setting of a field. */\nfunction stringSetting(field: Field, key: string): string | undefined {\n const value = field.settings?.[key];\n return typeof value === 'string' && value !== '' ? value : undefined;\n}\n\n/**\n * The rule each type implies: its values are checked whatever rules the field lists. `tel`,\n * `daterange` and `money` carry settings of their field: the extension, the open bounds, the\n * allowed currencies.\n */\nconst IMPLIED_RULES: Readonly<Record<string, (field: Field) => Rule>> = {\n json: () => ({ rule: 'json' }),\n tel: (field) =>\n field.settings?.extension === true ? { rule: 'tel', extension: true } : { rule: 'tel' },\n daterange: (field) => {\n const open = stringSetting(field, 'open');\n return { rule: 'daterange', ...(open !== undefined ? { open } : {}) } as Rule;\n },\n money: (field) => {\n const currency = stringSetting(field, 'currency');\n const listed = field.settings?.currencies;\n const currencies =\n currency !== undefined\n ? [currency]\n : Array.isArray(listed)\n ? listed.filter((code): code is string => typeof code === 'string')\n : [];\n return { rule: 'money', ...(currencies.length > 0 ? { currencies } : {}) } as Rule;\n },\n};\n\n/**\n * The rules of a field that apply in the mode, with the one its type implies: `json` for the\n * `json` type, `tel` for `tel`, `daterange` for `daterange` and `money` for `money`. A rule of\n * the same name on the field wins.\n */\nfunction rulesOf(field: Field, mode: CheckOptions['mode']): Rule[] {\n const rules = (field.rules ?? []).filter((rule) => appliesIn(rule, mode));\n const implied = IMPLIED_RULES[field.type]?.(field);\n return implied !== undefined && !rules.some((rule) => rule.rule === implied.rule)\n ? [...rules, implied]\n : rules;\n}\n\n/** The parts that make an address filled: a country or a point alone don't. */\nconst ADDRESS_TEXT_PARTS = ['street', 'unit', 'city', 'region', 'postalCode'] as const;\n\n/**\n * The checks of the parts of an `address` (decision 0054): a filled address, with a part other\n * than its country, has its required parts, and a postal code of its country.\n */\nfunction checkAddress(field: Field, value: unknown, path: string, context: Context) {\n if (!isRecord(value) || !ADDRESS_TEXT_PARTS.some((part) => isFilled(value[part]))) {\n return;\n }\n getAddressRequiredParts(field).forEach((part) => {\n if (!isFilled(value[part])) {\n addFailures(context, `${path}.${part}`, [{ rule: 'required' }]);\n }\n });\n const { postalCode, country } = value;\n if (\n typeof postalCode === 'string' &&\n isFilled(postalCode) &&\n !isPostalCode(postalCode, typeof country === 'string' ? country : null)\n ) {\n addFailures(context, `${path}.postalCode`, [{ rule: 'postalCode' }]);\n }\n}\n\n/** Whether a string is an email address. */\nconst isEmail = (text: string) => EMAIL.test(text);\n\n/** Whether the `url` of a link of a type is valid: the `rule` it fails, or `null`. */\nfunction checkLinkUrl(type: string, url: string, pattern: string | undefined): string | null {\n switch (type) {\n case 'url':\n return /^https?:\\/\\//i.test(url) && URL.canParse(url) ? null : 'url';\n case 'email':\n // `mailto:` and an address, with a query (`?subject=`) if any\n return /^mailto:/i.test(url) && isEmail(url.slice(7).split('?')[0] ?? '')\n ? null\n : 'email';\n case 'tel':\n return /^tel:/i.test(url) && TEL.test(url.slice(4)) ? null : 'tel';\n default:\n return pattern === undefined || new RegExp(pattern).test(url) ? null : 'pattern';\n }\n}\n\n/**\n * The checks of the parts of a `link` (decision 0055): a type of the field, the URL of its type,\n * its page or its file, and its label when the field requires one.\n */\nfunction checkLink(field: Field, value: unknown, path: string, context: Context) {\n if (!isRecord(value)) {\n return;\n }\n const types = getLinkTypes(field);\n const type = types.find((candidate) => candidate.id === value.type);\n if (type === undefined) {\n addFailures(context, `${path}.type`, [\n { rule: 'in', value: types.map((candidate) => candidate.id) },\n ]);\n return;\n }\n if (type.id === 'page' || type.id === 'file') {\n if (!isFilled(value[type.id])) {\n addFailures(context, `${path}.${type.id}`, [{ rule: 'required' }]);\n }\n } else if (typeof value.url !== 'string' || !isFilled(value.url)) {\n addFailures(context, `${path}.url`, [{ rule: 'required' }]);\n } else {\n const failed = checkLinkUrl(type.id, value.url.trim(), type.pattern);\n if (failed !== null) {\n addFailures(context, `${path}.url`, [\n failed === 'pattern' ? { rule: 'pattern', value: type.pattern } : { rule: failed },\n ]);\n }\n }\n const label = value.label;\n const hasLabel = isRecord(label) ? Object.values(label).some(isFilled) : isFilled(label);\n if (field.settings?.label === 'required' && !hasLabel) {\n addFailures(context, `${path}.label`, [{ rule: 'required' }]);\n }\n}\n\n/** The checks of the parts of a value that the field's type implies. */\nfunction checkParts(field: Field, value: unknown, path: string, context: Context) {\n if (field.type === 'address') {\n checkAddress(field, value, path, context);\n } else if (field.type === 'link') {\n checkLink(field, value, path, context);\n }\n}\n\nfunction checkFieldValue(field: Field, value: unknown, path: string, context: Context) {\n const rules = rulesOf(field, context.mode);\n if (field.localized === true) {\n const localized = isRecord(value) ? value : {};\n const required = rules.filter((rule) => rule.rule === 'required');\n const others = rules.filter((rule) => rule.rule !== 'required');\n if (required.length > 0) {\n const locales = context.locales;\n if (locales === undefined || locales.length === 0) {\n if (!Object.values(localized).some(isFilled)) {\n addFailures(context, path, required.map(failure));\n }\n } else {\n locales.forEach((locale) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(required, localized[locale], context.root, context.mode),\n );\n });\n }\n }\n Object.entries(localized).forEach(([locale, localeValue]) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(others, localeValue, context.root, context.mode),\n );\n checkParts(field, localeValue, `${path}.${locale}`, context);\n });\n return;\n }\n\n addFailures(context, path, checkRules(rules, value, context.root, context.mode));\n checkParts(field, value, path, context);\n\n if (field.type === 'group' && field.fields !== undefined && isRecord(value)) {\n checkFields(field.fields, value, `${path}.`, context);\n }\n if (field.type === 'repeater' && Array.isArray(value)) {\n value.forEach((item, index) => {\n if (!isRecord(item)) {\n return;\n }\n const blockFields =\n field.types !== undefined\n ? field.types.find((type) => type.id === item.type)?.fields\n : field.fields;\n if (blockFields !== undefined) {\n checkFields(blockFields, item, `${path}.${index}.`, context);\n }\n });\n }\n}\n\nfunction checkFields(\n fields: Field[],\n values: Record<string, unknown>,\n prefix: string,\n context: Context,\n) {\n fields.forEach((field) => {\n if (field.readOnly === true) {\n return;\n }\n if (context.mode === 'create' && field.updateOnly === true) {\n return;\n }\n if (context.mode === 'update' && field.createOnly === true) {\n return;\n }\n if (\n field.visibleWhen !== undefined &&\n !evaluateCondition(field.visibleWhen, prefix === '' ? context.root : values)\n ) {\n return;\n }\n if (context.partial === true && prefix === '' && !(field.name in values)) {\n return;\n }\n checkFieldValue(field, values[field.name], `${prefix}${field.name}`, context);\n });\n}\n\n/**\n * Checks form values against the portable rules of their fields. Returns the failures keyed by\n * the dot path of the value (`title.fr`, `blocks.2.image`), the same keys as validation errors.\n * Hidden and read-only fields are skipped. Rules this version doesn't know are ignored.\n */\nexport function checkValues(\n fields: Field[],\n values: Record<string, unknown>,\n options: CheckOptions = {},\n): Record<string, RuleFailure[]> {\n const root =\n options.partial === true && options.item !== undefined\n ? { ...options.item, ...values }\n : values;\n const context: Context = { ...options, root, failures: {} };\n checkFields(fields, values, '', context);\n return context.failures;\n}\n"],"mappings":";;;;;;;;AA6CA,IAAM,QAAQ;;AAEd,IAAM,MAAM;;AAEZ,IAAM,gBAAgB;AAEtB,SAAS,YAAY,MAAqB;CACtC,OAAQ,eAAqC,SAAS,KAAK,IAAI;AACnE;;;;;AAMA,SAAS,UAAU,MAAY,MAAqC;CAChE,OAAO,KAAK,SAAS,KAAA,KAAa,KAAK,SAAS;AACpD;AAEA,SAAS,QAAQ,MAAyB;CACtC,MAAM,SAAsB,EAAE,MAAM,KAAK,KAAK;CAC9C,IAAI,WAAW,QAAQ,KAAK,UAAU,KAAA,GAClC,OAAO,QAAQ,KAAK;CAExB,IAAI,KAAK,YAAY,KAAA,GACjB,OAAO,UAAU,KAAK;CAE1B,OAAO;AACX;AAEA,SAAS,OAAO,OAA+B;CAC3C,IAAI,OAAO,UAAU,UACjB,OAAO;CAGX,IAAI,SAAS,KAAK,KAAK,cAAc,SAAS,OAAO,MAAM,WAAW,UAClE,OAAO,MAAM;CAEjB,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAChD,OAAO,MAAM;CAEjB,OAAO;AACX;AAEA,SAAS,YAAY,MAAc,UAA6B;CAC5D,OAAO,SAAS,MAAM,YAAY;EAC9B,IAAI,QAAQ,SAAS,IAAI,GACrB,OAAO,KAAK,WAAW,QAAQ,MAAM,GAAG,EAAE,CAAC;EAE/C,OAAO,SAAS;CACpB,CAAC;A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,YAAY,QAAQ,QAAQ,SAAS,KAAA,IACvC;EAAE,GAAG,QAAQ;EAAM,GAAG;CAAO,IAC7B;CACV,MAAM,UAAmB;EAAE,GAAG;EAAS;EAAM,UAAU,CAAC;CAAE;CAC1D,YAAY,QAAQ,QAAQ,IAAI,OAAO;CACvC,OAAO,QAAQ;AACnB"}
1
+ {"version":3,"file":"rules.js","names":[],"sources":["../src/rules.ts"],"sourcesContent":["import { getAddressRequiredParts, isPostalCode } from './addresses';\nimport { getNestedShape } from './compound';\nimport { evaluateCondition } from './conditions';\nimport { PORTABLE_RULES } from './constants';\nimport { isCurrencyCode } from './currencies';\nimport { getLinkTypes } from './links';\nimport type { Field, Rule } from './schemas/field';\nimport { matchesRatio, renderedCropSize } from './transforms';\nimport { getValue, isFilled, isRecord } from './values';\n\n/** A rule that a value doesn't satisfy. */\nexport interface RuleFailure {\n rule: string;\n /**\n * The rule's parameter (`max: 120` gives `120`). For `daterange`, what fails: `start` or `end`\n * (a bound missing where the range isn't open), or `order` (the end is before the start).\n */\n value?: unknown;\n /** The message set on the rule, if any. */\n message?: string;\n}\n\nexport interface CheckOptions {\n /**\n * Locales a `required` localized field must be filled in. Without it, one filled locale is\n * enough.\n */\n locales?: string[];\n /** `create` skips `updateOnly` fields; `update` skips `createOnly` fields. */\n mode?: 'create' | 'update';\n /** Only check the fields present in the values (partial updates). */\n partial?: boolean;\n /**\n * The values of the item being updated. With `partial`, conditions (`visibleWhen`) and rules\n * that read other fields read them for the fields that aren't in the values: a field shown\n * when `status` is `published`, sent alone, is checked on a published item (decision 0043).\n */\n item?: Record<string, unknown>;\n}\n\ninterface Context extends CheckOptions {\n /** The whole form, for `visibleWhen` and date rules that reference other fields. */\n root: Record<string, unknown>;\n failures: Record<string, RuleFailure[]>;\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n/** An international phone number in E.164: `+`, then 7 to 15 digits, without a leading zero. */\nconst TEL = /^\\+[1-9]\\d{6,14}$/;\n/** The same number, with an optional extension after `;ext=` (RFC 3966): `+15145550199;ext=123`. */\nconst TEL_EXTENSION = /^\\+[1-9]\\d{6,14}(?:;ext=\\d{1,10})?$/;\n\nfunction isKnownRule(rule: Rule): boolean {\n return (PORTABLE_RULES as readonly string[]).includes(rule.rule);\n}\n\n/**\n * Whether a rule applies in a mode: a rule with a `mode` applies only in that mode, and not when the\n * mode isn't known.\n */\nfunction appliesIn(rule: Rule, mode: CheckOptions['mode']): boolean {\n return rule.mode === undefined || rule.mode === mode;\n}\n\nfunction failure(rule: Rule): RuleFailure {\n const result: RuleFailure = { rule: rule.rule };\n if ('value' in rule && rule.value !== undefined) {\n result.value = rule.value;\n }\n if (rule.message !== undefined) {\n result.message = rule.message;\n }\n return result;\n}\n\nfunction sizeOf(value: unknown): number | null {\n if (typeof value === 'number') {\n return value;\n }\n // A `money` value: `min` and `max` apply to its amount, in minor units (decision 0053).\n if (isRecord(value) && 'currency' in value && typeof value.amount === 'number') {\n return value.amount;\n }\n if (typeof value === 'string' || Array.isArray(value)) {\n return value.length;\n }\n return null;\n}\n\nfunction matchesMime(mime: string, patterns: string[]): boolean {\n return patterns.some((pattern) => {\n if (pattern.endsWith('/*')) {\n return mime.startsWith(pattern.slice(0, -1));\n }\n return mime === pattern;\n });\n}\n\n/** The files of a value, with their MIME type and size: stored files, or chosen ones (`File`). */\nfunction mediaList(value: unknown): Record<string, unknown>[] {\n const list = Array.isArray(value) ? value : [value];\n return list\n .filter(isRecord)\n .map((media) =>\n typeof Blob !== 'undefined' && media instanceof Blob\n ? { mime: media.type === '' ? undefined : media.type, size: media.size }\n : media,\n );\n}\n\n/**\n * Whether each image of a value has the crop the `crop` rule asks for (decision 0031): a crop when\n * it is required, and one of the ratios once rendered. An id alone has no crop.\n */\nfunction hasCrop(value: unknown, rule: { ratios?: string[]; required?: boolean }): boolean {\n const entries = Array.isArray(value) ? value : [value];\n return entries.every((entry) => {\n const transform = isRecord(entry) && isRecord(entry.transform) ? entry.transform : {};\n const size = renderedCropSize(transform);\n if (size === null) {\n return rule.required !== true;\n }\n const ratios = rule.ratios ?? [];\n return (\n ratios.length === 0 ||\n ratios.some((ratio) => matchesRatio(size.width, size.height, ratio))\n );\n });\n}\n\n/**\n * Whether an `embed` value comes from one of the providers, compared without case (decision 0058).\n * A value without a `provider` (an app without `GET /embeds`) is left to the backend.\n */\nfunction hasProvider(value: unknown, providers: readonly string[]): boolean {\n if (!isRecord(value) || typeof value.provider !== 'string') {\n return true;\n }\n const provider = value.provider.toLowerCase();\n return providers.some(\n (allowed) => typeof allowed === 'string' && allowed.toLowerCase() === provider,\n );\n}\n\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst DATE_TIME = /^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}/;\n\n/** A bound of a `daterange`: a day or a date-time, `null` when empty, `undefined` when invalid. */\nfunction rangeBound(value: unknown): string | null | undefined {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n if (typeof value !== 'string' || !(DAY.test(value) || DATE_TIME.test(value))) {\n return undefined;\n }\n return toTime(value) !== null ? value : undefined;\n}\n\n/**\n * What a `daterange` value fails (decision 0053): a bound that is missing or invalid where the range\n * isn't open (`start`, `end`), or an end before the start (`order`). `null` when it is valid.\n */\nfunction checkDateRange(value: unknown, open: unknown): 'start' | 'end' | 'order' | null {\n if (!isRecord(value)) {\n return 'start';\n }\n const start = rangeBound(value.start);\n const end = rangeBound(value.end);\n const openStart = open === 'start' || open === 'both';\n const openEnd = open === 'end' || open === 'both';\n if (start === undefined || (start === null && !openStart)) {\n return 'start';\n }\n if (end === undefined || (end === null && !openEnd)) {\n return 'end';\n }\n if (start === null || end === null) {\n return null;\n }\n // Days compare as days; a date-time compares as its instant.\n const before =\n DAY.test(start) && DAY.test(end)\n ? end < start\n : (toTime(end) as number) < (toTime(start) as number);\n return before ? 'order' : null;\n}\n\n/** Whether a `money` value has an integer amount, and a currency that the rule allows. */\nfunction isMoney(value: unknown, currencies: unknown): boolean {\n if (!isRecord(value) || !Number.isSafeInteger(value.amount)) {\n return false;\n }\n return Array.isArray(currencies) && currencies.length > 0\n ? currencies.includes(value.currency)\n : isCurrencyCode(value.currency);\n}\n\nfunction toTime(value: unknown): number | null {\n if (typeof value !== 'string' && typeof value !== 'number') {\n return null;\n }\n const time = new Date(value).getTime();\n return Number.isNaN(time) ? null : time;\n}\n\n/**\n * Checks one value against a field's rules. Returns the rules that fail. Rules limited to a `mode`\n * only apply when it is given.\n */\nexport function checkRules(\n rules: Rule[],\n value: unknown,\n root: Record<string, unknown> = {},\n mode?: CheckOptions['mode'],\n): RuleFailure[] {\n const failures: RuleFailure[] = [];\n const filled = isFilled(value);\n const applying = rules.filter((rule) => isKnownRule(rule) && appliesIn(rule, mode));\n applying.forEach((rule) => {\n if (rule.rule === 'required') {\n if (!filled) {\n failures.push(failure(rule));\n }\n return;\n }\n if (!filled) {\n return;\n }\n let valid = true;\n // What fails, when the rule says more than its parameter (`daterange`).\n let detail: string | null = null;\n switch (rule.rule) {\n case 'min':\n case 'max': {\n const size = sizeOf(value);\n const limit = rule.value as number;\n valid = size === null || (rule.rule === 'min' ? size >= limit : size <= limit);\n break;\n }\n case 'pattern':\n valid =\n typeof value !== 'string' ||\n new RegExp(rule.value as string, (rule as { flags?: string }).flags).test(\n value,\n );\n break;\n case 'email':\n valid = typeof value !== 'string' || EMAIL.test(value);\n break;\n case 'url':\n valid = typeof value !== 'string' || URL.canParse(value);\n break;\n case 'json':\n // Text that doesn't parse stays a string in the form: only objects and arrays pass\n valid = isRecord(value) || Array.isArray(value);\n break;\n case 'tel':\n valid =\n typeof value !== 'string' ||\n ((rule as { extension?: boolean }).extension === true\n ? TEL_EXTENSION\n : TEL\n ).test(value);\n break;\n case 'postalCode': {\n // The country is a code, or another field of the form (decision 0054)\n const country = isRecord(rule.value)\n ? getValue(root, String(rule.value.field))\n : rule.value;\n valid =\n typeof value !== 'string' ||\n isPostalCode(value, typeof country === 'string' ? country : null);\n break;\n }\n case 'daterange':\n detail = checkDateRange(value, (rule as { open?: unknown }).open);\n valid = detail === null;\n break;\n case 'money':\n valid = isMoney(value, (rule as { currencies?: unknown }).currencies);\n break;\n case 'in': {\n const allowed = rule.value as unknown[];\n const values = Array.isArray(value) ? value : [value];\n valid = values.every((item) => allowed.includes(item));\n break;\n }\n case 'accept':\n valid = mediaList(value).every(\n (media) =>\n typeof media.mime !== 'string' ||\n matchesMime(media.mime, rule.value as string[]),\n );\n break;\n case 'maxSize':\n valid = mediaList(value).every(\n (media) =>\n typeof media.size !== 'number' || media.size <= (rule.value as number),\n );\n break;\n case 'crop':\n valid = !isRecord(rule.value) || hasCrop(value, rule.value);\n break;\n case 'providers':\n valid = hasProvider(value, rule.value as string[]);\n break;\n case 'before':\n case 'after': {\n const bound = rule.value as string | { field: string };\n const boundTime = toTime(\n typeof bound === 'string' ? bound : getValue(root, bound.field),\n );\n const time = toTime(value);\n if (boundTime !== null && time !== null) {\n valid = rule.rule === 'before' ? time < boundTime : time > boundTime;\n }\n break;\n }\n }\n if (!valid) {\n failures.push(detail !== null ? { ...failure(rule), value: detail } : failure(rule));\n }\n });\n return failures;\n}\n\nfunction addFailures(context: Context, path: string, failures: RuleFailure[]) {\n if (failures.length > 0) {\n context.failures[path] = [...(context.failures[path] ?? []), ...failures];\n }\n}\n\n/** A string setting of a field. */\nfunction stringSetting(field: Field, key: string): string | undefined {\n const value = field.settings?.[key];\n return typeof value === 'string' && value !== '' ? value : undefined;\n}\n\n/**\n * The rule each type implies: its values are checked whatever rules the field lists. `tel`,\n * `daterange` and `money` carry settings of their field: the extension, the open bounds, the\n * allowed currencies.\n */\nconst IMPLIED_RULES: Readonly<Record<string, (field: Field) => Rule>> = {\n json: () => ({ rule: 'json' }),\n tel: (field) =>\n field.settings?.extension === true ? { rule: 'tel', extension: true } : { rule: 'tel' },\n daterange: (field) => {\n const open = stringSetting(field, 'open');\n return { rule: 'daterange', ...(open !== undefined ? { open } : {}) } as Rule;\n },\n money: (field) => {\n const currency = stringSetting(field, 'currency');\n const listed = field.settings?.currencies;\n const currencies =\n currency !== undefined\n ? [currency]\n : Array.isArray(listed)\n ? listed.filter((code): code is string => typeof code === 'string')\n : [];\n return { rule: 'money', ...(currencies.length > 0 ? { currencies } : {}) } as Rule;\n },\n};\n\n/**\n * The rules of a field that apply in the mode, with the one its type implies: `json` for the\n * `json` type, `tel` for `tel`, `daterange` for `daterange` and `money` for `money`. A rule of\n * the same name on the field wins.\n */\nfunction rulesOf(field: Field, mode: CheckOptions['mode']): Rule[] {\n const rules = (field.rules ?? []).filter((rule) => appliesIn(rule, mode));\n const implied = IMPLIED_RULES[field.type]?.(field);\n return implied !== undefined && !rules.some((rule) => rule.rule === implied.rule)\n ? [...rules, implied]\n : rules;\n}\n\n/** The parts that make an address filled: a country or a point alone don't. */\nconst ADDRESS_TEXT_PARTS = ['street', 'unit', 'city', 'region', 'postalCode'] as const;\n\n/**\n * The checks of the parts of an `address` (decision 0054): a filled address, with a part other\n * than its country, has its required parts, and a postal code of its country.\n */\nfunction checkAddress(field: Field, value: unknown, path: string, context: Context) {\n if (!isRecord(value) || !ADDRESS_TEXT_PARTS.some((part) => isFilled(value[part]))) {\n return;\n }\n getAddressRequiredParts(field).forEach((part) => {\n if (!isFilled(value[part])) {\n addFailures(context, `${path}.${part}`, [{ rule: 'required' }]);\n }\n });\n const { postalCode, country } = value;\n if (\n typeof postalCode === 'string' &&\n isFilled(postalCode) &&\n !isPostalCode(postalCode, typeof country === 'string' ? country : null)\n ) {\n addFailures(context, `${path}.postalCode`, [{ rule: 'postalCode' }]);\n }\n}\n\n/** Whether a string is an email address. */\nconst isEmail = (text: string) => EMAIL.test(text);\n\n/** Whether the `url` of a link of a type is valid: the `rule` it fails, or `null`. */\nfunction checkLinkUrl(type: string, url: string, pattern: string | undefined): string | null {\n switch (type) {\n case 'url':\n return /^https?:\\/\\//i.test(url) && URL.canParse(url) ? null : 'url';\n case 'email':\n // `mailto:` and an address, with a query (`?subject=`) if any\n return /^mailto:/i.test(url) && isEmail(url.slice(7).split('?')[0] ?? '')\n ? null\n : 'email';\n case 'tel':\n return /^tel:/i.test(url) && TEL.test(url.slice(4)) ? null : 'tel';\n default:\n return pattern === undefined || new RegExp(pattern).test(url) ? null : 'pattern';\n }\n}\n\n/**\n * The checks of the parts of a `link` (decision 0055): a type of the field, the URL of its type,\n * its page or its file, and its label when the field requires one.\n */\nfunction checkLink(field: Field, value: unknown, path: string, context: Context) {\n if (!isRecord(value)) {\n return;\n }\n const types = getLinkTypes(field);\n const type = types.find((candidate) => candidate.id === value.type);\n if (type === undefined) {\n addFailures(context, `${path}.type`, [\n { rule: 'in', value: types.map((candidate) => candidate.id) },\n ]);\n return;\n }\n if (type.id === 'page' || type.id === 'file') {\n if (!isFilled(value[type.id])) {\n addFailures(context, `${path}.${type.id}`, [{ rule: 'required' }]);\n }\n } else if (typeof value.url !== 'string' || !isFilled(value.url)) {\n addFailures(context, `${path}.url`, [{ rule: 'required' }]);\n } else {\n const failed = checkLinkUrl(type.id, value.url.trim(), type.pattern);\n if (failed !== null) {\n addFailures(context, `${path}.url`, [\n failed === 'pattern' ? { rule: 'pattern', value: type.pattern } : { rule: failed },\n ]);\n }\n }\n const label = value.label;\n const hasLabel = isRecord(label) ? Object.values(label).some(isFilled) : isFilled(label);\n if (field.settings?.label === 'required' && !hasLabel) {\n addFailures(context, `${path}.label`, [{ rule: 'required' }]);\n }\n}\n\n/** The checks of the parts of a value that the field's type implies. */\nfunction checkParts(field: Field, value: unknown, path: string, context: Context) {\n if (field.type === 'address') {\n checkAddress(field, value, path, context);\n } else if (field.type === 'link') {\n checkLink(field, value, path, context);\n }\n}\n\nfunction checkFieldValue(field: Field, value: unknown, path: string, context: Context) {\n const rules = rulesOf(field, context.mode);\n if (field.localized === true) {\n const localized = isRecord(value) ? value : {};\n const required = rules.filter((rule) => rule.rule === 'required');\n const others = rules.filter((rule) => rule.rule !== 'required');\n if (required.length > 0) {\n const locales = context.locales;\n if (locales === undefined || locales.length === 0) {\n if (!Object.values(localized).some(isFilled)) {\n addFailures(context, path, required.map(failure));\n }\n } else {\n locales.forEach((locale) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(required, localized[locale], context.root, context.mode),\n );\n });\n }\n }\n Object.entries(localized).forEach(([locale, localeValue]) => {\n addFailures(\n context,\n `${path}.${locale}`,\n checkRules(others, localeValue, context.root, context.mode),\n );\n checkParts(field, localeValue, `${path}.${locale}`, context);\n });\n return;\n }\n\n addFailures(context, path, checkRules(rules, value, context.root, context.mode));\n checkParts(field, value, path, context);\n\n // Compound fields of plugins check their `fields` as groups and repeaters do (decision 0065).\n const shape = getNestedShape(field);\n if (shape === 'group' && field.fields !== undefined && isRecord(value)) {\n checkFields(field.fields, value, `${path}.`, context);\n }\n if (shape === 'repeater' && Array.isArray(value)) {\n value.forEach((item, index) => {\n if (!isRecord(item)) {\n return;\n }\n const blockFields =\n field.types !== undefined\n ? field.types.find((type) => type.id === item.type)?.fields\n : field.fields;\n if (blockFields !== undefined) {\n checkFields(blockFields, item, `${path}.${index}.`, context);\n }\n });\n }\n}\n\nfunction checkFields(\n fields: Field[],\n values: Record<string, unknown>,\n prefix: string,\n context: Context,\n) {\n fields.forEach((field) => {\n if (field.readOnly === true) {\n return;\n }\n if (context.mode === 'create' && field.updateOnly === true) {\n return;\n }\n if (context.mode === 'update' && field.createOnly === true) {\n return;\n }\n if (\n field.visibleWhen !== undefined &&\n !evaluateCondition(field.visibleWhen, prefix === '' ? context.root : values)\n ) {\n return;\n }\n if (context.partial === true && prefix === '' && !(field.name in values)) {\n return;\n }\n checkFieldValue(field, values[field.name], `${prefix}${field.name}`, context);\n });\n}\n\n/**\n * Checks form values against the portable rules of their fields. Returns the failures keyed by\n * the dot path of the value (`title.fr`, `blocks.2.image`), the same keys as validation errors.\n * Hidden and read-only fields are skipped. Rules this version doesn't know are ignored.\n */\nexport function checkValues(\n fields: Field[],\n values: Record<string, unknown>,\n options: CheckOptions = {},\n): Record<string, RuleFailure[]> {\n const root =\n options.partial === true && options.item !== undefined\n ? { ...options.item, ...values }\n : values;\n const context: Context = { ...options, root, failures: {} };\n checkFields(fields, values, '', context);\n return context.failures;\n}\n"],"mappings":";;;;;;;;;AA8CA,IAAM,QAAQ;;AAEd,IAAM,MAAM;;AAEZ,IAAM,gBAAgB;AAEtB,SAAS,YAAY,MAAqB;CACtC,OAAQ,eAAqC,SAAS,KAAK,IAAI;AACnE;;;;;AAMA,SAAS,UAAU,MAAY,MAAqC;CAChE,OAAO,KAAK,SAAS,KAAA,KAAa,KAAK,SAAS;AACpD;AAEA,SAAS,QAAQ,MAAyB;CACtC,MAAM,SAAsB,EAAE,MAAM,KAAK,KAAK;CAC9C,IAAI,WAAW,QAAQ,KAAK,UAAU,KAAA,GAClC,OAAO,QAAQ,KAAK;CAExB,IAAI,KAAK,YAAY,KAAA,GACjB,OAAO,UAAU,KAAK;CAE1B,OAAO;AACX;AAEA,SAAS,OAAO,OAA+B;CAC3C,IAAI,OAAO,UAAU,UACjB,OAAO;CAGX,IAAI,SAAS,KAAK,KAAK,cAAc,SAAS,OAAO,MAAM,WAAW,UAClE,OAAO,MAAM;CAEjB,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAChD,OAAO,MAAM;CAEjB,OAAO;AACX;AAEA,SAAS,YAAY,MAAc,UAA6B;CAC5D,OAAO,SAAS,MAAM,YAAY;EAC9B,IAAI,QAAQ,SAAS,IAAI,GACrB,OAAO,KAAK,WAAW,QAAQ,MAAM,GAAG,EAAE,CAAC;EAE/C,OAAO,SAAS;CACpB,CAAC;AACL;;AAGA,SAAS,UAAU,OAA2C;CAE1D,QADa,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAA,CAE7C,OAAO,QAAQ,CAAC,CAChB,KAAK,UACF,OAAO,SAAS,eAAe,iBAAiB,OAC1C;EAAE,MAAM,MAAM,SAAS,KAAK,KAAA,IAAY,MAAM;EAAM,MAAM,MAAM;CAAK,IACrE,KAC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@ export * from '../constants.js';
3
3
  export { type CurrencyCode, CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits, } from '../currencies.js';
4
4
  export { type CheckOptions, type RuleFailure, checkRules, checkValues } from '../rules.js';
5
5
  export { evaluateCondition } from '../conditions.js';
6
+ export { type NestedShape, getNestedShape, isBuiltInFieldType, isCompoundField } from '../compound.js';
6
7
  export { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode, } from '../addresses.js';
7
8
  export { type LinkNewTab, type LinkType, getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab, } from '../links.js';
8
- export { getMediaLibraries, type MediaLibrariesDefinition } from '../libraries.js';
9
+ export { type ItemImageResource, type MediaLibrariesDefinition, getItemImageField, getMediaLibraries, } from '../libraries.js';
9
10
  export { matchesRatio, parseRatio, renderedCropSize } from '../transforms.js';
10
11
  export { lintDefinition } from '../lint.js';
11
12
  export type { ValidationIssue } from '../validate.js';
@@ -15,4 +16,5 @@ export { getValue, isFilled } from '../values.js';
15
16
  export { type ContextValues, contextBefore, formatContextHeader, parseContextHeader, } from '../context.js';
16
17
  export { isProblem } from '../problem.js';
17
18
  export { type PartialTheme, mergeThemes } from '../themes.js';
19
+ export { type BuiltInWidgetType, type WidgetResource, type WidgetSeriesPeriod, BUILT_IN_WIDGET_TYPES, RESOURCE_WIDGET_TYPES, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, checkWidgetData, getWidgetResource, isBuiltInWidgetType, } from '../widgets.js';
18
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpE,cAAc,cAAc,CAAC;AAC7B,OAAO,EACH,KAA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,EACZ,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,cAAc,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACH,KAAK,aAAa,EAClB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EACH,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,EAC5B,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,YAAY,CAAC"}
@@ -1,17 +1,19 @@
1
1
  import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "../version.js";
2
- import { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, isBuiltInItemAction, isBuiltInLink } from "../constants.js";
2
+ import { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, UNDO_LIMIT, isBuiltInItemAction, isBuiltInLink } from "../constants.js";
3
3
  import { CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits } from "../currencies.js";
4
4
  import { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode } from "../addresses.js";
5
+ import { getNestedShape, isBuiltInFieldType, isCompoundField } from "../compound.js";
5
6
  import { getValue, isFilled } from "../values.js";
6
7
  import { evaluateCondition } from "../conditions.js";
7
8
  import { getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab } from "../links.js";
8
9
  import { matchesRatio, parseRatio, renderedCropSize } from "../transforms.js";
9
10
  import { checkRules, checkValues } from "../rules.js";
10
- import { getMediaLibraries } from "../libraries.js";
11
- import { lintDefinition } from "../lint.js";
11
+ import { getItemImageField, getMediaLibraries } from "../libraries.js";
12
12
  import { fromSearchParams, isCursorPage, isFilterRange, matchesFilterRange, toSearchParams } from "../query.js";
13
+ import { BUILT_IN_WIDGET_TYPES, RESOURCE_WIDGET_TYPES, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, checkWidgetData, getWidgetResource, isBuiltInWidgetType } from "../widgets.js";
14
+ import { lintDefinition } from "../lint.js";
13
15
  import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "../search.js";
14
16
  import { contextBefore, formatContextHeader, parseContextHeader } from "../context.js";
15
17
  import { isProblem } from "../problem.js";
16
18
  import { mergeThemes } from "../themes.js";
17
- export { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, CURRENCY_CODES, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, POSTAL_CODE_COUNTRIES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, checkRules, checkValues, contextBefore, evaluateCondition, formatContextHeader, fromMinorUnits, fromSearchParams, getAddressRequiredParts, getCurrencyDigits, getLinkNewTab, getLinkTypes, getMediaLibraries, getValue, isAddressPart, isBuiltInItemAction, isBuiltInLink, isBuiltInLinkType, isCurrencyCode, isCursorPage, isExternalUrl, isFilled, isFilterRange, isPostalCode, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, normalizePostalCode, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, resolveLinkNewTab, toMinorUnits, toSearchParams, toSearchQueryParams };
19
+ export { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, BUILT_IN_WIDGET_TYPES, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, CURRENCY_CODES, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, POSTAL_CODE_COUNTRIES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, RESERVED_ROUTE_SEGMENTS, RESOURCE_WIDGET_TYPES, RICH_TEXT_STYLE_ELEMENTS, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, UNDO_LIMIT, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, checkRules, checkValues, checkWidgetData, contextBefore, evaluateCondition, formatContextHeader, fromMinorUnits, fromSearchParams, getAddressRequiredParts, getCurrencyDigits, getItemImageField, getLinkNewTab, getLinkTypes, getMediaLibraries, getNestedShape, getValue, getWidgetResource, isAddressPart, isBuiltInFieldType, isBuiltInItemAction, isBuiltInLink, isBuiltInLinkType, isBuiltInWidgetType, isCompoundField, isCurrencyCode, isCursorPage, isExternalUrl, isFilled, isFilterRange, isPostalCode, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, normalizePostalCode, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, resolveLinkNewTab, toMinorUnits, toSearchParams, toSearchQueryParams };
@@ -255,6 +255,7 @@ export declare const Action: z.ZodObject<{
255
255
  }, z.core.$loose>>>;
256
256
  queued: z.ZodOptional<z.ZodBoolean>;
257
257
  dryRun: z.ZodOptional<z.ZodBoolean>;
258
+ undoable: z.ZodOptional<z.ZodBoolean>;
258
259
  url: z.ZodOptional<z.ZodString>;
259
260
  route: z.ZodOptional<z.ZodString>;
260
261
  component: z.ZodOptional<z.ZodString>;
@@ -1 +1 @@
1
- {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/schemas/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,WAAW;;;;EAA4C,CAAC;AAErE,eAAO,MAAM,eAAe;;;;;EAA6C,CAAC;AAE1E,eAAO,MAAM,aAAa;;;;;mBAWxB,CAAC;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAC5C,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC"}
@@ -39,6 +39,7 @@ var Action = z.looseObject({
39
39
  layout: z.array(LayoutNode).optional(),
40
40
  queued: z.boolean().optional().meta({ description: "The action always answers `202` with a run." }),
41
41
  dryRun: z.boolean().optional().meta({ description: "The backend answers dry runs of this action (`dryRun` in the request): lists ask it how many items of a query selection will be skipped. Without it, the UI never sends `dryRun`, since a backend that ignores it would run the action." }),
42
+ undoable: z.boolean().optional().meta({ description: "Its runs can be undone: the client runs it without a confirmation (unless it sets `confirm`), and shows \"Undo\" when its result has an `undo`. Above `UNDO_LIMIT` items (100), and for queued runs, the client confirms it first (decision 0063). The `delete` of a resource with a trash declares it, undone by `restore`." }),
42
43
  url: z.string().optional().meta({ description: "`link`: URL template, with `{id}` for the item." }),
43
44
  route: z.string().optional().meta({ description: "`link`: name of a route in the definition." }),
44
45
  component: z.string().optional().meta({ description: "`client`: the plugin handler." }),
@@ -1 +1 @@
1
- {"version":3,"file":"action.js","names":[],"sources":["../../src/schemas/action.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { isBuiltInItemAction, isBuiltInLink } from '../constants';\nimport { Abilities } from './common';\nimport { Field } from './field';\nimport { actionJsonRules } from './jsonRules';\nimport { LayoutNode } from './layout';\n\nexport const ActionScope = z.enum(['item', 'selection', 'resource']);\n\nexport const ActionPlacement = z.enum(['row', 'toolbar', 'form', 'menu']);\n\nexport const ActionConfirm = z.union([\n z.boolean(),\n z.looseObject({\n title: z.string().optional(),\n message: z\n .string()\n .optional()\n .meta({ description: 'ICU message. `{count}` is the number of items.' }),\n confirmLabel: z.string().optional(),\n cancelLabel: z.string().optional(),\n }),\n]);\n\nexport const Action = z\n .looseObject({\n id: z.string().min(1),\n label: z.string().optional().meta({\n description:\n 'Required, except for the built-in item actions (`show`, `edit`, `duplicate`, `delete`), which the client labels in its locale.',\n }),\n icon: z.string().optional(),\n kind: z.enum(['server', 'link', 'client']).default('server').meta({\n description:\n '`server` calls the action endpoint; `link` navigates; `client` runs a plugin handler.',\n }),\n scope: z.array(ActionScope).min(1),\n placement: z.array(ActionPlacement).optional(),\n destructive: z.boolean().optional(),\n confirm: ActionConfirm.optional(),\n fields: z.array(Field).optional().meta({ description: 'Parameters, shown in a modal.' }),\n layout: z.array(LayoutNode).optional(),\n queued: z\n .boolean()\n .optional()\n .meta({ description: 'The action always answers `202` with a run.' }),\n dryRun: z.boolean().optional().meta({\n description:\n 'The backend answers dry runs of this action (`dryRun` in the request): lists ask it how many items of a query selection will be skipped. Without it, the UI never sends `dryRun`, since a backend that ignores it would run the action.',\n }),\n url: z\n .string()\n .optional()\n .meta({ description: '`link`: URL template, with `{id}` for the item.' }),\n route: z\n .string()\n .optional()\n .meta({ description: '`link`: name of a route in the definition.' }),\n component: z.string().optional().meta({ description: '`client`: the plugin handler.' }),\n abilities: Abilities.optional().meta({\n description: '`run`: whether the current user can run the action on the resource.',\n }),\n })\n .superRefine((action, context) => {\n const builtInLink = isBuiltInLink(action.id);\n if (builtInLink && action.kind !== 'link') {\n context.addIssue({\n code: 'custom',\n path: ['kind'],\n message: `The id \\`${action.id}\\` is reserved for the built-in link: its \\`kind\\` must be \\`link\\`.`,\n });\n }\n if (action.label === undefined && !isBuiltInItemAction(action.id)) {\n context.addIssue({\n code: 'custom',\n path: ['label'],\n message: 'An action needs a `label`.',\n });\n }\n if (\n action.kind === 'link' &&\n action.url === undefined &&\n action.route === undefined &&\n !builtInLink\n ) {\n context.addIssue({\n code: 'custom',\n message: 'A `link` action needs a `url` or a `route`.',\n });\n }\n if (action.kind === 'client' && action.component === undefined) {\n context.addIssue({ code: 'custom', message: 'A `client` action needs a `component`.' });\n }\n })\n .meta({\n description: 'An operation on one item, a selection, or the whole resource.',\n ...actionJsonRules,\n });\n\nexport type ActionScope = z.infer<typeof ActionScope>;\nexport type ActionPlacement = z.infer<typeof ActionPlacement>;\nexport type ActionConfirm = z.infer<typeof ActionConfirm>;\nexport type Action = z.infer<typeof Action>;\n/** An action as a backend writes it: `kind` defaults to `server`. */\nexport type ActionInput = z.input<typeof Action>;\n"],"mappings":";;;;;;;AAQA,IAAa,cAAc,EAAE,KAAK;CAAC;CAAQ;CAAa;AAAU,CAAC;AAEnE,IAAa,kBAAkB,EAAE,KAAK;CAAC;CAAO;CAAW;CAAQ;AAAM,CAAC;AAExE,IAAa,gBAAgB,EAAE,MAAM,CACjC,EAAE,QAAQ,GACV,EAAE,YAAY;CACV,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,SAAS,EACJ,OAAO,CAAC,CACR,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,iDAAiD,CAAC;CAC3E,cAAc,EAAE,OAAO,CAAC,CAAC,SAAS;CAClC,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AACrC,CAAC,CACL,CAAC;AAED,IAAa,SAAS,EACjB,YAAY;CACT,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACpB,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAC9B,aACI,iIACR,CAAC;CACD,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,MAAM,EAAE,KAAK;EAAC;EAAU;EAAQ;CAAQ,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,CAAC,KAAK,EAC9D,aACI,wFACR,CAAC;CACD,OAAO,EAAE,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC;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,IAAI,OAAO,SAAS,YAAY,OAAO,cAAc,KAAA,GACjD,QAAQ,SAAS;EAAE,MAAM;EAAU,SAAS;CAAyC,CAAC;AAE9F,CAAC,CAAC,CACD,KAAK;CACF,aAAa;CACb,GAAG;AACP,CAAC"}
1
+ {"version":3,"file":"action.js","names":[],"sources":["../../src/schemas/action.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { isBuiltInItemAction, isBuiltInLink } from '../constants';\nimport { Abilities } from './common';\nimport { Field } from './field';\nimport { actionJsonRules } from './jsonRules';\nimport { LayoutNode } from './layout';\n\nexport const ActionScope = z.enum(['item', 'selection', 'resource']);\n\nexport const ActionPlacement = z.enum(['row', 'toolbar', 'form', 'menu']);\n\nexport const ActionConfirm = z.union([\n z.boolean(),\n z.looseObject({\n title: z.string().optional(),\n message: z\n .string()\n .optional()\n .meta({ description: 'ICU message. `{count}` is the number of items.' }),\n confirmLabel: z.string().optional(),\n cancelLabel: z.string().optional(),\n }),\n]);\n\nexport const Action = z\n .looseObject({\n id: z.string().min(1),\n label: z.string().optional().meta({\n description:\n 'Required, except for the built-in item actions (`show`, `edit`, `duplicate`, `delete`), which the client labels in its locale.',\n }),\n icon: z.string().optional(),\n kind: z.enum(['server', 'link', 'client']).default('server').meta({\n description:\n '`server` calls the action endpoint; `link` navigates; `client` runs a plugin handler.',\n }),\n scope: z.array(ActionScope).min(1),\n placement: z.array(ActionPlacement).optional(),\n destructive: z.boolean().optional(),\n confirm: ActionConfirm.optional(),\n fields: z.array(Field).optional().meta({ description: 'Parameters, shown in a modal.' }),\n layout: z.array(LayoutNode).optional(),\n queued: z\n .boolean()\n .optional()\n .meta({ description: 'The action always answers `202` with a run.' }),\n dryRun: z.boolean().optional().meta({\n description:\n 'The backend answers dry runs of this action (`dryRun` in the request): lists ask it how many items of a query selection will be skipped. Without it, the UI never sends `dryRun`, since a backend that ignores it would run the action.',\n }),\n undoable: z.boolean().optional().meta({\n description:\n 'Its runs can be undone: the client runs it without a confirmation (unless it sets `confirm`), and shows \"Undo\" when its result has an `undo`. Above `UNDO_LIMIT` items (100), and for queued runs, the client confirms it first (decision 0063). The `delete` of a resource with a trash declares it, undone by `restore`.',\n }),\n url: z\n .string()\n .optional()\n .meta({ description: '`link`: URL template, with `{id}` for the item.' }),\n route: z\n .string()\n .optional()\n .meta({ description: '`link`: name of a route in the definition.' }),\n component: z.string().optional().meta({ description: '`client`: the plugin handler.' }),\n abilities: Abilities.optional().meta({\n description: '`run`: whether the current user can run the action on the resource.',\n }),\n })\n .superRefine((action, context) => {\n const builtInLink = isBuiltInLink(action.id);\n if (builtInLink && action.kind !== 'link') {\n context.addIssue({\n code: 'custom',\n path: ['kind'],\n message: `The id \\`${action.id}\\` is reserved for the built-in link: its \\`kind\\` must be \\`link\\`.`,\n });\n }\n if (action.label === undefined && !isBuiltInItemAction(action.id)) {\n context.addIssue({\n code: 'custom',\n path: ['label'],\n message: 'An action needs a `label`.',\n });\n }\n if (\n action.kind === 'link' &&\n action.url === undefined &&\n action.route === undefined &&\n !builtInLink\n ) {\n context.addIssue({\n code: 'custom',\n message: 'A `link` action needs a `url` or a `route`.',\n });\n }\n if (action.kind === 'client' && action.component === undefined) {\n context.addIssue({ code: 'custom', message: 'A `client` action needs a `component`.' });\n }\n })\n .meta({\n description: 'An operation on one item, a selection, or the whole resource.',\n ...actionJsonRules,\n });\n\nexport type ActionScope = z.infer<typeof ActionScope>;\nexport type ActionPlacement = z.infer<typeof ActionPlacement>;\nexport type ActionConfirm = z.infer<typeof ActionConfirm>;\nexport type Action = z.infer<typeof Action>;\n/** An action as a backend writes it: `kind` defaults to `server`. */\nexport type ActionInput = z.input<typeof Action>;\n"],"mappings":";;;;;;;AAQA,IAAa,cAAc,EAAE,KAAK;CAAC;CAAQ;CAAa;AAAU,CAAC;AAEnE,IAAa,kBAAkB,EAAE,KAAK;CAAC;CAAO;CAAW;CAAQ;AAAM,CAAC;AAExE,IAAa,gBAAgB,EAAE,MAAM,CACjC,EAAE,QAAQ,GACV,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