@notifizz/nodejs 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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # 📦 Notifizz Client SDK
2
+
3
+ A **JavaScript/TypeScript** client for sending and tracking events with **Notifizz**.
4
+ It allows you to:
5
+
6
+ - Send events (`track`) with workflows and recipients
7
+ - Configure enrichment functions
8
+ - Handle authentication via `sdkSecretKey` and `authSecretKey`
9
+ - Send notifications directly to the **Notification Center**
10
+
11
+ ---
12
+
13
+ ## 🚀 Installation
14
+
15
+ ```bash
16
+ npm install notifizz-client
17
+ # or
18
+ yarn add notifizz-client
19
+
20
+ ## Initialize the client
21
+
22
+ import { NotifizzClient } from "notifizz-client";
23
+
24
+ const client = new NotifizzClient(
25
+ "AUTH_SECRET_KEY", // provided by Notifizz
26
+ "SDK_SECRET_KEY" // provided by Notifizz
27
+ );
28
+
29
+ ## Track Events
30
+
31
+ await client
32
+ .track({
33
+ eventName: "user_signed_up",
34
+ sdkSecretKey: "SDK_SECRET_KEY",
35
+ properties: {
36
+ plan: "pro",
37
+ source: "landing_page",
38
+ },
39
+ })
40
+ .workflow("campaign_123", [
41
+ { id: "user_1", email: "test@test.com" },
42
+ { id: "user_2", email: "hello@test.com" },
43
+ ]);
44
+
45
+ ## Generate a user token
46
+
47
+ const token = client.generateHashedToken("user_123");
48
+
49
+
50
+ ## Configure enrichment functions
51
+
52
+ NotifizzClient.configureEnrich("workflow_abc", (properties) => ({
53
+ recipients: [{ id: "user_1", email: "test@test.com" }],
54
+ ...properties,
55
+ }));
56
+
57
+ ## Send a notification to the notification center
58
+
59
+ await client.send({
60
+ notifId: "notif_123",
61
+ properties: {
62
+ recipients: [{ id: "user_1", email: "test@test.com" }],
63
+ message: "Hello world",
64
+ },
65
+ });
@@ -0,0 +1,62 @@
1
+ export type TrackProps = {
2
+ eventName: string;
3
+ sdkSecretKey: string;
4
+ properties: {
5
+ [k: string]: any;
6
+ };
7
+ };
8
+ type NotifizzOptions = {
9
+ autoSendDelayMs?: number;
10
+ };
11
+ type EnrichFunction = (properties: {
12
+ [k: string]: any;
13
+ }) => {
14
+ recipients: [EventRecipient];
15
+ [k: string]: any;
16
+ };
17
+ type EventProperties = {
18
+ notifId: string;
19
+ properties: {
20
+ recipients: [EventRecipient];
21
+ [k: string]: any;
22
+ };
23
+ };
24
+ type EventRecipient = {
25
+ id: string;
26
+ email: string;
27
+ };
28
+ declare class TrackContext {
29
+ private readonly event;
30
+ private readonly workflows;
31
+ private hasSent;
32
+ private readonly autoSendTimer;
33
+ private readonly options;
34
+ private readonly sdkSecretKey;
35
+ private readonly baseUrl;
36
+ constructor(event: TrackProps, options: NotifizzOptions, sdkSecretKey: string);
37
+ workflow(campaignId: string, recipients: {
38
+ id: string;
39
+ email: string;
40
+ [k: string]: any;
41
+ }[]): this;
42
+ private send;
43
+ then(resolve: any, reject: any): Promise<void>;
44
+ }
45
+ export declare class NotifizzClient {
46
+ private readonly authSecretKey;
47
+ private readonly sdkSecretKey;
48
+ private readonly baseUrl;
49
+ private readonly algorithm;
50
+ private readonly encoding;
51
+ private options;
52
+ static enrichFunctions: Map<string, EnrichFunction[]>;
53
+ private sha256;
54
+ constructor(authSecretKey: string, sdkSecretKey: string);
55
+ generateHashedToken(userId: string): string;
56
+ static configureEnrich(workflowIds: string | string[], enrichFn: EnrichFunction): void;
57
+ private static addEnrichmentFunction;
58
+ track(props: TrackProps): TrackContext;
59
+ config(opts: Partial<NotifizzOptions>): void;
60
+ send(request: EventProperties): Promise<any>;
61
+ }
62
+ export {};
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NotifizzClient = void 0;
27
+ const axios_1 = __importDefault(require("axios"));
28
+ const node_crypto_1 = __importDefault(require("node:crypto"));
29
+ const defaultOptions = {
30
+ autoSendDelayMs: 1000,
31
+ };
32
+ class TrackContext {
33
+ constructor(event, options, sdkSecretKey) {
34
+ this.workflows = [];
35
+ this.hasSent = false;
36
+ this.autoSendTimer = null;
37
+ this.baseUrl = "http://localhost:6001/v1";
38
+ this.event = event;
39
+ this.options = options;
40
+ this.sdkSecretKey = sdkSecretKey;
41
+ if (options.autoSendDelayMs !== undefined) {
42
+ this.autoSendTimer = setTimeout(() => {
43
+ if (!this.hasSent) {
44
+ this.send();
45
+ }
46
+ }, options.autoSendDelayMs);
47
+ }
48
+ }
49
+ workflow(campaignId, recipients) {
50
+ if (this.hasSent)
51
+ throw new Error("Cannot add workflows after sending the event.");
52
+ this.workflows.push({ campaignId, recipients });
53
+ return this;
54
+ }
55
+ send() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (this.hasSent)
58
+ return;
59
+ if (this.autoSendTimer)
60
+ clearTimeout(this.autoSendTimer);
61
+ this.hasSent = true;
62
+ const payload = Object.assign(Object.assign({}, this.event), { workflows: this.workflows, sdkSecretKey: this.sdkSecretKey });
63
+ try {
64
+ yield axios_1.default.post(`${this.baseUrl}/events/track`, payload, {
65
+ headers: {
66
+ Authorization: `Bearer ${this.sdkSecretKey}`
67
+ }
68
+ });
69
+ }
70
+ catch (e) {
71
+ console.log('Error', e);
72
+ throw e;
73
+ }
74
+ });
75
+ }
76
+ // Optional for promise-like behavior
77
+ then(resolve, reject) {
78
+ return this.send().then(resolve, reject);
79
+ }
80
+ }
81
+ class NotifizzClient {
82
+ sha256(textToHash) {
83
+ return node_crypto_1.default.createHash(this.algorithm).update(textToHash).digest(this.encoding);
84
+ }
85
+ constructor(authSecretKey, sdkSecretKey) {
86
+ this.baseUrl = "http://localhost:6001/v1";
87
+ this.algorithm = 'sha256';
88
+ this.encoding = 'hex';
89
+ this.options = Object.assign({}, defaultOptions);
90
+ this.authSecretKey = authSecretKey;
91
+ this.sdkSecretKey = sdkSecretKey;
92
+ }
93
+ generateHashedToken(userId) {
94
+ return this.sha256(userId + this.authSecretKey);
95
+ }
96
+ static configureEnrich(workflowIds, enrichFn) {
97
+ if (typeof workflowIds === "string") {
98
+ this.addEnrichmentFunction(workflowIds, enrichFn);
99
+ }
100
+ else {
101
+ workflowIds.forEach(workflowId => {
102
+ this.addEnrichmentFunction(workflowId, enrichFn);
103
+ });
104
+ }
105
+ }
106
+ static addEnrichmentFunction(workflowId, enrichFn) {
107
+ var _a;
108
+ if (this.enrichFunctions.has(workflowId)) {
109
+ (_a = this.enrichFunctions.get(workflowId)) === null || _a === void 0 ? void 0 : _a.push(enrichFn);
110
+ }
111
+ else {
112
+ this.enrichFunctions.set(workflowId, [enrichFn]);
113
+ }
114
+ }
115
+ track(props) {
116
+ return new TrackContext(props, this.options, this.sdkSecretKey);
117
+ }
118
+ config(opts) {
119
+ this.options = Object.assign(Object.assign({}, this.options), opts);
120
+ }
121
+ send(request) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ try {
124
+ const _a = request.properties, { recipients } = _a, eventProperties = __rest(_a, ["recipients"]);
125
+ const { data } = yield axios_1.default.post(`${this.baseUrl}/notification/channel/notificationcenter/config/${request.notifId}/track`, { properties: eventProperties, recipients: recipients }, {
126
+ headers: {
127
+ Authorization: `Bearer ${this.sdkSecretKey}`
128
+ }
129
+ });
130
+ return data;
131
+ }
132
+ catch (e) {
133
+ console.log('Error', e);
134
+ throw e;
135
+ }
136
+ });
137
+ }
138
+ }
139
+ exports.NotifizzClient = NotifizzClient;
140
+ NotifizzClient.enrichFunctions = new Map();
141
+ //# sourceMappingURL=NotifizzClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotifizzClient.js","sourceRoot":"","sources":["../src/NotifizzClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,8DAAiC;AAwBjC,MAAM,cAAc,GAAoB;IACtC,eAAe,EAAE,IAAI;CACtB,CAAC;AAeF,MAAM,YAAY;IAWhB,YAAY,KAAiB,EAAE,OAAwB,EAAE,YAAoB;QAT5D,cAAS,GAAsB,EAAE,CAAC;QAC3C,YAAO,GAAG,KAAK,CAAC;QACP,kBAAa,GAA0B,IAAI,CAAC;QAI5C,YAAO,GAAW,0BAA0B,CAAC;QAI5D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,IAAI,OAAO,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YAC1C,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE;gBACnC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,CAAC;YACH,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;QAC9B,CAAC;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IAED,MAAM,CAAC,IAA8B;QACnC,IAAI,CAAC,OAAO,mCAAQ,IAAI,CAAC,OAAO,GAAK,IAAI,CAAE,CAAC;IAC9C,CAAC;IAEK,IAAI,CAAC,OAAwB;;YACjC,IAAI,CAAC;gBACH,MAAM,KAAqC,OAAO,CAAC,UAAU,EAAvD,EAAE,UAAU,OAA2C,EAAtC,eAAe,cAAhC,cAAkC,CAAqB,CAAA;gBAE7D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,IAAI,CAAC,OAAO,mDAAmD,OAAO,CAAC,OAAO,QAAQ,EACzF,EAAC,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAC,EACrD;oBACE,OAAO,EAAE;wBACP,aAAa,EAAE,UAAU,IAAI,CAAC,YAAY,EAAE;qBAC7C;iBACF,CACF,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACxB,MAAM,CAAC,CAAC;YACV,CAAC;QACH,CAAC;KAAA;;AAlEH,wCAmEC;AA5DQ,8BAAe,GAAkC,IAAI,GAAG,EAAE,AAA3C,CAA4C"}
@@ -0,0 +1 @@
1
+ export { NotifizzClient } from "./NotifizzClient";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotifizzClient = void 0;
4
+ var NotifizzClient_1 = require("./NotifizzClient");
5
+ Object.defineProperty(exports, "NotifizzClient", { enumerable: true, get: function () { return NotifizzClient_1.NotifizzClient; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAAvC,gHAAA,cAAc,OAAA"}
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@notifizz/nodejs",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "build": "tsc"
8
+ },
9
+ "keywords": [],
10
+ "author": "damiencosset",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "axios": "^1.8.3"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^22.13.10",
18
+ "typescript": "^5.8.2"
19
+ }
20
+ }
@@ -0,0 +1,175 @@
1
+ import axios from "axios";
2
+ import crypto from "node:crypto";
3
+
4
+ export type TrackProps = {
5
+ eventName: string;
6
+ sdkSecretKey: string;
7
+ properties: {
8
+ [k: string]: any;
9
+ },
10
+ };
11
+
12
+ type WorkflowContext = {
13
+ campaignId: string;
14
+ recipients: { id: string; email: string; [k: string]: any; }[];
15
+ };
16
+
17
+ type NotifizzOptions = {
18
+ autoSendDelayMs?: number;
19
+ };
20
+
21
+ type EnrichFunction = (properties: {[k: string]: any}) => {
22
+ recipients: [EventRecipient];
23
+ [k: string]: any;
24
+ };
25
+
26
+ const defaultOptions: NotifizzOptions = {
27
+ autoSendDelayMs: 1000,
28
+ };
29
+
30
+ type EventProperties = {
31
+ notifId: string;
32
+ properties: {
33
+ recipients: [EventRecipient];
34
+ [k: string]: any;
35
+ },
36
+ }
37
+
38
+ type EventRecipient = {
39
+ id: string,
40
+ email: string,
41
+ }
42
+
43
+ class TrackContext {
44
+ private readonly event: TrackProps;
45
+ private readonly workflows: WorkflowContext[] = [];
46
+ private hasSent = false;
47
+ private readonly autoSendTimer: NodeJS.Timeout | null = null;
48
+ private readonly options: NotifizzOptions;
49
+ private readonly sdkSecretKey: string;
50
+
51
+ private readonly baseUrl: string = "http://localhost:6001/v1";
52
+
53
+
54
+ constructor(event: TrackProps, options: NotifizzOptions, sdkSecretKey: string) {
55
+ this.event = event;
56
+ this.options = options;
57
+ this.sdkSecretKey = sdkSecretKey;
58
+
59
+ if (options.autoSendDelayMs !== undefined) {
60
+ this.autoSendTimer = setTimeout(() => {
61
+ if (!this.hasSent) {
62
+ this.send();
63
+ }
64
+ }, options.autoSendDelayMs);
65
+ }
66
+ }
67
+
68
+ workflow(campaignId: string, recipients: { id: string; email: string; [k: string]: any; }[]) {
69
+ if (this.hasSent) throw new Error("Cannot add workflows after sending the event.");
70
+ this.workflows.push({ campaignId, recipients });
71
+ return this;
72
+ }
73
+
74
+ private async send() {
75
+ if (this.hasSent) return;
76
+ if (this.autoSendTimer) clearTimeout(this.autoSendTimer);
77
+
78
+ this.hasSent = true;
79
+
80
+ const payload = {
81
+ ...this.event,
82
+ workflows: this.workflows,
83
+ sdkSecretKey: this.sdkSecretKey,
84
+ };
85
+ try {
86
+ await axios.post(
87
+ `${this.baseUrl}/events/track`,payload,
88
+ {
89
+ headers: {
90
+ Authorization: `Bearer ${this.sdkSecretKey}`
91
+ }
92
+ }
93
+ );
94
+ }catch(e) {
95
+ console.log('Error', e);
96
+ throw e;
97
+ }
98
+
99
+
100
+ }
101
+
102
+ // Optional for promise-like behavior
103
+ then(resolve: any, reject: any) {
104
+ return this.send().then(resolve, reject);
105
+ }
106
+ }
107
+
108
+ export class NotifizzClient {
109
+ private readonly authSecretKey: string;
110
+ private readonly sdkSecretKey: string;
111
+ private readonly baseUrl: string = "http://localhost:6001/v1";
112
+ private readonly algorithm: string = 'sha256';
113
+ private readonly encoding: crypto.BinaryToTextEncoding = 'hex';
114
+ private options: NotifizzOptions = { ...defaultOptions };
115
+ static enrichFunctions: Map<string, EnrichFunction[]> = new Map();
116
+
117
+ private sha256(textToHash: string): string {
118
+ return crypto.createHash(this.algorithm).update(textToHash).digest(this.encoding);
119
+ }
120
+
121
+ constructor(authSecretKey: string, sdkSecretKey: string) {
122
+ this.authSecretKey = authSecretKey;
123
+ this.sdkSecretKey = sdkSecretKey;
124
+ }
125
+
126
+ generateHashedToken(userId: string): string{
127
+ return this.sha256(userId + this.authSecretKey)
128
+ }
129
+
130
+ static configureEnrich(workflowIds: string | string[], enrichFn: EnrichFunction) {
131
+ if (typeof workflowIds === "string") {
132
+ this.addEnrichmentFunction(workflowIds, enrichFn);
133
+ } else {
134
+ workflowIds.forEach(workflowId => {
135
+ this.addEnrichmentFunction(workflowId, enrichFn);
136
+ });
137
+ }
138
+ }
139
+
140
+ private static addEnrichmentFunction(workflowId: string, enrichFn: EnrichFunction) {
141
+ if (this.enrichFunctions.has(workflowId)) {
142
+ this.enrichFunctions.get(workflowId)?.push(enrichFn);
143
+ } else {
144
+ this.enrichFunctions.set(workflowId, [enrichFn]);
145
+ }
146
+ }
147
+
148
+ track(props: TrackProps): TrackContext {
149
+ return new TrackContext(props, this.options, this.sdkSecretKey);
150
+ }
151
+
152
+ config(opts: Partial<NotifizzOptions>) {
153
+ this.options = { ...this.options, ...opts };
154
+ }
155
+
156
+ async send(request: EventProperties) {
157
+ try {
158
+ const { recipients, ...eventProperties } = request.properties
159
+
160
+ const { data } = await axios.post(
161
+ `${this.baseUrl}/notification/channel/notificationcenter/config/${request.notifId}/track`,
162
+ {properties: eventProperties, recipients: recipients},
163
+ {
164
+ headers: {
165
+ Authorization: `Bearer ${this.sdkSecretKey}`
166
+ }
167
+ }
168
+ );
169
+ return data;
170
+ } catch (e) {
171
+ console.log('Error', e);
172
+ throw e;
173
+ }
174
+ }
175
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {NotifizzClient} from "./NotifizzClient"
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "module": "CommonJS",
5
+ "target": "ES6",
6
+ "declaration": true,
7
+ "sourceMap": true,
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true
11
+ },
12
+ "include": ["src"],
13
+ "exclude": ["node_modules", "dist"]
14
+ }