MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseV2Edge

Function parseV2Edge

apps/cloud/src/edge/marketing.ts:266–304  ·  view source on GitHub ↗
(env: V2EdgeEnv)

Source from the content-addressed store, hash-verified

264 * v1 state, or a telemetry path of the wrong shape.
265 */
266export const parseV2Edge = (env: V2EdgeEnv): V2Edge | string | null => {
267 const service = env.V2;
268 const signUpUrl = env.V2_SIGN_UP_URL;
269 const oauthStatePrefix = env.V2_OAUTH_STATE_PREFIX;
270 const analyticsProxyPath = env.V2_ANALYTICS_PROXY_PATH;
271 const errorTunnelPath = env.V2_ERROR_TUNNEL_PATH;
272 if (
273 service === undefined &&
274 signUpUrl === undefined &&
275 oauthStatePrefix === undefined &&
276 analyticsProxyPath === undefined &&
277 errorTunnelPath === undefined
278 ) {
279 return null;
280 }
281 if (
282 service === undefined ||
283 signUpUrl === undefined ||
284 oauthStatePrefix === undefined ||
285 analyticsProxyPath === undefined ||
286 errorTunnelPath === undefined
287 ) {
288 return "The V2 binding, V2_SIGN_UP_URL, V2_OAUTH_STATE_PREFIX, V2_ANALYTICS_PROXY_PATH and V2_ERROR_TUNNEL_PATH must be set together";
289 }
290 const parsed = URL.parse(signUpUrl);
291 if (parsed === null || (parsed.protocol !== "https:" && parsed.protocol !== "http:")) {
292 return "V2_SIGN_UP_URL must be an absolute http(s) URL";
293 }
294 if (!OAUTH_STATE_PREFIX_PATTERN.test(oauthStatePrefix)) {
295 return "V2_OAUTH_STATE_PREFIX must be URL-safe and contain '.' or '~'";
296 }
297 if (!ANALYTICS_PROXY_PATH_PATTERN.test(analyticsProxyPath)) {
298 return "V2_ANALYTICS_PROXY_PATH must be /api/<16 lowercase hex>";
299 }
300 if (!ERROR_TUNNEL_PATH_PATTERN.test(errorTunnelPath)) {
301 return "V2_ERROR_TUNNEL_PATH must be /api/<16 lowercase hex>/submit";
302 }
303 return { service, signUpUrl: parsed, oauthStatePrefix, analyticsProxyPath, errorTunnelPath };
304};
305
306/** Whether a connected-account callback carries v2's state prefix. Reads the
307 * query only: a callback without `state` in its query stays with v1. */

Callers 4

v2AppOriginFunction · 0.90
marketing.test.tsFile · 0.90
v2EdgeResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected