@smess/networking 1.0.19 → 1.0.20

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.
@@ -1,7 +1,7 @@
1
1
  import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
2
2
  import { SmessService } from "./smess.service";
3
3
  import { Observable } from "rxjs";
4
- export type StoreProductTarget = "featured-product-list" | "featured-product-list-by-store" | "product-category-list" | "product-get-by-id" | "store-list" | "store-information" | "product-collection" | "product-collection-by-store" | "product-update-batch" | "customer-update-batch" | "cart-update-batch" | "order-item-update-batch";
4
+ export type StoreProductTarget = "featured-product-list" | "featured-product-list-by-store" | "product-category-list" | "product-get-by-id" | "product-collection" | "product-collection-by-store";
5
5
  export interface StoreProductCollectionRequest {
6
6
  page?: number;
7
7
  per_page?: number;
@@ -16,9 +16,6 @@ export interface StoreProductCollectionRequest {
16
16
  has_offer?: boolean;
17
17
  [key: string]: unknown;
18
18
  }
19
- export interface BatchUpdateRequest {
20
- [key: string]: unknown;
21
- }
22
19
  export interface PaginationLinks {
23
20
  first: string;
24
21
  last: string;
@@ -85,14 +82,8 @@ export interface StoreProductServiceType {
85
82
  getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
86
83
  getProductCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
87
84
  getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
88
- getStoreList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
89
- getStoreInformation(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
90
85
  getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
91
86
  getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
92
- updateProductBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
93
- updateCustomerBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
94
- updateCartBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
95
- updateOrderItemBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
96
87
  }
97
88
  export declare class StoreProductService implements StoreProductServiceType {
98
89
  private readonly config;
@@ -118,16 +109,6 @@ export declare class StoreProductService implements StoreProductServiceType {
118
109
  * GET /api/v1/store/product/{id}
119
110
  */
120
111
  getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
121
- /**
122
- * Get store list
123
- * GET /api/v1/store/list
124
- */
125
- getStoreList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
126
- /**
127
- * Get store information
128
- * GET /api/v1/store/{id}/information
129
- */
130
- getStoreInformation(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
131
112
  /**
132
113
  * Get product collection
133
114
  * GET /api/v1/store/product-collection
@@ -138,24 +119,4 @@ export declare class StoreProductService implements StoreProductServiceType {
138
119
  * GET /api/v1/store/{id}/product-collection
139
120
  */
140
121
  getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
141
- /**
142
- * Update product batch
143
- * POST /api/v1/store/{id}/product
144
- */
145
- updateProductBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
146
- /**
147
- * Update customer batch
148
- * POST /api/v1/store/{id}/customer/batch
149
- */
150
- updateCustomerBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
151
- /**
152
- * Update cart batch
153
- * POST /api/v1/store/{id}/order/batch
154
- */
155
- updateCartBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
156
- /**
157
- * Update order item batch
158
- * POST /api/v1/store/{id}/order-item
159
- */
160
- updateOrderItemBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
161
122
  }
@@ -19,36 +19,16 @@ export class StoreProductProvider {
19
19
  return "/store/product-category/list";
20
20
  case "product-get-by-id":
21
21
  return "/store/product/${id}";
22
- case "store-list":
23
- return "/store/list";
24
- case "store-information":
25
- return "/store/${id}/information";
26
22
  case "product-collection":
27
23
  return "/store/product-collection";
28
24
  case "product-collection-by-store":
29
25
  return "/store/${id}/product-collection";
30
- case "product-update-batch":
31
- return "/store/${id}/product";
32
- case "customer-update-batch":
33
- return "/store/${id}/customer/batch";
34
- case "cart-update-batch":
35
- return "/store/${id}/order/batch";
36
- case "order-item-update-batch":
37
- return "/store/${id}/order-item";
38
26
  default:
39
27
  return "/store";
40
28
  }
41
29
  }
42
30
  get method() {
43
- switch (this.target) {
44
- case "product-update-batch":
45
- case "customer-update-batch":
46
- case "cart-update-batch":
47
- case "order-item-update-batch":
48
- return "POST";
49
- default:
50
- return "GET";
51
- }
31
+ return "GET";
52
32
  }
53
33
  get headers() {
54
34
  let headers = SmessService.getHeaders(Accept.V1, null);
@@ -105,20 +85,6 @@ export class StoreProductService {
105
85
  getProductById(productId) {
106
86
  return this.provider("product-get-by-id").request(undefined, undefined, productId);
107
87
  }
108
- /**
109
- * Get store list
110
- * GET /api/v1/store/list
111
- */
112
- getStoreList() {
113
- return this.provider("store-list").request();
114
- }
115
- /**
116
- * Get store information
117
- * GET /api/v1/store/{id}/information
118
- */
119
- getStoreInformation(storeId) {
120
- return this.provider("store-information").request(undefined, undefined, storeId);
121
- }
122
88
  /**
123
89
  * Get product collection
124
90
  * GET /api/v1/store/product-collection
@@ -133,32 +99,4 @@ export class StoreProductService {
133
99
  getProductCollectionByStore(storeId, payload) {
134
100
  return this.provider("product-collection-by-store").request(null, undefined, storeId, payload);
135
101
  }
136
- /**
137
- * Update product batch
138
- * POST /api/v1/store/{id}/product
139
- */
140
- updateProductBatch(storeId, payload) {
141
- return this.provider("product-update-batch").request(payload, undefined, storeId);
142
- }
143
- /**
144
- * Update customer batch
145
- * POST /api/v1/store/{id}/customer/batch
146
- */
147
- updateCustomerBatch(storeId, payload) {
148
- return this.provider("customer-update-batch").request(payload, undefined, storeId);
149
- }
150
- /**
151
- * Update cart batch
152
- * POST /api/v1/store/{id}/order/batch
153
- */
154
- updateCartBatch(storeId, payload) {
155
- return this.provider("cart-update-batch").request(payload, undefined, storeId);
156
- }
157
- /**
158
- * Update order item batch
159
- * POST /api/v1/store/{id}/order-item
160
- */
161
- updateOrderItemBatch(storeId, payload) {
162
- return this.provider("order-item-update-batch").request(payload, undefined, storeId);
163
- }
164
102
  }
@@ -172,29 +172,6 @@ describe("StoreProductService", () => {
172
172
  expect(result?.response).toEqual(response);
173
173
  });
174
174
  });
175
- describe("getStoreList", () => {
176
- it("should get store list successfully", async () => {
177
- const response = { data: [{ id: "1", name: "Store 1" }] };
178
- jest.spyOn(service, "provider").mockReturnValue({
179
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
180
- });
181
- const result = await service.getStoreList().toPromise();
182
- expect(result?.hasSuccess).toBe(true);
183
- expect(result?.response).toEqual(response);
184
- });
185
- });
186
- describe("getStoreInformation", () => {
187
- it("should get store information successfully", async () => {
188
- const storeId = "store-123";
189
- const response = { data: { id: storeId, name: "Store 1" } };
190
- jest.spyOn(service, "provider").mockReturnValue({
191
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
192
- });
193
- const result = await service.getStoreInformation(storeId).toPromise();
194
- expect(result?.hasSuccess).toBe(true);
195
- expect(result?.response).toEqual(response);
196
- });
197
- });
198
175
  describe("getProductCollection", () => {
199
176
  it("should get product collection successfully", async () => {
200
177
  const payload = {
@@ -339,64 +316,4 @@ describe("StoreProductService", () => {
339
316
  expect(result?.response).toEqual(response);
340
317
  });
341
318
  });
342
- describe("updateProductBatch", () => {
343
- it("should update product batch successfully", async () => {
344
- const storeId = "store-123";
345
- const payload = {
346
- products: [{ id: "1", price: 100 }],
347
- };
348
- const response = { data: { updated: 1 } };
349
- jest.spyOn(service, "provider").mockReturnValue({
350
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
351
- });
352
- const result = await service.updateProductBatch(storeId, payload).toPromise();
353
- expect(result?.hasSuccess).toBe(true);
354
- expect(result?.response).toEqual(response);
355
- });
356
- });
357
- describe("updateCustomerBatch", () => {
358
- it("should update customer batch successfully", async () => {
359
- const storeId = "store-123";
360
- const payload = {
361
- customers: [{ id: "1", status: "active" }],
362
- };
363
- const response = { data: { updated: 1 } };
364
- jest.spyOn(service, "provider").mockReturnValue({
365
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
366
- });
367
- const result = await service.updateCustomerBatch(storeId, payload).toPromise();
368
- expect(result?.hasSuccess).toBe(true);
369
- expect(result?.response).toEqual(response);
370
- });
371
- });
372
- describe("updateCartBatch", () => {
373
- it("should update cart batch successfully", async () => {
374
- const storeId = "store-123";
375
- const payload = {
376
- orders: [{ id: "1", status: "completed" }],
377
- };
378
- const response = { data: { updated: 1 } };
379
- jest.spyOn(service, "provider").mockReturnValue({
380
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
381
- });
382
- const result = await service.updateCartBatch(storeId, payload).toPromise();
383
- expect(result?.hasSuccess).toBe(true);
384
- expect(result?.response).toEqual(response);
385
- });
386
- });
387
- describe("updateOrderItemBatch", () => {
388
- it("should update order item batch successfully", async () => {
389
- const storeId = "store-123";
390
- const payload = {
391
- items: [{ id: "1", quantity: 5 }],
392
- };
393
- const response = { data: { updated: 1 } };
394
- jest.spyOn(service, "provider").mockReturnValue({
395
- request: () => of(NetworkingUIEventWrapped.succeeded(response)),
396
- });
397
- const result = await service.updateOrderItemBatch(storeId, payload).toPromise();
398
- expect(result?.hasSuccess).toBe(true);
399
- expect(result?.response).toEqual(response);
400
- });
401
- });
402
319
  });
@@ -18,8 +18,7 @@ export interface ProductCollectionRequest {
18
18
  export declare class StoreProvider implements ProviderType {
19
19
  private readonly config;
20
20
  private readonly target;
21
- private readonly $authToken;
22
- constructor(config: NetworkingConfig, target: StoreTarget, $authToken: BehaviorSubject<string | null>);
21
+ constructor(config: NetworkingConfig, target: StoreTarget);
23
22
  get baseURL(): string;
24
23
  get path(): string;
25
24
  get method(): string;
@@ -52,14 +51,13 @@ export interface FeaturedProductData {
52
51
  }
53
52
  export declare class StoreService {
54
53
  private readonly config;
55
- private readonly $authToken;
56
54
  readonly $selectedStoreId: BehaviorSubject<string | null>;
57
55
  private readonly cacheService;
58
56
  private readonly storeListCache;
59
57
  private readonly productCollectionCache;
60
58
  private readonly productCategoryCache;
61
59
  private readonly featuredProductCache;
62
- constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
60
+ constructor(config: NetworkingConfig);
63
61
  provider(target: StoreTarget): SmessService<StoreProvider>;
64
62
  /**
65
63
  * Set the selected store ID
@@ -4,10 +4,9 @@ import { BehaviorSubject, from, of } from "rxjs";
4
4
  import { map, switchMap, catchError } from "rxjs/operators";
5
5
  import { GenericIndexedDBService } from "./cache.service";
6
6
  export class StoreProvider {
7
- constructor(config, target, $authToken) {
7
+ constructor(config, target) {
8
8
  this.config = config;
9
9
  this.target = target;
10
- this.$authToken = $authToken;
11
10
  }
12
11
  get baseURL() {
13
12
  return this.config.version
@@ -34,7 +33,7 @@ export class StoreProvider {
34
33
  return "GET";
35
34
  }
36
35
  get headers() {
37
- let headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
36
+ let headers = SmessService.getHeaders(Accept.V1, null);
38
37
  if (this.config.clientId) {
39
38
  headers[SMESSHeader.ClientId] = this.config.clientId;
40
39
  }
@@ -53,9 +52,8 @@ export class StoreProvider {
53
52
  }
54
53
  }
55
54
  export class StoreService {
56
- constructor(config, $authToken) {
55
+ constructor(config) {
57
56
  this.config = config;
58
- this.$authToken = $authToken;
59
57
  this.$selectedStoreId = new BehaviorSubject(null);
60
58
  // Initialize cache services for different data types
61
59
  this.cacheService = new GenericIndexedDBService("StoreCache", "id, timestamp", (data) => data, (data) => data);
@@ -65,7 +63,7 @@ export class StoreService {
65
63
  this.featuredProductCache = new GenericIndexedDBService("FeaturedProductCache", "storeId, timestamp", (data) => data, (data) => data);
66
64
  }
67
65
  provider(target) {
68
- const targetWrapper = new StoreProvider(this.config, target, this.$authToken);
66
+ const targetWrapper = new StoreProvider(this.config, target);
69
67
  return new SmessService(targetWrapper);
70
68
  }
71
69
  /**
@@ -1,7 +1,7 @@
1
1
  import "fake-indexeddb/auto";
2
2
  import { StoreService, } from "./store.service";
3
3
  import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
4
- import { of, BehaviorSubject } from "rxjs";
4
+ import { of } from "rxjs";
5
5
  describe("StoreService", () => {
6
6
  const config = {
7
7
  baseUrl: "https://api.example.com",
@@ -10,10 +10,8 @@ describe("StoreService", () => {
10
10
  apiKey: "test-api-key",
11
11
  };
12
12
  let service;
13
- let $authToken;
14
13
  beforeEach(() => {
15
- $authToken = new BehaviorSubject(null);
16
- service = new StoreService(config, $authToken);
14
+ service = new StoreService(config);
17
15
  });
18
16
  afterEach(async () => {
19
17
  await service.clearCache();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smess/networking",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "Networking utilities and services for SMESS platform.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",