@smess/networking 1.2.0 → 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 -65
- 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 -334
- 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 -211
- 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 -65
- 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 -334
- 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
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { NetworkingUIEventWrapped, } from "../types/types";
|
|
2
|
-
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
3
|
-
import { from, of } from "rxjs";
|
|
4
|
-
import { map, switchMap, catchError } from "rxjs/operators";
|
|
5
|
-
import { GenericIndexedDBService } from "./cache.service";
|
|
6
|
-
export class StorefrontStoreProvider {
|
|
7
|
-
constructor(config, target) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.target = target;
|
|
10
|
-
}
|
|
11
|
-
get baseURL() {
|
|
12
|
-
return this.config.version
|
|
13
|
-
? `${this.config.baseUrl}/${this.config.version}`
|
|
14
|
-
: this.config.baseUrl;
|
|
15
|
-
}
|
|
16
|
-
get path() {
|
|
17
|
-
switch (this.target) {
|
|
18
|
-
case "store-list":
|
|
19
|
-
return "/storefront/stores/list";
|
|
20
|
-
case "store-information":
|
|
21
|
-
return "/storefront/stores/${id}/information";
|
|
22
|
-
default:
|
|
23
|
-
return "/storefront/stores/list";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
get method() {
|
|
27
|
-
return "GET";
|
|
28
|
-
}
|
|
29
|
-
get headers() {
|
|
30
|
-
let headers = SmessService.getHeaders(Accept.V1, null);
|
|
31
|
-
if (this.config.clientId) {
|
|
32
|
-
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
33
|
-
}
|
|
34
|
-
if (this.config.apiKey) {
|
|
35
|
-
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
36
|
-
}
|
|
37
|
-
return SmessService.filterHeaders(headers);
|
|
38
|
-
}
|
|
39
|
-
getPath(...queryParams) {
|
|
40
|
-
let definedPath = this.path;
|
|
41
|
-
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
42
|
-
params?.forEach((value, index) => {
|
|
43
|
-
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
44
|
-
});
|
|
45
|
-
return definedPath;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export class StorefrontStoreService {
|
|
49
|
-
constructor(config, cacheOptions) {
|
|
50
|
-
this.config = config;
|
|
51
|
-
this.cacheOptions = cacheOptions || {};
|
|
52
|
-
this.cacheDuration =
|
|
53
|
-
this.cacheOptions.cacheTtlMs ?? 24 * 60 * 60 * 1000; // Default 24 hours
|
|
54
|
-
// Initialize cache services for different data types
|
|
55
|
-
this.cacheService = new GenericIndexedDBService("StorefrontStoreCache", "id, timestamp", (data) => data, (data) => data);
|
|
56
|
-
this.storeListCache = new GenericIndexedDBService("StorefrontStoreListCache", "timestamp", (data) => data, (data) => data);
|
|
57
|
-
}
|
|
58
|
-
provider(target) {
|
|
59
|
-
const targetWrapper = new StorefrontStoreProvider(this.config, target);
|
|
60
|
-
return new SmessService(targetWrapper);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* List all accessible stores with shipping rules
|
|
64
|
-
* GET /storefront/stores/list
|
|
65
|
-
*/
|
|
66
|
-
listStores() {
|
|
67
|
-
return from(this.storeListCache.getAll("storefront-store-list")).pipe(switchMap((cachedData) => {
|
|
68
|
-
if (cachedData &&
|
|
69
|
-
cachedData.length > 0 &&
|
|
70
|
-
this.isCacheValid(cachedData[0].timestamp)) {
|
|
71
|
-
return of(NetworkingUIEventWrapped.succeeded(cachedData[0].data));
|
|
72
|
-
}
|
|
73
|
-
return this.provider("store-list")
|
|
74
|
-
.request()
|
|
75
|
-
.pipe(map((response) => {
|
|
76
|
-
if (response.response) {
|
|
77
|
-
this.storeListCache.saveAll([
|
|
78
|
-
{
|
|
79
|
-
data: response.response,
|
|
80
|
-
timestamp: Date.now(),
|
|
81
|
-
},
|
|
82
|
-
], "storefront-store-list");
|
|
83
|
-
}
|
|
84
|
-
return response;
|
|
85
|
-
}), catchError((error) => {
|
|
86
|
-
if (cachedData && cachedData.length > 0) {
|
|
87
|
-
return of(NetworkingUIEventWrapped.succeeded(cachedData[0].data));
|
|
88
|
-
}
|
|
89
|
-
throw error;
|
|
90
|
-
}));
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get detailed store information by ID including shipping rules
|
|
95
|
-
* GET /storefront/stores/{id}/information
|
|
96
|
-
*/
|
|
97
|
-
getStoreInformation(id) {
|
|
98
|
-
return from(this.cacheService.getOne(String(id))).pipe(switchMap((cachedData) => {
|
|
99
|
-
if (cachedData && this.isCacheValid(cachedData.timestamp)) {
|
|
100
|
-
return of(NetworkingUIEventWrapped.succeeded(cachedData.data));
|
|
101
|
-
}
|
|
102
|
-
return this.provider("store-information")
|
|
103
|
-
.request(null, undefined, id)
|
|
104
|
-
.pipe(map((response) => {
|
|
105
|
-
if (response.response) {
|
|
106
|
-
this.cacheService.saveOne({
|
|
107
|
-
id,
|
|
108
|
-
data: response.response,
|
|
109
|
-
timestamp: Date.now(),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return response;
|
|
113
|
-
}), catchError((error) => {
|
|
114
|
-
if (cachedData) {
|
|
115
|
-
return of(NetworkingUIEventWrapped.succeeded(cachedData.data));
|
|
116
|
-
}
|
|
117
|
-
throw error;
|
|
118
|
-
}));
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Clear all cache
|
|
123
|
-
*/
|
|
124
|
-
clearCache() {
|
|
125
|
-
return Promise.all([
|
|
126
|
-
this.cacheService.clearAll(),
|
|
127
|
-
this.storeListCache.clearAll(),
|
|
128
|
-
]).then(() => { });
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Clear cache for a specific store
|
|
132
|
-
*/
|
|
133
|
-
clearStoreCache(id) {
|
|
134
|
-
return this.cacheService.delete(String(id));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Check if cache is still valid
|
|
138
|
-
*/
|
|
139
|
-
isCacheValid(timestamp) {
|
|
140
|
-
return Date.now() - timestamp < this.cacheDuration;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { StorefrontStoreService, StorefrontStoreProvider, } from "./storefront.store.service";
|
|
2
|
-
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
3
|
-
import { of } from "rxjs";
|
|
4
|
-
describe("StorefrontStoreService", () => {
|
|
5
|
-
const config = {
|
|
6
|
-
baseUrl: "https://api.example.com",
|
|
7
|
-
version: "api/v1",
|
|
8
|
-
isProd: false,
|
|
9
|
-
clientId: "test-client-id",
|
|
10
|
-
apiKey: "test-api-key",
|
|
11
|
-
};
|
|
12
|
-
let service;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
service = new StorefrontStoreService(config);
|
|
15
|
-
});
|
|
16
|
-
describe("StorefrontStoreProvider", () => {
|
|
17
|
-
it("should generate correct path for store-list", () => {
|
|
18
|
-
const provider = new StorefrontStoreProvider(config, "store-list");
|
|
19
|
-
expect(provider.path).toBe("/storefront/stores/list");
|
|
20
|
-
expect(provider.method).toBe("GET");
|
|
21
|
-
});
|
|
22
|
-
it("should generate correct path for store-information", () => {
|
|
23
|
-
const provider = new StorefrontStoreProvider(config, "store-information");
|
|
24
|
-
expect(provider.path).toBe("/storefront/stores/${id}/information");
|
|
25
|
-
expect(provider.method).toBe("GET");
|
|
26
|
-
expect(provider.getPath(1)).toBe("/storefront/stores/1/information");
|
|
27
|
-
});
|
|
28
|
-
it("should include correct headers", () => {
|
|
29
|
-
const provider = new StorefrontStoreProvider(config, "store-list");
|
|
30
|
-
const headers = provider.headers;
|
|
31
|
-
expect(headers["X-Client-Id"]).toBe("test-client-id");
|
|
32
|
-
expect(headers["X-Api-Key"]).toBe("test-api-key");
|
|
33
|
-
expect(headers["Accept"]).toBe("application/json");
|
|
34
|
-
});
|
|
35
|
-
it("should generate correct baseURL with version", () => {
|
|
36
|
-
const provider = new StorefrontStoreProvider(config, "store-list");
|
|
37
|
-
expect(provider.baseURL).toBe("https://api.example.com/api/v1");
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("listStores", () => {
|
|
41
|
-
it("should list stores successfully", async () => {
|
|
42
|
-
const response = {
|
|
43
|
-
data: { stores: [], total: 0 },
|
|
44
|
-
};
|
|
45
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
46
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
47
|
-
});
|
|
48
|
-
const result = await service.listStores().toPromise();
|
|
49
|
-
expect(result?.hasSuccess).toBe(true);
|
|
50
|
-
expect(result?.response).toEqual(response);
|
|
51
|
-
});
|
|
52
|
-
it("should handle list stores error", async () => {
|
|
53
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
54
|
-
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
55
|
-
});
|
|
56
|
-
const result = await service.listStores().toPromise();
|
|
57
|
-
expect(result?.hasFailed).toBe(true);
|
|
58
|
-
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe("getStoreInformation", () => {
|
|
62
|
-
it("should get store information successfully", async () => {
|
|
63
|
-
const response = {
|
|
64
|
-
data: { id: 1, name: "Test Store" },
|
|
65
|
-
};
|
|
66
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
67
|
-
request: (_payload, _mockResponse, id) => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
68
|
-
});
|
|
69
|
-
const result = await service.getStoreInformation(1).toPromise();
|
|
70
|
-
expect(result?.hasSuccess).toBe(true);
|
|
71
|
-
expect(result?.response).toEqual(response);
|
|
72
|
-
});
|
|
73
|
-
it("should handle get store information error", async () => {
|
|
74
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
75
|
-
request: (_payload, _mockResponse, id) => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
76
|
-
});
|
|
77
|
-
const result = await service.getStoreInformation(1).toPromise();
|
|
78
|
-
expect(result?.hasFailed).toBe(true);
|
|
79
|
-
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe("cache management", () => {
|
|
83
|
-
it("should clear all cache", async () => {
|
|
84
|
-
await expect(service.clearCache()).resolves.toBeUndefined();
|
|
85
|
-
});
|
|
86
|
-
it("should clear specific store cache", async () => {
|
|
87
|
-
await expect(service.clearStoreCache(1)).resolves.toBeUndefined();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "../core/base.provider";
|
|
2
|
-
import { BaseServiceWrapper } from "../core/base.service.wrapper";
|
|
3
|
-
import { NetworkingConfig } from "../types/types";
|
|
4
|
-
export interface User {
|
|
5
|
-
id: number;
|
|
6
|
-
name: string;
|
|
7
|
-
email: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class UserProvider extends BaseProvider {
|
|
10
|
-
constructor(config: NetworkingConfig, userId?: number);
|
|
11
|
-
}
|
|
12
|
-
export declare class UserService extends BaseServiceWrapper<UserProvider> {
|
|
13
|
-
constructor(config: NetworkingConfig, userId?: number);
|
|
14
|
-
fetchUserById(id: number): import("rxjs").Observable<import("../types/types").NetworkingUIEventWrapped<User>>;
|
|
15
|
-
fetchAllUsers(): import("rxjs").Observable<import("../types/types").NetworkingUIEventWrapped<User[]>>;
|
|
16
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "../core/base.provider";
|
|
2
|
-
import { BaseServiceWrapper } from "../core/base.service.wrapper";
|
|
3
|
-
// UserProvider implements ProviderType for user endpoints
|
|
4
|
-
export class UserProvider extends BaseProvider {
|
|
5
|
-
constructor(config, userId) {
|
|
6
|
-
super({
|
|
7
|
-
config,
|
|
8
|
-
path: userId ? `/users/${userId}` : "/users",
|
|
9
|
-
method: "GET",
|
|
10
|
-
headers: {},
|
|
11
|
-
getPath: () => (userId ? `/users/${userId}` : "/users"),
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
// UserService provides high-level methods for user API
|
|
16
|
-
export class UserService extends BaseServiceWrapper {
|
|
17
|
-
constructor(config, userId) {
|
|
18
|
-
super(new UserProvider(config, userId));
|
|
19
|
-
}
|
|
20
|
-
// Fetch a user by ID
|
|
21
|
-
fetchUserById(id) {
|
|
22
|
-
this.provider = new UserProvider({ baseUrl: "https://jsonplaceholder.typicode.com", isProd: false }, id);
|
|
23
|
-
return this.request();
|
|
24
|
-
}
|
|
25
|
-
// Fetch all users
|
|
26
|
-
fetchAllUsers() {
|
|
27
|
-
this.provider = new UserProvider({
|
|
28
|
-
baseUrl: "https://jsonplaceholder.typicode.com",
|
|
29
|
-
isProd: false,
|
|
30
|
-
});
|
|
31
|
-
return this.request();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Example usage:
|
|
35
|
-
// setNetworkingConfig({ baseUrl: 'https://jsonplaceholder.typicode.com', isProd: false });
|
|
36
|
-
// const userService = new UserService();
|
|
37
|
-
// userService.fetchUserById(1).subscribe(result => console.log(result));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { UserService } from "./user.service";
|
|
2
|
-
import { NetworkingUIEventWrapped } from "../types/types";
|
|
3
|
-
import { of, throwError } from "rxjs";
|
|
4
|
-
import { BaseServiceWrapper } from "../core/base.service.wrapper";
|
|
5
|
-
describe("UserService", () => {
|
|
6
|
-
const config = {
|
|
7
|
-
baseUrl: "https://jsonplaceholder.typicode.com",
|
|
8
|
-
isProd: false,
|
|
9
|
-
clientId: "test-client",
|
|
10
|
-
apiKey: "test-key",
|
|
11
|
-
};
|
|
12
|
-
const user = { id: 1, name: "Test", email: "test@example.com" };
|
|
13
|
-
let requestSpy;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
requestSpy = jest
|
|
16
|
-
.spyOn(BaseServiceWrapper.prototype, "request")
|
|
17
|
-
.mockImplementation(() => of(NetworkingUIEventWrapped.succeeded(user)));
|
|
18
|
-
});
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
requestSpy.mockRestore();
|
|
21
|
-
});
|
|
22
|
-
it("fetchUserById should return user (success)", (done) => {
|
|
23
|
-
const service = new UserService(config);
|
|
24
|
-
service
|
|
25
|
-
.fetchUserById(1)
|
|
26
|
-
.subscribe((result) => {
|
|
27
|
-
expect(result.response).toEqual(user);
|
|
28
|
-
done();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
it("fetchAllUsers should return users (success)", (done) => {
|
|
32
|
-
const service = new UserService(config);
|
|
33
|
-
service
|
|
34
|
-
.fetchAllUsers()
|
|
35
|
-
.subscribe((result) => {
|
|
36
|
-
expect(result.response).toEqual(user);
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
it("request should handle error", (done) => {
|
|
41
|
-
requestSpy.mockImplementationOnce(() => throwError(() => new Error("Test error")));
|
|
42
|
-
const service = new UserService(config);
|
|
43
|
-
// Simulate error by calling a method that uses request
|
|
44
|
-
service.fetchUserById(1).subscribe({
|
|
45
|
-
error: (err) => {
|
|
46
|
-
expect(err).toBeInstanceOf(Error);
|
|
47
|
-
expect(err.message).toBe("Test error");
|
|
48
|
-
done();
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
-
import { NetworkingUIEventWrapped } from "../../types/types";
|
|
3
|
-
export declare const withAuthReset: <T>(source$: Observable<NetworkingUIEventWrapped<T>>, $authToken: BehaviorSubject<string | null>) => Observable<NetworkingUIEventWrapped<T>>;
|
package/dist/src/core/axios.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "../utils/networking-import";
|
|
2
|
-
import type { AxiosInterceptorManager } from "axios";
|
|
3
|
-
import { AxiosObservable } from "./axios.observable";
|
|
4
|
-
export interface Axiosable {
|
|
5
|
-
request<T = unknown>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
6
|
-
get<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
7
|
-
head<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
8
|
-
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
9
|
-
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
10
|
-
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
11
|
-
delete<T = unknown>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
12
|
-
}
|
|
13
|
-
declare class Axios implements Axiosable {
|
|
14
|
-
private axiosInstance;
|
|
15
|
-
static defaults: Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
16
|
-
headers: import("axios").HeadersDefaults & {
|
|
17
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
static interceptors: {
|
|
21
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
22
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
23
|
-
};
|
|
24
|
-
constructor(axiosInstance: AxiosInstance);
|
|
25
|
-
get defaults(): Omit<import("axios").AxiosDefaults<any>, "headers"> & {
|
|
26
|
-
headers: import("axios").HeadersDefaults & {
|
|
27
|
-
[key: string]: import("axios").AxiosHeaderValue;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
get interceptors(): {
|
|
31
|
-
request: AxiosInterceptorManager<import("axios").InternalAxiosRequestConfig>;
|
|
32
|
-
response: AxiosInterceptorManager<AxiosResponse>;
|
|
33
|
-
};
|
|
34
|
-
static request<T = any>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
35
|
-
static get<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
36
|
-
static post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
37
|
-
static put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
38
|
-
static patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
39
|
-
static delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
40
|
-
static head<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
41
|
-
static create(config: AxiosRequestConfig): Axios;
|
|
42
|
-
request<T = any>(config: AxiosRequestConfig): AxiosObservable<T>;
|
|
43
|
-
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
44
|
-
head<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
45
|
-
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
46
|
-
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
47
|
-
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
48
|
-
delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosObservable<T>;
|
|
49
|
-
}
|
|
50
|
-
export default Axios;
|
|
51
|
-
export { Axios };
|
package/dist/src/core/axios.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
2
|
-
import { axios, } from "../utils/networking-import";
|
|
3
|
-
import { createObservable } from "./axios.observable";
|
|
4
|
-
class Axios {
|
|
5
|
-
constructor(axiosInstance) {
|
|
6
|
-
this.axiosInstance = axiosInstance;
|
|
7
|
-
}
|
|
8
|
-
get defaults() {
|
|
9
|
-
return this.axiosInstance.defaults;
|
|
10
|
-
}
|
|
11
|
-
get interceptors() {
|
|
12
|
-
return this.axiosInstance.interceptors;
|
|
13
|
-
}
|
|
14
|
-
// ----- Static Methods -----
|
|
15
|
-
static request(config) {
|
|
16
|
-
return createObservable(axios.request, [config]);
|
|
17
|
-
}
|
|
18
|
-
static get(url, config) {
|
|
19
|
-
return createObservable(axios.get, [url, config]);
|
|
20
|
-
}
|
|
21
|
-
static post(url, data, config) {
|
|
22
|
-
return createObservable(axios.post, [url, data, config]);
|
|
23
|
-
}
|
|
24
|
-
static put(url, data, config) {
|
|
25
|
-
return createObservable(axios.put, [url, data, config]);
|
|
26
|
-
}
|
|
27
|
-
static patch(url, data, config) {
|
|
28
|
-
return createObservable(axios.patch, [url, data, config]);
|
|
29
|
-
}
|
|
30
|
-
static delete(url, config) {
|
|
31
|
-
return createObservable(axios.delete, [url, config]);
|
|
32
|
-
}
|
|
33
|
-
static head(url, config) {
|
|
34
|
-
return createObservable(axios.head, [url, config]);
|
|
35
|
-
}
|
|
36
|
-
static create(config) {
|
|
37
|
-
return new Axios(axios.create(config));
|
|
38
|
-
}
|
|
39
|
-
// ----- Instance Methods -----
|
|
40
|
-
request(config) {
|
|
41
|
-
return createObservable(this.axiosInstance.request, [config]);
|
|
42
|
-
}
|
|
43
|
-
get(url, config) {
|
|
44
|
-
return createObservable(this.axiosInstance.get, [url, config]);
|
|
45
|
-
}
|
|
46
|
-
head(url, config) {
|
|
47
|
-
return createObservable(this.axiosInstance.head, [url, config]);
|
|
48
|
-
}
|
|
49
|
-
post(url, data, config) {
|
|
50
|
-
return createObservable(this.axiosInstance.post, [url, data, config]);
|
|
51
|
-
}
|
|
52
|
-
put(url, data, config) {
|
|
53
|
-
return createObservable(this.axiosInstance.put, [url, data, config]);
|
|
54
|
-
}
|
|
55
|
-
patch(url, data, config) {
|
|
56
|
-
return createObservable(this.axiosInstance.patch, [url, data, config]);
|
|
57
|
-
}
|
|
58
|
-
delete(url, config) {
|
|
59
|
-
return createObservable(this.axiosInstance.delete, [url, config]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
Axios.defaults = axios.defaults;
|
|
63
|
-
Axios.interceptors = axios.interceptors;
|
|
64
|
-
export default Axios;
|
|
65
|
-
export { Axios };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from "../utils/networking-import";
|
|
2
|
-
import type { AxiosPromise } from "axios";
|
|
3
|
-
import { Observable } from "../utils/rxjs-import";
|
|
4
|
-
export type AxiosObservable<T> = Observable<AxiosResponse<T>>;
|
|
5
|
-
interface ObservableOptions {
|
|
6
|
-
retry?: number;
|
|
7
|
-
timeoutMs?: number;
|
|
8
|
-
cache?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function createObservable<T>(promiseFactory: (...args: any[]) => AxiosPromise<T>, args: any[], options?: ObservableOptions): AxiosObservable<T>;
|
|
11
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- Required for axios compatibility */
|
|
2
|
-
import { axios, } from "../utils/networking-import";
|
|
3
|
-
import { Observable, timeout as rxTimeout, retry as rxRetry, shareReplay, catchError, throwError, } from "../utils/rxjs-import";
|
|
4
|
-
import { $logger } from "../services/logger.service";
|
|
5
|
-
export function createObservable(promiseFactory, args, options = {}) {
|
|
6
|
-
let config = args[args.length - 1];
|
|
7
|
-
if (config && typeof config === "object" && !Array.isArray(config)) {
|
|
8
|
-
config = { ...config };
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
config = {};
|
|
12
|
-
args.push(config);
|
|
13
|
-
}
|
|
14
|
-
let cancelSource = null;
|
|
15
|
-
const hasCancelToken = !!config.cancelToken;
|
|
16
|
-
if (!hasCancelToken) {
|
|
17
|
-
$logger.warn("[Networking] You can omit cancelToken — unsubscribing cancels the request automatically.", undefined, "axios.observable");
|
|
18
|
-
}
|
|
19
|
-
let source$ = new Observable((subscriber) => {
|
|
20
|
-
if (!hasCancelToken) {
|
|
21
|
-
cancelSource = axios.CancelToken.source();
|
|
22
|
-
config.cancelToken = cancelSource.token;
|
|
23
|
-
}
|
|
24
|
-
promiseFactory(...args)
|
|
25
|
-
.then((response) => {
|
|
26
|
-
subscriber.next(response);
|
|
27
|
-
subscriber.complete();
|
|
28
|
-
})
|
|
29
|
-
.catch((error) => {
|
|
30
|
-
if (!subscriber.closed) {
|
|
31
|
-
subscriber.error(error);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return () => {
|
|
35
|
-
if (cancelSource) {
|
|
36
|
-
cancelSource.cancel("Request canceled via unsubscribe.");
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
// Add timeout if specified
|
|
41
|
-
if (options.timeoutMs) {
|
|
42
|
-
source$ = source$.pipe(rxTimeout(options.timeoutMs));
|
|
43
|
-
}
|
|
44
|
-
// Add retry logic
|
|
45
|
-
if (options.retry) {
|
|
46
|
-
source$ = source$.pipe(rxRetry(options.retry));
|
|
47
|
-
}
|
|
48
|
-
// Cache the response if needed
|
|
49
|
-
if (options.cache) {
|
|
50
|
-
source$ = source$.pipe(shareReplay({ bufferSize: 1, refCount: false }));
|
|
51
|
-
}
|
|
52
|
-
// Optional: Log or catch errors globally
|
|
53
|
-
source$ = source$.pipe(catchError((err) => {
|
|
54
|
-
$logger.error("[createObservable error]:", err, "axios.observable");
|
|
55
|
-
return throwError(() => err);
|
|
56
|
-
}));
|
|
57
|
-
return source$;
|
|
58
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "./base.provider";
|
|
2
|
-
describe("BaseProvider Advanced", () => {
|
|
3
|
-
const config = {
|
|
4
|
-
baseUrl: "https://api.example.com",
|
|
5
|
-
isProd: false,
|
|
6
|
-
clientId: "test-client",
|
|
7
|
-
apiKey: "test-key",
|
|
8
|
-
};
|
|
9
|
-
it("should support dynamic getPath for multiple params", () => {
|
|
10
|
-
const provider = new BaseProvider({
|
|
11
|
-
config,
|
|
12
|
-
path: "/resource/:id/:action",
|
|
13
|
-
method: "GET",
|
|
14
|
-
headers: {},
|
|
15
|
-
getPath: (id, action) => `/resource/${id}/${action}`,
|
|
16
|
-
});
|
|
17
|
-
expect(provider.getPath("42", "edit")).toBe("/resource/42/edit");
|
|
18
|
-
});
|
|
19
|
-
it("should allow dynamic headers and method", () => {
|
|
20
|
-
const provider = new BaseProvider({
|
|
21
|
-
config,
|
|
22
|
-
path: "/resource",
|
|
23
|
-
method: "PATCH",
|
|
24
|
-
headers: { Authorization: "Bearer token" },
|
|
25
|
-
});
|
|
26
|
-
expect(provider.method).toBe("PATCH");
|
|
27
|
-
expect(provider.headers.Authorization).toBe("Bearer token");
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig } from "../types/types";
|
|
2
|
-
export declare class BaseProvider implements ProviderType {
|
|
3
|
-
baseURL: string;
|
|
4
|
-
path: string;
|
|
5
|
-
method: string;
|
|
6
|
-
headers: Record<string, string | undefined>;
|
|
7
|
-
getPath: (...queryParams: unknown[]) => string;
|
|
8
|
-
constructor({ config, path, method, headers, getPath, }: {
|
|
9
|
-
config: NetworkingConfig;
|
|
10
|
-
path: string;
|
|
11
|
-
method: string;
|
|
12
|
-
headers?: any;
|
|
13
|
-
getPath?: (...queryParams: any[]) => string;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export class BaseProvider {
|
|
2
|
-
constructor({ config, path, method, headers = {}, getPath = () => path, }) {
|
|
3
|
-
this.baseURL = config.baseUrl;
|
|
4
|
-
this.path = path;
|
|
5
|
-
this.method = method;
|
|
6
|
-
this.headers = {
|
|
7
|
-
...headers,
|
|
8
|
-
"X-Client-Id": config.clientId,
|
|
9
|
-
"X-Api-Key": config.apiKey,
|
|
10
|
-
};
|
|
11
|
-
this.getPath = getPath || (() => path);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { BaseProvider } from "./base.provider";
|
|
2
|
-
describe("BaseProvider", () => {
|
|
3
|
-
const config = {
|
|
4
|
-
baseUrl: "https://api.example.com",
|
|
5
|
-
isProd: false,
|
|
6
|
-
clientId: "test-client",
|
|
7
|
-
apiKey: "test-key",
|
|
8
|
-
};
|
|
9
|
-
it("should construct with required fields", () => {
|
|
10
|
-
const provider = new BaseProvider({
|
|
11
|
-
config,
|
|
12
|
-
path: "/resource",
|
|
13
|
-
method: "GET",
|
|
14
|
-
headers: { foo: "bar" },
|
|
15
|
-
});
|
|
16
|
-
expect(provider.baseURL).toBe("https://api.example.com");
|
|
17
|
-
expect(provider.path).toBe("/resource");
|
|
18
|
-
expect(provider.method).toBe("GET");
|
|
19
|
-
expect(provider.headers).toEqual({
|
|
20
|
-
foo: "bar",
|
|
21
|
-
"X-Client-Id": "test-client",
|
|
22
|
-
"X-Api-Key": "test-key",
|
|
23
|
-
});
|
|
24
|
-
expect(provider.getPath()).toBe("/resource");
|
|
25
|
-
});
|
|
26
|
-
it("should use custom getPath if provided", () => {
|
|
27
|
-
const provider = new BaseProvider({
|
|
28
|
-
config,
|
|
29
|
-
path: "/resource/:id",
|
|
30
|
-
method: "GET",
|
|
31
|
-
headers: {},
|
|
32
|
-
getPath: (id) => `/resource/${id}`,
|
|
33
|
-
});
|
|
34
|
-
expect(provider.getPath("123")).toBe("/resource/123");
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|