feeef 0.0.20 → 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.
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.20",
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,107 +1,110 @@
1
- import { EmbaddedCategory } from '../embadded/category.js'
2
- import { ShippingMethodEntity } from './shipping_method.js'
3
- import { StoreEntity } from './store.js'
1
+ import { EmbaddedCategory } from "../embadded/category.js";
2
+ import { ShippingMethodEntity } from "./shipping_method.js";
3
+ import { StoreEntity } from "./store.js";
4
4
 
5
5
  export interface ProductEntity {
6
- id: string
6
+ id: string;
7
7
 
8
- slug: string
8
+ slug: string;
9
9
 
10
- decoration: ProductDecoration | null
10
+ decoration: ProductDecoration | null;
11
11
 
12
- name: string | null
12
+ name: string | null;
13
13
 
14
- photoUrl: string | null
14
+ photoUrl: string | null;
15
15
 
16
- media: string[]
16
+ media: string[];
17
17
 
18
- storeId: string
18
+ storeId: string;
19
19
 
20
- shippingMethodId?: string | null
20
+ shippingMethodId?: string | null;
21
21
 
22
- category: EmbaddedCategory
22
+ category: EmbaddedCategory;
23
23
 
24
- title: string | null
24
+ title: string | null;
25
25
 
26
- description: string | null
26
+ description: string | null;
27
27
 
28
- body: string | null
28
+ body: string | null;
29
29
 
30
30
  // sku
31
- sku: string | null
31
+ sku: string | null;
32
32
 
33
- price: number
33
+ price: number;
34
34
 
35
- discount: number | null
35
+ discount: number | null;
36
36
 
37
- stock: number
37
+ stock: number;
38
38
 
39
- sold: number
39
+ sold: number;
40
40
 
41
- views: number
41
+ views: number;
42
42
 
43
- likes: number
43
+ likes: number;
44
44
 
45
- dislikes: number
45
+ dislikes: number;
46
46
 
47
- variant?: ProductVariant | null
47
+ variant?: ProductVariant | null;
48
48
 
49
- metadata: Record<string, any>
49
+ metadata: Record<string, any>;
50
50
 
51
- status: ProductStatus
51
+ status: ProductStatus;
52
52
 
53
- type: ProductType
53
+ type: ProductType;
54
54
 
55
- verifiedAt: any | null
55
+ verifiedAt: any | null;
56
56
 
57
- blockedAt: any | null
57
+ blockedAt: any | null;
58
58
 
59
- createdAt: any
59
+ createdAt: any;
60
60
 
61
- updatedAt: any
61
+ updatedAt: any;
62
62
 
63
63
  // relations
64
- store?: StoreEntity
65
- shippingMethod?: ShippingMethodEntity
64
+ store?: StoreEntity;
65
+ shippingMethod?: ShippingMethodEntity;
66
66
  }
67
67
 
68
68
  export enum ProductStatus {
69
- draft = 'draft',
70
- published = 'published',
71
- archived = 'archived',
72
- deleted = 'deleted',
69
+ draft = "draft",
70
+ published = "published",
71
+ archived = "archived",
72
+ deleted = "deleted",
73
73
  }
74
74
 
75
75
  export interface ProductDecoration {
76
- metadata: Record<string, any>
76
+ metadata: Record<string, any>;
77
77
  }
78
78
 
79
79
  export interface ProductVariant {
80
- name: string
81
- options: ProductVariantOption[]
80
+ name: string;
81
+ options: ProductVariantOption[];
82
82
  }
83
83
 
84
84
  export interface ProductVariantOption {
85
- name: string
86
- sku?: string | null
87
- price?: number | null
88
- discount?: number | null
89
- stock?: number | null
90
- sold?: number | null
91
- type?: VariantOptionType
92
- child?: ProductVariant | null
93
- mediaIndex?: number | null
94
- hint?: string | null
85
+ name: string;
86
+ sku?: string | null;
87
+ price?: number | null;
88
+ discount?: number | null;
89
+ stock?: number | null;
90
+ sold?: number | null;
91
+ type?: VariantOptionType;
92
+ child?: ProductVariant | null;
93
+ mediaIndex?: number | null;
94
+ hint?: string | null;
95
+ // value is the actual value of the option
96
+ // its dynamic and can be any type
97
+ value: any;
95
98
  }
96
99
 
97
100
  export enum VariantOptionType {
98
- color = 'color',
99
- image = 'image',
100
- text = 'text',
101
+ color = "color",
102
+ image = "image",
103
+ text = "text",
101
104
  }
102
105
 
103
106
  export enum ProductType {
104
- physical = 'physical',
105
- digital = 'digital',
106
- service = 'service',
107
+ physical = "physical",
108
+ digital = "digital",
109
+ service = "service",
107
110
  }
@@ -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