@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,268 @@
1
+ import type { Http } from './http.js';
2
+ import { type BilingualText, type PersonDomainCallOptions } from './actors.js';
3
+ import type { CatalogAmount, CatalogAvailability, CatalogCollection, CatalogEntry } from './catalogs.js';
4
+ import { type ListPage, type ListQueryState } from './list-query.js';
5
+ /** A business that sells, as a directory row, a product's seller and a shop page's header. */
6
+ export interface MarketplaceShopCard {
7
+ id: string;
8
+ handle: string | null;
9
+ display_name: BilingualText;
10
+ avatar_url: string | null;
11
+ verified: boolean;
12
+ /** A category key from the platform taxonomy; null when the business has not chosen one. */
13
+ category_key: string | null;
14
+ /** By the business's weekly hours in its own time zone. */
15
+ open_now: boolean;
16
+ /** The business's coarse public point (never more precise than it chose to show). */
17
+ coordinates: {
18
+ latitude: number;
19
+ longitude: number;
20
+ } | null;
21
+ /** Metres from `near`, only when the list was asked with `near`. */
22
+ distance_metres: number | null;
23
+ /** Public review average as a decimal string ("4.50") and the count; null = no reviews yet (never 0). */
24
+ rating: {
25
+ average: string;
26
+ count: number;
27
+ } | null;
28
+ /** How many catalogue entries the business has. */
29
+ item_count: number;
30
+ /** Its entries can be bought in the app (the cart pays from the wallet balance). */
31
+ accepts_wallet: boolean;
32
+ /** Its entries can also be bought for someone else. */
33
+ offers_for_someone_else: boolean;
34
+ /** The app path of the shop page: `/marketplace/shops/{id}`. */
35
+ deep_link: string;
36
+ }
37
+ /** `GET …/shops/{actor}`: one business's page. */
38
+ export interface MarketplaceShopView {
39
+ shop: MarketplaceShopCard;
40
+ bio: string | null;
41
+ cover_url: string | null;
42
+ category: {
43
+ key: string;
44
+ label: BilingualText;
45
+ } | null;
46
+ /** The public area only: the address parts the business's precision shows. */
47
+ area: {
48
+ address: Record<string, string>;
49
+ precision: string;
50
+ latitude: number | null;
51
+ longitude: number | null;
52
+ } | null;
53
+ time_zone: string | null;
54
+ /** Day key (`monday` …) to opening periods, `HH:MM` local time. */
55
+ weekly_hours: Record<string, Array<{
56
+ opens: string;
57
+ closes: string;
58
+ }>> | null;
59
+ /** `open`, `closed` or `unknown` (no hours published), and when that changes (ISO-8601). */
60
+ opening_status: {
61
+ state: string;
62
+ changes_at: string | null;
63
+ };
64
+ contact_actions: Array<{
65
+ type: string;
66
+ value: string | null;
67
+ label: BilingualText;
68
+ value_kind: string;
69
+ }>;
70
+ rating_summary: MarketplaceRatingSummary | null;
71
+ collections: CatalogCollection[];
72
+ /** Up to 8, in the business's own order. */
73
+ featured_items: CatalogEntry[];
74
+ /** Up to 8, newest first. */
75
+ newest_items: CatalogEntry[];
76
+ /** The viewer manages this business: show the owner's tools, not the shopper's. */
77
+ viewer_is_member: boolean;
78
+ }
79
+ export interface MarketplaceRatingSummary {
80
+ average: string;
81
+ count: number;
82
+ /** Score (1–5) to count. */
83
+ distribution: Record<string, number>;
84
+ verified_count: number;
85
+ aspects: Record<string, {
86
+ count: number;
87
+ average: string;
88
+ }>;
89
+ last_reviewed_at?: string | null;
90
+ }
91
+ export interface MarketplaceReview {
92
+ id: string;
93
+ score: number;
94
+ title: string | null;
95
+ body: string | null;
96
+ language: string | null;
97
+ /** The reviewer bought it (an order backs the review). */
98
+ verified: boolean;
99
+ created_at: string;
100
+ author: {
101
+ display_name: BilingualText;
102
+ handle: string | null;
103
+ avatar_url: string | null;
104
+ } | null;
105
+ }
106
+ /** One input an action still needs from the person. */
107
+ export interface MarketplaceActionInput {
108
+ /** The body field (or, for `idempotency_key_header`, the header) it fills. */
109
+ name: string;
110
+ /**
111
+ * `integer` · `text` · `long_text` · `person_handle` · `instant` (ISO-8601) · `choice` (one of
112
+ * `choices` — an item with variants asks for one before buy, for someone else or a pooled
113
+ * purchase) · `idempotency_key_header` (the SDK fills it).
114
+ */
115
+ kind: 'integer' | 'text' | 'long_text' | 'person_handle' | 'instant' | 'choice' | 'idempotency_key_header' | string;
116
+ required: boolean;
117
+ label: BilingualText;
118
+ minimum?: number;
119
+ maximum?: number;
120
+ default?: unknown;
121
+ /** For `choice`: the values to pick from (a variant's id and name); `disabled` = listed, not choosable (sold out). */
122
+ choices?: Array<{
123
+ value: string;
124
+ label: BilingualText;
125
+ disabled?: boolean;
126
+ }>;
127
+ }
128
+ /** One thing the viewer can do with a catalogue entry, declared by the server. */
129
+ export interface MarketplaceAction {
130
+ /** `buy` · `for_someone_else` · `pooled_purchase` · `wishlist` · `ask.availability` · `ask.price` · `ask.details` · `ask.custom` · `share` */
131
+ key: string;
132
+ /** `act` changes something; `ask` opens a question to the business; `signal` records interest. */
133
+ shape: 'ask' | 'signal' | 'act';
134
+ /** How prominent to draw it: `strong` is the primary button. */
135
+ weight_class: 'strong' | 'medium' | 'light';
136
+ /** The neutral core words; prefer the vertical's words for `vocabulary_key` when it has them. */
137
+ label: BilingualText;
138
+ vocabulary_key: string;
139
+ /** Same as `available`, for the shared engagement-action shape. */
140
+ enabled: boolean;
141
+ available: boolean;
142
+ /** Why not, ready to show. `code` is stable (e.g. `profile_purchase_off`, `item_unavailable`). */
143
+ unavailable_reason: {
144
+ code: string;
145
+ message: BilingualText;
146
+ } | null;
147
+ method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | string;
148
+ /** An absolute API path, e.g. `/api/person/cart/lines`. */
149
+ endpoint: string;
150
+ /** Fields already filled in (the entry, the target amount …); merged under the person's inputs. */
151
+ body: Record<string, unknown>;
152
+ inputs: MarketplaceActionInput[];
153
+ /** It also runs through `POST /api/person/engagements` (it needs no inputs). */
154
+ via_engagements: boolean;
155
+ }
156
+ /** `GET …/entries/{entry}/overview`: one catalogue entry with what relates to it. */
157
+ export interface MarketplaceProductView {
158
+ product: CatalogEntry & {
159
+ images: Array<{
160
+ url: string;
161
+ alt: BilingualText;
162
+ }>;
163
+ /** Money as decimal strings. `varies` = several prices: show "from minimum". */
164
+ price_range: {
165
+ minimum: CatalogAmount;
166
+ maximum: CatalogAmount;
167
+ currency_code: string;
168
+ varies: boolean;
169
+ } | null;
170
+ stock: {
171
+ availability: CatalogAvailability;
172
+ available_quantity: number | null;
173
+ };
174
+ /** Option groups (size, colour …) once the business's source publishes them; empty until then. */
175
+ options: Array<{
176
+ key: string;
177
+ label: BilingualText;
178
+ values: Array<{
179
+ key: string;
180
+ label: BilingualText;
181
+ }>;
182
+ }>;
183
+ /** Purchasable combinations once published; empty until then. */
184
+ variants: Array<{
185
+ id: string;
186
+ option_values: Record<string, string>;
187
+ price: CatalogAmount | null;
188
+ availability: CatalogAvailability;
189
+ }>;
190
+ };
191
+ seller: MarketplaceShopCard | null;
192
+ reviews: {
193
+ subject: {
194
+ type: string;
195
+ id: string;
196
+ } | null;
197
+ summary: MarketplaceRatingSummary | null;
198
+ /** Up to 3, newest first. Page on with `client.reviews` and `subject`. */
199
+ recent: MarketplaceReview[];
200
+ next_cursor: string | null;
201
+ };
202
+ /** Up to 8 other entries of the same business. */
203
+ more_from_shop: CatalogEntry[];
204
+ /** Up to 8 entries from other businesses: same parent category, a 0.5× to 1.5× price band. */
205
+ similar_items: CatalogEntry[];
206
+ actions: MarketplaceAction[];
207
+ viewer_is_member: boolean;
208
+ }
209
+ export interface MarketplaceNamespace {
210
+ /**
211
+ * List businesses that sell (`GET /api/person/catalog/shops`). Cursor-paginated; follow
212
+ * `next_cursor` until null.
213
+ *
214
+ * @example
215
+ * const nearby = await client.marketplace.shops({ sort: 'distance', parameters: { near: listPoint(31.95, 35.92) }, filter: { within: 5 } });
216
+ */
217
+ shops(query?: ListQueryState, options?: PersonDomainCallOptions): Promise<ListPage<MarketplaceShopCard>>;
218
+ /**
219
+ * Read one business's page (`GET /api/person/catalog/shops/{actorId}`). Rejects with 404 when
220
+ * the business is not visible or its catalogue is switched off.
221
+ *
222
+ * @example
223
+ * const view = await client.marketplace.shop(actorId);
224
+ */
225
+ shop(actorId: string, options?: PersonDomainCallOptions): Promise<MarketplaceShopView>;
226
+ /**
227
+ * Read one catalogue entry with its seller, reviews, related entries and declared actions
228
+ * (`GET /api/person/catalog/entries/{entryId}/overview`).
229
+ *
230
+ * @example
231
+ * const view = await client.marketplace.product(entryId);
232
+ */
233
+ product(entryId: string, options?: PersonDomainCallOptions): Promise<MarketplaceProductView>;
234
+ /**
235
+ * Run a declared action: sends `method` to `endpoint` with `body` merged under `values` (the
236
+ * person's answers to `inputs`), with an idempotency key. Rejects without calling the server
237
+ * when the action is unavailable or a required input is missing. Answers the endpoint's JSON.
238
+ *
239
+ * @example
240
+ * await client.marketplace.runAction(forSomeoneElse, { quantity: 1, recipient_name: 'Sara' });
241
+ */
242
+ runAction<T = unknown>(action: MarketplaceAction, values?: Record<string, unknown>, options?: PersonDomainCallOptions): Promise<T>;
243
+ }
244
+ /** Thrown by `runAction` before any request when the action cannot run as asked. */
245
+ export declare class MarketplaceActionRefused extends Error {
246
+ readonly action: string;
247
+ readonly reason: 'unavailable' | 'missing_input';
248
+ readonly detail: {
249
+ code?: string;
250
+ input?: string;
251
+ message?: BilingualText;
252
+ };
253
+ constructor(action: string, reason: 'unavailable' | 'missing_input', detail?: {
254
+ code?: string;
255
+ input?: string;
256
+ message?: BilingualText;
257
+ });
258
+ }
259
+ /**
260
+ * The request a declared action makes with these values: the pure half of `runAction`, exported so
261
+ * a screen can test or preview it. Header inputs (`idempotency_key_header`) are left to the request.
262
+ */
263
+ export declare function marketplaceActionRequest(action: MarketplaceAction, values?: Record<string, unknown>): {
264
+ method: string;
265
+ endpoint: string;
266
+ body: Record<string, unknown>;
267
+ };
268
+ export declare function createMarketplaceNamespace(http: Http): MarketplaceNamespace;
@@ -0,0 +1,59 @@
1
+ import { personDomainRequest, } from './actors.js';
2
+ import { listQueryParams } from './list-query.js';
3
+
4
+ export class MarketplaceActionRefused extends Error {
5
+ action;
6
+ reason;
7
+ detail;
8
+ constructor(action, reason, detail = {}) {
9
+ super(`Marketplace action ${action} refused: ${reason}${detail.input ? ` (${detail.input})` : ''}`);
10
+ this.action = action;
11
+ this.reason = reason;
12
+ this.detail = detail;
13
+ this.name = 'MarketplaceActionRefused';
14
+ }
15
+ }
16
+
17
+ export function marketplaceActionRequest(action, values = {}) {
18
+ if (!action.available) {
19
+ throw new MarketplaceActionRefused(action.key, 'unavailable', { code: action.unavailable_reason?.code, message: action.unavailable_reason?.message });
20
+ }
21
+ const body = { ...action.body };
22
+ for (const input of action.inputs) {
23
+ if (input.kind === 'idempotency_key_header')
24
+ continue;
25
+ const value = values[input.name] ?? input.default;
26
+ const missing = value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
27
+ if (missing) {
28
+ if (input.required)
29
+ throw new MarketplaceActionRefused(action.key, 'missing_input', { input: input.name });
30
+ continue;
31
+ }
32
+ body[input.name] = value;
33
+ }
34
+ return { method: action.method.toUpperCase(), endpoint: action.endpoint, body };
35
+ }
36
+ const BASE = '/api/person/catalog';
37
+ const segment = encodeURIComponent;
38
+ export function createMarketplaceNamespace(http) {
39
+ const data = async (promise) => (await promise).data;
40
+ return {
41
+ shops: (query = {}, options) => http.get(`${BASE}/shops`, personDomainRequest(options, false, listQueryParams(query))),
42
+ shop: (actorId, options) => data(http.get(`${BASE}/shops/${segment(actorId)}`, personDomainRequest(options))),
43
+ product: (entryId, options) => data(http.get(`${BASE}/entries/${segment(entryId)}/overview`, personDomainRequest(options))),
44
+ runAction: async (action, values = {}, options) => {
45
+ const request = marketplaceActionRequest(action, values);
46
+ const requestOptions = personDomainRequest(options, true);
47
+ switch (request.method) {
48
+ case 'PUT':
49
+ return http.put(request.endpoint, request.body, requestOptions);
50
+ case 'PATCH':
51
+ return http.patch(request.endpoint, request.body, requestOptions);
52
+ case 'DELETE':
53
+ return http.delete(request.endpoint, requestOptions);
54
+ default:
55
+ return http.post(request.endpoint, request.body, requestOptions);
56
+ }
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,103 @@
1
+ import type { Http } from './http.js';
2
+ import { type BilingualText, type PersonDomainCallOptions, type PersonDomainCursorPage } from './actors.js';
3
+ export type MatchingParticipationStatus = 'active' | 'paused' | 'off';
4
+ export type MatchingChainStatus = 'open' | 'formed' | 'dissolved' | 'expired' | 'failed';
5
+ export type MatchingChainRelation = 'you' | 'gives_to_you' | 'receives_from_you' | 'gives_to_you_and_receives_from_you' | 'another_participant';
6
+ export interface MatchingSource {
7
+ /** e.g. `listings.listing`, `listings.saved_search`, `wishlists.item`, `engagements.interest`. */
8
+ type: string;
9
+ side: 'have' | 'want';
10
+ data_category: 'offered_items' | 'stated_wants' | 'activity_signals';
11
+ label: BilingualText;
12
+ enabled: boolean;
13
+ /** False when this place's rules do not use this kind of source. */
14
+ offered: boolean;
15
+ }
16
+ export interface MatchingParticipation {
17
+ pool_key: string;
18
+ engine_on: boolean;
19
+ /** False for an account matching is never available to (a minor). */
20
+ allowed: boolean;
21
+ status: MatchingParticipationStatus;
22
+ sources: MatchingSource[];
23
+ have_count: number;
24
+ want_count: number;
25
+ synced_at: string | null;
26
+ policies: {
27
+ chain_length: string;
28
+ accept_window: string;
29
+ value_tolerance: string;
30
+ credit_top_up: string;
31
+ radius: string;
32
+ };
33
+ }
34
+ export interface MatchingItemCard {
35
+ title: BilingualText;
36
+ available: boolean;
37
+ image_url: string | null;
38
+ /** A decimal string at scale 4. Never a number. */
39
+ value_amount: string | null;
40
+ currency_code: string | null;
41
+ deep_link_path: string | null;
42
+ }
43
+ export interface MatchingChain {
44
+ id: string;
45
+ status: MatchingChainStatus;
46
+ closing_reason: 'formed' | 'declined' | 'expired' | 'participant_left' | 'item_unavailable' | 'exchange_refused' | 'erased' | 'account_changed' | null;
47
+ closing_label: BilingualText | null;
48
+ length: number;
49
+ accepted_count: number;
50
+ deadline_at: string | null;
51
+ proposed_at: string;
52
+ closed_at: string | null;
53
+ /** Set once everyone accepted. */
54
+ exchange_id: string | null;
55
+ viewer: {
56
+ position: number;
57
+ response: 'pending' | 'accepted' | 'declined';
58
+ can_answer: boolean;
59
+ can_withdraw_acceptance: boolean;
60
+ };
61
+ you_give: {
62
+ item: MatchingItemCard;
63
+ to: {
64
+ display_name: BilingualText | null;
65
+ } | null;
66
+ };
67
+ you_receive: {
68
+ item: MatchingItemCard | null;
69
+ from: {
70
+ display_name: BilingualText | null;
71
+ } | null;
72
+ };
73
+ top_up: {
74
+ direction: 'pay' | 'receive';
75
+ amount: string;
76
+ currency_code: string;
77
+ } | null;
78
+ ring: Array<{
79
+ position: number;
80
+ is_viewer: boolean;
81
+ relation: MatchingChainRelation;
82
+ display_name: BilingualText | null;
83
+ gives_to_position: number;
84
+ }>;
85
+ }
86
+ export interface MatchingNamespace {
87
+ participation(options?: PersonDomainCallOptions): Promise<MatchingParticipation>;
88
+ /** `sources` omitted keeps the current choice (or every offered source, when switching on the first time). */
89
+ updateParticipation(status: MatchingParticipationStatus, sources?: string[], options?: PersonDomainCallOptions): Promise<MatchingParticipation>;
90
+ /** Queue a re-read of the party's sources. */
91
+ refresh(options?: PersonDomainCallOptions): Promise<{
92
+ queued: boolean;
93
+ }>;
94
+ chains(query?: {
95
+ status?: 'open' | 'closed' | 'all';
96
+ cursor?: string | null;
97
+ limit?: number;
98
+ }, options?: PersonDomainCallOptions): Promise<PersonDomainCursorPage<MatchingChain>>;
99
+ chain(chainId: string, options?: PersonDomainCallOptions): Promise<MatchingChain>;
100
+ accept(chainId: string, options?: PersonDomainCallOptions): Promise<MatchingChain>;
101
+ decline(chainId: string, options?: PersonDomainCallOptions): Promise<MatchingChain>;
102
+ }
103
+ export declare function createMatchingNamespace(http: Http): MatchingNamespace;
@@ -0,0 +1,22 @@
1
+ import { personDomainRequest, } from './actors.js';
2
+ const BASE = '/api/person/matching';
3
+ const segment = encodeURIComponent;
4
+ export function createMatchingNamespace(http) {
5
+ const data = async (promise) => (await promise).data;
6
+ return {
7
+ participation: (options) => data(http.get(`${BASE}/participation`, personDomainRequest(options))),
8
+ updateParticipation: (status, sources, options) => data(http.put(`${BASE}/participation`, sources === undefined ? { status } : { status, sources }, personDomainRequest(options, true))),
9
+ refresh: (options) => data(http.post(`${BASE}/participation/refresh`, undefined, personDomainRequest(options, true))),
10
+ chains: (query = {}, options) => {
11
+ const params = { 'filter[status]': query.status ?? 'all' };
12
+ if (query.cursor)
13
+ params.cursor = query.cursor;
14
+ if (query.limit)
15
+ params.limit = query.limit;
16
+ return http.get(`${BASE}/chains`, personDomainRequest(options, false, params));
17
+ },
18
+ chain: (chainId, options) => data(http.get(`${BASE}/chains/${segment(chainId)}`, personDomainRequest(options))),
19
+ accept: (chainId, options) => data(http.post(`${BASE}/chains/${segment(chainId)}/accept`, undefined, personDomainRequest(options, true))),
20
+ decline: (chainId, options) => data(http.post(`${BASE}/chains/${segment(chainId)}/decline`, undefined, personDomainRequest(options, true))),
21
+ };
22
+ }
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Media — `/api/person/media/*`: first-class person-plane files. A consuming module declares a
3
+ * PURPOSE (what it accepts, for which subject type); the client uploads straight to storage and
4
+ * hands the module the resulting media id, which the module attaches to its own subject.
5
+ *
6
+ * purposes() what each purpose accepts — filter a picker and refuse an oversized file BEFORE
7
+ * the upload starts
8
+ * upload() the whole flow with progress, multipart, retry, abort and resume (below)
9
+ * describe() up to 200 files as the acting party may see them; `sources` is `<picture>`-ready
10
+ *
11
+ * The lower-level calls (`begin`, `presignParts`, `finalise`, `abort`) are exported for a client
12
+ * that drives its own transport.
13
+ *
14
+ * Delivery URLs are RELATIVE, signed and short-lived (15–20 minutes): prefix the API origin, and
15
+ * re-read the file rather than storing a URL.
16
+ */
17
+ import type { Http } from './http.js';
18
+ import { type BilingualText, type PartyReferenceString, type PersonDomainCallOptions, type PersonDomainEnvelope } from './actors.js';
19
+ /** `document` (PDF, text, Word, Excel): never re-encoded, always delivered as a download (`MediaAsset.document`). */
20
+ export type MediaKind = 'image' | 'video' | 'audio' | 'document';
21
+ export type MediaStatus = 'awaiting_upload' | 'uploaded' | 'scanning' | 'processing' | 'held' | 'ready' | 'rejected' | 'failed';
22
+ export interface MediaPurpose {
23
+ key: string;
24
+ subject_type: string;
25
+ label: BilingualText;
26
+ mime_types: string[];
27
+ /** Per kind present in `mime_types`. */
28
+ maximum_bytes: Partial<Record<MediaKind, number>>;
29
+ maximum_per_subject: number;
30
+ maximum_duration_seconds: number | null;
31
+ image_widths: number[];
32
+ requires_alt_text: boolean;
33
+ vertical_key?: string | null;
34
+ }
35
+ export interface MediaSourceEntry {
36
+ /** Relative signed URL, or null when this viewer may not receive the bytes yet. */
37
+ url: string | null;
38
+ width: number | null;
39
+ height: number | null;
40
+ }
41
+ /** One `<source>`: a format and its `srcset`, best format first (avif, webp, then jpeg/png). */
42
+ export interface MediaSource {
43
+ format: string;
44
+ mime_type: string;
45
+ srcset: MediaSourceEntry[];
46
+ }
47
+ export interface MediaRendition {
48
+ key: string;
49
+ mime_type: string;
50
+ width: number | null;
51
+ height: number | null;
52
+ bitrate_kilobits: number | null;
53
+ url: string | null;
54
+ }
55
+ export interface MediaAsset {
56
+ id: string;
57
+ owner: PartyReferenceString;
58
+ purpose: string;
59
+ kind: MediaKind;
60
+ status: MediaStatus;
61
+ mime_type: string;
62
+ size_bytes: number | null;
63
+ width: number | null;
64
+ height: number | null;
65
+ duration_milliseconds: number | null;
66
+ has_audio: boolean | null;
67
+ alt_text: {
68
+ en: string | null;
69
+ ar: string | null;
70
+ };
71
+ placeholder: {
72
+ blurhash: string | null;
73
+ dominant_colour: string | null;
74
+ aspect_ratio: number | null;
75
+ };
76
+ sources: MediaSource[];
77
+ poster: MediaSource[];
78
+ renditions: MediaRendition[];
79
+ /** A document's download (signed, relative, short-lived); null for other kinds. */
80
+ document?: {
81
+ url: string | null;
82
+ file_name: string;
83
+ mime_type: string;
84
+ size_bytes: number | null;
85
+ } | null;
86
+ /** The name the person chose for the file. */
87
+ file_name?: string | null;
88
+ subject: {
89
+ type: string;
90
+ id: string;
91
+ position: number;
92
+ } | null;
93
+ viewer_is_owner: boolean;
94
+ /** Video/audio delivered as uploaded because no transcoder was available. */
95
+ processing_degraded: boolean;
96
+ /** Owner side only: why the file was refused (`type_mismatch`, `infected`, …). */
97
+ rejection_reason: string | null;
98
+ created_at: string | null;
99
+ ready_at: string | null;
100
+ }
101
+ export interface MediaUploadTicket {
102
+ asset: MediaAsset;
103
+ mode: 'single' | 'multipart';
104
+ upload_url: string | null;
105
+ upload_headers: Record<string, string>;
106
+ part_size_bytes: number | null;
107
+ part_count: number | null;
108
+ expires_at: string;
109
+ /** This answers a retried begin with the same idempotency key. */
110
+ replayed: boolean;
111
+ }
112
+ export interface MediaPartUrls {
113
+ asset_id: string;
114
+ parts: Array<{
115
+ part_number: number;
116
+ upload_url: string;
117
+ }>;
118
+ expires_in_seconds: number;
119
+ }
120
+ export interface MediaUsage {
121
+ owner: PartyReferenceString;
122
+ bytes_held: number;
123
+ /** Null = unlimited. */
124
+ allowance_bytes: number | null;
125
+ remaining_bytes: number | null;
126
+ uploads_in_flight: number;
127
+ maximum_uploads_in_flight: number;
128
+ }
129
+ export interface BeginMediaUpload {
130
+ purpose: string;
131
+ mime_type: string;
132
+ size_bytes: number;
133
+ alt_text?: {
134
+ en?: string | null;
135
+ ar?: string | null;
136
+ } | null;
137
+ /** The name the person chose (shown on a document's download); a basename. */
138
+ file_name?: string | null;
139
+ }
140
+ export interface CompletedPart {
141
+ part_number: number;
142
+ etag: string;
143
+ }
144
+ export type MediaUploadPhase = 'starting' | 'sending' | 'finishing' | 'processing' | 'done';
145
+ export interface MediaUploadProgress {
146
+ phase: MediaUploadPhase;
147
+ sentBytes: number;
148
+ totalBytes: number;
149
+ /** 0–1, of the bytes sent. */
150
+ fraction: number;
151
+ }
152
+ /**
153
+ * Everything needed to continue an interrupted upload: keep it (for example in sessionStorage)
154
+ * and pass it back as `resume`. Parts already stored are not sent again.
155
+ */
156
+ export interface MediaUploadResumeState {
157
+ assetId: string;
158
+ idempotencyKey: string;
159
+ partSizeBytes: number | null;
160
+ completedParts: CompletedPart[];
161
+ }
162
+ export interface MediaUploadOptions extends Omit<PersonDomainCallOptions, 'idempotencyKey'> {
163
+ purpose: string;
164
+ altText?: {
165
+ en?: string | null;
166
+ ar?: string | null;
167
+ } | null;
168
+ onProgress?: (progress: MediaUploadProgress) => void;
169
+ /** Called whenever a part lands; persist it to survive a reload. */
170
+ onResumeState?: (state: MediaUploadResumeState) => void;
171
+ resume?: MediaUploadResumeState | null;
172
+ /** Parts sent at once (multipart). Default 3. */
173
+ concurrency?: number;
174
+ /** Attempts per network step before giving up. Default 4. */
175
+ attempts?: number;
176
+ /** Resolve only once processing settled (polls `describe`). Default false. */
177
+ waitUntilSettled?: boolean;
178
+ /** Polling interval while waiting, ms. Default 1500. */
179
+ pollIntervalMs?: number;
180
+ }
181
+ /** A refused or failed upload, with the server's stable reason when there is one. */
182
+ export declare class MediaUploadError extends Error {
183
+ readonly reason: string | null;
184
+ readonly retryable: boolean;
185
+ readonly assetId: string | null;
186
+ constructor(message: string, reason: string | null, retryable: boolean, assetId?: string | null);
187
+ }
188
+ /** The bytes to send. A `File` is a `Blob`; any `Blob` works. */
189
+ export type MediaUploadBody = Blob & {
190
+ name?: string;
191
+ };
192
+ export interface MediaNamespace {
193
+ purposes(options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaPurpose[]>>;
194
+ usage(options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaUsage>>;
195
+ describe(ids: string[], options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaAsset[]>>;
196
+ show(assetId: string, options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaAsset>>;
197
+ begin(input: BeginMediaUpload, options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaUploadTicket>>;
198
+ presignParts(assetId: string, partNumbers: number[], options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaPartUrls>>;
199
+ finalise(assetId: string, parts?: CompletedPart[], options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaAsset>>;
200
+ abort(assetId: string, options?: PersonDomainCallOptions): Promise<void>;
201
+ /** Set (or clear, with null) the alt text of one's own upload — written while it uploads, or later. */
202
+ describeAltText(assetId: string, altText: {
203
+ en?: string | null;
204
+ ar?: string | null;
205
+ } | null, options?: PersonDomainCallOptions): Promise<PersonDomainEnvelope<MediaAsset>>;
206
+ /** Begin → send (single PUT or multipart) → finalise, optionally waiting for processing. */
207
+ upload(file: MediaUploadBody, options: MediaUploadOptions): Promise<MediaAsset>;
208
+ }
209
+ export declare function createMediaNamespace(http: Http): MediaNamespace;
210
+ /**
211
+ * The whole upload. The `Idempotency-Key` is minted once per intent (or taken from `resume`), so
212
+ * a retried begin answers the SAME asset with fresh URLs instead of reserving allowance twice.
213
+ * Aborting through `signal` stops the transfer and releases the server-side slot (best effort).
214
+ */
215
+ export declare function uploadMedia(media: MediaNamespace, file: MediaUploadBody, options: MediaUploadOptions): Promise<MediaAsset>;
216
+ /**
217
+ * PUT bytes to a presigned storage URL and answer its `ETag`. XHR in a browser, because `fetch`
218
+ * still reports no UPLOAD progress anywhere; `fetch` elsewhere (progress then arrives per part).
219
+ * The URL is the storage host's, so this legitimately bypasses the API client.
220
+ */
221
+ export declare function putBytes(url: string, body: Blob, headers: Record<string, string>, signal: AbortSignal | undefined, onProgress: (loadedBytes: number) => void): Promise<string | null>;