@contentcredits/sdk 2.2.0 → 2.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/dist/api/client.d.ts +7 -7
- package/dist/api/comments.d.ts +3 -2
- package/dist/api/credits.d.ts +3 -2
- package/dist/comments/index.d.ts +7 -6
- package/dist/comments/panel.d.ts +6 -5
- package/dist/content-credits.cjs.js +110 -30
- package/dist/content-credits.cjs.js.map +1 -1
- package/dist/content-credits.d.ts +65 -0
- package/dist/content-credits.esm.js +110 -30
- 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/core/events.d.ts +7 -7
- package/dist/core/state.d.ts +8 -8
- package/dist/extension/bridge.d.ts +11 -11
- package/dist/index.d.ts +7 -0
- package/dist/paywall/index.d.ts +9 -8
- package/dist/paywall/renderer.d.ts +10 -9
- package/dist/types/index.d.ts +80 -1
- package/package.json +6 -2
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,13 @@ export declare class ContentCredits {
|
|
|
97
97
|
closeComments(): void;
|
|
98
98
|
/** Check if the user is currently authenticated. */
|
|
99
99
|
isLoggedIn(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Log the current user out.
|
|
102
|
+
*
|
|
103
|
+
* Revokes the refresh token on the server (best-effort), clears all local
|
|
104
|
+
* auth state, resets SDK state, and emits `auth:logout`.
|
|
105
|
+
*/
|
|
106
|
+
logout(): Promise<void>;
|
|
100
107
|
/** Tear down the SDK — removes all UI, event listeners, and stored state. */
|
|
101
108
|
destroy(): void;
|
|
102
109
|
/** SDK version string. */
|
package/dist/paywall/index.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ import type { createCreditsApi } from '../api/credits.js';
|
|
|
3
3
|
import type { StateStore } from '../core/state.js';
|
|
4
4
|
import type { EventEmitter } from '../core/events.js';
|
|
5
5
|
import type { ResolvedConfig } from '../types/index.js';
|
|
6
|
-
export
|
|
7
|
-
init
|
|
8
|
-
checkAccess
|
|
9
|
-
destroy
|
|
10
|
-
login
|
|
11
|
-
purchase
|
|
12
|
-
buyMoreCredits
|
|
13
|
-
}
|
|
6
|
+
export interface PaywallModule {
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
checkAccess(): Promise<void>;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
login(): Promise<void>;
|
|
11
|
+
purchase(): Promise<void>;
|
|
12
|
+
buyMoreCredits(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function createPaywall(config: ResolvedConfig, creditsApi: ReturnType<typeof createCreditsApi>, state: StateStore, emitter: EventEmitter, existingGate?: Gate): PaywallModule;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { ResolvedConfig } from '../types/index.js';
|
|
2
2
|
export type PaywallUIState = 'checking' | 'login' | 'purchase' | 'insufficient' | 'loading' | 'granted';
|
|
3
3
|
export interface PaywallRendererCallbacks {
|
|
4
|
-
onLogin(): void
|
|
5
|
-
onPurchase(): void
|
|
4
|
+
onLogin(): void | Promise<void>;
|
|
5
|
+
onPurchase(): void | Promise<void>;
|
|
6
6
|
onBuyMoreCredits(): void;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
init
|
|
10
|
-
render
|
|
8
|
+
export interface PaywallRenderer {
|
|
9
|
+
init(): void;
|
|
10
|
+
render(state: PaywallUIState, callbacks: PaywallRendererCallbacks, meta?: {
|
|
11
11
|
requiredCredits?: number | null;
|
|
12
12
|
creditBalance?: number | null;
|
|
13
|
-
})
|
|
14
|
-
setButtonLoading
|
|
15
|
-
destroy
|
|
16
|
-
}
|
|
13
|
+
}): void;
|
|
14
|
+
setButtonLoading(loading: boolean): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createPaywallRenderer(config: ResolvedConfig): PaywallRenderer;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentcredits/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/content-credits/sdk.git"
|
|
10
|
+
},
|
|
7
11
|
"main": "dist/content-credits.cjs.js",
|
|
8
12
|
"module": "dist/content-credits.esm.js",
|
|
9
13
|
"browser": "dist/content-credits.umd.min.js",
|
|
@@ -35,6 +39,7 @@
|
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
37
41
|
"@rollup/plugin-replace": "^5.0.5",
|
|
42
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
38
43
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
39
44
|
"@types/node": "^20.11.5",
|
|
40
45
|
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
@@ -44,7 +49,6 @@
|
|
|
44
49
|
"jsdom": "^24.0.0",
|
|
45
50
|
"rollup": "^4.9.6",
|
|
46
51
|
"rollup-plugin-dts": "^6.1.0",
|
|
47
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
48
52
|
"tslib": "^2.6.2",
|
|
49
53
|
"typescript": "^5.3.3",
|
|
50
54
|
"vitest": "^1.2.2"
|