@notifizz/nodejs 1.0.0 → 1.0.1

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 CHANGED
@@ -1,33 +1,32 @@
1
- # 📦 Notifizz Client SDK
1
+ # @notifizz/nodejs
2
2
 
3
- A **JavaScript/TypeScript** client for sending and tracking events with **Notifizz**.
4
- It allows you to:
3
+ JavaScript/TypeScript client for sending and tracking events with Notifizz. Use it to track events, run workflows, generate hashed user tokens and send notifications to the Notification Center.
5
4
 
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
5
+ ## Installation
14
6
 
15
7
  ```bash
16
- npm install notifizz-client
8
+ npm install @notifizz/nodejs
17
9
  # or
18
- yarn add notifizz-client
10
+ yarn add @notifizz/nodejs
11
+ ```
12
+
13
+ ## Usage
19
14
 
20
- ## Initialize the client
15
+ ### Initialize the client
21
16
 
22
- import { NotifizzClient } from "notifizz-client";
17
+ ```javascript
18
+ const { NotifizzClient } = require("@notifizz/nodejs");
19
+ // or ESM: import { NotifizzClient } from "@notifizz/nodejs";
23
20
 
24
21
  const client = new NotifizzClient(
25
- "AUTH_SECRET_KEY", // provided by Notifizz
26
- "SDK_SECRET_KEY" // provided by Notifizz
22
+ "AUTH_SECRET_KEY", // provided by Notifizz
23
+ "SDK_SECRET_KEY" // provided by Notifizz
27
24
  );
25
+ ```
28
26
 
29
- ## Track Events
27
+ ### Track events with workflows
30
28
 
29
+ ```javascript
31
30
  await client
32
31
  .track({
33
32
  eventName: "user_signed_up",
@@ -38,28 +37,39 @@ await client
38
37
  },
39
38
  })
40
39
  .workflow("campaign_123", [
41
- { id: "user_1", email: "test@test.com" },
42
- { id: "user_2", email: "hello@test.com" },
40
+ { id: "user_1", email: "user1@example.com" },
41
+ { id: "user_2", email: "user2@example.com" },
43
42
  ]);
43
+ ```
44
44
 
45
- ## Generate a user token
46
-
47
- const token = client.generateHashedToken("user_123");
45
+ You can chain multiple `.workflow(campaignId, recipients)` calls before it sends.
48
46
 
47
+ ### Generate a hashed user token
49
48
 
50
- ## Configure enrichment functions
49
+ Use this for backend authentication (e.g. Notification Center).
51
50
 
52
- NotifizzClient.configureEnrich("workflow_abc", (properties) => ({
53
- recipients: [{ id: "user_1", email: "test@test.com" }],
54
- ...properties,
55
- }));
51
+ ```javascript
52
+ const token = client.generateHashedToken("user_123");
53
+ ```
56
54
 
57
- ## Send a notification to the notification center
55
+ ### Send a notification to the Notification Center
58
56
 
57
+ ```javascript
59
58
  await client.send({
60
59
  notifId: "notif_123",
61
60
  properties: {
62
- recipients: [{ id: "user_1", email: "test@test.com" }],
61
+ recipients: [{ id: "user_1", email: "user@example.com" }],
63
62
  message: "Hello world",
64
63
  },
65
64
  });
65
+ ```
66
+
67
+ ## API summary| Method | Description |
68
+ |--------|-------------|
69
+ | `new NotifizzClient(authSecretKey, sdkSecretKey)` | Create a client. |
70
+ | `client.track({ eventName, sdkSecretKey, properties })` | Start tracking an event; returns a context. |
71
+ | `context.workflow(campaignId, recipients)` | Attach a workflow and recipients (chainable). |
72
+ | `client.generateHashedToken(userId)` | Generate a hashed token for the user. |
73
+ | `NotifizzClient.configureEnrich(workflowIds, fn)` | Register an enrichment function for workflow(s). |
74
+ | `client.send({ notifId, properties })` | Send a notification to the Notification Center. |
75
+ | `client.config({ autoSendDelayMs })` | Configure options (e.g. auto-send delay in ms). |
@@ -34,7 +34,7 @@ class TrackContext {
34
34
  this.workflows = [];
35
35
  this.hasSent = false;
36
36
  this.autoSendTimer = null;
37
- this.baseUrl = "http://localhost:6001/v1";
37
+ this.baseUrl = "https://eu.api.notifizz.com/v1";
38
38
  this.event = event;
39
39
  this.options = options;
40
40
  this.sdkSecretKey = sdkSecretKey;
@@ -83,7 +83,7 @@ class NotifizzClient {
83
83
  return node_crypto_1.default.createHash(this.algorithm).update(textToHash).digest(this.encoding);
84
84
  }
85
85
  constructor(authSecretKey, sdkSecretKey) {
86
- this.baseUrl = "http://localhost:6001/v1";
86
+ this.baseUrl = "https://eu.api.notifizz.com/v1";
87
87
  this.algorithm = 'sha256';
88
88
  this.encoding = 'hex';
89
89
  this.options = Object.assign({}, defaultOptions);
@@ -1 +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;IACH,CAAC;IAED,QAAQ,CAAC,UAAkB,EAAE,UAA8D;QACzF,IAAI,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAChD,OAAO,IA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KAAK,CAAC,KAAiB;QACrB,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClE,CAAC;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"}
package/package.json CHANGED
@@ -1,11 +1,20 @@
1
1
  {
2
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"
3
+ "version": "1.0.1",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org"
8
7
  },
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "start": "node dist/index.js"
17
+ },
9
18
  "keywords": [],
10
19
  "author": "damiencosset",
11
20
  "license": "ISC",
@@ -1,175 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export {NotifizzClient} from "./NotifizzClient"
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
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
- }