@scalemule/nextjs 0.1.39 → 0.1.41
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 +30 -0
- package/dist/audio.css +206 -0
- package/dist/audio.d.mts +33 -0
- package/dist/audio.d.ts +33 -0
- package/dist/audio.js +384 -0
- package/dist/audio.mjs +364 -0
- 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 +29 -2
- package/dist/server/auth.mjs +29 -2
- package/dist/server/index.d.mts +24 -4
- package/dist/server/index.d.ts +24 -4
- package/dist/server/index.js +38 -5
- package/dist/server/index.mjs +38 -5
- 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 +12 -5
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" }));
|
package/dist/server/auth.js
CHANGED
|
@@ -12,6 +12,9 @@ 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
|
|
|
@@ -106,6 +109,25 @@ function buildClientContextHeaders(context) {
|
|
|
106
109
|
return headers2;
|
|
107
110
|
}
|
|
108
111
|
|
|
112
|
+
// src/error-context.ts
|
|
113
|
+
function withErrorContext(error, responseData, headers2) {
|
|
114
|
+
const enriched = { ...error };
|
|
115
|
+
const meta = responseData?.meta;
|
|
116
|
+
const requestId = meta?.request_id ?? headers2?.get("x-request-id") ?? void 0;
|
|
117
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
118
|
+
enriched.requestId = requestId;
|
|
119
|
+
}
|
|
120
|
+
const traceId = meta?.trace_id;
|
|
121
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
122
|
+
enriched.traceId = traceId;
|
|
123
|
+
}
|
|
124
|
+
const rawError = responseData?.error;
|
|
125
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
126
|
+
enriched.problem = rawError;
|
|
127
|
+
}
|
|
128
|
+
return enriched;
|
|
129
|
+
}
|
|
130
|
+
|
|
109
131
|
// src/server/client.ts
|
|
110
132
|
var GATEWAY_URLS = {
|
|
111
133
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -525,7 +547,11 @@ var ScaleMuleServer = class {
|
|
|
525
547
|
}
|
|
526
548
|
if (!response.ok) {
|
|
527
549
|
throw new ScaleMuleApiError(
|
|
528
|
-
|
|
550
|
+
withErrorContext(
|
|
551
|
+
responseData?.error || { code: "UPLOAD_FAILED", message: text || "Upload failed" },
|
|
552
|
+
responseData,
|
|
553
|
+
response.headers
|
|
554
|
+
)
|
|
529
555
|
);
|
|
530
556
|
}
|
|
531
557
|
const data = responseData?.data !== void 0 ? responseData.data : responseData;
|
|
@@ -768,10 +794,11 @@ var ScaleMuleServer = class {
|
|
|
768
794
|
} catch {
|
|
769
795
|
}
|
|
770
796
|
if (!response.ok) {
|
|
771
|
-
const
|
|
797
|
+
const baseError = responseData?.error || {
|
|
772
798
|
code: `HTTP_${response.status}`,
|
|
773
799
|
message: responseData?.message || text || response.statusText
|
|
774
800
|
};
|
|
801
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
775
802
|
if (response.status === 401 && options.sessionToken && !options.isAutoRefresh) {
|
|
776
803
|
if (this.debug) console.log("[ScaleMule Server] 401 received, attempting auto-refresh...");
|
|
777
804
|
try {
|
package/dist/server/auth.mjs
CHANGED
|
@@ -10,6 +10,9 @@ 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
|
|
|
@@ -104,6 +107,25 @@ function buildClientContextHeaders(context) {
|
|
|
104
107
|
return headers2;
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
// src/error-context.ts
|
|
111
|
+
function withErrorContext(error, responseData, headers2) {
|
|
112
|
+
const enriched = { ...error };
|
|
113
|
+
const meta = responseData?.meta;
|
|
114
|
+
const requestId = meta?.request_id ?? headers2?.get("x-request-id") ?? void 0;
|
|
115
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
116
|
+
enriched.requestId = requestId;
|
|
117
|
+
}
|
|
118
|
+
const traceId = meta?.trace_id;
|
|
119
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
120
|
+
enriched.traceId = traceId;
|
|
121
|
+
}
|
|
122
|
+
const rawError = responseData?.error;
|
|
123
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
124
|
+
enriched.problem = rawError;
|
|
125
|
+
}
|
|
126
|
+
return enriched;
|
|
127
|
+
}
|
|
128
|
+
|
|
107
129
|
// src/server/client.ts
|
|
108
130
|
var GATEWAY_URLS = {
|
|
109
131
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -523,7 +545,11 @@ var ScaleMuleServer = class {
|
|
|
523
545
|
}
|
|
524
546
|
if (!response.ok) {
|
|
525
547
|
throw new ScaleMuleApiError(
|
|
526
|
-
|
|
548
|
+
withErrorContext(
|
|
549
|
+
responseData?.error || { code: "UPLOAD_FAILED", message: text || "Upload failed" },
|
|
550
|
+
responseData,
|
|
551
|
+
response.headers
|
|
552
|
+
)
|
|
527
553
|
);
|
|
528
554
|
}
|
|
529
555
|
const data = responseData?.data !== void 0 ? responseData.data : responseData;
|
|
@@ -766,10 +792,11 @@ var ScaleMuleServer = class {
|
|
|
766
792
|
} catch {
|
|
767
793
|
}
|
|
768
794
|
if (!response.ok) {
|
|
769
|
-
const
|
|
795
|
+
const baseError = responseData?.error || {
|
|
770
796
|
code: `HTTP_${response.status}`,
|
|
771
797
|
message: responseData?.message || text || response.statusText
|
|
772
798
|
};
|
|
799
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
773
800
|
if (response.status === 401 && options.sessionToken && !options.isAutoRefresh) {
|
|
774
801
|
if (this.debug) console.log("[ScaleMule Server] 401 received, attempting auto-refresh...");
|
|
775
802
|
try {
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { p as ClientContext, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-CVmBvPFN.mjs';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-CVmBvPFN.mjs';
|
|
3
|
+
import { p as ClientContext, A as ApiError } from '../index-Bv1m_qQ8.mjs';
|
|
4
4
|
export { L as LedveryRoutesConfig, a as LedverySessionData, S as SM_LEDVERY_ACCESS_TOKEN_COOKIE, b as SM_LEDVERY_ID_TOKEN_COOKIE, c as SM_LEDVERY_NONCE_COOKIE, d as SM_LEDVERY_PKCE_VERIFIER_COOKIE, e as SM_LEDVERY_STATE_COOKIE, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.mjs';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
6
|
import '@scalemule/money';
|
|
@@ -509,7 +509,21 @@ declare class ScaleMuleError extends Error {
|
|
|
509
509
|
readonly code: string;
|
|
510
510
|
readonly status: number;
|
|
511
511
|
readonly details?: Record<string, unknown> | undefined;
|
|
512
|
-
|
|
512
|
+
/**
|
|
513
|
+
* Correlation id of the upstream platform request that produced this
|
|
514
|
+
* error, when there was one. `apiHandler()` echoes it back to the browser
|
|
515
|
+
* as `meta.request_id` so a client-side failure can be traced all the way
|
|
516
|
+
* through the route handler to the platform service.
|
|
517
|
+
*/
|
|
518
|
+
readonly requestId?: string | undefined;
|
|
519
|
+
constructor(code: string, message: string, status?: number, details?: Record<string, unknown> | undefined,
|
|
520
|
+
/**
|
|
521
|
+
* Correlation id of the upstream platform request that produced this
|
|
522
|
+
* error, when there was one. `apiHandler()` echoes it back to the browser
|
|
523
|
+
* as `meta.request_id` so a client-side failure can be traced all the way
|
|
524
|
+
* through the route handler to the platform service.
|
|
525
|
+
*/
|
|
526
|
+
requestId?: string | undefined);
|
|
513
527
|
}
|
|
514
528
|
declare function errorCodeToStatus(code: string): number;
|
|
515
529
|
/**
|
|
@@ -521,6 +535,12 @@ type SdkResult<T> = {
|
|
|
521
535
|
data?: T | null;
|
|
522
536
|
error?: ApiError | null;
|
|
523
537
|
success?: boolean;
|
|
538
|
+
/** Platform envelope metadata; `request_id` is echoed onto ScaleMuleError. */
|
|
539
|
+
meta?: {
|
|
540
|
+
request_id?: string;
|
|
541
|
+
trace_id?: string;
|
|
542
|
+
timestamp?: string;
|
|
543
|
+
};
|
|
524
544
|
};
|
|
525
545
|
/**
|
|
526
546
|
* Convert an SDK result into throw-on-error, or pass through a raw value.
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { p as ClientContext, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-5ymVecTD.js';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-5ymVecTD.js';
|
|
3
|
+
import { p as ClientContext, A as ApiError } from '../index-Bv1m_qQ8.js';
|
|
4
4
|
export { L as LedveryRoutesConfig, a as LedverySessionData, S as SM_LEDVERY_ACCESS_TOKEN_COOKIE, b as SM_LEDVERY_ID_TOKEN_COOKIE, c as SM_LEDVERY_NONCE_COOKIE, d as SM_LEDVERY_PKCE_VERIFIER_COOKIE, e as SM_LEDVERY_STATE_COOKIE, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.js';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
6
|
import '@scalemule/money';
|
|
@@ -509,7 +509,21 @@ declare class ScaleMuleError extends Error {
|
|
|
509
509
|
readonly code: string;
|
|
510
510
|
readonly status: number;
|
|
511
511
|
readonly details?: Record<string, unknown> | undefined;
|
|
512
|
-
|
|
512
|
+
/**
|
|
513
|
+
* Correlation id of the upstream platform request that produced this
|
|
514
|
+
* error, when there was one. `apiHandler()` echoes it back to the browser
|
|
515
|
+
* as `meta.request_id` so a client-side failure can be traced all the way
|
|
516
|
+
* through the route handler to the platform service.
|
|
517
|
+
*/
|
|
518
|
+
readonly requestId?: string | undefined;
|
|
519
|
+
constructor(code: string, message: string, status?: number, details?: Record<string, unknown> | undefined,
|
|
520
|
+
/**
|
|
521
|
+
* Correlation id of the upstream platform request that produced this
|
|
522
|
+
* error, when there was one. `apiHandler()` echoes it back to the browser
|
|
523
|
+
* as `meta.request_id` so a client-side failure can be traced all the way
|
|
524
|
+
* through the route handler to the platform service.
|
|
525
|
+
*/
|
|
526
|
+
requestId?: string | undefined);
|
|
513
527
|
}
|
|
514
528
|
declare function errorCodeToStatus(code: string): number;
|
|
515
529
|
/**
|
|
@@ -521,6 +535,12 @@ type SdkResult<T> = {
|
|
|
521
535
|
data?: T | null;
|
|
522
536
|
error?: ApiError | null;
|
|
523
537
|
success?: boolean;
|
|
538
|
+
/** Platform envelope metadata; `request_id` is echoed onto ScaleMuleError. */
|
|
539
|
+
meta?: {
|
|
540
|
+
request_id?: string;
|
|
541
|
+
trace_id?: string;
|
|
542
|
+
timestamp?: string;
|
|
543
|
+
};
|
|
524
544
|
};
|
|
525
545
|
/**
|
|
526
546
|
* Convert an SDK result into throw-on-error, or pass through a raw value.
|
package/dist/server/index.js
CHANGED
|
@@ -17,6 +17,9 @@ var ScaleMuleApiError = class extends Error {
|
|
|
17
17
|
this.code = error.code;
|
|
18
18
|
this.field = error.field;
|
|
19
19
|
this.status = status;
|
|
20
|
+
this.requestId = error.requestId;
|
|
21
|
+
this.traceId = error.traceId;
|
|
22
|
+
this.problem = error.problem;
|
|
20
23
|
}
|
|
21
24
|
};
|
|
22
25
|
|
|
@@ -179,6 +182,25 @@ function buildFlagContext(clientContext, extraContext = {}) {
|
|
|
179
182
|
return context;
|
|
180
183
|
}
|
|
181
184
|
|
|
185
|
+
// src/error-context.ts
|
|
186
|
+
function withErrorContext(error, responseData, headers3) {
|
|
187
|
+
const enriched = { ...error };
|
|
188
|
+
const meta = responseData?.meta;
|
|
189
|
+
const requestId = meta?.request_id ?? headers3?.get("x-request-id") ?? void 0;
|
|
190
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
191
|
+
enriched.requestId = requestId;
|
|
192
|
+
}
|
|
193
|
+
const traceId = meta?.trace_id;
|
|
194
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
195
|
+
enriched.traceId = traceId;
|
|
196
|
+
}
|
|
197
|
+
const rawError = responseData?.error;
|
|
198
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
199
|
+
enriched.problem = rawError;
|
|
200
|
+
}
|
|
201
|
+
return enriched;
|
|
202
|
+
}
|
|
203
|
+
|
|
182
204
|
// src/server/client.ts
|
|
183
205
|
var GATEWAY_URLS = {
|
|
184
206
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -598,7 +620,11 @@ var ScaleMuleServer = class {
|
|
|
598
620
|
}
|
|
599
621
|
if (!response.ok) {
|
|
600
622
|
throw new ScaleMuleApiError(
|
|
601
|
-
|
|
623
|
+
withErrorContext(
|
|
624
|
+
responseData?.error || { code: "UPLOAD_FAILED", message: text || "Upload failed" },
|
|
625
|
+
responseData,
|
|
626
|
+
response.headers
|
|
627
|
+
)
|
|
602
628
|
);
|
|
603
629
|
}
|
|
604
630
|
const data = responseData?.data !== void 0 ? responseData.data : responseData;
|
|
@@ -841,10 +867,11 @@ var ScaleMuleServer = class {
|
|
|
841
867
|
} catch {
|
|
842
868
|
}
|
|
843
869
|
if (!response.ok) {
|
|
844
|
-
const
|
|
870
|
+
const baseError = responseData?.error || {
|
|
845
871
|
code: `HTTP_${response.status}`,
|
|
846
872
|
message: responseData?.message || text || response.statusText
|
|
847
873
|
};
|
|
874
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
848
875
|
if (response.status === 401 && options.sessionToken && !options.isAutoRefresh) {
|
|
849
876
|
if (this.debug) console.log("[ScaleMule Server] 401 received, attempting auto-refresh...");
|
|
850
877
|
try {
|
|
@@ -2537,11 +2564,12 @@ function createNotificationRoutes(config) {
|
|
|
2537
2564
|
|
|
2538
2565
|
// src/server/errors.ts
|
|
2539
2566
|
var ScaleMuleError = class extends Error {
|
|
2540
|
-
constructor(code, message, status = 400, details) {
|
|
2567
|
+
constructor(code, message, status = 400, details, requestId) {
|
|
2541
2568
|
super(message);
|
|
2542
2569
|
this.code = code;
|
|
2543
2570
|
this.status = status;
|
|
2544
2571
|
this.details = details;
|
|
2572
|
+
this.requestId = requestId;
|
|
2545
2573
|
this.name = "ScaleMuleError";
|
|
2546
2574
|
}
|
|
2547
2575
|
};
|
|
@@ -2595,7 +2623,8 @@ function unwrap(result) {
|
|
|
2595
2623
|
code,
|
|
2596
2624
|
err?.message || "An error occurred",
|
|
2597
2625
|
status,
|
|
2598
|
-
err?.details
|
|
2626
|
+
err?.details,
|
|
2627
|
+
err?.requestId ?? envelope.meta?.request_id
|
|
2599
2628
|
);
|
|
2600
2629
|
}
|
|
2601
2630
|
return envelope.data;
|
|
@@ -2644,7 +2673,11 @@ function apiHandler(handler, options) {
|
|
|
2644
2673
|
console.error("Internal API error:", error.message);
|
|
2645
2674
|
}
|
|
2646
2675
|
return Response.json(
|
|
2647
|
-
{
|
|
2676
|
+
{
|
|
2677
|
+
success: false,
|
|
2678
|
+
error: { code: error.code, message: safeMessage },
|
|
2679
|
+
...error.requestId ? { meta: { request_id: error.requestId } } : {}
|
|
2680
|
+
},
|
|
2648
2681
|
{ status: error.status }
|
|
2649
2682
|
);
|
|
2650
2683
|
}
|
package/dist/server/index.mjs
CHANGED
|
@@ -15,6 +15,9 @@ 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
|
|
|
@@ -177,6 +180,25 @@ function buildFlagContext(clientContext, extraContext = {}) {
|
|
|
177
180
|
return context;
|
|
178
181
|
}
|
|
179
182
|
|
|
183
|
+
// src/error-context.ts
|
|
184
|
+
function withErrorContext(error, responseData, headers3) {
|
|
185
|
+
const enriched = { ...error };
|
|
186
|
+
const meta = responseData?.meta;
|
|
187
|
+
const requestId = meta?.request_id ?? headers3?.get("x-request-id") ?? void 0;
|
|
188
|
+
if (requestId !== void 0 && enriched.requestId === void 0) {
|
|
189
|
+
enriched.requestId = requestId;
|
|
190
|
+
}
|
|
191
|
+
const traceId = meta?.trace_id;
|
|
192
|
+
if (traceId !== void 0 && enriched.traceId === void 0) {
|
|
193
|
+
enriched.traceId = traceId;
|
|
194
|
+
}
|
|
195
|
+
const rawError = responseData?.error;
|
|
196
|
+
if (rawError !== null && typeof rawError === "object" && enriched.problem === void 0) {
|
|
197
|
+
enriched.problem = rawError;
|
|
198
|
+
}
|
|
199
|
+
return enriched;
|
|
200
|
+
}
|
|
201
|
+
|
|
180
202
|
// src/server/client.ts
|
|
181
203
|
var GATEWAY_URLS = {
|
|
182
204
|
dev: "https://api-dev.scalemule.com",
|
|
@@ -596,7 +618,11 @@ var ScaleMuleServer = class {
|
|
|
596
618
|
}
|
|
597
619
|
if (!response.ok) {
|
|
598
620
|
throw new ScaleMuleApiError(
|
|
599
|
-
|
|
621
|
+
withErrorContext(
|
|
622
|
+
responseData?.error || { code: "UPLOAD_FAILED", message: text || "Upload failed" },
|
|
623
|
+
responseData,
|
|
624
|
+
response.headers
|
|
625
|
+
)
|
|
600
626
|
);
|
|
601
627
|
}
|
|
602
628
|
const data = responseData?.data !== void 0 ? responseData.data : responseData;
|
|
@@ -839,10 +865,11 @@ var ScaleMuleServer = class {
|
|
|
839
865
|
} catch {
|
|
840
866
|
}
|
|
841
867
|
if (!response.ok) {
|
|
842
|
-
const
|
|
868
|
+
const baseError = responseData?.error || {
|
|
843
869
|
code: `HTTP_${response.status}`,
|
|
844
870
|
message: responseData?.message || text || response.statusText
|
|
845
871
|
};
|
|
872
|
+
const error = withErrorContext(baseError, responseData, response.headers);
|
|
846
873
|
if (response.status === 401 && options.sessionToken && !options.isAutoRefresh) {
|
|
847
874
|
if (this.debug) console.log("[ScaleMule Server] 401 received, attempting auto-refresh...");
|
|
848
875
|
try {
|
|
@@ -2535,11 +2562,12 @@ function createNotificationRoutes(config) {
|
|
|
2535
2562
|
|
|
2536
2563
|
// src/server/errors.ts
|
|
2537
2564
|
var ScaleMuleError = class extends Error {
|
|
2538
|
-
constructor(code, message, status = 400, details) {
|
|
2565
|
+
constructor(code, message, status = 400, details, requestId) {
|
|
2539
2566
|
super(message);
|
|
2540
2567
|
this.code = code;
|
|
2541
2568
|
this.status = status;
|
|
2542
2569
|
this.details = details;
|
|
2570
|
+
this.requestId = requestId;
|
|
2543
2571
|
this.name = "ScaleMuleError";
|
|
2544
2572
|
}
|
|
2545
2573
|
};
|
|
@@ -2593,7 +2621,8 @@ function unwrap(result) {
|
|
|
2593
2621
|
code,
|
|
2594
2622
|
err?.message || "An error occurred",
|
|
2595
2623
|
status,
|
|
2596
|
-
err?.details
|
|
2624
|
+
err?.details,
|
|
2625
|
+
err?.requestId ?? envelope.meta?.request_id
|
|
2597
2626
|
);
|
|
2598
2627
|
}
|
|
2599
2628
|
return envelope.data;
|
|
@@ -2642,7 +2671,11 @@ function apiHandler(handler, options) {
|
|
|
2642
2671
|
console.error("Internal API error:", error.message);
|
|
2643
2672
|
}
|
|
2644
2673
|
return Response.json(
|
|
2645
|
-
{
|
|
2674
|
+
{
|
|
2675
|
+
success: false,
|
|
2676
|
+
error: { code: error.code, message: safeMessage },
|
|
2677
|
+
...error.requestId ? { meta: { request_id: error.requestId } } : {}
|
|
2678
|
+
},
|
|
2646
2679
|
{ status: error.status }
|
|
2647
2680
|
);
|
|
2648
2681
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { g as createWebhookHandler } from '../webhook-handler-
|
|
1
|
+
export { g as createWebhookHandler } from '../webhook-handler-CVmBvPFN.mjs';
|
|
2
2
|
import '@scalemule/money';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-Bv1m_qQ8.mjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { g as createWebhookHandler } from '../webhook-handler-
|
|
1
|
+
export { g as createWebhookHandler } from '../webhook-handler-5ymVecTD.js';
|
|
2
2
|
import '@scalemule/money';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-Bv1m_qQ8.js';
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { U as User, A as ApiError, a9 as StorageFile } from './index-
|
|
3
|
+
import { U as User, A as ApiError, a9 as StorageFile } from './index-Bv1m_qQ8.mjs';
|
|
4
4
|
|
|
5
5
|
interface MockUserOptions {
|
|
6
6
|
id?: string;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { U as User, A as ApiError, a9 as StorageFile } from './index-
|
|
3
|
+
import { U as User, A as ApiError, a9 as StorageFile } from './index-Bv1m_qQ8.js';
|
|
4
4
|
|
|
5
5
|
interface MockUserOptions {
|
|
6
6
|
id?: string;
|
package/dist/testing.js
CHANGED
|
@@ -11,6 +11,9 @@ var ScaleMuleApiError = class extends Error {
|
|
|
11
11
|
this.code = error.code;
|
|
12
12
|
this.field = error.field;
|
|
13
13
|
this.status = status;
|
|
14
|
+
this.requestId = error.requestId;
|
|
15
|
+
this.traceId = error.traceId;
|
|
16
|
+
this.problem = error.problem;
|
|
14
17
|
}
|
|
15
18
|
};
|
|
16
19
|
function createMockUser(options = {}) {
|
package/dist/testing.mjs
CHANGED
|
@@ -9,6 +9,9 @@ var ScaleMuleApiError = class extends Error {
|
|
|
9
9
|
this.code = error.code;
|
|
10
10
|
this.field = error.field;
|
|
11
11
|
this.status = status;
|
|
12
|
+
this.requestId = error.requestId;
|
|
13
|
+
this.traceId = error.traceId;
|
|
14
|
+
this.problem = error.problem;
|
|
12
15
|
}
|
|
13
16
|
};
|
|
14
17
|
function createMockUser(options = {}) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MoneyClient } from '@scalemule/money';
|
|
2
|
-
import { A as ApiError, $ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a9 as StorageFile, af as UploadResponse } from './index-
|
|
2
|
+
import { A as ApiError, $ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a9 as StorageFile, af as UploadResponse } from './index-Bv1m_qQ8.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Server-Side ScaleMule Client
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MoneyClient } from '@scalemule/money';
|
|
2
|
-
import { A as ApiError, $ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a9 as StorageFile, af as UploadResponse } from './index-
|
|
2
|
+
import { A as ApiError, $ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a9 as StorageFile, af as UploadResponse } from './index-Bv1m_qQ8.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Server-Side ScaleMule Client
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalemule/nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -40,7 +40,13 @@
|
|
|
40
40
|
"types": "./dist/testing.d.ts",
|
|
41
41
|
"import": "./dist/testing.mjs",
|
|
42
42
|
"require": "./dist/testing.js"
|
|
43
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"./audio": {
|
|
45
|
+
"types": "./dist/audio.d.ts",
|
|
46
|
+
"import": "./dist/audio.mjs",
|
|
47
|
+
"require": "./dist/audio.js"
|
|
48
|
+
},
|
|
49
|
+
"./audio.css": "./dist/audio.css"
|
|
44
50
|
},
|
|
45
51
|
"files": [
|
|
46
52
|
"dist",
|
|
@@ -48,19 +54,20 @@
|
|
|
48
54
|
"LICENSE"
|
|
49
55
|
],
|
|
50
56
|
"scripts": {
|
|
51
|
-
"build": "tsup",
|
|
57
|
+
"build": "npm run clean && tsup",
|
|
52
58
|
"dev": "tsup --watch",
|
|
53
59
|
"test": "vitest run",
|
|
54
60
|
"test:watch": "vitest",
|
|
55
61
|
"type-check": "tsc --noEmit",
|
|
56
62
|
"lint": "tsc --noEmit",
|
|
57
63
|
"clean": "rm -rf dist",
|
|
58
|
-
"prepublishOnly": "node -e \"const v=require('./package.json').version; if(!/^0\\.(0|1)\\.\\d+$/.test(v)){console.error('ERR: SDK '+v+' violates patch-only policy (0.0.x or 0.1.x only). See CONTRIBUTING.md SDK versioning section.');process.exit(1)}\""
|
|
64
|
+
"prepublishOnly": "node -e \"const v=require('./package.json').version; if(!/^0\\.(0|1)\\.\\d+$/.test(v)){console.error('ERR: SDK '+v+' violates patch-only policy (0.0.x or 0.1.x only). See CONTRIBUTING.md SDK versioning section.');process.exit(1)}\"",
|
|
65
|
+
"release": "npm run build && npm test && npm run type-check && npm publish --access public"
|
|
59
66
|
},
|
|
60
67
|
"dependencies": {
|
|
61
68
|
"@scalemule/ledvery": "^0.0.1",
|
|
62
69
|
"@scalemule/money": "^0.0.1",
|
|
63
|
-
"@scalemule/sdk": "^0.0.
|
|
70
|
+
"@scalemule/sdk": "^0.0.64"
|
|
64
71
|
},
|
|
65
72
|
"peerDependencies": {
|
|
66
73
|
"next": ">=14.0.0",
|