@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,56 @@
1
+
2
+
3
+ import { NuwahApiError } from './http.js';
4
+
5
+ const STATUS_FOR_ASSISTANT_ERROR_CODE = {
6
+ ai_disabled: 503,
7
+ ai_credits_exhausted: 402,
8
+ rate_limited: 429,
9
+ overloaded: 429,
10
+ };
11
+
12
+ export function assistantResultFromAskResponse(response) {
13
+ if (response && typeof response === 'object')
14
+ return response;
15
+ if (typeof response !== 'string')
16
+ throw new Error('ai_ask_incomplete_stream');
17
+ let result = null;
18
+ for (const frame of response.replace(/\r\n/g, '\n').split('\n\n')) {
19
+ if (frame.trim() === '')
20
+ continue;
21
+ let eventName = 'message';
22
+ let dataText = '';
23
+ for (const line of frame.split('\n')) {
24
+ if (line.startsWith('event:'))
25
+ eventName = line.slice(6).trim();
26
+ else if (line.startsWith('data:'))
27
+ dataText += line.slice(5).trim();
28
+ }
29
+ if (dataText === '')
30
+ continue;
31
+ const data = JSON.parse(dataText);
32
+ if (eventName === 'done') {
33
+ result = data;
34
+ }
35
+ else if (eventName === 'error') {
36
+ const code = typeof data.code === 'string' ? data.code : '';
37
+ throw new NuwahApiError(STATUS_FOR_ASSISTANT_ERROR_CODE[code] ?? 500, data);
38
+ }
39
+ }
40
+ if (!result)
41
+ throw new Error('ai_ask_incomplete_stream');
42
+ return result;
43
+ }
44
+ export function createReportingNamespace(http) {
45
+ return {
46
+ ask: async (args) => assistantResultFromAskResponse(await http.post('/api/v1/ai/reporting/ask', {
47
+ question: args.question,
48
+ ...(args.locale ? { locale: args.locale } : {}),
49
+ ...(args.conversationId ? { conversation_id: args.conversationId } : {}),
50
+ ...(args.history ? { history: args.history } : {}),
51
+ },
52
+
53
+ { headers: { Accept: 'text/event-stream, application/json' } })),
54
+ config: () => http.get('/api/v1/ai/config'),
55
+ };
56
+ }
@@ -0,0 +1,270 @@
1
+ import type { Http } from './http.js';
2
+ import type { ListQuery, Paginated } from './types.js';
3
+ export interface SalesOrderLine {
4
+ id: string;
5
+ sales_order_id: string;
6
+ item_id: string | null;
7
+ item_sku: string | null;
8
+ description: string;
9
+ quantity: string;
10
+ unit_price: string;
11
+ tax_rate_percent: string;
12
+ discount: string;
13
+ line_subtotal: string;
14
+ line_tax: string;
15
+ line_total: string;
16
+ reserved_qty: string;
17
+ fulfilled_qty: string;
18
+ invoiced_qty: string;
19
+ sort: number;
20
+ /** Analytical dimension stamped by Accounting; `SalesOrderLineResource` emits it. */
21
+ cost_center_id: string | null;
22
+ }
23
+ export interface SalesOrder {
24
+ id: string;
25
+ order_number: string;
26
+ channel: string | null;
27
+ source_type: string | null;
28
+ source_id: string | null;
29
+ warehouse_id: string | null;
30
+ customer_account_id: string | null;
31
+ customer_person_id: string | null;
32
+ contact_name: string | null;
33
+ status: string;
34
+ currency_code: string;
35
+ subtotal: string;
36
+ tax_total: string;
37
+ discount_total: string;
38
+ total: string;
39
+ accounting_invoice_id: string | null;
40
+ accounting_invoice_number: string | null;
41
+ notes: string | null;
42
+ expected_ship_date: string | null;
43
+ created_by_person_id: string | null;
44
+ lines?: SalesOrderLine[];
45
+ created_at: string | null;
46
+ updated_at: string | null;
47
+ }
48
+ export interface SalesOrderLineInput {
49
+ item_id?: string | null;
50
+ item_sku?: string | null;
51
+ description: string;
52
+ quantity: number | string;
53
+ unit_price: number | string;
54
+ tax_rate_percent?: number | string | null;
55
+ discount?: number | string | null;
56
+ sort?: number | null;
57
+ }
58
+ export interface CreateSalesOrderInput {
59
+ channel?: string | null;
60
+ warehouse_id?: string | null;
61
+ customer_account_id?: string | null;
62
+ customer_person_id?: string | null;
63
+ contact_name?: string | null;
64
+ currency_code: string;
65
+ notes?: string | null;
66
+ expected_ship_date?: string | null;
67
+ created_by_person_id?: string | null;
68
+ lines?: SalesOrderLineInput[];
69
+ }
70
+ export interface UpdateSalesOrderInput {
71
+ channel?: string;
72
+ warehouse_id?: string | null;
73
+ customer_account_id?: string | null;
74
+ customer_person_id?: string | null;
75
+ contact_name?: string | null;
76
+ currency_code?: string;
77
+ notes?: string | null;
78
+ expected_ship_date?: string | null;
79
+ }
80
+ /**
81
+ * Body for `PUT /orders/{id}/lines/{line}`. Every key is `sometimes`; only the item
82
+ * references are nullable (UpdateOrderLineRequest) — a null tax/discount/sort is a 422,
83
+ * so send `0` to clear.
84
+ */
85
+ export interface UpdateSalesOrderLineInput {
86
+ item_id?: string | null;
87
+ item_sku?: string | null;
88
+ description?: string;
89
+ quantity?: number | string;
90
+ unit_price?: number | string;
91
+ tax_rate_percent?: number | string;
92
+ discount?: number | string;
93
+ sort?: number;
94
+ }
95
+ export interface SalesOrderListQuery extends ListQuery {
96
+ status?: string;
97
+ channel?: string;
98
+ }
99
+ export interface SalesShipmentLine {
100
+ id: string;
101
+ sales_shipment_id: string;
102
+ sales_order_line_id: string;
103
+ item_id: string | null;
104
+ quantity: string;
105
+ stock_movement_id: string | null;
106
+ cogs_amount: string | null;
107
+ }
108
+ export interface SalesShipment {
109
+ id: string;
110
+ sales_order_id: string;
111
+ shipment_number: string;
112
+ warehouse_id: string | null;
113
+ status: string;
114
+ shipped_at: string | null;
115
+ notes: string | null;
116
+ created_by_person_id: string | null;
117
+ lines?: SalesShipmentLine[];
118
+ created_at: string | null;
119
+ updated_at: string | null;
120
+ }
121
+ /**
122
+ * Ship an order. `lines` is an OPTIONAL map of `order_line_id => qty_to_ship`;
123
+ * omit it (or send an empty map) to ship the full remaining balance of every line.
124
+ */
125
+ export interface ShipOrderInput {
126
+ lines?: Record<string, number | string>;
127
+ notes?: string | null;
128
+ }
129
+ export interface SalesInvoiceLine {
130
+ id: string;
131
+ description: string;
132
+ quantity: string;
133
+ unit_price: string;
134
+ discount_percent: string;
135
+ tax_rate_percent: string;
136
+ line_subtotal: string;
137
+ line_tax: string;
138
+ line_total: string;
139
+ }
140
+ export interface SalesInvoice {
141
+ id: string;
142
+ invoice_number: string;
143
+ status: string;
144
+ invoice_date: string | null;
145
+ due_date: string | null;
146
+ subtotal: string;
147
+ tax_amount: string;
148
+ total: string;
149
+ reference: string | null;
150
+ lines?: SalesInvoiceLine[];
151
+ }
152
+ /**
153
+ * Invoice an order. `lines` is an OPTIONAL map of `order_line_id => qty_to_invoice`;
154
+ * omit it (or send an empty map) to invoice the full remaining un-invoiced balance.
155
+ */
156
+ export interface InvoiceOrderInput {
157
+ lines?: Record<string, number | string>;
158
+ }
159
+ export interface SalesReturnLine {
160
+ id: string;
161
+ sales_order_line_id: string;
162
+ item_id: string | null;
163
+ quantity: string;
164
+ unit_cogs: string | null;
165
+ }
166
+ export interface SalesReturn {
167
+ id: string;
168
+ sales_order_id: string;
169
+ return_number: string;
170
+ status: string;
171
+ reason: string | null;
172
+ refund_amount: string;
173
+ credit_note_ref: string | null;
174
+ received_at: string | null;
175
+ refunded_at: string | null;
176
+ created_by_person_id: string | null;
177
+ created_at: string | null;
178
+ lines?: SalesReturnLine[];
179
+ }
180
+ /**
181
+ * Create a return against an order. `lines` is a REQUIRED map of
182
+ * `order_line_id => qty_to_return`.
183
+ */
184
+ export interface CreateReturnInput {
185
+ reason?: string | null;
186
+ lines: Record<string, number | string>;
187
+ }
188
+ export interface SalesReturnListQuery extends ListQuery {
189
+ status?: string;
190
+ sales_order_id?: string;
191
+ }
192
+ export interface SalesReportQuery extends ListQuery {
193
+ from?: string;
194
+ to?: string;
195
+ /** by-period only. */
196
+ bucket?: 'day' | 'month';
197
+ }
198
+ export interface SalesReportEnvelope<T = Record<string, unknown>> {
199
+ data: T;
200
+ meta: {
201
+ from: string;
202
+ to: string;
203
+ bucket?: string;
204
+ };
205
+ }
206
+ export declare function createSalesNamespace(http: Http): {
207
+ orders: {
208
+ /** GET /api/sales/orders — paginated `{data, meta}`. */
209
+ list: (query?: SalesOrderListQuery) => Promise<Paginated<SalesOrder>>;
210
+ /** GET /api/sales/orders/{id} — includes `lines`. */
211
+ get: (id: string) => Promise<SalesOrder>;
212
+ /** POST /api/sales/orders — creates a draft (201). `currency_code` is required. */
213
+ create: (input: CreateSalesOrderInput) => Promise<SalesOrder>;
214
+ /** PUT /api/sales/orders/{id} — header update; DRAFT ONLY (else 422). */
215
+ update: (id: string, input: UpdateSalesOrderInput) => Promise<SalesOrder>;
216
+ /** DELETE /api/sales/orders/{id} — DRAFT ONLY (else 422), 204. */
217
+ remove: (id: string) => Promise<void>;
218
+ /** POST /api/sales/orders/{id}/confirm — DRAFT ONLY; reserves stock (422 if short). */
219
+ confirm: (id: string) => Promise<SalesOrder>;
220
+ /** POST /api/sales/orders/{id}/cancel — DRAFT or CONFIRMED only; releases reservations. */
221
+ cancel: (id: string) => Promise<SalesOrder>;
222
+ /** POST /api/sales/orders/{id}/lines — append a line (201). DRAFT ONLY. */
223
+ addLine: (orderId: string, input: SalesOrderLineInput) => Promise<SalesOrderLine>;
224
+ /** PUT /api/sales/orders/{id}/lines/{line} — DRAFT ONLY. */
225
+ updateLine: (orderId: string, lineId: string, input: UpdateSalesOrderLineInput) => Promise<SalesOrderLine>;
226
+ /** DELETE /api/sales/orders/{id}/lines/{line} — DRAFT ONLY, 204. */
227
+ removeLine: (orderId: string, lineId: string) => Promise<void>;
228
+ };
229
+ fulfillment: {
230
+ /** GET /api/sales/orders/{order}/shipments — bare `{data}` collection. */
231
+ listShipments: (orderId: string) => Promise<{
232
+ data: SalesShipment[];
233
+ }>;
234
+ /** GET /api/sales/shipments/{id} */
235
+ getShipment: (id: string) => Promise<SalesShipment>;
236
+ /** POST /api/sales/orders/{order}/shipments — CONFIRMED or FULFILLING only (201). */
237
+ ship: (orderId: string, input?: ShipOrderInput) => Promise<SalesShipment>;
238
+ };
239
+ billing: {
240
+ /** GET /api/sales/orders/{order}/invoice — the posted AR invoice (404 until invoiced). */
241
+ getInvoice: (orderId: string) => Promise<SalesInvoice>;
242
+ /** POST /api/sales/orders/{order}/invoice — FULFILLED ONLY (201). */
243
+ invoice: (orderId: string, input?: InvoiceOrderInput) => Promise<SalesInvoice>;
244
+ };
245
+ returns: {
246
+ /** GET /api/sales/returns — paginated `{data, meta}`; lines are eager-loaded. */
247
+ list: (query?: SalesReturnListQuery) => Promise<Paginated<SalesReturn>>;
248
+ /** GET /api/sales/returns/{id} */
249
+ get: (id: string) => Promise<SalesReturn>;
250
+ /** POST /api/sales/orders/{order}/returns — create an RMA (201). `lines` is required. */
251
+ create: (orderId: string, input: CreateReturnInput) => Promise<SalesReturn>;
252
+ /** POST /api/sales/returns/{id}/receive — restocks; not already received/refunded. */
253
+ receive: (id: string) => Promise<SalesReturn>;
254
+ /** POST /api/sales/returns/{id}/refund — RECEIVED ONLY; posts the AR reversal. */
255
+ refund: (id: string) => Promise<SalesReturn>;
256
+ };
257
+ reports: {
258
+ /** GET /api/sales/reports/summary?from=&to= */
259
+ summary: (query?: SalesReportQuery) => Promise<SalesReportEnvelope<Record<string, unknown>>>;
260
+ /** GET /api/sales/reports/by-channel?from=&to= */
261
+ byChannel: (query?: SalesReportQuery) => Promise<SalesReportEnvelope<Record<string, unknown>[]>>;
262
+ /** GET /api/sales/reports/by-product?from=&to= */
263
+ byProduct: (query?: SalesReportQuery) => Promise<SalesReportEnvelope<Record<string, unknown>[]>>;
264
+ /** GET /api/sales/reports/by-customer?from=&to= */
265
+ byCustomer: (query?: SalesReportQuery) => Promise<SalesReportEnvelope<Record<string, unknown>[]>>;
266
+ /** GET /api/sales/reports/by-period?from=&to=&bucket=day|month */
267
+ byPeriod: (query?: SalesReportQuery) => Promise<SalesReportEnvelope<Record<string, unknown>[]>>;
268
+ };
269
+ };
270
+ export type SalesNamespace = ReturnType<typeof createSalesNamespace>;
package/dist/sales.js ADDED
@@ -0,0 +1,66 @@
1
+ export function createSalesNamespace(http) {
2
+
3
+ const one = (promise) => promise.then((r) => r.data);
4
+ return {
5
+ orders: {
6
+
7
+ list: (query) => http.get('/api/sales/orders', { params: query }),
8
+
9
+ get: (id) => one(http.get(`/api/sales/orders/${id}`)),
10
+
11
+ create: (input) => one(http.post('/api/sales/orders', input)),
12
+
13
+ update: (id, input) => one(http.put(`/api/sales/orders/${id}`, input)),
14
+
15
+ remove: (id) => http.delete(`/api/sales/orders/${id}`),
16
+
17
+ confirm: (id) => one(http.post(`/api/sales/orders/${id}/confirm`)),
18
+
19
+ cancel: (id) => one(http.post(`/api/sales/orders/${id}/cancel`)),
20
+
21
+ addLine: (orderId, input) => one(http.post(`/api/sales/orders/${orderId}/lines`, input)),
22
+
23
+ updateLine: (orderId, lineId, input) => one(http.put(`/api/sales/orders/${orderId}/lines/${lineId}`, input)),
24
+
25
+ removeLine: (orderId, lineId) => http.delete(`/api/sales/orders/${orderId}/lines/${lineId}`),
26
+ },
27
+ fulfillment: {
28
+
29
+ listShipments: (orderId) => http.get(`/api/sales/orders/${orderId}/shipments`),
30
+
31
+ getShipment: (id) => one(http.get(`/api/sales/shipments/${id}`)),
32
+
33
+ ship: (orderId, input) => one(http.post(`/api/sales/orders/${orderId}/shipments`, input ?? {})),
34
+ },
35
+ billing: {
36
+
37
+ getInvoice: (orderId) => one(http.get(`/api/sales/orders/${orderId}/invoice`)),
38
+
39
+ invoice: (orderId, input) => one(http.post(`/api/sales/orders/${orderId}/invoice`, input ?? {})),
40
+ },
41
+ returns: {
42
+
43
+ list: (query) => http.get('/api/sales/returns', { params: query }),
44
+
45
+ get: (id) => one(http.get(`/api/sales/returns/${id}`)),
46
+
47
+ create: (orderId, input) => one(http.post(`/api/sales/orders/${orderId}/returns`, input)),
48
+
49
+ receive: (id) => one(http.post(`/api/sales/returns/${id}/receive`)),
50
+
51
+ refund: (id) => one(http.post(`/api/sales/returns/${id}/refund`)),
52
+ },
53
+ reports: {
54
+
55
+ summary: (query) => http.get('/api/sales/reports/summary', { params: query }),
56
+
57
+ byChannel: (query) => http.get('/api/sales/reports/by-channel', { params: query }),
58
+
59
+ byProduct: (query) => http.get('/api/sales/reports/by-product', { params: query }),
60
+
61
+ byCustomer: (query) => http.get('/api/sales/reports/by-customer', { params: query }),
62
+
63
+ byPeriod: (query) => http.get('/api/sales/reports/by-period', { params: query }),
64
+ },
65
+ };
66
+ }
@@ -0,0 +1,105 @@
1
+ import type { Http } from './http.js';
2
+ import { type BilingualText, type PartyReference, type PersonDomainCallOptions, type PersonDomainEnvelope } from './actors.js';
3
+ /** Where a conversation lives. A tenant conversation names its organisation. */
4
+ export type ShareConversationPlane = 'person' | 'tenant';
5
+ /** One conversation to share into. `tenant_id` is required for the tenant plane and forbidden otherwise. */
6
+ export interface ShareConversationAddress {
7
+ plane: ShareConversationPlane;
8
+ id: string;
9
+ tenant_id?: string | null;
10
+ }
11
+ /** POST /api/person/shares — share one subject into at most ten conversations. */
12
+ export interface ShareIntoConversationsRequest {
13
+ /** A registered shareable type, `<module>.<thing>` — e.g. `publications.item`. */
14
+ subject_type: string;
15
+ subject_id: string;
16
+ conversations: ShareConversationAddress[];
17
+ }
18
+ /** One share as recorded: the reference that was posted, and the message that carries it. */
19
+ export interface Share {
20
+ id: string;
21
+ subject_type: string;
22
+ subject_id: string;
23
+ sharer: PartyReference;
24
+ conversation: {
25
+ plane: ShareConversationPlane;
26
+ id: string;
27
+ tenant_id: string | null;
28
+ };
29
+ message_id: string | null;
30
+ shared_at: string;
31
+ }
32
+ /** `{data, replayed}` — `replayed` is true when the Idempotency-Key repeated an earlier share (core replays the first answer with `Idempotency-Replay: true`; the SDK sets `replayed` from it). */
33
+ export interface ShareOutcome {
34
+ data: Share[];
35
+ replayed: boolean;
36
+ }
37
+ /** The subject as ONE viewer may see it now. */
38
+ export interface ShareCardContent {
39
+ module: 'sharing' | string;
40
+ card_type: string;
41
+ external_id: string;
42
+ title: BilingualText;
43
+ summary: BilingualText | null;
44
+ image_url: string | null;
45
+ owner: PartyReference | null;
46
+ owner_display_name: string | null;
47
+ visibility: string;
48
+ /** A path on the platform's origin — the subject's own screen. */
49
+ deep_link: string;
50
+ actions: never[];
51
+ }
52
+ /** One share rendered for the viewer: `card` is null whenever `state` is `unavailable`. */
53
+ export interface SharedCardView {
54
+ share_id: string;
55
+ subject_type: string;
56
+ subject_id: string;
57
+ sharer: PartyReference;
58
+ conversation: {
59
+ plane: ShareConversationPlane;
60
+ id: string;
61
+ tenant_id: string | null;
62
+ };
63
+ message_id: string | null;
64
+ shared_at: string;
65
+ state: 'available' | 'unavailable';
66
+ card: ShareCardContent | null;
67
+ }
68
+ /** POST /api/person/shares/links — issue a signed link. */
69
+ export interface IssueShareLinkRequest {
70
+ subject_type: string;
71
+ subject_id: string;
72
+ /** 5 minutes to 365 days; the default is 30 days. */
73
+ lifetime_seconds?: number | null;
74
+ }
75
+ export interface ShareLink {
76
+ token: string;
77
+ /** `/s/{token}` — the path that unfurls and then opens the app. */
78
+ path: string;
79
+ url: string;
80
+ expires_at: string;
81
+ }
82
+ /** The server's limits, mirrored so a caller can batch before calling. */
83
+ export declare const MAXIMUM_SHARE_CONVERSATIONS = 10;
84
+ export declare const MAXIMUM_SHARED_CARDS_PER_REQUEST = 50;
85
+ export declare function createSharesNamespace(http: Http): {
86
+ /**
87
+ * POST — share into conversations (all or nothing). 201 with the new shares; 200 with the
88
+ * same shares when the Idempotency-Key replays. Refusals carry a stable `reason`:
89
+ * `subject_not_found`, `conversation_not_found`, `conversation_unavailable`,
90
+ * `too_many_conversations`, `share_budget_exhausted`, `sharing_unavailable`.
91
+ */
92
+ intoConversations: (request: ShareIntoConversationsRequest, options?: PersonDomainCallOptions) => Promise<ShareOutcome>;
93
+ /**
94
+ * POST /cards — the viewer's live cards for up to fifty share ids, in ONE call. Ids that are
95
+ * not the viewer's to see are absent from the answer; render those as unavailable.
96
+ */
97
+ cards: (shareIds: string[], options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<SharedCardView[]>>;
98
+ /** POST /links — issue a signed, expiring link. */
99
+ issueLink: (request: IssueShareLinkRequest, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ShareLink>>;
100
+ /** GET /links/{token} — open a link as the signed-in viewer. 404 opens nothing; 410 expired or revoked. */
101
+ openLink: (token: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<ShareCardContent>>;
102
+ /** GET /api/public/shares/{token} — open a link with no viewer (what anyone holding it may see). */
103
+ openPublicLink: (token: string, options?: Pick<PersonDomainCallOptions, "signal">) => Promise<PersonDomainEnvelope<ShareCardContent>>;
104
+ };
105
+ export type SharesNamespace = ReturnType<typeof createSharesNamespace>;
package/dist/shares.js ADDED
@@ -0,0 +1,27 @@
1
+ import { personDomainRequest, } from './actors.js';
2
+
3
+ export const MAXIMUM_SHARE_CONVERSATIONS = 10;
4
+ export const MAXIMUM_SHARED_CARDS_PER_REQUEST = 50;
5
+ const BASE = '/api/person/shares';
6
+ const TOKEN = /^[A-Za-z0-9._-]{16,512}$/;
7
+ function assertToken(token) {
8
+ if (!TOKEN.test(token))
9
+ throw new Error('A share link token is 16 to 512 characters of [A-Za-z0-9._-].');
10
+ return encodeURIComponent(token);
11
+ }
12
+ export function createSharesNamespace(http) {
13
+ const read = (options) => personDomainRequest(options, false);
14
+ const write = (options) => personDomainRequest(options, true);
15
+ return {
16
+
17
+ intoConversations: (request, options) => http.post(BASE, request, write(options)),
18
+
19
+ cards: (shareIds, options) => http.post(`${BASE}/cards`, { share_ids: shareIds.slice(0, MAXIMUM_SHARED_CARDS_PER_REQUEST) }, read(options)),
20
+
21
+ issueLink: (request, options) => http.post(`${BASE}/links`, request, write(options)),
22
+
23
+ openLink: (token, options) => http.get(`${BASE}/links/${assertToken(token)}`, read(options)),
24
+
25
+ openPublicLink: (token, options) => http.get(`/api/public/shares/${assertToken(token)}`, read(options)),
26
+ };
27
+ }