@niadra/sdk 0.9.0 → 0.9.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +40 -1
  3. package/dist/ai-sdk.d.cts +3 -3
  4. package/dist/ai-sdk.d.ts +3 -3
  5. package/dist/anthropic.d.cts +4 -4
  6. package/dist/anthropic.d.ts +4 -4
  7. package/dist/bedrock.d.cts +4 -4
  8. package/dist/bedrock.d.ts +4 -4
  9. package/dist/cli.js +51 -10
  10. package/dist/cli.js.map +1 -1
  11. package/dist/{client-B_ip8T2o.d.cts → client-CWMxmJHs.d.cts} +22 -14
  12. package/dist/{client-B_ip8T2o.d.ts → client-CWMxmJHs.d.ts} +22 -14
  13. package/dist/cloudflare-agents.d.cts +3 -3
  14. package/dist/cloudflare-agents.d.ts +3 -3
  15. package/dist/elevenlabs.d.cts +5 -5
  16. package/dist/elevenlabs.d.ts +5 -5
  17. package/dist/genkit.d.cts +3 -3
  18. package/dist/genkit.d.ts +3 -3
  19. package/dist/google-adk.d.cts +3 -3
  20. package/dist/google-adk.d.ts +3 -3
  21. package/dist/google-genai.d.cts +4 -4
  22. package/dist/google-genai.d.ts +4 -4
  23. package/dist/index.cjs +51 -10
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +51 -10
  28. package/dist/index.js.map +1 -1
  29. package/dist/{intercept-CBaPK_-k.d.ts → intercept-Bv0nLpSw.d.ts} +1 -1
  30. package/dist/{intercept-CxmBLfoj.d.cts → intercept-CGngQI8B.d.cts} +1 -1
  31. package/dist/langchain.d.cts +3 -3
  32. package/dist/langchain.d.ts +3 -3
  33. package/dist/livekit.d.cts +3 -3
  34. package/dist/livekit.d.ts +3 -3
  35. package/dist/llamaindex.d.cts +3 -3
  36. package/dist/llamaindex.d.ts +3 -3
  37. package/dist/mastra.d.cts +3 -3
  38. package/dist/mastra.d.ts +3 -3
  39. package/dist/openai-agents.d.cts +3 -3
  40. package/dist/openai-agents.d.ts +3 -3
  41. package/dist/retell.d.cts +5 -5
  42. package/dist/retell.d.ts +5 -5
  43. package/dist/{shared-BLkAbvuf.d.ts → shared-B4Ef2Wpg.d.ts} +1 -1
  44. package/dist/{shared-DEkF2Y_z.d.cts → shared-Cq8mz-7m.d.cts} +1 -1
  45. package/dist/strands.d.cts +3 -3
  46. package/dist/strands.d.ts +3 -3
  47. package/dist/twilio.d.cts +4 -4
  48. package/dist/twilio.d.ts +4 -4
  49. package/dist/vapi.d.cts +5 -5
  50. package/dist/vapi.d.ts +5 -5
  51. package/dist/voltagent.d.cts +3 -3
  52. package/dist/voltagent.d.ts +3 -3
  53. package/dist/{webhook-CuR0Wckd.d.cts → webhook-jTx_SegV.d.cts} +1 -1
  54. package/dist/{webhook-BaraTaA9.d.ts → webhook-z2TjUzjv.d.ts} +1 -1
  55. package/dist/whatsapp.d.cts +2 -2
  56. package/dist/whatsapp.d.ts +2 -2
  57. package/package.json +3 -2
@@ -1167,12 +1167,14 @@ interface OutcomeLink {
1167
1167
  /** The outcome definition of the `measurement` document. */
1168
1168
  outcome: string;
1169
1169
  position?: number | null;
1170
+ /** The purchase it counts in, when the revenue definition counts a split purchase's parts as one order. */
1171
+ purchase?: string | null;
1170
1172
  /** The state the object or its line is in. */
1171
1173
  state: string;
1172
1174
  turn_id?: string | null;
1173
1175
  /** When the outcome first counted. */
1174
1176
  valid_at: string;
1175
- /** In the currency's minor units; absent: none. */
1177
+ /** In the currency's minor units, as the signed revenue definition counts it; absent: none. */
1176
1178
  value_minor?: number | null;
1177
1179
  }
1178
1180
  interface OutcomePage {
@@ -1519,6 +1521,12 @@ interface DerivedState {
1519
1521
  logic: "yes" | "no" | "unobserved";
1520
1522
  /** The related objects it was computed over. */
1521
1523
  over: number;
1524
+ /**
1525
+ * When it is not `yes`, the related objects, as `type:namespace:id`, that kept it from `yes`: for `all` and
1526
+ * `any` the ones the condition does not hold for or that are not known, for `count`, `min` and `max` the
1527
+ * ones not known. In the relation's order, the first 10.
1528
+ */
1529
+ pieces_out?: string[];
1522
1530
  /**
1523
1531
  * How many of them were not known: out of the working set, not an exact match (`status_field`), or with the
1524
1532
  * data the condition reads not observed.
@@ -2668,6 +2676,19 @@ declare const TOOL_DEFINITIONS: readonly ToolDefinition[];
2668
2676
  */
2669
2677
  declare const AGENT_MEMORY_TOOL_DEFINITIONS: readonly ToolDefinition[];
2670
2678
 
2679
+ /**
2680
+ * Where the SDK reports what it swallowed in fail-open mode. Messages carry status codes,
2681
+ * error codes and request ids, never handles, message text or other personal data.
2682
+ */
2683
+ interface Logger {
2684
+ debug(message: string, ...details: unknown[]): void;
2685
+ warn(message: string, ...details: unknown[]): void;
2686
+ error(message: string, ...details: unknown[]): void;
2687
+ }
2688
+ /** Warnings and errors go to the console; debug output is off unless you pass your own logger. */
2689
+ declare const consoleLogger: Logger;
2690
+ declare const silentLogger: Logger;
2691
+
2671
2692
  /**
2672
2693
  * When a request may be sent again.
2673
2694
  *
@@ -3903,19 +3924,6 @@ declare class InternalText {
3903
3924
  private fingerprints;
3904
3925
  }
3905
3926
 
3906
- /**
3907
- * Where the SDK reports what it swallowed in fail-open mode. Messages carry status codes,
3908
- * error codes and request ids, never handles, message text or other personal data.
3909
- */
3910
- interface Logger {
3911
- debug(message: string, ...details: unknown[]): void;
3912
- warn(message: string, ...details: unknown[]): void;
3913
- error(message: string, ...details: unknown[]): void;
3914
- }
3915
- /** Warnings and errors go to the console; debug output is off unless you pass your own logger. */
3916
- declare const consoleLogger: Logger;
3917
- declare const silentLogger: Logger;
3918
-
3919
3927
  /**
3920
3928
  * Writes the agent's code made that must reach Niadra, sent in the background and in order: coordination
3921
3929
  * declarations, and agent state writes made while Niadra was out of reach.
@@ -1167,12 +1167,14 @@ interface OutcomeLink {
1167
1167
  /** The outcome definition of the `measurement` document. */
1168
1168
  outcome: string;
1169
1169
  position?: number | null;
1170
+ /** The purchase it counts in, when the revenue definition counts a split purchase's parts as one order. */
1171
+ purchase?: string | null;
1170
1172
  /** The state the object or its line is in. */
1171
1173
  state: string;
1172
1174
  turn_id?: string | null;
1173
1175
  /** When the outcome first counted. */
1174
1176
  valid_at: string;
1175
- /** In the currency's minor units; absent: none. */
1177
+ /** In the currency's minor units, as the signed revenue definition counts it; absent: none. */
1176
1178
  value_minor?: number | null;
1177
1179
  }
1178
1180
  interface OutcomePage {
@@ -1519,6 +1521,12 @@ interface DerivedState {
1519
1521
  logic: "yes" | "no" | "unobserved";
1520
1522
  /** The related objects it was computed over. */
1521
1523
  over: number;
1524
+ /**
1525
+ * When it is not `yes`, the related objects, as `type:namespace:id`, that kept it from `yes`: for `all` and
1526
+ * `any` the ones the condition does not hold for or that are not known, for `count`, `min` and `max` the
1527
+ * ones not known. In the relation's order, the first 10.
1528
+ */
1529
+ pieces_out?: string[];
1522
1530
  /**
1523
1531
  * How many of them were not known: out of the working set, not an exact match (`status_field`), or with the
1524
1532
  * data the condition reads not observed.
@@ -2668,6 +2676,19 @@ declare const TOOL_DEFINITIONS: readonly ToolDefinition[];
2668
2676
  */
2669
2677
  declare const AGENT_MEMORY_TOOL_DEFINITIONS: readonly ToolDefinition[];
2670
2678
 
2679
+ /**
2680
+ * Where the SDK reports what it swallowed in fail-open mode. Messages carry status codes,
2681
+ * error codes and request ids, never handles, message text or other personal data.
2682
+ */
2683
+ interface Logger {
2684
+ debug(message: string, ...details: unknown[]): void;
2685
+ warn(message: string, ...details: unknown[]): void;
2686
+ error(message: string, ...details: unknown[]): void;
2687
+ }
2688
+ /** Warnings and errors go to the console; debug output is off unless you pass your own logger. */
2689
+ declare const consoleLogger: Logger;
2690
+ declare const silentLogger: Logger;
2691
+
2671
2692
  /**
2672
2693
  * When a request may be sent again.
2673
2694
  *
@@ -3903,19 +3924,6 @@ declare class InternalText {
3903
3924
  private fingerprints;
3904
3925
  }
3905
3926
 
3906
- /**
3907
- * Where the SDK reports what it swallowed in fail-open mode. Messages carry status codes,
3908
- * error codes and request ids, never handles, message text or other personal data.
3909
- */
3910
- interface Logger {
3911
- debug(message: string, ...details: unknown[]): void;
3912
- warn(message: string, ...details: unknown[]): void;
3913
- error(message: string, ...details: unknown[]): void;
3914
- }
3915
- /** Warnings and errors go to the console; debug output is off unless you pass your own logger. */
3916
- declare const consoleLogger: Logger;
3917
- declare const silentLogger: Logger;
3918
-
3919
3927
  /**
3920
3928
  * Writes the agent's code made that must reach Niadra, sent in the background and in order: coordination
3921
3929
  * declarations, and agent state writes made while Niadra was out of reach.
@@ -1,8 +1,8 @@
1
1
  import { ToolSet } from 'ai';
2
- import { c as Niadra, g as Handle, fX as TurnOptions, f as ModelUsage } from './client-B_ip8T2o.cjs';
2
+ import { c as Niadra, g as Handle, fX as TurnOptions, f as ModelUsage } from './client-CWMxmJHs.cjs';
3
3
  import { NiadraMiddleware } from './ai-sdk.cjs';
4
- import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-DEkF2Y_z.cjs';
5
- export { P as Proof, c as attestationProof } from './shared-DEkF2Y_z.cjs';
4
+ import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-Cq8mz-7m.cjs';
5
+ export { P as Proof, c as attestationProof } from './shared-Cq8mz-7m.cjs';
6
6
 
7
7
  /**
8
8
  * Niadra for the Cloudflare Agents SDK (`agents` 0.x): one helper per `Agent` instance (a Durable
@@ -1,8 +1,8 @@
1
1
  import { ToolSet } from 'ai';
2
- import { c as Niadra, g as Handle, fX as TurnOptions, f as ModelUsage } from './client-B_ip8T2o.js';
2
+ import { c as Niadra, g as Handle, fX as TurnOptions, f as ModelUsage } from './client-CWMxmJHs.js';
3
3
  import { NiadraMiddleware } from './ai-sdk.js';
4
- import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-BLkAbvuf.js';
5
- export { P as Proof, c as attestationProof } from './shared-BLkAbvuf.js';
4
+ import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-B4Ef2Wpg.js';
5
+ export { P as Proof, c as attestationProof } from './shared-B4Ef2Wpg.js';
6
6
 
7
7
  /**
8
8
  * Niadra for the Cloudflare Agents SDK (`agents` 0.x): one helper per `Agent` instance (a Durable
@@ -1,8 +1,8 @@
1
- import { c as Niadra, g as Handle } from './client-B_ip8T2o.cjs';
2
- import { P as Proof, A as AgentMemoryOption } from './shared-DEkF2Y_z.cjs';
3
- export { c as attestationProof } from './shared-DEkF2Y_z.cjs';
4
- import { H as HeadersLike, W as WebhookResponse, C as CallStore } from './webhook-CuR0Wckd.cjs';
5
- export { a as CallRecord, m as memoryCallStore } from './webhook-CuR0Wckd.cjs';
1
+ import { c as Niadra, g as Handle } from './client-CWMxmJHs.cjs';
2
+ import { P as Proof, A as AgentMemoryOption } from './shared-Cq8mz-7m.cjs';
3
+ export { c as attestationProof } from './shared-Cq8mz-7m.cjs';
4
+ import { H as HeadersLike, W as WebhookResponse, C as CallStore } from './webhook-jTx_SegV.cjs';
5
+ export { a as CallRecord, m as memoryCallStore } from './webhook-jTx_SegV.cjs';
6
6
 
7
7
  /**
8
8
  * Niadra for the ElevenLabs Agents Platform, on the server side: a phone call reaches ElevenLabs,
@@ -1,8 +1,8 @@
1
- import { c as Niadra, g as Handle } from './client-B_ip8T2o.js';
2
- import { P as Proof, A as AgentMemoryOption } from './shared-BLkAbvuf.js';
3
- export { c as attestationProof } from './shared-BLkAbvuf.js';
4
- import { H as HeadersLike, W as WebhookResponse, C as CallStore } from './webhook-BaraTaA9.js';
5
- export { a as CallRecord, m as memoryCallStore } from './webhook-BaraTaA9.js';
1
+ import { c as Niadra, g as Handle } from './client-CWMxmJHs.js';
2
+ import { P as Proof, A as AgentMemoryOption } from './shared-B4Ef2Wpg.js';
3
+ export { c as attestationProof } from './shared-B4Ef2Wpg.js';
4
+ import { H as HeadersLike, W as WebhookResponse, C as CallStore } from './webhook-z2TjUzjv.js';
5
+ export { a as CallRecord, m as memoryCallStore } from './webhook-z2TjUzjv.js';
6
6
 
7
7
  /**
8
8
  * Niadra for the ElevenLabs Agents Platform, on the server side: a phone call reaches ElevenLabs,
package/dist/genkit.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ModelMiddleware } from 'genkit/model';
2
2
  import { ToolAction } from 'genkit/tool';
3
- import { f as ModelUsage } from './client-B_ip8T2o.cjs';
4
- import { a as ProofSource, A as AgentMemoryOption, S as SessionResolver, b as Session } from './shared-DEkF2Y_z.cjs';
5
- export { P as Proof, c as attestationProof } from './shared-DEkF2Y_z.cjs';
3
+ import { f as ModelUsage } from './client-CWMxmJHs.cjs';
4
+ import { a as ProofSource, A as AgentMemoryOption, S as SessionResolver, b as Session } from './shared-Cq8mz-7m.cjs';
5
+ export { P as Proof, c as attestationProof } from './shared-Cq8mz-7m.cjs';
6
6
 
7
7
  /**
8
8
  * Niadra for Genkit (`genkit` 1.x, Firebase Genkit for JavaScript): a model middleware for
package/dist/genkit.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ModelMiddleware } from 'genkit/model';
2
2
  import { ToolAction } from 'genkit/tool';
3
- import { f as ModelUsage } from './client-B_ip8T2o.js';
4
- import { a as ProofSource, A as AgentMemoryOption, S as SessionResolver, b as Session } from './shared-BLkAbvuf.js';
5
- export { P as Proof, c as attestationProof } from './shared-BLkAbvuf.js';
3
+ import { f as ModelUsage } from './client-CWMxmJHs.js';
4
+ import { a as ProofSource, A as AgentMemoryOption, S as SessionResolver, b as Session } from './shared-B4Ef2Wpg.js';
5
+ export { P as Proof, c as attestationProof } from './shared-B4Ef2Wpg.js';
6
6
 
7
7
  /**
8
8
  * Niadra for Genkit (`genkit` 1.x, Firebase Genkit for JavaScript): a model middleware for
@@ -1,7 +1,7 @@
1
1
  import { Context, LlmRequest, LlmResponse, BaseTool, ReadonlyContext } from '@google/adk';
2
- import { f as ModelUsage } from './client-B_ip8T2o.cjs';
3
- import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-DEkF2Y_z.cjs';
4
- export { P as Proof, c as attestationProof } from './shared-DEkF2Y_z.cjs';
2
+ import { f as ModelUsage } from './client-CWMxmJHs.cjs';
3
+ import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-Cq8mz-7m.cjs';
4
+ export { P as Proof, c as attestationProof } from './shared-Cq8mz-7m.cjs';
5
5
 
6
6
  /**
7
7
  * Niadra for the Agent Development Kit for TypeScript (`@google/adk` 2.x): model callbacks and the
@@ -1,7 +1,7 @@
1
1
  import { Context, LlmRequest, LlmResponse, BaseTool, ReadonlyContext } from '@google/adk';
2
- import { f as ModelUsage } from './client-B_ip8T2o.js';
3
- import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-BLkAbvuf.js';
4
- export { P as Proof, c as attestationProof } from './shared-BLkAbvuf.js';
2
+ import { f as ModelUsage } from './client-CWMxmJHs.js';
3
+ import { b as Session, a as ProofSource, A as AgentMemoryOption } from './shared-B4Ef2Wpg.js';
4
+ export { P as Proof, c as attestationProof } from './shared-B4Ef2Wpg.js';
5
5
 
6
6
  /**
7
7
  * Niadra for the Agent Development Kit for TypeScript (`@google/adk` 2.x): model callbacks and the
@@ -1,7 +1,7 @@
1
- import { f as ModelUsage } from './client-B_ip8T2o.cjs';
2
- import { W as WrapOptions } from './intercept-CxmBLfoj.cjs';
3
- import { S as SessionResolver } from './shared-DEkF2Y_z.cjs';
4
- export { A as AgentMemoryOption, P as Proof, a as ProofSource, b as Session, c as attestationProof } from './shared-DEkF2Y_z.cjs';
1
+ import { f as ModelUsage } from './client-CWMxmJHs.cjs';
2
+ import { W as WrapOptions } from './intercept-CGngQI8B.cjs';
3
+ import { S as SessionResolver } from './shared-Cq8mz-7m.cjs';
4
+ export { A as AgentMemoryOption, P as Proof, a as ProofSource, b as Session, c as attestationProof } from './shared-Cq8mz-7m.cjs';
5
5
 
6
6
  /**
7
7
  * Niadra for the Google Gen AI SDK (`@google/genai`), as `wrap()` is for OpenAI.
@@ -1,7 +1,7 @@
1
- import { f as ModelUsage } from './client-B_ip8T2o.js';
2
- import { W as WrapOptions } from './intercept-CBaPK_-k.js';
3
- import { S as SessionResolver } from './shared-BLkAbvuf.js';
4
- export { A as AgentMemoryOption, P as Proof, a as ProofSource, b as Session, c as attestationProof } from './shared-BLkAbvuf.js';
1
+ import { f as ModelUsage } from './client-CWMxmJHs.js';
2
+ import { W as WrapOptions } from './intercept-Bv0nLpSw.js';
3
+ import { S as SessionResolver } from './shared-B4Ef2Wpg.js';
4
+ export { A as AgentMemoryOption, P as Proof, a as ProofSource, b as Session, c as attestationProof } from './shared-B4Ef2Wpg.js';
5
5
 
6
6
  /**
7
7
  * Niadra for the Google Gen AI SDK (`@google/genai`), as `wrap()` is for OpenAI.
package/dist/index.cjs CHANGED
@@ -518,7 +518,7 @@ function internalRecord(span, ref, act) {
518
518
  }
519
519
 
520
520
  // src/version.ts
521
- var VERSION = "0.9.0";
521
+ var VERSION = "0.9.1";
522
522
 
523
523
  // src/transport.ts
524
524
  var RETRYABLE_WRITE_STATUS = /* @__PURE__ */ new Set([408, 421, 429, 500, 502, 503, 504]);
@@ -612,6 +612,7 @@ var Transport = class {
612
612
  } catch (error) {
613
613
  throw deadline.explain(error);
614
614
  }
615
+ warnIfDeprecated(this.config.logger, init.method ?? "GET", url, response.headers);
615
616
  const requestId = response.headers.get("x-request-id");
616
617
  let payload;
617
618
  try {
@@ -681,6 +682,29 @@ var Deadline = class {
681
682
  return new NiadraConnectionError(`connection failed: ${message}`, { cause: error });
682
683
  }
683
684
  };
685
+ var VERSIONING_DOCS = "https://docs.niadra.com/en/security/api-versioning";
686
+ var DEPRECATION_LINK = /<([^>]*)>[^,]*;\s*rel="?deprecation"?/gi;
687
+ var deprecationsSeen = /* @__PURE__ */ new Set();
688
+ function warnIfDeprecated(logger, method, url, headers) {
689
+ const since = headers.get("deprecation");
690
+ if (since === null) return;
691
+ const links = [...(headers.get("link") ?? "").matchAll(DEPRECATION_LINK)].map((match) => match[1] ?? "");
692
+ const key2 = `${method} ${links.join(" ") || (url.split("?")[0] ?? url)}`;
693
+ if (deprecationsSeen.has(key2)) return;
694
+ deprecationsSeen.add(key2);
695
+ const sunset = headers.get("sunset");
696
+ logger.warn(
697
+ `the API deprecated a ${method} route this client calls, since ${deprecatedSince(since)}; it stops answering on ${sunset === null ? "a date not announced yet" : sunsetDay(sunset)}. See ${links.join(", ") || VERSIONING_DOCS}`
698
+ );
699
+ }
700
+ function deprecatedSince(value) {
701
+ const seconds = Number(value.trim().replace(/^@/, ""));
702
+ return Number.isInteger(seconds) ? new Date(seconds * 1e3).toISOString().slice(0, 10) : value;
703
+ }
704
+ function sunsetDay(value) {
705
+ const time = Date.parse(value);
706
+ return Number.isNaN(time) ? value : new Date(time).toISOString().slice(0, 10);
707
+ }
684
708
  async function readBody(response) {
685
709
  const text2 = await response.text();
686
710
  if (text2.length === 0) return null;
@@ -4395,26 +4419,42 @@ async function suppressionKey(salt, canonical2) {
4395
4419
  const key2 = await subtle.importKey("raw", saltBytes(salt), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
4396
4420
  return toBase64url(new Uint8Array(await subtle.sign("HMAC", key2, new TextEncoder().encode(canonical2))));
4397
4421
  }
4422
+ var AREA_CODES = new Set(
4423
+ "11 12 13 14 15 16 17 18 19 21 22 24 27 28 31 32 33 34 35 37 38 41 42 43 44 45 46 47 48 49 51 53 54 55 61 62 63 64 65 66 67 68 69 71 73 74 75 77 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99".split(" ")
4424
+ );
4425
+ var FORMAT_CHARACTERS = /\p{Cf}/gu;
4398
4426
  function phone(value) {
4399
- const raw = value.trim().replace(SEPARATORS2, "");
4400
- const international = raw.startsWith("+") || raw.startsWith("00");
4427
+ let text2 = value.normalize("NFKC").replace(FORMAT_CHARACTERS, "").trim();
4428
+ if (text2.slice(0, 4).toLowerCase() === "tel:") text2 = text2.slice(4);
4429
+ const international = text2.startsWith("+") || text2.startsWith("00");
4430
+ if (international) text2 = text2.replaceAll("(0)", "");
4431
+ const raw = text2.replace(SEPARATORS2, "");
4401
4432
  let digits = raw.startsWith("+") ? raw.slice(1) : international ? raw.slice(2) : raw;
4402
4433
  if (!DIGITS2.test(digits)) throw new NiadraDestinationError("invalid_handle");
4403
- const national = digits.replace(/^0+/, "");
4404
- if (!international && (national.length === 10 || national.length === 11) && isArea(national.slice(0, 2))) {
4405
- digits = `55${national}`;
4434
+ if (!international) {
4435
+ const national = digits.replace(/^0+/, "");
4436
+ if (isBrazilianNational(national)) {
4437
+ digits = `55${national}`;
4438
+ } else if (digits.startsWith("0") && (national.length === 12 || national.length === 13)) {
4439
+ if (isBrazilianNational(national.slice(2))) digits = `55${national.slice(2)}`;
4440
+ }
4406
4441
  }
4407
4442
  if (digits.length < 8 || digits.length > 15 || digits.startsWith("0")) {
4408
4443
  throw new NiadraDestinationError("invalid_handle");
4409
4444
  }
4410
4445
  const rest = digits.slice(2);
4411
- if (digits.startsWith("55") && rest.length === 10 && isArea(rest.slice(0, 2)) && "6789".includes(rest.charAt(2))) {
4446
+ if (digits.startsWith("55") && rest.length === 10 && AREA_CODES.has(rest.slice(0, 2)) && "6789".includes(rest.charAt(2))) {
4412
4447
  digits = `55${rest.slice(0, 2)}9${rest.slice(2)}`;
4413
4448
  }
4449
+ if (digits.length === 13 && (digits.startsWith("521") || digits.startsWith("549"))) {
4450
+ digits = digits.slice(0, 2) + digits.slice(3);
4451
+ }
4414
4452
  return `phone:+${digits}`;
4415
4453
  }
4416
- function isArea(code) {
4417
- return /^[1-9]{2}$/.test(code);
4454
+ function isBrazilianNational(national) {
4455
+ if (!AREA_CODES.has(national.slice(0, 2))) return false;
4456
+ if (national.length === 10) return "23456789".includes(national.charAt(2));
4457
+ return national.length === 11 && national.charAt(2) === "9";
4418
4458
  }
4419
4459
  function saltBytes(salt) {
4420
4460
  const bytes = fromBase64url(salt);
@@ -8505,7 +8545,8 @@ var Niadra = class _Niadra {
8505
8545
  baseURL,
8506
8546
  apiKey,
8507
8547
  fetch: fetchImpl,
8508
- defaultHeaders: options.defaultHeaders ?? {}
8548
+ defaultHeaders: options.defaultHeaders ?? {},
8549
+ logger: this.logger
8509
8550
  });
8510
8551
  const queueOptions = { ...DEFAULT_QUEUE, ...options.queue };
8511
8552
  queueOptions.maxBatchSize = Math.min(queueOptions.maxBatchSize, 499);