@smess/networking 1.0.30 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
1
+ import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse, CacheOptions } from "../types/types";
2
2
  import { SmessService } from "./smess.service";
3
3
  import { Observable } from "rxjs";
4
4
  export type StorefrontStoreTarget = "store-list" | "store-information";
@@ -25,7 +25,9 @@ export declare class StorefrontStoreService {
25
25
  private readonly config;
26
26
  private readonly cacheService;
27
27
  private readonly storeListCache;
28
- constructor(config: NetworkingConfig);
28
+ private readonly cacheOptions;
29
+ private readonly cacheDuration;
30
+ constructor(config: NetworkingConfig, cacheOptions?: CacheOptions);
29
31
  provider(target: StorefrontStoreTarget): SmessService<StorefrontStoreProvider>;
30
32
  /**
31
33
  * List all accessible stores with shipping rules
@@ -46,7 +48,7 @@ export declare class StorefrontStoreService {
46
48
  */
47
49
  clearStoreCache(id: number): Promise<void>;
48
50
  /**
49
- * Check if cache is still valid (24 hours)
51
+ * Check if cache is still valid
50
52
  */
51
53
  private isCacheValid;
52
54
  }
@@ -46,8 +46,11 @@ export class StorefrontStoreProvider {
46
46
  }
47
47
  }
48
48
  export class StorefrontStoreService {
49
- constructor(config) {
49
+ constructor(config, cacheOptions) {
50
50
  this.config = config;
51
+ this.cacheOptions = cacheOptions || {};
52
+ this.cacheDuration =
53
+ this.cacheOptions.cacheTtlMs ?? 24 * 60 * 60 * 1000; // Default 24 hours
51
54
  // Initialize cache services for different data types
52
55
  this.cacheService = new GenericIndexedDBService("StorefrontStoreCache", "id, timestamp", (data) => data, (data) => data);
53
56
  this.storeListCache = new GenericIndexedDBService("StorefrontStoreListCache", "timestamp", (data) => data, (data) => data);
@@ -131,10 +134,9 @@ export class StorefrontStoreService {
131
134
  return this.cacheService.delete(String(id));
132
135
  }
133
136
  /**
134
- * Check if cache is still valid (24 hours)
137
+ * Check if cache is still valid
135
138
  */
136
139
  isCacheValid(timestamp) {
137
- const CACHE_DURATION = 24 * 60 * 60 * 1000; // 24 hours
138
- return Date.now() - timestamp < CACHE_DURATION;
140
+ return Date.now() - timestamp < this.cacheDuration;
139
141
  }
140
142
  }
@@ -90,4 +90,7 @@ export interface NetworkingConfig {
90
90
  clientId?: string;
91
91
  apiKey?: string;
92
92
  }
93
+ export interface CacheOptions {
94
+ cacheTtlMs?: number;
95
+ }
93
96
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smess/networking",
3
- "version": "1.0.30",
3
+ "version": "1.1.0",
4
4
  "description": "Networking utilities and services for SMESS platform.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",