@open-apime/sdk 0.3.1 → 0.4.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 +29 -0
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +27 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
ConfigurationError: () => ConfigurationError,
|
|
30
30
|
ConflictError: () => ConflictError,
|
|
31
31
|
ConnectionError: () => ConnectionError,
|
|
32
|
+
DEFAULT_HEALTH_TIMEOUT_MS: () => DEFAULT_HEALTH_TIMEOUT_MS,
|
|
32
33
|
InvalidRequestError: () => InvalidRequestError,
|
|
33
34
|
InvalidSignatureError: () => InvalidSignatureError,
|
|
34
35
|
NotFoundError: () => NotFoundError,
|
|
@@ -37,6 +38,7 @@ __export(index_exports, {
|
|
|
37
38
|
SessionUnavailableError: () => SessionUnavailableError,
|
|
38
39
|
TimeoutError: () => TimeoutError,
|
|
39
40
|
UnprocessableError: () => UnprocessableError,
|
|
41
|
+
checkHealth: () => checkHealth,
|
|
40
42
|
constructEvent: () => constructEvent,
|
|
41
43
|
hasSentry: () => hasSentry,
|
|
42
44
|
verifyWebhookSignature: () => verifyWebhookSignature
|
|
@@ -785,6 +787,31 @@ var Apime = {
|
|
|
785
787
|
}
|
|
786
788
|
};
|
|
787
789
|
|
|
790
|
+
// src/health.ts
|
|
791
|
+
var DEFAULT_HEALTH_TIMEOUT_MS = 1e4;
|
|
792
|
+
async function checkHealth(baseUrl, options = {}) {
|
|
793
|
+
const url = buildUrl(assertUsableBaseUrl(baseUrl), "/healthz");
|
|
794
|
+
const impl = options.fetch ?? globalThis.fetch;
|
|
795
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_HEALTH_TIMEOUT_MS;
|
|
796
|
+
const controller = new AbortController();
|
|
797
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
798
|
+
try {
|
|
799
|
+
const response = await impl(url, { method: "GET", signal: controller.signal });
|
|
800
|
+
if (!response.ok) {
|
|
801
|
+
throw new ApimeError(`apime respondeu ${response.status} no healthz`, { status: response.status });
|
|
802
|
+
}
|
|
803
|
+
return await response.json();
|
|
804
|
+
} catch (cause) {
|
|
805
|
+
if (cause instanceof ApimeError) throw cause;
|
|
806
|
+
if (controller.signal.aborted) {
|
|
807
|
+
throw new TimeoutError(`o healthz passou de ${timeoutMs}ms`, { cause });
|
|
808
|
+
}
|
|
809
|
+
throw new ConnectionError("falha de rede ao falar com o apime", { cause });
|
|
810
|
+
} finally {
|
|
811
|
+
clearTimeout(timer);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
788
815
|
// src/webhook/index.ts
|
|
789
816
|
var import_node_crypto = require("crypto");
|
|
790
817
|
var InvalidSignatureError = class extends ApimeError {
|
|
@@ -822,6 +849,7 @@ function constructEvent(rawBody, signature, secret) {
|
|
|
822
849
|
ConfigurationError,
|
|
823
850
|
ConflictError,
|
|
824
851
|
ConnectionError,
|
|
852
|
+
DEFAULT_HEALTH_TIMEOUT_MS,
|
|
825
853
|
InvalidRequestError,
|
|
826
854
|
InvalidSignatureError,
|
|
827
855
|
NotFoundError,
|
|
@@ -830,6 +858,7 @@ function constructEvent(rawBody, signature, secret) {
|
|
|
830
858
|
SessionUnavailableError,
|
|
831
859
|
TimeoutError,
|
|
832
860
|
UnprocessableError,
|
|
861
|
+
checkHealth,
|
|
833
862
|
constructEvent,
|
|
834
863
|
hasSentry,
|
|
835
864
|
verifyWebhookSignature
|
package/dist/index.d.cts
CHANGED
|
@@ -523,4 +523,16 @@ declare const Apime: {
|
|
|
523
523
|
}, options: ClientOptions): ApimeInstanceClient;
|
|
524
524
|
};
|
|
525
525
|
|
|
526
|
-
|
|
526
|
+
interface HealthOptions {
|
|
527
|
+
/** Kept short on purpose: a health check that hangs is worse than one that fails. */
|
|
528
|
+
timeoutMs?: number;
|
|
529
|
+
fetch?: typeof globalThis.fetch;
|
|
530
|
+
}
|
|
531
|
+
interface HealthResult {
|
|
532
|
+
status?: string;
|
|
533
|
+
[key: string]: unknown;
|
|
534
|
+
}
|
|
535
|
+
declare const DEFAULT_HEALTH_TIMEOUT_MS = 10000;
|
|
536
|
+
declare function checkHealth(baseUrl: string, options?: HealthOptions): Promise<HealthResult>;
|
|
537
|
+
|
|
538
|
+
export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, DEFAULT_HEALTH_TIMEOUT_MS, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, type HealthOptions, type HealthResult, 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, checkHealth, hasSentry };
|
package/dist/index.d.ts
CHANGED
|
@@ -523,4 +523,16 @@ declare const Apime: {
|
|
|
523
523
|
}, options: ClientOptions): ApimeInstanceClient;
|
|
524
524
|
};
|
|
525
525
|
|
|
526
|
-
|
|
526
|
+
interface HealthOptions {
|
|
527
|
+
/** Kept short on purpose: a health check that hangs is worse than one that fails. */
|
|
528
|
+
timeoutMs?: number;
|
|
529
|
+
fetch?: typeof globalThis.fetch;
|
|
530
|
+
}
|
|
531
|
+
interface HealthResult {
|
|
532
|
+
status?: string;
|
|
533
|
+
[key: string]: unknown;
|
|
534
|
+
}
|
|
535
|
+
declare const DEFAULT_HEALTH_TIMEOUT_MS = 10000;
|
|
536
|
+
declare function checkHealth(baseUrl: string, options?: HealthOptions): Promise<HealthResult>;
|
|
537
|
+
|
|
538
|
+
export { type ApiToken, type ApiTokenAuth, Apime, ApimeError, ApimeInstanceClient, ApimeUserClient, type Auth, type AuthKind, type CheckNumberResult, type ClientOptions, type ContactEntry, type CreateInstanceInput, DEFAULT_HEALTH_TIMEOUT_MS, EventLogEntry, type FailureInfo, type GroupInfo, type GroupParticipant, type HealthOptions, type HealthResult, 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, checkHealth, hasSentry };
|
package/dist/index.js
CHANGED
|
@@ -715,6 +715,31 @@ var Apime = {
|
|
|
715
715
|
);
|
|
716
716
|
}
|
|
717
717
|
};
|
|
718
|
+
|
|
719
|
+
// src/health.ts
|
|
720
|
+
var DEFAULT_HEALTH_TIMEOUT_MS = 1e4;
|
|
721
|
+
async function checkHealth(baseUrl, options = {}) {
|
|
722
|
+
const url = buildUrl(assertUsableBaseUrl(baseUrl), "/healthz");
|
|
723
|
+
const impl = options.fetch ?? globalThis.fetch;
|
|
724
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_HEALTH_TIMEOUT_MS;
|
|
725
|
+
const controller = new AbortController();
|
|
726
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
727
|
+
try {
|
|
728
|
+
const response = await impl(url, { method: "GET", signal: controller.signal });
|
|
729
|
+
if (!response.ok) {
|
|
730
|
+
throw new ApimeError(`apime respondeu ${response.status} no healthz`, { status: response.status });
|
|
731
|
+
}
|
|
732
|
+
return await response.json();
|
|
733
|
+
} catch (cause) {
|
|
734
|
+
if (cause instanceof ApimeError) throw cause;
|
|
735
|
+
if (controller.signal.aborted) {
|
|
736
|
+
throw new TimeoutError(`o healthz passou de ${timeoutMs}ms`, { cause });
|
|
737
|
+
}
|
|
738
|
+
throw new ConnectionError("falha de rede ao falar com o apime", { cause });
|
|
739
|
+
} finally {
|
|
740
|
+
clearTimeout(timer);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
718
743
|
export {
|
|
719
744
|
ApiError,
|
|
720
745
|
Apime,
|
|
@@ -725,6 +750,7 @@ export {
|
|
|
725
750
|
ConfigurationError,
|
|
726
751
|
ConflictError,
|
|
727
752
|
ConnectionError,
|
|
753
|
+
DEFAULT_HEALTH_TIMEOUT_MS,
|
|
728
754
|
InvalidRequestError,
|
|
729
755
|
InvalidSignatureError,
|
|
730
756
|
NotFoundError,
|
|
@@ -733,6 +759,7 @@ export {
|
|
|
733
759
|
SessionUnavailableError,
|
|
734
760
|
TimeoutError,
|
|
735
761
|
UnprocessableError,
|
|
762
|
+
checkHealth,
|
|
736
763
|
constructEvent,
|
|
737
764
|
hasSentry,
|
|
738
765
|
verifyWebhookSignature
|