@acmekit/notification 2.13.1
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/README.md +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/providers.d.ts +5 -0
- package/dist/loaders/providers.d.ts.map +1 -0
- package/dist/loaders/providers.js +106 -0
- package/dist/loaders/providers.js.map +1 -0
- package/dist/migrations/Migration20240509083918_InitialSetupMigration.d.ts +5 -0
- package/dist/migrations/Migration20240509083918_InitialSetupMigration.d.ts.map +1 -0
- package/dist/migrations/Migration20240509083918_InitialSetupMigration.js +18 -0
- package/dist/migrations/Migration20240509083918_InitialSetupMigration.js.map +1 -0
- package/dist/migrations/Migration20240628075401.d.ts +5 -0
- package/dist/migrations/Migration20240628075401.d.ts.map +1 -0
- package/dist/migrations/Migration20240628075401.js +16 -0
- package/dist/migrations/Migration20240628075401.js.map +1 -0
- package/dist/migrations/Migration20240830094712.d.ts +6 -0
- package/dist/migrations/Migration20240830094712.d.ts.map +1 -0
- package/dist/migrations/Migration20240830094712.js +14 -0
- package/dist/migrations/Migration20240830094712.js.map +1 -0
- package/dist/migrations/Migration20250120110514.d.ts +6 -0
- package/dist/migrations/Migration20250120110514.d.ts.map +1 -0
- package/dist/migrations/Migration20250120110514.js +16 -0
- package/dist/migrations/Migration20250120110514.js.map +1 -0
- package/dist/migrations/Migration20251028172715.d.ts +6 -0
- package/dist/migrations/Migration20251028172715.d.ts.map +1 -0
- package/dist/migrations/Migration20251028172715.js +16 -0
- package/dist/migrations/Migration20251028172715.js.map +1 -0
- package/dist/migrations/Migration20251121123942.d.ts +6 -0
- package/dist/migrations/Migration20251121123942.d.ts.map +1 -0
- package/dist/migrations/Migration20251121123942.js +14 -0
- package/dist/migrations/Migration20251121123942.js.map +1 -0
- package/dist/migrations/Migration20251121150408.d.ts +6 -0
- package/dist/migrations/Migration20251121150408.d.ts.map +1 -0
- package/dist/migrations/Migration20251121150408.js +14 -0
- package/dist/migrations/Migration20251121150408.js.map +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +8 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/notification-provider.d.ts +26 -0
- package/dist/models/notification-provider.d.ts.map +1 -0
- package/dist/models/notification-provider.js +14 -0
- package/dist/models/notification-provider.js.map +1 -0
- package/dist/models/notification.d.ts +34 -0
- package/dist/models/notification.d.ts.map +1 -0
- package/dist/models/notification.js +39 -0
- package/dist/models/notification.js.map +1 -0
- package/dist/providers/acmekit-cloud-email.d.ts +11 -0
- package/dist/providers/acmekit-cloud-email.d.ts.map +1 -0
- package/dist/providers/acmekit-cloud-email.js +48 -0
- package/dist/providers/acmekit-cloud-email.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +11 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/notification-module-service.d.ts +26 -0
- package/dist/services/notification-module-service.d.ts.map +1 -0
- package/dist/services/notification-module-service.js +136 -0
- package/dist/services/notification-module-service.js.map +1 -0
- package/dist/services/notification-provider.d.ts +25 -0
- package/dist/services/notification-provider.d.ts.map +1 -0
- package/dist/services/notification-provider.js +67 -0
- package/dist/services/notification-provider.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +45 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Notification Module
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./types";
|
|
2
|
+
import { NotificationModuleService } from "./services";
|
|
3
|
+
declare const _default: import("@acmekit/types").ModuleExports<typeof NotificationModuleService> & {
|
|
4
|
+
linkable: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAA;AAChB,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;;;;AAIrD,wBAGE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
require("./types");
|
|
7
|
+
const _services_1 = require("./services");
|
|
8
|
+
const providers_1 = __importDefault(require("./loaders/providers"));
|
|
9
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
10
|
+
exports.default = (0, utils_1.Module)(utils_1.Modules.NOTIFICATION, {
|
|
11
|
+
service: _services_1.NotificationModuleService,
|
|
12
|
+
loaders: [providers_1.default],
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,mBAAgB;AAChB,yCAAqD;AACrD,oEAA+C;AAC/C,oDAA0D;AAE1D,kBAAe,IAAA,cAAM,EAAC,eAAO,CAAC,YAAY,EAAE;IAC1C,OAAO,EAAE,qCAAyB;IAClC,OAAO,EAAE,CAAC,mBAAa,CAAC;CACzB,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LoaderOptions, ModulesSdkTypes } from "@acmekit/framework/types";
|
|
2
|
+
import { NotificationModuleOptions } from "../types";
|
|
3
|
+
declare const _default: ({ container, options, }: LoaderOptions<(ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions) & NotificationModuleOptions>) => Promise<void>;
|
|
4
|
+
export default _default;
|
|
5
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/loaders/providers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAQzE,OAAO,EAEL,yBAAyB,EAE1B,MAAM,QAAQ,CAAA;yBAkCO,yBAGnB,aAAa,CACd,CACI,eAAe,CAAC,8BAA8B,GAC9C,eAAe,CAAC,6CAA6C,CAChE,GACC,yBAAyB,CAC5B,KAAG,OAAO,CAAC,IAAI,CAAC;AATjB,wBAgDC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const awilix_1 = require("@acmekit/framework/awilix");
|
|
4
|
+
const modules_sdk_1 = require("@acmekit/framework/modules-sdk");
|
|
5
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
6
|
+
const _services_1 = require("../services");
|
|
7
|
+
const _types_1 = require("../types");
|
|
8
|
+
const acmekit_cloud_email_1 = require("../providers/acmekit-cloud-email");
|
|
9
|
+
const validateCloudOptions = (options) => {
|
|
10
|
+
const { api_key, endpoint, environment_handle, sandbox_handle } = options ?? {};
|
|
11
|
+
if (!environment_handle && !sandbox_handle) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!api_key || !endpoint) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
const registrationFn = async (klass, container, pluginOptions) => {
|
|
20
|
+
container.register({
|
|
21
|
+
[_types_1.NotificationProviderRegistrationPrefix + pluginOptions.id]: (0, awilix_1.asFunction)((cradle) => new klass(cradle, pluginOptions.options ?? {}), {
|
|
22
|
+
lifetime: klass.LIFE_TIME || awilix_1.Lifetime.SINGLETON,
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
container.registerAdd(_types_1.NotificationIdentifiersRegistrationName, (0, awilix_1.asValue)(pluginOptions.id));
|
|
26
|
+
};
|
|
27
|
+
exports.default = async ({ container, options, }) => {
|
|
28
|
+
let providers = options?.providers || [];
|
|
29
|
+
// We add the AcmeKit Cloud Email provider if there is no other email provider configured
|
|
30
|
+
const hasEmailProvider = options?.providers?.some((provider) => provider.options?.channels?.some((channel) => channel === "email"));
|
|
31
|
+
if (!hasEmailProvider) {
|
|
32
|
+
const shouldRegisterAcmeKitCloudEmailProvider = validateCloudOptions(options?.cloud);
|
|
33
|
+
if (shouldRegisterAcmeKitCloudEmailProvider) {
|
|
34
|
+
await registrationFn(acmekit_cloud_email_1.AcmeKitCloudEmailNotificationProvider, container, {
|
|
35
|
+
options: options?.cloud,
|
|
36
|
+
id: "cloud",
|
|
37
|
+
});
|
|
38
|
+
const provider = {
|
|
39
|
+
id: "cloud",
|
|
40
|
+
resolve: "",
|
|
41
|
+
options: {
|
|
42
|
+
...options?.cloud,
|
|
43
|
+
channels: ["email"],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
providers = [...providers, provider];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
await (0, modules_sdk_1.moduleProviderLoader)({
|
|
50
|
+
container,
|
|
51
|
+
providers: options?.providers || [],
|
|
52
|
+
registerServiceFn: registrationFn,
|
|
53
|
+
});
|
|
54
|
+
await syncDatabaseProviders({
|
|
55
|
+
container,
|
|
56
|
+
providers: providers,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
async function syncDatabaseProviders({ container, providers, }) {
|
|
60
|
+
const providerServiceRegistrationKey = (0, utils_1.lowerCaseFirst)(_services_1.NotificationProviderService.name);
|
|
61
|
+
const providerService = container.resolve(providerServiceRegistrationKey);
|
|
62
|
+
const logger = container.resolve(utils_1.ContainerRegistrationKeys.LOGGER) ?? console;
|
|
63
|
+
const normalizedProviders = providers.map((provider) => {
|
|
64
|
+
if (!provider.id) {
|
|
65
|
+
throw new Error("An entry in the provider config is required to initialize notification providers");
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
id: provider.id,
|
|
69
|
+
handle: provider.id,
|
|
70
|
+
name: provider.id,
|
|
71
|
+
is_enabled: true,
|
|
72
|
+
channels: provider.options?.channels ?? [],
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
validateProviders(normalizedProviders);
|
|
76
|
+
try {
|
|
77
|
+
const providersInDb = await providerService.list({});
|
|
78
|
+
const providersToDisable = providersInDb.filter((dbProvider) => !normalizedProviders.some((normalizedProvider) => normalizedProvider.id === dbProvider.id));
|
|
79
|
+
const promises = [];
|
|
80
|
+
if (normalizedProviders.length) {
|
|
81
|
+
promises.push(providerService.upsert(normalizedProviders));
|
|
82
|
+
}
|
|
83
|
+
if (providersToDisable.length) {
|
|
84
|
+
promises.push(providerService.update(providersToDisable.map((p) => ({
|
|
85
|
+
id: p.id,
|
|
86
|
+
is_enabled: false,
|
|
87
|
+
}))));
|
|
88
|
+
}
|
|
89
|
+
await (0, utils_1.promiseAll)(promises);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger.error(`Error syncing the notification providers: ${error.message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function validateProviders(providers) {
|
|
96
|
+
const hasForChannel = {};
|
|
97
|
+
providers.forEach((provider) => {
|
|
98
|
+
provider.channels.forEach((channel) => {
|
|
99
|
+
if (hasForChannel[channel]) {
|
|
100
|
+
throw new Error(`Multiple providers are configured for the same channel: ${channel}`);
|
|
101
|
+
}
|
|
102
|
+
hasForChannel[channel] = true;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,6CAA6C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAmC;IAC5D,MAAM,aAAa,GAAG,EAAE,CAAA;IACxB,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC7B,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACpC,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,2DAA2D,OAAO,EAAE,CACrE,CAAA;YACH,CAAC;YACD,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;QAC/B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240509083918_InitialSetupMigration.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240509083918_InitialSetupMigration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,6CAA8C,SAAQ,SAAS;IACpE,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CAyB1B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20240509083918_InitialSetupMigration = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20240509083918_InitialSetupMigration extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql("drop table if exists notification");
|
|
8
|
+
this.addSql("drop table if exists notification_provider");
|
|
9
|
+
this.addSql('create table if not exists "notification_provider" ("id" text not null, "handle" text not null, "name" text not null, "is_enabled" boolean not null default true, "channels" text[] not null, constraint "notification_provider_pkey" primary key ("id"));');
|
|
10
|
+
this.addSql('create table if not exists "notification" ("id" text not null, "to" text not null, "channel" text not null, "template" text not null, "data" jsonb null, "trigger_type" text null, "resource_id" text null, "resource_type" text null, "receiver_id" text null, "original_notification_id" text null, "idempotency_key" text null, "external_id" text null, "provider_id" text null, "created_at" timestamptz not null default now(), constraint "notification_pkey" primary key ("id"));');
|
|
11
|
+
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_provider_id" ON "notification" (provider_id);');
|
|
12
|
+
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_idempotency_key" ON "notification" (idempotency_key);');
|
|
13
|
+
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_receiver_id" ON "notification" (receiver_id);');
|
|
14
|
+
this.addSql('alter table if exists "notification" add constraint "notification_provider_id_foreign" foreign key ("provider_id") references "notification_provider" ("id") on update cascade on delete set null;');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Migration20240509083918_InitialSetupMigration = Migration20240509083918_InitialSetupMigration;
|
|
18
|
+
//# sourceMappingURL=Migration20240509083918_InitialSetupMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240509083918_InitialSetupMigration.js","sourceRoot":"","sources":["../../src/migrations/Migration20240509083918_InitialSetupMigration.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,6CAA8C,SAAQ,sBAAS;IAC1E,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CAAC,mCAAmC,CAAC,CAAA;QAChD,IAAI,CAAC,MAAM,CAAC,4CAA4C,CAAC,CAAA;QAEzD,IAAI,CAAC,MAAM,CACT,4PAA4P,CAC7P,CAAA;QAED,IAAI,CAAC,MAAM,CACT,2dAA2d,CAC5d,CAAA;QACD,IAAI,CAAC,MAAM,CACT,4FAA4F,CAC7F,CAAA;QACD,IAAI,CAAC,MAAM,CACT,oGAAoG,CACrG,CAAA;QACD,IAAI,CAAC,MAAM,CACT,4FAA4F,CAC7F,CAAA;QAED,IAAI,CAAC,MAAM,CACT,oMAAoM,CACrM,CAAA;IACH,CAAC;CACF;AA1BD,sGA0BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240628075401.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240628075401.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CAmB1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20240628075401 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20240628075401 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql('alter table if exists "notification_provider" add column if not exists "created_at" timestamptz not null default now(), add column "updated_at" timestamptz not null default now(), add column "deleted_at" timestamptz null;');
|
|
8
|
+
this.addSql('alter table if exists "notification_provider" alter column "channels" type text[] using ("channels"::text[]);');
|
|
9
|
+
this.addSql('alter table if exists "notification_provider" alter column "channels" set default \'{}\';');
|
|
10
|
+
this.addSql('alter table if exists "notification" add column if not exists "updated_at" timestamptz not null default now(), add column "deleted_at" timestamptz null;');
|
|
11
|
+
this.addSql('drop index if exists "IDX_notification_idempotency_key";');
|
|
12
|
+
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_notification_idempotency_key_unique" ON "notification" (idempotency_key) WHERE deleted_at IS NULL;');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Migration20240628075401 = Migration20240628075401;
|
|
16
|
+
//# sourceMappingURL=Migration20240628075401.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240628075401.js","sourceRoot":"","sources":["../../src/migrations/Migration20240628075401.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,uBAAwB,SAAQ,sBAAS;IACpD,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CACT,+NAA+N,CAChO,CAAA;QACD,IAAI,CAAC,MAAM,CACT,+GAA+G,CAChH,CAAA;QACD,IAAI,CAAC,MAAM,CACT,2FAA2F,CAC5F,CAAA;QAED,IAAI,CAAC,MAAM,CACT,0JAA0J,CAC3J,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,0DAA0D,CAAC,CAAA;QACvE,IAAI,CAAC,MAAM,CACT,2IAA2I,CAC5I,CAAA;IACH,CAAC;CACF;AApBD,0DAoBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240830094712.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240830094712.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20240830094712 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20240830094712 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql("alter table if exists \"notification\" add column if not exists \"status\" text check (\"status\" in ('pending', 'success', 'failure')) not null default 'pending';");
|
|
8
|
+
}
|
|
9
|
+
async down() {
|
|
10
|
+
this.addSql('alter table if exists "notification" drop column if exists "status";');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Migration20240830094712 = Migration20240830094712;
|
|
14
|
+
//# sourceMappingURL=Migration20240830094712.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20240830094712.js","sourceRoot":"","sources":["../../src/migrations/Migration20240830094712.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,uBAAwB,SAAQ,sBAAS;IACpD,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CACT,qKAAqK,CACtK,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CACT,sEAAsE,CACvE,CAAA;IACH,CAAC;CACF;AAZD,0DAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20250120110514.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20250120110514.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,qBAAa,uBAAwB,SAAQ,SAAS;IAE9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAM5B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20250120110514 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20250120110514 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_provider_deleted_at" ON "notification_provider" (deleted_at) WHERE deleted_at IS NULL;');
|
|
8
|
+
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_notification_deleted_at" ON "notification" (deleted_at) WHERE deleted_at IS NULL;');
|
|
9
|
+
}
|
|
10
|
+
async down() {
|
|
11
|
+
this.addSql('drop index if exists "IDX_notification_provider_deleted_at";');
|
|
12
|
+
this.addSql('drop index if exists "IDX_notification_deleted_at";');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Migration20250120110514 = Migration20250120110514;
|
|
16
|
+
//# sourceMappingURL=Migration20250120110514.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20250120110514.js","sourceRoot":"","sources":["../../src/migrations/Migration20250120110514.ts"],"names":[],"mappings":";;;AAAA,wEAAoE;AAEpE,MAAa,uBAAwB,SAAQ,sBAAS;IAEpD,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CAAC,qIAAqI,CAAC,CAAC;QAEnJ,IAAI,CAAC,MAAM,CAAC,mHAAmH,CAAC,CAAC;IACnI,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CAAC,8DAA8D,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,CAAC,qDAAqD,CAAC,CAAC;IACrE,CAAC;CAEF;AAdD,0DAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251028172715.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20251028172715.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IASnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20251028172715 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20251028172715 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql(`alter table if exists "notification" alter column "template" type text using ("template"::text);`);
|
|
8
|
+
this.addSql(`alter table if exists "notification" alter column "template" drop not null;`);
|
|
9
|
+
}
|
|
10
|
+
async down() {
|
|
11
|
+
this.addSql(`alter table if exists "notification" alter column "template" type text using ("template"::text);`);
|
|
12
|
+
this.addSql(`alter table if exists "notification" alter column "template" set not null;`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Migration20251028172715 = Migration20251028172715;
|
|
16
|
+
//# sourceMappingURL=Migration20251028172715.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251028172715.js","sourceRoot":"","sources":["../../src/migrations/Migration20251028172715.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,uBAAwB,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,kGAAkG,CACnG,CAAA;QACD,IAAI,CAAC,MAAM,CACT,6EAA6E,CAC9E,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CACT,kGAAkG,CACnG,CAAA;QACD,IAAI,CAAC,MAAM,CACT,4EAA4E,CAC7E,CAAA;IACH,CAAC;CACF;AAlBD,0DAkBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251121123942.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20251121123942.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20251121123942 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20251121123942 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql(`alter table if exists "notification" add column if not exists "from" text null;`);
|
|
8
|
+
}
|
|
9
|
+
async down() {
|
|
10
|
+
this.addSql(`alter table if exists "notification" drop column if exists "from";`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Migration20251121123942 = Migration20251121123942;
|
|
14
|
+
//# sourceMappingURL=Migration20251121123942.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251121123942.js","sourceRoot":"","sources":["../../src/migrations/Migration20251121123942.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,uBAAwB,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,iFAAiF,CAClF,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CACT,oEAAoE,CACrE,CAAA;IACH,CAAC;CACF;AAZD,0DAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251121150408.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20251121150408.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAEnE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20251121150408 = void 0;
|
|
4
|
+
const migrations_1 = require("@acmekit/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20251121150408 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql(`alter table if exists "notification" add column if not exists "provider_data" jsonb null;`);
|
|
8
|
+
}
|
|
9
|
+
async down() {
|
|
10
|
+
this.addSql(`alter table if exists "notification" drop column if exists "provider_data";`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Migration20251121150408 = Migration20251121150408;
|
|
14
|
+
//# sourceMappingURL=Migration20251121150408.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251121150408.js","sourceRoot":"","sources":["../../src/migrations/Migration20251121150408.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AAEnE,MAAa,uBAAwB,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,2FAA2F,CAC5F,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CACT,6EAA6E,CAC9E,CAAA;IACH,CAAC;CACF;AAZD,0DAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationProvider = exports.Notification = void 0;
|
|
4
|
+
var notification_1 = require("./notification");
|
|
5
|
+
Object.defineProperty(exports, "Notification", { enumerable: true, get: function () { return notification_1.Notification; } });
|
|
6
|
+
var notification_provider_1 = require("./notification-provider");
|
|
7
|
+
Object.defineProperty(exports, "NotificationProvider", { enumerable: true, get: function () { return notification_provider_1.NotificationProvider; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,iEAA8D;AAArD,6HAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const NotificationProvider: import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder<{
|
|
2
|
+
id: import("@acmekit/framework/utils").PrimaryKeyModifier<string, import("@acmekit/framework/utils").IdProperty>;
|
|
3
|
+
handle: import("@acmekit/framework/utils").TextProperty;
|
|
4
|
+
name: import("@acmekit/framework/utils").TextProperty;
|
|
5
|
+
is_enabled: import("@acmekit/framework/utils").BooleanProperty;
|
|
6
|
+
channels: import("@acmekit/framework/utils").ArrayProperty;
|
|
7
|
+
notifications: import("@acmekit/framework/utils").HasMany<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder<{
|
|
8
|
+
id: import("@acmekit/framework/utils").PrimaryKeyModifier<string, import("@acmekit/framework/utils").IdProperty>;
|
|
9
|
+
to: import("@acmekit/framework/utils").TextProperty;
|
|
10
|
+
from: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
11
|
+
channel: import("@acmekit/framework/utils").TextProperty;
|
|
12
|
+
template: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
13
|
+
data: import("@acmekit/framework/utils").NullableModifier<Record<string, unknown>, import("@acmekit/framework/utils").JSONProperty>;
|
|
14
|
+
provider_data: import("@acmekit/framework/utils").NullableModifier<Record<string, unknown>, import("@acmekit/framework/utils").JSONProperty>;
|
|
15
|
+
trigger_type: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
16
|
+
resource_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
17
|
+
resource_type: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
18
|
+
receiver_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
19
|
+
original_notification_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
20
|
+
idempotency_key: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
21
|
+
external_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
22
|
+
status: import("@acmekit/framework/utils").EnumProperty<typeof import("@acmekit/framework/utils").NotificationStatus>;
|
|
23
|
+
provider: import("@acmekit/framework/utils").RelationNullableModifier<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "notificationProvider">, import("@acmekit/framework/utils").BelongsTo<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "notificationProvider">, undefined>, true>;
|
|
24
|
+
}>, "notification">>;
|
|
25
|
+
}>, "notificationProvider">;
|
|
26
|
+
//# sourceMappingURL=notification-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-provider.d.ts","sourceRoot":"","sources":["../../src/models/notification-provider.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;2BAO/B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationProvider = void 0;
|
|
4
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
5
|
+
const notification_1 = require("./notification");
|
|
6
|
+
exports.NotificationProvider = utils_1.model.define("notificationProvider", {
|
|
7
|
+
id: utils_1.model.id({ prefix: "notpro" }).primaryKey(),
|
|
8
|
+
handle: utils_1.model.text(),
|
|
9
|
+
name: utils_1.model.text(),
|
|
10
|
+
is_enabled: utils_1.model.boolean().default(true),
|
|
11
|
+
channels: utils_1.model.array().default([]),
|
|
12
|
+
notifications: utils_1.model.hasMany(() => notification_1.Notification, { mappedBy: "provider" }),
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=notification-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-provider.js","sourceRoot":"","sources":["../../src/models/notification-provider.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAChD,iDAA6C;AAEhC,QAAA,oBAAoB,GAAG,aAAK,CAAC,MAAM,CAAC,sBAAsB,EAAE;IACvE,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,UAAU,EAAE;IAC/C,MAAM,EAAE,aAAK,CAAC,IAAI,EAAE;IACpB,IAAI,EAAE,aAAK,CAAC,IAAI,EAAE;IAClB,UAAU,EAAE,aAAK,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACzC,QAAQ,EAAE,aAAK,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACnC,aAAa,EAAE,aAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,2BAAY,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;CAC3E,CAAC,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NotificationStatus } from "@acmekit/framework/utils";
|
|
2
|
+
export declare const Notification: import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder<{
|
|
3
|
+
id: import("@acmekit/framework/utils").PrimaryKeyModifier<string, import("@acmekit/framework/utils").IdProperty>;
|
|
4
|
+
to: import("@acmekit/framework/utils").TextProperty;
|
|
5
|
+
from: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
6
|
+
channel: import("@acmekit/framework/utils").TextProperty;
|
|
7
|
+
template: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
8
|
+
data: import("@acmekit/framework/utils").NullableModifier<Record<string, unknown>, import("@acmekit/framework/utils").JSONProperty>;
|
|
9
|
+
provider_data: import("@acmekit/framework/utils").NullableModifier<Record<string, unknown>, import("@acmekit/framework/utils").JSONProperty>;
|
|
10
|
+
trigger_type: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
11
|
+
resource_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
12
|
+
resource_type: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
13
|
+
receiver_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
14
|
+
original_notification_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
15
|
+
idempotency_key: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
16
|
+
external_id: import("@acmekit/framework/utils").NullableModifier<string, import("@acmekit/framework/utils").TextProperty>;
|
|
17
|
+
status: import("@acmekit/framework/utils").EnumProperty<typeof NotificationStatus>;
|
|
18
|
+
provider: import("@acmekit/framework/utils").RelationNullableModifier<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder<{
|
|
19
|
+
id: import("@acmekit/framework/utils").PrimaryKeyModifier<string, import("@acmekit/framework/utils").IdProperty>;
|
|
20
|
+
handle: import("@acmekit/framework/utils").TextProperty;
|
|
21
|
+
name: import("@acmekit/framework/utils").TextProperty;
|
|
22
|
+
is_enabled: import("@acmekit/framework/utils").BooleanProperty;
|
|
23
|
+
channels: import("@acmekit/framework/utils").ArrayProperty;
|
|
24
|
+
notifications: import("@acmekit/framework/utils").HasMany<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "notification">>;
|
|
25
|
+
}>, "notificationProvider">, import("@acmekit/framework/utils").BelongsTo<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder<{
|
|
26
|
+
id: import("@acmekit/framework/utils").PrimaryKeyModifier<string, import("@acmekit/framework/utils").IdProperty>;
|
|
27
|
+
handle: import("@acmekit/framework/utils").TextProperty;
|
|
28
|
+
name: import("@acmekit/framework/utils").TextProperty;
|
|
29
|
+
is_enabled: import("@acmekit/framework/utils").BooleanProperty;
|
|
30
|
+
channels: import("@acmekit/framework/utils").ArrayProperty;
|
|
31
|
+
notifications: import("@acmekit/framework/utils").HasMany<() => import("@acmekit/framework/utils").DmlEntity<import("@acmekit/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "notification">>;
|
|
32
|
+
}>, "notificationProvider">, undefined>, true>;
|
|
33
|
+
}>, "notification">;
|
|
34
|
+
//# sourceMappingURL=notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/models/notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAIpE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAgCvB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Notification = void 0;
|
|
4
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
5
|
+
const notification_provider_1 = require("./notification-provider");
|
|
6
|
+
// We probably want to have a TTL for each entry, so we don't bloat the DB (and also for GDPR reasons if TTL < 30 days).
|
|
7
|
+
exports.Notification = utils_1.model.define("notification", {
|
|
8
|
+
id: utils_1.model.id({ prefix: "noti" }).primaryKey(),
|
|
9
|
+
// This can be an email, phone number, or username, depending on the channel.
|
|
10
|
+
to: utils_1.model.text().searchable(),
|
|
11
|
+
// This can be an email, phone number, or username, depending on the channel.
|
|
12
|
+
from: utils_1.model.text().searchable().nullable(),
|
|
13
|
+
channel: utils_1.model.text(),
|
|
14
|
+
// The template name in the provider's system.
|
|
15
|
+
template: utils_1.model.text().nullable(),
|
|
16
|
+
// The data that gets passed over to the provider for rendering the notification.
|
|
17
|
+
data: utils_1.model.json().nullable(),
|
|
18
|
+
// Additional data specific to the channel or provider. For example, cc and bcc for emails.
|
|
19
|
+
provider_data: utils_1.model.json().nullable(),
|
|
20
|
+
// This can be the event name, the workflow, or anything else that can help to identify what triggered the notification.
|
|
21
|
+
trigger_type: utils_1.model.text().nullable(),
|
|
22
|
+
// The ID of the resource this notification is for, if applicable. Useful for displaying relevant information in the UI
|
|
23
|
+
resource_id: utils_1.model.text().searchable().nullable(),
|
|
24
|
+
// The typeame of the resource this notification is for, if applicable, eg. "order"
|
|
25
|
+
resource_type: utils_1.model.text().nullable(),
|
|
26
|
+
// The ID of the receiver of the notification, if applicable. This can be a customer, user, a company, or anything else.
|
|
27
|
+
receiver_id: utils_1.model.text().index().nullable(),
|
|
28
|
+
// The original notification, in case this is a retried notification.
|
|
29
|
+
original_notification_id: utils_1.model.text().nullable(),
|
|
30
|
+
idempotency_key: utils_1.model.text().unique().nullable(),
|
|
31
|
+
// The ID of the notification in the external system, if applicable
|
|
32
|
+
external_id: utils_1.model.text().nullable(),
|
|
33
|
+
// The status of the notification
|
|
34
|
+
status: utils_1.model.enum(utils_1.NotificationStatus).default(utils_1.NotificationStatus.PENDING),
|
|
35
|
+
provider: utils_1.model
|
|
36
|
+
.belongsTo(() => notification_provider_1.NotificationProvider, { mappedBy: "notifications" })
|
|
37
|
+
.nullable(),
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/models/notification.ts"],"names":[],"mappings":";;;AAAA,oDAAoE;AACpE,mEAA8D;AAE9D,wHAAwH;AAC3G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BAAkB,CAAC,CAAC,OAAO,CAAC,0BAAkB,CAAC,OAAO,CAAC;IAE1E,QAAQ,EAAE,aAAK;SACZ,SAAS,CAAC,GAAG,EAAE,CAAC,4CAAoB,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;SACpE,QAAQ,EAAE;CACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger, NotificationTypes } from "@acmekit/framework/types";
|
|
2
|
+
import { AbstractNotificationProviderService } from "@acmekit/framework/utils";
|
|
3
|
+
import { AcmeKitCloudEmailOptions } from "../types";
|
|
4
|
+
export declare class AcmeKitCloudEmailNotificationProvider extends AbstractNotificationProviderService {
|
|
5
|
+
static identifier: string;
|
|
6
|
+
protected options_: AcmeKitCloudEmailOptions;
|
|
7
|
+
protected logger_: Logger;
|
|
8
|
+
constructor({}: {}, options: AcmeKitCloudEmailOptions);
|
|
9
|
+
send(notification: NotificationTypes.ProviderSendNotificationDTO): Promise<NotificationTypes.ProviderSendNotificationResultsDTO>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=acmekit-cloud-email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acmekit-cloud-email.d.ts","sourceRoot":"","sources":["../../src/providers/acmekit-cloud-email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAA;AAEjD,qBAAa,qCAAsC,SAAQ,mCAAmC;IAC5F,MAAM,CAAC,UAAU,SAAqC;IACtD,SAAS,CAAC,QAAQ,EAAE,wBAAwB,CAAA;IAC5C,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAEb,EAAE,IAAA,EAAE,OAAO,EAAE,wBAAwB;IAM3C,IAAI,CACR,YAAY,EAAE,iBAAiB,CAAC,2BAA2B,GAC1D,OAAO,CAAC,iBAAiB,CAAC,kCAAkC,CAAC;CAyCjE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AcmeKitCloudEmailNotificationProvider = void 0;
|
|
4
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
5
|
+
class AcmeKitCloudEmailNotificationProvider extends utils_1.AbstractNotificationProviderService {
|
|
6
|
+
constructor({}, options) {
|
|
7
|
+
super();
|
|
8
|
+
this.options_ = options;
|
|
9
|
+
}
|
|
10
|
+
async send(notification) {
|
|
11
|
+
const headers = {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
Authorization: `Basic ${this.options_.api_key}`,
|
|
14
|
+
};
|
|
15
|
+
if (this.options_.sandbox_handle) {
|
|
16
|
+
headers["x-acmekit-sandbox-handle"] = this.options_.sandbox_handle;
|
|
17
|
+
}
|
|
18
|
+
if (this.options_.environment_handle) {
|
|
19
|
+
headers["x-acmekit-environment-handle"] = this.options_.environment_handle;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(`${this.options_.endpoint}/send`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers,
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
to: notification.to,
|
|
27
|
+
from: notification.from,
|
|
28
|
+
attachments: notification.attachments,
|
|
29
|
+
template: notification.template,
|
|
30
|
+
data: notification.data,
|
|
31
|
+
provider_data: notification.provider_data,
|
|
32
|
+
content: notification.content,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
const responseBody = await response.json();
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new Error(`Failed to send email: ${response.status} - ${response.statusText}: ${responseBody.message}`);
|
|
38
|
+
}
|
|
39
|
+
return { id: responseBody.id };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Failed to send email: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AcmeKitCloudEmailNotificationProvider = AcmeKitCloudEmailNotificationProvider;
|
|
47
|
+
AcmeKitCloudEmailNotificationProvider.identifier = "notification-acmekit-cloud-email";
|
|
48
|
+
//# sourceMappingURL=acmekit-cloud-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acmekit-cloud-email.js","sourceRoot":"","sources":["../../src/providers/acmekit-cloud-email.ts"],"names":[],"mappings":";;;AACA,oDAA8E;AAG9E,MAAa,qCAAsC,SAAQ,2CAAmC;IAK5F,YAAY,EAAE,EAAE,OAAiC;QAC/C,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,YAA2D;QAE3D,MAAM,OAAO,GAAG;YACd,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,SAAS,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;SAChD,CAAA;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;YACjC,OAAO,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAA;QACpE,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;YACrC,OAAO,CAAC,8BAA8B,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAA;QAC5E,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,OAAO,EAAE;gBAC7D,MAAM,EAAE,MAAM;gBACd,OAAO;gBACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,EAAE,EAAE,YAAY,CAAC,EAAE;oBACnB,IAAI,EAAE,YAAY,CAAC,IAAI;oBACvB,WAAW,EAAE,YAAY,CAAC,WAAW;oBACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;oBAC/B,IAAI,EAAE,YAAY,CAAC,IAAI;oBACvB,aAAa,EAAE,YAAY,CAAC,aAAa;oBACzC,OAAO,EAAE,YAAY,CAAC,OAAO;iBAC9B,CAAC;aACH,CAAC,CAAA;YACF,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAE1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,yBAAyB,QAAQ,CAAC,MAAM,MAAM,QAAQ,CAAC,UAAU,KAAK,YAAY,CAAC,OAAO,EAAE,CAC7F,CAAA;YACH,CAAC;YAED,OAAO,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,CAAA;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;;AArDH,sFAsDC;AArDQ,gDAAU,GAAG,kCAAkC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AACpF,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NotificationProviderService = exports.NotificationModuleService = void 0;
|
|
7
|
+
var notification_module_service_1 = require("./notification-module-service");
|
|
8
|
+
Object.defineProperty(exports, "NotificationModuleService", { enumerable: true, get: function () { return __importDefault(notification_module_service_1).default; } });
|
|
9
|
+
var notification_provider_1 = require("./notification-provider");
|
|
10
|
+
Object.defineProperty(exports, "NotificationProviderService", { enumerable: true, get: function () { return __importDefault(notification_provider_1).default; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,6EAAoF;AAA3E,yJAAA,OAAO,OAA6B;AAC7C,iEAAgF;AAAvE,qJAAA,OAAO,OAA+B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context, DAL, InferEntityType, INotificationModuleService, InternalModuleDeclaration, Logger, ModulesSdkTypes, NotificationTypes } from "@acmekit/framework/types";
|
|
2
|
+
import { Notification } from "../models";
|
|
3
|
+
import NotificationProviderService from "./notification-provider";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
logger?: Logger;
|
|
6
|
+
baseRepository: DAL.RepositoryService;
|
|
7
|
+
notificationService: ModulesSdkTypes.IAcmeKitInternalService<typeof Notification>;
|
|
8
|
+
notificationProviderService: NotificationProviderService;
|
|
9
|
+
};
|
|
10
|
+
declare const NotificationModuleService_base: import("@acmekit/framework/utils").AcmeKitServiceReturnType<{
|
|
11
|
+
Notification: {
|
|
12
|
+
dto: NotificationTypes.NotificationDTO;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export default class NotificationModuleService extends NotificationModuleService_base implements INotificationModuleService {
|
|
16
|
+
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
17
|
+
protected baseRepository_: DAL.RepositoryService;
|
|
18
|
+
protected readonly notificationService_: ModulesSdkTypes.IAcmeKitInternalService<typeof Notification>;
|
|
19
|
+
protected readonly notificationProviderService_: NotificationProviderService;
|
|
20
|
+
constructor({ baseRepository, notificationService, notificationProviderService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
21
|
+
createNotifications(data: NotificationTypes.CreateNotificationDTO[], sharedContext?: Context): Promise<NotificationTypes.NotificationDTO[]>;
|
|
22
|
+
createNotifications(data: NotificationTypes.CreateNotificationDTO, sharedContext?: Context): Promise<NotificationTypes.NotificationDTO>;
|
|
23
|
+
protected createNotifications_(data: NotificationTypes.CreateNotificationDTO[], sharedContext?: Context): Promise<InferEntityType<typeof Notification>[]>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=notification-module-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-module-service.d.ts","sourceRoot":"","sources":["../../src/services/notification-module-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,eAAe,EACf,0BAA0B,EAC1B,yBAAyB,EACzB,MAAM,EACN,eAAe,EACf,iBAAiB,EAClB,MAAM,0BAA0B,CAAA;AAWjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,2BAA2B,MAAM,yBAAyB,CAAA;AAEjE,KAAK,oBAAoB,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,mBAAmB,EAAE,eAAe,CAAC,uBAAuB,CAC1D,OAAO,YAAY,CACpB,CAAA;IACD,2BAA2B,EAAE,2BAA2B,CAAA;CACzD,CAAA;;kBAIiB;QAAE,GAAG,EAAE,iBAAiB,CAAC,eAAe,CAAA;KAAE;;AAF5D,MAAM,CAAC,OAAO,OAAO,yBACnB,SAAQ,8BAGR,YAAW,0BAA0B;IAcnC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB;IAZjE,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,CAAA;IAChD,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,eAAe,CAAC,uBAAuB,CAC9E,OAAO,YAAY,CACpB,CAAA;IACD,SAAS,CAAC,QAAQ,CAAC,4BAA4B,EAAE,2BAA2B,CAAA;gBAG1E,EACE,cAAc,EACd,mBAAmB,EACnB,2BAA2B,GAC5B,EAAE,oBAAoB,EACJ,iBAAiB,EAAE,yBAAyB;IAUjE,mBAAmB,CACjB,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,EAAE,EAC/C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,iBAAiB,CAAC,eAAe,EAAE,CAAC;IAE/C,mBAAmB,CACjB,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,EAC7C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,iBAAiB,CAAC,eAAe,CAAC;cA4B7B,oBAAoB,CAClC,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,EAAE,EAC7B,aAAa,GAAE,OAAY,GAC5C,OAAO,CAAC,eAAe,CAAC,OAAO,YAAY,CAAC,EAAE,CAAC;CAuInD"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
16
|
+
const _models_1 = require("../models");
|
|
17
|
+
class NotificationModuleService extends (0, utils_1.AcmeKitService)({ Notification: _models_1.Notification }) {
|
|
18
|
+
constructor({ baseRepository, notificationService, notificationProviderService, }, moduleDeclaration) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.moduleDeclaration = moduleDeclaration;
|
|
22
|
+
this.baseRepository_ = baseRepository;
|
|
23
|
+
this.notificationService_ = notificationService;
|
|
24
|
+
this.notificationProviderService_ = notificationProviderService;
|
|
25
|
+
}
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
async createNotifications(data, sharedContext = {}) {
|
|
28
|
+
const normalized = Array.isArray(data) ? data : [data];
|
|
29
|
+
const createdNotifications = await this.createNotifications_(normalized, sharedContext);
|
|
30
|
+
const serialized = await this.baseRepository_.serialize(createdNotifications);
|
|
31
|
+
return Array.isArray(data) ? serialized : serialized[0];
|
|
32
|
+
}
|
|
33
|
+
async createNotifications_(data, sharedContext = {}) {
|
|
34
|
+
if (!data.length) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
// TODO: At this point we should probably take a lock with the idempotency keys so we don't have race conditions.
|
|
38
|
+
// Also, we should probably rely on Redis for this instead of the database.
|
|
39
|
+
const idempotencyKeys = data
|
|
40
|
+
.map((entry) => entry.idempotency_key)
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
let { notificationsToProcess, createdNotifications } = await this.baseRepository_.transaction(async (txManager) => {
|
|
43
|
+
const context = {
|
|
44
|
+
...sharedContext,
|
|
45
|
+
transactionManager: txManager,
|
|
46
|
+
};
|
|
47
|
+
const alreadySentNotifications = await this.notificationService_.list({
|
|
48
|
+
idempotency_key: idempotencyKeys,
|
|
49
|
+
}, {}, context);
|
|
50
|
+
const existsMap = new Map(alreadySentNotifications.map((n) => [n.idempotency_key, n]));
|
|
51
|
+
const notificationsToProcess = data.filter((entry) => !entry.idempotency_key ||
|
|
52
|
+
!existsMap.has(entry.idempotency_key) ||
|
|
53
|
+
(existsMap.has(entry.idempotency_key) &&
|
|
54
|
+
existsMap.get(entry.idempotency_key).status ===
|
|
55
|
+
utils_1.NotificationStatus.FAILURE));
|
|
56
|
+
const channels = notificationsToProcess.map((not) => not.channel);
|
|
57
|
+
const providers = await this.notificationProviderService_.getProviderForChannels(channels);
|
|
58
|
+
// Create the notifications to be sent to prevent concurrent actions listing the same notifications
|
|
59
|
+
const normalizedNotificationsToProcess = notificationsToProcess.map((entry) => {
|
|
60
|
+
const provider = providers.find((provider) => provider?.channels.includes(entry.channel));
|
|
61
|
+
return {
|
|
62
|
+
provider,
|
|
63
|
+
data: {
|
|
64
|
+
id: (0, utils_1.generateEntityId)(undefined, "noti"),
|
|
65
|
+
...entry,
|
|
66
|
+
provider_id: provider?.id,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const toCreate = normalizedNotificationsToProcess
|
|
71
|
+
.filter((e) => !e.data.idempotency_key || !existsMap.has(e.data.idempotency_key))
|
|
72
|
+
.map((e) => e.data);
|
|
73
|
+
const createdNotifications = toCreate.length
|
|
74
|
+
? await this.notificationService_.create(toCreate, context)
|
|
75
|
+
: [];
|
|
76
|
+
return {
|
|
77
|
+
notificationsToProcess: normalizedNotificationsToProcess,
|
|
78
|
+
createdNotifications,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const notificationToUpdate = [];
|
|
82
|
+
try {
|
|
83
|
+
await (0, utils_1.promiseAll)(notificationsToProcess.map(async (entry) => {
|
|
84
|
+
const provider = entry.provider;
|
|
85
|
+
if (!provider?.is_enabled) {
|
|
86
|
+
entry.data.status = utils_1.NotificationStatus.FAILURE;
|
|
87
|
+
notificationToUpdate.push(entry.data);
|
|
88
|
+
const errorMessage = !provider
|
|
89
|
+
? `Could not find a notification provider for channel: ${entry.data.channel} for notification id ${entry.data.id}`
|
|
90
|
+
: `Notification provider ${provider.id} is not enabled. To enable it, configure it as a provider in the notification module options.`;
|
|
91
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.NOT_FOUND, errorMessage);
|
|
92
|
+
}
|
|
93
|
+
const res = await this.notificationProviderService_
|
|
94
|
+
.send(provider, entry.data)
|
|
95
|
+
.catch((e) => {
|
|
96
|
+
entry.data.status = utils_1.NotificationStatus.FAILURE;
|
|
97
|
+
notificationToUpdate.push(entry.data);
|
|
98
|
+
throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.UNEXPECTED_STATE, `Failed to send notification with id ${entry.data.id}:\n${e.message}`);
|
|
99
|
+
});
|
|
100
|
+
entry.data.external_id = res.id;
|
|
101
|
+
entry.data.status = utils_1.NotificationStatus.SUCCESS;
|
|
102
|
+
notificationToUpdate.push(entry.data);
|
|
103
|
+
}), {
|
|
104
|
+
aggregateErrors: true,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
const updatedNotifications = await this.notificationService_.update(notificationToUpdate, sharedContext);
|
|
109
|
+
const updatedNotificationsMap = new Map(updatedNotifications.map((n) => [n.id, n]));
|
|
110
|
+
// Maintain the order of the notifications
|
|
111
|
+
createdNotifications = createdNotifications.map((notification) => {
|
|
112
|
+
return updatedNotificationsMap.get(notification.id) || notification;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return createdNotifications;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.default = NotificationModuleService;
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, utils_1.InjectManager)(),
|
|
121
|
+
(0, utils_1.EmitEvents)()
|
|
122
|
+
// @ts-expect-error
|
|
123
|
+
,
|
|
124
|
+
__param(1, (0, utils_1.AcmeKitContext)()),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
127
|
+
__metadata("design:returntype", Promise)
|
|
128
|
+
], NotificationModuleService.prototype, "createNotifications", null);
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, utils_1.InjectManager)(),
|
|
131
|
+
__param(1, (0, utils_1.AcmeKitContext)()),
|
|
132
|
+
__metadata("design:type", Function),
|
|
133
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
134
|
+
__metadata("design:returntype", Promise)
|
|
135
|
+
], NotificationModuleService.prototype, "createNotifications_", null);
|
|
136
|
+
//# sourceMappingURL=notification-module-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-module-service.js","sourceRoot":"","sources":["../../src/services/notification-module-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAUA,oDASiC;AACjC,qCAAsC;AAYtC,MAAqB,yBACnB,SAAQ,IAAA,sBAAc,EAEnB,EAAE,YAAY,EAAZ,sBAAY,EAAE,CAAC;IASpB,YACE,EACE,cAAc,EACd,mBAAmB,EACnB,2BAA2B,GACN,EACJ,iBAA4C;QAE/D,aAAa;QACb,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QAHA,sBAAiB,GAAjB,iBAAiB,CAA2B;QAI/D,IAAI,CAAC,eAAe,GAAG,cAAc,CAAA;QACrC,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAA;QAC/C,IAAI,CAAC,4BAA4B,GAAG,2BAA2B,CAAA;IACjE,CAAC;IAgBK,AADN,mBAAmB;IACnB,KAAK,CAAC,mBAAmB,CACvB,IAE6C,EAC3B,gBAAyB,EAAE;QAI7C,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAEtD,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAC1D,UAAU,EACV,aAAa,CACd,CAAA;QAED,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,SAA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AAW,GAAG,GAAG,CAAC,EAAE,CAAA;gBAC/B,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,0BAAkB,CAAC,OAAO,CAAA;gBAE9C,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACvC,CAAC,CAAC,EACF;gBACE,eAAe,EAAE,IAAI;aACtB,CACF,CAAA;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,MAAM,CACjE,oBAAoB,EACpB,aAAa,CACd,CAAA;YACD,MAAM,uBAAuB,GAAG,IAAI,GAAG,CACrC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAC3C,CAAA;YAED,0CAA0C;YAC1C,oBAAoB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE;gBAC/D,OAAO,uBAAuB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,YAAY,CAAA;YACrE,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,oBAAoB,CAAA;IAC7B,CAAC;CACF;AA1MD,4CA0MC;AAjKO;IAHL,IAAA,qBAAa,GAAE;IACf,IAAA,kBAAU,GAAE;IACb,mBAAmB;;IAKhB,WAAA,IAAA,sBAAc,GAAE,CAAA;;;;oEAgBlB;AAGe;IADf,IAAA,qBAAa,GAAE;IAGb,WAAA,IAAA,sBAAc,GAAE,CAAA;;;;qEAuIlB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DAL, InferEntityType, Logger, NotificationTypes } from "@acmekit/framework/types";
|
|
2
|
+
import { ModulesSdkUtils } from "@acmekit/framework/utils";
|
|
3
|
+
import { NotificationProvider } from "../models";
|
|
4
|
+
import { NotificationProviderRegistrationPrefix } from "../types";
|
|
5
|
+
type InjectedDependencies = {
|
|
6
|
+
logger?: Logger;
|
|
7
|
+
notificationProviderRepository: DAL.RepositoryService<InferEntityType<typeof NotificationProvider>>;
|
|
8
|
+
[key: `${typeof NotificationProviderRegistrationPrefix}${string}`]: NotificationTypes.INotificationProvider;
|
|
9
|
+
};
|
|
10
|
+
type Provider = InferEntityType<typeof NotificationProvider>;
|
|
11
|
+
declare const NotificationProviderService_base: {
|
|
12
|
+
new <TContainer extends object = object, TEntity extends object = any>(container: TContainer): import("@acmekit/framework/types").IAcmeKitInternalService<TEntity, TContainer>;
|
|
13
|
+
setEventSubscriber(subscriber: ModulesSdkUtils.AcmeKitMikroOrmEventSubscriber): void;
|
|
14
|
+
};
|
|
15
|
+
export default class NotificationProviderService extends NotificationProviderService_base {
|
|
16
|
+
#private;
|
|
17
|
+
protected readonly notificationProviderRepository_: DAL.RepositoryService<InferEntityType<typeof NotificationProvider>>;
|
|
18
|
+
protected providersCache: Map<string, InferEntityType<typeof NotificationProvider>>;
|
|
19
|
+
constructor(container: InjectedDependencies);
|
|
20
|
+
protected retrieveProviderRegistration(providerId: string): NotificationTypes.INotificationProvider;
|
|
21
|
+
getProviderForChannels<TChannel = string | string[], TOutput = TChannel extends string[] ? Provider[] : Provider | undefined>(channels: TChannel): Promise<TOutput>;
|
|
22
|
+
send(provider: InferEntityType<typeof NotificationProvider>, notification: NotificationTypes.ProviderSendNotificationDTO): Promise<NotificationTypes.ProviderSendNotificationResultsDTO>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=notification-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-provider.d.ts","sourceRoot":"","sources":["../../src/services/notification-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,eAAe,EACf,MAAM,EACN,iBAAiB,EAClB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,M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&& this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _NotificationProviderService_logger;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@acmekit/framework/utils");
|
|
16
|
+
const _models_1 = require("../models");
|
|
17
|
+
const _types_1 = require("../types");
|
|
18
|
+
class NotificationProviderService extends utils_1.ModulesSdkUtils.AcmeKitInternalService(_models_1.NotificationProvider) {
|
|
19
|
+
constructor(container) {
|
|
20
|
+
super(container);
|
|
21
|
+
// We can store the providers in a memory since they can only be registered on startup and not changed during runtime
|
|
22
|
+
_NotificationProviderService_logger.set(this, void 0);
|
|
23
|
+
this.notificationProviderRepository_ =
|
|
24
|
+
container.notificationProviderRepository;
|
|
25
|
+
__classPrivateFieldSet(this, _NotificationProviderService_logger, container["logger"]
|
|
26
|
+
? container.logger
|
|
27
|
+
: console, "f");
|
|
28
|
+
}
|
|
29
|
+
retrieveProviderRegistration(providerId) {
|
|
30
|
+
try {
|
|
31
|
+
return this.__container__[`${_types_1.NotificationProviderRegistrationPrefix}${providerId}`];
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err.name === "AwilixResolutionError") {
|
|
35
|
+
const errMessage = `
|
|
36
|
+
Unable to retrieve the notification provider with id: ${providerId}
|
|
37
|
+
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`;
|
|
38
|
+
// Log full error for debugging
|
|
39
|
+
__classPrivateFieldGet(this, _NotificationProviderService_logger, "f").error(`AwilixResolutionError: ${err.message}`, err);
|
|
40
|
+
throw new Error(errMessage);
|
|
41
|
+
}
|
|
42
|
+
const errMessage = `Unable to retrieve the notification provider with id: ${providerId}, the following error occurred: ${err.message}`;
|
|
43
|
+
__classPrivateFieldGet(this, _NotificationProviderService_logger, "f").error(errMessage);
|
|
44
|
+
throw new Error(errMessage);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async getProviderForChannels(channels) {
|
|
48
|
+
if (!this.providersCache) {
|
|
49
|
+
const providers = await this.notificationProviderRepository_.find({
|
|
50
|
+
where: { is_enabled: true },
|
|
51
|
+
});
|
|
52
|
+
this.providersCache = new Map(providers.flatMap((provider) => provider.channels.map((c) => [c, provider])));
|
|
53
|
+
}
|
|
54
|
+
const normalizedChannels = Array.isArray(channels) ? channels : [channels];
|
|
55
|
+
const results = normalizedChannels
|
|
56
|
+
.map((channel) => this.providersCache.get(channel))
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
return (Array.isArray(channels) ? results : results[0]);
|
|
59
|
+
}
|
|
60
|
+
async send(provider, notification) {
|
|
61
|
+
const providerHandler = this.retrieveProviderRegistration(provider.id);
|
|
62
|
+
return await providerHandler.send(notification);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
_NotificationProviderService_logger = new WeakMap();
|
|
66
|
+
exports.default = NotificationProviderService;
|
|
67
|
+
//# sourceMappingURL=notification-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-provider.js","sourceRoot":"","sources":["../../src/services/notification-provider.ts"],"names":[],"mappings":";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IAAI,CAAC;gBAChE,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;aAC5B,CAAC,CAAA;YAEF,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,CAC3B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC7B,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAC5C,CACF,CAAA;QACH,CAAC;QAED,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC1E,MAAM,OAAO,GAAG,kBAAkB;aAC/B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;aAClD,MAAM,CAAC,OAAO,CAAC,CAAA;QAElB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAY,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,IAAI,CACR,QAAsD,EACtD,YAA2D;QAE3D,MAAM,eAAe,GAAG,IAAI,CAAC,4BAA4B,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACtE,OAAO,MAAM,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACjD,CAAC;CACF;;kBAnFoB,2BAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/loaders/providers.ts","../src/migrations/migration20240509083918_initialsetupmigration.ts","../src/migrations/migration20240628075401.ts","../src/migrations/migration20240830094712.ts","../src/migrations/migration20250120110514.ts","../src/migrations/migration20251028172715.ts","../src/migrations/migration20251121123942.ts","../src/migrations/migration20251121150408.ts","../src/models/index.ts","../src/models/notification-provider.ts","../src/models/notification.ts","../src/providers/acmekit-cloud-email.ts","../src/services/index.ts","../src/services/notification-module-service.ts","../src/services/notification-provider.ts","../src/types/index.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Logger, ModuleProviderExports, ModuleServiceInitializeOptions } from "@acmekit/framework/types";
|
|
2
|
+
export type InitializeModuleInjectableDependencies = {
|
|
3
|
+
logger?: Logger;
|
|
4
|
+
};
|
|
5
|
+
export declare const NotificationIdentifiersRegistrationName = "notification_providers_identifier";
|
|
6
|
+
export declare const NotificationProviderRegistrationPrefix = "np_";
|
|
7
|
+
export type NotificationModuleOptions = Partial<ModuleServiceInitializeOptions> & {
|
|
8
|
+
/**
|
|
9
|
+
* Providers to be registered
|
|
10
|
+
*/
|
|
11
|
+
providers?: {
|
|
12
|
+
/**
|
|
13
|
+
* The module provider to be registered
|
|
14
|
+
*/
|
|
15
|
+
resolve: string | ModuleProviderExports;
|
|
16
|
+
/**
|
|
17
|
+
* The id of the provider
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* key value pair of the configuration to be passed to the provider constructor, plus the channels supported by the provider
|
|
22
|
+
*/
|
|
23
|
+
options?: Record<string, unknown> & {
|
|
24
|
+
channels: string[];
|
|
25
|
+
};
|
|
26
|
+
}[];
|
|
27
|
+
/**
|
|
28
|
+
* Options for the default AcmeKit Cloud Email provider
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
cloud?: AcmeKitCloudEmailOptions;
|
|
32
|
+
};
|
|
33
|
+
export type AcmeKitCloudEmailOptions = {
|
|
34
|
+
api_key: string;
|
|
35
|
+
endpoint: string;
|
|
36
|
+
environment_handle?: string;
|
|
37
|
+
sandbox_handle?: string;
|
|
38
|
+
};
|
|
39
|
+
declare module "@acmekit/types" {
|
|
40
|
+
interface ModuleOptions {
|
|
41
|
+
"@acmekit/notification": NotificationModuleOptions;
|
|
42
|
+
"@acmekit/acmekit/notification": NotificationModuleOptions;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,8BAA8B,EAC/B,MAAM,0BAA0B,CAAA;AAEjC,MAAM,MAAM,sCAAsC,GAAG;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,uCAAuC,sCACf,CAAA;AAErC,eAAO,MAAM,sCAAsC,QAAQ,CAAA;AAE3D,MAAM,MAAM,yBAAyB,GACnC,OAAO,CAAC,8BAA8B,CAAC,GAAG;IACxC;;OAEG;IACH,SAAS,CAAC,EAAE;QACV;;WAEG;QACH,OAAO,EAAE,MAAM,GAAG,qBAAqB,CAAA;QACvC;;WAEG;QACH,EAAE,EAAE,MAAM,CAAA;QACV;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;YAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;SAAE,CAAA;KAC3D,EAAE,CAAA;IACH;;;OAGG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAA;CACjC,CAAA;AAEH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,aAAa;QACrB,uBAAuB,EAAE,yBAAyB,CAAA;QAClD,+BAA+B,EAAE,yBAAyB,CAAA;KAC3D;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationProviderRegistrationPrefix = exports.NotificationIdentifiersRegistrationName = void 0;
|
|
4
|
+
exports.NotificationIdentifiersRegistrationName = "notification_providers_identifier";
|
|
5
|
+
exports.NotificationProviderRegistrationPrefix = "np_";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAUa,QAAA,uCAAuC,GAClD,mCAAmC,CAAA;AAExB,QAAA,sCAAsC,GAAG,KAAK,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acmekit/notification",
|
|
3
|
+
"version": "2.13.1",
|
|
4
|
+
"description": "AcmeKit Notification module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"!dist/**/__tests__",
|
|
10
|
+
"!dist/**/__mocks__",
|
|
11
|
+
"!dist/**/__fixtures__"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/acmekit/acmekit",
|
|
19
|
+
"directory": "packages/modules/notification"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"author": "AcmeKit",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"watch": "yarn run -T tsc --build --watch",
|
|
28
|
+
"watch:test": "yarn run -T tsc --build tsconfig.spec.json --watch",
|
|
29
|
+
"resolve:aliases": "yarn run -T tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && yarn run -T tsc-alias -p tsconfig.resolved.json && yarn run -T rimraf tsconfig.resolved.json",
|
|
30
|
+
"build": "yarn run -T rimraf dist && yarn run -T tsc --build && npm run resolve:aliases",
|
|
31
|
+
"test": "../../../node_modules/.bin/jest --bail --forceExit --passWithNoTests --testPathPattern=src",
|
|
32
|
+
"test:integration": "../../../node_modules/.bin/jest --passWithNoTests --forceExit --testPathPattern=\"integration-tests/__tests__/.*\\.spec\\.ts\"",
|
|
33
|
+
"migration:initial": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true acmekit-mikro-orm migration:create --initial -n InitialSetupMigration",
|
|
34
|
+
"migration:create": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true acmekit-mikro-orm migration:create",
|
|
35
|
+
"migration:up": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true acmekit-mikro-orm migration:up",
|
|
36
|
+
"orm:cache:clear": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true acmekit-mikro-orm cache:clear"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@acmekit/framework": "2.13.1",
|
|
40
|
+
"@acmekit/test-utils": "2.13.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@acmekit/framework": "2.13.1"
|
|
44
|
+
}
|
|
45
|
+
}
|