@nu-art/thunderstorm-shared 0.400.5
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/BaseHttpModule.d.ts +28 -0
- package/BaseHttpModule.js +56 -0
- package/BaseHttpRequest.d.ts +70 -0
- package/BaseHttpRequest.js +261 -0
- package/_entity/app-config/api-def.d.ts +10 -0
- package/_entity/app-config/api-def.js +6 -0
- package/_entity/app-config/db-def.d.ts +3 -0
- package/_entity/app-config/db-def.js +20 -0
- package/_entity/app-config/index.d.ts +3 -0
- package/_entity/app-config/index.js +4 -0
- package/_entity/app-config/types.d.ts +16 -0
- package/_entity/app-config/types.js +1 -0
- package/_entity/backup-doc/api-def.d.ts +17 -0
- package/_entity/backup-doc/api-def.js +7 -0
- package/_entity/backup-doc/db-def.d.ts +3 -0
- package/_entity/backup-doc/db-def.js +30 -0
- package/_entity/backup-doc/index.d.ts +3 -0
- package/_entity/backup-doc/index.js +4 -0
- package/_entity/backup-doc/types.d.ts +45 -0
- package/_entity/backup-doc/types.js +1 -0
- package/_entity/deleted-doc/api-def.d.ts +7 -0
- package/_entity/deleted-doc/api-def.js +3 -0
- package/_entity/deleted-doc/db-def.d.ts +3 -0
- package/_entity/deleted-doc/db-def.js +20 -0
- package/_entity/deleted-doc/index.d.ts +3 -0
- package/_entity/deleted-doc/index.js +4 -0
- package/_entity/deleted-doc/types.d.ts +17 -0
- package/_entity/deleted-doc/types.js +1 -0
- package/_entity/editable-test/api-def.d.ts +7 -0
- package/_entity/editable-test/api-def.js +3 -0
- package/_entity/editable-test/db-def.d.ts +3 -0
- package/_entity/editable-test/db-def.js +24 -0
- package/_entity/editable-test/index.d.ts +3 -0
- package/_entity/editable-test/index.js +4 -0
- package/_entity/editable-test/types.d.ts +18 -0
- package/_entity/editable-test/types.js +1 -0
- package/_entity.d.ts +4 -0
- package/_entity.js +4 -0
- package/action-processor/apis.d.ts +17 -0
- package/action-processor/apis.js +8 -0
- package/action-processor/index.d.ts +1 -0
- package/action-processor/index.js +1 -0
- package/archiving/apis.d.ts +22 -0
- package/archiving/apis.js +8 -0
- package/archiving/index.d.ts +1 -0
- package/archiving/index.js +1 -0
- package/base64-tools.d.ts +3 -0
- package/base64-tools.js +30 -0
- package/collection-actions/api-def.d.ts +39 -0
- package/collection-actions/api-def.js +10 -0
- package/collection-actions/index.d.ts +2 -0
- package/collection-actions/index.js +2 -0
- package/collection-actions/types.d.ts +13 -0
- package/collection-actions/types.js +1 -0
- package/consts.d.ts +12 -0
- package/consts.js +41 -0
- package/db-api-gen/apiV1.d.ts +42 -0
- package/db-api-gen/apiV1.js +51 -0
- package/db-api-gen/apiV2.d.ts +42 -0
- package/db-api-gen/apiV2.js +51 -0
- package/db-api-gen/apiV3.d.ts +42 -0
- package/db-api-gen/apiV3.js +51 -0
- package/force-upgrade.d.ts +16 -0
- package/force-upgrade.js +33 -0
- package/headers.d.ts +10 -0
- package/headers.js +10 -0
- package/index.d.ts +15 -0
- package/index.js +36 -0
- package/no-auth-listener.d.ts +6 -0
- package/no-auth-listener.js +2 -0
- package/package.json +101 -0
- package/request-types.d.ts +16 -0
- package/request-types.js +30 -0
- package/route-tools.d.ts +1 -0
- package/route-tools.js +3 -0
- package/server-info/api.d.ts +15 -0
- package/server-info/api.js +7 -0
- package/server-info/consts.d.ts +7 -0
- package/server-info/consts.js +18 -0
- package/server-info/index.d.ts +3 -0
- package/server-info/index.js +3 -0
- package/server-info/types.d.ts +6 -0
- package/server-info/types.js +1 -0
- package/sync-env/apis.d.ts +40 -0
- package/sync-env/apis.js +12 -0
- package/sync-env/index.d.ts +1 -0
- package/sync-env/index.js +1 -0
- package/sync-manager/apis.d.ts +16 -0
- package/sync-manager/apis.js +7 -0
- package/sync-manager/types.d.ts +27 -0
- package/sync-manager/types.js +3 -0
- package/types.d.ts +79 -0
- package/types.js +31 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApiDef, TypedApi } from './types.js';
|
|
2
|
+
import { Module } from '@nu-art/ts-common';
|
|
3
|
+
import { BaseHttpRequest } from './BaseHttpRequest.js';
|
|
4
|
+
import { HttpException } from './request-types.js';
|
|
5
|
+
type HttpConfig = {
|
|
6
|
+
origin?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
compress?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class BaseHttpModule_Class<Config extends HttpConfig = HttpConfig> extends Module<Config> {
|
|
11
|
+
protected origin: string;
|
|
12
|
+
protected timeout: number;
|
|
13
|
+
private readonly defaultHeaders;
|
|
14
|
+
protected defaultOnComplete?: (response: unknown, input: unknown, request: BaseHttpRequest<any>) => Promise<any>;
|
|
15
|
+
protected defaultOnError?: (errorResponse: HttpException, input: unknown, request: BaseHttpRequest<any>) => Promise<any>;
|
|
16
|
+
constructor();
|
|
17
|
+
init(): void;
|
|
18
|
+
getOrigin(): string;
|
|
19
|
+
shouldCompress(): boolean | undefined;
|
|
20
|
+
setDefaultOnComplete: (defaultOnComplete: (response: unknown, input: unknown, request: BaseHttpRequest<any>) => Promise<any>) => void;
|
|
21
|
+
setDefaultOnError: (defaultOnError: (errorResponse: HttpException, input: unknown, request: BaseHttpRequest<any>) => Promise<any>) => void;
|
|
22
|
+
addDefaultHeader(key: string, header: (() => string | string[]) | string | string[]): void;
|
|
23
|
+
getDefaultHeaders(): {
|
|
24
|
+
[k: string]: string | string[];
|
|
25
|
+
};
|
|
26
|
+
abstract createRequest<API extends TypedApi<any, any, any, any>>(apiDef: ApiDef<API>, data?: any): BaseHttpRequest<API>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BadImplementationException, Module, } from '@nu-art/ts-common';
|
|
2
|
+
export class BaseHttpModule_Class extends Module {
|
|
3
|
+
origin;
|
|
4
|
+
timeout = 10000;
|
|
5
|
+
defaultHeaders = {};
|
|
6
|
+
defaultOnComplete;
|
|
7
|
+
defaultOnError;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.setDefaultConfig({ compress: true });
|
|
11
|
+
}
|
|
12
|
+
init() {
|
|
13
|
+
this.timeout = this.config.timeout || this.timeout;
|
|
14
|
+
}
|
|
15
|
+
getOrigin() {
|
|
16
|
+
return this.origin;
|
|
17
|
+
}
|
|
18
|
+
shouldCompress() {
|
|
19
|
+
return this.config.compress;
|
|
20
|
+
}
|
|
21
|
+
setDefaultOnComplete = (defaultOnComplete) => {
|
|
22
|
+
this.defaultOnComplete = defaultOnComplete;
|
|
23
|
+
};
|
|
24
|
+
setDefaultOnError = (defaultOnError) => {
|
|
25
|
+
this.defaultOnError = defaultOnError;
|
|
26
|
+
};
|
|
27
|
+
addDefaultHeader(key, header) {
|
|
28
|
+
this.defaultHeaders[key] = header;
|
|
29
|
+
}
|
|
30
|
+
getDefaultHeaders() {
|
|
31
|
+
return Object.keys(this.defaultHeaders).reduce((toRet, _key) => {
|
|
32
|
+
const defaultHeader = this.defaultHeaders[_key];
|
|
33
|
+
switch (typeof defaultHeader) {
|
|
34
|
+
case 'string':
|
|
35
|
+
toRet[_key] = [defaultHeader];
|
|
36
|
+
break;
|
|
37
|
+
case 'function':
|
|
38
|
+
toRet[_key] = defaultHeader();
|
|
39
|
+
break;
|
|
40
|
+
case 'object':
|
|
41
|
+
if (Array.isArray(defaultHeader)) {
|
|
42
|
+
toRet[_key] = defaultHeader;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line no-fallthrough
|
|
46
|
+
case 'boolean':
|
|
47
|
+
case 'number':
|
|
48
|
+
case 'symbol':
|
|
49
|
+
case 'bigint':
|
|
50
|
+
case 'undefined':
|
|
51
|
+
throw new BadImplementationException(`Headers values can only be of type: (() => string | string[]) | string | string[], got type ${typeof defaultHeader} `);
|
|
52
|
+
}
|
|
53
|
+
return toRet;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Logger } from '@nu-art/ts-common';
|
|
2
|
+
import { HttpMethod, TypedApi } from './types.js';
|
|
3
|
+
import { HttpException, TS_Progress } from './request-types.js';
|
|
4
|
+
import { ApiErrorResponse } from '@nu-art/ts-common/core/exceptions/types';
|
|
5
|
+
export declare abstract class BaseHttpRequest<API extends TypedApi<any, any, any, any>> {
|
|
6
|
+
key: string;
|
|
7
|
+
requestData: any;
|
|
8
|
+
protected origin?: string;
|
|
9
|
+
protected headers: {
|
|
10
|
+
[s: string]: string[];
|
|
11
|
+
};
|
|
12
|
+
protected method: HttpMethod;
|
|
13
|
+
protected timeout: number;
|
|
14
|
+
protected body: API['B'];
|
|
15
|
+
protected url: string;
|
|
16
|
+
protected params: {
|
|
17
|
+
[K in keyof API['P']]?: API['P'][K];
|
|
18
|
+
};
|
|
19
|
+
protected responseType: string;
|
|
20
|
+
protected label: string;
|
|
21
|
+
protected onProgressListener: (ev: TS_Progress) => void;
|
|
22
|
+
protected aborted: boolean;
|
|
23
|
+
protected compress: boolean;
|
|
24
|
+
protected logger?: Logger;
|
|
25
|
+
private onCompleted?;
|
|
26
|
+
private onError?;
|
|
27
|
+
constructor(requestKey: string, requestData?: any);
|
|
28
|
+
resolveTypedException(exception: HttpException<any> | unknown): API['E'] | undefined;
|
|
29
|
+
setLogger(logger?: Logger): this;
|
|
30
|
+
getRequestData(): any;
|
|
31
|
+
setOrigin(origin?: string): this;
|
|
32
|
+
setOnProgressListener(onProgressListener: (ev: TS_Progress) => void): this;
|
|
33
|
+
setLabel(label: string): this;
|
|
34
|
+
setMethod(method: HttpMethod): this;
|
|
35
|
+
setResponseType(responseType: string): this;
|
|
36
|
+
setUrlParams(params: API['P']): this;
|
|
37
|
+
setUrlParam<K extends keyof API['P'] = keyof API['P']>(key: K, value: API['P'][K]): this;
|
|
38
|
+
setUrl(url: string): this;
|
|
39
|
+
getUrl(): string;
|
|
40
|
+
setRelativeUrl(relativeUrl: string): this;
|
|
41
|
+
setTimeout(timeout: number): this;
|
|
42
|
+
setHeaders(headers: {
|
|
43
|
+
[s: string]: string | string[];
|
|
44
|
+
}): this;
|
|
45
|
+
addHeaders(headers: {
|
|
46
|
+
[s: string]: string | string[];
|
|
47
|
+
}): this;
|
|
48
|
+
setHeader(_key: string, value: string | string[]): this;
|
|
49
|
+
addHeader(_key: string, value: string | string[]): this;
|
|
50
|
+
removeHeader(key: string): this;
|
|
51
|
+
protected _addHeaderImpl(key: string, value: string | string[]): this;
|
|
52
|
+
protected prepareJsonBody(bodyObject: API['B']): any;
|
|
53
|
+
setBodyAsJson(bodyObject: API['B'], compress?: boolean): this;
|
|
54
|
+
setBody(bodyAsString: any, _compress?: boolean): this;
|
|
55
|
+
isValidStatus(statusCode: number): boolean;
|
|
56
|
+
protected print(): void;
|
|
57
|
+
executeSync(print?: boolean): Promise<API['R']>;
|
|
58
|
+
execute(onSuccess?: (response: API['R'], data?: string) => Promise<void> | void, onError?: (reason: HttpException<API['E']>) => any): this;
|
|
59
|
+
clearOnCompleted: () => void;
|
|
60
|
+
setOnCompleted: (onCompleted?: (response: API["R"], input: API["P"] | API["B"], request: BaseHttpRequest<API>) => Promise<any>) => this;
|
|
61
|
+
setOnError(onError?: (errorResponse: HttpException<API['E']>, input: API['P'] | API['B'], request: BaseHttpRequest<API>) => Promise<any>): this;
|
|
62
|
+
protected abstract getResponse(): API['R'];
|
|
63
|
+
abstract getErrorResponse(): ApiErrorResponse<API['E']>;
|
|
64
|
+
protected abstract abortImpl(): void;
|
|
65
|
+
abstract getStatus(): number;
|
|
66
|
+
getResponseHeader(headerKey: string): string | string[] | undefined;
|
|
67
|
+
abstract _getResponseHeader(headerKey: string): string | string[] | undefined;
|
|
68
|
+
abort(): void;
|
|
69
|
+
protected abstract executeImpl(): Promise<void>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Thunderstorm is a full web app framework!
|
|
3
|
+
*
|
|
4
|
+
* Typescript & Express backend infrastructure that natively runs on firebase function
|
|
5
|
+
* Typescript & React frontend infrastructure
|
|
6
|
+
*
|
|
7
|
+
* Copyright (C) 2020 Adam van der Kruk aka TacB0sS
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
import { __stringify, _keys, asArray, BadImplementationException, exists, isErrorOfType, MimeType_json, Minute, ModuleManager } from '@nu-art/ts-common';
|
|
22
|
+
import { HttpMethod } from './types.js';
|
|
23
|
+
import { HttpException } from './request-types.js';
|
|
24
|
+
import { dispatcher_onAuthRequired } from './no-auth-listener.js';
|
|
25
|
+
import { DefaultHttpServerConfig } from './consts.js';
|
|
26
|
+
import { HttpCodes } from '@nu-art/ts-common/core/exceptions/http-codes';
|
|
27
|
+
export class BaseHttpRequest {
|
|
28
|
+
key;
|
|
29
|
+
requestData;
|
|
30
|
+
origin;
|
|
31
|
+
headers = {};
|
|
32
|
+
method = HttpMethod.GET;
|
|
33
|
+
timeout = 10000;
|
|
34
|
+
body;
|
|
35
|
+
url;
|
|
36
|
+
params = {};
|
|
37
|
+
responseType;
|
|
38
|
+
label;
|
|
39
|
+
onProgressListener;
|
|
40
|
+
aborted = false;
|
|
41
|
+
compress;
|
|
42
|
+
logger;
|
|
43
|
+
onCompleted;
|
|
44
|
+
onError;
|
|
45
|
+
constructor(requestKey, requestData) {
|
|
46
|
+
this.key = requestKey;
|
|
47
|
+
this.requestData = requestData;
|
|
48
|
+
this.label = `http request: ${requestKey}${requestData ? ` ${requestData}` : ''}`;
|
|
49
|
+
this.compress = false;
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
if (ModuleManager.instance.config.isDebug)
|
|
52
|
+
this.timeout = 5 * Minute;
|
|
53
|
+
}
|
|
54
|
+
resolveTypedException(exception) {
|
|
55
|
+
if (isErrorOfType(exception, HttpException))
|
|
56
|
+
return exception.errorResponse?.error;
|
|
57
|
+
}
|
|
58
|
+
setLogger(logger) {
|
|
59
|
+
this.logger = logger;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
getRequestData() {
|
|
63
|
+
return this.requestData;
|
|
64
|
+
}
|
|
65
|
+
setOrigin(origin) {
|
|
66
|
+
this.origin = origin;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
setOnProgressListener(onProgressListener) {
|
|
70
|
+
this.onProgressListener = onProgressListener;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
setLabel(label) {
|
|
74
|
+
this.label = label;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
setMethod(method) {
|
|
78
|
+
this.method = method;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
setResponseType(responseType) {
|
|
82
|
+
this.responseType = responseType;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
setUrlParams(params) {
|
|
86
|
+
if (!params)
|
|
87
|
+
return this;
|
|
88
|
+
_keys(params).forEach((key) => {
|
|
89
|
+
const param = params[key];
|
|
90
|
+
return param && typeof param === 'string' && this.setUrlParam(key, param);
|
|
91
|
+
});
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
setUrlParam(key, value) {
|
|
95
|
+
delete this.params[key];
|
|
96
|
+
this.params[key] = value;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
setUrl(url) {
|
|
100
|
+
this.url = url;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
getUrl() {
|
|
104
|
+
return this.url;
|
|
105
|
+
}
|
|
106
|
+
setRelativeUrl(relativeUrl) {
|
|
107
|
+
if (!this.origin)
|
|
108
|
+
throw new BadImplementationException('if you want to use relative urls, you need to set an origin');
|
|
109
|
+
if (relativeUrl.startsWith('/'))
|
|
110
|
+
relativeUrl = relativeUrl.substring(1);
|
|
111
|
+
this.url = `${this.origin}/${relativeUrl}`;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
setTimeout(timeout) {
|
|
115
|
+
// console.log(`${this.url} - setting timeout: ${timeout}`);
|
|
116
|
+
this.timeout = timeout;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
setHeaders(headers) {
|
|
120
|
+
if (!headers)
|
|
121
|
+
return this;
|
|
122
|
+
Object.keys(headers).forEach((key) => this.setHeader(key, headers[key]));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
addHeaders(headers) {
|
|
126
|
+
if (!headers)
|
|
127
|
+
return this;
|
|
128
|
+
Object.keys(headers).forEach((key) => this.addHeader(key, headers[key]));
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
setHeader(_key, value) {
|
|
132
|
+
const key = _key.toLowerCase();
|
|
133
|
+
delete this.headers[key];
|
|
134
|
+
return this.addHeader(key, value);
|
|
135
|
+
}
|
|
136
|
+
addHeader(_key, value) {
|
|
137
|
+
const key = _key.toLowerCase();
|
|
138
|
+
return this._addHeaderImpl(key, value);
|
|
139
|
+
}
|
|
140
|
+
removeHeader(key) {
|
|
141
|
+
delete this.headers[key];
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
_addHeaderImpl(key, value) {
|
|
145
|
+
const values = asArray(value);
|
|
146
|
+
if (!this.headers[key])
|
|
147
|
+
this.headers[key] = values;
|
|
148
|
+
else
|
|
149
|
+
this.headers[key].push(...values);
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
prepareJsonBody(bodyObject) {
|
|
153
|
+
return bodyObject;
|
|
154
|
+
}
|
|
155
|
+
setBodyAsJson(bodyObject, compress) {
|
|
156
|
+
this.setHeader('content-type', MimeType_json);
|
|
157
|
+
this.setBody(this.prepareJsonBody(bodyObject), compress);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
setBody(bodyAsString, _compress) {
|
|
161
|
+
this.body = bodyAsString;
|
|
162
|
+
this.compress = _compress === undefined ? this.compress : _compress;
|
|
163
|
+
if (typeof bodyAsString === 'string' && this.compress)
|
|
164
|
+
this.setHeader('Content-encoding', 'gzip');
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
isValidStatus(statusCode) {
|
|
168
|
+
return statusCode >= 200 && statusCode < 300;
|
|
169
|
+
}
|
|
170
|
+
print() {
|
|
171
|
+
this.logger?.logWarning(`Url: ${this.url}`);
|
|
172
|
+
this.logger?.logWarning(`Params:`, this.params);
|
|
173
|
+
this.logger?.logWarning(`Headers:`, this.headers);
|
|
174
|
+
}
|
|
175
|
+
async executeSync(print = false) {
|
|
176
|
+
if (print)
|
|
177
|
+
this.print();
|
|
178
|
+
await this.executeImpl();
|
|
179
|
+
const status = this.getStatus();
|
|
180
|
+
const requestData = this.body || this.params;
|
|
181
|
+
if (this.aborted) {
|
|
182
|
+
const httpException = new HttpException(status, this.url); // should be status 0
|
|
183
|
+
await this.onError?.(httpException, requestData, this);
|
|
184
|
+
throw httpException;
|
|
185
|
+
}
|
|
186
|
+
if (!this.isValidStatus(status)) {
|
|
187
|
+
const errorResponse = this.getErrorResponse();
|
|
188
|
+
const httpException = new HttpException(status, this.url, errorResponse);
|
|
189
|
+
if (status === HttpCodes._4XX.UNAUTHORIZED.code)
|
|
190
|
+
await dispatcher_onAuthRequired.dispatchModuleAsync(this);
|
|
191
|
+
await this.onError?.(httpException, requestData, this);
|
|
192
|
+
throw httpException;
|
|
193
|
+
}
|
|
194
|
+
let response = this.getResponse();
|
|
195
|
+
if (!exists(response)) {
|
|
196
|
+
await this.onCompleted?.(response, requestData, this);
|
|
197
|
+
return response;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
response = JSON.parse(response);
|
|
201
|
+
}
|
|
202
|
+
catch (ignore) {
|
|
203
|
+
//
|
|
204
|
+
}
|
|
205
|
+
await this.onCompleted?.(response, requestData, this);
|
|
206
|
+
return response;
|
|
207
|
+
}
|
|
208
|
+
execute(onSuccess = () => this.logger?.logVerbose(`Completed: ${this.label}`), onError = reason => this.logger?.logWarning(`Error: ${this.label}`, reason)) {
|
|
209
|
+
this.executeSync()
|
|
210
|
+
.then(onSuccess)
|
|
211
|
+
.catch(onError);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
clearOnCompleted = () => {
|
|
215
|
+
delete this.onCompleted;
|
|
216
|
+
};
|
|
217
|
+
setOnCompleted = (onCompleted) => {
|
|
218
|
+
if (!onCompleted)
|
|
219
|
+
return this;
|
|
220
|
+
if (this.onCompleted && onCompleted) {
|
|
221
|
+
const _onCompleted = this.onCompleted;
|
|
222
|
+
this.onCompleted = async (response, input, request) => {
|
|
223
|
+
await _onCompleted(response, input, request);
|
|
224
|
+
await onCompleted(response, input, request);
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
this.onCompleted = async (response, input, request) => {
|
|
229
|
+
await onCompleted?.(response, input, request);
|
|
230
|
+
};
|
|
231
|
+
return this;
|
|
232
|
+
};
|
|
233
|
+
setOnError(onError) {
|
|
234
|
+
if (!onError)
|
|
235
|
+
return this;
|
|
236
|
+
if (this.onError && onError) {
|
|
237
|
+
const _onError = this.onError;
|
|
238
|
+
this.onError = async (response, input, request) => {
|
|
239
|
+
await _onError(response, input, request);
|
|
240
|
+
await onError(response, input, request);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else
|
|
244
|
+
this.onError = async (response, input, request) => {
|
|
245
|
+
await onError?.(response, input, request);
|
|
246
|
+
};
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
getResponseHeader(headerKey) {
|
|
250
|
+
try {
|
|
251
|
+
return this._getResponseHeader(headerKey);
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
this.logger?.logError(`Need to add responseHeaders to backend config: ${__stringify(DefaultHttpServerConfig, true)}`, e);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
abort() {
|
|
258
|
+
this.aborted = true;
|
|
259
|
+
this.abortImpl();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiDefResolver, QueryApi } from '../../types.js';
|
|
2
|
+
export type RequestBody_GetResolverByKey = {
|
|
3
|
+
key: string;
|
|
4
|
+
};
|
|
5
|
+
export type ApiStruct_AppConfig = {
|
|
6
|
+
_v1: {
|
|
7
|
+
getConfigByKey: QueryApi<any, RequestBody_GetResolverByKey>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const ApiDef_AppConfig: ApiDefResolver<ApiStruct_AppConfig>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { tsValidateMustExist, tsValidateString } from '@nu-art/ts-common';
|
|
2
|
+
const Validator_ModifiableProps = {
|
|
3
|
+
key: tsValidateString(),
|
|
4
|
+
data: tsValidateMustExist,
|
|
5
|
+
};
|
|
6
|
+
const Validator_GeneratedProps = {};
|
|
7
|
+
export const DBDef_AppConfig = {
|
|
8
|
+
modifiablePropsValidator: Validator_ModifiableProps,
|
|
9
|
+
generatedPropsValidator: Validator_GeneratedProps,
|
|
10
|
+
versions: ['1.0.0'],
|
|
11
|
+
dbKey: 'app-configs',
|
|
12
|
+
entityName: 'AppConfig',
|
|
13
|
+
frontend: {
|
|
14
|
+
group: 'app',
|
|
15
|
+
name: 'config'
|
|
16
|
+
},
|
|
17
|
+
backend: {
|
|
18
|
+
name: 'app-configs'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DB_Object, DBProto, Proto_DB_Object, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
type VersionTypes_AppConfig = {
|
|
3
|
+
'1.0.0': DB_AppConfig;
|
|
4
|
+
};
|
|
5
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_AppConfig>;
|
|
6
|
+
type Dependencies = {};
|
|
7
|
+
type UniqueKeys = '_id';
|
|
8
|
+
type GeneratedProps = never;
|
|
9
|
+
type Proto<D> = Proto_DB_Object<DB_AppConfig<D>, 'app-configs', GeneratedProps, Versions, UniqueKeys, Dependencies>;
|
|
10
|
+
export type DBProto_AppConfig<D = any> = DBProto<Proto<D>>;
|
|
11
|
+
export type UI_AppConfig = DBProto_AppConfig['uiType'];
|
|
12
|
+
export type DB_AppConfig<D = any> = DB_Object & {
|
|
13
|
+
key: string;
|
|
14
|
+
data: D;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiDefResolver, QueryApi } from '../../types.js';
|
|
2
|
+
import { FetchBackupDoc } from './types.js';
|
|
3
|
+
export type Request_BackupId = {
|
|
4
|
+
backupId: string;
|
|
5
|
+
};
|
|
6
|
+
export type Response_BackupDocs = {
|
|
7
|
+
backupInfo: FetchBackupDoc;
|
|
8
|
+
};
|
|
9
|
+
export type ApiStruct_BackupDoc = {
|
|
10
|
+
_v1: {
|
|
11
|
+
initiateBackup: QueryApi<{
|
|
12
|
+
pathToBackup: string;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
fetchBackupDocs: QueryApi<Response_BackupDocs, Request_BackupId>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const ApiDef_BackupDoc: ApiDefResolver<ApiStruct_BackupDoc>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tsValidateArray, tsValidateNumber, tsValidateString, tsValidateTimestamp } from '@nu-art/ts-common';
|
|
2
|
+
const Validator_ModifiableProps = {
|
|
3
|
+
timestamp: tsValidateTimestamp(),
|
|
4
|
+
backupPath: tsValidateString(),
|
|
5
|
+
firebasePath: tsValidateString(),
|
|
6
|
+
metadataPath: tsValidateString(),
|
|
7
|
+
metadata: {
|
|
8
|
+
timestamp: tsValidateTimestamp(),
|
|
9
|
+
collectionsData: tsValidateArray({
|
|
10
|
+
dbKey: tsValidateString(),
|
|
11
|
+
numOfDocs: tsValidateNumber(),
|
|
12
|
+
version: tsValidateString()
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const Validator_GeneratedProps = {};
|
|
17
|
+
export const DBDef_BackupDoc = {
|
|
18
|
+
modifiablePropsValidator: Validator_ModifiableProps,
|
|
19
|
+
generatedPropsValidator: Validator_GeneratedProps,
|
|
20
|
+
versions: ['1.0.0'],
|
|
21
|
+
dbKey: 'firestore-backup-status-v2',
|
|
22
|
+
entityName: 'firestoreBackupStatus',
|
|
23
|
+
frontend: {
|
|
24
|
+
group: 'app',
|
|
25
|
+
name: 'firestore-backup-status-v2'
|
|
26
|
+
},
|
|
27
|
+
backend: {
|
|
28
|
+
name: 'backup-doc'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DB_Object, DBProto, Proto_DB_Object, VersionsDeclaration } from '@nu-art/ts-common';
|
|
2
|
+
type VersionTypes_BackupDoc = {
|
|
3
|
+
'1.0.0': DB_BackupDoc;
|
|
4
|
+
};
|
|
5
|
+
type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_BackupDoc>;
|
|
6
|
+
type Dependencies = {};
|
|
7
|
+
type UniqueKeys = '_id';
|
|
8
|
+
type GeneratedProps = never;
|
|
9
|
+
type DBKey = 'firestore-backup-status-v2';
|
|
10
|
+
type Proto = Proto_DB_Object<DB_BackupDoc, DBKey, GeneratedProps, Versions, UniqueKeys, Dependencies>;
|
|
11
|
+
export type DBProto_BackupDoc = DBProto<Proto>;
|
|
12
|
+
export type UI_BackupDoc = DBProto_BackupDoc['uiType'];
|
|
13
|
+
export type DB_BackupDoc = DB_Object & {
|
|
14
|
+
timestamp: number;
|
|
15
|
+
backupPath: string;
|
|
16
|
+
metadataPath: string;
|
|
17
|
+
firebasePath: string;
|
|
18
|
+
metadata: BackupMetaData;
|
|
19
|
+
};
|
|
20
|
+
export type ActDetailsDoc = {
|
|
21
|
+
timestamp: number;
|
|
22
|
+
moduleKey: string;
|
|
23
|
+
};
|
|
24
|
+
export type BackupDoc = ActDetailsDoc & {
|
|
25
|
+
backupPath: string;
|
|
26
|
+
backupId: string;
|
|
27
|
+
};
|
|
28
|
+
export type FetchBackupDoc = {
|
|
29
|
+
_id: string;
|
|
30
|
+
backupFilePath: string;
|
|
31
|
+
metadataFilePath: string;
|
|
32
|
+
firebaseFilePath: string;
|
|
33
|
+
firestoreSignedUrl: string;
|
|
34
|
+
firebaseSignedUrl: string;
|
|
35
|
+
metadata: BackupMetaData;
|
|
36
|
+
};
|
|
37
|
+
export type BackupMetaData = {
|
|
38
|
+
collectionsData: {
|
|
39
|
+
dbKey: string;
|
|
40
|
+
numOfDocs: number;
|
|
41
|
+
version: string;
|
|
42
|
+
}[];
|
|
43
|
+
timestamp: number;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApiDefResolver } from '../../types.js';
|
|
2
|
+
export type RequestType_DeletedDoc = {};
|
|
3
|
+
export type ResponseType_DeletedDoc = {};
|
|
4
|
+
export type ApiStruct_DeletedDoc = {
|
|
5
|
+
_v1: {};
|
|
6
|
+
};
|
|
7
|
+
export declare const ApiDef_DeletedDoc: ApiDefResolver<ApiStruct_DeletedDoc>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { tsValidateMustExist } from '@nu-art/ts-common';
|
|
2
|
+
// const Validator_ModifiableProps: DBProto_DeletedDoc['modifiablePropsValidator'] = {
|
|
3
|
+
// __docId: tsValidateUniqueId,
|
|
4
|
+
// __collectionName: tsValidateString(),
|
|
5
|
+
// };
|
|
6
|
+
const Validator_GeneratedProps = {};
|
|
7
|
+
export const DBDef_DeletedDoc = {
|
|
8
|
+
modifiablePropsValidator: tsValidateMustExist,
|
|
9
|
+
generatedPropsValidator: Validator_GeneratedProps,
|
|
10
|
+
versions: ['1.0.0'],
|
|
11
|
+
dbKey: '__deleted__docs',
|
|
12
|
+
entityName: 'DeletedDoc',
|
|
13
|
+
frontend: {
|
|
14
|
+
group: 'ts-default',
|
|
15
|
+
name: 'deleted-doc'
|
|
16
|
+
},
|
|
17
|
+
backend: {
|
|
18
|
+
name: '__deleted__docs'
|
|
19
|
+
}
|
|
20
|
+
};
|