@nuwah/vertical-sdk 0.0.0-stage → 0.2.0-rc.1

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 (239) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +229 -2
  3. package/bin/nuwah-contract-check-rules.d.mts +41 -0
  4. package/bin/nuwah-contract-check-rules.mjs +333 -0
  5. package/bin/nuwah-contract-check.mjs +64 -0
  6. package/dist/accounting.d.ts +1417 -0
  7. package/dist/accounting.js +274 -0
  8. package/dist/active-org.d.ts +13 -0
  9. package/dist/active-org.js +59 -0
  10. package/dist/actors.d.ts +448 -0
  11. package/dist/actors.js +143 -0
  12. package/dist/ai.d.ts +359 -0
  13. package/dist/ai.js +229 -0
  14. package/dist/analytics.d.ts +37 -0
  15. package/dist/analytics.js +8 -0
  16. package/dist/atlas.d.ts +291 -0
  17. package/dist/atlas.js +78 -0
  18. package/dist/audit.d.ts +193 -0
  19. package/dist/audit.js +26 -0
  20. package/dist/authentication.d.ts +119 -0
  21. package/dist/authentication.js +83 -0
  22. package/dist/awards.d.ts +38 -0
  23. package/dist/awards.js +10 -0
  24. package/dist/blueprint/document.d.ts +178 -0
  25. package/dist/blueprint/document.js +17 -0
  26. package/dist/blueprint/index.d.ts +3 -0
  27. package/dist/blueprint/index.js +5 -0
  28. package/dist/blueprint/manifest.d.ts +105 -0
  29. package/dist/blueprint/manifest.js +11 -0
  30. package/dist/blueprint/validate.d.ts +14 -0
  31. package/dist/blueprint/validate.js +416 -0
  32. package/dist/bookings-directory.d.ts +118 -0
  33. package/dist/bookings-directory.js +289 -0
  34. package/dist/bookings-extra.d.ts +1448 -0
  35. package/dist/bookings-extra.js +582 -0
  36. package/dist/bookings.d.ts +1365 -0
  37. package/dist/bookings.js +305 -0
  38. package/dist/builder-code.d.ts +164 -0
  39. package/dist/builder-code.js +12 -0
  40. package/dist/builder-core-gaps.d.ts +83 -0
  41. package/dist/builder-core-gaps.js +8 -0
  42. package/dist/builder-repos.d.ts +73 -0
  43. package/dist/builder-repos.js +37 -0
  44. package/dist/builder.d.ts +730 -0
  45. package/dist/builder.js +105 -0
  46. package/dist/campaigns.d.ts +105 -0
  47. package/dist/campaigns.js +25 -0
  48. package/dist/catalogs.d.ts +188 -0
  49. package/dist/catalogs.js +36 -0
  50. package/dist/commerce-ai.d.ts +182 -0
  51. package/dist/commerce-ai.js +27 -0
  52. package/dist/connections.d.ts +278 -0
  53. package/dist/connections.js +96 -0
  54. package/dist/content-control.d.ts +121 -0
  55. package/dist/content-control.js +23 -0
  56. package/dist/contributions.d.ts +560 -0
  57. package/dist/contributions.js +140 -0
  58. package/dist/conversation-assist.d.ts +154 -0
  59. package/dist/conversation-assist.js +51 -0
  60. package/dist/conversation-info.d.ts +219 -0
  61. package/dist/conversation-info.js +43 -0
  62. package/dist/crm.d.ts +533 -0
  63. package/dist/crm.js +142 -0
  64. package/dist/dashboards.d.ts +119 -0
  65. package/dist/dashboards.js +22 -0
  66. package/dist/delegations.d.ts +161 -0
  67. package/dist/delegations.js +39 -0
  68. package/dist/docs.d.ts +289 -0
  69. package/dist/docs.js +49 -0
  70. package/dist/documents.d.ts +317 -0
  71. package/dist/documents.js +84 -0
  72. package/dist/drafts.d.ts +132 -0
  73. package/dist/drafts.js +56 -0
  74. package/dist/engagements.d.ts +133 -0
  75. package/dist/engagements.js +15 -0
  76. package/dist/event-stream.d.ts +54 -0
  77. package/dist/event-stream.js +228 -0
  78. package/dist/exchanges.d.ts +447 -0
  79. package/dist/exchanges.js +145 -0
  80. package/dist/exports.d.ts +113 -0
  81. package/dist/exports.js +81 -0
  82. package/dist/feeds.d.ts +228 -0
  83. package/dist/feeds.js +52 -0
  84. package/dist/files.d.ts +56 -0
  85. package/dist/files.js +55 -0
  86. package/dist/finance-insights.d.ts +41 -0
  87. package/dist/finance-insights.js +61 -0
  88. package/dist/fixed-assets.d.ts +155 -0
  89. package/dist/fixed-assets.js +28 -0
  90. package/dist/fulfilment-jobs.d.ts +405 -0
  91. package/dist/fulfilment-jobs.js +76 -0
  92. package/dist/fulfilment.d.ts +205 -0
  93. package/dist/fulfilment.js +39 -0
  94. package/dist/hr.d.ts +350 -0
  95. package/dist/hr.js +94 -0
  96. package/dist/http.d.ts +124 -0
  97. package/dist/http.js +392 -0
  98. package/dist/inbox.d.ts +206 -0
  99. package/dist/inbox.js +36 -0
  100. package/dist/index.d.ts +384 -0
  101. package/dist/index.js +294 -0
  102. package/dist/insights.d.ts +176 -0
  103. package/dist/insights.js +52 -0
  104. package/dist/inventory.d.ts +797 -0
  105. package/dist/inventory.js +120 -0
  106. package/dist/list-query.d.ts +211 -0
  107. package/dist/list-query.js +158 -0
  108. package/dist/listings.d.ts +381 -0
  109. package/dist/listings.js +173 -0
  110. package/dist/location-sharing.d.ts +83 -0
  111. package/dist/location-sharing.js +20 -0
  112. package/dist/marketplace.d.ts +268 -0
  113. package/dist/marketplace.js +59 -0
  114. package/dist/matching.d.ts +103 -0
  115. package/dist/matching.js +22 -0
  116. package/dist/media.d.ts +221 -0
  117. package/dist/media.js +239 -0
  118. package/dist/metrics.d.ts +125 -0
  119. package/dist/metrics.js +45 -0
  120. package/dist/moderation.d.ts +240 -0
  121. package/dist/moderation.js +40 -0
  122. package/dist/money.d.ts +41 -0
  123. package/dist/money.js +79 -0
  124. package/dist/my-data.d.ts +266 -0
  125. package/dist/my-data.js +32 -0
  126. package/dist/names.d.ts +14 -0
  127. package/dist/names.js +17 -0
  128. package/dist/occasions.d.ts +256 -0
  129. package/dist/occasions.js +40 -0
  130. package/dist/onboarding.d.ts +88 -0
  131. package/dist/onboarding.js +38 -0
  132. package/dist/pagination.d.ts +204 -0
  133. package/dist/pagination.js +141 -0
  134. package/dist/party-baseline-attributes.d.ts +245 -0
  135. package/dist/party-baseline-attributes.js +36 -0
  136. package/dist/party.d.ts +401 -0
  137. package/dist/party.js +56 -0
  138. package/dist/patient.d.ts +161 -0
  139. package/dist/patient.js +45 -0
  140. package/dist/payroll.d.ts +378 -0
  141. package/dist/payroll.js +60 -0
  142. package/dist/person-addresses.d.ts +88 -0
  143. package/dist/person-addresses.js +18 -0
  144. package/dist/person-cart.d.ts +250 -0
  145. package/dist/person-cart.js +63 -0
  146. package/dist/person-chat-assist.d.ts +47 -0
  147. package/dist/person-chat-assist.js +13 -0
  148. package/dist/person-data-webhooks.d.ts +72 -0
  149. package/dist/person-data-webhooks.js +86 -0
  150. package/dist/person-data.d.ts +212 -0
  151. package/dist/person-data.js +162 -0
  152. package/dist/person-locations.d.ts +54 -0
  153. package/dist/person-locations.js +6 -0
  154. package/dist/person-messaging.d.ts +405 -0
  155. package/dist/person-messaging.js +112 -0
  156. package/dist/person-notifications.d.ts +319 -0
  157. package/dist/person-notifications.js +164 -0
  158. package/dist/personalisation.d.ts +21 -0
  159. package/dist/personalisation.js +8 -0
  160. package/dist/platform.d.ts +63 -0
  161. package/dist/platform.js +45 -0
  162. package/dist/portfolio.d.ts +163 -0
  163. package/dist/portfolio.js +28 -0
  164. package/dist/pos.d.ts +743 -0
  165. package/dist/pos.js +129 -0
  166. package/dist/procurement.d.ts +664 -0
  167. package/dist/procurement.js +157 -0
  168. package/dist/promotions.d.ts +169 -0
  169. package/dist/promotions.js +39 -0
  170. package/dist/publications.d.ts +583 -0
  171. package/dist/publications.js +164 -0
  172. package/dist/ranking.d.ts +43 -0
  173. package/dist/ranking.js +34 -0
  174. package/dist/ratings.d.ts +293 -0
  175. package/dist/ratings.js +109 -0
  176. package/dist/reactions.d.ts +123 -0
  177. package/dist/reactions.js +41 -0
  178. package/dist/recipient-orders.d.ts +294 -0
  179. package/dist/recipient-orders.js +73 -0
  180. package/dist/relationships.d.ts +18 -0
  181. package/dist/relationships.js +8 -0
  182. package/dist/reporting.d.ts +107 -0
  183. package/dist/reporting.js +56 -0
  184. package/dist/sales.d.ts +270 -0
  185. package/dist/sales.js +66 -0
  186. package/dist/shares.d.ts +105 -0
  187. package/dist/shares.js +27 -0
  188. package/dist/shop.d.ts +993 -0
  189. package/dist/shop.js +215 -0
  190. package/dist/shopping-assistant.d.ts +65 -0
  191. package/dist/shopping-assistant.js +14 -0
  192. package/dist/spaces.d.ts +422 -0
  193. package/dist/spaces.js +118 -0
  194. package/dist/stored-value.d.ts +754 -0
  195. package/dist/stored-value.js +177 -0
  196. package/dist/types.d.ts +83 -0
  197. package/dist/types.js +2 -0
  198. package/dist/vault.d.ts +290 -0
  199. package/dist/vault.js +55 -0
  200. package/dist/vertical-runtime.d.ts +17 -0
  201. package/dist/vertical-runtime.js +8 -0
  202. package/dist/vite/build-manifest-plugin.d.ts +42 -0
  203. package/dist/vite/build-manifest-plugin.js +42 -0
  204. package/dist/vite/first-paint-plugin.d.ts +26 -0
  205. package/dist/vite/first-paint-plugin.js +57 -0
  206. package/dist/wishlists.d.ts +591 -0
  207. package/dist/wishlists.js +188 -0
  208. package/dist/workbench.d.ts +114 -0
  209. package/dist/workbench.js +22 -0
  210. package/dist/workspace.d.ts +190 -0
  211. package/dist/workspace.js +41 -0
  212. package/package.json +52 -4
  213. package/templates/extension-image.Dockerfile +38 -0
  214. package/templates/nuwah-vertical.yml +102 -0
  215. package/templates/vertical-app/.env.example +34 -0
  216. package/templates/vertical-app/README.md +108 -0
  217. package/templates/vertical-app/github/workflows/ci.yml +51 -0
  218. package/templates/vertical-app/gitignore +5 -0
  219. package/templates/vertical-app/index.html +12 -0
  220. package/templates/vertical-app/package.json +28 -0
  221. package/templates/vertical-app/src/App.tsx +64 -0
  222. package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
  223. package/templates/vertical-app/src/blueprint/screens.ts +15 -0
  224. package/templates/vertical-app/src/env.d.ts +18 -0
  225. package/templates/vertical-app/src/index.css +139 -0
  226. package/templates/vertical-app/src/lib/i18n.ts +5 -0
  227. package/templates/vertical-app/src/lib/iam.ts +19 -0
  228. package/templates/vertical-app/src/lib/operations.ts +93 -0
  229. package/templates/vertical-app/src/lib/router.ts +24 -0
  230. package/templates/vertical-app/src/lib/sdk.ts +21 -0
  231. package/templates/vertical-app/src/lib/theme.ts +18 -0
  232. package/templates/vertical-app/src/lib/words.ts +39 -0
  233. package/templates/vertical-app/src/main.tsx +25 -0
  234. package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
  235. package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
  236. package/templates/vertical-app/src/pages/Home.tsx +36 -0
  237. package/templates/vertical-app/tsconfig.json +24 -0
  238. package/templates/vertical-app/vite.config.ts +23 -0
  239. package/templates/vertical-ci.yml +192 -0
@@ -0,0 +1,119 @@
1
+ import { type JWTPayload, type JWTVerifyGetKey } from 'jose';
2
+ export interface AuthConfig {
3
+ /** Expected issuer (`iss`) — iam-verse stamps its own APP_URL. */
4
+ issuer: string;
5
+ /** Expected audience — enforced only when `enforceAudience` is set. */
6
+ audience: string;
7
+ /** `aud` is opt-in on the platform; only assert it when core stamps it. */
8
+ enforceAudience: boolean;
9
+ /** A jose key resolver. Prod: `createRemoteJWKSet(url)`. Tests: a local set. */
10
+ jwks: JWTVerifyGetKey;
11
+ }
12
+ /** Build a remote JWKS resolver from the platform JWKS URL. */
13
+ export declare function remoteJwks(jwksUrl: string): JWTVerifyGetKey;
14
+ export interface StaffIdentity {
15
+ sub: string;
16
+ name: string;
17
+ email: string;
18
+ org: string | null;
19
+ modules: string[];
20
+ /**
21
+ * The platform Terms version this token's holder has accepted, read off the `terms_version`
22
+ * claim. THREE distinct states, and a consumer that collapses any two of them is wrong:
23
+ *
24
+ * a non-empty string → accepted, and the identity service confirmed that version is still
25
+ * in force (it does the effective/retired test itself, so a vertical
26
+ * must NOT re-derive it)
27
+ * `null` → the identity service speaks Terms, and this holder has not accepted
28
+ * (or accepted a version since retired)
29
+ * `undefined` → the claim was not on the token AT ALL — a token minted before the
30
+ * claim existed, or by a service that does not know about Terms
31
+ *
32
+ * Only `termsVersion` is surfaced here. The other claims this seam can now read
33
+ * (`consent_version`, `person_id`, `assurance_tier`, `org_cleared`, `scp` — see
34
+ * {@link IamClaims}) are deliberately NOT copied onto the staff identity: this object is the
35
+ * body `/whoami` returns, and widening a public response is a product decision rather than a
36
+ * refactor. Read them off the payload where you need them.
37
+ */
38
+ termsVersion?: string | null;
39
+ }
40
+ /**
41
+ * The Hono `Env` the vertical backends parameterise their app with. Declared here rather than
42
+ * imported from hono, for the reason in the file header; it satisfies hono's own `Env` shape
43
+ * structurally, so `new Hono<StaffEnv>()` keeps working unchanged.
44
+ */
45
+ export interface StaffEnv {
46
+ Variables: {
47
+ staff: StaffIdentity;
48
+ /** The raw verified bearer, so orchestration routes can re-present it to core. */
49
+ token: string;
50
+ };
51
+ }
52
+ /**
53
+ * The slice of a Hono `Context` this seam touches — THREE members, and no more on purpose.
54
+ *
55
+ * Every member added here is a member a consumer's `Context` must still structurally satisfy, so
56
+ * the narrowness is the compatibility. `json()` is conspicuously absent: its hono signature is
57
+ * generic over `ContentfulStatusCode` and a `TypedResponse` return, which is exactly the kind of
58
+ * surface that stops being assignable across two copies of a declaration file. Refusals are
59
+ * built with the platform `Response` constructor instead.
60
+ */
61
+ export interface StaffMiddlewareContext {
62
+ req: {
63
+ header(name: string): string | undefined;
64
+ };
65
+ set<Key extends keyof StaffEnv['Variables']>(key: Key, value: StaffEnv['Variables'][Key]): void;
66
+ get<Key extends keyof StaffEnv['Variables']>(key: Key): StaffEnv['Variables'][Key];
67
+ }
68
+ /**
69
+ * A middleware in this seam. Structurally a hono `MiddlewareHandler<StaffEnv>` — assignable to
70
+ * it in both directions that matter, without naming it.
71
+ */
72
+ export type StaffMiddleware = (context: StaffMiddlewareContext, next: () => Promise<void>) => Promise<Response | void>;
73
+ export interface IamClaims extends JWTPayload {
74
+ name?: string;
75
+ email?: string;
76
+ org?: string | null;
77
+ modules?: Record<string, unknown>;
78
+ /**
79
+ * The accepted-and-in-force Terms version, or `null`. The KEY IS ALWAYS PRESENT on a token
80
+ * from an identity service that knows about Terms, including when the value is null — that
81
+ * is deliberate on the issuing side, and it is the only reason "not accepted" can be told
82
+ * apart from "this token predates Terms". Optional here because both kinds of token are in
83
+ * circulation during the rollout.
84
+ */
85
+ terms_version?: string | null;
86
+ /** The optional-processing consent version. `''`, not null, when there is none. */
87
+ consent_version?: string;
88
+ /** The granular consent purposes behind `consent_version`. */
89
+ consent_purposes?: string[];
90
+ /** KYC assurance tier off the Person's metadata; null when unbound or not yet verified. */
91
+ assurance_tier?: string | null;
92
+ /** The Person this user is bound to. Omitted entirely when the user has no Person. */
93
+ person_id?: string | null;
94
+ /** Whether the org is cleared for provisioning. A boolean, and absent on an ID token. */
95
+ org_cleared?: boolean;
96
+ /** Granted OAuth scopes. */
97
+ scp?: string[];
98
+ }
99
+ /**
100
+ * Bearer-token guard (factory). Attaches the verified staff identity AND the raw
101
+ * token to the context — the raw token is what orchestration routes hand to the
102
+ * SDK so every core call runs as the caller.
103
+ */
104
+ export declare function requireStaff(config: AuthConfig): StaffMiddleware;
105
+ /**
106
+ * Tenant-data guard. The vertical-only stores (protocols, overlays, settings) and the
107
+ * subject-360 are TENANT-scoped, so they require a token that carries an `org`.
108
+ * Chains after {@link requireStaff}; 403s an org-less token.
109
+ */
110
+ export declare const requireOrg: StaffMiddleware;
111
+ export interface TermsAcceptanceGuardOptions {
112
+ tokensWithoutTheTermsClaim?: 'allow' | 'deny';
113
+ /**
114
+ * Where the holder goes to accept. Named in the refusal when supplied, because a 403 that
115
+ * does not say where to go is a dead end. Falls back to naming the IAM account settings.
116
+ */
117
+ acceptanceUrl?: string;
118
+ }
119
+ export declare function requireTermsAccepted(options?: TermsAcceptanceGuardOptions): StaffMiddleware;
@@ -0,0 +1,83 @@
1
+ import { createRemoteJWKSet, jwtVerify } from 'jose';
2
+
3
+ export function remoteJwks(jwksUrl) {
4
+ return createRemoteJWKSet(new URL(jwksUrl));
5
+ }
6
+
7
+ function refuse(status, message) {
8
+ return new Response(JSON.stringify({ error: message }), {
9
+ status,
10
+ headers: { 'content-type': 'application/json; charset=UTF-8' },
11
+ });
12
+ }
13
+
14
+ export function requireStaff(config) {
15
+ return async (context, next) => {
16
+ const header = context.req.header('authorization') ?? '';
17
+ const match = header.trim().match(/^Bearer\s+(.+)$/i);
18
+ if (!match)
19
+ return refuse(401, 'missing bearer token');
20
+ const token = match[1];
21
+ let payload;
22
+ try {
23
+ const verified = await jwtVerify(token, config.jwks, {
24
+ issuer: config.issuer,
25
+ algorithms: ['RS256'],
26
+ ...(config.enforceAudience ? { audience: config.audience } : {}),
27
+ });
28
+ payload = verified.payload;
29
+ }
30
+ catch {
31
+
32
+ return refuse(401, 'invalid token');
33
+ }
34
+ if (!payload.sub)
35
+ return refuse(401, 'token missing sub');
36
+ context.set('staff', {
37
+ sub: payload.sub,
38
+ name: payload.name ?? payload.sub,
39
+ email: payload.email ?? '',
40
+ org: typeof payload.org === 'string' && payload.org !== '' ? payload.org : null,
41
+ modules: Object.keys(payload.modules ?? {}),
42
+
43
+ termsVersion: payload.terms_version,
44
+ });
45
+ context.set('token', token);
46
+ await next();
47
+ };
48
+ }
49
+
50
+ export const requireOrg = async (context, next) => {
51
+ if (!context.get('staff').org) {
52
+ return refuse(403, 'this endpoint requires an org-scoped token');
53
+ }
54
+ await next();
55
+ };
56
+
57
+ export function requireTermsAccepted(options = {}) {
58
+ const tokensWithoutTheTermsClaim = options.tokensWithoutTheTermsClaim ?? 'allow';
59
+ return async (context, next) => {
60
+ const acceptedTermsVersion = context.get('staff').termsVersion;
61
+
62
+ if (acceptedTermsVersion === undefined) {
63
+ if (tokensWithoutTheTermsClaim === 'allow') {
64
+ await next();
65
+ return;
66
+ }
67
+ return refuse(403, termsRefusalMessage('this token carries no terms_version claim, so whether its holder accepted the platform Terms cannot be established', options.acceptanceUrl));
68
+ }
69
+
70
+ if (typeof acceptedTermsVersion === 'string' && acceptedTermsVersion !== '') {
71
+ await next();
72
+ return;
73
+ }
74
+ return refuse(403, termsRefusalMessage('the signed-in account has not accepted the platform Terms currently in force', options.acceptanceUrl));
75
+ };
76
+ }
77
+
78
+ function termsRefusalMessage(reason, acceptanceUrl) {
79
+ const remedy = acceptanceUrl
80
+ ? `accept them at ${acceptanceUrl}, then sign in again so a token carrying terms_version is issued`
81
+ : 'accept them in the IAM account settings, then sign in again so a token carrying terms_version is issued';
82
+ return `${reason} — ${remedy}`;
83
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Awards module — `/api/awards/*`. Person-plane vault + showcase Bridge, plus the operator M2M
3
+ * issue route. Awards are platform-issued collectibles (rarity tiers) collected into a vault and
4
+ * showcased on the public Portfolio.
5
+ */
6
+ import type { Http } from './http.js';
7
+ export interface VaultAward {
8
+ key: string;
9
+ name: string;
10
+ rarity: string;
11
+ icon: string;
12
+ earned: boolean;
13
+ showcased: boolean;
14
+ issuance_id: string | null;
15
+ }
16
+ export interface VaultResponse {
17
+ vault: VaultAward[];
18
+ }
19
+ export interface IssueAwardRequest {
20
+ person_id: string;
21
+ award_key: string;
22
+ org_id?: string | null;
23
+ reason?: string | null;
24
+ }
25
+ export declare function createAwardsNamespace(http: Http): {
26
+ /** GET /api/awards/vault — the caller's award vault (earned + locked + showcased). */
27
+ vault: () => Promise<VaultResponse>;
28
+ /** POST /api/awards/showcase — toggle an earned award onto/off the public Portfolio. */
29
+ showcase: (issuanceId: string, showcase: boolean) => Promise<{
30
+ ok: boolean;
31
+ }>;
32
+ /** POST /api/awards/issue — operator M2M: issue an award to a person (audited). */
33
+ issue: (req: IssueAwardRequest) => Promise<{
34
+ issued: boolean;
35
+ issuance_id: string;
36
+ }>;
37
+ };
38
+ export type AwardsNamespace = ReturnType<typeof createAwardsNamespace>;
package/dist/awards.js ADDED
@@ -0,0 +1,10 @@
1
+ export function createAwardsNamespace(http) {
2
+ return {
3
+
4
+ vault: () => http.get('/api/awards/vault'),
5
+
6
+ showcase: (issuanceId, showcase) => http.post('/api/awards/showcase', { issuance_id: issuanceId, showcase }),
7
+
8
+ issue: (req) => http.post('/api/awards/issue', req),
9
+ };
10
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * The blueprint document, version 1: the ONE declarative description of a vertical.
3
+ *
4
+ * Matches core's `Builder/Schema/blueprint.v1.json` (served at `GET api/builder/blueprint-schema`)
5
+ * field for field. The AI builder and a developer's own forms produce it; the vertical runtime
6
+ * consumes it. Changes within version "1" are additive only, so a reader written against this
7
+ * type keeps working; a new major shape gets a new `schema_version`.
8
+ *
9
+ * Shape is not enough: every key must also be DECLARED by the platform (modules in the module
10
+ * catalog, words in the vocabulary registry, policies open at the vertical level, data categories,
11
+ * screen packs). `validateBlueprint` checks the shape offline; core's validator checks both, through
12
+ * `client.verticalRuntime.interpret` or the builder's own routes.
13
+ */
14
+ export declare const BLUEPRINT_SCHEMA_VERSION: "1";
15
+ /** Copy shown in both locales (vocabulary words, a data request's reason, the public page): both languages. */
16
+ export interface BlueprintBilingual {
17
+ en: string;
18
+ ar: string;
19
+ }
20
+ export type BlueprintLanguage = 'en' | 'ar';
21
+ export interface BlueprintName {
22
+ en?: string;
23
+ ar?: string;
24
+ }
25
+ export type BlueprintFieldType = 'text' | 'long_text' | 'number' | 'date' | 'yes_no' | 'choice';
26
+ export type BlueprintFieldSetTarget = 'client' | 'staff' | 'booking' | 'item';
27
+ export type BlueprintDataPurpose = 'service_delivery' | 'communication' | 'billing' | 'legal_obligation' | 'safety' | 'personalisation' | 'analytics' | 'advertising';
28
+ export type BlueprintRetention = 'legal_obligation' | 'ongoing_service' | 'contract';
29
+ export type BlueprintRecipientMode = 'whole_app' | 'per_business';
30
+ export type BlueprintDemoProfile = 'none' | 'small' | 'realistic';
31
+ export interface BlueprintRole {
32
+ /** A local key: `^[a-z][a-z0-9_]{1,39}$`. A bookable role whose key is a party role (`coach`) becomes a bookable person role. */
33
+ key: string;
34
+ label: BlueprintName;
35
+ /** Dotted capability keys, e.g. `bookings.recurring`. */
36
+ capabilities?: string[];
37
+ bookable?: boolean;
38
+ /** A safety-critical role tracked in the compliance register. */
39
+ compliance?: boolean;
40
+ }
41
+ export interface BlueprintSessionType {
42
+ key: string;
43
+ label: BlueprintName;
44
+ /** 5 to 1440. */
45
+ duration_minutes: number;
46
+ }
47
+ export interface BlueprintField {
48
+ key: string;
49
+ label: BlueprintName;
50
+ type: BlueprintFieldType;
51
+ options?: BlueprintName[];
52
+ required?: boolean;
53
+ }
54
+ export interface BlueprintFieldSet {
55
+ key: string;
56
+ label: BlueprintName;
57
+ applies_to: BlueprintFieldSetTarget;
58
+ fields: BlueprintField[];
59
+ }
60
+ export interface BlueprintDataRequest {
61
+ /** A key of the person-data category registry. */
62
+ category: string;
63
+ purpose: BlueprintDataPurpose;
64
+ retention: BlueprintRetention;
65
+ recipient_mode: BlueprintRecipientMode;
66
+ why: BlueprintBilingual;
67
+ }
68
+ export interface BlueprintDocument {
69
+ schema_version: typeof BLUEPRINT_SCHEMA_VERSION;
70
+ /** The vertical key: `^[a-z][a-z0-9-]{2,39}$`. Immutable after publish. */
71
+ key: string;
72
+ identity: {
73
+ name: BlueprintName;
74
+ tagline?: BlueprintName | null;
75
+ /** The language every name and label must be written in; absent or null: any one is enough. */
76
+ primary_language?: BlueprintLanguage | null;
77
+ };
78
+ branding?: {
79
+ primary_color?: string;
80
+ accent_color?: string | null;
81
+ };
82
+ /** Module catalog keys, at most 40. */
83
+ modules: string[];
84
+ /** Declared vocabulary keys to the vertical's words. */
85
+ vocabulary?: Record<string, BlueprintBilingual>;
86
+ /** Policy key to the option chosen at the vertical level. */
87
+ policies?: Record<string, string>;
88
+ roles?: BlueprintRole[];
89
+ session_types?: BlueprintSessionType[];
90
+ field_sets?: BlueprintFieldSet[];
91
+ data_requests?: BlueprintDataRequest[];
92
+ onboarding_steps?: {
93
+ key: string;
94
+ label: BlueprintName;
95
+ }[];
96
+ site?: {
97
+ headline: BlueprintBilingual;
98
+ about?: BlueprintBilingual;
99
+ } | null;
100
+ /** Screen pack keys in navigation order, at most 20. */
101
+ screens?: string[];
102
+ /** Level 2: screens composed from the closed block catalogue, at most 20. */
103
+ composed_screens?: BlueprintComposedScreen[];
104
+ /** Level 2: the navigation tree, at most 30 entries and three levels, never in a circle. */
105
+ nav?: BlueprintNavigationEntry[];
106
+ demo_profile?: BlueprintDemoProfile;
107
+ }
108
+ export declare const BLUEPRINT_BLOCK_TYPES: readonly ["record_list", "form", "kpi", "schedule", "detail", "site_section", "catalog_grid", "assistant", "empty", "wishlist", "wallet", "cart", "shopping_assistant", "catalog_browse"];
109
+ export type BlueprintBlockType = (typeof BLUEPRINT_BLOCK_TYPES)[number];
110
+ /**
111
+ * Who a composed screen is for: `staff` (the business's team, the default), `public` (signed-out
112
+ * visitors) or `person` (a signed-in customer using the app for themselves: their own records
113
+ * under the person binding, and what the business publishes; never its staff data, no roles).
114
+ */
115
+ export declare const BLUEPRINT_SCREEN_AUDIENCES: readonly ["staff", "public", "person"];
116
+ export type BlueprintScreenAudience = (typeof BLUEPRINT_SCREEN_AUDIENCES)[number];
117
+ /** The yes/no options each person block takes (core's `BlockType::options()`); any left out take their default. */
118
+ export declare const BLUEPRINT_BLOCK_OPTIONS: Partial<Record<BlueprintBlockType, readonly string[]>>;
119
+ /**
120
+ * What a block reads or writes: one operation of the pinned OpenAPI snapshot marked
121
+ * `x-nuwah-compose`. Sort and filters use only the operation's declared list keys; fields never
122
+ * name a person's raw details (person data goes through the `person_data/read` gate).
123
+ */
124
+ export interface BlueprintBlockBinding {
125
+ operation: string;
126
+ /** A declared sort, `-key` for descending. */
127
+ sort?: string;
128
+ filters?: Record<string, string | number | boolean>;
129
+ /** 1 to 50. */
130
+ limit?: number;
131
+ fields?: string[];
132
+ /** A key figure's measure: `count`, or a numeric field summed. */
133
+ measure?: string;
134
+ /** Person-data categories read through the gate, each declared in `data_requests`. */
135
+ categories?: string[];
136
+ }
137
+ export interface BlueprintBlockAction {
138
+ key: string;
139
+ /** A writing operation, guarded by its permission. */
140
+ operation: string;
141
+ label: BlueprintName;
142
+ }
143
+ export interface BlueprintBlock {
144
+ key: string;
145
+ type: BlueprintBlockType;
146
+ title?: BlueprintName;
147
+ text?: BlueprintBilingual;
148
+ binding?: BlueprintBlockBinding;
149
+ /** At most 4, on row blocks only. */
150
+ actions?: BlueprintBlockAction[];
151
+ /** A composed screen a row opens. */
152
+ open_screen?: string;
153
+ /** Person blocks only: their declared yes/no choices ({@link BLUEPRINT_BLOCK_OPTIONS}). */
154
+ options?: Record<string, boolean>;
155
+ }
156
+ export interface BlueprintComposedScreen {
157
+ key: string;
158
+ title: BlueprintName;
159
+ /** `public` screens bind only public operations; `person` screens only person-plane and public ones. Default `staff`. */
160
+ audience?: BlueprintScreenAudience;
161
+ /** Role keys that see it (staff screens only); empty: every role. */
162
+ roles?: string[];
163
+ /** At most 30. */
164
+ blocks: BlueprintBlock[];
165
+ }
166
+ export interface BlueprintNavigationEntry {
167
+ key: string;
168
+ label: BlueprintName;
169
+ /** Exactly one of `screen` (a composed screen) and `pack` (a ready-made screen). */
170
+ screen?: string;
171
+ pack?: string;
172
+ parent?: string;
173
+ }
174
+ /** One thing wrong with a document: a path into it (`roles.2.label`) and a bilingual reason. Same shape as core's. */
175
+ export interface BlueprintIssue {
176
+ path: string;
177
+ message: BlueprintBilingual;
178
+ }
@@ -0,0 +1,17 @@
1
+
2
+
3
+ export const BLUEPRINT_SCHEMA_VERSION = '1';
4
+ export const BLUEPRINT_BLOCK_TYPES = [
5
+ 'record_list', 'form', 'kpi', 'schedule', 'detail', 'site_section', 'catalog_grid', 'assistant', 'empty',
6
+
7
+ 'wishlist', 'wallet', 'cart', 'shopping_assistant', 'catalog_browse',
8
+ ];
9
+
10
+ export const BLUEPRINT_SCREEN_AUDIENCES = ['staff', 'public', 'person'];
11
+
12
+ export const BLUEPRINT_BLOCK_OPTIONS = {
13
+ catalog_browse: ['save_to_wishlist', 'add_to_cart', 'send_to_someone'],
14
+ wishlist: ['claim_items'],
15
+ wallet: ['show_history'],
16
+ cart: ['checkout'],
17
+ };
@@ -0,0 +1,3 @@
1
+ export * from './document.js';
2
+ export * from './manifest.js';
3
+ export { validateBlueprint } from './validate.js';
@@ -0,0 +1,5 @@
1
+
2
+
3
+ export * from './document.js';
4
+ export * from './manifest.js';
5
+ export { validateBlueprint } from './validate.js';
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The RUNTIME MANIFEST: what an app shell renders for a blueprint. Core derives it from the
3
+ * document (`VerticalRuntime/Manifest/RuntimeManifestBuilder`), so a developer's preview and the
4
+ * live app render from the same answer.
5
+ *
6
+ * Every key in it is one the platform declares: undeclared modules and words are left out, and
7
+ * a screen pack whose module the app does not include stays in `navigation` with
8
+ * `available: false` and a reason, so a shell shows "not available" instead of a broken screen.
9
+ */
10
+ import type { BlueprintBilingual, BlueprintDataPurpose, BlueprintDemoProfile, BlueprintFieldSetTarget, BlueprintFieldType, BlueprintIssue, BlueprintRecipientMode, BlueprintRetention } from './document.js';
11
+ import type { BuilderComposition } from '../builder.js';
12
+ export type RuntimeMode = 'published' | 'preview';
13
+ export interface RuntimeNavigationEntry {
14
+ /** The screen pack key (`today`, `calendar`, `clients`, `catalog`, `customers`, `invoices`, `site`, `staff_assistant`, `settings`, or a later one). */
15
+ key: string;
16
+ label: BlueprintBilingual;
17
+ description: BlueprintBilingual;
18
+ needs_module: string | null;
19
+ available: boolean;
20
+ unavailable_reason: BlueprintBilingual | null;
21
+ }
22
+ export interface RuntimeManifest {
23
+ schema_version: string;
24
+ key: string;
25
+ mode: RuntimeMode;
26
+ identity: {
27
+ name: BlueprintBilingual;
28
+ tagline: BlueprintBilingual | null;
29
+ };
30
+ branding: {
31
+ primary_color: string | null;
32
+ accent_color: string | null;
33
+ };
34
+ vocabulary: Record<string, BlueprintBilingual>;
35
+ modules: {
36
+ key: string;
37
+ label: BlueprintBilingual;
38
+ }[];
39
+ navigation: RuntimeNavigationEntry[];
40
+ site: {
41
+ headline: BlueprintBilingual;
42
+ about: BlueprintBilingual | null;
43
+ } | null;
44
+ roles: {
45
+ key: string;
46
+ label: BlueprintBilingual;
47
+ capabilities: string[];
48
+ bookable: boolean;
49
+ compliance: boolean;
50
+ }[];
51
+ session_types: {
52
+ key: string;
53
+ label: BlueprintBilingual;
54
+ duration_minutes: number;
55
+ }[];
56
+ field_sets: {
57
+ key: string;
58
+ label: BlueprintBilingual;
59
+ applies_to: BlueprintFieldSetTarget;
60
+ fields: {
61
+ key: string;
62
+ label: BlueprintBilingual;
63
+ type: BlueprintFieldType;
64
+ options: BlueprintBilingual[];
65
+ required: boolean;
66
+ }[];
67
+ }[];
68
+ data_requests: {
69
+ category: string;
70
+ category_label: BlueprintBilingual;
71
+ sensitive: boolean;
72
+ purpose: BlueprintDataPurpose | null;
73
+ retention: BlueprintRetention | null;
74
+ recipient_mode: BlueprintRecipientMode | null;
75
+ why: BlueprintBilingual | null;
76
+ }[];
77
+ onboarding_steps: {
78
+ key: string;
79
+ label: BlueprintBilingual;
80
+ }[];
81
+ demo_profile: BlueprintDemoProfile;
82
+ /**
83
+ * Level 2: the blueprint's composed screens resolved for the developer's view (no role), or
84
+ * null when it composes none. Optional so a locally interpreted manifest may leave it out.
85
+ */
86
+ composition?: Omit<BuilderComposition, 'issues'> | null;
87
+ }
88
+ /** What core answers for a preview: the manifest plus what is wrong and what is still missing. */
89
+ export interface RuntimeInterpretation {
90
+ manifest: RuntimeManifest;
91
+ /** Shape and declared-key problems. Empty means valid. */
92
+ issues: BlueprintIssue[];
93
+ /** What a valid document still lacks before review (a module, a screen, a role). Empty while `issues` is not. */
94
+ readiness: BlueprintIssue[];
95
+ valid: boolean;
96
+ ready: boolean;
97
+ schema_version: string;
98
+ }
99
+ /** The vertical's word for a vocabulary key, else `fallback`. */
100
+ export declare function runtimeWord(manifest: Pick<RuntimeManifest, 'vocabulary'>, key: string, fallback: BlueprintBilingual): BlueprintBilingual;
101
+ /** The navigation a shell shows: available packs first in the developer's order, unavailable ones after. */
102
+ export declare function runtimeNavigation(manifest: Pick<RuntimeManifest, 'navigation'>): {
103
+ available: RuntimeNavigationEntry[];
104
+ unavailable: RuntimeNavigationEntry[];
105
+ };
@@ -0,0 +1,11 @@
1
+
2
+ export function runtimeWord(manifest, key, fallback) {
3
+ return manifest.vocabulary[key] ?? fallback;
4
+ }
5
+
6
+ export function runtimeNavigation(manifest) {
7
+ return {
8
+ available: manifest.navigation.filter((entry) => entry.available),
9
+ unavailable: manifest.navigation.filter((entry) => !entry.available),
10
+ };
11
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `validateBlueprint`: the SHAPE half of blueprint validation, offline.
3
+ *
4
+ * It mirrors `blueprint.v1.json` rule for rule (required fields, patterns, lengths, enums, list
5
+ * limits, unknown properties, duplicate keys) so an editor, a repository's CI or a form can answer
6
+ * at once, without a network call. It cannot know which modules, words, policies, data categories
7
+ * or screen packs the platform declares; that is core's half (`client.verticalRuntime.interpret`).
8
+ * A document that passes here can still be refused there, never the other way round.
9
+ *
10
+ * Issues use core's shape: a dotted path into the document and a bilingual reason.
11
+ */
12
+ import { type BlueprintIssue } from './document.js';
13
+ /** Every shape problem in `document`, in document order. Empty means the shape is valid. */
14
+ export declare function validateBlueprint(document: unknown): BlueprintIssue[];