namirasoft-core 1.4.68 → 1.4.71
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/dist/StringOperation.d.ts +1 -0
- package/dist/StringOperation.js +3 -0
- package/dist/StringOperation.js.map +1 -1
- package/dist/TimeOperation.d.ts +1 -0
- package/dist/TimeOperation.js +3 -0
- package/dist/TimeOperation.js.map +1 -1
- package/package.json +27 -27
- package/src/BaseDatabaseRow.ts +6 -6
- package/src/BaseMetaColumn.ts +17 -17
- package/src/BaseMetaDatabase.ts +30 -30
- package/src/BaseMetaTable.ts +40 -40
- package/src/BaseServer.ts +112 -112
- package/src/BaseUUID.ts +61 -61
- package/src/CacheService.ts +75 -75
- package/src/ConsoleOperation.ts +68 -68
- package/src/ConvertService.ts +118 -118
- package/src/CookieService.ts +33 -33
- package/src/Countries.ts +486 -486
- package/src/Country.ts +21 -21
- package/src/CountryOperation.ts +98 -98
- package/src/EncodingOperation.ts +12 -12
- package/src/EncryptionOperation.ts +40 -40
- package/src/EnvService.ts +22 -22
- package/src/ErrorOperation.ts +13 -13
- package/src/FileOperation.ts +57 -57
- package/src/FilterItem.ts +117 -117
- package/src/FilterItemColumnType.ts +9 -9
- package/src/FilterItemOperator.ts +52 -52
- package/src/GeoOperation.ts +18 -18
- package/src/HTTPError.ts +8 -8
- package/src/HTTPMethod.ts +6 -6
- package/src/HashOperation.ts +24 -24
- package/src/IStorage.ts +5 -5
- package/src/IStorageCookie.ts +52 -52
- package/src/IStorageJsonFile.ts +45 -45
- package/src/IStorageLocal.ts +16 -16
- package/src/IStorageMemoryDedicated.ts +25 -25
- package/src/IStorageMemoryShared.ts +21 -21
- package/src/IStorageSession.ts +16 -16
- package/src/NamingConvention.ts +188 -188
- package/src/ObjectService.ts +27 -27
- package/src/PackageService.ts +76 -76
- package/src/PhoneOperation.ts +8 -8
- package/src/PriceOperation.ts +20 -20
- package/src/SearchOperation.ts +31 -31
- package/src/SetTimeouService.ts +33 -33
- package/src/SortItem.ts +88 -88
- package/src/StringOperation.ts +22 -18
- package/src/TimeOperation.ts +283 -278
- package/src/TimeUnitOperation.ts +39 -39
- package/src/URLOperation.ts +54 -54
- package/src/VersionOperation.ts +46 -46
- package/src/index.ts +45 -45
package/dist/StringOperation.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringOperation = void 0;
|
|
4
4
|
class StringOperation {
|
|
5
|
+
static split(text) {
|
|
6
|
+
return text.split(/[\s;,|]+/).filter(x => x);
|
|
7
|
+
}
|
|
5
8
|
static format(string, ...args) {
|
|
6
9
|
return string.replace(/{(\d+)}/g, (match, index) => {
|
|
7
10
|
const arg = args[index];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringOperation.js","sourceRoot":"","sources":["../src/StringOperation.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAe;IAExB,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,GAAG,IAAc;QAE3C,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAE/C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACxB,OAAO,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,KAAa;QAEvB,IAAI,KAAK,IAAI,IAAI;YACb,KAAK,GAAG,EAAE,CAAC;QACf,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACtC,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;
|
|
1
|
+
{"version":3,"file":"StringOperation.js","sourceRoot":"","sources":["../src/StringOperation.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAe;IAExB,MAAM,CAAC,KAAK,CAAC,IAAY;QAErB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,GAAG,IAAc;QAE3C,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAE/C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACxB,OAAO,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,KAAa;QAEvB,IAAI,KAAK,IAAI,IAAI;YACb,KAAK,GAAG,EAAE,CAAC;QACf,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACtC,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAtBD,0CAsBC"}
|
package/dist/TimeOperation.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type DateInterval = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare class TimeOperation {
|
|
12
12
|
static toDBFormat(date: Date): string;
|
|
13
|
+
static format(date: Date, format: string): string;
|
|
13
14
|
static toDate(year: number, month: number, day: number): Date;
|
|
14
15
|
static toDateByWeek(year: number, week: number, firstDay: number): Date;
|
|
15
16
|
static fromDate(date: Date): YMD;
|
package/dist/TimeOperation.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeOperation.js","sourceRoot":"","sources":["../src/TimeOperation.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;
|
|
1
|
+
{"version":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AAM,CAAC;QAEhB,OAAO;YACH,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK;SACxD,CAAC;IACN,CAAC;IACD,MAAM,CAAC,YAAY,CAAC,IAAU;QAE1B,IAAI,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC/C,IAAI,OAAO,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,CAAC,WAAW,CAAC,KAAa;QAE5B,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,CAAC,eAAe,CAAC,KAAa;QAEhC,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,CAAC,WAAW,CAAC,KAAa;QAE5B,OAAO,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;CACJ;AAtRD,sCAsRC"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "namirasoft-core",
|
|
3
|
-
"title": "Namirasoft Core NPM Package",
|
|
4
|
-
"description": "Namira Software Corporation Core NPM Package",
|
|
5
|
-
"icon": "logo.png",
|
|
6
|
-
"logo": "https://static.namirasoft.com/image/namirasoft/site/logo/base.png",
|
|
7
|
-
"language": "ts",
|
|
8
|
-
"framework": "npm",
|
|
9
|
-
"application": "package",
|
|
10
|
-
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
12
|
-
"author": "Amir Abolhasani",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"main": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": ""
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@types/node": "^22.14.1",
|
|
21
|
-
"async-mutex": "^0.5.0",
|
|
22
|
-
"axios": "^1.8.4",
|
|
23
|
-
"buffer": "^6.0.3",
|
|
24
|
-
"moment": "^2.30.1",
|
|
25
|
-
"phone": "^3.1.
|
|
26
|
-
"uuid": "^11.1.0"
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "namirasoft-core",
|
|
3
|
+
"title": "Namirasoft Core NPM Package",
|
|
4
|
+
"description": "Namira Software Corporation Core NPM Package",
|
|
5
|
+
"icon": "logo.png",
|
|
6
|
+
"logo": "https://static.namirasoft.com/image/namirasoft/site/logo/base.png",
|
|
7
|
+
"language": "ts",
|
|
8
|
+
"framework": "npm",
|
|
9
|
+
"application": "package",
|
|
10
|
+
"private": false,
|
|
11
|
+
"version": "1.4.71",
|
|
12
|
+
"author": "Amir Abolhasani",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": ""
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@types/node": "^22.14.1",
|
|
21
|
+
"async-mutex": "^0.5.0",
|
|
22
|
+
"axios": "^1.8.4",
|
|
23
|
+
"buffer": "^6.0.3",
|
|
24
|
+
"moment": "^2.30.1",
|
|
25
|
+
"phone": "^3.1.59",
|
|
26
|
+
"uuid": "^11.1.0"
|
|
27
|
+
}
|
|
28
28
|
}
|
package/src/BaseDatabaseRow.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type BaseDatabaseRow<ID> =
|
|
2
|
-
{
|
|
3
|
-
id: ID;
|
|
4
|
-
createdAt: string;
|
|
5
|
-
updatedAt: string;
|
|
6
|
-
deletedAt: string;
|
|
1
|
+
export type BaseDatabaseRow<ID> =
|
|
2
|
+
{
|
|
3
|
+
id: ID;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
deletedAt: string;
|
|
7
7
|
}
|
package/src/BaseMetaColumn.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BaseMetaTable } from "./BaseMetaTable";
|
|
2
|
-
|
|
3
|
-
export class BaseMetaColumn
|
|
4
|
-
{
|
|
5
|
-
table: BaseMetaTable;
|
|
6
|
-
name: string;
|
|
7
|
-
text: string;
|
|
8
|
-
type: string; // todo
|
|
9
|
-
required: boolean;
|
|
10
|
-
constructor(table: BaseMetaTable, name: string, text: string, type: string, required: boolean)
|
|
11
|
-
{
|
|
12
|
-
this.table = table;
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.text = text;
|
|
15
|
-
this.type = type;
|
|
16
|
-
this.required = required;
|
|
17
|
-
}
|
|
1
|
+
import { BaseMetaTable } from "./BaseMetaTable";
|
|
2
|
+
|
|
3
|
+
export class BaseMetaColumn
|
|
4
|
+
{
|
|
5
|
+
table: BaseMetaTable;
|
|
6
|
+
name: string;
|
|
7
|
+
text: string;
|
|
8
|
+
type: string; // todo
|
|
9
|
+
required: boolean;
|
|
10
|
+
constructor(table: BaseMetaTable, name: string, text: string, type: string, required: boolean)
|
|
11
|
+
{
|
|
12
|
+
this.table = table;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.text = text;
|
|
15
|
+
this.type = type;
|
|
16
|
+
this.required = required;
|
|
17
|
+
}
|
|
18
18
|
}
|
package/src/BaseMetaDatabase.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { BaseMetaTable } from "./BaseMetaTable";
|
|
2
|
-
|
|
3
|
-
export abstract class BaseMetaDatabase
|
|
4
|
-
{
|
|
5
|
-
public tables: { [name: string]: BaseMetaTable } = {};
|
|
6
|
-
forEachTable<T, MT extends BaseMetaTable>(handler: (table: MT) => T | null): T | null
|
|
7
|
-
{
|
|
8
|
-
for (const key in this.tables)
|
|
9
|
-
{
|
|
10
|
-
const element = this.tables[key];
|
|
11
|
-
let ans = handler(element as MT);
|
|
12
|
-
if (ans != null)
|
|
13
|
-
return ans;
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
getTables<MT extends BaseMetaTable>(): MT[]
|
|
18
|
-
{
|
|
19
|
-
let ans: MT[] = [];
|
|
20
|
-
this.forEachTable((table) =>
|
|
21
|
-
{
|
|
22
|
-
ans.push(table as MT);
|
|
23
|
-
return null;
|
|
24
|
-
});
|
|
25
|
-
return ans;
|
|
26
|
-
}
|
|
27
|
-
hasTable(name: string): boolean
|
|
28
|
-
{
|
|
29
|
-
return this.tables[name] != null;
|
|
30
|
-
}
|
|
1
|
+
import { BaseMetaTable } from "./BaseMetaTable";
|
|
2
|
+
|
|
3
|
+
export abstract class BaseMetaDatabase
|
|
4
|
+
{
|
|
5
|
+
public tables: { [name: string]: BaseMetaTable } = {};
|
|
6
|
+
forEachTable<T, MT extends BaseMetaTable>(handler: (table: MT) => T | null): T | null
|
|
7
|
+
{
|
|
8
|
+
for (const key in this.tables)
|
|
9
|
+
{
|
|
10
|
+
const element = this.tables[key];
|
|
11
|
+
let ans = handler(element as MT);
|
|
12
|
+
if (ans != null)
|
|
13
|
+
return ans;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
getTables<MT extends BaseMetaTable>(): MT[]
|
|
18
|
+
{
|
|
19
|
+
let ans: MT[] = [];
|
|
20
|
+
this.forEachTable((table) =>
|
|
21
|
+
{
|
|
22
|
+
ans.push(table as MT);
|
|
23
|
+
return null;
|
|
24
|
+
});
|
|
25
|
+
return ans;
|
|
26
|
+
}
|
|
27
|
+
hasTable(name: string): boolean
|
|
28
|
+
{
|
|
29
|
+
return this.tables[name] != null;
|
|
30
|
+
}
|
|
31
31
|
};
|
package/src/BaseMetaTable.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
-
import { BaseMetaDatabase } from "./BaseMetaDatabase";
|
|
3
|
-
|
|
4
|
-
export class BaseMetaTable
|
|
5
|
-
{
|
|
6
|
-
database: BaseMetaDatabase | null;
|
|
7
|
-
name: string;
|
|
8
|
-
text: string;
|
|
9
|
-
public columns: { [name: string]: BaseMetaColumn } = {};
|
|
10
|
-
constructor(database: BaseMetaDatabase | null, name: string, text: string)
|
|
11
|
-
{
|
|
12
|
-
this.database = database;
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.text = text;
|
|
15
|
-
}
|
|
16
|
-
forEachColumn<T, MC extends BaseMetaColumn>(handler: (column: MC) => T | null): T | null
|
|
17
|
-
{
|
|
18
|
-
for (const key in this.columns)
|
|
19
|
-
{
|
|
20
|
-
const element = this.columns[key];
|
|
21
|
-
let ans = handler(element as MC);
|
|
22
|
-
if (ans != null)
|
|
23
|
-
return ans;
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
getColumns<MC extends BaseMetaColumn>(): MC[]
|
|
28
|
-
{
|
|
29
|
-
let ans: MC[] = [];
|
|
30
|
-
this.forEachColumn((column) =>
|
|
31
|
-
{
|
|
32
|
-
ans.push(column as MC);
|
|
33
|
-
return null;
|
|
34
|
-
});
|
|
35
|
-
return ans;
|
|
36
|
-
}
|
|
37
|
-
hasColumn(name: string): boolean
|
|
38
|
-
{
|
|
39
|
-
return this.columns[name] != null;
|
|
40
|
-
}
|
|
1
|
+
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
+
import { BaseMetaDatabase } from "./BaseMetaDatabase";
|
|
3
|
+
|
|
4
|
+
export class BaseMetaTable
|
|
5
|
+
{
|
|
6
|
+
database: BaseMetaDatabase | null;
|
|
7
|
+
name: string;
|
|
8
|
+
text: string;
|
|
9
|
+
public columns: { [name: string]: BaseMetaColumn } = {};
|
|
10
|
+
constructor(database: BaseMetaDatabase | null, name: string, text: string)
|
|
11
|
+
{
|
|
12
|
+
this.database = database;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.text = text;
|
|
15
|
+
}
|
|
16
|
+
forEachColumn<T, MC extends BaseMetaColumn>(handler: (column: MC) => T | null): T | null
|
|
17
|
+
{
|
|
18
|
+
for (const key in this.columns)
|
|
19
|
+
{
|
|
20
|
+
const element = this.columns[key];
|
|
21
|
+
let ans = handler(element as MC);
|
|
22
|
+
if (ans != null)
|
|
23
|
+
return ans;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
getColumns<MC extends BaseMetaColumn>(): MC[]
|
|
28
|
+
{
|
|
29
|
+
let ans: MC[] = [];
|
|
30
|
+
this.forEachColumn((column) =>
|
|
31
|
+
{
|
|
32
|
+
ans.push(column as MC);
|
|
33
|
+
return null;
|
|
34
|
+
});
|
|
35
|
+
return ans;
|
|
36
|
+
}
|
|
37
|
+
hasColumn(name: string): boolean
|
|
38
|
+
{
|
|
39
|
+
return this.columns[name] != null;
|
|
40
|
+
}
|
|
41
41
|
}
|
package/src/BaseServer.ts
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
-
import { HashOperation } from "./HashOperation";
|
|
3
|
-
import { URLOperation } from "./URLOperation";
|
|
4
|
-
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
-
import { ParsedNameValue } from "./ParsedNameValue";
|
|
6
|
-
import { ConsoleOperation } from "./ConsoleOperation";
|
|
7
|
-
import { EnvService } from "./EnvService";
|
|
8
|
-
|
|
9
|
-
export abstract class BaseServer
|
|
10
|
-
{
|
|
11
|
-
protected base_url: string;
|
|
12
|
-
private onBeforeRequests: ((url: string, config?: AxiosRequestConfig) => void)[] = [];
|
|
13
|
-
private onAfterRequests: ((url: string, res: AxiosResponse) => void)[] = [];
|
|
14
|
-
protected abstract onError(error: Error): void;
|
|
15
|
-
public suppressErrors: boolean = false;
|
|
16
|
-
public suppressOnErrors: boolean = false;
|
|
17
|
-
|
|
18
|
-
constructor(base_url: string)
|
|
19
|
-
{
|
|
20
|
-
this.base_url = base_url;
|
|
21
|
-
}
|
|
22
|
-
public addOnBeforeRequest(onBeforeRequest: (url: string, config?: AxiosRequestConfig) => void)
|
|
23
|
-
{
|
|
24
|
-
this.onBeforeRequests.push(onBeforeRequest);
|
|
25
|
-
}
|
|
26
|
-
public addOnAfterRequest(onAfterRequest: (url: string, res: AxiosResponse) => void)
|
|
27
|
-
{
|
|
28
|
-
this.onAfterRequests.push(onAfterRequest);
|
|
29
|
-
}
|
|
30
|
-
private async _request<ResData = any, ReqData = any>(onRequest: (url: string, data?: any, config?: AxiosRequestConfig<ReqData>) => Promise<AxiosResponse<ResData>>, sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
31
|
-
{
|
|
32
|
-
let url: string = URLOperation.getLink(this.base_url, sub, query);
|
|
33
|
-
if (!config)
|
|
34
|
-
config = { headers: {} };
|
|
35
|
-
if (sign_header)
|
|
36
|
-
if (sign_key)
|
|
37
|
-
if (data)
|
|
38
|
-
if (config?.headers)
|
|
39
|
-
config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
|
|
40
|
-
try
|
|
41
|
-
{
|
|
42
|
-
this.onBeforeRequests.forEach(onBeforeRequest =>
|
|
43
|
-
{
|
|
44
|
-
onBeforeRequest(url, config);
|
|
45
|
-
});
|
|
46
|
-
let response: AxiosResponse<ResData> = await onRequest(url, data, config);
|
|
47
|
-
this.onAfterRequests.forEach(onAfterRequest =>
|
|
48
|
-
{
|
|
49
|
-
onAfterRequest(url, response);
|
|
50
|
-
});
|
|
51
|
-
return { response, data: response.data };
|
|
52
|
-
} catch (error)
|
|
53
|
-
{
|
|
54
|
-
if (error instanceof Error)
|
|
55
|
-
{
|
|
56
|
-
let BASESERVER_ERROR_VERBOSE = new EnvService("BASESERVER_ERROR_VERBOSE", false).getBoolean(false);
|
|
57
|
-
|
|
58
|
-
if (this.onError)
|
|
59
|
-
{
|
|
60
|
-
if (BASESERVER_ERROR_VERBOSE)
|
|
61
|
-
error.message = `Error calling url '${url}' ` + error.message;
|
|
62
|
-
if (!this.suppressOnErrors)
|
|
63
|
-
this.onError(error);
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
{
|
|
67
|
-
ConsoleOperation.warning("onError function has not been properly set.");
|
|
68
|
-
ConsoleOperation.error(error?.message);
|
|
69
|
-
}
|
|
70
|
-
if (axios.isAxiosError(error))
|
|
71
|
-
if (error?.response?.data)
|
|
72
|
-
if (!this.suppressErrors)
|
|
73
|
-
{
|
|
74
|
-
if (BASESERVER_ERROR_VERBOSE)
|
|
75
|
-
ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
|
|
76
|
-
else
|
|
77
|
-
ErrorOperation.throwHTTP(error.response.status, JSON.stringify(error.response.data));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (!this.suppressErrors)
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
return {} as any;
|
|
84
|
-
}
|
|
85
|
-
public async _get<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
86
|
-
{
|
|
87
|
-
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
88
|
-
{
|
|
89
|
-
return await axios.get(url, config);
|
|
90
|
-
}, sub, query, undefined, config);
|
|
91
|
-
}
|
|
92
|
-
public async _post<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
93
|
-
{
|
|
94
|
-
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
95
|
-
{
|
|
96
|
-
return await axios.post(url, data, config);
|
|
97
|
-
}, sub, query, data, config, sign_header, sign_key);
|
|
98
|
-
}
|
|
99
|
-
public async _put<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
100
|
-
{
|
|
101
|
-
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
102
|
-
{
|
|
103
|
-
return await axios.put(url, data, config);
|
|
104
|
-
}, sub, query, data, config, sign_header, sign_key);
|
|
105
|
-
}
|
|
106
|
-
public async _delete<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
107
|
-
{
|
|
108
|
-
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
109
|
-
{
|
|
110
|
-
return await axios.delete(url, config);
|
|
111
|
-
}, sub, query, undefined, config, sign_header, sign_key);
|
|
112
|
-
}
|
|
1
|
+
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
import { HashOperation } from "./HashOperation";
|
|
3
|
+
import { URLOperation } from "./URLOperation";
|
|
4
|
+
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
+
import { ParsedNameValue } from "./ParsedNameValue";
|
|
6
|
+
import { ConsoleOperation } from "./ConsoleOperation";
|
|
7
|
+
import { EnvService } from "./EnvService";
|
|
8
|
+
|
|
9
|
+
export abstract class BaseServer
|
|
10
|
+
{
|
|
11
|
+
protected base_url: string;
|
|
12
|
+
private onBeforeRequests: ((url: string, config?: AxiosRequestConfig) => void)[] = [];
|
|
13
|
+
private onAfterRequests: ((url: string, res: AxiosResponse) => void)[] = [];
|
|
14
|
+
protected abstract onError(error: Error): void;
|
|
15
|
+
public suppressErrors: boolean = false;
|
|
16
|
+
public suppressOnErrors: boolean = false;
|
|
17
|
+
|
|
18
|
+
constructor(base_url: string)
|
|
19
|
+
{
|
|
20
|
+
this.base_url = base_url;
|
|
21
|
+
}
|
|
22
|
+
public addOnBeforeRequest(onBeforeRequest: (url: string, config?: AxiosRequestConfig) => void)
|
|
23
|
+
{
|
|
24
|
+
this.onBeforeRequests.push(onBeforeRequest);
|
|
25
|
+
}
|
|
26
|
+
public addOnAfterRequest(onAfterRequest: (url: string, res: AxiosResponse) => void)
|
|
27
|
+
{
|
|
28
|
+
this.onAfterRequests.push(onAfterRequest);
|
|
29
|
+
}
|
|
30
|
+
private async _request<ResData = any, ReqData = any>(onRequest: (url: string, data?: any, config?: AxiosRequestConfig<ReqData>) => Promise<AxiosResponse<ResData>>, sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
31
|
+
{
|
|
32
|
+
let url: string = URLOperation.getLink(this.base_url, sub, query);
|
|
33
|
+
if (!config)
|
|
34
|
+
config = { headers: {} };
|
|
35
|
+
if (sign_header)
|
|
36
|
+
if (sign_key)
|
|
37
|
+
if (data)
|
|
38
|
+
if (config?.headers)
|
|
39
|
+
config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
|
|
40
|
+
try
|
|
41
|
+
{
|
|
42
|
+
this.onBeforeRequests.forEach(onBeforeRequest =>
|
|
43
|
+
{
|
|
44
|
+
onBeforeRequest(url, config);
|
|
45
|
+
});
|
|
46
|
+
let response: AxiosResponse<ResData> = await onRequest(url, data, config);
|
|
47
|
+
this.onAfterRequests.forEach(onAfterRequest =>
|
|
48
|
+
{
|
|
49
|
+
onAfterRequest(url, response);
|
|
50
|
+
});
|
|
51
|
+
return { response, data: response.data };
|
|
52
|
+
} catch (error)
|
|
53
|
+
{
|
|
54
|
+
if (error instanceof Error)
|
|
55
|
+
{
|
|
56
|
+
let BASESERVER_ERROR_VERBOSE = new EnvService("BASESERVER_ERROR_VERBOSE", false).getBoolean(false);
|
|
57
|
+
|
|
58
|
+
if (this.onError)
|
|
59
|
+
{
|
|
60
|
+
if (BASESERVER_ERROR_VERBOSE)
|
|
61
|
+
error.message = `Error calling url '${url}' ` + error.message;
|
|
62
|
+
if (!this.suppressOnErrors)
|
|
63
|
+
this.onError(error);
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
ConsoleOperation.warning("onError function has not been properly set.");
|
|
68
|
+
ConsoleOperation.error(error?.message);
|
|
69
|
+
}
|
|
70
|
+
if (axios.isAxiosError(error))
|
|
71
|
+
if (error?.response?.data)
|
|
72
|
+
if (!this.suppressErrors)
|
|
73
|
+
{
|
|
74
|
+
if (BASESERVER_ERROR_VERBOSE)
|
|
75
|
+
ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
|
|
76
|
+
else
|
|
77
|
+
ErrorOperation.throwHTTP(error.response.status, JSON.stringify(error.response.data));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!this.suppressErrors)
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
return {} as any;
|
|
84
|
+
}
|
|
85
|
+
public async _get<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
86
|
+
{
|
|
87
|
+
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
88
|
+
{
|
|
89
|
+
return await axios.get(url, config);
|
|
90
|
+
}, sub, query, undefined, config);
|
|
91
|
+
}
|
|
92
|
+
public async _post<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
93
|
+
{
|
|
94
|
+
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
95
|
+
{
|
|
96
|
+
return await axios.post(url, data, config);
|
|
97
|
+
}, sub, query, data, config, sign_header, sign_key);
|
|
98
|
+
}
|
|
99
|
+
public async _put<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
100
|
+
{
|
|
101
|
+
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
102
|
+
{
|
|
103
|
+
return await axios.put(url, data, config);
|
|
104
|
+
}, sub, query, data, config, sign_header, sign_key);
|
|
105
|
+
}
|
|
106
|
+
public async _delete<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
107
|
+
{
|
|
108
|
+
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
109
|
+
{
|
|
110
|
+
return await axios.delete(url, config);
|
|
111
|
+
}, sub, query, undefined, config, sign_header, sign_key);
|
|
112
|
+
}
|
|
113
113
|
}
|