@scalemule/nextjs 0.0.28 → 0.0.30
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/{index-DewTyMF2.d.mts → index-BoENfro3.d.mts} +1 -1
- package/dist/{index-DewTyMF2.d.ts → index-BoENfro3.d.ts} +1 -1
- package/dist/index.d.mts +57 -3
- package/dist/index.d.ts +57 -3
- package/dist/index.js +262 -0
- package/dist/index.mjs +261 -1
- package/dist/server/index.d.mts +46 -9
- package/dist/server/index.d.ts +46 -9
- package/dist/server/index.js +137 -1
- package/dist/server/index.mjs +137 -2
- 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/{webhook-handler-CQ2lZgy0.d.ts → webhook-handler-CjSSCdvI.d.ts} +2 -2
- package/dist/{webhook-handler-DS0r_w4M.d.mts → webhook-handler-Cz9jtet2.d.mts} +2 -2
- package/package.json +2 -2
package/dist/server/index.mjs
CHANGED
|
@@ -1599,6 +1599,137 @@ function createAnalyticsRoutes(config = {}) {
|
|
|
1599
1599
|
return { POST };
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
|
+
// src/server/push.ts
|
|
1603
|
+
function errorResponse2(code, message, status) {
|
|
1604
|
+
return new Response(
|
|
1605
|
+
JSON.stringify({ success: false, error: { code, message } }),
|
|
1606
|
+
{ status, headers: { "Content-Type": "application/json" } }
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
function successResponse2(data, status = 200) {
|
|
1610
|
+
return new Response(
|
|
1611
|
+
JSON.stringify({ success: true, data }),
|
|
1612
|
+
{ status, headers: { "Content-Type": "application/json" } }
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
function createPushRoutes(config) {
|
|
1616
|
+
const { apiKey, gatewayUrl, csrf = true } = config;
|
|
1617
|
+
async function proxyToGateway(request, method, subPath) {
|
|
1618
|
+
const targetUrl = `${gatewayUrl}/v1/communication/push/${subPath}`;
|
|
1619
|
+
const headers2 = {
|
|
1620
|
+
"x-api-key": apiKey
|
|
1621
|
+
};
|
|
1622
|
+
const session = getSessionFromRequest(request);
|
|
1623
|
+
if (session?.sessionToken) {
|
|
1624
|
+
headers2["Authorization"] = `Bearer ${session.sessionToken}`;
|
|
1625
|
+
}
|
|
1626
|
+
const clientContext = extractClientContext(
|
|
1627
|
+
request
|
|
1628
|
+
);
|
|
1629
|
+
const contextHeaders = buildClientContextHeaders(clientContext);
|
|
1630
|
+
Object.assign(headers2, contextHeaders);
|
|
1631
|
+
const workspaceId = request.headers.get("x-sm-workspace-id");
|
|
1632
|
+
if (workspaceId) {
|
|
1633
|
+
headers2["x-sm-workspace-id"] = workspaceId;
|
|
1634
|
+
}
|
|
1635
|
+
const fetchOptions = {
|
|
1636
|
+
method,
|
|
1637
|
+
headers: headers2
|
|
1638
|
+
};
|
|
1639
|
+
if (method !== "GET" && method !== "DELETE") {
|
|
1640
|
+
try {
|
|
1641
|
+
const body = await request.text();
|
|
1642
|
+
if (body) {
|
|
1643
|
+
headers2["Content-Type"] = "application/json";
|
|
1644
|
+
fetchOptions.body = body;
|
|
1645
|
+
}
|
|
1646
|
+
} catch {
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
const response = await fetch(targetUrl, fetchOptions);
|
|
1650
|
+
if (response.status === 204) {
|
|
1651
|
+
return successResponse2(null);
|
|
1652
|
+
}
|
|
1653
|
+
const contentType = response.headers.get("content-type") || "";
|
|
1654
|
+
if (contentType.includes("application/json")) {
|
|
1655
|
+
const json = await response.json();
|
|
1656
|
+
if (response.ok) {
|
|
1657
|
+
return new Response(JSON.stringify(json), {
|
|
1658
|
+
status: response.status,
|
|
1659
|
+
headers: { "Content-Type": "application/json" }
|
|
1660
|
+
});
|
|
1661
|
+
} else {
|
|
1662
|
+
const errMsg = json?.error?.message || json?.message || "Request failed";
|
|
1663
|
+
const errCode = json?.error?.code || json?.code || "PUSH_ERROR";
|
|
1664
|
+
return errorResponse2(errCode, errMsg, response.status);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
const text = await response.text();
|
|
1668
|
+
if (response.ok) {
|
|
1669
|
+
return successResponse2(text);
|
|
1670
|
+
}
|
|
1671
|
+
return errorResponse2("PUSH_ERROR", text || "Request failed", response.status);
|
|
1672
|
+
}
|
|
1673
|
+
function extractSubPath(params) {
|
|
1674
|
+
return (params.action || []).join("/");
|
|
1675
|
+
}
|
|
1676
|
+
const GET = async (request, context) => {
|
|
1677
|
+
try {
|
|
1678
|
+
const params = await context?.params;
|
|
1679
|
+
const subPath = extractSubPath(params || {});
|
|
1680
|
+
return proxyToGateway(request, "GET", subPath);
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
return errorResponse2("INTERNAL_ERROR", String(e), 500);
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
const POST = async (request, context) => {
|
|
1686
|
+
if (csrf) {
|
|
1687
|
+
const csrfError = validateCSRFToken(request);
|
|
1688
|
+
if (csrfError) {
|
|
1689
|
+
return errorResponse2("CSRF_ERROR", "CSRF validation failed", 403);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
try {
|
|
1693
|
+
const params = await context?.params;
|
|
1694
|
+
const subPath = extractSubPath(params || {});
|
|
1695
|
+
return proxyToGateway(request, "POST", subPath);
|
|
1696
|
+
} catch (e) {
|
|
1697
|
+
return errorResponse2("INTERNAL_ERROR", String(e), 500);
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
const PUT = async (request, context) => {
|
|
1701
|
+
if (csrf) {
|
|
1702
|
+
const csrfError = validateCSRFToken(request);
|
|
1703
|
+
if (csrfError) {
|
|
1704
|
+
return errorResponse2("CSRF_ERROR", "CSRF validation failed", 403);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
try {
|
|
1708
|
+
const params = await context?.params;
|
|
1709
|
+
const subPath = extractSubPath(params || {});
|
|
1710
|
+
return proxyToGateway(request, "PUT", subPath);
|
|
1711
|
+
} catch (e) {
|
|
1712
|
+
return errorResponse2("INTERNAL_ERROR", String(e), 500);
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
const DELETE = async (request, context) => {
|
|
1716
|
+
if (csrf) {
|
|
1717
|
+
const csrfError = validateCSRFToken(request);
|
|
1718
|
+
if (csrfError) {
|
|
1719
|
+
return errorResponse2("CSRF_ERROR", "CSRF validation failed", 403);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
try {
|
|
1723
|
+
const params = await context?.params;
|
|
1724
|
+
const subPath = extractSubPath(params || {});
|
|
1725
|
+
return proxyToGateway(request, "DELETE", subPath);
|
|
1726
|
+
} catch (e) {
|
|
1727
|
+
return errorResponse2("INTERNAL_ERROR", String(e), 500);
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
return { GET, POST, PUT, DELETE };
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1602
1733
|
// src/server/errors.ts
|
|
1603
1734
|
var ScaleMuleError = class extends Error {
|
|
1604
1735
|
constructor(code, message, status = 400, details) {
|
|
@@ -1703,8 +1834,12 @@ function apiHandler(handler, options) {
|
|
|
1703
1834
|
const custom = options.onError(error);
|
|
1704
1835
|
if (custom) return custom;
|
|
1705
1836
|
}
|
|
1837
|
+
const safeMessage = error.status >= 500 ? "An unexpected error occurred" : error.message;
|
|
1838
|
+
if (error.status >= 500) {
|
|
1839
|
+
console.error("Internal API error:", error.message);
|
|
1840
|
+
}
|
|
1706
1841
|
return Response.json(
|
|
1707
|
-
{ success: false, error: { code: error.code, message:
|
|
1842
|
+
{ success: false, error: { code: error.code, message: safeMessage } },
|
|
1708
1843
|
{ status: error.status }
|
|
1709
1844
|
);
|
|
1710
1845
|
}
|
|
@@ -2201,4 +2336,4 @@ async function prefetchBundles(keys) {
|
|
|
2201
2336
|
await Promise.all(keys.map((key) => getBundle(key)));
|
|
2202
2337
|
}
|
|
2203
2338
|
|
|
2204
|
-
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, buildFlagContext, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createServerClient, createWebhookHandler, createWebhookRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, parseWebhookEvent, prefetchBundles, prefetchSecrets, registerVideoWebhook, requireAppSecret, requireBundle, requireSession, resolveGatewayUrl, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, verifyWebhookSignature, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
|
2339
|
+
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, buildFlagContext, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createPushRoutes, createServerClient, createWebhookHandler, createWebhookRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, parseWebhookEvent, prefetchBundles, prefetchSecrets, registerVideoWebhook, requireAppSecret, requireBundle, requireSession, resolveGatewayUrl, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, verifyWebhookSignature, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../index-
|
|
1
|
+
export { g as createWebhookHandler } from '../webhook-handler-Cz9jtet2.mjs';
|
|
2
|
+
import '../index-BoENfro3.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../index-
|
|
1
|
+
export { g as createWebhookHandler } from '../webhook-handler-CjSSCdvI.js';
|
|
2
|
+
import '../index-BoENfro3.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,
|
|
3
|
+
import { U as User, A as ApiError, a8 as StorageFile } from './index-BoENfro3.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,
|
|
3
|
+
import { U as User, A as ApiError, a8 as StorageFile } from './index-BoENfro3.js';
|
|
4
4
|
|
|
5
5
|
interface MockUserOptions {
|
|
6
6
|
id?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a8 as StorageFile, ae as UploadResponse } from './index-BoENfro3.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Server-Side ScaleMule Client
|
|
@@ -776,4 +776,4 @@ type RouteHandler = (request: Request) => Promise<Response>;
|
|
|
776
776
|
*/
|
|
777
777
|
declare function createWebhookHandler(config?: WebhookHandlerConfig): RouteHandler;
|
|
778
778
|
|
|
779
|
-
export { type ServerConfig as S, type
|
|
779
|
+
export { type ServerConfig as S, type VideoFailedEvent as V, type WebhookEvent as W, ScaleMuleServer as a, type VideoReadyEvent as b, type VideoTranscodedEvent as c, type VideoUploadedEvent as d, type WebhookRoutesConfig as e, createServerClient as f, createWebhookHandler as g, createWebhookRoutes as h, resolveGatewayUrl as i, parseWebhookEvent as p, registerVideoWebhook as r, verifyWebhookSignature as v };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a8 as StorageFile, ae as UploadResponse } from './index-BoENfro3.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Server-Side ScaleMule Client
|
|
@@ -776,4 +776,4 @@ type RouteHandler = (request: Request) => Promise<Response>;
|
|
|
776
776
|
*/
|
|
777
777
|
declare function createWebhookHandler(config?: WebhookHandlerConfig): RouteHandler;
|
|
778
778
|
|
|
779
|
-
export { type ServerConfig as S, type
|
|
779
|
+
export { type ServerConfig as S, type VideoFailedEvent as V, type WebhookEvent as W, ScaleMuleServer as a, type VideoReadyEvent as b, type VideoTranscodedEvent as c, type VideoUploadedEvent as d, type WebhookRoutesConfig as e, createServerClient as f, createWebhookHandler as g, createWebhookRoutes as h, resolveGatewayUrl as i, parseWebhookEvent as p, registerVideoWebhook as r, verifyWebhookSignature as v };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalemule/nextjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
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",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"clean": "rm -rf dist"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@scalemule/sdk": "
|
|
55
|
+
"@scalemule/sdk": ">=0.0.23"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"next": ">=14.0.0",
|