@de./sdk 1.0.4 → 2.0.0

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 (383) hide show
  1. package/dist/allend/Access.d.ts +39 -3
  2. package/dist/allend/Access.js +147 -114
  3. package/dist/allend/Access.js.map +1 -1
  4. package/dist/allend/Agent/consolidation.d.ts +16 -0
  5. package/dist/allend/Agent/consolidation.js +38 -0
  6. package/dist/allend/Agent/consolidation.js.map +1 -0
  7. package/dist/allend/Agent/delivery.d.ts +11 -0
  8. package/dist/allend/Agent/delivery.js +43 -0
  9. package/dist/allend/Agent/delivery.js.map +1 -0
  10. package/dist/allend/Agent/dispatch.d.ts +8 -0
  11. package/dist/allend/Agent/dispatch.js +24 -0
  12. package/dist/allend/Agent/dispatch.js.map +1 -0
  13. package/dist/allend/Agent/index.d.ts +49 -0
  14. package/dist/allend/Agent/index.js +74 -0
  15. package/dist/allend/Agent/index.js.map +1 -0
  16. package/dist/allend/Agent/navigation.d.ts +8 -0
  17. package/dist/allend/Agent/navigation.js +25 -0
  18. package/dist/allend/Agent/navigation.js.map +1 -0
  19. package/dist/allend/Agent/origin.d.ts +9 -0
  20. package/dist/allend/Agent/origin.js +31 -0
  21. package/dist/allend/Agent/origin.js.map +1 -0
  22. package/dist/allend/Agent/reallocation.d.ts +7 -0
  23. package/dist/allend/Agent/reallocation.js +17 -0
  24. package/dist/allend/Agent/reallocation.js.map +1 -0
  25. package/dist/allend/Agent/realtime.d.ts +36 -0
  26. package/dist/allend/Agent/realtime.js +111 -0
  27. package/dist/allend/Agent/realtime.js.map +1 -0
  28. package/dist/allend/Agent/rides.d.ts +12 -0
  29. package/dist/allend/Agent/rides.js +51 -0
  30. package/dist/allend/Agent/rides.js.map +1 -0
  31. package/dist/allend/Agent/shipping.d.ts +11 -0
  32. package/dist/allend/Agent/shipping.js +43 -0
  33. package/dist/allend/Agent/shipping.js.map +1 -0
  34. package/dist/allend/CSP/analytics.d.ts +12 -0
  35. package/dist/allend/CSP/analytics.js +51 -0
  36. package/dist/allend/CSP/analytics.js.map +1 -0
  37. package/dist/allend/CSP/index.d.ts +25 -0
  38. package/dist/allend/CSP/index.js +43 -0
  39. package/dist/allend/CSP/index.js.map +1 -0
  40. package/dist/allend/CSP/inventory.d.ts +16 -0
  41. package/dist/allend/CSP/inventory.js +78 -0
  42. package/dist/allend/CSP/inventory.js.map +1 -0
  43. package/dist/allend/CSP/orders.d.ts +19 -0
  44. package/dist/allend/CSP/orders.js +97 -0
  45. package/dist/allend/CSP/orders.js.map +1 -0
  46. package/dist/allend/CSP/webhooks.d.ts +13 -0
  47. package/dist/allend/CSP/webhooks.js +56 -0
  48. package/dist/allend/CSP/webhooks.js.map +1 -0
  49. package/dist/allend/Customer/index.d.ts +27 -0
  50. package/dist/allend/Customer/index.js +39 -0
  51. package/dist/allend/Customer/index.js.map +1 -0
  52. package/dist/allend/Customer/intents.d.ts +12 -0
  53. package/dist/allend/Customer/intents.js +55 -0
  54. package/dist/allend/Customer/intents.js.map +1 -0
  55. package/dist/allend/Customer/orders.d.ts +11 -0
  56. package/dist/allend/Customer/orders.js +43 -0
  57. package/dist/allend/Customer/orders.js.map +1 -0
  58. package/dist/allend/Customer/rides.d.ts +12 -0
  59. package/dist/allend/Customer/rides.js +50 -0
  60. package/dist/allend/Customer/rides.js.map +1 -0
  61. package/dist/allend/DEV/developers.d.ts +11 -0
  62. package/dist/allend/DEV/developers.js +35 -0
  63. package/dist/allend/DEV/developers.js.map +1 -0
  64. package/dist/allend/DEV/index.d.ts +19 -0
  65. package/dist/allend/DEV/index.js +37 -0
  66. package/dist/allend/DEV/index.js.map +1 -0
  67. package/dist/allend/IoTClient.js +29 -35
  68. package/dist/allend/IoTClient.js.map +1 -1
  69. package/dist/allend/IoTSP/backend.d.ts +29 -0
  70. package/dist/allend/IoTSP/backend.js +75 -0
  71. package/dist/allend/IoTSP/backend.js.map +1 -0
  72. package/dist/allend/IoTSP/devices.d.ts +14 -0
  73. package/dist/allend/IoTSP/devices.js +61 -0
  74. package/dist/allend/IoTSP/devices.js.map +1 -0
  75. package/dist/allend/IoTSP/index.d.ts +28 -0
  76. package/dist/allend/IoTSP/index.js +84 -0
  77. package/dist/allend/IoTSP/index.js.map +1 -0
  78. package/dist/allend/IoTSP/rules.d.ts +17 -0
  79. package/dist/allend/IoTSP/rules.js +81 -0
  80. package/dist/allend/IoTSP/rules.js.map +1 -0
  81. package/dist/allend/IoTSP/topics.d.ts +17 -0
  82. package/dist/allend/IoTSP/topics.js +81 -0
  83. package/dist/allend/IoTSP/topics.js.map +1 -0
  84. package/dist/allend/LSP/agents.d.ts +20 -0
  85. package/dist/allend/LSP/agents.js +89 -0
  86. package/dist/allend/LSP/agents.js.map +1 -0
  87. package/dist/allend/LSP/carriers.d.ts +54 -0
  88. package/dist/allend/LSP/carriers.js +315 -0
  89. package/dist/allend/LSP/carriers.js.map +1 -0
  90. package/dist/allend/LSP/coverage.d.ts +44 -0
  91. package/dist/allend/LSP/coverage.js +135 -0
  92. package/dist/allend/LSP/coverage.js.map +1 -0
  93. package/dist/allend/LSP/fleets.d.ts +66 -0
  94. package/dist/allend/LSP/fleets.js +381 -0
  95. package/dist/allend/LSP/fleets.js.map +1 -0
  96. package/dist/allend/LSP/hubs.d.ts +39 -0
  97. package/dist/allend/LSP/hubs.js +186 -0
  98. package/dist/allend/LSP/hubs.js.map +1 -0
  99. package/dist/allend/LSP/index.d.ts +37 -0
  100. package/dist/allend/LSP/index.js +55 -0
  101. package/dist/allend/LSP/index.js.map +1 -0
  102. package/dist/allend/LSP/inventory.d.ts +13 -0
  103. package/dist/allend/LSP/inventory.js +56 -0
  104. package/dist/allend/LSP/inventory.js.map +1 -0
  105. package/dist/allend/LSP/operations.d.ts +47 -0
  106. package/dist/allend/LSP/operations.js +156 -0
  107. package/dist/allend/LSP/operations.js.map +1 -0
  108. package/dist/allend/LSP/orders.d.ts +69 -0
  109. package/dist/allend/LSP/orders.js +303 -0
  110. package/dist/allend/LSP/orders.js.map +1 -0
  111. package/dist/allend/LSP/pods.d.ts +26 -0
  112. package/dist/allend/LSP/pods.js +137 -0
  113. package/dist/allend/LSP/pods.js.map +1 -0
  114. package/dist/allend/LSP/pricing.d.ts +35 -0
  115. package/dist/allend/LSP/pricing.js +151 -0
  116. package/dist/allend/LSP/pricing.js.map +1 -0
  117. package/dist/allend/LSP/psl.d.ts +15 -0
  118. package/dist/allend/LSP/psl.js +68 -0
  119. package/dist/allend/LSP/psl.js.map +1 -0
  120. package/dist/allend/LSP/warehouses.d.ts +23 -0
  121. package/dist/allend/LSP/warehouses.js +94 -0
  122. package/dist/allend/LSP/warehouses.js.map +1 -0
  123. package/dist/allend/MSI/Controls.d.ts +9 -5
  124. package/dist/allend/MSI/Controls.js +269 -297
  125. package/dist/allend/MSI/Controls.js.map +1 -1
  126. package/dist/allend/MSI/Handles.d.ts +5 -4
  127. package/dist/allend/MSI/Handles.js +136 -233
  128. package/dist/allend/MSI/Handles.js.map +1 -1
  129. package/dist/allend/MSI/Plugins.d.ts +2 -2
  130. package/dist/allend/MSI/Plugins.js +12 -15
  131. package/dist/allend/MSI/Plugins.js.map +1 -1
  132. package/dist/allend/MSI/index.d.ts +4 -3
  133. package/dist/allend/MSI/index.js +123 -87
  134. package/dist/allend/MSI/index.js.map +1 -1
  135. package/dist/allend/MSI/native.d.ts +32 -0
  136. package/dist/allend/MSI/native.js +246 -0
  137. package/dist/allend/MSI/native.js.map +1 -0
  138. package/dist/allend/MSI/token.d.ts +12 -0
  139. package/dist/allend/MSI/token.js +21 -0
  140. package/dist/allend/MSI/token.js.map +1 -0
  141. package/dist/allend/OTPAuth/index.d.ts +77 -0
  142. package/dist/allend/OTPAuth/index.js +69 -0
  143. package/dist/allend/OTPAuth/index.js.map +1 -0
  144. package/dist/allend/Pipelines/analytics.d.ts +8 -0
  145. package/dist/allend/Pipelines/analytics.js +24 -0
  146. package/dist/allend/Pipelines/analytics.js.map +1 -0
  147. package/dist/allend/Pipelines/escalations.d.ts +8 -0
  148. package/dist/allend/Pipelines/escalations.js +25 -0
  149. package/dist/allend/Pipelines/escalations.js.map +1 -0
  150. package/dist/allend/Pipelines/executions.d.ts +11 -0
  151. package/dist/allend/Pipelines/executions.js +44 -0
  152. package/dist/allend/Pipelines/executions.js.map +1 -0
  153. package/dist/allend/Pipelines/index.d.ts +42 -0
  154. package/dist/allend/Pipelines/index.js +88 -0
  155. package/dist/allend/Pipelines/index.js.map +1 -0
  156. package/dist/allend/Pipelines/interventions.d.ts +8 -0
  157. package/dist/allend/Pipelines/interventions.js +25 -0
  158. package/dist/allend/Pipelines/interventions.js.map +1 -0
  159. package/dist/allend/Pipelines/monitor.d.ts +9 -0
  160. package/dist/allend/Pipelines/monitor.js +30 -0
  161. package/dist/allend/Pipelines/monitor.js.map +1 -0
  162. package/dist/allend/Pipelines/queries.d.ts +8 -0
  163. package/dist/allend/Pipelines/queries.js +25 -0
  164. package/dist/allend/Pipelines/queries.js.map +1 -0
  165. package/dist/allend/Pipelines/templates.d.ts +11 -0
  166. package/dist/allend/Pipelines/templates.js +46 -0
  167. package/dist/allend/Pipelines/templates.js.map +1 -0
  168. package/dist/allend/Pipelines/utils.d.ts +0 -0
  169. package/dist/allend/Pipelines/utils.js +2 -0
  170. package/dist/allend/Pipelines/utils.js.map +1 -0
  171. package/dist/allend/Pipelines/webhooks.d.ts +9 -0
  172. package/dist/allend/Pipelines/webhooks.js +35 -0
  173. package/dist/allend/Pipelines/webhooks.js.map +1 -0
  174. package/dist/allend/Pipelines/workers.d.ts +11 -0
  175. package/dist/allend/Pipelines/workers.js +45 -0
  176. package/dist/allend/Pipelines/workers.js.map +1 -0
  177. package/dist/allend/Queries/capacity.d.ts +11 -0
  178. package/dist/allend/Queries/capacity.js +44 -0
  179. package/dist/allend/Queries/capacity.js.map +1 -0
  180. package/dist/allend/Queries/discovery.d.ts +11 -0
  181. package/dist/allend/Queries/discovery.js +45 -0
  182. package/dist/allend/Queries/discovery.js.map +1 -0
  183. package/dist/allend/Queries/index.d.ts +27 -0
  184. package/dist/allend/Queries/index.js +40 -0
  185. package/dist/allend/Queries/index.js.map +1 -0
  186. package/dist/allend/Queries/matching.d.ts +7 -0
  187. package/dist/allend/Queries/matching.js +18 -0
  188. package/dist/allend/Queries/matching.js.map +1 -0
  189. package/dist/allend/Queries/performance.d.ts +9 -0
  190. package/dist/allend/Queries/performance.js +31 -0
  191. package/dist/allend/Queries/performance.js.map +1 -0
  192. package/dist/allend/Queries/pricing.d.ts +11 -0
  193. package/dist/allend/Queries/pricing.js +43 -0
  194. package/dist/allend/Queries/pricing.js.map +1 -0
  195. package/dist/allend/{DClient/Event.d.ts → Realtime/index.d.ts} +2 -6
  196. package/dist/allend/Realtime/index.js +62 -0
  197. package/dist/allend/Realtime/index.js.map +1 -0
  198. package/dist/allend/Shared/account.d.ts +10 -0
  199. package/dist/allend/Shared/account.js +22 -0
  200. package/dist/allend/Shared/account.js.map +1 -0
  201. package/dist/allend/Shared/buckets.d.ts +21 -0
  202. package/dist/allend/Shared/buckets.js +95 -0
  203. package/dist/allend/Shared/buckets.js.map +1 -0
  204. package/dist/allend/Shared/context.d.ts +14 -0
  205. package/dist/allend/Shared/context.js +33 -0
  206. package/dist/allend/Shared/context.js.map +1 -0
  207. package/dist/allend/Shared/faqs.d.ts +20 -0
  208. package/dist/allend/Shared/faqs.js +87 -0
  209. package/dist/allend/Shared/faqs.js.map +1 -0
  210. package/dist/allend/Shared/invitation.d.ts +42 -0
  211. package/dist/allend/Shared/invitation.js +40 -0
  212. package/dist/allend/Shared/invitation.js.map +1 -0
  213. package/dist/allend/Shared/operators.d.ts +39 -0
  214. package/dist/allend/Shared/operators.js +37 -0
  215. package/dist/allend/Shared/operators.js.map +1 -0
  216. package/dist/allend/Shared/users.d.ts +11 -0
  217. package/dist/allend/Shared/users.js +29 -0
  218. package/dist/allend/Shared/users.js.map +1 -0
  219. package/dist/allend/Tracking/index.d.ts +17 -0
  220. package/dist/allend/Tracking/index.js +39 -0
  221. package/dist/allend/Tracking/index.js.map +1 -0
  222. package/dist/allend/Utilities/common.d.ts +12 -0
  223. package/dist/allend/Utilities/common.js +53 -0
  224. package/dist/allend/Utilities/common.js.map +1 -0
  225. package/dist/allend/Utilities/fares.d.ts +10 -0
  226. package/dist/allend/Utilities/fares.js +39 -0
  227. package/dist/allend/Utilities/fares.js.map +1 -0
  228. package/dist/allend/Utilities/index.d.ts +23 -0
  229. package/dist/allend/Utilities/index.js +36 -0
  230. package/dist/allend/Utilities/index.js.map +1 -0
  231. package/dist/allend/Utilities/nearby.d.ts +9 -0
  232. package/dist/allend/Utilities/nearby.js +32 -0
  233. package/dist/allend/Utilities/nearby.js.map +1 -0
  234. package/dist/allend/Workflows/Client.d.ts +17 -0
  235. package/dist/allend/Workflows/Client.js +50 -0
  236. package/dist/allend/Workflows/Client.js.map +1 -0
  237. package/dist/allend/Workflows/Delivery.d.ts +36 -0
  238. package/dist/allend/Workflows/Delivery.js +16 -0
  239. package/dist/allend/Workflows/Delivery.js.map +1 -0
  240. package/dist/allend/Workflows/index.d.ts +11 -0
  241. package/dist/allend/Workflows/index.js +25 -0
  242. package/dist/allend/Workflows/index.js.map +1 -0
  243. package/dist/allend/Workspace/index.d.ts +162 -0
  244. package/dist/allend/Workspace/index.js +220 -0
  245. package/dist/allend/Workspace/index.js.map +1 -0
  246. package/dist/allend/index.d.ts +8 -5
  247. package/dist/allend/index.js +15 -8
  248. package/dist/allend/index.js.map +1 -1
  249. package/dist/backend/Auth.d.ts +28 -4
  250. package/dist/backend/Auth.js +125 -245
  251. package/dist/backend/Auth.js.map +1 -1
  252. package/dist/baseUrl.d.ts +56 -0
  253. package/dist/baseUrl.js +72 -4
  254. package/dist/baseUrl.js.map +1 -1
  255. package/dist/core.d.ts +88 -0
  256. package/dist/core.js +121 -0
  257. package/dist/core.js.map +1 -0
  258. package/dist/error.d.ts +17 -0
  259. package/dist/error.js +26 -0
  260. package/dist/error.js.map +1 -0
  261. package/dist/index.d.ts +30 -12
  262. package/dist/index.js +38 -14
  263. package/dist/index.js.map +1 -1
  264. package/dist/react-native.d.ts +30 -0
  265. package/dist/react-native.js +55 -0
  266. package/dist/react-native.js.map +1 -0
  267. package/dist/types/access.d.ts +64 -7
  268. package/dist/types/auth.d.ts +17 -17
  269. package/dist/types/channel.d.ts +45 -0
  270. package/dist/types/index.d.ts +379 -237
  271. package/dist/utils/index.d.ts +25 -0
  272. package/dist/utils/index.js +11 -1
  273. package/dist/utils/index.js.map +1 -1
  274. package/dist/utils/stream.js +25 -26
  275. package/dist/utils/stream.js.map +1 -1
  276. package/package.json +38 -18
  277. package/src/allend/Access.ts +143 -13
  278. package/src/allend/Agent/consolidation.ts +43 -0
  279. package/src/allend/Agent/delivery.ts +51 -0
  280. package/src/allend/Agent/dispatch.ts +27 -0
  281. package/src/allend/Agent/index.ts +113 -0
  282. package/src/allend/Agent/navigation.ts +27 -0
  283. package/src/allend/Agent/origin.ts +36 -0
  284. package/src/allend/Agent/reallocation.ts +16 -0
  285. package/src/allend/Agent/realtime.ts +140 -0
  286. package/src/allend/Agent/rides.ts +61 -0
  287. package/src/allend/Agent/shipping.ts +51 -0
  288. package/src/allend/CSP/analytics.ts +61 -0
  289. package/src/allend/CSP/index.ts +57 -0
  290. package/src/allend/CSP/inventory.ts +96 -0
  291. package/src/allend/CSP/orders.ts +121 -0
  292. package/src/allend/CSP/webhooks.ts +68 -0
  293. package/src/allend/Customer/index.ts +56 -0
  294. package/src/allend/Customer/intents.ts +66 -0
  295. package/src/allend/Customer/orders.ts +51 -0
  296. package/src/allend/Customer/rides.ts +60 -0
  297. package/src/allend/DEV/developers.ts +42 -0
  298. package/src/allend/DEV/index.ts +48 -0
  299. package/src/allend/IoTSP/backend.ts +103 -0
  300. package/src/allend/IoTSP/devices.ts +74 -0
  301. package/src/allend/IoTSP/index.ts +69 -0
  302. package/src/allend/IoTSP/rules.ts +99 -0
  303. package/src/allend/IoTSP/topics.ts +99 -0
  304. package/src/allend/LSP/agents.ts +115 -0
  305. package/src/allend/LSP/carriers.ts +408 -0
  306. package/src/allend/LSP/coverage.ts +212 -0
  307. package/src/allend/LSP/fleets.ts +505 -0
  308. package/src/allend/LSP/hubs.ts +245 -0
  309. package/src/allend/LSP/index.ts +75 -0
  310. package/src/allend/LSP/inventory.ts +65 -0
  311. package/src/allend/LSP/operations.ts +202 -0
  312. package/src/allend/LSP/orders.ts +397 -0
  313. package/src/allend/LSP/pods.ts +176 -0
  314. package/src/allend/LSP/pricing.ts +192 -0
  315. package/src/allend/LSP/psl.ts +81 -0
  316. package/src/allend/LSP/warehouses.ts +118 -0
  317. package/src/allend/MSI/Controls.ts +109 -90
  318. package/src/allend/MSI/Handles.ts +24 -15
  319. package/src/allend/MSI/Plugins.ts +3 -3
  320. package/src/allend/MSI/index.ts +85 -16
  321. package/src/allend/MSI/native.tsx +314 -0
  322. package/src/allend/MSI/token.ts +20 -0
  323. package/src/allend/OTPAuth/index.ts +130 -0
  324. package/src/allend/Pipelines/analytics.ts +25 -0
  325. package/src/allend/Pipelines/escalations.ts +26 -0
  326. package/src/allend/Pipelines/executions.ts +51 -0
  327. package/src/allend/Pipelines/index.ts +125 -0
  328. package/src/allend/Pipelines/interventions.ts +27 -0
  329. package/src/allend/Pipelines/monitor.ts +33 -0
  330. package/src/allend/Pipelines/queries.ts +27 -0
  331. package/src/allend/Pipelines/templates.ts +51 -0
  332. package/src/allend/Pipelines/utils.ts +0 -0
  333. package/src/allend/Pipelines/webhooks.ts +36 -0
  334. package/src/allend/Pipelines/workers.ts +49 -0
  335. package/src/allend/Queries/capacity.ts +51 -0
  336. package/src/allend/Queries/discovery.ts +53 -0
  337. package/src/allend/Queries/index.ts +58 -0
  338. package/src/allend/Queries/matching.ts +16 -0
  339. package/src/allend/Queries/performance.ts +35 -0
  340. package/src/allend/Queries/pricing.ts +51 -0
  341. package/src/allend/{DClient/Event.ts → Realtime/index.ts} +23 -22
  342. package/src/allend/Shared/account.ts +24 -0
  343. package/src/allend/Shared/buckets.ts +117 -0
  344. package/src/allend/Shared/context.ts +36 -0
  345. package/src/allend/Shared/faqs.ts +106 -0
  346. package/src/allend/Shared/invitation.ts +77 -0
  347. package/src/allend/Shared/operators.ts +84 -0
  348. package/src/allend/Shared/users.ts +32 -0
  349. package/src/allend/Tracking/index.ts +48 -0
  350. package/src/allend/Utilities/common.ts +63 -0
  351. package/src/allend/Utilities/fares.ts +45 -0
  352. package/src/allend/Utilities/index.ts +52 -0
  353. package/src/allend/Utilities/nearby.ts +36 -0
  354. package/src/allend/{DClient → Workflows}/Client.ts +12 -22
  355. package/src/allend/Workflows/Delivery.ts +94 -0
  356. package/src/allend/Workflows/index.ts +31 -0
  357. package/src/allend/Workspace/index.ts +302 -0
  358. package/src/allend/index.ts +23 -10
  359. package/src/backend/Auth.ts +68 -35
  360. package/src/baseUrl.ts +81 -7
  361. package/src/core.ts +145 -0
  362. package/src/error.ts +27 -0
  363. package/src/index.ts +25 -17
  364. package/src/react-native.ts +43 -0
  365. package/src/types/access.d.ts +64 -7
  366. package/src/types/auth.d.ts +17 -17
  367. package/src/types/channel.d.ts +45 -0
  368. package/src/types/index.d.ts +379 -237
  369. package/src/utils/index.ts +33 -1
  370. package/dist/allend/DAuth/index.d.ts +0 -20
  371. package/dist/allend/DAuth/index.js +0 -92
  372. package/dist/allend/DAuth/index.js.map +0 -1
  373. package/dist/allend/DClient/Client.d.ts +0 -10
  374. package/dist/allend/DClient/Client.js +0 -144
  375. package/dist/allend/DClient/Client.js.map +0 -1
  376. package/dist/allend/DClient/Event.js +0 -100
  377. package/dist/allend/DClient/Event.js.map +0 -1
  378. package/dist/allend/DClient/Order.d.ts +0 -49
  379. package/dist/allend/DClient/Order.js +0 -601
  380. package/dist/allend/DClient/Order.js.map +0 -1
  381. package/dist/bundle.js +0 -1
  382. package/src/allend/DAuth/index.ts +0 -39
  383. package/src/allend/DClient/Order.ts +0 -452
@@ -1,4 +1,29 @@
1
+ import type { HTTPRequestOptions } from '../types';
1
2
  import Stream from './stream';
3
+ export type Http = {
4
+ request<T>(opts: HTTPRequestOptions): Promise<T>;
5
+ };
6
+ export type Res<T = any> = {
7
+ error: boolean;
8
+ status?: string;
9
+ message?: string;
10
+ data: T;
11
+ };
12
+ /**
13
+ * The payload inside De.'s envelope, for a caller who wants only that.
14
+ *
15
+ * Clients return the envelope — `{ error, status, message, data }` — because
16
+ * `status` names a refusal precisely and throwing it away leaves the caller
17
+ * reconstructing it from prose. This names the `data` half for the places that
18
+ * want to talk about the payload type on its own.
19
+ *
20
+ * A route answering with no payload resolves to `undefined`, and a payload the
21
+ * route may omit keeps the `| undefined` its schema gave it — the distinction
22
+ * a conditional on `T extends { data: infer D }` loses, since an optional
23
+ * property fails that test outright.
24
+ */
25
+ export type Data<T> = 'data' extends keyof T ? T['data'] : undefined;
26
+ export declare const qs: (params?: Record<string, any>) => string;
2
27
  declare const _default: {
3
28
  Stream: typeof Stream;
4
29
  };
@@ -3,6 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var stream_1 = __importDefault(require("./stream"));
6
+ exports.qs = void 0;
7
+ const stream_1 = __importDefault(require("./stream"));
8
+ const qs = (params) => {
9
+ if (!params)
10
+ return '';
11
+ const q = new URLSearchParams(Object.fromEntries(Object.entries(params)
12
+ .filter(([, v]) => v != null)
13
+ .map(([k, v]) => [k, String(v)]))).toString();
14
+ return q ? `?${q}` : '';
15
+ };
16
+ exports.qs = qs;
7
17
  exports.default = { Stream: stream_1.default };
8
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;AACA,oDAA6B;AAE7B,kBAAe,EAAE,MAAM,kBAAA,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AACA,sDAA6B;AAsBtB,MAAM,EAAE,GAAG,CAAE,MAA4B,EAAW,EAAE;IAC3D,IAAI,CAAC,MAAM;QAAG,OAAO,EAAE,CAAA;IACvB,MAAM,CAAC,GAAG,IAAI,eAAe,CAC3B,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAE,MAAM,CAAE;SACjB,MAAM,CAAE,CAAE,CAAC,EAAE,CAAC,CAAC,EAAG,EAAE,CAAC,CAAC,IAAI,IAAI,CAAE;SAChC,GAAG,CAAE,CAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAG,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAE,CAAC,CAAE,CAAC,CAAE,CAC7C,CACF,CAAC,QAAQ,EAAE,CAAA;IACZ,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AACzB,CAAC,CAAA;AAVY,QAAA,EAAE,MAUd;AAED,kBAAe,EAAE,MAAM,EAAN,gBAAM,EAAE,CAAA"}
@@ -1,44 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var Stream = /** @class */ (function () {
4
- function Stream() {
3
+ class Stream {
4
+ constructor() {
5
5
  this._STALED = false;
6
6
  this._CLOSED = false;
7
7
  this._fns = [];
8
- this._exitFn = (function () { });
9
- this._errorFn = (function (error) { });
8
+ this._exitFn = (() => { });
9
+ this._errorFn = ((error) => { });
10
10
  }
11
- Stream.prototype._upstream = function (stream) {
11
+ _upstream(stream) {
12
12
  this._upStream = stream;
13
13
  return this;
14
- };
15
- Stream.prototype._backpressure = function (data) {
16
- !this._CLOSED && this._fns.map(function (fn) { return fn(data); });
17
- };
18
- Stream.prototype.sync = function (data) {
14
+ }
15
+ _backpressure(data) {
16
+ !this._CLOSED && this._fns.map(fn => fn(data));
17
+ }
18
+ sync(data) {
19
19
  var _a;
20
20
  !this._CLOSED && ((_a = this._downStream) === null || _a === void 0 ? void 0 : _a._backpressure(data));
21
- };
22
- Stream.prototype.on = function (_event, fn) {
21
+ }
22
+ on(_event, fn) {
23
23
  if (this._CLOSED)
24
24
  throw new Error('Stream closed');
25
25
  this._fns.push(fn);
26
26
  return this;
27
- };
28
- Stream.prototype.pipe = function (stream) {
27
+ }
28
+ pipe(stream) {
29
29
  stream._upstream(this);
30
30
  this._downStream = stream;
31
31
  return this;
32
- };
33
- Stream.prototype.error = function (error) {
32
+ }
33
+ error(error) {
34
34
  var _a;
35
35
  // Throw error to self
36
36
  this._errorFn(typeof error == 'string' ? new Error(error) : error);
37
37
  // Throw error to downstream pipe
38
38
  (_a = this._downStream) === null || _a === void 0 ? void 0 : _a.error(error);
39
39
  return this;
40
- };
41
- Stream.prototype.close = function () {
40
+ }
41
+ close() {
42
42
  var _a;
43
43
  if (this._CLOSED)
44
44
  return;
@@ -47,17 +47,16 @@ var Stream = /** @class */ (function () {
47
47
  this._exitFn();
48
48
  (_a = this._downStream) === null || _a === void 0 ? void 0 : _a.close(); // Close down streams
49
49
  // this._upStream?.close() // Close up streams: Recursive loop call effect
50
- };
51
- Stream.prototype.isActive = function () { return !this._CLOSED; };
52
- Stream.prototype.onerror = function (fn) {
50
+ }
51
+ isActive() { return !this._CLOSED; }
52
+ onerror(fn) {
53
53
  this._errorFn = fn;
54
54
  return this;
55
- };
56
- Stream.prototype.onclose = function (fn) {
55
+ }
56
+ onclose(fn) {
57
57
  this._exitFn = fn;
58
58
  return this;
59
- };
60
- return Stream;
61
- }());
59
+ }
60
+ }
62
61
  exports.default = Stream;
63
62
  //# sourceMappingURL=stream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";;AAGA;IAAA;QACU,YAAO,GAAY,KAAK,CAAA;QACxB,YAAO,GAAY,KAAK,CAAA;QACxB,SAAI,GAAyB,EAAE,CAAA;QAC/B,YAAO,GAAG,CAAC,cAAO,CAAC,CAAC,CAAA;QACpB,aAAQ,G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AAG,EAAE,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhED,yBAgEC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@de./sdk",
3
- "version": "1.0.4",
4
- "description": "Complete SDK pack for MSI (Map Service Interface), IoTClient and DClient services",
3
+ "version": "2.0.0",
4
+ "description": "Complete SDK pack for MSI (Map Service Interface), IoTClient and DClient services — web, server and React Native",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "files": [
@@ -11,46 +11,66 @@
11
11
  ],
12
12
  "exports": {
13
13
  ".": {
14
+ "types": "./dist/index.d.ts",
14
15
  "import": "./dist/index.js",
15
- "require": "./dist/index.js",
16
- "types": "./dist/index.d.ts"
16
+ "require": "./dist/index.js"
17
+ },
18
+ "./react-native": {
19
+ "types": "./dist/react-native.d.ts",
20
+ "import": "./dist/react-native.js",
21
+ "require": "./dist/react-native.js"
17
22
  },
18
23
  "./types": {
19
24
  "types": "./dist/types/index.d.ts",
20
25
  "default": "./dist/types/index.d.ts"
21
- }
26
+ },
27
+ "./package.json": "./package.json"
22
28
  },
23
29
  "author": "SCOREX Corporation",
24
30
  "private": false,
25
31
  "scripts": {
26
32
  "build:tsc": "rimraf ./dist && tsc",
27
- "build:webpack": "WEBPACK_ENV=build webpack",
28
33
  "build:copy-types": "mkdir -p dist/types && cp -r src/types/* dist/types/",
29
- "compile": "yarn build:tsc && yarn build:webpack && yarn build:copy-types",
30
- "prepack": "yarn run compile",
31
- "test": "Echo 'Error: No test specified' && exit 1",
32
- "test:auth": "yarn build:tsc && jest test/auth.test.js",
33
- "test:client": "yarn build:tsc && jest test/client.test.js",
34
- "test:order": "yarn build:tsc && jest test/order.test.js",
35
- "test:event": "yarn build:tsc && jest test/event.test.js"
34
+ "compile": "npm run build:tsc && npm run build:copy-types",
35
+ "verify:entries": "node scripts/verify-entries.mjs",
36
+ "prepack": "npm run compile && npm run verify:entries",
37
+ "test": "npm run build:tsc && jest",
38
+ "test:auth": "npm run build:tsc && jest test/auth.test.js",
39
+ "test:client": "npm run build:tsc && jest test/client.test.js",
40
+ "test:order": "npm run build:tsc && jest test/order.test.js",
41
+ "test:event": "npm run build:tsc && jest test/event.test.js"
36
42
  },
37
43
  "dependencies": {
44
+ "@de./types": "^2.0.0",
38
45
  "events": "^3.3.0",
39
46
  "iframe.io": "^1.1.0",
40
47
  "node-fetch": "2.6.1",
41
- "socket.io-client": "^4.6.1"
48
+ "socket.io-client": "^4.6.1",
49
+ "webview.io": "^1.1.0"
50
+ },
51
+ "peerDependencies": {
52
+ "react": ">=16.8.0",
53
+ "react-native": ">=0.60.0",
54
+ "react-native-webview": ">=11.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "react": { "optional": true },
58
+ "react-native": { "optional": true },
59
+ "react-native-webview": { "optional": true }
42
60
  },
43
61
  "devDependencies": {
62
+ "@babel/core": "^7.26.0",
44
63
  "@types/jest": "^29.5.0",
45
64
  "@types/node-fetch": "^2.6.3",
65
+ "@types/react": "^18.0.0",
46
66
  "expect.js": "^0.3.1",
47
67
  "jest": "^29.7.0",
68
+ "react": "^18.2.0",
69
+ "react-native": "^0.72.8",
70
+ "react-native-webview": "13.16.0",
48
71
  "rimraf": "^4.4.0",
49
72
  "ts-jest": "^29.0.5",
50
- "ts-loader": "^9.4.2",
51
- "typescript": "^5.0.2",
52
- "webpack": "^5.77.0",
53
- "webpack-cli": "^5.0.1"
73
+ "typescript": "^5.9.0"
54
74
  },
55
75
  "directories": {
56
76
  "dist": "dist/",
@@ -1,35 +1,76 @@
1
- import type { AccessOptions } from '../types/access'
1
+ import type { AccessOptions, UserSession } from '../types/access'
2
2
  import type { HTTPRequestOptions } from '../types'
3
- import { API_SERVER_BASEURL, ASI_SERVER_BASEURL } from '../baseUrl'
3
+ import { baseURL } from '../baseUrl'
4
+ import APIError from '../error'
4
5
 
5
- type AccessType = 'API' | 'ASI'
6
+ /**
7
+ * Which service the client addresses.
8
+ *
9
+ * De. is more than one server: de.arch answers the API, de.auth the ASI, and
10
+ * de.workspace the control plane. They are separate hosts, so the client has
11
+ * to say which one it means rather than assume the API.
12
+ */
13
+ type AccessType = 'API' | 'ASI' | 'WSP'
6
14
 
7
15
  const USER_ACCOUNT_SERVICE = 'De.API'
8
16
 
17
+ /**
18
+ * Resolve a fetch implementation for the host runtime.
19
+ *
20
+ * Node 18+, every browser and React Native all expose a global `fetch`, so that
21
+ * is the first and usual answer. `node-fetch` remains only as a fallback for
22
+ * Node versions predating the global.
23
+ *
24
+ * The previous check tested `globalThis.window && globalThis.fetch`, which was
25
+ * wrong for React Native: there is no `window` there but `fetch` is global, so
26
+ * it fell through to importing node-fetch and broke. Testing for `fetch`
27
+ * directly is what lets one Access layer serve node, browser and native.
28
+ */
29
+ async function resolveFetch(): Promise<typeof globalThis.fetch> {
30
+ if( typeof globalThis?.fetch === 'function' )
31
+ return globalThis.fetch
32
+
33
+ return ( await import('node-fetch') ).default as any
34
+ }
35
+
9
36
  export default class AccessManager {
10
37
  private atype: AccessType
11
38
  private version: number
12
39
  private platform: AccessOptions['platform']
13
40
  private baseURL: string
41
+ /**
42
+ * The client's own `wid:TYPE:xcode`, base64-encoded.
43
+ *
44
+ * Not a transport header: de.arch resolves the workspace from the access
45
+ * token, and its header contract has no context field. It is kept because a
46
+ * client is scoped to one context for its lifetime, and a caller holding
47
+ * several — a proxy serving many workspaces — needs to ask which is which.
48
+ * `scope` decodes it.
49
+ */
50
+ readonly context: string
14
51
  protected accessToken?: string
15
52
  protected remoteOrigin?: string
53
+ protected session?: UserSession
54
+ private timeout?: number
16
55
 
17
56
  constructor( options: AccessOptions, atype: AccessType ){
18
57
  if( !options ) throw new Error('Undefined Access Configuration')
19
58
  if( !options.context ) throw new Error('Undefined Context Reference. Check https://doc.dedot.io/sdk/auth')
20
59
  if( !options.accessToken ) throw new Error('Undefined Access Token. Check https://doc.dedot.io/sdk/auth')
21
60
 
61
+ this.context = options.context
22
62
  this.atype = atype
23
63
  this.version = options.version || 1
24
64
  this.platform = options.platform || 'proxy'
25
65
  this.accessToken = options.accessToken
26
66
  this.remoteOrigin = options.remoteOrigin
27
- this.baseURL = this.atype === 'ASI'
28
- ? ASI_SERVER_BASEURL[ options.env || 'dev' ]
29
- : API_SERVER_BASEURL[ options.env || 'dev' ]
67
+ this.session = options.session
68
+ this.timeout = options.timeout
69
+ this.baseURL = options.baseUrl?.replace( /\/+$/, '' )
70
+ || baseURL( this.atype, options.env || 'dev', options.devHostname )
30
71
  }
31
72
 
32
- async request<Response>({ url, ...options }: HTTPRequestOptions ): Promise<Response> {
73
+ async request<Response>({ url, timeout, ...options }: HTTPRequestOptions ): Promise<Response> {
33
74
  const rawOptions: any = {
34
75
  method: 'GET',
35
76
  headers: {
@@ -49,6 +90,17 @@ export default class AccessManager {
49
90
  if( this.accessToken )
50
91
  rawOptions.headers.authorization = `Bearer ${this.accessToken}`
51
92
 
93
+ /**
94
+ * User-session credentials, sent alongside the bearer token rather than
95
+ * instead of it. `isConnected` (AUX agent routes) reads only this pair;
96
+ * `isAuthorized` reads only the bearer. Routes guarded by either one are
97
+ * then reachable from a single client.
98
+ */
99
+ if( this.session ){
100
+ rawOptions.headers['de-auth-token'] = this.session.token
101
+ rawOptions.headers['de-auth-device'] = this.session.device
102
+ }
103
+
52
104
  if( options.body ){
53
105
  rawOptions.headers['content-type'] = 'application/json'
54
106
  if( typeof options.body === 'object' )
@@ -63,16 +115,94 @@ export default class AccessManager {
63
115
 
64
116
  options = { ...rawOptions, ...options }
65
117
 
118
+ /**
119
+ * Bound the request when a deadline is configured.
120
+ *
121
+ * `AbortSignal.timeout` is not in the pre-18 Node the node-fetch fallback
122
+ * exists for, so this is guarded rather than assumed. A missing signal
123
+ * leaves the previous unbounded behaviour, which is the right degradation:
124
+ * the request still goes out.
125
+ */
126
+ const deadline = timeout ?? this.timeout
127
+ if( deadline && typeof AbortSignal?.timeout === 'function' )
128
+ ( options as any ).signal = AbortSignal.timeout( deadline )
129
+
66
130
  url = `${this.baseURL}/v${this.version}/${url.replace(/^\//, '')}`
67
131
 
68
- // Support fetch for in both node & browser environment
69
- let fetch = globalThis?.window && globalThis?.fetch
70
- if( !fetch )
71
- fetch = ( await import('node-fetch') ).default as any
132
+ const fetch = await resolveFetch(),
133
+ response = await fetch( url, options as any )
134
+
135
+ /**
136
+ * Everything De. answers is the `{ error, message, data }` envelope, so a
137
+ * body that will not parse did not come from De. — a gateway 502 page, a
138
+ * proxy timeout, an empty 204. Reporting that as a JSON syntax error hides
139
+ * the only two facts worth having, which are the status and the URL.
140
+ */
141
+ let body: any
142
+ try { body = await response.json() }
143
+ catch {
144
+ /**
145
+ * Not De. answering — a gateway's HTML 502, a proxy timeout, an empty
146
+ * 204. There is no envelope to hand back, so this is the one case that
147
+ * raises, carrying the status and URL rather than a JSON syntax error.
148
+ */
149
+ throw new APIError(`${options.method} ${url} — ${response.statusText || 'no JSON body'}`, response.status )
150
+ }
151
+
152
+ /**
153
+ * A refusal is returned, not raised.
154
+ *
155
+ * De.'s answer is the `{ error, status, message, data }` envelope whether
156
+ * it succeeded or not, and `status` names the refusal precisely —
157
+ * SENDER_CAP_REACHED, CONSOLIDATION::NOT_IN_PROGRESS. Throwing that away
158
+ * and reconstructing it from an exception message is what callers were
159
+ * reduced to; handing back the envelope lets them read it.
160
+ *
161
+ * A non-2xx carrying an envelope is still De. answering, so it comes back
162
+ * the same way.
163
+ *
164
+ * What is NOT De. answering is raised. A wrong path gets Fastify's own
165
+ * 404 body, which is JSON but not the envelope — `error` there is the
166
+ * string 'Not Found', not a boolean. Returning that as though it were a
167
+ * refusal is how a client addressing a route that does not exist would
168
+ * look like a workspace being told no, which is precisely the bug that
169
+ * hid `/LSP/invitation/agent` behind a plausible-looking failure.
170
+ */
171
+ if( typeof body?.error !== 'boolean' )
172
+ throw new APIError(
173
+ body?.message || `${options.method} ${url} — ${response.status} ${response.statusText || 'not a De. response'}`,
174
+ response.status,
175
+ body
176
+ )
72
177
 
73
- // console.log( options )
74
- return await ( await fetch( url, options ) ).json() as Response
178
+ return body as Response
179
+ }
180
+
181
+ /**
182
+ * The context decoded into its parts.
183
+ *
184
+ * Every consumer was decoding the base64 and splitting on ':' by hand,
185
+ * including validating that it produced three fields. Returns undefined
186
+ * rather than throwing when the string is not a context, since a caller
187
+ * asking is usually checking.
188
+ */
189
+ get scope(): { wid: string, type: string, xcode: string } | undefined {
190
+ try {
191
+ const decoded = typeof atob === 'function'
192
+ ? atob( this.context )
193
+ : Buffer.from( this.context, 'base64' ).toString('utf8'),
194
+ [ wid, type, xcode ] = decoded.split(':')
195
+
196
+ return wid && type && xcode ? { wid, type, xcode } : undefined
197
+ }
198
+ catch { return undefined }
75
199
  }
76
200
 
77
201
  setToken( token: string ): void { this.accessToken = token }
202
+
203
+ /** Attach or replace the signed-in user after construction. */
204
+ setSession( session: UserSession ): void { this.session = session }
205
+
206
+ /** Drop the user session — e.g. on sign-out. */
207
+ clearSession(): void { this.session = undefined }
78
208
  }
@@ -0,0 +1,43 @@
1
+ import type {
2
+ AgentConsolidationRespondValidation,
3
+ AgentConsolidationHandoffValidation,
4
+ AgentConsolidationCompleteValidation
5
+ } from '@de./types'
6
+ import { type Http, type Res, type Data } from '../../utils'
7
+
8
+ // ─── Agent Consolidation ──────────────────────────────────────────────────────
9
+
10
+ export default class AgentConsolidation {
11
+ constructor( private http: Http ){}
12
+
13
+ async respond( body: AgentConsolidationRespondValidation['body'] ): Promise<AgentConsolidationRespondValidation['response']> {
14
+ return await this.http.request<AgentConsolidationRespondValidation['response']>({
15
+ url: '/agent/consolidation/respond',
16
+ method: 'POST',
17
+ body
18
+ })
19
+ }
20
+
21
+ async handoffConfirm( body: AgentConsolidationHandoffValidation['body'] ): Promise<AgentConsolidationHandoffValidation['response']> {
22
+ return await this.http.request<AgentConsolidationHandoffValidation['response']>({
23
+ url: '/agent/consolidation/handoff/confirm',
24
+ method: 'POST',
25
+ body
26
+ })
27
+ }
28
+
29
+ /**
30
+ * The receiving rider reporting leg 2 delivered.
31
+ *
32
+ * No handoff code — the PIN authenticated the transfer between riders at
33
+ * confirm. This is what takes the offer out of IN_PROGRESS and returns the
34
+ * rider to their zone pool.
35
+ */
36
+ async handoffComplete( body: AgentConsolidationCompleteValidation['body'] ): Promise<AgentConsolidationCompleteValidation['response']> {
37
+ return await this.http.request<AgentConsolidationCompleteValidation['response']>({
38
+ url: '/agent/consolidation/handoff/complete',
39
+ method: 'POST',
40
+ body
41
+ })
42
+ }
43
+ }
@@ -0,0 +1,51 @@
1
+ import type {
2
+ AgentDeliveryListValidation,
3
+ AgentDeliveryGetValidation,
4
+ AgentDeliveryAcceptValidation,
5
+ AgentDeliveryUpdateStatusValidation,
6
+ AgentDeliveryReportIssueValidation
7
+ } from '@de./types'
8
+ import { qs, type Http, type Res, type Data } from '../../utils'
9
+
10
+ // ─── Agent Delivery Orders ────────────────────────────────────────────────────
11
+
12
+ export default class AgentDelivery {
13
+ constructor( private http: Http ){}
14
+
15
+ async list( querystring?: AgentDeliveryListValidation['querystring'] ): Promise<AgentDeliveryListValidation['response']> {
16
+ return await this.http.request<AgentDeliveryListValidation['response']>({
17
+ url: `/agent/delivery/orders${qs( querystring )}`,
18
+ method: 'GET'
19
+ })
20
+ }
21
+
22
+ async get( reference: string ): Promise<AgentDeliveryGetValidation['response']> {
23
+ return await this.http.request<AgentDeliveryGetValidation['response']>({
24
+ url: `/agent/delivery/orders/${reference}`,
25
+ method: 'GET'
26
+ })
27
+ }
28
+
29
+ async accept( reference: string ): Promise<AgentDeliveryAcceptValidation['response']> {
30
+ return await this.http.request<AgentDeliveryAcceptValidation['response']>({
31
+ url: `/agent/delivery/orders/${reference}/accept`,
32
+ method: 'POST'
33
+ })
34
+ }
35
+
36
+ async updateStatus( reference: string, body: AgentDeliveryUpdateStatusValidation['body'] ): Promise<AgentDeliveryUpdateStatusValidation['response']> {
37
+ return await this.http.request<AgentDeliveryUpdateStatusValidation['response']>({
38
+ url: `/agent/delivery/orders/${reference}/status`,
39
+ method: 'PATCH',
40
+ body
41
+ })
42
+ }
43
+
44
+ async reportIssue( reference: string, body: AgentDeliveryReportIssueValidation['body'] ): Promise<AgentDeliveryReportIssueValidation['response']> {
45
+ return await this.http.request<AgentDeliveryReportIssueValidation['response']>({
46
+ url: `/agent/delivery/orders/${reference}/issue`,
47
+ method: 'POST',
48
+ body
49
+ })
50
+ }
51
+ }
@@ -0,0 +1,27 @@
1
+ import type {
2
+ AgentDispatchRespondValidation,
3
+ AgentDispatchRateValidation
4
+ } from '@de./types'
5
+ import { type Http, type Res, type Data } from '../../utils'
6
+
7
+ // ─── Agent Dispatch ───────────────────────────────────────────────────────────
8
+
9
+ export default class AgentDispatch {
10
+ constructor( private http: Http ){}
11
+
12
+ async respond( body: AgentDispatchRespondValidation['body'] ): Promise<AgentDispatchRespondValidation['response']> {
13
+ return await this.http.request<AgentDispatchRespondValidation['response']>({
14
+ url: '/agent/dispatch/respond',
15
+ method: 'POST',
16
+ body
17
+ })
18
+ }
19
+
20
+ async rate( body: AgentDispatchRateValidation['body'] ): Promise<AgentDispatchRateValidation['response']> {
21
+ return await this.http.request<AgentDispatchRateValidation['response']>({
22
+ url: '/agent/dispatch/rate',
23
+ method: 'POST',
24
+ body
25
+ })
26
+ }
27
+ }