@deenruv/newsletter-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.
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/newsletter-plugin
2
+
3
+ Plugin that provides newsletter subscription functionality via the Shop API. It uses a strategy-based approach, allowing you to plug in any newsletter service provider (e.g., Mailchimp, SendGrid, custom API).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/newsletter-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { NewsletterPlugin, DefaultNewsletterStrategy } from '@deenruv/newsletter-plugin';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ NewsletterPlugin.init({
19
+ strategy: new DefaultNewsletterStrategy(),
20
+ // Or provide your own:
21
+ // strategy: new MyCustomNewsletterStrategy(),
22
+ }),
23
+ ]
24
+ ```
25
+
26
+ ### Custom Strategy
27
+
28
+ ```typescript
29
+ import type { NewsletterStrategy } from '@deenruv/newsletter-plugin';
30
+
31
+ class MyNewsletterStrategy implements NewsletterStrategy {
32
+ async addToNewsLetter(ctx, email) {
33
+ // Integrate with your newsletter provider
34
+ return { success: true };
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Features
40
+
41
+ - Strategy-based newsletter subscription architecture
42
+ - Built-in `DefaultNewsletterStrategy` for quick setup
43
+ - Shop API mutation for email subscription
44
+ - Error handling with typed error codes (e.g., `InvalidEmail`)
45
+ - Lifecycle management with automatic strategy init/destroy
46
+
47
+ ## Admin UI
48
+
49
+ This plugin is server-only and does not add any admin UI extensions.
50
+
51
+ ## API Extensions
52
+
53
+ ### Shop API
54
+
55
+ - **Mutation** `addToNewsletter(email: String!): AddToNewsletterResult!` — Subscribes an email to the newsletter. Returns either `AddToNewsletterSuccessResult` or `AddToNewsletterErrorResult` with a `NewsletterErrorCode`.
@@ -0,0 +1,13 @@
1
+ import { RequestContext } from "@deenruv/core";
2
+ import { NewsletterService } from "../services/newsletter-service.js";
3
+ export declare class NewsletterShopResolver {
4
+ private newsletterService;
5
+ constructor(newsletterService: NewsletterService);
6
+ addToNewsletter(ctx: RequestContext, args: {
7
+ email: string;
8
+ }): Promise<{
9
+ success: boolean;
10
+ } | {
11
+ errorCode: string;
12
+ }>;
13
+ }
@@ -0,0 +1,36 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Args, Resolver, Mutation } from "@nestjs/graphql";
14
+ import { Ctx, RequestContext } from "@deenruv/core";
15
+ import { NewsletterService } from "../services/newsletter-service.js";
16
+ let NewsletterShopResolver = class NewsletterShopResolver {
17
+ constructor(newsletterService) {
18
+ this.newsletterService = newsletterService;
19
+ }
20
+ async addToNewsletter(ctx, args) {
21
+ return this.newsletterService.addToNewsLetter(ctx, args.email);
22
+ }
23
+ };
24
+ __decorate([
25
+ Mutation(),
26
+ __param(0, Ctx()),
27
+ __param(1, Args()),
28
+ __metadata("design:type", Function),
29
+ __metadata("design:paramtypes", [RequestContext, Object]),
30
+ __metadata("design:returntype", Promise)
31
+ ], NewsletterShopResolver.prototype, "addToNewsletter", null);
32
+ NewsletterShopResolver = __decorate([
33
+ Resolver(),
34
+ __metadata("design:paramtypes", [NewsletterService])
35
+ ], NewsletterShopResolver);
36
+ export { NewsletterShopResolver };
@@ -0,0 +1 @@
1
+ export declare const NEWSLETTER_PLUGIN_OPTIONS: unique symbol;
@@ -0,0 +1 @@
1
+ export const NEWSLETTER_PLUGIN_OPTIONS = Symbol("options");
@@ -0,0 +1 @@
1
+ export declare const shopApiExtension: import("graphql").DocumentNode;
@@ -0,0 +1,19 @@
1
+ import { gql } from "graphql-tag";
2
+ export const shopApiExtension = gql `
3
+ enum NewsletterErrorCode {
4
+ InvalidEmail
5
+ }
6
+ type AddToNewsletterSuccessResult {
7
+ success: Boolean!
8
+ }
9
+ type AddToNewsletterErrorResult {
10
+ errorCode: NewsletterErrorCode!
11
+ }
12
+ union AddToNewsletterResult =
13
+ | AddToNewsletterSuccessResult
14
+ | AddToNewsletterErrorResult
15
+
16
+ extend type Mutation {
17
+ addToNewsletter(email: String!): AddToNewsletterResult!
18
+ }
19
+ `;
@@ -0,0 +1,15 @@
1
+ import { DefaultNewsletterStrategy } from "./strategies/default-newsletter-strategy.js";
2
+ import { NewsletterPluginOptions, NewsletterStrategy } from "./types.js";
3
+ import { ModuleRef } from "@nestjs/core";
4
+ import { OnApplicationBootstrap } from "@nestjs/common";
5
+ declare class NewsletterPlugin implements OnApplicationBootstrap {
6
+ private moduleRef;
7
+ static options: NewsletterPluginOptions;
8
+ constructor(moduleRef: ModuleRef);
9
+ static init(options: NewsletterPluginOptions): typeof NewsletterPlugin;
10
+ onApplicationBootstrap(): Promise<void>;
11
+ onApplicationShutdown(): Promise<void>;
12
+ private initStrategy;
13
+ private destroyStrategy;
14
+ }
15
+ export { NewsletterPlugin, DefaultNewsletterStrategy, NewsletterStrategy };
@@ -0,0 +1,67 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injector, PluginCommonModule, DeenruvPlugin } from "@deenruv/core";
11
+ import { DefaultNewsletterStrategy } from "./strategies/default-newsletter-strategy.js";
12
+ import { ModuleRef } from "@nestjs/core";
13
+ import { NEWSLETTER_PLUGIN_OPTIONS } from "./constants.js";
14
+ import { NewsletterService } from "./services/newsletter-service.js";
15
+ import { shopApiExtension } from "./extensions/api-extension.js";
16
+ import { NewsletterShopResolver } from "./api/newsletter-shop-resolver.js";
17
+ let NewsletterPlugin = class NewsletterPlugin {
18
+ constructor(moduleRef) {
19
+ this.moduleRef = moduleRef;
20
+ }
21
+ static init(options) {
22
+ this.options = options;
23
+ return this;
24
+ }
25
+ async onApplicationBootstrap() {
26
+ await this.initStrategy();
27
+ }
28
+ async onApplicationShutdown() {
29
+ await this.destroyStrategy();
30
+ }
31
+ async initStrategy() {
32
+ const injector = new Injector(this.moduleRef);
33
+ const service = injector.get(NewsletterService);
34
+ if (typeof service.strategy.init === "function") {
35
+ await service.strategy.init(injector);
36
+ }
37
+ }
38
+ async destroyStrategy() {
39
+ const injector = new Injector(this.moduleRef);
40
+ const service = injector.get(NewsletterService);
41
+ if (typeof service.strategy.destroy === "function") {
42
+ await service.strategy.destroy();
43
+ }
44
+ }
45
+ };
46
+ NewsletterPlugin = __decorate([
47
+ DeenruvPlugin({
48
+ compatibility: "^0.0.40",
49
+ imports: [PluginCommonModule],
50
+ providers: [
51
+ {
52
+ provide: NEWSLETTER_PLUGIN_OPTIONS,
53
+ useFactory: () => NewsletterPlugin.options,
54
+ },
55
+ NewsletterService,
56
+ ],
57
+ shopApiExtensions: {
58
+ schema: shopApiExtension,
59
+ resolvers: [NewsletterShopResolver],
60
+ },
61
+ configuration: (config) => {
62
+ return config;
63
+ },
64
+ }),
65
+ __metadata("design:paramtypes", [ModuleRef])
66
+ ], NewsletterPlugin);
67
+ export { NewsletterPlugin, DefaultNewsletterStrategy };
@@ -0,0 +1,14 @@
1
+ import { RequestContext } from "@deenruv/core";
2
+ import { NewsletterPluginOptions, NewsletterStrategy } from "../types.js";
3
+ export declare class NewsletterService {
4
+ private readonly options;
5
+ strategy: NewsletterStrategy;
6
+ private readonly logger;
7
+ private log;
8
+ constructor(options: NewsletterPluginOptions);
9
+ addToNewsLetter(ctx: RequestContext, email: string): Promise<{
10
+ success: boolean;
11
+ } | {
12
+ errorCode: string;
13
+ }>;
14
+ }
@@ -0,0 +1,35 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from "@nestjs/common";
14
+ import { Logger } from "@deenruv/core";
15
+ import { DefaultNewsletterStrategy } from "../strategies/default-newsletter-strategy.js";
16
+ import { NEWSLETTER_PLUGIN_OPTIONS } from "../constants.js";
17
+ let NewsletterService = class NewsletterService {
18
+ constructor(options) {
19
+ var _a;
20
+ this.options = options;
21
+ this.logger = new Logger();
22
+ this.log = (message) => this.logger.log(message, "Newsletter Service");
23
+ this.strategy = (_a = options === null || options === void 0 ? void 0 : options.strategy) !== null && _a !== void 0 ? _a : new DefaultNewsletterStrategy();
24
+ }
25
+ async addToNewsLetter(ctx, email) {
26
+ const response = await this.strategy.addToNewsLetter(ctx, email);
27
+ return response;
28
+ }
29
+ };
30
+ NewsletterService = __decorate([
31
+ Injectable(),
32
+ __param(0, Inject(NEWSLETTER_PLUGIN_OPTIONS)),
33
+ __metadata("design:paramtypes", [Object])
34
+ ], NewsletterService);
35
+ export { NewsletterService };
@@ -0,0 +1,7 @@
1
+ import { RequestContext } from "@deenruv/core";
2
+ import { NewsletterStrategy } from "../types.js";
3
+ export declare class DefaultNewsletterStrategy implements NewsletterStrategy {
4
+ addToNewsLetter(ctx: RequestContext, email: string): Promise<{
5
+ success: boolean;
6
+ }>;
7
+ }
@@ -0,0 +1,5 @@
1
+ export class DefaultNewsletterStrategy {
2
+ async addToNewsLetter(ctx, email) {
3
+ return { success: true };
4
+ }
5
+ }
@@ -0,0 +1,13 @@
1
+ import { InjectableStrategy, RequestContext } from "@deenruv/core";
2
+ export type NewsletterPluginOptions = {
3
+ strategy?: NewsletterStrategy;
4
+ };
5
+ type NewsletterResponse = {
6
+ success: boolean;
7
+ } | {
8
+ errorCode: string;
9
+ };
10
+ export interface NewsletterStrategy extends InjectableStrategy {
11
+ addToNewsLetter: (ctx: RequestContext, email: string) => Promise<NewsletterResponse>;
12
+ }
13
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@deenruv/newsletter-plugin",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "files": [
10
+ "dist/**/*"
11
+ ],
12
+ "exports": {
13
+ "./plugin-server": "./dist/plugin-server/index.js"
14
+ },
15
+ "dependencies": {
16
+ "@nestjs/common": "~10.3.10",
17
+ "@nestjs/graphql": "~12.2.0",
18
+ "graphql": "~16.9.0",
19
+ "graphql-tag": "^2.12.6",
20
+ "graphql-zeus": "^5.4.2",
21
+ "@deenruv/common": "^1.0.0",
22
+ "@deenruv/admin-types": "^1.0.0",
23
+ "@deenruv/react-ui-devkit": "^1.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/express": "^4.17.21",
27
+ "rimraf": "^5.0.10",
28
+ "tslib": "^2.6.2",
29
+ "typescript": "5.3.3",
30
+ "@deenruv/core": "^1.0.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@deenruv/core": "^0.1.0"
34
+ },
35
+ "scripts": {
36
+ "build": "rimraf dist && tsc --build",
37
+ "watch": "concurrently -k -p \"[{name}]\" -n \"SERVER,UI\" -c \"yellow.bold,cyan.bold\" \"tsc --watch --project src/plugin-server/tsconfig.json\"",
38
+ "lint": "eslint ./src/**/*.ts",
39
+ "lint:fix": "eslint --fix ./src/**/*.ts",
40
+ "zeus": "zeus http://localhost:3000/admin-api ./src/plugin-server --es"
41
+ }
42
+ }