@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,401 @@
1
+ import type { Http, QueryParams } from './http.js';
2
+ import type { LaravelResourceCollection } from './types.js';
3
+ import type { PartyAttributePatch, PartyAttributes, PartyAttributeValue, PartyFieldType, PartyPiiClass, PartyRoleAttributes } from './party-baseline-attributes.js';
4
+ export * from './party-baseline-attributes.js';
5
+ /** `person` or `organization` — closed, because it selects which attribute definitions apply. */
6
+ export type PartyTypeCode = 'person' | 'organization';
7
+ /**
8
+ * The directory's role vocabulary (`PartyRoleType`).
9
+ *
10
+ * Widened with `(string & {})` on purpose: `party.roles.role` is a `varchar(255)` with no
11
+ * CHECK constraint, `Parties` takes `string $role` throughout, and `PartyResource` falls
12
+ * back to the raw value when an enum case is missing — so a tenant-defined role can reach
13
+ * a client. The union keeps autocomplete on the eleven known values without lying about
14
+ * the set being closed on the wire.
15
+ */
16
+ export type PartyRoleCode = 'member' | 'patient' | 'employee' | 'practitioner' | 'coach' | 'client' | 'contact' | 'applicant' | 'customer' | 'vendor' | 'guardian' | 'lead' | (string & {});
17
+ /** A bilingual label pair, as every core enum emits it. */
18
+ export interface BilingualLabel {
19
+ en: string;
20
+ ar: string;
21
+ }
22
+ /** One role a party holds, over one span, as `PartyResource` presents it. */
23
+ export interface PartyRoleEntry {
24
+ id: string;
25
+ role: PartyRoleCode;
26
+ /** Server-rendered, both languages. Falls back to the raw value for a tenant role. */
27
+ role_label: BilingualLabel;
28
+ status: string;
29
+ /** Calendar dates (`YYYY-MM-DD`), not instants. */
30
+ started_at: string | null;
31
+ ended_at: string | null;
32
+ /** `ended_at === null`. The database permits only ONE active instance of a given role. */
33
+ active: boolean;
34
+ /**
35
+ * A human sub-label where the role alone does not say enough — today only a club
36
+ * member's STANDING: `عضو عامل` (working, carries duties and votes) versus `عضو عام`
37
+ * (ordinary). Null when the role needs no qualifier or none is recorded.
38
+ *
39
+ * Derived from the role's `standing` attribute (also in `attributes`), as a ready-made
40
+ * label. Render it INSTEAD of `role_label` when present: showing both standings as
41
+ * "Member" tells a club its two classes are one thing, and a directory that cannot tell
42
+ * them apart cannot be used to call a general assembly.
43
+ */
44
+ qualifier: BilingualLabel | null;
45
+ /**
46
+ * This role span's fields the caller may READ, `{key: value}` — definitions for
47
+ * `role:<role>`, filtered by each field's read grant on the server. An undefined key is
48
+ * never published.
49
+ */
50
+ attributes: PartyRoleAttributes;
51
+ /** Keys on this span the caller may NOT read — names only. Render "N hidden", not a gap. */
52
+ attributes_withheld: string[];
53
+ }
54
+ /** A row of `roles()` and the answer to `roles.setAttributes()` — no `qualifier` there. */
55
+ export type PartyRoleRow = Omit<PartyRoleEntry, 'qualifier'>;
56
+ /** One party, as `PartyResource` presents it. */
57
+ export interface Party {
58
+ id: string;
59
+ party_type: PartyTypeCode;
60
+ party_type_label: BilingualLabel;
61
+ display_name: string;
62
+ /**
63
+ * The Arabic display name, or null when none is recorded.
64
+ *
65
+ * The `display_name_ar` attribute, lifted to a named key because every consumer renders a
66
+ * name; it is present even when `?fields[]=` trims `attributes`. Without it a bilingual UI
67
+ * renders English names in Arabic. Fall back to `display_name` when this is null — do not
68
+ * render a blank where a name should be.
69
+ */
70
+ display_name_ar: string | null;
71
+ /**
72
+ * The party's own fields the caller may READ, `{key: value}` — definitions for
73
+ * `party:<party_type>`, filtered by each field's read grant on the server (gender needs
74
+ * `party.sensitive.view`, a tenant field may need more). Undefined keys and the server's
75
+ * `_norm` shadows are never published. Always an object, possibly empty.
76
+ */
77
+ attributes: PartyAttributes;
78
+ /**
79
+ * Keys the party carries that the caller may NOT read — names, never values. Say "2
80
+ * fields hidden" rather than rendering a shorter record an operator reads as missing data.
81
+ */
82
+ attributes_withheld: string[];
83
+ email: string | null;
84
+ phone: string | null;
85
+ status: string;
86
+ /** The shared-identity anchor — null until linked. */
87
+ platform_person_id: string | null;
88
+ /** `platform_person_id !== null` — a null anchor means "never signed in", not "missing". */
89
+ can_sign_in: boolean;
90
+ /**
91
+ * Present only when the server eager-loaded them (`whenLoaded`). `list()`, `get()`,
92
+ * `create()`, `update()` and `link()` all load them; nothing else promises to.
93
+ */
94
+ roles?: PartyRoleEntry[];
95
+ created_at: string | null;
96
+ updated_at: string | null;
97
+ }
98
+ /**
99
+ * A directory filter operator, in the URL-friendly spelling the server accepts. Which ones a
100
+ * field allows depends on its type — `x-nuwah-operators` in `fields.schema()` lists them; an
101
+ * operator the type cannot answer is a 422, never a confidently wrong result.
102
+ */
103
+ export type PartyFilterOperator = 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'not_in' | 'between' | 'contains' | 'starts_with';
104
+ /** A filter value: a scalar, or a list for `in` / `not_in` / `between` (exactly two bounds). */
105
+ export type PartyFilterValue = PartyAttributeValue | Array<string | number>;
106
+ /**
107
+ * `filter[<key>][<operator>]=value`. A bare value means `eq`.
108
+ *
109
+ * Party keys resolve against `party:<party_type>` (`party:*` without one — so `date_of_birth`
110
+ * needs `party_type: 'person'`); a ROLE key needs `role` and matches that role's active span.
111
+ * A key you cannot read is refused exactly like an unknown one (422).
112
+ */
113
+ export type PartyAttributeFilter = Record<string, PartyFilterValue | Partial<Record<PartyFilterOperator, PartyFilterValue>>>;
114
+ /** `attr:<key>` ascending, `-attr:<key>` descending. NULLs sort last either way. */
115
+ export type PartyAttributeSort = `attr:${string}` | `-attr:${string}`;
116
+ /** `GET /api/v1/party/parties` query. Every key is validated server-side. */
117
+ export interface PartyListQuery {
118
+ /**
119
+ * Substring over display_name, email and phone, plus every field flagged `searchable` that
120
+ * the caller may read (party fields always; a role's fields when `role` is given — the
121
+ * practitioner `specialty` is one). Arabic is folded on both sides. Max 120 chars.
122
+ */
123
+ q?: string;
124
+ /** Narrow to parties holding this role ACTIVELY. One role, not a list. */
125
+ role?: PartyRoleCode;
126
+ /** With `role`: `current` (the default) lists today's holders, `former` those whose span has ended. */
127
+ role_state?: 'current' | 'former';
128
+ party_type?: PartyTypeCode;
129
+ status?: string;
130
+ /** 1–100. Defaults to 25 server-side. */
131
+ per_page?: number;
132
+ page?: number;
133
+ /** At most ten keys. */
134
+ filter?: PartyAttributeFilter;
135
+ sort?: PartyAttributeSort;
136
+ /** Trim every row's `attributes` (and `attributes_withheld`) to these keys. Never widens. */
137
+ fields?: string[];
138
+ }
139
+ /** `POST /api/v1/party/parties` body. */
140
+ export interface CreatePartyInput {
141
+ display_name: string;
142
+ party_type: PartyTypeCode;
143
+ email?: string | null;
144
+ phone?: string | null;
145
+ platform_person_id?: string | null;
146
+ /** Granted idempotently after the party resolves. Must be a KNOWN enum value here. */
147
+ role?: PartyRoleCode;
148
+ /**
149
+ * The party's own fields. Written in the SAME transaction as the party, under each field's
150
+ * write grant — and onto the matched party too when `matched_existing` comes back true.
151
+ */
152
+ attributes?: PartyAttributePatch;
153
+ /**
154
+ * Fields per role: `{ member: { standing: 'working' } }`. Each role must be `role` above
155
+ * or one the party already holds. Any refusal anywhere rolls back the whole request,
156
+ * including the party it would have created.
157
+ */
158
+ role_attributes?: Record<string, PartyAttributePatch>;
159
+ }
160
+ /**
161
+ * `PUT /api/v1/party/parties/{party}` body — the contact columns and the party's own fields.
162
+ *
163
+ * `party_type` is NOT updatable (it selects which attribute definitions apply), and
164
+ * `platform_person_id` has its own endpoint because linking can be REFUSED. Every key is
165
+ * `sometimes`, so omitting one leaves it untouched; `email` and `phone` are additionally
166
+ * `nullable`, so sending `null` CLEARS them.
167
+ */
168
+ export interface UpdatePartyInput {
169
+ display_name?: string;
170
+ email?: string | null;
171
+ phone?: string | null;
172
+ status?: string;
173
+ /**
174
+ * A patch of the party's fields: omitted keys untouched, `null` clears. Each key needs its
175
+ * field's write grant and may not be `managed`; any refusal saves NOTHING (contact columns
176
+ * included) and answers {@link PartyAttributesRefused}.
177
+ */
178
+ attributes?: PartyAttributePatch;
179
+ /**
180
+ * A patch per role, on that role's ACTIVE span: `{ client: { notes: null } }`. Written in the
181
+ * SAME transaction as everything above — a refused role field (or a role the party does not
182
+ * hold right now) saves nothing at all, and is reported under `role_attributes.<role>.<key>`.
183
+ */
184
+ role_attributes?: Record<string, PartyAttributePatch>;
185
+ }
186
+ /**
187
+ * The 422 every attribute refusal answers with. `errors` is keyed by REQUEST path —
188
+ * `attributes.gender`, `role_attributes.member.standing` — the same paths Laravel's own
189
+ * validation errors use, each in both languages. Nothing was saved.
190
+ */
191
+ export interface PartyAttributesRefused {
192
+ message: string;
193
+ message_ar: string;
194
+ errors: Record<string, BilingualLabel>;
195
+ }
196
+ /** One field in {@link PartyFieldSchema}: standard JSON Schema plus `x-nuwah-*` annotations. */
197
+ export interface PartyFieldSchemaProperty {
198
+ /** A JSON Schema type, with `'null'` beside it when the field is optional (null clears). */
199
+ type: string | string[];
200
+ title: string;
201
+ /** True where the server would refuse THIS caller a write: managed, retired, or no grant. */
202
+ readOnly: boolean;
203
+ deprecated?: boolean;
204
+ format?: 'date' | 'date-time' | 'uuid';
205
+ enum?: Array<string | null>;
206
+ pattern?: string;
207
+ maxLength?: number;
208
+ minimum?: number;
209
+ maximum?: number;
210
+ 'x-nuwah-label': BilingualLabel;
211
+ 'x-nuwah-type': PartyFieldType;
212
+ 'x-nuwah-control': string;
213
+ 'x-nuwah-pii-class': PartyPiiClass;
214
+ 'x-nuwah-state': 'published' | 'deprecated' | 'retired';
215
+ 'x-nuwah-version': number;
216
+ 'x-nuwah-managed': boolean;
217
+ /** What `filter[<key>][<operator>]` accepts — the ENGINE spellings (`=`, `>=`, `not in`). */
218
+ 'x-nuwah-operators': string[];
219
+ 'x-nuwah-options'?: Array<{
220
+ value: string;
221
+ label: BilingualLabel;
222
+ }>;
223
+ 'x-nuwah-scale'?: number;
224
+ 'x-nuwah-currency'?: string;
225
+ 'x-nuwah-target'?: string;
226
+ }
227
+ /**
228
+ * `GET /api/v1/party/fields/schema` — a JSON Schema 2020-12 document at the ROOT of the body
229
+ * (no `data` envelope), describing only the fields the caller may read.
230
+ */
231
+ export interface PartyFieldSchema {
232
+ $schema: 'https://json-schema.org/draft/2020-12/schema';
233
+ $id: string;
234
+ title: string;
235
+ type: 'object';
236
+ properties: Record<string, PartyFieldSchemaProperty>;
237
+ /** Fields a COMPLETE record holds — checked over the merged record, not each PATCH. */
238
+ required: string[];
239
+ additionalProperties: false;
240
+ 'x-nuwah-applies-to': string;
241
+ }
242
+ /** `party:person`, `party:organization`, `party:*`, or `role:<role>`. */
243
+ export type PartyFieldShape = 'party:person' | 'party:organization' | 'party:*' | `role:${string}`;
244
+ /**
245
+ * Flatten {@link PartyListQuery} into the bracketed keys Laravel parses:
246
+ * `filter[standing][eq]=working`, `fields[]=gender`. Exported so a caller building its own URL
247
+ * (a CSV export link) spells it the same way.
248
+ */
249
+ export declare function partyListParams(query: PartyListQuery): QueryParams;
250
+ /** `{ data, resolved_from }` — see the class note on tombstone resolution. */
251
+ export interface PartyResolved {
252
+ data: Party;
253
+ /**
254
+ * Non-null when the id you asked for was a merge tombstone and `data` is its SURVIVOR.
255
+ * Surface it; a silently swapped record reads as a lost one.
256
+ */
257
+ resolved_from: string | null;
258
+ }
259
+ /**
260
+ * `{ data, matched_existing }`.
261
+ *
262
+ * `ensureParty()` de-duplicates on email, case-insensitively, and the endpoint answers
263
+ * **200 + `matched_existing: true`** rather than 201 when it matched — so a client can say
264
+ * "we already had them" instead of claiming to have created a duplicate.
265
+ */
266
+ export interface PartyCreated {
267
+ data: Party;
268
+ matched_existing: boolean;
269
+ }
270
+ /**
271
+ * What `addRole()` returns — FOUR keys, deliberately not {@link PartyRoleEntry}.
272
+ *
273
+ * The grant endpoint echoes the row it wrote and nothing more. Typing it as the full entry
274
+ * would promise a `role_label` that is not in the response, and every consumer rendering
275
+ * it would print `undefined`.
276
+ */
277
+ export interface PartyRoleGranted {
278
+ id: string;
279
+ role: PartyRoleCode;
280
+ started_at: string | null;
281
+ active: boolean;
282
+ }
283
+ export declare function createPartyNamespace(http: Http): {
284
+ /**
285
+ * GET /api/v1/party/parties — the tenant's directory, filtered and paginated.
286
+ *
287
+ * Guard `party.view`, which is the BROADEST read in the people plane: four club
288
+ * roles hold it where only one holds `hr.employees.view`.
289
+ *
290
+ * Server-side: `q` is a trigram-indexed substring over name/email/phone, ordering is
291
+ * `display_name COLLATE "ar-x-icu"` so Arabic names sort the way an Arabic speaker
292
+ * expects, merge tombstones are filtered out, and `roles` are eager-loaded.
293
+ *
294
+ * `per_page` is capped at 100 — page, do not widen.
295
+ *
296
+ * Attribute search: `filter` (`{ standing: { eq: 'working' } }`, with `role`), `sort`
297
+ * (`'-attr:member_since'`) and `fields` (trim `attributes`). A refused key or operator
298
+ * is a 422 with `message` / `message_ar`.
299
+ */
300
+ list: (query?: PartyListQuery) => Promise<LaravelResourceCollection<Party>>;
301
+ /**
302
+ * GET /api/v1/party/parties/{party} — one party, FOLLOWING a merge tombstone.
303
+ *
304
+ * Returns `{ data, resolved_from }`. Check `resolved_from`: when it is non-null the
305
+ * caller's id was retired by a merge and `data` is the survivor.
306
+ */
307
+ get: (partyId: string) => Promise<PartyResolved>;
308
+ /**
309
+ * POST /api/v1/party/parties — create, or return the party that already matches.
310
+ *
311
+ * Guard `party.manage`. Read `matched_existing` before telling anyone you created
312
+ * something: this endpoint is the de-duplication seam, and a 200 means it matched an
313
+ * existing person by email.
314
+ *
315
+ * `attributes` and `role_attributes` are written in the same transaction; a refusal
316
+ * of any one rolls everything back and answers {@link PartyAttributesRefused}.
317
+ */
318
+ create: (input: CreatePartyInput) => Promise<PartyCreated>;
319
+ /**
320
+ * PUT /api/v1/party/parties/{party} — the contact columns and the party's fields.
321
+ *
322
+ * Guard `party.manage`, plus each field's own write grant. Send only the keys being
323
+ * changed; `null` on `email`/`phone` or on an attribute clears it. A refused attribute
324
+ * saves nothing and answers {@link PartyAttributesRefused}.
325
+ */
326
+ update: (partyId: string, input: UpdatePartyInput) => Promise<{
327
+ data: Party;
328
+ }>;
329
+ /**
330
+ * GET /api/v1/party/parties/{party}/roles — every role, current and historical.
331
+ * Also `roles.setAttributes(…)`.
332
+ *
333
+ * Guard `party.view`. A party legitimately holds the same role several times across
334
+ * the years (a lapsed membership beside a current one), so filter on `active` rather
335
+ * than assuming one row per role.
336
+ */
337
+ roles: ((partyId: string) => Promise<{
338
+ data: PartyRoleRow[];
339
+ }>) & {
340
+ /**
341
+ * PATCH /api/v1/party/parties/{party}/roles/{role}/attributes — fields on the
342
+ * party's ACTIVE span of `role`.
343
+ *
344
+ * Guard `party.manage`, plus each field's write grant; `managed` fields
345
+ * (`last_booked_at`) are refused to a person. Omitted keys untouched, `null`
346
+ * clears. 404 when the party does not hold the role right now; 422
347
+ * {@link PartyAttributesRefused} when any key is refused, with nothing saved.
348
+ */
349
+ setAttributes: (partyId: string, role: PartyRoleCode, attributes: PartyAttributePatch) => Promise<{
350
+ data: PartyRoleRow;
351
+ }>;
352
+ };
353
+ /**
354
+ * POST /api/v1/party/parties/{party}/roles — grant a role. Idempotent.
355
+ *
356
+ * Guard `party.manage`. A retried request returns the same row rather than colliding
357
+ * with the one-active-instance index. A person-only role on an organization is
358
+ * REFUSED with a bilingual 422 naming the correct model.
359
+ *
360
+ * `startedAt` is `Y-m-d` STRICTLY — an ISO instant is a validation error, not a
361
+ * coercion. Returns {@link PartyRoleGranted}, which is narrower than a `roles()` row.
362
+ */
363
+ addRole: (partyId: string, role: PartyRoleCode, startedAt?: string) => Promise<{
364
+ data: PartyRoleGranted;
365
+ }>;
366
+ /**
367
+ * DELETE /api/v1/party/parties/{party}/roles/{role} — END a role.
368
+ *
369
+ * Guard `party.manage`. The row SURVIVES with `ended_at` set: a lapsed membership is
370
+ * history, not a mistake, and the span is what makes "was this person a member in
371
+ * March" answerable. `endedAt` is `Y-m-d`; omitted means today.
372
+ */
373
+ endRole: (partyId: string, role: PartyRoleCode, endedAt?: string) => Promise<{
374
+ data: {
375
+ role: string;
376
+ ended: boolean;
377
+ };
378
+ }>;
379
+ /**
380
+ * POST /api/v1/party/parties/{party}/link — bind a party to a platform identity.
381
+ *
382
+ * Guard `party.manage`. Returns `{ data: Party }` on success; a REFUSED link
383
+ * (the identity already belongs to another party in this tenant) is a 409 whose
384
+ * body carries `conflicting_party_id` for the merge the operator must do instead.
385
+ *
386
+ * There is deliberately NO unlink: detaching a sign-in from the record it has been
387
+ * accumulating history against is a merge or a DSAR, not a "forget it".
388
+ */
389
+ link: (partyId: string, platformPersonId: string) => Promise<{
390
+ data: Party;
391
+ }>;
392
+ fields: {
393
+ /**
394
+ * GET /api/v1/party/fields/schema — the fields one record shape carries, as JSON
395
+ * Schema 2020-12, built from what THIS caller may read (`readOnly` where they may
396
+ * not write). Guard `party.view`. Unwrapped: the schema is the body.
397
+ */
398
+ schema: (appliesTo: PartyFieldShape) => Promise<PartyFieldSchema>;
399
+ };
400
+ };
401
+ export type PartyNamespace = ReturnType<typeof createPartyNamespace>;
package/dist/party.js ADDED
@@ -0,0 +1,56 @@
1
+ export * from './party-baseline-attributes.js';
2
+
3
+ export function partyListParams(query) {
4
+ const { filter, fields, ...plain } = query;
5
+ const params = { ...plain };
6
+ for (const [key, condition] of Object.entries(filter ?? {})) {
7
+ if (condition === null || typeof condition !== 'object' || Array.isArray(condition)) {
8
+ params[`filter[${key}]`] = condition;
9
+ continue;
10
+ }
11
+ for (const [operator, value] of Object.entries(condition)) {
12
+ params[`filter[${key}][${operator}]`] = value;
13
+ }
14
+ }
15
+ if (fields !== undefined) {
16
+ params.fields = fields;
17
+ }
18
+ return params;
19
+ }
20
+ export function createPartyNamespace(http) {
21
+ const base = '/api/v1/party/parties';
22
+ return {
23
+
24
+ list: (query = {}) => http.get(base, { params: partyListParams(query) }),
25
+
26
+ get: (partyId) => http.get(`${base}/${partyId}`),
27
+
28
+ create: (input) => http.post(base, input),
29
+
30
+ update: (partyId, input) => http.put(`${base}/${partyId}`, input),
31
+
32
+ roles: Object.assign((partyId) => http.get(`${base}/${partyId}/roles`), {
33
+
34
+ setAttributes: (partyId, role, attributes) => http.patch(`${base}/${partyId}/roles/${role}/attributes`, {
35
+ attributes,
36
+ }),
37
+ }),
38
+
39
+ addRole: (partyId, role, startedAt) => http.post(`${base}/${partyId}/roles`, {
40
+ role,
41
+ ...(startedAt === undefined ? {} : { started_at: startedAt }),
42
+ }),
43
+
44
+ endRole: (partyId, role, endedAt) => http.delete(`${base}/${partyId}/roles/${role}`, { params: endedAt === undefined ? {} : { ended_at: endedAt } }),
45
+
46
+ link: (partyId, platformPersonId) => http.post(`${base}/${partyId}/link`, {
47
+ platform_person_id: platformPersonId,
48
+ }),
49
+ fields: {
50
+
51
+ schema: (appliesTo) => http.get('/api/v1/party/fields/schema', {
52
+ params: { applies_to: appliesTo },
53
+ }),
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,161 @@
1
+ /** GET /api/patient/me — the caller's own profile, from their clinic record. */
2
+ export interface PatientProfile {
3
+ person_id: string;
4
+ name: string;
5
+ email: string | null;
6
+ phone: string | null;
7
+ /** False when the clinic has no patient record for this person yet. */
8
+ has_record: boolean;
9
+ }
10
+ /** Minimal practitioner reference on a patient-facing record. */
11
+ export interface PatientPractitionerRef {
12
+ id: string;
13
+ display_name: string;
14
+ }
15
+ /** Minimal, bilingual service reference on a patient-facing appointment. */
16
+ export interface PatientSessionTypeRef {
17
+ id: string;
18
+ name_en: string | null;
19
+ name_ar: string | null;
20
+ }
21
+ export interface PatientAppointment {
22
+ id: string;
23
+ starts_at: string | null;
24
+ ends_at: string | null;
25
+ /** `booked | confirmed | in_progress | completed | cancelled`. */
26
+ status: string;
27
+ fee_amount: string | null;
28
+ currency_code: string | null;
29
+ practitioner: PatientPractitionerRef | null;
30
+ session_type: PatientSessionTypeRef | null;
31
+ }
32
+ /** GET /api/patient/appointments — the caller's sessions, split by time. */
33
+ export interface PatientAppointments {
34
+ upcoming: PatientAppointment[];
35
+ past: PatientAppointment[];
36
+ }
37
+ export interface PatientInvoice {
38
+ id: string;
39
+ invoice_number: string;
40
+ invoice_date: string | null;
41
+ due_date: string | null;
42
+ status: string;
43
+ total: string;
44
+ amount_paid: string;
45
+ amount_due: string;
46
+ currency_code: string | null;
47
+ }
48
+ /** Aggregate over the caller's open invoices. */
49
+ export interface PatientInvoiceSummary {
50
+ /** Sum of `amount_due` across confirmed/partially-paid invoices, 4dp string. */
51
+ outstanding_amount_due: string;
52
+ outstanding_count: number;
53
+ currency_code: string | null;
54
+ }
55
+ /** GET /api/patient/invoices — the caller's invoices + outstanding balance. */
56
+ export interface PatientInvoices {
57
+ invoices: PatientInvoice[];
58
+ summary: PatientInvoiceSummary;
59
+ }
60
+ export interface PatientTreatmentSession {
61
+ id: string;
62
+ starts_at: string | null;
63
+ status: string;
64
+ }
65
+ export interface PatientTreatmentPlan {
66
+ id: string;
67
+ title: string;
68
+ /** `active | completed | cancelled`. */
69
+ status: string;
70
+ description: string | null;
71
+ goals: string | null;
72
+ start_date: string | null;
73
+ end_date: string | null;
74
+ practitioner: PatientPractitionerRef | null;
75
+ sessions: PatientTreatmentSession[];
76
+ }
77
+ /** The patient-relevant slice of the clinic's reschedule/cancel policy (GET /api/patient/reschedule-policy). */
78
+ export interface PatientReschedulePolicy {
79
+ /** Whether the clinic lets patients reschedule/cancel their own appointments online. */
80
+ self_service: boolean;
81
+ /** Whether a patient change needs staff approval (currently directs them to the desk). */
82
+ requires_approval: boolean;
83
+ /** Hours of notice the clinic asks for; 0 = no window. */
84
+ notice_window_hours: number;
85
+ /** `advisory` (warn only) vs `blocked` (refuse) inside the window. */
86
+ notice_enforcement: 'advisory' | 'blocked';
87
+ }
88
+ export interface PatientClient {
89
+ /** GET /api/patient/me */
90
+ me: () => Promise<PatientProfile>;
91
+ /** The caller's own bookings-client ids, derived server-side from the token's person. */
92
+ clientIds: () => Promise<string[]>;
93
+ /** The caller's own home-exercise programmes, and marking one done for today. */
94
+ exercises: {
95
+ programs: (status?: 'active' | 'completed' | 'cancelled') => Promise<PatientExerciseProgram[]>;
96
+ markDone: (prescriptionId: string) => Promise<PatientExerciseCheckin>;
97
+ };
98
+ /** GET /api/patient/appointments */
99
+ appointments: () => Promise<PatientAppointments>;
100
+ /** GET /api/patient/invoices */
101
+ invoices: () => Promise<PatientInvoices>;
102
+ /** GET /api/patient/treatment-plan */
103
+ treatmentPlan: () => Promise<PatientTreatmentPlan[]>;
104
+ /** GET /api/patient/reschedule-policy — what self-service the clinic allows. */
105
+ reschedulePolicy: () => Promise<PatientReschedulePolicy>;
106
+ /** POST /api/patient/appointments/{sessionId}/rate — rate one of the caller's completed sessions. */
107
+ rateSession: (sessionId: string, score: number, comment?: string) => Promise<void>;
108
+ /** POST /api/patient/appointments/{sessionId}/reschedule — move one of the caller's own upcoming appointments. */
109
+ rescheduleAppointment: (sessionId: string, scheduledAtIso: string) => Promise<PatientAppointment>;
110
+ /** POST /api/patient/appointments/{sessionId}/cancel — cancel one of the caller's own upcoming appointments. */
111
+ cancelAppointment: (sessionId: string, reason?: string) => Promise<PatientAppointment>;
112
+ }
113
+ /** Config for the patient client — keyed by the mini-app identity token. */
114
+ export interface PatientClientConfig {
115
+ /** Base URL of the core monolith (or `''` for same-origin). No trailing slash. */
116
+ baseUrl: string;
117
+ /** Yields the mini-app identity token (the bearer). Sync or async. */
118
+ getToken: () => string | Promise<string>;
119
+ /** Injectable fetch (tests / Node < 18). Defaults to global `fetch`. */
120
+ fetch?: typeof fetch;
121
+ /** Extra headers merged into every request (e.g. `Accept-Language`). */
122
+ defaultHeaders?: Record<string, string> | (() => Record<string, string>);
123
+ }
124
+ /**
125
+ * Build the patient portal client. Every call attaches the identity token as the
126
+ * bearer and unwraps core's `{ data }` envelope so callers get the payload directly.
127
+ */
128
+ /** One prescribed exercise inside a home-exercise programme (mirrors the core prescription item). */
129
+ export interface PatientExerciseItem {
130
+ id: string;
131
+ exercise_name: string;
132
+ body_region: string | null;
133
+ sets: number | null;
134
+ reps: number | null;
135
+ hold_seconds: number | null;
136
+ frequency: string | null;
137
+ notes: string | null;
138
+ sort: number;
139
+ /** Optional media/how-to fields; core's patient items omit them today. */
140
+ video_url?: string | null;
141
+ image_url?: string | null;
142
+ instructions?: string | null;
143
+ }
144
+ /** A home-exercise programme: a header plus its prescribed exercises. */
145
+ export interface PatientExerciseProgram {
146
+ id: string;
147
+ title: string;
148
+ status: 'active' | 'completed' | 'cancelled';
149
+ notes: string | null;
150
+ assigned_at: string | null;
151
+ items: PatientExerciseItem[];
152
+ /** True once the caller has marked this programme done today. */
153
+ checked_in_today: boolean;
154
+ }
155
+ /** A recorded adherence check-in. */
156
+ export interface PatientExerciseCheckin {
157
+ id: string;
158
+ exercise_prescription_id: string;
159
+ checkin_date: string | null;
160
+ }
161
+ export declare function createPatientClient(config: PatientClientConfig): PatientClient;
@@ -0,0 +1,45 @@
1
+
2
+
3
+ import { createHttp } from './http.js';
4
+ export function createPatientClient(config) {
5
+ const httpConfig = {
6
+ baseUrl: config.baseUrl,
7
+ getToken: config.getToken,
8
+ fetch: config.fetch,
9
+ defaultHeaders: config.defaultHeaders,
10
+ };
11
+ const http = createHttp(httpConfig);
12
+ return {
13
+ me: () => http.get('/api/patient/me').then((r) => r.data),
14
+
15
+ clientIds: () => http
16
+ .get('/api/patient/me')
17
+ .then((r) => r.data.client_ids ?? []),
18
+
19
+ exercises: {
20
+
21
+ programs: (status = 'active') => http
22
+ .get('/api/patient/exercise-prescriptions', {
23
+ params: { status },
24
+ })
25
+ .then((r) => r.data),
26
+
27
+ markDone: (prescriptionId) => http
28
+ .post(`/api/patient/exercise-prescriptions/${prescriptionId}/checkins`, {})
29
+ .then((r) => r.data),
30
+ },
31
+ appointments: () => http.get('/api/patient/appointments').then((r) => r.data),
32
+ invoices: () => http.get('/api/patient/invoices').then((r) => r.data),
33
+ treatmentPlan: () => http.get('/api/patient/treatment-plan').then((r) => r.data),
34
+ reschedulePolicy: () => http.get('/api/patient/reschedule-policy').then((r) => r.data),
35
+ rateSession: (sessionId, score, comment) => http.post(`/api/patient/appointments/${sessionId}/rate`, { score, comment }).then(() => undefined),
36
+ rescheduleAppointment: (sessionId, scheduledAtIso) => http
37
+ .post(`/api/patient/appointments/${sessionId}/reschedule`, {
38
+ scheduled_at: scheduledAtIso,
39
+ })
40
+ .then((r) => r.data),
41
+ cancelAppointment: (sessionId, reason) => http
42
+ .post(`/api/patient/appointments/${sessionId}/cancel`, { reason })
43
+ .then((r) => r.data),
44
+ };
45
+ }