@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,120 @@
1
+ export function createInventoryNamespace(http) {
2
+ return {
3
+ items: {
4
+
5
+ list: (query) => http.get('/api/inventory/items', { params: query }),
6
+
7
+ get: (id) => http.get(`/api/inventory/items/${id}`),
8
+
9
+ create: (input) => http.post('/api/inventory/items', input),
10
+
11
+ update: (id, input) => http.put(`/api/inventory/items/${id}`, input),
12
+
13
+ archive: (id) => http.post(`/api/inventory/items/${id}/archive`),
14
+
15
+ restore: (id) => http.post(`/api/inventory/items/${id}/restore`),
16
+
17
+ variants: (id) => http.get(`/api/inventory/items/${id}/variants`),
18
+ },
19
+ stock: {
20
+
21
+ levels: (query) => http.get('/api/inventory/stock/levels', { params: query }),
22
+
23
+ movements: (query) => http.get('/api/inventory/stock/movements', {
24
+ params: query,
25
+ }),
26
+ },
27
+ warehouses: {
28
+
29
+ list: (query) => http.get('/api/inventory/warehouses', { params: query }),
30
+
31
+ get: (id) => http.get(`/api/inventory/warehouses/${id}`),
32
+
33
+ create: (input) => http.post('/api/inventory/warehouses', input),
34
+
35
+ update: (id, input) => http.put(`/api/inventory/warehouses/${id}`, input),
36
+
37
+ bins: (id) => http.get(`/api/inventory/warehouses/${id}/bins`),
38
+
39
+ createBin: (warehouseId, input) => http.post(`/api/inventory/warehouses/${warehouseId}/bins`, input),
40
+
41
+ updateBin: (warehouseId, binId, input) => http.put(`/api/inventory/warehouses/${warehouseId}/bins/${binId}`, input),
42
+ },
43
+ uom: {
44
+
45
+ list: () => http.get('/api/inventory/uom'),
46
+
47
+ create: (input) => http.post('/api/inventory/uom', input),
48
+
49
+ update: (id, input) => http.put(`/api/inventory/uom/${id}`, input),
50
+
51
+ createConversion: (input) => http.post('/api/inventory/uom/conversions', input),
52
+
53
+ removeConversion: (id) => http.delete(`/api/inventory/uom/conversions/${id}`),
54
+ },
55
+ categories: {
56
+
57
+ list: () => http.get('/api/inventory/categories'),
58
+
59
+ create: (input) => http.post('/api/inventory/categories', input),
60
+
61
+ update: (id, input) => http.put(`/api/inventory/categories/${id}`, input),
62
+ },
63
+ adjustments: {
64
+
65
+ list: (query) => http.get('/api/inventory/adjustments', {
66
+ params: query,
67
+ }),
68
+
69
+ get: (uuid) => http.get(`/api/inventory/adjustments/${uuid}`),
70
+
71
+ create: (input) => http.post('/api/inventory/adjustments', input),
72
+
73
+ update: (uuid, input) => http.put(`/api/inventory/adjustments/${uuid}`, input),
74
+
75
+ remove: (uuid) => http.delete(`/api/inventory/adjustments/${uuid}`),
76
+
77
+ startCounting: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/start-counting`),
78
+
79
+ submitForReview: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/submit-for-review`),
80
+
81
+ sendBackToCounting: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/send-back-to-counting`),
82
+
83
+ approve: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/approve`),
84
+
85
+ post: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/post`),
86
+
87
+ cancel: (uuid) => http.post(`/api/inventory/adjustments/${uuid}/cancel`),
88
+ },
89
+ transfers: {
90
+
91
+ list: (query) => http.get('/api/inventory/transfers', {
92
+ params: query,
93
+ }),
94
+
95
+ get: (uuid) => http.get(`/api/inventory/transfers/${uuid}`),
96
+
97
+ create: (input) => http.post('/api/inventory/transfers', input),
98
+
99
+ update: (uuid, input) => http.put(`/api/inventory/transfers/${uuid}`, input),
100
+
101
+ remove: (uuid) => http.delete(`/api/inventory/transfers/${uuid}`),
102
+
103
+ ship: (uuid) => http.post(`/api/inventory/transfers/${uuid}/ship`),
104
+
105
+ receive: (uuid) => http.post(`/api/inventory/transfers/${uuid}/receive`),
106
+
107
+ cancel: (uuid) => http.post(`/api/inventory/transfers/${uuid}/cancel`),
108
+ },
109
+
110
+ goodsReceipts: {
111
+
112
+ list: (query) => http.get('/api/inventory/goods-receipts', {
113
+ params: query,
114
+ }),
115
+
116
+ get: (uuid) => http.get(`/api/inventory/goods-receipts/${uuid}`),
117
+ },
118
+
119
+ };
120
+ }
@@ -0,0 +1,211 @@
1
+ /** A pair in both languages. */
2
+ export interface ListLabel {
3
+ en: string;
4
+ ar: string;
5
+ }
6
+ export type ListSortDirection = 'asc' | 'desc';
7
+ export type ListFilterType = 'one_of' | 'boolean' | 'date_range' | 'instant_range' | 'decimal_range' | 'party' | 'identifier' | 'tag' | 'within_distance';
8
+ export interface ListSortDescription {
9
+ key: string;
10
+ label: ListLabel;
11
+ /** The directions the server accepts; a header toggles only between these. */
12
+ directions: ListSortDirection[];
13
+ value_type: 'Integer' | 'Decimal' | 'Instant' | 'Text' | 'Uuid';
14
+ /** v2: keys of `bound_parameters` this order needs (`['near']` for a distance). Absent = none. */
15
+ requires?: string[];
16
+ /** v2: true when this order needs a search (`relevance`). Absent = false. */
17
+ requires_search?: boolean;
18
+ }
19
+ export interface ListFilterOption {
20
+ value: string;
21
+ label: ListLabel;
22
+ }
23
+ interface ListFilterDescriptionBase {
24
+ key: string;
25
+ label: ListLabel;
26
+ /** v2: keys of `bound_parameters` this filter needs. Absent = none. */
27
+ requires?: string[];
28
+ }
29
+ export interface OneOfFilterDescription extends ListFilterDescriptionBase {
30
+ type: 'one_of';
31
+ options: ListFilterOption[];
32
+ multiple: true;
33
+ }
34
+ export interface BooleanFilterDescription extends ListFilterDescriptionBase {
35
+ type: 'boolean';
36
+ }
37
+ export interface DateRangeFilterDescription extends ListFilterDescriptionBase {
38
+ type: 'date_range';
39
+ /** The zone the server reads the days in when the request sends none. Send the reader's. */
40
+ default_time_zone: string;
41
+ maximum_days: number | null;
42
+ }
43
+ export interface InstantRangeFilterDescription extends ListFilterDescriptionBase {
44
+ type: 'instant_range';
45
+ }
46
+ export interface DecimalRangeFilterDescription extends ListFilterDescriptionBase {
47
+ type: 'decimal_range';
48
+ /** True when the range compares the size of a signed amount, either way. */
49
+ magnitude: boolean;
50
+ allow_negative: boolean;
51
+ pattern: string;
52
+ }
53
+ export interface PartyFilterDescription extends ListFilterDescriptionBase {
54
+ type: 'party';
55
+ accepted_kinds: Array<'person' | 'actor' | 'organisation'>;
56
+ }
57
+ export interface IdentifierFilterDescription extends ListFilterDescriptionBase {
58
+ type: 'identifier';
59
+ pattern: string;
60
+ }
61
+ export interface TagFilterDescription extends ListFilterDescriptionBase {
62
+ type: 'tag';
63
+ multiple: true;
64
+ match: 'any' | 'all';
65
+ maximum: number;
66
+ }
67
+ /** v2: kilometres from a point parameter — `filter[within]=25` with `near[...]`. */
68
+ export interface WithinDistanceFilterDescription extends ListFilterDescriptionBase {
69
+ type: 'within_distance';
70
+ point_parameter: string;
71
+ /** Decimal strings. */
72
+ minimum_kilometres: string;
73
+ maximum_kilometres: string;
74
+ }
75
+ export type ListFilterDescription = OneOfFilterDescription | BooleanFilterDescription | DateRangeFilterDescription | InstantRangeFilterDescription | DecimalRangeFilterDescription | PartyFilterDescription | IdentifierFilterDescription | TagFilterDescription | WithinDistanceFilterDescription;
76
+ export interface ListSearchDescription {
77
+ label: ListLabel;
78
+ strategy: 'folded_contains' | 'folded_prefix';
79
+ minimum_length: number;
80
+ maximum_length: number;
81
+ }
82
+ /** One typed part of a bound parameter (`near[latitude]`): a decimal between minimum and maximum. */
83
+ export interface ListParameterPartDescription {
84
+ name: string;
85
+ label: ListLabel;
86
+ minimum: string;
87
+ maximum: string;
88
+ scale: number;
89
+ }
90
+ /**
91
+ * v2: a typed value the list's sorts and filters bind, sent as its own key (`near[latitude]=…`).
92
+ * `kind: 'point'` has exactly the parts `latitude` and `longitude`; a UI draws its location picker.
93
+ */
94
+ export interface ListBoundParameterDescription {
95
+ key: string;
96
+ kind: 'point' | 'values';
97
+ label: ListLabel;
98
+ parts: ListParameterPartDescription[];
99
+ }
100
+ /** `meta.list` — what a list lets a client ask. */
101
+ export interface ListDeclarationDescription {
102
+ name: string;
103
+ version: number;
104
+ /** Wire form, e.g. `-posted_at`. */
105
+ default_sort: string;
106
+ default_limit: number;
107
+ maximum_limit: number;
108
+ sorts: ListSortDescription[];
109
+ filters: ListFilterDescription[];
110
+ search: ListSearchDescription | null;
111
+ /** v2: typed values sorts and filters may bind. Absent from servers before v2. */
112
+ bound_parameters?: ListBoundParameterDescription[];
113
+ parameters: {
114
+ sort: 'sort';
115
+ filter: 'filter';
116
+ search: 'search';
117
+ cursor: 'cursor';
118
+ limit: 'limit';
119
+ boolean_true: '1';
120
+ boolean_false: '0';
121
+ descending_prefix: '-';
122
+ list_separator: ',';
123
+ };
124
+ }
125
+ /** A day range: `YYYY-MM-DD` days read in `time_zone` (IANA); `to` is inclusive of the whole day. */
126
+ export interface DateRangeValue {
127
+ from?: string | null;
128
+ to?: string | null;
129
+ time_zone?: string | null;
130
+ }
131
+ /** An instant range: ISO 8601 WITH an offset (`2026-11-20T10:00:00+03:00`); both edges inclusive. */
132
+ export interface InstantRangeValue {
133
+ from?: string | null;
134
+ to?: string | null;
135
+ }
136
+ /** A decimal range as STRINGS (`"10.5"`); both edges inclusive. */
137
+ export interface DecimalRangeValue {
138
+ minimum?: string | null;
139
+ maximum?: string | null;
140
+ }
141
+ /** A filter's value, by filter type: string[] (one_of, tag), boolean, a range, or a string (party, identifier). */
142
+ export type ListFilterValue = string[] | boolean | string | DateRangeValue | InstantRangeValue | DecimalRangeValue;
143
+ /** `meta.query` — the question the server answered (its defaults included). */
144
+ export interface AppliedListQuery {
145
+ list: string;
146
+ version: number;
147
+ sort: string;
148
+ filter: Record<string, string[] | boolean | string | DateRangeValue | InstantRangeValue | DecimalRangeValue>;
149
+ search: string | null;
150
+ limit: number;
151
+ /** v2: the canonical parameters given (`{near: {latitude: '31.953949', …}}`), on lists that declare any. */
152
+ parameters?: Record<string, Record<string, string>>;
153
+ }
154
+ /** A parameter's parts: decimal strings (or finite numbers, written as plain decimals). */
155
+ export type ListParameterValue = Record<string, string | number>;
156
+ /** What a caller may ask. Every field is optional; an absent one takes the list's default. */
157
+ export interface ListQueryState {
158
+ /** Wire form: `posted_at` ascending, `-posted_at` descending. */
159
+ sort?: string | null;
160
+ filter?: Record<string, ListFilterValue | null | undefined>;
161
+ search?: string | null;
162
+ cursor?: string | null;
163
+ limit?: number | null;
164
+ /** Ask for `meta.list` (do it once, on the first page). */
165
+ describe?: boolean;
166
+ /** v2: declared parameters, by key — `{ near: listPoint(31.95, 35.91) }`. All parts or none. */
167
+ parameters?: Record<string, ListParameterValue | null | undefined>;
168
+ }
169
+ /** One page of a declared list. */
170
+ export interface ListPage<T> {
171
+ data: T[];
172
+ next_cursor: string | null;
173
+ meta?: {
174
+ query: AppliedListQuery;
175
+ list?: ListDeclarationDescription;
176
+ };
177
+ }
178
+ /** A point parameter from a position (a geolocation fix, a map tap): six decimals, as the server keeps it. */
179
+ export declare function listPoint(latitude: number, longitude: number): {
180
+ latitude: string;
181
+ longitude: string;
182
+ };
183
+ /** True when a sort can be asked with what is given (its parameters and search). */
184
+ export declare function listSortAvailable(sort: Pick<ListSortDescription, 'requires' | 'requires_search'>, given: {
185
+ parameters?: Record<string, unknown> | null;
186
+ search?: string | null;
187
+ }): boolean;
188
+ /**
189
+ * The query parameters for a list question — flat keys (`filter[x][from]`), ready for the SDK's
190
+ * `params`. Empty values are omitted; booleans are 1/0; decimals must already be strings (a
191
+ * number is refused here rather than sent with float noise).
192
+ */
193
+ export declare function listQueryParams(state?: ListQueryState): Record<string, string | number | undefined>;
194
+ /**
195
+ * Read a list question back from URL parameters (a shared link). With the list's declaration,
196
+ * values are typed per filter (booleans, comma lists); without it, a bracketed filter is a range
197
+ * and anything else stays a string. Unknown parameters are ignored; the server is the judge.
198
+ */
199
+ export declare function parseListQueryParams(params: URLSearchParams | Record<string, string>, declaration?: Pick<ListDeclarationDescription, 'filters' | 'bound_parameters'> | null): ListQueryState;
200
+ /** `-posted_at` → `{ key: 'posted_at', direction: 'desc' }`. */
201
+ export declare function parseListSort(wire: string): {
202
+ key: string;
203
+ direction: ListSortDirection;
204
+ };
205
+ /** `{ key, direction }` → `-posted_at` / `posted_at`. */
206
+ export declare function listSortWire(key: string, direction: ListSortDirection): string;
207
+ /** True when the refusal is a cursor issued for another question (start from the first page). */
208
+ export declare function isStaleListCursor(error: unknown): boolean;
209
+ /** True when a caller started new searches faster than the list allows (429). */
210
+ export declare function isListSearchTooFrequent(error: unknown): boolean;
211
+ export {};
@@ -0,0 +1,158 @@
1
+
2
+
3
+ import { refusalReason } from './http.js';
4
+ const DECIMAL = /^-?\d{1,15}(\.\d{1,4})?$/;
5
+ const RESERVED = new Set(['sort', 'filter', 'search', 'cursor', 'limit', 'describe']);
6
+
7
+ function decimalPart(value, where) {
8
+ if (typeof value === 'number') {
9
+ if (!Number.isFinite(value))
10
+ throw new TypeError(`${where} must be a finite number.`);
11
+ const fixed = value.toFixed(12).replace(/0+$/, '').replace(/\.$/, '');
12
+ return fixed === '-0' ? '0' : fixed;
13
+ }
14
+ const text = value.trim();
15
+ if (!/^-?\d{1,15}(\.\d{1,12})?$/.test(text))
16
+ throw new TypeError(`${where} is not a plain decimal: ${value}`);
17
+ return text;
18
+ }
19
+
20
+ export function listPoint(latitude, longitude) {
21
+ if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90)
22
+ throw new RangeError(`latitude out of range: ${latitude}`);
23
+ if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180)
24
+ throw new RangeError(`longitude out of range: ${longitude}`);
25
+ return { latitude: latitude.toFixed(6), longitude: longitude.toFixed(6) };
26
+ }
27
+
28
+ export function listSortAvailable(sort, given) {
29
+ const parameters = given.parameters ?? {};
30
+ const hasSearch = typeof given.search === 'string' && given.search.trim() !== '';
31
+ return (sort.requires ?? []).every((key) => parameters[key] !== null && parameters[key] !== undefined) && (!sort.requires_search || hasSearch);
32
+ }
33
+ function isRange(value) {
34
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
35
+ }
36
+
37
+ export function listQueryParams(state = {}) {
38
+ const params = {};
39
+ if (state.sort)
40
+ params.sort = state.sort;
41
+ if (state.search && state.search.trim() !== '')
42
+ params.search = state.search.trim();
43
+ if (state.cursor)
44
+ params.cursor = state.cursor;
45
+ if (typeof state.limit === 'number' && Number.isFinite(state.limit) && state.limit > 0)
46
+ params.limit = Math.floor(state.limit);
47
+ if (state.describe)
48
+ params.describe = 1;
49
+ for (const [key, value] of Object.entries(state.parameters ?? {})) {
50
+ if (value === null || value === undefined)
51
+ continue;
52
+ if (RESERVED.has(key))
53
+ throw new TypeError(`"${key}" is the list's own parameter, not a declared one.`);
54
+ for (const [part, partValue] of Object.entries(value)) {
55
+ params[`${key}[${part}]`] = decimalPart(partValue, `${key}[${part}]`);
56
+ }
57
+ }
58
+ for (const [key, value] of Object.entries(state.filter ?? {})) {
59
+ if (value === null || value === undefined)
60
+ continue;
61
+ if (Array.isArray(value)) {
62
+ const members = [...new Set(value.map((member) => String(member).trim()).filter((member) => member !== ''))];
63
+ if (members.length > 0)
64
+ params[`filter[${key}]`] = members.join(',');
65
+ continue;
66
+ }
67
+ if (typeof value === 'boolean') {
68
+ params[`filter[${key}]`] = value ? '1' : '0';
69
+ continue;
70
+ }
71
+ if (typeof value === 'string') {
72
+ if (value.trim() !== '')
73
+ params[`filter[${key}]`] = value.trim();
74
+ continue;
75
+ }
76
+ if (isRange(value)) {
77
+ for (const [edge, edgeValue] of Object.entries(value)) {
78
+ if (edgeValue === null || edgeValue === undefined || edgeValue === '')
79
+ continue;
80
+ if (typeof edgeValue !== 'string') {
81
+ throw new TypeError(`filter[${key}][${edge}] must be a string; send decimals and dates as text.`);
82
+ }
83
+ if ((edge === 'minimum' || edge === 'maximum') && !DECIMAL.test(edgeValue.trim())) {
84
+ throw new TypeError(`filter[${key}][${edge}] is not a plain decimal: ${edgeValue}`);
85
+ }
86
+ params[`filter[${key}][${edge}]`] = edgeValue.trim();
87
+ }
88
+ }
89
+ }
90
+ return params;
91
+ }
92
+
93
+ export function parseListQueryParams(params, declaration) {
94
+ const entries = params instanceof URLSearchParams ? [...params.entries()] : Object.entries(params);
95
+ const declared = declaration?.bound_parameters ? new Set(declaration.bound_parameters.map((parameter) => parameter.key)) : null;
96
+ const types = new Map((declaration?.filters ?? []).map((filter) => [filter.key, filter.type]));
97
+ const state = {};
98
+ const filter = {};
99
+ for (const [name, raw] of entries) {
100
+ if (name === 'sort')
101
+ state.sort = raw || null;
102
+ else if (name === 'search')
103
+ state.search = raw || null;
104
+ else if (name === 'cursor')
105
+ state.cursor = raw || null;
106
+ else if (name === 'limit') {
107
+ const limit = Number.parseInt(raw, 10);
108
+ if (Number.isFinite(limit) && limit > 0)
109
+ state.limit = limit;
110
+ }
111
+ else {
112
+ const ranged = /^filter\[([a-z][a-z0-9_]*)\]\[([a-z_]+)\]$/.exec(name);
113
+ const plain = /^filter\[([a-z][a-z0-9_]*)\]$/.exec(name);
114
+ const parameter = /^([a-z][a-z0-9_]*)\[([a-z][a-z0-9_]*)\]$/.exec(name);
115
+ if (parameter && !ranged && !plain && parameter[1] !== 'filter') {
116
+ const [, key, part] = parameter;
117
+ if (declared && !declared.has(key))
118
+ continue;
119
+ state.parameters = { ...(state.parameters ?? {}), [key]: { ...(state.parameters?.[key] ?? {}), [part]: raw } };
120
+ }
121
+ else if (ranged) {
122
+ const [, key, edge] = ranged;
123
+ const current = (isRange(filter[key]) ? filter[key] : {});
124
+ current[edge] = raw;
125
+ filter[key] = current;
126
+ }
127
+ else if (plain) {
128
+ const key = plain[1];
129
+ const type = types.get(key);
130
+ if (type === 'boolean')
131
+ filter[key] = raw === '1' || raw === 'true';
132
+ else if (type === 'one_of' || type === 'tag')
133
+ filter[key] = raw.split(',').map((part) => part.trim()).filter(Boolean);
134
+ else
135
+ filter[key] = raw;
136
+ }
137
+ }
138
+ }
139
+ if (Object.keys(filter).length > 0)
140
+ state.filter = filter;
141
+ return state;
142
+ }
143
+
144
+ export function parseListSort(wire) {
145
+ return wire.startsWith('-') ? { key: wire.slice(1), direction: 'desc' } : { key: wire, direction: 'asc' };
146
+ }
147
+
148
+ export function listSortWire(key, direction) {
149
+ return direction === 'desc' ? `-${key}` : key;
150
+ }
151
+
152
+ export function isStaleListCursor(error) {
153
+ return refusalReason(error) === 'cursor_invalid';
154
+ }
155
+
156
+ export function isListSearchTooFrequent(error) {
157
+ return refusalReason(error) === 'list_search_too_frequent';
158
+ }