@appweaver/core 1.0.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/LICENSE +1 -0
- package/README.md +7 -0
- package/app/application.d.ts +43 -0
- package/app/application.js +112 -0
- package/app/create-app.d.ts +32 -0
- package/app/create-app.js +38 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +18 -0
- package/app/lifecycle-manager.d.ts +20 -0
- package/app/lifecycle-manager.js +42 -0
- package/app/load-modules.d.ts +10 -0
- package/app/load-modules.js +50 -0
- package/app/load-providers.d.ts +8 -0
- package/app/load-providers.js +33 -0
- package/cache/cache-service.d.ts +72 -0
- package/cache/cache-service.js +202 -0
- package/cache/cache.d.ts +12 -0
- package/cache/cache.js +184 -0
- package/cache/caching.d.ts +8 -0
- package/cache/caching.js +72 -0
- package/cache/eviction/eviction-index.d.ts +35 -0
- package/cache/eviction/eviction-index.js +2 -0
- package/cache/eviction/fifo-eviction-index.d.ts +7 -0
- package/cache/eviction/fifo-eviction-index.js +28 -0
- package/cache/eviction/index.d.ts +4 -0
- package/cache/eviction/index.js +20 -0
- package/cache/eviction/lfu-eviction-index.d.ts +8 -0
- package/cache/eviction/lfu-eviction-index.js +82 -0
- package/cache/eviction/lru-eviction-index.d.ts +8 -0
- package/cache/eviction/lru-eviction-index.js +81 -0
- package/cache/index.d.ts +2 -0
- package/cache/index.js +18 -0
- package/cache/memory-cache.d.ts +4 -0
- package/cache/memory-cache.js +12 -0
- package/cache/redis-cache.d.ts +4 -0
- package/cache/redis-cache.js +12 -0
- package/context/context.d.ts +2 -0
- package/context/context.js +13 -0
- package/context/dependency-injection.d.ts +98 -0
- package/context/dependency-injection.js +276 -0
- package/context/index.d.ts +2 -0
- package/context/index.js +18 -0
- package/database/create-client.d.ts +11 -0
- package/database/create-client.js +142 -0
- package/database/index.d.ts +1 -0
- package/database/index.js +17 -0
- package/database/prisma-database.d.ts +15 -0
- package/database/prisma-database.js +53 -0
- package/errors/error-handler.d.ts +3 -0
- package/errors/error-handler.js +24 -0
- package/errors/error-schema.d.ts +32 -0
- package/errors/error-schema.js +31 -0
- package/errors/http-error.d.ts +21 -0
- package/errors/http-error.js +33 -0
- package/errors/index.d.ts +3 -0
- package/errors/index.js +19 -0
- package/events/node-events.d.ts +7 -0
- package/events/node-events.js +39 -0
- package/export/export-service.d.ts +19 -0
- package/export/export-service.js +154 -0
- package/export/index.d.ts +1 -0
- package/export/index.js +17 -0
- package/factory/create-model.d.ts +2 -0
- package/factory/create-model.js +366 -0
- package/factory/create-policy.d.ts +2 -0
- package/factory/create-policy.js +16 -0
- package/factory/create-routes.d.ts +2 -0
- package/factory/create-routes.js +21 -0
- package/factory/create-service.d.ts +3 -0
- package/factory/create-service.js +97 -0
- package/factory/index.d.ts +4 -0
- package/factory/index.js +20 -0
- package/health/health-routes.d.ts +2 -0
- package/health/health-routes.js +36 -0
- package/health/health-schema.d.ts +45 -0
- package/health/health-schema.js +52 -0
- package/health/health-service.d.ts +38 -0
- package/health/health-service.js +82 -0
- package/health/index.d.ts +2 -0
- package/health/index.js +18 -0
- package/index.d.ts +15 -0
- package/index.js +31 -0
- package/mailer/email-service.d.ts +36 -0
- package/mailer/email-service.js +89 -0
- package/mailer/index.d.ts +1 -0
- package/mailer/index.js +17 -0
- package/mailer/json-mailer.d.ts +7 -0
- package/mailer/json-mailer.js +32 -0
- package/mailer/smtp-mailer.d.ts +7 -0
- package/mailer/smtp-mailer.js +43 -0
- package/memory/in-memory.d.ts +24 -0
- package/memory/in-memory.js +164 -0
- package/memory/redis.d.ts +26 -0
- package/memory/redis.js +158 -0
- package/package.json +68 -0
- package/prisma/client/browser.d.ts +34 -0
- package/prisma/client/browser.js +56 -0
- package/prisma/client/client.d.ts +53 -0
- package/prisma/client/client.js +70 -0
- package/prisma/client/commonInputTypes.d.ts +395 -0
- package/prisma/client/commonInputTypes.js +11 -0
- package/prisma/client/enums.d.ts +1 -0
- package/prisma/client/enums.js +11 -0
- package/prisma/client/internal/class.d.ts +187 -0
- package/prisma/client/internal/class.js +85 -0
- package/prisma/client/internal/prismaNamespace.d.ts +987 -0
- package/prisma/client/internal/prismaNamespace.js +193 -0
- package/prisma/client/internal/prismaNamespaceBrowser.d.ts +125 -0
- package/prisma/client/internal/prismaNamespaceBrowser.js +164 -0
- package/prisma/client/models/ApiKey.d.ts +1167 -0
- package/prisma/client/models/ApiKey.js +2 -0
- package/prisma/client/models/File.d.ts +1248 -0
- package/prisma/client/models/File.js +2 -0
- package/prisma/client/models/OneTimeToken.d.ts +1083 -0
- package/prisma/client/models/OneTimeToken.js +2 -0
- package/prisma/client/models/Permission.d.ts +1209 -0
- package/prisma/client/models/Permission.js +2 -0
- package/prisma/client/models/Role.d.ts +1209 -0
- package/prisma/client/models/Role.js +2 -0
- package/prisma/client/models/Seeder.d.ts +1023 -0
- package/prisma/client/models/Seeder.js +2 -0
- package/prisma/client/models.d.ts +7 -0
- package/prisma/client/models.js +2 -0
- package/queue/bull-queue.d.ts +37 -0
- package/queue/bull-queue.js +207 -0
- package/queue/memory-queue.d.ts +54 -0
- package/queue/memory-queue.js +283 -0
- package/resource/index.d.ts +4 -0
- package/resource/index.js +20 -0
- package/resource/resource-loader.d.ts +26 -0
- package/resource/resource-loader.js +161 -0
- package/resource/resource-routes.d.ts +3 -0
- package/resource/resource-routes.js +174 -0
- package/resource/resource-schema.d.ts +33 -0
- package/resource/resource-schema.js +186 -0
- package/resource/resource-service.d.ts +89 -0
- package/resource/resource-service.js +772 -0
- package/resources.d.ts +9 -0
- package/resources.js +24 -0
- package/scheduler/cron-scheduler.d.ts +12 -0
- package/scheduler/cron-scheduler.js +73 -0
- package/security/account/account-routes.d.ts +2 -0
- package/security/account/account-routes.js +104 -0
- package/security/account/account-schema.d.ts +290 -0
- package/security/account/account-schema.js +166 -0
- package/security/account/account-service.d.ts +88 -0
- package/security/account/account-service.js +218 -0
- package/security/account/index.d.ts +3 -0
- package/security/account/index.js +19 -0
- package/security/api-key/api-key-auth.d.ts +4 -0
- package/security/api-key/api-key-auth.js +66 -0
- package/security/api-key/index.d.ts +1 -0
- package/security/api-key/index.js +17 -0
- package/security/auth-routes.d.ts +2 -0
- package/security/auth-routes.js +80 -0
- package/security/auth-schema.d.ts +215 -0
- package/security/auth-schema.js +129 -0
- package/security/auth-service.d.ts +117 -0
- package/security/auth-service.js +272 -0
- package/security/auth.d.ts +3 -0
- package/security/auth.js +127 -0
- package/security/basic/basic-auth.d.ts +4 -0
- package/security/basic/basic-auth.js +32 -0
- package/security/basic/index.d.ts +1 -0
- package/security/basic/index.js +17 -0
- package/security/create-auth-resources.d.ts +6 -0
- package/security/create-auth-resources.js +129 -0
- package/security/helper.d.ts +127 -0
- package/security/helper.js +329 -0
- package/security/index.d.ts +4 -0
- package/security/index.js +20 -0
- package/security/jwt/index.d.ts +2 -0
- package/security/jwt/index.js +18 -0
- package/security/jwt/jwt-auth.d.ts +4 -0
- package/security/jwt/jwt-auth.js +57 -0
- package/security/jwt/jwt-keys.d.ts +7 -0
- package/security/jwt/jwt-keys.js +43 -0
- package/security/oauth2/create-oauth2-plugin.d.ts +17 -0
- package/security/oauth2/create-oauth2-plugin.js +85 -0
- package/security/oauth2/index.d.ts +3 -0
- package/security/oauth2/index.js +19 -0
- package/security/oauth2/oauth2-custom.d.ts +7 -0
- package/security/oauth2/oauth2-custom.js +40 -0
- package/security/oauth2/oauth2-facebook.d.ts +1 -0
- package/security/oauth2/oauth2-facebook.js +30 -0
- package/security/oauth2/oauth2-google.d.ts +1 -0
- package/security/oauth2/oauth2-google.js +28 -0
- package/security/oauth2/oauth2-schema.d.ts +10 -0
- package/security/oauth2/oauth2-schema.js +53 -0
- package/security/recaptcha/index.d.ts +2 -0
- package/security/recaptcha/index.js +18 -0
- package/security/recaptcha/recaptcha-verify.d.ts +1 -0
- package/security/recaptcha/recaptcha-verify.js +33 -0
- package/security/recaptcha/recaptcha.d.ts +2 -0
- package/security/recaptcha/recaptcha.js +22 -0
- package/security/resources/api-key/model.d.ts +2 -0
- package/security/resources/api-key/model.js +63 -0
- package/security/resources/api-key/policy.d.ts +2 -0
- package/security/resources/api-key/policy.js +26 -0
- package/security/resources/api-key/routes.d.ts +2 -0
- package/security/resources/api-key/routes.js +15 -0
- package/security/resources/api-key/service.d.ts +3 -0
- package/security/resources/api-key/service.js +33 -0
- package/security/resources/one-time-token/model.d.ts +2 -0
- package/security/resources/one-time-token/model.js +32 -0
- package/security/resources/permission/model.d.ts +2 -0
- package/security/resources/permission/model.js +16 -0
- package/security/resources/role/model.d.ts +2 -0
- package/security/resources/role/model.js +22 -0
- package/security/store/database-security-store.d.ts +5 -0
- package/security/store/database-security-store.js +51 -0
- package/security/store/redis-security-store.d.ts +5 -0
- package/security/store/redis-security-store.js +32 -0
- package/seeder/create-seeder.d.ts +21 -0
- package/seeder/create-seeder.js +17 -0
- package/seeder/index.d.ts +2 -0
- package/seeder/index.js +18 -0
- package/seeder/resources/seeder/model.d.ts +2 -0
- package/seeder/resources/seeder/model.js +38 -0
- package/seeder/seeder.d.ts +20 -0
- package/seeder/seeder.js +175 -0
- package/server/create-server.d.ts +20 -0
- package/server/create-server.js +160 -0
- package/server/index.d.ts +4 -0
- package/server/index.js +20 -0
- package/server/info-route.d.ts +2 -0
- package/server/info-route.js +18 -0
- package/server/info-schema.d.ts +37 -0
- package/server/info-schema.js +19 -0
- package/server/register-model.d.ts +2 -0
- package/server/register-model.js +12 -0
- package/server/register-plugin.d.ts +2 -0
- package/server/register-plugin.js +13 -0
- package/server/register-route.d.ts +3 -0
- package/server/register-route.js +74 -0
- package/server/schemas.d.ts +3 -0
- package/server/schemas.js +30 -0
- package/server/swagger.d.ts +3 -0
- package/server/swagger.js +122 -0
- package/storage/file-route.d.ts +2 -0
- package/storage/file-route.js +39 -0
- package/storage/file-schema.d.ts +9 -0
- package/storage/file-schema.js +42 -0
- package/storage/file-service.d.ts +81 -0
- package/storage/file-service.js +384 -0
- package/storage/filesystem-storage.d.ts +10 -0
- package/storage/filesystem-storage.js +128 -0
- package/storage/index.d.ts +2 -0
- package/storage/index.js +18 -0
- package/storage/resources/file/model.d.ts +2 -0
- package/storage/resources/file/model.js +75 -0
- package/types/application-context.d.ts +20 -0
- package/types/application-context.js +2 -0
- package/types/auth.d.ts +31 -0
- package/types/auth.js +2 -0
- package/types/fastify-extensions.d.ts +24 -0
- package/types/fastify-extensions.js +4 -0
- package/types/generated.d.ts +193 -0
- package/types/generated.js +3 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +20 -0
- package/types/server.d.ts +4 -0
- package/types/server.js +2 -0
- package/utils/export-util.d.ts +8 -0
- package/utils/export-util.js +25 -0
- package/utils/file-util.d.ts +64 -0
- package/utils/file-util.js +141 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +19 -0
- package/utils/schema-util.d.ts +20 -0
- package/utils/schema-util.js +37 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.healthReadySchema = exports.ReadyResponse = exports.HealthCheckCommonData = exports.HealthCheckResult = void 0;
|
|
4
|
+
exports.createHealthCheckSchema = createHealthCheckSchema;
|
|
5
|
+
const typebox_1 = require("@sinclair/typebox");
|
|
6
|
+
const common_1 = require("@appweaver/common");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
exports.HealthCheckResult = typebox_1.Type.Object({
|
|
10
|
+
status: (0, common_1.StringEnum)(common_1.HealthCheckStatus),
|
|
11
|
+
message: typebox_1.Type.Optional(typebox_1.Type.String())
|
|
12
|
+
});
|
|
13
|
+
exports.HealthCheckCommonData = typebox_1.Type.Object({
|
|
14
|
+
status: (0, common_1.StringEnum)(common_1.HealthCheckStatus),
|
|
15
|
+
timestamp: (0, common_1.StringDate)()
|
|
16
|
+
});
|
|
17
|
+
exports.ReadyResponse = typebox_1.Type.Object({
|
|
18
|
+
ready: typebox_1.Type.Boolean({ example: true })
|
|
19
|
+
}, { $id: 'HealthReadyResponse' });
|
|
20
|
+
exports.healthReadySchema = {
|
|
21
|
+
tags: ['Health'],
|
|
22
|
+
summary: 'Application ready status',
|
|
23
|
+
description: 'Application ready status',
|
|
24
|
+
response: {
|
|
25
|
+
200: (0, utils_1.createSchemaModel)(exports.ReadyResponse),
|
|
26
|
+
...errors_1.AllErrorResponses
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function createHealthCheckSchema(serviceNames) {
|
|
30
|
+
const healthChecks = {};
|
|
31
|
+
const healthCheckResult = (0, utils_1.createSchemaModel)(exports.HealthCheckResult, {
|
|
32
|
+
name: 'HealthCheckResult'
|
|
33
|
+
});
|
|
34
|
+
for (const service of serviceNames) {
|
|
35
|
+
healthChecks[service] = healthCheckResult;
|
|
36
|
+
}
|
|
37
|
+
const healthCheckResponse = (0, utils_1.createSchemaModel)(typebox_1.Type.Composite([
|
|
38
|
+
exports.HealthCheckCommonData,
|
|
39
|
+
typebox_1.Type.Object({ checks: typebox_1.Type.Object(healthChecks) })
|
|
40
|
+
], { $id: 'HealthCheckResponse' }));
|
|
41
|
+
return {
|
|
42
|
+
tags: ['Health'],
|
|
43
|
+
security: common_1.config.HEALTH_CHECK_AUTH ? [{ bearer: [] }] : [],
|
|
44
|
+
summary: 'Health check status',
|
|
45
|
+
description: 'Health check status',
|
|
46
|
+
response: {
|
|
47
|
+
200: healthCheckResponse,
|
|
48
|
+
503: healthCheckResponse,
|
|
49
|
+
...errors_1.AllErrorResponses
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HealthCheckConfig, HealthCheckStatus, IHealthCheck } from '@appweaver/common';
|
|
2
|
+
export type HealthCheckResponse = {
|
|
3
|
+
status: HealthCheckStatus;
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
export type HealthCheckInstance = {
|
|
7
|
+
name: string;
|
|
8
|
+
value: IHealthCheck;
|
|
9
|
+
config?: HealthCheckConfig;
|
|
10
|
+
};
|
|
11
|
+
export declare class HealthService {
|
|
12
|
+
/**
|
|
13
|
+
* Performs a health check for multiple health check instances by invoking their respective health check methods.
|
|
14
|
+
*
|
|
15
|
+
* @return {Promise<Record<string, HealthCheckResponse>>} A promise that resolves to an object where each key is the
|
|
16
|
+
* name of the instance, and the value is a health check response containing the instance status and, if applicable,
|
|
17
|
+
* its corresponding message.
|
|
18
|
+
*/
|
|
19
|
+
checkHealth(): Promise<Record<string, HealthCheckResponse>>;
|
|
20
|
+
/**
|
|
21
|
+
* Asynchronously checks the readiness status of a system or component.
|
|
22
|
+
*
|
|
23
|
+
* @return {Promise<boolean>} A promise that resolves to a boolean value indicating readiness status. Returns `true`
|
|
24
|
+
* if ready, otherwise `false`.
|
|
25
|
+
*/
|
|
26
|
+
checkReadiness(): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves a list of instances that implement the health check functionality, ensuring they are unique
|
|
29
|
+
* and properly configured. Each instance is returned with its name, instance, and optional configuration.
|
|
30
|
+
* Some instances can be removed from the list based on the configured pick and omit properties.
|
|
31
|
+
*
|
|
32
|
+
* @return {HealthCheckInstance[]} An array of objects, where each object contains:
|
|
33
|
+
* - `name`: The unique name assigned to the instance.
|
|
34
|
+
* - `value`: The instance value implementing the health check interface.
|
|
35
|
+
* - `config` (optional): Additional configuration details for the health check, if available.
|
|
36
|
+
*/
|
|
37
|
+
healthCheckInstances(): HealthCheckInstance[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HealthService = void 0;
|
|
4
|
+
const common_1 = require("@appweaver/common");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
class HealthService {
|
|
7
|
+
/**
|
|
8
|
+
* Performs a health check for multiple health check instances by invoking their respective health check methods.
|
|
9
|
+
*
|
|
10
|
+
* @return {Promise<Record<string, HealthCheckResponse>>} A promise that resolves to an object where each key is the
|
|
11
|
+
* name of the instance, and the value is a health check response containing the instance status and, if applicable,
|
|
12
|
+
* its corresponding message.
|
|
13
|
+
*/
|
|
14
|
+
async checkHealth() {
|
|
15
|
+
const healthCheckInstances = this.healthCheckInstances();
|
|
16
|
+
const hideMessages = [];
|
|
17
|
+
const healthChecks = {};
|
|
18
|
+
for (const instance of healthCheckInstances) {
|
|
19
|
+
healthChecks[instance.name] = instance.value.checkHealth();
|
|
20
|
+
if (instance.config?.showMessage === false) {
|
|
21
|
+
hideMessages.push(instance.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const checkResults = await Promise.all(Object.values(healthChecks));
|
|
25
|
+
const healthCheckResponse = Object.keys(healthChecks).reduce((acc, key, index) => {
|
|
26
|
+
acc[key] = {
|
|
27
|
+
status: checkResults[index].success
|
|
28
|
+
? common_1.HealthCheckStatus.Up
|
|
29
|
+
: common_1.HealthCheckStatus.Down,
|
|
30
|
+
message: !hideMessages[key] ? checkResults[index].message : undefined
|
|
31
|
+
};
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
common_1.logger.debug({ healthCheckResponse }, 'Health checks completed');
|
|
35
|
+
return healthCheckResponse;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Asynchronously checks the readiness status of a system or component.
|
|
39
|
+
*
|
|
40
|
+
* @return {Promise<boolean>} A promise that resolves to a boolean value indicating readiness status. Returns `true`
|
|
41
|
+
* if ready, otherwise `false`.
|
|
42
|
+
*/
|
|
43
|
+
async checkReadiness() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves a list of instances that implement the health check functionality, ensuring they are unique
|
|
48
|
+
* and properly configured. Each instance is returned with its name, instance, and optional configuration.
|
|
49
|
+
* Some instances can be removed from the list based on the configured pick and omit properties.
|
|
50
|
+
*
|
|
51
|
+
* @return {HealthCheckInstance[]} An array of objects, where each object contains:
|
|
52
|
+
* - `name`: The unique name assigned to the instance.
|
|
53
|
+
* - `value`: The instance value implementing the health check interface.
|
|
54
|
+
* - `config` (optional): Additional configuration details for the health check, if available.
|
|
55
|
+
*/
|
|
56
|
+
healthCheckInstances() {
|
|
57
|
+
const instances = (0, context_1.injectAllWhere)((def) => (0, common_1.isHealthCheck)(def.value));
|
|
58
|
+
// Return a unique set of instances that correctly implement the health check
|
|
59
|
+
let all = Array.from(new Map(instances.map((value) => {
|
|
60
|
+
const instanceConfig = value.checkHealthConfig?.();
|
|
61
|
+
const name = instanceConfig?.name || (0, common_1.uncapitalize)(value.constructor.name);
|
|
62
|
+
return [
|
|
63
|
+
name,
|
|
64
|
+
{
|
|
65
|
+
name,
|
|
66
|
+
value,
|
|
67
|
+
config: instanceConfig
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
})).values());
|
|
71
|
+
const pick = common_1.config.HEALTH_CHECK_PICK_INSTANCES;
|
|
72
|
+
if (pick) {
|
|
73
|
+
all = all.filter((instance) => pick.includes(instance.name));
|
|
74
|
+
}
|
|
75
|
+
const omit = common_1.config.HEALTH_CHECK_OMIT_INSTANCES;
|
|
76
|
+
if (omit) {
|
|
77
|
+
all = all.filter((instance) => !omit.includes(instance.name));
|
|
78
|
+
}
|
|
79
|
+
return all;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.HealthService = HealthService;
|
package/health/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./health-routes"), exports);
|
|
18
|
+
__exportStar(require("./health-service"), exports);
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './app';
|
|
2
|
+
export * from './context/dependency-injection';
|
|
3
|
+
export * from './errors';
|
|
4
|
+
export * from './export/export-service';
|
|
5
|
+
export * from './factory';
|
|
6
|
+
export * from './mailer/email-service';
|
|
7
|
+
export * from './database';
|
|
8
|
+
export * from './resource';
|
|
9
|
+
export * from './security';
|
|
10
|
+
export * from './seeder';
|
|
11
|
+
export * from './security/create-auth-resources';
|
|
12
|
+
export * from './server';
|
|
13
|
+
export * from './storage/file-service';
|
|
14
|
+
export * from './types';
|
|
15
|
+
export * from './utils';
|
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./app"), exports);
|
|
18
|
+
__exportStar(require("./context/dependency-injection"), exports);
|
|
19
|
+
__exportStar(require("./errors"), exports);
|
|
20
|
+
__exportStar(require("./export/export-service"), exports);
|
|
21
|
+
__exportStar(require("./factory"), exports);
|
|
22
|
+
__exportStar(require("./mailer/email-service"), exports);
|
|
23
|
+
__exportStar(require("./database"), exports);
|
|
24
|
+
__exportStar(require("./resource"), exports);
|
|
25
|
+
__exportStar(require("./security"), exports);
|
|
26
|
+
__exportStar(require("./seeder"), exports);
|
|
27
|
+
__exportStar(require("./security/create-auth-resources"), exports);
|
|
28
|
+
__exportStar(require("./server"), exports);
|
|
29
|
+
__exportStar(require("./storage/file-service"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Email } from '@appweaver/common';
|
|
2
|
+
export declare class EmailService {
|
|
3
|
+
constructor();
|
|
4
|
+
/**
|
|
5
|
+
* Sends an email by adding it to the mail queue for processing.
|
|
6
|
+
*
|
|
7
|
+
* @param {Email} email - The email object containing the details of the email to be sent.
|
|
8
|
+
* @return A promise that resolves when the email is successfully added to the queue.
|
|
9
|
+
*/
|
|
10
|
+
sendEmail(email: Email): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Sends bulk emails by queuing them for asynchronous processing.
|
|
13
|
+
*
|
|
14
|
+
* @param {Email[]} email - An array of email objects to be sent in bulk.
|
|
15
|
+
* @return {Promise<void>} A promise that resolves when the bulk email jobs are successfully queued.
|
|
16
|
+
*/
|
|
17
|
+
sendEmailBulk(email: Email[]): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Sends bulk emails and waits for all of them to finish.
|
|
20
|
+
*
|
|
21
|
+
* @param {Email[]} emails - An array of email objects to be sent.
|
|
22
|
+
* @return {Promise<{ success: boolean; error?: Error }[]>} A promise that resolves with an array of results, each
|
|
23
|
+
* containing `success` and an optional `error`.
|
|
24
|
+
*/
|
|
25
|
+
sendEmailBulkAndWait(emails: Email[]): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
error?: Error;
|
|
28
|
+
}[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Sends an email and waits for the sending process to finish.
|
|
31
|
+
*
|
|
32
|
+
* @param {Email} email - The email object containing the details of the email to be sent.
|
|
33
|
+
* @return A promise that resolves with `true` when the email is sent successfully, or rejects if sending fails.
|
|
34
|
+
*/
|
|
35
|
+
sendEmailAndWait(email: Email): Promise<boolean>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailService = void 0;
|
|
4
|
+
const common_1 = require("@appweaver/common");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
class EmailService {
|
|
7
|
+
/** @internal */
|
|
8
|
+
_mailer = (0, context_1.inject)(common_1.Mailer);
|
|
9
|
+
/** @internal */
|
|
10
|
+
_mailQueue = (0, context_1.inject)(common_1.Queue).get('email');
|
|
11
|
+
/** @internal */
|
|
12
|
+
_waitedJobs = new Map();
|
|
13
|
+
constructor() {
|
|
14
|
+
this._mailQueue.addWorker(this.processEmail.bind(this));
|
|
15
|
+
this._mailQueue.onCompleted(this.onEmailSent.bind(this));
|
|
16
|
+
this._mailQueue.onFailed(this.onEmailError.bind(this));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sends an email by adding it to the mail queue for processing.
|
|
20
|
+
*
|
|
21
|
+
* @param {Email} email - The email object containing the details of the email to be sent.
|
|
22
|
+
* @return A promise that resolves when the email is successfully added to the queue.
|
|
23
|
+
*/
|
|
24
|
+
async sendEmail(email) {
|
|
25
|
+
await this._mailQueue.sendJob(email);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sends bulk emails by queuing them for asynchronous processing.
|
|
29
|
+
*
|
|
30
|
+
* @param {Email[]} email - An array of email objects to be sent in bulk.
|
|
31
|
+
* @return {Promise<void>} A promise that resolves when the bulk email jobs are successfully queued.
|
|
32
|
+
*/
|
|
33
|
+
async sendEmailBulk(email) {
|
|
34
|
+
await this._mailQueue.sendBulkJobs(email.map((e) => ({ data: e })));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sends bulk emails and waits for all of them to finish.
|
|
38
|
+
*
|
|
39
|
+
* @param {Email[]} emails - An array of email objects to be sent.
|
|
40
|
+
* @return {Promise<{ success: boolean; error?: Error }[]>} A promise that resolves with an array of results, each
|
|
41
|
+
* containing `success` and an optional `error`.
|
|
42
|
+
*/
|
|
43
|
+
async sendEmailBulkAndWait(emails) {
|
|
44
|
+
const results = await Promise.allSettled(emails.map((email) => this.sendEmailAndWait(email)));
|
|
45
|
+
return results.map((result) => result.status === 'fulfilled'
|
|
46
|
+
? { success: true }
|
|
47
|
+
: { success: false, error: result.reason });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sends an email and waits for the sending process to finish.
|
|
51
|
+
*
|
|
52
|
+
* @param {Email} email - The email object containing the details of the email to be sent.
|
|
53
|
+
* @return A promise that resolves with `true` when the email is sent successfully, or rejects if sending fails.
|
|
54
|
+
*/
|
|
55
|
+
async sendEmailAndWait(email) {
|
|
56
|
+
const job = await this._mailQueue.sendJob(email);
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
if (!job.id) {
|
|
59
|
+
return reject(new Error('Email Job not found. Email could still be sent.'));
|
|
60
|
+
}
|
|
61
|
+
this._waitedJobs.set(job.id, { resolve, reject });
|
|
62
|
+
}).finally(() => {
|
|
63
|
+
if (job.id) {
|
|
64
|
+
this._waitedJobs.delete(job.id);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
async processEmail(job) {
|
|
70
|
+
return this._mailer.sendEmail(job.data);
|
|
71
|
+
}
|
|
72
|
+
/** @internal */
|
|
73
|
+
onEmailSent(job) {
|
|
74
|
+
if (job.id) {
|
|
75
|
+
const resolver = this._waitedJobs.get(job.id);
|
|
76
|
+
resolver?.resolve(true);
|
|
77
|
+
}
|
|
78
|
+
common_1.logger.debug(`E-mail '${job.data.subject}' sent successfully`);
|
|
79
|
+
}
|
|
80
|
+
/** @internal */
|
|
81
|
+
onEmailError(job, error) {
|
|
82
|
+
if (job?.id) {
|
|
83
|
+
const resolver = this._waitedJobs.get(job.id);
|
|
84
|
+
resolver?.reject(error);
|
|
85
|
+
}
|
|
86
|
+
common_1.logger.error(error, `E-mail '${job?.data.subject}' sending failed`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.EmailService = EmailService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './email-service';
|
package/mailer/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./email-service"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Attachment } from 'nodemailer/lib/mailer';
|
|
2
|
+
import { Email, HealthCheckResult, Mailer } from '@appweaver/common';
|
|
3
|
+
export declare class JsonMailer extends Mailer<Attachment> {
|
|
4
|
+
constructor();
|
|
5
|
+
sendEmail(data: Email): Promise<boolean>;
|
|
6
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonMailer = void 0;
|
|
4
|
+
const nodemailer_1 = require("nodemailer");
|
|
5
|
+
const common_1 = require("@appweaver/common");
|
|
6
|
+
class JsonMailer extends common_1.Mailer {
|
|
7
|
+
/** @internal */
|
|
8
|
+
_transporter;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._transporter = (0, nodemailer_1.createTransport)({
|
|
12
|
+
jsonTransport: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async sendEmail(data) {
|
|
16
|
+
const { to, subject, text, html, attachments } = data;
|
|
17
|
+
const msg = await this._transporter.sendMail({
|
|
18
|
+
from: `"${common_1.config.MAILER_SENDER_NAME}" <${common_1.config.MAILER_SENDER_ADDRESS}>`,
|
|
19
|
+
to,
|
|
20
|
+
subject,
|
|
21
|
+
text,
|
|
22
|
+
html: html ?? `<p style="white-space: pre;">${text}</p>`,
|
|
23
|
+
attachments
|
|
24
|
+
});
|
|
25
|
+
common_1.logger.info(JSON.parse(msg.message), `Mock E-mail`);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
async checkHealth() {
|
|
29
|
+
return { success: true };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.JsonMailer = JsonMailer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Attachment } from 'nodemailer/lib/mailer';
|
|
2
|
+
import { Email, HealthCheckResult, Mailer } from '@appweaver/common';
|
|
3
|
+
export declare class SmtpMailer extends Mailer<Attachment> {
|
|
4
|
+
constructor();
|
|
5
|
+
sendEmail(data: Email): Promise<boolean>;
|
|
6
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmtpMailer = void 0;
|
|
4
|
+
const nodemailer_1 = require("nodemailer");
|
|
5
|
+
const common_1 = require("@appweaver/common");
|
|
6
|
+
class SmtpMailer extends common_1.Mailer {
|
|
7
|
+
/** @internal */
|
|
8
|
+
_transporter;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._transporter = (0, nodemailer_1.createTransport)({
|
|
12
|
+
host: common_1.config.MAILER_SMTP_HOST,
|
|
13
|
+
port: common_1.config.MAILER_SMTP_PORT,
|
|
14
|
+
secure: common_1.config.MAILER_SMTP_SECURE,
|
|
15
|
+
auth: {
|
|
16
|
+
user: common_1.config.MAILER_SMTP_USER,
|
|
17
|
+
pass: common_1.config.MAILER_SMTP_PASSWORD
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async sendEmail(data) {
|
|
22
|
+
const { to, subject, text, html, attachments } = data;
|
|
23
|
+
await this._transporter.sendMail({
|
|
24
|
+
from: `"${common_1.config.MAILER_SENDER_NAME}" <${common_1.config.MAILER_SENDER_ADDRESS}>`,
|
|
25
|
+
to,
|
|
26
|
+
subject,
|
|
27
|
+
text,
|
|
28
|
+
html: html ?? `<p style="white-space: pre;">${text}</p>`,
|
|
29
|
+
attachments
|
|
30
|
+
});
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
async checkHealth() {
|
|
34
|
+
try {
|
|
35
|
+
const success = await this._transporter.verify();
|
|
36
|
+
return { success };
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return { success: false, message: e.message };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.SmtpMailer = SmtpMailer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HealthCheckResult, Memory } from '@appweaver/common';
|
|
2
|
+
export declare class InMemory extends Memory {
|
|
3
|
+
onInit(): Promise<void>;
|
|
4
|
+
onDestroy(): Promise<void>;
|
|
5
|
+
connect(): Promise<void>;
|
|
6
|
+
disconnect(): Promise<void>;
|
|
7
|
+
createClient(): undefined;
|
|
8
|
+
getValue<T = any>(key: string): Promise<T | null>;
|
|
9
|
+
putValue(key: string, value: any, expireMs?: number): Promise<boolean>;
|
|
10
|
+
hasKey(key: string): Promise<boolean>;
|
|
11
|
+
removeValue(key: string): Promise<boolean>;
|
|
12
|
+
removeEntries(query: string): Promise<number>;
|
|
13
|
+
findKeys(pattern?: string): Promise<Set<string>>;
|
|
14
|
+
valueSizeBytes(key: string): Promise<number | null>;
|
|
15
|
+
lock(resource: string, lockConfig?: {
|
|
16
|
+
expireMs?: number;
|
|
17
|
+
retryCount?: number;
|
|
18
|
+
retryDelay?: number;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
release: () => Promise<boolean>;
|
|
21
|
+
}>;
|
|
22
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
23
|
+
private cleanupExpired;
|
|
24
|
+
}
|