@velocity-astro/cms-core 0.0.0-stage → 0.1.0-beta.2

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 (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/access.d.ts +24 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +22 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/checks.d.ts +24 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +17 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/cms.d.ts +86 -0
  12. package/dist/cms.d.ts.map +1 -0
  13. package/dist/cms.js +50 -0
  14. package/dist/cms.js.map +1 -0
  15. package/dist/day.d.ts +3 -0
  16. package/dist/day.d.ts.map +1 -0
  17. package/dist/day.js +8 -0
  18. package/dist/day.js.map +1 -0
  19. package/dist/define-fields.d.ts +27 -0
  20. package/dist/define-fields.d.ts.map +1 -0
  21. package/dist/define-fields.js +57 -0
  22. package/dist/define-fields.js.map +1 -0
  23. package/dist/errors.d.ts +27 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +29 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/events.d.ts +146 -0
  28. package/dist/events.d.ts.map +1 -0
  29. package/dist/events.js +29 -0
  30. package/dist/events.js.map +1 -0
  31. package/dist/field-type.d.ts +78 -0
  32. package/dist/field-type.d.ts.map +1 -0
  33. package/dist/field-type.js +64 -0
  34. package/dist/field-type.js.map +1 -0
  35. package/dist/fields/blocks.d.ts +76 -0
  36. package/dist/fields/blocks.d.ts.map +1 -0
  37. package/dist/fields/blocks.js +141 -0
  38. package/dist/fields/blocks.js.map +1 -0
  39. package/dist/fields/index.d.ts +227 -0
  40. package/dist/fields/index.d.ts.map +1 -0
  41. package/dist/fields/index.js +285 -0
  42. package/dist/fields/index.js.map +1 -0
  43. package/dist/fields/link.d.ts +44 -0
  44. package/dist/fields/link.d.ts.map +1 -0
  45. package/dist/fields/link.js +34 -0
  46. package/dist/fields/link.js.map +1 -0
  47. package/dist/image-file.d.ts +15 -0
  48. package/dist/image-file.d.ts.map +1 -0
  49. package/dist/image-file.js +63 -0
  50. package/dist/image-file.js.map +1 -0
  51. package/dist/index.d.ts +32 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +30 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/model.d.ts +487 -0
  56. package/dist/model.d.ts.map +1 -0
  57. package/dist/model.js +23 -0
  58. package/dist/model.js.map +1 -0
  59. package/dist/net.d.ts +8 -0
  60. package/dist/net.d.ts.map +1 -0
  61. package/dist/net.js +39 -0
  62. package/dist/net.js.map +1 -0
  63. package/dist/page-address.d.ts +22 -0
  64. package/dist/page-address.d.ts.map +1 -0
  65. package/dist/page-address.js +37 -0
  66. package/dist/page-address.js.map +1 -0
  67. package/dist/pages.d.ts +34 -0
  68. package/dist/pages.d.ts.map +1 -0
  69. package/dist/pages.js +33 -0
  70. package/dist/pages.js.map +1 -0
  71. package/dist/plugin.d.ts +352 -0
  72. package/dist/plugin.d.ts.map +1 -0
  73. package/dist/plugin.js +617 -0
  74. package/dist/plugin.js.map +1 -0
  75. package/dist/ports.d.ts +307 -0
  76. package/dist/ports.d.ts.map +1 -0
  77. package/dist/ports.js +2 -0
  78. package/dist/ports.js.map +1 -0
  79. package/dist/preview.d.ts +20 -0
  80. package/dist/preview.d.ts.map +1 -0
  81. package/dist/preview.js +44 -0
  82. package/dist/preview.js.map +1 -0
  83. package/dist/registry.d.ts +23 -0
  84. package/dist/registry.d.ts.map +1 -0
  85. package/dist/registry.js +40 -0
  86. package/dist/registry.js.map +1 -0
  87. package/dist/rich-text.d.ts +66 -0
  88. package/dist/rich-text.d.ts.map +1 -0
  89. package/dist/rich-text.js +99 -0
  90. package/dist/rich-text.js.map +1 -0
  91. package/dist/schema-builder.d.ts +25 -0
  92. package/dist/schema-builder.d.ts.map +1 -0
  93. package/dist/schema-builder.js +148 -0
  94. package/dist/schema-builder.js.map +1 -0
  95. package/dist/search-text.d.ts +10 -0
  96. package/dist/search-text.d.ts.map +1 -0
  97. package/dist/search-text.js +22 -0
  98. package/dist/search-text.js.map +1 -0
  99. package/dist/services/contact-service.d.ts +153 -0
  100. package/dist/services/contact-service.d.ts.map +1 -0
  101. package/dist/services/contact-service.js +490 -0
  102. package/dist/services/contact-service.js.map +1 -0
  103. package/dist/services/content-service.d.ts +114 -0
  104. package/dist/services/content-service.d.ts.map +1 -0
  105. package/dist/services/content-service.js +377 -0
  106. package/dist/services/content-service.js.map +1 -0
  107. package/dist/services/custom-fields-service.d.ts +51 -0
  108. package/dist/services/custom-fields-service.d.ts.map +1 -0
  109. package/dist/services/custom-fields-service.js +114 -0
  110. package/dist/services/custom-fields-service.js.map +1 -0
  111. package/dist/services/deal-service.d.ts +81 -0
  112. package/dist/services/deal-service.d.ts.map +1 -0
  113. package/dist/services/deal-service.js +228 -0
  114. package/dist/services/deal-service.js.map +1 -0
  115. package/dist/services/form-service.d.ts +108 -0
  116. package/dist/services/form-service.d.ts.map +1 -0
  117. package/dist/services/form-service.js +278 -0
  118. package/dist/services/form-service.js.map +1 -0
  119. package/dist/services/media-service.d.ts +61 -0
  120. package/dist/services/media-service.d.ts.map +1 -0
  121. package/dist/services/media-service.js +153 -0
  122. package/dist/services/media-service.js.map +1 -0
  123. package/dist/services/pipeline-service.d.ts +53 -0
  124. package/dist/services/pipeline-service.d.ts.map +1 -0
  125. package/dist/services/pipeline-service.js +113 -0
  126. package/dist/services/pipeline-service.js.map +1 -0
  127. package/dist/services/preview-service.d.ts +34 -0
  128. package/dist/services/preview-service.d.ts.map +1 -0
  129. package/dist/services/preview-service.js +46 -0
  130. package/dist/services/preview-service.js.map +1 -0
  131. package/dist/services/schema-service.d.ts +164 -0
  132. package/dist/services/schema-service.d.ts.map +1 -0
  133. package/dist/services/schema-service.js +394 -0
  134. package/dist/services/schema-service.js.map +1 -0
  135. package/dist/services/submission-service.d.ts +87 -0
  136. package/dist/services/submission-service.d.ts.map +1 -0
  137. package/dist/services/submission-service.js +235 -0
  138. package/dist/services/submission-service.js.map +1 -0
  139. package/dist/slug.d.ts +28 -0
  140. package/dist/slug.d.ts.map +1 -0
  141. package/dist/slug.js +33 -0
  142. package/dist/slug.js.map +1 -0
  143. package/dist/testing/contracts.d.ts +18 -0
  144. package/dist/testing/contracts.d.ts.map +1 -0
  145. package/dist/testing/contracts.js +824 -0
  146. package/dist/testing/contracts.js.map +1 -0
  147. package/dist/testing/in-memory.d.ts +123 -0
  148. package/dist/testing/in-memory.d.ts.map +1 -0
  149. package/dist/testing/in-memory.js +407 -0
  150. package/dist/testing/in-memory.js.map +1 -0
  151. package/dist/testing/index.d.ts +3 -0
  152. package/dist/testing/index.d.ts.map +1 -0
  153. package/dist/testing/index.js +3 -0
  154. package/dist/testing/index.js.map +1 -0
  155. package/package.json +49 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Southwell Media
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @velocity-astro/cms-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Velocity CMS content model and every rule about it. No database, no Astro, no HTTP.
4
+
5
+ Part of [Velocity CMS](https://github.com/Velocity-Astro/velocity-cms), a content management system for Astro sites. A site installs `@velocity-astro/cms-astro`, which brings the rest:
6
+
7
+ ```sh
8
+ npx velocity-cms init
9
+ ```
10
+
11
+ Docs: https://docs.deployvelocity.com/cms/
12
+
13
+ MIT
@@ -0,0 +1,24 @@
1
+ export type Role = 'owner' | 'editor' | 'author';
2
+ export type Permission = 'schema:write' | 'entry:read' | 'entry:write' | 'entry:publish' | 'entry:delete' | 'form:write' | 'submission:read' | 'submission:manage' | 'contact:read' | 'contact:manage' | 'user:manage' | 'plugin:manage';
3
+ /**
4
+ * Whoever is asking for something: a signed-in person, a plugin, the CLI or an AI agent.
5
+ * All four pass through the same permission checks.
6
+ */
7
+ export interface Actor {
8
+ readonly kind: 'user' | 'plugin' | 'cli' | 'agent';
9
+ readonly id: string;
10
+ readonly role: Role;
11
+ /**
12
+ * Exactly what this actor may do, in place of what its role grants. A plugin carries the
13
+ * permissions it declared; people are judged by their role and leave this out.
14
+ */
15
+ readonly permissions?: readonly Permission[];
16
+ }
17
+ /** Every role there is, from most to least allowed. */
18
+ export declare const ROLES: readonly Role[];
19
+ export declare class AccessControl {
20
+ can(actor: Actor, permission: Permission): boolean;
21
+ /** Throws unless the actor holds the permission. Every service method calls this first. */
22
+ require(actor: Actor, permission: Permission): void;
23
+ }
24
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,eAAe,GAAG,cAAc,GAAG,YAAY,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,cAAc,GAAG,gBAAgB,GAAG,aAAa,GAAG,eAAe,CAAC;AAEzO;;;GAGG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;IACnD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9C;AAQD,uDAAuD;AACvD,eAAO,MAAM,KAAK,EAAE,SAAS,IAAI,EAAkC,CAAC;AAEpE,qBAAa,aAAa;IACxB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAIlD,2FAA2F;IAC3F,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;CASpD"}
package/dist/access.js ADDED
@@ -0,0 +1,22 @@
1
+ import { ForbiddenError } from './errors.js';
2
+ const GRANTS = {
3
+ owner: new Set(['schema:write', 'entry:read', 'entry:write', 'entry:publish', 'entry:delete', 'form:write', 'submission:read', 'submission:manage', 'contact:read', 'contact:manage', 'user:manage', 'plugin:manage']),
4
+ editor: new Set(['entry:read', 'entry:write', 'entry:publish', 'entry:delete', 'form:write', 'submission:read', 'submission:manage', 'contact:read', 'contact:manage']),
5
+ author: new Set(['entry:read', 'entry:write']),
6
+ };
7
+ /** Every role there is, from most to least allowed. */
8
+ export const ROLES = ['owner', 'editor', 'author'];
9
+ export class AccessControl {
10
+ can(actor, permission) {
11
+ return actor.permissions ? actor.permissions.includes(permission) : GRANTS[actor.role].has(permission);
12
+ }
13
+ /** Throws unless the actor holds the permission. Every service method calls this first. */
14
+ require(actor, permission) {
15
+ if (!this.can(actor, permission)) {
16
+ throw new ForbiddenError(actor.permissions
17
+ ? `The ${actor.kind} "${actor.id}" was not given "${permission}".`
18
+ : `The ${actor.role} role does not allow "${permission}".`);
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqB7C,MAAM,MAAM,GAAoD;IAC9D,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;IACtN,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;IACvK,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;CAC/C,CAAC;AAEF,uDAAuD;AACvD,MAAM,CAAC,MAAM,KAAK,GAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAEpE,MAAM,OAAO,aAAa;IACxB,GAAG,CAAC,KAAY,EAAE,UAAsB;QACtC,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACzG,CAAC;IAED,2FAA2F;IAC3F,OAAO,CAAC,KAAY,EAAE,UAAsB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,cAAc,CACtB,KAAK,CAAC,WAAW;gBACf,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,oBAAoB,UAAU,IAAI;gBAClE,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,yBAAyB,UAAU,IAAI,CAC7D,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { Actor } from './access.js';
2
+ import type { ValidationIssue } from './errors.js';
3
+ import type { ContentTypeDef, PublicEntry } from './model.js';
4
+ /** What a check is shown: the entry as it would go out, with values by field key. */
5
+ export interface PublishCheckInput {
6
+ readonly entry: PublicEntry;
7
+ readonly type: ContentTypeDef;
8
+ readonly actor: Actor;
9
+ }
10
+ /**
11
+ * A rule an entry must pass before it is published, beyond what its fields require: a
12
+ * description for search engines, a photo with a caption. It answers with what is wrong, naming
13
+ * fields by key, or with nothing.
14
+ */
15
+ export type PublishCheck = (input: PublishCheckInput) => readonly ValidationIssue[] | Promise<readonly ValidationIssue[]>;
16
+ /** The checks a publish runs, in the order they were added, after the fields' own validation. */
17
+ export declare class PublishChecks {
18
+ #private;
19
+ /** Adds a check. Returns a function that takes it away again. */
20
+ add(check: PublishCheck): () => void;
21
+ /** Everything every check found. Empty means the entry may go out. */
22
+ run(input: PublishCheckInput): Promise<ValidationIssue[]>;
23
+ }
24
+ //# sourceMappingURL=checks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../src/checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,SAAS,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC,CAAC;AAE1H,iGAAiG;AACjG,qBAAa,aAAa;;IAGxB,iEAAiE;IACjE,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,IAAI;IAKpC,sEAAsE;IAChE,GAAG,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAKhE"}
package/dist/checks.js ADDED
@@ -0,0 +1,17 @@
1
+ /** The checks a publish runs, in the order they were added, after the fields' own validation. */
2
+ export class PublishChecks {
3
+ #checks = new Set();
4
+ /** Adds a check. Returns a function that takes it away again. */
5
+ add(check) {
6
+ this.#checks.add(check);
7
+ return () => this.#checks.delete(check);
8
+ }
9
+ /** Everything every check found. Empty means the entry may go out. */
10
+ async run(input) {
11
+ const issues = [];
12
+ for (const check of this.#checks)
13
+ issues.push(...(await check(input)));
14
+ return issues;
15
+ }
16
+ }
17
+ //# sourceMappingURL=checks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks.js","sourceRoot":"","sources":["../src/checks.ts"],"names":[],"mappings":"AAkBA,iGAAiG;AACjG,MAAM,OAAO,aAAa;IACf,OAAO,GAAG,IAAI,GAAG,EAAgB,CAAC;IAE3C,iEAAiE;IACjE,GAAG,CAAC,KAAmB;QACrB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,sEAAsE;IACtE,KAAK,CAAC,GAAG,CAAC,KAAwB;QAChC,MAAM,MAAM,GAAsB,EAAE,CAAC;QACrC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
package/dist/cms.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { AccessControl } from './access.js';
2
+ import { EventBus } from './events.js';
3
+ import type { FieldType } from './field-type.js';
4
+ import { PageHeads } from './pages.js';
5
+ import { PluginHost } from './plugin.js';
6
+ import type { Clock, ContactRepository, DealRepository, EntryRepository, FormRepository, IdGenerator, NameLookup, PipelineStore, CustomFieldsStore, PluginStore, SchemaRepository, SubmissionRepository, Team } from './ports.js';
7
+ import type { Registry } from './registry.js';
8
+ import { ContentService } from './services/content-service.js';
9
+ import { ContactService } from './services/contact-service.js';
10
+ import { DealService } from './services/deal-service.js';
11
+ import { PipelineService } from './services/pipeline-service.js';
12
+ import { CustomFieldsService } from './services/custom-fields-service.js';
13
+ import { FormService } from './services/form-service.js';
14
+ import { SubmissionService } from './services/submission-service.js';
15
+ import { MediaService, type MediaServiceOptions } from './services/media-service.js';
16
+ import { PreviewService, type PreviewServiceOptions } from './services/preview-service.js';
17
+ import { SchemaService } from './services/schema-service.js';
18
+ export interface CmsOptions {
19
+ readonly entries: EntryRepository;
20
+ readonly types: SchemaRepository;
21
+ /** Defaults to the built-in field types. */
22
+ readonly fields?: Registry<FieldType>;
23
+ /** Where uploaded images are kept, and where they are served from. Without storage there are no uploads. */
24
+ readonly media?: MediaServiceOptions;
25
+ /** The secret that signs preview links, and the language of the pages at a type's `urlPattern`. Without a secret there are no previews. */
26
+ readonly previews?: PreviewServiceOptions;
27
+ /** What plugins' keys and passwords are sealed with. Left out, the previews' secret is used; with neither, none can be saved. */
28
+ readonly secret?: string;
29
+ /**
30
+ * Where forms and what visitors send through them are kept. Without them both are kept in
31
+ * memory and forgotten when the server stops, which only suits tests.
32
+ */
33
+ readonly forms?: FormRepository;
34
+ readonly submissions?: SubmissionRepository;
35
+ /** Where contacts and the team's notes about them are kept. Without one, in memory, as above. */
36
+ readonly contacts?: ContactRepository;
37
+ /** Where deals are kept. Without one, in memory, as above. */
38
+ readonly deals?: DealRepository;
39
+ /** Where the stages of the pipeline are kept once someone changes them. Without one, in memory. */
40
+ readonly pipeline?: PipelineStore;
41
+ /** Where the fields a site adds to its contacts and deals are kept. Without one, in memory. */
42
+ readonly customFields?: CustomFieldsStore;
43
+ /** Who is on the team, so a contact can be given to one of them. Without it nobody can be. */
44
+ readonly team?: Team;
45
+ readonly clock?: Clock;
46
+ readonly ids?: IdGenerator;
47
+ /**
48
+ * Where plugins keep their settings and whether each is switched on. Without one they are
49
+ * kept in memory and forgotten when the server stops, which only suits tests.
50
+ */
51
+ readonly pluginStore?: PluginStore;
52
+ /** How the site looks a host's name up, so plugins can refuse a name that leads to a private machine. */
53
+ readonly lookup?: NameLookup;
54
+ /** Told of every plugin failure, for the server's log. */
55
+ readonly onPluginFault?: (plugin: string, error: unknown) => void;
56
+ }
57
+ /** The CMS, wired together. Everything outside the core reaches it through this object. */
58
+ export interface Cms {
59
+ readonly schema: SchemaService;
60
+ readonly content: ContentService;
61
+ readonly media: MediaService;
62
+ /** The forms visitors fill in, and what they sent. */
63
+ readonly forms: FormService;
64
+ readonly submissions: SubmissionService;
65
+ /** The people who wrote to the site, what each sent and what the team noted. */
66
+ readonly contacts: ContactService;
67
+ /** The stages a contact moves through. */
68
+ readonly pipeline: PipelineService;
69
+ readonly customFields: CustomFieldsService;
70
+ /** What contacts may buy, what each is worth and how far along it is. */
71
+ readonly deals: DealService;
72
+ readonly previews: PreviewService;
73
+ readonly fields: Registry<FieldType>;
74
+ readonly events: EventBus;
75
+ readonly access: AccessControl;
76
+ /** The site's plugins. A host calls `plugins.load` once, before it serves anything. */
77
+ readonly plugins: PluginHost;
78
+ /** What each page says about itself to search engines, after the plugins' rules. The site asks it as it draws a page. */
79
+ readonly pages: PageHeads;
80
+ }
81
+ /**
82
+ * Builds the services from the adapters they need. This is the one place that knows how the
83
+ * parts fit, so a test or a host can swap any of them.
84
+ */
85
+ export declare function createCms(options: CmsOptions): Cms;
86
+ //# sourceMappingURL=cms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../src/cms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElO,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;A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C,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACnE;AAED,2FAA2F;AAC3F,MAAM,WAAW,GAAG;IAClB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,uFAAuF;IACvF,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,yHAAyH;IACzH,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B;AAKD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,GAAG,CAyBlD"}
package/dist/cms.js ADDED
@@ -0,0 +1,50 @@
1
+ import { AccessControl } from './access.js';
2
+ import { EventBus } from './events.js';
3
+ import { createFieldRegistry } from './fields/index.js';
4
+ import { PublishChecks } from './checks.js';
5
+ import { PageHeads } from './pages.js';
6
+ import { PluginHost } from './plugin.js';
7
+ import { InMemoryContactRepository, InMemoryDealRepository, InMemoryFormRepository, InMemoryPipelineStore, InMemoryCustomFieldsStore, InMemoryPluginStore, InMemorySubmissionRepository } from './testing/in-memory.js';
8
+ import { ContentService } from './services/content-service.js';
9
+ import { ContactService } from './services/contact-service.js';
10
+ import { DealService } from './services/deal-service.js';
11
+ import { PipelineService } from './services/pipeline-service.js';
12
+ import { CustomFieldsService } from './services/custom-fields-service.js';
13
+ import { FormService } from './services/form-service.js';
14
+ import { SubmissionService } from './services/submission-service.js';
15
+ import { MediaService } from './services/media-service.js';
16
+ import { PreviewService } from './services/preview-service.js';
17
+ import { SchemaService } from './services/schema-service.js';
18
+ const systemClock = { now: () => new Date().toISOString() };
19
+ const randomIds = { next: () => globalThis.crypto.randomUUID() };
20
+ /**
21
+ * Builds the services from the adapters they need. This is the one place that knows how the
22
+ * parts fit, so a test or a host can swap any of them.
23
+ */
24
+ export function createCms(options) {
25
+ const fields = options.fields ?? createFieldRegistry();
26
+ const clock = options.clock ?? systemClock;
27
+ const ids = options.ids ?? randomIds;
28
+ const access = new AccessControl();
29
+ const events = new EventBus();
30
+ const schema = new SchemaService(options.types, fields, access, events, clock, ids);
31
+ const checks = new PublishChecks();
32
+ const pages = new PageHeads();
33
+ const content = new ContentService(options.entries, schema, fields, access, events, clock, ids, checks);
34
+ const media = new MediaService(access, events, clock, options.media);
35
+ const formStore = options.forms ?? new InMemoryFormRepository();
36
+ const submissionStore = options.submissions ?? new InMemorySubmissionRepository();
37
+ const forms = new FormService(formStore, submissionStore, fields, access, events, clock, ids);
38
+ const contactStore = options.contacts ?? new InMemoryContactRepository();
39
+ const dealStore = options.deals ?? new InMemoryDealRepository();
40
+ const pipeline = new PipelineService(options.pipeline ?? new InMemoryPipelineStore(), contactStore, access, events, ids, dealStore, options.team);
41
+ const customFields = new CustomFieldsService(options.customFields ?? new InMemoryCustomFieldsStore(), fields, access, events, clock, ids);
42
+ const contacts = new ContactService(contactStore, submissionStore, formStore, fields, access, events, clock, ids, pipeline, options.team, dealStore, customFields);
43
+ const deals = new DealService(dealStore, contactStore, contacts, pipeline, access, events, clock, ids, customFields, { types: options.types, entries: options.entries });
44
+ const submissions = new SubmissionService(submissionStore, formStore, fields, access, events, clock, ids, contacts, deals);
45
+ const previews = new PreviewService(content, schema, clock, options.previews);
46
+ const sealWith = options.secret ?? options.previews?.secret;
47
+ const plugins = new PluginHost({ fields, events, checks, pages, store: options.pluginStore ?? new InMemoryPluginStore(), ids, schema, content, access, clock, ...(sealWith !== undefined && { secret: sealWith }), ...(options.lookup && { lookup: options.lookup }), ...(options.onPluginFault && { onFault: options.onPluginFault }) });
48
+ return { schema, content, media, forms, submissions, contacts, pipeline, customFields, deals, previews, fields, events, access, plugins, pages };
49
+ }
50
+ //# sourceMappingURL=cms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cms.js","sourceRoot":"","sources":["../src/cms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAExN,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC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DED
@@ -0,0 +1,3 @@
1
+ /** Whether the text is a real day written as `2026-03-14`, in this century or later. */
2
+ export declare function isDay(text: string): boolean;
3
+ //# sourceMappingURL=day.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day.d.ts","sourceRoot":"","sources":["../src/day.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI3C"}
package/dist/day.js ADDED
@@ -0,0 +1,8 @@
1
+ /** Whether the text is a real day written as `2026-03-14`, in this century or later. */
2
+ export function isDay(text) {
3
+ if (!/^[2-9]\d{3}-\d{2}-\d{2}$/.test(text))
4
+ return false;
5
+ const date = new Date(`${text}T00:00:00.000Z`);
6
+ return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === text;
7
+ }
8
+ //# sourceMappingURL=day.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day.js","sourceRoot":"","sources":["../src/day.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACzD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,gBAAgB,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC;AACnF,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { DefineContext } from './field-type.js';
2
+ import { type FieldDef, type LocalizedText } from './model.js';
3
+ /** A field as someone describes it. The CMS assigns the id. */
4
+ export interface NewField {
5
+ readonly key: string;
6
+ readonly type: string;
7
+ readonly label: LocalizedText;
8
+ readonly help?: LocalizedText;
9
+ readonly translated?: boolean;
10
+ readonly required?: boolean;
11
+ /** Settings for the field type. A group's `fields` and a list's `of` are described the same way. */
12
+ readonly options?: Readonly<Record<string, unknown>>;
13
+ }
14
+ /** Refuses a key that code and templates could not use. */
15
+ export declare function requireKey(key: string, what: string): void;
16
+ /**
17
+ * One field as it is stored. `previous` is the field that already has this key, if there is
18
+ * one: its id is kept, so the content saved under it is still there.
19
+ */
20
+ export declare function defineField(input: NewField, previous: FieldDef | undefined, context: DefineContext): FieldDef;
21
+ /**
22
+ * Fields as they are stored, in the order described. A field already there under the same key
23
+ * keeps its id. Fields that were there and are not described are kept as they were, after the
24
+ * described ones, so describing a type again never loses content.
25
+ */
26
+ export declare function defineFields(described: readonly NewField[], previous: readonly FieldDef[], context: DefineContext): FieldDef[];
27
+ //# sourceMappingURL=define-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-fields.d.ts","sourceRoot":"","sources":["../src/define-fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAc,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3E,+DAA+D;AAC/D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,oGAAoG;IACpG,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACtD;AAID,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAO1D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAAE,OAAO,EAAE,aAAa,GAAG,QAAQ,CAyB7G;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAAE,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,QAAQ,EAAE,CAa9H"}
@@ -0,0 +1,57 @@
1
+ import { ConflictError, ValidationError } from './errors.js';
2
+ import { liveFields } from './model.js';
3
+ const KEY = /^[a-z][a-zA-Z0-9]*(-[a-z0-9]+)*$/;
4
+ /** Refuses a key that code and templates could not use. */
5
+ export function requireKey(key, what) {
6
+ if (!KEY.test(key)) {
7
+ throw new ValidationError(`"${key}" can't be used as a ${what} key. Start with a lowercase letter and use letters, numbers and single hyphens.`, [{ path: ['key'], message: 'Invalid key' }]);
8
+ }
9
+ }
10
+ /**
11
+ * One field as it is stored. `previous` is the field that already has this key, if there is
12
+ * one: its id is kept, so the content saved under it is still there.
13
+ */
14
+ export function defineField(input, previous, context) {
15
+ requireKey(input.key, 'field');
16
+ const type = context.fields.get(input.type);
17
+ const described = input.options ?? {};
18
+ const options = type.options.safeParse(described);
19
+ if (!options.success) {
20
+ throw new ValidationError(`The settings for field "${input.key}" are not valid for a ${input.type} field.`, options.error.issues.map((issue) => ({
21
+ path: issue.path.map((segment) => (typeof segment === 'symbol' ? String(segment) : segment)),
22
+ message: issue.message,
23
+ })));
24
+ }
25
+ const given = input.id;
26
+ return {
27
+ id: previous?.id ?? (typeof given === 'string' ? given : context.ids.next()),
28
+ key: input.key,
29
+ type: input.type,
30
+ label: input.label,
31
+ ...(input.help !== undefined && { help: input.help }),
32
+ translated: input.translated ?? true,
33
+ required: input.required ?? false,
34
+ options: type.define(described, previous?.type === input.type ? previous.options : undefined, context),
35
+ };
36
+ }
37
+ /**
38
+ * Fields as they are stored, in the order described. A field already there under the same key
39
+ * keeps its id. Fields that were there and are not described are kept as they were, after the
40
+ * described ones, so describing a type again never loses content.
41
+ */
42
+ export function defineFields(described, previous, context) {
43
+ const live = new Map(liveFields(previous).map((field) => [field.key, field]));
44
+ const fields = [];
45
+ for (const input of described) {
46
+ // A removed field sent back with the rest is stored state, not a description: it stays removed.
47
+ if (typeof input.deletedAt === 'string')
48
+ continue;
49
+ if (fields.some((field) => field.key === input.key)) {
50
+ throw new ConflictError(`This content type already has a field with the key "${input.key}".`);
51
+ }
52
+ fields.push(defineField(input, live.get(input.key), context));
53
+ }
54
+ const kept = new Set(fields.map((field) => field.id));
55
+ return [...fields, ...previous.filter((field) => !kept.has(field.id))];
56
+ }
57
+ //# sourceMappingURL=define-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-fields.js","sourceRoot":"","sources":["../src/define-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAqC,MAAM,YAAY,CAAC;AAc3E,MAAM,GAAG,GAAG,kCAAkC,CAAC;AAE/C,2DAA2D;AAC3D,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,IAAY;IAClD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,eAAe,CACvB,IAAI,GAAG,wBAAwB,IAAI,kFAAkF,EACrH,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAC5C,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAe,EAAE,QAA8B,EAAE,OAAsB;IACjG,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,C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AAE,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,27 @@
1
+ /** Every error the CMS raises on purpose extends this, with a stable `code` for API responses. */
2
+ export declare abstract class CmsError extends Error {
3
+ abstract readonly code: string;
4
+ constructor(message: string);
5
+ }
6
+ export interface ValidationIssue {
7
+ /** Where the problem is, as field keys and list positions: `['address', 'city']`. */
8
+ readonly path: readonly (string | number)[];
9
+ readonly message: string;
10
+ }
11
+ export declare class ValidationError extends CmsError {
12
+ readonly issues: readonly ValidationIssue[];
13
+ readonly code = "validation_failed";
14
+ constructor(message: string, issues: readonly ValidationIssue[]);
15
+ }
16
+ export declare class ForbiddenError extends CmsError {
17
+ readonly code = "forbidden";
18
+ }
19
+ export declare class NotFoundError extends CmsError {
20
+ readonly code = "not_found";
21
+ constructor(what: string, id: string);
22
+ }
23
+ /** Something else changed first, or a name is already taken. */
24
+ export declare class ConflictError extends CmsError {
25
+ readonly code = "conflict";
26
+ }
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,8BAAsB,QAAS,SAAQ,KAAK;IAC1C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEnB,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,eAAe;IAC9B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,eAAgB,SAAQ,QAAQ;IAKzC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE;IAJ7C,QAAQ,CAAC,IAAI,uBAAuB;gBAGlC,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,SAAS,eAAe,EAAE;CAI9C;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,QAAQ,CAAC,IAAI,eAAe;CAC7B;AAED,qBAAa,aAAc,SAAQ,QAAQ;IACzC,QAAQ,CAAC,IAAI,eAAe;gBAEhB,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAGrC;AAED,gEAAgE;AAChE,qBAAa,aAAc,SAAQ,QAAQ;IACzC,QAAQ,CAAC,IAAI,cAAc;CAC5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,29 @@
1
+ /** Every error the CMS raises on purpose extends this, with a stable `code` for API responses. */
2
+ export class CmsError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = new.target.name;
6
+ }
7
+ }
8
+ export class ValidationError extends CmsError {
9
+ issues;
10
+ code = 'validation_failed';
11
+ constructor(message, issues) {
12
+ super(message);
13
+ this.issues = issues;
14
+ }
15
+ }
16
+ export class ForbiddenError extends CmsError {
17
+ code = 'forbidden';
18
+ }
19
+ export class NotFoundError extends CmsError {
20
+ code = 'not_found';
21
+ constructor(what, id) {
22
+ super(`${what} "${id}" was not found.`);
23
+ }
24
+ }
25
+ /** Something else changed first, or a name is already taken. */
26
+ export class ConflictError extends CmsError {
27
+ code = 'conflict';
28
+ }
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,OAAgB,QAAS,SAAQ,KAAK;IAG1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAQD,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAKhC;IAJF,IAAI,GAAG,mBAAmB,CAAC;IAEpC,YACE,OAAe,EACN,MAAkC;QAE3C,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,WAAM,GAAN,MAAM,CAA4B;IAG7C,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,QAAQ;IACjC,IAAI,GAAG,WAAW,CAAC;CAC7B;AAED,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAChC,IAAI,GAAG,WAAW,CAAC;IAE5B,YAAY,IAAY,EAAE,EAAU;QAClC,KAAK,CAAC,GAAG,IAAI,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,gEAAgE;AAChE,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAChC,IAAI,GAAG,UAAU,CAAC;CAC5B"}
@@ -0,0 +1,146 @@
1
+ import type { Actor } from './access.js';
2
+ import type { Permission } from './access.js';
3
+ import type { Contact, CustomFields, Deal, ContentTypeDef, Entry, FormDef, MediaFile, Pipeline, Submission } from './model.js';
4
+ /** Everything the CMS announces, and what each announcement carries. */
5
+ export interface CmsEvents {
6
+ 'type.saved': {
7
+ type: ContentTypeDef;
8
+ actor: Actor;
9
+ };
10
+ /** The type's pages have left the site, or with `type.restored` are back on it. */
11
+ 'type.archived': {
12
+ type: ContentTypeDef;
13
+ actor: Actor;
14
+ };
15
+ 'type.restored': {
16
+ type: ContentTypeDef;
17
+ actor: Actor;
18
+ };
19
+ 'entry.saved': {
20
+ entry: Entry;
21
+ actor: Actor;
22
+ };
23
+ /** `before` is the entry as it was, so a listener can tell what visitors saw until now. */
24
+ 'entry.published': {
25
+ entry: Entry;
26
+ before: Entry;
27
+ actor: Actor;
28
+ };
29
+ 'entry.unpublished': {
30
+ entry: Entry;
31
+ before: Entry;
32
+ actor: Actor;
33
+ };
34
+ /** The entry went to the trash. One that was on the site is announced as unpublished first. */
35
+ 'entry.trashed': {
36
+ entry: Entry;
37
+ before: Entry;
38
+ actor: Actor;
39
+ };
40
+ /** The entry came back from the trash, as a draft. */
41
+ 'entry.restored': {
42
+ entry: Entry;
43
+ actor: Actor;
44
+ };
45
+ /** The entry and its history are gone for good. `entry` is what it was. */
46
+ 'entry.deleted': {
47
+ entry: Entry;
48
+ actor: Actor;
49
+ };
50
+ 'form.saved': {
51
+ form: FormDef;
52
+ actor: Actor;
53
+ };
54
+ /** The form went to the trash, came back from it, or is gone for good with its submissions. */
55
+ 'form.trashed': {
56
+ form: FormDef;
57
+ actor: Actor;
58
+ };
59
+ 'form.restored': {
60
+ form: FormDef;
61
+ actor: Actor;
62
+ };
63
+ 'form.deleted': {
64
+ form: FormDef;
65
+ actor: Actor;
66
+ };
67
+ /** A visitor sent a form. Nobody is acting: the sender is not a user of the CMS. */
68
+ 'submission.received': {
69
+ submission: Submission;
70
+ form: FormDef;
71
+ };
72
+ /** A submission was marked new, handled or spam. */
73
+ 'submission.changed': {
74
+ submission: Submission;
75
+ actor: Actor;
76
+ };
77
+ /** Submissions are gone for good: deleted, erased for a person, or past the time they are kept. */
78
+ 'submission.deleted': {
79
+ formId: string;
80
+ ids: readonly string[];
81
+ actor: Actor;
82
+ };
83
+ /** A contact was made or changed. Nobody is acting when a submission made it. */
84
+ /** `imported` says the contact came in with many others from a file, so it is not news one at a time. */
85
+ 'contact.saved': {
86
+ contact: Contact;
87
+ actor?: Actor;
88
+ imported?: true;
89
+ };
90
+ /** A contact is gone for good, with its notes. `contact` is what it was. */
91
+ 'contact.deleted': {
92
+ contact: Contact;
93
+ actor: Actor;
94
+ };
95
+ /** A deal was made or changed, or is gone for good. */
96
+ 'deal.saved': {
97
+ deal: Deal;
98
+ actor?: Actor;
99
+ };
100
+ 'deal.deleted': {
101
+ deal: Deal;
102
+ actor: Actor;
103
+ };
104
+ /** The stages contacts move through were changed. */
105
+ 'pipeline.saved': {
106
+ pipeline: Pipeline;
107
+ actor: Actor;
108
+ };
109
+ /** The fields a site adds to its contacts and deals were changed. */
110
+ 'custom-fields.saved': {
111
+ fields: CustomFields;
112
+ actor: Actor;
113
+ };
114
+ 'media.uploaded': {
115
+ file: MediaFile;
116
+ actor: Actor;
117
+ };
118
+ 'media.removed': {
119
+ file: MediaFile;
120
+ actor: Actor;
121
+ };
122
+ /** A plugin was switched on or off, or its settings were saved. */
123
+ 'plugin.changed': {
124
+ plugin: string;
125
+ actor: Actor;
126
+ };
127
+ /** A plugin says the site's pages would now come out differently, so kept copies are stale. */
128
+ 'pages.changed': {
129
+ plugin: string;
130
+ };
131
+ }
132
+ /**
133
+ * What a listener must be allowed before it is told of an event. Submissions and contacts are
134
+ * personal data, so a plugin hears of them only if it declared that it reads them.
135
+ */
136
+ export declare const EVENT_NEEDS: Readonly<Partial<Record<keyof CmsEvents, Permission>>>;
137
+ type Listener<T> = (payload: T) => void | Promise<void>;
138
+ export declare class EventBus {
139
+ #private;
140
+ /** Listens for an event. Returns a function that stops listening. */
141
+ on<K extends keyof CmsEvents>(event: K, listener: Listener<CmsEvents[K]>): () => void;
142
+ /** Runs every listener in the order it was added, and waits for each. */
143
+ emit<K extends keyof CmsEvents>(event: K, payload: CmsEvents[K]): Promise<void>;
144
+ }
145
+ export {};
146
+ //# sourceMappingURL=events.d.ts.map