@veribenim/react 1.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/index.d.mts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +168 -0
- package/dist/index.mjs +135 -0
- package/package.json +55 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import * as _veribenim_core from '@veribenim/core';
|
|
5
|
+
import { VeribenimConfig, Veribenim, ConsentPreferences } from '@veribenim/core';
|
|
6
|
+
export { ConsentAction, ConsentPreferences, PreferencesResponse, VeribenimConfig } from '@veribenim/core';
|
|
7
|
+
|
|
8
|
+
interface VeribenimProviderProps {
|
|
9
|
+
config: VeribenimConfig;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Veribenim Provider — uygulamanın kökünde kullanılır
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <VeribenimProvider config={{ token: 'ENV_TOKEN' }}>
|
|
17
|
+
* <App />
|
|
18
|
+
* </VeribenimProvider>
|
|
19
|
+
*/
|
|
20
|
+
declare function VeribenimProvider({ config, children }: VeribenimProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
interface VeribenimContextValue {
|
|
23
|
+
client: Veribenim;
|
|
24
|
+
preferences: ConsentPreferences | null;
|
|
25
|
+
isLoaded: boolean;
|
|
26
|
+
isConsented: boolean;
|
|
27
|
+
accept: (prefs?: Partial<ConsentPreferences>) => Promise<void>;
|
|
28
|
+
decline: () => Promise<void>;
|
|
29
|
+
savePreferences: (prefs: ConsentPreferences) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
declare const VeribenimContext: react.Context<VeribenimContextValue | null>;
|
|
32
|
+
|
|
33
|
+
interface ConsentBannerProps {
|
|
34
|
+
/** Banner henüz onay verilmemişken render edilsin mi? */
|
|
35
|
+
showWhenPending?: boolean;
|
|
36
|
+
/** Özel render fonksiyonu */
|
|
37
|
+
children?: (props: {
|
|
38
|
+
preferences: ConsentPreferences | null;
|
|
39
|
+
isConsented: boolean;
|
|
40
|
+
accept: () => Promise<void>;
|
|
41
|
+
decline: () => Promise<void>;
|
|
42
|
+
savePreferences: (prefs: ConsentPreferences) => Promise<void>;
|
|
43
|
+
}) => ReactNode;
|
|
44
|
+
/** Hazır banner mı kullanılacak? */
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Basit headless banner bileşeni
|
|
49
|
+
* Kendi UI'ınızı children render prop ile sağlayın.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* <ConsentBanner>
|
|
53
|
+
* {({ accept, decline }) => (
|
|
54
|
+
* <div>
|
|
55
|
+
* <button onClick={accept}>Kabul Et</button>
|
|
56
|
+
* <button onClick={decline}>Reddet</button>
|
|
57
|
+
* </div>
|
|
58
|
+
* )}
|
|
59
|
+
* </ConsentBanner>
|
|
60
|
+
*/
|
|
61
|
+
declare function ConsentBanner({ children, showWhenPending }: ConsentBannerProps): react_jsx_runtime.JSX.Element | null;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Ana Veribenim hook'u — tüm state ve aksiyonlara erişim
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const { preferences, accept, decline } = useVeribenim();
|
|
68
|
+
*/
|
|
69
|
+
declare function useVeribenim(): VeribenimContextValue;
|
|
70
|
+
/**
|
|
71
|
+
* Belirli bir çerez kategorisinin durumunu döner
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const analyticsAllowed = useConsentCategory('analytics');
|
|
75
|
+
*/
|
|
76
|
+
declare function useConsentCategory(category: keyof ConsentPreferences): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Kullanıcı henüz karar vermedi mi?
|
|
79
|
+
*/
|
|
80
|
+
declare function useConsentPending(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Doğrudan API client'a erişim (gelişmiş kullanım)
|
|
83
|
+
*/
|
|
84
|
+
declare function useVeribenimClient(): _veribenim_core.Veribenim;
|
|
85
|
+
|
|
86
|
+
export { ConsentBanner, type ConsentBannerProps, VeribenimContext, type VeribenimContextValue, VeribenimProvider, type VeribenimProviderProps, useConsentCategory, useConsentPending, useVeribenim, useVeribenimClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import * as _veribenim_core from '@veribenim/core';
|
|
5
|
+
import { VeribenimConfig, Veribenim, ConsentPreferences } from '@veribenim/core';
|
|
6
|
+
export { ConsentAction, ConsentPreferences, PreferencesResponse, VeribenimConfig } from '@veribenim/core';
|
|
7
|
+
|
|
8
|
+
interface VeribenimProviderProps {
|
|
9
|
+
config: VeribenimConfig;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Veribenim Provider — uygulamanın kökünde kullanılır
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <VeribenimProvider config={{ token: 'ENV_TOKEN' }}>
|
|
17
|
+
* <App />
|
|
18
|
+
* </VeribenimProvider>
|
|
19
|
+
*/
|
|
20
|
+
declare function VeribenimProvider({ config, children }: VeribenimProviderProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
interface VeribenimContextValue {
|
|
23
|
+
client: Veribenim;
|
|
24
|
+
preferences: ConsentPreferences | null;
|
|
25
|
+
isLoaded: boolean;
|
|
26
|
+
isConsented: boolean;
|
|
27
|
+
accept: (prefs?: Partial<ConsentPreferences>) => Promise<void>;
|
|
28
|
+
decline: () => Promise<void>;
|
|
29
|
+
savePreferences: (prefs: ConsentPreferences) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
declare const VeribenimContext: react.Context<VeribenimContextValue | null>;
|
|
32
|
+
|
|
33
|
+
interface ConsentBannerProps {
|
|
34
|
+
/** Banner henüz onay verilmemişken render edilsin mi? */
|
|
35
|
+
showWhenPending?: boolean;
|
|
36
|
+
/** Özel render fonksiyonu */
|
|
37
|
+
children?: (props: {
|
|
38
|
+
preferences: ConsentPreferences | null;
|
|
39
|
+
isConsented: boolean;
|
|
40
|
+
accept: () => Promise<void>;
|
|
41
|
+
decline: () => Promise<void>;
|
|
42
|
+
savePreferences: (prefs: ConsentPreferences) => Promise<void>;
|
|
43
|
+
}) => ReactNode;
|
|
44
|
+
/** Hazır banner mı kullanılacak? */
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Basit headless banner bileşeni
|
|
49
|
+
* Kendi UI'ınızı children render prop ile sağlayın.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* <ConsentBanner>
|
|
53
|
+
* {({ accept, decline }) => (
|
|
54
|
+
* <div>
|
|
55
|
+
* <button onClick={accept}>Kabul Et</button>
|
|
56
|
+
* <button onClick={decline}>Reddet</button>
|
|
57
|
+
* </div>
|
|
58
|
+
* )}
|
|
59
|
+
* </ConsentBanner>
|
|
60
|
+
*/
|
|
61
|
+
declare function ConsentBanner({ children, showWhenPending }: ConsentBannerProps): react_jsx_runtime.JSX.Element | null;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Ana Veribenim hook'u — tüm state ve aksiyonlara erişim
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const { preferences, accept, decline } = useVeribenim();
|
|
68
|
+
*/
|
|
69
|
+
declare function useVeribenim(): VeribenimContextValue;
|
|
70
|
+
/**
|
|
71
|
+
* Belirli bir çerez kategorisinin durumunu döner
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const analyticsAllowed = useConsentCategory('analytics');
|
|
75
|
+
*/
|
|
76
|
+
declare function useConsentCategory(category: keyof ConsentPreferences): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Kullanıcı henüz karar vermedi mi?
|
|
79
|
+
*/
|
|
80
|
+
declare function useConsentPending(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Doğrudan API client'a erişim (gelişmiş kullanım)
|
|
83
|
+
*/
|
|
84
|
+
declare function useVeribenimClient(): _veribenim_core.Veribenim;
|
|
85
|
+
|
|
86
|
+
export { ConsentBanner, type ConsentBannerProps, VeribenimContext, type VeribenimContextValue, VeribenimProvider, type VeribenimProviderProps, useConsentCategory, useConsentPending, useVeribenim, useVeribenimClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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.tsx
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ConsentBanner: () => ConsentBanner,
|
|
24
|
+
VeribenimContext: () => VeribenimContext,
|
|
25
|
+
VeribenimProvider: () => VeribenimProvider,
|
|
26
|
+
useConsentCategory: () => useConsentCategory,
|
|
27
|
+
useConsentPending: () => useConsentPending,
|
|
28
|
+
useVeribenim: () => useVeribenim,
|
|
29
|
+
useVeribenimClient: () => useVeribenimClient
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/VeribenimProvider.tsx
|
|
34
|
+
var import_react2 = require("react");
|
|
35
|
+
var import_core = require("@veribenim/core");
|
|
36
|
+
|
|
37
|
+
// src/VeribenimContext.tsx
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var VeribenimContext = (0, import_react.createContext)(null);
|
|
40
|
+
function useVeribenimContext() {
|
|
41
|
+
const ctx = (0, import_react.useContext)(VeribenimContext);
|
|
42
|
+
if (!ctx) {
|
|
43
|
+
throw new Error("[Veribenim] useVeribenim hook'u <VeribenimProvider> i\xE7inde kullan\u0131lmal\u0131d\u0131r");
|
|
44
|
+
}
|
|
45
|
+
return ctx;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/VeribenimProvider.tsx
|
|
49
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
50
|
+
var ALL_ACCEPTED = {
|
|
51
|
+
necessary: true,
|
|
52
|
+
analytics: true,
|
|
53
|
+
marketing: true,
|
|
54
|
+
preferences: true
|
|
55
|
+
};
|
|
56
|
+
var ALL_DECLINED = {
|
|
57
|
+
necessary: true,
|
|
58
|
+
analytics: false,
|
|
59
|
+
marketing: false,
|
|
60
|
+
preferences: false
|
|
61
|
+
};
|
|
62
|
+
function VeribenimProvider({ config, children }) {
|
|
63
|
+
const [preferences, setPreferences] = (0, import_react2.useState)(null);
|
|
64
|
+
const [isLoaded, setIsLoaded] = (0, import_react2.useState)(false);
|
|
65
|
+
const client = (0, import_react2.useMemo)(() => {
|
|
66
|
+
return new import_core.Veribenim(config, {
|
|
67
|
+
onAccept: (prefs) => setPreferences(prefs),
|
|
68
|
+
onDecline: (prefs) => setPreferences(prefs),
|
|
69
|
+
onChange: (prefs) => setPreferences(prefs)
|
|
70
|
+
});
|
|
71
|
+
}, [config.token]);
|
|
72
|
+
(0, import_react2.useEffect)(() => {
|
|
73
|
+
client.getPreferences().then((res) => {
|
|
74
|
+
if (res) setPreferences(res.preferences);
|
|
75
|
+
setIsLoaded(true);
|
|
76
|
+
});
|
|
77
|
+
}, [client]);
|
|
78
|
+
const accept = (0, import_react2.useCallback)(
|
|
79
|
+
async (prefs) => {
|
|
80
|
+
const fullPrefs = { ...ALL_ACCEPTED, ...prefs };
|
|
81
|
+
const res = await client.savePreferences(fullPrefs);
|
|
82
|
+
if (res) {
|
|
83
|
+
setPreferences(res.preferences);
|
|
84
|
+
await client.logConsent({ action: "accept_all", preferences: fullPrefs });
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
[client]
|
|
88
|
+
);
|
|
89
|
+
const decline = (0, import_react2.useCallback)(async () => {
|
|
90
|
+
const res = await client.savePreferences(ALL_DECLINED);
|
|
91
|
+
if (res) {
|
|
92
|
+
setPreferences(res.preferences);
|
|
93
|
+
await client.logConsent({ action: "reject_all", preferences: ALL_DECLINED });
|
|
94
|
+
}
|
|
95
|
+
}, [client]);
|
|
96
|
+
const savePreferences = (0, import_react2.useCallback)(
|
|
97
|
+
async (prefs) => {
|
|
98
|
+
const res = await client.savePreferences(prefs);
|
|
99
|
+
if (res) {
|
|
100
|
+
setPreferences(res.preferences);
|
|
101
|
+
await client.logConsent({ action: "save_preferences", preferences: prefs });
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
[client]
|
|
105
|
+
);
|
|
106
|
+
const isConsented = preferences !== null;
|
|
107
|
+
const value = {
|
|
108
|
+
client,
|
|
109
|
+
preferences,
|
|
110
|
+
isLoaded,
|
|
111
|
+
isConsented,
|
|
112
|
+
accept,
|
|
113
|
+
decline,
|
|
114
|
+
savePreferences
|
|
115
|
+
};
|
|
116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VeribenimContext.Provider, { value, children });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/hooks.ts
|
|
120
|
+
function useVeribenim() {
|
|
121
|
+
return useVeribenimContext();
|
|
122
|
+
}
|
|
123
|
+
function useConsentCategory(category) {
|
|
124
|
+
var _a;
|
|
125
|
+
const { preferences } = useVeribenimContext();
|
|
126
|
+
if (!preferences) return false;
|
|
127
|
+
return (_a = preferences[category]) != null ? _a : false;
|
|
128
|
+
}
|
|
129
|
+
function useConsentPending() {
|
|
130
|
+
const { isConsented } = useVeribenimContext();
|
|
131
|
+
return !isConsented;
|
|
132
|
+
}
|
|
133
|
+
function useVeribenimClient() {
|
|
134
|
+
return useVeribenimContext().client;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/ConsentBanner.tsx
|
|
138
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
139
|
+
function ConsentBanner({ children, showWhenPending = true }) {
|
|
140
|
+
const { preferences, isConsented, accept, decline, savePreferences } = useVeribenim();
|
|
141
|
+
if (isConsented && showWhenPending) return null;
|
|
142
|
+
if (children) {
|
|
143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: children({ preferences, isConsented, accept, decline, savePreferences }) });
|
|
144
|
+
}
|
|
145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
146
|
+
"div",
|
|
147
|
+
{
|
|
148
|
+
role: "dialog",
|
|
149
|
+
"aria-label": "\xC7erez izni",
|
|
150
|
+
"data-veribenim-banner": true,
|
|
151
|
+
children: [
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Bu site \xE7erezler kullanmaktad\u0131r. Deneyiminizi iyile\u015Ftirmek i\xE7in onay\u0131n\u0131za ihtiyac\u0131m\u0131z var." }),
|
|
153
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: () => accept(), children: "T\xFCm\xFCn\xFC Kabul Et" }),
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: decline, children: "Yaln\u0131zca Zorunlular" })
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
ConsentBanner,
|
|
162
|
+
VeribenimContext,
|
|
163
|
+
VeribenimProvider,
|
|
164
|
+
useConsentCategory,
|
|
165
|
+
useConsentPending,
|
|
166
|
+
useVeribenim,
|
|
167
|
+
useVeribenimClient
|
|
168
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/VeribenimProvider.tsx
|
|
2
|
+
import { useState, useEffect, useCallback, useMemo } from "react";
|
|
3
|
+
import { Veribenim } from "@veribenim/core";
|
|
4
|
+
|
|
5
|
+
// src/VeribenimContext.tsx
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
var VeribenimContext = createContext(null);
|
|
8
|
+
function useVeribenimContext() {
|
|
9
|
+
const ctx = useContext(VeribenimContext);
|
|
10
|
+
if (!ctx) {
|
|
11
|
+
throw new Error("[Veribenim] useVeribenim hook'u <VeribenimProvider> i\xE7inde kullan\u0131lmal\u0131d\u0131r");
|
|
12
|
+
}
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/VeribenimProvider.tsx
|
|
17
|
+
import { jsx } from "react/jsx-runtime";
|
|
18
|
+
var ALL_ACCEPTED = {
|
|
19
|
+
necessary: true,
|
|
20
|
+
analytics: true,
|
|
21
|
+
marketing: true,
|
|
22
|
+
preferences: true
|
|
23
|
+
};
|
|
24
|
+
var ALL_DECLINED = {
|
|
25
|
+
necessary: true,
|
|
26
|
+
analytics: false,
|
|
27
|
+
marketing: false,
|
|
28
|
+
preferences: false
|
|
29
|
+
};
|
|
30
|
+
function VeribenimProvider({ config, children }) {
|
|
31
|
+
const [preferences, setPreferences] = useState(null);
|
|
32
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
33
|
+
const client = useMemo(() => {
|
|
34
|
+
return new Veribenim(config, {
|
|
35
|
+
onAccept: (prefs) => setPreferences(prefs),
|
|
36
|
+
onDecline: (prefs) => setPreferences(prefs),
|
|
37
|
+
onChange: (prefs) => setPreferences(prefs)
|
|
38
|
+
});
|
|
39
|
+
}, [config.token]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
client.getPreferences().then((res) => {
|
|
42
|
+
if (res) setPreferences(res.preferences);
|
|
43
|
+
setIsLoaded(true);
|
|
44
|
+
});
|
|
45
|
+
}, [client]);
|
|
46
|
+
const accept = useCallback(
|
|
47
|
+
async (prefs) => {
|
|
48
|
+
const fullPrefs = { ...ALL_ACCEPTED, ...prefs };
|
|
49
|
+
const res = await client.savePreferences(fullPrefs);
|
|
50
|
+
if (res) {
|
|
51
|
+
setPreferences(res.preferences);
|
|
52
|
+
await client.logConsent({ action: "accept_all", preferences: fullPrefs });
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[client]
|
|
56
|
+
);
|
|
57
|
+
const decline = useCallback(async () => {
|
|
58
|
+
const res = await client.savePreferences(ALL_DECLINED);
|
|
59
|
+
if (res) {
|
|
60
|
+
setPreferences(res.preferences);
|
|
61
|
+
await client.logConsent({ action: "reject_all", preferences: ALL_DECLINED });
|
|
62
|
+
}
|
|
63
|
+
}, [client]);
|
|
64
|
+
const savePreferences = useCallback(
|
|
65
|
+
async (prefs) => {
|
|
66
|
+
const res = await client.savePreferences(prefs);
|
|
67
|
+
if (res) {
|
|
68
|
+
setPreferences(res.preferences);
|
|
69
|
+
await client.logConsent({ action: "save_preferences", preferences: prefs });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[client]
|
|
73
|
+
);
|
|
74
|
+
const isConsented = preferences !== null;
|
|
75
|
+
const value = {
|
|
76
|
+
client,
|
|
77
|
+
preferences,
|
|
78
|
+
isLoaded,
|
|
79
|
+
isConsented,
|
|
80
|
+
accept,
|
|
81
|
+
decline,
|
|
82
|
+
savePreferences
|
|
83
|
+
};
|
|
84
|
+
return /* @__PURE__ */ jsx(VeribenimContext.Provider, { value, children });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/hooks.ts
|
|
88
|
+
function useVeribenim() {
|
|
89
|
+
return useVeribenimContext();
|
|
90
|
+
}
|
|
91
|
+
function useConsentCategory(category) {
|
|
92
|
+
var _a;
|
|
93
|
+
const { preferences } = useVeribenimContext();
|
|
94
|
+
if (!preferences) return false;
|
|
95
|
+
return (_a = preferences[category]) != null ? _a : false;
|
|
96
|
+
}
|
|
97
|
+
function useConsentPending() {
|
|
98
|
+
const { isConsented } = useVeribenimContext();
|
|
99
|
+
return !isConsented;
|
|
100
|
+
}
|
|
101
|
+
function useVeribenimClient() {
|
|
102
|
+
return useVeribenimContext().client;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/ConsentBanner.tsx
|
|
106
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
107
|
+
function ConsentBanner({ children, showWhenPending = true }) {
|
|
108
|
+
const { preferences, isConsented, accept, decline, savePreferences } = useVeribenim();
|
|
109
|
+
if (isConsented && showWhenPending) return null;
|
|
110
|
+
if (children) {
|
|
111
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: children({ preferences, isConsented, accept, decline, savePreferences }) });
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ jsxs(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
role: "dialog",
|
|
117
|
+
"aria-label": "\xC7erez izni",
|
|
118
|
+
"data-veribenim-banner": true,
|
|
119
|
+
children: [
|
|
120
|
+
/* @__PURE__ */ jsx2("p", { children: "Bu site \xE7erezler kullanmaktad\u0131r. Deneyiminizi iyile\u015Ftirmek i\xE7in onay\u0131n\u0131za ihtiyac\u0131m\u0131z var." }),
|
|
121
|
+
/* @__PURE__ */ jsx2("button", { onClick: () => accept(), children: "T\xFCm\xFCn\xFC Kabul Et" }),
|
|
122
|
+
/* @__PURE__ */ jsx2("button", { onClick: decline, children: "Yaln\u0131zca Zorunlular" })
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
ConsentBanner,
|
|
129
|
+
VeribenimContext,
|
|
130
|
+
VeribenimProvider,
|
|
131
|
+
useConsentCategory,
|
|
132
|
+
useConsentPending,
|
|
133
|
+
useVeribenim,
|
|
134
|
+
useVeribenimClient
|
|
135
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@veribenim/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Veribenim KVKK/GDPR çerez onayı SDK - React",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"kvkk",
|
|
7
|
+
"gdpr",
|
|
8
|
+
"cookie",
|
|
9
|
+
"consent",
|
|
10
|
+
"veribenim",
|
|
11
|
+
"react"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://veribenim.com",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/pariette/veribenim.js.sdk",
|
|
17
|
+
"directory": "packages/react"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"require": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@veribenim/core": "1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=17.0.0",
|
|
38
|
+
"react-dom": ">=17.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.0.0",
|
|
42
|
+
"@types/react-dom": "^18.0.0",
|
|
43
|
+
"react": "^18.0.0",
|
|
44
|
+
"react-dom": "^18.0.0",
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.4.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts --clean",
|
|
50
|
+
"dev": "tsup src/index.tsx --format cjs,esm --dts --watch",
|
|
51
|
+
"test": "jest --passWithNoTests",
|
|
52
|
+
"lint": "tsc --noEmit",
|
|
53
|
+
"clean": "rm -rf dist"
|
|
54
|
+
}
|
|
55
|
+
}
|