@nu-art/thunderstorm-backend 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.
Files changed (111) hide show
  1. package/_entity/app-config/ModuleBE_AppConfigAPI.d.ts +9 -0
  2. package/_entity/app-config/ModuleBE_AppConfigAPI.js +20 -0
  3. package/_entity/app-config/ModuleBE_AppConfigDB.d.ts +27 -0
  4. package/_entity/app-config/ModuleBE_AppConfigDB.js +91 -0
  5. package/_entity/app-config/index.d.ts +2 -0
  6. package/_entity/app-config/index.js +2 -0
  7. package/_entity/app-config/module-pack.d.ts +2 -0
  8. package/_entity/app-config/module-pack.js +3 -0
  9. package/_entity/backup-doc/ModuleBE_BackupDocDB.d.ts +52 -0
  10. package/_entity/backup-doc/ModuleBE_BackupDocDB.js +350 -0
  11. package/_entity/backup-doc/ModuleBE_BackupScheduler.d.ts +7 -0
  12. package/_entity/backup-doc/ModuleBE_BackupScheduler.js +14 -0
  13. package/_entity/backup-doc/index.d.ts +3 -0
  14. package/_entity/backup-doc/index.js +3 -0
  15. package/_entity/backup-doc/module-pack.d.ts +2 -0
  16. package/_entity/backup-doc/module-pack.js +3 -0
  17. package/_entity/editable-test/ModuleBE_EditableTestDB.d.ts +8 -0
  18. package/_entity/editable-test/ModuleBE_EditableTestDB.js +8 -0
  19. package/_entity/editable-test/index.d.ts +1 -0
  20. package/_entity/editable-test/index.js +1 -0
  21. package/_entity/editable-test/module-pack.d.ts +1 -0
  22. package/_entity/editable-test/module-pack.js +3 -0
  23. package/_entity.d.ts +3 -0
  24. package/_entity.js +3 -0
  25. package/core/BaseStorm.d.ts +17 -0
  26. package/core/BaseStorm.js +77 -0
  27. package/core/Storm.d.ts +15 -0
  28. package/core/Storm.js +93 -0
  29. package/core/db-def.d.ts +10 -0
  30. package/core/db-def.js +11 -0
  31. package/core/default-storm.d.ts +3 -0
  32. package/core/default-storm.js +30 -0
  33. package/core/storm-modulepack.d.ts +3 -0
  34. package/core/storm-modulepack.js +20 -0
  35. package/core/typed-api.d.ts +7 -0
  36. package/core/typed-api.js +46 -0
  37. package/exceptions.d.ts +1 -0
  38. package/exceptions.js +21 -0
  39. package/index.d.ts +27 -0
  40. package/index.js +48 -0
  41. package/modules/CleanupScheduler.d.ts +14 -0
  42. package/modules/CleanupScheduler.js +50 -0
  43. package/modules/ModuleBE_APIs.d.ts +11 -0
  44. package/modules/ModuleBE_APIs.js +19 -0
  45. package/modules/ModuleBE_CSVParser.d.ts +9 -0
  46. package/modules/ModuleBE_CSVParser.js +50 -0
  47. package/modules/ModuleBE_ForceUpgrade.d.ts +21 -0
  48. package/modules/ModuleBE_ForceUpgrade.js +70 -0
  49. package/modules/ModuleBE_ServerInfo.d.ts +20 -0
  50. package/modules/ModuleBE_ServerInfo.js +76 -0
  51. package/modules/_imports.d.ts +6 -0
  52. package/modules/_imports.js +26 -0
  53. package/modules/_tdb/service-accounts.d.ts +19 -0
  54. package/modules/_tdb/service-accounts.js +2 -0
  55. package/modules/action-processor/Action_SetupProject.d.ts +9 -0
  56. package/modules/action-processor/Action_SetupProject.js +23 -0
  57. package/modules/action-processor/ModuleBE_ActionProcessor.d.ts +11 -0
  58. package/modules/action-processor/ModuleBE_ActionProcessor.js +67 -0
  59. package/modules/action-processor/types.d.ts +10 -0
  60. package/modules/action-processor/types.js +1 -0
  61. package/modules/archiving/ModuleBE_Archiving.d.ts +119 -0
  62. package/modules/archiving/ModuleBE_Archiving.js +236 -0
  63. package/modules/collection-actions/ModuleBE_CollectionActions.d.ts +12 -0
  64. package/modules/collection-actions/ModuleBE_CollectionActions.js +69 -0
  65. package/modules/collection-actions/dispatcher.d.ts +7 -0
  66. package/modules/collection-actions/dispatcher.js +2 -0
  67. package/modules/db-api-gen/ModuleBE_BaseApi.d.ts +16 -0
  68. package/modules/db-api-gen/ModuleBE_BaseApi.js +74 -0
  69. package/modules/db-api-gen/ModuleBE_BaseDB.d.ts +78 -0
  70. package/modules/db-api-gen/ModuleBE_BaseDB.js +298 -0
  71. package/modules/http/AxiosHttpModule.d.ts +25 -0
  72. package/modules/http/AxiosHttpModule.js +132 -0
  73. package/modules/http/types.d.ts +6 -0
  74. package/modules/http/types.js +1 -0
  75. package/modules/proxy/ModuleBE_RemoteProxy.d.ts +35 -0
  76. package/modules/proxy/ModuleBE_RemoteProxy.js +86 -0
  77. package/modules/proxy/RemoteProxyCaller.d.ts +19 -0
  78. package/modules/proxy/RemoteProxyCaller.js +82 -0
  79. package/modules/proxy/assert-secret-middleware.d.ts +2 -0
  80. package/modules/proxy/assert-secret-middleware.js +24 -0
  81. package/modules/server/HeaderKey.d.ts +8 -0
  82. package/modules/server/HeaderKey.js +41 -0
  83. package/modules/server/HttpServer.d.ts +41 -0
  84. package/modules/server/HttpServer.js +223 -0
  85. package/modules/server/consts.d.ts +13 -0
  86. package/modules/server/consts.js +9 -0
  87. package/modules/server/route-resolvers/RouteResolver_Dummy.d.ts +7 -0
  88. package/modules/server/route-resolvers/RouteResolver_Dummy.js +34 -0
  89. package/modules/server/route-resolvers/RouteResolver_ModulePath.d.ts +22 -0
  90. package/modules/server/route-resolvers/RouteResolver_ModulePath.js +84 -0
  91. package/modules/server/route-resolvers/index.d.ts +7 -0
  92. package/modules/server/route-resolvers/index.js +21 -0
  93. package/modules/server/server-api.d.ts +85 -0
  94. package/modules/server/server-api.js +362 -0
  95. package/modules/server/server-errors.d.ts +4 -0
  96. package/modules/server/server-errors.js +79 -0
  97. package/modules/sync-env/ModuleBE_SyncEnv.d.ts +36 -0
  98. package/modules/sync-env/ModuleBE_SyncEnv.js +212 -0
  99. package/modules/sync-manager/ModuleBE_SyncManager.d.ts +63 -0
  100. package/modules/sync-manager/ModuleBE_SyncManager.js +254 -0
  101. package/package.json +104 -0
  102. package/shared.d.ts +1 -0
  103. package/shared.js +21 -0
  104. package/test/StormTest.d.ts +23 -0
  105. package/test/StormTest.js +49 -0
  106. package/utils/file.d.ts +2 -0
  107. package/utils/file.js +29 -0
  108. package/utils/promisify-request.d.ts +3 -0
  109. package/utils/promisify-request.js +33 -0
  110. package/utils/types.d.ts +11 -0
  111. package/utils/types.js +21 -0
@@ -0,0 +1,23 @@
1
+ import { AsyncVoidFunction, Module, RecursiveObjectOfPrimitives } from '@nu-art/ts-common';
2
+ import { TestModel } from '@nu-art/ts-common/testing/types';
3
+ type StormTestConfig = {
4
+ databaseName?: string;
5
+ modules: Module[];
6
+ config: RecursiveObjectOfPrimitives;
7
+ };
8
+ export type StormTestInput = {
9
+ modules: Module[];
10
+ config?: RecursiveObjectOfPrimitives;
11
+ cleanup?: AsyncVoidFunction;
12
+ before?: AsyncVoidFunction;
13
+ after?: AsyncVoidFunction;
14
+ };
15
+ export declare class StormTest {
16
+ private firebaseConfig;
17
+ private testConfig;
18
+ constructor(config: StormTestConfig);
19
+ init(): Promise<this>;
20
+ cleanup(): Promise<void>;
21
+ }
22
+ export declare const stormTester: <TestCase extends TestModel<any, any>>(stormTestInput: StormTestInput, testCaseRunner: () => Promise<void>) => Promise<void>;
23
+ export {};
@@ -0,0 +1,49 @@
1
+ import { generateHex, ModuleManager } from '@nu-art/ts-common';
2
+ import { FIREBASE_DEFAULT_PROJECT_ID } from '@nu-art/firebase-backend';
3
+ import { RouteResolver_Dummy } from '../modules/server/route-resolvers/RouteResolver_Dummy.js';
4
+ import { Storm } from '../core/Storm.js';
5
+ import { ModuleBE_Auth } from '@nu-art/google-services-backend';
6
+ import { dispatcher_resetTests } from '@nu-art/ts-common/testing/consts';
7
+ export class StormTest {
8
+ firebaseConfig;
9
+ testConfig;
10
+ constructor(config) {
11
+ this.testConfig = config;
12
+ const database = config.databaseName ?? `demo-test`;
13
+ this.firebaseConfig = {
14
+ project_id: generateHex(4),
15
+ databaseURL: `http://localhost:8102/?ns=${database}`,
16
+ isEmulator: true
17
+ };
18
+ process.env.FUNCTIONS_EMULATOR = 'true';
19
+ process.env.GCLOUD_PROJECT = database;
20
+ ModuleBE_Auth.setDefaultConfig({ auth: { [FIREBASE_DEFAULT_PROJECT_ID]: this.firebaseConfig } });
21
+ }
22
+ async init() {
23
+ new Storm({ envKey: 'local', pathToDefaultConfig: '_config/default', pathToEnvOverrideConfig: '_config/test' })
24
+ .addModulePack(this.testConfig.modules)
25
+ .setConfig({ ...this.testConfig.config, isDebug: true, })
26
+ .setInitialRouteResolver(new RouteResolver_Dummy())
27
+ .init();
28
+ return this;
29
+ }
30
+ async cleanup() {
31
+ await dispatcher_resetTests.dispatchModuleAsync();
32
+ // @ts-ignore
33
+ ModuleManager.__resetForTests();
34
+ }
35
+ }
36
+ export const stormTester = async (stormTestInput, testCaseRunner) => {
37
+ const stormTest = new StormTest({ modules: stormTestInput.modules, config: stormTestInput.config ?? {} });
38
+ await stormTest.init();
39
+ try {
40
+ await stormTestInput.before?.();
41
+ await testCaseRunner();
42
+ }
43
+ finally {
44
+ // first we do all the applicative test cleanups, for example, delete firestore collections
45
+ await stormTestInput.after?.();
46
+ // only then we clean infra stuff, like firebase apps
47
+ await stormTest.cleanup();
48
+ }
49
+ };
@@ -0,0 +1,2 @@
1
+ export declare function fileToBase64(file: string): Promise<string>;
2
+ export declare function base64ToFile(contentAsBase64: string, file: string): Promise<void>;
package/utils/file.js ADDED
@@ -0,0 +1,29 @@
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 * as fs from 'fs';
22
+ export async function fileToBase64(file) {
23
+ const buffer = await fs.readFileSync(file);
24
+ return buffer.toString('base64');
25
+ }
26
+ export async function base64ToFile(contentAsBase64, file) {
27
+ const bitmap = Buffer.from(contentAsBase64, 'base64');
28
+ await fs.writeFileSync(file, bitmap);
29
+ }
@@ -0,0 +1,3 @@
1
+ import { Response } from 'request';
2
+ import { RequestOptions } from '../index.js';
3
+ export declare function promisifyRequest(_request: RequestOptions, throwException?: boolean): Promise<Response>;
@@ -0,0 +1,33 @@
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 request from 'request';
22
+ import { __stringify, ApiException } from '@nu-art/ts-common';
23
+ export async function promisifyRequest(_request, throwException = true) {
24
+ return new Promise((resolve, rejected) => {
25
+ request(_request, (error, response) => {
26
+ if (error)
27
+ return rejected(new ApiException(503, `Error: ${error}\n Request: ${__stringify(_request, true)}`));
28
+ if (throwException && response.statusCode !== 200)
29
+ return rejected(new ApiException(response.statusCode, `Redirect proxy message, ${__stringify(response.body)} \n${__stringify(request, true)}`));
30
+ resolve(response);
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,11 @@
1
+ import * as express from 'express';
2
+ import { CoreOptions, UriOptions } from 'request';
3
+ import { ApiException } from '@nu-art/ts-common';
4
+ export type Express = express.Express;
5
+ export type ExpressRouter = express.Router;
6
+ export type ExpressRequest = express.Request<any>;
7
+ export type ExpressResponse = express.Response;
8
+ export type ExpressRequestHandler = express.RequestHandler;
9
+ export type RequestOptions = CoreOptions & UriOptions;
10
+ export type ServerApi_Middleware = () => Promise<any>;
11
+ export type HttpErrorHandler = (error: ApiException) => Promise<string>;
package/utils/types.js ADDED
@@ -0,0 +1,21 @@
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
+ export {};