feeef 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/feeef/feeef.ts +18 -7
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "feeef sdk for the web",
4
4
  "main": "src/index.ts",
5
5
  "private": false,
6
- "version": "0.0.21",
6
+ "version": "0.0.22",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "dev": "vite --host",
@@ -26,4 +26,4 @@
26
26
  "typescript": "^5.0.2",
27
27
  "vite": "^4.4.5"
28
28
  }
29
- }
29
+ }
@@ -1,5 +1,9 @@
1
1
  import axios, { AxiosInstance } from "axios";
2
- import { buildWebStorage, setupCache } from "axios-cache-interceptor";
2
+ import {
3
+ buildMemoryStorage,
4
+ buildWebStorage,
5
+ setupCache,
6
+ } from "axios-cache-interceptor";
3
7
  import { OrderRepository } from "./repositories/orders";
4
8
  import { ProductRepository } from "./repositories/products";
5
9
  import { StoreRepository } from "./repositories/stores";
@@ -74,19 +78,26 @@ export class FeeeF {
74
78
  * @param {AxiosInstance} config.client - The Axios instance used for making HTTP requests.
75
79
  * @param {boolean | number} config.cache - The caching configuration. Set to `false` to disable caching, or provide a number to set the cache TTL in milliseconds.
76
80
  */
77
- constructor({ apiKey, client, cache, baseURL = "http://localhost:3333/api/v1"}: FeeeFConfig) {
81
+ constructor({
82
+ apiKey,
83
+ client,
84
+ cache,
85
+ baseURL = "http://localhost:3333/api/v1",
86
+ }: FeeeFConfig) {
78
87
  this.apiKey = apiKey;
79
88
  // get th "cache" search param
80
- const urlParams = new URLSearchParams(window.location.search);
81
- const cacheParam = urlParams.get("cache");
82
89
  // if is 0 or false, disable cache
83
- if (cacheParam == '0') {
90
+ if (cache === false) {
84
91
  this.client = client || axios;
85
92
  } else {
93
+ const isInBrowser =
94
+ typeof window !== "undefined" && typeof localStorage !== "undefined";
86
95
  this.client = setupCache(client || axios, {
87
- ttl: cache === false ? 5 : Math.max(cache!, 5) || 1 * 60 * 1000, // 1 minute by default
96
+ ttl: cache === undefined ? 1000 * 60 * 5 : Math.max(cache!, 1000), //|| 1 * 60 * 1000, // 1 minute by default
88
97
  // for persistent cache use buildWebStorage
89
- storage: buildWebStorage(localStorage, "ff:"),
98
+ storage: isInBrowser
99
+ ? buildWebStorage(localStorage, "ff:")
100
+ : buildMemoryStorage(),
90
101
  });
91
102
  }
92
103
  // set base url