cordova-plugin-pushizo 0.1.0 → 0.3.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/www/core.js CHANGED
@@ -4,6 +4,7 @@ exports.PushizoCore = void 0;
4
4
  exports.normalizeNotification = normalizeNotification;
5
5
  const LOG_LEVELS = ['none', 'error', 'warn', 'info', 'debug'];
6
6
  const LIFECYCLE_EVENTS = ['willDisplay', 'didDisplay', 'willDismiss', 'didDismiss'];
7
+ const INBOX_CHANGE_TYPES = ['listed', 'read', 'read_all', 'archived', 'count'];
7
8
  /** Dinleyici hatası diğer dinleyicileri ve native köprüyü etkilemez. */
8
9
  function safeInvoke(listener, event) {
9
10
  try {
@@ -34,6 +35,43 @@ function stringRecord(input, name) {
34
35
  }
35
36
  return out;
36
37
  }
38
+ /** Kullanıcı özelliği anahtarı en çok bu kadar karakterdir (yerel iOS SDK kuralı; daha uzunu orada sessizce yok sayılır). */
39
+ const MAX_PROPERTY_KEY_LENGTH = 64;
40
+ function propertyKey(value) {
41
+ const key = requireString(value, 'key').trim();
42
+ if (key.length > MAX_PROPERTY_KEY_LENGTH) {
43
+ throw new RangeError(`Pushizo: key en fazla ${MAX_PROPERTY_KEY_LENGTH} karakter olabilir.`);
44
+ }
45
+ return key;
46
+ }
47
+ /**
48
+ * `User.setProperty` değeri: metin, sonlu sayı, mantıksal ya da bunların dizisi/düz nesnesi. Yalnızca en üstteki
49
+ * `null`/`undefined` kabul edilir (özelliği siler); iç içe `null` yerel iOS SDK'da tüm yazmayı düşürdüğünden reddedilir.
50
+ */
51
+ function propertyValue(value, name, nested = false) {
52
+ if (value === null || value === undefined) {
53
+ if (nested)
54
+ throw new TypeError(`Pushizo: ${name} null olamaz.`);
55
+ return null;
56
+ }
57
+ if (typeof value === 'string' || typeof value === 'boolean')
58
+ return value;
59
+ if (typeof value === 'number') {
60
+ if (!Number.isFinite(value))
61
+ throw new TypeError(`Pushizo: ${name} sonlu bir sayı olmalı.`);
62
+ return value;
63
+ }
64
+ if (Array.isArray(value))
65
+ return value.map((item, i) => propertyValue(item, `${name}[${i}]`, true));
66
+ const proto = typeof value === 'object' ? Object.getPrototypeOf(value) : undefined;
67
+ if (typeof value !== 'object' || (proto !== Object.prototype && proto !== null)) {
68
+ throw new TypeError(`Pushizo: ${name} metin, sayı, mantıksal, dizi veya düz nesne olmalı.`);
69
+ }
70
+ const out = {};
71
+ for (const [key, item] of Object.entries(value))
72
+ out[key] = propertyValue(item, `${name}.${key}`, true);
73
+ return out;
74
+ }
37
75
  const CHAT_ATTACHMENT_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif', 'application/pdf', 'text/plain'];
38
76
  /** Sohbet metni: boş olmayan, en çok 4000 karakter (sunucu kuralı). */
39
77
  function chatText(value) {
@@ -79,6 +117,14 @@ function liveActivityValues(input, name, reservedKey) {
79
117
  }
80
118
  return out;
81
119
  }
120
+ /** Yerleşim anahtarı: native SDK ve sunucu kuralı. */
121
+ const PLACEMENT_KEY = /^[a-z][a-z0-9_.-]{0,63}$/;
122
+ /** Rapor çağrılarında yalnızca mesaj kimliği köprüye gider; native katman mesajı son `list` yanıtlarından bulur. */
123
+ function placementMessageId(message) {
124
+ if (message === null || typeof message !== 'object')
125
+ throw new TypeError('Pushizo: message bir nesne olmalı.');
126
+ return requireString(message.id, 'message.id');
127
+ }
82
128
  const PREFERENCE_CHANNELS = ['ios_push', 'android_push', 'web_push', 'email', 'sms'];
83
129
  /** `setPreferences` girdisini yerel SDK kurallarıyla doğrular: 1-100 kayıt, kategori 1-64 karakter, bilinen kanal. */
84
130
  function preferenceArgs(input) {
@@ -101,6 +147,48 @@ function preferenceArgs(input) {
101
147
  return { category, channel, optedIn: p.optedIn };
102
148
  });
103
149
  }
150
+ /** `login` profilini doğrular; etiket değerleri metne çevrilir, boş alanlar köprüye gönderilmez. */
151
+ function profileArgs(input) {
152
+ if (input === null || typeof input !== 'object' || Array.isArray(input)) {
153
+ throw new TypeError('Pushizo: profile bir nesne olmalı.');
154
+ }
155
+ const out = {};
156
+ if (input.email !== undefined && input.email !== null)
157
+ out.email = requireString(input.email, 'profile.email');
158
+ if (input.sms !== undefined && input.sms !== null)
159
+ out.sms = requireString(input.sms, 'profile.sms');
160
+ if (input.tags !== undefined && input.tags !== null) {
161
+ const tags = stringRecord(input.tags, 'profile.tags');
162
+ if (Object.keys(tags).length > 0)
163
+ out.tags = tags;
164
+ }
165
+ if (input.aliases !== undefined && input.aliases !== null) {
166
+ const aliases = stringRecord(input.aliases, 'profile.aliases');
167
+ if (Object.keys(aliases).length > 0)
168
+ out.aliases = aliases;
169
+ }
170
+ return out;
171
+ }
172
+ /** Native rıza listesini eksik alanlara karşı normalize eder (`updatedAt` epoch milisaniye). */
173
+ function normalizeConsents(raw) {
174
+ if (!Array.isArray(raw))
175
+ return [];
176
+ const out = [];
177
+ for (const item of raw) {
178
+ if (item === null || typeof item !== 'object')
179
+ continue;
180
+ const c = item;
181
+ if (typeof c.purpose !== 'string' || c.purpose === '')
182
+ continue;
183
+ out.push({
184
+ purpose: c.purpose,
185
+ granted: c.granted === true,
186
+ source: typeof c.source === 'string' ? c.source : null,
187
+ updatedAt: typeof c.updatedAt === 'number' && Number.isFinite(c.updatedAt) ? c.updatedAt : null,
188
+ });
189
+ }
190
+ return out;
191
+ }
104
192
  function textMap(value) {
105
193
  const out = {};
106
194
  if (value === null || typeof value !== 'object' || Array.isArray(value))
@@ -114,6 +202,44 @@ function stringArray(value) {
114
202
  return Array.isArray(value) ? value.filter((v) => typeof v === 'string') : [];
115
203
  }
116
204
  /** Native tercih yanıtını eksik alanlara karşı normalize eder (zamanlar epoch milisaniye). */
205
+ const DELIVERY_SETTINGS = ['auto', 'notifications', 'auto_start', 'battery_optimization', 'app_details'];
206
+ function deliverySetting(value) {
207
+ if (value === undefined || value === null)
208
+ return 'auto';
209
+ if (!DELIVERY_SETTINGS.includes(value)) {
210
+ throw new TypeError(`Pushizo: setting ${DELIVERY_SETTINGS.join('|')} olmalı.`);
211
+ }
212
+ return value;
213
+ }
214
+ /** Native teslim durumu; `supported` true değilse (iOS, web, başlatılmamış SDK) "desteklenmiyor / risk yok" durumu. */
215
+ function normalizeDeliveryStatus(raw) {
216
+ const m = raw !== null && raw !== void 0 ? raw : {};
217
+ const supported = m.supported === true;
218
+ const text = (value, fallback) => (supported && typeof value === 'string' ? value : fallback);
219
+ // Native SDK'nın ileride ekleyeceği, bu sürümün tanımadığı ekran atlanır.
220
+ const recommendedSettings = supported
221
+ ? stringArray(m.recommendedSettings).filter((s) => s !== 'auto' && DELIVERY_SETTINGS.includes(s))
222
+ : [];
223
+ return {
224
+ supported,
225
+ manufacturer: text(m.manufacturer, ''),
226
+ brand: text(m.brand, ''),
227
+ vendor: text(m.vendor, 'other'),
228
+ aggressiveVendor: supported && m.aggressiveVendor === true,
229
+ rom: text(m.rom, ''),
230
+ romVersion: supported && typeof m.romVersion === 'string' ? m.romVersion : null,
231
+ notificationsEnabled: !supported || m.notificationsEnabled !== false,
232
+ channelBlocked: supported && m.channelBlocked === true,
233
+ batteryOptimizationExempt: !supported || m.batteryOptimizationExempt !== false,
234
+ backgroundRestricted: supported && m.backgroundRestricted === true,
235
+ standbyBucket: supported && typeof m.standbyBucket === 'string' ? m.standbyBucket : null,
236
+ powerSaveMode: supported && m.powerSaveMode === true,
237
+ dataSaverEnabled: supported && m.dataSaverEnabled === true,
238
+ restricted: supported && m.restricted === true,
239
+ risk: supported && (m.risk === 'high' || m.risk === 'elevated') ? m.risk : 'none',
240
+ recommendedSettings,
241
+ };
242
+ }
117
243
  function normalizePreferences(raw) {
118
244
  const preferences = Array.isArray(raw === null || raw === void 0 ? void 0 : raw.preferences) ? raw.preferences : [];
119
245
  const categories = Array.isArray(raw === null || raw === void 0 ? void 0 : raw.categories) ? raw.categories : [];
@@ -165,6 +291,8 @@ class PushizoCore {
165
291
  this.permissionObservers = new Set();
166
292
  this.inAppClickListeners = new Set();
167
293
  this.inAppLifecycleListeners = new Set();
294
+ this.featureFlagObservers = new Set();
295
+ this.inboxObservers = new Set();
168
296
  /** Dinleyici yokken gelen tıklamalar (soğuk başlatma); ilk dinleyiciye teslim edilir. */
169
297
  this.pendingClicks = [];
170
298
  /** Canlı sohbet dinleyicileri (tür başına). */
@@ -181,6 +309,8 @@ class PushizoCore {
181
309
  /** Dinleyici yokken gelen sohbet bildirimi tıklamaları (soğuk başlatma). */
182
310
  this.pendingChatOpens = [];
183
311
  this.foregroundFlag = false;
312
+ /** Native SDK başlatıldı mı (`initialize` tamamlandı ya da süreç saklanan yapılandırmayla erkenden başlatıldı). */
313
+ this.isInitialized = async () => { var _a; return Boolean((_a = (await this.bridge.call('isInitialized'))) === null || _a === void 0 ? void 0 : _a.initialized); };
184
314
  // --- Kullanıcı ---
185
315
  this.User = {
186
316
  addTag: (key, value) => this.bridge.call('addTags', { tags: stringRecord({ [requireString(key, 'key')]: value }, 'tags') }),
@@ -189,6 +319,11 @@ class PushizoCore {
189
319
  removeTags: (keys) => this.bridge.call('removeTags', { keys: keys.map((k) => requireString(k, 'key')) }),
190
320
  getTags: async () => { var _a; return (_a = (await this.bridge.call('getTags')).tags) !== null && _a !== void 0 ? _a : {}; },
191
321
  setLanguage: (code) => this.bridge.call('setLanguage', { code: requireString(code, 'code') }),
322
+ /**
323
+ * Kullanıcı özelliği yazar (ör. `setProperty('plan', 'pro')`); `null` özelliği siler. Değer metin, sayı, mantıksal ya da
324
+ * bunların dizisi/düz nesnesi olabilir; anahtar 1-64 karakterdir. Çevrimdışıyken yerel SDK kuyruğunda bekler.
325
+ */
326
+ setProperty: (key, value) => this.bridge.call('setUserProperty', { key: propertyKey(key), value: propertyValue(value, 'value') }),
192
327
  addAlias: (label, id) => this.bridge.call('addAliases', { aliases: { [requireString(label, 'label')]: requireString(id, 'id') } }),
193
328
  addAliases: (aliases) => this.bridge.call('addAliases', { aliases: stringRecord(aliases, 'aliases') }),
194
329
  removeAlias: (label) => this.bridge.call('removeAlias', { label: requireString(label, 'label') }),
@@ -209,6 +344,22 @@ class PushizoCore {
209
344
  getPreferences: async () => normalizePreferences(await this.bridge.call('getPreferences')),
210
345
  /** Tercihleri yazar (1-100 kayıt; `channel` verilmezse tüm kanallar); güncel listeyi döndürür. */
211
346
  setPreferences: async (preferences) => normalizePreferences(await this.bridge.call('setPreferences', { preferences: preferenceArgs(preferences) })),
347
+ /**
348
+ * Reklam kişiselleştirme rızası (ADR-0037): `true` iken kullanıcının e-posta/telefon özeti app'in bağladığı reklam
349
+ * platformu kitlelerine gönderilebilir; `false` rızayı geri alır. Güncel tercih listesini döndürür.
350
+ */
351
+ setAdsPersonalizationConsent: async (granted) => {
352
+ if (typeof granted !== 'boolean')
353
+ throw new TypeError('Pushizo: granted boolean olmalı.');
354
+ return normalizePreferences(await this.bridge.call('setAdsPersonalizationConsent', { granted }));
355
+ },
356
+ /** Rıza kayıtları (`ads_personalization` …). Abonelik henüz yoksa `NOT_READY` koduyla reddedilir. */
357
+ getConsents: async () => { var _a; return normalizeConsents((_a = (await this.bridge.call('getConsents'))) === null || _a === void 0 ? void 0 : _a.consents); },
358
+ /**
359
+ * Fire OS ADM kayıt kimliği (yalnızca Android; ana FCM aboneliğinin yerine geçmez). ADM kaydını kendisi yapan
360
+ * uygulamalar içindir. iOS ve web'de etkisizdir.
361
+ */
362
+ registerAdm: (token) => this.bridge.call('registerAdm', { token: requireString(token, 'token') }),
212
363
  pushSubscription: {
213
364
  getState: () => this.bridge.call('getPushSubscription'),
214
365
  getId: async () => { var _a; return (_a = (await this.bridge.call('getPushSubscription')).id) !== null && _a !== void 0 ? _a : null; },
@@ -244,6 +395,29 @@ class PushizoCore {
244
395
  },
245
396
  /** Aynı gruptaki bildirimleri kaldırır (Android `android_group`, iOS `thread-id`). */
246
397
  removeGroupedNotifications: (group) => this.bridge.call('removeGroupedNotifications', { group: requireString(group, 'group') }),
398
+ /**
399
+ * Uygulama rozetini ayarlar; rozet bu cihazda gösterilebiliyorsa true döner. iOS: rozet ve bildirim uzantısıyla
400
+ * paylaşılan sayaç ayarlanır (her zaman true). Android: başlatıcı rozeti için "sayıyı ayarla" API'si yoktur; yerel SDK
401
+ * sayıyı saklar ve sonraki bildirimlere yazar (Android 8 öncesinde, bildirimler ya da kanal rozeti kapalıyken false).
402
+ * Web: App Badging API (yüklü PWA); tarayıcı desteklemiyorsa false.
403
+ */
404
+ setBadgeCount: (count) => {
405
+ if (typeof count !== 'number' || !Number.isInteger(count) || count < 0) {
406
+ throw new RangeError('Pushizo: count negatif olmayan tam sayı olmalı.');
407
+ }
408
+ return this.badge(count);
409
+ },
410
+ /** Rozeti sıfırlar (`setBadgeCount(0)`); sonuç `setBadgeCount` ile aynıdır. */
411
+ clearBadge: () => this.badge(0),
412
+ /**
413
+ * Güncel rozet sayısı. Android: `setBadgeCount` ile saklanan son sayı; iOS: uygulama simgesindeki rozet; web: bu
414
+ * oturumda `setBadgeCount` ile başarıyla ayarlanan son sayı (tarayıcı rozeti okutmaz).
415
+ */
416
+ getBadgeCount: async () => {
417
+ var _a;
418
+ const count = (_a = (await this.bridge.call('getBadgeCount'))) === null || _a === void 0 ? void 0 : _a.count;
419
+ return typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;
420
+ },
247
421
  /** Bildirim/düğme tıklaması; soğuk başlatmada bekleyen tıklama ilk dinleyiciye teslim edilir. */
248
422
  addClickListener: (cb) => {
249
423
  const remove = this.listen(this.clickListeners, cb);
@@ -275,14 +449,25 @@ class PushizoCore {
275
449
  };
276
450
  // --- Oturum / olaylar ---
277
451
  this.Session = {
278
- /** Özel olay / outcome; in-app olay tetiklerini de değerlendirir. */
279
- sendEvent: (name, properties, value) => {
452
+ /**
453
+ * Özel olay / outcome; in-app olay tetiklerini de değerlendirir. `options.eventId` tekilleştirme kimliğidir
454
+ * (8-64 karakter; harf, rakam ve `. _ : -`): reklam pikseliyle aynı kimlik verilirse sunucu olayı tekilleşir
455
+ * (ADR-0038). Biçim geçersizse yerel SDK kendi kimliğini üretir.
456
+ */
457
+ sendEvent: (name, properties, value, options) => {
280
458
  const args = { name: requireString(name, 'name'), properties: properties !== null && properties !== void 0 ? properties : {} };
281
459
  if (value !== undefined && value !== null) {
282
460
  if (typeof value !== 'number' || !Number.isFinite(value))
283
461
  throw new TypeError('Pushizo: value sayı olmalı.');
284
462
  args.value = value;
285
463
  }
464
+ const eventId = options === null || options === void 0 ? void 0 : options.eventId;
465
+ if (eventId !== undefined && eventId !== null) {
466
+ if (typeof eventId !== 'string')
467
+ throw new TypeError('Pushizo: eventId metin olmalı.');
468
+ if (eventId !== '')
469
+ args.eventId = eventId;
470
+ }
286
471
  return this.bridge.call('sendEvent', args);
287
472
  },
288
473
  };
@@ -328,11 +513,36 @@ class PushizoCore {
328
513
  /** Öğeyi kutudan kaldırır (sunucuda arşivlenir). */
329
514
  archive: (id) => this.bridge.call('inboxArchive', { id: requireString(id, 'id') }),
330
515
  unreadCount: async () => { var _a; return (_a = (await this.bridge.call('inboxUnreadCount')).unreadCount) !== null && _a !== void 0 ? _a : 0; },
516
+ /**
517
+ * Kutu değişim gözlemcisi (rozet güncellemek için): `read`/`read_all`/`archived` her işlemde, `listed`/`count`
518
+ * yalnızca okunmamış sayısı değiştiğinde bildirilir. Dönen fonksiyon aboneliği kaldırır.
519
+ */
520
+ addObserver: (cb) => this.listen(this.inboxObservers, cb),
521
+ removeObserver: (cb) => {
522
+ this.inboxObservers.delete(cb);
523
+ },
524
+ };
525
+ // --- İçerik kartları (ADR-0082) ---
526
+ this.ContentCards = {
527
+ /** Kart akışı (sabitlenmiş → öncelik → yeni) ve görülmemiş kart sayısı; `limit` 1-100 (varsayılan 50). */
528
+ list: (limit = 50) => {
529
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
530
+ return Promise.reject(new RangeError('Pushizo: limit 1-100 olmalı.'));
531
+ }
532
+ return this.bridge.call('contentCardsList', { limit });
533
+ },
534
+ /** Kart ekranda gösterildi (ilk gösterim kaydedilir). */
535
+ logImpression: (id) => this.cardEvent(id, 'impression'),
536
+ /** Karta tıklandı (gösterim de sayılır). */
537
+ logClick: (id) => this.cardEvent(id, 'click'),
538
+ /** Kart kapatıldı; akıştan kalkar. */
539
+ dismiss: (id) => this.cardEvent(id, 'dismiss'),
331
540
  };
332
541
  // --- Canlı sohbet (ADR-0040) ---
333
542
  /**
334
543
  * Canlı sohbet (Android ve iOS): ziyaretçi kimliği, çevrimdışı kuyruk, canlı akış (SSE + yoklama yedeği) ve push ile
335
- * gelen mesajlar native SDK'dadır; login/logout ve push aboneliği değişince bağlama native SDK'da yenilenir.
544
+ * gelen mesajlar native SDK'dadır; login/logout ve push aboneliği değişince bağlama native SDK'da yenilenir. Hazır
545
+ * arayüz için `show()` / `hide()`; kendi arayüzünüz için diğer çağrılar ve olaylar.
336
546
  */
337
547
  this.Chat = {
338
548
  /** Sohbeti etkinleştirir ve ziyaretçiyi bağlar (giriş yapmış kullanıcı, push aboneliği); konuşma varsa döner. */
@@ -418,8 +628,23 @@ class PushizoCore {
418
628
  stopListening: () => this.bridge.call('chatStopListening'),
419
629
  /** Ek dosyasının adresi; ziyaretçi belirtecini taşır, yalnızca görsel bileşenine verin ve loglamayın. */
420
630
  attachmentUrl: async (attachmentId, download = false) => (await this.bridge.call('chatAttachmentUrl', { attachmentId: requireString(attachmentId, 'attachmentId'), download })).url,
631
+ /** Canlı dinleme açık mı (`startListening` çağrıldı ve akış etkin). */
632
+ isListening: async () => { var _a; return Boolean((_a = (await this.bridge.call('chatIsListening'))) === null || _a === void 0 ? void 0 : _a.listening); },
421
633
  /** Bu cihazın ziyaretçi kimliği (sohbet henüz kullanılmadıysa null). */
422
634
  getVisitorId: async () => { var _a; return (_a = (await this.bridge.call('chatGetVisitorId')).visitorId) !== null && _a !== void 0 ? _a : null; },
635
+ /**
636
+ * Hazır sohbet ekranını açar (Android `HsChatActivity`, iOS `HSChatViewController` modal; web: Web SDK sohbet
637
+ * widget'ı açık pencereyle). Ekran zaten açıksa yenisi açılmaz. `initialize` öncesinde `NOT_READY` ile reddedilir.
638
+ */
639
+ show: async () => {
640
+ await this.bridge.call('chatShow');
641
+ },
642
+ /** `show` ile açılan sohbet ekranını kapatır (açık değilse hiçbir şey yapmaz). */
643
+ hide: async () => {
644
+ await this.bridge.call('chatHide');
645
+ },
646
+ /** `show` ile açılan sohbet ekranı şu an açık mı. */
647
+ isPresented: async () => { var _a; return Boolean((_a = (await this.bridge.call('chatIsPresented'))) === null || _a === void 0 ? void 0 : _a.presented); },
423
648
  /** Sohbet olay dinleyicisi; kaldırma fonksiyonu döner. `open`: sohbet bildirimine tıklama. */
424
649
  addEventListener: (event, listener) => {
425
650
  const set = this.chatListeners[event];
@@ -437,13 +662,66 @@ class PushizoCore {
437
662
  (_a = this.chatListeners[event]) === null || _a === void 0 ? void 0 : _a.delete(listener);
438
663
  },
439
664
  };
665
+ // --- Özellik bayrakları (ADR-0066) ---
666
+ /**
667
+ * Özellik bayrakları: değerler native SDK'da oturum başında yenilenir ve cihazda saklanır; ağ yoksa son değer, hiç
668
+ * alınmadıysa verilen varsayılan döner. Gizlilik onayı beklenirken istek gönderilmez.
669
+ */
670
+ this.FeatureFlags = {
671
+ /** Değerleri sunucudan hemen yeniler; yeni değerler alındıysa true (hata son değerleri korur). */
672
+ refresh: async () => { var _a; return Boolean((_a = (await this.bridge.call('featureFlagsRefresh'))) === null || _a === void 0 ? void 0 : _a.success); },
673
+ /** Bayrak bu kullanıcı için açık mı; değer henüz yoksa `defaultValue`. */
674
+ isEnabled: async (key, defaultValue = false) => {
675
+ var _a;
676
+ const args = { key: requireString(key, 'key'), defaultValue: Boolean(defaultValue) };
677
+ return Boolean((_a = (await this.bridge.call('featureFlagsIsEnabled', args))) === null || _a === void 0 ? void 0 : _a.enabled);
678
+ },
679
+ /** Bayrağın değeri (metin, sayı, mantıksal, nesne veya dizi); değer yoksa `defaultValue`. */
680
+ getValue: async (key, defaultValue = null) => {
681
+ const result = await this.bridge.call('featureFlagsGetValue', {
682
+ key: requireString(key, 'key'),
683
+ });
684
+ const value = result === null || result === void 0 ? void 0 : result.value;
685
+ return value === undefined || value === null ? defaultValue : value;
686
+ },
687
+ /**
688
+ * Bayrak değerleri sunucudan her yenilendiğinde (oturum başı ve `refresh()`) çağrılır; güncel değerler `isEnabled` /
689
+ * `getValue` ile okunur. Dönen fonksiyon aboneliği kaldırır.
690
+ */
691
+ addObserver: (cb) => this.listen(this.featureFlagObservers, cb),
692
+ removeObserver: (cb) => {
693
+ this.featureFlagObservers.delete(cb);
694
+ },
695
+ };
696
+ // --- Gömülü yerleşimler (ADR-0068) ---
697
+ /**
698
+ * Gömülü yerleşimler: uygulamanın ayırdığı alana içerik. Model döner, çizim uygulamanındır; içerik ekrana gelince
699
+ * `reportImpression`, düğme tıklanınca `reportClick`, kapatılınca `reportDismiss` çağrılır.
700
+ */
701
+ this.Placements = {
702
+ /** Alanın içeriği (`limit` 1-10, varsayılan 1). Abonelik yoksa veya gizlilik onayı bekleniyorsa boş döner. */
703
+ list: async (key, options = {}) => {
704
+ var _a;
705
+ if (typeof key !== 'string' || !PLACEMENT_KEY.test(key))
706
+ throw new TypeError('Pushizo: geçersiz yerleşim anahtarı.');
707
+ const limit = (_a = options.limit) !== null && _a !== void 0 ? _a : 1;
708
+ if (!Number.isInteger(limit) || limit < 1 || limit > 10)
709
+ throw new RangeError('Pushizo: limit 1-10 olmalı.');
710
+ const result = await this.bridge.call('placementsList', { key, limit });
711
+ return Array.isArray(result === null || result === void 0 ? void 0 : result.messages) ? result.messages : [];
712
+ },
713
+ /** Raporlar `list` ile alınmış mesaj içindir; native katmanın tanımadığı mesaj yok sayılır. */
714
+ reportImpression: async (message) => this.bridge.call('placementsReportImpression', { id: placementMessageId(message) }),
715
+ reportClick: async (message, buttonId) => this.bridge.call('placementsReportClick', { id: placementMessageId(message), buttonId: requireString(buttonId, 'buttonId') }),
716
+ reportDismiss: async (message) => this.bridge.call('placementsReportDismiss', { id: placementMessageId(message) }),
717
+ };
440
718
  // --- Konum (v2 Faz 17b) ---
441
719
  /**
442
- * Konum paylaşımı (yalnızca ön plan; arka plan konumu yok). Paylaşım açıkken native SDK konumu oturum başında ve
443
- * uygulama ön plana döndüğünde en sık 5 dakikada bir push aboneliğine yazar; izin yoksa veya gizlilik onayı
444
- * verilmemişse hiçbir şey gönderilmez. İlk konum sunucuda KVKK açık rıza kaydı sayılır; `setShared(false)` konumu ve
445
- * rıza kaydını sildirir. Tercih kalıcıdır. `initialize` öncesinde `setShared`/`requestPermission` `NOT_READY` ile
446
- * reddedilir (web: Web SDK hatası).
720
+ * Konum paylaşımı (yalnızca ön plan; arka planda koordinat toplanmaz, bölge izleme için `setGeofencingEnabled`).
721
+ * Paylaşım açıkken native SDK konumu oturum başında ve uygulama ön plana döndüğünde en sık 5 dakikada bir push
722
+ * aboneliğine yazar; izin yoksa veya gizlilik onayı verilmemişse hiçbir şey gönderilmez. İlk konum sunucuda KVKK açık
723
+ * rıza kaydı sayılır; `setShared(false)` konumu ve rıza kaydını sildirir. Tercih kalıcıdır. `initialize` öncesinde
724
+ * `setShared`/`requestPermission`/`setGeofencingEnabled` `NOT_READY` ile reddedilir (web: Web SDK hatası).
447
725
  */
448
726
  this.Location = {
449
727
  /** Paylaşımı açar/kapatır (kalıcı). Açılırken izin varsa konum hemen gönderilir; izin için `requestPermission`. */
@@ -467,6 +745,101 @@ class PushizoCore {
467
745
  args.rationale = rationale;
468
746
  return Boolean((await this.bridge.call('requestLocationPermission', args)).permission);
469
747
  },
748
+ /**
749
+ * Ön plan konum izni verilmiş mi (Android yaklaşık/hassas, iOS "kullanırken" veya "her zaman"; web: tarayıcı konum
750
+ * izninin son bilinen durumu). İstem açmaz.
751
+ */
752
+ permissionGranted: async () => { var _a; return Boolean((_a = (await this.bridge.call('getLocationPermission'))) === null || _a === void 0 ? void 0 : _a.permission); },
753
+ /** Arka plan konum izni verilmiş mi (Android `ACCESS_BACKGROUND_LOCATION`, iOS "her zaman"). Web'de false. */
754
+ backgroundPermissionGranted: async () => { var _a; return Boolean((_a = (await this.bridge.call('getLocationPermission'))) === null || _a === void 0 ? void 0 : _a.background); },
755
+ /**
756
+ * Arka plan konum iznini ister (bölge izleme için). Android: açıklama diyaloğu (`rationale`; verilmezse SDK metni),
757
+ * ardından `ACCESS_BACKGROUND_LOCATION` (Android 11+ sistem Ayarlar ekranını açar; önce ön plan konum izni verilmiş
758
+ * olmalı). iOS: "her zaman" izni (`rationale` yok sayılır; önce "kullanırken" izni verilmiş olmalı). Sonuç: izin
759
+ * varsa veya verildiyse true; reddedildiyse, uygulama izni tanımlamadıysa veya vazgeçildiyse false. Web'de false.
760
+ */
761
+ requestBackgroundPermission: async (rationale) => {
762
+ if (rationale !== undefined && rationale !== null && typeof rationale !== 'string') {
763
+ throw new TypeError('Pushizo: rationale metin olmalı.');
764
+ }
765
+ const args = {};
766
+ if (typeof rationale === 'string' && rationale.trim() !== '')
767
+ args.rationale = rationale;
768
+ const result = await this.bridge.call('requestBackgroundLocationPermission', args);
769
+ return Boolean(result === null || result === void 0 ? void 0 : result.permission);
770
+ },
771
+ /** `requestBackgroundPermission` ile aynı izin (iOS adı: "her zaman"); iki ad da her platformda çalışır. */
772
+ requestAlwaysPermission: async () => {
773
+ var _a;
774
+ return Boolean((_a = (await this.bridge.call('requestBackgroundLocationPermission', {}))) === null || _a === void 0 ? void 0 : _a.permission);
775
+ },
776
+ /**
777
+ * Arka plan bölge izlemeyi açar/kapatır (ADR-0065; kalıcı, varsayılan kapalı). İzlemeyi işletim sistemi yapar,
778
+ * sunucuya koordinat gitmez. `setShared(true)` ve arka plan konum izni gerekir (`requestBackgroundPermission`);
779
+ * köprü manifest/Info.plist'e izin eklemez.
780
+ */
781
+ setGeofencingEnabled: (enabled) => this.bridge.call('setGeofencingEnabled', { enabled: Boolean(enabled) }),
782
+ /** Bölge izleme açık mı (kalıcı tercih; izin durumundan bağımsız). */
783
+ isGeofencingEnabled: async () => { var _a; return Boolean((_a = (await this.bridge.call('isGeofencingEnabled'))) === null || _a === void 0 ? void 0 : _a.enabled); },
784
+ };
785
+ // --- Reklam kimliği (ADR-0037) ---
786
+ /**
787
+ * Mobil reklam kimliği (Android GAID, iOS IDFA). SDK reklam kitaplığı ve izin istemi içermez: kimliği uygulama alır
788
+ * (Android `AdvertisingIdClient`, iOS App Tracking Transparency izninden sonra `ASIdentifierManager`) ve buraya verir.
789
+ * Kimlik reklam kitlesine yalnızca `ads_personalization` rızası olan kullanıcıda ve SHA-256 özetiyle gider.
790
+ */
791
+ this.Ads = {
792
+ /** Reklam kimliğini yazar; `null` veya sıfır kimlik sunucudaki kaydı siler. Web'de etkisizdir. */
793
+ setAdvertisingId: (id) => {
794
+ if (id !== null && id !== undefined && typeof id !== 'string') {
795
+ throw new TypeError('Pushizo: id metin veya null olmalı.');
796
+ }
797
+ return this.bridge.call('setAdvertisingId', { id: typeof id === 'string' && id.trim() !== '' ? id : null });
798
+ },
799
+ };
800
+ // --- Android teslimat güçlendirme (ADR-0092) ---
801
+ /**
802
+ * Android teslimat güçlendirme: bazı üreticilerin pil/otomatik başlatma yöneticisi arka plandaki uygulamayı durdurduğu
803
+ * için bildirimler gecikir ya da gelmez. Bu yüzey cihazdaki kısıtları okur ve kullanıcıyı ilgili ayar ekranına götürür.
804
+ * Yalnızca Android'de etkilidir: iOS ve web'de `status()` `supported: false` ve `risk: 'none'` döner, `openSettings` ile
805
+ * `showGuidance` hiçbir şey yapmadan `false` döner.
806
+ */
807
+ this.Delivery = {
808
+ /** Cihazın teslim durumu: üretici, ROM, pil muafiyeti, arka plan kısıtı, risk ve önerilen ayar ekranları. */
809
+ status: async () => normalizeDeliveryStatus(await this.bridge.call('deliveryStatus')),
810
+ /** Hazır açıklama diyaloğu şimdi gösterilmeli mi: teslim riski var ve diyalog son `minIntervalDays` günde gösterilmedi. */
811
+ shouldShowGuidance: async (minIntervalDays = 14) => {
812
+ if (!Number.isInteger(minIntervalDays) || minIntervalDays < 0) {
813
+ throw new RangeError('Pushizo: minIntervalDays negatif olmayan tam sayı olmalı.');
814
+ }
815
+ const result = await this.bridge.call('deliveryShouldShowGuidance', { minIntervalDays });
816
+ return Boolean(result === null || result === void 0 ? void 0 : result.show);
817
+ },
818
+ /**
819
+ * Ayar ekranını açar (`auto`: duruma en uygun ekran). Üreticiye özgü ekran bulunamazsa standart Android ekranına
820
+ * düşülür. Bir ekran açıldıysa true.
821
+ */
822
+ openSettings: async (setting = 'auto') => {
823
+ var _a;
824
+ const args = { setting: deliverySetting(setting) };
825
+ return Boolean((_a = (await this.bridge.call('deliveryOpenSettings', args))) === null || _a === void 0 ? void 0 : _a.opened);
826
+ },
827
+ /**
828
+ * Hazır açıklama diyaloğunu gösterir (22 dil; `message` verilirse SDK metni yerine o gösterilir). Kullanıcı kabul
829
+ * ederse `setting` ekranı açılır. Ayar ekranı açıldıysa true; kullanıcı vazgeçtiyse, ekran açılamadıysa ya da etkin
830
+ * Activity yoksa false. SDK diyaloğu kendiliğinden göstermez; uygun anı uygulama seçer (`shouldShowGuidance`).
831
+ */
832
+ showGuidance: async (options = {}) => {
833
+ var _a;
834
+ const message = options.message;
835
+ if (message !== undefined && message !== null && typeof message !== 'string') {
836
+ throw new TypeError('Pushizo: message metin olmalı.');
837
+ }
838
+ const args = { setting: deliverySetting(options.setting) };
839
+ if (typeof message === 'string' && message.trim() !== '')
840
+ args.message = message;
841
+ return Boolean((_a = (await this.bridge.call('deliveryShowGuidance', args))) === null || _a === void 0 ? void 0 : _a.opened);
842
+ },
470
843
  };
471
844
  // --- Live Activities (iOS) ---
472
845
  /**
@@ -563,6 +936,24 @@ class PushizoCore {
563
936
  case 'chatOpen':
564
937
  this.onChatOpen((payload !== null && payload !== void 0 ? payload : {}));
565
938
  break;
939
+ case 'featureFlagsChange':
940
+ this.featureFlagObservers.forEach((l) => safeInvoke(l, undefined));
941
+ break;
942
+ case 'inboxChange': {
943
+ const raw = (payload !== null && payload !== void 0 ? payload : {});
944
+ const type = INBOX_CHANGE_TYPES.find((t) => t === raw.type);
945
+ if (!type)
946
+ return;
947
+ const event = {
948
+ type,
949
+ unreadCount: typeof raw.unreadCount === 'number' && Number.isFinite(raw.unreadCount) ? raw.unreadCount : 0,
950
+ };
951
+ // `itemId` yalnızca tek öğe olaylarında (`read`, `archived`) bulunur; Android `null` gönderir, iOS alanı göndermez.
952
+ if (typeof raw.itemId === 'string' && raw.itemId !== '')
953
+ event.itemId = raw.itemId;
954
+ this.inboxObservers.forEach((l) => safeInvoke(l, event));
955
+ break;
956
+ }
566
957
  default:
567
958
  break;
568
959
  }
@@ -651,16 +1042,20 @@ class PushizoCore {
651
1042
  }
652
1043
  /**
653
1044
  * Anonim kullanıcıyı kimlikli kullanıcıya bağlar. Identity verification açıksa app moduna göre `identityHash`
654
- * (eski imza: ikinci argüman metin) ve/veya JWT gerekir: `login(id, { jwt })`.
1045
+ * (eski imza: ikinci argüman metin) ve/veya JWT gerekir: `login(id, { jwt })`. `profile` verilirse e-posta, SMS,
1046
+ * etiket ve takma adlar aynı çağrıda ayarlanır: `login(id, { profile: { email: 'ali@ornek.com' } })`; geçersiz
1047
+ * e-posta veya telefon girişten önce `INVALID_ARGUMENT` ile reddedilir (yarım kalmış kimlik değişimi olmaz).
655
1048
  */
656
1049
  login(externalId, proof) {
657
1050
  requireString(externalId, 'externalId');
658
- const { identityHash, jwt } = typeof proof === 'string' ? { identityHash: proof } : (proof !== null && proof !== void 0 ? proof : {});
1051
+ const { identityHash, jwt, profile } = typeof proof === 'string' ? { identityHash: proof } : (proof !== null && proof !== void 0 ? proof : {});
659
1052
  const args = { externalId };
660
1053
  if (identityHash !== undefined && identityHash !== null)
661
1054
  args.identityHash = requireString(identityHash, 'identityHash');
662
1055
  if (jwt !== undefined && jwt !== null)
663
1056
  args.jwt = requireString(jwt, 'jwt');
1057
+ if (profile !== undefined && profile !== null)
1058
+ args.profile = profileArgs(profile);
664
1059
  return this.bridge.call('login', args);
665
1060
  }
666
1061
  /** Süresi dolan kimlik JWT'sini yeniler (giriş yapmış kullanıcı için); sonraki SDK istekleri yeni belirteci taşır. */
@@ -671,6 +1066,14 @@ class PushizoCore {
671
1066
  logout() {
672
1067
  return this.bridge.call('logout');
673
1068
  }
1069
+ /** Rozet çağrısı; yanıt vermeyen (eski) native katman başarılı sayılır. */
1070
+ async badge(count) {
1071
+ var _a;
1072
+ return ((_a = (await this.bridge.call('setBadgeCount', { count }))) === null || _a === void 0 ? void 0 : _a.success) !== false;
1073
+ }
1074
+ cardEvent(id, event) {
1075
+ return this.bridge.call('contentCardEvent', { id: requireString(id, 'id'), event });
1076
+ }
674
1077
  /** Native sohbet olayını türüne göre dağıtır. */
675
1078
  onChatEvent(raw) {
676
1079
  var _a, _b, _c;