@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,188 @@
1
+
2
+
3
+ import { refusalReason } from './http.js';
4
+ import { personDomainRequest } from './actors.js';
5
+
6
+ export const WISHLIST_CLAIM_REFUSAL = {
7
+
8
+ itemNotFound: 'wishlist_item_not_found',
9
+ claimNotFound: 'wishlist_claim_not_found',
10
+
11
+ unavailable: 'wishlist_claim_unavailable',
12
+ alreadyHeld: 'wishlist_claim_already_held',
13
+ notActive: 'wishlist_claim_not_active',
14
+ idempotencyKeyInvalid: 'idempotency_key_invalid',
15
+ idempotencyKeyReused: 'idempotency_key_reused',
16
+ };
17
+
18
+ export const WISHLIST_CLAIM_MAXIMUM_QUANTITY = 1000;
19
+
20
+ export function wishlistClaimRefusalReason(error) {
21
+ return refusalReason(error);
22
+ }
23
+
24
+ export const WISHLIST_REFUSAL = {
25
+ listNotOwned: 'list_not_owned',
26
+ itemNotFound: 'item_not_found',
27
+ descriptionRequired: 'description_required',
28
+ unknownKind: 'wishlist_kind_unknown',
29
+ unknownPriority: 'wishlist_priority_unknown',
30
+ urlRefused: 'wishlist_url_refused',
31
+ linkPreviewUnavailable: 'link_preview_unavailable',
32
+ handleNotFound: 'handle_not_found',
33
+ };
34
+
35
+ export function wishlistMoney(amount, currencyCode) {
36
+ if (!/^\d{1,15}(\.\d{1,4})?$/.test(amount)) {
37
+ throw new TypeError(`wishlists: an amount is a plain decimal string, got ${JSON.stringify(amount)}.`);
38
+ }
39
+ if (!/^[A-Z]{3}$/.test(currencyCode)) {
40
+ throw new TypeError(`wishlists: a currency code is three capital letters, got ${JSON.stringify(currencyCode)}.`);
41
+ }
42
+ return { amount, currency_code: currencyCode };
43
+ }
44
+ const BASE = '/api/wishlists';
45
+
46
+ function flag(value) {
47
+ return value === undefined ? undefined : value ? 1 : 0;
48
+ }
49
+ function assertQuantity(quantity) {
50
+ if (!Number.isInteger(quantity) || quantity < 1 || quantity > WISHLIST_CLAIM_MAXIMUM_QUANTITY) {
51
+
52
+ throw new TypeError(`wishlists: a claim quantity must be a whole number from 1 to ${WISHLIST_CLAIM_MAXIMUM_QUANTITY}, got ${JSON.stringify(quantity)}.`);
53
+ }
54
+ return quantity;
55
+ }
56
+ export function createWishlistsNamespace(http) {
57
+ const read = (options, params) => personDomainRequest(options, false, params);
58
+ const write = (options) => personDomainRequest(options, true);
59
+ const segment = encodeURIComponent;
60
+ return {
61
+
62
+ shared: (wishlistId, options) => http.get(`${BASE}/shared/${segment(wishlistId)}`, read(options)),
63
+ claims: {
64
+
65
+ mine: (query = {}, options) => http.get(`${BASE}/claims`, read(options, { cursor: query.cursor ?? undefined, limit: query.limit })),
66
+
67
+ claim: (itemId, quantity = 1, options) => http.post(`${BASE}/items/${segment(itemId)}/claims`, { quantity: assertQuantity(quantity) }, write(options)),
68
+
69
+ release: (claimId, options) => http.post(`${BASE}/claims/${segment(claimId)}/release`, undefined, write(options)),
70
+
71
+ markPurchased: (claimId, outcome = null, options) => http.post(`${BASE}/claims/${segment(claimId)}/purchased`, outcome === null ? {} : { outcome_type: outcome.type, outcome_id: outcome.id }, write(options)),
72
+
73
+ summary: (wishlistId, options) => http.get(`${BASE}/shared/${segment(wishlistId)}/claims-summary`, read(options)),
74
+ },
75
+
76
+ kinds: (options) => http.get(`${BASE}/kinds`, read(options)),
77
+
78
+ lists: {
79
+ page: (query = {}, options) => http.get(`${BASE}/lists`, read(options, {
80
+ archived: flag(query.archived),
81
+ sort: query.sort,
82
+ search: query.search || undefined,
83
+ cursor: query.cursor ?? undefined,
84
+ limit: query.limit,
85
+ })),
86
+ one: (listId, options) => http.get(`${BASE}/lists/${segment(listId)}`, read(options)),
87
+
88
+ create: (input, options) => http.post(`${BASE}/lists`, input, write(options)),
89
+
90
+ update: (listId, patch, options) => http.patch(`${BASE}/lists/${segment(listId)}`, patch, write(options)),
91
+ remove: (listId, options) => http.delete(`${BASE}/lists/${segment(listId)}`, write(options)),
92
+ archive: (listId, options) => http.post(`${BASE}/lists/${segment(listId)}/archive`, undefined, write(options)),
93
+ restore: (listId, options) => http.post(`${BASE}/lists/${segment(listId)}/restore`, undefined, write(options)),
94
+
95
+ duplicate: (listId, title, options) => http.post(`${BASE}/lists/${segment(listId)}/duplicate`, title ? { title } : {}, write(options)),
96
+ move: (listId, target, options) => http.post(`${BASE}/lists/${segment(listId)}/move`, target, write(options)),
97
+ uploadCover: (listId, file, options) => {
98
+ const form = new FormData();
99
+ form.append('file', file);
100
+ return http.post(`${BASE}/lists/${segment(listId)}/cover`, form, write(options));
101
+ },
102
+
103
+ setCover: (listId, mediaId, options) => http.post(`${BASE}/lists/${segment(listId)}/cover`, { media_id: mediaId }, write(options)),
104
+ removeCover: (listId, options) => http.delete(`${BASE}/lists/${segment(listId)}/cover`, write(options)),
105
+ collaborators: (listId, options) => http.get(`${BASE}/lists/${segment(listId)}/collaborators`, read(options)),
106
+
107
+ inviteCollaborator: (listId, handle, options) => http.post(`${BASE}/lists/${segment(listId)}/collaborators`, { handle }, write(options)),
108
+
109
+ removeCollaborator: (listId, collaboratorId, options) => http.delete(`${BASE}/lists/${segment(listId)}/collaborators/${segment(collaboratorId)}`, write(options)),
110
+
111
+ leaveList: (listId, myCollaboratorId, options) => {
112
+ if (typeof myCollaboratorId !== 'string' || myCollaboratorId === '') {
113
+ return Promise.reject(new TypeError('wishlists: only a collaborator can leave a list (my_collaborator_id is null for the owner).'));
114
+ }
115
+ return http.delete(`${BASE}/lists/${segment(listId)}/collaborators/${segment(myCollaboratorId)}`, write(options));
116
+ },
117
+ },
118
+ items: {
119
+ page: (listId, query = {}, options) => http.get(`${BASE}/lists/${segment(listId)}/items`, read(options, {
120
+ status: query.status,
121
+ priority: query.priority || undefined,
122
+ most_wanted: flag(query.most_wanted),
123
+ search: query.search || undefined,
124
+ sort: query.sort,
125
+ cursor: query.cursor ?? undefined,
126
+ limit: query.limit,
127
+ })),
128
+
129
+ create: (listId, input, options) => http.post(`${BASE}/lists/${segment(listId)}/items`, input, write(options)),
130
+ update: (itemId, patch, options) => http.patch(`${BASE}/items/${segment(itemId)}`, patch, write(options)),
131
+ remove: (itemId, options) => http.delete(`${BASE}/items/${segment(itemId)}`, write(options)),
132
+
133
+ move: (itemId, target, options) => http.post(`${BASE}/items/${segment(itemId)}/move`, target, write(options)),
134
+ uploadImage: (itemId, file, options) => {
135
+ const form = new FormData();
136
+ form.append('file', file);
137
+ return http.post(`${BASE}/items/${segment(itemId)}/images`, form, write(options));
138
+ },
139
+ removeImage: (imageId, options) => http.delete(`${BASE}/item-images/${segment(imageId)}`, write(options)),
140
+
141
+ refreshPreview: (itemId, options) => http.post(`${BASE}/items/${segment(itemId)}/preview`, undefined, write(options)),
142
+
143
+ chipIn: (itemId, input = {}, options) => http.post(`${BASE}/items/${segment(itemId)}/chip-in`, input, write(options)),
144
+ },
145
+
146
+ linkPreview: (url, options) => http.post(`${BASE}/link-preview`, { url }, write(options)),
147
+
148
+ assist: {
149
+
150
+ describeItem: (input, options) => http.post(`${BASE}/assist/describe-item`, { ...input, opt_in: true }, write(options)),
151
+
152
+ tidy: (input, options) => http.post(`${BASE}/assist/tidy`, { ...input, opt_in: true }, write(options)),
153
+
154
+ ideas: (input, options) => http.post(`${BASE}/assist/ideas`, { ...input, opt_in: true }, write(options)),
155
+ },
156
+
157
+ collaborations: {
158
+ pending: (options) => http.get(`${BASE}/collaborations`, read(options)),
159
+ accept: (invitationId, options) => http.post(`${BASE}/collaborations/${segment(invitationId)}/accept`, undefined, write(options)),
160
+ decline: (invitationId, options) => http.post(`${BASE}/collaborations/${segment(invitationId)}/decline`, undefined, write(options)),
161
+ },
162
+
163
+ sharedLists: {
164
+ page: (query = {}, options) => http.get(`${BASE}/shared`, read(options, { cursor: query.cursor ?? undefined, limit: query.limit })),
165
+
166
+ one: (wishlistId, query = {}, options) => http.get(`${BASE}/shared/${segment(wishlistId)}`, read(options, {
167
+ status: query.status,
168
+ priority: query.priority || undefined,
169
+ most_wanted: flag(query.most_wanted),
170
+ search: query.search || undefined,
171
+ sort: query.sort,
172
+ })),
173
+
174
+ contributionProgress: (wishlistId, options) => http.get(`${BASE}/shared/${segment(wishlistId)}/contribution-progress`, read(options)),
175
+ },
176
+
177
+ follows: {
178
+
179
+ page: (query = {}, options) => http.get(`${BASE}/following`, read(options, { cursor: query.cursor ?? undefined, limit: query.limit, search: query.search || undefined })),
180
+
181
+ state: (wishlistId, options) => http.get(`${BASE}/shared/${segment(wishlistId)}/follow`, read(options)),
182
+
183
+ follow: (wishlistId, body = {}, options) => http.put(`${BASE}/shared/${segment(wishlistId)}/follow`, body, write(options)),
184
+
185
+ unfollow: (wishlistId, options) => http.delete(`${BASE}/shared/${segment(wishlistId)}/follow`, write(options)),
186
+ },
187
+ };
188
+ }
@@ -0,0 +1,114 @@
1
+ import type { Http } from './http.js';
2
+ /** One (org, role) context the person holds — as returned by LauncherService. */
3
+ export interface LauncherContext {
4
+ org_id: string;
5
+ org_name: string | null;
6
+ vertical: string | null;
7
+ role: string | null;
8
+ capabilities: string[];
9
+ }
10
+ /** GET /api/workbench/launcher — every context the caller holds, plus by-role / by-tenant groupings. */
11
+ export interface LauncherResponse {
12
+ contexts: LauncherContext[];
13
+ /** role → the contexts holding that role. */
14
+ by_role: Record<string, LauncherContext[]>;
15
+ by_tenant: LauncherContext[];
16
+ }
17
+ export interface RollupListItem {
18
+ key: string;
19
+ label: string;
20
+ verticals: string[];
21
+ org_count: number;
22
+ }
23
+ export interface RollupListResponse {
24
+ rollups: RollupListItem[];
25
+ }
26
+ export interface RollupResponse {
27
+ key: string;
28
+ label: string;
29
+ /** One slice per org, each tagged with its org_id plus the roll-up's own fields. */
30
+ orgs: Array<Record<string, unknown> & {
31
+ org_id: string;
32
+ }>;
33
+ }
34
+ export interface InboxItem {
35
+ id: string;
36
+ org_id: string;
37
+ source: string;
38
+ category: 'needs_action' | 'update';
39
+ title: string;
40
+ subtitle: string | null;
41
+ occurred_at: string | null;
42
+ endpoint: string | null;
43
+ capability: string | null;
44
+ read: boolean;
45
+ }
46
+ export interface InboxResponse {
47
+ needs_action: InboxItem[];
48
+ updates: InboxItem[];
49
+ counts: {
50
+ needs_action: number;
51
+ updates: number;
52
+ unread: number;
53
+ };
54
+ }
55
+ export interface ActRequest {
56
+ org_id: string;
57
+ capability: string;
58
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
59
+ endpoint: string;
60
+ payload?: Record<string, unknown>;
61
+ }
62
+ export interface ActResponse {
63
+ status: number;
64
+ body: unknown;
65
+ }
66
+ /** The derived Standing (Influence + tier) — the inner object StandingController returns. */
67
+ export interface Standing {
68
+ person_id: string;
69
+ influence: number;
70
+ tier: string;
71
+ tier_label: string;
72
+ delta_month: number;
73
+ }
74
+ /** One verified fact behind the Standing (attributes list). */
75
+ export interface VerifiedAttribute {
76
+ id: string;
77
+ org_id: string | null;
78
+ kind: string;
79
+ value: Record<string, unknown>;
80
+ }
81
+ /** GET /api/standing/me — the Standing plus the verified attributes it was derived from. */
82
+ export interface StandingResponse {
83
+ standing: Standing;
84
+ attributes: VerifiedAttribute[];
85
+ }
86
+ /** POST /api/standing/refresh — folds fresh facts, recomputes Standing, auto-issues awards. */
87
+ export interface StandingRefreshResponse {
88
+ facts_recorded: number;
89
+ standing: Standing;
90
+ awards_issued: string[];
91
+ }
92
+ export declare function createWorkbenchNamespace(http: Http): {
93
+ /** GET /api/workbench/launcher — the (org,role) launcher, grouped by role or tenant. */
94
+ launcher: (group?: "role" | "tenant") => Promise<LauncherResponse>;
95
+ /** GET /api/workbench/rollups — the roll-ups the caller is entitled to. */
96
+ rollups: () => Promise<RollupListResponse>;
97
+ /** GET /api/workbench/rollups/{key} — one roll-up merged across the caller's orgs. */
98
+ rollup: (key: string) => Promise<RollupResponse>;
99
+ /** GET /api/workbench/inbox — the cross-org inbox (needs_action / updates). */
100
+ inbox: () => Promise<InboxResponse>;
101
+ /** POST /api/workbench/inbox/read-all — stamp the read cursor. */
102
+ inboxReadAll: () => Promise<{
103
+ ok: boolean;
104
+ }>;
105
+ /** POST /api/workbench/act — forward a write to one org's endpoint (capability-guarded). */
106
+ act: (req: ActRequest) => Promise<ActResponse>;
107
+ standing: {
108
+ /** GET /api/standing/me — the caller's Influence + tier. */
109
+ me: () => Promise<StandingResponse>;
110
+ /** POST /api/standing/refresh — fold facts → standing → auto-awards in one call. */
111
+ refresh: () => Promise<StandingRefreshResponse>;
112
+ };
113
+ };
114
+ export type WorkbenchNamespace = ReturnType<typeof createWorkbenchNamespace>;
@@ -0,0 +1,22 @@
1
+ export function createWorkbenchNamespace(http) {
2
+ return {
3
+
4
+ launcher: (group) => http.get('/api/workbench/launcher', { params: group ? { group } : undefined }),
5
+
6
+ rollups: () => http.get('/api/workbench/rollups'),
7
+
8
+ rollup: (key) => http.get(`/api/workbench/rollups/${key}`),
9
+
10
+ inbox: () => http.get('/api/workbench/inbox'),
11
+
12
+ inboxReadAll: () => http.post('/api/workbench/inbox/read-all'),
13
+
14
+ act: (req) => http.post('/api/workbench/act', req),
15
+ standing: {
16
+
17
+ me: () => http.get('/api/standing/me'),
18
+
19
+ refresh: () => http.post('/api/standing/refresh'),
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,190 @@
1
+ import type { Http, RequestOptions } from './http.js';
2
+ /**
3
+ * A nav label. Both languages are always present — core builds it as
4
+ * `['en' => labelEn, 'ar' => labelAr]` with no conditional — so a shell never has to
5
+ * decide what to show when the active locale is missing.
6
+ */
7
+ export interface WorkspaceNavLabel {
8
+ en: string;
9
+ ar: string;
10
+ }
11
+ export type WorkspaceNavSection = 'overview' | 'front-desk' | 'people' | 'programme' | 'money' | 'operations' | 'reports' | 'system';
12
+ /**
13
+ * One nav entry, already filtered.
14
+ *
15
+ * The server has dropped every item the org is not entitled to before sending this, so a
16
+ * shell renders the list as given — `requiresModule` and `requiresCapability` are carried
17
+ * for context, not for the client to re-apply.
18
+ *
19
+ * `module` and `requiresModule` hold the SAME value on purpose: the sidebar groups by the
20
+ * first and the entitlement filter reads the second, and core emits both from one place
21
+ * rather than duplicating the decision across its 258 entries.
22
+ */
23
+ export interface WorkspaceNavItem {
24
+ key: string;
25
+ label: WorkspaceNavLabel;
26
+ icon: string;
27
+ path: string;
28
+ /** Always sent by core. Optional only so an older deployment still renders. */
29
+ section?: WorkspaceNavSection;
30
+ /** Absent on an entry that belongs to no module. */
31
+ module?: string;
32
+ requiresModule?: string;
33
+ requiresCapability?: string;
34
+ }
35
+ /** Where one role lands when it becomes the active one. */
36
+ export interface WorkspaceDescriptor {
37
+ role: string;
38
+ /** The workspace key the vertical registers this role's shell under. */
39
+ workspace: string;
40
+ label: WorkspaceNavLabel;
41
+ /** The route this role opens on. */
42
+ home: string;
43
+ }
44
+ /** What the ORG is entitled to, which is what the nav slice was filtered against. */
45
+ export interface WorkspaceEntitlements {
46
+ modules: string[];
47
+ capabilities: string[];
48
+ }
49
+ /** The `/me` payload, flattened by core into one object. */
50
+ export interface WorkspaceMe {
51
+ person: {
52
+ id: string;
53
+ name: string | null;
54
+ email: string | null;
55
+ };
56
+ org: {
57
+ id: string | null;
58
+ role: string | null;
59
+ };
60
+ vertical: {
61
+ key: string | null;
62
+ label: string | null;
63
+ };
64
+ entitlements: WorkspaceEntitlements;
65
+ /** The roles the caller actually HOLDS. */
66
+ roles: string[];
67
+ /**
68
+ * Every role THIS VERTICAL declares, which is a different question from what the
69
+ * caller holds.
70
+ *
71
+ * It is the same allowlist the endpoint validates `?role=` against, so it is what an
72
+ * admin's "view as" menu must be built from. Core sends it precisely because the
73
+ * payload used not to, and every shell kept a static copy instead — one of which was
74
+ * another product's role list, stale from the day that vertical was branched. A client
75
+ * that cannot see this field is guessing at a list the server is already holding.
76
+ */
77
+ declaredRoles: string[];
78
+ /** The first held role, or a validated `?role=` override. */
79
+ activeRole: string;
80
+ /** True only while an admin previews a role they do not hold. */
81
+ isImpersonating: boolean;
82
+ /** One descriptor per held role. */
83
+ workspaces: WorkspaceDescriptor[];
84
+ /** The entitlement-filtered nav for `activeRole`. */
85
+ nav: WorkspaceNavItem[];
86
+ /** Whether the org is entitled to the inbox capability. */
87
+ inbox: boolean;
88
+ search: boolean;
89
+ }
90
+ /** One global-search hit. `path` is where to navigate. */
91
+ export interface WorkspaceSearchResult {
92
+ type: string;
93
+ label: string;
94
+ sublabel: string | null;
95
+ path: string;
96
+ module: string;
97
+ /** The result's kind in the reader's language ("فاتورة"). Older servers omit it — fall back to `type`. */
98
+ type_label?: string;
99
+ }
100
+ /** A manual role grant. */
101
+ export interface RoleAssignment {
102
+ id: string;
103
+ platform_person_id: string;
104
+ role_key: string;
105
+ /** How the grant arose — `manual` for one made through this endpoint. */
106
+ source: string;
107
+ /** The person who granted it. */
108
+ assigned_by: string | null;
109
+ created_at: string | null;
110
+ }
111
+ export declare function createWorkspaceNamespace(http: Http): {
112
+ /**
113
+ * GET /api/workspace/me — the whole shell descriptor in one call.
114
+ *
115
+ * `role` asks for a specific role's lens and is honoured only if the caller holds
116
+ * it; otherwise the first held role answers. Set `impersonate` to let an ADMIN
117
+ * preview a role they do not hold: core then accepts any role the vertical
118
+ * declares and sets `isImpersonating`. A non-admin passing it is ignored rather
119
+ * than refused, so it can never be an escalation.
120
+ *
121
+ * The preview changes which shell this endpoint returns — nav, home, workspace —
122
+ * and nothing else. Every other endpoint still authorises against the caller's
123
+ * real grants, so it is a presentation lens, not a security boundary.
124
+ */
125
+ me: (role?: string, impersonate?: boolean, options?: RequestOptions) => Promise<WorkspaceMe>;
126
+ /**
127
+ * GET /api/workspace/search — global cross-entity search.
128
+ *
129
+ * Each source is gated on the org's entitlement AND the caller's view permission,
130
+ * so results are already safe to show. `limit` is clamped to 1..30 and defaults
131
+ * to 20; a value outside that range is adjusted rather than refused.
132
+ */
133
+ search: (query: string, limit?: number, options?: RequestOptions) => Promise<WorkspaceSearchResult[]>;
134
+ /** Per-person UI preferences, stored server-side so they follow the person. */
135
+ preferences: {
136
+ /**
137
+ * GET /api/workspace/preferences — every stored preference for the caller, as a
138
+ * flat object keyed by preference name.
139
+ *
140
+ * Per PERSON, not per browser, which is the point: a preference set on a laptop is
141
+ * there on a phone.
142
+ */
143
+ all: (options?: RequestOptions) => Promise<Record<string, string>>;
144
+ /**
145
+ * PUT /api/workspace/preferences/{key} — upsert one preference.
146
+ *
147
+ * The key must match `[A-Za-z0-9_]+`, enforced as a route constraint: a key
148
+ * carrying anything else does not fail validation, it fails to ROUTE, and answers
149
+ * 404. Sanitise before calling — see `sanitizePreferenceKey`.
150
+ */
151
+ set: (key: string, value: string, options?: RequestOptions) => Promise<{
152
+ ok: boolean;
153
+ }>;
154
+ };
155
+ /** Manual role grants. */
156
+ roleAssignments: {
157
+ /**
158
+ * GET /api/workspace/role-assignments — manual grants, oldest first. Optionally
159
+ * narrowed to one person. Needs `workspace.roles.manage`.
160
+ */
161
+ list: (platformPersonId?: string, options?: RequestOptions) => Promise<{
162
+ data: RoleAssignment[];
163
+ }>;
164
+ /**
165
+ * POST /api/workspace/role-assignments — grant a role. Needs `workspace.roles.manage`.
166
+ *
167
+ * Idempotent, and the status code is the only thing that says which happened: 201
168
+ * for a new grant, 200 when the person already held it. Only a real grant is
169
+ * written to the audit trail, so a repeat is genuinely a no-op rather than noise.
170
+ *
171
+ * `roleKey` must be one the vertical declares; anything else answers 422.
172
+ */
173
+ grant: (platformPersonId: string, roleKey: string, options?: RequestOptions) => Promise<RoleAssignment>;
174
+ /**
175
+ * DELETE /api/workspace/role-assignments/{id} — revoke a grant.
176
+ * Needs `workspace.roles.manage`. Audited before the row is removed.
177
+ */
178
+ revoke: (id: string, options?: RequestOptions) => Promise<void>;
179
+ };
180
+ };
181
+ /**
182
+ * Coerce a string into a legal preference key (`[A-Za-z0-9_]+`), replacing anything else
183
+ * with an underscore.
184
+ *
185
+ * Exported because it has to be applied CONSISTENTLY: a caller that caches preferences
186
+ * locally must use the same key on both sides, or the local copy and the stored one drift
187
+ * apart silently and the preference appears not to persist.
188
+ */
189
+ export declare function sanitizePreferenceKey(key: string): string;
190
+ export type WorkspaceNamespace = ReturnType<typeof createWorkspaceNamespace>;
@@ -0,0 +1,41 @@
1
+ export function createWorkspaceNamespace(http) {
2
+ const preferences = {
3
+
4
+ all: (options) => http.get('/api/workspace/preferences', options),
5
+
6
+ set: (key, value, options) => http.put(`/api/workspace/preferences/${key}`, { value }, options),
7
+ };
8
+ const roleAssignments = {
9
+
10
+ list: (platformPersonId, options) => http.get('/api/workspace/role-assignments', {
11
+ ...options,
12
+ params: platformPersonId ? { platform_person_id: platformPersonId } : undefined,
13
+ }),
14
+
15
+ grant: (platformPersonId, roleKey, options) => http.post('/api/workspace/role-assignments', { platform_person_id: platformPersonId, role_key: roleKey }, options),
16
+
17
+ revoke: (id, options) => http.delete(`/api/workspace/role-assignments/${id}`, options),
18
+ };
19
+ return {
20
+
21
+ me: (role, impersonate = false, options) => http.get('/api/workspace/me', {
22
+ ...options,
23
+ params: role === undefined ? undefined : impersonate ? { role, as: 1 } : { role },
24
+ }),
25
+
26
+ search: (query, limit = 20, options) => http
27
+ .get('/api/workspace/search', {
28
+ ...options,
29
+ params: { q: query, limit },
30
+ })
31
+ .then((response) => response.data),
32
+
33
+ preferences,
34
+
35
+ roleAssignments,
36
+ };
37
+ }
38
+
39
+ export function sanitizePreferenceKey(key) {
40
+ return key.replace(/[^A-Za-z0-9_]/g, '_');
41
+ }
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@nuwah/vertical-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0-rc.1",
4
+ "description": "Typed, stack-agnostic TypeScript client a vertical (its FE or thin backend) uses to call nuwah-core's modular-monolith module APIs (CRM, Bookings, Accounting, HR) with a bearer token.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "bin": {
16
+ "nuwah-contract-check": "./bin/nuwah-contract-check.mjs"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "bin",
21
+ "templates"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.build.json && node ../scripts/finalize-dist.mjs --keep-doc-comments",
25
+ "clean": "rm -rf dist",
26
+ "swap-pkg": "node scripts/swap-pkg.mjs",
27
+ "prepack": "npm run clean && npm run build && npm run swap-pkg to-dist",
28
+ "postpack": "npm run swap-pkg restore",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "typecheck": "tsc --noEmit"
32
+ },
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org",
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "hono": "^4.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "hono": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "license": "SEE LICENSE IN LICENSE",
46
+ "author": "Nuwah",
47
+ "homepage": "https://developers.nuwah.com",
48
+ "engines": {
49
+ "node": ">=18.17"
50
+ },
51
+ "dependencies": {
52
+ "jose": "^5.0.0"
53
+ }
54
+ }
@@ -0,0 +1,38 @@
1
+ # syntax=docker/dockerfile:1.7
2
+ #
3
+ # A level-3 vertical's extension image. Seeded into the builder repository as
4
+ # deploy/extension-image.Dockerfile and built by vertical-ci's `extension-image` job after a green
5
+ # push to the default branch. Production runs the image of the commit an independent reviewer
6
+ # approved (`builder.code_reviews`), never "latest".
7
+ #
8
+ # One image, two parts: the thin server (server/, Hono, esbuild-bundled like every vertical's, see
9
+ # nuwah-workspace deploy/images/vertical) serving the API on 5401, and the built app (app/dist)
10
+ # served by that same server as static files. The npm token for @nuwah/* is a BuildKit secret, so
11
+ # it never lands in a layer.
12
+ #
13
+ # Source of truth: @nuwah/vertical-sdk/templates/extension-image.Dockerfile.
14
+
15
+ FROM node:22-slim AS build
16
+ WORKDIR /repository
17
+ COPY package.json package-lock.json* .npmrc* ./
18
+ COPY app/package.json app/package.json
19
+ COPY server/package.json server/package.json
20
+ RUN --mount=type=secret,id=npm_token \
21
+ NODE_AUTH_TOKEN="$(cat /run/secrets/npm_token 2>/dev/null || true)" \
22
+ npm ci --ignore-scripts --no-audit --no-fund
23
+ COPY . .
24
+ RUN npm run build \
25
+ && npx --no-install esbuild server/src/index.ts --bundle --platform=node --target=node22 --format=esm \
26
+ --outfile=/out/server.mjs --external:better-sqlite3 \
27
+ && cp -r app/dist /out/public
28
+
29
+ FROM node:22-slim
30
+ WORKDIR /app
31
+ ENV NODE_ENV=production PORT=5401 STATIC_DIRECTORY=/app/public
32
+ COPY --from=build /out/server.mjs ./server.mjs
33
+ COPY --from=build /out/public ./public
34
+ RUN mkdir -p /app/data && chown -R node:node /app
35
+ USER node
36
+ EXPOSE 5401
37
+ HEALTHCHECK --interval=30s --timeout=3s CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
38
+ CMD ["node", "server.mjs"]