@deenruv/cronjobs-plugin 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.
Files changed (52) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +56 -0
  3. package/dist/plugin-server/api/admin-api.resolver.d.ts +19 -0
  4. package/dist/plugin-server/api/admin-api.resolver.js +121 -0
  5. package/dist/plugin-server/constants.d.ts +2 -0
  6. package/dist/plugin-server/constants.js +5 -0
  7. package/dist/plugin-server/controllers/cronjobs-executor.controller.d.ts +8 -0
  8. package/dist/plugin-server/controllers/cronjobs-executor.controller.js +58 -0
  9. package/dist/plugin-server/extensions/admin-api.extension.d.ts +1 -0
  10. package/dist/plugin-server/extensions/admin-api.extension.js +56 -0
  11. package/dist/plugin-server/guards/controllers.guard.d.ts +20 -0
  12. package/dist/plugin-server/guards/controllers.guard.js +74 -0
  13. package/dist/plugin-server/index.d.ts +14 -0
  14. package/dist/plugin-server/index.js +70 -0
  15. package/dist/plugin-server/services/cronjobs.service.d.ts +20 -0
  16. package/dist/plugin-server/services/cronjobs.service.js +91 -0
  17. package/dist/plugin-server/strategies/default-executor.strategy.d.ts +15 -0
  18. package/dist/plugin-server/strategies/default-executor.strategy.js +19 -0
  19. package/dist/plugin-server/strategies/kubernetes-cronjob-executor.strategy.d.ts +41 -0
  20. package/dist/plugin-server/strategies/kubernetes-cronjob-executor.strategy.js +238 -0
  21. package/dist/plugin-server/types.d.ts +22 -0
  22. package/dist/plugin-server/types.js +2 -0
  23. package/dist/plugin-server/zeus/const.d.ts +6 -0
  24. package/dist/plugin-server/zeus/const.js +3936 -0
  25. package/dist/plugin-server/zeus/index.d.ts +20031 -0
  26. package/dist/plugin-server/zeus/index.js +1122 -0
  27. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  28. package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
  29. package/dist/plugin-ui/components/CronSchedule.d.ts +9 -0
  30. package/dist/plugin-ui/components/CronSchedule.js +674 -0
  31. package/dist/plugin-ui/constants.d.ts +1 -0
  32. package/dist/plugin-ui/constants.js +1 -0
  33. package/dist/plugin-ui/graphql/mutations.d.ts +24 -0
  34. package/dist/plugin-ui/graphql/mutations.js +12 -0
  35. package/dist/plugin-ui/graphql/queries.d.ts +34 -0
  36. package/dist/plugin-ui/graphql/queries.js +27 -0
  37. package/dist/plugin-ui/graphql/selectors.d.ts +16 -0
  38. package/dist/plugin-ui/graphql/selectors.js +15 -0
  39. package/dist/plugin-ui/index.d.ts +1 -0
  40. package/dist/plugin-ui/index.js +25 -0
  41. package/dist/plugin-ui/locales/en/translations.json +56 -0
  42. package/dist/plugin-ui/locales/pl/translations.json +56 -0
  43. package/dist/plugin-ui/pages/CronJobsPage.d.ts +12 -0
  44. package/dist/plugin-ui/pages/CronJobsPage.js +151 -0
  45. package/dist/plugin-ui/tsconfig.json +18 -0
  46. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  47. package/dist/plugin-ui/zeus/const.js +3933 -0
  48. package/dist/plugin-ui/zeus/index.d.ts +20031 -0
  49. package/dist/plugin-ui/zeus/index.js +1114 -0
  50. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  51. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  52. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # License 1
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2025-present Aexol
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
13
+ # License 2
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2018-2025 Michael Bromley
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @deenruv/cronjobs-plugin
2
+
3
+ Plugin for managing scheduled cron jobs within Deenruv. It provides a strategy-based executor pattern (e.g., Kubernetes CronJobs) with an admin UI for creating, listing, updating, and removing cron jobs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/cronjobs-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { CronJobsPlugin, KubernetesCronJobExecutor } from '@deenruv/cronjobs-plugin';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ CronJobsPlugin.init({
19
+ controllerAuthToken: 'your-secret-token',
20
+ executor: new KubernetesCronJobExecutor({
21
+ // Kubernetes executor options
22
+ }),
23
+ knownWorkerJobsToSuggest: ['sync-products', 'cleanup-sessions'],
24
+ presets: {
25
+ merge: true,
26
+ values: [
27
+ { label: 'Every hour', value: '0 * * * *' },
28
+ { label: 'Every day at midnight', value: '0 0 * * *' },
29
+ ],
30
+ },
31
+ }),
32
+ ]
33
+ ```
34
+
35
+ ## Features
36
+
37
+ - Strategy-based cron job execution (includes Kubernetes CronJob executor)
38
+ - Admin UI for creating, listing, updating, and removing scheduled jobs
39
+ - Configurable cron schedule presets for quick setup
40
+ - Suggested worker job names for easier configuration
41
+ - Authenticated controller endpoint for job execution triggers
42
+ - Lifecycle management with automatic init/destroy of executor strategies
43
+
44
+ ## Admin UI
45
+
46
+ This plugin extends the admin UI with a dedicated cron jobs management page where administrators can view all scheduled jobs, create new ones with cron expressions, update schedules, and remove jobs.
47
+
48
+ ## API Extensions
49
+
50
+ ### Admin API
51
+
52
+ - **Query** `cronJobsConfig: CronJobsConfig!` — Returns suggested jobs and schedule presets
53
+ - **Query** `cronJobs(input: CronJobsListInput!): CronJobsList!` — Lists cron jobs with optional filtering by channel token and job queue name
54
+ - **Mutation** `createCronJob(input: CronJobCreateInput!): Boolean` — Creates a new cron job
55
+ - **Mutation** `updateCronJob(job: CronJobInput!): Boolean` — Updates an existing cron job's schedule
56
+ - **Mutation** `removeCronJob(jobs: [CronJobInput!]!): Boolean` — Removes one or more cron jobs
@@ -0,0 +1,19 @@
1
+ import { RequestContext } from "@deenruv/core";
2
+ import { ModelTypes } from "../zeus/index.js";
3
+ import { CronJobsService } from "../services/cronjobs.service.js";
4
+ export declare class CronJobsAdminAPIResolver {
5
+ private readonly cronJobsService;
6
+ constructor(cronJobsService: CronJobsService);
7
+ cronJobsConfig(ctx: RequestContext): Promise<{
8
+ suggestedJobs: string[];
9
+ presets: {
10
+ default: boolean;
11
+ label: string;
12
+ value: string;
13
+ }[];
14
+ }>;
15
+ cronJobs(ctx: RequestContext, input: ModelTypes["CronJobsListInput"]): Promise<ModelTypes["CronJobsList"]>;
16
+ createCronJob(ctx: RequestContext, input: ModelTypes["CronJobCreateInput"]): Promise<boolean>;
17
+ updateCronJob(ctx: RequestContext, job: ModelTypes["CronJob"]): Promise<boolean>;
18
+ removeCronJob(ctx: RequestContext, jobs: ModelTypes["CronJob"][]): Promise<boolean>;
19
+ }
@@ -0,0 +1,121 @@
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
+ exports.CronJobsAdminAPIResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@deenruv/core");
18
+ const cronjobs_service_js_1 = require("../services/cronjobs.service.js");
19
+ let CronJobsAdminAPIResolver = class CronJobsAdminAPIResolver {
20
+ constructor(cronJobsService) {
21
+ this.cronJobsService = cronJobsService;
22
+ }
23
+ async cronJobsConfig(ctx) {
24
+ try {
25
+ return this.cronJobsService.config(ctx);
26
+ }
27
+ catch (e) {
28
+ console.error(e);
29
+ return { suggestedJobs: [], presets: [] };
30
+ }
31
+ }
32
+ async cronJobs(ctx, input) {
33
+ try {
34
+ const jobs = await this.cronJobsService.listJobs(ctx, input);
35
+ return jobs;
36
+ }
37
+ catch (e) {
38
+ console.error(e);
39
+ return { items: [], totalItems: 0 };
40
+ }
41
+ }
42
+ async createCronJob(ctx, input) {
43
+ try {
44
+ await this.cronJobsService.createJob(ctx, input);
45
+ return true;
46
+ }
47
+ catch (e) {
48
+ console.error(e);
49
+ return false;
50
+ }
51
+ }
52
+ async updateCronJob(ctx, job) {
53
+ try {
54
+ await this.cronJobsService.updateJob(ctx, job);
55
+ return true;
56
+ }
57
+ catch (e) {
58
+ console.error(e);
59
+ return false;
60
+ }
61
+ }
62
+ async removeCronJob(ctx, jobs) {
63
+ try {
64
+ await this.cronJobsService.removeJobs(ctx, jobs);
65
+ return true;
66
+ }
67
+ catch (e) {
68
+ console.error(e);
69
+ return false;
70
+ }
71
+ }
72
+ };
73
+ exports.CronJobsAdminAPIResolver = CronJobsAdminAPIResolver;
74
+ __decorate([
75
+ (0, graphql_1.Query)(),
76
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
77
+ __param(0, (0, core_1.Ctx)()),
78
+ __metadata("design:type", Function),
79
+ __metadata("design:paramtypes", [core_1.RequestContext]),
80
+ __metadata("design:returntype", Promise)
81
+ ], CronJobsAdminAPIResolver.prototype, "cronJobsConfig", null);
82
+ __decorate([
83
+ (0, graphql_1.Query)(),
84
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
85
+ __param(0, (0, core_1.Ctx)()),
86
+ __param(1, (0, graphql_1.Args)("input")),
87
+ __metadata("design:type", Function),
88
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
89
+ __metadata("design:returntype", Promise)
90
+ ], CronJobsAdminAPIResolver.prototype, "cronJobs", null);
91
+ __decorate([
92
+ (0, graphql_1.Mutation)(),
93
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
94
+ __param(0, (0, core_1.Ctx)()),
95
+ __param(1, (0, graphql_1.Args)("input")),
96
+ __metadata("design:type", Function),
97
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
98
+ __metadata("design:returntype", Promise)
99
+ ], CronJobsAdminAPIResolver.prototype, "createCronJob", null);
100
+ __decorate([
101
+ (0, graphql_1.Mutation)(),
102
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
103
+ __param(0, (0, core_1.Ctx)()),
104
+ __param(1, (0, graphql_1.Args)("job")),
105
+ __metadata("design:type", Function),
106
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
107
+ __metadata("design:returntype", Promise)
108
+ ], CronJobsAdminAPIResolver.prototype, "updateCronJob", null);
109
+ __decorate([
110
+ (0, graphql_1.Mutation)(),
111
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
112
+ __param(0, (0, core_1.Ctx)()),
113
+ __param(1, (0, graphql_1.Args)("jobs")),
114
+ __metadata("design:type", Function),
115
+ __metadata("design:paramtypes", [core_1.RequestContext, Array]),
116
+ __metadata("design:returntype", Promise)
117
+ ], CronJobsAdminAPIResolver.prototype, "removeCronJob", null);
118
+ exports.CronJobsAdminAPIResolver = CronJobsAdminAPIResolver = __decorate([
119
+ (0, graphql_1.Resolver)(),
120
+ __metadata("design:paramtypes", [cronjobs_service_js_1.CronJobsService])
121
+ ], CronJobsAdminAPIResolver);
@@ -0,0 +1,2 @@
1
+ export declare const CRONJOBS_PLUGIN_OPTIONS: unique symbol;
2
+ export declare const CONTROLLER_PATH = "cronjobs-executor";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTROLLER_PATH = exports.CRONJOBS_PLUGIN_OPTIONS = void 0;
4
+ exports.CRONJOBS_PLUGIN_OPTIONS = Symbol("CRONJOBS_PLUGIN_OPTIONS");
5
+ exports.CONTROLLER_PATH = "cronjobs-executor";
@@ -0,0 +1,8 @@
1
+ import { Response } from "express";
2
+ import { JobQueueService, Logger, RequestContext } from "@deenruv/core";
3
+ export declare class CronJobsExecutorController {
4
+ private readonly jobQueueService;
5
+ logger: Logger;
6
+ constructor(jobQueueService: JobQueueService);
7
+ synchronize(ctx: RequestContext, res: Response, name: string): Promise<void>;
8
+ }
@@ -0,0 +1,58 @@
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
+ exports.CronJobsExecutorController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@deenruv/core");
18
+ const constants_js_1 = require("../constants.js");
19
+ const controllers_guard_js_1 = require("../guards/controllers.guard.js");
20
+ let CronJobsExecutorController = class CronJobsExecutorController {
21
+ constructor(jobQueueService) {
22
+ this.jobQueueService = jobQueueService;
23
+ this.logger = new core_1.Logger();
24
+ }
25
+ async synchronize(ctx, res, name) {
26
+ try {
27
+ const jobQueue = this.jobQueueService
28
+ .getJobQueues()
29
+ .find((q) => q.name === name);
30
+ if (!jobQueue) {
31
+ this.logger.log(`Job queue ${name} not found`, "CronJobsExecutorController");
32
+ res.status(404).send("Job queue not found");
33
+ return;
34
+ }
35
+ await jobQueue.add({ serializedContext: ctx.serialize() });
36
+ }
37
+ catch (e) {
38
+ this.logger.log(`Error starting job queue ${name}: ${e}`, "CronJobsExecutorController");
39
+ res.status(500).send("Error starting job queue");
40
+ }
41
+ res.send("OK !");
42
+ }
43
+ };
44
+ exports.CronJobsExecutorController = CronJobsExecutorController;
45
+ __decorate([
46
+ (0, common_1.Get)(":name"),
47
+ __param(0, (0, core_1.Ctx)()),
48
+ __param(1, (0, common_1.Res)()),
49
+ __param(2, (0, common_1.Param)("name")),
50
+ __metadata("design:type", Function),
51
+ __metadata("design:paramtypes", [core_1.RequestContext, Object, String]),
52
+ __metadata("design:returntype", Promise)
53
+ ], CronJobsExecutorController.prototype, "synchronize", null);
54
+ exports.CronJobsExecutorController = CronJobsExecutorController = __decorate([
55
+ (0, common_1.Controller)(constants_js_1.CONTROLLER_PATH),
56
+ (0, common_1.UseGuards)(controllers_guard_js_1.ControllersGuard),
57
+ __metadata("design:paramtypes", [core_1.JobQueueService])
58
+ ], CronJobsExecutorController);
@@ -0,0 +1 @@
1
+ export declare const AdminAPIExtension: import("graphql").DocumentNode;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminAPIExtension = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ exports.AdminAPIExtension = (0, graphql_tag_1.gql) `
6
+ type CronJob {
7
+ name: String!
8
+ schedule: String!
9
+ lastScheduleTime: String!
10
+ lastSuccessfulTime: String!
11
+ channelToken: String!
12
+ }
13
+
14
+ input CronJobsListInput {
15
+ take: Int
16
+ channelToken: String
17
+ jobQueueName: String
18
+ }
19
+
20
+ type CronJobsList {
21
+ items: [CronJob!]!
22
+ totalItems: Int!
23
+ }
24
+
25
+ input CronJobInput {
26
+ name: String!
27
+ schedule: String!
28
+ }
29
+
30
+ input CronJobCreateInput {
31
+ jobQueueName: String!
32
+ schedule: String!
33
+ }
34
+
35
+ type CronJobsPreset {
36
+ label: String!
37
+ value: String!
38
+ default: Boolean!
39
+ }
40
+
41
+ type CronJobsConfig {
42
+ suggestedJobs: [String!]!
43
+ presets: [CronJobsPreset!]!
44
+ }
45
+
46
+ extend type Query {
47
+ cronJobsConfig: CronJobsConfig!
48
+ cronJobs(input: CronJobsListInput!): CronJobsList!
49
+ }
50
+
51
+ extend type Mutation {
52
+ createCronJob(input: CronJobCreateInput!): Boolean
53
+ updateCronJob(job: CronJobInput!): Boolean
54
+ removeCronJob(jobs: [CronJobInput!]!): Boolean
55
+ }
56
+ `;
@@ -0,0 +1,20 @@
1
+ import type { CanActivate, ExecutionContext } from "@nestjs/common";
2
+ import { RequestContextService, TransactionalConnection } from "@deenruv/core";
3
+ import { CronJobsPluginOptions } from "../types.js";
4
+ export declare class CardMarketAuthErrorResult extends Error {
5
+ readonly httpStatus: number;
6
+ }
7
+ export declare class AuthenticationError extends CardMarketAuthErrorResult {
8
+ readonly __typename = "AuthenticationError";
9
+ readonly name = "authentication_error";
10
+ readonly httpStatus = 403;
11
+ readonly message = "AUTH_ERROR";
12
+ }
13
+ export declare class ControllersGuard implements CanActivate {
14
+ private connection;
15
+ private requestContextService;
16
+ private options;
17
+ constructor(connection: TransactionalConnection, requestContextService: RequestContextService, options: CronJobsPluginOptions);
18
+ canActivate(context: ExecutionContext): Promise<boolean>;
19
+ private verifySignature;
20
+ }
@@ -0,0 +1,74 @@
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
+ exports.ControllersGuard = exports.AuthenticationError = exports.CardMarketAuthErrorResult = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@deenruv/core");
18
+ const constants_js_1 = require("../constants.js");
19
+ class CardMarketAuthErrorResult extends Error {
20
+ }
21
+ exports.CardMarketAuthErrorResult = CardMarketAuthErrorResult;
22
+ class AuthenticationError extends CardMarketAuthErrorResult {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.__typename = "AuthenticationError";
26
+ this.name = "authentication_error";
27
+ this.httpStatus = 403;
28
+ this.message = "AUTH_ERROR";
29
+ }
30
+ }
31
+ exports.AuthenticationError = AuthenticationError;
32
+ let ControllersGuard = class ControllersGuard {
33
+ constructor(connection, requestContextService, options) {
34
+ this.connection = connection;
35
+ this.requestContextService = requestContextService;
36
+ this.options = options;
37
+ }
38
+ async canActivate(context) {
39
+ return this.verifySignature(context);
40
+ }
41
+ async verifySignature(context) {
42
+ var _a;
43
+ const req = context.switchToHttp().getRequest();
44
+ const token = (_a = req === null || req === void 0 ? void 0 : req.query) === null || _a === void 0 ? void 0 : _a.token;
45
+ if (!token || token !== this.options.controllerAuthToken) {
46
+ throw new AuthenticationError();
47
+ }
48
+ const channel = await this.connection.rawConnection
49
+ .getRepository(core_1.Channel)
50
+ .findOne({
51
+ where: { code: "__default_channel__" },
52
+ relations: ["defaultTaxZone", "defaultShippingZone"],
53
+ });
54
+ if (!channel)
55
+ throw new AuthenticationError();
56
+ const ctx = await this.requestContextService.create({
57
+ req,
58
+ apiType: "admin",
59
+ channelOrToken: channel,
60
+ languageCode: channel.defaultLanguageCode,
61
+ });
62
+ if (!ctx)
63
+ throw new AuthenticationError();
64
+ context.switchToHttp().getRequest()["ctx"] = ctx;
65
+ return true;
66
+ }
67
+ };
68
+ exports.ControllersGuard = ControllersGuard;
69
+ exports.ControllersGuard = ControllersGuard = __decorate([
70
+ (0, common_1.Injectable)(),
71
+ __param(2, (0, common_1.Inject)(constants_js_1.CRONJOBS_PLUGIN_OPTIONS)),
72
+ __metadata("design:paramtypes", [core_1.TransactionalConnection,
73
+ core_1.RequestContextService, Object])
74
+ ], ControllersGuard);
@@ -0,0 +1,14 @@
1
+ import { CronJobsPluginOptions } from "./types.js";
2
+ import { OnApplicationBootstrap } from "@nestjs/common";
3
+ import { ModuleRef } from "@nestjs/core";
4
+ export { KubernetesCronJobExecutor } from "./strategies/kubernetes-cronjob-executor.strategy.js";
5
+ export declare class CronJobsPlugin implements OnApplicationBootstrap {
6
+ private moduleRef;
7
+ private static options;
8
+ constructor(moduleRef: ModuleRef);
9
+ static init(options: CronJobsPluginOptions): typeof CronJobsPlugin;
10
+ onApplicationBootstrap(): Promise<void>;
11
+ onApplicationShutdown(): Promise<void>;
12
+ private initCronJobsExecutorStrategy;
13
+ private destroyCronJobsExecutorStrategy;
14
+ }
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CronJobsPlugin = exports.KubernetesCronJobExecutor = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const constants_js_1 = require("./constants.js");
15
+ const core_2 = require("@nestjs/core");
16
+ const cronjobs_service_js_1 = require("./services/cronjobs.service.js");
17
+ const cronjobs_executor_controller_js_1 = require("./controllers/cronjobs-executor.controller.js");
18
+ const admin_api_extension_js_1 = require("./extensions/admin-api.extension.js");
19
+ const admin_api_resolver_js_1 = require("./api/admin-api.resolver.js");
20
+ var kubernetes_cronjob_executor_strategy_js_1 = require("./strategies/kubernetes-cronjob-executor.strategy.js");
21
+ Object.defineProperty(exports, "KubernetesCronJobExecutor", { enumerable: true, get: function () { return kubernetes_cronjob_executor_strategy_js_1.KubernetesCronJobExecutor; } });
22
+ let CronJobsPlugin = class CronJobsPlugin {
23
+ constructor(moduleRef) {
24
+ this.moduleRef = moduleRef;
25
+ }
26
+ static init(options) {
27
+ this.options = options;
28
+ return this;
29
+ }
30
+ async onApplicationBootstrap() {
31
+ await this.initCronJobsExecutorStrategy();
32
+ }
33
+ async onApplicationShutdown() {
34
+ await this.destroyCronJobsExecutorStrategy();
35
+ }
36
+ async initCronJobsExecutorStrategy() {
37
+ const injector = new core_1.Injector(this.moduleRef);
38
+ const service = injector.get(cronjobs_service_js_1.CronJobsService);
39
+ if (typeof service.executor.init === "function") {
40
+ await service.executor.init(injector);
41
+ }
42
+ }
43
+ async destroyCronJobsExecutorStrategy() {
44
+ const injector = new core_1.Injector(this.moduleRef);
45
+ const service = injector.get(cronjobs_service_js_1.CronJobsService);
46
+ if (typeof service.executor.destroy === "function") {
47
+ await service.executor.destroy();
48
+ }
49
+ }
50
+ };
51
+ exports.CronJobsPlugin = CronJobsPlugin;
52
+ exports.CronJobsPlugin = CronJobsPlugin = __decorate([
53
+ (0, core_1.DeenruvPlugin)({
54
+ compatibility: "^0.0.40",
55
+ imports: [core_1.PluginCommonModule],
56
+ controllers: [cronjobs_executor_controller_js_1.CronJobsExecutorController],
57
+ providers: [
58
+ {
59
+ provide: constants_js_1.CRONJOBS_PLUGIN_OPTIONS,
60
+ useFactory: () => CronJobsPlugin.options,
61
+ },
62
+ cronjobs_service_js_1.CronJobsService,
63
+ ],
64
+ adminApiExtensions: {
65
+ resolvers: [admin_api_resolver_js_1.CronJobsAdminAPIResolver],
66
+ schema: admin_api_extension_js_1.AdminAPIExtension,
67
+ },
68
+ }),
69
+ __metadata("design:paramtypes", [core_2.ModuleRef])
70
+ ], CronJobsPlugin);
@@ -0,0 +1,20 @@
1
+ import { CronJobsExecutorStrategy, CronJobsPluginOptions } from "../types.js";
2
+ import { RequestContext } from "@deenruv/core";
3
+ import { ModelTypes } from "../zeus/index.js";
4
+ export declare class CronJobsService {
5
+ private options;
6
+ executor: CronJobsExecutorStrategy;
7
+ constructor(options: CronJobsPluginOptions);
8
+ config(ctx: RequestContext): Promise<{
9
+ suggestedJobs: string[];
10
+ presets: {
11
+ default: boolean;
12
+ label: string;
13
+ value: string;
14
+ }[];
15
+ }>;
16
+ listJobs(ctx: RequestContext, args: ModelTypes["CronJobsListInput"]): Promise<ModelTypes["CronJobsList"]>;
17
+ createJob(ctx: RequestContext, input: ModelTypes["CronJobCreateInput"]): Promise<boolean>;
18
+ updateJob(ctx: RequestContext, job: ModelTypes["CronJob"]): Promise<boolean>;
19
+ removeJobs(ctx: RequestContext, jobs: ModelTypes["CronJob"][]): Promise<boolean>;
20
+ }
@@ -0,0 +1,91 @@
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
+ exports.CronJobsService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const constants_js_1 = require("../constants.js");
18
+ const default_executor_strategy_js_1 = require("../strategies/default-executor.strategy.js");
19
+ const DEFAULT_CRON_PRESETS = [
20
+ { label: "every-minute", value: "* * * * *" },
21
+ { label: "every-hour", value: "0 * * * *" },
22
+ { label: "every-day-at-midnight", value: "0 0 * * *" },
23
+ { label: "every-week-on-sunday", value: "0 0 * * 0" },
24
+ { label: "every-month-first-day", value: "0 0 1 * *" },
25
+ ];
26
+ let CronJobsService = class CronJobsService {
27
+ constructor(options) {
28
+ this.options = options;
29
+ this.executor = (options === null || options === void 0 ? void 0 : options.executor) || new default_executor_strategy_js_1.DefaultExecutorStrategy();
30
+ }
31
+ async config(ctx) {
32
+ var _a;
33
+ const { knownWorkerJobsToSuggest = [], presets } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
34
+ let finalPresets = DEFAULT_CRON_PRESETS.map((preset) => (Object.assign(Object.assign({}, preset), { default: true })));
35
+ if (presets === null || presets === void 0 ? void 0 : presets.values) {
36
+ if (presets.merge) {
37
+ const existingValues = presets.values.map((p) => p.value);
38
+ finalPresets = [
39
+ ...presets.values.map((preset) => (Object.assign(Object.assign({}, preset), { default: false }))),
40
+ ...DEFAULT_CRON_PRESETS.filter((preset) => !existingValues.includes(preset.value)).map((preset) => (Object.assign(Object.assign({}, preset), { default: true }))),
41
+ ];
42
+ }
43
+ else {
44
+ finalPresets = presets.values.map((preset) => (Object.assign(Object.assign({}, preset), { default: false })));
45
+ }
46
+ }
47
+ return {
48
+ suggestedJobs: knownWorkerJobsToSuggest,
49
+ presets: finalPresets,
50
+ };
51
+ }
52
+ async listJobs(ctx, args) {
53
+ return this.executor.listJobs(ctx, args);
54
+ }
55
+ async createJob(ctx, input) {
56
+ try {
57
+ await this.executor.createJob(ctx, Object.assign(Object.assign({}, input), { controllerPath: ["", constants_js_1.CONTROLLER_PATH, input.jobQueueName].join("/") }));
58
+ return true;
59
+ }
60
+ catch (e) {
61
+ console.error(e);
62
+ return false;
63
+ }
64
+ }
65
+ async updateJob(ctx, job) {
66
+ try {
67
+ await this.executor.updateJob(ctx, job);
68
+ return true;
69
+ }
70
+ catch (e) {
71
+ console.error(e);
72
+ return false;
73
+ }
74
+ }
75
+ async removeJobs(ctx, jobs) {
76
+ try {
77
+ await this.executor.removeJobs(ctx, jobs);
78
+ return true;
79
+ }
80
+ catch (e) {
81
+ console.error(e);
82
+ return false;
83
+ }
84
+ }
85
+ };
86
+ exports.CronJobsService = CronJobsService;
87
+ exports.CronJobsService = CronJobsService = __decorate([
88
+ (0, common_1.Injectable)(),
89
+ __param(0, (0, common_1.Inject)(constants_js_1.CRONJOBS_PLUGIN_OPTIONS)),
90
+ __metadata("design:paramtypes", [Object])
91
+ ], CronJobsService);