@scalemule/nextjs 0.1.38 → 0.1.40
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/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +33 -3
- package/dist/client.mjs +33 -3
- package/dist/{index-Tq5WdDfS.d.mts → index-Bv1m_qQ8.d.mts} +20 -0
- package/dist/{index-Tq5WdDfS.d.ts → index-Bv1m_qQ8.d.ts} +20 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -3
- package/dist/index.mjs +33 -3
- package/dist/server/auth.js +110 -62
- package/dist/server/auth.mjs +111 -63
- package/dist/server/index.d.mts +24 -4
- package/dist/server/index.d.ts +24 -4
- package/dist/server/index.js +161 -103
- package/dist/server/index.mjs +161 -103
- package/dist/server/webhook-handler.d.mts +2 -2
- package/dist/server/webhook-handler.d.ts +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -0
- package/dist/testing.mjs +3 -0
- package/dist/{webhook-handler-Cfa7-yKN.d.ts → webhook-handler-5ymVecTD.d.ts} +1 -1
- package/dist/{webhook-handler-DN4WBjbm.d.mts → webhook-handler-CVmBvPFN.d.mts} +1 -1
- package/package.json +4 -3
package/dist/client.d.mts
CHANGED
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -12,9 +12,31 @@ var ScaleMuleApiError = class extends Error {
|
|
|
12
12
|
this.code = error.code;
|
|
13
13
|
this.field = error.field;
|
|
14
14
|
this.status = status;
|
|
15
|
+
this.requestId = error.requestId;
|
|
16
|
+
this.traceId = error.traceId;
|
|
17
|
+
this.problem = error.problem;
|
|
15
18
|
}
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
// src/error-context.ts
|
|
22
|
+
function withErrorContext(error, responseData, headers) {
|
|
23
|
+
const enriched = { ...error };
|
|
24
|
+
const meta = responseData?.meta;
|
|
25
|
+
const requestId = meta?.request_id ?? headers?.get("x-request-id") ?? void 0;
|
|
26
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
27
|
+
enriched.requestId = requestId;
|
|
28
|
+
}
|
|
29
|
+
const traceId = meta?.trace_id;
|
|
30
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
31
|
+
enriched.traceId = traceId;
|
|
32
|
+
}
|
|
33
|
+
const rawError = responseData?.error;
|
|
34
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
35
|
+
enriched.problem = rawError;
|
|
36
|
+
}
|
|
37
|
+
return enriched;
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
// src/client.ts
|
|
19
41
|
var GATEWAY_URLS = {
|
|
20
42
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -591,7 +613,8 @@ var ScaleMuleClient = class {
|
|
|
591
613
|
}
|
|
592
614
|
if (!response.ok) {
|
|
593
615
|
const rawError = responseData?.error;
|
|
594
|
-
const
|
|
616
|
+
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
617
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
595
618
|
if (response.status === 401 && this.sessionToken && !options.isAutoRefresh && refreshAttempts < MAX_REFRESH_ATTEMPTS) {
|
|
596
619
|
refreshAttempts++;
|
|
597
620
|
if (this.debug) console.log("[ScaleMule] 401 received, attempting auto-refresh...");
|
|
@@ -853,10 +876,17 @@ var ScaleMuleClient = class {
|
|
|
853
876
|
const unwrapped = data?.data !== void 0 ? data.data : data;
|
|
854
877
|
resolve(unwrapped);
|
|
855
878
|
} else {
|
|
856
|
-
|
|
879
|
+
const uploadError = data?.error || {
|
|
857
880
|
code: `HTTP_${xhr.status}`,
|
|
858
881
|
message: data?.message || xhr.responseText || "Upload failed"
|
|
859
|
-
}
|
|
882
|
+
};
|
|
883
|
+
reject(
|
|
884
|
+
new ScaleMuleApiError(
|
|
885
|
+
withErrorContext(uploadError, data, {
|
|
886
|
+
get: (name) => xhr.getResponseHeader(name)
|
|
887
|
+
})
|
|
888
|
+
)
|
|
889
|
+
);
|
|
860
890
|
}
|
|
861
891
|
} catch {
|
|
862
892
|
reject(new ScaleMuleApiError({ code: "PARSE_ERROR", message: "Failed to parse response" }));
|
package/dist/client.mjs
CHANGED
|
@@ -10,9 +10,31 @@ var ScaleMuleApiError = class extends Error {
|
|
|
10
10
|
this.code = error.code;
|
|
11
11
|
this.field = error.field;
|
|
12
12
|
this.status = status;
|
|
13
|
+
this.requestId = error.requestId;
|
|
14
|
+
this.traceId = error.traceId;
|
|
15
|
+
this.problem = error.problem;
|
|
13
16
|
}
|
|
14
17
|
};
|
|
15
18
|
|
|
19
|
+
// src/error-context.ts
|
|
20
|
+
function withErrorContext(error, responseData, headers) {
|
|
21
|
+
const enriched = { ...error };
|
|
22
|
+
const meta = responseData?.meta;
|
|
23
|
+
const requestId = meta?.request_id ?? headers?.get("x-request-id") ?? void 0;
|
|
24
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
25
|
+
enriched.requestId = requestId;
|
|
26
|
+
}
|
|
27
|
+
const traceId = meta?.trace_id;
|
|
28
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
29
|
+
enriched.traceId = traceId;
|
|
30
|
+
}
|
|
31
|
+
const rawError = responseData?.error;
|
|
32
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
33
|
+
enriched.problem = rawError;
|
|
34
|
+
}
|
|
35
|
+
return enriched;
|
|
36
|
+
}
|
|
37
|
+
|
|
16
38
|
// src/client.ts
|
|
17
39
|
var GATEWAY_URLS = {
|
|
18
40
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -589,7 +611,8 @@ var ScaleMuleClient = class {
|
|
|
589
611
|
}
|
|
590
612
|
if (!response.ok) {
|
|
591
613
|
const rawError = responseData?.error;
|
|
592
|
-
const
|
|
614
|
+
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
615
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
593
616
|
if (response.status === 401 && this.sessionToken && !options.isAutoRefresh && refreshAttempts < MAX_REFRESH_ATTEMPTS) {
|
|
594
617
|
refreshAttempts++;
|
|
595
618
|
if (this.debug) console.log("[ScaleMule] 401 received, attempting auto-refresh...");
|
|
@@ -851,10 +874,17 @@ var ScaleMuleClient = class {
|
|
|
851
874
|
const unwrapped = data?.data !== void 0 ? data.data : data;
|
|
852
875
|
resolve(unwrapped);
|
|
853
876
|
} else {
|
|
854
|
-
|
|
877
|
+
const uploadError = data?.error || {
|
|
855
878
|
code: `HTTP_${xhr.status}`,
|
|
856
879
|
message: data?.message || xhr.responseText || "Upload failed"
|
|
857
|
-
}
|
|
880
|
+
};
|
|
881
|
+
reject(
|
|
882
|
+
new ScaleMuleApiError(
|
|
883
|
+
withErrorContext(uploadError, data, {
|
|
884
|
+
get: (name) => xhr.getResponseHeader(name)
|
|
885
|
+
})
|
|
886
|
+
)
|
|
887
|
+
);
|
|
858
888
|
}
|
|
859
889
|
} catch {
|
|
860
890
|
reject(new ScaleMuleApiError({ code: "PARSE_ERROR", message: "Failed to parse response" }));
|
|
@@ -121,6 +121,20 @@ declare class ScaleMuleApiError extends Error {
|
|
|
121
121
|
status?: number;
|
|
122
122
|
field?: string;
|
|
123
123
|
details?: unknown;
|
|
124
|
+
/**
|
|
125
|
+
* Correlation id for the failed request. Comes from the response envelope
|
|
126
|
+
* (`meta.request_id`), falling back to the `x-request-id` response header
|
|
127
|
+
* echoed by the gateway. Surface this in support flows.
|
|
128
|
+
*/
|
|
129
|
+
requestId?: string;
|
|
130
|
+
/** Distributed-trace id, when the backend supplies `meta.trace_id`. */
|
|
131
|
+
traceId?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The raw `error` object from the response body, unmodified. Escape hatch
|
|
134
|
+
* for consumers (such as `@scalemule/signals` `fromError`) that need fields
|
|
135
|
+
* this class does not model yet.
|
|
136
|
+
*/
|
|
137
|
+
problem?: unknown;
|
|
124
138
|
constructor(error: ApiError, status?: number);
|
|
125
139
|
}
|
|
126
140
|
interface ApiResponse<T> {
|
|
@@ -132,6 +146,12 @@ interface ApiError {
|
|
|
132
146
|
code: string;
|
|
133
147
|
message: string;
|
|
134
148
|
field?: string;
|
|
149
|
+
/** Correlation id: envelope `meta.request_id`, else the `x-request-id` header. */
|
|
150
|
+
requestId?: string;
|
|
151
|
+
/** Distributed-trace id from envelope `meta.trace_id`. */
|
|
152
|
+
traceId?: string;
|
|
153
|
+
/** The raw body `error` object, passed through untouched. */
|
|
154
|
+
problem?: unknown;
|
|
135
155
|
}
|
|
136
156
|
interface User {
|
|
137
157
|
id: string;
|
|
@@ -121,6 +121,20 @@ declare class ScaleMuleApiError extends Error {
|
|
|
121
121
|
status?: number;
|
|
122
122
|
field?: string;
|
|
123
123
|
details?: unknown;
|
|
124
|
+
/**
|
|
125
|
+
* Correlation id for the failed request. Comes from the response envelope
|
|
126
|
+
* (`meta.request_id`), falling back to the `x-request-id` response header
|
|
127
|
+
* echoed by the gateway. Surface this in support flows.
|
|
128
|
+
*/
|
|
129
|
+
requestId?: string;
|
|
130
|
+
/** Distributed-trace id, when the backend supplies `meta.trace_id`. */
|
|
131
|
+
traceId?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The raw `error` object from the response body, unmodified. Escape hatch
|
|
134
|
+
* for consumers (such as `@scalemule/signals` `fromError`) that need fields
|
|
135
|
+
* this class does not model yet.
|
|
136
|
+
*/
|
|
137
|
+
problem?: unknown;
|
|
124
138
|
constructor(error: ApiError, status?: number);
|
|
125
139
|
}
|
|
126
140
|
interface ApiResponse<T> {
|
|
@@ -132,6 +146,12 @@ interface ApiError {
|
|
|
132
146
|
code: string;
|
|
133
147
|
message: string;
|
|
134
148
|
field?: string;
|
|
149
|
+
/** Correlation id: envelope `meta.request_id`, else the `x-request-id` header. */
|
|
150
|
+
requestId?: string;
|
|
151
|
+
/** Distributed-trace id from envelope `meta.trace_id`. */
|
|
152
|
+
traceId?: string;
|
|
153
|
+
/** The raw body `error` object, passed through untouched. */
|
|
154
|
+
problem?: unknown;
|
|
135
155
|
}
|
|
136
156
|
interface User {
|
|
137
157
|
id: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@ import { MoneyClient } from '@scalemule/money';
|
|
|
6
6
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
7
7
|
import { ScaleMuleClient } from './client.mjs';
|
|
8
8
|
export { ClientConfig, RequestOptions, createClient } from './client.mjs';
|
|
9
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
10
|
-
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-
|
|
9
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-Bv1m_qQ8.mjs';
|
|
10
|
+
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-Bv1m_qQ8.mjs';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Tri-state file visibility — `'private' | 'app_public' | 'anonymous_visible'`.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { MoneyClient } from '@scalemule/money';
|
|
|
6
6
|
export { MoneyClient, MoneyClientConfig, createMoneyClient } from '@scalemule/money';
|
|
7
7
|
import { ScaleMuleClient } from './client.js';
|
|
8
8
|
export { ClientConfig, RequestOptions, createClient } from './client.js';
|
|
9
|
-
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-
|
|
10
|
-
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-
|
|
9
|
+
import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError$1, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-Bv1m_qQ8.js';
|
|
10
|
+
export { h as AccountBalance, i as AnalyticsEvent, j as ApiResponse, B as BatchTrackRequest, k as BillingPayment, l as BillingPayout, m as BillingRefund, n as BillingTransaction, C as ChangeEmailRequest, o as ChangePasswordRequest, p as ClientContext, q as ConnectedAccount, D as DeviceFingerprint, r as DeviceInfo, E as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, K as KnownAccountInfo, s as LinkedAccount, t as ListFilesResponse, u as LoginDeviceInfo, v as LoginRequest, w as LoginResponseWithMFA, x as LoginRiskInfo, M as MFAChallengeResponse, y as MFAMethod, z as MFASMSSetupResponse, G as MFASetupRequest, H as MFAStatus, I as MFATOTPSetupResponse, J as MFAVerifyRequest, O as OAuthCallbackRequest, N as OAuthCallbackResponse, P as OAuthConfig, Q as OAuthProvider, R as OAuthStartResponse, T as PageViewData, V as PayoutSchedule, W as PhoneLoginRequest, X as PhoneSendCodeRequest, Y as PhoneVerifyRequest, Z as Profile, _ as RefreshResponse, $ as RegisterRequest, a0 as ResetPasswordRequest, a1 as ScaleMuleApiError, a2 as ScaleMuleEnvironment, a3 as Session, a4 as SignedUploadCompleteRequest, a5 as SignedUploadRequest, a6 as SignedUploadResponse, a7 as SignedUploadUrl, a8 as StorageAdapter, a9 as StorageFile, aa as TrackEventResponse, ab as TransactionSummary, ac as UTMParams, ad as UpdateProfileRequest, ae as UploadOptions, af as UploadResponse, ag as VerifyEmailRequest } from './index-Bv1m_qQ8.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Tri-state file visibility — `'private' | 'app_public' | 'anonymous_visible'`.
|
package/dist/index.js
CHANGED
|
@@ -35,9 +35,31 @@ var ScaleMuleApiError = class extends Error {
|
|
|
35
35
|
this.code = error.code;
|
|
36
36
|
this.field = error.field;
|
|
37
37
|
this.status = status;
|
|
38
|
+
this.requestId = error.requestId;
|
|
39
|
+
this.traceId = error.traceId;
|
|
40
|
+
this.problem = error.problem;
|
|
38
41
|
}
|
|
39
42
|
};
|
|
40
43
|
|
|
44
|
+
// src/error-context.ts
|
|
45
|
+
function withErrorContext(error, responseData, headers) {
|
|
46
|
+
const enriched = { ...error };
|
|
47
|
+
const meta = responseData?.meta;
|
|
48
|
+
const requestId = meta?.request_id ?? headers?.get("x-request-id") ?? void 0;
|
|
49
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
50
|
+
enriched.requestId = requestId;
|
|
51
|
+
}
|
|
52
|
+
const traceId = meta?.trace_id;
|
|
53
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
54
|
+
enriched.traceId = traceId;
|
|
55
|
+
}
|
|
56
|
+
const rawError = responseData?.error;
|
|
57
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
58
|
+
enriched.problem = rawError;
|
|
59
|
+
}
|
|
60
|
+
return enriched;
|
|
61
|
+
}
|
|
62
|
+
|
|
41
63
|
// src/client.ts
|
|
42
64
|
var GATEWAY_URLS = {
|
|
43
65
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -614,7 +636,8 @@ var ScaleMuleClient = class {
|
|
|
614
636
|
}
|
|
615
637
|
if (!response.ok) {
|
|
616
638
|
const rawError = responseData?.error;
|
|
617
|
-
const
|
|
639
|
+
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
640
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
618
641
|
if (response.status === 401 && this.sessionToken && !options.isAutoRefresh && refreshAttempts < MAX_REFRESH_ATTEMPTS) {
|
|
619
642
|
refreshAttempts++;
|
|
620
643
|
if (this.debug) console.log("[ScaleMule] 401 received, attempting auto-refresh...");
|
|
@@ -876,10 +899,17 @@ var ScaleMuleClient = class {
|
|
|
876
899
|
const unwrapped = data?.data !== void 0 ? data.data : data;
|
|
877
900
|
resolve(unwrapped);
|
|
878
901
|
} else {
|
|
879
|
-
|
|
902
|
+
const uploadError = data?.error || {
|
|
880
903
|
code: `HTTP_${xhr.status}`,
|
|
881
904
|
message: data?.message || xhr.responseText || "Upload failed"
|
|
882
|
-
}
|
|
905
|
+
};
|
|
906
|
+
reject(
|
|
907
|
+
new ScaleMuleApiError(
|
|
908
|
+
withErrorContext(uploadError, data, {
|
|
909
|
+
get: (name) => xhr.getResponseHeader(name)
|
|
910
|
+
})
|
|
911
|
+
)
|
|
912
|
+
);
|
|
883
913
|
}
|
|
884
914
|
} catch {
|
|
885
915
|
reject(new ScaleMuleApiError({ code: "PARSE_ERROR", message: "Failed to parse response" }));
|
package/dist/index.mjs
CHANGED
|
@@ -15,9 +15,31 @@ var ScaleMuleApiError = class extends Error {
|
|
|
15
15
|
this.code = error.code;
|
|
16
16
|
this.field = error.field;
|
|
17
17
|
this.status = status;
|
|
18
|
+
this.requestId = error.requestId;
|
|
19
|
+
this.traceId = error.traceId;
|
|
20
|
+
this.problem = error.problem;
|
|
18
21
|
}
|
|
19
22
|
};
|
|
20
23
|
|
|
24
|
+
// src/error-context.ts
|
|
25
|
+
function withErrorContext(error, responseData, headers) {
|
|
26
|
+
const enriched = { ...error };
|
|
27
|
+
const meta = responseData?.meta;
|
|
28
|
+
const requestId = meta?.request_id ?? headers?.get("x-request-id") ?? void 0;
|
|
29
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
30
|
+
enriched.requestId = requestId;
|
|
31
|
+
}
|
|
32
|
+
const traceId = meta?.trace_id;
|
|
33
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
34
|
+
enriched.traceId = traceId;
|
|
35
|
+
}
|
|
36
|
+
const rawError = responseData?.error;
|
|
37
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
38
|
+
enriched.problem = rawError;
|
|
39
|
+
}
|
|
40
|
+
return enriched;
|
|
41
|
+
}
|
|
42
|
+
|
|
21
43
|
// src/client.ts
|
|
22
44
|
var GATEWAY_URLS = {
|
|
23
45
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -594,7 +616,8 @@ var ScaleMuleClient = class {
|
|
|
594
616
|
}
|
|
595
617
|
if (!response.ok) {
|
|
596
618
|
const rawError = responseData?.error;
|
|
597
|
-
const
|
|
619
|
+
const baseError = rawError && typeof rawError === "object" ? rawError : { code: `HTTP_${response.status}`, message: typeof rawError === "string" ? rawError : responseData?.message || text || response.statusText };
|
|
620
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
598
621
|
if (response.status === 401 && this.sessionToken && !options.isAutoRefresh && refreshAttempts < MAX_REFRESH_ATTEMPTS) {
|
|
599
622
|
refreshAttempts++;
|
|
600
623
|
if (this.debug) console.log("[ScaleMule] 401 received, attempting auto-refresh...");
|
|
@@ -856,10 +879,17 @@ var ScaleMuleClient = class {
|
|
|
856
879
|
const unwrapped = data?.data !== void 0 ? data.data : data;
|
|
857
880
|
resolve(unwrapped);
|
|
858
881
|
} else {
|
|
859
|
-
|
|
882
|
+
const uploadError = data?.error || {
|
|
860
883
|
code: `HTTP_${xhr.status}`,
|
|
861
884
|
message: data?.message || xhr.responseText || "Upload failed"
|
|
862
|
-
}
|
|
885
|
+
};
|
|
886
|
+
reject(
|
|
887
|
+
new ScaleMuleApiError(
|
|
888
|
+
withErrorContext(uploadError, data, {
|
|
889
|
+
get: (name) => xhr.getResponseHeader(name)
|
|
890
|
+
})
|
|
891
|
+
)
|
|
892
|
+
);
|
|
863
893
|
}
|
|
864
894
|
} catch {
|
|
865
895
|
reject(new ScaleMuleApiError({ code: "PARSE_ERROR", message: "Failed to parse response" }));
|