@contentcredits/sdk 2.0.0 → 2.0.2
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/LICENSE +178 -0
- package/README.md +180 -0
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, and
|
|
120
|
+
distribute those modifications.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate license agreement you may have executed
|
|
128
|
+
with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any warranties or conditions
|
|
140
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
141
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
142
|
+
appropriateness of using or reproducing the Work and assume any
|
|
143
|
+
risks associated with Your exercise of permissions under this License.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
147
|
+
unless required by applicable law (such as deliberate and grossly
|
|
148
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special,
|
|
150
|
+
incidental, or exemplary damages of any character arising as a
|
|
151
|
+
result of this License or out of the use or inability to use the
|
|
152
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
153
|
+
work stoppage, computer failure or malfunction, or all other
|
|
154
|
+
commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
158
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
159
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
160
|
+
or other liability obligations and/or rights consistent with this
|
|
161
|
+
License. However, in accepting such obligations, You may offer only
|
|
162
|
+
conditions consistent with this License.
|
|
163
|
+
|
|
164
|
+
END OF TERMS AND CONDITIONS
|
|
165
|
+
|
|
166
|
+
Copyright 2025 Content Credits
|
|
167
|
+
|
|
168
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
169
|
+
you may not use this file except in compliance with the License.
|
|
170
|
+
You may obtain a copy of the License at
|
|
171
|
+
|
|
172
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
173
|
+
|
|
174
|
+
Unless required by applicable law or agreed to in writing, software
|
|
175
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
176
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
177
|
+
implied. See the License for the specific language governing
|
|
178
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @contentcredits/sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@contentcredits/sdk)
|
|
4
|
+
[](https://github.com/contentcredits/sdk/blob/main/LICENSE)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
Drop-in paywall and threaded comment system for any website. Add credit-based article monetisation in under 5 minutes — no backend changes required.
|
|
8
|
+
|
|
9
|
+
**[Full documentation →](https://docs.contentcredits.com)**
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What it does
|
|
14
|
+
|
|
15
|
+
- **Paywall** — hides premium content behind a credit gate using a CSS selector. Reveals it instantly when the reader pays. No server-side content splitting needed.
|
|
16
|
+
- **Comments** — threaded comment panel with likes, edit, delete, and sorting. Rendered in a Shadow DOM so it never conflicts with your CSS.
|
|
17
|
+
- **Auth** — popup-based login on desktop, redirect flow on mobile. Tokens stored in memory (never cookies).
|
|
18
|
+
- **Extension support** — detects the Content Credits Chrome extension for a one-click experience.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @contentcredits/sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or via CDN (no build step):
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/@contentcredits/sdk@2.0.0/dist/content-credits.umd.min.js"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
### Script tag (CDN)
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<!-- Wrap your premium content -->
|
|
42
|
+
<div id="premium-content">
|
|
43
|
+
<p>This content is only visible after the reader pays.</p>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<!-- Load and initialise the SDK -->
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/npm/@contentcredits/sdk@2.0.0/dist/content-credits.umd.min.js"></script>
|
|
48
|
+
<script>
|
|
49
|
+
ContentCreditsSDK.ContentCredits.init({
|
|
50
|
+
apiKey: 'pub_YOUR_API_KEY',
|
|
51
|
+
contentSelector: '#premium-content',
|
|
52
|
+
teaserParagraphs: 2,
|
|
53
|
+
enableComments: true,
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Auto-init (zero JavaScript)
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<script
|
|
62
|
+
src="https://cdn.jsdelivr.net/npm/@contentcredits/sdk@2.0.0/dist/content-credits.umd.min.js"
|
|
63
|
+
data-api-key="pub_YOUR_API_KEY"
|
|
64
|
+
data-content-selector="#premium-content"
|
|
65
|
+
data-teaser-paragraphs="2"
|
|
66
|
+
></script>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### npm / ES module
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { ContentCredits } from '@contentcredits/sdk';
|
|
73
|
+
|
|
74
|
+
const cc = ContentCredits.init({
|
|
75
|
+
apiKey: 'pub_YOUR_API_KEY',
|
|
76
|
+
contentSelector: '#premium-content',
|
|
77
|
+
teaserParagraphs: 2,
|
|
78
|
+
enableComments: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
cc.on('paywall:hidden', () => {
|
|
82
|
+
console.log('Article unlocked!');
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
| Option | Type | Default | Description |
|
|
91
|
+
|--------|------|---------|-------------|
|
|
92
|
+
| `apiKey` | `string` | **required** | Your publisher API key from the dashboard |
|
|
93
|
+
| `contentSelector` | `string` | `'.cc-premium-content'` | CSS selector for the gated element |
|
|
94
|
+
| `teaserParagraphs` | `number` | `2` | Paragraphs to show before the paywall |
|
|
95
|
+
| `enableComments` | `boolean` | `true` | Show the comment widget |
|
|
96
|
+
| `articleUrl` | `string` | `location.href` | Canonical URL of the article |
|
|
97
|
+
| `theme.primaryColor` | `string` | `'#44C678'` | Brand colour for buttons |
|
|
98
|
+
| `theme.fontFamily` | `string` | system UI | Font for all SDK UI |
|
|
99
|
+
| `onAccessGranted` | `() => void` | — | Fires when content is unlocked |
|
|
100
|
+
| `debug` | `boolean` | `false` | Verbose console logging |
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Events
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
cc.on('ready', ({ state }) => { });
|
|
108
|
+
cc.on('auth:login', ({ user }) => { });
|
|
109
|
+
cc.on('auth:logout', () => { });
|
|
110
|
+
cc.on('paywall:shown', () => { });
|
|
111
|
+
cc.on('paywall:hidden', () => { });
|
|
112
|
+
cc.on('article:purchased', ({ creditsSpent, remainingBalance }) => { });
|
|
113
|
+
cc.on('credits:insufficient',({ required, available }) => { });
|
|
114
|
+
cc.on('comment:posted', ({ comment }) => { });
|
|
115
|
+
cc.on('comment:liked', ({ commentId, hasLiked }) => { });
|
|
116
|
+
cc.on('comment:deleted', ({ commentId }) => { });
|
|
117
|
+
cc.on('error', ({ message, error }) => { });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
All events are also dispatched as native `CustomEvent`s on `document` with the prefix `contentcredits:` — useful for Google Tag Manager and analytics integrations.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## API
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const cc = ContentCredits.init(config);
|
|
128
|
+
|
|
129
|
+
cc.on(event, handler) // subscribe — returns unsubscribe fn
|
|
130
|
+
cc.off(event, handler) // unsubscribe
|
|
131
|
+
cc.getState() // → SDKState snapshot
|
|
132
|
+
cc.checkAccess() // trigger access check manually
|
|
133
|
+
cc.openComments() // open comment panel
|
|
134
|
+
cc.closeComments() // close comment panel
|
|
135
|
+
cc.isLoggedIn() // → boolean
|
|
136
|
+
cc.destroy() // tear down SDK, restore hidden content
|
|
137
|
+
|
|
138
|
+
ContentCredits.version // → "2.0.0"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## React / Next.js
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
'use client'; // Next.js App Router
|
|
147
|
+
|
|
148
|
+
import { useEffect } from 'react';
|
|
149
|
+
import { ContentCredits } from '@contentcredits/sdk';
|
|
150
|
+
|
|
151
|
+
export function PremiumGate({ apiKey, children }) {
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const cc = ContentCredits.init({
|
|
154
|
+
apiKey,
|
|
155
|
+
contentSelector: '#premium-content',
|
|
156
|
+
});
|
|
157
|
+
return () => cc.destroy();
|
|
158
|
+
}, [apiKey]);
|
|
159
|
+
|
|
160
|
+
return <div id="premium-content">{children}</div>;
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Requirements
|
|
167
|
+
|
|
168
|
+
- Modern browsers (Chrome, Firefox, Safari, Edge)
|
|
169
|
+
- Your domain must be registered as a publisher at [app.contentcredits.com](https://app.contentcredits.com)
|
|
170
|
+
- HTTPS required in production
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Links
|
|
175
|
+
|
|
176
|
+
- [Full documentation](https://docs.contentcredits.com)
|
|
177
|
+
- [Quick start guide](https://docs.contentcredits.com/getting-started/quick-start)
|
|
178
|
+
- [API reference](https://docs.contentcredits.com/api-reference/contentcredits-class)
|
|
179
|
+
- [Publisher dashboard](https://app.contentcredits.com)
|
|
180
|
+
- [Content Credits website](https://contentcredits.com)
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentcredits/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Content Credits JS SDK — drop-in paywall and comments for any website",
|
|
5
5
|
"author": "Content Credits",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/content-credits.cjs.js",
|
|
8
8
|
"module": "dist/content-credits.esm.js",
|
|
9
9
|
"browser": "dist/content-credits.umd.min.js",
|