@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,40 @@
1
+ import { personDomainRequest, } from './actors.js';
2
+ import { listQueryParams } from './list-query.js';
3
+
4
+ export const MODERATION_LEGAL_REASONS = ['child_safety', 'violence_or_threat'];
5
+
6
+ export const MODERATION_NOTES_MAXIMUM = 1000;
7
+ export const MODERATION_STATEMENT_MAXIMUM = 2000;
8
+ const BASE = '/api/person';
9
+ export function createModerationNamespace(http) {
10
+ const read = (options, params) => personDomainRequest(options, false, params);
11
+ const write = (options) => personDomainRequest(options, true);
12
+ const id = (value) => encodeURIComponent(value);
13
+ return {
14
+
15
+ reasons: (subjectType, options) => http.get(`${BASE}/moderation/reasons`, read(options, { subject_type: subjectType })),
16
+
17
+ report: (input, options) => http.post(`${BASE}/reports`, input, write({ ...options, actingAs: null })),
18
+
19
+ myReports: (cursor, limit, options) => http.get(`${BASE}/reports`, read({ ...options, actingAs: null }, {
20
+ cursor: cursor ?? undefined,
21
+ limit,
22
+ })),
23
+
24
+ getReport: (reportId, options) => http.get(`${BASE}/reports/${id(reportId)}`, read({ ...options, actingAs: null })),
25
+
26
+ decision: (decisionId, options) => http.get(`${BASE}/moderation/decisions/${id(decisionId)}`, read(options)),
27
+
28
+ appeal: (decisionId, statement, options) => http.post(`${BASE}/moderation/decisions/${id(decisionId)}/appeals`, { statement }, write(options)),
29
+
30
+ getAppeal: (appealId, options) => http.get(`${BASE}/moderation/appeals/${id(appealId)}`, read({ ...options, actingAs: null })),
31
+
32
+ queue: (host, query = {}, options) => http.get(`${BASE}/moderation/queue`, read(options, { host, ...listQueryParams(query) })),
33
+
34
+ getCase: (host, caseId, options) => http.get(`${BASE}/moderation/cases/${id(caseId)}`, read(options, { host })),
35
+
36
+ decide: (host, caseId, input, options) => http.post(`${BASE}/moderation/cases/${id(caseId)}/decisions`, { ...input, host }, write(options)),
37
+
38
+ escalate: (host, caseId, reasonKey, options) => http.post(`${BASE}/moderation/cases/${id(caseId)}/escalations`, { host, reason_key: reasonKey }, write(options)),
39
+ };
40
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Parse a decimal-string money value into scaled bigint units (value × 10^4).
3
+ *
4
+ * Anything unparseable — text, two decimal points, exponent notation, an empty string —
5
+ * yields `0n` rather than throwing. That matters: the three vertical copies this replaces
6
+ * called `BigInt(whole)` directly, so a malformed value raised a SyntaxError and took down
7
+ * whichever page was summing the column.
8
+ *
9
+ * More than four decimal places are parsed at full precision and then rounded
10
+ * half-away-from-zero to four, so a stray fifth digit cannot bias every amount downward.
11
+ */
12
+ export declare function toScaledUnits(value: string | null | undefined): bigint;
13
+ /** Render scaled bigint units back to a decimal string with exactly four decimal places. */
14
+ export declare function fromScaledUnits(units: bigint): string;
15
+ /**
16
+ * Divide scaled units by a whole number, rounding HALF-AWAY-FROM-ZERO.
17
+ *
18
+ * Needed wherever a figure is normalised across a period — a yearly plan price spread over
19
+ * twelve months, a quarterly one over three. Plain bigint `/` TRUNCATES, so a 100.00 quarterly
20
+ * plan came out as 33.33 a month and the three months summed to 99.99 rather than 100.00.
21
+ *
22
+ * Unlike the private `roundedDivide` above, this one handles a NEGATIVE numerator, because a
23
+ * credit or a refund is a real input here and the sign is not tracked separately.
24
+ */
25
+ export declare function divideScaledUnits(units: bigint, divisor: bigint): bigint;
26
+ /** Exact sum of decimal-string money values → a fixed-4dp decimal string. */
27
+ export declare function sumMoney(values: readonly (string | null | undefined)[]): string;
28
+ /** True when two decimal-string money values are exactly equal at core's scale. */
29
+ export declare function moneyEquals(a: string | null | undefined, b: string | null | undefined): boolean;
30
+ /** True when a decimal-string money value is greater than zero. */
31
+ export declare function moneyIsPositive(value: string | null | undefined): boolean;
32
+ /**
33
+ * A numeric sort key for a decimal-string money value.
34
+ *
35
+ * This one goes through a float, and that is correct here and nowhere else: ordering tolerates
36
+ * the imprecision that summing and comparing do not. It parses EXACTLY first — the helper this
37
+ * replaces was `Number(value ?? 0) || 0`, a second parse that disagreed with the one used to
38
+ * sum and compare, so a value the sum accepted and the sort rejected sorted as zero and put
39
+ * the largest row at the bottom of an ascending column.
40
+ */
41
+ export declare function moneySort(value: string | null | undefined): number;
package/dist/money.js ADDED
@@ -0,0 +1,79 @@
1
+
2
+
3
+ const SCALE_DECIMAL_PLACES = 4;
4
+
5
+ const SCALE_FACTOR = 10000n;
6
+
7
+ function roundedDivide(nonNegativeNumerator, denominator) {
8
+ const quotient = nonNegativeNumerator / denominator;
9
+ const remainder = nonNegativeNumerator % denominator;
10
+ return remainder * 2n >= denominator ? quotient + 1n : quotient;
11
+ }
12
+
13
+ function powerOfTen(exponent) {
14
+ let result = 1n;
15
+ for (let step = 0; step < exponent; step += 1)
16
+ result *= 10n;
17
+ return result;
18
+ }
19
+
20
+ export function toScaledUnits(value) {
21
+ if (value === null || value === undefined)
22
+ return 0n;
23
+ const trimmed = String(value).trim();
24
+ if (trimmed === '')
25
+ return 0n;
26
+ const match = /^([+-]?)(\d*)(?:\.(\d+))?$/.exec(trimmed);
27
+ if (match === null)
28
+ return 0n;
29
+ const sign = match[1] === '-' ? -1n : 1n;
30
+ const integerDigits = match[2] ?? '';
31
+ const fractionDigits = match[3] ?? '';
32
+ if (integerDigits === '' && fractionDigits === '')
33
+ return 0n;
34
+ const integerPart = integerDigits === '' ? 0n : BigInt(integerDigits);
35
+ if (fractionDigits.length <= SCALE_DECIMAL_PLACES) {
36
+ const padded = fractionDigits.padEnd(SCALE_DECIMAL_PLACES, '0');
37
+ return sign * (integerPart * SCALE_FACTOR + (padded === '' ? 0n : BigInt(padded)));
38
+ }
39
+ const fullPrecision = integerPart * powerOfTen(fractionDigits.length) + BigInt(fractionDigits);
40
+ const extraPlaces = fractionDigits.length - SCALE_DECIMAL_PLACES;
41
+ return sign * roundedDivide(fullPrecision, powerOfTen(extraPlaces));
42
+ }
43
+
44
+ export function fromScaledUnits(units) {
45
+ const isNegative = units < 0n;
46
+ const magnitude = isNegative ? -units : units;
47
+ const fraction = (magnitude % SCALE_FACTOR).toString().padStart(SCALE_DECIMAL_PLACES, '0');
48
+ return `${isNegative ? '-' : ''}${(magnitude / SCALE_FACTOR).toString()}.${fraction}`;
49
+ }
50
+
51
+ export function divideScaledUnits(units, divisor) {
52
+ if (divisor === 0n)
53
+ return 0n;
54
+ const negative = (units < 0n) !== (divisor < 0n);
55
+ const magnitude = roundedDivide(units < 0n ? -units : units, divisor < 0n ? -divisor : divisor);
56
+ return negative ? -magnitude : magnitude;
57
+ }
58
+
59
+ export function sumMoney(values) {
60
+ let total = 0n;
61
+ for (const value of values)
62
+ total += toScaledUnits(value);
63
+ return fromScaledUnits(total);
64
+ }
65
+
66
+ export function moneyEquals(a, b) {
67
+ return toScaledUnits(a) === toScaledUnits(b);
68
+ }
69
+
70
+ export function moneyIsPositive(value) {
71
+ return toScaledUnits(value) > 0n;
72
+ }
73
+
74
+ export function moneySort(value) {
75
+ const units = toScaledUnits(value);
76
+ const whole = units / SCALE_FACTOR;
77
+ const fraction = units % SCALE_FACTOR;
78
+ return Number(whole) + Number(fraction) / Number(SCALE_FACTOR);
79
+ }
@@ -0,0 +1,266 @@
1
+ import type { Http } from './http.js';
2
+ import type { BilingualText, PersonDomainCallOptions, PersonDomainCursorPage, PersonDomainEnvelope } from './actors.js';
3
+ import { type OnBehalfCallOptions } from './delegations.js';
4
+ /** Why an app may use a category (`DataPurpose`). */
5
+ export type MyDataPurpose = 'service_delivery' | 'communication' | 'billing' | 'legal_obligation' | 'safety' | 'personalisation' | 'analytics' | 'advertising' | (string & {});
6
+ /** One app's standing with Nuwah, per measure. `frozen` and `terminated` are shown, never hidden. */
7
+ export type MyDataStandingState = 'active' | 'frozen' | 'terminated' | (string & {});
8
+ export interface MyDataStanding {
9
+ app: MyDataStandingState;
10
+ account: MyDataStandingState;
11
+ data_access: MyDataStandingState;
12
+ }
13
+ export type MyDataAppKind = 'first_party_vertical' | 'third_party' | 'host_app' | 'mini_app' | (string & {});
14
+ export interface MyDataAppSummary {
15
+ id: string;
16
+ key: string | null;
17
+ kind: MyDataAppKind | null;
18
+ name: BilingualText;
19
+ /** The business's optional public values statement (shown per `standards.values_statement_on_consent`). */
20
+ values_statement: BilingualText | null;
21
+ /** False when the registry no longer describes the app (render "an app no longer registered"). */
22
+ known: boolean;
23
+ }
24
+ /** What an app keeps after a revoke, as it declared it (design §9.2). */
25
+ export interface MyDataKeptUnderLaw {
26
+ category: string;
27
+ what_kept: BilingualText;
28
+ basis: 'legal_obligation' | 'ongoing_service' | 'contract' | (string & {});
29
+ max_days: number | null;
30
+ }
31
+ export type MyDataGrantBasis = 'explicit' | 'grandfathered' | 'on_behalf' | (string & {});
32
+ export type MyDataRevokeReason = 'person' | 'guardian' | 'app_terminated' | 'majority_review' | 'expiry' | 'replaced' | 'erasure' | (string & {});
33
+ /** One grant row as the ledger stores it (`GrantRecordData`). */
34
+ export interface MyDataGrantRecord {
35
+ id: string;
36
+ person_id: string;
37
+ app_id: string;
38
+ /** Set when the grant is to ONE business on the app (per-business recipient); null = the whole app. */
39
+ recipient_tenant_org_id: string | null;
40
+ category: string;
41
+ purposes: MyDataPurpose[];
42
+ granted_at: string;
43
+ expires_at: string | null;
44
+ revoked_at: string | null;
45
+ revoked_reason: MyDataRevokeReason | null;
46
+ basis: MyDataGrantBasis;
47
+ /** The guardian, when `basis` is `on_behalf`. */
48
+ granted_by_person_id: string | null;
49
+ request_version: number;
50
+ single_use: boolean;
51
+ consumed_at: string | null;
52
+ consent_request_id: string | null;
53
+ /** Made on the person's behalf before they came of age, awaiting their confirm or revoke. */
54
+ under_review: boolean;
55
+ review_due_at: string | null;
56
+ confirmed_at: string | null;
57
+ }
58
+ /** A live grant on the "My data" screen: the record plus what the screen needs to say it. */
59
+ export interface MyDataGrant extends MyDataGrantRecord {
60
+ category_label: BilingualText;
61
+ sensitive: boolean;
62
+ /** The receiving business's name, when per-business and the person may see it. */
63
+ recipient_name: BilingualText | null;
64
+ last_access_at: string | null;
65
+ }
66
+ /** One app on "My data and who has it". */
67
+ export interface MyDataApp {
68
+ app: MyDataAppSummary;
69
+ standing: MyDataStanding;
70
+ grants: MyDataGrant[];
71
+ kept_under_law: MyDataKeptUnderLaw[];
72
+ last_access_at: string | null;
73
+ /** Nothing live any more; listed for what it keeps. */
74
+ former: boolean;
75
+ }
76
+ export type MyDataChannel = 'in_process' | 'http' | 'service' | 'mini_app_token' | 'webhook' | 'case_review' | 'self' | (string & {});
77
+ export type MyDataAccessOutcome = 'allowed' | 'partial' | 'withheld' | 'report_only' | (string & {});
78
+ export type MyDataWithheldReason = 'unknown_app' | 'frozen' | 'scope_missing' | 'category_undeclared' | 'purpose_undeclared' | 'no_grant' | 'expired' | 'revoked' | 'minor_guardian_required' | 'report_only_allowed' | 'purpose_not_granted' | 'recipient_unavailable' | 'subject_unavailable' | 'case_not_authorised' | 'not_self' | (string & {});
79
+ /** One read of the person's data, as the person sees it. Never names another person. */
80
+ export interface MyDataAccessEntry {
81
+ id: string;
82
+ accessed_at: string;
83
+ /** Null for a case review (an investigation, not an app). */
84
+ app_id: string | null;
85
+ tenant_org_id: string | null;
86
+ channel: MyDataChannel | null;
87
+ case_review: boolean;
88
+ requested_categories: string[];
89
+ disclosed_categories: string[];
90
+ purpose: MyDataPurpose | null;
91
+ outcome: MyDataAccessOutcome;
92
+ /** category → why it was not disclosed. */
93
+ withheld: Record<string, MyDataWithheldReason>;
94
+ /** The read happened while a delegate acted for the person. */
95
+ acted_by_delegate: boolean;
96
+ /** The app's name, frozen or terminated apps included; "A removed app" when gone; null for a case review. */
97
+ app_name: BilingualText | null;
98
+ /** The registry no longer describes the app (`app_name` is then "A removed app"). */
99
+ app_removed: boolean;
100
+ }
101
+ /** A consent request waiting for my answer, as the My data list shows it. */
102
+ export interface MyDataPendingConsentRequest {
103
+ id: string;
104
+ app: {
105
+ id: string;
106
+ name: BilingualText;
107
+ };
108
+ tenant_org_id: string | null;
109
+ categories: {
110
+ category: string;
111
+ purposes: MyDataPurpose[];
112
+ sensitive: boolean;
113
+ }[];
114
+ expires_at: string;
115
+ created_at: string;
116
+ /** Where the person answers it: `/me/data-access/consent/<id>`. */
117
+ consent_url: string;
118
+ }
119
+ /** What a person asks to share with an app they use (a mini-app's first launch, "share more"). */
120
+ export interface MyDataConsentAsk {
121
+ category: string;
122
+ purposes: MyDataPurpose[];
123
+ duration_days?: number | null;
124
+ }
125
+ export type MyDataRecipientMode = 'whole_app' | 'per_business';
126
+ /** Who receives one category: the whole app, or one business on it. */
127
+ export interface MyDataRecipient {
128
+ mode: MyDataRecipientMode;
129
+ tenant_org_id: string | null;
130
+ /** The business, when per-business and describable to the person. */
131
+ name: BilingualText | null;
132
+ }
133
+ export interface MyDataConsentCategory {
134
+ category: string;
135
+ label: BilingualText;
136
+ /** Sensitive categories need their OWN `confirm_sensitive: true`; never one tap. */
137
+ sensitive: boolean;
138
+ purposes: {
139
+ purpose: MyDataPurpose;
140
+ label: BilingualText;
141
+ }[];
142
+ /** How long the app asks to keep access; null = until revoked. */
143
+ duration_days: number | null;
144
+ retention_days: number | null;
145
+ recipient: MyDataRecipient;
146
+ already_granted: boolean;
147
+ kept_under_law: MyDataKeptUnderLaw[];
148
+ }
149
+ export type MyDataConsentRequestState = 'pending' | 'decided' | 'expired' | (string & {});
150
+ /** A consent request as the person's consent screen shows it. Sensitive categories come first. */
151
+ export interface MyDataConsentRequest {
152
+ id: string;
153
+ state: MyDataConsentRequestState;
154
+ expires_at: string;
155
+ return_url: string | null;
156
+ /** category → granted, once answered. */
157
+ decision: Record<string, boolean> | null;
158
+ decided_at: string | null;
159
+ app: MyDataAppSummary & {
160
+ standing: MyDataStanding & {
161
+ permits_data_access: boolean;
162
+ };
163
+ };
164
+ business: {
165
+ tenant_org_id: string;
166
+ name: BilingualText | null;
167
+ } | null;
168
+ categories: MyDataConsentCategory[];
169
+ }
170
+ /** One answer per category. A category not named is declined. */
171
+ export interface MyDataConsentDecision {
172
+ category: string;
173
+ granted: boolean;
174
+ /** Required (true) to grant a sensitive category. */
175
+ confirm_sensitive?: boolean;
176
+ /** Narrow what was asked (fine-grained control). */
177
+ purposes?: MyDataPurpose[] | null;
178
+ /** End the grant earlier than the app asked (ISO 8601, in the future). */
179
+ expires_at?: string | null;
180
+ }
181
+ export interface MyDataConsentOutcome {
182
+ request: MyDataConsentRequest;
183
+ grants: MyDataGrantRecord[];
184
+ /** The same answer sent again (a double tap); nothing new was written. */
185
+ replayed: boolean;
186
+ }
187
+ /** One declared data category, as every person-facing screen names it. */
188
+ export interface MyDataCategory {
189
+ key: string;
190
+ label: BilingualText;
191
+ sensitivity: 'ordinary' | 'sensitive';
192
+ parent: string | null;
193
+ description: BilingualText | null;
194
+ }
195
+ /** One step of the enforcement ladder, as the public record shows it. */
196
+ export interface MyDataStandingMeasure {
197
+ id: string;
198
+ kind: 'warning' | 'data_access_freeze' | 'account_freeze' | 'app_freeze' | 'termination' | (string & {});
199
+ state: 'active' | 'lifted' | 'overturned_on_appeal' | 'completed' | (string & {});
200
+ standard: BilingualText | null;
201
+ summary: BilingualText | null;
202
+ interim: boolean;
203
+ started_at: string;
204
+ deadline_at: string | null;
205
+ ended_at: string | null;
206
+ }
207
+ export interface MyDataStandingRecord {
208
+ standing: MyDataStanding;
209
+ standards_version: string | null;
210
+ accepted_at: string | null;
211
+ findings_last_twelve_months: number;
212
+ open_case: boolean;
213
+ measures: MyDataStandingMeasure[];
214
+ }
215
+ export declare function createMyDataNamespace(http: Http): {
216
+ /** An app's public standing record: the same for everyone, no person data. 404 for an unknown app. */
217
+ standing: (appId: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<MyDataStandingRecord>>;
218
+ /** The declared category catalogue (core's and every vertical's). Show `label`, never `key`. */
219
+ categories: (options?: OnBehalfCallOptions) => Promise<{
220
+ data: MyDataCategory[];
221
+ }>;
222
+ /** Every app that holds my data (live first, then former apps that keep something), by name. */
223
+ apps: (options?: OnBehalfCallOptions) => Promise<{
224
+ data: MyDataApp[];
225
+ }>;
226
+ /** What one app holds — including one I revoked everything from. */
227
+ app: (appId: string, options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataApp>>;
228
+ /** Revoke one grant. Immediate: the app's next read of it is withheld. Idempotent. */
229
+ revoke: (grantId: string, options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataGrantRecord>>;
230
+ /** Revoke every category on every business of one app. What it keeps under law is not revoked here. */
231
+ revokeAll: (appId: string, options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<{
232
+ revoked: number;
233
+ }>>;
234
+ /** Confirm a grant made for me before I came of age. The person only; a delegate is refused. */
235
+ confirm: (grantId: string, options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataGrantRecord>>;
236
+ /** Grants made on my behalf that await my confirm or revoke (after a guardianship ended at majority). */
237
+ review: (options?: OnBehalfCallOptions) => Promise<{
238
+ data: MyDataGrantRecord[];
239
+ }>;
240
+ /** What apps read about me, newest first. Follow `next_cursor` until null. */
241
+ history: (query?: {
242
+ app?: string | null;
243
+ cursor?: string | null;
244
+ limit?: number;
245
+ }, options?: OnBehalfCallOptions) => Promise<PersonDomainCursorPage<MyDataAccessEntry>>;
246
+ /** Consent requests waiting for my answer, newest first. Follow `next_cursor` until null. */
247
+ pendingConsentRequests: (query?: {
248
+ cursor?: string | null;
249
+ limit?: number;
250
+ }, options?: OnBehalfCallOptions) => Promise<PersonDomainCursorPage<MyDataPendingConsentRequest>>;
251
+ /**
252
+ * Open a consent request for an app I use (only categories approved for it, with purposes it
253
+ * declared). Answer it at the returned `consent_url`; nothing is granted until then.
254
+ */
255
+ openConsentRequest: (appId: string, categories: MyDataConsentAsk[], options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataConsentRequest & {
256
+ consent_url: string;
257
+ }>>;
258
+ /** The consent request an app sent me to (`/me/data-access/consent/<id>`). */
259
+ consentRequest: (requestId: string, options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataConsentRequest>>;
260
+ /**
261
+ * Answer per category. 201 on a new answer, 200 when the same answer is replayed. A sensitive
262
+ * category granted without `confirm_sensitive: true` is refused (422).
263
+ */
264
+ decide: (requestId: string, decisions: MyDataConsentDecision[], options?: OnBehalfCallOptions) => Promise<PersonDomainEnvelope<MyDataConsentOutcome>>;
265
+ };
266
+ export type MyDataNamespace = ReturnType<typeof createMyDataNamespace>;
@@ -0,0 +1,32 @@
1
+ import { onBehalfRequest } from './delegations.js';
2
+ const BASE = '/api/person/data-access';
3
+ export function createMyDataNamespace(http) {
4
+ return {
5
+
6
+ standing: (appId, options) => http.get(`/api/person/apps/${encodeURIComponent(appId)}/standing`, onBehalfRequest(options)),
7
+
8
+ categories: (options) => http.get(`${BASE}/categories`, onBehalfRequest(options)),
9
+
10
+ apps: (options) => http.get(`${BASE}/apps`, onBehalfRequest(options)),
11
+
12
+ app: (appId, options) => http.get(`${BASE}/apps/${appId}`, onBehalfRequest(options)),
13
+
14
+ revoke: (grantId, options) => http.delete(`${BASE}/grants/${grantId}`, onBehalfRequest(options, true)),
15
+
16
+ revokeAll: (appId, options) => http.post(`${BASE}/apps/${appId}/revoke-all`, undefined, onBehalfRequest(options, true)),
17
+
18
+ confirm: (grantId, options) => http.post(`${BASE}/grants/${grantId}/confirm`, undefined, onBehalfRequest(options, true)),
19
+
20
+ review: (options) => http.get(`${BASE}/review`, onBehalfRequest(options)),
21
+
22
+ history: (query = {}, options) => http.get(`${BASE}/history`, onBehalfRequest(options, false, Object.fromEntries(Object.entries(query).filter(([, value]) => value != null)))),
23
+
24
+ pendingConsentRequests: (query = {}, options) => http.get(`${BASE}/consent-requests`, onBehalfRequest(options, false, Object.fromEntries(Object.entries(query).filter(([, value]) => value != null)))),
25
+
26
+ openConsentRequest: (appId, categories, options) => http.post(`${BASE}/consent-requests`, { app_id: appId, categories }, onBehalfRequest(options, true)),
27
+
28
+ consentRequest: (requestId, options) => http.get(`${BASE}/consent-requests/${requestId}`, onBehalfRequest(options)),
29
+
30
+ decide: (requestId, decisions, options) => http.post(`${BASE}/consent-requests/${requestId}/decision`, { decisions }, onBehalfRequest(options, true)),
31
+ };
32
+ }
@@ -0,0 +1,14 @@
1
+ /** A record named in two languages, either of which may be missing. */
2
+ export interface NamedInTwoLanguages {
3
+ name_en?: string | null;
4
+ name_ar?: string | null;
5
+ }
6
+ /** True when the locale (`ar`, `ar-JO`, …) reads Arabic. */
7
+ export declare function readsArabic(locale: string | null | undefined): boolean;
8
+ /**
9
+ * The value in the reader's language, else the other one, else ''. Blank strings count as
10
+ * missing, the way core's CHECK constraint counts them.
11
+ */
12
+ export declare function pickInLanguage(english: string | null | undefined, arabic: string | null | undefined, locale: string | null | undefined): string;
13
+ /** A record's name in the reader's language, falling back to the other language, else ''. */
14
+ export declare function pickName(record: NamedInTwoLanguages | null | undefined, locale: string | null | undefined): string;
package/dist/names.js ADDED
@@ -0,0 +1,17 @@
1
+
2
+
3
+ export function readsArabic(locale) {
4
+ return (locale ?? '').toLowerCase().startsWith('ar');
5
+ }
6
+
7
+ export function pickInLanguage(english, arabic, locale) {
8
+ const englishValue = (english ?? '').trim();
9
+ const arabicValue = (arabic ?? '').trim();
10
+ return readsArabic(locale) ? arabicValue || englishValue : englishValue || arabicValue;
11
+ }
12
+
13
+ export function pickName(record, locale) {
14
+ if (!record)
15
+ return '';
16
+ return pickInLanguage(record.name_en, record.name_ar, locale);
17
+ }