@contentcredits/sdk 2.1.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.
- package/dist/content-credits.cjs.js +175 -42
- package/dist/content-credits.cjs.js.map +1 -1
- package/dist/content-credits.d.ts +118 -0
- package/dist/content-credits.esm.js +175 -42
- package/dist/content-credits.esm.js.map +1 -1
- package/dist/content-credits.umd.min.js +1 -1
- package/dist/content-credits.umd.min.js.map +1 -1
- package/dist/index.d.ts +46 -0
- package/dist/paywall/index.d.ts +3 -0
- package/dist/types/index.d.ts +94 -1
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -93,8 +93,80 @@ 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;
|
|
156
|
+
/**
|
|
157
|
+
* Headless mode — disables all built-in DOM manipulation and UI rendering.
|
|
158
|
+
*
|
|
159
|
+
* When `true` the SDK will NOT:
|
|
160
|
+
* - hide / reveal the premium content element
|
|
161
|
+
* - inject the paywall overlay or gradient fade
|
|
162
|
+
*
|
|
163
|
+
* Instead it exposes reactive state (via `subscribe()`) and action methods
|
|
164
|
+
* (`login()`, `purchase()`, `buyMoreCredits()`) so you can build a fully
|
|
165
|
+
* custom paywall UI in React, Vue, Svelte, or plain JS.
|
|
166
|
+
*
|
|
167
|
+
* Default: `false`
|
|
168
|
+
*/
|
|
169
|
+
headless?: boolean;
|
|
98
170
|
}
|
|
99
171
|
export interface SDKTheme {
|
|
100
172
|
/** Primary brand colour used for buttons and accents. Default: '#44C678' */
|
|
@@ -102,7 +174,7 @@ export interface SDKTheme {
|
|
|
102
174
|
/** Font family for all SDK UI elements */
|
|
103
175
|
fontFamily?: string;
|
|
104
176
|
}
|
|
105
|
-
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'>> {
|
|
106
178
|
articleUrl: string;
|
|
107
179
|
hostName: string;
|
|
108
180
|
pageTitle: string;
|
|
@@ -110,6 +182,27 @@ export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTemplat
|
|
|
110
182
|
accountsUrl: string;
|
|
111
183
|
paywallTemplate?: string;
|
|
112
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;
|
|
113
206
|
theme: Required<SDKTheme>;
|
|
114
207
|
}
|
|
115
208
|
export interface SDKState {
|