@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,93 @@
1
+ /**
2
+ * How a composed screen reads and writes: each block is bound to a PUBLISHED operation (its method
3
+ * and path are in the screen's constant, `src/screens/*Screen.tsx`), and this file calls that
4
+ * operation through `@nuwah/vertical-sdk` with the signed-in person's own token. It is the same
5
+ * wire the builder's live preview uses, without the builder in between:
6
+ *
7
+ * - a list sends the declared ListQuery wire: `sort`, `filter[key]`, `limit`, `search`, `cursor`
8
+ * (and `page` for the few page-numbered lists);
9
+ * - a row write fills the path's `{parameters}` from the row (`{id}` from `row.id`);
10
+ * - a write the operation marks `idempotent` carries an `Idempotency-Key` header, the same on a
11
+ * retry of the same submission.
12
+ *
13
+ * Staff screens act inside one organisation: set VITE_ORGANISATION_ID (see `src/lib/sdk.ts`).
14
+ */
15
+ import { blockDataFromAnswer, type ComposedBlockLoader, type ComposedBlockSender, type ComposedOperationView, type ComposedScreenView } from '@nuwah/ui/solid/composer';
16
+ import { NuwahApiError } from '@nuwah/vertical-sdk';
17
+ import { navigate } from './router';
18
+ import { sdk } from './sdk';
19
+
20
+ type Query = Record<string, string | number | boolean>;
21
+
22
+ /** The operation's path with `{name}` filled from the row; null when the row lacks one. */
23
+ export function pathFor(operation: ComposedOperationView, row: Record<string, unknown> = {}): string | null {
24
+ let missing = false;
25
+ const path = (operation.path ?? '').replace(/\{([A-Za-z0-9_]+)\??\}/g, (_match, name: string) => {
26
+ const value = row[name] ?? row.id;
27
+ if (value === undefined || value === null || String(value) === '') {
28
+ missing = true;
29
+ return '';
30
+ }
31
+ return encodeURIComponent(String(value));
32
+ });
33
+ return missing || path === '' ? null : path;
34
+ }
35
+
36
+ /** A refusal as the block shows it: the server's readable reason, and its per-field messages. */
37
+ function refusal(error: unknown): Error {
38
+ if (error instanceof NuwahApiError) {
39
+ const body = (error.body ?? {}) as { message?: unknown; errors?: Record<string, unknown> };
40
+ const failure = new Error(typeof body.message === 'string' && body.message !== '' ? body.message : error.message) as Error & { fieldErrors?: Record<string, string[]> };
41
+ if (body.errors && typeof body.errors === 'object') {
42
+ failure.fieldErrors = Object.fromEntries(Object.entries(body.errors).map(([field, messages]) => [field, Array.isArray(messages) ? messages.map(String) : [String(messages)]]));
43
+ }
44
+ return failure;
45
+ }
46
+ return error instanceof Error ? error : new Error(String(error));
47
+ }
48
+
49
+ export interface ScreenRuntime {
50
+ load: ComposedBlockLoader;
51
+ send: ComposedBlockSender;
52
+ openScreen: (screenKey: string, row: Record<string, unknown>) => void;
53
+ }
54
+
55
+ export function screenRuntime(_screen: ComposedScreenView): ScreenRuntime {
56
+ const load: ComposedBlockLoader = async (block, request) => {
57
+ const operation = block.operation;
58
+ if (!operation?.path) return { rows: [] };
59
+ const binding = block.binding;
60
+ const query: Query = {};
61
+ const sort = request?.sort ?? binding?.sort ?? null;
62
+ if (sort) query.sort = sort;
63
+ for (const [key, value] of Object.entries({ ...(request?.filters ?? {}), ...(binding?.filters ?? {}) })) {
64
+ query[`filter[${key}]`] = value;
65
+ }
66
+ if (binding?.limit) query.limit = binding.limit;
67
+ if (request?.search) query.search = request.search;
68
+ if (request?.cursor) query.cursor = request.cursor;
69
+ if (request?.page) query.page = request.page;
70
+ try {
71
+ return blockDataFromAnswer(await sdk.http.get<unknown>(operation.path, { params: query }));
72
+ } catch (error) {
73
+ throw refusal(error);
74
+ }
75
+ };
76
+
77
+ const send: ComposedBlockSender = async (_block, operation, values, context) => {
78
+ const path = context?.row ? pathFor(operation, context.row) : pathFor(operation);
79
+ if (path === null) throw new Error('This row is missing what the action needs.');
80
+ const headers: Record<string, string> = operation.idempotent && context?.idempotencyKey ? { 'Idempotency-Key': context.idempotencyKey } : {};
81
+ const method = (operation.method ?? 'POST').toUpperCase();
82
+ try {
83
+ if (method === 'DELETE') await sdk.http.delete(path, { headers });
84
+ else if (method === 'PUT') await sdk.http.put(path, values, { headers });
85
+ else if (method === 'PATCH') await sdk.http.patch(path, values, { headers });
86
+ else await sdk.http.post(path, values, { headers });
87
+ } catch (error) {
88
+ throw refusal(error);
89
+ }
90
+ };
91
+
92
+ return { load, send, openScreen: (screenKey) => navigate(`/${encodeURIComponent(screenKey)}`) };
93
+ }
@@ -0,0 +1,24 @@
1
+ import { createSignal } from 'solid-js';
2
+
3
+ /**
4
+ * The smallest router that does the job: the path is a signal, `navigate` pushes a history entry,
5
+ * Back and Forward work. Each composed screen lives at `/<screen key>`. Swap in `@solidjs/router`
6
+ * when the app needs nested routes or parameters; nothing else depends on this file's shape.
7
+ */
8
+ const [path, setPath] = createSignal(window.location.pathname);
9
+
10
+ window.addEventListener('popstate', () => setPath(window.location.pathname));
11
+
12
+ export const currentPath = path;
13
+
14
+ export function navigate(to: string): void {
15
+ if (to === window.location.pathname) return;
16
+ window.history.pushState(null, '', to);
17
+ setPath(to);
18
+ }
19
+
20
+ /** The screen key in the address (`/orders` → `orders`), or null on `/`. */
21
+ export function currentScreenKey(): string | null {
22
+ const key = path().replace(/^\/+|\/+$/g, '').split('/')[0] ?? '';
23
+ return key === '' ? null : decodeURIComponent(key);
24
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The typed Nuwah Core client. The token is the signed-in person's IAM access token; core scopes
3
+ * every answer to what that token may see. Same origin in development (the dev server proxies
4
+ * `/api`), VITE_CORE_API_URL in production.
5
+ *
6
+ * Staff screens act inside one organisation: VITE_ORGANISATION_ID, when set, goes as
7
+ * `X-Active-Org` on every call (a person who belongs to several organisations picks one). Person
8
+ * and public screens need none.
9
+ */
10
+ import { createNuwahClient } from '@nuwah/vertical-sdk';
11
+ import { accessToken } from './iam';
12
+ import { locale } from './i18n';
13
+
14
+ const organisationId = (import.meta.env.VITE_ORGANISATION_ID ?? '').trim();
15
+
16
+ export const sdk = createNuwahClient({
17
+ baseUrl: import.meta.env.VITE_CORE_API_URL ?? '',
18
+ getToken: () => accessToken() ?? '',
19
+ // Server-written text (notifications, exports) comes back in the reader's language.
20
+ defaultHeaders: () => ({ 'Accept-Language': locale(), ...(organisationId !== '' ? { 'X-Active-Org': organisationId } : {}) }),
21
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Light and dark from the platform's theme store (it writes `data-theme` on `<html>` and follows
3
+ * the system until the person chooses). The blueprint's brand colours are laid over the tokens.
4
+ */
5
+ import { createThemeStore } from '@nuwah/ui/theme/solid';
6
+ import { blueprintApp } from '@/blueprint/blueprint';
7
+
8
+ export const theme = createThemeStore({ defaultTheme: 'system' });
9
+
10
+ export function toggleTheme(): void {
11
+ theme.setTheme(theme.resolvedTheme() === 'dark' ? 'light' : 'dark');
12
+ }
13
+
14
+ export function applyBrandColours(root: HTMLElement = document.documentElement): void {
15
+ const { primaryColor, accentColor } = blueprintApp.branding;
16
+ if (primaryColor) root.style.setProperty('--color-primary', primaryColor);
17
+ if (accentColor) root.style.setProperty('--color-accent', accentColor);
18
+ }
@@ -0,0 +1,39 @@
1
+ import { locale, type Bilingual } from './i18n';
2
+ import { blueprintApp, words } from '@/blueprint/blueprint';
3
+
4
+ /**
5
+ * A word in the reader's language. Blueprint words first (`app.name`, `nav.*`, `role.*`,
6
+ * `vocabulary.*`), then the template's few interface words. A name written in one language only
7
+ * falls back to the other side, the platform's rule for names.
8
+ */
9
+ export function word(key: string, fallback = ''): string {
10
+ const entry: Bilingual | undefined = words[key] ?? INTERFACE_WORDS[key];
11
+ if (!entry) return fallback || key;
12
+ const preferred = locale() === 'ar' ? entry.ar : entry.en;
13
+ return preferred || entry.en || entry.ar || fallback || key;
14
+ }
15
+
16
+ /** The blueprint's language when it declares one, else English. */
17
+ export const startingLanguage = (): 'en' | 'ar' => blueprintApp.primaryLanguage ?? 'en';
18
+
19
+ /** The template's interface words: sign-in, language and theme controls. */
20
+ const INTERFACE_WORDS: Record<string, Bilingual> = {
21
+ 'interface.sign_in': { en: 'Sign in', ar: 'تسجيل الدخول' },
22
+ 'interface.sign_out': { en: 'Sign out', ar: 'تسجيل الخروج' },
23
+ 'interface.signing_in': { en: 'Signing you in…', ar: 'جارٍ تسجيل دخولك…' },
24
+ 'interface.sign_in_failed': { en: 'Sign-in did not complete.', ar: 'لم يكتمل تسجيل الدخول.' },
25
+ 'interface.try_again': { en: 'Try again', ar: 'حاول مجددًا' },
26
+ 'interface.other_language': { en: 'العربية', ar: 'English' },
27
+ 'interface.dark_theme': { en: 'Dark', ar: 'داكن' },
28
+ 'interface.light_theme': { en: 'Light', ar: 'فاتح' },
29
+ 'interface.welcome': { en: 'Welcome', ar: 'أهلًا بك' },
30
+ 'interface.signed_in_as': { en: 'Signed in as', ar: 'مسجّل الدخول باسم' },
31
+ 'interface.modules': { en: 'Built on', ar: 'مبني على' },
32
+ 'interface.navigation': { en: 'App navigation', ar: 'تنقّل التطبيق' },
33
+ 'interface.screen_missing': { en: 'This screen is not part of the app.', ar: 'هذه الشاشة ليست جزءًا من التطبيق.' },
34
+ 'interface.unavailable': { en: 'Sign-in is not reachable right now.', ar: 'تسجيل الدخول غير متاح الآن.' },
35
+ 'interface.client_missing': {
36
+ en: 'Set VITE_IAM_CLIENT_ID in .env to your OAuth client id, then restart the dev server.',
37
+ ar: 'اضبط VITE_IAM_CLIENT_ID في ملف .env على معرّف عميل OAuth الخاص بك، ثم أعد تشغيل خادم التطوير.',
38
+ },
39
+ };
@@ -0,0 +1,25 @@
1
+ /* @refresh reload */
2
+ import { render } from 'solid-js/web';
3
+ import './index.css';
4
+ import App from './App';
5
+ import AuthCallback from './pages/AuthCallback';
6
+ import { setLocale } from './lib/i18n';
7
+ import { startingLanguage } from './lib/words';
8
+ import { applyBrandColours } from './lib/theme';
9
+
10
+ /*
11
+ * Two entry paths: the OAuth callback, and everything else. Inside the app, `src/lib/router.ts`
12
+ * opens each composed screen at /<screen key>; the sign-in wiring does not change.
13
+ */
14
+ const root = document.getElementById('root')!;
15
+ const isCallback = window.location.pathname === '/auth/callback';
16
+
17
+ // A first visit opens in the blueprint's language; the person's own choice wins afterwards.
18
+ try {
19
+ if (!localStorage.getItem('locale')) setLocale(startingLanguage());
20
+ } catch {
21
+ setLocale(startingLanguage());
22
+ }
23
+ applyBrandColours();
24
+
25
+ render(() => (isCallback ? <AuthCallback /> : <App />), root);
@@ -0,0 +1,71 @@
1
+ import { createMemo, For, Show } from 'solid-js';
2
+ import { Dynamic } from 'solid-js/web';
3
+ import { blueprintApp } from '@/blueprint/blueprint';
4
+ import { screens } from '@/blueprint/screens';
5
+ import { currentScreenKey, navigate } from '@/lib/router';
6
+ import { locale } from '@/lib/i18n';
7
+ import { word } from '@/lib/words';
8
+ import Home from './Home';
9
+
10
+ /**
11
+ * The signed-in app: the blueprint's navigation as a bar of links, and the screen the address
12
+ * names (`/<screen key>`). Entries whose screen is not a composed screen (a module's own pages,
13
+ * such as the catalogue pack) are left out: build those pages yourself. With no composed screens
14
+ * at all (a level-1 blueprint) the app shows Home.
15
+ */
16
+ export default function AppScreens() {
17
+ const entries = createMemo(() =>
18
+ blueprintApp.navigation
19
+ .filter((entry) => entry.screen !== null && screens.some((screen) => screen.key === entry.screen))
20
+ .map((entry) => ({ ...entry, screen: entry.screen as string })),
21
+ );
22
+ // A screen nobody linked in the navigation is still reachable by its address, and listed last.
23
+ const unlinked = createMemo(() => screens.filter((screen) => !entries().some((entry) => entry.screen === screen.key)));
24
+ const active = createMemo(() => {
25
+ const key = currentScreenKey() ?? entries()[0]?.screen ?? screens[0]?.key ?? null;
26
+ return screens.find((screen) => screen.key === key) ?? null;
27
+ });
28
+
29
+ return (
30
+ <Show when={screens.length > 0} fallback={<Home />}>
31
+ <div class="app-screens">
32
+ <nav class="app-screens__nav" aria-label={word('interface.navigation')}>
33
+ <For each={entries()}>
34
+ {(entry) => (
35
+ <a
36
+ class="app-screens__link"
37
+ href={`/${entry.screen}`}
38
+ aria-current={active()?.key === entry.screen ? 'page' : undefined}
39
+ onClick={(event) => {
40
+ event.preventDefault();
41
+ navigate(`/${entry.screen}`);
42
+ }}
43
+ >
44
+ <bdi>{word(entry.word, entry.key)}</bdi>
45
+ </a>
46
+ )}
47
+ </For>
48
+ <For each={unlinked()}>
49
+ {(screen) => (
50
+ <a
51
+ class="app-screens__link"
52
+ href={`/${screen.key}`}
53
+ aria-current={active()?.key === screen.key ? 'page' : undefined}
54
+ onClick={(event) => {
55
+ event.preventDefault();
56
+ navigate(`/${screen.key}`);
57
+ }}
58
+ >
59
+ <bdi>{(locale() === 'ar' ? screen.title.ar || screen.title.en : screen.title.en || screen.title.ar) || screen.key}</bdi>
60
+ </a>
61
+ )}
62
+ </For>
63
+ </nav>
64
+
65
+ <Show when={active()} fallback={<p class="app-home__muted">{word('interface.screen_missing')}</p>}>
66
+ {(screen) => <Dynamic component={screen().component} />}
67
+ </Show>
68
+ </div>
69
+ </Show>
70
+ );
71
+ }
@@ -0,0 +1,44 @@
1
+ import { createSignal, onMount, Show } from 'solid-js';
2
+ import { Button } from '@nuwah/ui/solid/Button';
3
+ import { completeSignIn, initiateLogin } from '@/lib/iam';
4
+ import { word } from '@/lib/words';
5
+
6
+ const RETRY_FLAG = 'app_sign_in_retry';
7
+
8
+ /**
9
+ * `/auth/callback`: exchanges the PKCE code for tokens, then returns to where sign-in started.
10
+ * A stale sign-in state restarts sign-in ONCE, so a broken setup cannot loop.
11
+ */
12
+ export default function AuthCallback() {
13
+ const [failed, setFailed] = createSignal<string | null>(null);
14
+
15
+ onMount(async () => {
16
+ try {
17
+ const { returnTo } = await completeSignIn();
18
+ sessionStorage.removeItem(RETRY_FLAG);
19
+ window.location.replace(returnTo || '/');
20
+ } catch (error) {
21
+ const code = (error as { code?: string } | null)?.code;
22
+ const recoverable = code === 'state_mismatch' || code === 'missing_verifier' || code === 'missing_params';
23
+
24
+ if (recoverable && !sessionStorage.getItem(RETRY_FLAG)) {
25
+ sessionStorage.setItem(RETRY_FLAG, '1');
26
+ void initiateLogin({ returnTo: '/' });
27
+ return;
28
+ }
29
+
30
+ sessionStorage.removeItem(RETRY_FLAG);
31
+ setFailed(error instanceof Error ? error.message : '');
32
+ }
33
+ });
34
+
35
+ return (
36
+ <main class="app-callback" role="status" aria-live="polite">
37
+ <Show when={failed() !== null} fallback={<p>{word('interface.signing_in')}</p>}>
38
+ <p>{word('interface.sign_in_failed')}</p>
39
+ <p class="app-home__muted" dir="auto">{failed()}</p>
40
+ <Button onClick={() => window.location.replace('/')}>{word('interface.try_again')}</Button>
41
+ </Show>
42
+ </main>
43
+ );
44
+ }
@@ -0,0 +1,36 @@
1
+ import { For, Show } from 'solid-js';
2
+ import { Card } from '@nuwah/ui/solid/Card';
3
+ import { blueprintApp } from '@/blueprint/blueprint';
4
+ import { user } from '@/lib/iam';
5
+ import { word } from '@/lib/words';
6
+
7
+ /**
8
+ * The first screen after sign-in: who is signed in, and the app's navigation as the blueprint
9
+ * declares it. Replace the cards with your screens; keep reading labels through `word()`.
10
+ */
11
+ export default function Home() {
12
+ return (
13
+ <section class="app-home">
14
+ <h1 class="app-home__title">{word('interface.welcome')}</h1>
15
+ <p class="app-home__muted">
16
+ {word('interface.signed_in_as')} <bdi>{user()?.name ?? user()?.email ?? ''}</bdi>
17
+ </p>
18
+
19
+ <div class="app-home__grid">
20
+ <For each={blueprintApp.navigation}>
21
+ {(entry) => (
22
+ <Card title={word(entry.word, entry.key)}>
23
+ <p class="app-home__muted" dir="ltr"><bdi>{entry.key}</bdi></p>
24
+ </Card>
25
+ )}
26
+ </For>
27
+ </div>
28
+
29
+ <Show when={blueprintApp.modules.length > 0}>
30
+ <p class="app-home__muted">
31
+ {word('interface.modules')}: <bdi dir="ltr">{blueprintApp.modules.join(', ')}</bdi>
32
+ </p>
33
+ </Show>
34
+ </section>
35
+ );
36
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
+ "moduleResolution": "bundler",
8
+ "allowImportingTsExtensions": true,
9
+ "resolveJsonModule": true,
10
+ "isolatedModules": true,
11
+ "noEmit": true,
12
+ "strict": true,
13
+ "skipLibCheck": true,
14
+ "noUnusedLocals": true,
15
+ "noUnusedParameters": true,
16
+ "jsx": "preserve",
17
+ "jsxImportSource": "solid-js",
18
+ "types": ["vite/client"],
19
+ "paths": {
20
+ "@/*": ["./src/*"]
21
+ }
22
+ },
23
+ "include": ["src"]
24
+ }
@@ -0,0 +1,23 @@
1
+ import { fileURLToPath, URL } from 'node:url';
2
+ import { defineConfig } from 'vite';
3
+ import solidPlugin from 'vite-plugin-solid';
4
+
5
+ export default defineConfig({
6
+ plugins: [solidPlugin()],
7
+ resolve: {
8
+ alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
9
+ // ONE copy of solid-js, which Solid needs.
10
+ dedupe: ['solid-js'],
11
+ },
12
+ // @nuwah/ui components import their own stylesheets; the dev server serves them as they are.
13
+ optimizeDeps: { exclude: ['@nuwah/ui', '@nuwah/iam-client'] },
14
+ server: {
15
+ // Must match the redirect URI of your OAuth client (see .env.example).
16
+ port: Number(process.env.VITE_PORT ?? '5600'),
17
+ // Same-origin `/api` in development: the dev server forwards it to Nuwah Core.
18
+ proxy: {
19
+ '/api': { target: process.env.VITE_CORE_PROXY_TARGET ?? 'http://localhost:8090', changeOrigin: true },
20
+ },
21
+ },
22
+ build: { outDir: 'dist' },
23
+ });
@@ -0,0 +1,192 @@
1
+ # Nuwah vertical CI. Seeded into
2
+ # every level-3 builder repository as .github/workflows/vertical-ci.yml. Runs on every push and
3
+ # pull request, from the builder or from anywhere else; production releases need this workflow
4
+ # green AND a recorded code review by someone other than the developer.
5
+ #
6
+ # Steps: install (locked) → count tests (warn on a drop) → tests → npm audit → semgrep
7
+ # (nuwah-vertical rules) → gitleaks → nuwah-contract-check → build. Each is its own step so a red
8
+ # check names itself. A secret found by gitleaks fails the run, and core treats any failed check as
9
+ # a red run whatever else passed.
10
+ #
11
+ # Reporting: when the variables NUWAH_CI_REPORT_URL, NUWAH_IAM_TOKEN_URL, NUWAH_BLUEPRINT_ID and the
12
+ # secrets NUWAH_CI_CLIENT_ID, NUWAH_CI_CLIENT_SECRET are set (an owner step), a push reports every
13
+ # check's outcome to core (`POST api/builder/code/ci-results`). Without them nothing is reported and
14
+ # an operator records the result by hand (`php artisan builder:record-ci-result`).
15
+ #
16
+ # Extension image: after a green push to the default branch, `extension-image` builds the
17
+ # vertical's extension image from deploy/extension-image.Dockerfile; it is pushed only when the
18
+ # variable NUWAH_EXTENSION_REGISTRY is set.
19
+ #
20
+ # Source of truth: @nuwah/vertical-sdk/templates/vertical-ci.yml. Edit it there, not in a repo.
21
+ name: vertical-ci
22
+
23
+ on:
24
+ push:
25
+ pull_request:
26
+
27
+ permissions:
28
+ contents: read
29
+
30
+ concurrency:
31
+ group: vertical-ci-${{ github.ref }}
32
+ cancel-in-progress: true
33
+
34
+ jobs:
35
+ checks:
36
+ runs-on: ubuntu-latest
37
+ timeout-minutes: 20
38
+ steps:
39
+ - name: Check out (full history, for secret scanning)
40
+ uses: actions/checkout@v4
41
+ with:
42
+ fetch-depth: 0
43
+
44
+ - name: Set up Node
45
+ uses: actions/setup-node@v4
46
+ with:
47
+ node-version: 22
48
+ registry-url: https://registry.npmjs.org
49
+ scope: '@nuwah'
50
+
51
+ - name: Install (locked)
52
+ id: install
53
+ env:
54
+ NODE_AUTH_TOKEN: ${{ secrets.NUWAH_PACKAGES_TOKEN }}
55
+ run: |
56
+ if [ -f package-lock.json ]; then
57
+ npm ci --ignore-scripts
58
+ else
59
+ echo "::warning::No package-lock.json: installing unlocked. Commit the lockfile."
60
+ npm install --ignore-scripts --no-audit
61
+ fi
62
+
63
+ - name: Count tests (and warn when the count dropped)
64
+ id: tests_count
65
+ run: |
66
+ count_cases() {
67
+ # Test cases, not files: every it( / test( call in a test file at the given commit.
68
+ git ls-tree -r --name-only "$1" -- tests app/src server/src 2>/dev/null \
69
+ | grep -E '\.(test|spec)\.tsx?$' \
70
+ | while read -r file; do git show "$1:$file"; done \
71
+ | grep -cE '(^|[^A-Za-z0-9_.])(it|test)(\.each\([^)]*\))?\(' || true
72
+ }
73
+ count=$(count_cases HEAD)
74
+ echo "count=$count" >> "$GITHUB_OUTPUT"
75
+ echo "test cases: $count"
76
+ if git rev-parse --verify --quiet HEAD~1 >/dev/null; then
77
+ previous=$(count_cases HEAD~1)
78
+ if [ "$count" -lt "$previous" ]; then
79
+ echo "::warning::The number of test cases dropped from $previous to $count. The reviewer must acknowledge it before release."
80
+ echo "warning=Test cases dropped from $previous to $count in this commit." >> "$GITHUB_OUTPUT"
81
+ fi
82
+ fi
83
+
84
+ - name: Tests
85
+ id: tests
86
+ run: npm test
87
+
88
+ - name: Dependency audit
89
+ id: npm_audit
90
+ run: npm audit --audit-level=high --omit=dev
91
+
92
+ - name: Semgrep (nuwah-vertical rules)
93
+ id: semgrep
94
+ run: |
95
+ python3 -m pip install --quiet --user semgrep==1.95.0
96
+ ~/.local/bin/semgrep scan --config .semgrep/nuwah-vertical.yml --error --metrics=off --exclude node_modules --exclude dist
97
+
98
+ - name: Secret scanning (gitleaks)
99
+ id: gitleaks
100
+ run: |
101
+ docker run --rm -v "$PWD:/repository" ghcr.io/gitleaks/gitleaks:v8.21.2 \
102
+ detect --source /repository --redact --no-banner --exit-code 1
103
+
104
+ - name: Nuwah contract check
105
+ id: contract_check
106
+ run: npx --no-install nuwah-contract-check --root . --operations contract/operations.json
107
+
108
+ - name: Build
109
+ id: build
110
+ run: npm run build
111
+
112
+ - name: Report to Nuwah
113
+ if: always() && github.event_name == 'push'
114
+ env:
115
+ REPORT_URL: ${{ vars.NUWAH_CI_REPORT_URL }}
116
+ TOKEN_URL: ${{ vars.NUWAH_IAM_TOKEN_URL }}
117
+ BLUEPRINT_ID: ${{ vars.NUWAH_BLUEPRINT_ID }}
118
+ CLIENT_ID: ${{ secrets.NUWAH_CI_CLIENT_ID }}
119
+ CLIENT_SECRET: ${{ secrets.NUWAH_CI_CLIENT_SECRET }}
120
+ JOB_STATUS: ${{ job.status }}
121
+ TEST_COUNT: ${{ steps.tests_count.outputs.count }}
122
+ TEST_WARNING: ${{ steps.tests_count.outputs.warning }}
123
+ OUTCOMES: >-
124
+ install=${{ steps.install.outcome }}
125
+ tests=${{ steps.tests.outcome }}
126
+ npm_audit=${{ steps.npm_audit.outcome }}
127
+ semgrep=${{ steps.semgrep.outcome }}
128
+ gitleaks=${{ steps.gitleaks.outcome }}
129
+ contract_check=${{ steps.contract_check.outcome }}
130
+ build=${{ steps.build.outcome }}
131
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
132
+ run: |
133
+ if [ -z "$REPORT_URL" ] || [ -z "$CLIENT_ID" ] || [ -z "$CLIENT_SECRET" ] || [ -z "$TOKEN_URL" ] || [ -z "$BLUEPRINT_ID" ]; then
134
+ echo "Reporting to Nuwah is not set up for this repository; an operator records the result."
135
+ exit 0
136
+ fi
137
+ checks="[]"
138
+ for pair in $OUTCOMES; do
139
+ key=${pair%%=*}; outcome=${pair#*=}
140
+ case "$outcome" in success) status=passed ;; failure) status=failed ;; *) status=pending ;; esac
141
+ checks=$(jq -c --arg key "$key" --arg status "$status" '. + [{key: $key, status: $status}]' <<<"$checks")
142
+ done
143
+ # A step that failed makes the run red; one that never ran (after a failure) stays pending.
144
+ case "$JOB_STATUS" in success) status=passed ;; failure) status=failed ;; *) status=pending ;; esac
145
+ diff=$(git diff --numstat HEAD~1 HEAD 2>/dev/null | head -500 | jq -R -s -c '
146
+ split("\n") | map(select(length > 0) | split("\t") | {path: .[2], change: "modified",
147
+ additions: ((.[0] | tonumber?) // 0), deletions: ((.[1] | tonumber?) // 0)})
148
+ | {files: ., totals: {files: length, additions: (map(.additions) | add // 0), deletions: (map(.deletions) | add // 0)}}' || echo null)
149
+ warnings=$(jq -c -n --arg warning "$TEST_WARNING" 'if $warning == "" then [] else [$warning] end')
150
+ token=$(curl -fsS -X POST "$TOKEN_URL" -d grant_type=client_credentials -d scope=builder.code.ci_report \
151
+ --data-urlencode "client_id=$CLIENT_ID" --data-urlencode "client_secret=$CLIENT_SECRET" | jq -r .access_token)
152
+ jq -n -c --arg blueprint "$BLUEPRINT_ID" --arg commit "$GITHUB_SHA" --arg status "$status" \
153
+ --argjson tests "${TEST_COUNT:-null}" --argjson checks "$checks" --argjson diff "${diff:-null}" \
154
+ --argjson warnings "$warnings" --arg run "$RUN_URL" \
155
+ '{blueprint_id: $blueprint, commit_sha: $commit, status: $status, test_count: $tests, checks: $checks,
156
+ diff_summary: $diff, warnings: $warnings, run_url: $run}' \
157
+ | curl -fsS -X POST "$REPORT_URL" -H "Authorization: Bearer $token" -H 'Content-Type: application/json' -H 'Accept: application/json' --data @- >/dev/null
158
+ echo "Reported $status for $GITHUB_SHA."
159
+
160
+ extension-image:
161
+ needs: checks
162
+ if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
163
+ runs-on: ubuntu-latest
164
+ timeout-minutes: 20
165
+ permissions:
166
+ contents: read
167
+ packages: write
168
+ env:
169
+ REGISTRY: ${{ vars.NUWAH_EXTENSION_REGISTRY }}
170
+ steps:
171
+ - uses: actions/checkout@v4
172
+
173
+ - name: Build the extension image
174
+ env:
175
+ NODE_AUTH_TOKEN: ${{ secrets.NUWAH_PACKAGES_TOKEN }}
176
+ run: |
177
+ name="${REGISTRY:-local}/${GITHUB_REPOSITORY##*/}-extension"
178
+ printf '%s' "$NODE_AUTH_TOKEN" > "$RUNNER_TEMP/npm-token"
179
+ docker build --file deploy/extension-image.Dockerfile \
180
+ --secret id=npm_token,src="$RUNNER_TEMP/npm-token" \
181
+ --label org.opencontainers.image.revision="$GITHUB_SHA" \
182
+ --tag "$name:$GITHUB_SHA" .
183
+ rm -f "$RUNNER_TEMP/npm-token"
184
+ echo "IMAGE=$name:$GITHUB_SHA" >> "$GITHUB_ENV"
185
+
186
+ - name: Push (only when a registry is set)
187
+ if: env.REGISTRY != ''
188
+ env:
189
+ REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190
+ run: |
191
+ printf '%s' "$REGISTRY_TOKEN" | docker login "${REGISTRY%%/*}" -u "$GITHUB_ACTOR" --password-stdin
192
+ docker push "$IMAGE"