@smess/networking 1.1.5 → 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.
- package/CHANGELOG.md +211 -0
- package/README.md +165 -114
- package/dist/core/body.d.ts +10 -0
- package/dist/core/body.d.ts.map +1 -0
- package/dist/core/body.js +22 -0
- package/dist/core/body.js.map +1 -0
- package/dist/core/client.d.ts +74 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +124 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/decoders.d.ts +8 -0
- package/dist/core/decoders.d.ts.map +1 -0
- package/dist/core/decoders.js +26 -0
- package/dist/core/decoders.js.map +1 -0
- package/dist/core/endpoint.d.ts +69 -0
- package/dist/core/endpoint.d.ts.map +1 -0
- package/dist/core/endpoint.js +6 -0
- package/dist/core/endpoint.js.map +1 -0
- package/dist/core/hosts.d.ts +25 -0
- package/dist/core/hosts.d.ts.map +1 -0
- package/dist/core/hosts.js +22 -0
- package/dist/core/hosts.js.map +1 -0
- package/dist/core/pagination.d.ts +33 -0
- package/dist/core/pagination.d.ts.map +1 -0
- package/dist/core/pagination.js +23 -0
- package/dist/core/pagination.js.map +1 -0
- package/dist/core/pipeline.d.ts +25 -0
- package/dist/core/pipeline.d.ts.map +1 -0
- package/dist/core/pipeline.js +12 -0
- package/dist/core/pipeline.js.map +1 -0
- package/dist/core/retry.d.ts +18 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +47 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/transport.d.ts +30 -0
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/transport.js +73 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/core/types.d.ts +24 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/url.d.ts +15 -0
- package/dist/core/url.d.ts.map +1 -0
- package/dist/core/url.js +46 -0
- package/dist/core/url.js.map +1 -0
- package/dist/errors/parse-error-body.d.ts +20 -0
- package/dist/errors/parse-error-body.d.ts.map +1 -0
- package/dist/errors/parse-error-body.js +73 -0
- package/dist/errors/parse-error-body.js.map +1 -0
- package/dist/errors/smess-api-error.d.ts +70 -0
- package/dist/errors/smess-api-error.d.ts.map +1 -0
- package/dist/errors/smess-api-error.js +84 -0
- package/dist/errors/smess-api-error.js.map +1 -0
- package/dist/index.d.ts +27 -25
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -29
- package/dist/index.js.map +1 -0
- package/dist/modules/authentication/index.d.ts +89 -0
- package/dist/modules/authentication/index.d.ts.map +1 -0
- package/dist/modules/authentication/index.js +128 -0
- package/dist/modules/authentication/index.js.map +1 -0
- package/dist/modules/campaign/index.d.ts +212 -0
- package/dist/modules/campaign/index.d.ts.map +1 -0
- package/dist/modules/campaign/index.js +193 -0
- package/dist/modules/campaign/index.js.map +1 -0
- package/dist/modules/campaign/types.d.ts +562 -0
- package/dist/modules/campaign/types.d.ts.map +1 -0
- package/dist/modules/campaign/types.js +2 -0
- package/dist/modules/campaign/types.js.map +1 -0
- package/dist/modules/danara/index.d.ts +153 -0
- package/dist/modules/danara/index.d.ts.map +1 -0
- package/dist/modules/danara/index.js +144 -0
- package/dist/modules/danara/index.js.map +1 -0
- package/dist/modules/danara/types.d.ts +479 -0
- package/dist/modules/danara/types.d.ts.map +1 -0
- package/dist/modules/danara/types.js +2 -0
- package/dist/modules/danara/types.js.map +1 -0
- package/dist/modules/smeup-file/index.d.ts +27 -0
- package/dist/modules/smeup-file/index.d.ts.map +1 -0
- package/dist/modules/smeup-file/index.js +17 -0
- package/dist/modules/smeup-file/index.js.map +1 -0
- package/dist/modules/sso/index.d.ts +40 -0
- package/dist/modules/sso/index.d.ts.map +1 -0
- package/dist/modules/sso/index.js +41 -0
- package/dist/modules/sso/index.js.map +1 -0
- package/dist/rx/index.d.ts +11 -0
- package/dist/rx/index.d.ts.map +1 -0
- package/dist/rx/index.js +20 -0
- package/dist/rx/index.js.map +1 -0
- package/dist/session/auth-middleware.d.ts +27 -0
- package/dist/session/auth-middleware.d.ts.map +1 -0
- package/dist/session/auth-middleware.js +122 -0
- package/dist/session/auth-middleware.js.map +1 -0
- package/dist/session/jwt.d.ts +20 -0
- package/dist/session/jwt.d.ts.map +1 -0
- package/dist/session/jwt.js +25 -0
- package/dist/session/jwt.js.map +1 -0
- package/dist/session/stores.d.ts +19 -0
- package/dist/session/stores.d.ts.map +1 -0
- package/dist/session/stores.js +103 -0
- package/dist/session/stores.js.map +1 -0
- package/dist/session/types.d.ts +28 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +2 -0
- package/dist/session/types.js.map +1 -0
- package/package.json +80 -30
- package/dist/core/axios.d.ts +0 -51
- package/dist/core/axios.js +0 -65
- package/dist/core/axios.observable.d.ts +0 -11
- package/dist/core/axios.observable.js +0 -58
- package/dist/core/base.provider.advanced.test.d.ts +0 -1
- package/dist/core/base.provider.advanced.test.js +0 -29
- package/dist/core/base.provider.d.ts +0 -15
- package/dist/core/base.provider.js +0 -13
- package/dist/core/base.provider.test.d.ts +0 -1
- package/dist/core/base.provider.test.js +0 -36
- package/dist/core/base.service.wrapper.advanced.test.d.ts +0 -1
- package/dist/core/base.service.wrapper.advanced.test.js +0 -39
- package/dist/core/base.service.wrapper.d.ts +0 -7
- package/dist/core/base.service.wrapper.js +0 -11
- package/dist/core/base.service.wrapper.test.d.ts +0 -1
- package/dist/core/base.service.wrapper.test.js +0 -25
- package/dist/core/rx.http.service.d.ts +0 -51
- package/dist/core/rx.http.service.js +0 -65
- package/dist/services/auth.service.d.ts +0 -69
- package/dist/services/auth.service.js +0 -197
- package/dist/services/auth.service.test.d.ts +0 -1
- package/dist/services/auth.service.test.js +0 -340
- package/dist/services/cache.service.d.ts +0 -31
- package/dist/services/cache.service.js +0 -77
- package/dist/services/cache.service.test.d.ts +0 -1
- package/dist/services/cache.service.test.js +0 -88
- package/dist/services/customer.service.d.ts +0 -213
- package/dist/services/customer.service.js +0 -128
- package/dist/services/customer.service.test.d.ts +0 -1
- package/dist/services/customer.service.test.js +0 -430
- package/dist/services/employee.service.d.ts +0 -73
- package/dist/services/employee.service.js +0 -74
- package/dist/services/employee.service.test.d.ts +0 -1
- package/dist/services/employee.service.test.js +0 -127
- package/dist/services/logger.service.d.ts +0 -31
- package/dist/services/logger.service.js +0 -93
- package/dist/services/logger.service.test.d.ts +0 -1
- package/dist/services/logger.service.test.js +0 -31
- package/dist/services/order.service.d.ts +0 -73
- package/dist/services/order.service.js +0 -97
- package/dist/services/order.service.test.d.ts +0 -1
- package/dist/services/order.service.test.js +0 -163
- package/dist/services/product.service.d.ts +0 -21
- package/dist/services/product.service.js +0 -42
- package/dist/services/product.service.test.d.ts +0 -1
- package/dist/services/product.service.test.js +0 -61
- package/dist/services/smess.service.d.ts +0 -36
- package/dist/services/smess.service.js +0 -128
- package/dist/services/smess.service.test.d.ts +0 -1
- package/dist/services/smess.service.test.js +0 -103
- package/dist/services/store.cart.service.d.ts +0 -158
- package/dist/services/store.cart.service.js +0 -177
- package/dist/services/store.cart.service.test.d.ts +0 -1
- package/dist/services/store.cart.service.test.js +0 -394
- package/dist/services/store.product.service.d.ts +0 -124
- package/dist/services/store.product.service.js +0 -102
- package/dist/services/store.product.service.test.d.ts +0 -1
- package/dist/services/store.product.service.test.js +0 -319
- package/dist/services/store.service.d.ts +0 -79
- package/dist/services/store.service.js +0 -235
- package/dist/services/store.service.test.d.ts +0 -1
- package/dist/services/store.service.test.js +0 -274
- package/dist/services/storefront.cart.service.d.ts +0 -73
- package/dist/services/storefront.cart.service.js +0 -167
- package/dist/services/storefront.cart.service.test.d.ts +0 -1
- package/dist/services/storefront.cart.service.test.js +0 -211
- package/dist/services/storefront.checkout.service.d.ts +0 -62
- package/dist/services/storefront.checkout.service.js +0 -75
- package/dist/services/storefront.checkout.service.test.d.ts +0 -1
- package/dist/services/storefront.checkout.service.test.js +0 -158
- package/dist/services/storefront.customer.metadata.service.d.ts +0 -91
- package/dist/services/storefront.customer.metadata.service.js +0 -225
- package/dist/services/storefront.customer.metadata.service.test.d.ts +0 -1
- package/dist/services/storefront.customer.metadata.service.test.js +0 -271
- package/dist/services/storefront.order.service.d.ts +0 -45
- package/dist/services/storefront.order.service.js +0 -99
- package/dist/services/storefront.order.service.test.d.ts +0 -1
- package/dist/services/storefront.order.service.test.js +0 -158
- package/dist/services/storefront.product.service.d.ts +0 -52
- package/dist/services/storefront.product.service.js +0 -75
- package/dist/services/storefront.product.service.test.d.ts +0 -1
- package/dist/services/storefront.product.service.test.js +0 -120
- package/dist/services/storefront.store.service.d.ts +0 -54
- package/dist/services/storefront.store.service.js +0 -142
- package/dist/services/storefront.store.service.test.d.ts +0 -1
- package/dist/services/storefront.store.service.test.js +0 -90
- package/dist/services/user.service.d.ts +0 -16
- package/dist/services/user.service.js +0 -37
- package/dist/services/user.service.test.d.ts +0 -1
- package/dist/services/user.service.test.js +0 -52
- package/dist/services/utils/withAuthReset.d.ts +0 -3
- package/dist/services/utils/withAuthReset.js +0 -8
- package/dist/src/core/axios.d.ts +0 -51
- package/dist/src/core/axios.js +0 -65
- package/dist/src/core/axios.observable.d.ts +0 -11
- package/dist/src/core/axios.observable.js +0 -58
- package/dist/src/core/base.provider.advanced.test.d.ts +0 -1
- package/dist/src/core/base.provider.advanced.test.js +0 -29
- package/dist/src/core/base.provider.d.ts +0 -15
- package/dist/src/core/base.provider.js +0 -13
- package/dist/src/core/base.provider.test.d.ts +0 -1
- package/dist/src/core/base.provider.test.js +0 -36
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +0 -1
- package/dist/src/core/base.service.wrapper.advanced.test.js +0 -39
- package/dist/src/core/base.service.wrapper.d.ts +0 -7
- package/dist/src/core/base.service.wrapper.js +0 -11
- package/dist/src/core/base.service.wrapper.test.d.ts +0 -1
- package/dist/src/core/base.service.wrapper.test.js +0 -25
- package/dist/src/core/rx.http.service.d.ts +0 -51
- package/dist/src/core/rx.http.service.js +0 -65
- package/dist/src/index.d.ts +0 -25
- package/dist/src/index.js +0 -29
- package/dist/src/services/auth.service.d.ts +0 -69
- package/dist/src/services/auth.service.js +0 -197
- package/dist/src/services/auth.service.test.d.ts +0 -1
- package/dist/src/services/auth.service.test.js +0 -340
- package/dist/src/services/cache.service.d.ts +0 -31
- package/dist/src/services/cache.service.js +0 -77
- package/dist/src/services/cache.service.test.d.ts +0 -1
- package/dist/src/services/cache.service.test.js +0 -88
- package/dist/src/services/customer.service.d.ts +0 -199
- package/dist/src/services/customer.service.js +0 -114
- package/dist/src/services/customer.service.test.d.ts +0 -1
- package/dist/src/services/customer.service.test.js +0 -430
- package/dist/src/services/employee.service.d.ts +0 -73
- package/dist/src/services/employee.service.js +0 -74
- package/dist/src/services/employee.service.test.d.ts +0 -1
- package/dist/src/services/employee.service.test.js +0 -127
- package/dist/src/services/logger.service.d.ts +0 -31
- package/dist/src/services/logger.service.js +0 -93
- package/dist/src/services/logger.service.test.d.ts +0 -1
- package/dist/src/services/logger.service.test.js +0 -31
- package/dist/src/services/order.service.d.ts +0 -73
- package/dist/src/services/order.service.js +0 -97
- package/dist/src/services/order.service.test.d.ts +0 -1
- package/dist/src/services/order.service.test.js +0 -163
- package/dist/src/services/product.service.d.ts +0 -21
- package/dist/src/services/product.service.js +0 -42
- package/dist/src/services/product.service.test.d.ts +0 -1
- package/dist/src/services/product.service.test.js +0 -61
- package/dist/src/services/smess.service.d.ts +0 -36
- package/dist/src/services/smess.service.js +0 -128
- package/dist/src/services/smess.service.test.d.ts +0 -1
- package/dist/src/services/smess.service.test.js +0 -103
- package/dist/src/services/store.cart.service.d.ts +0 -158
- package/dist/src/services/store.cart.service.js +0 -177
- package/dist/src/services/store.cart.service.test.d.ts +0 -1
- package/dist/src/services/store.cart.service.test.js +0 -394
- package/dist/src/services/store.product.service.d.ts +0 -124
- package/dist/src/services/store.product.service.js +0 -102
- package/dist/src/services/store.product.service.test.d.ts +0 -1
- package/dist/src/services/store.product.service.test.js +0 -319
- package/dist/src/services/store.service.d.ts +0 -79
- package/dist/src/services/store.service.js +0 -235
- package/dist/src/services/store.service.test.d.ts +0 -1
- package/dist/src/services/store.service.test.js +0 -274
- package/dist/src/services/storefront.cart.service.d.ts +0 -73
- package/dist/src/services/storefront.cart.service.js +0 -167
- package/dist/src/services/storefront.cart.service.test.d.ts +0 -1
- package/dist/src/services/storefront.cart.service.test.js +0 -211
- package/dist/src/services/storefront.checkout.service.d.ts +0 -62
- package/dist/src/services/storefront.checkout.service.js +0 -75
- package/dist/src/services/storefront.checkout.service.test.d.ts +0 -1
- package/dist/src/services/storefront.checkout.service.test.js +0 -158
- package/dist/src/services/storefront.customer.metadata.service.d.ts +0 -91
- package/dist/src/services/storefront.customer.metadata.service.js +0 -225
- package/dist/src/services/storefront.customer.metadata.service.test.d.ts +0 -1
- package/dist/src/services/storefront.customer.metadata.service.test.js +0 -271
- package/dist/src/services/storefront.order.service.d.ts +0 -45
- package/dist/src/services/storefront.order.service.js +0 -99
- package/dist/src/services/storefront.order.service.test.d.ts +0 -1
- package/dist/src/services/storefront.order.service.test.js +0 -158
- package/dist/src/services/storefront.product.service.d.ts +0 -52
- package/dist/src/services/storefront.product.service.js +0 -75
- package/dist/src/services/storefront.product.service.test.d.ts +0 -1
- package/dist/src/services/storefront.product.service.test.js +0 -120
- package/dist/src/services/storefront.store.service.d.ts +0 -52
- package/dist/src/services/storefront.store.service.js +0 -140
- package/dist/src/services/storefront.store.service.test.d.ts +0 -1
- package/dist/src/services/storefront.store.service.test.js +0 -90
- package/dist/src/services/user.service.d.ts +0 -16
- package/dist/src/services/user.service.js +0 -37
- package/dist/src/services/user.service.test.d.ts +0 -1
- package/dist/src/services/user.service.test.js +0 -52
- package/dist/src/services/utils/withAuthReset.d.ts +0 -3
- package/dist/src/services/utils/withAuthReset.js +0 -8
- package/dist/src/types/types.d.ts +0 -93
- package/dist/src/types/types.js +0 -82
- package/dist/src/types/types.test.d.ts +0 -1
- package/dist/src/types/types.test.js +0 -25
- package/dist/src/utils/cache-import.d.ts +0 -3
- package/dist/src/utils/cache-import.js +0 -2
- package/dist/src/utils/networking-import.d.ts +0 -4
- package/dist/src/utils/networking-import.js +0 -3
- package/dist/src/utils/rxjs-import.d.ts +0 -5
- package/dist/src/utils/rxjs-import.js +0 -5
- package/dist/types/types.d.ts +0 -96
- package/dist/types/types.js +0 -82
- package/dist/types/types.test.d.ts +0 -1
- package/dist/types/types.test.js +0 -25
- package/dist/utils/cache-import.d.ts +0 -3
- package/dist/utils/cache-import.js +0 -2
- package/dist/utils/networking-import.d.ts +0 -4
- package/dist/utils/networking-import.js +0 -3
- package/dist/utils/rxjs-import.d.ts +0 -5
- package/dist/utils/rxjs-import.js +0 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@smess/networking`. Versions follow [semver](https://semver.org).
|
|
4
|
+
|
|
5
|
+
## 2.0.0 (2026-11-07)
|
|
6
|
+
|
|
7
|
+
A rewrite: one typed client for core-services, built on `fetch`. Not compatible with 1.x.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `createSmessClient` with a host map per core service, the tenant header (`clientId` → `X-Client-Id`),
|
|
12
|
+
per-request timeout combined with the caller's `AbortSignal`, app middleware and opt-in retries.
|
|
13
|
+
- Endpoint contracts (`defineEndpoint`) with per-route auth mode (`none` / `optional` / `required`), so a
|
|
14
|
+
stale Bearer is never sent to core's anonymous firewalls.
|
|
15
|
+
- Sessions: `webStorageSession`, `memorySession`, `staticSession`; refresh 30 s before expiry and once on
|
|
16
|
+
401, single-flight across concurrent requests; `onSessionExpired`.
|
|
17
|
+
- `SmessApiError` with `kind`, `status`, `code`, `serverMessage`, `fields`, `retryAfter`, parsed from every
|
|
18
|
+
error format core-services emits.
|
|
19
|
+
- Modules: `authentication`, `sso`, `campaign` (the smeup.email API), `smeup-file`, `danara`; optional
|
|
20
|
+
`rx` adapter.
|
|
21
|
+
- Read-only smoke test against PROD Danara (`make smoke`), route table snapshot test.
|
|
22
|
+
- Publishing from GitHub Actions with npm trusted publishing.
|
|
23
|
+
|
|
24
|
+
### Fixed (compared with the hand-written app clients it replaces)
|
|
25
|
+
|
|
26
|
+
- OTP and password-reset logins keep their refresh token: core returns it as `refreshToken` (camelCase),
|
|
27
|
+
which smeup.email read as `refresh_token`, so those sessions ended after one hour.
|
|
28
|
+
- A caller's `AbortSignal` no longer disables the request timeout (Danara client).
|
|
29
|
+
|
|
30
|
+
### Removed
|
|
31
|
+
|
|
32
|
+
- The whole 1.x API (axios, rxjs services, Dexie cache, storefront services). Apps on 1.x keep working on
|
|
33
|
+
their pinned 1.x version; GPM migrates module by module.
|
|
34
|
+
- Duplicate source tree `src/src`, the committed 1.0.18 tarball, Jest, per-version changelog files.
|
|
35
|
+
|
|
36
|
+
## 1.x history
|
|
37
|
+
|
|
38
|
+
Generated from the former per-version changelog files. `1.2.0` was published by mistake before `1.1.1`;
|
|
39
|
+
do not use it.
|
|
40
|
+
|
|
41
|
+
### 1.2.0
|
|
42
|
+
|
|
43
|
+
- Update customer.service.ts
|
|
44
|
+
- Update package
|
|
45
|
+
|
|
46
|
+
### 1.1.5 (2026-01-14)
|
|
47
|
+
|
|
48
|
+
- [Authentication] Update VerifyResetPassword
|
|
49
|
+
|
|
50
|
+
### 1.1.4 (2026-01-14)
|
|
51
|
+
|
|
52
|
+
- [Authentication] Update VerifyResetPassword
|
|
53
|
+
|
|
54
|
+
### 1.1.3 (2026-01-14)
|
|
55
|
+
|
|
56
|
+
- [Authentication] Update VerifyResetPassword
|
|
57
|
+
|
|
58
|
+
### 1.1.2 (2025-11-24)
|
|
59
|
+
|
|
60
|
+
- Update customer-product-remove
|
|
61
|
+
|
|
62
|
+
### 1.1.1 (2025-11-23)
|
|
63
|
+
|
|
64
|
+
- Update customer.service.ts
|
|
65
|
+
- Update package
|
|
66
|
+
|
|
67
|
+
### 1.1.0 (2025-11-20)
|
|
68
|
+
|
|
69
|
+
- Update storefront.store.service.ts
|
|
70
|
+
- Update storefront.store.service.ts
|
|
71
|
+
|
|
72
|
+
### 1.0.30
|
|
73
|
+
|
|
74
|
+
- Update storefront.store.service.ts
|
|
75
|
+
- Update storefront.store.service.ts
|
|
76
|
+
|
|
77
|
+
### 1.0.29 (2025-11-10)
|
|
78
|
+
|
|
79
|
+
- [Fix] Bug
|
|
80
|
+
|
|
81
|
+
### 1.0.28 (2025-11-10)
|
|
82
|
+
|
|
83
|
+
- fix: remove customer product notes flow
|
|
84
|
+
|
|
85
|
+
### 1.0.27 (2025-11-10)
|
|
86
|
+
|
|
87
|
+
- feat(customer): add product category management
|
|
88
|
+
|
|
89
|
+
### 1.0.26 (2025-11-09)
|
|
90
|
+
|
|
91
|
+
- chore(build): clean publish artifacts
|
|
92
|
+
|
|
93
|
+
### 1.0.25 (2025-11-09)
|
|
94
|
+
|
|
95
|
+
- chore: export employee service
|
|
96
|
+
- chore: expose helper and archive changelog
|
|
97
|
+
- feat(auth): share auth reset helper
|
|
98
|
+
|
|
99
|
+
### 1.0.24 (2025-11-09)
|
|
100
|
+
|
|
101
|
+
- feat(employee): add service and tests
|
|
102
|
+
- feat(customer): support cart and product operations
|
|
103
|
+
|
|
104
|
+
### 1.0.23 (2025-10-24)
|
|
105
|
+
|
|
106
|
+
- fix: Fix customer services
|
|
107
|
+
|
|
108
|
+
### 1.0.22 (2025-10-24)
|
|
109
|
+
|
|
110
|
+
- [StoreProduct] Fix bug
|
|
111
|
+
|
|
112
|
+
### 1.0.21 (2025-10-20)
|
|
113
|
+
|
|
114
|
+
- 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
|
|
115
|
+
- 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
|
|
116
|
+
|
|
117
|
+
### 1.0.20 (2025-10-16)
|
|
118
|
+
|
|
119
|
+
- fix: update real-test.ts to use correct services and remove
|
|
120
|
+
- fix: resolve errors in dev-test.ts
|
|
121
|
+
- refactor: remove from StoreService - stores are open access
|
|
122
|
+
- refactor: remove redundant functions from StoreProductService
|
|
123
|
+
|
|
124
|
+
### 1.0.19 (2025-10-15)
|
|
125
|
+
|
|
126
|
+
- fix: standardize service return types and fix dev-test JSON parsing
|
|
127
|
+
|
|
128
|
+
### 1.0.18 (2025-10-14)
|
|
129
|
+
|
|
130
|
+
- fix(store-product): rename interfaces to avoid export conflicts
|
|
131
|
+
|
|
132
|
+
### 1.0.17 (2025-10-14)
|
|
133
|
+
|
|
134
|
+
- fix(dev-test): properly extract cart data from nested response structure
|
|
135
|
+
- fix(store-cart): handle nested data structure in cart response
|
|
136
|
+
- feat(dev-test): add comprehensive E2E store and cart flow test
|
|
137
|
+
- feat(store-cart): add storeId support and X-Store-Id header
|
|
138
|
+
- feat(store): add StoreProductService with product and store endpoints
|
|
139
|
+
- Add StoreCartService with cart hash management
|
|
140
|
+
|
|
141
|
+
### 1.0.16 (2025-09-23)
|
|
142
|
+
|
|
143
|
+
- Simplify AuthService logic and add rememberMe test
|
|
144
|
+
|
|
145
|
+
### 1.0.15 (2025-09-23)
|
|
146
|
+
|
|
147
|
+
- Fix orde.service collection
|
|
148
|
+
|
|
149
|
+
### 1.0.14 (2025-09-22)
|
|
150
|
+
|
|
151
|
+
- Fix bear authentication
|
|
152
|
+
|
|
153
|
+
### 1.0.13 (2025-09-22)
|
|
154
|
+
|
|
155
|
+
- feat: add collection function to OrderService
|
|
156
|
+
|
|
157
|
+
### 1.0.12 (2025-09-22)
|
|
158
|
+
|
|
159
|
+
- fix release script
|
|
160
|
+
|
|
161
|
+
### 1.0.11 (2025-09-22)
|
|
162
|
+
|
|
163
|
+
- Fix types check
|
|
164
|
+
- refactor: AuthService manages authToken internally
|
|
165
|
+
|
|
166
|
+
### 1.0.10 (2025-08-02)
|
|
167
|
+
|
|
168
|
+
- refactor: AuthService manages authToken internally
|
|
169
|
+
- chore(release): generate changelog for v1.0.10
|
|
170
|
+
- Update order services
|
|
171
|
+
|
|
172
|
+
### 1.0.9 (2025-07-26)
|
|
173
|
+
|
|
174
|
+
- Implement cache-first strategy for store
|
|
175
|
+
- Implement cache-service
|
|
176
|
+
|
|
177
|
+
### 1.0.8 (2025-07-26)
|
|
178
|
+
|
|
179
|
+
- Export all services
|
|
180
|
+
|
|
181
|
+
### 1.0.7 (2025-07-26)
|
|
182
|
+
|
|
183
|
+
- Update build fixed
|
|
184
|
+
- Revert "Update build for ES module"
|
|
185
|
+
- Revert Update build for ES module
|
|
186
|
+
- Revert "chore(release): generate changelog for v1.0.6"
|
|
187
|
+
|
|
188
|
+
### 1.0.5 (2025-07-23)
|
|
189
|
+
|
|
190
|
+
- Update build for ES module
|
|
191
|
+
|
|
192
|
+
### 1.0.4 (2025-07-22)
|
|
193
|
+
|
|
194
|
+
- Implement store service
|
|
195
|
+
- Implement order service
|
|
196
|
+
- Implement customer service
|
|
197
|
+
- Fix bugs and improvement auth.services - make real test working
|
|
198
|
+
- refactor!: move all services to services/, update docs and examples for @smess/networking, fix all tests and scripts for new structure
|
|
199
|
+
|
|
200
|
+
### 1.0.3 (2025-07-22)
|
|
201
|
+
|
|
202
|
+
- Fix bugs and improvement
|
|
203
|
+
|
|
204
|
+
### 1.0.2 (2025-07-17)
|
|
205
|
+
|
|
206
|
+
- Bump new version
|
|
207
|
+
|
|
208
|
+
### 1.0.1 (2025-07-17)
|
|
209
|
+
|
|
210
|
+
- Build Networking utilities and services for SMESS platform
|
|
211
|
+
|
package/README.md
CHANGED
|
@@ -1,147 +1,198 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @smess/networking
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
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
|
+
- One error type, `SmessApiError`, for every error format core emits.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Layers and the backend facts behind them: [docs/architecture.md](docs/architecture.md).
|
|
12
13
|
|
|
13
|
-
```
|
|
14
|
+
```sh
|
|
14
15
|
npm install @smess/networking
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
##
|
|
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
|
|
18
|
+
## Quick start
|
|
37
19
|
|
|
38
|
-
|
|
39
|
-
import { ProductService, UserService, AuthService } from "@smess/networking";
|
|
20
|
+
### Browser app with a signed-in user (smeup.email)
|
|
40
21
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```
|
|
22
|
+
```ts
|
|
23
|
+
import { createSmessClient, PRODUCTION_HOSTS, webStorageSession } from '@smess/networking';
|
|
24
|
+
import { authentication, authenticationRefresh } from '@smess/networking/authentication';
|
|
25
|
+
import { campaign } from '@smess/networking/campaign';
|
|
46
26
|
|
|
47
|
-
|
|
27
|
+
export const smess = createSmessClient({
|
|
28
|
+
hosts: PRODUCTION_HOSTS,
|
|
29
|
+
session: webStorageSession({ accessKey: 'app.token', refreshKey: 'app.refresh' }),
|
|
30
|
+
refresh: authenticationRefresh(),
|
|
31
|
+
onSessionExpired: () => router.navigate({ to: '/login' }),
|
|
32
|
+
});
|
|
48
33
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
productServiceB.createProduct({ name: 'X', price: 10 }).subscribe(...);
|
|
53
|
-
userServiceA.fetchUserById(1).subscribe(...);
|
|
54
|
-
authServiceA.login({ identifier: 'user', password: 'pass' }).subscribe(...);
|
|
34
|
+
const auth = authentication(smess);
|
|
35
|
+
await auth.otp.request({ identifier: email });
|
|
36
|
+
await auth.otp.verify({ identifier: email, code }); // saves the session
|
|
55
37
|
|
|
56
|
-
|
|
57
|
-
const user = await userServiceA.fetchUserById(1).toPromise();
|
|
58
|
-
const products = await productServiceA.fetchAllProducts().toPromise();
|
|
38
|
+
const templates = await campaign(smess).email.templates.list(); // ApiList<Template>
|
|
59
39
|
```
|
|
60
40
|
|
|
61
|
-
###
|
|
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
|
-
}
|
|
41
|
+
### Tenant-scoped app, Next.js server component (Danara)
|
|
84
42
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// handle result
|
|
89
|
-
});
|
|
90
|
-
```
|
|
43
|
+
```ts
|
|
44
|
+
import { createSmessClient, staticSession } from '@smess/networking';
|
|
45
|
+
import { danara } from '@smess/networking/danara';
|
|
91
46
|
|
|
92
|
-
|
|
47
|
+
// Module scope: no session here, a server client is shared by every request.
|
|
48
|
+
const base = createSmessClient({
|
|
49
|
+
hosts: { danara: 'https://api.danara.vn' },
|
|
50
|
+
clientId: process.env.NEXT_PUBLIC_CLIENT_ID, // X-Client-Id on every request
|
|
51
|
+
timeoutMs: 15_000,
|
|
52
|
+
});
|
|
93
53
|
|
|
94
|
-
|
|
54
|
+
// Per request: the visitor's token, read from the request cookie.
|
|
55
|
+
const api = danara(base.with({ session: staticSession(await getServerAuthToken()) }));
|
|
56
|
+
const { data, meta } = await api.listings.list({ page: 1, ward: 'son-tra' });
|
|
57
|
+
const contracts = await api.leasing.contracts.get(uuid); // sends the Bearer
|
|
58
|
+
```
|
|
95
59
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
60
|
+
## The client
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
createSmessClient({
|
|
64
|
+
hosts, // required: base URL per service (PRODUCTION_HOSTS, or your environment)
|
|
65
|
+
clientId, // tenant UUID → X-Client-Id on every request
|
|
66
|
+
session, // SessionStore: webStorageSession() | memorySession() | staticSession(token) | your own
|
|
67
|
+
refresh, // RefreshStrategy, e.g. authenticationRefresh()
|
|
68
|
+
onSessionExpired, // called once when the session is cleared because it could not be renewed
|
|
69
|
+
timeoutMs, // default 30 000; 0 disables
|
|
70
|
+
headers, // on every request (e.g. Accept-Language)
|
|
71
|
+
fetchOptions, // passed to fetch (cache, credentials, Next.js `next`)
|
|
72
|
+
middleware, // app middleware (logging, metrics, test doubles)
|
|
73
|
+
retry, // opt-in: { retries: 2 } retries GET on network errors, 429, 502, 503, 504
|
|
74
|
+
fetch, // custom fetch
|
|
75
|
+
});
|
|
76
|
+
```
|
|
100
77
|
|
|
101
|
-
|
|
78
|
+
| Method | Purpose |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `client.call(endpoint, input)` | Call a declared endpoint (what modules do). |
|
|
81
|
+
| `client.request({ service, method, path, auth, … })` | Any route no module covers yet. `auth` is required. |
|
|
82
|
+
| `client.with(overrides)` | Derived client (per-request session, other timeout). Shares the session store. |
|
|
83
|
+
| `client.session.get/set/clear/claims()` | The current session and its JWT claims (unverified). |
|
|
84
|
+
|
|
85
|
+
Every module function takes optional per-call options as its last argument:
|
|
86
|
+
`{ signal, timeoutMs, headers, idempotencyKey, fetchOptions }`.
|
|
87
|
+
|
|
88
|
+
### Auth modes
|
|
89
|
+
|
|
90
|
+
Each endpoint declares how it uses the session, because core rejects any stale Bearer with 401, even
|
|
91
|
+
on public routes:
|
|
92
|
+
|
|
93
|
+
| `auth` | Behaviour |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `none` | Never sends `Authorization` (login, refresh, OTP, SSO, public catalogs). |
|
|
96
|
+
| `optional` | Sends the token when signed in. |
|
|
97
|
+
| `required` | Fails with `unauthenticated` / `no_session` before the network when signed out. |
|
|
98
|
+
|
|
99
|
+
### Sessions and refresh
|
|
100
|
+
|
|
101
|
+
- The access token is refreshed 30 s before its `exp`, and once on a 401. Concurrent requests share
|
|
102
|
+
one refresh.
|
|
103
|
+
- A refresh rejected with 4xx clears the session and calls `onSessionExpired({ reason: 'refresh_failed' })`.
|
|
104
|
+
A network or 5xx failure keeps the session.
|
|
105
|
+
- A 401 that cannot be refreshed clears the session (`reason: 'unauthorized'`).
|
|
106
|
+
- Server code: never share a writable store between requests. Use `staticSession(token)` per request.
|
|
107
|
+
|
|
108
|
+
### Tenant (`clientId`)
|
|
109
|
+
|
|
110
|
+
core-services rejects a JWT whose `client_id` differs from the `X-Client-Id` header, and a browser
|
|
111
|
+
origin bound to a tenant must send that tenant. So a client either always sends the same tenant or
|
|
112
|
+
never sends one. smeup.email sends none (the tenant comes from the JWT); Danara always sends its own.
|
|
113
|
+
|
|
114
|
+
## Modules
|
|
115
|
+
|
|
116
|
+
| Import | Backend module | Host key | Notes |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| `@smess/networking/authentication` | Authentication | `authentication` | password, OTP, refresh, reset, change password, logout |
|
|
119
|
+
| `@smess/networking/sso` | Sso | `sso` | `start`, `completeLogin(location.hash)`, `parseSsoCallback`, `readSsoError` |
|
|
120
|
+
| `@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 |
|
|
121
|
+
| `@smess/networking/smeup-file` | SMEUpFile | `smeupFile` | base64 upload |
|
|
122
|
+
| `@smess/networking/danara` | Danara | `danara` | identity, listings, sales, fit-out, leasing, owner portal, transit |
|
|
123
|
+
| `@smess/networking/rx` | – | – | `fromSmess(signal => call)` → cancellable Observable (peer dep `rxjs`) |
|
|
124
|
+
|
|
125
|
+
Each module also exports its endpoint table (`campaignEmailEndpoints`, `danaraEndpoints`, …) and its
|
|
126
|
+
wire types.
|
|
127
|
+
|
|
128
|
+
**Wire types are the server's.** Field names are exactly what core sends (mostly snake_case; Danara
|
|
129
|
+
and a few others camelCase), so a type always matches DevTools. Single objects wrapped in `{"data": …}`
|
|
130
|
+
are unwrapped; list envelopes are returned as sent because they carry the pagination
|
|
131
|
+
(`ApiList<T>` = `{object: 'list', data, has_more, total_count}`, `PagedList<T>` = `{data, meta}`).
|
|
132
|
+
Walk a cursor list with `paginate()`.
|
|
133
|
+
|
|
134
|
+
## Errors
|
|
135
|
+
|
|
136
|
+
Every call rejects with `SmessApiError`:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
try {
|
|
140
|
+
await email.domains.create('example.com');
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (isSmessApiError(error)) {
|
|
143
|
+
error.kind; // 'validation' | 'unauthenticated' | 'forbidden' | 'not_found' | 'rate_limited' | …
|
|
144
|
+
error.status; // HTTP status, 0 without a response
|
|
145
|
+
error.code; // e.g. 'missing_client_id', 'email_already_registered', 'invalid_code'
|
|
146
|
+
error.serverMessage; // the server's text (may be an i18n key such as error.validation.not_blank)
|
|
147
|
+
error.fields; // { field: 'first message' }
|
|
148
|
+
error.retryAfter; // seconds, on 429
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
102
152
|
|
|
103
|
-
|
|
153
|
+
The parser reads all of core's formats: Stripe-style `{error: {type, code, message, param}}`,
|
|
154
|
+
`{errors: {field: [{message}]}}`, `{code, message}`, `{is_success: false, error_message}`,
|
|
155
|
+
`{error: "text"}`, `violations`, plain text, and HTML pages (status only).
|
|
104
156
|
|
|
105
|
-
|
|
106
|
-
// ✅ This works perfectly with bundlers
|
|
107
|
-
import { UserService, ProductService } from "@smess/networking";
|
|
157
|
+
## Routes not in a module yet
|
|
108
158
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
159
|
+
```ts
|
|
160
|
+
await client.request<MoveInCost>({
|
|
161
|
+
service: 'danara',
|
|
162
|
+
method: 'GET',
|
|
163
|
+
path: '/v1/listings/{uuid}/move-in-cost',
|
|
164
|
+
pathParams: { uuid },
|
|
165
|
+
auth: 'none',
|
|
166
|
+
});
|
|
112
167
|
```
|
|
113
168
|
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
Add the route to its module once it exists in core-services, with its type taken from the backend
|
|
170
|
+
transformer or DTO, and a line in the route table snapshot (`test/__snapshots__`).
|
|
122
171
|
|
|
123
172
|
## Development
|
|
124
173
|
|
|
125
|
-
```
|
|
126
|
-
#
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# Build the package
|
|
130
|
-
npm run build
|
|
131
|
-
|
|
132
|
-
# Run tests
|
|
133
|
-
npm test
|
|
134
|
-
|
|
135
|
-
# Clean build artifacts
|
|
136
|
-
npm run clean
|
|
174
|
+
```sh
|
|
175
|
+
make install # npm ci
|
|
176
|
+
make check # lint, typecheck, tests, build, publint
|
|
177
|
+
make smoke # read-only checks of the built package against PROD Danara (DANARA_CLIENT_ID=… make smoke)
|
|
137
178
|
```
|
|
138
179
|
|
|
139
|
-
|
|
180
|
+
Try a local build in an app without publishing: `npm pack`, then in the app
|
|
181
|
+
`npm install --no-save /path/to/smess-networking-2.x.y.tgz`.
|
|
182
|
+
|
|
183
|
+
## Release
|
|
140
184
|
|
|
141
|
-
|
|
185
|
+
Releases are published from GitHub Actions (`.github/workflows/release.yml`) when a `v*` tag is
|
|
186
|
+
pushed, with npm trusted publishing (no token stored anywhere).
|
|
142
187
|
|
|
143
|
-
|
|
188
|
+
1. Add the version's section to `CHANGELOG.md` and commit.
|
|
189
|
+
2. `make release VERSION=2.0.1` (bumps `package.json`, commits, tags `v2.0.1`, pushes).
|
|
190
|
+
3. The workflow checks the tag against `package.json`, runs `npm run check`, publishes (pre-releases such
|
|
191
|
+
as `2.1.0-beta.1` go to the `next` dist-tag) and creates the GitHub release.
|
|
144
192
|
|
|
145
|
-
|
|
193
|
+
One-time setup on npmjs.com: package `@smess/networking` → Settings → Trusted Publisher → GitHub
|
|
194
|
+
Actions, owner `smeservicescloud`, repository `smess-networking`, workflow `release.yml`. The repository is
|
|
195
|
+
private, so npm does not attach provenance.
|
|
146
196
|
|
|
147
|
-
|
|
197
|
+
Version policy: semver. Breaking changes to a module's functions or wire types are major versions;
|
|
198
|
+
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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"}
|