@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,212 @@
1
+ import type { Http } from './http.js';
2
+ import type { PersonDataWebhookEvent } from './person-data-webhooks.js';
3
+ /** The hard ceiling of design §8.3: what an app read may live at most five minutes. */
4
+ export declare const PERSON_DATA_MAXIMUM_CACHE_SECONDS = 300;
5
+ export type PersonDataPurpose = 'service_delivery' | 'communication' | 'billing' | 'legal_obligation' | 'safety' | 'personalisation' | 'analytics' | 'advertising';
6
+ /** Why one category of one person was not disclosed. Stable keys. */
7
+ export type PersonDataWithheldReason = 'unknown_app' | 'frozen' | 'scope_missing' | 'category_undeclared' | 'purpose_undeclared' | 'no_grant' | 'expired' | 'revoked' | 'minor_guardian_required' | 'purpose_not_granted' | 'recipient_unavailable' | 'subject_unavailable' | 'case_not_authorised' | 'not_self';
8
+ export interface PersonDataReadInput {
9
+ /** The ids this app knows the persons by (platform ids for first-party apps, pairwise otherwise). At most 200. */
10
+ personIds: string[];
11
+ /** Data category keys, e.g. `public_profile`, `contact`, `health`. */
12
+ categories: string[];
13
+ purpose: PersonDataPurpose;
14
+ /** Optional `<schema>.<table>.<column>` list; omitted = every readable field of the categories. */
15
+ fields?: string[];
16
+ }
17
+ export interface PersonDataSubject {
18
+ person_id: string;
19
+ /** The categories disclosed for this person. */
20
+ categories: string[];
21
+ /** `<schema>.<table>.<column>` → value. May be empty when a category has no reader yet. */
22
+ fields: Record<string, unknown>;
23
+ }
24
+ export interface PersonDataReadAnswer {
25
+ data: PersonDataSubject[];
26
+ /** person id → category → reason, for every requested pair that was not disclosed. */
27
+ withheld: Record<string, Record<string, PersonDataWithheldReason>>;
28
+ meta: {
29
+ /** How long this answer may be kept, at most 300. Zero: not past this call. */
30
+ cache_seconds: number;
31
+ /** When what was read must be gone. */
32
+ expires_at: string;
33
+ unclassified_fields: string[];
34
+ unreadable_fields: string[];
35
+ };
36
+ }
37
+ export interface PersonDataConsentCategory {
38
+ category: string;
39
+ purposes: PersonDataPurpose[];
40
+ duration_days?: number | null;
41
+ }
42
+ export interface PersonDataConsentRequest {
43
+ id: string;
44
+ state: 'pending' | 'decided' | 'expired' | 'cancelled' | string;
45
+ categories: Array<{
46
+ category: string;
47
+ purposes: PersonDataPurpose[];
48
+ duration_days: number | null;
49
+ retention_days: number | null;
50
+ }>;
51
+ /** Named only once the person answered. */
52
+ person_id: string | null;
53
+ /** category → granted, once answered. */
54
+ decision: Record<string, boolean> | null;
55
+ decided_at: string | null;
56
+ expires_at: string;
57
+ return_url: string | null;
58
+ /** The path in Nuwah's own consent screen (person app) to send the person to. */
59
+ consent_url: string;
60
+ created_at: string;
61
+ }
62
+ export interface PersonDataConsentPrompt {
63
+ request: PersonDataConsentRequest;
64
+ /** Open in a browser, relative to the person app's origin. */
65
+ consentPath: string;
66
+ /** Inside the Nuwah host (embedded mini-app or vertical): call the host bridge with this. */
67
+ bridgeCall: {
68
+ method: 'requestData';
69
+ request_id: string;
70
+ };
71
+ }
72
+ export interface PersonDataProposalInput {
73
+ personId: string;
74
+ /** A declared vault entry type, e.g. `vault.contact_phone`. */
75
+ typeKey: string;
76
+ attributes: Record<string, unknown>;
77
+ /** The business's OWN record this value rests on. Its organisation is the calling business. */
78
+ evidence: {
79
+ type: string;
80
+ id: string;
81
+ };
82
+ targetEntryId?: string | null;
83
+ /**
84
+ * The business's own documents for this value (a receipt, a warranty card), at most 10. Stage
85
+ * each with `stageAttachment` first and pass its token. The vault keeps a pointer, never the
86
+ * bytes, and shows the person a file only once its virus scan came back clean.
87
+ */
88
+ attachments?: PersonDataProposalAttachment[];
89
+ }
90
+ export interface PersonDataProposalAttachment {
91
+ /** The `token` `stageAttachment` answered. */
92
+ token: string;
93
+ /** What the person sees, in both languages, at most 120 characters each. */
94
+ label: {
95
+ en: string;
96
+ ar: string;
97
+ };
98
+ }
99
+ /** A staged proposal attachment. Name it in a proposal before `expiresAt`, or stage it again. */
100
+ export interface PersonDataStagedAttachment {
101
+ token: string;
102
+ /** A preview URL, or null while the file is not servable yet. */
103
+ url: string | null;
104
+ filename: string;
105
+ size: number;
106
+ mimeType: string | null;
107
+ expiresAt: string;
108
+ }
109
+ export interface PersonDataProposalOutcome {
110
+ status: 'created' | 'already_pending' | 'already_current';
111
+ proposal_id: string | null;
112
+ }
113
+ export interface PersonDataMyApp {
114
+ app_id: string;
115
+ app_key: string;
116
+ kind: 'first_party_vertical' | 'third_party' | 'host_app' | 'mini_app' | string;
117
+ name: {
118
+ en: string;
119
+ ar: string;
120
+ } | null;
121
+ status: string | null;
122
+ values_statement: {
123
+ en: string;
124
+ ar: string;
125
+ } | null;
126
+ approved_categories: string[];
127
+ requests_version: number;
128
+ requests: Array<{
129
+ category: string;
130
+ purpose: PersonDataPurpose;
131
+ recipient_mode: string | null;
132
+ requires_evidenced: boolean;
133
+ retention_days: number | null;
134
+ }>;
135
+ may_propose: boolean;
136
+ standing: {
137
+ app: string;
138
+ developer_account: string;
139
+ data_access: string;
140
+ business_account: string | null;
141
+ business_data_access: string | null;
142
+ may_read_person_data: boolean;
143
+ case_reference: string | null;
144
+ };
145
+ token_scopes: string[];
146
+ subject_identifiers: 'global' | 'pairwise';
147
+ business_org_id: string | null;
148
+ max_cache_seconds: number;
149
+ }
150
+ export interface PersonDataCallOptions {
151
+ /** Writes only. Pass the SAME key when retrying the same intent. */
152
+ idempotencyKey?: string;
153
+ signal?: AbortSignal;
154
+ }
155
+ export declare function createPersonDataNamespace(http: Http): {
156
+ /** Read through the gate. A partial grant answers with `withheld`, never an error. */
157
+ read: (input: PersonDataReadInput, options?: PersonDataCallOptions) => Promise<PersonDataReadAnswer>;
158
+ /**
159
+ * Ask a person for data. The person answers in Nuwah's own consent screen, never in yours:
160
+ * send them to `consentPath`, or inside the Nuwah host call the bridge with `bridgeCall`.
161
+ */
162
+ requestConsent: (input: {
163
+ categories: PersonDataConsentCategory[];
164
+ personId?: string | null;
165
+ returnUrl?: string | null;
166
+ }, options?: PersonDataCallOptions) => Promise<PersonDataConsentPrompt>;
167
+ /** The outcome of a consent request this app made. */
168
+ consentRequest: (requestId: string, options?: PersonDataCallOptions) => Promise<{
169
+ data: PersonDataConsentRequest;
170
+ }>;
171
+ /** Propose a value for a person's vault; the person accepts or declines. Needs a business token. */
172
+ propose: (input: PersonDataProposalInput, options?: PersonDataCallOptions) => Promise<{
173
+ data: PersonDataProposalOutcome;
174
+ }>;
175
+ stageAttachment: (file: Blob, fileName: string, options?: PersonDataCallOptions) => Promise<PersonDataStagedAttachment>;
176
+ /** Withdraw a staged attachment that no proposal will use. */
177
+ cancelStagedAttachment: (token: string, options?: PersonDataCallOptions) => Promise<void>;
178
+ /** This app's registration, standing and categories, as the gate sees it. */
179
+ myApp: (options?: PersonDataCallOptions) => Promise<{
180
+ data: PersonDataMyApp;
181
+ }>;
182
+ };
183
+ export type PersonDataNamespace = ReturnType<typeof createPersonDataNamespace>;
184
+ export interface GatedCacheOptions {
185
+ /** How long an entry may live. Clamped to 0..300 — five minutes is the rule, not a default. */
186
+ ttlSeconds: number;
187
+ /** Injectable clock (milliseconds), for tests. */
188
+ now?: () => number;
189
+ /** The most entries kept; the oldest go first. Default 5,000. */
190
+ maximumEntries?: number;
191
+ }
192
+ /**
193
+ * An IN-MEMORY cache of gated reads that can never outlive five minutes, nor the expiry core put
194
+ * on the answer, and that purges on revoke and freeze. It is process memory only: never write
195
+ * its contents to a database, a file, a log or a shared cache — that would be a copy of the
196
+ * person's data, which the platform's terms forbid.
197
+ */
198
+ export declare function createGatedCache(options: GatedCacheOptions): {
199
+ /** The effective lifetime, after the clamp. */
200
+ ttlSeconds: number;
201
+ get: (input: PersonDataReadInput) => PersonDataReadAnswer | undefined;
202
+ set: (input: PersonDataReadInput, answer: PersonDataReadAnswer) => void;
203
+ /** Read through the cache: a live entry answers, otherwise core is asked and the answer kept. */
204
+ read: (personData: PersonDataNamespace, input: PersonDataReadInput, callOptions?: PersonDataCallOptions) => Promise<PersonDataReadAnswer>;
205
+ purgePerson: (personId: string) => number;
206
+ purgeAll: () => number;
207
+ /** Act on a verified webhook: what must be forgotten now. Returns how many entries were purged. */
208
+ handle: (event: PersonDataWebhookEvent) => number;
209
+ /** Live entries, after dropping the expired ones. */
210
+ size: () => number;
211
+ };
212
+ export type GatedCache = ReturnType<typeof createGatedCache>;
@@ -0,0 +1,162 @@
1
+ import { newIdempotencyKey } from './actors.js';
2
+ const BASE = '/api/person-data';
3
+
4
+ export const PERSON_DATA_MAXIMUM_CACHE_SECONDS = 300;
5
+ function callOptions(options = {}, write = false) {
6
+ return {
7
+ headers: {
8
+ Accept: 'application/vnd.nuwah.v1+json',
9
+ ...(write ? { 'Idempotency-Key': options.idempotencyKey ?? newIdempotencyKey() } : {}),
10
+ },
11
+ ...(options.signal ? { signal: options.signal } : {}),
12
+ };
13
+ }
14
+ export function createPersonDataNamespace(http) {
15
+ return {
16
+
17
+ read: (input, options) => http.post(`${BASE}/read`, {
18
+ person_ids: input.personIds,
19
+ categories: input.categories,
20
+ purpose: input.purpose,
21
+ ...(input.fields ? { fields: input.fields } : {}),
22
+ }, callOptions(options)),
23
+
24
+ requestConsent: async (input, options) => {
25
+ const answer = await http.post(`${BASE}/consent-requests`, {
26
+ categories: input.categories,
27
+ ...(input.personId ? { person_id: input.personId } : {}),
28
+ ...(input.returnUrl ? { return_url: input.returnUrl } : {}),
29
+ }, callOptions(options, true));
30
+ return {
31
+ request: answer.data,
32
+ consentPath: answer.data.consent_url,
33
+ bridgeCall: { method: 'requestData', request_id: answer.data.id },
34
+ };
35
+ },
36
+
37
+ consentRequest: (requestId, options) => http.get(`${BASE}/consent-requests/${encodeURIComponent(requestId)}`, callOptions(options)),
38
+
39
+ propose: (input, options) => http.post(`${BASE}/proposals`, {
40
+ person_id: input.personId,
41
+ type_key: input.typeKey,
42
+ attributes: input.attributes,
43
+ evidence: input.evidence,
44
+ ...(input.targetEntryId ? { target_entry_id: input.targetEntryId } : {}),
45
+ ...(input.attachments && input.attachments.length > 0
46
+ ? { attachments: input.attachments.map((attachment) => ({ token: attachment.token, label: attachment.label })) }
47
+ : {}),
48
+ }, callOptions(options, true)),
49
+
50
+ stageAttachment: (file, fileName, options) => {
51
+ const form = new FormData();
52
+ form.append('file', file, fileName);
53
+ return http.post(`${BASE}/proposal-attachments/upload-temp`, form, callOptions(options));
54
+ },
55
+
56
+ cancelStagedAttachment: (token, options) => http.delete(`${BASE}/proposal-attachments/temp/${encodeURIComponent(token)}`, callOptions(options)),
57
+
58
+ myApp: (options) => http.get(`${BASE}/apps/me`, callOptions(options)),
59
+ };
60
+ }
61
+
62
+ export function createGatedCache(options) {
63
+ const ttlSeconds = Math.max(0, Math.min(PERSON_DATA_MAXIMUM_CACHE_SECONDS, Math.floor(Number(options.ttlSeconds) || 0)));
64
+ const now = options.now ?? (() => Date.now());
65
+ const maximumEntries = Math.max(1, options.maximumEntries ?? 5000);
66
+ const entries = new Map();
67
+ const keyFor = (input) => JSON.stringify([
68
+ [...input.personIds].map((id) => id.toLowerCase()).sort(),
69
+ [...input.categories].sort(),
70
+ input.purpose,
71
+ input.fields ? [...input.fields].sort() : null,
72
+ ]);
73
+ const sweep = () => {
74
+ const at = now();
75
+ for (const [key, entry] of entries)
76
+ if (entry.expiresAtMilliseconds <= at)
77
+ entries.delete(key);
78
+ };
79
+ const store = (input, answer) => {
80
+ const at = now();
81
+ const allowedSeconds = Math.min(ttlSeconds, Math.max(0, Number(answer.meta?.cache_seconds) || 0));
82
+ const coreExpiry = Date.parse(answer.meta?.expires_at ?? '');
83
+ const expiresAtMilliseconds = Math.min(at + allowedSeconds * 1000, Number.isFinite(coreExpiry) ? coreExpiry : at);
84
+ if (expiresAtMilliseconds <= at)
85
+ return;
86
+ if (entries.size >= maximumEntries) {
87
+ const oldest = entries.keys().next().value;
88
+ if (oldest !== undefined)
89
+ entries.delete(oldest);
90
+ }
91
+ entries.set(keyFor(input), {
92
+ value: answer,
93
+ personIds: input.personIds.map((id) => id.toLowerCase()),
94
+ expiresAtMilliseconds,
95
+ });
96
+ };
97
+ const lookup = (input) => {
98
+ const key = keyFor(input);
99
+ const entry = entries.get(key);
100
+ if (!entry)
101
+ return undefined;
102
+ if (entry.expiresAtMilliseconds <= now()) {
103
+ entries.delete(key);
104
+ return undefined;
105
+ }
106
+ return entry.value;
107
+ };
108
+ const purgePerson = (personId) => {
109
+ const target = personId.toLowerCase();
110
+ let purged = 0;
111
+ for (const [key, entry] of entries) {
112
+ if (entry.personIds.includes(target)) {
113
+ entries.delete(key);
114
+ purged++;
115
+ }
116
+ }
117
+ return purged;
118
+ };
119
+ const purgeAll = () => {
120
+ const purged = entries.size;
121
+ entries.clear();
122
+ return purged;
123
+ };
124
+ return {
125
+
126
+ ttlSeconds,
127
+ get: lookup,
128
+ set: store,
129
+
130
+ read: async (personData, input, callOptions) => {
131
+ const cached = lookup(input);
132
+ if (cached)
133
+ return cached;
134
+ const answer = await personData.read(input, callOptions);
135
+ store(input, answer);
136
+ return answer;
137
+ },
138
+ purgePerson,
139
+ purgeAll,
140
+
141
+ handle: (event) => {
142
+ switch (event.type) {
143
+ case 'person_data.grant.revoked':
144
+ case 'person_data.grant.changed': {
145
+ const personId = typeof event.data.person_id === 'string' ? event.data.person_id : null;
146
+
147
+ return personId ? purgePerson(personId) : purgeAll();
148
+ }
149
+ case 'person_data.app.frozen':
150
+ case 'person_data.app.terminated':
151
+ return purgeAll();
152
+ default:
153
+ return 0;
154
+ }
155
+ },
156
+
157
+ size: () => {
158
+ sweep();
159
+ return entries.size;
160
+ },
161
+ };
162
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Person locations — send a point into one of the person's own conversations as a SNAPSHOT
3
+ * (core `Messaging/Residency/Locations`).
4
+ *
5
+ * POST /api/person/conversations/{conversation}/locations
6
+ * {latitude, longitude, precision?: 'exact'|'approximate', label?, address?, icon?,
7
+ * source?: 'saved_place'|'current_position'|'map_point'}
8
+ * → the message (type `location`, `metadata.location` = the snapshot), as the text send answers
9
+ *
10
+ * `approximate` coarsens to a ~1.1 km grid and never sends the street. Editing or deleting a saved
11
+ * place later never moves a sent message. Refused 403 (neutral wording) when anyone in the room is
12
+ * blocked with the sender either way; 403 when the caller is not in the room. Send an
13
+ * `Idempotency-Key` so a retried send posts once.
14
+ */
15
+ import type { Http } from './http.js';
16
+ export type SharedLocationPrecision = 'exact' | 'approximate';
17
+ export type SharedLocationSource = 'saved_place' | 'current_position' | 'map_point';
18
+ export interface ShareLocationRequest {
19
+ latitude: number;
20
+ longitude: number;
21
+ precision?: SharedLocationPrecision;
22
+ label?: string | null;
23
+ address?: string | null;
24
+ icon?: string | null;
25
+ source?: SharedLocationSource;
26
+ }
27
+ /** `metadata.location` of a `location` message. Coordinates are 7-place strings. */
28
+ export interface SharedLocation {
29
+ latitude: string;
30
+ longitude: string;
31
+ precision: SharedLocationPrecision;
32
+ label: string | null;
33
+ address: string | null;
34
+ icon: string | null;
35
+ source: SharedLocationSource;
36
+ }
37
+ export interface LocationMessage {
38
+ id: string;
39
+ conversation_id: string;
40
+ sender_person_id: string;
41
+ body: string;
42
+ type: 'location';
43
+ metadata: {
44
+ location: SharedLocation;
45
+ };
46
+ created_at: string;
47
+ }
48
+ export declare function createPersonLocationsNamespace(http: Http): {
49
+ /** POST — send the point into the conversation. Pass an idempotency key for retries. */
50
+ share: (conversationId: string, location: ShareLocationRequest, options?: {
51
+ idempotencyKey?: string;
52
+ }) => Promise<LocationMessage>;
53
+ };
54
+ export type PersonLocationsNamespace = ReturnType<typeof createPersonLocationsNamespace>;
@@ -0,0 +1,6 @@
1
+ export function createPersonLocationsNamespace(http) {
2
+ return {
3
+
4
+ share: (conversationId, location, options) => http.post(`/api/person/conversations/${encodeURIComponent(conversationId)}/locations`, location, options?.idempotencyKey ? { headers: { 'Idempotency-Key': options.idempotencyKey } } : {}),
5
+ };
6
+ }