@deenruv/merchant-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 (78) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +55 -0
  3. package/dist/plugin-server/api/platform-integration-admin-resolver.d.ts +26 -0
  4. package/dist/plugin-server/api/platform-integration-admin-resolver.js +103 -0
  5. package/dist/plugin-server/constants.d.ts +1 -0
  6. package/dist/plugin-server/constants.js +4 -0
  7. package/dist/plugin-server/e2e/plugin.e2e.test.d.ts +1 -0
  8. package/dist/plugin-server/e2e/plugin.e2e.test.js +36 -0
  9. package/dist/plugin-server/entities/platform-integration-setting.entity.d.ts +10 -0
  10. package/dist/plugin-server/entities/platform-integration-setting.entity.js +37 -0
  11. package/dist/plugin-server/entities/platform-integration-settings.entity.d.ts +9 -0
  12. package/dist/plugin-server/entities/platform-integration-settings.entity.js +33 -0
  13. package/dist/plugin-server/extensions/api-extensions.d.ts +2 -0
  14. package/dist/plugin-server/extensions/api-extensions.js +49 -0
  15. package/dist/plugin-server/index.d.ts +14 -0
  16. package/dist/plugin-server/index.js +100 -0
  17. package/dist/plugin-server/services/facebook-platform-integration.service.d.ts +51 -0
  18. package/dist/plugin-server/services/facebook-platform-integration.service.js +219 -0
  19. package/dist/plugin-server/services/google-platform-integration.service.d.ts +63 -0
  20. package/dist/plugin-server/services/google-platform-integration.service.js +352 -0
  21. package/dist/plugin-server/services/merchant-strategy.service.d.ts +10 -0
  22. package/dist/plugin-server/services/merchant-strategy.service.js +39 -0
  23. package/dist/plugin-server/services/platform-integration.service.d.ts +43 -0
  24. package/dist/plugin-server/services/platform-integration.service.js +282 -0
  25. package/dist/plugin-server/services/subscriber.service.d.ts +30 -0
  26. package/dist/plugin-server/services/subscriber.service.js +90 -0
  27. package/dist/plugin-server/strategies/default-merchant-export-strategy.d.ts +21 -0
  28. package/dist/plugin-server/strategies/default-merchant-export-strategy.js +34 -0
  29. package/dist/plugin-server/types.d.ts +29 -0
  30. package/dist/plugin-server/types.js +2 -0
  31. package/dist/plugin-server/ui/graphql/mutations.ts +23 -0
  32. package/dist/plugin-server/ui/graphql/queries.ts +18 -0
  33. package/dist/plugin-server/ui/graphql/scalars.ts +12 -0
  34. package/dist/plugin-server/ui/pages/FacebookPage.tsx +259 -0
  35. package/dist/plugin-server/ui/pages/GooglePage.tsx +281 -0
  36. package/dist/plugin-server/ui/providers.ts +42 -0
  37. package/dist/plugin-server/ui/routes.ts +18 -0
  38. package/dist/plugin-server/ui/styles/styles.css +3 -0
  39. package/dist/plugin-server/ui/styles/tailwind.css +1297 -0
  40. package/dist/plugin-server/ui/zeus/const.ts +3981 -0
  41. package/dist/plugin-server/ui/zeus/index.ts +18354 -0
  42. package/dist/plugin-server/ui/zeus/typedDocumentNode.ts +30 -0
  43. package/dist/plugin-server/ui.d.ts +2 -0
  44. package/dist/plugin-server/ui.js +15 -0
  45. package/dist/plugin-server/zeus/const.d.ts +6 -0
  46. package/dist/plugin-server/zeus/const.js +3687 -0
  47. package/dist/plugin-server/zeus/index.d.ts +18769 -0
  48. package/dist/plugin-server/zeus/index.js +466 -0
  49. package/dist/plugin-server/zeus/selectors.d.ts +52 -0
  50. package/dist/plugin-server/zeus/selectors.js +51 -0
  51. package/dist/plugin-ui/graphql/mutations.d.ts +29 -0
  52. package/dist/plugin-ui/graphql/mutations.js +17 -0
  53. package/dist/plugin-ui/graphql/queries.d.ts +19 -0
  54. package/dist/plugin-ui/graphql/queries.js +17 -0
  55. package/dist/plugin-ui/graphql/scalars.d.ts +10 -0
  56. package/dist/plugin-ui/graphql/scalars.js +11 -0
  57. package/dist/plugin-ui/index.d.ts +1 -0
  58. package/dist/plugin-ui/index.js +40 -0
  59. package/dist/plugin-ui/locales/en/index.d.ts +8 -0
  60. package/dist/plugin-ui/locales/en/index.js +2 -0
  61. package/dist/plugin-ui/locales/en/merchant.json +7 -0
  62. package/dist/plugin-ui/locales/pl/index.d.ts +8 -0
  63. package/dist/plugin-ui/locales/pl/index.js +2 -0
  64. package/dist/plugin-ui/locales/pl/merchant.json +7 -0
  65. package/dist/plugin-ui/pages/FacebookPage.d.ts +1 -0
  66. package/dist/plugin-ui/pages/FacebookPage.js +130 -0
  67. package/dist/plugin-ui/pages/GooglePage.d.ts +1 -0
  68. package/dist/plugin-ui/pages/GooglePage.js +155 -0
  69. package/dist/plugin-ui/translation-ns.d.ts +1 -0
  70. package/dist/plugin-ui/translation-ns.js +1 -0
  71. package/dist/plugin-ui/tsconfig.json +18 -0
  72. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  73. package/dist/plugin-ui/zeus/const.js +3684 -0
  74. package/dist/plugin-ui/zeus/index.d.ts +18769 -0
  75. package/dist/plugin-ui/zeus/index.js +459 -0
  76. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  77. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  78. package/package.json +63 -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,55 @@
1
+ # @deenruv/merchant-plugin
2
+
3
+ Plugin for exporting product catalog data to merchant platforms like Google Merchant Center and Facebook Commerce. It supports a strategy-based approach for transforming product data into platform-specific formats and managing platform integration settings.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/merchant-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { MerchantPlugin } from '@deenruv/merchant-plugin';
15
+ import type { MerchantExportStrategy } from '@deenruv/merchant-plugin';
16
+
17
+ // Implement your export strategy:
18
+ const myStrategy: MerchantExportStrategy<MyProductData[]> = {
19
+ getBaseData: async (ctx, product) => { /* ... */ },
20
+ prepareGoogleProductPayload: async (ctx, data) => { /* ... */ },
21
+ prepareFacebookProductPayload: async (ctx, data) => { /* ... */ },
22
+ };
23
+
24
+ // In your Deenruv server config:
25
+ plugins: [
26
+ MerchantPlugin.init({
27
+ strategy: myStrategy,
28
+ }),
29
+ ]
30
+ ```
31
+
32
+ ## Features
33
+
34
+ - Strategy-based product export architecture supporting Google and Facebook platforms
35
+ - Google Merchant Center integration via Google Content API
36
+ - Facebook Commerce integration via Facebook Business SDK
37
+ - Per-platform settings storage and management
38
+ - Bulk product sync to merchant platforms
39
+ - Orphan item cleanup for removed products
40
+ - `communicateID` custom field on ProductVariant for platform communication tracking
41
+ - Lifecycle management with automatic strategy init/destroy
42
+
43
+ ## Admin UI
44
+
45
+ This plugin extends the admin UI with dedicated Google and Facebook integration pages where administrators can configure platform credentials, trigger product sync, view connection status, and manage platform settings.
46
+
47
+ ## API Extensions
48
+
49
+ ### Admin API
50
+
51
+ - **Query** `getMerchantPlatformSettings(platform: String!): MerchantPlatformSettingsEntity` — Returns saved settings for a platform
52
+ - **Query** `getMerchantPlatformInfo(platform: String!): [MerchantPlatformInfo!]` — Returns connection status and product count for a platform
53
+ - **Mutation** `sendAllProductsToMerchantPlatform(platform: String!): Boolean` — Triggers a full product sync to the specified platform
54
+ - **Mutation** `saveMerchantPlatformSettings(input: SaveMerchantPlatformSettingInput!): MerchantPlatformSettingsEntity!` — Saves platform credentials and settings
55
+ - **Mutation** `removeOrphanItems(platform: String!): Boolean` — Removes products from the platform that no longer exist in the catalog
@@ -0,0 +1,26 @@
1
+ import { RequestContext } from "@deenruv/core";
2
+ import { GooglePlatformIntegrationService } from "../services/google-platform-integration.service.js";
3
+ import { PlatformIntegrationService } from "../services/platform-integration.service.js";
4
+ import { FacebookPlatformIntegrationService } from "../services/facebook-platform-integration.service.js";
5
+ import { MerchantPlatformSettingsEntity } from "../entities/platform-integration-settings.entity.js";
6
+ export declare class PlatformIntegrationAdminResolver {
7
+ private googlePlatformIntegrationService;
8
+ private facebookPlatformIntegrationService;
9
+ private platformIntegrationService;
10
+ constructor(googlePlatformIntegrationService: GooglePlatformIntegrationService, facebookPlatformIntegrationService: FacebookPlatformIntegrationService, platformIntegrationService: PlatformIntegrationService);
11
+ getMerchantPlatformSettings(ctx: RequestContext, args: {
12
+ platform: string;
13
+ }): Promise<MerchantPlatformSettingsEntity | null>;
14
+ getMerchantPlatformInfo(ctx: RequestContext, args: {
15
+ platform: string;
16
+ }): Promise<{
17
+ productsCount: number;
18
+ isValidConnection: boolean;
19
+ }[]>;
20
+ saveMerchantPlatformSettings(ctx: RequestContext, args: {
21
+ input: MerchantPlatformSettingsEntity;
22
+ }): Promise<MerchantPlatformSettingsEntity | undefined>;
23
+ removeOrphanItems(ctx: RequestContext, args: {
24
+ platform: string;
25
+ }): Promise<boolean>;
26
+ }
@@ -0,0 +1,103 @@
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.PlatformIntegrationAdminResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@deenruv/core");
18
+ const google_platform_integration_service_js_1 = require("../services/google-platform-integration.service.js");
19
+ const platform_integration_setting_entity_js_1 = require("../entities/platform-integration-setting.entity.js");
20
+ const platform_integration_service_js_1 = require("../services/platform-integration.service.js");
21
+ const facebook_platform_integration_service_js_1 = require("../services/facebook-platform-integration.service.js");
22
+ const platform_integration_settings_entity_js_1 = require("../entities/platform-integration-settings.entity.js");
23
+ let PlatformIntegrationAdminResolver = class PlatformIntegrationAdminResolver {
24
+ constructor(googlePlatformIntegrationService, facebookPlatformIntegrationService, platformIntegrationService) {
25
+ this.googlePlatformIntegrationService = googlePlatformIntegrationService;
26
+ this.facebookPlatformIntegrationService = facebookPlatformIntegrationService;
27
+ this.platformIntegrationService = platformIntegrationService;
28
+ }
29
+ getMerchantPlatformSettings(ctx, args) {
30
+ return this.platformIntegrationService.getBaseSettings(ctx, args.platform);
31
+ }
32
+ async getMerchantPlatformInfo(ctx, args) {
33
+ var _a, _b;
34
+ const settings = await this.platformIntegrationService.getBaseSettings(ctx, args.platform);
35
+ if (args.platform === "google") {
36
+ return [
37
+ {
38
+ productsCount: 0,
39
+ isValidConnection: ((_a = settings === null || settings === void 0 ? void 0 : settings.entries.find((entry) => entry.key === "credentials")) === null || _a === void 0 ? void 0 : _a.value) !== "",
40
+ },
41
+ ];
42
+ }
43
+ if (args.platform === "facebook") {
44
+ return [
45
+ {
46
+ productsCount: 0,
47
+ isValidConnection: ((_b = settings === null || settings === void 0 ? void 0 : settings.entries.find((entry) => entry.key === "accessToken")) === null || _b === void 0 ? void 0 : _b.value) !== "",
48
+ },
49
+ ];
50
+ }
51
+ return [{ productsCount: 0, isValidConnection: false }];
52
+ }
53
+ async saveMerchantPlatformSettings(ctx, args) {
54
+ const settingsEntity = new platform_integration_settings_entity_js_1.MerchantPlatformSettingsEntity({
55
+ platform: args.input.platform,
56
+ entries: args.input.entries.map((entry) => new platform_integration_setting_entity_js_1.MerchantPlatformSetting(entry)),
57
+ });
58
+ const settings = await this.platformIntegrationService.savePlatformIntegrationSettings(ctx, settingsEntity);
59
+ return settings;
60
+ }
61
+ async removeOrphanItems(ctx, args) {
62
+ return this.platformIntegrationService.removeOrphanItems(ctx, args.platform);
63
+ }
64
+ };
65
+ exports.PlatformIntegrationAdminResolver = PlatformIntegrationAdminResolver;
66
+ __decorate([
67
+ (0, graphql_1.Query)(),
68
+ __param(0, (0, core_1.Ctx)()),
69
+ __param(1, (0, graphql_1.Args)()),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
72
+ __metadata("design:returntype", void 0)
73
+ ], PlatformIntegrationAdminResolver.prototype, "getMerchantPlatformSettings", null);
74
+ __decorate([
75
+ (0, graphql_1.Query)(),
76
+ __param(0, (0, core_1.Ctx)()),
77
+ __param(1, (0, graphql_1.Args)()),
78
+ __metadata("design:type", Function),
79
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
80
+ __metadata("design:returntype", Promise)
81
+ ], PlatformIntegrationAdminResolver.prototype, "getMerchantPlatformInfo", null);
82
+ __decorate([
83
+ (0, graphql_1.Mutation)(),
84
+ __param(0, (0, core_1.Ctx)()),
85
+ __param(1, (0, graphql_1.Args)()),
86
+ __metadata("design:type", Function),
87
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
88
+ __metadata("design:returntype", Promise)
89
+ ], PlatformIntegrationAdminResolver.prototype, "saveMerchantPlatformSettings", null);
90
+ __decorate([
91
+ (0, graphql_1.Mutation)(),
92
+ __param(0, (0, core_1.Ctx)()),
93
+ __param(1, (0, graphql_1.Args)()),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
96
+ __metadata("design:returntype", Promise)
97
+ ], PlatformIntegrationAdminResolver.prototype, "removeOrphanItems", null);
98
+ exports.PlatformIntegrationAdminResolver = PlatformIntegrationAdminResolver = __decorate([
99
+ (0, graphql_1.Resolver)(),
100
+ __metadata("design:paramtypes", [google_platform_integration_service_js_1.GooglePlatformIntegrationService,
101
+ facebook_platform_integration_service_js_1.FacebookPlatformIntegrationService,
102
+ platform_integration_service_js_1.PlatformIntegrationService])
103
+ ], PlatformIntegrationAdminResolver);
@@ -0,0 +1 @@
1
+ export declare const MERCHANT_PLUGIN_OPTIONS: unique symbol;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MERCHANT_PLUGIN_OPTIONS = void 0;
4
+ exports.MERCHANT_PLUGIN_OPTIONS = Symbol("options");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testing_1 = require("@deenruv/testing");
4
+ const node_test_1 = require("node:test");
5
+ (0, testing_1.registerInitializer)("postgres", new testing_1.PostgresInitializer());
6
+ (0, node_test_1.describe)("test merchant plugin", async () => {
7
+ // const config = {
8
+ // ...testConfig,
9
+ // dbConnectionOptions: {
10
+ // type: "postgres",
11
+ // } as { type: "postgres" },
12
+ // plugins: [MerchantPlugin],
13
+ // };
14
+ // const { server } = createTestEnvironment(config);
15
+ // let magicznyRynekService: PlatformIntegrationService;
16
+ // before(async () => {
17
+ // await server.init({
18
+ // initialData: {
19
+ // defaultLanguage: LanguageCode.en,
20
+ // defaultZone: "Europe",
21
+ // countries: [{ name: "Poland", code: "PL", zone: "Europe" }],
22
+ // taxRates: [],
23
+ // shippingMethods: [],
24
+ // paymentMethods: [],
25
+ // collections: [],
26
+ // },
27
+ // });
28
+ // magicznyRynekService = server.app.get(PlatformIntegrationService);
29
+ // });
30
+ // after(async () => {
31
+ // await server.destroy();
32
+ // });
33
+ // it("should define MagicznyRynekService", () => {
34
+ // ok(magicznyRynekService, "MagicznyRynekService is not defined");
35
+ // });
36
+ });
@@ -0,0 +1,10 @@
1
+ import { DeepPartial } from "@deenruv/common/lib/shared-types.js";
2
+ import { DeenruvEntity } from "@deenruv/core";
3
+ import { MerchantPlatformSettingsEntity } from "./platform-integration-settings.entity.js";
4
+ import type { Relation } from "typeorm";
5
+ export declare class MerchantPlatformSetting extends DeenruvEntity {
6
+ constructor(input?: DeepPartial<MerchantPlatformSetting>);
7
+ key: string;
8
+ value: string;
9
+ settingsEntity: Relation<MerchantPlatformSettingsEntity>;
10
+ }
@@ -0,0 +1,37 @@
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.MerchantPlatformSetting = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const typeorm_1 = require("typeorm");
15
+ const platform_integration_settings_entity_js_1 = require("./platform-integration-settings.entity.js");
16
+ let MerchantPlatformSetting = class MerchantPlatformSetting extends core_1.DeenruvEntity {
17
+ constructor(input) {
18
+ super(input);
19
+ }
20
+ };
21
+ exports.MerchantPlatformSetting = MerchantPlatformSetting;
22
+ __decorate([
23
+ (0, typeorm_1.Column)(),
24
+ __metadata("design:type", String)
25
+ ], MerchantPlatformSetting.prototype, "key", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ type: "text" }),
28
+ __metadata("design:type", String)
29
+ ], MerchantPlatformSetting.prototype, "value", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.ManyToOne)(() => platform_integration_settings_entity_js_1.MerchantPlatformSettingsEntity, (settings) => settings.entries, { onDelete: "CASCADE" }),
32
+ __metadata("design:type", Object)
33
+ ], MerchantPlatformSetting.prototype, "settingsEntity", void 0);
34
+ exports.MerchantPlatformSetting = MerchantPlatformSetting = __decorate([
35
+ (0, typeorm_1.Entity)(),
36
+ __metadata("design:paramtypes", [Object])
37
+ ], MerchantPlatformSetting);
@@ -0,0 +1,9 @@
1
+ import { DeepPartial } from "@deenruv/common/lib/shared-types.js";
2
+ import { DeenruvEntity } from "@deenruv/core";
3
+ import { MerchantPlatformSetting } from "./platform-integration-setting.entity.js";
4
+ import type { Relation } from "typeorm";
5
+ export declare class MerchantPlatformSettingsEntity extends DeenruvEntity {
6
+ constructor(input?: DeepPartial<MerchantPlatformSettingsEntity>);
7
+ platform: string;
8
+ entries: Relation<Array<MerchantPlatformSetting>>;
9
+ }
@@ -0,0 +1,33 @@
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.MerchantPlatformSettingsEntity = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const typeorm_1 = require("typeorm");
15
+ const platform_integration_setting_entity_js_1 = require("./platform-integration-setting.entity.js");
16
+ let MerchantPlatformSettingsEntity = class MerchantPlatformSettingsEntity extends core_1.DeenruvEntity {
17
+ constructor(input) {
18
+ super(input);
19
+ }
20
+ };
21
+ exports.MerchantPlatformSettingsEntity = MerchantPlatformSettingsEntity;
22
+ __decorate([
23
+ (0, typeorm_1.Column)(),
24
+ __metadata("design:type", String)
25
+ ], MerchantPlatformSettingsEntity.prototype, "platform", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.OneToMany)(() => platform_integration_setting_entity_js_1.MerchantPlatformSetting, (setting) => setting.settingsEntity, { eager: true, cascade: true }),
28
+ __metadata("design:type", Object)
29
+ ], MerchantPlatformSettingsEntity.prototype, "entries", void 0);
30
+ exports.MerchantPlatformSettingsEntity = MerchantPlatformSettingsEntity = __decorate([
31
+ (0, typeorm_1.Entity)(),
32
+ __metadata("design:paramtypes", [Object])
33
+ ], MerchantPlatformSettingsEntity);
@@ -0,0 +1,2 @@
1
+ import { DocumentNode } from "graphql";
2
+ export declare const adminApiExtensions: DocumentNode;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adminApiExtensions = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ const base = (0, graphql_tag_1.gql) `
6
+ type MerchantPlatformSetting {
7
+ key: String!
8
+ value: String!
9
+ }
10
+
11
+ type MerchantPlatformSettingsEntity implements Node {
12
+ id: ID!
13
+ platform: String!
14
+ entries: [MerchantPlatformSetting!]
15
+ }
16
+
17
+ type MerchantPlatformInfo {
18
+ isValidConnection: Boolean!
19
+ productsCount: Int!
20
+ }
21
+ `;
22
+ exports.adminApiExtensions = (0, graphql_tag_1.gql) `
23
+ ${base}
24
+
25
+ input MerchantPlatformSettingInput {
26
+ key: String!
27
+ value: String!
28
+ }
29
+
30
+ input SaveMerchantPlatformSettingInput {
31
+ platform: String!
32
+ entries: [MerchantPlatformSettingInput!]
33
+ }
34
+
35
+ extend type Mutation {
36
+ sendAllProductsToMerchantPlatform(platform: String!): Boolean
37
+ saveMerchantPlatformSettings(
38
+ input: SaveMerchantPlatformSettingInput!
39
+ ): MerchantPlatformSettingsEntity!
40
+ removeOrphanItems(platform: String!): Boolean
41
+ }
42
+
43
+ extend type Query {
44
+ getMerchantPlatformSettings(
45
+ platform: String!
46
+ ): MerchantPlatformSettingsEntity
47
+ getMerchantPlatformInfo(platform: String!): [MerchantPlatformInfo!]
48
+ }
49
+ `;
@@ -0,0 +1,14 @@
1
+ import { OnApplicationBootstrap } from "@nestjs/common";
2
+ import { ModuleRef } from "@nestjs/core";
3
+ import { FacebookProduct, GoogleProduct, MerchantExportStrategy, MerchantPluginOptions } from "./types.js";
4
+ declare class MerchantPlugin implements OnApplicationBootstrap {
5
+ private moduleRef;
6
+ static options: MerchantPluginOptions;
7
+ constructor(moduleRef: ModuleRef);
8
+ static init(options: MerchantPluginOptions): typeof MerchantPlugin;
9
+ onApplicationBootstrap(): Promise<void>;
10
+ onApplicationShutdown(): Promise<void>;
11
+ private initMerchantStrategy;
12
+ private destroyMerchantStrategy;
13
+ }
14
+ export { FacebookProduct, GoogleProduct, MerchantExportStrategy, MerchantPlugin, };
@@ -0,0 +1,100 @@
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.MerchantPlugin = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const core_2 = require("@nestjs/core");
15
+ const platform_integration_admin_resolver_js_1 = require("./api/platform-integration-admin-resolver.js");
16
+ const constants_js_1 = require("./constants.js");
17
+ const platform_integration_setting_entity_js_1 = require("./entities/platform-integration-setting.entity.js");
18
+ const platform_integration_settings_entity_js_1 = require("./entities/platform-integration-settings.entity.js");
19
+ const api_extensions_js_1 = require("./extensions/api-extensions.js");
20
+ const facebook_platform_integration_service_js_1 = require("./services/facebook-platform-integration.service.js");
21
+ const google_platform_integration_service_js_1 = require("./services/google-platform-integration.service.js");
22
+ const merchant_strategy_service_js_1 = require("./services/merchant-strategy.service.js");
23
+ const platform_integration_service_js_1 = require("./services/platform-integration.service.js");
24
+ const subscriber_service_js_1 = require("./services/subscriber.service.js");
25
+ let MerchantPlugin = class MerchantPlugin {
26
+ constructor(moduleRef) {
27
+ this.moduleRef = moduleRef;
28
+ }
29
+ static init(options) {
30
+ this.options = options;
31
+ return this;
32
+ }
33
+ async onApplicationBootstrap() {
34
+ await this.initMerchantStrategy();
35
+ }
36
+ async onApplicationShutdown() {
37
+ await this.destroyMerchantStrategy();
38
+ }
39
+ async initMerchantStrategy() {
40
+ const injector = new core_1.Injector(this.moduleRef);
41
+ const service = injector.get(merchant_strategy_service_js_1.MerchantStrategyService);
42
+ if (typeof service.strategy.init === "function") {
43
+ await service.strategy.init(injector);
44
+ }
45
+ }
46
+ async destroyMerchantStrategy() {
47
+ const injector = new core_1.Injector(this.moduleRef);
48
+ const service = injector.get(merchant_strategy_service_js_1.MerchantStrategyService);
49
+ if (typeof service.strategy.destroy === "function") {
50
+ await service.strategy.destroy();
51
+ }
52
+ }
53
+ };
54
+ exports.MerchantPlugin = MerchantPlugin;
55
+ exports.MerchantPlugin = MerchantPlugin = __decorate([
56
+ (0, core_1.DeenruvPlugin)({
57
+ compatibility: "^2.0.0",
58
+ imports: [core_1.PluginCommonModule],
59
+ entities: [platform_integration_setting_entity_js_1.MerchantPlatformSetting, platform_integration_settings_entity_js_1.MerchantPlatformSettingsEntity],
60
+ shopApiExtensions: {},
61
+ adminApiExtensions: {
62
+ schema: api_extensions_js_1.adminApiExtensions,
63
+ resolvers: [platform_integration_admin_resolver_js_1.PlatformIntegrationAdminResolver],
64
+ },
65
+ providers: [
66
+ {
67
+ provide: constants_js_1.MERCHANT_PLUGIN_OPTIONS,
68
+ useFactory: () => MerchantPlugin.options,
69
+ },
70
+ merchant_strategy_service_js_1.MerchantStrategyService,
71
+ platform_integration_service_js_1.PlatformIntegrationService,
72
+ google_platform_integration_service_js_1.GooglePlatformIntegrationService,
73
+ facebook_platform_integration_service_js_1.FacebookPlatformIntegrationService,
74
+ subscriber_service_js_1.SubscriberService,
75
+ ],
76
+ configuration: (config) => {
77
+ config.customFields.ProductVariant.push({
78
+ type: "string",
79
+ name: "communicateID",
80
+ readonly: true,
81
+ label: [
82
+ { languageCode: core_1.LanguageCode.pl, value: "ID komunikacji" },
83
+ { languageCode: core_1.LanguageCode.en, value: "Communication ID" },
84
+ ],
85
+ description: [
86
+ {
87
+ languageCode: core_1.LanguageCode.pl,
88
+ value: "ID do komunikacji z facebookiem lub googlem",
89
+ },
90
+ {
91
+ languageCode: core_1.LanguageCode.en,
92
+ value: "ID for communication with Facebook or Google",
93
+ },
94
+ ],
95
+ });
96
+ return config;
97
+ },
98
+ }),
99
+ __metadata("design:paramtypes", [core_2.ModuleRef])
100
+ ], MerchantPlugin);
@@ -0,0 +1,51 @@
1
+ import { Product, RequestContext, TransactionalConnection } from "@deenruv/core";
2
+ import { MerchantPlatformSettingsEntity } from "../entities/platform-integration-settings.entity.js";
3
+ import { BaseData, BaseProductData } from "../types.js";
4
+ import { MerchantStrategyService } from "./merchant-strategy.service.js";
5
+ type OpResult = {
6
+ status: "success" | "error";
7
+ message?: string;
8
+ };
9
+ export declare class FacebookPlatformIntegrationService {
10
+ private readonly connection;
11
+ private readonly strategy;
12
+ private readonly logger;
13
+ private log;
14
+ private error;
15
+ constructor(connection: TransactionalConnection, strategy: MerchantStrategyService);
16
+ removeOrphanItems(ctx: RequestContext, items: BaseData[]): Promise<void>;
17
+ getAllProducts(ctx: RequestContext): Promise<{
18
+ communicateID: any;
19
+ name: any;
20
+ }[]>;
21
+ private withCatalog;
22
+ private sendBatch;
23
+ createProduct({ ctx, data, }: {
24
+ ctx: RequestContext;
25
+ data: BaseProductData<BaseData>;
26
+ entity?: Product;
27
+ }): Promise<OpResult>;
28
+ updateProduct({ ctx, data, }: {
29
+ ctx: RequestContext;
30
+ data: BaseProductData<BaseData>;
31
+ entity?: Product;
32
+ }): Promise<OpResult>;
33
+ deleteProduct({ ctx, data, }: {
34
+ ctx: RequestContext;
35
+ data: BaseProductData<BaseData>;
36
+ entity?: Product;
37
+ }): Promise<OpResult>;
38
+ batchProductsAction({ ctx, products, }: {
39
+ ctx: RequestContext;
40
+ products: BaseProductData<BaseData>[];
41
+ entity?: Product;
42
+ }): Promise<OpResult>;
43
+ setFacebookSettings(ctx: RequestContext, rawSettings?: MerchantPlatformSettingsEntity): Promise<{
44
+ autoUpdate: boolean;
45
+ accessToken: string;
46
+ catalogId: string;
47
+ brand: string;
48
+ } | null>;
49
+ private prepareFacebookProductPayload;
50
+ }
51
+ export {};