@spoketech/hub-client 0.1.6 → 0.1.8
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/README.md +50 -7
- package/dist/index.d.ts +144 -121
- package/dist/index.js +123 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/spoke-hub-client/SKILL.md +2 -0
- package/skills/spoke-hub-client/references/workflows.md +22 -4
package/dist/index.js
CHANGED
|
@@ -3711,6 +3711,32 @@ var HubApi = HttpApi.make("hub").add(authGroup).add(organizationsGroup).add(memb
|
|
|
3711
3711
|
);
|
|
3712
3712
|
|
|
3713
3713
|
// src/client.ts
|
|
3714
|
+
var SpokeHubClientError = class extends Error {
|
|
3715
|
+
kind;
|
|
3716
|
+
code;
|
|
3717
|
+
body;
|
|
3718
|
+
cause;
|
|
3719
|
+
constructor(input) {
|
|
3720
|
+
super(input.message);
|
|
3721
|
+
this.name = "SpokeHubClientError";
|
|
3722
|
+
this.kind = input.kind;
|
|
3723
|
+
this.code = input.code;
|
|
3724
|
+
this.body = input.body;
|
|
3725
|
+
this.cause = input.cause;
|
|
3726
|
+
}
|
|
3727
|
+
};
|
|
3728
|
+
var SpokeHubApiError = class extends SpokeHubClientError {
|
|
3729
|
+
constructor(body, cause) {
|
|
3730
|
+
super({
|
|
3731
|
+
kind: "api",
|
|
3732
|
+
message: body.message ?? body.code ?? "Spoke Hub API request failed",
|
|
3733
|
+
code: body.code,
|
|
3734
|
+
body,
|
|
3735
|
+
cause
|
|
3736
|
+
});
|
|
3737
|
+
this.name = "SpokeHubApiError";
|
|
3738
|
+
}
|
|
3739
|
+
};
|
|
3714
3740
|
var defaultApiBasePath = "/api";
|
|
3715
3741
|
function trimSlashes(value) {
|
|
3716
3742
|
return value.replace(/^\/+|\/+$/g, "");
|
|
@@ -3803,6 +3829,82 @@ function configureSignedHttpClient(client, options) {
|
|
|
3803
3829
|
})
|
|
3804
3830
|
);
|
|
3805
3831
|
}
|
|
3832
|
+
function hasApiErrorBody(value) {
|
|
3833
|
+
if (value instanceof Error) {
|
|
3834
|
+
return false;
|
|
3835
|
+
}
|
|
3836
|
+
const body = value;
|
|
3837
|
+
return !!value && typeof value === "object" && (typeof body.message === "string" || typeof body.code === "string");
|
|
3838
|
+
}
|
|
3839
|
+
function apiErrorBodyFromUnknown(value) {
|
|
3840
|
+
if (hasApiErrorBody(value)) {
|
|
3841
|
+
return value;
|
|
3842
|
+
}
|
|
3843
|
+
if (value instanceof Error) {
|
|
3844
|
+
const cause = value.cause;
|
|
3845
|
+
if (hasApiErrorBody(cause)) {
|
|
3846
|
+
return cause;
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
if (value && typeof value === "object") {
|
|
3850
|
+
const cause = value.cause;
|
|
3851
|
+
if (hasApiErrorBody(cause)) {
|
|
3852
|
+
return cause;
|
|
3853
|
+
}
|
|
3854
|
+
const fiberFailureCause = value[/* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause")];
|
|
3855
|
+
if (fiberFailureCause && typeof fiberFailureCause === "object") {
|
|
3856
|
+
const error = fiberFailureCause.error;
|
|
3857
|
+
if (hasApiErrorBody(error)) {
|
|
3858
|
+
return error;
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
return null;
|
|
3863
|
+
}
|
|
3864
|
+
function errorMessageFromUnknown(value) {
|
|
3865
|
+
if (value instanceof Error && value.message.length > 0) {
|
|
3866
|
+
return value.message;
|
|
3867
|
+
}
|
|
3868
|
+
if (typeof value === "string" && value.length > 0) {
|
|
3869
|
+
return value;
|
|
3870
|
+
}
|
|
3871
|
+
return "Spoke Hub client request failed";
|
|
3872
|
+
}
|
|
3873
|
+
function classifyClientError(value) {
|
|
3874
|
+
const message = errorMessageFromUnknown(value).toLowerCase();
|
|
3875
|
+
if (value instanceof TypeError || message.includes("fetch failed") || message.includes("network") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("etimedout")) {
|
|
3876
|
+
return "network";
|
|
3877
|
+
}
|
|
3878
|
+
if (message.includes("private key") || message.includes("asn1") || message.includes("key object") || message.includes("decoder")) {
|
|
3879
|
+
return "client";
|
|
3880
|
+
}
|
|
3881
|
+
return "unknown";
|
|
3882
|
+
}
|
|
3883
|
+
function clientErrorFromUnknown(value) {
|
|
3884
|
+
const body = apiErrorBodyFromUnknown(value);
|
|
3885
|
+
if (body) {
|
|
3886
|
+
return new SpokeHubApiError(body, value);
|
|
3887
|
+
}
|
|
3888
|
+
return new SpokeHubClientError({
|
|
3889
|
+
kind: classifyClientError(value),
|
|
3890
|
+
message: errorMessageFromUnknown(value),
|
|
3891
|
+
cause: value
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
async function runPromise2(effect) {
|
|
3895
|
+
try {
|
|
3896
|
+
return [await Effect.runPromise(effect), null];
|
|
3897
|
+
} catch (error) {
|
|
3898
|
+
return [null, clientErrorFromUnknown(error)];
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
async function runPromiseUnsafe(effect) {
|
|
3902
|
+
const [data, error] = await runPromise2(effect);
|
|
3903
|
+
if (error !== null) {
|
|
3904
|
+
throw error;
|
|
3905
|
+
}
|
|
3906
|
+
return data;
|
|
3907
|
+
}
|
|
3806
3908
|
function resolveHubApiBaseUrl(baseUrl, apiBasePath = defaultApiBasePath) {
|
|
3807
3909
|
const resolved = new URL(baseUrl.toString());
|
|
3808
3910
|
resolved.pathname = joinUrlPath(resolved.pathname, apiBasePath);
|
|
@@ -3838,7 +3940,7 @@ function toPromiseClient(value) {
|
|
|
3838
3940
|
if (typeof member === "function") {
|
|
3839
3941
|
return [
|
|
3840
3942
|
key,
|
|
3841
|
-
(...args) =>
|
|
3943
|
+
(...args) => runPromise2(
|
|
3842
3944
|
member(
|
|
3843
3945
|
...args
|
|
3844
3946
|
)
|
|
@@ -3852,23 +3954,29 @@ function toPromiseClient(value) {
|
|
|
3852
3954
|
});
|
|
3853
3955
|
return Object.fromEntries(entries);
|
|
3854
3956
|
}
|
|
3855
|
-
var makePromiseHubApiClient = async (options) => toPromiseClient(await
|
|
3957
|
+
var makePromiseHubApiClient = async (options) => toPromiseClient(await runPromiseUnsafe(makeHubApiClient(options)));
|
|
3856
3958
|
var makePromiseServiceHubApiClient = async (options) => {
|
|
3857
|
-
const { client } = await
|
|
3959
|
+
const { client } = await runPromiseUnsafe(makeServiceHubApiClient(options));
|
|
3858
3960
|
return {
|
|
3859
3961
|
client: toPromiseClient(client)
|
|
3860
3962
|
};
|
|
3861
3963
|
};
|
|
3862
3964
|
|
|
3863
3965
|
// src/onsite-resource-client.ts
|
|
3966
|
+
function unwrapMaybeResult(result) {
|
|
3967
|
+
return Array.isArray(result) && result.length === 2 ? result[0] : result;
|
|
3968
|
+
}
|
|
3864
3969
|
function makeOnsiteResourceClient(client) {
|
|
3865
3970
|
const call = async (input) => {
|
|
3866
3971
|
const { organizationId, ...payload } = input;
|
|
3867
|
-
const result = await client.onsiteCalls.callOnsiteResource({
|
|
3972
|
+
const [result, error] = await client.onsiteCalls.callOnsiteResource({
|
|
3868
3973
|
path: { organizationId },
|
|
3869
3974
|
payload
|
|
3870
3975
|
});
|
|
3871
|
-
|
|
3976
|
+
if (error !== null) {
|
|
3977
|
+
return [null, error];
|
|
3978
|
+
}
|
|
3979
|
+
return [unwrapMaybeResult(result), null];
|
|
3872
3980
|
};
|
|
3873
3981
|
return {
|
|
3874
3982
|
call,
|
|
@@ -3930,9 +4038,15 @@ function cleanParams(value) {
|
|
|
3930
4038
|
])
|
|
3931
4039
|
);
|
|
3932
4040
|
}
|
|
4041
|
+
function unwrapMaybeResult2(result) {
|
|
4042
|
+
return Array.isArray(result) && result.length === 2 ? result[0] : result;
|
|
4043
|
+
}
|
|
3933
4044
|
async function unwrap(value) {
|
|
3934
|
-
const result = await value;
|
|
3935
|
-
|
|
4045
|
+
const [result, error] = await value;
|
|
4046
|
+
if (error !== null) {
|
|
4047
|
+
return [null, error];
|
|
4048
|
+
}
|
|
4049
|
+
return [unwrapMaybeResult2(result), null];
|
|
3936
4050
|
}
|
|
3937
4051
|
function makeSpokeClient(hubClient) {
|
|
3938
4052
|
const onsite = makeOnsiteResourceClient(hubClient);
|
|
@@ -4465,6 +4579,8 @@ export {
|
|
|
4465
4579
|
SourceManagedMemberLookupCommandPayloadSchema,
|
|
4466
4580
|
SourceManagedMemberRenewalCommandPayloadSchema,
|
|
4467
4581
|
SourceManagedMemberUpdateCommandPayloadSchema,
|
|
4582
|
+
SpokeHubApiError,
|
|
4583
|
+
SpokeHubClientError,
|
|
4468
4584
|
TimestampSchema,
|
|
4469
4585
|
TriggerOrganizationMemberSyncSchema,
|
|
4470
4586
|
UnauthorizedErrorSchema,
|