@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,61 @@
1
+
2
+
3
+ import { sumMoney as sum, toScaledUnits } from './money.js';
4
+
5
+ export const DEFERRED_REVENUE_CODE = '2300';
6
+ export function createFinanceInsights(accounting) {
7
+
8
+ async function loadDeferredPosition(asOf) {
9
+ const report = await accounting.reports.accountBalances({ as_of: asOf });
10
+ const acct = report.accounts.find((a) => a.code === DEFERRED_REVENUE_CODE);
11
+ if (!acct) {
12
+ return { accountExists: false, accountUuid: null, balance: '0.00', asOf };
13
+ }
14
+
15
+ const magnitude = acct.balance.startsWith('-') ? acct.balance.slice(1) : acct.balance;
16
+ return { accountExists: true, accountUuid: acct.uuid, balance: magnitude, asOf };
17
+ }
18
+
19
+ async function loadRecognitionMovement(from, to) {
20
+ const pos = await loadDeferredPosition(to);
21
+ if (!pos.accountExists || !pos.accountUuid) {
22
+ return { accountExists: false, from, to, openingBalance: '0.00', closingBalance: '0.00', deferred: '0.00', recognized: '0.00', netChange: '0.00' };
23
+ }
24
+ const gl = await accounting.reports.generalLedger({ account_id: pos.accountUuid, from, to });
25
+ const recognized = sum(gl.lines.map((l) => l.debit));
26
+ const deferred = sum(gl.lines.map((l) => l.credit));
27
+ return {
28
+ accountExists: true,
29
+ from,
30
+ to,
31
+ openingBalance: gl.opening_balance.startsWith('-') ? gl.opening_balance.slice(1) : gl.opening_balance,
32
+ closingBalance: gl.closing_balance.startsWith('-') ? gl.closing_balance.slice(1) : gl.closing_balance,
33
+ deferred,
34
+ recognized,
35
+ netChange: sum([deferred, `-${recognized}`]),
36
+ };
37
+ }
38
+
39
+ const OPEN_CLAIM_STATUSES = ['submitted', 'adjudicated'];
40
+ async function loadInsuranceSplit() {
41
+ const [aging, submitted, adjudicated] = await Promise.all([
42
+ accounting.arAging(),
43
+ accounting.claims.list({ status: 'submitted', per_page: 500 }),
44
+ accounting.claims.list({ status: 'adjudicated', per_page: 500 }).catch(() => ({ data: [] })),
45
+ ]);
46
+ const patientAr = sum(Object.values(aging.buckets).map((b) => b.total));
47
+ const openClaims = [...submitted.data, ...adjudicated.data].filter((c) => OPEN_CLAIM_STATUSES.includes(c.status));
48
+
49
+ const insurerAr = sum(openClaims.map((c) => sum([c.billed_amount, `-${c.paid_amount ?? '0'}`])));
50
+ const total = sum([patientAr, insurerAr]);
51
+ const totalUnits = toScaledUnits(total);
52
+ return {
53
+ patientAr,
54
+ insurerAr,
55
+ total,
56
+ insurerShare: totalUnits > 0n ? Number(toScaledUnits(insurerAr)) / Number(totalUnits) : null,
57
+ openClaimCount: openClaims.length,
58
+ };
59
+ }
60
+ return { loadDeferredPosition, loadRecognitionMovement, loadInsuranceSplit };
61
+ }
@@ -0,0 +1,155 @@
1
+ import type { Http } from './http.js';
2
+ import type { LaravelPaginator, ListQuery } from './types.js';
3
+ export type DepreciationMethod = 'straight_line' | 'declining_balance';
4
+ export type AssetStatus = 'active' | 'disposed' | 'fully_depreciated';
5
+ export interface DepreciationEntry {
6
+ id: string;
7
+ tenant_id?: string;
8
+ asset_id: string;
9
+ period_date: string;
10
+ depreciation_amount: string;
11
+ book_value_after: string;
12
+ journal_entry_id: string | null;
13
+ created_at: string | null;
14
+ updated_at: string | null;
15
+ }
16
+ /** Raw `FixedAsset` model. `book_value` is NOT serialized — compute client-side. */
17
+ export interface FixedAsset {
18
+ id: string;
19
+ tenant_id?: string;
20
+ asset_number: string;
21
+ name_en: string;
22
+ name_ar: string | null;
23
+ description: string | null;
24
+ location: string | null;
25
+ cost: string;
26
+ residual_value: string;
27
+ accumulated_depreciation: string;
28
+ depreciation_method: DepreciationMethod;
29
+ useful_life_months: number | null;
30
+ placed_in_service_on: string;
31
+ fully_depreciated_on: string | null;
32
+ status: AssetStatus;
33
+ disposed_on: string | null;
34
+ disposal_proceeds: string | null;
35
+ disposal_notes: string | null;
36
+ category_id: string | null;
37
+ /** A currency UUID (`acc_currencies.uuid`), NOT a currency code. */
38
+ currency_id: string | null;
39
+ asset_account_id: string | null;
40
+ accum_depr_account_id: string | null;
41
+ depr_expense_account_id: string | null;
42
+ depreciation_method_overridden: boolean;
43
+ useful_life_overridden: boolean;
44
+ residual_value_overridden: boolean;
45
+ created_by?: string;
46
+ created_at: string | null;
47
+ updated_at: string | null;
48
+ deleted_at: string | null;
49
+ /** Eager-loaded on list. */
50
+ category?: AssetCategory | null;
51
+ currency?: Record<string, unknown> | null;
52
+ /** Embedded on `get` (show) — realized/posted history rows (no forward schedule). */
53
+ depreciation_entries?: DepreciationEntry[];
54
+ }
55
+ export interface CreateAssetInput {
56
+ name_en: string;
57
+ name_ar?: string | null;
58
+ category_id: string;
59
+ currency_id?: string | null;
60
+ description?: string | null;
61
+ cost: number | string;
62
+ residual_value?: number | string | null;
63
+ depreciation_method?: DepreciationMethod | null;
64
+ useful_life_months?: number | null;
65
+ placed_in_service_on: string;
66
+ asset_number?: string | null;
67
+ }
68
+ /** `update` accepts only these three (mapped internally to name_en/location/description). */
69
+ export interface UpdateAssetInput {
70
+ name?: string;
71
+ location?: string | null;
72
+ notes?: string | null;
73
+ }
74
+ export interface DisposeAssetInput {
75
+ disposed_on: string;
76
+ proceeds?: number | string | null;
77
+ notes?: string | null;
78
+ }
79
+ export interface AssetListQuery extends ListQuery {
80
+ status?: AssetStatus;
81
+ category_id?: string;
82
+ }
83
+ export interface AssetCategory {
84
+ id: string;
85
+ tenant_id?: string;
86
+ name_en: string;
87
+ name_ar: string | null;
88
+ slug: string;
89
+ is_default: boolean;
90
+ is_active: boolean;
91
+ depreciation_method: 'straight_line' | 'declining_balance' | 'sum_of_years' | 'units_of_production' | null;
92
+ useful_life_months: number | null;
93
+ residual_value_pct: string | null;
94
+ asset_account_id: string | null;
95
+ accum_depr_account_id: string | null;
96
+ depr_expense_account_id: string | null;
97
+ parent_id: string | null;
98
+ sort_order: number;
99
+ code: string | null;
100
+ created_at: string | null;
101
+ updated_at: string | null;
102
+ }
103
+ export interface CreateAssetCategoryInput {
104
+ name_en: string;
105
+ name_ar?: string | null;
106
+ depreciation_method?: AssetCategory['depreciation_method'];
107
+ useful_life_months?: number | null;
108
+ residual_value_pct?: number | null;
109
+ asset_account_id?: string | null;
110
+ accum_depr_account_id?: string | null;
111
+ depr_expense_account_id?: string | null;
112
+ code?: string | null;
113
+ parent_id?: string | null;
114
+ is_active?: boolean;
115
+ }
116
+ /**
117
+ * Body for `PUT /fixed-assets/categories/{id}` — partial: core writes only the keys you
118
+ * send (AssetCategoryController::update). An omitted key keeps its stored value; a key sent
119
+ * as `null` clears that field. Sending the whole category still works as a full replacement.
120
+ */
121
+ export type UpdateAssetCategoryInput = Partial<CreateAssetCategoryInput> & {
122
+ sort_order?: number;
123
+ };
124
+ /** Result of `runDepreciation` — a tenant-wide idempotent batch. */
125
+ export interface RunDepreciationResult {
126
+ posted: number;
127
+ skipped: number;
128
+ }
129
+ export declare function createFixedAssetsNamespace(http: Http): {
130
+ assets: {
131
+ /** GET /api/fixed-assets — RAW Laravel paginator. */
132
+ list: (query?: AssetListQuery) => Promise<LaravelPaginator<FixedAsset>>;
133
+ /** GET /api/fixed-assets/{id} — bare asset with embedded `depreciation_entries`. */
134
+ get: (id: string) => Promise<FixedAsset>;
135
+ /** POST /api/fixed-assets */
136
+ create: (input: CreateAssetInput) => Promise<FixedAsset>;
137
+ /** PATCH /api/fixed-assets/{id} */
138
+ update: (id: string, input: UpdateAssetInput) => Promise<FixedAsset>;
139
+ /** POST /api/fixed-assets/{id}/dispose */
140
+ dispose: (id: string, input: DisposeAssetInput) => Promise<FixedAsset>;
141
+ };
142
+ /** POST /api/fixed-assets/run-depreciation — tenant-wide batch for a period. */
143
+ runDepreciation: (periodDate: string) => Promise<RunDepreciationResult>;
144
+ categories: {
145
+ /** GET /api/fixed-assets/categories — `{ data }` only (no meta). */
146
+ list: () => Promise<{
147
+ data: AssetCategory[];
148
+ }>;
149
+ /** POST /api/fixed-assets/categories */
150
+ create: (input: CreateAssetCategoryInput) => Promise<AssetCategory>;
151
+ /** PUT /api/fixed-assets/categories/{id} */
152
+ update: (id: string, input: UpdateAssetCategoryInput) => Promise<AssetCategory>;
153
+ };
154
+ };
155
+ export type FixedAssetsNamespace = ReturnType<typeof createFixedAssetsNamespace>;
@@ -0,0 +1,28 @@
1
+ export function createFixedAssetsNamespace(http) {
2
+ return {
3
+ assets: {
4
+
5
+ list: (query) => http.get('/api/fixed-assets', { params: query }),
6
+
7
+ get: (id) => http.get(`/api/fixed-assets/${id}`),
8
+
9
+ create: (input) => http.post('/api/fixed-assets', input),
10
+
11
+ update: (id, input) => http.patch(`/api/fixed-assets/${id}`, input),
12
+
13
+ dispose: (id, input) => http.post(`/api/fixed-assets/${id}/dispose`, input),
14
+ },
15
+
16
+ runDepreciation: (periodDate) => http.post('/api/fixed-assets/run-depreciation', {
17
+ period_date: periodDate,
18
+ }),
19
+ categories: {
20
+
21
+ list: () => http.get('/api/fixed-assets/categories'),
22
+
23
+ create: (input) => http.post('/api/fixed-assets/categories', input),
24
+
25
+ update: (id, input) => http.put(`/api/fixed-assets/categories/${id}`, input),
26
+ },
27
+ };
28
+ }
@@ -0,0 +1,405 @@
1
+ import type { Http } from './http.js';
2
+ import { type BilingualText, type PersonDomainCallOptions, type PersonDomainEnvelope } from './actors.js';
3
+ export type FulfilmentJobStatus = 'unassigned' | 'offered' | 'assigned' | 'in_progress' | 'completed' | 'partially_completed' | 'failed' | 'cancelled';
4
+ export type FulfilmentRunStatus = 'planned' | 'offered' | 'assigned' | 'in_progress' | 'completed' | 'cancelled';
5
+ export type FulfilmentStopStatus = 'pending' | 'en_route' | 'arrived' | 'completed' | 'failed' | 'cancelled';
6
+ export type FulfilmentStopKind = 'pickup' | 'drop';
7
+ export type FulfilmentProof = 'one_time_code' | 'photo' | 'signature' | 'none';
8
+ /** How a run's stops were ordered. Say it on screen: anything but `router` is a guess about roads. */
9
+ export type FulfilmentStopOrdering = 'router' | 'as_scheduled' | 'straight_line';
10
+ export type FulfilmentAssignment = 'own_staff' | 'shared_pool' | 'off';
11
+ export type FulfilmentCourierResponse = 'assigned_directly' | 'accept_or_decline';
12
+ export type FulfilmentFailureReason = 'recipient_absent' | 'address_not_found' | 'recipient_refused' | 'wrong_code' | 'goods_damaged' | 'goods_not_ready' | 'unsafe_to_deliver' | 'vehicle_problem' | 'other';
13
+ /** The reasons a fulfilment write may be refused with (422 unless marked 409). */
14
+ export type FulfilmentRefusalReason = 'dispatch_off' | 'batch_too_large' | 'already_picked_up' | 'job_not_batchable' | 'run_not_assignable' | 'pool_not_allowed' | 'not_a_courier' | 'response_not_expected' | 'not_offered_to_pool' | 'run_not_startable' | 'day_not_open' | 'stop_out_of_order' | 'proof_missing' | 'code_mismatch' | 'code_locked' | 'cash_mismatch' | 'note_required' | 'reason_not_for_pickup';
15
+ /** Reasons that may be given at a pickup point (the rest only at a door). */
16
+ export declare const PICKUP_FAILURE_REASONS: readonly FulfilmentFailureReason[];
17
+ export interface FulfilmentPlace {
18
+ label: string | null;
19
+ address: string | null;
20
+ /** Null when the place was never pinned (a pickup) or was erased. */
21
+ latitude: string | null;
22
+ longitude: string | null;
23
+ }
24
+ export interface FulfilmentItem {
25
+ description: string;
26
+ quantity: string;
27
+ }
28
+ /** One door of a job, as the dispatcher sees it. Never carries the one-time code. */
29
+ export interface FulfilmentDrop {
30
+ id: string;
31
+ sequence: number;
32
+ recipient_first_name: string;
33
+ /** The recipient can follow the delivery live in the person app. */
34
+ has_recipient_account: boolean;
35
+ destination: FulfilmentPlace;
36
+ /** Empty: the job's items. */
37
+ items: FulfilmentItem[];
38
+ cash_to_collect_amount: string;
39
+ cash_collected_amount: string | null;
40
+ status: FulfilmentStopStatus;
41
+ status_label: BilingualText;
42
+ failure_reason: FulfilmentFailureReason | null;
43
+ failure_reason_label: BilingualText | null;
44
+ failure_note: string | null;
45
+ proof_kind: FulfilmentProof | null;
46
+ has_proof_file: boolean;
47
+ arrived_at: string | null;
48
+ finished_at: string | null;
49
+ }
50
+ export interface FulfilmentJob {
51
+ id: string;
52
+ /** The scheduling module's own key (`shop.order:<id>`), for tracing. */
53
+ source_reference: string;
54
+ display_reference: string | null;
55
+ status: FulfilmentJobStatus;
56
+ status_label: BilingualText;
57
+ proof_required: FulfilmentProof;
58
+ proof_label: BilingualText;
59
+ pickup: FulfilmentPlace;
60
+ window_starts_at: string | null;
61
+ window_ends_at: string | null;
62
+ /** The window has ended and the job is not finished. */
63
+ is_late: boolean;
64
+ items: FulfilmentItem[];
65
+ currency_code: string | null;
66
+ cash_to_collect_total: string;
67
+ notes: string | null;
68
+ run_id: string | null;
69
+ drops: FulfilmentDrop[];
70
+ picked_up_at: string | null;
71
+ finished_at: string | null;
72
+ cancelled_at: string | null;
73
+ cancellation_reason: string | null;
74
+ created_at: string | null;
75
+ }
76
+ /** A stop on a run, as the dispatcher sees it. */
77
+ export interface FulfilmentRunStop {
78
+ id: string;
79
+ sequence: number;
80
+ kind: FulfilmentStopKind;
81
+ kind_label: BilingualText;
82
+ status: FulfilmentStopStatus;
83
+ status_label: BilingualText;
84
+ job_id: string;
85
+ display_reference: string | null;
86
+ label: string | null;
87
+ recipient_first_name: string | null;
88
+ latitude: string | null;
89
+ longitude: string | null;
90
+ /** Seconds after the run starts, from the road router; null otherwise. */
91
+ estimated_arrival_offset_seconds: number | null;
92
+ failure_reason: FulfilmentFailureReason | null;
93
+ failure_reason_label: BilingualText | null;
94
+ arrived_at: string | null;
95
+ finished_at: string | null;
96
+ }
97
+ export interface FulfilmentCourierPosition {
98
+ latitude: string;
99
+ longitude: string;
100
+ reported_at: string;
101
+ }
102
+ /** A run, as the dispatcher sees it. */
103
+ export interface FulfilmentRun {
104
+ id: string;
105
+ run_date: string;
106
+ status: FulfilmentRunStatus;
107
+ status_label: BilingualText;
108
+ courier: {
109
+ person_id: string;
110
+ name: string | null;
111
+ } | null;
112
+ assignment_mode: Exclude<FulfilmentAssignment, 'off'> | null;
113
+ /** Named, waiting for accept or decline. */
114
+ awaiting_courier_answer: boolean;
115
+ declined_reason: string | null;
116
+ ordered_by: FulfilmentStopOrdering;
117
+ ordered_by_label: BilingualText;
118
+ estimated_duration_seconds: number | null;
119
+ estimated_distance_metres: number | null;
120
+ courier_position: FulfilmentCourierPosition | null;
121
+ progress: {
122
+ stops: number;
123
+ finished: number;
124
+ failed: number;
125
+ };
126
+ stops: FulfilmentRunStop[];
127
+ journey_plan_id: string | null;
128
+ assigned_at: string | null;
129
+ accepted_at: string | null;
130
+ started_at: string | null;
131
+ completed_at: string | null;
132
+ cancelled_at: string | null;
133
+ }
134
+ export type FulfilmentDelayCode = 'late_job' | 'waiting_for_answer' | 'unclaimed_in_pool' | 'courier_silent' | 'failed_stops';
135
+ export interface FulfilmentDelay {
136
+ code: FulfilmentDelayCode;
137
+ /** 0–100; the list is sorted highest first. */
138
+ severity: number;
139
+ job_id: string | null;
140
+ run_id: string | null;
141
+ label: BilingualText;
142
+ detail: BilingualText;
143
+ }
144
+ export interface FulfilmentBoard {
145
+ run_date: string;
146
+ as_of: string;
147
+ delays: FulfilmentDelay[];
148
+ unassigned_jobs: FulfilmentJob[];
149
+ runs: FulfilmentRun[];
150
+ totals: {
151
+ unassigned_jobs: number;
152
+ runs: number;
153
+ runs_under_way: number;
154
+ runs_waiting: number;
155
+ delays: number;
156
+ };
157
+ }
158
+ /** A stop as the COURIER sees it: the place, a first name, items, proof and cash — nothing more. */
159
+ export interface CourierStop {
160
+ id: string;
161
+ sequence: number;
162
+ kind: FulfilmentStopKind;
163
+ kind_label: BilingualText;
164
+ status: FulfilmentStopStatus;
165
+ status_label: BilingualText;
166
+ display_reference: string | null;
167
+ place: FulfilmentPlace;
168
+ /** A maps directions link to the stop, or null when it has no point. */
169
+ navigate_url: string | null;
170
+ recipient_first_name: string | null;
171
+ items: FulfilmentItem[];
172
+ proof_required: FulfilmentProof;
173
+ proof_label: BilingualText | null;
174
+ cash_to_collect_amount: string | null;
175
+ currency_code: string | null;
176
+ window_starts_at: string | null;
177
+ window_ends_at: string | null;
178
+ notes: string | null;
179
+ failure_reason: FulfilmentFailureReason | null;
180
+ failure_reason_label: BilingualText | null;
181
+ arrived_at: string | null;
182
+ finished_at: string | null;
183
+ }
184
+ export interface CourierRun {
185
+ id: string;
186
+ run_date: string;
187
+ status: FulfilmentRunStatus;
188
+ status_label: BilingualText;
189
+ ordered_by: FulfilmentStopOrdering;
190
+ ordered_by_label: BilingualText;
191
+ can_accept: boolean;
192
+ can_decline: boolean;
193
+ can_claim: boolean;
194
+ can_start: boolean;
195
+ estimated_duration_seconds: number | null;
196
+ estimated_distance_metres: number | null;
197
+ /** The cash he will hold at the end of the run. */
198
+ cash_to_collect_total: string;
199
+ currency_code: string | null;
200
+ next_stop_id: string | null;
201
+ stops: CourierStop[];
202
+ }
203
+ export interface FulfilmentCourier {
204
+ person_id: string;
205
+ name: string | null;
206
+ role: 'courier' | 'field_representative' | 'field_supervisor';
207
+ }
208
+ export interface FulfilmentPolicyChoice<TValue extends string> {
209
+ /** The request field this choice is written under in `updatePolicies`. */
210
+ field: keyof UpdateFulfilmentPoliciesRequest;
211
+ key: string;
212
+ label: BilingualText;
213
+ default: TValue;
214
+ levels: string[];
215
+ options: Array<{
216
+ value: TValue;
217
+ label: BilingualText;
218
+ }>;
219
+ value: TValue;
220
+ /** Where the value in force was decided: `platform`, `vertical` or `organisation`. */
221
+ decided_at: string;
222
+ /** This organisation's own choice; null when it inherits. */
223
+ chosen: TValue | null;
224
+ }
225
+ export interface FulfilmentPolicies {
226
+ assignment: FulfilmentPolicyChoice<FulfilmentAssignment>;
227
+ courier_response: FulfilmentPolicyChoice<FulfilmentCourierResponse>;
228
+ stop_ordering_fallback: FulfilmentPolicyChoice<'as_scheduled' | 'straight_line'>;
229
+ }
230
+ /** Send only what changes; `null` returns a choice to the inherited answer. */
231
+ export interface UpdateFulfilmentPoliciesRequest {
232
+ assignment?: FulfilmentAssignment | null;
233
+ courier_response?: FulfilmentCourierResponse | null;
234
+ stop_ordering_fallback?: 'as_scheduled' | 'straight_line' | null;
235
+ }
236
+ export interface ListFulfilmentJobsQuery {
237
+ status?: FulfilmentJobStatus;
238
+ /** Only jobs not yet in a run. */
239
+ waiting?: boolean;
240
+ search?: string;
241
+ sort?: 'created_at' | 'window';
242
+ per_page?: number;
243
+ cursor?: string | null;
244
+ }
245
+ export interface FulfilmentJobPage {
246
+ data: FulfilmentJob[];
247
+ meta: {
248
+ next_cursor: string | null;
249
+ per_page: number;
250
+ };
251
+ }
252
+ /** Delivered: the proof the job requires and the cash it collects. */
253
+ export interface CompleteFulfilmentStopRequest {
254
+ /** The code the recipient reads out (`one_time_code`). Spaces and dashes are ignored. */
255
+ code?: string | null;
256
+ /** From `uploadProof`'s staged upload (`photo` / `signature`). */
257
+ staged_file_token?: string | null;
258
+ /** The device's idempotency key for that file (a uuid). */
259
+ client_reference?: string | null;
260
+ captured_at?: string | null;
261
+ /** Required when the drop collects cash; must equal `cash_to_collect_amount`. */
262
+ cash_collected_amount?: string | null;
263
+ }
264
+ export interface FailFulfilmentStopRequest {
265
+ reason: FulfilmentFailureReason;
266
+ /** Required with `other`. Up to 500 characters. */
267
+ note?: string | null;
268
+ }
269
+ /** The recipient's live view of their own delivery. */
270
+ export interface FulfilmentTracking {
271
+ display_reference: string | null;
272
+ organisation_name: string | null;
273
+ status: FulfilmentStopStatus;
274
+ status_label: BilingualText;
275
+ job_status: FulfilmentJobStatus;
276
+ job_status_label: BilingualText;
277
+ recipient_first_name: string;
278
+ destination: FulfilmentPlace;
279
+ window_starts_at: string | null;
280
+ window_ends_at: string | null;
281
+ courier_first_name: string | null;
282
+ /** Only while this delivery is the one being made and fresher than 15 minutes. */
283
+ courier_position: FulfilmentCourierPosition | null;
284
+ stops_before_yours: number | null;
285
+ proof_required: FulfilmentProof;
286
+ proof_label: BilingualText;
287
+ /** The code to read to the courier; until the delivery finishes. */
288
+ one_time_code: string | null;
289
+ failure_reason: FulfilmentFailureReason | null;
290
+ failure_reason_label: BilingualText | null;
291
+ arrived_at: string | null;
292
+ finished_at: string | null;
293
+ /** Poll again after this many seconds. */
294
+ refresh_after_seconds: number;
295
+ }
296
+ export declare function createFulfilmentJobsNamespace(http: Http): {
297
+ /** The dispatcher's screens. Needs `field-ops.fulfilment.dispatch`. */
298
+ dispatch: {
299
+ /** GET /board — the day (default today): delays first, waiting jobs, runs with stops and live positions. */
300
+ board: (runDate?: string) => Promise<{
301
+ data: FulfilmentBoard;
302
+ }>;
303
+ /** GET /jobs — cursor-paginated; follow `meta.next_cursor` until null. */
304
+ jobs: (query?: ListFulfilmentJobsQuery) => Promise<FulfilmentJobPage>;
305
+ /** GET /jobs/{id} — one job with its drops. */
306
+ job: (jobId: string) => Promise<{
307
+ data: FulfilmentJob;
308
+ }>;
309
+ /** POST /jobs/{id}/cancel — before pickup only (409 `already_picked_up`). Idempotent. */
310
+ cancelJob: (jobId: string, reason: string) => Promise<{
311
+ data: FulfilmentJob;
312
+ }>;
313
+ /** GET /runs — the date's runs (default today), withdrawn ones included. */
314
+ runs: (runDate?: string) => Promise<{
315
+ data: FulfilmentRun[];
316
+ }>;
317
+ /** GET /runs/{id}. */
318
+ run: (runId: string) => Promise<{
319
+ data: FulfilmentRun;
320
+ }>;
321
+ /**
322
+ * POST /runs — batch waiting jobs (1–100) into a run for a date. 201. The stops are ordered
323
+ * by the road router when it answers, else by the organisation's fallback (`ordered_by`).
324
+ * 409 `job_not_batchable` when a job is already in a run or finished.
325
+ */
326
+ createRun: (jobIds: string[], runDate: string) => Promise<{
327
+ data: FulfilmentRun;
328
+ }>;
329
+ /** POST /runs/{id}/assign — name a courier (one of `couriers()`); under `accept_or_decline` it waits for his answer. */
330
+ assign: (runId: string, courierPersonId: string) => Promise<{
331
+ data: FulfilmentRun;
332
+ }>;
333
+ /** POST /runs/{id}/offer-to-pool — only under the `shared_pool` policy (422 `pool_not_allowed`). */
334
+ offerToPool: (runId: string) => Promise<{
335
+ data: FulfilmentRun;
336
+ }>;
337
+ /** POST /runs/{id}/withdraw — take it back before it starts; its jobs wait for a new run. */
338
+ withdraw: (runId: string) => Promise<{
339
+ data: FulfilmentRun;
340
+ }>;
341
+ /** GET /couriers — members who may carry runs, by name. */
342
+ couriers: () => Promise<{
343
+ data: FulfilmentCourier[];
344
+ }>;
345
+ /** GET /policies — the three dispatch choices, each with options and the value in force. */
346
+ policies: () => Promise<{
347
+ data: FulfilmentPolicies;
348
+ }>;
349
+ /** PUT /policies — also needs `field-ops.settings.manage`. */
350
+ updatePolicies: (request: UpdateFulfilmentPoliciesRequest) => Promise<{
351
+ data: FulfilmentPolicies;
352
+ }>;
353
+ };
354
+ /** The courier's screens ("My deliveries"). Needs `field-ops.fulfilment.deliver`. */
355
+ courier: {
356
+ /** GET /runs/mine — his runs for a date (default today). */
357
+ myRuns: (runDate?: string) => Promise<{
358
+ data: CourierRun[];
359
+ }>;
360
+ /** GET /runs/pool — runs offered to the pool and not yet claimed (empty unless `shared_pool`). */
361
+ pool: () => Promise<{
362
+ data: CourierRun[];
363
+ }>;
364
+ /** GET /runs/{id}/courier-view — one of his runs, or a pool run he may claim; else 404. */
365
+ run: (runId: string) => Promise<{
366
+ data: CourierRun;
367
+ }>;
368
+ /** POST /runs/{id}/accept. */
369
+ accept: (runId: string) => Promise<{
370
+ data: CourierRun;
371
+ }>;
372
+ /** POST /runs/{id}/decline — 204; the dispatcher sees the reason. */
373
+ decline: (runId: string, reason: string) => Promise<void>;
374
+ /** POST /runs/{id}/claim — first claim wins (409 `not_offered_to_pool` after). */
375
+ claim: (runId: string) => Promise<{
376
+ data: CourierRun;
377
+ }>;
378
+ /** POST /runs/{id}/start — a cash run needs his open day (422 `day_not_open`). */
379
+ start: (runId: string) => Promise<{
380
+ data: CourierRun;
381
+ }>;
382
+ /** POST /runs/{id}/position — every ~30 s while under way; 204. */
383
+ reportPosition: (runId: string, latitude: number, longitude: number) => Promise<void>;
384
+ /** POST /stops/{id}/arrive — idempotent. */
385
+ arrive: (stopId: string) => Promise<{
386
+ data: CourierRun;
387
+ }>;
388
+ /** POST /stops/{id}/complete — picked up, or delivered with proof and cash. */
389
+ complete: (stopId: string, request?: CompleteFulfilmentStopRequest) => Promise<{
390
+ data: CourierRun;
391
+ }>;
392
+ /** POST /stops/{id}/fail — with a declared reason (and a note for `other`). */
393
+ fail: (stopId: string, request: FailFulfilmentStopRequest) => Promise<{
394
+ data: CourierRun;
395
+ }>;
396
+ /** The staged-upload base for a proof photo or signature (`upload-temp`, `temp`, `rules`). */
397
+ proofUploadBase: string;
398
+ };
399
+ /**
400
+ * GET /api/person/fulfilment-tracking/{organisationId}/{trackingToken} — the recipient's own
401
+ * delivery. Anyone else gets 404. Poll after `refresh_after_seconds`.
402
+ */
403
+ track: (organisationId: string, trackingToken: string, options?: PersonDomainCallOptions) => Promise<PersonDomainEnvelope<FulfilmentTracking>>;
404
+ };
405
+ export type FulfilmentJobsNamespace = ReturnType<typeof createFulfilmentJobsNamespace>;