@veribenim/core 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.
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Veribenim SDK tip tanımlamaları
3
+ * Token = Environment token (32 karakter, her site için unique)
4
+ */
5
+ type ConsentAction = 'accept_all' | 'reject_all' | 'save_preferences' | 'ping' | 'visit' | 'exit';
6
+ interface ConsentPreferences {
7
+ necessary: boolean;
8
+ analytics: boolean;
9
+ marketing: boolean;
10
+ preferences: boolean;
11
+ }
12
+ interface VeribenimConfig {
13
+ /**
14
+ * Environment token — Veribenim panelinden alınır.
15
+ * Panelde: Siteniz → Entegrasyon → Token
16
+ */
17
+ token: string;
18
+ /** Banner dili. Varsayılan: 'tr' */
19
+ lang?: 'tr' | 'en';
20
+ /** Debug modu. Varsayılan: false */
21
+ debug?: boolean;
22
+ /**
23
+ * @internal — Yalnızca ileri düzey kullanım.
24
+ * SDK normalde yalnızca API işlemleri için kullanılır;
25
+ * banner script'i doğrudan <script> tag ile eklenir.
26
+ */
27
+ _scriptUrl?: string;
28
+ /** @internal */
29
+ _apiUrl?: string;
30
+ }
31
+ interface VeribenimInternalConfig {
32
+ token: string;
33
+ apiUrl: string;
34
+ lang: 'tr' | 'en';
35
+ debug: boolean;
36
+ }
37
+ interface ImpressionPayload {
38
+ url: string;
39
+ referrer?: string;
40
+ user_agent?: string;
41
+ }
42
+ interface ConsentLogPayload {
43
+ action: ConsentAction;
44
+ preferences?: ConsentPreferences;
45
+ session_id?: string;
46
+ url?: string;
47
+ }
48
+ interface PreferencesResponse {
49
+ session_id: string;
50
+ preferences: ConsentPreferences;
51
+ created_at: string;
52
+ updated_at: string;
53
+ }
54
+ type ConsentCallback = (preferences: ConsentPreferences) => void;
55
+ interface VeribenimEvents {
56
+ onAccept?: ConsentCallback;
57
+ onDecline?: ConsentCallback;
58
+ onChange?: ConsentCallback;
59
+ }
60
+ interface FormConsentPayload {
61
+ /** Formun adı / tipi (örn: "contact", "newsletter", "register") */
62
+ form_name: string;
63
+ /** Kullanıcının onay verip vermediği */
64
+ consented: boolean;
65
+ /** Onay metni — kullanıcının gördüğü ifade */
66
+ consent_text?: string;
67
+ /** İsteğe bağlı ek veri — şema zorunluluğu yok */
68
+ metadata?: Record<string, unknown>;
69
+ }
70
+ interface FormConsentResponse {
71
+ id: string;
72
+ form_name: string;
73
+ consented: boolean;
74
+ ip_address: string;
75
+ created_at: string;
76
+ }
77
+ type DsarRequestType = 'access' | 'rectification' | 'erasure' | 'restriction' | 'portability' | 'objection' | 'automated';
78
+ interface DsarPayload {
79
+ request_type: DsarRequestType;
80
+ /** Başvuranın adı soyadı */
81
+ full_name: string;
82
+ /** İletişim e-posta adresi */
83
+ email: string;
84
+ /** Başvuru açıklaması (opsiyonel) */
85
+ description?: string;
86
+ /** İsteğe bağlı ek belge URL'i */
87
+ attachment_url?: string;
88
+ }
89
+ interface DsarResponse {
90
+ id: string;
91
+ request_type: DsarRequestType;
92
+ status: 'pending' | 'in_progress' | 'resolved' | 'rejected' | 'cancelled';
93
+ deadline: string;
94
+ created_at: string;
95
+ }
96
+
97
+ declare class VeribenimApiClient {
98
+ private readonly config;
99
+ constructor(config: VeribenimInternalConfig);
100
+ private get baseUrl();
101
+ private log;
102
+ private request;
103
+ /**
104
+ * Sayfa görüntüleme loglar
105
+ * POST /api/impressions/{token}
106
+ */
107
+ logImpression(payload?: Partial<ImpressionPayload>): Promise<boolean>;
108
+ /**
109
+ * Onay kararı loglar
110
+ * POST /api/consents/{token}/log
111
+ */
112
+ logConsent(payload: ConsentLogPayload): Promise<boolean>;
113
+ /**
114
+ * Ziyaretçi tercihlerini okur
115
+ * GET /api/preferences/{token}?session_id=...
116
+ */
117
+ getPreferences(sessionId?: string): Promise<PreferencesResponse | null>;
118
+ /**
119
+ * Ziyaretçi tercihlerini kaydeder
120
+ * POST /api/preferences/{token}
121
+ */
122
+ savePreferences(preferences: ConsentPreferences, sessionId?: string): Promise<PreferencesResponse | null>;
123
+ /**
124
+ * Form rızasını kaydeder
125
+ * POST /api/form-consents/{token}
126
+ *
127
+ * İletişim formu, üyelik formu, bülten gibi custom formlardaki
128
+ * KVKK onay kutucuğu verilerini Veribenim'e iletir.
129
+ *
130
+ * @example
131
+ * await client.logFormConsent({
132
+ * form_name: 'contact',
133
+ * consented: true,
134
+ * consent_text: 'KVKK kapsamında verilerimin işlenmesini onaylıyorum',
135
+ * metadata: { page: '/iletisim', email: 'user@example.com' },
136
+ * });
137
+ */
138
+ logFormConsent(payload: FormConsentPayload): Promise<FormConsentResponse | null>;
139
+ /**
140
+ * DSAR (Veri Sahibi Başvurusu) oluşturur
141
+ * POST /api/dsar/{token}
142
+ *
143
+ * Ziyaretçinin erişim, silme, taşınabilirlik vb. haklarını kullanması için
144
+ * başvuru oluşturur. 30 günlük yasal süre otomatik hesaplanır.
145
+ *
146
+ * @example
147
+ * await client.submitDsar({
148
+ * request_type: 'erasure',
149
+ * full_name: 'Ahmet Yılmaz',
150
+ * email: 'ahmet@example.com',
151
+ * description: 'Tüm verilerimin silinmesini talep ediyorum.',
152
+ * });
153
+ */
154
+ submitDsar(payload: DsarPayload): Promise<DsarResponse | null>;
155
+ }
156
+
157
+ /**
158
+ * Veribenim SDK ana sınıfı
159
+ *
160
+ * @example
161
+ * const veribenim = new Veribenim({ token: 'ENV_TOKEN_32_CHAR' });
162
+ * veribenim.onAccept((prefs) => { enableAnalytics(); });
163
+ */
164
+ declare class Veribenim {
165
+ private readonly config;
166
+ private readonly api;
167
+ private readonly callbacks;
168
+ constructor(config: VeribenimConfig, events?: VeribenimEvents);
169
+ /** Kullanıcı tüm çerezleri kabul ettiğinde çağrılır */
170
+ onAccept(callback: (prefs: ConsentPreferences) => void): this;
171
+ /** Kullanıcı tüm çerezleri reddetti */
172
+ onDecline(callback: (prefs: ConsentPreferences) => void): this;
173
+ /** Herhangi bir tercih değişikliğinde çağrılır */
174
+ onChange(callback: (prefs: ConsentPreferences) => void): this;
175
+ /** Callback'leri tetikle */
176
+ emit(event: 'accept' | 'decline' | 'change', prefs?: ConsentPreferences): void;
177
+ /** Sayfa görüntüleme logla */
178
+ logImpression(): Promise<boolean>;
179
+ /** Onay kararını logla */
180
+ logConsent(payload: ConsentLogPayload): Promise<boolean>;
181
+ /** Ziyaretçi tercihlerini getir */
182
+ getPreferences(sessionId?: string): Promise<PreferencesResponse | null>;
183
+ /** Ziyaretçi tercihlerini kaydet */
184
+ savePreferences(preferences: ConsentPreferences, sessionId?: string): Promise<PreferencesResponse | null>;
185
+ /**
186
+ * Form rızasını kaydet (iletişim formu, üyelik, bülten vb.)
187
+ * POST /api/form-consents/{token}
188
+ */
189
+ logFormConsent(payload: FormConsentPayload): Promise<FormConsentResponse | null>;
190
+ /**
191
+ * DSAR başvurusu oluştur (erişim, silme, taşınabilirlik vb.)
192
+ * POST /api/dsar/{token}
193
+ */
194
+ submitDsar(payload: DsarPayload): Promise<DsarResponse | null>;
195
+ }
196
+ /** Factory fonksiyonu */
197
+ /** @deprecated createVeribenim yerine init kullanın */
198
+ declare const createVeribenim: typeof init;
199
+ declare function init(config: VeribenimConfig, events?: VeribenimEvents): Veribenim;
200
+
201
+ export { type ConsentAction, type ConsentCallback, type ConsentLogPayload, type ConsentPreferences, type DsarPayload, type DsarRequestType, type DsarResponse, type FormConsentPayload, type FormConsentResponse, type ImpressionPayload, type PreferencesResponse, Veribenim, VeribenimApiClient, type VeribenimConfig, type VeribenimEvents, type VeribenimInternalConfig, createVeribenim, Veribenim as default, init };
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Veribenim SDK tip tanımlamaları
3
+ * Token = Environment token (32 karakter, her site için unique)
4
+ */
5
+ type ConsentAction = 'accept_all' | 'reject_all' | 'save_preferences' | 'ping' | 'visit' | 'exit';
6
+ interface ConsentPreferences {
7
+ necessary: boolean;
8
+ analytics: boolean;
9
+ marketing: boolean;
10
+ preferences: boolean;
11
+ }
12
+ interface VeribenimConfig {
13
+ /**
14
+ * Environment token — Veribenim panelinden alınır.
15
+ * Panelde: Siteniz → Entegrasyon → Token
16
+ */
17
+ token: string;
18
+ /** Banner dili. Varsayılan: 'tr' */
19
+ lang?: 'tr' | 'en';
20
+ /** Debug modu. Varsayılan: false */
21
+ debug?: boolean;
22
+ /**
23
+ * @internal — Yalnızca ileri düzey kullanım.
24
+ * SDK normalde yalnızca API işlemleri için kullanılır;
25
+ * banner script'i doğrudan <script> tag ile eklenir.
26
+ */
27
+ _scriptUrl?: string;
28
+ /** @internal */
29
+ _apiUrl?: string;
30
+ }
31
+ interface VeribenimInternalConfig {
32
+ token: string;
33
+ apiUrl: string;
34
+ lang: 'tr' | 'en';
35
+ debug: boolean;
36
+ }
37
+ interface ImpressionPayload {
38
+ url: string;
39
+ referrer?: string;
40
+ user_agent?: string;
41
+ }
42
+ interface ConsentLogPayload {
43
+ action: ConsentAction;
44
+ preferences?: ConsentPreferences;
45
+ session_id?: string;
46
+ url?: string;
47
+ }
48
+ interface PreferencesResponse {
49
+ session_id: string;
50
+ preferences: ConsentPreferences;
51
+ created_at: string;
52
+ updated_at: string;
53
+ }
54
+ type ConsentCallback = (preferences: ConsentPreferences) => void;
55
+ interface VeribenimEvents {
56
+ onAccept?: ConsentCallback;
57
+ onDecline?: ConsentCallback;
58
+ onChange?: ConsentCallback;
59
+ }
60
+ interface FormConsentPayload {
61
+ /** Formun adı / tipi (örn: "contact", "newsletter", "register") */
62
+ form_name: string;
63
+ /** Kullanıcının onay verip vermediği */
64
+ consented: boolean;
65
+ /** Onay metni — kullanıcının gördüğü ifade */
66
+ consent_text?: string;
67
+ /** İsteğe bağlı ek veri — şema zorunluluğu yok */
68
+ metadata?: Record<string, unknown>;
69
+ }
70
+ interface FormConsentResponse {
71
+ id: string;
72
+ form_name: string;
73
+ consented: boolean;
74
+ ip_address: string;
75
+ created_at: string;
76
+ }
77
+ type DsarRequestType = 'access' | 'rectification' | 'erasure' | 'restriction' | 'portability' | 'objection' | 'automated';
78
+ interface DsarPayload {
79
+ request_type: DsarRequestType;
80
+ /** Başvuranın adı soyadı */
81
+ full_name: string;
82
+ /** İletişim e-posta adresi */
83
+ email: string;
84
+ /** Başvuru açıklaması (opsiyonel) */
85
+ description?: string;
86
+ /** İsteğe bağlı ek belge URL'i */
87
+ attachment_url?: string;
88
+ }
89
+ interface DsarResponse {
90
+ id: string;
91
+ request_type: DsarRequestType;
92
+ status: 'pending' | 'in_progress' | 'resolved' | 'rejected' | 'cancelled';
93
+ deadline: string;
94
+ created_at: string;
95
+ }
96
+
97
+ declare class VeribenimApiClient {
98
+ private readonly config;
99
+ constructor(config: VeribenimInternalConfig);
100
+ private get baseUrl();
101
+ private log;
102
+ private request;
103
+ /**
104
+ * Sayfa görüntüleme loglar
105
+ * POST /api/impressions/{token}
106
+ */
107
+ logImpression(payload?: Partial<ImpressionPayload>): Promise<boolean>;
108
+ /**
109
+ * Onay kararı loglar
110
+ * POST /api/consents/{token}/log
111
+ */
112
+ logConsent(payload: ConsentLogPayload): Promise<boolean>;
113
+ /**
114
+ * Ziyaretçi tercihlerini okur
115
+ * GET /api/preferences/{token}?session_id=...
116
+ */
117
+ getPreferences(sessionId?: string): Promise<PreferencesResponse | null>;
118
+ /**
119
+ * Ziyaretçi tercihlerini kaydeder
120
+ * POST /api/preferences/{token}
121
+ */
122
+ savePreferences(preferences: ConsentPreferences, sessionId?: string): Promise<PreferencesResponse | null>;
123
+ /**
124
+ * Form rızasını kaydeder
125
+ * POST /api/form-consents/{token}
126
+ *
127
+ * İletişim formu, üyelik formu, bülten gibi custom formlardaki
128
+ * KVKK onay kutucuğu verilerini Veribenim'e iletir.
129
+ *
130
+ * @example
131
+ * await client.logFormConsent({
132
+ * form_name: 'contact',
133
+ * consented: true,
134
+ * consent_text: 'KVKK kapsamında verilerimin işlenmesini onaylıyorum',
135
+ * metadata: { page: '/iletisim', email: 'user@example.com' },
136
+ * });
137
+ */
138
+ logFormConsent(payload: FormConsentPayload): Promise<FormConsentResponse | null>;
139
+ /**
140
+ * DSAR (Veri Sahibi Başvurusu) oluşturur
141
+ * POST /api/dsar/{token}
142
+ *
143
+ * Ziyaretçinin erişim, silme, taşınabilirlik vb. haklarını kullanması için
144
+ * başvuru oluşturur. 30 günlük yasal süre otomatik hesaplanır.
145
+ *
146
+ * @example
147
+ * await client.submitDsar({
148
+ * request_type: 'erasure',
149
+ * full_name: 'Ahmet Yılmaz',
150
+ * email: 'ahmet@example.com',
151
+ * description: 'Tüm verilerimin silinmesini talep ediyorum.',
152
+ * });
153
+ */
154
+ submitDsar(payload: DsarPayload): Promise<DsarResponse | null>;
155
+ }
156
+
157
+ /**
158
+ * Veribenim SDK ana sınıfı
159
+ *
160
+ * @example
161
+ * const veribenim = new Veribenim({ token: 'ENV_TOKEN_32_CHAR' });
162
+ * veribenim.onAccept((prefs) => { enableAnalytics(); });
163
+ */
164
+ declare class Veribenim {
165
+ private readonly config;
166
+ private readonly api;
167
+ private readonly callbacks;
168
+ constructor(config: VeribenimConfig, events?: VeribenimEvents);
169
+ /** Kullanıcı tüm çerezleri kabul ettiğinde çağrılır */
170
+ onAccept(callback: (prefs: ConsentPreferences) => void): this;
171
+ /** Kullanıcı tüm çerezleri reddetti */
172
+ onDecline(callback: (prefs: ConsentPreferences) => void): this;
173
+ /** Herhangi bir tercih değişikliğinde çağrılır */
174
+ onChange(callback: (prefs: ConsentPreferences) => void): this;
175
+ /** Callback'leri tetikle */
176
+ emit(event: 'accept' | 'decline' | 'change', prefs?: ConsentPreferences): void;
177
+ /** Sayfa görüntüleme logla */
178
+ logImpression(): Promise<boolean>;
179
+ /** Onay kararını logla */
180
+ logConsent(payload: ConsentLogPayload): Promise<boolean>;
181
+ /** Ziyaretçi tercihlerini getir */
182
+ getPreferences(sessionId?: string): Promise<PreferencesResponse | null>;
183
+ /** Ziyaretçi tercihlerini kaydet */
184
+ savePreferences(preferences: ConsentPreferences, sessionId?: string): Promise<PreferencesResponse | null>;
185
+ /**
186
+ * Form rızasını kaydet (iletişim formu, üyelik, bülten vb.)
187
+ * POST /api/form-consents/{token}
188
+ */
189
+ logFormConsent(payload: FormConsentPayload): Promise<FormConsentResponse | null>;
190
+ /**
191
+ * DSAR başvurusu oluştur (erişim, silme, taşınabilirlik vb.)
192
+ * POST /api/dsar/{token}
193
+ */
194
+ submitDsar(payload: DsarPayload): Promise<DsarResponse | null>;
195
+ }
196
+ /** Factory fonksiyonu */
197
+ /** @deprecated createVeribenim yerine init kullanın */
198
+ declare const createVeribenim: typeof init;
199
+ declare function init(config: VeribenimConfig, events?: VeribenimEvents): Veribenim;
200
+
201
+ export { type ConsentAction, type ConsentCallback, type ConsentLogPayload, type ConsentPreferences, type DsarPayload, type DsarRequestType, type DsarResponse, type FormConsentPayload, type FormConsentResponse, type ImpressionPayload, type PreferencesResponse, Veribenim, VeribenimApiClient, type VeribenimConfig, type VeribenimEvents, type VeribenimInternalConfig, createVeribenim, Veribenim as default, init };
package/dist/index.js ADDED
@@ -0,0 +1,253 @@
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
+ Veribenim: () => Veribenim,
24
+ VeribenimApiClient: () => VeribenimApiClient,
25
+ createVeribenim: () => createVeribenim,
26
+ default: () => index_default,
27
+ init: () => init
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/client.ts
32
+ var VeribenimApiClient = class {
33
+ constructor(config) {
34
+ this.config = config;
35
+ }
36
+ get baseUrl() {
37
+ return this.config.apiUrl.replace(/\/$/, "");
38
+ }
39
+ log(...args) {
40
+ if (this.config.debug) {
41
+ console.log("[Veribenim]", ...args);
42
+ }
43
+ }
44
+ async request(method, path, body) {
45
+ const url = `${this.baseUrl}${path}`;
46
+ this.log(`${method} ${url}`, body);
47
+ try {
48
+ const res = await fetch(url, {
49
+ method,
50
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
51
+ body: body ? JSON.stringify(body) : void 0
52
+ });
53
+ if (!res.ok) {
54
+ this.log(`HTTP ${res.status}`, await res.text());
55
+ return null;
56
+ }
57
+ const text = await res.text();
58
+ return text ? JSON.parse(text) : null;
59
+ } catch (err) {
60
+ this.log("Request failed:", err);
61
+ return null;
62
+ }
63
+ }
64
+ /**
65
+ * Sayfa görüntüleme loglar
66
+ * POST /api/impressions/{token}
67
+ */
68
+ async logImpression(payload) {
69
+ const data = {
70
+ url: typeof window !== "undefined" ? window.location.href : "",
71
+ referrer: typeof document !== "undefined" ? document.referrer : "",
72
+ user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
73
+ ...payload
74
+ };
75
+ const result = await this.request("POST", `/api/impressions/${this.config.token}`, data);
76
+ return result !== null;
77
+ }
78
+ /**
79
+ * Onay kararı loglar
80
+ * POST /api/consents/{token}/log
81
+ */
82
+ async logConsent(payload) {
83
+ const result = await this.request(
84
+ "POST",
85
+ `/api/consents/${this.config.token}/log`,
86
+ payload
87
+ );
88
+ return result !== null;
89
+ }
90
+ /**
91
+ * Ziyaretçi tercihlerini okur
92
+ * GET /api/preferences/{token}?session_id=...
93
+ */
94
+ async getPreferences(sessionId) {
95
+ const qs = sessionId ? `?session_id=${encodeURIComponent(sessionId)}` : "";
96
+ return this.request(
97
+ "GET",
98
+ `/api/preferences/${this.config.token}${qs}`
99
+ );
100
+ }
101
+ /**
102
+ * Ziyaretçi tercihlerini kaydeder
103
+ * POST /api/preferences/{token}
104
+ */
105
+ async savePreferences(preferences, sessionId) {
106
+ return this.request(
107
+ "POST",
108
+ `/api/preferences/${this.config.token}`,
109
+ { preferences, session_id: sessionId }
110
+ );
111
+ }
112
+ /**
113
+ * Form rızasını kaydeder
114
+ * POST /api/form-consents/{token}
115
+ *
116
+ * İletişim formu, üyelik formu, bülten gibi custom formlardaki
117
+ * KVKK onay kutucuğu verilerini Veribenim'e iletir.
118
+ *
119
+ * @example
120
+ * await client.logFormConsent({
121
+ * form_name: 'contact',
122
+ * consented: true,
123
+ * consent_text: 'KVKK kapsamında verilerimin işlenmesini onaylıyorum',
124
+ * metadata: { page: '/iletisim', email: 'user@example.com' },
125
+ * });
126
+ */
127
+ async logFormConsent(payload) {
128
+ return this.request(
129
+ "POST",
130
+ `/api/form-consents/${this.config.token}`,
131
+ payload
132
+ );
133
+ }
134
+ /**
135
+ * DSAR (Veri Sahibi Başvurusu) oluşturur
136
+ * POST /api/dsar/{token}
137
+ *
138
+ * Ziyaretçinin erişim, silme, taşınabilirlik vb. haklarını kullanması için
139
+ * başvuru oluşturur. 30 günlük yasal süre otomatik hesaplanır.
140
+ *
141
+ * @example
142
+ * await client.submitDsar({
143
+ * request_type: 'erasure',
144
+ * full_name: 'Ahmet Yılmaz',
145
+ * email: 'ahmet@example.com',
146
+ * description: 'Tüm verilerimin silinmesini talep ediyorum.',
147
+ * });
148
+ */
149
+ async submitDsar(payload) {
150
+ return this.request(
151
+ "POST",
152
+ `/api/dsar/${this.config.token}`,
153
+ payload
154
+ );
155
+ }
156
+ };
157
+
158
+ // src/index.ts
159
+ var DEFAULT_CONFIG = {
160
+ apiUrl: "https://api.veribenim.com",
161
+ lang: "tr",
162
+ debug: false
163
+ };
164
+ var Veribenim = class {
165
+ constructor(config, events) {
166
+ this.callbacks = { onAccept: [], onDecline: [], onChange: [] };
167
+ var _a, _b, _c;
168
+ if (!config.token) throw new Error("[Veribenim] token zorunludur");
169
+ this.config = {
170
+ ...DEFAULT_CONFIG,
171
+ token: config.token,
172
+ lang: (_a = config.lang) != null ? _a : "tr",
173
+ debug: (_b = config.debug) != null ? _b : false,
174
+ apiUrl: (_c = config._apiUrl) != null ? _c : "https://api.veribenim.com"
175
+ };
176
+ this.api = new VeribenimApiClient(this.config);
177
+ if (events == null ? void 0 : events.onAccept) this.onAccept(events.onAccept);
178
+ if (events == null ? void 0 : events.onDecline) this.onDecline(events.onDecline);
179
+ if (events == null ? void 0 : events.onChange) this.onChange(events.onChange);
180
+ }
181
+ /** Kullanıcı tüm çerezleri kabul ettiğinde çağrılır */
182
+ onAccept(callback) {
183
+ this.callbacks.onAccept.push(callback);
184
+ return this;
185
+ }
186
+ /** Kullanıcı tüm çerezleri reddetti */
187
+ onDecline(callback) {
188
+ this.callbacks.onDecline.push(callback);
189
+ return this;
190
+ }
191
+ /** Herhangi bir tercih değişikliğinde çağrılır */
192
+ onChange(callback) {
193
+ this.callbacks.onChange.push(callback);
194
+ return this;
195
+ }
196
+ /** Callback'leri tetikle */
197
+ emit(event, prefs) {
198
+ switch (event) {
199
+ case "accept":
200
+ this.callbacks.onAccept.forEach((cb) => prefs && cb(prefs));
201
+ break;
202
+ case "decline":
203
+ this.callbacks.onDecline.forEach((cb) => prefs && cb(prefs));
204
+ break;
205
+ case "change":
206
+ this.callbacks.onChange.forEach((cb) => prefs && cb(prefs));
207
+ break;
208
+ }
209
+ }
210
+ // --- API Kısayolları ---
211
+ /** Sayfa görüntüleme logla */
212
+ logImpression() {
213
+ return this.api.logImpression();
214
+ }
215
+ /** Onay kararını logla */
216
+ logConsent(payload) {
217
+ return this.api.logConsent(payload);
218
+ }
219
+ /** Ziyaretçi tercihlerini getir */
220
+ getPreferences(sessionId) {
221
+ return this.api.getPreferences(sessionId);
222
+ }
223
+ /** Ziyaretçi tercihlerini kaydet */
224
+ savePreferences(preferences, sessionId) {
225
+ return this.api.savePreferences(preferences, sessionId);
226
+ }
227
+ /**
228
+ * Form rızasını kaydet (iletişim formu, üyelik, bülten vb.)
229
+ * POST /api/form-consents/{token}
230
+ */
231
+ logFormConsent(payload) {
232
+ return this.api.logFormConsent(payload);
233
+ }
234
+ /**
235
+ * DSAR başvurusu oluştur (erişim, silme, taşınabilirlik vb.)
236
+ * POST /api/dsar/{token}
237
+ */
238
+ submitDsar(payload) {
239
+ return this.api.submitDsar(payload);
240
+ }
241
+ };
242
+ var createVeribenim = init;
243
+ function init(config, events) {
244
+ return new Veribenim(config, events);
245
+ }
246
+ var index_default = Veribenim;
247
+ // Annotate the CommonJS export names for ESM import in node:
248
+ 0 && (module.exports = {
249
+ Veribenim,
250
+ VeribenimApiClient,
251
+ createVeribenim,
252
+ init
253
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,223 @@
1
+ // src/client.ts
2
+ var VeribenimApiClient = class {
3
+ constructor(config) {
4
+ this.config = config;
5
+ }
6
+ get baseUrl() {
7
+ return this.config.apiUrl.replace(/\/$/, "");
8
+ }
9
+ log(...args) {
10
+ if (this.config.debug) {
11
+ console.log("[Veribenim]", ...args);
12
+ }
13
+ }
14
+ async request(method, path, body) {
15
+ const url = `${this.baseUrl}${path}`;
16
+ this.log(`${method} ${url}`, body);
17
+ try {
18
+ const res = await fetch(url, {
19
+ method,
20
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
21
+ body: body ? JSON.stringify(body) : void 0
22
+ });
23
+ if (!res.ok) {
24
+ this.log(`HTTP ${res.status}`, await res.text());
25
+ return null;
26
+ }
27
+ const text = await res.text();
28
+ return text ? JSON.parse(text) : null;
29
+ } catch (err) {
30
+ this.log("Request failed:", err);
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Sayfa görüntüleme loglar
36
+ * POST /api/impressions/{token}
37
+ */
38
+ async logImpression(payload) {
39
+ const data = {
40
+ url: typeof window !== "undefined" ? window.location.href : "",
41
+ referrer: typeof document !== "undefined" ? document.referrer : "",
42
+ user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
43
+ ...payload
44
+ };
45
+ const result = await this.request("POST", `/api/impressions/${this.config.token}`, data);
46
+ return result !== null;
47
+ }
48
+ /**
49
+ * Onay kararı loglar
50
+ * POST /api/consents/{token}/log
51
+ */
52
+ async logConsent(payload) {
53
+ const result = await this.request(
54
+ "POST",
55
+ `/api/consents/${this.config.token}/log`,
56
+ payload
57
+ );
58
+ return result !== null;
59
+ }
60
+ /**
61
+ * Ziyaretçi tercihlerini okur
62
+ * GET /api/preferences/{token}?session_id=...
63
+ */
64
+ async getPreferences(sessionId) {
65
+ const qs = sessionId ? `?session_id=${encodeURIComponent(sessionId)}` : "";
66
+ return this.request(
67
+ "GET",
68
+ `/api/preferences/${this.config.token}${qs}`
69
+ );
70
+ }
71
+ /**
72
+ * Ziyaretçi tercihlerini kaydeder
73
+ * POST /api/preferences/{token}
74
+ */
75
+ async savePreferences(preferences, sessionId) {
76
+ return this.request(
77
+ "POST",
78
+ `/api/preferences/${this.config.token}`,
79
+ { preferences, session_id: sessionId }
80
+ );
81
+ }
82
+ /**
83
+ * Form rızasını kaydeder
84
+ * POST /api/form-consents/{token}
85
+ *
86
+ * İletişim formu, üyelik formu, bülten gibi custom formlardaki
87
+ * KVKK onay kutucuğu verilerini Veribenim'e iletir.
88
+ *
89
+ * @example
90
+ * await client.logFormConsent({
91
+ * form_name: 'contact',
92
+ * consented: true,
93
+ * consent_text: 'KVKK kapsamında verilerimin işlenmesini onaylıyorum',
94
+ * metadata: { page: '/iletisim', email: 'user@example.com' },
95
+ * });
96
+ */
97
+ async logFormConsent(payload) {
98
+ return this.request(
99
+ "POST",
100
+ `/api/form-consents/${this.config.token}`,
101
+ payload
102
+ );
103
+ }
104
+ /**
105
+ * DSAR (Veri Sahibi Başvurusu) oluşturur
106
+ * POST /api/dsar/{token}
107
+ *
108
+ * Ziyaretçinin erişim, silme, taşınabilirlik vb. haklarını kullanması için
109
+ * başvuru oluşturur. 30 günlük yasal süre otomatik hesaplanır.
110
+ *
111
+ * @example
112
+ * await client.submitDsar({
113
+ * request_type: 'erasure',
114
+ * full_name: 'Ahmet Yılmaz',
115
+ * email: 'ahmet@example.com',
116
+ * description: 'Tüm verilerimin silinmesini talep ediyorum.',
117
+ * });
118
+ */
119
+ async submitDsar(payload) {
120
+ return this.request(
121
+ "POST",
122
+ `/api/dsar/${this.config.token}`,
123
+ payload
124
+ );
125
+ }
126
+ };
127
+
128
+ // src/index.ts
129
+ var DEFAULT_CONFIG = {
130
+ apiUrl: "https://api.veribenim.com",
131
+ lang: "tr",
132
+ debug: false
133
+ };
134
+ var Veribenim = class {
135
+ constructor(config, events) {
136
+ this.callbacks = { onAccept: [], onDecline: [], onChange: [] };
137
+ var _a, _b, _c;
138
+ if (!config.token) throw new Error("[Veribenim] token zorunludur");
139
+ this.config = {
140
+ ...DEFAULT_CONFIG,
141
+ token: config.token,
142
+ lang: (_a = config.lang) != null ? _a : "tr",
143
+ debug: (_b = config.debug) != null ? _b : false,
144
+ apiUrl: (_c = config._apiUrl) != null ? _c : "https://api.veribenim.com"
145
+ };
146
+ this.api = new VeribenimApiClient(this.config);
147
+ if (events == null ? void 0 : events.onAccept) this.onAccept(events.onAccept);
148
+ if (events == null ? void 0 : events.onDecline) this.onDecline(events.onDecline);
149
+ if (events == null ? void 0 : events.onChange) this.onChange(events.onChange);
150
+ }
151
+ /** Kullanıcı tüm çerezleri kabul ettiğinde çağrılır */
152
+ onAccept(callback) {
153
+ this.callbacks.onAccept.push(callback);
154
+ return this;
155
+ }
156
+ /** Kullanıcı tüm çerezleri reddetti */
157
+ onDecline(callback) {
158
+ this.callbacks.onDecline.push(callback);
159
+ return this;
160
+ }
161
+ /** Herhangi bir tercih değişikliğinde çağrılır */
162
+ onChange(callback) {
163
+ this.callbacks.onChange.push(callback);
164
+ return this;
165
+ }
166
+ /** Callback'leri tetikle */
167
+ emit(event, prefs) {
168
+ switch (event) {
169
+ case "accept":
170
+ this.callbacks.onAccept.forEach((cb) => prefs && cb(prefs));
171
+ break;
172
+ case "decline":
173
+ this.callbacks.onDecline.forEach((cb) => prefs && cb(prefs));
174
+ break;
175
+ case "change":
176
+ this.callbacks.onChange.forEach((cb) => prefs && cb(prefs));
177
+ break;
178
+ }
179
+ }
180
+ // --- API Kısayolları ---
181
+ /** Sayfa görüntüleme logla */
182
+ logImpression() {
183
+ return this.api.logImpression();
184
+ }
185
+ /** Onay kararını logla */
186
+ logConsent(payload) {
187
+ return this.api.logConsent(payload);
188
+ }
189
+ /** Ziyaretçi tercihlerini getir */
190
+ getPreferences(sessionId) {
191
+ return this.api.getPreferences(sessionId);
192
+ }
193
+ /** Ziyaretçi tercihlerini kaydet */
194
+ savePreferences(preferences, sessionId) {
195
+ return this.api.savePreferences(preferences, sessionId);
196
+ }
197
+ /**
198
+ * Form rızasını kaydet (iletişim formu, üyelik, bülten vb.)
199
+ * POST /api/form-consents/{token}
200
+ */
201
+ logFormConsent(payload) {
202
+ return this.api.logFormConsent(payload);
203
+ }
204
+ /**
205
+ * DSAR başvurusu oluştur (erişim, silme, taşınabilirlik vb.)
206
+ * POST /api/dsar/{token}
207
+ */
208
+ submitDsar(payload) {
209
+ return this.api.submitDsar(payload);
210
+ }
211
+ };
212
+ var createVeribenim = init;
213
+ function init(config, events) {
214
+ return new Veribenim(config, events);
215
+ }
216
+ var index_default = Veribenim;
217
+ export {
218
+ Veribenim,
219
+ VeribenimApiClient,
220
+ createVeribenim,
221
+ index_default as default,
222
+ init
223
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@veribenim/core",
3
+ "version": "1.0.0",
4
+ "description": "Veribenim KVKK/GDPR çerez onayı SDK - Core",
5
+ "keywords": [
6
+ "kvkk",
7
+ "gdpr",
8
+ "cookie",
9
+ "consent",
10
+ "veribenim"
11
+ ],
12
+ "homepage": "https://veribenim.com",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/pariette/veribenim.js.sdk",
16
+ "directory": "packages/core"
17
+ },
18
+ "license": "MIT",
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.mjs",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.mjs",
26
+ "require": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "devDependencies": {
33
+ "@types/jest": "^29.5.0",
34
+ "jest": "^29.7.0",
35
+ "ts-jest": "^29.1.0",
36
+ "tsup": "^8.0.0",
37
+ "typescript": "^5.4.0"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
41
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
42
+ "test": "jest --passWithNoTests",
43
+ "lint": "tsc --noEmit",
44
+ "clean": "rm -rf dist"
45
+ }
46
+ }