@contentcredits/sdk 2.2.0 → 2.3.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.
@@ -93,6 +93,64 @@ export interface SDKConfig {
93
93
  paywallTemplate?: string;
94
94
  /** Called when the user is granted access to the article */
95
95
  onAccessGranted?: () => void;
96
+ /**
97
+ * Called on every state change. Receives the full state snapshot.
98
+ * Use this as the single reactive hook to drive a custom UI instead of
99
+ * calling `cc.subscribe()` separately.
100
+ */
101
+ onStateChange?: (state: SDKState) => void;
102
+ /**
103
+ * Called once the SDK has finished its first access check.
104
+ * Equivalent to listening for the `ready` event.
105
+ */
106
+ onReady?: (state: SDKState) => void;
107
+ /**
108
+ * Called when the paywall is reached and the user is **not logged in**.
109
+ * Render your login UI here and call `cc.login()` from your button.
110
+ */
111
+ onLoginRequired?: () => void;
112
+ /**
113
+ * Called when the user is logged in but has **not yet purchased** this article.
114
+ * Render your unlock/purchase UI here and call `cc.purchase()` from your button.
115
+ */
116
+ onPurchaseRequired?: (info: {
117
+ requiredCredits: number | null;
118
+ creditBalance: number | null;
119
+ }) => void;
120
+ /**
121
+ * Called when the user is logged in but their credit balance is **below** the
122
+ * article price. Render a top-up UI here and call `cc.buyMoreCredits()`.
123
+ */
124
+ onInsufficientCredits?: (info: {
125
+ required: number;
126
+ available: number;
127
+ }) => void;
128
+ /**
129
+ * Called after a successful article purchase.
130
+ * Equivalent to listening for the `article:purchased` event.
131
+ */
132
+ onPurchased?: (info: {
133
+ creditsSpent: number;
134
+ remainingBalance: number;
135
+ }) => void;
136
+ /**
137
+ * Called when a user logs in.
138
+ * Equivalent to listening for the `auth:login` event.
139
+ */
140
+ onUserLogin?: (user: User) => void;
141
+ /**
142
+ * Called when the user logs out.
143
+ * Equivalent to listening for the `auth:logout` event.
144
+ */
145
+ onUserLogout?: () => void;
146
+ /**
147
+ * Called when any SDK error occurs.
148
+ * Equivalent to listening for the `error` event.
149
+ */
150
+ onError?: (info: {
151
+ message: string;
152
+ error?: unknown;
153
+ }) => void;
96
154
  /** Enable verbose debug logging */
97
155
  debug?: boolean;
98
156
  /**
@@ -116,7 +174,7 @@ export interface SDKTheme {
116
174
  /** Font family for all SDK UI elements */
117
175
  fontFamily?: string;
118
176
  }
119
- export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTemplate' | 'onAccessGranted' | 'theme'>> {
177
+ export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTemplate' | 'onAccessGranted' | 'onStateChange' | 'onReady' | 'onLoginRequired' | 'onPurchaseRequired' | 'onInsufficientCredits' | 'onPurchased' | 'onUserLogin' | 'onUserLogout' | 'onError' | 'theme'>> {
120
178
  articleUrl: string;
121
179
  hostName: string;
122
180
  pageTitle: string;
@@ -124,6 +182,27 @@ export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTemplat
124
182
  accountsUrl: string;
125
183
  paywallTemplate?: string;
126
184
  onAccessGranted?: () => void;
185
+ onStateChange?: (state: SDKState) => void;
186
+ onReady?: (state: SDKState) => void;
187
+ onLoginRequired?: () => void;
188
+ onPurchaseRequired?: (info: {
189
+ requiredCredits: number | null;
190
+ creditBalance: number | null;
191
+ }) => void;
192
+ onInsufficientCredits?: (info: {
193
+ required: number;
194
+ available: number;
195
+ }) => void;
196
+ onPurchased?: (info: {
197
+ creditsSpent: number;
198
+ remainingBalance: number;
199
+ }) => void;
200
+ onUserLogin?: (user: User) => void;
201
+ onUserLogout?: () => void;
202
+ onError?: (info: {
203
+ message: string;
204
+ error?: unknown;
205
+ }) => void;
127
206
  theme: Required<SDKTheme>;
128
207
  }
129
208
  export interface SDKState {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentcredits/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Content Credits JS SDK — drop-in paywall and comments for any website",
5
5
  "author": "Content Credits",
6
6
  "license": "Apache-2.0",