@contentcredits/sdk 2.0.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 +13 -0
- package/dist/api/comments.d.ts +27 -0
- package/dist/api/credits.d.ts +16 -0
- package/dist/auth/popup.d.ts +18 -0
- package/dist/auth/storage.d.ts +6 -0
- package/dist/auth/token.d.ts +17 -0
- package/dist/comments/index.d.ts +9 -0
- package/dist/comments/panel.d.ts +8 -0
- package/dist/comments/widget.d.ts +7 -0
- package/dist/content-credits.cjs.js +2574 -0
- package/dist/content-credits.cjs.js.map +1 -0
- package/dist/content-credits.d.ts +175 -0
- package/dist/content-credits.esm.js +2572 -0
- package/dist/content-credits.esm.js.map +1 -0
- package/dist/content-credits.umd.min.js +2 -0
- package/dist/content-credits.umd.min.js.map +1 -0
- package/dist/core/config.d.ts +2 -0
- package/dist/core/events.d.ts +8 -0
- package/dist/core/state.d.ts +10 -0
- package/dist/extension/bridge.d.ts +19 -0
- package/dist/extension/detector.d.ts +13 -0
- package/dist/index.d.ts +58 -0
- package/dist/paywall/gate.d.ts +20 -0
- package/dist/paywall/index.d.ts +9 -0
- package/dist/paywall/renderer.d.ts +16 -0
- package/dist/types/index.d.ts +174 -0
- package/dist/ui/sanitize.d.ts +24 -0
- package/dist/ui/shadow.d.ts +12 -0
- package/dist/ui/styles.d.ts +2 -0
- package/package.json +52 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventEmitter } from '../core/events.js';
|
|
2
|
+
export declare function createApiClient(baseUrl: string, emitter: EventEmitter): {
|
|
3
|
+
get: <T>(path: string) => Promise<T>;
|
|
4
|
+
post: <T>(path: string, body: Record<string, unknown>) => Promise<T>;
|
|
5
|
+
put: <T>(path: string, body: Record<string, unknown>) => Promise<T>;
|
|
6
|
+
delete: <T>(path: string) => Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export declare class ApiError extends Error {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly data?: unknown | undefined;
|
|
11
|
+
constructor(status: number, message: string, data?: unknown | undefined);
|
|
12
|
+
}
|
|
13
|
+
export type ApiClient = ReturnType<typeof createApiClient>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ApiClient } from './client.js';
|
|
2
|
+
import type { CommentsResponse, CommentThread, Comment, CommentSortBy } from '../types/index.js';
|
|
3
|
+
export declare function createCommentsApi(client: ApiClient): {
|
|
4
|
+
ensureThread(params: {
|
|
5
|
+
pageUrl: string;
|
|
6
|
+
hostname: string;
|
|
7
|
+
}): Promise<CommentThread>;
|
|
8
|
+
getComments(params: {
|
|
9
|
+
pageUrl: string;
|
|
10
|
+
sortBy: CommentSortBy;
|
|
11
|
+
}): Promise<CommentsResponse>;
|
|
12
|
+
postComment(params: {
|
|
13
|
+
threadId: string;
|
|
14
|
+
content: string;
|
|
15
|
+
parentCommentId?: string | null;
|
|
16
|
+
}): Promise<Comment>;
|
|
17
|
+
editComment(commentId: string, content: string): Promise<Comment>;
|
|
18
|
+
deleteComment(commentId: string): Promise<Comment>;
|
|
19
|
+
toggleLike(commentId: string): Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
data: {
|
|
22
|
+
_id: string;
|
|
23
|
+
likeCount: number;
|
|
24
|
+
hasLiked: boolean;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApiClient } from './client.js';
|
|
2
|
+
import type { CheckAccessResponse, PurchaseResponse } from '../types/index.js';
|
|
3
|
+
export declare function createCreditsApi(client: ApiClient): {
|
|
4
|
+
checkAccess(params: {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
postUrl: string;
|
|
7
|
+
postName: string;
|
|
8
|
+
hostName: string;
|
|
9
|
+
}): Promise<CheckAccessResponse>;
|
|
10
|
+
purchaseArticle(params: {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
postUrl: string;
|
|
13
|
+
postName: string;
|
|
14
|
+
hostName: string;
|
|
15
|
+
}): Promise<PurchaseResponse>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function isMobileDevice(): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Scrub `token` and `cc_token` query parameters from the current URL
|
|
4
|
+
* so the token doesn't appear in browser history or server logs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function scrubTokenFromUrl(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Read and store a token that may have been placed in the current URL
|
|
9
|
+
* (e.g. after a mobile redirect back from the accounts site).
|
|
10
|
+
* Always scrubs the token from the URL after reading it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function consumeTokenFromUrl(): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Open a centered auth popup and poll for the token callback.
|
|
15
|
+
* Returns a promise that resolves with the token when login completes,
|
|
16
|
+
* or null if the popup is closed without completing login.
|
|
17
|
+
*/
|
|
18
|
+
export declare function openAuthPopup(authUrl: string): Promise<string | null>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface JwtPayload {
|
|
2
|
+
id?: string;
|
|
3
|
+
_id?: string;
|
|
4
|
+
email?: string;
|
|
5
|
+
exp?: number;
|
|
6
|
+
iat?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Decode a JWT payload without verifying the signature.
|
|
10
|
+
* Signature verification happens server-side on every API call.
|
|
11
|
+
*/
|
|
12
|
+
export declare function decodeJwt(token: string): JwtPayload | null;
|
|
13
|
+
/** Returns true if the JWT is expired (or unparseable). */
|
|
14
|
+
export declare function isTokenExpired(token: string): boolean;
|
|
15
|
+
/** Extract the user ID from a JWT. Returns null if token is invalid. */
|
|
16
|
+
export declare function getUserIdFromToken(token: string): string | null;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { createCommentsApi } from '../api/comments.js';
|
|
2
|
+
import type { EventEmitter } from '../core/events.js';
|
|
3
|
+
import type { ResolvedConfig } from '../types/index.js';
|
|
4
|
+
export declare function createComments(config: ResolvedConfig, commentsApi: ReturnType<typeof createCommentsApi>, emitter: EventEmitter): {
|
|
5
|
+
init: () => void;
|
|
6
|
+
open: () => void;
|
|
7
|
+
close: () => void;
|
|
8
|
+
destroy: () => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { createCommentsApi } from '../api/comments.js';
|
|
2
|
+
import type { ResolvedConfig } from '../types/index.js';
|
|
3
|
+
import type { EventEmitter } from '../core/events.js';
|
|
4
|
+
export declare function createCommentPanel(config: ResolvedConfig, commentsApi: ReturnType<typeof createCommentsApi>, emitter: EventEmitter, onClose: () => void): {
|
|
5
|
+
openPanel: () => void;
|
|
6
|
+
closePanel: () => void;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
};
|