@open-apime/sdk 0.2.2 → 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/dist/index.cjs CHANGED
@@ -176,6 +176,18 @@ function errorFromResponse(status, body, headers) {
176
176
  }
177
177
  }
178
178
 
179
+ // src/http/dispatcher.ts
180
+ var import_node_dns = require("dns");
181
+ var applied;
182
+ function preferIpFamily(family) {
183
+ if (applied !== void 0) return;
184
+ try {
185
+ (0, import_node_dns.setDefaultResultOrder)(family === 4 ? "ipv4first" : "ipv6first");
186
+ applied = family;
187
+ } catch {
188
+ }
189
+ }
190
+
179
191
  // src/http/url.ts
180
192
  var BLOCKED_HOSTS = /* @__PURE__ */ new Set(["169.254.169.254", "metadata.google.internal"]);
181
193
  function assertUsableBaseUrl(raw) {
@@ -237,6 +249,7 @@ var HttpClient = class {
237
249
  this.auth = options.auth;
238
250
  this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
239
251
  this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
252
+ if (options.ipFamily) preferIpFamily(options.ipFamily);
240
253
  this.fetchImpl = options.fetch ?? globalThis.fetch;
241
254
  this.userAgent = options.appName ? `open-apime-sdk (${options.appName})` : "open-apime-sdk";
242
255
  this.observer = options.observer;
@@ -745,6 +758,7 @@ function toHttpOptions(auth, options) {
745
758
  ...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {},
746
759
  ...options.maxRetries !== void 0 ? { maxRetries: options.maxRetries } : {},
747
760
  ...options.fetch !== void 0 ? { fetch: options.fetch } : {},
761
+ ...options.ipFamily !== void 0 ? { ipFamily: options.ipFamily } : {},
748
762
  ...options.appName !== void 0 ? { appName: options.appName } : {},
749
763
  ...options.observer !== void 0 ? { observer: options.observer } : {},
750
764
  ...options.autoReport !== void 0 ? { autoReport: options.autoReport } : {}
package/dist/index.d.cts CHANGED
@@ -79,6 +79,8 @@ interface Observer {
79
79
  /** True when the app has an initialized Sentry. Absent means every report is a no-op. */
80
80
  declare function hasSentry(): boolean;
81
81
 
82
+ type IpFamily = 4 | 6;
83
+
82
84
  interface RequestOptions {
83
85
  timeoutMs?: number;
84
86
  maxRetries?: number;
@@ -97,6 +99,12 @@ interface HttpClientOptions {
97
99
  timeoutMs?: number;
98
100
  maxRetries?: number;
99
101
  fetch?: typeof globalThis.fetch;
102
+ /**
103
+ * Tries this IP family first when resolving the host. Use 4 when the apime
104
+ * answers AAAA but the network has no IPv6 route, so failed v6 attempts stop
105
+ * polluting the errors. Process-wide: Node offers no per-request knob.
106
+ */
107
+ ipFamily?: IpFamily;
100
108
  /** Appended to the User-Agent, to identify the calling app in the apime logs. */
101
109
  appName?: string;
102
110
  /** Where the app plugs its logger or error tracker. See Observer. */
@@ -461,6 +469,12 @@ interface ClientOptions {
461
469
  timeoutMs?: number;
462
470
  maxRetries?: number;
463
471
  fetch?: typeof globalThis.fetch;
472
+ /**
473
+ * Tries this IP family first when resolving the host. Use 4 when the apime
474
+ * answers AAAA but the network has no IPv6 route, so failed v6 attempts stop
475
+ * polluting the errors. Process-wide: Node offers no per-request knob.
476
+ */
477
+ ipFamily?: IpFamily;
464
478
  appName?: string;
465
479
  /**
466
480
  * Reports every request, failure and retry to the app's own logger or error
@@ -468,8 +482,8 @@ interface ClientOptions {
468
482
  */
469
483
  observer?: Observer;
470
484
  /**
471
- * Sem `observer`, a falha definitiva ainda vai para o Sentry que o app
472
- * roda, achado pelo cliente global. Sem Sentry, não faz nada. `false` cala.
485
+ * With no `observer`, definitive failures still reach the Sentry the app
486
+ * already runs, found through its global client. No Sentry means no-op.
473
487
  */
474
488
  autoReport?: boolean;
475
489
  }
@@ -509,4 +523,4 @@ declare const Apime: {
509
523
  }, options: ClientOptions): ApimeInstanceClient;
510
524
  };
511
525
 
512
- export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, Instance, InstanceInfo, type InstanceTokenAuth, type JoinRequestAction, type MarkReadInput, type Observer, type ParticipantAction, type PresenceState, Profile, QrCode, type QuoteInput, type RequestInfo, type RequestOptions, type SendAudioInput, type SendContactInput, type SendDocumentInput, type SendLocationInput, type SendMediaInput, type SendTextInput, SentMessage, type SuccessInfo, type UpdateInstanceInput, type User, type UserAuth, type UserJwtAuth, hasSentry };
526
+ export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, Instance, InstanceInfo, type InstanceTokenAuth, type IpFamily, type JoinRequestAction, type MarkReadInput, type Observer, type ParticipantAction, type PresenceState, Profile, QrCode, type QuoteInput, type RequestInfo, type RequestOptions, type SendAudioInput, type SendContactInput, type SendDocumentInput, type SendLocationInput, type SendMediaInput, type SendTextInput, SentMessage, type SuccessInfo, type UpdateInstanceInput, type User, type UserAuth, type UserJwtAuth, hasSentry };
package/dist/index.d.ts CHANGED
@@ -79,6 +79,8 @@ interface Observer {
79
79
  /** True when the app has an initialized Sentry. Absent means every report is a no-op. */
80
80
  declare function hasSentry(): boolean;
81
81
 
82
+ type IpFamily = 4 | 6;
83
+
82
84
  interface RequestOptions {
83
85
  timeoutMs?: number;
84
86
  maxRetries?: number;
@@ -97,6 +99,12 @@ interface HttpClientOptions {
97
99
  timeoutMs?: number;
98
100
  maxRetries?: number;
99
101
  fetch?: typeof globalThis.fetch;
102
+ /**
103
+ * Tries this IP family first when resolving the host. Use 4 when the apime
104
+ * answers AAAA but the network has no IPv6 route, so failed v6 attempts stop
105
+ * polluting the errors. Process-wide: Node offers no per-request knob.
106
+ */
107
+ ipFamily?: IpFamily;
100
108
  /** Appended to the User-Agent, to identify the calling app in the apime logs. */
101
109
  appName?: string;
102
110
  /** Where the app plugs its logger or error tracker. See Observer. */
@@ -461,6 +469,12 @@ interface ClientOptions {
461
469
  timeoutMs?: number;
462
470
  maxRetries?: number;
463
471
  fetch?: typeof globalThis.fetch;
472
+ /**
473
+ * Tries this IP family first when resolving the host. Use 4 when the apime
474
+ * answers AAAA but the network has no IPv6 route, so failed v6 attempts stop
475
+ * polluting the errors. Process-wide: Node offers no per-request knob.
476
+ */
477
+ ipFamily?: IpFamily;
464
478
  appName?: string;
465
479
  /**
466
480
  * Reports every request, failure and retry to the app's own logger or error
@@ -468,8 +482,8 @@ interface ClientOptions {
468
482
  */
469
483
  observer?: Observer;
470
484
  /**
471
- * Sem `observer`, a falha definitiva ainda vai para o Sentry que o app
472
- * roda, achado pelo cliente global. Sem Sentry, não faz nada. `false` cala.
485
+ * With no `observer`, definitive failures still reach the Sentry the app
486
+ * already runs, found through its global client. No Sentry means no-op.
473
487
  */
474
488
  autoReport?: boolean;
475
489
  }
@@ -509,4 +523,4 @@ declare const Apime: {
509
523
  }, options: ClientOptions): ApimeInstanceClient;
510
524
  };
511
525
 
512
- export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, Instance, InstanceInfo, type InstanceTokenAuth, type JoinRequestAction, type MarkReadInput, type Observer, type ParticipantAction, type PresenceState, Profile, QrCode, type QuoteInput, type RequestInfo, type RequestOptions, type SendAudioInput, type SendContactInput, type SendDocumentInput, type SendLocationInput, type SendMediaInput, type SendTextInput, SentMessage, type SuccessInfo, type UpdateInstanceInput, type User, type UserAuth, type UserJwtAuth, hasSentry };
526
+ export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, Instance, InstanceInfo, type InstanceTokenAuth, type IpFamily, type JoinRequestAction, type MarkReadInput, type Observer, type ParticipantAction, type PresenceState, Profile, QrCode, type QuoteInput, type RequestInfo, type RequestOptions, type SendAudioInput, type SendContactInput, type SendDocumentInput, type SendLocationInput, type SendMediaInput, type SendTextInput, SentMessage, type SuccessInfo, type UpdateInstanceInput, type User, type UserAuth, type UserJwtAuth, hasSentry };
package/dist/index.js CHANGED
@@ -107,6 +107,18 @@ function errorFromResponse(status, body, headers) {
107
107
  }
108
108
  }
109
109
 
110
+ // src/http/dispatcher.ts
111
+ import { setDefaultResultOrder } from "dns";
112
+ var applied;
113
+ function preferIpFamily(family) {
114
+ if (applied !== void 0) return;
115
+ try {
116
+ setDefaultResultOrder(family === 4 ? "ipv4first" : "ipv6first");
117
+ applied = family;
118
+ } catch {
119
+ }
120
+ }
121
+
110
122
  // src/http/url.ts
111
123
  var BLOCKED_HOSTS = /* @__PURE__ */ new Set(["169.254.169.254", "metadata.google.internal"]);
112
124
  function assertUsableBaseUrl(raw) {
@@ -168,6 +180,7 @@ var HttpClient = class {
168
180
  this.auth = options.auth;
169
181
  this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
170
182
  this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
183
+ if (options.ipFamily) preferIpFamily(options.ipFamily);
171
184
  this.fetchImpl = options.fetch ?? globalThis.fetch;
172
185
  this.userAgent = options.appName ? `open-apime-sdk (${options.appName})` : "open-apime-sdk";
173
186
  this.observer = options.observer;
@@ -676,6 +689,7 @@ function toHttpOptions(auth, options) {
676
689
  ...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {},
677
690
  ...options.maxRetries !== void 0 ? { maxRetries: options.maxRetries } : {},
678
691
  ...options.fetch !== void 0 ? { fetch: options.fetch } : {},
692
+ ...options.ipFamily !== void 0 ? { ipFamily: options.ipFamily } : {},
679
693
  ...options.appName !== void 0 ? { appName: options.appName } : {},
680
694
  ...options.observer !== void 0 ? { observer: options.observer } : {},
681
695
  ...options.autoReport !== void 0 ? { autoReport: options.autoReport } : {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-apime/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Cliente TypeScript da API do apime: WhatsApp, instâncias e webhooks",
5
5
  "license": "MIT",
6
6
  "repository": {