notiformer 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/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Notiformer Node.js SDK
3
3
  *
4
- * Real-time alerts, notifications and feature gates for your backend code.
4
+ * ⚠️ BACKEND ONLY Do NOT use this in frontend/browser code.
5
+ * Your API key would be exposed publicly. Use server-side code only
6
+ * (Node.js, Express, Next.js API routes, Cloud Functions, etc.)
5
7
  *
6
8
  * @example
7
9
  * ```ts
@@ -9,27 +11,24 @@
9
11
  *
10
12
  * const n = new Notiformer({ apiKey: 'ntf_live_...' });
11
13
  *
12
- * // Send a notification event
13
14
  * await n.event({
14
15
  * channel: 'payments',
15
16
  * event: 'payment_success',
16
- * description: '$49.00 — john@example.com',
17
+ * description: '$49.00 — user@email.com',
17
18
  * icon: '💳',
18
19
  * notify: true,
19
20
  * });
20
- *
21
- * // Check a feature gate
22
- * const isEnabled = await n.gate('new-checkout-flow');
23
- * if (isEnabled) { ... }
24
21
  * ```
25
22
  */
26
- import type { NotiformerConfig, EventPayload, EventResponse, GateOptions, GateResult } from './types';
23
+ import type { NotiformerConfig, EventPayload, EventResponse, GateOptions, GateResult } from "./types";
27
24
  export type { NotiformerConfig, EventPayload, EventResponse, GateOptions, GateResult, };
28
25
  export declare class Notiformer {
29
26
  private readonly apiKey;
30
27
  private readonly baseUrl;
31
28
  private readonly timeout;
32
29
  private readonly silent;
30
+ private readonly throwOnError;
31
+ private readonly onError?;
33
32
  private readonly logger;
34
33
  private readonly gateCache;
35
34
  constructor(config: NotiformerConfig);
@@ -37,49 +36,29 @@ export declare class Notiformer {
37
36
  * Send an event to a channel. Triggers notifications based on your
38
37
  * dashboard settings.
39
38
  *
40
- * @param payload - The event data
41
- * @returns The created event ID and timestamp, or null if silent mode
39
+ * By default this never throws — a failed notification should never
40
+ * crash your app. Set `throwOnError: true` in config if you need exceptions.
42
41
  *
43
- * @example
44
- * ```ts
45
- * await n.event({
46
- * channel: 'payments',
47
- * event: 'payment_success',
48
- * description: `$49.00 — ${user.email}`,
49
- * icon: '💳',
50
- * tags: { userId: user.id, plan: 'pro' },
51
- * notify: true,
52
- * });
53
- * ```
42
+ * @returns The created event, or null if the call failed.
54
43
  */
55
44
  event(payload: EventPayload): Promise<EventResponse | null>;
56
45
  /**
57
- * Check whether a feature gate is enabled. Results are cached locally
58
- * for `cacheTtl` seconds (default: 30) to minimize API calls.
59
- *
60
- * @param key - The gate key as defined in your dashboard
61
- * @param options - Cache and fallback options
62
- * @returns `true` if the gate is enabled, `false` otherwise
46
+ * Check whether a feature gate is enabled.
47
+ * Results are cached locally for `cacheTtl` seconds (default: 30).
63
48
  *
64
- * @example
65
- * ```ts
66
- * const isEnabled = await n.gate('new-checkout-flow');
67
- * if (isEnabled) {
68
- * // use new checkout
69
- * }
70
- * ```
49
+ * Returns the fallback value (default: false) if the request fails.
71
50
  */
72
51
  gate(key: string, options?: GateOptions): Promise<boolean>;
73
52
  /**
74
- * Like `gate()` but returns the full GateResult object
75
- * including whether the value was cached.
53
+ * Like gate() but returns the full result object with metadata.
76
54
  */
77
55
  gateDetails(key: string, options?: GateOptions): Promise<GateResult>;
78
56
  /**
79
57
  * Clears the in-memory gate cache.
80
- * Useful if you need to force a fresh fetch.
58
+ * Pass a key to clear only that gate, or no args to clear all.
81
59
  */
82
60
  clearGateCache(key?: string): void;
61
+ private handleError;
83
62
  private fetchWithTimeout;
84
63
  }
85
64
  export default Notiformer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EAEX,MAAM,SAAS,CAAC;AAIjB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,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CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,MAAM,EAAE,gBAAgB;IAqDpC;;;;;;;;OAQG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAuDjE;;;;;OAKG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAkCpE;;OAEG;IACG,WAAW,CACf,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC;IAKtB;;;OAGG;IACH,cAAc,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQlC,OAAO,CAAC,WAAW;YAOL,gBAAgB;CAuB/B;AAgDD,eAAe,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -2,7 +2,9 @@
2
2
  /**
3
3
  * Notiformer Node.js SDK
4
4
  *
5
- * Real-time alerts, notifications and feature gates for your backend code.
5
+ * ⚠️ BACKEND ONLY Do NOT use this in frontend/browser code.
6
+ * Your API key would be exposed publicly. Use server-side code only
7
+ * (Node.js, Express, Next.js API routes, Cloud Functions, etc.)
6
8
  *
7
9
  * @example
8
10
  * ```ts
@@ -10,211 +12,180 @@
10
12
  *
11
13
  * const n = new Notiformer({ apiKey: 'ntf_live_...' });
12
14
  *
13
- * // Send a notification event
14
15
  * await n.event({
15
16
  * channel: 'payments',
16
17
  * event: 'payment_success',
17
- * description: '$49.00 — john@example.com',
18
+ * description: '$49.00 — user@email.com',
18
19
  * icon: '💳',
19
20
  * notify: true,
20
21
  * });
21
- *
22
- * // Check a feature gate
23
- * const isEnabled = await n.gate('new-checkout-flow');
24
- * if (isEnabled) { ... }
25
22
  * ```
26
23
  */
27
24
  Object.defineProperty(exports, "__esModule", { value: true });
28
25
  exports.Notiformer = void 0;
29
26
  const logger_1 = require("./logger");
30
27
  const cache_1 = require("./cache");
31
- const DEFAULT_BASE_URL = 'https://api.notiformer.com';
28
+ const PLACEHOLDER_URL = "https://api.notiformer.com";
32
29
  const DEFAULT_TIMEOUT = 5000;
33
30
  const DEFAULT_GATE_TTL = 30;
34
31
  class Notiformer {
35
32
  constructor(config) {
36
- var _a, _b, _c, _d;
33
+ // ── Validation ──────────────────────────────────────────────
34
+ var _a, _b, _c, _d, _e;
37
35
  if (!config.apiKey) {
38
- throw new Error('[notiformer] apiKey is required.');
39
- }
40
- if (!config.apiKey.startsWith('ntf_')) {
41
- console.warn('[notiformer] API key should start with "ntf_". Make sure you are using a valid key from your dashboard.');
42
- }
36
+ throw new Error("[notiformer] Missing apiKey.\n" +
37
+ "Get your API key at https://app.notiformer.com/projects");
38
+ }
39
+ if (!config.apiKey.startsWith("ntf_")) {
40
+ console.warn("[notiformer] ⚠️ Invalid API key format.\n" +
41
+ 'Your key should start with "ntf_live_" or "ntf_test_".\n' +
42
+ "Get a valid key at https://app.notiformer.com/projects");
43
+ }
44
+ const resolvedUrl = ((_a = config.baseUrl) !== null && _a !== void 0 ? _a : PLACEHOLDER_URL).replace(/\/$/, "");
45
+ if (resolvedUrl === PLACEHOLDER_URL) {
46
+ console.warn("[notiformer] ⚠️ No baseUrl configured — using placeholder URL.\n" +
47
+ "The SDK will not work until you set your real Cloud Functions URL.\n" +
48
+ "\n" +
49
+ "Fix: pass your URL when initializing:\n" +
50
+ " new Notiformer({\n" +
51
+ ' apiKey: "ntf_live_...",\n' +
52
+ ' baseUrl: "https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net",\n' +
53
+ " })\n" +
54
+ "\n" +
55
+ "Find your URL in: Firebase Console → Functions → your function URL");
56
+ }
57
+ // ── Init ────────────────────────────────────────────────────
43
58
  this.apiKey = config.apiKey;
44
- this.baseUrl = ((_a = config.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL).replace(/\/$/, '');
59
+ this.baseUrl = resolvedUrl;
45
60
  this.timeout = (_b = config.timeout) !== null && _b !== void 0 ? _b : DEFAULT_TIMEOUT;
46
61
  this.silent = (_c = config.silent) !== null && _c !== void 0 ? _c : false;
47
- this.logger = new logger_1.Logger((_d = config.logLevel) !== null && _d !== void 0 ? _d : 'error');
62
+ this.throwOnError = (_d = config.throwOnError) !== null && _d !== void 0 ? _d : false;
63
+ this.onError = config.onError;
64
+ this.logger = new logger_1.Logger((_e = config.logLevel) !== null && _e !== void 0 ? _e : "warn");
48
65
  this.gateCache = new cache_1.GateCache();
49
- this.logger.debug('Notiformer initialized', { baseUrl: this.baseUrl });
66
+ this.logger.debug("Notiformer initialized", { baseUrl: this.baseUrl });
50
67
  }
51
- // ─────────────────────────────────────────────
52
- // event() — Send a notification event
53
- // ─────────────────────────────────────────────
68
+ // ─────────────────────────────────────────────────────────────
69
+ // event()
70
+ // ─────────────────────────────────────────────────────────────
54
71
  /**
55
72
  * Send an event to a channel. Triggers notifications based on your
56
73
  * dashboard settings.
57
74
  *
58
- * @param payload - The event data
59
- * @returns The created event ID and timestamp, or null if silent mode
75
+ * By default this never throws — a failed notification should never
76
+ * crash your app. Set `throwOnError: true` in config if you need exceptions.
60
77
  *
61
- * @example
62
- * ```ts
63
- * await n.event({
64
- * channel: 'payments',
65
- * event: 'payment_success',
66
- * description: `$49.00 — ${user.email}`,
67
- * icon: '💳',
68
- * tags: { userId: user.id, plan: 'pro' },
69
- * notify: true,
70
- * });
71
- * ```
78
+ * @returns The created event, or null if the call failed.
72
79
  */
73
80
  async event(payload) {
74
81
  var _a;
75
82
  if (this.silent) {
76
- this.logger.info('Silent mode: event suppressed', payload);
83
+ this.logger.info("Silent mode: event suppressed", payload);
77
84
  return null;
78
85
  }
79
86
  if (!payload.channel)
80
- throw new Error('[notiformer] event.channel is required.');
87
+ throw new Error("[notiformer] event.channel is required.");
81
88
  if (!payload.event)
82
- throw new Error('[notiformer] event.event is required.');
83
- this.logger.debug('Sending event', payload);
89
+ throw new Error("[notiformer] event.event is required.");
90
+ this.logger.debug("Sending event", payload);
84
91
  try {
85
- const body = {
86
- channel: payload.channel,
87
- event: payload.event,
88
- description: payload.description,
89
- icon: payload.icon,
90
- tags: payload.tags,
91
- value: payload.value,
92
- notify: (_a = payload.notify) !== null && _a !== void 0 ? _a : true,
93
- groupId: payload.groupId,
94
- };
95
- const res = await this.fetchWithTimeout('/v1/events', {
96
- method: 'POST',
97
- body: JSON.stringify(body),
92
+ const res = await this.fetchWithTimeout("/v1/events", {
93
+ method: "POST",
94
+ body: JSON.stringify({
95
+ channel: payload.channel,
96
+ event: payload.event,
97
+ description: payload.description,
98
+ icon: payload.icon,
99
+ tags: payload.tags,
100
+ value: payload.value,
101
+ notify: (_a = payload.notify) !== null && _a !== void 0 ? _a : true,
102
+ groupId: payload.groupId,
103
+ }),
98
104
  });
99
105
  if (!res.ok) {
100
- const err = await res.json().catch(() => ({ error: 'Unknown', code: String(res.status) }));
101
- this.logger.error(`Event failed: ${err.error} (${err.code})`);
102
- return null;
106
+ const errBody = await res.json().catch(() => ({
107
+ error: `HTTP ${res.status}`,
108
+ code: String(res.status),
109
+ }));
110
+ const err = new Error(`[notiformer] Event failed: ${errBody.error} (${errBody.code})`);
111
+ return this.handleError(err, "event", payload);
103
112
  }
104
113
  const data = await res.json();
105
- this.logger.debug('Event sent', data);
114
+ this.logger.debug("Event sent successfully", data);
106
115
  return data;
107
116
  }
108
117
  catch (err) {
109
- const message = err instanceof Error ? err.message : String(err);
110
- this.logger.error('Event request failed', message);
111
- // Never throw a failed notification should not crash your app
112
- return null;
118
+ const error = toError(err);
119
+ // Detect the most common misconfigurations and give a clear message
120
+ const friendlyError = enrichError(error, this.baseUrl);
121
+ return this.handleError(friendlyError, "event", payload);
113
122
  }
114
123
  }
115
- // ─────────────────────────────────────────────
116
- // gate() — Check a feature gate
117
- // ─────────────────────────────────────────────
124
+ // ─────────────────────────────────────────────────────────────
125
+ // gate()
126
+ // ─────────────────────────────────────────────────────────────
118
127
  /**
119
- * Check whether a feature gate is enabled. Results are cached locally
120
- * for `cacheTtl` seconds (default: 30) to minimize API calls.
121
- *
122
- * @param key - The gate key as defined in your dashboard
123
- * @param options - Cache and fallback options
124
- * @returns `true` if the gate is enabled, `false` otherwise
128
+ * Check whether a feature gate is enabled.
129
+ * Results are cached locally for `cacheTtl` seconds (default: 30).
125
130
  *
126
- * @example
127
- * ```ts
128
- * const isEnabled = await n.gate('new-checkout-flow');
129
- * if (isEnabled) {
130
- * // use new checkout
131
- * }
132
- * ```
131
+ * Returns the fallback value (default: false) if the request fails.
133
132
  */
134
133
  async gate(key, options = {}) {
135
134
  var _a, _b;
136
135
  if (!key)
137
- throw new Error('[notiformer] gate key is required.');
136
+ throw new Error("[notiformer] gate key is required.");
138
137
  const fallback = (_a = options.fallback) !== null && _a !== void 0 ? _a : false;
139
138
  const ttl = (_b = options.cacheTtl) !== null && _b !== void 0 ? _b : DEFAULT_GATE_TTL;
140
- if (this.silent) {
141
- this.logger.info(`Silent mode: gate "${key}" returning fallback (${String(fallback)})`);
139
+ if (this.silent)
142
140
  return fallback;
143
- }
144
- // Check cache first
145
141
  const cached = this.gateCache.get(key);
146
142
  if (cached !== null) {
147
- this.logger.debug(`Gate "${key}" from cache: ${String(cached)}`);
143
+ this.logger.debug(`Gate "${key}" from cache: ${cached}`);
148
144
  return cached;
149
145
  }
150
146
  try {
151
147
  const res = await this.fetchWithTimeout(`/v1/gates/${encodeURIComponent(key)}`);
152
148
  if (!res.ok) {
153
- this.logger.warn(`Gate "${key}" fetch failed (${res.status}), using fallback: ${String(fallback)}`);
149
+ this.logger.warn(`Gate "${key}" fetch failed (${res.status}), using fallback: ${fallback}`);
154
150
  return fallback;
155
151
  }
156
152
  const data = await res.json();
157
153
  this.gateCache.set(key, data.enabled, ttl);
158
- this.logger.debug(`Gate "${key}": ${String(data.enabled)}`);
159
154
  return data.enabled;
160
155
  }
161
156
  catch (err) {
162
- const message = err instanceof Error ? err.message : String(err);
163
- this.logger.warn(`Gate "${key}" request failed (${message}), using fallback: ${String(fallback)}`);
157
+ const error = enrichError(toError(err), this.baseUrl);
158
+ this.handleError(error, "gate", { key });
164
159
  return fallback;
165
160
  }
166
161
  }
167
- // ─────────────────────────────────────────────
168
- // gateDetails() — Get full gate result with metadata
169
- // ─────────────────────────────────────────────
170
162
  /**
171
- * Like `gate()` but returns the full GateResult object
172
- * including whether the value was cached.
163
+ * Like gate() but returns the full result object with metadata.
173
164
  */
174
165
  async gateDetails(key, options = {}) {
175
- var _a, _b;
176
- const fallback = (_a = options.fallback) !== null && _a !== void 0 ? _a : false;
177
- const ttl = (_b = options.cacheTtl) !== null && _b !== void 0 ? _b : DEFAULT_GATE_TTL;
178
- const now = new Date().toISOString();
179
- if (this.silent) {
180
- return { key, enabled: fallback, cached: false, fetchedAt: now };
181
- }
182
- const cachedVal = this.gateCache.get(key);
183
- if (cachedVal !== null) {
184
- return { key, enabled: cachedVal, cached: true, fetchedAt: now };
185
- }
186
- try {
187
- const res = await this.fetchWithTimeout(`/v1/gates/${encodeURIComponent(key)}`);
188
- if (!res.ok) {
189
- return { key, enabled: fallback, cached: false, fetchedAt: now };
190
- }
191
- const data = await res.json();
192
- this.gateCache.set(key, data.enabled, ttl);
193
- return data;
194
- }
195
- catch (_c) {
196
- return { key, enabled: fallback, cached: false, fetchedAt: now };
197
- }
166
+ const enabled = await this.gate(key, options);
167
+ return { key, enabled, cached: false, fetchedAt: new Date().toISOString() };
198
168
  }
199
- // ─────────────────────────────────────────────
200
- // clearGateCache() — Force fresh gate fetch
201
- // ─────────────────────────────────────────────
202
169
  /**
203
170
  * Clears the in-memory gate cache.
204
- * Useful if you need to force a fresh fetch.
171
+ * Pass a key to clear only that gate, or no args to clear all.
205
172
  */
206
173
  clearGateCache(key) {
207
- if (key) {
208
- this.gateCache.delete(key);
209
- }
210
- else {
211
- this.gateCache.clear();
212
- }
174
+ key ? this.gateCache.delete(key) : this.gateCache.clear();
213
175
  }
214
- // ─────────────────────────────────────────────
176
+ // ─────────────────────────────────────────────────────────────
215
177
  // Private helpers
216
- // ─────────────────────────────────────────────
178
+ // ─────────────────────────────────────────────────────────────
179
+ handleError(error, method, payload) {
180
+ var _a;
181
+ this.logger.error(error.message);
182
+ (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error, { method, payload });
183
+ if (this.throwOnError)
184
+ throw error;
185
+ return null;
186
+ }
217
187
  async fetchWithTimeout(path, init = {}) {
188
+ var _a;
218
189
  const controller = new AbortController();
219
190
  const timer = setTimeout(() => controller.abort(), this.timeout);
220
191
  try {
@@ -222,11 +193,11 @@ class Notiformer {
222
193
  ...init,
223
194
  signal: controller.signal,
224
195
  headers: {
225
- 'Content-Type': 'application/json',
226
- 'Authorization': `Bearer ${this.apiKey}`,
227
- 'X-SDK-Version': '1.0.0',
228
- 'X-SDK-Language': 'node',
229
- ...init.headers,
196
+ "Content-Type": "application/json",
197
+ Authorization: `Bearer ${this.apiKey}`,
198
+ "X-SDK-Version": "1.0.1",
199
+ "X-SDK-Language": "node",
200
+ ...((_a = init.headers) !== null && _a !== void 0 ? _a : {}),
230
201
  },
231
202
  });
232
203
  }
@@ -236,8 +207,37 @@ class Notiformer {
236
207
  }
237
208
  }
238
209
  exports.Notiformer = Notiformer;
239
- // ─────────────────────────────────────────────
240
- // Named export for convenience
241
- // ─────────────────────────────────────────────
210
+ // ─────────────────────────────────────────────────────────────
211
+ // Helpers
212
+ // ─────────────────────────────────────────────────────────────
213
+ function toError(err) {
214
+ return err instanceof Error ? err : new Error(String(err));
215
+ }
216
+ /**
217
+ * Converts generic network errors into actionable messages.
218
+ */
219
+ function enrichError(error, baseUrl) {
220
+ const msg = error.message.toLowerCase();
221
+ if (msg.includes("failed to fetch") ||
222
+ msg.includes("err_name_not_resolved") ||
223
+ msg.includes("enotfound") ||
224
+ msg.includes("network")) {
225
+ if (baseUrl === PLACEHOLDER_URL) {
226
+ return new Error("[notiformer] Cannot reach the API — you are using the placeholder URL.\n" +
227
+ "Set your real Cloud Functions URL:\n" +
228
+ " new Notiformer({\n" +
229
+ ' apiKey: "ntf_live_...",\n' +
230
+ ' baseUrl: "https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net",\n' +
231
+ " })");
232
+ }
233
+ return new Error(`[notiformer] Network error — cannot reach ${baseUrl}\n` +
234
+ "Check that your baseUrl is correct and that the server is running.");
235
+ }
236
+ if (msg.includes("aborted") || msg.includes("timeout")) {
237
+ return new Error(`[notiformer] Request timed out after ${DEFAULT_TIMEOUT}ms.\n` +
238
+ "Increase timeout: new Notiformer({ ..., timeout: 10000 })");
239
+ }
240
+ return error;
241
+ }
242
242
  exports.default = Notiformer;
243
243
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAUH,qCAAkC;AAClC,mCAAoC;AAUpC,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AACtD,MAAM,eAAe,GAAG,IAAK,CAAC;AAC9B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAa,UAAU;IAQrB,YAAY,MAAwB;;QAClC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,yGAAyG,CAAC,CAAC;QAC1H,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,CAAC,MAAA,M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AG,CAAC,QAAQ,CAAC,uBAAuB,CAAC;QACrC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;QACzB,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EACvB,CAAC;QACD,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;YAChC,OAAO,IAAI,KAAK,CACd,0EAA0E;gBACxE,sCAAsC;gBACtC,sBAAsB;gBACtB,+BAA+B;gBAC/B,uEAAuE;gBACvE,MAAM,CACT,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,KAAK,CACd,6CAA6C,OAAO,IAAI;YACtD,oEAAoE,CACvE,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACvD,OAAO,IAAI,KAAK,CACd,wCAAwC,eAAe,OAAO;YAC5D,2DAA2D,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,kBAAe,UAAU,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,70 +1,34 @@
1
1
  export interface NotiformerConfig {
2
- /**
3
- * Your project API key from the Notiformer dashboard.
4
- * Get it at: https://app.notiformer.com/projects
5
- */
6
2
  apiKey: string;
7
- /**
8
- * Base URL of the Notiformer API.
9
- * @default 'https://api.notiformer.com'
10
- */
11
3
  baseUrl?: string;
12
- /**
13
- * Request timeout in milliseconds.
14
- * @default 5000
15
- */
16
4
  timeout?: number;
5
+ silent?: boolean;
6
+ logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
17
7
  /**
18
- * If true, SDK calls are no-ops. Useful for local development.
19
- * @default false
8
+ * Called whenever an event() or gate() call fails silently.
9
+ * Use this to log errors to your own monitoring system.
10
+ * @example
11
+ * onError: (err) => Sentry.captureException(err)
20
12
  */
21
- silent?: boolean;
13
+ onError?: (error: Error, context: {
14
+ method: string;
15
+ payload?: unknown;
16
+ }) => void;
22
17
  /**
23
- * Log level for SDK internals.
24
- * @default 'error'
18
+ * If true, event() and gate() will throw on failure instead of returning null/fallback.
19
+ * Only use this if you want to handle errors yourself with try/catch.
20
+ * Default: false (recommended — a failed notification should never crash your app)
25
21
  */
26
- logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'none';
22
+ throwOnError?: boolean;
27
23
  }
28
24
  export interface EventPayload {
29
- /**
30
- * The channel to send this event to.
31
- * Channels group related events (e.g. 'payments', 'auth', 'errors').
32
- * Created automatically on first use.
33
- */
34
25
  channel: string;
35
- /**
36
- * Machine-readable event name (e.g. 'payment_success', 'user_signup').
37
- */
38
26
  event: string;
39
- /**
40
- * Human-readable description shown in the dashboard feed.
41
- */
42
27
  description?: string;
43
- /**
44
- * An emoji icon shown next to the event in the feed.
45
- * @example '💳' | '🚨' | '✅'
46
- */
47
28
  icon?: string;
48
- /**
49
- * Optional key-value tags for filtering and search.
50
- * @example { userId: 'usr_123', plan: 'pro', amount: 49 }
51
- */
52
29
  tags?: Record<string, string | number | boolean>;
53
- /**
54
- * A scalar value to display alongside the event.
55
- * @example '$49.00' | 200 | '98ms'
56
- */
57
30
  value?: string | number;
58
- /**
59
- * If true, triggers configured notification channels (push, email, etc).
60
- * If false, the event is logged silently (analytics only).
61
- * @default true
62
- */
63
31
  notify?: boolean;
64
- /**
65
- * Used for deduplication. Events with the same groupId within
66
- * a short window are rate-limited.
67
- */
68
32
  groupId?: string;
69
33
  }
70
34
  export interface EventResponse {
@@ -72,17 +36,7 @@ export interface EventResponse {
72
36
  createdAt: string;
73
37
  }
74
38
  export interface GateOptions {
75
- /**
76
- * Fallback value returned if the network request fails
77
- * or times out.
78
- * @default false
79
- */
80
39
  fallback?: boolean;
81
- /**
82
- * Cache TTL in seconds. Set to 0 to disable caching.
83
- * Recommended: 30 (default) to reduce API calls.
84
- * @default 30
85
- */
86
40
  cacheTtl?: number;
87
41
  }
88
42
  export interface GateResult {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot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C;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC"}
package/dist/types.js CHANGED
@@ -1,6 +1,3 @@
1
1
  "use strict";
2
- // ─────────────────────────────────────────────
3
- // Notiformer Node.js SDK — Types
4
- // ─────────────────────────────────────────────
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,gDAAgD;AAChD,iCAAiC;AACjC,gDAAgD"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notiformer",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Real-time alerts, notifications and feature gates for your backend code",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",