consentik-cmp 0.1.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/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # consentik-cmp
2
+
3
+ React component and hook for integrating the [Consentik](https://consentik.com) cookie consent banner.
4
+
5
+ Ships with TypeScript declarations.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install consentik-cmp
11
+ # or
12
+ pnpm add consentik-cmp
13
+ # or
14
+ yarn add consentik-cmp
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Component
20
+
21
+ ```tsx
22
+ import { ConsentikCMP } from 'consentik-cmp';
23
+
24
+ function App() {
25
+ return (
26
+ <>
27
+ <ConsentikCMP
28
+ config={{
29
+ instanceId: 'your-instance-id',
30
+ siteId: 'your-site-id'
31
+ }}
32
+ />
33
+ {/* rest of your app */}
34
+ </>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### Hook
40
+
41
+ ```tsx
42
+ import { useConsentik } from 'consentik-cmp';
43
+
44
+ function App() {
45
+ useConsentik({
46
+ instanceId: 'your-instance-id',
47
+ siteId: 'your-site-id'
48
+ });
49
+
50
+ return <div>{/* your app */}</div>;
51
+ }
52
+ ```
53
+
54
+ ### Config Options
55
+
56
+ | Option | Type | Required | Description |
57
+ |--------|------|----------|-------------|
58
+ | `instanceId` | `string` | Yes | Your Consentik instance ID |
59
+ | `siteId` | `string` | Yes | Your Consentik site ID |
60
+ | `timestamp` | `number` | No | Cache bust value. Defaults to `new Date().getMinutes()` |
61
+
62
+ ## Framework Compatibility
63
+
64
+ Works with any React-based framework:
65
+ - React (CRA, Vite)
66
+ - Next.js (App Router & Pages Router)
67
+ - Remix
68
+ - Gatsby
69
+
70
+ The script is injected client-side via `useEffect`, so it is SSR-safe.
71
+
72
+ ## License
73
+
74
+ MIT
@@ -0,0 +1,14 @@
1
+ interface ConsentikConfig {
2
+ instanceId: string;
3
+ siteId: string;
4
+ timestamp?: number;
5
+ }
6
+
7
+ declare function useConsentik(config: ConsentikConfig): void;
8
+
9
+ interface ConsentikCMPProps {
10
+ config: ConsentikConfig;
11
+ }
12
+ declare function ConsentikCMP({ config }: ConsentikCMPProps): null;
13
+
14
+ export { ConsentikCMP, type ConsentikConfig, useConsentik };
@@ -0,0 +1,14 @@
1
+ interface ConsentikConfig {
2
+ instanceId: string;
3
+ siteId: string;
4
+ timestamp?: number;
5
+ }
6
+
7
+ declare function useConsentik(config: ConsentikConfig): void;
8
+
9
+ interface ConsentikCMPProps {
10
+ config: ConsentikConfig;
11
+ }
12
+ declare function ConsentikCMP({ config }: ConsentikCMPProps): null;
13
+
14
+ export { ConsentikCMP, type ConsentikConfig, useConsentik };
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ConsentikCMP: () => ConsentikCMP,
24
+ useConsentik: () => useConsentik
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/useConsentik.ts
29
+ var import_react = require("react");
30
+ var SCRIPT_ID = "cst-package";
31
+ var BASE_URL = "https://cmp.consentik.com/sites";
32
+ function useConsentik(config) {
33
+ const { instanceId, siteId, timestamp } = config;
34
+ const cachedTimestamp = (0, import_react.useRef)(timestamp != null ? timestamp : (/* @__PURE__ */ new Date()).getMinutes());
35
+ (0, import_react.useEffect)(() => {
36
+ if (document.getElementById(SCRIPT_ID)) {
37
+ return;
38
+ }
39
+ const script = document.createElement("script");
40
+ script.id = SCRIPT_ID;
41
+ script.async = true;
42
+ script.src = `${BASE_URL}/${instanceId}/${siteId}/index.js?v=${cachedTimestamp.current}`;
43
+ const firstScript = document.getElementsByTagName("script")[0];
44
+ if (firstScript == null ? void 0 : firstScript.parentNode) {
45
+ firstScript.parentNode.insertBefore(script, firstScript);
46
+ } else {
47
+ document.head.appendChild(script);
48
+ }
49
+ }, []);
50
+ }
51
+
52
+ // src/ConsentikCMP.tsx
53
+ function ConsentikCMP({ config }) {
54
+ useConsentik(config);
55
+ return null;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ ConsentikCMP,
60
+ useConsentik
61
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,33 @@
1
+ // src/useConsentik.ts
2
+ import { useEffect, useRef } from "react";
3
+ var SCRIPT_ID = "cst-package";
4
+ var BASE_URL = "https://cmp.consentik.com/sites";
5
+ function useConsentik(config) {
6
+ const { instanceId, siteId, timestamp } = config;
7
+ const cachedTimestamp = useRef(timestamp != null ? timestamp : (/* @__PURE__ */ new Date()).getMinutes());
8
+ useEffect(() => {
9
+ if (document.getElementById(SCRIPT_ID)) {
10
+ return;
11
+ }
12
+ const script = document.createElement("script");
13
+ script.id = SCRIPT_ID;
14
+ script.async = true;
15
+ script.src = `${BASE_URL}/${instanceId}/${siteId}/index.js?v=${cachedTimestamp.current}`;
16
+ const firstScript = document.getElementsByTagName("script")[0];
17
+ if (firstScript == null ? void 0 : firstScript.parentNode) {
18
+ firstScript.parentNode.insertBefore(script, firstScript);
19
+ } else {
20
+ document.head.appendChild(script);
21
+ }
22
+ }, []);
23
+ }
24
+
25
+ // src/ConsentikCMP.tsx
26
+ function ConsentikCMP({ config }) {
27
+ useConsentik(config);
28
+ return null;
29
+ }
30
+ export {
31
+ ConsentikCMP,
32
+ useConsentik
33
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "consentik-cmp",
3
+ "version": "0.1.0",
4
+ "description": "React component and hook for integrating Consentik cookie consent banner",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "test": "jest",
21
+ "test:watch": "jest --watch",
22
+ "test:cov": "jest --coverage",
23
+ "lint": "tsc --noEmit",
24
+ "prepublishOnly": "pnpm run build"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=16.8.0"
28
+ },
29
+ "devDependencies": {
30
+ "@testing-library/react": "^14.0.0",
31
+ "@types/jest": "^29.5.0",
32
+ "@types/react": "^18.2.0",
33
+ "jest": "^29.7.0",
34
+ "jest-environment-jsdom": "^29.7.0",
35
+ "react": "^18.2.0",
36
+ "react-dom": "^18.2.0",
37
+ "ts-jest": "^29.1.0",
38
+ "ts-node": "^10.9.2",
39
+ "tsup": "^8.0.0",
40
+ "typescript": "^5.4.0"
41
+ },
42
+ "keywords": [
43
+ "consentik",
44
+ "cookie-consent",
45
+ "gdpr",
46
+ "react",
47
+ "cmp"
48
+ ],
49
+ "license": "MIT"
50
+ }