@scalemule/nextjs 0.0.12 → 0.0.14
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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -4
- package/dist/index.mjs +16 -4
- package/dist/server/index.d.mts +8 -11
- package/dist/server/index.d.ts +8 -11
- package/dist/server/index.js +67 -14
- package/dist/server/index.mjs +67 -15
- package/dist/server/webhook-handler.d.mts +1 -1
- package/dist/server/webhook-handler.d.ts +1 -1
- package/dist/{webhook-handler-CweF_nT3.d.mts → webhook-handler-CN_N2XlA.d.mts} +2 -1
- package/dist/{webhook-handler-Bi3bMNty.d.ts → webhook-handler-DrC9rOoh.d.ts} +2 -1
- package/package.json +4 -1
package/dist/index.d.mts
CHANGED
|
@@ -26,6 +26,8 @@ interface ScaleMuleContextValue {
|
|
|
26
26
|
publishableKey?: string;
|
|
27
27
|
/** Gateway URL for direct API calls */
|
|
28
28
|
gatewayUrl?: string;
|
|
29
|
+
/** Configured environment ('dev' or 'prod') */
|
|
30
|
+
environment?: string;
|
|
29
31
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
30
32
|
bootstrapFlags?: Record<string, unknown>;
|
|
31
33
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ interface ScaleMuleContextValue {
|
|
|
26
26
|
publishableKey?: string;
|
|
27
27
|
/** Gateway URL for direct API calls */
|
|
28
28
|
gatewayUrl?: string;
|
|
29
|
+
/** Configured environment ('dev' or 'prod') */
|
|
30
|
+
environment?: string;
|
|
29
31
|
/** Server-evaluated flag values to bootstrap the client (eliminates loading flash) */
|
|
30
32
|
bootstrapFlags?: Record<string, unknown>;
|
|
31
33
|
}
|
package/dist/index.js
CHANGED
|
@@ -931,6 +931,7 @@ function ScaleMuleProvider({
|
|
|
931
931
|
authProxyUrl,
|
|
932
932
|
publishableKey,
|
|
933
933
|
gatewayUrl: gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com"),
|
|
934
|
+
environment: environment || void 0,
|
|
934
935
|
bootstrapFlags
|
|
935
936
|
}),
|
|
936
937
|
[client, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, gatewayUrl, environment, bootstrapFlags]
|
|
@@ -2847,13 +2848,14 @@ function toApiError(error) {
|
|
|
2847
2848
|
};
|
|
2848
2849
|
}
|
|
2849
2850
|
function useFeatureFlags(options = {}) {
|
|
2851
|
+
const smContext = useScaleMule();
|
|
2850
2852
|
const {
|
|
2851
|
-
environment = "prod",
|
|
2853
|
+
environment = smContext.environment ?? "prod",
|
|
2852
2854
|
context = {},
|
|
2853
2855
|
keys,
|
|
2854
2856
|
enabled = true
|
|
2855
2857
|
} = options;
|
|
2856
|
-
const { client, publishableKey, gatewayUrl, bootstrapFlags } =
|
|
2858
|
+
const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
|
|
2857
2859
|
const initialFlags = react.useMemo(() => {
|
|
2858
2860
|
if (!bootstrapFlags) return {};
|
|
2859
2861
|
const result = {};
|
|
@@ -2908,9 +2910,19 @@ function useFeatureFlags(options = {}) {
|
|
|
2908
2910
|
setLoading(false);
|
|
2909
2911
|
}
|
|
2910
2912
|
}, [client, enabled, environment, keys, keysKey, publishableKey, gatewayUrl]);
|
|
2913
|
+
const bootstrapCoversKeys = react.useMemo(() => {
|
|
2914
|
+
if (!hasBootstrap || !keys || keys.length === 0) return false;
|
|
2915
|
+
if (!keys.every((k) => k in initialFlags)) return false;
|
|
2916
|
+
if (environment !== (smContext.environment ?? "prod")) return false;
|
|
2917
|
+
const contextKeys = Object.keys(context).filter((k) => k !== "ip_address");
|
|
2918
|
+
if (contextKeys.length > 0) return false;
|
|
2919
|
+
return true;
|
|
2920
|
+
}, [hasBootstrap, keys, initialFlags, environment, smContext.environment, context]);
|
|
2911
2921
|
react.useEffect(() => {
|
|
2912
|
-
|
|
2913
|
-
|
|
2922
|
+
if (!bootstrapCoversKeys) {
|
|
2923
|
+
void refresh();
|
|
2924
|
+
}
|
|
2925
|
+
}, [refresh, bootstrapCoversKeys]);
|
|
2914
2926
|
const isEnabled = react.useCallback(
|
|
2915
2927
|
(flagKey, fallback = false) => {
|
|
2916
2928
|
const evaluation = flags[flagKey];
|
package/dist/index.mjs
CHANGED
|
@@ -929,6 +929,7 @@ function ScaleMuleProvider({
|
|
|
929
929
|
authProxyUrl,
|
|
930
930
|
publishableKey,
|
|
931
931
|
gatewayUrl: gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com"),
|
|
932
|
+
environment: environment || void 0,
|
|
932
933
|
bootstrapFlags
|
|
933
934
|
}),
|
|
934
935
|
[client, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, gatewayUrl, environment, bootstrapFlags]
|
|
@@ -2845,13 +2846,14 @@ function toApiError(error) {
|
|
|
2845
2846
|
};
|
|
2846
2847
|
}
|
|
2847
2848
|
function useFeatureFlags(options = {}) {
|
|
2849
|
+
const smContext = useScaleMule();
|
|
2848
2850
|
const {
|
|
2849
|
-
environment = "prod",
|
|
2851
|
+
environment = smContext.environment ?? "prod",
|
|
2850
2852
|
context = {},
|
|
2851
2853
|
keys,
|
|
2852
2854
|
enabled = true
|
|
2853
2855
|
} = options;
|
|
2854
|
-
const { client, publishableKey, gatewayUrl, bootstrapFlags } =
|
|
2856
|
+
const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
|
|
2855
2857
|
const initialFlags = useMemo(() => {
|
|
2856
2858
|
if (!bootstrapFlags) return {};
|
|
2857
2859
|
const result = {};
|
|
@@ -2906,9 +2908,19 @@ function useFeatureFlags(options = {}) {
|
|
|
2906
2908
|
setLoading(false);
|
|
2907
2909
|
}
|
|
2908
2910
|
}, [client, enabled, environment, keys, keysKey, publishableKey, gatewayUrl]);
|
|
2911
|
+
const bootstrapCoversKeys = useMemo(() => {
|
|
2912
|
+
if (!hasBootstrap || !keys || keys.length === 0) return false;
|
|
2913
|
+
if (!keys.every((k) => k in initialFlags)) return false;
|
|
2914
|
+
if (environment !== (smContext.environment ?? "prod")) return false;
|
|
2915
|
+
const contextKeys = Object.keys(context).filter((k) => k !== "ip_address");
|
|
2916
|
+
if (contextKeys.length > 0) return false;
|
|
2917
|
+
return true;
|
|
2918
|
+
}, [hasBootstrap, keys, initialFlags, environment, smContext.environment, context]);
|
|
2909
2919
|
useEffect(() => {
|
|
2910
|
-
|
|
2911
|
-
|
|
2920
|
+
if (!bootstrapCoversKeys) {
|
|
2921
|
+
void refresh();
|
|
2922
|
+
}
|
|
2923
|
+
}, [refresh, bootstrapCoversKeys]);
|
|
2912
2924
|
const isEnabled = useCallback(
|
|
2913
2925
|
(flagKey, fallback = false) => {
|
|
2914
2926
|
const evaluation = flags[flagKey];
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer,
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-CN_N2XlA.mjs';
|
|
2
|
+
export { a as ScaleMuleServer, e as VideoFailedEvent, V as VideoReadyEvent, g as VideoTranscodedEvent, f as VideoUploadedEvent, W as WebhookEvent, h as WebhookRoutesConfig, c as createServerClient, i as createWebhookHandler, d as createWebhookRoutes, p as parseWebhookEvent, b as registerVideoWebhook, r as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-CN_N2XlA.mjs';
|
|
3
3
|
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.mjs';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
@@ -436,8 +436,8 @@ declare function apiHandler(handler: HandlerFn, options?: HandlerOptions): (requ
|
|
|
436
436
|
/**
|
|
437
437
|
* Server-side flag bootstrapping for Next.js layouts.
|
|
438
438
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
439
|
+
* Uses @scalemule/sdk FlagClient for local evaluation — ZERO API calls per SSR render.
|
|
440
|
+
* Falls back to legacy evaluateBatch API call if FlagClient init fails.
|
|
441
441
|
*
|
|
442
442
|
* @example
|
|
443
443
|
* ```ts
|
|
@@ -457,18 +457,15 @@ declare function apiHandler(handler: HandlerFn, options?: HandlerOptions): (requ
|
|
|
457
457
|
/**
|
|
458
458
|
* Evaluate feature flags server-side for bootstrapping the client provider.
|
|
459
459
|
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* rules work correctly.
|
|
463
|
-
*
|
|
464
|
-
* Returns a Record that can be passed directly to ScaleMuleProvider's
|
|
465
|
-
* bootstrapFlags prop.
|
|
460
|
+
* Uses local evaluation via FlagClient (zero network calls per render).
|
|
461
|
+
* Falls back to legacy API if FlagClient is unavailable.
|
|
466
462
|
*
|
|
467
463
|
* @param flagKeys - Array of flag keys to evaluate
|
|
468
464
|
* @param environment - Environment name (default: 'prod')
|
|
469
465
|
* @param extraContext - Additional context attributes to include
|
|
466
|
+
* @param cacheTtlMs - Deprecated (ignored). FlagClient handles caching internally.
|
|
470
467
|
*/
|
|
471
|
-
declare function getBootstrapFlags(flagKeys: string[], environment?: string, extraContext?: Record<string, unknown
|
|
468
|
+
declare function getBootstrapFlags(flagKeys: string[], environment?: string, extraContext?: Record<string, unknown>, cacheTtlMs?: number): Promise<Record<string, unknown>>;
|
|
472
469
|
|
|
473
470
|
/**
|
|
474
471
|
* Next.js Middleware Helpers
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer,
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-DrC9rOoh.js';
|
|
2
|
+
export { a as ScaleMuleServer, e as VideoFailedEvent, V as VideoReadyEvent, g as VideoTranscodedEvent, f as VideoUploadedEvent, W as WebhookEvent, h as WebhookRoutesConfig, c as createServerClient, i as createWebhookHandler, d as createWebhookRoutes, p as parseWebhookEvent, b as registerVideoWebhook, r as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-DrC9rOoh.js';
|
|
3
3
|
import { $ as ClientContext, L as LoginResponse, A as ApiError } from '../index-jomBa89d.js';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
@@ -436,8 +436,8 @@ declare function apiHandler(handler: HandlerFn, options?: HandlerOptions): (requ
|
|
|
436
436
|
/**
|
|
437
437
|
* Server-side flag bootstrapping for Next.js layouts.
|
|
438
438
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
439
|
+
* Uses @scalemule/sdk FlagClient for local evaluation — ZERO API calls per SSR render.
|
|
440
|
+
* Falls back to legacy evaluateBatch API call if FlagClient init fails.
|
|
441
441
|
*
|
|
442
442
|
* @example
|
|
443
443
|
* ```ts
|
|
@@ -457,18 +457,15 @@ declare function apiHandler(handler: HandlerFn, options?: HandlerOptions): (requ
|
|
|
457
457
|
/**
|
|
458
458
|
* Evaluate feature flags server-side for bootstrapping the client provider.
|
|
459
459
|
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* rules work correctly.
|
|
463
|
-
*
|
|
464
|
-
* Returns a Record that can be passed directly to ScaleMuleProvider's
|
|
465
|
-
* bootstrapFlags prop.
|
|
460
|
+
* Uses local evaluation via FlagClient (zero network calls per render).
|
|
461
|
+
* Falls back to legacy API if FlagClient is unavailable.
|
|
466
462
|
*
|
|
467
463
|
* @param flagKeys - Array of flag keys to evaluate
|
|
468
464
|
* @param environment - Environment name (default: 'prod')
|
|
469
465
|
* @param extraContext - Additional context attributes to include
|
|
466
|
+
* @param cacheTtlMs - Deprecated (ignored). FlagClient handles caching internally.
|
|
470
467
|
*/
|
|
471
|
-
declare function getBootstrapFlags(flagKeys: string[], environment?: string, extraContext?: Record<string, unknown
|
|
468
|
+
declare function getBootstrapFlags(flagKeys: string[], environment?: string, extraContext?: Record<string, unknown>, cacheTtlMs?: number): Promise<Record<string, unknown>>;
|
|
472
469
|
|
|
473
470
|
/**
|
|
474
471
|
* Next.js Middleware Helpers
|
package/dist/server/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var headers = require('next/headers');
|
|
4
4
|
var server = require('next/server');
|
|
5
5
|
var crypto$1 = require('crypto');
|
|
6
|
+
var server$1 = require('@scalemule/sdk/flags/server');
|
|
6
7
|
|
|
7
8
|
// src/types/index.ts
|
|
8
9
|
var ScaleMuleApiError = class extends Error {
|
|
@@ -1765,29 +1766,80 @@ function createWebhookHandler(config = {}) {
|
|
|
1765
1766
|
}
|
|
1766
1767
|
};
|
|
1767
1768
|
}
|
|
1769
|
+
var _clients = /* @__PURE__ */ new Map();
|
|
1770
|
+
var _initPromises = /* @__PURE__ */ new Map();
|
|
1768
1771
|
var _serverClient = null;
|
|
1769
|
-
function
|
|
1772
|
+
function getServerClient() {
|
|
1770
1773
|
if (!_serverClient) {
|
|
1771
1774
|
_serverClient = createServerClient();
|
|
1772
1775
|
}
|
|
1773
1776
|
return _serverClient;
|
|
1774
1777
|
}
|
|
1775
|
-
|
|
1778
|
+
var GATEWAY_URLS2 = {
|
|
1779
|
+
dev: "https://api-dev.scalemule.com",
|
|
1780
|
+
prod: "https://api.scalemule.com"
|
|
1781
|
+
};
|
|
1782
|
+
function resolveGatewayUrl2() {
|
|
1783
|
+
if (process.env.SCALEMULE_API_URL) return process.env.SCALEMULE_API_URL;
|
|
1784
|
+
const env = process.env.SCALEMULE_ENV || "prod";
|
|
1785
|
+
return GATEWAY_URLS2[env] || GATEWAY_URLS2.prod;
|
|
1786
|
+
}
|
|
1787
|
+
async function getFlagClient(environment) {
|
|
1788
|
+
const apiKey = process.env.SCALEMULE_API_KEY;
|
|
1789
|
+
const gatewayUrl = resolveGatewayUrl2();
|
|
1790
|
+
const key = `${environment}:${gatewayUrl}`;
|
|
1791
|
+
const existing = _clients.get(key);
|
|
1792
|
+
if (existing) return existing;
|
|
1793
|
+
const pending = _initPromises.get(key);
|
|
1794
|
+
if (pending) return pending;
|
|
1795
|
+
const promise = (async () => {
|
|
1796
|
+
const client = new server$1.FlagClient({ apiKey, environment, gatewayUrl });
|
|
1797
|
+
await client.init();
|
|
1798
|
+
_clients.set(key, client);
|
|
1799
|
+
return client;
|
|
1800
|
+
})();
|
|
1801
|
+
_initPromises.set(key, promise);
|
|
1776
1802
|
try {
|
|
1803
|
+
return await promise;
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
_initPromises.delete(key);
|
|
1806
|
+
throw e;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
var _shutdownRegistered = false;
|
|
1810
|
+
function ensureShutdownHook() {
|
|
1811
|
+
if (_shutdownRegistered) return;
|
|
1812
|
+
_shutdownRegistered = true;
|
|
1813
|
+
process.once("SIGTERM", async () => {
|
|
1814
|
+
const shutdowns = Array.from(_clients.values()).map((c) => c.shutdown());
|
|
1815
|
+
await Promise.allSettled(shutdowns);
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
function extractClientIp(hdrs) {
|
|
1819
|
+
const realIp = hdrs.get("x-real-ip") || hdrs.get("x-real-client-ip");
|
|
1820
|
+
const forwardedFor = hdrs.get("x-forwarded-for");
|
|
1821
|
+
return realIp || (forwardedFor ? forwardedFor.split(",")[0].trim() : void 0);
|
|
1822
|
+
}
|
|
1823
|
+
async function getBootstrapFlags(flagKeys, environment = "prod", extraContext = {}, cacheTtlMs = 0) {
|
|
1824
|
+
try {
|
|
1825
|
+
const client = await getFlagClient(environment);
|
|
1826
|
+
ensureShutdownHook();
|
|
1777
1827
|
const hdrs = await headers.headers();
|
|
1778
|
-
const
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
...extraContext
|
|
1783
|
-
};
|
|
1784
|
-
if (clientIp) {
|
|
1785
|
-
context.ip_address = clientIp;
|
|
1786
|
-
}
|
|
1787
|
-
const result = await getClient().flags.evaluateBatch(flagKeys, context, environment);
|
|
1788
|
-
return result || {};
|
|
1828
|
+
const clientIp = extractClientIp(hdrs);
|
|
1829
|
+
const context = { ...extraContext };
|
|
1830
|
+
if (clientIp) context.ip_address = clientIp;
|
|
1831
|
+
return client.evaluateBatch(flagKeys, context);
|
|
1789
1832
|
} catch {
|
|
1790
|
-
|
|
1833
|
+
try {
|
|
1834
|
+
const hdrs = await headers.headers();
|
|
1835
|
+
const clientIp = extractClientIp(hdrs);
|
|
1836
|
+
const context = { ...extraContext };
|
|
1837
|
+
if (clientIp) context.ip_address = clientIp;
|
|
1838
|
+
const result = await getServerClient().flags.evaluateBatch(flagKeys, context, environment);
|
|
1839
|
+
return result || {};
|
|
1840
|
+
} catch {
|
|
1841
|
+
return {};
|
|
1842
|
+
}
|
|
1791
1843
|
}
|
|
1792
1844
|
}
|
|
1793
1845
|
function globToRegex(pattern) {
|
|
@@ -2122,6 +2174,7 @@ exports.registerVideoWebhook = registerVideoWebhook;
|
|
|
2122
2174
|
exports.requireAppSecret = requireAppSecret;
|
|
2123
2175
|
exports.requireBundle = requireBundle;
|
|
2124
2176
|
exports.requireSession = requireSession;
|
|
2177
|
+
exports.resolveGatewayUrl = resolveGatewayUrl;
|
|
2125
2178
|
exports.setOAuthState = setOAuthState;
|
|
2126
2179
|
exports.unwrap = unwrap;
|
|
2127
2180
|
exports.validateCSRFToken = validateCSRFToken;
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cookies, headers } from 'next/headers';
|
|
2
2
|
import { NextResponse } from 'next/server';
|
|
3
3
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
4
|
+
import { FlagClient } from '@scalemule/sdk/flags/server';
|
|
4
5
|
|
|
5
6
|
// src/types/index.ts
|
|
6
7
|
var ScaleMuleApiError = class extends Error {
|
|
@@ -1763,29 +1764,80 @@ function createWebhookHandler(config = {}) {
|
|
|
1763
1764
|
}
|
|
1764
1765
|
};
|
|
1765
1766
|
}
|
|
1767
|
+
var _clients = /* @__PURE__ */ new Map();
|
|
1768
|
+
var _initPromises = /* @__PURE__ */ new Map();
|
|
1766
1769
|
var _serverClient = null;
|
|
1767
|
-
function
|
|
1770
|
+
function getServerClient() {
|
|
1768
1771
|
if (!_serverClient) {
|
|
1769
1772
|
_serverClient = createServerClient();
|
|
1770
1773
|
}
|
|
1771
1774
|
return _serverClient;
|
|
1772
1775
|
}
|
|
1773
|
-
|
|
1776
|
+
var GATEWAY_URLS2 = {
|
|
1777
|
+
dev: "https://api-dev.scalemule.com",
|
|
1778
|
+
prod: "https://api.scalemule.com"
|
|
1779
|
+
};
|
|
1780
|
+
function resolveGatewayUrl2() {
|
|
1781
|
+
if (process.env.SCALEMULE_API_URL) return process.env.SCALEMULE_API_URL;
|
|
1782
|
+
const env = process.env.SCALEMULE_ENV || "prod";
|
|
1783
|
+
return GATEWAY_URLS2[env] || GATEWAY_URLS2.prod;
|
|
1784
|
+
}
|
|
1785
|
+
async function getFlagClient(environment) {
|
|
1786
|
+
const apiKey = process.env.SCALEMULE_API_KEY;
|
|
1787
|
+
const gatewayUrl = resolveGatewayUrl2();
|
|
1788
|
+
const key = `${environment}:${gatewayUrl}`;
|
|
1789
|
+
const existing = _clients.get(key);
|
|
1790
|
+
if (existing) return existing;
|
|
1791
|
+
const pending = _initPromises.get(key);
|
|
1792
|
+
if (pending) return pending;
|
|
1793
|
+
const promise = (async () => {
|
|
1794
|
+
const client = new FlagClient({ apiKey, environment, gatewayUrl });
|
|
1795
|
+
await client.init();
|
|
1796
|
+
_clients.set(key, client);
|
|
1797
|
+
return client;
|
|
1798
|
+
})();
|
|
1799
|
+
_initPromises.set(key, promise);
|
|
1774
1800
|
try {
|
|
1801
|
+
return await promise;
|
|
1802
|
+
} catch (e) {
|
|
1803
|
+
_initPromises.delete(key);
|
|
1804
|
+
throw e;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
var _shutdownRegistered = false;
|
|
1808
|
+
function ensureShutdownHook() {
|
|
1809
|
+
if (_shutdownRegistered) return;
|
|
1810
|
+
_shutdownRegistered = true;
|
|
1811
|
+
process.once("SIGTERM", async () => {
|
|
1812
|
+
const shutdowns = Array.from(_clients.values()).map((c) => c.shutdown());
|
|
1813
|
+
await Promise.allSettled(shutdowns);
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
function extractClientIp(hdrs) {
|
|
1817
|
+
const realIp = hdrs.get("x-real-ip") || hdrs.get("x-real-client-ip");
|
|
1818
|
+
const forwardedFor = hdrs.get("x-forwarded-for");
|
|
1819
|
+
return realIp || (forwardedFor ? forwardedFor.split(",")[0].trim() : void 0);
|
|
1820
|
+
}
|
|
1821
|
+
async function getBootstrapFlags(flagKeys, environment = "prod", extraContext = {}, cacheTtlMs = 0) {
|
|
1822
|
+
try {
|
|
1823
|
+
const client = await getFlagClient(environment);
|
|
1824
|
+
ensureShutdownHook();
|
|
1775
1825
|
const hdrs = await headers();
|
|
1776
|
-
const
|
|
1777
|
-
const
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
...extraContext
|
|
1781
|
-
};
|
|
1782
|
-
if (clientIp) {
|
|
1783
|
-
context.ip_address = clientIp;
|
|
1784
|
-
}
|
|
1785
|
-
const result = await getClient().flags.evaluateBatch(flagKeys, context, environment);
|
|
1786
|
-
return result || {};
|
|
1826
|
+
const clientIp = extractClientIp(hdrs);
|
|
1827
|
+
const context = { ...extraContext };
|
|
1828
|
+
if (clientIp) context.ip_address = clientIp;
|
|
1829
|
+
return client.evaluateBatch(flagKeys, context);
|
|
1787
1830
|
} catch {
|
|
1788
|
-
|
|
1831
|
+
try {
|
|
1832
|
+
const hdrs = await headers();
|
|
1833
|
+
const clientIp = extractClientIp(hdrs);
|
|
1834
|
+
const context = { ...extraContext };
|
|
1835
|
+
if (clientIp) context.ip_address = clientIp;
|
|
1836
|
+
const result = await getServerClient().flags.evaluateBatch(flagKeys, context, environment);
|
|
1837
|
+
return result || {};
|
|
1838
|
+
} catch {
|
|
1839
|
+
return {};
|
|
1840
|
+
}
|
|
1789
1841
|
}
|
|
1790
1842
|
}
|
|
1791
1843
|
function globToRegex(pattern) {
|
|
@@ -2075,4 +2127,4 @@ async function prefetchBundles(keys) {
|
|
|
2075
2127
|
await Promise.all(keys.map((key) => getBundle(key)));
|
|
2076
2128
|
}
|
|
2077
2129
|
|
|
2078
|
-
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, 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, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, verifyWebhookSignature, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
|
2130
|
+
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, 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 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { i as createWebhookHandler } from '../webhook-handler-CN_N2XlA.mjs';
|
|
2
2
|
import '../index-jomBa89d.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { i as createWebhookHandler } from '../webhook-handler-DrC9rOoh.js';
|
|
2
2
|
import '../index-jomBa89d.js';
|
|
@@ -18,6 +18,7 @@ interface ServerConfig {
|
|
|
18
18
|
/** Enable debug logging */
|
|
19
19
|
debug?: boolean;
|
|
20
20
|
}
|
|
21
|
+
declare function resolveGatewayUrl(config: ServerConfig): string;
|
|
21
22
|
declare class ScaleMuleServer {
|
|
22
23
|
private apiKey;
|
|
23
24
|
private gatewayUrl;
|
|
@@ -771,4 +772,4 @@ type RouteHandler = (request: Request) => Promise<Response>;
|
|
|
771
772
|
*/
|
|
772
773
|
declare function createWebhookHandler(config?: WebhookHandlerConfig): RouteHandler;
|
|
773
774
|
|
|
774
|
-
export { type ServerConfig as S, type VideoReadyEvent as V, type WebhookEvent as W, ScaleMuleServer as a,
|
|
775
|
+
export { type ServerConfig as S, type VideoReadyEvent as V, type WebhookEvent as W, ScaleMuleServer as a, registerVideoWebhook as b, createServerClient as c, createWebhookRoutes as d, type VideoFailedEvent as e, type VideoUploadedEvent as f, type VideoTranscodedEvent as g, type WebhookRoutesConfig as h, createWebhookHandler as i, parseWebhookEvent as p, resolveGatewayUrl as r, verifyWebhookSignature as v };
|
|
@@ -18,6 +18,7 @@ interface ServerConfig {
|
|
|
18
18
|
/** Enable debug logging */
|
|
19
19
|
debug?: boolean;
|
|
20
20
|
}
|
|
21
|
+
declare function resolveGatewayUrl(config: ServerConfig): string;
|
|
21
22
|
declare class ScaleMuleServer {
|
|
22
23
|
private apiKey;
|
|
23
24
|
private gatewayUrl;
|
|
@@ -771,4 +772,4 @@ type RouteHandler = (request: Request) => Promise<Response>;
|
|
|
771
772
|
*/
|
|
772
773
|
declare function createWebhookHandler(config?: WebhookHandlerConfig): RouteHandler;
|
|
773
774
|
|
|
774
|
-
export { type ServerConfig as S, type VideoReadyEvent as V, type WebhookEvent as W, ScaleMuleServer as a,
|
|
775
|
+
export { type ServerConfig as S, type VideoReadyEvent as V, type WebhookEvent as W, ScaleMuleServer as a, registerVideoWebhook as b, createServerClient as c, createWebhookRoutes as d, type VideoFailedEvent as e, type VideoUploadedEvent as f, type VideoTranscodedEvent as g, type WebhookRoutesConfig as h, createWebhookHandler as i, parseWebhookEvent as p, resolveGatewayUrl 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.14",
|
|
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",
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"lint": "eslint src --ext .ts,.tsx",
|
|
52
52
|
"clean": "rm -rf dist"
|
|
53
53
|
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@scalemule/sdk": "^0.0.14"
|
|
56
|
+
},
|
|
54
57
|
"peerDependencies": {
|
|
55
58
|
"next": ">=14.0.0",
|
|
56
59
|
"react": ">=18.0.0",
|