@12-apps/tenant 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  *
5
5
  * Backend: `@12-apps/tenant/server` (`createApiTenant`). Hono mount:
6
6
  * `@12-apps/tenant/hono`. Frontend: `@12-apps/tenant/react`
7
- * (`createWebTenant`). Adoption contract: ADOPTING.md.
7
+ * (`createWebTenant`). Custom domains: the engine here, the pure half in
8
+ * `@12-apps/tenant/domains`, the screen in `@12-apps/tenant/domains/react`. Adoption contract: ADOPTING.md.
8
9
  */
9
10
  export {
10
11
  TENANT_COPY_KEYS,
@@ -63,6 +64,32 @@ export {
63
64
  type TenantSlugResolver,
64
65
  type TenantSlugs,
65
66
  } from './slugs';
67
+ export {
68
+ TENANT_DOMAIN_PORT_METHODS,
69
+ TENANT_DOMAIN_QUOTA_METHODS,
70
+ TENANT_DOMAIN_RESOLVER_METHODS,
71
+ createApiTenantDomains,
72
+ createDnsChecks,
73
+ createTenantDomains,
74
+ createTlsAsk,
75
+ validateDomains,
76
+ type ApiTenantDomains,
77
+ type TenantDomainAnswer,
78
+ type TenantDomainContext,
79
+ type TenantDomainDnsChecks,
80
+ type TenantDomainDnsChecksConfig,
81
+ type TenantDomainOutcome,
82
+ type TenantDomainPort,
83
+ type TenantDomainQuota,
84
+ type TenantDomainResolver,
85
+ type TenantDomainResult,
86
+ type TenantDomains,
87
+ type TenantDomainsConfig,
88
+ type TenantDomainsServerConfig,
89
+ type TenantDomainTls,
90
+ type TenantDomainTlsAnswer,
91
+ type TenantDomainTlsConfig,
92
+ } from './domains/server';
66
93
  export { TenantConfigError, validateCoreConfig, validatePort, validateSlugs, validateTreePort } from './validate';
67
94
  export type { DeepReadonly, TenantReadings, TenantRefusalKind } from './core';
68
95
  export {
@@ -21,6 +21,12 @@ import { validateCoreConfig, validatePort, validateSlugs, validateTreePort } fro
21
21
  import { createTenantLifecycle, type TenantLifecycle, type TenantLifecycleConfig } from '../lifecycle';
22
22
 
23
23
  export * from '../lifecycle';
24
+ import {
25
+ createApiTenantDomains,
26
+ validateDomains,
27
+ type ApiTenantDomains,
28
+ type TenantDomainsServerConfig,
29
+ } from '../domains/server';
24
30
 
25
31
  export { TenantConfigError } from '../validate';
26
32
  export {
@@ -44,6 +50,32 @@ export {
44
50
  type TenantSlugResolver,
45
51
  type TenantSlugs,
46
52
  } from '../slugs';
53
+ export {
54
+ TENANT_DOMAIN_PORT_METHODS,
55
+ TENANT_DOMAIN_QUOTA_METHODS,
56
+ TENANT_DOMAIN_RESOLVER_METHODS,
57
+ createApiTenantDomains,
58
+ createDnsChecks,
59
+ createTenantDomains,
60
+ createTlsAsk,
61
+ validateDomains,
62
+ type ApiTenantDomains,
63
+ type TenantDomainAnswer,
64
+ type TenantDomainContext,
65
+ type TenantDomainDnsChecks,
66
+ type TenantDomainDnsChecksConfig,
67
+ type TenantDomainOutcome,
68
+ type TenantDomainPort,
69
+ type TenantDomainQuota,
70
+ type TenantDomainResolver,
71
+ type TenantDomainResult,
72
+ type TenantDomains,
73
+ type TenantDomainsConfig,
74
+ type TenantDomainsServerConfig,
75
+ type TenantDomainTls,
76
+ type TenantDomainTlsAnswer,
77
+ type TenantDomainTlsConfig,
78
+ } from '../domains/server';
47
79
 
48
80
  /** Slug resolution's config: the host's slug port and its kept memory. */
49
81
  export interface TenantSlugsConfig<R extends TenantSlugRecord = TenantSlugRecord> {
@@ -61,9 +93,9 @@ export interface TenantRoute {
61
93
  }
62
94
 
63
95
  /**
64
- * Everything `createApiTenant` needs. Nothing is optional but the tenant tree and
65
- * slug resolution, opt-in features: give `tree` or `slugs` and every one of
66
- * its members is required.
96
+ * Everything `createApiTenant` needs. Nothing is optional but the tenant tree,
97
+ * slug resolution, the lifecycle and custom domains, opt-in features: give
98
+ * `tree`, `slugs`, `lifecycle` or `domains` and every one of its members is required.
67
99
  */
68
100
  export interface TenantServerConfig<
69
101
  S extends string = string,
@@ -89,6 +121,11 @@ export interface TenantServerConfig<
89
121
  * `byId` MUST return each tenant's `name`.
90
122
  */
91
123
  lifecycle?: TenantLifecycleConfig<S, Tx>;
124
+ /**
125
+ * Custom domains (the host's domain port, its quota, the DNS checks' resolver,
126
+ * targets and TXT prefix, the TLS ask). Left out, `tenant.domains` is absent.
127
+ */
128
+ domains?: TenantDomainsServerConfig<Tx>;
92
129
  }
93
130
 
94
131
  export interface ApiTenant<S extends string = string, Tx = unknown, R extends TenantSlugRecord = TenantSlugRecord>
@@ -103,6 +140,8 @@ export interface ApiTenant<S extends string = string, Tx = unknown, R extends Te
103
140
  slugs?: TenantSlugs<R>;
104
141
  /** The closing lifecycle through `config.lifecycle`; absent when none was given. */
105
142
  lifecycle?: TenantLifecycle<S>;
143
+ /** Custom domains through `config.domains`; absent when none was given. */
144
+ domains?: ApiTenantDomains;
106
145
  /** The package's routes, in mount order. None yet: the lifecycle slice adds them. */
107
146
  routes: readonly TenantRoute[];
108
147
  /** The tenant, read through the port, on `tx` when given. */
@@ -125,6 +164,8 @@ export function createApiTenant<S extends string, Tx = unknown, R extends Tenant
125
164
  if (treePort !== undefined) validateTreePort(treePort);
126
165
  const slugs = (config as { slugs?: unknown }).slugs;
127
166
  if (slugs !== undefined) validateSlugs(slugs);
167
+ const domains = (config as { domains?: unknown }).domains;
168
+ if (domains !== undefined) validateDomains(domains);
128
169
  const data = frozenCopy({ statuses: config.statuses, ids: config.ids, copy: config.copy });
129
170
  const known = new Set<string>(data.statuses.all);
130
171
  const { port } = config;
@@ -134,6 +175,7 @@ export function createApiTenant<S extends string, Tx = unknown, R extends Tenant
134
175
  port,
135
176
  ...(config.tree === undefined ? {} : { tree: createTenantTree(config.tree) }),
136
177
  ...(config.slugs === undefined ? {} : { slugs: createTenantSlugs(config.slugs) }),
178
+ ...(config.domains === undefined ? {} : { domains: createApiTenantDomains(config.domains) }),
137
179
  routes: Object.freeze([]),
138
180
  byId: (id, tx) => port.byId(id, tx),
139
181
  setStatusIf: (id, from, to, tx) => {