@etsoo/appscript 1.3.19 → 1.3.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.
@@ -219,9 +219,13 @@ test('Tests for publicApi', async () => {
219
219
  const options = app.publicApi.repeatOptions(['MONTH', 'QUATER', 'YEAR']);
220
220
  expect(options[2]).toStrictEqual({ id: 12, label: '每年' });
221
221
 
222
- const currencies = await app.publicApi.currencies(['NZD', 'AUD', 'USD']);
222
+ const currencies = app.publicApi.currencies(['NZD', 'AUD', 'USD']);
223
+ expect(currencies.length).toBe(3);
223
224
  expect(currencies[1].id).toBe('AUD');
224
225
 
226
+ const currencies1 = app.publicApi.currencies(true);
227
+ expect(currencies1.length >= 10).toBeTruthy();
228
+
225
229
  /*
226
230
  const orgs = await app.orgApi.list();
227
231
  console.log(orgs);
@@ -16,7 +16,8 @@ export declare class PublicApi extends BaseApi {
16
16
  * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
17
17
  * @returns Result
18
18
  */
19
- currencies<T extends string[] | Currency[] | undefined>(currencyNames?: T): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]>;
19
+ currencies(): Promise<CurrencyDto[] | undefined>;
20
+ currencies(names: string[] | Currency[] | boolean): ListType1[];
20
21
  /**
21
22
  * Get exchange rate
22
23
  * @param currency Currency
@@ -55,7 +56,7 @@ export declare class PublicApi extends BaseApi {
55
56
  * @param payload Payload
56
57
  * @returns Result
57
58
  */
58
- product<T extends number | string>(id: T, culture?: string, payload?: IApiPayload<PublicProductDto>): Promise<(T extends number ? PublicProductDto : PublicOrgProductDto) | undefined>;
59
+ product<T extends number | string>(id: T, culture?: string, payload?: IApiPayload<T extends number ? PublicProductDto : PublicOrgProductDto>): Promise<(T extends number ? PublicProductDto : PublicOrgProductDto) | undefined>;
59
60
  /**
60
61
  *
61
62
  * Get all repeat options
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PublicApi = void 0;
4
4
  const shared_1 = require("@etsoo/shared");
5
+ const Currency_1 = require("../business/Currency");
5
6
  const ProductUnit_1 = require("../business/ProductUnit");
6
7
  const RepeatOption_1 = require("../business/RepeatOption");
7
8
  const BaseApi_1 = require("./BaseApi");
@@ -9,22 +10,29 @@ const BaseApi_1 = require("./BaseApi");
9
10
  * Public API
10
11
  */
11
12
  class PublicApi extends BaseApi_1.BaseApi {
12
- /**
13
- * Get currencies
14
- * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
15
- * @returns Result
16
- */
17
- async currencies(currencyNames) {
18
- if (currencyNames == null)
19
- return (await this.api.get('Public/GetCurrencies', undefined, { defaultValue: [], showLoading: false }));
20
- else
21
- return currencyNames.map((name) => {
13
+ currencies(names) {
14
+ if (typeof names === 'boolean' && names) {
15
+ return Currency_1.Currencies.map((name) => {
16
+ var _a;
17
+ return ({
18
+ id: name,
19
+ label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
20
+ });
21
+ });
22
+ }
23
+ if (Array.isArray(names)) {
24
+ return names.map((name) => {
22
25
  var _a;
23
26
  return ({
24
27
  id: name,
25
28
  label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
26
29
  });
27
30
  });
31
+ }
32
+ return this.api.get('Public/GetCurrencies', undefined, {
33
+ defaultValue: [],
34
+ showLoading: false
35
+ });
28
36
  }
29
37
  /**
30
38
  * Get exchange rate
@@ -80,6 +88,7 @@ class PublicApi extends BaseApi_1.BaseApi {
80
88
  mobileQRCode(id, host, payload) {
81
89
  return this.api.post('Public/MobileQRCode', { id, host }, payload);
82
90
  }
91
+ //product(id: number, culture?: string, ): Promise<PublicProductDto | undefined>;
83
92
  /**
84
93
  * Get public and valid product data
85
94
  * @param id Product/Service Id or Uid
@@ -16,7 +16,8 @@ export declare class PublicApi extends BaseApi {
16
16
  * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
17
17
  * @returns Result
18
18
  */
19
- currencies<T extends string[] | Currency[] | undefined>(currencyNames?: T): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]>;
19
+ currencies(): Promise<CurrencyDto[] | undefined>;
20
+ currencies(names: string[] | Currency[] | boolean): ListType1[];
20
21
  /**
21
22
  * Get exchange rate
22
23
  * @param currency Currency
@@ -55,7 +56,7 @@ export declare class PublicApi extends BaseApi {
55
56
  * @param payload Payload
56
57
  * @returns Result
57
58
  */
58
- product<T extends number | string>(id: T, culture?: string, payload?: IApiPayload<PublicProductDto>): Promise<(T extends number ? PublicProductDto : PublicOrgProductDto) | undefined>;
59
+ product<T extends number | string>(id: T, culture?: string, payload?: IApiPayload<T extends number ? PublicProductDto : PublicOrgProductDto>): Promise<(T extends number ? PublicProductDto : PublicOrgProductDto) | undefined>;
59
60
  /**
60
61
  *
61
62
  * Get all repeat options
@@ -1,4 +1,5 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
+ import { Currencies } from '../business/Currency';
2
3
  import { ProductUnit } from '../business/ProductUnit';
3
4
  import { RepeatOption } from '../business/RepeatOption';
4
5
  import { BaseApi } from './BaseApi';
@@ -6,22 +7,29 @@ import { BaseApi } from './BaseApi';
6
7
  * Public API
7
8
  */
8
9
  export class PublicApi extends BaseApi {
9
- /**
10
- * Get currencies
11
- * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
12
- * @returns Result
13
- */
14
- async currencies(currencyNames) {
15
- if (currencyNames == null)
16
- return (await this.api.get('Public/GetCurrencies', undefined, { defaultValue: [], showLoading: false }));
17
- else
18
- return currencyNames.map((name) => {
10
+ currencies(names) {
11
+ if (typeof names === 'boolean' && names) {
12
+ return Currencies.map((name) => {
13
+ var _a;
14
+ return ({
15
+ id: name,
16
+ label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
17
+ });
18
+ });
19
+ }
20
+ if (Array.isArray(names)) {
21
+ return names.map((name) => {
19
22
  var _a;
20
23
  return ({
21
24
  id: name,
22
25
  label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
23
26
  });
24
27
  });
28
+ }
29
+ return this.api.get('Public/GetCurrencies', undefined, {
30
+ defaultValue: [],
31
+ showLoading: false
32
+ });
25
33
  }
26
34
  /**
27
35
  * Get exchange rate
@@ -77,6 +85,7 @@ export class PublicApi extends BaseApi {
77
85
  mobileQRCode(id, host, payload) {
78
86
  return this.api.post('Public/MobileQRCode', { id, host }, payload);
79
87
  }
88
+ //product(id: number, culture?: string, ): Promise<PublicProductDto | undefined>;
80
89
  /**
81
90
  * Get public and valid product data
82
91
  * @param id Product/Service Id or Uid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.19",
3
+ "version": "1.3.20",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -67,7 +67,7 @@
67
67
  "@types/jest": "^29.2.0",
68
68
  "@typescript-eslint/eslint-plugin": "^5.40.1",
69
69
  "@typescript-eslint/parser": "^5.40.1",
70
- "eslint": "^8.25.0",
70
+ "eslint": "^8.26.0",
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.26.0",
73
73
  "jest": "^29.2.1",
@@ -1,6 +1,6 @@
1
1
  import { IApiPayload } from '@etsoo/restclient';
2
2
  import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
3
- import { Currency } from '../business/Currency';
3
+ import { Currencies, Currency } from '../business/Currency';
4
4
  import { ProductUnit } from '../business/ProductUnit';
5
5
  import { RepeatOption } from '../business/RepeatOption';
6
6
  import { BaseApi } from './BaseApi';
@@ -18,20 +18,27 @@ export class PublicApi extends BaseApi {
18
18
  * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
19
19
  * @returns Result
20
20
  */
21
- async currencies<T extends string[] | Currency[] | undefined>(
22
- currencyNames?: T
23
- ): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]> {
24
- if (currencyNames == null)
25
- return (await this.api.get<CurrencyDto[]>(
26
- 'Public/GetCurrencies',
27
- undefined,
28
- { defaultValue: [], showLoading: false }
29
- )) as any;
30
- else
31
- return currencyNames.map((name) => ({
21
+ currencies(): Promise<CurrencyDto[] | undefined>;
22
+ currencies(names: string[] | Currency[] | boolean): ListType1[];
23
+ currencies(names?: string[] | Currency[] | boolean) {
24
+ if (typeof names === 'boolean' && names) {
25
+ return Currencies.map((name) => ({
32
26
  id: name,
33
27
  label: this.app.get(`currency${name}`) ?? name
34
- })) as any;
28
+ }));
29
+ }
30
+
31
+ if (Array.isArray(names)) {
32
+ return names.map((name) => ({
33
+ id: name,
34
+ label: this.app.get(`currency${name}`) ?? name
35
+ }));
36
+ }
37
+
38
+ return this.api.get<CurrencyDto[]>('Public/GetCurrencies', undefined, {
39
+ defaultValue: [],
40
+ showLoading: false
41
+ });
35
42
  }
36
43
 
37
44
  /**
@@ -106,6 +113,8 @@ export class PublicApi extends BaseApi {
106
113
  return this.api.post('Public/MobileQRCode', { id, host }, payload);
107
114
  }
108
115
 
116
+ //product(id: number, culture?: string, ): Promise<PublicProductDto | undefined>;
117
+
109
118
  /**
110
119
  * Get public and valid product data
111
120
  * @param id Product/Service Id or Uid
@@ -116,16 +125,16 @@ export class PublicApi extends BaseApi {
116
125
  product<T extends number | string>(
117
126
  id: T,
118
127
  culture?: string,
119
- payload?: IApiPayload<PublicProductDto>
120
- ): Promise<
121
- (T extends number ? PublicProductDto : PublicOrgProductDto) | undefined
122
- > {
128
+ payload?: IApiPayload<
129
+ T extends number ? PublicProductDto : PublicOrgProductDto
130
+ >
131
+ ) {
123
132
  culture = this.app.checkLanguage(culture);
124
133
  return this.api.get(
125
134
  `Public/Product/${id}/${culture}`,
126
135
  undefined,
127
136
  payload
128
- ) as any;
137
+ );
129
138
  }
130
139
 
131
140
  /**