@contentcredits/sdk 2.11.0 → 2.13.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.
@@ -74,6 +74,29 @@ export interface CommentsResponse {
74
74
  comments: Comment[];
75
75
  }
76
76
  export type EnsureThreadResponse = CommentThread;
77
+ export type PaywallSlotItemVariant = 'primary' | 'secondary' | 'outline';
78
+ export interface PaywallSlotItem {
79
+ type: 'heading' | 'subheading' | 'text' | 'button' | 'divider';
80
+ /** Text content — used by heading, subheading, text, button, and divider (for the label) */
81
+ content?: string;
82
+ /** Button style variant. Default: 'primary' */
83
+ variant?: PaywallSlotItemVariant;
84
+ /** Click handler for button items */
85
+ onClick?: () => void;
86
+ }
87
+ /**
88
+ * Loosely-typed ReactDOM adapter — matches both React 18 (`createRoot`) and
89
+ * React 16/17 (`render`) without pulling React into the SDK's own bundle.
90
+ */
91
+ export interface ReactDOMAdapter {
92
+ /** React 18+ */
93
+ createRoot?(container: Element): {
94
+ render(node: unknown): void;
95
+ unmount(): void;
96
+ };
97
+ /** React 16/17 */
98
+ render?(node: unknown, container: Element, callback?: () => void): void;
99
+ }
77
100
  export interface SDKConfig {
78
101
  /** Publisher API key from the Content Credits admin panel */
79
102
  apiKey: string;
@@ -89,8 +112,43 @@ export interface SDKConfig {
89
112
  extensionId?: string;
90
113
  /** Visual theme options */
91
114
  theme?: SDKTheme;
92
- /** Custom HTML template string for the paywall overlay */
93
- paywallTemplate?: string;
115
+ /**
116
+ * Paywall display mode.
117
+ * - `'inline'` — panel sits below the teaser content in the page flow (original behaviour)
118
+ * - `'overlay'` — full-width panel that renders below the gated content (default)
119
+ *
120
+ * Default: `'overlay'`
121
+ */
122
+ paywallMode?: 'inline' | 'overlay';
123
+ /**
124
+ * Your ReactDOM instance. Required when `paywallTopSlot` is a React element.
125
+ * Supports React 18 (`createRoot`) and React 16/17 (`render`).
126
+ *
127
+ * @example
128
+ * import ReactDOM from 'react-dom/client'; // React 18
129
+ * ContentCredits.init({ reactDOM, paywallTopSlot: <DonationWidget /> });
130
+ */
131
+ reactDOM?: ReactDOMAdapter;
132
+ /**
133
+ * Content to render in the top section of the paywall panel, above the SDK's
134
+ * own unlock UI.
135
+ *
136
+ * Accepts:
137
+ * - A React element (JSX) — requires `reactDOM` to also be set
138
+ * - A structured `PaywallSlotItem[]` array — SDK renders & styles the items
139
+ * - A plain `HTMLElement` — appended directly into the slot container
140
+ * - A factory `(container: HTMLElement) => void` — called with the slot DOM node
141
+ *
142
+ * @example React widget
143
+ * paywallTopSlot: <DonationWidget /> // also set reactDOM
144
+ *
145
+ * @example Structured items
146
+ * paywallTopSlot: [
147
+ * { type: 'heading', content: 'Donate to access this story.' },
148
+ * { type: 'button', content: 'See Donation Options', variant: 'primary', onClick: openDonate },
149
+ * ]
150
+ */
151
+ paywallTopSlot?: PaywallSlotItem[] | HTMLElement | ((container: HTMLElement) => void) | Record<string, unknown>;
94
152
  /** Called when the user is granted access to the article */
95
153
  onAccessGranted?: () => void;
96
154
  /**
@@ -174,13 +232,15 @@ export interface SDKTheme {
174
232
  /** Font family for all SDK UI elements */
175
233
  fontFamily?: string;
176
234
  }
177
- export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTemplate' | 'onAccessGranted' | 'onStateChange' | 'onReady' | 'onLoginRequired' | 'onPurchaseRequired' | 'onInsufficientCredits' | 'onPurchased' | 'onUserLogin' | 'onUserLogout' | 'onError' | 'theme'>> {
235
+ export interface ResolvedConfig extends Required<Omit<SDKConfig, 'paywallTopSlot' | 'reactDOM' | 'onAccessGranted' | 'onStateChange' | 'onReady' | 'onLoginRequired' | 'onPurchaseRequired' | 'onInsufficientCredits' | 'onPurchased' | 'onUserLogin' | 'onUserLogout' | 'onError' | 'theme'>> {
178
236
  articleUrl: string;
179
237
  hostName: string;
180
238
  pageTitle: string;
181
239
  apiBaseUrl: string;
182
240
  accountsUrl: string;
183
- paywallTemplate?: string;
241
+ paywallMode: 'inline' | 'overlay';
242
+ paywallTopSlot?: SDKConfig['paywallTopSlot'];
243
+ reactDOM?: ReactDOMAdapter;
184
244
  onAccessGranted?: () => void;
185
245
  onStateChange?: (state: SDKState) => void;
186
246
  onReady?: (state: SDKState) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentcredits/sdk",
3
- "version": "2.11.0",
3
+ "version": "2.13.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",