signalbird 2.8.1 → 2.9.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.ts CHANGED
@@ -57,7 +57,7 @@ interface LogResult {
57
57
  ok: boolean;
58
58
  /** Sunucunun döndüğü olay kimliği (rev_…). */
59
59
  eventId?: string;
60
- /** Reddedildiyse sebep: INVALID_KEY, MODULE_DISABLED, LIMIT_REACHED… */
60
+ /** Reddedildiyse sebep: DOMAIN_KEY_INVALID, MODULE_DISABLED, MODULE_KEY_DISABLED, LIMIT_REACHED… */
61
61
  code?: string;
62
62
  status?: number;
63
63
  }
@@ -114,13 +114,22 @@ declare class SignalbirdClient {
114
114
  error: (message: string, context?: Record<string, unknown>) => Promise<LogResult>;
115
115
  critical: (message: string, context?: Record<string, unknown>) => Promise<LogResult>;
116
116
  };
117
- /** Tek kayıt gönderir. */
117
+ /**
118
+ * Tek kayıt gönderir.
119
+ *
120
+ * `message` 4000 kod noktasına kırpılır (API sınırı; aşan satır 422 alırdı)
121
+ * ve `context` güvenli kopyaya çevrilir: döngüsel nesne ya da BigInt artık
122
+ * `NETWORK_ERROR` gibi görünen bir istisnaya dönüşmez.
123
+ */
118
124
  log(input: LogInput): Promise<LogResult>;
119
125
  /**
120
126
  * Toplu gönderim - 100 kayda kadar.
121
127
  *
122
128
  * Kısmi başarı normaldir (kota tam ortada dolabilir), o yüzden sonuç tek bir
123
129
  * durum değil satır satır döner.
130
+ *
131
+ * Doğrulama ise satır satır DEĞİLDİR: tek bir geçersiz satır (4000'i aşan
132
+ * mesaj) bütün paketi 422 ile düşürür. Bu yüzden kırpma burada da yapılır.
124
133
  */
125
134
  batch(events: LogInput[]): Promise<BatchResult>;
126
135
  debugLog(key: string, message: string, context?: Record<string, unknown>): Promise<LogResult>;
@@ -159,7 +168,7 @@ declare class SignalbirdClient {
159
168
  * bulunur ve iki doküman arasında çeviri tablosu gerekmez.
160
169
  */
161
170
  interface MessagingConfig {
162
- /** Takım API anahtarı (`sb_…`). GİZLİDİR, yalnız sunucuda kullanılır. */
171
+ /** Gizli domain anahtarı (`sb_secret_live_…`). Yalnız sunucuda kullanılır. */
163
172
  domainKey: string;
164
173
  /** Varsayılan: https://live.signalbird.io/api */
165
174
  baseUrl?: string;
@@ -185,22 +194,96 @@ type SbResult$1<T> = {
185
194
  /** İleti sınıfı - API'de zorunludur ve varsayılanı YOKTUR (hukuki kapı). */
186
195
  type MessageClass = 'transactional' | 'commercial';
187
196
  type Channel = 'email' | 'sms' | 'push';
197
+ /** E-posta eki - içerik base64; toplam çözülmüş boyut sınırı sunucudadır (7 MB). */
198
+ interface EmailAttachment {
199
+ filename: string;
200
+ mime?: string;
201
+ /** Dosya içeriği, base64. */
202
+ content_b64: string;
203
+ }
204
+ /**
205
+ * `POST /v1/email/send` gövdesi - alanlar API doğrulamasıyla birebir
206
+ * (signalbird.api `Api\V1\MessagingController::sendEmail`).
207
+ *
208
+ * İçerik iki yoldan gelir: ya `subject` + `body`, ya panelde tanımlı bir
209
+ * şablon (`template` adıyla ya da `template_id` ile). Şablon verilmediyse
210
+ * `subject` ve `body` ZORUNLUDUR (API: `required_without_all:template_id,template`);
211
+ * verildiyse ikisi de şablondan gelir ve istenirse ezilebilir.
212
+ *
213
+ * Tip bilerek arayüz olarak kaldı (birleşim tipi değil): kullanıcı kodunda
214
+ * `extends SendEmailInput` yazan herkes kırılırdı.
215
+ */
188
216
  interface SendEmailInput {
217
+ /** Alıcı e-posta adresi. */
189
218
  to: string;
219
+ /** Zorunlu, varsayılanı yok: işlemsel ile ticari arasındaki fark hukukidir. */
190
220
  class: MessageClass;
191
- subject: string;
221
+ /** Konu (en fazla 255). Şablon yoksa zorunlu. */
222
+ subject?: string;
223
+ /** Gövde - HTML ya da düz metin. Şablon yoksa zorunlu. */
192
224
  body?: string;
193
- template_hash?: string;
225
+ /** Panelde tanımlı şablonun ADI (en fazla 190). Ad tercih edilir: şablon yeniden yaratılsa da kod değişmez. */
226
+ template?: string;
227
+ /** Panelde tanımlı şablonun kimliği. */
228
+ template_id?: number;
229
+ /** Şablon/gövde değişkenleri - `{{ad}}` yerine geçer. */
194
230
  vars?: Record<string, unknown>;
231
+ /**
232
+ * GÖNDERİCİ KANALI: panelde adresle birlikte açılan `email` modül anahtarı
233
+ * (`noReply`). From adresini kanal seçer - PHP'deki
234
+ * `Signalbird::sendMail('noReply')` karşılığı. Kanala adres bağlanmamışsa
235
+ * 422 `SENDER_NOT_CONFIGURED`; tanımsız kanal `MODULE_KEY_NOT_FOUND`.
236
+ */
237
+ module_key?: string;
238
+ /** Belirli bir doğrulanmış gönderen alan adından çıksın. */
195
239
  sending_domain_id?: number;
240
+ /** Gönderen ADRES seçimi (destek@…); alan adını da belirler. `module_key` verilirse kanalınki geçerlidir. */
241
+ sending_address_id?: number;
242
+ /** Signalbird'deki kişi kaydı - açılma/tıklama geçmişi ona yazılsın. */
196
243
  contact_id?: number;
244
+ /** Görünen gönderen adı (en fazla 120). Zarf adresi değil. */
245
+ from_name?: string;
246
+ /** "Yanıtla" adresi. */
247
+ reply_to?: string;
248
+ /** En fazla 5 ek. */
249
+ attachments?: EmailAttachment[];
250
+ /**
251
+ * @deprecated API bu alanı hiç okumaz ve SDK onu GÖNDERMEZ (2.9.0). Şablon
252
+ * için `template` (ad) ya da `template_id` kullanın. Yalnız eski kodun tip
253
+ * denetiminde kırılmaması için tanımlı; başka bir alana eşlenmez.
254
+ */
255
+ template_hash?: string;
197
256
  }
257
+ /**
258
+ * `POST /v1/sms/send` gövdesi - alanlar API doğrulamasıyla birebir
259
+ * (signalbird.api `Api\V1\MessagingController::sendSms`).
260
+ *
261
+ * İçerik ya `body` ya da panelde tanımlı bir şablondur (`template` adıyla ya
262
+ * da `template_id` ile). Şablon verilmediyse `body` ZORUNLUDUR (API:
263
+ * `required_without_all:template_id,template`).
264
+ *
265
+ * E-postanın aksine SMS ucunda gönderici KANALI (`module_key`) yoktur;
266
+ * gönderen adı `sender` ile seçilir.
267
+ */
198
268
  interface SendSmsInput {
269
+ /** Alıcı telefon (en fazla 20). Sunucu normalize eder; geçersizse 422 `INVALID_PHONE`. */
199
270
  to: string;
271
+ /** Zorunlu, varsayılanı yok: işlemsel ile ticari arasındaki fark hukukidir. */
200
272
  class: MessageClass;
201
- body: string;
273
+ /** Mesaj metni (en fazla 1600). Şablon yoksa zorunlu. */
274
+ body?: string;
275
+ /** Panelde tanımlı şablonun ADI (en fazla 190). */
276
+ template?: string;
277
+ /** Panelde tanımlı şablonun kimliği. */
278
+ template_id?: number;
279
+ /** Şablon/gövde değişkenleri - `{{ad}}` yerine geçer. */
280
+ vars?: Record<string, unknown>;
281
+ /** Marka (SMS başlığı/kotası bu markadan). */
202
282
  brand_id?: number;
283
+ /** Signalbird'deki kişi kaydı. */
203
284
  contact_id?: number;
285
+ /** Onaylı SMS gönderici adı (en fazla 11). Verilmezse şirketin varsayılanı. */
286
+ sender?: string;
204
287
  }
205
288
  interface SendPushInput {
206
289
  /** Cihaz token'ı, `contact:<id>` ya da `external:<external_id>`. */
@@ -610,7 +693,7 @@ interface EmbedToken {
610
693
  }
611
694
 
612
695
  interface ManagementConfig {
613
- /** Takım API anahtarı (`sb_…`) - `radio:*`, `chat:*`, `apps:*` scope'larıyla. */
696
+ /** Gizli domain anahtarı (`sb_secret_live_…`). Scope yoktur (v2); yalnız gömme jetonu ayrı onay ister. */
614
697
  domainKey: string;
615
698
  /** Varsayılan: https://live.signalbird.io/api */
616
699
  baseUrl?: string;
@@ -924,9 +1007,9 @@ interface TeamEmbedTokenInput {
924
1007
  * kayıtlarına dokunur; başka takımın kaydı 404 döner.
925
1008
  *
926
1009
  * Neden ayrı sınıf: Gönderim (`SignalbirdMessaging`) ileti gönderir ve kota
927
- * harcar; bu istemci yapılandırma değiştirir. Aynı anahtar ailesini kullanırlar
928
- * (`sb_…`) ama scope'ları ve hata kümeleri farklıdır - tek sınıfta birleşseydi
929
- * "hangi scope gerekiyordu" sorusu her metotta yeniden sorulurdu.
1010
+ * harcar; bu istemci yapılandırma değiştirir. Aynı gizli domain anahtarını
1011
+ * (`sb_secret_live_…`) kullanırlar ama hata kümeleri farklıdır - tek sınıfta
1012
+ * birleşseydi her metotta "bu kod hangi yüzeyin" sorusu sorulurdu.
930
1013
  *
931
1014
  * Sözleşme: docs/CONTRACT.md § 10
932
1015
  */
@@ -1066,7 +1149,7 @@ declare class SignalbirdManagement {
1066
1149
  *
1067
1150
  * **Bu, CLAUDE.md'deki "Admin yüzeyi OLMAYACAK" kuralının bilinçli
1068
1151
  * istisnasıdır** ve istisna olduğu için ayrı anahtar türü taşır. Kural,
1069
- * müşterinin kendi anahtarıyla (`sb_`) şirket açamaması içindi; o kural aynen
1152
+ * müşterinin kendi anahtarıyla şirket açamaması içindi; o kural aynen
1070
1153
  * duruyor. Sözleşmeli partner farklı bir taraftır.
1071
1154
  *
1072
1155
  * Gizli anahtar **asla tarayıcıya inmez**: gömme jetonunu partner'ın
@@ -1173,11 +1256,12 @@ declare function verifyWebhook(rawBody: string | Uint8Array, signatureHeader: st
1173
1256
  * Node betikleri buradan alır. TARAYICI için `signalbird/browser`
1174
1257
  * kullanılır - gizli anahtar istemciye inmez.
1175
1258
  *
1176
- * Üç sunucu istemcisi vardır; anahtarları ve kapıları farklıdır:
1177
- * - `SignalbirdClient` → Telsiz (log yazma), `sb_secret_live_…`
1178
- * - `SignalbirdMessaging` → Gönderim (e-posta/SMS/push/kişi/kampanya), `sb_…`
1179
- * - `SignalbirdManagement` → Yönetim (Telsiz projesi, sohbet gelen kutusu,
1180
- * uygulama kaydı), `sb_…` + `radio|chat|apps` scope'ları
1259
+ * Sunucu istemcilerinin HEPSİ aynı gizli domain anahtarını (`sb_secret_live_…`)
1260
+ * kullanır; ayrım anahtarda değil, kapıdadır:
1261
+ * - `SignalbirdClient` → Telsiz (log yazma)
1262
+ * - `SignalbirdMessaging` → Gönderim (e-posta/SMS/push/kişi/kampanya)
1263
+ * - `SignalbirdManagement` → Yönetim (olay akışı, modül anahtarları, sohbet
1264
+ * gelen kutusu)
1181
1265
  * - `SignalbirdPartner` → Partner (müşteri sağlama, modül yetkisi, gömme),
1182
1266
  * gizli anahtar - yalnız sözleşmeli platformlar
1183
1267
  *
@@ -1201,8 +1285,8 @@ declare function resetSignalbird(): void;
1201
1285
  /**
1202
1286
  * Ortam değişkeninden kurulan paylaşımlı yönetim istemcisi.
1203
1287
  *
1204
- * `SIGNALBIRD_DOMAIN_KEY` okunur (yoksa `SIGNALBIRD_DOMAIN_KEY` - ikisi de aynı
1205
- * takım anahtarı ailesidir ve çoğu kurulumda tek anahtar kullanılır).
1288
+ * `SIGNALBIRD_DOMAIN_KEY` okunur - Telsiz ve Gönderim ile aynı gizli domain
1289
+ * anahtarı (`sb_secret_live_…`).
1206
1290
  *
1207
1291
  * import { management } from 'signalbird'
1208
1292
  * await management().createModuleKey('logger', { title: 'Kritik API hatası' })
@@ -1211,4 +1295,4 @@ declare function management(config?: Partial<ManagementConfig>): SignalbirdManag
1211
1295
  /** Test ve sıcak yeniden yükleme için yönetim istemcisini sıfırlar. */
1212
1296
  declare function resetManagement(): void;
1213
1297
 
1214
- export { type AddDomainInput, type AddDomainResult, type AppDevice, type AppPlatform, type Batch, type BatchResult, type BulkContactsInput, type BulkContactsResult, type CampaignCreateResult, type CampaignDetail, type CannedReply, type CannedReplyInput, type Channel, type ChatConversation, type ChatMessage, type ChatVisitor, type Contact, type ContactInput, type ContactList, type ConversationStatus, type CreateCampaignInput, type CreateCompanyInput, type CreateCompanyResult, type CreateContactListInput, DEFAULT_BASE_URL, type DnsRecord, type EmbedModule, type EmbedToken, type EmbedTokenInput, type GrantModuleInput, type Level, type ListAppDevicesQuery, type ListCampaignMessagesQuery, type ListCampaignsQuery, type ListChatMessagesQuery, type ListContactsQuery, type ListConversationsQuery, type ListMessagesQuery, type ListRadioEventsQuery, type LogInput, type LogResult, type ManagementConfig, type Message, type MessageClass, type MessagingConfig, type MessagingErrorCode, type ModuleEntitlement, type Paginated$1 as Paginated, type PartnerCompany, type PartnerConfig, type PartnerDomain, type PartnerOwnerInput, type PartnerUser, type PartnerUserInput, type RadioEvent, type RadioLevel, type ReplyInput, type SbResult$1 as SbResult, type SendEmailInput, type SendPushInput, type SendResult, type SendSmsInput, SignalbirdClient, type SignalbirdConfig, SignalbirdError, SignalbirdManagement, SignalbirdMessaging, SignalbirdPartner, type SmsPreview, type StartConversationInput, type TeamEmbedTokenInput, type UpdateConversationInput, type UpdateVisitorInput, type UptimeIncident, type UptimeRange, type UptimeReport, type VerifyDomainResult, management, resetManagement, resetSignalbird, signalbird, verifyWebhook };
1298
+ export { type AddDomainInput, type AddDomainResult, type AppDevice, type AppPlatform, type Batch, type BatchResult, type BulkContactsInput, type BulkContactsResult, type CampaignCreateResult, type CampaignDetail, type CannedReply, type CannedReplyInput, type Channel, type ChatConversation, type ChatMessage, type ChatVisitor, type Contact, type ContactInput, type ContactList, type ConversationStatus, type CreateCampaignInput, type CreateCompanyInput, type CreateCompanyResult, type CreateContactListInput, DEFAULT_BASE_URL, type DnsRecord, type EmailAttachment, type EmbedModule, type EmbedToken, type EmbedTokenInput, type GrantModuleInput, type Level, type ListAppDevicesQuery, type ListCampaignMessagesQuery, type ListCampaignsQuery, type ListChatMessagesQuery, type ListContactsQuery, type ListConversationsQuery, type ListMessagesQuery, type ListRadioEventsQuery, type LogInput, type LogResult, type ManagementConfig, type Message, type MessageClass, type MessagingConfig, type MessagingErrorCode, type ModuleEntitlement, type Paginated$1 as Paginated, type PartnerCompany, type PartnerConfig, type PartnerDomain, type PartnerOwnerInput, type PartnerUser, type PartnerUserInput, type RadioEvent, type RadioLevel, type ReplyInput, type SbResult$1 as SbResult, type SendEmailInput, type SendPushInput, type SendResult, type SendSmsInput, SignalbirdClient, type SignalbirdConfig, SignalbirdError, SignalbirdManagement, SignalbirdMessaging, SignalbirdPartner, type SmsPreview, type StartConversationInput, type TeamEmbedTokenInput, type UpdateConversationInput, type UpdateVisitorInput, type UptimeIncident, type UptimeRange, type UptimeReport, type VerifyDomainResult, management, resetManagement, resetSignalbird, signalbird, verifyWebhook };
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var SignalbirdError = class extends Error {
17
17
  var DEFAULT_BASE_URL = "https://live.signalbird.io/api";
18
18
 
19
19
  // src/shared/version.ts
20
- var SDK_VERSION = "2.8.1" ;
20
+ var SDK_VERSION = "2.9.0" ;
21
21
  var SDK_HEADER = "X-Signalbird-Sdk";
22
22
  function sdkHeaderValue(platform) {
23
23
  return `${platform}/${SDK_VERSION}`;
@@ -35,6 +35,70 @@ function noteSdkStatus(headers) {
35
35
  } catch {
36
36
  }
37
37
  }
38
+
39
+ // src/shared/serialize.ts
40
+ var MAX_MESSAGE_LENGTH = 4e3;
41
+ function truncateMessage(message) {
42
+ const text = typeof message === "string" ? message : String(message);
43
+ if (text.length <= MAX_MESSAGE_LENGTH) {
44
+ return text;
45
+ }
46
+ return Array.from(text).slice(0, MAX_MESSAGE_LENGTH).join("");
47
+ }
48
+ function toJsonSafe(value) {
49
+ const ancestors = [];
50
+ const walk = (current) => {
51
+ if (typeof current === "bigint") {
52
+ return current.toString();
53
+ }
54
+ if (current === null || typeof current !== "object") {
55
+ return current;
56
+ }
57
+ if (ancestors.includes(current)) {
58
+ return "[Circular]";
59
+ }
60
+ if (current instanceof Error) {
61
+ return { name: current.name, message: current.message, stack: current.stack };
62
+ }
63
+ const withToJson = current;
64
+ if (typeof withToJson.toJSON === "function") {
65
+ try {
66
+ ancestors.push(current);
67
+ return walk(withToJson.toJSON());
68
+ } catch {
69
+ return "[Unserializable]";
70
+ } finally {
71
+ ancestors.pop();
72
+ }
73
+ }
74
+ ancestors.push(current);
75
+ try {
76
+ if (Array.isArray(current)) {
77
+ return current.map((item) => walk(item));
78
+ }
79
+ const out = {};
80
+ for (const key of Object.keys(current)) {
81
+ let item;
82
+ try {
83
+ item = current[key];
84
+ } catch {
85
+ item = "[Unserializable]";
86
+ }
87
+ out[key] = walk(item);
88
+ }
89
+ return out;
90
+ } finally {
91
+ ancestors.pop();
92
+ }
93
+ };
94
+ return walk(value);
95
+ }
96
+ function safeContext(context) {
97
+ if (context === void 0 || context === null) {
98
+ return void 0;
99
+ }
100
+ return toJsonSafe(context);
101
+ }
38
102
  var SignalbirdClient = class {
39
103
  constructor(config) {
40
104
  this.config = config;
@@ -79,13 +143,19 @@ var SignalbirdClient = class {
79
143
  critical: (message, context) => this.critical(key, message, context)
80
144
  };
81
145
  }
82
- /** Tek kayıt gönderir. */
146
+ /**
147
+ * Tek kayıt gönderir.
148
+ *
149
+ * `message` 4000 kod noktasına kırpılır (API sınırı; aşan satır 422 alırdı)
150
+ * ve `context` güvenli kopyaya çevrilir: döngüsel nesne ya da BigInt artık
151
+ * `NETWORK_ERROR` gibi görünen bir istisnaya dönüşmez.
152
+ */
83
153
  async log(input) {
84
154
  return this.send("/v1/radio/log", {
85
155
  key: input.key,
86
- message: input.message,
156
+ message: truncateMessage(input.message),
87
157
  level: input.level,
88
- context: input.context,
158
+ context: safeContext(input.context),
89
159
  source: input.source ?? this.source
90
160
  });
91
161
  }
@@ -94,14 +164,17 @@ var SignalbirdClient = class {
94
164
  *
95
165
  * Kısmi başarı normaldir (kota tam ortada dolabilir), o yüzden sonuç tek bir
96
166
  * durum değil satır satır döner.
167
+ *
168
+ * Doğrulama ise satır satır DEĞİLDİR: tek bir geçersiz satır (4000'i aşan
169
+ * mesaj) bütün paketi 422 ile düşürür. Bu yüzden kırpma burada da yapılır.
97
170
  */
98
171
  async batch(events) {
99
172
  const payload = {
100
173
  events: events.slice(0, 100).map((event) => ({
101
174
  key: event.key,
102
- message: event.message,
175
+ message: truncateMessage(event.message),
103
176
  level: event.level,
104
- context: event.context,
177
+ context: safeContext(event.context),
105
178
  source: event.source ?? this.source
106
179
  }))
107
180
  };
@@ -188,7 +261,7 @@ var SignalbirdClient = class {
188
261
  if (!response) {
189
262
  return { ok: false, code: "NETWORK_ERROR" };
190
263
  }
191
- if (!response.ok) {
264
+ if (!response.ok || response.body?.ok === false) {
192
265
  const code = response.body?.code ?? "UNKNOWN";
193
266
  if (this.throwOnError) {
194
267
  throw new SignalbirdError(`Signalbird: ${code}`, response.status, code);
@@ -260,7 +333,11 @@ var SignalbirdMessaging = class {
260
333
  }
261
334
  // ── Gönderim ──────────────────────────────────────────────────────────
262
335
  sendEmail(input) {
263
- return this.request("POST", "/v1/email/send", input);
336
+ const { template_hash: _ignored, ...body } = input;
337
+ if (_ignored !== void 0 && this.debug) {
338
+ console.warn("[signalbird] sendEmail: template_hash kullan\u0131mdan kalkt\u0131 ve g\xF6nderilmiyor; template ya da template_id kullan\u0131n.");
339
+ }
340
+ return this.request("POST", "/v1/email/send", body);
264
341
  }
265
342
  sendSms(input) {
266
343
  return this.request("POST", "/v1/sms/send", input);