@panneau/protocol 5.0.0-alpha.3 → 5.0.0-alpha.31

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 (147) hide show
  1. package/dist/addresses.d.ts +23 -0
  2. package/dist/addresses.d.ts.map +1 -0
  3. package/dist/addresses.js +52 -0
  4. package/dist/addresses.js.map +1 -0
  5. package/dist/compound.d.ts +20 -0
  6. package/dist/compound.d.ts.map +1 -0
  7. package/dist/compound.js +27 -0
  8. package/dist/compound.js.map +1 -0
  9. package/dist/conditions.d.ts +1 -1
  10. package/dist/conformance/index.d.ts +6 -0
  11. package/dist/conformance/index.d.ts.map +1 -1
  12. package/dist/conformance/index.js +801 -11
  13. package/dist/conformance/index.js.map +1 -1
  14. package/dist/constants.d.ts +108 -2
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js +181 -3
  17. package/dist/constants.js.map +1 -1
  18. package/dist/context.d.ts +15 -0
  19. package/dist/context.d.ts.map +1 -0
  20. package/dist/context.js +34 -0
  21. package/dist/context.js.map +1 -0
  22. package/dist/currencies.d.ts +22 -0
  23. package/dist/currencies.d.ts.map +1 -0
  24. package/dist/currencies.js +231 -0
  25. package/dist/currencies.js.map +1 -0
  26. package/dist/index.d.ts +4 -4
  27. package/dist/index.js +19 -8
  28. package/dist/libraries.d.ts +33 -0
  29. package/dist/libraries.d.ts.map +1 -0
  30. package/dist/libraries.js +59 -0
  31. package/dist/libraries.js.map +1 -0
  32. package/dist/links.d.ts +38 -0
  33. package/dist/links.d.ts.map +1 -0
  34. package/dist/links.js +65 -0
  35. package/dist/links.js.map +1 -0
  36. package/dist/lint.d.ts +4 -3
  37. package/dist/lint.d.ts.map +1 -1
  38. package/dist/lint.js +168 -7
  39. package/dist/lint.js.map +1 -1
  40. package/dist/mock/auth.d.ts +71 -0
  41. package/dist/mock/auth.d.ts.map +1 -0
  42. package/dist/mock/auth.js +346 -0
  43. package/dist/mock/auth.js.map +1 -0
  44. package/dist/mock/example.d.ts +3 -2
  45. package/dist/mock/example.d.ts.map +1 -1
  46. package/dist/mock/example.js +241 -144
  47. package/dist/mock/example.js.map +1 -1
  48. package/dist/mock/index.d.ts +79 -7
  49. package/dist/mock/index.d.ts.map +1 -1
  50. package/dist/mock/index.js +603 -38
  51. package/dist/mock/index.js.map +1 -1
  52. package/dist/openapi.d.ts.map +1 -1
  53. package/dist/openapi.js +392 -144
  54. package/dist/openapi.js.map +1 -1
  55. package/dist/problem.d.ts +1 -1
  56. package/dist/query.d.ts +18 -0
  57. package/dist/query.d.ts.map +1 -1
  58. package/dist/query.js +34 -8
  59. package/dist/query.js.map +1 -1
  60. package/dist/resourceTypes.d.ts +39 -0
  61. package/dist/resourceTypes.d.ts.map +1 -0
  62. package/dist/resourceTypes.js +34 -0
  63. package/dist/resourceTypes.js.map +1 -0
  64. package/dist/rules.d.ts +18 -5
  65. package/dist/rules.d.ts.map +1 -1
  66. package/dist/rules.js +233 -15
  67. package/dist/rules.js.map +1 -1
  68. package/dist/runtime/index.d.ts +20 -10
  69. package/dist/runtime/index.d.ts.map +1 -1
  70. package/dist/runtime/index.js +13 -3
  71. package/dist/schemas/action.d.ts +118 -10
  72. package/dist/schemas/action.d.ts.map +1 -1
  73. package/dist/schemas/action.js +20 -3
  74. package/dist/schemas/action.js.map +1 -1
  75. package/dist/schemas/api.d.ts +334 -42
  76. package/dist/schemas/api.d.ts.map +1 -1
  77. package/dist/schemas/api.js +194 -34
  78. package/dist/schemas/api.js.map +1 -1
  79. package/dist/schemas/boot.d.ts +25 -1
  80. package/dist/schemas/boot.d.ts.map +1 -1
  81. package/dist/schemas/boot.js +2 -1
  82. package/dist/schemas/boot.js.map +1 -1
  83. package/dist/schemas/common.d.ts +1 -0
  84. package/dist/schemas/common.d.ts.map +1 -1
  85. package/dist/schemas/common.js +2 -1
  86. package/dist/schemas/common.js.map +1 -1
  87. package/dist/schemas/definition.d.ts +341 -28
  88. package/dist/schemas/definition.d.ts.map +1 -1
  89. package/dist/schemas/definition.js +65 -19
  90. package/dist/schemas/definition.js.map +1 -1
  91. package/dist/schemas/field.d.ts +357 -2
  92. package/dist/schemas/field.d.ts.map +1 -1
  93. package/dist/schemas/field.js +160 -20
  94. package/dist/schemas/field.js.map +1 -1
  95. package/dist/schemas/index.d.ts +1429 -80
  96. package/dist/schemas/index.d.ts.map +1 -1
  97. package/dist/schemas/index.js +60 -10
  98. package/dist/schemas/index.js.map +1 -1
  99. package/dist/schemas/jsonRules.d.ts +83 -0
  100. package/dist/schemas/jsonRules.d.ts.map +1 -0
  101. package/dist/schemas/jsonRules.js +46 -0
  102. package/dist/schemas/jsonRules.js.map +1 -0
  103. package/dist/schemas/layout.d.ts +2 -1
  104. package/dist/schemas/layout.d.ts.map +1 -1
  105. package/dist/schemas/layout.js +2 -1
  106. package/dist/schemas/layout.js.map +1 -1
  107. package/dist/schemas/list.d.ts +23 -2
  108. package/dist/schemas/list.d.ts.map +1 -1
  109. package/dist/schemas/list.js +15 -6
  110. package/dist/schemas/list.js.map +1 -1
  111. package/dist/schemas/resource.d.ts +263 -17
  112. package/dist/schemas/resource.d.ts.map +1 -1
  113. package/dist/schemas/resource.js +19 -4
  114. package/dist/schemas/resource.js.map +1 -1
  115. package/dist/schemas/theme.d.ts +4 -0
  116. package/dist/schemas/theme.d.ts.map +1 -1
  117. package/dist/schemas/theme.js +1 -0
  118. package/dist/schemas/theme.js.map +1 -1
  119. package/dist/schemas/widget.d.ts +109 -0
  120. package/dist/schemas/widget.d.ts.map +1 -0
  121. package/dist/schemas/widget.js +74 -0
  122. package/dist/schemas/widget.js.map +1 -0
  123. package/dist/search.d.ts +51 -0
  124. package/dist/search.d.ts.map +1 -0
  125. package/dist/search.js +53 -0
  126. package/dist/search.js.map +1 -0
  127. package/dist/themes.d.ts +1 -1
  128. package/dist/transforms.d.ts +17 -0
  129. package/dist/transforms.d.ts.map +1 -0
  130. package/dist/transforms.js +34 -0
  131. package/dist/transforms.js.map +1 -0
  132. package/dist/validate.d.ts +5 -3
  133. package/dist/validate.d.ts.map +1 -1
  134. package/dist/validate.js +36 -2
  135. package/dist/validate.js.map +1 -1
  136. package/dist/values.d.ts +5 -1
  137. package/dist/values.d.ts.map +1 -1
  138. package/dist/values.js +16 -2
  139. package/dist/values.js.map +1 -1
  140. package/dist/widgets.d.ts +42 -0
  141. package/dist/widgets.d.ts.map +1 -0
  142. package/dist/widgets.js +130 -0
  143. package/dist/widgets.js.map +1 -0
  144. package/package.json +6 -3
  145. package/schema/boot.schema.json +713 -20
  146. package/schema/definition.schema.json +710 -20
  147. package/schema/openapi.json +5656 -2229
package/dist/constants.js CHANGED
@@ -9,6 +9,49 @@ var BUILT_IN_ACTIONS = [
9
9
  "export",
10
10
  "import"
11
11
  ];
12
+ /**
13
+ * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them
14
+ * to its own routes, and labels them itself when they have no `label`.
15
+ */
16
+ var BUILT_IN_LINK_ACTIONS = ["show", "edit"];
17
+ /** Whether an action id is one of the built-in links, `show` and `edit`. */
18
+ function isBuiltInLink(id) {
19
+ return BUILT_IN_LINK_ACTIONS.includes(id);
20
+ }
21
+ /**
22
+ * A run on more items than this can't be undone (decision 0063): the client confirms it before it
23
+ * starts, and its result has no `undo`. Under it, the result lists the ids to put back.
24
+ */
25
+ var UNDO_LIMIT = 100;
26
+ /**
27
+ * The filter of every list on the ids of its items (decision 0069): `filter[ids][]=12`. No list's
28
+ * definition declares it, and none can declare a filter with this id.
29
+ */
30
+ var IDS_FILTER = "ids";
31
+ /** A list filtered on ids takes at most this many (decision 0069), as an undo does. */
32
+ var IDS_FILTER_LIMIT = 100;
33
+ /**
34
+ * Built-in item actions, in their default order (decision 0040). Every resource has them without
35
+ * declaring them, and clients show each one on the items whose abilities allow it
36
+ * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.
37
+ */
38
+ var BUILT_IN_ITEM_ACTIONS = [
39
+ "show",
40
+ "edit",
41
+ "duplicate",
42
+ "delete"
43
+ ];
44
+ /** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */
45
+ var ITEM_ACTION_ABILITIES = {
46
+ show: "view",
47
+ edit: "update",
48
+ duplicate: "duplicate",
49
+ delete: "delete"
50
+ };
51
+ /** Whether an action id is one of the built-in item actions. */
52
+ function isBuiltInItemAction(id) {
53
+ return BUILT_IN_ITEM_ACTIONS.includes(id);
54
+ }
12
55
  /** Field types every Panneau frontend renders. Plugins add others. */
13
56
  var BUILT_IN_FIELD_TYPES = [
14
57
  "text",
@@ -24,10 +67,24 @@ var BUILT_IN_FIELD_TYPES = [
24
67
  "url",
25
68
  "color",
26
69
  "media",
70
+ "image",
27
71
  "relation",
28
72
  "group",
29
73
  "repeater",
30
- "slug"
74
+ "slug",
75
+ "tel",
76
+ "range",
77
+ "duration",
78
+ "json",
79
+ "tags",
80
+ "embed",
81
+ "location",
82
+ "country",
83
+ "region",
84
+ "address",
85
+ "link",
86
+ "daterange",
87
+ "money"
31
88
  ];
32
89
  /** Validation rules that both frontends and backends check. */
33
90
  var PORTABLE_RULES = [
@@ -37,11 +94,47 @@ var PORTABLE_RULES = [
37
94
  "pattern",
38
95
  "email",
39
96
  "url",
97
+ "json",
98
+ "tel",
99
+ "postalCode",
100
+ "daterange",
101
+ "money",
40
102
  "in",
41
103
  "accept",
42
104
  "maxSize",
43
105
  "before",
44
- "after"
106
+ "after",
107
+ "crop",
108
+ "providers"
109
+ ];
110
+ /** The parts of an `address` value, in the order of the field (decision 0054). */
111
+ var ADDRESS_PARTS = [
112
+ "country",
113
+ "street",
114
+ "unit",
115
+ "city",
116
+ "region",
117
+ "postalCode"
118
+ ];
119
+ /** The parts a filled address must have, without `settings.required` (decision 0054). */
120
+ var DEFAULT_ADDRESS_REQUIRED_PARTS = [
121
+ "street",
122
+ "city",
123
+ "country"
124
+ ];
125
+ /** The built-in types of `link` values (decision 0055). Sites add others in `settings.types`. */
126
+ var BUILT_IN_LINK_TYPES = [
127
+ "url",
128
+ "page",
129
+ "email",
130
+ "tel",
131
+ "file"
132
+ ];
133
+ /** Which bounds of a `daterange` value can be `null` (decision 0053). */
134
+ var DATE_RANGE_OPEN_BOUNDS = [
135
+ "start",
136
+ "end",
137
+ "both"
45
138
  ];
46
139
  /** Layout node types every Panneau frontend renders. */
47
140
  var BUILT_IN_LAYOUT_NODE_TYPES = [
@@ -67,7 +160,92 @@ var BUILT_IN_LIST_LAYOUTS = [
67
160
  * `<script type="application/json" id="panneau-boot">` element whose text is the JSON object.
68
161
  */
69
162
  var BOOT_CONFIG_ELEMENT_ID = "panneau-boot";
163
+ /**
164
+ * The units of a `duration` field, from the smallest to the largest: of its value
165
+ * (`settings.unit`), and of the parts its input shows (`settings.precision` and
166
+ * `settings.largestUnit`). A day is 24 hours: no calendar is involved.
167
+ */
168
+ var DURATION_UNITS = [
169
+ "seconds",
170
+ "minutes",
171
+ "hours",
172
+ "days"
173
+ ];
174
+ /** The elements a block style of a `richtext` field can apply to. */
175
+ var RICH_TEXT_STYLE_ELEMENTS = [
176
+ "p",
177
+ "h1",
178
+ "h2",
179
+ "h3",
180
+ "h4",
181
+ "h5",
182
+ "h6",
183
+ "blockquote",
184
+ "ul",
185
+ "ol",
186
+ "li"
187
+ ];
188
+ /**
189
+ * The first segments of the client routes under `basePath` that Panneau keeps for itself
190
+ * (decision 0019). A param of the context can't be named like one: the context is a prefix of
191
+ * the routes, `{basePath}/{name}/{value}/…` (decision 0045).
192
+ */
193
+ var RESERVED_ROUTE_SEGMENTS = [
194
+ "resources",
195
+ "pages",
196
+ "media",
197
+ "search",
198
+ "account",
199
+ "auth"
200
+ ];
201
+ /** The request header that carries the values of the current context (decision 0045). */
202
+ var CONTEXT_HEADER = "Panneau-Context";
203
+ /** The type of the `403` problem of a value of the context that the user can't use. */
204
+ var CONTEXT_PROBLEM_TYPE = "urn:panneau:problem:context";
205
+ /**
206
+ * The type of the `403` problem of a user whose email address isn't verified yet, with
207
+ * `auth.emailVerification` (decision 0048). The app shows a page that sends a new link.
208
+ */
209
+ var EMAIL_UNVERIFIED_PROBLEM_TYPE = "urn:panneau:problem:email-unverified";
210
+ /**
211
+ * The type of the `403` problem of a user who must have two-factor authentication and hasn't set
212
+ * it up (decision 0049). The app shows its setup.
213
+ */
214
+ var TWO_FACTOR_REQUIRED_PROBLEM_TYPE = "urn:panneau:problem:two-factor-required";
215
+ /**
216
+ * The type of the `423` problem of an operation that needs the password, when it wasn't confirmed
217
+ * recently (decision 0049): the app confirms it with `POST /auth/password/confirm`, then runs the
218
+ * operation again.
219
+ */
220
+ var PASSWORD_CONFIRMATION_PROBLEM_TYPE = "urn:panneau:problem:password-confirmation";
221
+ /**
222
+ * The paths of the auth pages of the app, under `basePath` (decision 0048), that the links of the
223
+ * backend's emails open:
224
+ *
225
+ * - `resetPassword`, with the `token` and the `email` of a password reset in the query;
226
+ * - `verifyEmail`, with the `token` of an email verification in the query.
227
+ */
228
+ /**
229
+ * The query param of a login with an OAuth provider that failed (decision 0052): the backend comes
230
+ * back to the base path of the app with one of `AUTH_ERROR_CODES`, which the login page says.
231
+ */
232
+ var AUTH_ERROR_PARAM = "authError";
233
+ /**
234
+ * Why a login with an OAuth provider failed (decision 0052): the provider failed or the user
235
+ * cancelled, it gave no verified email address, the address isn't in an allowed domain, or no user
236
+ * with this address is allowed in.
237
+ */
238
+ var AUTH_ERROR_CODES = [
239
+ "provider",
240
+ "email",
241
+ "domain",
242
+ "access"
243
+ ];
244
+ var AUTH_PAGE_PATHS = {
245
+ resetPassword: "auth/reset-password",
246
+ verifyEmail: "auth/verify-email"
247
+ };
70
248
  //#endregion
71
- export { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES };
249
+ 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, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, IDS_FILTER, IDS_FILTER_LIMIT, 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 };
72
250
 
73
251
  //# sourceMappingURL=constants.js.map
@@ -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/** 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 'relation',\n 'group',\n 'repeater',\n 'slug',\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 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\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"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,uBAAuB;CAChC;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;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"}
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 * A run on more items than this can't be undone (decision 0063): the client confirms it before it\n * starts, and its result has no `undo`. Under it, the result lists the ids to put back.\n */\nexport const UNDO_LIMIT = 100;\n\n/**\n * The filter of every list on the ids of its items (decision 0069): `filter[ids][]=12`. No list's\n * definition declares it, and none can declare a filter with this id.\n */\nexport const IDS_FILTER = 'ids';\n\n/** A list filtered on ids takes at most this many (decision 0069), as an undo does. */\nexport const IDS_FILTER_LIMIT = 100;\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 'address',\n 'link',\n 'daterange',\n 'money',\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 'postalCode',\n 'daterange',\n 'money',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n 'providers',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** The parts of an `address` value, in the order of the field (decision 0054). */\nexport const ADDRESS_PARTS = ['country', 'street', 'unit', 'city', 'region', 'postalCode'] as const;\n/** A part of an `address` value. */\nexport type AddressPart = (typeof ADDRESS_PARTS)[number];\n\n/** The parts a filled address must have, without `settings.required` (decision 0054). */\nexport const DEFAULT_ADDRESS_REQUIRED_PARTS: readonly AddressPart[] = ['street', 'city', 'country'];\n\n/** The built-in types of `link` values (decision 0055). Sites add others in `settings.types`. */\nexport const BUILT_IN_LINK_TYPES = ['url', 'page', 'email', 'tel', 'file'] as const;\n/** A built-in type of `link` values. */\nexport type BuiltInLinkType = (typeof BUILT_IN_LINK_TYPES)[number];\n\n/** Which bounds of a `daterange` value can be `null` (decision 0053). */\nexport const DATE_RANGE_OPEN_BOUNDS = ['start', 'end', 'both'] as const;\nexport type DateRangeOpenBound = (typeof DATE_RANGE_OPEN_BOUNDS)[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/**\n * The units of a `duration` field, from the smallest to the largest: of its value\n * (`settings.unit`), and of the parts its input shows (`settings.precision` and\n * `settings.largestUnit`). A day is 24 hours: no calendar is involved.\n */\nexport const DURATION_UNITS = ['seconds', 'minutes', 'hours', 'days'] as const;\n\n/** A unit of a `duration` field. */\nexport type DurationUnit = (typeof DURATION_UNITS)[number];\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;;;;;AAMA,IAAa,aAAa;;;;;AAM1B,IAAa,aAAa;;AAG1B,IAAa,mBAAmB;;;;;;AAOhC,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;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,gBAAgB;CAAC;CAAW;CAAU;CAAQ;CAAQ;CAAU;AAAY;;AAKzF,IAAa,iCAAyD;CAAC;CAAU;CAAQ;AAAS;;AAGlG,IAAa,sBAAsB;CAAC;CAAO;CAAQ;CAAS;CAAO;AAAM;;AAKzE,IAAa,yBAAyB;CAAC;CAAS;CAAO;AAAM;;AAI7D,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;;;;;AAOtC,IAAa,iBAAiB;CAAC;CAAW;CAAW;CAAS;AAAM;;AAMpE,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"}
@@ -0,0 +1,15 @@
1
+ /** Values of the params of the context, by name. A param without a value is left out. */
2
+ export type ContextValues = Readonly<Record<string, string>>;
3
+ /**
4
+ * The value of the `Panneau-Context` header: the values in the format of a query string, in the
5
+ * order of `names` (the order of the params of the definition) when given. Empty without values.
6
+ */
7
+ export declare function formatContextHeader(values: Readonly<Record<string, string | null | undefined>>, names?: readonly string[]): string;
8
+ /** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */
9
+ export declare function parseContextHeader(header: string | null | undefined): ContextValues;
10
+ /**
11
+ * The values of the context in the params before `name`: those that the request of its choices
12
+ * sends, since a param depends on the params before it.
13
+ */
14
+ export declare function contextBefore(values: ContextValues, names: readonly string[], name: string): ContextValues;
15
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,yFAAyF;AACzF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAS7D;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,EAC3D,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,MAAM,CAMR;AAED,yGAAyG;AACzG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,CAQnF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,MAAM,GACb,aAAa,CAGf"}
@@ -0,0 +1,34 @@
1
+ //#region src/context.ts
2
+ /** Only the values that are set: `null`, `undefined` and empty values are left out. */
3
+ function setValues(values) {
4
+ return Object.entries(values).filter((entry) => typeof entry[1] === "string" && entry[1] !== "");
5
+ }
6
+ /**
7
+ * The value of the `Panneau-Context` header: the values in the format of a query string, in the
8
+ * order of `names` (the order of the params of the definition) when given. Empty without values.
9
+ */
10
+ function formatContextHeader(values, names) {
11
+ const entries = setValues(values);
12
+ if (names !== void 0) entries.sort(([a], [b]) => names.indexOf(a) - names.indexOf(b));
13
+ return new URLSearchParams(entries).toString();
14
+ }
15
+ /** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */
16
+ function parseContextHeader(header) {
17
+ const values = {};
18
+ new URLSearchParams(header ?? "").forEach((value, name) => {
19
+ if (value !== "" && !(name in values)) values[name] = value;
20
+ });
21
+ return values;
22
+ }
23
+ /**
24
+ * The values of the context in the params before `name`: those that the request of its choices
25
+ * sends, since a param depends on the params before it.
26
+ */
27
+ function contextBefore(values, names, name) {
28
+ const before = names.slice(0, Math.max(0, names.indexOf(name)));
29
+ return Object.fromEntries(setValues(values).filter(([key]) => before.includes(key)));
30
+ }
31
+ //#endregion
32
+ export { contextBefore, formatContextHeader, parseContextHeader };
33
+
34
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["// The current context (decision 0045): the values of its params, in the `Panneau-Context` header\n// and in the prefix of the client routes. This module doesn't import zod.\n\n/** Values of the params of the context, by name. A param without a value is left out. */\nexport type ContextValues = Readonly<Record<string, string>>;\n\n/** Only the values that are set: `null`, `undefined` and empty values are left out. */\nfunction setValues(values: Readonly<Record<string, string | null | undefined>>) {\n return Object.entries(values).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string' && entry[1] !== '',\n );\n}\n\n/**\n * The value of the `Panneau-Context` header: the values in the format of a query string, in the\n * order of `names` (the order of the params of the definition) when given. Empty without values.\n */\nexport function formatContextHeader(\n values: Readonly<Record<string, string | null | undefined>>,\n names?: readonly string[],\n): string {\n const entries = setValues(values);\n if (names !== undefined) {\n entries.sort(([a], [b]) => names.indexOf(a) - names.indexOf(b));\n }\n return new URLSearchParams(entries).toString();\n}\n\n/** The values of a `Panneau-Context` header. The first value of a name wins; empty ones are left out. */\nexport function parseContextHeader(header: string | null | undefined): ContextValues {\n const values: Record<string, string> = {};\n new URLSearchParams(header ?? '').forEach((value, name) => {\n if (value !== '' && !(name in values)) {\n values[name] = value;\n }\n });\n return values;\n}\n\n/**\n * The values of the context in the params before `name`: those that the request of its choices\n * sends, since a param depends on the params before it.\n */\nexport function contextBefore(\n values: ContextValues,\n names: readonly string[],\n name: string,\n): ContextValues {\n const before = names.slice(0, Math.max(0, names.indexOf(name)));\n return Object.fromEntries(setValues(values).filter(([key]) => before.includes(key)));\n}\n"],"mappings":";;AAOA,SAAS,UAAU,QAA6D;CAC5E,OAAO,OAAO,QAAQ,MAAM,CAAC,CAAC,QACzB,UAAqC,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,EACvF;AACJ;;;;;AAMA,SAAgB,oBACZ,QACA,OACM;CACN,MAAM,UAAU,UAAU,MAAM;CAChC,IAAI,UAAU,KAAA,GACV,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC;CAElE,OAAO,IAAI,gBAAgB,OAAO,CAAC,CAAC,SAAS;AACjD;;AAGA,SAAgB,mBAAmB,QAAkD;CACjF,MAAM,SAAiC,CAAC;CACxC,IAAI,gBAAgB,UAAU,EAAE,CAAC,CAAC,SAAS,OAAO,SAAS;EACvD,IAAI,UAAU,MAAM,EAAE,QAAQ,SAC1B,OAAO,QAAQ;CAEvB,CAAC;CACD,OAAO;AACX;;;;;AAMA,SAAgB,cACZ,QACA,OACA,MACa;CACb,MAAM,SAAS,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,MAAM,QAAQ,IAAI,CAAC,CAAC;CAC9D,OAAO,OAAO,YAAY,UAAU,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,OAAO,SAAS,GAAG,CAAC,CAAC;AACvF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in
3
+ * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals
4
+ * and test codes are left out.
5
+ */
6
+ export declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWG", "ZWL"];
7
+ export type CurrencyCode = (typeof CURRENCY_CODES)[number];
8
+ /** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */
9
+ export declare function isCurrencyCode(code: unknown): code is CurrencyCode;
10
+ /**
11
+ * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),
12
+ * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.
13
+ */
14
+ export declare function getCurrencyDigits(code: string): number;
15
+ /**
16
+ * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away
17
+ * from zero, without the errors of floating point (`1.005` gives `101`).
18
+ */
19
+ export declare function toMinorUnits(amount: number, currency: string): number;
20
+ /** Turns an amount in minor units (`1250`) into major units (`12.5`). */
21
+ export declare function fromMinorUnits(amount: number, currency: string): number;
22
+ //# sourceMappingURL=currencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currencies.d.ts","sourceRoot":"","sources":["../src/currencies.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,knCAcjB,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAmC3D,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAElE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvE"}
@@ -0,0 +1,231 @@
1
+ //#region src/currencies.ts
2
+ /**
3
+ * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in
4
+ * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals
5
+ * and test codes are left out.
6
+ */
7
+ var CURRENCY_CODES = [
8
+ "AED",
9
+ "AFN",
10
+ "ALL",
11
+ "AMD",
12
+ "ANG",
13
+ "AOA",
14
+ "ARS",
15
+ "AUD",
16
+ "AWG",
17
+ "AZN",
18
+ "BAM",
19
+ "BBD",
20
+ "BDT",
21
+ "BGN",
22
+ "BHD",
23
+ "BIF",
24
+ "BMD",
25
+ "BND",
26
+ "BOB",
27
+ "BRL",
28
+ "BSD",
29
+ "BTN",
30
+ "BWP",
31
+ "BYN",
32
+ "BZD",
33
+ "CAD",
34
+ "CDF",
35
+ "CHF",
36
+ "CLP",
37
+ "CNY",
38
+ "COP",
39
+ "CRC",
40
+ "CUC",
41
+ "CUP",
42
+ "CVE",
43
+ "CZK",
44
+ "DJF",
45
+ "DKK",
46
+ "DOP",
47
+ "DZD",
48
+ "EGP",
49
+ "ERN",
50
+ "ETB",
51
+ "EUR",
52
+ "FJD",
53
+ "FKP",
54
+ "GBP",
55
+ "GEL",
56
+ "GHS",
57
+ "GIP",
58
+ "GMD",
59
+ "GNF",
60
+ "GTQ",
61
+ "GYD",
62
+ "HKD",
63
+ "HNL",
64
+ "HRK",
65
+ "HTG",
66
+ "HUF",
67
+ "IDR",
68
+ "ILS",
69
+ "INR",
70
+ "IQD",
71
+ "IRR",
72
+ "ISK",
73
+ "JMD",
74
+ "JOD",
75
+ "JPY",
76
+ "KES",
77
+ "KGS",
78
+ "KHR",
79
+ "KMF",
80
+ "KPW",
81
+ "KRW",
82
+ "KWD",
83
+ "KYD",
84
+ "KZT",
85
+ "LAK",
86
+ "LBP",
87
+ "LKR",
88
+ "LRD",
89
+ "LSL",
90
+ "LYD",
91
+ "MAD",
92
+ "MDL",
93
+ "MGA",
94
+ "MKD",
95
+ "MMK",
96
+ "MNT",
97
+ "MOP",
98
+ "MRU",
99
+ "MUR",
100
+ "MVR",
101
+ "MWK",
102
+ "MXN",
103
+ "MYR",
104
+ "MZN",
105
+ "NAD",
106
+ "NGN",
107
+ "NIO",
108
+ "NOK",
109
+ "NPR",
110
+ "NZD",
111
+ "OMR",
112
+ "PAB",
113
+ "PEN",
114
+ "PGK",
115
+ "PHP",
116
+ "PKR",
117
+ "PLN",
118
+ "PYG",
119
+ "QAR",
120
+ "RON",
121
+ "RSD",
122
+ "RUB",
123
+ "RWF",
124
+ "SAR",
125
+ "SBD",
126
+ "SCR",
127
+ "SDG",
128
+ "SEK",
129
+ "SGD",
130
+ "SHP",
131
+ "SLE",
132
+ "SLL",
133
+ "SOS",
134
+ "SRD",
135
+ "SSP",
136
+ "STN",
137
+ "SVC",
138
+ "SYP",
139
+ "SZL",
140
+ "THB",
141
+ "TJS",
142
+ "TMT",
143
+ "TND",
144
+ "TOP",
145
+ "TRY",
146
+ "TTD",
147
+ "TWD",
148
+ "TZS",
149
+ "UAH",
150
+ "UGX",
151
+ "USD",
152
+ "UYU",
153
+ "UZS",
154
+ "VED",
155
+ "VES",
156
+ "VND",
157
+ "VUV",
158
+ "WST",
159
+ "XAF",
160
+ "XCD",
161
+ "XCG",
162
+ "XOF",
163
+ "XPF",
164
+ "YER",
165
+ "ZAR",
166
+ "ZMW",
167
+ "ZWG",
168
+ "ZWL"
169
+ ];
170
+ /**
171
+ * The currencies whose minor unit isn't a hundredth, by their exponent in ISO 4217. The CLDR, which
172
+ * `Intl.NumberFormat` follows, differs for a few cash currencies: amounts follow ISO 4217.
173
+ */
174
+ var CURRENCY_EXPONENTS = {
175
+ BIF: 0,
176
+ CLP: 0,
177
+ DJF: 0,
178
+ GNF: 0,
179
+ ISK: 0,
180
+ JPY: 0,
181
+ KMF: 0,
182
+ KRW: 0,
183
+ PYG: 0,
184
+ RWF: 0,
185
+ UGX: 0,
186
+ UYI: 0,
187
+ VND: 0,
188
+ VUV: 0,
189
+ XAF: 0,
190
+ XOF: 0,
191
+ XPF: 0,
192
+ BHD: 3,
193
+ IQD: 3,
194
+ JOD: 3,
195
+ KWD: 3,
196
+ LYD: 3,
197
+ OMR: 3,
198
+ TND: 3,
199
+ CLF: 4,
200
+ UYW: 4
201
+ };
202
+ /** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */
203
+ function isCurrencyCode(code) {
204
+ return typeof code === "string" && CURRENCY_CODES.includes(code);
205
+ }
206
+ /**
207
+ * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),
208
+ * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.
209
+ */
210
+ function getCurrencyDigits(code) {
211
+ return CURRENCY_EXPONENTS[code] ?? 2;
212
+ }
213
+ /**
214
+ * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away
215
+ * from zero, without the errors of floating point (`1.005` gives `101`).
216
+ */
217
+ function toMinorUnits(amount, currency) {
218
+ const digits = getCurrencyDigits(currency);
219
+ const [mantissa = "0", exponent = "0"] = String(Math.abs(amount)).split("e");
220
+ const shifted = Number(`${mantissa}e${String(Number(exponent) + digits)}`);
221
+ return Math.sign(amount) * Math.round(shifted) || 0;
222
+ }
223
+ /** Turns an amount in minor units (`1250`) into major units (`12.5`). */
224
+ function fromMinorUnits(amount, currency) {
225
+ const digits = getCurrencyDigits(currency);
226
+ return Number(`${String(amount)}e-${String(digits)}`);
227
+ }
228
+ //#endregion
229
+ export { CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits };
230
+
231
+ //# sourceMappingURL=currencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currencies.js","names":[],"sources":["../src/currencies.ts"],"sourcesContent":["/**\n * The ISO 4217 codes of the currencies a `money` value can have (decision 0053): the currencies in\n * use, and a few withdrawn recently, which stored amounts may still have. Funds, precious metals\n * and test codes are left out.\n */\nexport const CURRENCY_CODES = [\n 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT',\n 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD',\n 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP',\n 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF',\n 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK',\n 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK',\n 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU',\n 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',\n 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR',\n 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC',\n 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX',\n 'USD', 'UYU', 'UZS', 'VED', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XCG', 'XOF', 'XPF',\n 'YER', 'ZAR', 'ZMW', 'ZWG', 'ZWL',\n] as const; // prettier-ignore\nexport type CurrencyCode = (typeof CURRENCY_CODES)[number];\n\n/**\n * The currencies whose minor unit isn't a hundredth, by their exponent in ISO 4217. The CLDR, which\n * `Intl.NumberFormat` follows, differs for a few cash currencies: amounts follow ISO 4217.\n */\nconst CURRENCY_EXPONENTS: Readonly<Record<string, number>> = {\n BIF: 0,\n CLP: 0,\n DJF: 0,\n GNF: 0,\n ISK: 0,\n JPY: 0,\n KMF: 0,\n KRW: 0,\n PYG: 0,\n RWF: 0,\n UGX: 0,\n UYI: 0,\n VND: 0,\n VUV: 0,\n XAF: 0,\n XOF: 0,\n XPF: 0,\n BHD: 3,\n IQD: 3,\n JOD: 3,\n KWD: 3,\n LYD: 3,\n OMR: 3,\n TND: 3,\n CLF: 4,\n UYW: 4,\n};\n\n/** Whether a string is the ISO 4217 code of a currency that Panneau knows (`CAD`). */\nexport function isCurrencyCode(code: unknown): code is CurrencyCode {\n return typeof code === 'string' && (CURRENCY_CODES as readonly string[]).includes(code);\n}\n\n/**\n * The number of digits of the minor unit of a currency, its ISO 4217 exponent: 2 for `CAD` (cents),\n * 0 for `JPY`, 3 for `KWD`. A `money` amount is an integer in that unit.\n */\nexport function getCurrencyDigits(code: string): number {\n return CURRENCY_EXPONENTS[code] ?? 2;\n}\n\n/**\n * Turns an amount in major units, as typed (`12.5`), into minor units (`1250`), rounded half away\n * from zero, without the errors of floating point (`1.005` gives `101`).\n */\nexport function toMinorUnits(amount: number, currency: string): number {\n const digits = getCurrencyDigits(currency);\n const [mantissa = '0', exponent = '0'] = String(Math.abs(amount)).split('e');\n const shifted = Number(`${mantissa}e${String(Number(exponent) + digits)}`);\n return Math.sign(amount) * Math.round(shifted) || 0;\n}\n\n/** Turns an amount in minor units (`1250`) into major units (`12.5`). */\nexport function fromMinorUnits(amount: number, currency: string): number {\n const digits = getCurrencyDigits(currency);\n return Number(`${String(amount)}e-${String(digits)}`);\n}\n"],"mappings":";;;;;;AAKA,IAAa,iBAAiB;CAC1B;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CACpF;CAAO;CAAO;CAAO;CAAO;AAChC;;;;;AAOA,IAAM,qBAAuD;CACzD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACT;;AAGA,SAAgB,eAAe,MAAqC;CAChE,OAAO,OAAO,SAAS,YAAa,eAAqC,SAAS,IAAI;AAC1F;;;;;AAMA,SAAgB,kBAAkB,MAAsB;CACpD,OAAO,mBAAmB,SAAS;AACvC;;;;;AAMA,SAAgB,aAAa,QAAgB,UAA0B;CACnE,MAAM,SAAS,kBAAkB,QAAQ;CACzC,MAAM,CAAC,WAAW,KAAK,WAAW,OAAO,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG;CAC3E,MAAM,UAAU,OAAO,GAAG,SAAS,GAAG,OAAO,OAAO,QAAQ,IAAI,MAAM,GAAG;CACzE,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,MAAM,OAAO,KAAK;AACtD;;AAGA,SAAgB,eAAe,QAAgB,UAA0B;CACrE,MAAM,SAAS,kBAAkB,QAAQ;CACzC,OAAO,OAAO,GAAG,OAAO,MAAM,EAAE,IAAI,OAAO,MAAM,GAAG;AACxD"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './runtime';
2
- export * from './schemas';
3
- export { type ValidationIssue, type ValidationResult, validate, validateBootConfig, validateDefinition, } from './validate';
4
- export { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema, } from './openapi';
1
+ export * from './runtime/index.js';
2
+ export * from './schemas/index.js';
3
+ export { type ValidationIssue, type ValidationResult, validate, validateBootConfig, validateDefinition, } from './validate.js';
4
+ export { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema, } from './openapi.js';
5
5
  //# sourceMappingURL=index.d.ts.map