@deenruv/replicate-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 (62) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +43 -0
  3. package/dist/plugin-server/constants.d.ts +2 -0
  4. package/dist/plugin-server/constants.js +5 -0
  5. package/dist/plugin-server/controllers/replicate.d.ts +22 -0
  6. package/dist/plugin-server/controllers/replicate.js +56 -0
  7. package/dist/plugin-server/e2e/order-export.e2e.test.d.ts +1 -0
  8. package/dist/plugin-server/e2e/order-export.e2e.test.js +163 -0
  9. package/dist/plugin-server/e2e/with-token.e2e.test.d.ts +1 -0
  10. package/dist/plugin-server/e2e/with-token.e2e.test.js +72 -0
  11. package/dist/plugin-server/e2e/without-token.e2e.test.d.ts +1 -0
  12. package/dist/plugin-server/e2e/without-token.e2e.test.js +75 -0
  13. package/dist/plugin-server/entites/replicate.entity.d.ts +13 -0
  14. package/dist/plugin-server/entites/replicate.entity.js +41 -0
  15. package/dist/plugin-server/extensions/replicate.extension.d.ts +1 -0
  16. package/dist/plugin-server/extensions/replicate.extension.js +78 -0
  17. package/dist/plugin-server/graphql/generated-admin-types.d.ts +5847 -0
  18. package/dist/plugin-server/graphql/generated-admin-types.js +1036 -0
  19. package/dist/plugin-server/index.d.ts +5 -0
  20. package/dist/plugin-server/index.js +42 -0
  21. package/dist/plugin-server/resolvers/replicate-admin.resolver.d.ts +35 -0
  22. package/dist/plugin-server/resolvers/replicate-admin.resolver.js +84 -0
  23. package/dist/plugin-server/services/replicate.service.d.ts +43 -0
  24. package/dist/plugin-server/services/replicate.service.js +389 -0
  25. package/dist/plugin-server/types.d.ts +19 -0
  26. package/dist/plugin-server/types.js +2 -0
  27. package/dist/plugin-server/zeus/const.d.ts +6 -0
  28. package/dist/plugin-server/zeus/const.js +3777 -0
  29. package/dist/plugin-server/zeus/index.d.ts +19250 -0
  30. package/dist/plugin-server/zeus/index.js +1104 -0
  31. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  32. package/dist/plugin-server/zeus/typedDocumentNode.js +13 -0
  33. package/dist/plugin-ui/components/Replicate.d.ts +2 -0
  34. package/dist/plugin-ui/components/Replicate.js +307 -0
  35. package/dist/plugin-ui/components/ReplicateUtilities.d.ts +4 -0
  36. package/dist/plugin-ui/components/ReplicateUtilities.js +57 -0
  37. package/dist/plugin-ui/components/index.d.ts +1 -0
  38. package/dist/plugin-ui/components/index.js +1 -0
  39. package/dist/plugin-ui/graphql/mutations.d.ts +11 -0
  40. package/dist/plugin-ui/graphql/mutations.js +11 -0
  41. package/dist/plugin-ui/graphql/queries.d.ts +73 -0
  42. package/dist/plugin-ui/graphql/queries.js +30 -0
  43. package/dist/plugin-ui/graphql/selectors.d.ts +24 -0
  44. package/dist/plugin-ui/graphql/selectors.js +17 -0
  45. package/dist/plugin-ui/index.d.ts +1 -0
  46. package/dist/plugin-ui/index.js +25 -0
  47. package/dist/plugin-ui/locales/en/badges.json +25 -0
  48. package/dist/plugin-ui/locales/en/index.d.ts +26 -0
  49. package/dist/plugin-ui/locales/en/index.js +2 -0
  50. package/dist/plugin-ui/locales/pl/badges.json +25 -0
  51. package/dist/plugin-ui/locales/pl/index.d.ts +26 -0
  52. package/dist/plugin-ui/locales/pl/index.js +2 -0
  53. package/dist/plugin-ui/translation-ns.d.ts +1 -0
  54. package/dist/plugin-ui/translation-ns.js +1 -0
  55. package/dist/plugin-ui/tsconfig.json +18 -0
  56. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  57. package/dist/plugin-ui/zeus/const.js +3774 -0
  58. package/dist/plugin-ui/zeus/index.d.ts +19250 -0
  59. package/dist/plugin-ui/zeus/index.js +1096 -0
  60. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  61. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  62. package/package.json +54 -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,43 @@
1
+ # @deenruv/replicate-plugin
2
+
3
+ An AI-powered plugin that integrates [Replicate](https://replicate.com/) machine learning models with your Deenruv server for model training and order prediction tasks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/replicate-plugin replicate
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { ReplicatePlugin } from '@deenruv/replicate-plugin';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ ReplicatePlugin.init({
19
+ deploymentName: 'your-replicate-deployment',
20
+ apiToken: process.env.REPLICATE_API_TOKEN,
21
+ }),
22
+ ]
23
+ ```
24
+
25
+ ## Features
26
+
27
+ - Integration with Replicate AI deployment API
28
+ - Model training based on order history data
29
+ - Order export and prediction capabilities
30
+ - Custom entity for tracking Replicate job status
31
+ - Admin API for managing AI model operations
32
+ - Webhook controller for receiving Replicate prediction results
33
+
34
+ ## Admin UI
35
+
36
+ This plugin extends the admin UI with a Replicate management dashboard for configuring deployments, initiating model training, viewing prediction results, and monitoring job statuses.
37
+
38
+ ## API Extensions
39
+
40
+ The plugin extends the **Admin API** with:
41
+
42
+ - Mutations for triggering model training and order predictions
43
+ - Queries for retrieving Replicate job status and prediction results
@@ -0,0 +1,2 @@
1
+ export declare const REPLICATE_PLUGIN_OPTIONS: unique symbol;
2
+ export declare const LOGGER_CTX = "ReplicatePlugin";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOGGER_CTX = exports.REPLICATE_PLUGIN_OPTIONS = void 0;
4
+ exports.REPLICATE_PLUGIN_OPTIONS = Symbol("options");
5
+ exports.LOGGER_CTX = "ReplicatePlugin";
@@ -0,0 +1,22 @@
1
+ import { Response } from "express";
2
+ import { ReplicateService } from "../services/replicate.service";
3
+ import { RequestContext } from "@deenruv/core";
4
+ import { PredictionType } from "../graphql/generated-admin-types.js";
5
+ export declare class ReplicateController {
6
+ private replicateService;
7
+ constructor(replicateService: ReplicateService);
8
+ synchronize(res: Response, ctx: RequestContext, { input, }: {
9
+ input: {
10
+ numLastOrder: number;
11
+ startDate: string;
12
+ endDate: string;
13
+ };
14
+ }): Promise<Response<any, Record<string, any>>>;
15
+ exportOrder(res: Response, ctx: RequestContext, input: {
16
+ numLastOrder: number;
17
+ startDate: string;
18
+ endDate: string;
19
+ predictType: PredictionType;
20
+ showMetrics: boolean;
21
+ }): Promise<Response<any, Record<string, any>>>;
22
+ }
@@ -0,0 +1,56 @@
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.ReplicateController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const replicate_service_1 = require("../services/replicate.service");
18
+ const core_1 = require("@deenruv/core");
19
+ const graphql_1 = require("@nestjs/graphql");
20
+ let ReplicateController = class ReplicateController {
21
+ constructor(replicateService) {
22
+ this.replicateService = replicateService;
23
+ }
24
+ async synchronize(res, ctx, { input, }) {
25
+ await this.replicateService.modelTrainingJob(ctx, input);
26
+ return res.send("Job started - model training started");
27
+ }
28
+ async exportOrder(res, ctx, input) {
29
+ const prediction_id = await this.replicateService.orderExportJob(ctx, input);
30
+ return res.send(prediction_id);
31
+ }
32
+ };
33
+ exports.ReplicateController = ReplicateController;
34
+ __decorate([
35
+ (0, common_1.Get)("training/start"),
36
+ __param(0, (0, common_1.Res)()),
37
+ __param(1, (0, core_1.Ctx)()),
38
+ __param(2, (0, graphql_1.Args)()),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", [Object, core_1.RequestContext, Object]),
41
+ __metadata("design:returntype", Promise)
42
+ ], ReplicateController.prototype, "synchronize", null);
43
+ __decorate([
44
+ (0, common_1.Get)("order/export"),
45
+ __param(0, (0, common_1.Res)()),
46
+ __param(1, (0, core_1.Ctx)()),
47
+ __param(2, (0, common_1.Body)()),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", [Object, core_1.RequestContext, Object]),
50
+ __metadata("design:returntype", Promise)
51
+ ], ReplicateController.prototype, "exportOrder", null);
52
+ exports.ReplicateController = ReplicateController = __decorate([
53
+ (0, common_1.Controller)("api/replicate"),
54
+ __param(0, (0, common_1.Inject)(replicate_service_1.ReplicateService)),
55
+ __metadata("design:paramtypes", [replicate_service_1.ReplicateService])
56
+ ], ReplicateController);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const core_1 = require("@deenruv/core");
27
+ const testing_1 = require("@deenruv/testing");
28
+ const node_test_1 = __importStar(require("node:test"));
29
+ const index_js_1 = require("../index.js");
30
+ const replicate_service_js_1 = require("../services/replicate.service.js");
31
+ (0, testing_1.registerInitializer)("postgres", new testing_1.PostgresInitializer());
32
+ (0, node_test_1.describe)("integration tests with replicate token", async () => {
33
+ const deploymentName = "test";
34
+ const apiToken = "test";
35
+ index_js_1.ReplicatePlugin.init({ deploymentName: deploymentName, apiToken: apiToken });
36
+ if (!apiToken || !deploymentName)
37
+ throw new Error("impossible");
38
+ const config = Object.assign(Object.assign({}, testing_1.testConfig), { dbConnectionOptions: {
39
+ type: "postgres",
40
+ host: "localhost",
41
+ port: 5432,
42
+ username: "deenruv",
43
+ password: "deenruv",
44
+ database: "deenruv",
45
+ schema: "public",
46
+ logging: ["error", "warn", "schema", "query", "info", "log"],
47
+ }, plugins: [
48
+ core_1.DefaultJobQueuePlugin.init({}),
49
+ index_js_1.ReplicatePlugin.init({ deploymentName, apiToken }),
50
+ ] });
51
+ const { server, adminClient } = (0, testing_1.createTestEnvironment)(config);
52
+ let app;
53
+ let ctx;
54
+ (0, node_test_1.before)(async () => {
55
+ try {
56
+ await server.init({
57
+ initialData: {
58
+ defaultLanguage: core_1.LanguageCode.en,
59
+ defaultZone: "Europe",
60
+ countries: [{ name: "Poland", code: "PL", zone: "Europe" }],
61
+ taxRates: [],
62
+ shippingMethods: [],
63
+ paymentMethods: [],
64
+ collections: [],
65
+ },
66
+ customerCount: 1,
67
+ });
68
+ app = server.app;
69
+ await app.get(core_1.JobQueueService).start();
70
+ const { superadminCredentials } = app.get(core_1.ConfigService).authOptions;
71
+ const superAdminUser = await app
72
+ .get(core_1.TransactionalConnection)
73
+ .getRepository(core_1.User)
74
+ .findOneOrFail({
75
+ where: { identifier: superadminCredentials.identifier },
76
+ });
77
+ ctx = await app.get(core_1.RequestContextService).create({
78
+ apiType: "admin",
79
+ user: superAdminUser,
80
+ });
81
+ }
82
+ catch (error) {
83
+ console.error("Error:", error);
84
+ }
85
+ });
86
+ (0, node_test_1.after)(async () => {
87
+ await server.destroy();
88
+ });
89
+ (0, node_test_1.default)("test order export job - model training", async () => {
90
+ const productVariantService = app.get(core_1.ProductVariantService);
91
+ const replicateService = app.get(replicate_service_js_1.ReplicateService);
92
+ const orderService = app.get(core_1.OrderService);
93
+ const productService = app.get(core_1.ProductService);
94
+ const assetService = app.get(core_1.AssetService);
95
+ // await productService.create(ctx, {
96
+ // translations: [
97
+ // {
98
+ // languageCode: LanguageCode.en,
99
+ // name: 'Test Product',
100
+ // slug: 'test-product',
101
+ // description: 'A product for testing purposes',
102
+ // },
103
+ // ],
104
+ // enabled: true,
105
+ // });
106
+ // const assetInput: CreateAssetInput = {
107
+ // file: {
108
+ // createReadStream: () => fs.createReadStream(__dirname + '/fixtures/test_product_asset.png'),
109
+ // filename: __dirname + '/fixtures/test_product_asset.png',
110
+ // mimetype: 'image/png',
111
+ // },
112
+ // tags: ['test', 'product'],
113
+ // customFields: {
114
+ // field1: 'value1',
115
+ // field2: 'value2',
116
+ // },
117
+ // };
118
+ // await assetService.create(ctx, assetInput);
119
+ // await productVariantService.create(ctx, [
120
+ // {
121
+ // productId: 1,
122
+ // translations: [
123
+ // {
124
+ // languageCode: LanguageCode.en,
125
+ // name: 'Test Product Variant',
126
+ // },
127
+ // ],
128
+ // facetValueIds: [],
129
+ // sku: 'TEST-SKU',
130
+ // price: 1000,
131
+ // optionIds: [],
132
+ // featuredAssetId: 1,
133
+ // assetIds: [],
134
+ // },
135
+ // ]);
136
+ await productVariantService.create(ctx, [
137
+ {
138
+ productId: 1,
139
+ translations: [
140
+ {
141
+ languageCode: core_1.LanguageCode.en,
142
+ name: "Test Product Variant",
143
+ },
144
+ ],
145
+ facetValueIds: [],
146
+ sku: "TEST-SKU",
147
+ price: 1000,
148
+ optionIds: [],
149
+ featuredAssetId: 1,
150
+ assetIds: [],
151
+ },
152
+ ]);
153
+ // const numLastOrder = 100;
154
+ // await replicateService.startModelTraining(ctx, {
155
+ // numLastOrder,
156
+ // });
157
+ // const ordersCount = (await orderService.findAll(ctx, {})).totalItems;
158
+ // ok(
159
+ // ordersCount >= numLastOrder,
160
+ // 'Total number of orders should be equal or greater than numLastOrder',
161
+ // );
162
+ });
163
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const core_1 = require("@deenruv/core");
27
+ const testing_1 = require("@deenruv/testing");
28
+ const node_test_1 = __importStar(require("node:test"));
29
+ const index_js_1 = require("../index.js");
30
+ (0, testing_1.registerInitializer)("postgres", new testing_1.PostgresInitializer());
31
+ (0, node_test_1.describe)("integration tests with replicate token", async () => {
32
+ const deploymentName = "test";
33
+ const apiToken = "test";
34
+ index_js_1.ReplicatePlugin.init({ deploymentName: deploymentName, apiToken: apiToken });
35
+ if (!apiToken || !deploymentName)
36
+ throw new Error("impossible");
37
+ const config = Object.assign(Object.assign({}, testing_1.testConfig), { dbConnectionOptions: {
38
+ type: "postgres",
39
+ host: "localhost",
40
+ port: 5432,
41
+ username: "deenruv",
42
+ password: "deenruv",
43
+ database: "deenruv",
44
+ schema: "public",
45
+ }, plugins: [
46
+ core_1.DefaultJobQueuePlugin.init({}),
47
+ index_js_1.ReplicatePlugin.init({ deploymentName, apiToken }),
48
+ ] });
49
+ const { server, adminClient } = (0, testing_1.createTestEnvironment)(config);
50
+ let app;
51
+ (0, node_test_1.before)(async () => {
52
+ await server.init({
53
+ initialData: {
54
+ defaultLanguage: core_1.LanguageCode.en,
55
+ defaultZone: "Europe",
56
+ countries: [{ name: "Poland", code: "PL", zone: "Europe" }],
57
+ taxRates: [],
58
+ shippingMethods: [],
59
+ paymentMethods: [],
60
+ collections: [],
61
+ },
62
+ });
63
+ app = server.app;
64
+ await app.get(core_1.JobQueueService).start();
65
+ });
66
+ (0, node_test_1.after)(async () => {
67
+ await server.destroy();
68
+ });
69
+ (0, node_test_1.default)("test model training integration controller api", async () => {
70
+ await adminClient.asSuperAdmin();
71
+ });
72
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const core_1 = require("@deenruv/core");
27
+ const testing_1 = require("@deenruv/testing");
28
+ const node_test_1 = __importStar(require("node:test"));
29
+ const index_js_1 = require("../index.js");
30
+ const constants_js_1 = require("../constants.js");
31
+ const assert_1 = require("assert");
32
+ (0, testing_1.registerInitializer)("postgres", new testing_1.PostgresInitializer());
33
+ (0, node_test_1.describe)("integration tests without replicate token", async () => {
34
+ const deploymentName = "test";
35
+ const apiToken = "test";
36
+ if (!apiToken || !deploymentName)
37
+ throw new Error("impossible");
38
+ const config = Object.assign(Object.assign({}, testing_1.testConfig), { dbConnectionOptions: {
39
+ type: "postgres",
40
+ host: "localhost",
41
+ port: 5432,
42
+ username: "deenruv",
43
+ password: "deenruv",
44
+ database: "deenruv",
45
+ schema: "public",
46
+ }, plugins: [
47
+ core_1.DefaultJobQueuePlugin.init({}),
48
+ index_js_1.ReplicatePlugin.init({
49
+ deploymentName,
50
+ apiToken,
51
+ }),
52
+ ] });
53
+ const { server } = (0, testing_1.createTestEnvironment)(config);
54
+ let app;
55
+ (0, node_test_1.before)(async () => {
56
+ await server.init({
57
+ initialData: {
58
+ defaultLanguage: core_1.LanguageCode.en,
59
+ defaultZone: "Europe",
60
+ countries: [{ name: "Poland", code: "PL", zone: "Europe" }],
61
+ taxRates: [],
62
+ shippingMethods: [],
63
+ paymentMethods: [],
64
+ collections: [],
65
+ },
66
+ });
67
+ app = server.app;
68
+ });
69
+ (0, node_test_1.after)(async () => {
70
+ await server.destroy();
71
+ });
72
+ (0, node_test_1.default)("plugin loads api key", () => {
73
+ (0, assert_1.equal)(app.get(constants_js_1.REPLICATE_PLUGIN_OPTIONS).apiToken, "test");
74
+ });
75
+ });
@@ -0,0 +1,13 @@
1
+ import { DeenruvEntity } from "@deenruv/core";
2
+ import type { DeepPartial, ID } from "@deenruv/core";
3
+ import "reflect-metadata";
4
+ export declare class ReplicateEntity extends DeenruvEntity {
5
+ constructor(input?: DeepPartial<ReplicateEntity>);
6
+ prediction_id: string;
7
+ output: [{
8
+ customerId: ID;
9
+ score: number;
10
+ }];
11
+ status: string;
12
+ finishedAt: Date | null;
13
+ }
@@ -0,0 +1,41 @@
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.ReplicateEntity = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const typeorm_1 = require("typeorm");
15
+ require("reflect-metadata");
16
+ let ReplicateEntity = class ReplicateEntity extends core_1.DeenruvEntity {
17
+ constructor(input) {
18
+ super(input);
19
+ }
20
+ };
21
+ exports.ReplicateEntity = ReplicateEntity;
22
+ __decorate([
23
+ (0, typeorm_1.Column)({ nullable: true, type: "varchar", length: 255 }),
24
+ __metadata("design:type", String)
25
+ ], ReplicateEntity.prototype, "prediction_id", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)("simple-json", { nullable: true }),
28
+ __metadata("design:type", Array)
29
+ ], ReplicateEntity.prototype, "output", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ default: "starting" }),
32
+ __metadata("design:type", String)
33
+ ], ReplicateEntity.prototype, "status", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({ type: Date, nullable: true }),
36
+ __metadata("design:type", Object)
37
+ ], ReplicateEntity.prototype, "finishedAt", void 0);
38
+ exports.ReplicateEntity = ReplicateEntity = __decorate([
39
+ (0, typeorm_1.Entity)(),
40
+ __metadata("design:paramtypes", [Object])
41
+ ], ReplicateEntity);
@@ -0,0 +1 @@
1
+ export declare const AdminExtension: import("graphql").DocumentNode;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminExtension = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ exports.AdminExtension = (0, graphql_tag_1.gql) `
6
+ enum PredictionType {
7
+ RFM_SCORE
8
+ SEGMENTATION
9
+ }
10
+ input StartOrderExportToReplicateInput {
11
+ numLastOrder: Int
12
+ startDate: DateTime
13
+ endDate: DateTime
14
+ predictType: PredictionType
15
+ showMetrics: Boolean
16
+ }
17
+ input startModelTrainingInput {
18
+ numLastOrder: Int
19
+ startDate: DateTime
20
+ endDate: DateTime
21
+ }
22
+
23
+ extend type Mutation {
24
+ startOrderExportToReplicate(
25
+ input: StartOrderExportToReplicateInput!
26
+ ): String!
27
+ }
28
+
29
+ extend type Mutation {
30
+ startModelTraining(input: startModelTrainingInput!): String!
31
+ }
32
+
33
+ input GetPredictionInput {
34
+ prediction_id: String!
35
+ }
36
+
37
+ input GetPredictionEntityInput {
38
+ prediction_entity_id: String!
39
+ }
40
+
41
+ enum PredictionStatus {
42
+ starting
43
+ succeeded
44
+ failed
45
+ }
46
+
47
+ type Prediction {
48
+ id: String!
49
+ score: Float!
50
+ customer: Customer
51
+ }
52
+
53
+ type PredictionResult {
54
+ status: PredictionStatus!
55
+ predictions: [Prediction!]
56
+ }
57
+
58
+ input ReplicateEntityListOptions
59
+
60
+ extend type Query {
61
+ getPredictionID(input: GetPredictionEntityInput!): String
62
+ getReplicatePredictions(
63
+ options: ReplicateEntityListOptions
64
+ ): ReplicateEntityList!
65
+ getPredictionItem(id: String!): PredictionResult!
66
+ }
67
+
68
+ type ReplicateEntity implements Node {
69
+ id: ID!
70
+ status: PredictionStatus!
71
+ finishedAt: DateTime
72
+ }
73
+
74
+ type ReplicateEntityList implements PaginatedList {
75
+ items: [ReplicateEntity!]!
76
+ totalItems: Int!
77
+ }
78
+ `;