@smess/networking 1.2.0 → 2.1.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 (317) hide show
  1. package/CHANGELOG.md +221 -0
  2. package/README.md +178 -111
  3. package/dist/core/body.d.ts +10 -0
  4. package/dist/core/body.d.ts.map +1 -0
  5. package/dist/core/body.js +22 -0
  6. package/dist/core/body.js.map +1 -0
  7. package/dist/core/client.d.ts +74 -0
  8. package/dist/core/client.d.ts.map +1 -0
  9. package/dist/core/client.js +124 -0
  10. package/dist/core/client.js.map +1 -0
  11. package/dist/core/decoders.d.ts +8 -0
  12. package/dist/core/decoders.d.ts.map +1 -0
  13. package/dist/core/decoders.js +26 -0
  14. package/dist/core/decoders.js.map +1 -0
  15. package/dist/core/endpoint.d.ts +69 -0
  16. package/dist/core/endpoint.d.ts.map +1 -0
  17. package/dist/core/endpoint.js +6 -0
  18. package/dist/core/endpoint.js.map +1 -0
  19. package/dist/core/hosts.d.ts +27 -0
  20. package/dist/core/hosts.d.ts.map +1 -0
  21. package/dist/core/hosts.js +24 -0
  22. package/dist/core/hosts.js.map +1 -0
  23. package/dist/core/pagination.d.ts +33 -0
  24. package/dist/core/pagination.d.ts.map +1 -0
  25. package/dist/core/pagination.js +23 -0
  26. package/dist/core/pagination.js.map +1 -0
  27. package/dist/core/pipeline.d.ts +25 -0
  28. package/dist/core/pipeline.d.ts.map +1 -0
  29. package/dist/core/pipeline.js +12 -0
  30. package/dist/core/pipeline.js.map +1 -0
  31. package/dist/core/retry.d.ts +18 -0
  32. package/dist/core/retry.d.ts.map +1 -0
  33. package/dist/core/retry.js +47 -0
  34. package/dist/core/retry.js.map +1 -0
  35. package/dist/core/transport.d.ts +30 -0
  36. package/dist/core/transport.d.ts.map +1 -0
  37. package/dist/core/transport.js +73 -0
  38. package/dist/core/transport.js.map +1 -0
  39. package/dist/core/types.d.ts +24 -0
  40. package/dist/core/types.d.ts.map +1 -0
  41. package/dist/core/types.js +3 -0
  42. package/dist/core/types.js.map +1 -0
  43. package/dist/core/url.d.ts +15 -0
  44. package/dist/core/url.d.ts.map +1 -0
  45. package/dist/core/url.js +46 -0
  46. package/dist/core/url.js.map +1 -0
  47. package/dist/errors/parse-error-body.d.ts +20 -0
  48. package/dist/errors/parse-error-body.d.ts.map +1 -0
  49. package/dist/errors/parse-error-body.js +73 -0
  50. package/dist/errors/parse-error-body.js.map +1 -0
  51. package/dist/errors/smess-api-error.d.ts +70 -0
  52. package/dist/errors/smess-api-error.d.ts.map +1 -0
  53. package/dist/errors/smess-api-error.js +84 -0
  54. package/dist/errors/smess-api-error.js.map +1 -0
  55. package/dist/index.d.ts +27 -25
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +15 -29
  58. package/dist/index.js.map +1 -0
  59. package/dist/modules/authentication/index.d.ts +89 -0
  60. package/dist/modules/authentication/index.d.ts.map +1 -0
  61. package/dist/modules/authentication/index.js +128 -0
  62. package/dist/modules/authentication/index.js.map +1 -0
  63. package/dist/modules/campaign/index.d.ts +212 -0
  64. package/dist/modules/campaign/index.d.ts.map +1 -0
  65. package/dist/modules/campaign/index.js +193 -0
  66. package/dist/modules/campaign/index.js.map +1 -0
  67. package/dist/modules/campaign/types.d.ts +562 -0
  68. package/dist/modules/campaign/types.d.ts.map +1 -0
  69. package/dist/modules/campaign/types.js +2 -0
  70. package/dist/modules/campaign/types.js.map +1 -0
  71. package/dist/modules/danara/index.d.ts +153 -0
  72. package/dist/modules/danara/index.d.ts.map +1 -0
  73. package/dist/modules/danara/index.js +144 -0
  74. package/dist/modules/danara/index.js.map +1 -0
  75. package/dist/modules/danara/types.d.ts +479 -0
  76. package/dist/modules/danara/types.d.ts.map +1 -0
  77. package/dist/modules/danara/types.js +2 -0
  78. package/dist/modules/danara/types.js.map +1 -0
  79. package/dist/modules/messenger/index.d.ts +92 -0
  80. package/dist/modules/messenger/index.d.ts.map +1 -0
  81. package/dist/modules/messenger/index.js +44 -0
  82. package/dist/modules/messenger/index.js.map +1 -0
  83. package/dist/modules/smeup-file/index.d.ts +27 -0
  84. package/dist/modules/smeup-file/index.d.ts.map +1 -0
  85. package/dist/modules/smeup-file/index.js +17 -0
  86. package/dist/modules/smeup-file/index.js.map +1 -0
  87. package/dist/modules/sso/index.d.ts +40 -0
  88. package/dist/modules/sso/index.d.ts.map +1 -0
  89. package/dist/modules/sso/index.js +41 -0
  90. package/dist/modules/sso/index.js.map +1 -0
  91. package/dist/rx/index.d.ts +11 -0
  92. package/dist/rx/index.d.ts.map +1 -0
  93. package/dist/rx/index.js +20 -0
  94. package/dist/rx/index.js.map +1 -0
  95. package/dist/session/auth-middleware.d.ts +27 -0
  96. package/dist/session/auth-middleware.d.ts.map +1 -0
  97. package/dist/session/auth-middleware.js +122 -0
  98. package/dist/session/auth-middleware.js.map +1 -0
  99. package/dist/session/jwt.d.ts +20 -0
  100. package/dist/session/jwt.d.ts.map +1 -0
  101. package/dist/session/jwt.js +25 -0
  102. package/dist/session/jwt.js.map +1 -0
  103. package/dist/session/stores.d.ts +19 -0
  104. package/dist/session/stores.d.ts.map +1 -0
  105. package/dist/session/stores.js +103 -0
  106. package/dist/session/stores.js.map +1 -0
  107. package/dist/session/types.d.ts +28 -0
  108. package/dist/session/types.d.ts.map +1 -0
  109. package/dist/session/types.js +2 -0
  110. package/dist/session/types.js.map +1 -0
  111. package/package.json +84 -30
  112. package/dist/core/axios.d.ts +0 -51
  113. package/dist/core/axios.js +0 -65
  114. package/dist/core/axios.observable.d.ts +0 -11
  115. package/dist/core/axios.observable.js +0 -58
  116. package/dist/core/base.provider.advanced.test.d.ts +0 -1
  117. package/dist/core/base.provider.advanced.test.js +0 -29
  118. package/dist/core/base.provider.d.ts +0 -15
  119. package/dist/core/base.provider.js +0 -13
  120. package/dist/core/base.provider.test.d.ts +0 -1
  121. package/dist/core/base.provider.test.js +0 -36
  122. package/dist/core/base.service.wrapper.advanced.test.d.ts +0 -1
  123. package/dist/core/base.service.wrapper.advanced.test.js +0 -39
  124. package/dist/core/base.service.wrapper.d.ts +0 -7
  125. package/dist/core/base.service.wrapper.js +0 -11
  126. package/dist/core/base.service.wrapper.test.d.ts +0 -1
  127. package/dist/core/base.service.wrapper.test.js +0 -25
  128. package/dist/core/rx.http.service.d.ts +0 -51
  129. package/dist/core/rx.http.service.js +0 -65
  130. package/dist/services/auth.service.d.ts +0 -65
  131. package/dist/services/auth.service.js +0 -197
  132. package/dist/services/auth.service.test.d.ts +0 -1
  133. package/dist/services/auth.service.test.js +0 -334
  134. package/dist/services/cache.service.d.ts +0 -31
  135. package/dist/services/cache.service.js +0 -77
  136. package/dist/services/cache.service.test.d.ts +0 -1
  137. package/dist/services/cache.service.test.js +0 -88
  138. package/dist/services/customer.service.d.ts +0 -211
  139. package/dist/services/customer.service.js +0 -128
  140. package/dist/services/customer.service.test.d.ts +0 -1
  141. package/dist/services/customer.service.test.js +0 -430
  142. package/dist/services/employee.service.d.ts +0 -73
  143. package/dist/services/employee.service.js +0 -74
  144. package/dist/services/employee.service.test.d.ts +0 -1
  145. package/dist/services/employee.service.test.js +0 -127
  146. package/dist/services/logger.service.d.ts +0 -31
  147. package/dist/services/logger.service.js +0 -93
  148. package/dist/services/logger.service.test.d.ts +0 -1
  149. package/dist/services/logger.service.test.js +0 -31
  150. package/dist/services/order.service.d.ts +0 -73
  151. package/dist/services/order.service.js +0 -97
  152. package/dist/services/order.service.test.d.ts +0 -1
  153. package/dist/services/order.service.test.js +0 -163
  154. package/dist/services/product.service.d.ts +0 -21
  155. package/dist/services/product.service.js +0 -42
  156. package/dist/services/product.service.test.d.ts +0 -1
  157. package/dist/services/product.service.test.js +0 -61
  158. package/dist/services/smess.service.d.ts +0 -36
  159. package/dist/services/smess.service.js +0 -128
  160. package/dist/services/smess.service.test.d.ts +0 -1
  161. package/dist/services/smess.service.test.js +0 -103
  162. package/dist/services/store.cart.service.d.ts +0 -158
  163. package/dist/services/store.cart.service.js +0 -177
  164. package/dist/services/store.cart.service.test.d.ts +0 -1
  165. package/dist/services/store.cart.service.test.js +0 -394
  166. package/dist/services/store.product.service.d.ts +0 -124
  167. package/dist/services/store.product.service.js +0 -102
  168. package/dist/services/store.product.service.test.d.ts +0 -1
  169. package/dist/services/store.product.service.test.js +0 -319
  170. package/dist/services/store.service.d.ts +0 -79
  171. package/dist/services/store.service.js +0 -235
  172. package/dist/services/store.service.test.d.ts +0 -1
  173. package/dist/services/store.service.test.js +0 -274
  174. package/dist/services/storefront.cart.service.d.ts +0 -73
  175. package/dist/services/storefront.cart.service.js +0 -167
  176. package/dist/services/storefront.cart.service.test.d.ts +0 -1
  177. package/dist/services/storefront.cart.service.test.js +0 -211
  178. package/dist/services/storefront.checkout.service.d.ts +0 -62
  179. package/dist/services/storefront.checkout.service.js +0 -75
  180. package/dist/services/storefront.checkout.service.test.d.ts +0 -1
  181. package/dist/services/storefront.checkout.service.test.js +0 -158
  182. package/dist/services/storefront.customer.metadata.service.d.ts +0 -91
  183. package/dist/services/storefront.customer.metadata.service.js +0 -225
  184. package/dist/services/storefront.customer.metadata.service.test.d.ts +0 -1
  185. package/dist/services/storefront.customer.metadata.service.test.js +0 -271
  186. package/dist/services/storefront.order.service.d.ts +0 -45
  187. package/dist/services/storefront.order.service.js +0 -99
  188. package/dist/services/storefront.order.service.test.d.ts +0 -1
  189. package/dist/services/storefront.order.service.test.js +0 -158
  190. package/dist/services/storefront.product.service.d.ts +0 -52
  191. package/dist/services/storefront.product.service.js +0 -75
  192. package/dist/services/storefront.product.service.test.d.ts +0 -1
  193. package/dist/services/storefront.product.service.test.js +0 -120
  194. package/dist/services/storefront.store.service.d.ts +0 -54
  195. package/dist/services/storefront.store.service.js +0 -142
  196. package/dist/services/storefront.store.service.test.d.ts +0 -1
  197. package/dist/services/storefront.store.service.test.js +0 -90
  198. package/dist/services/user.service.d.ts +0 -16
  199. package/dist/services/user.service.js +0 -37
  200. package/dist/services/user.service.test.d.ts +0 -1
  201. package/dist/services/user.service.test.js +0 -52
  202. package/dist/services/utils/withAuthReset.d.ts +0 -3
  203. package/dist/services/utils/withAuthReset.js +0 -8
  204. package/dist/src/core/axios.d.ts +0 -51
  205. package/dist/src/core/axios.js +0 -65
  206. package/dist/src/core/axios.observable.d.ts +0 -11
  207. package/dist/src/core/axios.observable.js +0 -58
  208. package/dist/src/core/base.provider.advanced.test.d.ts +0 -1
  209. package/dist/src/core/base.provider.advanced.test.js +0 -29
  210. package/dist/src/core/base.provider.d.ts +0 -15
  211. package/dist/src/core/base.provider.js +0 -13
  212. package/dist/src/core/base.provider.test.d.ts +0 -1
  213. package/dist/src/core/base.provider.test.js +0 -36
  214. package/dist/src/core/base.service.wrapper.advanced.test.d.ts +0 -1
  215. package/dist/src/core/base.service.wrapper.advanced.test.js +0 -39
  216. package/dist/src/core/base.service.wrapper.d.ts +0 -7
  217. package/dist/src/core/base.service.wrapper.js +0 -11
  218. package/dist/src/core/base.service.wrapper.test.d.ts +0 -1
  219. package/dist/src/core/base.service.wrapper.test.js +0 -25
  220. package/dist/src/core/rx.http.service.d.ts +0 -51
  221. package/dist/src/core/rx.http.service.js +0 -65
  222. package/dist/src/index.d.ts +0 -25
  223. package/dist/src/index.js +0 -29
  224. package/dist/src/services/auth.service.d.ts +0 -65
  225. package/dist/src/services/auth.service.js +0 -197
  226. package/dist/src/services/auth.service.test.d.ts +0 -1
  227. package/dist/src/services/auth.service.test.js +0 -334
  228. package/dist/src/services/cache.service.d.ts +0 -31
  229. package/dist/src/services/cache.service.js +0 -77
  230. package/dist/src/services/cache.service.test.d.ts +0 -1
  231. package/dist/src/services/cache.service.test.js +0 -88
  232. package/dist/src/services/customer.service.d.ts +0 -199
  233. package/dist/src/services/customer.service.js +0 -114
  234. package/dist/src/services/customer.service.test.d.ts +0 -1
  235. package/dist/src/services/customer.service.test.js +0 -430
  236. package/dist/src/services/employee.service.d.ts +0 -73
  237. package/dist/src/services/employee.service.js +0 -74
  238. package/dist/src/services/employee.service.test.d.ts +0 -1
  239. package/dist/src/services/employee.service.test.js +0 -127
  240. package/dist/src/services/logger.service.d.ts +0 -31
  241. package/dist/src/services/logger.service.js +0 -93
  242. package/dist/src/services/logger.service.test.d.ts +0 -1
  243. package/dist/src/services/logger.service.test.js +0 -31
  244. package/dist/src/services/order.service.d.ts +0 -73
  245. package/dist/src/services/order.service.js +0 -97
  246. package/dist/src/services/order.service.test.d.ts +0 -1
  247. package/dist/src/services/order.service.test.js +0 -163
  248. package/dist/src/services/product.service.d.ts +0 -21
  249. package/dist/src/services/product.service.js +0 -42
  250. package/dist/src/services/product.service.test.d.ts +0 -1
  251. package/dist/src/services/product.service.test.js +0 -61
  252. package/dist/src/services/smess.service.d.ts +0 -36
  253. package/dist/src/services/smess.service.js +0 -128
  254. package/dist/src/services/smess.service.test.d.ts +0 -1
  255. package/dist/src/services/smess.service.test.js +0 -103
  256. package/dist/src/services/store.cart.service.d.ts +0 -158
  257. package/dist/src/services/store.cart.service.js +0 -177
  258. package/dist/src/services/store.cart.service.test.d.ts +0 -1
  259. package/dist/src/services/store.cart.service.test.js +0 -394
  260. package/dist/src/services/store.product.service.d.ts +0 -124
  261. package/dist/src/services/store.product.service.js +0 -102
  262. package/dist/src/services/store.product.service.test.d.ts +0 -1
  263. package/dist/src/services/store.product.service.test.js +0 -319
  264. package/dist/src/services/store.service.d.ts +0 -79
  265. package/dist/src/services/store.service.js +0 -235
  266. package/dist/src/services/store.service.test.d.ts +0 -1
  267. package/dist/src/services/store.service.test.js +0 -274
  268. package/dist/src/services/storefront.cart.service.d.ts +0 -73
  269. package/dist/src/services/storefront.cart.service.js +0 -167
  270. package/dist/src/services/storefront.cart.service.test.d.ts +0 -1
  271. package/dist/src/services/storefront.cart.service.test.js +0 -211
  272. package/dist/src/services/storefront.checkout.service.d.ts +0 -62
  273. package/dist/src/services/storefront.checkout.service.js +0 -75
  274. package/dist/src/services/storefront.checkout.service.test.d.ts +0 -1
  275. package/dist/src/services/storefront.checkout.service.test.js +0 -158
  276. package/dist/src/services/storefront.customer.metadata.service.d.ts +0 -91
  277. package/dist/src/services/storefront.customer.metadata.service.js +0 -225
  278. package/dist/src/services/storefront.customer.metadata.service.test.d.ts +0 -1
  279. package/dist/src/services/storefront.customer.metadata.service.test.js +0 -271
  280. package/dist/src/services/storefront.order.service.d.ts +0 -45
  281. package/dist/src/services/storefront.order.service.js +0 -99
  282. package/dist/src/services/storefront.order.service.test.d.ts +0 -1
  283. package/dist/src/services/storefront.order.service.test.js +0 -158
  284. package/dist/src/services/storefront.product.service.d.ts +0 -52
  285. package/dist/src/services/storefront.product.service.js +0 -75
  286. package/dist/src/services/storefront.product.service.test.d.ts +0 -1
  287. package/dist/src/services/storefront.product.service.test.js +0 -120
  288. package/dist/src/services/storefront.store.service.d.ts +0 -52
  289. package/dist/src/services/storefront.store.service.js +0 -140
  290. package/dist/src/services/storefront.store.service.test.d.ts +0 -1
  291. package/dist/src/services/storefront.store.service.test.js +0 -90
  292. package/dist/src/services/user.service.d.ts +0 -16
  293. package/dist/src/services/user.service.js +0 -37
  294. package/dist/src/services/user.service.test.d.ts +0 -1
  295. package/dist/src/services/user.service.test.js +0 -52
  296. package/dist/src/services/utils/withAuthReset.d.ts +0 -3
  297. package/dist/src/services/utils/withAuthReset.js +0 -8
  298. package/dist/src/types/types.d.ts +0 -93
  299. package/dist/src/types/types.js +0 -82
  300. package/dist/src/types/types.test.d.ts +0 -1
  301. package/dist/src/types/types.test.js +0 -25
  302. package/dist/src/utils/cache-import.d.ts +0 -3
  303. package/dist/src/utils/cache-import.js +0 -2
  304. package/dist/src/utils/networking-import.d.ts +0 -4
  305. package/dist/src/utils/networking-import.js +0 -3
  306. package/dist/src/utils/rxjs-import.d.ts +0 -5
  307. package/dist/src/utils/rxjs-import.js +0 -5
  308. package/dist/types/types.d.ts +0 -96
  309. package/dist/types/types.js +0 -82
  310. package/dist/types/types.test.d.ts +0 -1
  311. package/dist/types/types.test.js +0 -25
  312. package/dist/utils/cache-import.d.ts +0 -3
  313. package/dist/utils/cache-import.js +0 -2
  314. package/dist/utils/networking-import.d.ts +0 -4
  315. package/dist/utils/networking-import.js +0 -3
  316. package/dist/utils/rxjs-import.d.ts +0 -5
  317. package/dist/utils/rxjs-import.js +0 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,221 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@smess/networking`. Versions follow [semver](https://semver.org).
4
+
5
+ ## 2.1.0 (2026-11-07)
6
+
7
+ ### Added
8
+
9
+ - `@smess/networking/messenger`: `send` (website contact forms and leads, `POST /v1/messenger/send`), `get`
10
+ and `trackWebsiteEvent` (`POST /v1/messenger/website_events`). Anonymous; the tenant goes in the body's
11
+ `client_id` (defaults to the client's `clientId`), so one build can serve domains whose CORS origins are
12
+ bound to different tenants.
13
+ - `messenger` host key in `PRODUCTION_HOSTS` (`api.smess.vn`).
14
+
15
+ ## 2.0.0 (2026-11-07)
16
+
17
+ A rewrite: one typed client for core-services, built on `fetch`. Not compatible with 1.x.
18
+
19
+ ### Added
20
+
21
+ - `createSmessClient` with a host map per core service, the tenant header (`clientId` → `X-Client-Id`),
22
+ per-request timeout combined with the caller's `AbortSignal`, app middleware and opt-in retries.
23
+ - Endpoint contracts (`defineEndpoint`) with per-route auth mode (`none` / `optional` / `required`), so a
24
+ stale Bearer is never sent to core's anonymous firewalls.
25
+ - Sessions: `webStorageSession`, `memorySession`, `staticSession`; refresh 30 s before expiry and once on
26
+ 401, single-flight across concurrent requests; `onSessionExpired`.
27
+ - `SmessApiError` with `kind`, `status`, `code`, `serverMessage`, `fields`, `retryAfter`, parsed from every
28
+ error format core-services emits.
29
+ - Modules: `authentication`, `sso`, `campaign` (the smeup.email API), `smeup-file`, `danara`; optional
30
+ `rx` adapter.
31
+ - Read-only smoke test against PROD Danara (`make smoke`), route table snapshot test.
32
+ - Publishing from GitHub Actions with npm trusted publishing.
33
+
34
+ ### Fixed (compared with the hand-written app clients it replaces)
35
+
36
+ - OTP and password-reset logins keep their refresh token: core returns it as `refreshToken` (camelCase),
37
+ which smeup.email read as `refresh_token`, so those sessions ended after one hour.
38
+ - A caller's `AbortSignal` no longer disables the request timeout (Danara client).
39
+
40
+ ### Removed
41
+
42
+ - The whole 1.x API (axios, rxjs services, Dexie cache, storefront services). Apps on 1.x keep working on
43
+ their pinned 1.x version; GPM migrates module by module.
44
+ - Duplicate source tree `src/src`, the committed 1.0.18 tarball, Jest, per-version changelog files.
45
+
46
+ ## 1.x history
47
+
48
+ Generated from the former per-version changelog files. `1.2.0` was published by mistake before `1.1.1`;
49
+ do not use it.
50
+
51
+ ### 1.2.0
52
+
53
+ - Update customer.service.ts
54
+ - Update package
55
+
56
+ ### 1.1.5 (2026-01-14)
57
+
58
+ - [Authentication] Update VerifyResetPassword
59
+
60
+ ### 1.1.4 (2026-01-14)
61
+
62
+ - [Authentication] Update VerifyResetPassword
63
+
64
+ ### 1.1.3 (2026-01-14)
65
+
66
+ - [Authentication] Update VerifyResetPassword
67
+
68
+ ### 1.1.2 (2025-11-24)
69
+
70
+ - Update customer-product-remove
71
+
72
+ ### 1.1.1 (2025-11-23)
73
+
74
+ - Update customer.service.ts
75
+ - Update package
76
+
77
+ ### 1.1.0 (2025-11-20)
78
+
79
+ - Update storefront.store.service.ts
80
+ - Update storefront.store.service.ts
81
+
82
+ ### 1.0.30
83
+
84
+ - Update storefront.store.service.ts
85
+ - Update storefront.store.service.ts
86
+
87
+ ### 1.0.29 (2025-11-10)
88
+
89
+ - [Fix] Bug
90
+
91
+ ### 1.0.28 (2025-11-10)
92
+
93
+ - fix: remove customer product notes flow
94
+
95
+ ### 1.0.27 (2025-11-10)
96
+
97
+ - feat(customer): add product category management
98
+
99
+ ### 1.0.26 (2025-11-09)
100
+
101
+ - chore(build): clean publish artifacts
102
+
103
+ ### 1.0.25 (2025-11-09)
104
+
105
+ - chore: export employee service
106
+ - chore: expose helper and archive changelog
107
+ - feat(auth): share auth reset helper
108
+
109
+ ### 1.0.24 (2025-11-09)
110
+
111
+ - feat(employee): add service and tests
112
+ - feat(customer): support cart and product operations
113
+
114
+ ### 1.0.23 (2025-10-24)
115
+
116
+ - fix: Fix customer services
117
+
118
+ ### 1.0.22 (2025-10-24)
119
+
120
+ - [StoreProduct] Fix bug
121
+
122
+ ### 1.0.21 (2025-10-20)
123
+
124
+ - feat(dev-test): add Step 7.5 to use StoreCartService.batchItems\n\n- Call POST /store/cart/items/batch with dynamic create/update payloads\n- Log cart state after batch op and handle errors consistently
125
+ - feat(cart): add batch items endpoint and tests\n\n- Add cart-batch-items target in StoreCartProvider (POST /store/cart/items/batch)\n- Define CartBatchItemsRequest payload type (create/update arrays)\n- Implement StoreCartService.batchItems(payload) with cart hash update\n- Add unit tests for success and error cases of batchItems
126
+
127
+ ### 1.0.20 (2025-10-16)
128
+
129
+ - fix: update real-test.ts to use correct services and remove
130
+ - fix: resolve errors in dev-test.ts
131
+ - refactor: remove from StoreService - stores are open access
132
+ - refactor: remove redundant functions from StoreProductService
133
+
134
+ ### 1.0.19 (2025-10-15)
135
+
136
+ - fix: standardize service return types and fix dev-test JSON parsing
137
+
138
+ ### 1.0.18 (2025-10-14)
139
+
140
+ - fix(store-product): rename interfaces to avoid export conflicts
141
+
142
+ ### 1.0.17 (2025-10-14)
143
+
144
+ - fix(dev-test): properly extract cart data from nested response structure
145
+ - fix(store-cart): handle nested data structure in cart response
146
+ - feat(dev-test): add comprehensive E2E store and cart flow test
147
+ - feat(store-cart): add storeId support and X-Store-Id header
148
+ - feat(store): add StoreProductService with product and store endpoints
149
+ - Add StoreCartService with cart hash management
150
+
151
+ ### 1.0.16 (2025-09-23)
152
+
153
+ - Simplify AuthService logic and add rememberMe test
154
+
155
+ ### 1.0.15 (2025-09-23)
156
+
157
+ - Fix orde.service collection
158
+
159
+ ### 1.0.14 (2025-09-22)
160
+
161
+ - Fix bear authentication
162
+
163
+ ### 1.0.13 (2025-09-22)
164
+
165
+ - feat: add collection function to OrderService
166
+
167
+ ### 1.0.12 (2025-09-22)
168
+
169
+ - fix release script
170
+
171
+ ### 1.0.11 (2025-09-22)
172
+
173
+ - Fix types check
174
+ - refactor: AuthService manages authToken internally
175
+
176
+ ### 1.0.10 (2025-08-02)
177
+
178
+ - refactor: AuthService manages authToken internally
179
+ - chore(release): generate changelog for v1.0.10
180
+ - Update order services
181
+
182
+ ### 1.0.9 (2025-07-26)
183
+
184
+ - Implement cache-first strategy for store
185
+ - Implement cache-service
186
+
187
+ ### 1.0.8 (2025-07-26)
188
+
189
+ - Export all services
190
+
191
+ ### 1.0.7 (2025-07-26)
192
+
193
+ - Update build fixed
194
+ - Revert "Update build for ES module"
195
+ - Revert Update build for ES module
196
+ - Revert "chore(release): generate changelog for v1.0.6"
197
+
198
+ ### 1.0.5 (2025-07-23)
199
+
200
+ - Update build for ES module
201
+
202
+ ### 1.0.4 (2025-07-22)
203
+
204
+ - Implement store service
205
+ - Implement order service
206
+ - Implement customer service
207
+ - Fix bugs and improvement auth.services - make real test working
208
+ - refactor!: move all services to services/, update docs and examples for @smess/networking, fix all tests and scripts for new structure
209
+
210
+ ### 1.0.3 (2025-07-22)
211
+
212
+ - Fix bugs and improvement
213
+
214
+ ### 1.0.2 (2025-07-17)
215
+
216
+ - Bump new version
217
+
218
+ ### 1.0.1 (2025-07-17)
219
+
220
+ - Build Networking utilities and services for SMESS platform
221
+
package/README.md CHANGED
@@ -1,147 +1,214 @@
1
- # SMESS Networking Package
1
+ # @smess/networking
2
2
 
3
- ## Features
3
+ The standard client for the SMESS core-services API (`backend/smess-core-services`), for every SMESS
4
+ JavaScript/TypeScript product: browser SPAs, Next.js (server and client components), Node scripts and
5
+ React Native.
4
6
 
5
- - Per-instance configuration (no global config)
6
- - RxJS-based HTTP services
7
- - Extensible provider/service architecture
8
- - TypeScript-first
9
- - **Bundler-friendly** (Webpack, Vite, Rollup compatible)
7
+ - Built on `fetch`, no runtime dependencies, ESM, typed.
8
+ - One client per app: it knows core's hosts, the tenant header, the session and its refresh.
9
+ - One module per core-services Microservice: `authentication`, `sso`, `campaign`, `smeup-file`, `danara`,
10
+ `messenger`.
11
+ - One error type, `SmessApiError`, for every error format core emits.
10
12
 
11
- ## Installation
13
+ Layers and the backend facts behind them: [docs/architecture.md](docs/architecture.md).
12
14
 
13
- ```bash
15
+ ```sh
14
16
  npm install @smess/networking
15
17
  ```
16
18
 
17
- ## Usage
18
-
19
- ### 1. Define your config
20
-
21
- ```typescript
22
- const configA = {
23
- baseUrl: "https://api-a",
24
- isProd: false,
25
- clientId: "A",
26
- apiKey: "keyA",
27
- };
28
- const configB = {
29
- baseUrl: "https://api-b",
30
- isProd: true,
31
- clientId: "B",
32
- apiKey: "keyB",
33
- };
34
- ```
35
-
36
- ### 2. Create providers/services with config
19
+ ## Quick start
37
20
 
38
- ```typescript
39
- import { ProductService, UserService, AuthService } from "@smess/networking";
21
+ ### Browser app with a signed-in user (smeup.email)
40
22
 
41
- const productServiceA = new ProductService(configA);
42
- const productServiceB = new ProductService(configB);
43
- const userServiceA = new UserService(configA);
44
- const authServiceA = new AuthService(configA);
45
- ```
23
+ ```ts
24
+ import { createSmessClient, PRODUCTION_HOSTS, webStorageSession } from '@smess/networking';
25
+ import { authentication, authenticationRefresh } from '@smess/networking/authentication';
26
+ import { campaign } from '@smess/networking/campaign';
46
27
 
47
- ### 3. Use services independently
28
+ export const smess = createSmessClient({
29
+ hosts: PRODUCTION_HOSTS,
30
+ session: webStorageSession({ accessKey: 'app.token', refreshKey: 'app.refresh' }),
31
+ refresh: authenticationRefresh(),
32
+ onSessionExpired: () => router.navigate({ to: '/login' }),
33
+ });
48
34
 
49
- ```typescript
50
- // Using RxJS Observables
51
- productServiceA.fetchAllProducts().subscribe(...);
52
- productServiceB.createProduct({ name: 'X', price: 10 }).subscribe(...);
53
- userServiceA.fetchUserById(1).subscribe(...);
54
- authServiceA.login({ identifier: 'user', password: 'pass' }).subscribe(...);
35
+ const auth = authentication(smess);
36
+ await auth.otp.request({ identifier: email });
37
+ await auth.otp.verify({ identifier: email, code }); // saves the session
55
38
 
56
- // Or convert to Promises for async/await
57
- const user = await userServiceA.fetchUserById(1).toPromise();
58
- const products = await productServiceA.fetchAllProducts().toPromise();
39
+ const templates = await campaign(smess).email.templates.list(); // ApiList<Template>
59
40
  ```
60
41
 
61
- ### 4. Example: Custom Provider
62
-
63
- ```typescript
64
- import { BaseProvider, SmessService } from "@smess/networking";
65
-
66
- const config = {
67
- baseUrl: "https://custom-api",
68
- isProd: false,
69
- clientId: "custom-client",
70
- apiKey: "custom-key",
71
- };
72
-
73
- class ExampleProvider extends BaseProvider {
74
- constructor(config, resourceId: string) {
75
- super({
76
- config,
77
- path: `/resource/${resourceId}`,
78
- method: "GET",
79
- headers: { "Custom-Header": "value" },
80
- getPath: () => `/resource/${resourceId}`,
81
- });
82
- }
83
- }
42
+ ### Public website form (smess.vn)
43
+
44
+ ```ts
45
+ import { createSmessClient, PRODUCTION_HOSTS } from '@smess/networking';
46
+ import { messenger } from '@smess/networking/messenger';
84
47
 
85
- const provider = new ExampleProvider(config, "123");
86
- const service = new SmessService(provider);
87
- service.request().subscribe((result) => {
88
- // handle result
48
+ const forms = messenger(createSmessClient({ hosts: PRODUCTION_HOSTS }));
49
+ await forms.send({
50
+ client_id: TENANT_ID, // the tenant that owns the site's leads
51
+ type: 'contact_form', // never lead_capture on a contact form: that starts a Rebuild job
52
+ from_name, from_email, subject, message,
89
53
  });
90
54
  ```
91
55
 
92
- ## Bundler Compatibility
93
-
94
- This package is designed to work seamlessly with modern bundlers:
56
+ ### Tenant-scoped app, Next.js server component (Danara)
95
57
 
96
- - **Webpack** ✅
97
- - **Vite** ✅
98
- - **Rollup** ✅
99
- - **Parcel** ✅
58
+ ```ts
59
+ import { createSmessClient, staticSession } from '@smess/networking';
60
+ import { danara } from '@smess/networking/danara';
100
61
 
101
- The package uses **extensionless imports** in TypeScript source code, which bundlers handle automatically. No `.js` extensions needed in your imports!
102
-
103
- ### Example with Webpack/Vite
62
+ // Module scope: no session here, a server client is shared by every request.
63
+ const base = createSmessClient({
64
+ hosts: { danara: 'https://api.danara.vn' },
65
+ clientId: process.env.NEXT_PUBLIC_CLIENT_ID, // X-Client-Id on every request
66
+ timeoutMs: 15_000,
67
+ });
104
68
 
105
- ```typescript
106
- // ✅ This works perfectly with bundlers
107
- import { UserService, ProductService } from "@smess/networking";
69
+ // Per request: the visitor's token, read from the request cookie.
70
+ const api = danara(base.with({ session: staticSession(await getServerAuthToken()) }));
71
+ const { data, meta } = await api.listings.list({ page: 1, ward: 'son-tra' });
72
+ const contracts = await api.leasing.contracts.get(uuid); // sends the Bearer
73
+ ```
108
74
 
109
- const config = { baseUrl: "https://api.example.com", isProd: false };
110
- const userService = new UserService(config);
111
- const productService = new ProductService(config);
75
+ ## The client
76
+
77
+ ```ts
78
+ createSmessClient({
79
+ hosts, // required: base URL per service (PRODUCTION_HOSTS, or your environment)
80
+ clientId, // tenant UUID → X-Client-Id on every request
81
+ session, // SessionStore: webStorageSession() | memorySession() | staticSession(token) | your own
82
+ refresh, // RefreshStrategy, e.g. authenticationRefresh()
83
+ onSessionExpired, // called once when the session is cleared because it could not be renewed
84
+ timeoutMs, // default 30 000; 0 disables
85
+ headers, // on every request (e.g. Accept-Language)
86
+ fetchOptions, // passed to fetch (cache, credentials, Next.js `next`)
87
+ middleware, // app middleware (logging, metrics, test doubles)
88
+ retry, // opt-in: { retries: 2 } retries GET on network errors, 429, 502, 503, 504
89
+ fetch, // custom fetch
90
+ });
112
91
  ```
113
92
 
114
- ## Available Services
93
+ | Method | Purpose |
94
+ |---|---|
95
+ | `client.call(endpoint, input)` | Call a declared endpoint (what modules do). |
96
+ | `client.request({ service, method, path, auth, … })` | Any route no module covers yet. `auth` is required. |
97
+ | `client.with(overrides)` | Derived client (per-request session, other timeout). Shares the session store. |
98
+ | `client.session.get/set/clear/claims()` | The current session and its JWT claims (unverified). |
99
+
100
+ Every module function takes optional per-call options as its last argument:
101
+ `{ signal, timeoutMs, headers, idempotencyKey, fetchOptions }`.
102
+
103
+ ### Auth modes
104
+
105
+ Each endpoint declares how it uses the session, because core rejects any stale Bearer with 401, even
106
+ on public routes:
107
+
108
+ | `auth` | Behaviour |
109
+ |---|---|
110
+ | `none` | Never sends `Authorization` (login, refresh, OTP, SSO, public catalogs). |
111
+ | `optional` | Sends the token when signed in. |
112
+ | `required` | Fails with `unauthenticated` / `no_session` before the network when signed out. |
113
+
114
+ ### Sessions and refresh
115
+
116
+ - The access token is refreshed 30 s before its `exp`, and once on a 401. Concurrent requests share
117
+ one refresh.
118
+ - A refresh rejected with 4xx clears the session and calls `onSessionExpired({ reason: 'refresh_failed' })`.
119
+ A network or 5xx failure keeps the session.
120
+ - A 401 that cannot be refreshed clears the session (`reason: 'unauthorized'`).
121
+ - Server code: never share a writable store between requests. Use `staticSession(token)` per request.
122
+
123
+ ### Tenant (`clientId`)
124
+
125
+ core-services rejects a JWT whose `client_id` differs from the `X-Client-Id` header, and a browser
126
+ origin bound to a tenant must send that tenant. So a client either always sends the same tenant or
127
+ never sends one. smeup.email sends none (the tenant comes from the JWT); Danara always sends its own.
128
+
129
+ ## Modules
130
+
131
+ | Import | Backend module | Host key | Notes |
132
+ |---|---|---|---|
133
+ | `@smess/networking/authentication` | Authentication | `authentication` | password, OTP, refresh, reset, change password, logout |
134
+ | `@smess/networking/sso` | Sso | `sso` | `start`, `completeLogin(location.hash)`, `parseSsoCallback`, `readSsoError` |
135
+ | `@smess/networking/campaign` | Campaign (email) | `campaignApi` | the whole smeup.email API: sender, templates, campaigns, audiences, domains, addresses, short links, segments, automations, A/B tests, developers, SSO settings |
136
+ | `@smess/networking/smeup-file` | SMEUpFile | `smeupFile` | base64 upload |
137
+ | `@smess/networking/danara` | Danara | `danara` | identity, listings, sales, fit-out, leasing, owner portal, transit |
138
+ | `@smess/networking/messenger` | Messenger | `messenger` | website contact forms and leads (`send`), visitor events (`trackWebsiteEvent`) |
139
+ | `@smess/networking/rx` | – | – | `fromSmess(signal => call)` → cancellable Observable (peer dep `rxjs`) |
140
+
141
+ Each module also exports its endpoint table (`campaignEmailEndpoints`, `danaraEndpoints`, …) and its
142
+ wire types.
143
+
144
+ **Wire types are the server's.** Field names are exactly what core sends (mostly snake_case; Danara
145
+ and a few others camelCase), so a type always matches DevTools. Single objects wrapped in `{"data": …}`
146
+ are unwrapped; list envelopes are returned as sent because they carry the pagination
147
+ (`ApiList<T>` = `{object: 'list', data, has_more, total_count}`, `PagedList<T>` = `{data, meta}`).
148
+ Walk a cursor list with `paginate()`.
149
+
150
+ ## Errors
151
+
152
+ Every call rejects with `SmessApiError`:
153
+
154
+ ```ts
155
+ try {
156
+ await email.domains.create('example.com');
157
+ } catch (error) {
158
+ if (isSmessApiError(error)) {
159
+ error.kind; // 'validation' | 'unauthenticated' | 'forbidden' | 'not_found' | 'rate_limited' | …
160
+ error.status; // HTTP status, 0 without a response
161
+ error.code; // e.g. 'missing_client_id', 'email_already_registered', 'invalid_code'
162
+ error.serverMessage; // the server's text (may be an i18n key such as error.validation.not_blank)
163
+ error.fields; // { field: 'first message' }
164
+ error.retryAfter; // seconds, on 429
165
+ }
166
+ }
167
+ ```
115
168
 
116
- - `UserService` - User management operations
117
- - `ProductService` - Product CRUD operations
118
- - `AuthService` - Authentication (login, logout, password reset)
119
- - `CustomerService` - Customer registration and profile management
120
- - `OrderService` - Order management
121
- - `StoreService` - Store and product catalog operations
169
+ The parser reads all of core's formats: Stripe-style `{error: {type, code, message, param}}`,
170
+ `{errors: {field: [{message}]}}`, `{code, message}`, `{is_success: false, error_message}`,
171
+ `{error: "text"}`, `violations`, plain text, and HTML pages (status only).
122
172
 
123
- ## Development
173
+ ## Routes not in a module yet
124
174
 
125
- ```bash
126
- # Install dependencies
127
- npm install
175
+ ```ts
176
+ await client.request<MoveInCost>({
177
+ service: 'danara',
178
+ method: 'GET',
179
+ path: '/v1/listings/{uuid}/move-in-cost',
180
+ pathParams: { uuid },
181
+ auth: 'none',
182
+ });
183
+ ```
128
184
 
129
- # Build the package
130
- npm run build
185
+ Add the route to its module once it exists in core-services, with its type taken from the backend
186
+ transformer or DTO, and a line in the route table snapshot (`test/__snapshots__`).
131
187
 
132
- # Run tests
133
- npm test
188
+ ## Development
134
189
 
135
- # Clean build artifacts
136
- npm run clean
190
+ ```sh
191
+ make install # npm ci
192
+ make check # lint, typecheck, tests, build, publint
193
+ make smoke # read-only checks of the built package against PROD Danara (DANARA_CLIENT_ID=… make smoke)
137
194
  ```
138
195
 
139
- ---
196
+ Try a local build in an app without publishing: `npm pack`, then in the app
197
+ `npm install --no-save /path/to/smess-networking-2.x.y.tgz`.
198
+
199
+ ## Release
140
200
 
141
- ## Private Package Usage
201
+ Releases are published from GitHub Actions (`.github/workflows/release.yml`) when a `v*` tag is
202
+ pushed, with npm trusted publishing (no token stored anywhere).
142
203
 
143
- See [SETUP.md](./SETUP.md) for instructions on using this package as a private dependency (GitHub repo, GitHub Packages, npm private registry) with the correct package name: `@smess/networking`.
204
+ 1. Add the version's section to `CHANGELOG.md` and commit.
205
+ 2. `make release VERSION=2.0.1` (bumps `package.json`, commits, tags `v2.0.1`, pushes).
206
+ 3. The workflow checks the tag against `package.json`, runs `npm run check`, publishes (pre-releases such
207
+ as `2.1.0-beta.1` go to the `next` dist-tag) and creates the GitHub release.
144
208
 
145
- ---
209
+ One-time setup on npmjs.com: package `@smess/networking` → Settings → Trusted Publisher → GitHub
210
+ Actions, owner `smeservicescloud`, repository `smess-networking`, workflow `release.yml`. The repository is
211
+ private, so npm does not attach provenance.
146
212
 
147
- MIT License
213
+ Version policy: semver. Breaking changes to a module's functions or wire types are major versions;
214
+ new endpoints and modules are minor.
@@ -0,0 +1,10 @@
1
+ export interface EncodedBody {
2
+ body: BodyInit | undefined;
3
+ /** Set only for JSON; FormData and friends let `fetch` pick the header (multipart boundary). */
4
+ contentType?: string;
5
+ /** False for one-shot streams, which cannot be sent again on a retry. */
6
+ replayable: boolean;
7
+ }
8
+ /** Plain values become JSON; platform body types (FormData, Blob, URLSearchParams, buffers, strings) pass through. */
9
+ export declare function encodeBody(body: unknown): EncodedBody;
10
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/core/body.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,gGAAgG;IAChG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,UAAU,EAAE,OAAO,CAAC;CACrB;AAQD,sHAAsH;AACtH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAcrD"}
@@ -0,0 +1,22 @@
1
+ const has = (name) => typeof globalThis[name] === 'function';
2
+ function isInstance(value, name) {
3
+ return has(name) && value instanceof globalThis[name];
4
+ }
5
+ /** Plain values become JSON; platform body types (FormData, Blob, URLSearchParams, buffers, strings) pass through. */
6
+ export function encodeBody(body) {
7
+ if (body === undefined || body === null)
8
+ return { body: undefined, replayable: true };
9
+ if (typeof body === 'string')
10
+ return { body, replayable: true };
11
+ if (isInstance(body, 'ReadableStream'))
12
+ return { body: body, replayable: false };
13
+ if (isInstance(body, 'FormData') ||
14
+ isInstance(body, 'URLSearchParams') ||
15
+ isInstance(body, 'Blob') ||
16
+ body instanceof ArrayBuffer ||
17
+ ArrayBuffer.isView(body)) {
18
+ return { body: body, replayable: true };
19
+ }
20
+ return { body: JSON.stringify(body), contentType: 'application/json', replayable: true };
21
+ }
22
+ //# sourceMappingURL=body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/core/body.ts"],"names":[],"mappings":"AAQA,MAAM,GAAG,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,OAAQ,UAAsC,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC;AAE3G,SAAS,UAAU,CAAC,KAAc,EAAE,IAAY;IAC9C,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,YAAc,UAAsC,CAAC,IAAI,CAAuB,CAAC;AAC5G,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IACtF,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAChE,IAAI,UAAU,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAgB,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC7F,IACE,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC;QAC5B,UAAU,CAAC,IAAI,EAAE,iBAAiB,CAAC;QACnC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;QACxB,IAAI,YAAY,WAAW;QAC3B,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EACxB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,IAAgB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { RefreshStrategy } from '../session/auth-middleware.js';
2
+ import type { SmessJwtClaims } from '../session/jwt.js';
3
+ import type { Session, SessionExpiredEvent, SessionStore } from '../session/types.js';
4
+ import type { AnyEndpoint, CallArgs, CallOptions, EndpointResult } from './endpoint.js';
5
+ import type { HostMap, ServiceKey } from './hosts.js';
6
+ import type { Middleware } from './pipeline.js';
7
+ import type { RetryOptions } from './retry.js';
8
+ import type { AuthMode, FetchFunction, FetchOptions, HttpMethod, QueryParams, ResponseType } from './types.js';
9
+ export declare const DEFAULT_TIMEOUT_MS = 30000;
10
+ export declare const DEFAULT_REFRESH_SKEW_MS = 30000;
11
+ export interface SmessClientConfig {
12
+ /** Base URL per service. Required: the client never guesses an environment. See `PRODUCTION_HOSTS`. */
13
+ hosts: HostMap;
14
+ /**
15
+ * The tenant (Authentication Client UUID), sent as `X-Client-Id` on every request when set.
16
+ * core-services rejects a JWT whose `client_id` differs from this header, so a client either always
17
+ * sends the same tenant or never sends one.
18
+ */
19
+ clientId?: string | undefined;
20
+ /** Where the signed-in session lives. Omit for anonymous clients (and on servers, use `staticSession` per request). */
21
+ session?: SessionStore | null | undefined;
22
+ /** How to renew the access token; e.g. `authenticationRefresh()`. Omit when the login flow has no refresh token. */
23
+ refresh?: RefreshStrategy | null | undefined;
24
+ /** Called once when the session is cleared because it could not be renewed. */
25
+ onSessionExpired?: ((event: SessionExpiredEvent) => void) | undefined;
26
+ /** Per-request timeout in ms. Default 30 000; 0 disables. */
27
+ timeoutMs?: number | undefined;
28
+ /** Headers on every request (e.g. `Accept-Language`). */
29
+ headers?: Readonly<Record<string, string>> | undefined;
30
+ /** Custom fetch (tests, instrumentation). Default: the global fetch, resolved per call. */
31
+ fetch?: FetchFunction | undefined;
32
+ /** Extra fetch options on every request (`cache`, `credentials`, Next.js `next`, ...). */
33
+ fetchOptions?: FetchOptions | undefined;
34
+ /** App middleware, outermost first; runs around retries and auth. */
35
+ middleware?: readonly Middleware[] | undefined;
36
+ /** Opt-in retries for idempotent requests. Default: none. */
37
+ retry?: RetryOptions | null | undefined;
38
+ /** Refresh this long before the access token's `exp`. Default 30 000 ms. */
39
+ refreshSkewMs?: number | undefined;
40
+ }
41
+ /** An ad-hoc request for routes no module covers yet. `auth` is required: decide per route. */
42
+ export interface RawRequest extends CallOptions {
43
+ service?: ServiceKey;
44
+ /** Use instead of `service` for a URL outside the host map. */
45
+ baseUrl?: string;
46
+ method: HttpMethod;
47
+ /** Absolute path; `{name}` placeholders are filled from `pathParams`. */
48
+ path: string;
49
+ pathParams?: Readonly<Record<string, string | number>>;
50
+ auth: AuthMode;
51
+ query?: QueryParams;
52
+ body?: unknown;
53
+ requiresTenant?: boolean;
54
+ responseType?: ResponseType;
55
+ }
56
+ export interface SessionHandle {
57
+ get(): Promise<Session | null>;
58
+ set(session: Session): Promise<void>;
59
+ clear(): Promise<void>;
60
+ /** The current access token's claims (unverified), or null. */
61
+ claims(): Promise<SmessJwtClaims | null>;
62
+ }
63
+ export interface SmessClient {
64
+ readonly config: Readonly<SmessClientConfig>;
65
+ /** Calls a declared endpoint. */
66
+ call<E extends AnyEndpoint>(endpoint: E, ...args: CallArgs<E>): Promise<EndpointResult<E>>;
67
+ /** Calls any route. Prefer a module function when one exists. */
68
+ request<T = unknown>(request: RawRequest): Promise<T>;
69
+ /** A client with some settings replaced (headers are merged). Shares the session store unless replaced. */
70
+ with(overrides: Partial<SmessClientConfig>): SmessClient;
71
+ readonly session: SessionHandle;
72
+ }
73
+ export declare function createSmessClient(config: SmessClientConfig): SmessClient;
74
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"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"}