@etsoo/appscript 1.4.44 → 1.4.46

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,17 +1,21 @@
1
1
  import { DataTypes, IStorage } from '@etsoo/shared';
2
+ import { Currency } from './Currency';
2
3
  /**
3
4
  * Shopping cart owner
4
5
  * 购物篮所有人
5
6
  */
6
7
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
7
8
  isSupplier?: boolean;
9
+ culture?: string;
10
+ currency?: Currency;
8
11
  };
9
12
  /**
10
13
  * Shopping cart data
11
14
  * 购物篮数据
12
15
  */
13
16
  export type ShoppingCartData<T extends ShoppingCartItem> = {
14
- currency: string;
17
+ culture: string;
18
+ currency: Currency;
15
19
  owner: ShoppingCartOwner;
16
20
  items: T[];
17
21
  promotions: ShoppingPromotion[];
@@ -110,10 +114,11 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
110
114
  * Create identifier key
111
115
  * 创建识别键
112
116
  * @param currency Currency
117
+ * @param culture Culture
113
118
  * @param key Additional key
114
119
  * @returns Result
115
120
  */
116
- static createKey(currency: string, key?: string): string;
121
+ static createKey(currency: Currency, culture: string, key?: string): string;
117
122
  /**
118
123
  * Clear shopping cart
119
124
  * 清除购物篮
@@ -125,9 +130,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
125
130
  * Clear shopping cart
126
131
  * 清除购物篮
127
132
  * @param currency Currency
133
+ * @param culture Culture
128
134
  * @param storage Storage
129
135
  */
130
- static clearWith(currency: string, storage?: IStorage): void;
136
+ static clearWith(currency: Currency, culture: string, storage?: IStorage): void;
131
137
  /**
132
138
  * Get cart data
133
139
  * 获取购物篮数据
@@ -147,7 +153,12 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
147
153
  * ISO currency id
148
154
  * 标准货币编号
149
155
  */
150
- readonly currency: string;
156
+ readonly currency: Currency;
157
+ /**
158
+ * ISO culture id, like zh-Hans
159
+ * 标准语言文化编号
160
+ */
161
+ readonly culture: string;
151
162
  _items: T[];
152
163
  /**
153
164
  * Items
@@ -216,10 +227,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
216
227
  /**
217
228
  * Constructor
218
229
  * 构造函数
219
- * @param currency Currency ISO code
230
+ * @param init Currency & culture ISO code array
220
231
  * @param storage Data storage
221
232
  */
222
- constructor(currency: string, storage?: IStorage);
233
+ constructor(init: [Currency, string], storage?: IStorage);
223
234
  /**
224
235
  * Constructor
225
236
  * 构造函数
@@ -12,11 +12,12 @@ class ShoppingCart {
12
12
  * Create identifier key
13
13
  * 创建识别键
14
14
  * @param currency Currency
15
+ * @param culture Culture
15
16
  * @param key Additional key
16
17
  * @returns Result
17
18
  */
18
- static createKey(currency, key = 'KEY') {
19
- return `ETSOO-CART-${key}-${currency}`;
19
+ static createKey(currency, culture, key = 'KEY') {
20
+ return `ETSOO-CART-${culture}-${key}-${currency}`;
20
21
  }
21
22
  /**
22
23
  * Clear shopping cart
@@ -37,10 +38,11 @@ class ShoppingCart {
37
38
  * Clear shopping cart
38
39
  * 清除购物篮
39
40
  * @param currency Currency
41
+ * @param culture Culture
40
42
  * @param storage Storage
41
43
  */
42
- static clearWith(currency, storage = new shared_1.WindowStorage()) {
43
- const identifier = this.createKey(currency);
44
+ static clearWith(currency, culture, storage = new shared_1.WindowStorage()) {
45
+ const identifier = this.createKey(currency, culture);
44
46
  this.clear(identifier, storage);
45
47
  }
46
48
  /**
@@ -103,7 +105,7 @@ class ShoppingCart {
103
105
  */
104
106
  get identifier() {
105
107
  const o = this.owner;
106
- return ShoppingCart.createKey(this.currency, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
108
+ return ShoppingCart.createKey(this.currency, this.culture, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
107
109
  }
108
110
  /**
109
111
  * All data keys
@@ -162,12 +164,14 @@ class ShoppingCart {
162
164
  * 缓存的价格
163
165
  */
164
166
  this.prices = {};
165
- if (typeof currencyOrState === 'string') {
166
- this.currency = currencyOrState;
167
+ if (Array.isArray(currencyOrState)) {
168
+ this.currency = currencyOrState[0];
169
+ this.culture = currencyOrState[1];
167
170
  }
168
171
  else {
169
172
  this.setCartData(currencyOrState);
170
173
  this.currency = currencyOrState.currency;
174
+ this.culture = currencyOrState.culture;
171
175
  }
172
176
  this.symbol = shared_1.NumberUtils.getCurrencySymbol(this.currency);
173
177
  }
@@ -261,9 +265,10 @@ class ShoppingCart {
261
265
  save(persisted = true) {
262
266
  if (this.owner == null)
263
267
  return;
264
- const { currency, owner, items, promotions, formData } = this;
268
+ const { currency, culture, owner, items, promotions, formData } = this;
265
269
  const data = {
266
270
  currency,
271
+ culture,
267
272
  owner,
268
273
  items,
269
274
  promotions,
@@ -1,17 +1,21 @@
1
1
  import { DataTypes, IStorage } from '@etsoo/shared';
2
+ import { Currency } from './Currency';
2
3
  /**
3
4
  * Shopping cart owner
4
5
  * 购物篮所有人
5
6
  */
6
7
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
7
8
  isSupplier?: boolean;
9
+ culture?: string;
10
+ currency?: Currency;
8
11
  };
9
12
  /**
10
13
  * Shopping cart data
11
14
  * 购物篮数据
12
15
  */
13
16
  export type ShoppingCartData<T extends ShoppingCartItem> = {
14
- currency: string;
17
+ culture: string;
18
+ currency: Currency;
15
19
  owner: ShoppingCartOwner;
16
20
  items: T[];
17
21
  promotions: ShoppingPromotion[];
@@ -110,10 +114,11 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
110
114
  * Create identifier key
111
115
  * 创建识别键
112
116
  * @param currency Currency
117
+ * @param culture Culture
113
118
  * @param key Additional key
114
119
  * @returns Result
115
120
  */
116
- static createKey(currency: string, key?: string): string;
121
+ static createKey(currency: Currency, culture: string, key?: string): string;
117
122
  /**
118
123
  * Clear shopping cart
119
124
  * 清除购物篮
@@ -125,9 +130,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
125
130
  * Clear shopping cart
126
131
  * 清除购物篮
127
132
  * @param currency Currency
133
+ * @param culture Culture
128
134
  * @param storage Storage
129
135
  */
130
- static clearWith(currency: string, storage?: IStorage): void;
136
+ static clearWith(currency: Currency, culture: string, storage?: IStorage): void;
131
137
  /**
132
138
  * Get cart data
133
139
  * 获取购物篮数据
@@ -147,7 +153,12 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
147
153
  * ISO currency id
148
154
  * 标准货币编号
149
155
  */
150
- readonly currency: string;
156
+ readonly currency: Currency;
157
+ /**
158
+ * ISO culture id, like zh-Hans
159
+ * 标准语言文化编号
160
+ */
161
+ readonly culture: string;
151
162
  _items: T[];
152
163
  /**
153
164
  * Items
@@ -216,10 +227,10 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
216
227
  /**
217
228
  * Constructor
218
229
  * 构造函数
219
- * @param currency Currency ISO code
230
+ * @param init Currency & culture ISO code array
220
231
  * @param storage Data storage
221
232
  */
222
- constructor(currency: string, storage?: IStorage);
233
+ constructor(init: [Currency, string], storage?: IStorage);
223
234
  /**
224
235
  * Constructor
225
236
  * 构造函数
@@ -9,11 +9,12 @@ export class ShoppingCart {
9
9
  * Create identifier key
10
10
  * 创建识别键
11
11
  * @param currency Currency
12
+ * @param culture Culture
12
13
  * @param key Additional key
13
14
  * @returns Result
14
15
  */
15
- static createKey(currency, key = 'KEY') {
16
- return `ETSOO-CART-${key}-${currency}`;
16
+ static createKey(currency, culture, key = 'KEY') {
17
+ return `ETSOO-CART-${culture}-${key}-${currency}`;
17
18
  }
18
19
  /**
19
20
  * Clear shopping cart
@@ -34,10 +35,11 @@ export class ShoppingCart {
34
35
  * Clear shopping cart
35
36
  * 清除购物篮
36
37
  * @param currency Currency
38
+ * @param culture Culture
37
39
  * @param storage Storage
38
40
  */
39
- static clearWith(currency, storage = new WindowStorage()) {
40
- const identifier = this.createKey(currency);
41
+ static clearWith(currency, culture, storage = new WindowStorage()) {
42
+ const identifier = this.createKey(currency, culture);
41
43
  this.clear(identifier, storage);
42
44
  }
43
45
  /**
@@ -100,7 +102,7 @@ export class ShoppingCart {
100
102
  */
101
103
  get identifier() {
102
104
  const o = this.owner;
103
- return ShoppingCart.createKey(this.currency, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
105
+ return ShoppingCart.createKey(this.currency, this.culture, o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined);
104
106
  }
105
107
  /**
106
108
  * All data keys
@@ -159,12 +161,14 @@ export class ShoppingCart {
159
161
  * 缓存的价格
160
162
  */
161
163
  this.prices = {};
162
- if (typeof currencyOrState === 'string') {
163
- this.currency = currencyOrState;
164
+ if (Array.isArray(currencyOrState)) {
165
+ this.currency = currencyOrState[0];
166
+ this.culture = currencyOrState[1];
164
167
  }
165
168
  else {
166
169
  this.setCartData(currencyOrState);
167
170
  this.currency = currencyOrState.currency;
171
+ this.culture = currencyOrState.culture;
168
172
  }
169
173
  this.symbol = NumberUtils.getCurrencySymbol(this.currency);
170
174
  }
@@ -258,9 +262,10 @@ export class ShoppingCart {
258
262
  save(persisted = true) {
259
263
  if (this.owner == null)
260
264
  return;
261
- const { currency, owner, items, promotions, formData } = this;
265
+ const { currency, culture, owner, items, promotions, formData } = this;
262
266
  const data = {
263
267
  currency,
268
+ culture,
264
269
  owner,
265
270
  items,
266
271
  promotions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.44",
3
+ "version": "1.4.46",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -53,7 +53,7 @@
53
53
  "homepage": "https://github.com/ETSOO/AppScript#readme",
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.28",
56
- "@etsoo/restclient": "^1.0.89",
56
+ "@etsoo/restclient": "^1.0.90",
57
57
  "@etsoo/shared": "^1.2.12",
58
58
  "crypto-js": "^4.1.1"
59
59
  },
@@ -65,8 +65,8 @@
65
65
  "@babel/runtime-corejs3": "^7.22.15",
66
66
  "@types/crypto-js": "^4.1.2",
67
67
  "@types/jest": "^29.5.4",
68
- "jest": "^29.6.4",
69
- "jest-environment-jsdom": "^29.6.4",
68
+ "jest": "^29.7.0",
69
+ "jest-environment-jsdom": "^29.7.0",
70
70
  "ts-jest": "^29.1.1",
71
71
  "typescript": "^5.2.2"
72
72
  }
@@ -1,4 +1,5 @@
1
1
  import { DataTypes, IStorage, NumberUtils, WindowStorage } from '@etsoo/shared';
2
+ import { Currency } from './Currency';
2
3
 
3
4
  /**
4
5
  * Shopping cart owner
@@ -6,6 +7,8 @@ import { DataTypes, IStorage, NumberUtils, WindowStorage } from '@etsoo/shared';
6
7
  */
7
8
  export type ShoppingCartOwner = DataTypes.IdNameItem & {
8
9
  isSupplier?: boolean;
10
+ culture?: string;
11
+ currency?: Currency;
9
12
  };
10
13
 
11
14
  /**
@@ -13,7 +16,8 @@ export type ShoppingCartOwner = DataTypes.IdNameItem & {
13
16
  * 购物篮数据
14
17
  */
15
18
  export type ShoppingCartData<T extends ShoppingCartItem> = {
16
- currency: string;
19
+ culture: string;
20
+ currency: Currency;
17
21
  owner: ShoppingCartOwner;
18
22
  items: T[];
19
23
  promotions: ShoppingPromotion[];
@@ -132,11 +136,12 @@ export class ShoppingCart<T extends ShoppingCartItem> {
132
136
  * Create identifier key
133
137
  * 创建识别键
134
138
  * @param currency Currency
139
+ * @param culture Culture
135
140
  * @param key Additional key
136
141
  * @returns Result
137
142
  */
138
- static createKey(currency: string, key: string = 'KEY') {
139
- return `ETSOO-CART-${key}-${currency}`;
143
+ static createKey(currency: Currency, culture: string, key: string = 'KEY') {
144
+ return `ETSOO-CART-${culture}-${key}-${currency}`;
140
145
  }
141
146
 
142
147
  /**
@@ -158,13 +163,15 @@ export class ShoppingCart<T extends ShoppingCartItem> {
158
163
  * Clear shopping cart
159
164
  * 清除购物篮
160
165
  * @param currency Currency
166
+ * @param culture Culture
161
167
  * @param storage Storage
162
168
  */
163
169
  static clearWith(
164
- currency: string,
170
+ currency: Currency,
171
+ culture: string,
165
172
  storage: IStorage = new WindowStorage()
166
173
  ) {
167
- const identifier = this.createKey(currency);
174
+ const identifier = this.createKey(currency, culture);
168
175
  this.clear(identifier, storage);
169
176
  }
170
177
 
@@ -213,7 +220,13 @@ export class ShoppingCart<T extends ShoppingCartItem> {
213
220
  * ISO currency id
214
221
  * 标准货币编号
215
222
  */
216
- readonly currency: string;
223
+ readonly currency: Currency;
224
+
225
+ /**
226
+ * ISO culture id, like zh-Hans
227
+ * 标准语言文化编号
228
+ */
229
+ readonly culture: string;
217
230
 
218
231
  _items: T[] = [];
219
232
 
@@ -260,6 +273,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
260
273
  const o = this.owner;
261
274
  return ShoppingCart.createKey(
262
275
  this.currency,
276
+ this.culture,
263
277
  o ? `${o.isSupplier ? 'S' : 'C'}${o.id}` : undefined
264
278
  );
265
279
  }
@@ -331,10 +345,10 @@ export class ShoppingCart<T extends ShoppingCartItem> {
331
345
  /**
332
346
  * Constructor
333
347
  * 构造函数
334
- * @param currency Currency ISO code
348
+ * @param init Currency & culture ISO code array
335
349
  * @param storage Data storage
336
350
  */
337
- constructor(currency: string, storage?: IStorage);
351
+ constructor(init: [Currency, string], storage?: IStorage);
338
352
 
339
353
  /**
340
354
  * Constructor
@@ -351,14 +365,16 @@ export class ShoppingCart<T extends ShoppingCartItem> {
351
365
  * @param storage Data storage
352
366
  */
353
367
  constructor(
354
- currencyOrState: string | ShoppingCartData<T>,
368
+ currencyOrState: [Currency, string] | ShoppingCartData<T>,
355
369
  private readonly storage: IStorage = new WindowStorage()
356
370
  ) {
357
- if (typeof currencyOrState === 'string') {
358
- this.currency = currencyOrState;
371
+ if (Array.isArray(currencyOrState)) {
372
+ this.currency = currencyOrState[0];
373
+ this.culture = currencyOrState[1];
359
374
  } else {
360
375
  this.setCartData(currencyOrState);
361
376
  this.currency = currencyOrState.currency;
377
+ this.culture = currencyOrState.culture;
362
378
  }
363
379
  this.symbol = NumberUtils.getCurrencySymbol(this.currency);
364
380
  }
@@ -463,9 +479,10 @@ export class ShoppingCart<T extends ShoppingCartItem> {
463
479
  save(persisted: boolean = true) {
464
480
  if (this.owner == null) return;
465
481
 
466
- const { currency, owner, items, promotions, formData } = this;
482
+ const { currency, culture, owner, items, promotions, formData } = this;
467
483
  const data: ShoppingCartData<T> = {
468
484
  currency,
485
+ culture,
469
486
  owner,
470
487
  items,
471
488
  promotions,