@panneau/protocol 5.0.0-alpha.14 → 5.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +113 -2
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +40 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +44 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/mock/auth.d.ts +71 -0
- package/dist/mock/auth.d.ts.map +1 -0
- package/dist/mock/auth.js +346 -0
- package/dist/mock/auth.js.map +1 -0
- package/dist/mock/index.d.ts +8 -0
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +16 -1
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +227 -30
- package/dist/openapi.js.map +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/schemas/api.d.ts +35 -0
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +24 -1
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/boot.d.ts +1 -0
- package/dist/schemas/boot.d.ts.map +1 -1
- package/dist/schemas/definition.d.ts +2 -0
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +6 -5
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/index.d.ts +31 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +8 -2
- package/dist/schemas/index.js.map +1 -1
- package/package.json +1 -1
- package/schema/boot.schema.json +3 -0
- package/schema/definition.schema.json +3 -0
- package/schema/openapi.json +1213 -94
package/dist/constants.js
CHANGED
|
@@ -142,7 +142,50 @@ var RESERVED_ROUTE_SEGMENTS = [
|
|
|
142
142
|
var CONTEXT_HEADER = "Panneau-Context";
|
|
143
143
|
/** The type of the `403` problem of a value of the context that the user can't use. */
|
|
144
144
|
var CONTEXT_PROBLEM_TYPE = "urn:panneau:problem:context";
|
|
145
|
+
/**
|
|
146
|
+
* The type of the `403` problem of a user whose email address isn't verified yet, with
|
|
147
|
+
* `auth.emailVerification` (decision 0048). The app shows a page that sends a new link.
|
|
148
|
+
*/
|
|
149
|
+
var EMAIL_UNVERIFIED_PROBLEM_TYPE = "urn:panneau:problem:email-unverified";
|
|
150
|
+
/**
|
|
151
|
+
* The type of the `403` problem of a user who must have two-factor authentication and hasn't set
|
|
152
|
+
* it up (decision 0049). The app shows its setup.
|
|
153
|
+
*/
|
|
154
|
+
var TWO_FACTOR_REQUIRED_PROBLEM_TYPE = "urn:panneau:problem:two-factor-required";
|
|
155
|
+
/**
|
|
156
|
+
* The type of the `423` problem of an operation that needs the password, when it wasn't confirmed
|
|
157
|
+
* recently (decision 0049): the app confirms it with `POST /auth/password/confirm`, then runs the
|
|
158
|
+
* operation again.
|
|
159
|
+
*/
|
|
160
|
+
var PASSWORD_CONFIRMATION_PROBLEM_TYPE = "urn:panneau:problem:password-confirmation";
|
|
161
|
+
/**
|
|
162
|
+
* The paths of the auth pages of the app, under `basePath` (decision 0048), that the links of the
|
|
163
|
+
* backend's emails open:
|
|
164
|
+
*
|
|
165
|
+
* - `resetPassword`, with the `token` and the `email` of a password reset in the query;
|
|
166
|
+
* - `verifyEmail`, with the `token` of an email verification in the query.
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* The query param of a login with an OAuth provider that failed (decision 0052): the backend comes
|
|
170
|
+
* back to the base path of the app with one of `AUTH_ERROR_CODES`, which the login page says.
|
|
171
|
+
*/
|
|
172
|
+
var AUTH_ERROR_PARAM = "authError";
|
|
173
|
+
/**
|
|
174
|
+
* Why a login with an OAuth provider failed (decision 0052): the provider failed or the user
|
|
175
|
+
* cancelled, it gave no verified email address, the address isn't in an allowed domain, or no user
|
|
176
|
+
* with this address is allowed in.
|
|
177
|
+
*/
|
|
178
|
+
var AUTH_ERROR_CODES = [
|
|
179
|
+
"provider",
|
|
180
|
+
"email",
|
|
181
|
+
"domain",
|
|
182
|
+
"access"
|
|
183
|
+
];
|
|
184
|
+
var AUTH_PAGE_PATHS = {
|
|
185
|
+
resetPassword: "auth/reset-password",
|
|
186
|
+
verifyEmail: "auth/verify-email"
|
|
187
|
+
};
|
|
145
188
|
//#endregion
|
|
146
|
-
export { 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_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink };
|
|
189
|
+
export { 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_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, 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 };
|
|
147
190
|
|
|
148
191
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/**\n * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them\n * to its own routes, and labels them itself when they have no `label`.\n */\nexport const BUILT_IN_LINK_ACTIONS = ['show', 'edit'] as const;\nexport type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];\n\n/** Whether an action id is one of the built-in links, `show` and `edit`. */\nexport function isBuiltInLink(id: string): id is BuiltInLinkAction {\n return (BUILT_IN_LINK_ACTIONS as readonly string[]).includes(id);\n}\n\n/**\n * Built-in item actions, in their default order (decision 0040). Every resource has them without\n * declaring them, and clients show each one on the items whose abilities allow it\n * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.\n */\nexport const BUILT_IN_ITEM_ACTIONS = ['show', 'edit', 'duplicate', 'delete'] as const;\nexport type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];\n\n/** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */\nexport const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>> = {\n show: 'view',\n edit: 'update',\n duplicate: 'duplicate',\n delete: 'delete',\n};\n\n/** Whether an action id is one of the built-in item actions. */\nexport function isBuiltInItemAction(id: string): id is BuiltInItemAction {\n return (BUILT_IN_ITEM_ACTIONS as readonly string[]).includes(id);\n}\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'image',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n 'tel',\n 'range',\n 'duration',\n 'json',\n 'tags',\n 'embed',\n 'location',\n 'country',\n 'region',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'json',\n 'tel',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n\n/** The elements a block style of a `richtext` field can apply to. */\nexport const RICH_TEXT_STYLE_ELEMENTS = [\n 'p',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'blockquote',\n 'ul',\n 'ol',\n 'li',\n] as const;\n\n/** An element a block style of a `richtext` field can apply to. */\nexport type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];\n\n/**\n * The first segments of the client routes under `basePath` that Panneau keeps for itself\n * (decision 0019). A param of the context can't be named like one: the context is a prefix of\n * the routes, `{basePath}/{name}/{value}/…` (decision 0045).\n */\nexport const RESERVED_ROUTE_SEGMENTS = [\n 'resources',\n 'pages',\n 'media',\n 'search',\n 'account',\n 'auth',\n] as const;\n\n/** The request header that carries the values of the current context (decision 0045). */\nexport const CONTEXT_HEADER = 'Panneau-Context';\n\n/** The type of the `403` problem of a value of the context that the user can't use. */\nexport const CONTEXT_PROBLEM_TYPE = 'urn:panneau:problem:context';\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;AAOA,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAIpD,SAAgB,cAAc,IAAqC;CAC/D,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;;;;;AAOA,IAAa,wBAAwB;CAAC;CAAQ;CAAQ;CAAa;AAAQ;;AAI3E,IAAa,wBAAqE;CAC9E,MAAM;CACN,MAAM;CACN,WAAW;CACX,QAAQ;AACZ;;AAGA,SAAgB,oBAAoB,IAAqC;CACrE,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;AAGA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;AAGtC,IAAa,2BAA2B;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,0BAA0B;CACnC;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,IAAa,iBAAiB;;AAG9B,IAAa,uBAAuB"}
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/**\n * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them\n * to its own routes, and labels them itself when they have no `label`.\n */\nexport const BUILT_IN_LINK_ACTIONS = ['show', 'edit'] as const;\nexport type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];\n\n/** Whether an action id is one of the built-in links, `show` and `edit`. */\nexport function isBuiltInLink(id: string): id is BuiltInLinkAction {\n return (BUILT_IN_LINK_ACTIONS as readonly string[]).includes(id);\n}\n\n/**\n * Built-in item actions, in their default order (decision 0040). Every resource has them without\n * declaring them, and clients show each one on the items whose abilities allow it\n * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.\n */\nexport const BUILT_IN_ITEM_ACTIONS = ['show', 'edit', 'duplicate', 'delete'] as const;\nexport type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];\n\n/** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */\nexport const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>> = {\n show: 'view',\n edit: 'update',\n duplicate: 'duplicate',\n delete: 'delete',\n};\n\n/** Whether an action id is one of the built-in item actions. */\nexport function isBuiltInItemAction(id: string): id is BuiltInItemAction {\n return (BUILT_IN_ITEM_ACTIONS as readonly string[]).includes(id);\n}\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'image',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n 'tel',\n 'range',\n 'duration',\n 'json',\n 'tags',\n 'embed',\n 'location',\n 'country',\n 'region',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'json',\n 'tel',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n\n/** The elements a block style of a `richtext` field can apply to. */\nexport const RICH_TEXT_STYLE_ELEMENTS = [\n 'p',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'blockquote',\n 'ul',\n 'ol',\n 'li',\n] as const;\n\n/** An element a block style of a `richtext` field can apply to. */\nexport type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];\n\n/**\n * The first segments of the client routes under `basePath` that Panneau keeps for itself\n * (decision 0019). A param of the context can't be named like one: the context is a prefix of\n * the routes, `{basePath}/{name}/{value}/…` (decision 0045).\n */\nexport const RESERVED_ROUTE_SEGMENTS = [\n 'resources',\n 'pages',\n 'media',\n 'search',\n 'account',\n 'auth',\n] as const;\n\n/** The request header that carries the values of the current context (decision 0045). */\nexport const CONTEXT_HEADER = 'Panneau-Context';\n\n/** The type of the `403` problem of a value of the context that the user can't use. */\nexport const CONTEXT_PROBLEM_TYPE = 'urn:panneau:problem:context';\n\n/**\n * The type of the `403` problem of a user whose email address isn't verified yet, with\n * `auth.emailVerification` (decision 0048). The app shows a page that sends a new link.\n */\nexport const EMAIL_UNVERIFIED_PROBLEM_TYPE = 'urn:panneau:problem:email-unverified';\n\n/**\n * The type of the `403` problem of a user who must have two-factor authentication and hasn't set\n * it up (decision 0049). The app shows its setup.\n */\nexport const TWO_FACTOR_REQUIRED_PROBLEM_TYPE = 'urn:panneau:problem:two-factor-required';\n\n/**\n * The type of the `423` problem of an operation that needs the password, when it wasn't confirmed\n * recently (decision 0049): the app confirms it with `POST /auth/password/confirm`, then runs the\n * operation again.\n */\nexport const PASSWORD_CONFIRMATION_PROBLEM_TYPE = 'urn:panneau:problem:password-confirmation';\n\n/**\n * The paths of the auth pages of the app, under `basePath` (decision 0048), that the links of the\n * backend's emails open:\n *\n * - `resetPassword`, with the `token` and the `email` of a password reset in the query;\n * - `verifyEmail`, with the `token` of an email verification in the query.\n */\n/**\n * The query param of a login with an OAuth provider that failed (decision 0052): the backend comes\n * back to the base path of the app with one of `AUTH_ERROR_CODES`, which the login page says.\n */\nexport const AUTH_ERROR_PARAM = 'authError';\n\n/**\n * Why a login with an OAuth provider failed (decision 0052): the provider failed or the user\n * cancelled, it gave no verified email address, the address isn't in an allowed domain, or no user\n * with this address is allowed in.\n */\nexport const AUTH_ERROR_CODES = ['provider', 'email', 'domain', 'access'] as const;\n\n/** A code of `AUTH_ERROR_CODES`. */\nexport type AuthErrorCode = (typeof AUTH_ERROR_CODES)[number];\n\nexport const AUTH_PAGE_PATHS = {\n resetPassword: 'auth/reset-password',\n verifyEmail: 'auth/verify-email',\n} as const;\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;AAOA,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAIpD,SAAgB,cAAc,IAAqC;CAC/D,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;;;;;AAOA,IAAa,wBAAwB;CAAC;CAAQ;CAAQ;CAAa;AAAQ;;AAI3E,IAAa,wBAAqE;CAC9E,MAAM;CACN,MAAM;CACN,WAAW;CACX,QAAQ;AACZ;;AAGA,SAAgB,oBAAoB,IAAqC;CACrE,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;AAGA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;AAGtC,IAAa,2BAA2B;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,0BAA0B;CACnC;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,IAAa,iBAAiB;;AAG9B,IAAa,uBAAuB;;;;;AAMpC,IAAa,gCAAgC;;;;;AAM7C,IAAa,mCAAmC;;;;;;AAOhD,IAAa,qCAAqC;;;;;;;;;;;;AAalD,IAAa,mBAAmB;;;;;;AAOhC,IAAa,mBAAmB;CAAC;CAAY;CAAS;CAAU;AAAQ;AAKxE,IAAa,kBAAkB;CAC3B,eAAe;CACf,aAAa;AACjB"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "./version.js";
|
|
2
|
-
import { 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_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
|
|
2
|
+
import { 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_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, 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";
|
|
3
3
|
import { getValue, isFilled } from "./values.js";
|
|
4
4
|
import { evaluateCondition } from "./conditions.js";
|
|
5
5
|
import { matchesRatio, parseRatio, renderedCropSize } from "./transforms.js";
|
|
@@ -19,9 +19,9 @@ import { Column, Filter, ListCalendar, ListDefinition } from "./schemas/list.js"
|
|
|
19
19
|
import { Resource, ResourceFeatures } from "./schemas/resource.js";
|
|
20
20
|
import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./schemas/theme.js";
|
|
21
21
|
import { Auth, AuthProvider, AuthToken, ContextOption, ContextParam, Definition, DefinitionContext, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
|
|
22
|
-
import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ContextOptionsResponse, CursorPagination, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse } from "./schemas/api.js";
|
|
22
|
+
import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ContextOptionsResponse, CursorPagination, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, SearchResponse, Selection, Session, StoredFile, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, WebAuthnOptions } from "./schemas/api.js";
|
|
23
23
|
import { BootConfig } from "./schemas/boot.js";
|
|
24
24
|
import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
|
|
25
25
|
import { validate, validateBootConfig, validateDefinition } from "./validate.js";
|
|
26
26
|
import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema } from "./openapi.js";
|
|
27
|
-
export { Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, Auth, AuthProvider, AuthToken, 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_LIST_LAYOUTS, BlockType, BootConfig, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, Definition, DefinitionContext, DefinitionTheme, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, Widget, checkRules, checkValues, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, formatContextHeader, fromSearchParams, getMediaLibraries, getValue, isBuiltInItemAction, isBuiltInLink, isCursorPage, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
|
|
27
|
+
export { AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, Auth, AuthProvider, AuthToken, 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_LIST_LAYOUTS, BlockType, BootConfig, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, Definition, DefinitionContext, DefinitionTheme, EMAIL_UNVERIFIED_PROBLEM_TYPE, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListCalendar, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, Passkey, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, RecoveryCodes, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, Session, StoredFile, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WebAuthnOptions, Widget, checkRules, checkValues, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, formatContextHeader, fromSearchParams, getMediaLibraries, getValue, isBuiltInItemAction, isBuiltInLink, isCursorPage, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Auth, User } from '../schemas/index.js';
|
|
2
|
+
/** A user of the mock backend. */
|
|
3
|
+
export interface MockUser {
|
|
4
|
+
/** Defaults to the position of the user in `users`, from 1. */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Defaults to the email. */
|
|
7
|
+
name?: string;
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
/** Whether the email address is verified, for `auth.emailVerification`. Defaults to true. */
|
|
11
|
+
emailVerified?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the user has two-factor authentication, for `auth.twoFactor`: their password login
|
|
14
|
+
* then asks for `twoFactorCode` or a recovery code. Defaults to false.
|
|
15
|
+
*/
|
|
16
|
+
twoFactor?: boolean;
|
|
17
|
+
/** Recovery codes of a user with `twoFactor`. Defaults to none. */
|
|
18
|
+
recoveryCodes?: string[];
|
|
19
|
+
/** Whether the backend requires two-factor authentication for the user. Defaults to false. */
|
|
20
|
+
twoFactorRequired?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The passkeys of the user, for `auth.passkeys`: the `id` of their credential, and a name. The
|
|
23
|
+
* mock doesn't check signatures: a credential with one of these ids logs in.
|
|
24
|
+
*/
|
|
25
|
+
passkeys?: {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
/** An email that the mock backend "sends", with the path of its link under the app's base path. */
|
|
31
|
+
export interface MockMail {
|
|
32
|
+
kind: 'password-reset' | 'email-verification';
|
|
33
|
+
to: string;
|
|
34
|
+
token: string;
|
|
35
|
+
/** The page of the app that the link opens, with its query: `auth/reset-password?token=…`. */
|
|
36
|
+
path: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The auth of the mock backend: its users, and who is logged in. With it, the routes of the
|
|
40
|
+
* `panneau` auth mode answer (`/auth/login`, `/auth/logout`, `/auth/session`, and those of
|
|
41
|
+
* `auth.passwordReset` and `auth.emailVerification`), and the other routes answer `401` to
|
|
42
|
+
* guests.
|
|
43
|
+
*/
|
|
44
|
+
export interface MockAuthOptions {
|
|
45
|
+
users: MockUser[];
|
|
46
|
+
/** The email of the user logged in at the start. Defaults to the first user; `null`: a guest. */
|
|
47
|
+
loggedIn?: string | null;
|
|
48
|
+
/** Called with each email the backend sends: there is no mailbox. */
|
|
49
|
+
onMail?: (mail: MockMail) => void;
|
|
50
|
+
/** The code of the authenticator app of every user, for `auth.twoFactor`. Defaults to `123456`. */
|
|
51
|
+
twoFactorCode?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The email of the user that each OAuth provider of `auth.providers` logs in, at once, when the
|
|
54
|
+
* app goes to its `redirect` (decision 0052). A provider without one fails with `access`.
|
|
55
|
+
*/
|
|
56
|
+
providerUsers?: Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
type Values = Record<string, unknown>;
|
|
59
|
+
export interface MockAuth {
|
|
60
|
+
/** The current user, as the definition and `/auth/session` give it. */
|
|
61
|
+
user(): User | null;
|
|
62
|
+
/** The answer of a route of `/auth/…`, without its first segment. */
|
|
63
|
+
answer(segments: string[], method: string, readBody: () => Promise<Values>, url?: URL): Promise<Response>;
|
|
64
|
+
/** The answer of a route of `/account/…`, without its first segment, or null for another. */
|
|
65
|
+
account(segments: string[], method: string, readBody: () => Promise<Values>): Promise<Response> | null;
|
|
66
|
+
/** The answer to a request of another route by the current user, when it is refused. */
|
|
67
|
+
refuse(): Response | null;
|
|
68
|
+
}
|
|
69
|
+
export declare function createMockAuth(options: MockAuthOptions, settings: Auth | undefined): MockAuth;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/mock/auth.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAI7C,kCAAkC;AAClC,MAAM,WAAW,QAAQ;IACrB,+DAA+D;IAC/D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,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AM,OAAO,CAAC,MAAM,CAAC,EAC/B,GAAG,CAAC,EAAE,GAAG,GACV,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrB,6FAA6F;IAC7F,OAAO,CACH,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IAC5B,wFAAwF;IACxF,MAAM,IAAI,QAAQ,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,GAAG,SAAS,GAAG,QAAQ,CA8a7F"}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { PROBLEM_CONTENT_TYPE } from "../version.js";
|
|
2
|
+
import { AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, EMAIL_UNVERIFIED_PROBLEM_TYPE, TWO_FACTOR_REQUIRED_PROBLEM_TYPE } from "../constants.js";
|
|
3
|
+
//#region src/mock/auth.ts
|
|
4
|
+
/** The secret that the mock backend gives every two-factor setup. */
|
|
5
|
+
var SECRET = "JBSWY3DPEHPK3PXP";
|
|
6
|
+
var EMAIL = /^[^\s@]+@[^\s@]+$/;
|
|
7
|
+
function json(status, body) {
|
|
8
|
+
return new Response(status === 204 ? null : JSON.stringify(body), {
|
|
9
|
+
status,
|
|
10
|
+
headers: status === 204 ? {} : { "Content-Type": "application/json" }
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function problem(status, title, extra = {}) {
|
|
14
|
+
const body = {
|
|
15
|
+
type: "about:blank",
|
|
16
|
+
title,
|
|
17
|
+
status,
|
|
18
|
+
...extra
|
|
19
|
+
};
|
|
20
|
+
return new Response(JSON.stringify(body), {
|
|
21
|
+
status,
|
|
22
|
+
headers: { "Content-Type": PROBLEM_CONTENT_TYPE }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function invalid(errors) {
|
|
26
|
+
return problem(422, "The given data was invalid.", {
|
|
27
|
+
type: "urn:panneau:problem:validation",
|
|
28
|
+
errors
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function randomToken() {
|
|
32
|
+
return Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
33
|
+
}
|
|
34
|
+
/** Text in base64url, without padding, as WebAuthn's JSON form has binary values. */
|
|
35
|
+
function base64Url(text) {
|
|
36
|
+
return btoa(text).replace(/=+$/, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
37
|
+
}
|
|
38
|
+
/** A credential in the JSON form of the WebAuthn spec: the mock only reads its id. */
|
|
39
|
+
function isCredential(value) {
|
|
40
|
+
return value !== null && typeof value === "object" && typeof value.id === "string" && value.id !== "";
|
|
41
|
+
}
|
|
42
|
+
function recoveryCodes() {
|
|
43
|
+
return Array.from({ length: 8 }, () => `${randomToken().slice(0, 5)}-${randomToken().slice(0, 5)}`);
|
|
44
|
+
}
|
|
45
|
+
function createMockAuth(options, settings) {
|
|
46
|
+
let nextPasskey = 1;
|
|
47
|
+
const accounts = options.users.map((user, index) => ({
|
|
48
|
+
id: user.id ?? String(index + 1),
|
|
49
|
+
name: user.name ?? user.email,
|
|
50
|
+
email: user.email,
|
|
51
|
+
password: user.password,
|
|
52
|
+
emailVerified: user.emailVerified ?? true,
|
|
53
|
+
twoFactor: user.twoFactor === true ? "enabled" : "disabled",
|
|
54
|
+
recoveryCodes: [...user.recoveryCodes ?? []],
|
|
55
|
+
twoFactorRequired: user.twoFactorRequired ?? false,
|
|
56
|
+
passkeys: (user.passkeys ?? []).map((passkey) => ({
|
|
57
|
+
id: String(nextPasskey++),
|
|
58
|
+
credentialId: passkey.id,
|
|
59
|
+
name: passkey.name,
|
|
60
|
+
createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
61
|
+
lastUsedAt: null
|
|
62
|
+
}))
|
|
63
|
+
}));
|
|
64
|
+
const code = options.twoFactorCode ?? "123456";
|
|
65
|
+
let pending = null;
|
|
66
|
+
let current = options.loggedIn === null ? null : (options.loggedIn !== void 0 ? accounts.find((account) => account.email === options.loggedIn) : accounts[0]) ?? null;
|
|
67
|
+
const resets = /* @__PURE__ */ new Map();
|
|
68
|
+
const verifications = /* @__PURE__ */ new Map();
|
|
69
|
+
const find = (email) => typeof email === "string" ? accounts.find((account) => account.email.toLowerCase() === email.toLowerCase()) : void 0;
|
|
70
|
+
const userOf = (account) => ({
|
|
71
|
+
id: account.id,
|
|
72
|
+
name: account.name,
|
|
73
|
+
email: account.email,
|
|
74
|
+
abilities: {}
|
|
75
|
+
});
|
|
76
|
+
const send = (kind, account) => {
|
|
77
|
+
const token = randomToken();
|
|
78
|
+
const query = new URLSearchParams({ token });
|
|
79
|
+
if (kind === "password-reset") {
|
|
80
|
+
resets.set(token, account);
|
|
81
|
+
query.set("email", account.email);
|
|
82
|
+
} else verifications.set(token, account);
|
|
83
|
+
const page = kind === "password-reset" ? AUTH_PAGE_PATHS.resetPassword : AUTH_PAGE_PATHS.verifyEmail;
|
|
84
|
+
options.onMail?.({
|
|
85
|
+
kind,
|
|
86
|
+
to: account.email,
|
|
87
|
+
token,
|
|
88
|
+
path: `${page}?${query.toString()}`
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const routes = {
|
|
92
|
+
"GET session": () => Promise.resolve(current !== null ? json(200, { user: userOf(current) }) : problem(401, "Unauthenticated.")),
|
|
93
|
+
"POST login": async (body) => {
|
|
94
|
+
const { email, password } = await body();
|
|
95
|
+
const account = find(email);
|
|
96
|
+
if (account === void 0 || account.password !== password) return invalid({ email: ["These credentials do not match our records."] });
|
|
97
|
+
if (settings?.twoFactor === true && account.twoFactor === "enabled") {
|
|
98
|
+
pending = { account };
|
|
99
|
+
return json(202, { twoFactor: true });
|
|
100
|
+
}
|
|
101
|
+
current = account;
|
|
102
|
+
return json(200, { user: userOf(account) });
|
|
103
|
+
},
|
|
104
|
+
"POST logout": () => {
|
|
105
|
+
current = null;
|
|
106
|
+
pending = null;
|
|
107
|
+
return Promise.resolve(json(204, null));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (settings?.twoFactor === true) {
|
|
111
|
+
routes["POST two-factor/challenge"] = async (body) => {
|
|
112
|
+
const answer = await body();
|
|
113
|
+
if (pending === null) return invalid({ code: ["The login has expired. Log in again."] });
|
|
114
|
+
const { account } = pending;
|
|
115
|
+
if (typeof answer.recoveryCode === "string") {
|
|
116
|
+
const index = account.recoveryCodes.indexOf(answer.recoveryCode);
|
|
117
|
+
if (index === -1) return invalid({ recoveryCode: ["This recovery code is invalid."] });
|
|
118
|
+
account.recoveryCodes.splice(index, 1);
|
|
119
|
+
} else if (answer.code !== code) return invalid({ code: ["This code is invalid."] });
|
|
120
|
+
pending = null;
|
|
121
|
+
current = account;
|
|
122
|
+
return json(200, { user: userOf(account) });
|
|
123
|
+
};
|
|
124
|
+
routes["POST password/confirm"] = async (body) => {
|
|
125
|
+
const { password } = await body();
|
|
126
|
+
if (current === null) return problem(401, "Unauthenticated.");
|
|
127
|
+
return password === current.password ? json(204, null) : invalid({ password: ["The password is incorrect."] });
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (settings?.passkeys === true) {
|
|
131
|
+
routes["POST passkeys/options"] = () => Promise.resolve(json(200, { options: {
|
|
132
|
+
challenge: randomToken(),
|
|
133
|
+
timeout: 6e4,
|
|
134
|
+
userVerification: "preferred",
|
|
135
|
+
allowCredentials: []
|
|
136
|
+
} }));
|
|
137
|
+
routes["POST passkeys/login"] = async (body) => {
|
|
138
|
+
const { credential } = await body();
|
|
139
|
+
const id = isCredential(credential) ? credential.id : null;
|
|
140
|
+
const account = accounts.find((candidate) => candidate.passkeys.some((passkey) => passkey.credentialId === id));
|
|
141
|
+
const passkey = account?.passkeys.find((candidate) => candidate.credentialId === id);
|
|
142
|
+
if (account === void 0 || passkey === void 0) return invalid({ credential: ["This passkey isn’t known. It may have been removed."] });
|
|
143
|
+
passkey.lastUsedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
144
|
+
pending = null;
|
|
145
|
+
current = account;
|
|
146
|
+
return json(200, { user: userOf(account) });
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (settings?.passwordReset === true) {
|
|
150
|
+
routes["POST password/forgot"] = async (body) => {
|
|
151
|
+
const { email } = await body();
|
|
152
|
+
if (typeof email !== "string" || !EMAIL.test(email)) return invalid({ email: ["The email field must be a valid email address."] });
|
|
153
|
+
const account = find(email);
|
|
154
|
+
if (account !== void 0) send("password-reset", account);
|
|
155
|
+
return json(204, null);
|
|
156
|
+
};
|
|
157
|
+
routes["POST password/reset"] = async (body) => {
|
|
158
|
+
const { token, email, password } = await body();
|
|
159
|
+
const account = typeof token === "string" ? resets.get(token) : void 0;
|
|
160
|
+
if (account === void 0 || find(email) !== account) return invalid({ email: ["This password reset token is invalid."] });
|
|
161
|
+
if (typeof password !== "string" || password.length < 8) return invalid({ password: ["The password field must be at least 8 characters."] });
|
|
162
|
+
account.password = password;
|
|
163
|
+
resets.delete(token);
|
|
164
|
+
return json(204, null);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (settings?.emailVerification === true) {
|
|
168
|
+
routes["POST email/verification"] = () => {
|
|
169
|
+
if (current === null) return Promise.resolve(problem(401, "Unauthenticated."));
|
|
170
|
+
if (!current.emailVerified) send("email-verification", current);
|
|
171
|
+
return Promise.resolve(json(204, null));
|
|
172
|
+
};
|
|
173
|
+
routes["POST email/verify"] = async (body) => {
|
|
174
|
+
const { token } = await body();
|
|
175
|
+
const account = typeof token === "string" ? verifications.get(token) : void 0;
|
|
176
|
+
if (account === void 0) return invalid({ token: ["This verification link is invalid or has expired."] });
|
|
177
|
+
account.emailVerified = true;
|
|
178
|
+
verifications.delete(token);
|
|
179
|
+
return json(204, null);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const conflict = (title) => problem(409, title);
|
|
183
|
+
const twoFactorRoutes = {
|
|
184
|
+
GET: (account) => json(200, {
|
|
185
|
+
status: account.twoFactor,
|
|
186
|
+
required: account.twoFactorRequired
|
|
187
|
+
}),
|
|
188
|
+
POST: (account) => {
|
|
189
|
+
if (account.twoFactor === "enabled") return conflict("Two-factor authentication is already on.");
|
|
190
|
+
account.twoFactor = "pending";
|
|
191
|
+
return json(200, {
|
|
192
|
+
secret: SECRET,
|
|
193
|
+
otpauthUrl: `otpauth://totp/${encodeURIComponent(`Panneau:${account.email}`)}?secret=${SECRET}&issuer=Panneau`
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
DELETE: (account) => {
|
|
197
|
+
if (account.twoFactorRequired) return conflict("Two-factor authentication is required for this account.");
|
|
198
|
+
account.twoFactor = "disabled";
|
|
199
|
+
account.recoveryCodes = [];
|
|
200
|
+
return json(204, null);
|
|
201
|
+
},
|
|
202
|
+
"POST confirm": async (account, body) => {
|
|
203
|
+
if (account.twoFactor !== "pending") return conflict("Two-factor authentication isn’t being set up.");
|
|
204
|
+
if ((await body()).code !== code) return invalid({ code: ["This code is invalid."] });
|
|
205
|
+
account.twoFactor = "enabled";
|
|
206
|
+
account.recoveryCodes = recoveryCodes();
|
|
207
|
+
return json(200, { recoveryCodes: account.recoveryCodes });
|
|
208
|
+
},
|
|
209
|
+
"POST recovery-codes": (account) => {
|
|
210
|
+
if (account.twoFactor !== "enabled") return conflict("Two-factor authentication is off.");
|
|
211
|
+
account.recoveryCodes = recoveryCodes();
|
|
212
|
+
return json(200, { recoveryCodes: account.recoveryCodes });
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const accountRoutes = {
|
|
216
|
+
GET: (account) => json(200, { data: userOf(account) }),
|
|
217
|
+
PATCH: async (account, body) => {
|
|
218
|
+
const { name, email } = await body();
|
|
219
|
+
const errors = {};
|
|
220
|
+
if (typeof name !== "string" || name.trim() === "") errors.name = ["The name field is required."];
|
|
221
|
+
if (typeof email !== "string" || !EMAIL.test(email)) errors.email = ["The email field must be a valid email address."];
|
|
222
|
+
else if (find(email) !== void 0 && find(email) !== account) errors.email = ["The email has already been taken."];
|
|
223
|
+
if (Object.keys(errors).length > 0) return invalid(errors);
|
|
224
|
+
const changed = email.toLowerCase() !== account.email.toLowerCase();
|
|
225
|
+
account.name = name;
|
|
226
|
+
account.email = email;
|
|
227
|
+
if (changed && settings?.emailVerification === true) {
|
|
228
|
+
account.emailVerified = false;
|
|
229
|
+
send("email-verification", account);
|
|
230
|
+
}
|
|
231
|
+
return json(200, { data: userOf(account) });
|
|
232
|
+
},
|
|
233
|
+
"PUT password": async (account, body) => {
|
|
234
|
+
const { currentPassword, password } = await body();
|
|
235
|
+
if (currentPassword !== account.password) return invalid({ currentPassword: ["The provided password does not match your current password."] });
|
|
236
|
+
if (typeof password !== "string" || password.length < 8) return invalid({ password: ["The password field must be at least 8 characters."] });
|
|
237
|
+
account.password = password;
|
|
238
|
+
return json(204, null);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const redirectToProvider = (id, url) => {
|
|
242
|
+
if (!(settings?.providers ?? []).some((provider) => provider.id === id)) return problem(404, "Not found.");
|
|
243
|
+
const next = url?.searchParams.get("next") ?? "/";
|
|
244
|
+
const local = next.startsWith("/") && !next.startsWith("//") ? next : "/";
|
|
245
|
+
const account = find(options.providerUsers?.[id]);
|
|
246
|
+
if (account === void 0) return new Response(null, {
|
|
247
|
+
status: 302,
|
|
248
|
+
headers: { Location: `/?${AUTH_ERROR_PARAM}=access` }
|
|
249
|
+
});
|
|
250
|
+
current = account;
|
|
251
|
+
return new Response(null, {
|
|
252
|
+
status: 302,
|
|
253
|
+
headers: { Location: local }
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
const passkeyOf = ({ id, name, createdAt, lastUsedAt }) => ({
|
|
257
|
+
id,
|
|
258
|
+
name,
|
|
259
|
+
authenticator: null,
|
|
260
|
+
createdAt,
|
|
261
|
+
lastUsedAt
|
|
262
|
+
});
|
|
263
|
+
const passkeyRoutes = async (account, method, segments, body) => {
|
|
264
|
+
const [, second] = segments;
|
|
265
|
+
if (method === "GET" && second === void 0) return json(200, { data: account.passkeys.map(passkeyOf) });
|
|
266
|
+
if (method === "POST" && second === "options") return json(200, { options: {
|
|
267
|
+
challenge: randomToken(),
|
|
268
|
+
rp: { name: "Panneau" },
|
|
269
|
+
user: {
|
|
270
|
+
id: base64Url(account.id),
|
|
271
|
+
name: account.email,
|
|
272
|
+
displayName: account.name
|
|
273
|
+
},
|
|
274
|
+
pubKeyCredParams: [{
|
|
275
|
+
type: "public-key",
|
|
276
|
+
alg: -7
|
|
277
|
+
}, {
|
|
278
|
+
type: "public-key",
|
|
279
|
+
alg: -257
|
|
280
|
+
}],
|
|
281
|
+
authenticatorSelection: {
|
|
282
|
+
residentKey: "required",
|
|
283
|
+
userVerification: "preferred"
|
|
284
|
+
},
|
|
285
|
+
excludeCredentials: account.passkeys.map((passkey) => ({
|
|
286
|
+
type: "public-key",
|
|
287
|
+
id: passkey.credentialId
|
|
288
|
+
})),
|
|
289
|
+
timeout: 6e4
|
|
290
|
+
} });
|
|
291
|
+
if (method === "POST" && second === void 0) {
|
|
292
|
+
const { name, credential } = await body();
|
|
293
|
+
if (!isCredential(credential)) return invalid({ credential: ["This passkey could not be added. Try again."] });
|
|
294
|
+
const passkey = {
|
|
295
|
+
id: String(nextPasskey++),
|
|
296
|
+
credentialId: credential.id,
|
|
297
|
+
name: typeof name === "string" && name.trim() !== "" ? name : "Passkey",
|
|
298
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
299
|
+
lastUsedAt: null
|
|
300
|
+
};
|
|
301
|
+
account.passkeys.push(passkey);
|
|
302
|
+
return json(201, { data: passkeyOf(passkey) });
|
|
303
|
+
}
|
|
304
|
+
const index = account.passkeys.findIndex((passkey) => passkey.id === second);
|
|
305
|
+
if (method === "DELETE" && segments.length === 2 && index !== -1) {
|
|
306
|
+
account.passkeys.splice(index, 1);
|
|
307
|
+
return json(204, null);
|
|
308
|
+
}
|
|
309
|
+
return problem(404, "Not found.");
|
|
310
|
+
};
|
|
311
|
+
const refuseUnverified = (account) => settings?.emailVerification === true && !account.emailVerified ? problem(403, "Your email address is not verified.", { type: EMAIL_UNVERIFIED_PROBLEM_TYPE }) : null;
|
|
312
|
+
return {
|
|
313
|
+
user: () => current !== null ? userOf(current) : null,
|
|
314
|
+
account: (segments, method, readBody) => {
|
|
315
|
+
const twoFactor = segments[0] === "two-factor" && settings?.twoFactor === true;
|
|
316
|
+
const passkeys = segments[0] === "passkeys" && settings?.passkeys === true;
|
|
317
|
+
if (!twoFactor && !passkeys && settings?.account !== true) return null;
|
|
318
|
+
if (current === null) return Promise.resolve(problem(401, "Unauthenticated."));
|
|
319
|
+
if (passkeys) {
|
|
320
|
+
const refusedPasskeys = refuse();
|
|
321
|
+
return refusedPasskeys !== null ? Promise.resolve(refusedPasskeys) : passkeyRoutes(current, method, segments, readBody);
|
|
322
|
+
}
|
|
323
|
+
const refused = twoFactor ? refuseUnverified(current) : refuse();
|
|
324
|
+
const route = twoFactor ? twoFactorRoutes[[method, ...segments.slice(1)].join(" ")] : accountRoutes[[method, ...segments].join(" ")];
|
|
325
|
+
if (refused !== null || route === void 0) return Promise.resolve(refused ?? problem(404, "Not found."));
|
|
326
|
+
return Promise.resolve(route(current, readBody));
|
|
327
|
+
},
|
|
328
|
+
answer: (segments, method, readBody, url) => {
|
|
329
|
+
if (method === "GET" && segments.length === 3 && segments[0] === "providers" && segments[2] === "redirect") return Promise.resolve(redirectToProvider(segments[1] ?? "", url));
|
|
330
|
+
const route = routes[`${method} ${segments.join("/")}`];
|
|
331
|
+
return route !== void 0 ? route(readBody) : Promise.resolve(problem(404, "Not found."));
|
|
332
|
+
},
|
|
333
|
+
refuse
|
|
334
|
+
};
|
|
335
|
+
function refuse() {
|
|
336
|
+
if (current === null) return problem(401, "Unauthenticated.");
|
|
337
|
+
const unverified = refuseUnverified(current);
|
|
338
|
+
if (unverified !== null) return unverified;
|
|
339
|
+
if (settings?.twoFactor === true && current.twoFactorRequired && current.twoFactor !== "enabled") return problem(403, "Two-factor authentication is required for this account.", { type: TWO_FACTOR_REQUIRED_PROBLEM_TYPE });
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
export { createMockAuth };
|
|
345
|
+
|
|
346
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","names":[],"sources":["../../src/mock/auth.ts"],"sourcesContent":["import {\n AUTH_ERROR_PARAM,\n AUTH_PAGE_PATHS,\n EMAIL_UNVERIFIED_PROBLEM_TYPE,\n TWO_FACTOR_REQUIRED_PROBLEM_TYPE,\n} from '../constants';\nimport type { Auth, User } from '../schemas';\nimport type { Problem, TwoFactorStatus } from '../schemas/api';\nimport { PROBLEM_CONTENT_TYPE } from '../version';\n\n/** A user of the mock backend. */\nexport interface MockUser {\n /** Defaults to the position of the user in `users`, from 1. */\n id?: string;\n /** Defaults to the email. */\n name?: string;\n email: string;\n password: string;\n /** Whether the email address is verified, for `auth.emailVerification`. Defaults to true. */\n emailVerified?: boolean;\n /**\n * Whether the user has two-factor authentication, for `auth.twoFactor`: their password login\n * then asks for `twoFactorCode` or a recovery code. Defaults to false.\n */\n twoFactor?: boolean;\n /** Recovery codes of a user with `twoFactor`. Defaults to none. */\n recoveryCodes?: string[];\n /** Whether the backend requires two-factor authentication for the user. Defaults to false. */\n twoFactorRequired?: boolean;\n /**\n * The passkeys of the user, for `auth.passkeys`: the `id` of their credential, and a name. The\n * mock doesn't check signatures: a credential with one of these ids logs in.\n */\n passkeys?: { id: string; name: string }[];\n}\n\n/** An email that the mock backend \"sends\", with the path of its link under the app's base path. */\nexport interface MockMail {\n kind: 'password-reset' | 'email-verification';\n to: string;\n token: string;\n /** The page of the app that the link opens, with its query: `auth/reset-password?token=…`. */\n path: string;\n}\n\n/**\n * The auth of the mock backend: its users, and who is logged in. With it, the routes of the\n * `panneau` auth mode answer (`/auth/login`, `/auth/logout`, `/auth/session`, and those of\n * `auth.passwordReset` and `auth.emailVerification`), and the other routes answer `401` to\n * guests.\n */\nexport interface MockAuthOptions {\n users: MockUser[];\n /** The email of the user logged in at the start. Defaults to the first user; `null`: a guest. */\n loggedIn?: string | null;\n /** Called with each email the backend sends: there is no mailbox. */\n onMail?: (mail: MockMail) => void;\n /** The code of the authenticator app of every user, for `auth.twoFactor`. Defaults to `123456`. */\n twoFactorCode?: string;\n /**\n * The email of the user that each OAuth provider of `auth.providers` logs in, at once, when the\n * app goes to its `redirect` (decision 0052). A provider without one fails with `access`.\n */\n providerUsers?: Record<string, string>;\n}\n\ntype Values = Record<string, unknown>;\n\ninterface Account {\n id: string;\n name: string;\n email: string;\n password: string;\n emailVerified: boolean;\n twoFactor: TwoFactorStatus['status'];\n recoveryCodes: string[];\n twoFactorRequired: boolean;\n passkeys: StoredPasskey[];\n}\n\ninterface StoredPasskey {\n id: string;\n credentialId: string;\n name: string;\n createdAt: string;\n lastUsedAt: string | null;\n}\n\n/** The secret that the mock backend gives every two-factor setup. */\nconst SECRET = 'JBSWY3DPEHPK3PXP';\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+$/;\n\nfunction json(status: number, body: unknown): Response {\n return new Response(status === 204 ? null : JSON.stringify(body), {\n status,\n headers: status === 204 ? {} : { 'Content-Type': 'application/json' },\n });\n}\n\nfunction problem(status: number, title: string, extra: Partial<Problem> = {}): Response {\n const body: Problem = { type: 'about:blank', title, status, ...extra };\n return new Response(JSON.stringify(body), {\n status,\n headers: { 'Content-Type': PROBLEM_CONTENT_TYPE },\n });\n}\n\nfunction invalid(errors: Record<string, string[]>): Response {\n return problem(422, 'The given data was invalid.', {\n type: 'urn:panneau:problem:validation',\n errors,\n });\n}\n\nfunction randomToken(): string {\n return Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) =>\n byte.toString(16).padStart(2, '0'),\n ).join('');\n}\n\n/** Text in base64url, without padding, as WebAuthn's JSON form has binary values. */\nfunction base64Url(text: string): string {\n return btoa(text).replace(/=+$/, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\n\n/** A credential in the JSON form of the WebAuthn spec: the mock only reads its id. */\nfunction isCredential(value: unknown): value is { id: string } {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Record<string, unknown>).id === 'string' &&\n (value as Record<string, unknown>).id !== ''\n );\n}\n\nfunction recoveryCodes(): string[] {\n return Array.from(\n { length: 8 },\n () => `${randomToken().slice(0, 5)}-${randomToken().slice(0, 5)}`,\n );\n}\n\nexport interface MockAuth {\n /** The current user, as the definition and `/auth/session` give it. */\n user(): User | null;\n /** The answer of a route of `/auth/…`, without its first segment. */\n answer(\n segments: string[],\n method: string,\n readBody: () => Promise<Values>,\n url?: URL,\n ): Promise<Response>;\n /** The answer of a route of `/account/…`, without its first segment, or null for another. */\n account(\n segments: string[],\n method: string,\n readBody: () => Promise<Values>,\n ): Promise<Response> | null;\n /** The answer to a request of another route by the current user, when it is refused. */\n refuse(): Response | null;\n}\n\nexport function createMockAuth(options: MockAuthOptions, settings: Auth | undefined): MockAuth {\n let nextPasskey = 1;\n const accounts: Account[] = options.users.map((user, index) => ({\n id: user.id ?? String(index + 1),\n name: user.name ?? user.email,\n email: user.email,\n password: user.password,\n emailVerified: user.emailVerified ?? true,\n twoFactor: user.twoFactor === true ? 'enabled' : 'disabled',\n recoveryCodes: [...(user.recoveryCodes ?? [])],\n twoFactorRequired: user.twoFactorRequired ?? false,\n passkeys: (user.passkeys ?? []).map((passkey) => ({\n id: String(nextPasskey++),\n credentialId: passkey.id,\n name: passkey.name,\n createdAt: new Date(0).toISOString(),\n lastUsedAt: null,\n })),\n }));\n const code = options.twoFactorCode ?? '123456';\n // A password login that waits for its second factor\n let pending: { account: Account } | null = null;\n let current: Account | null =\n options.loggedIn === null\n ? null\n : ((options.loggedIn !== undefined\n ? accounts.find((account) => account.email === options.loggedIn)\n : accounts[0]) ?? null);\n // Tokens of the links sent, to their account\n const resets = new Map<string, Account>();\n const verifications = new Map<string, Account>();\n\n const find = (email: unknown) =>\n typeof email === 'string'\n ? accounts.find((account) => account.email.toLowerCase() === email.toLowerCase())\n : undefined;\n const userOf = (account: Account): User => ({\n id: account.id,\n name: account.name,\n email: account.email,\n abilities: {},\n });\n const send = (kind: MockMail['kind'], account: Account) => {\n const token = randomToken();\n const query = new URLSearchParams({ token });\n if (kind === 'password-reset') {\n resets.set(token, account);\n query.set('email', account.email);\n } else {\n verifications.set(token, account);\n }\n const page =\n kind === 'password-reset' ? AUTH_PAGE_PATHS.resetPassword : AUTH_PAGE_PATHS.verifyEmail;\n options.onMail?.({ kind, to: account.email, token, path: `${page}?${query.toString()}` });\n };\n\n const routes: Record<string, (body: () => Promise<Values>) => Promise<Response>> = {\n 'GET session': () =>\n Promise.resolve(\n current !== null\n ? json(200, { user: userOf(current) })\n : problem(401, 'Unauthenticated.'),\n ),\n 'POST login': async (body) => {\n const { email, password } = await body();\n const account = find(email);\n if (account === undefined || account.password !== password) {\n return invalid({ email: ['These credentials do not match our records.'] });\n }\n if (settings?.twoFactor === true && account.twoFactor === 'enabled') {\n pending = { account };\n return json(202, { twoFactor: true });\n }\n current = account;\n return json(200, { user: userOf(account) });\n },\n 'POST logout': () => {\n current = null;\n pending = null;\n return Promise.resolve(json(204, null));\n },\n };\n if (settings?.twoFactor === true) {\n routes['POST two-factor/challenge'] = async (body) => {\n const answer = await body();\n if (pending === null) {\n return invalid({ code: ['The login has expired. Log in again.'] });\n }\n const { account } = pending;\n if (typeof answer.recoveryCode === 'string') {\n const index = account.recoveryCodes.indexOf(answer.recoveryCode);\n if (index === -1) {\n return invalid({ recoveryCode: ['This recovery code is invalid.'] });\n }\n account.recoveryCodes.splice(index, 1);\n } else if (answer.code !== code) {\n return invalid({ code: ['This code is invalid.'] });\n }\n pending = null;\n current = account;\n return json(200, { user: userOf(account) });\n };\n routes['POST password/confirm'] = async (body) => {\n const { password } = await body();\n if (current === null) {\n return problem(401, 'Unauthenticated.');\n }\n return password === current.password\n ? json(204, null)\n : invalid({ password: ['The password is incorrect.'] });\n };\n }\n if (settings?.passkeys === true) {\n routes['POST passkeys/options'] = () =>\n Promise.resolve(\n json(200, {\n options: {\n challenge: randomToken(),\n timeout: 60000,\n userVerification: 'preferred',\n allowCredentials: [],\n },\n }),\n );\n routes['POST passkeys/login'] = async (body) => {\n const { credential } = await body();\n const id = isCredential(credential) ? credential.id : null;\n const account = accounts.find((candidate) =>\n candidate.passkeys.some((passkey) => passkey.credentialId === id),\n );\n const passkey = account?.passkeys.find((candidate) => candidate.credentialId === id);\n if (account === undefined || passkey === undefined) {\n return invalid({\n credential: ['This passkey isn’t known. It may have been removed.'],\n });\n }\n passkey.lastUsedAt = new Date().toISOString();\n pending = null;\n current = account;\n return json(200, { user: userOf(account) });\n };\n }\n if (settings?.passwordReset === true) {\n routes['POST password/forgot'] = async (body) => {\n const { email } = await body();\n if (typeof email !== 'string' || !EMAIL.test(email)) {\n return invalid({ email: ['The email field must be a valid email address.'] });\n }\n const account = find(email);\n if (account !== undefined) {\n send('password-reset', account);\n }\n return json(204, null);\n };\n routes['POST password/reset'] = async (body) => {\n const { token, email, password } = await body();\n const account = typeof token === 'string' ? resets.get(token) : undefined;\n if (account === undefined || find(email) !== account) {\n return invalid({ email: ['This password reset token is invalid.'] });\n }\n if (typeof password !== 'string' || password.length < 8) {\n return invalid({ password: ['The password field must be at least 8 characters.'] });\n }\n account.password = password;\n resets.delete(token as string);\n return json(204, null);\n };\n }\n if (settings?.emailVerification === true) {\n routes['POST email/verification'] = () => {\n if (current === null) {\n return Promise.resolve(problem(401, 'Unauthenticated.'));\n }\n if (!current.emailVerified) {\n send('email-verification', current);\n }\n return Promise.resolve(json(204, null));\n };\n routes['POST email/verify'] = async (body) => {\n const { token } = await body();\n const account = typeof token === 'string' ? verifications.get(token) : undefined;\n if (account === undefined) {\n return invalid({ token: ['This verification link is invalid or has expired.'] });\n }\n account.emailVerified = true;\n verifications.delete(token as string);\n return json(204, null);\n };\n }\n\n const conflict = (title: string) => problem(409, title);\n const twoFactorRoutes: Record<\n string,\n (account: Account, body: () => Promise<Values>) => Promise<Response> | Response\n > = {\n GET: (account) =>\n json(200, { status: account.twoFactor, required: account.twoFactorRequired }),\n POST: (account) => {\n if (account.twoFactor === 'enabled') {\n return conflict('Two-factor authentication is already on.');\n }\n account.twoFactor = 'pending';\n const label = encodeURIComponent(`Panneau:${account.email}`);\n return json(200, {\n secret: SECRET,\n otpauthUrl: `otpauth://totp/${label}?secret=${SECRET}&issuer=Panneau`,\n });\n },\n DELETE: (account) => {\n if (account.twoFactorRequired) {\n return conflict('Two-factor authentication is required for this account.');\n }\n account.twoFactor = 'disabled';\n account.recoveryCodes = [];\n return json(204, null);\n },\n 'POST confirm': async (account, body) => {\n if (account.twoFactor !== 'pending') {\n return conflict('Two-factor authentication isn’t being set up.');\n }\n if ((await body()).code !== code) {\n return invalid({ code: ['This code is invalid.'] });\n }\n account.twoFactor = 'enabled';\n account.recoveryCodes = recoveryCodes();\n return json(200, { recoveryCodes: account.recoveryCodes });\n },\n 'POST recovery-codes': (account) => {\n if (account.twoFactor !== 'enabled') {\n return conflict('Two-factor authentication is off.');\n }\n account.recoveryCodes = recoveryCodes();\n return json(200, { recoveryCodes: account.recoveryCodes });\n },\n };\n const accountRoutes: Record<\n string,\n (account: Account, body: () => Promise<Values>) => Promise<Response> | Response\n > = {\n GET: (account) => json(200, { data: userOf(account) }),\n PATCH: async (account, body) => {\n const { name, email } = await body();\n const errors: Record<string, string[]> = {};\n if (typeof name !== 'string' || name.trim() === '') {\n errors.name = ['The name field is required.'];\n }\n if (typeof email !== 'string' || !EMAIL.test(email)) {\n errors.email = ['The email field must be a valid email address.'];\n } else if (find(email) !== undefined && find(email) !== account) {\n errors.email = ['The email has already been taken.'];\n }\n if (Object.keys(errors).length > 0) {\n return invalid(errors);\n }\n const changed = (email as string).toLowerCase() !== account.email.toLowerCase();\n account.name = name as string;\n account.email = email as string;\n if (changed && settings?.emailVerification === true) {\n account.emailVerified = false;\n send('email-verification', account);\n }\n return json(200, { data: userOf(account) });\n },\n 'PUT password': async (account, body) => {\n const { currentPassword, password } = await body();\n if (currentPassword !== account.password) {\n return invalid({\n currentPassword: [\n 'The provided password does not match your current password.',\n ],\n });\n }\n if (typeof password !== 'string' || password.length < 8) {\n return invalid({ password: ['The password field must be at least 8 characters.'] });\n }\n account.password = password;\n return json(204, null);\n },\n };\n // A provider that logs in at once: it goes to `next`, or comes back with `authError`\n const redirectToProvider = (id: string, url: URL | undefined) => {\n if (!(settings?.providers ?? []).some((provider) => provider.id === id)) {\n return problem(404, 'Not found.');\n }\n const next = url?.searchParams.get('next') ?? '/';\n const local = next.startsWith('/') && !next.startsWith('//') ? next : '/';\n const account = find(options.providerUsers?.[id]);\n if (account === undefined) {\n return new Response(null, {\n status: 302,\n headers: { Location: `/?${AUTH_ERROR_PARAM}=access` },\n });\n }\n current = account;\n return new Response(null, { status: 302, headers: { Location: local } });\n };\n const passkeyOf = ({ id, name, createdAt, lastUsedAt }: StoredPasskey) => ({\n id,\n name,\n authenticator: null,\n createdAt,\n lastUsedAt,\n });\n const passkeyRoutes = async (\n account: Account,\n method: string,\n segments: string[],\n body: () => Promise<Values>,\n ): Promise<Response> => {\n const [, second] = segments;\n if (method === 'GET' && second === undefined) {\n return json(200, { data: account.passkeys.map(passkeyOf) });\n }\n if (method === 'POST' && second === 'options') {\n return json(200, {\n options: {\n challenge: randomToken(),\n rp: { name: 'Panneau' },\n user: {\n id: base64Url(account.id),\n name: account.email,\n displayName: account.name,\n },\n pubKeyCredParams: [\n { type: 'public-key', alg: -7 },\n { type: 'public-key', alg: -257 },\n ],\n authenticatorSelection: {\n residentKey: 'required',\n userVerification: 'preferred',\n },\n excludeCredentials: account.passkeys.map((passkey) => ({\n type: 'public-key',\n id: passkey.credentialId,\n })),\n timeout: 60000,\n },\n });\n }\n if (method === 'POST' && second === undefined) {\n const { name, credential } = await body();\n if (!isCredential(credential)) {\n return invalid({ credential: ['This passkey could not be added. Try again.'] });\n }\n const passkey: StoredPasskey = {\n id: String(nextPasskey++),\n credentialId: credential.id,\n name: typeof name === 'string' && name.trim() !== '' ? name : 'Passkey',\n createdAt: new Date().toISOString(),\n lastUsedAt: null,\n };\n account.passkeys.push(passkey);\n return json(201, { data: passkeyOf(passkey) });\n }\n const index = account.passkeys.findIndex((passkey) => passkey.id === second);\n if (method === 'DELETE' && segments.length === 2 && index !== -1) {\n account.passkeys.splice(index, 1);\n return json(204, null);\n }\n return problem(404, 'Not found.');\n };\n const refuseUnverified = (account: Account) =>\n settings?.emailVerification === true && !account.emailVerified\n ? problem(403, 'Your email address is not verified.', {\n type: EMAIL_UNVERIFIED_PROBLEM_TYPE,\n })\n : null;\n\n return {\n user: () => (current !== null ? userOf(current) : null),\n account: (segments, method, readBody) => {\n const twoFactor = segments[0] === 'two-factor' && settings?.twoFactor === true;\n const passkeys = segments[0] === 'passkeys' && settings?.passkeys === true;\n if (!twoFactor && !passkeys && settings?.account !== true) {\n return null;\n }\n if (current === null) {\n return Promise.resolve(problem(401, 'Unauthenticated.'));\n }\n if (passkeys) {\n const refusedPasskeys = refuse();\n return refusedPasskeys !== null\n ? Promise.resolve(refusedPasskeys)\n : passkeyRoutes(current, method, segments, readBody);\n }\n const refused = twoFactor ? refuseUnverified(current) : refuse();\n const route = twoFactor\n ? twoFactorRoutes[[method, ...segments.slice(1)].join(' ')]\n : accountRoutes[[method, ...segments].join(' ')];\n if (refused !== null || route === undefined) {\n return Promise.resolve(refused ?? problem(404, 'Not found.'));\n }\n return Promise.resolve(route(current, readBody));\n },\n answer: (segments, method, readBody, url) => {\n if (\n method === 'GET' &&\n segments.length === 3 &&\n segments[0] === 'providers' &&\n segments[2] === 'redirect'\n ) {\n return Promise.resolve(redirectToProvider(segments[1] ?? '', url));\n }\n const route = routes[`${method} ${segments.join('/')}`];\n return route !== undefined\n ? route(readBody)\n : Promise.resolve(problem(404, 'Not found.'));\n },\n refuse,\n };\n\n function refuse(): Response | null {\n if (current === null) {\n return problem(401, 'Unauthenticated.');\n }\n const unverified = refuseUnverified(current);\n if (unverified !== null) {\n return unverified;\n }\n if (\n settings?.twoFactor === true &&\n current.twoFactorRequired &&\n current.twoFactor !== 'enabled'\n ) {\n return problem(403, 'Two-factor authentication is required for this account.', {\n type: TWO_FACTOR_REQUIRED_PROBLEM_TYPE,\n });\n }\n return null;\n }\n}\n"],"mappings":";;;;AAyFA,IAAM,SAAS;AAEf,IAAM,QAAQ;AAEd,SAAS,KAAK,QAAgB,MAAyB;CACnD,OAAO,IAAI,SAAS,WAAW,MAAM,OAAO,KAAK,UAAU,IAAI,GAAG;EAC9D;EACA,SAAS,WAAW,MAAM,CAAC,IAAI,EAAE,gBAAgB,mBAAmB;CACxE,CAAC;AACL;AAEA,SAAS,QAAQ,QAAgB,OAAe,QAA0B,CAAC,GAAa;CACpF,MAAM,OAAgB;EAAE,MAAM;EAAe;EAAO;EAAQ,GAAG;CAAM;CACrE,OAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;EACtC;EACA,SAAS,EAAE,gBAAgB,qBAAqB;CACpD,CAAC;AACL;AAEA,SAAS,QAAQ,QAA4C;CACzD,OAAO,QAAQ,KAAK,+BAA+B;EAC/C,MAAM;EACN;CACJ,CAAC;AACL;AAEA,SAAS,cAAsB;CAC3B,OAAO,MAAM,KAAK,OAAO,gCAAgB,IAAI,WAAW,EAAE,CAAC,IAAI,SAC3D,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CACrC,CAAC,CAAC,KAAK,EAAE;AACb;;AAGA,SAAS,UAAU,MAAsB;CACrC,OAAO,KAAK,IAAI,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG;AAC/E;;AAGA,SAAS,aAAa,OAAyC;CAC3D,OACI,UAAU,QACV,OAAO,UAAU,YACjB,OA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