@noirtrack/sdk 0.3.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to `@noirtrack/sdk` are documented here. This project follows semantic versioning (while pre-1.0, a minor bump may include breaking changes).
4
4
 
5
+ ## 0.4.0
6
+
7
+ ### Added
8
+
9
+ - **Subscriptions.** `revenue()` accepts `subscriptionId`, `interval` (`day`, `week`, `month` or `year`) and `intervalCount`, so sales sent from your backend count toward MRR and churn on the Subscriptions page.
10
+ - **Failed payments.** `revenue({ status: 'failed', amount, paymentId })` records a declined attempt as revenue at risk. It never adds to revenue, and the same `paymentId` is stored once.
11
+
5
12
  ## 0.3.0
6
13
 
7
14
  ### Added
@@ -15,7 +15,11 @@ export interface SecretApi {
15
15
  currency?: string;
16
16
  visitorId?: string;
17
17
  event?: string;
18
- status?: 'paid' | 'refunded' | 'cancelled' | 'subscription_ended';
18
+ status?: 'paid' | 'refunded' | 'cancelled' | 'subscription_ended' | 'failed';
19
+ subscriptionId?: string;
20
+ interval?: 'day' | 'week' | 'month' | 'year';
21
+ intervalCount?: number;
22
+ paymentId?: string;
19
23
  refund?: boolean;
20
24
  }): Promise<boolean>;
21
25
  identify(input: IdentifyInput & {
@@ -36,6 +36,10 @@ export function createSecretApi(config) {
36
36
  visitor_id: input.visitorId,
37
37
  event: input.event,
38
38
  status: input.status,
39
+ subscription_id: input.subscriptionId,
40
+ interval: input.interval,
41
+ interval_count: input.intervalCount,
42
+ payment_id: input.paymentId,
39
43
  refund: input.refund, // legacy; the server normalises it to status:refunded
40
44
  }, head, timeoutMs);
41
45
  }
@@ -55,7 +55,7 @@ export type RevenueInput = {
55
55
  visitorId?: string;
56
56
  } | {
57
57
  /**
58
- * Required for `paid`/`refunded`; omit for `cancelled`/`subscription_ended` (no money moves).
58
+ * Required for `paid`/`refunded`/`failed`; omit for `cancelled`/`subscription_ended` (no money moves).
59
59
  * The server rejects a `paid`/`refunded` call with no amount (422) and the SDK fails open
60
60
  * silently — the revenue is dropped, not thrown — so always pass it for those two statuses.
61
61
  */
@@ -63,8 +63,16 @@ export type RevenueInput = {
63
63
  currency?: string;
64
64
  visitorId?: string;
65
65
  event?: string;
66
- /** Lifecycle status. Default `paid`. */
67
- status?: 'paid' | 'refunded' | 'cancelled' | 'subscription_ended';
66
+ /** Lifecycle status. Default `paid`. `failed` records a declined attempt as revenue at risk, never as revenue. */
67
+ status?: 'paid' | 'refunded' | 'cancelled' | 'subscription_ended' | 'failed';
68
+ /** Your subscription id. Links renewals and cancellations so MRR and churn are tracked. */
69
+ subscriptionId?: string;
70
+ /** Billing period of the subscription. Default `month`. */
71
+ interval?: 'day' | 'week' | 'month' | 'year';
72
+ /** How many intervals one payment covers, 1 to 36. Default 1 (a quarterly plan is `month` × 3). */
73
+ intervalCount?: number;
74
+ /** Your provider's id for a failed attempt, so a retried notification is stored once. */
75
+ paymentId?: string;
68
76
  /** @deprecated Legacy alias for `status: 'refunded'`. */
69
77
  refund?: boolean;
70
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noirtrack/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "NoirTrack server SDK. Block bots and bad traffic before your app renders, and record goals, revenue, and identify from your backend with one secret key. Framework-agnostic core plus Next.js, Express, and fetch/edge adapters.",
5
5
  "homepage": "https://noirtrack.com/docs",
6
6
  "bugs": {