UNPKG

rivetkit

Version:

Lightweight libraries for building stateful actors on edge platforms

103 lines (86 loc) 4.1 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _chunkYKVTF7MPcjs = require('./chunk-YKVTF7MP.cjs'); // src/inspector/protocol/actor.ts var _client = require('hono/client'); var client = _client.hc.call(void 0, ""); var createActorInspectorClient = (...args) => _client.hc.call(void 0, ...args); // src/inspector/protocol/manager.ts var client2 = _client.hc.call(void 0, ""); var createManagerInspectorClient = (...args) => _client.hc.call(void 0, ...args); // src/inspector/utils.ts var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto); var _factory = require('hono/factory'); // src/inspector/log.ts function inspectorLogger() { return _chunkYKVTF7MPcjs.getLogger.call(void 0, "inspector"); } // src/inspector/utils.ts function compareSecrets(providedSecret, validSecret) { if (providedSecret.length !== validSecret.length) { return false; } const encoder = new TextEncoder(); const a = encoder.encode(providedSecret); const b = encoder.encode(validSecret); if (a.byteLength !== b.byteLength) { return false; } if (!_crypto2.default.timingSafeEqual(a, b)) { return false; } return true; } var secureInspector = (runConfig) => _factory.createMiddleware.call(void 0, async (c, next) => { var _a, _b, _c; const userToken = (_a = c.req.header("Authorization")) == null ? void 0 : _a.replace("Bearer ", ""); if (!userToken) { return c.text("Unauthorized", 401); } const inspectorToken = (_c = (_b = runConfig.inspector).token) == null ? void 0 : _c.call(_b); if (!inspectorToken) { return c.text("Unauthorized", 401); } const isValid = compareSecrets(userToken, inspectorToken); if (!isValid) { return c.text("Unauthorized", 401); } await next(); }); function getInspectorUrl(runConfig) { var _a, _b, _c, _d; if (!((_a = runConfig == null ? void 0 : runConfig.inspector) == null ? void 0 : _a.enabled)) { return "disabled"; } const accessToken = (_c = (_b = runConfig == null ? void 0 : runConfig.inspector) == null ? void 0 : _b.token) == null ? void 0 : _c.call(_b); if (!accessToken) { inspectorLogger().warn( "Inspector Token is not set, but Inspector is enabled. Please set it in the run configuration `inspector.token` or via `RIVETKIT_INSPECTOR_TOKEN` environment variable. Inspector will not be accessible." ); return "disabled"; } const url = new URL("https://inspect.rivet.dev"); url.searchParams.set("t", accessToken); const overrideDefaultEndpoint = _nullishCoalesce(((_d = runConfig == null ? void 0 : runConfig.inspector) == null ? void 0 : _d.defaultEndpoint), () => ( runConfig.overrideServerAddress)); if (overrideDefaultEndpoint) { url.searchParams.set("u", overrideDefaultEndpoint); } return url.href; } var isInspectorEnabled = (runConfig, context) => { var _a, _b; if (typeof ((_a = runConfig.inspector) == null ? void 0 : _a.enabled) === "boolean") { return runConfig.inspector.enabled; } else if (typeof ((_b = runConfig.inspector) == null ? void 0 : _b.enabled) === "object") { return runConfig.inspector.enabled[context]; } return false; }; var configureInspectorAccessToken = (runConfig, managerDriver) => { var _a; if (!((_a = runConfig.inspector) == null ? void 0 : _a.token())) { const token = managerDriver.getOrCreateInspectorAccessToken(); runConfig.inspector.token = () => token; } }; exports.inspectorLogger = inspectorLogger; exports.compareSecrets = compareSecrets; exports.secureInspector = secureInspector; exports.getInspectorUrl = getInspectorUrl; exports.isInspectorEnabled = isInspectorEnabled; exports.configureInspectorAccessToken = configureInspectorAccessToken; exports.createActorInspectorClient = createActorInspectorClient; exports.createManagerInspectorClient = createManagerInspectorClient; //# sourceMappingURL=chunk-SIWYIRXP.cjs.map