node-server-engine 1.4.8 → 1.5.0
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/.commitlintrc.js +27 -0
- package/.releaserc.js +56 -0
- package/README.md +154 -2
- package/dist/const/tokenIssuer.js +1 -0
- package/dist/const/tokenIssuer.js.map +1 -1
- package/dist/db/models/SequelizeMeta.js +3 -1
- package/dist/db/models/SequelizeMeta.js.map +1 -1
- package/dist/entities/ElasticSearch/ElasticSearch.js +1 -2
- package/dist/entities/ElasticSearch/ElasticSearch.js.map +1 -1
- package/dist/entities/SocketClient/SocketClient.js +1 -0
- package/dist/entities/SocketClient/SocketClient.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/checkPermission/checkPermission.d.ts +1 -1
- package/dist/middleware/checkPermission/checkPermission.js +4 -2
- package/dist/middleware/checkPermission/checkPermission.js.map +1 -1
- package/dist/utils/createHttpServer/createHttpServer.js +1 -1
- package/dist/utils/createHttpServer/createHttpServer.js.map +1 -1
- package/dist/utils/jwt/jwt.js +1 -1
- package/dist/utils/jwt/jwt.js.map +1 -1
- package/dist/utils/semverCompare/semverCompare.js +1 -5
- package/dist/utils/semverCompare/semverCompare.js.map +1 -1
- package/package.json +30 -19
- package/.env.example +0 -186
- package/.github/workflows/publish.yml +0 -41
- package/.prettierrc +0 -7
- package/Dockerfile +0 -31
- package/babel.config.json +0 -34
- package/eslint.config.mjs +0 -11
- package/src/const/DebeziumEvent.ts +0 -6
- package/src/const/LogSeverity.ts +0 -7
- package/src/const/index.ts +0 -5
- package/src/const/metrics.ts +0 -6
- package/src/const/mime.ts +0 -37
- package/src/const/tokenIssuer.ts +0 -7
- package/src/db/migrations/20241030121500-create-sequelize-meta-table.ts +0 -29
- package/src/db/models/SequelizeMeta.ts +0 -16
- package/src/db/models/index.ts +0 -2
- package/src/entities/ElasticSearch/ElasticSearch.ts +0 -103
- package/src/entities/ElasticSearch/ElasticSearch.types.ts +0 -7
- package/src/entities/ElasticSearch/index.ts +0 -2
- package/src/entities/Endpoint/Endpoint.test.ts +0 -248
- package/src/entities/Endpoint/Endpoint.ts +0 -221
- package/src/entities/Endpoint/Endpoint.types.ts +0 -181
- package/src/entities/Endpoint/index.ts +0 -2
- package/src/entities/EngineError/EngineError.ts +0 -28
- package/src/entities/EngineError/EngineError.types.ts +0 -15
- package/src/entities/EngineError/index.ts +0 -2
- package/src/entities/KeySet/KeySet.test.ts +0 -126
- package/src/entities/KeySet/KeySet.ts +0 -172
- package/src/entities/KeySet/KeySet.types.ts +0 -28
- package/src/entities/KeySet/index.ts +0 -2
- package/src/entities/LifecycleController/LifecycleController.test.ts +0 -48
- package/src/entities/LifecycleController/LifecycleController.ts +0 -24
- package/src/entities/LifecycleController/LifecycleController.types.ts +0 -5
- package/src/entities/LifecycleController/index.ts +0 -2
- package/src/entities/Localizator/Localizator.ts +0 -139
- package/src/entities/Localizator/Localizator.types.ts +0 -52
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.test.ts +0 -165
- package/src/entities/Localizator/guessNamingConvention/guessNamingConvention.ts +0 -58
- package/src/entities/Localizator/guessNamingConvention/index.ts +0 -1
- package/src/entities/Localizator/index.ts +0 -2
- package/src/entities/MessageHandler/MessageHandler.test.ts +0 -130
- package/src/entities/MessageHandler/MessageHandler.ts +0 -72
- package/src/entities/MessageHandler/MessageHandler.types.ts +0 -15
- package/src/entities/MessageHandler/index.ts +0 -2
- package/src/entities/PubSub/PubSub.test.ts +0 -297
- package/src/entities/PubSub/PubSub.ts +0 -202
- package/src/entities/PubSub/PubSub.types.ts +0 -76
- package/src/entities/PubSub/handleMessage/handleMessage.test.ts +0 -102
- package/src/entities/PubSub/handleMessage/handleMessage.ts +0 -65
- package/src/entities/PubSub/handleMessage/index.ts +0 -1
- package/src/entities/PubSub/index.ts +0 -2
- package/src/entities/PushNotification/PushNotification.test.ts +0 -35
- package/src/entities/PushNotification/PushNotification.ts +0 -44
- package/src/entities/PushNotification/PushNotification.types.ts +0 -25
- package/src/entities/PushNotification/index.ts +0 -2
- package/src/entities/Redis/Redis.ts +0 -71
- package/src/entities/Redis/Redis.types.ts +0 -19
- package/src/entities/Redis/Redis.validate.ts +0 -17
- package/src/entities/Redis/index.ts +0 -2
- package/src/entities/Sequelize/Sequelize.config.ts +0 -59
- package/src/entities/Sequelize/Sequelize.test.ts +0 -21
- package/src/entities/Sequelize/Sequelize.ts +0 -75
- package/src/entities/Sequelize/Sequelize.types.ts +0 -10
- package/src/entities/Sequelize/Sequelize.validate.ts +0 -15
- package/src/entities/Sequelize/index.ts +0 -2
- package/src/entities/Server/Server.const.ts +0 -56
- package/src/entities/Server/Server.test.ts +0 -272
- package/src/entities/Server/Server.ts +0 -471
- package/src/entities/Server/Server.types.ts +0 -88
- package/src/entities/Server/index.ts +0 -2
- package/src/entities/SocketClient/SocketClient.test.ts +0 -392
- package/src/entities/SocketClient/SocketClient.ts +0 -401
- package/src/entities/SocketClient/SocketClient.types.ts +0 -62
- package/src/entities/SocketClient/index.ts +0 -2
- package/src/entities/SocketClient/parseMessage/index.ts +0 -1
- package/src/entities/SocketClient/parseMessage/parseMessage.test.ts +0 -20
- package/src/entities/SocketClient/parseMessage/parseMessage.ts +0 -26
- package/src/entities/Storage/Storage.test.ts +0 -58
- package/src/entities/Storage/Storage.ts +0 -219
- package/src/entities/Storage/Storage.types.ts +0 -57
- package/src/entities/Storage/index.ts +0 -2
- package/src/entities/ValidationError/ValidationError.ts +0 -34
- package/src/entities/ValidationError/index.ts +0 -1
- package/src/entities/WebError/WebError.test.ts +0 -18
- package/src/entities/WebError/WebError.ts +0 -23
- package/src/entities/WebError/WebError.types.ts +0 -9
- package/src/entities/WebError/index.ts +0 -2
- package/src/entities/index.ts +0 -16
- package/src/index.ts +0 -6
- package/src/metrics/debug.ts +0 -10
- package/src/metrics/index.ts +0 -2
- package/src/metrics/request.ts +0 -17
- package/src/middleware/authHmac/authHmac.test.ts +0 -86
- package/src/middleware/authHmac/authHmac.ts +0 -56
- package/src/middleware/authHmac/authHmac.types.ts +0 -7
- package/src/middleware/authHmac/index.ts +0 -2
- package/src/middleware/authJwt/authJwt.test.ts +0 -54
- package/src/middleware/authJwt/authJwt.ts +0 -55
- package/src/middleware/authJwt/authJwt.types.ts +0 -14
- package/src/middleware/authJwt/index.ts +0 -2
- package/src/middleware/authStatic/authStatic.test.ts +0 -36
- package/src/middleware/authStatic/authStatic.ts +0 -45
- package/src/middleware/authStatic/index.ts +0 -1
- package/src/middleware/authTls/authTls.test.ts +0 -138
- package/src/middleware/authTls/authTls.ts +0 -119
- package/src/middleware/authTls/authTls.types.ts +0 -13
- package/src/middleware/authTls/index.ts +0 -2
- package/src/middleware/checkPermission/checkPermission.ts +0 -33
- package/src/middleware/checkPermission/index.ts +0 -1
- package/src/middleware/error/error.test.ts +0 -60
- package/src/middleware/error/error.ts +0 -25
- package/src/middleware/error/index.ts +0 -1
- package/src/middleware/fileUploader/fileUploader.ts +0 -154
- package/src/middleware/fileUploader/fileUploader.types.ts +0 -35
- package/src/middleware/fileUploader/index.ts +0 -2
- package/src/middleware/fileUploader/isMultiPart/index.ts +0 -1
- package/src/middleware/fileUploader/isMultiPart/isMultipart.ts +0 -9
- package/src/middleware/fileUploader/validate/index.ts +0 -1
- package/src/middleware/fileUploader/validate/validate.ts +0 -27
- package/src/middleware/fourOhFour/fourOhFour.test.ts +0 -14
- package/src/middleware/fourOhFour/fourOhFour.ts +0 -13
- package/src/middleware/fourOhFour/index.ts +0 -1
- package/src/middleware/geminiFileUploader/geminiFileUploader.ts +0 -68
- package/src/middleware/geminiFileUploader/index.ts +0 -1
- package/src/middleware/healthCheck/healthCheck.test.ts +0 -12
- package/src/middleware/healthCheck/healthCheck.ts +0 -14
- package/src/middleware/healthCheck/index.ts +0 -1
- package/src/middleware/index.ts +0 -17
- package/src/middleware/metrics/index.ts +0 -1
- package/src/middleware/metrics/metrics.test.ts +0 -46
- package/src/middleware/metrics/metrics.ts +0 -24
- package/src/middleware/multiPartFileUploader/index.ts +0 -2
- package/src/middleware/multiPartFileUploader/multiPartFileUploader.ts +0 -249
- package/src/middleware/multiPartFileUploader/multiPartFileUploader.types.ts +0 -23
- package/src/middleware/multiPartFileUploader/validate/index.ts +0 -1
- package/src/middleware/multiPartFileUploader/validate/validate.ts +0 -27
- package/src/middleware/requestMetrics/index.ts +0 -1
- package/src/middleware/requestMetrics/requestMetrics.test.ts +0 -77
- package/src/middleware/requestMetrics/requestMetrics.ts +0 -20
- package/src/middleware/swaggerDocs/index.ts +0 -2
- package/src/middleware/swaggerDocs/swaggerDocs.ts +0 -114
- package/src/middleware/swaggerDocs/swaggerDocs.types.ts +0 -41
- package/src/middleware/userResolver/index.ts +0 -1
- package/src/middleware/userResolver/userResolver.ts +0 -53
- package/src/middleware/validate/index.ts +0 -1
- package/src/middleware/validate/validate.test.ts +0 -43
- package/src/middleware/validate/validate.ts +0 -25
- package/src/middleware/version/index.ts +0 -1
- package/src/middleware/version/version.test.ts +0 -23
- package/src/middleware/version/version.ts +0 -12
- package/src/utils/checkEnvironment/index.ts +0 -49
- package/src/utils/createHttpServer/createHttpServer.test.ts +0 -24
- package/src/utils/createHttpServer/createHttpServer.ts +0 -34
- package/src/utils/createHttpServer/createHttpServer.validate.ts +0 -17
- package/src/utils/createHttpServer/index.ts +0 -1
- package/src/utils/createSortedObject/createSortedObject.ts +0 -20
- package/src/utils/createSortedObject/createSortedObjet.test.ts +0 -47
- package/src/utils/createSortedObject/index.ts +0 -1
- package/src/utils/dbMigration/dbMigration.test.ts +0 -209
- package/src/utils/dbMigration/dbMigration.ts +0 -199
- package/src/utils/dbMigration/dbMigration.types.ts +0 -11
- package/src/utils/dbMigration/index.ts +0 -2
- package/src/utils/dbMigration/migrateMetadataTable/index.ts +0 -1
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.test.ts +0 -59
- package/src/utils/dbMigration/migrateMetadataTable/migrateMetadataTable.ts +0 -102
- package/src/utils/envAssert/envAssert.ts +0 -31
- package/src/utils/envAssert/index.ts +0 -1
- package/src/utils/envAssert/validators/hostList.ts +0 -17
- package/src/utils/envAssert/validators/index.ts +0 -5
- package/src/utils/envAssert/validators/ipList.ts +0 -13
- package/src/utils/envAssert/validators/path.ts +0 -13
- package/src/utils/envAssert/validators/string.ts +0 -9
- package/src/utils/envAssert/validators/stringList.ts +0 -13
- package/src/utils/filter/filter.ts +0 -17
- package/src/utils/filter/index.ts +0 -1
- package/src/utils/geminiFileUpload/geminiFileUpload.ts +0 -93
- package/src/utils/geminiFileUpload/index.ts +0 -1
- package/src/utils/hmac/checkEnv/checkEnv.test.ts +0 -18
- package/src/utils/hmac/checkEnv/checkEnv.ts +0 -9
- package/src/utils/hmac/checkEnv/index.ts +0 -1
- package/src/utils/hmac/createHmac/createHmac.ts +0 -33
- package/src/utils/hmac/createHmac/index.ts +0 -1
- package/src/utils/hmac/index.ts +0 -4
- package/src/utils/hmac/index.types.ts +0 -13
- package/src/utils/hmac/signPayload/index.ts +0 -1
- package/src/utils/hmac/signPayload/signPayload.ts +0 -16
- package/src/utils/hmac/verifySignature/index.ts +0 -1
- package/src/utils/hmac/verifySignature/verifySignature.ts +0 -24
- package/src/utils/index.ts +0 -29
- package/src/utils/jwt/index.ts +0 -2
- package/src/utils/jwt/jwt.test.ts +0 -28
- package/src/utils/jwt/jwt.ts +0 -182
- package/src/utils/jwt/jwt.types.ts +0 -21
- package/src/utils/report/index.ts +0 -3
- package/src/utils/report/output.ts +0 -45
- package/src/utils/report/output.types.ts +0 -70
- package/src/utils/report/report.test.ts +0 -133
- package/src/utils/report/report.ts +0 -133
- package/src/utils/report/report.types.ts +0 -13
- package/src/utils/request/index.ts +0 -1
- package/src/utils/request/request.test.ts +0 -26
- package/src/utils/request/request.ts +0 -48
- package/src/utils/secretManager/index.ts +0 -2
- package/src/utils/secretManager/secretLoader.ts +0 -62
- package/src/utils/secretManager/secretResolver.ts +0 -35
- package/src/utils/semverCompare/index.ts +0 -1
- package/src/utils/semverCompare/semverCompare.test.ts +0 -49
- package/src/utils/semverCompare/semverCompare.ts +0 -60
- package/src/utils/sendEmail/index.ts +0 -2
- package/src/utils/sendEmail/sendEmail.ts +0 -61
- package/src/utils/sendEmail/sendEmail.types.ts +0 -61
- package/src/utils/sendPush/index.ts +0 -2
- package/src/utils/sendPush/sendPush.ts +0 -20
- package/src/utils/sendPush/sendPush.types.ts +0 -25
- package/src/utils/tlsConfig/index.ts +0 -2
- package/src/utils/tlsConfig/tlsConfig.test.ts +0 -32
- package/src/utils/tlsConfig/tlsConfig.ts +0 -47
- package/src/utils/tlsConfig/tlsConfig.types.ts +0 -11
- package/src/utils/tlsConfig/tlsConfig.validate.ts +0 -25
- package/src/utils/tlsRequest/index.ts +0 -1
- package/src/utils/tlsRequest/tlsRequest.test.ts +0 -63
- package/src/utils/tlsRequest/tlsRequest.ts +0 -12
- package/src/utils/trimPathSlash/index.ts +0 -1
- package/src/utils/trimPathSlash/trimPathSlash.test.ts +0 -26
- package/src/utils/trimPathSlash/trimPathSlash.ts +0 -8
- package/test/env.ts +0 -53
- package/test/factory/index.ts +0 -8
- package/test/factory/sequelizeMeta.ts +0 -12
- package/test/hooks.ts +0 -35
- package/test/index.ts +0 -3
- package/test/stub/index.ts +0 -3
- package/test/stub/stubLocales.ts +0 -68
- package/test/stub/stubPubSub.ts +0 -7
- package/test/stub/stubStorage.ts +0 -77
- package/test/stub/stubStorage.types.ts +0 -11
- package/test/utils/app.ts +0 -31
- package/test/utils/index.ts +0 -1
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -32
package/test/env.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { faker } from '@faker-js/faker';
|
|
3
|
-
|
|
4
|
-
const audience = faker.internet.url();
|
|
5
|
-
|
|
6
|
-
/** Load a test environment */
|
|
7
|
-
process.env = {
|
|
8
|
-
SILENCE_REPORT: 'true',
|
|
9
|
-
// DEBUG: 'engine:*',
|
|
10
|
-
PORT: '3030',
|
|
11
|
-
SECONDARY_PORT: '3031',
|
|
12
|
-
NODE_ENV: 'test',
|
|
13
|
-
WEBSOCKET_CLOSE_TIMEOUT: '0',
|
|
14
|
-
JWT_SECRET: faker.lorem.word(),
|
|
15
|
-
PAYLOAD_SIGNATURE_SECRET: faker.lorem.word(),
|
|
16
|
-
ACCESS_TOKEN_AUDIENCE: audience,
|
|
17
|
-
ACCESS_TOKEN_ISSUER: faker.lorem.word(),
|
|
18
|
-
AUTH_SERVICE_PUBLIC_URL: faker.internet.url(),
|
|
19
|
-
VALID_IPS: '::ffff:127.0.0.1,127.0.0.1,::1',
|
|
20
|
-
REDIS_HOST: process.env.REDIS_HOST ?? '127.0.0.1',
|
|
21
|
-
REDIS_PORT: '6379',
|
|
22
|
-
REDIS_CLUSTER: 'false',
|
|
23
|
-
LOCALES_BUCKET: faker.lorem.word(),
|
|
24
|
-
USER_SERVICE_URL: faker.internet.url(),
|
|
25
|
-
PUBSUB_CACHE_TOPIC: faker.lorem.word(),
|
|
26
|
-
PUBSUB_EVENT_TOPIC: faker.lorem.word(),
|
|
27
|
-
TLS_SERVER_KEY: path.resolve('certs/server.key'),
|
|
28
|
-
TLS_SERVER_CERT: path.resolve('certs/server.crt'),
|
|
29
|
-
TLS_CA: path.resolve('certs/ca.crt'),
|
|
30
|
-
TLS_REQUEST_KEY_PASSPHRASE: path.resolve('certs/ecdsa.key.pub'),
|
|
31
|
-
ECDSA_PRIVATE_KEY: path.resolve('certs/ecdsa.key'),
|
|
32
|
-
ECDSA_PUBLIC_KEY: path.resolve('certs/ecdsa.key.pub'),
|
|
33
|
-
GITHUB_WEBHOOK_SECRET: faker.lorem.word(),
|
|
34
|
-
STATIC_TOKEN: faker.lorem.word(),
|
|
35
|
-
HOSTNAME: faker.lorem.slug(),
|
|
36
|
-
ELASTIC_SEARCH_HOST:
|
|
37
|
-
process.env.ELASTIC_SEARCH_HOST ?? 'http://localhost:9200/',
|
|
38
|
-
ELASTIC_SEARCH_USERNAME: 'elastic',
|
|
39
|
-
ELASTIC_SEARCH_PASSWORD: 'changeme',
|
|
40
|
-
ELASTIC_SEARCH_MIGRATION_PATH: faker.lorem.word(),
|
|
41
|
-
RUN_MIGRATION: 'false',
|
|
42
|
-
UNDO_MIGRATION: 'false',
|
|
43
|
-
SQL_HOST: process.env.SQL_HOST ?? '127.0.0.1',
|
|
44
|
-
SQL_PORT: '3306',
|
|
45
|
-
SQL_USER: 'tao',
|
|
46
|
-
SQL_PASSWORD: 'abc@123',
|
|
47
|
-
SQL_DB: 'testDb',
|
|
48
|
-
SQL_TYPE: 'mysql',
|
|
49
|
-
DEFAULT_MESSAGE_AUDIENCE: audience,
|
|
50
|
-
GOOGLE_AI_KEY: 'AIKEY',
|
|
51
|
-
ACCESS_TOKEN_EXPIRATION_TIME: '2000',
|
|
52
|
-
...process.env
|
|
53
|
-
};
|
package/test/factory/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { factory } from 'factory-waifu';
|
|
2
|
-
import { defineSequelizeMetaFactory } from './sequelizeMeta';
|
|
3
|
-
|
|
4
|
-
/** Generates and defines a factory object that can create all of our data models */
|
|
5
|
-
defineSequelizeMetaFactory(factory);
|
|
6
|
-
|
|
7
|
-
export default factory;
|
|
8
|
-
export { factory };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Factory } from 'factory-waifu';
|
|
2
|
-
import { faker } from '@faker-js/faker';
|
|
3
|
-
import { SequelizeMeta } from 'db/models';
|
|
4
|
-
|
|
5
|
-
/** Defines all the sequelize meta schematics for a factory */
|
|
6
|
-
export function defineSequelizeMetaFactory(factory: Factory): void {
|
|
7
|
-
factory.define('sequelizeMeta', SequelizeMeta, () => {
|
|
8
|
-
return {
|
|
9
|
-
name: faker.lorem.word()
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
}
|
package/test/hooks.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generatePkiEnvironment,
|
|
3
|
-
generateEcdsaKeyPair
|
|
4
|
-
} from 'backend-test-tools';
|
|
5
|
-
import chai from 'chai';
|
|
6
|
-
import chaiAsPromised from 'chai-as-promised';
|
|
7
|
-
import sinon from 'sinon';
|
|
8
|
-
import sinonChai from 'sinon-chai';
|
|
9
|
-
import { factory } from './factory';
|
|
10
|
-
import { sequelize } from 'entities/Sequelize';
|
|
11
|
-
import * as models from 'db/models';
|
|
12
|
-
|
|
13
|
-
chai.use(chaiAsPromised);
|
|
14
|
-
chai.use(sinonChai);
|
|
15
|
-
|
|
16
|
-
// Save a copy to revert the environment variables to their original state before each test
|
|
17
|
-
const savedEnv = { ...process.env };
|
|
18
|
-
const modelArray = Object.values(models);
|
|
19
|
-
|
|
20
|
-
before(async () => {
|
|
21
|
-
factory.init(sequelize);
|
|
22
|
-
generatePkiEnvironment();
|
|
23
|
-
generateEcdsaKeyPair();
|
|
24
|
-
sequelize.init();
|
|
25
|
-
sequelize.addModels(modelArray);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
process.env = { ...savedEnv };
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
afterEach(async () => {
|
|
33
|
-
sinon.restore();
|
|
34
|
-
await sequelize.shutdown();
|
|
35
|
-
});
|
package/test/index.ts
DELETED
package/test/stub/index.ts
DELETED
package/test/stub/stubLocales.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto';
|
|
2
|
-
import { faker } from '@faker-js/faker';
|
|
3
|
-
import sinon, { SinonStub } from 'sinon';
|
|
4
|
-
import { Storage } from 'entities/Storage/Storage';
|
|
5
|
-
import { StorageUploadedFile } from 'entities/Storage/Storage.types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Locales server stubbing
|
|
9
|
-
* Will return fake content based on paths
|
|
10
|
-
*/
|
|
11
|
-
export function stubLocales(): SinonStub {
|
|
12
|
-
return sinon
|
|
13
|
-
.stub(Storage, 'get')
|
|
14
|
-
.callsFake(async (bucket: string, path: string) => {
|
|
15
|
-
let content;
|
|
16
|
-
|
|
17
|
-
switch (path) {
|
|
18
|
-
case 'locales.json':
|
|
19
|
-
content = { 'en-US': 'English' };
|
|
20
|
-
break;
|
|
21
|
-
case 'index.json':
|
|
22
|
-
content = ['emails.json'];
|
|
23
|
-
break;
|
|
24
|
-
case 'localeData.json':
|
|
25
|
-
content = {
|
|
26
|
-
'en-US': {
|
|
27
|
-
enabled: true,
|
|
28
|
-
display: 'English',
|
|
29
|
-
names: {
|
|
30
|
-
firstNameFirst: true,
|
|
31
|
-
spacing: true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
break;
|
|
36
|
-
case 'scripts.json':
|
|
37
|
-
content = {};
|
|
38
|
-
break;
|
|
39
|
-
case 'en-US/emails.json':
|
|
40
|
-
content = {
|
|
41
|
-
welcome: {
|
|
42
|
-
subject: '🎊 {USER_FIRST_NAME} your account is ready!',
|
|
43
|
-
header: '{USER_FIRST_NAME}, your account is ready!',
|
|
44
|
-
body: 'Congratulations {USER_FIRST_NAME}!\n\nYou have successfully created an account with {USER_EMAIL}\n\nPlease return to the screen where you signed up, and you will be signed in.',
|
|
45
|
-
footer:
|
|
46
|
-
'This email was sent to {USER_EMAIL}.\nYou received this email because you successfully signed up.'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
break;
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(`No match for path '${path}' on locales server`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const metadata: StorageUploadedFile = {
|
|
55
|
-
bucket,
|
|
56
|
-
name: path,
|
|
57
|
-
contentType: faker.system.mimeType(),
|
|
58
|
-
size: `${faker.number.int()}`,
|
|
59
|
-
timeCreated: new Date().toISOString(),
|
|
60
|
-
updated: new Date().toISOString(),
|
|
61
|
-
md5Hash: randomBytes(32).toString('base64'),
|
|
62
|
-
crc32c: randomBytes(32).toString('base64'),
|
|
63
|
-
storageClass: 'normal'
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return { data: Buffer.from(JSON.stringify(content), 'utf-8'), metadata };
|
|
67
|
-
});
|
|
68
|
-
}
|
package/test/stub/stubPubSub.ts
DELETED
package/test/stub/stubStorage.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { randomUUID, randomBytes } from 'crypto';
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
import { CreateWriteStreamOptions } from '@google-cloud/storage';
|
|
4
|
-
import { faker } from '@faker-js/faker';
|
|
5
|
-
import { stub } from 'sinon';
|
|
6
|
-
import { StubbedStorage } from './stubStorage.types';
|
|
7
|
-
import { Storage } from 'entities/Storage/Storage';
|
|
8
|
-
import {
|
|
9
|
-
UploadDestinationOptions,
|
|
10
|
-
StorageUploadedFile
|
|
11
|
-
} from 'entities/Storage/Storage.types';
|
|
12
|
-
|
|
13
|
-
/** Create a stub for the Storage entity */
|
|
14
|
-
export function stubStorage(
|
|
15
|
-
uploadOverride: Partial<StorageUploadedFile> = {}
|
|
16
|
-
): StubbedStorage {
|
|
17
|
-
const upload = stub(Storage, 'upload').callsFake(
|
|
18
|
-
async (
|
|
19
|
-
readStream: Readable,
|
|
20
|
-
bucket: string,
|
|
21
|
-
destinationOptions: UploadDestinationOptions = {},
|
|
22
|
-
storageOptions: CreateWriteStreamOptions = {}
|
|
23
|
-
) => {
|
|
24
|
-
readStream.resume(); // Pause the stream
|
|
25
|
-
const path = Storage.generateFileDestination(destinationOptions);
|
|
26
|
-
return {
|
|
27
|
-
kind: 'storage#object',
|
|
28
|
-
id: `${bucket}/${path}/${randomUUID()}`,
|
|
29
|
-
selfLink: `https://www.googleapis.com/storage/v1/b/${bucket}/o/${encodeURIComponent(path)}`,
|
|
30
|
-
mediaLink: `https://storage.googleapis.com/download/storage/v1/b/${bucket}/o/${encodeURIComponent(
|
|
31
|
-
path
|
|
32
|
-
)}?generation=1610116408152540&alt=media`,
|
|
33
|
-
name: path,
|
|
34
|
-
bucket,
|
|
35
|
-
generation: randomUUID(),
|
|
36
|
-
metageneration: '1',
|
|
37
|
-
contentType: (
|
|
38
|
-
storageOptions.metadata as {
|
|
39
|
-
/** file type */
|
|
40
|
-
fileType: string;
|
|
41
|
-
}
|
|
42
|
-
)?.fileType,
|
|
43
|
-
storageClass: 'STANDARD',
|
|
44
|
-
size: '4',
|
|
45
|
-
md5Hash: 'CY9rzUYh03PK3k6DJie09g==',
|
|
46
|
-
crc32c: 'hqBywA==',
|
|
47
|
-
etag: 'CNyjuITHjO4CEAE=',
|
|
48
|
-
timeCreated: new Date().toISOString(),
|
|
49
|
-
updated: new Date().toISOString(),
|
|
50
|
-
timeStorageClassUpdated: new Date().toISOString(),
|
|
51
|
-
...uploadOverride
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
const remove = stub(Storage, 'delete').resolves();
|
|
56
|
-
|
|
57
|
-
const download = stub(Storage, 'download').callsFake(
|
|
58
|
-
async (bucket: string, path: string) => {
|
|
59
|
-
const stream = new Readable();
|
|
60
|
-
stream.push(faker.lorem.paragraph());
|
|
61
|
-
stream.push(null); // EOF
|
|
62
|
-
const metadata: StorageUploadedFile = {
|
|
63
|
-
bucket,
|
|
64
|
-
name: path,
|
|
65
|
-
contentType: faker.system.mimeType(),
|
|
66
|
-
size: `${faker.number.int()}`,
|
|
67
|
-
timeCreated: new Date().toISOString(),
|
|
68
|
-
updated: new Date().toISOString(),
|
|
69
|
-
md5Hash: randomBytes(32).toString('base64'),
|
|
70
|
-
crc32c: randomBytes(32).toString('base64'),
|
|
71
|
-
storageClass: 'normal'
|
|
72
|
-
};
|
|
73
|
-
return { stream, metadata };
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
return { upload, remove, download };
|
|
77
|
-
}
|
package/test/utils/app.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import express, { Application, Request, Response } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
Endpoint,
|
|
4
|
-
EndpointMethod,
|
|
5
|
-
EndpointOptions,
|
|
6
|
-
EndpointAuthType
|
|
7
|
-
} from 'entities/Endpoint';
|
|
8
|
-
import { error } from 'middleware';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create a test application with the given endpoint and error handling
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export function createTestApp(
|
|
15
|
-
config: Partial<EndpointOptions<EndpointAuthType.NONE>>
|
|
16
|
-
): Application {
|
|
17
|
-
const app = express();
|
|
18
|
-
const endpoint = new Endpoint({
|
|
19
|
-
path: '/test',
|
|
20
|
-
method: EndpointMethod.POST,
|
|
21
|
-
handler: (req: Request, res: Response): void => {
|
|
22
|
-
res.sendStatus(200);
|
|
23
|
-
},
|
|
24
|
-
authType: EndpointAuthType.NONE,
|
|
25
|
-
validator: {},
|
|
26
|
-
...config
|
|
27
|
-
});
|
|
28
|
-
endpoint.register(app);
|
|
29
|
-
app.use(error);
|
|
30
|
-
return app;
|
|
31
|
-
}
|
package/test/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './app';
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": "src",
|
|
4
|
-
"paths": {
|
|
5
|
-
"test": ["../test"],
|
|
6
|
-
"test/*": ["../test/*"]
|
|
7
|
-
},
|
|
8
|
-
"target": "ES6",
|
|
9
|
-
"lib": ["ES2023"],
|
|
10
|
-
"module": "commonjs",
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"outDir": "./dist",
|
|
13
|
-
"noImplicitAny": true,
|
|
14
|
-
"noImplicitThis": true,
|
|
15
|
-
"strictNullChecks": true,
|
|
16
|
-
"allowJs": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"esModuleInterop": true,
|
|
19
|
-
"allowSyntheticDefaultImports": true,
|
|
20
|
-
"strict": true,
|
|
21
|
-
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
23
|
-
"sourceMap": true,
|
|
24
|
-
"resolveJsonModule": true,
|
|
25
|
-
"isolatedModules": true,
|
|
26
|
-
"declaration": true,
|
|
27
|
-
"emitDeclarationOnly": true,
|
|
28
|
-
"experimentalDecorators": true,
|
|
29
|
-
"emitDecoratorMetadata": true
|
|
30
|
-
},
|
|
31
|
-
"include": ["src", "test"]
|
|
32
|
-
}
|