@zapier/policy-context 0.9.0 → 1.0.0
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.cjs +262 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +163 -37
- package/dist/index.d.ts +163 -37
- package/dist/index.js +256 -111
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/constants.ts","../src/builders.ts","../src/conditions.ts","../src/policies.ts","../src/connection-policy.ts"],"sourcesContent":["// ABOUTME: Public API for @zapier/policy-context.\n// ABOUTME: Shared context types, builders, and condition generators for sdkapi + approvalsapi.\n\nexport {\n HttpRequestContextSchema,\n ActionRunContextSchema,\n RequestContextSchema,\n JsonValueSchema,\n ParsedUrlSchema,\n DEFAULT_PORTS,\n parseUrl,\n buildUrlString,\n type HttpRequestContext,\n type ActionRunContext,\n type RequestContext,\n type ParsedUrl,\n} from \"./types.ts\";\n\nexport { IGNORED_HEADERS } from \"./constants.ts\";\n\nexport {\n buildHttpRequestContext,\n buildActionRunContext,\n BuildHttpRequestContextOptionsSchema,\n BuildActionRunContextOptionsSchema,\n type BuildHttpRequestContextOptions,\n type BuildActionRunContextOptions,\n} from \"./builders.ts\";\n\nexport {\n buildExactHttpConditions,\n buildDomainHttpConditions,\n buildExactActionConditions,\n buildActionResource,\n buildBroadActionResource,\n} from \"./conditions.ts\";\n\nexport { toExactPolicy } from \"./policies.ts\";\n\nexport {\n buildConnectionPolicy,\n AccessLevelSchema,\n type AccessLevel,\n} from \"./connection-policy.ts\";\n","// ABOUTME: Canonical request context types shared between sdkapi and approvalsapi.\n// ABOUTME: These define the contract for how requests are described in approval flows and policy evaluation.\n\nimport { z } from \"zod\";\nimport type { JsonValue } from \"@zapier/policy-schema\";\n\n/**\n * Zod schema for arbitrary JSON values. Used across context schemas for\n * unstructured fields like `body_json` and `inputs`.\n */\nexport const JsonValueSchema = z.custom<JsonValue>();\n\n/**\n * Parsed URL components for policy evaluation.\n * Matches the ParsedUrl shape from @zapier/policy-schema so that\n * evaluatePolicy condition paths like [\"url\", \"host\"] resolve correctly.\n */\nexport const ParsedUrlSchema = z.object({\n scheme: z.string(),\n host: z.string(),\n port: z.number(),\n path: z.string(),\n query: z.record(z.string(), z.array(z.string())),\n});\nexport type ParsedUrl = z.infer<typeof ParsedUrlSchema>;\n\n/** Default ports by scheme, used when URL has no explicit port. */\nexport const DEFAULT_PORTS: Record<string, number> = {\n http: 80,\n https: 443,\n};\n\n/**\n * Parse a raw URL string into a ParsedUrl.\n * Same logic as parseUrlForPolicyContext in @zapier/policy.\n */\nexport function parseUrl(raw: string): ParsedUrl {\n const url = new URL(raw);\n const scheme = url.protocol.slice(0, -1).toLowerCase();\n const host = url.hostname.toLowerCase();\n const port = url.port ? parseInt(url.port, 10) : (DEFAULT_PORTS[scheme] ?? 0);\n const path = url.pathname || \"/\";\n const query: Record<string, string[]> = {};\n for (const [key, value] of url.searchParams) {\n if (!query[key]) {\n query[key] = [];\n }\n query[key].push(value);\n }\n return { scheme, host, port, path, query };\n}\n\n/**\n * Reconstruct a URL string from a ParsedUrl.\n * Same logic as buildUrl in @zapier/policy.\n */\nexport function buildUrlString(parsed: ParsedUrl): string {\n const { scheme, host, port, path, query } = parsed;\n const defaultPort = DEFAULT_PORTS[scheme];\n const portString = port !== defaultPort ? `:${String(port)}` : \"\";\n const params = new URLSearchParams();\n for (const [key, values] of Object.entries(query)) {\n for (const value of values) {\n params.append(key, value);\n }\n }\n const queryString = params.toString();\n return `${scheme}://${host}${portString}${path}${queryString ? \"?\" + queryString : \"\"}`;\n}\n\n/**\n * HTTP request context for approval/policy flows.\n * Sent by sdkapi when a relay request is denied, stored by approvalsapi,\n * and used for both policy evaluation and building policy conditions.\n *\n * The url field is a ParsedUrl object (matching @zapier/policy-schema's ParsedUrl)\n * so that evaluatePolicy conditions like [\"url\", \"host\"] resolve correctly.\n */\nexport const HttpRequestContextSchema = z.object({\n request_type: z.literal(\"http_request\"),\n method: z.string(),\n /** Parsed URL components for policy condition matching */\n url: ParsedUrlSchema,\n /** Filtered headers (IGNORED_HEADERS excluded, keys lowercased) */\n headers: z.record(z.string(), z.string()),\n /** Raw body string */\n body: z.string().nullable(),\n /** Parsed JSON body */\n body_json: JsonValueSchema.nullable(),\n /** Zapier connection ID used for this request */\n connection_id: z.string().optional(),\n /** Optional human-readable reason for the request */\n reason: z.string().optional(),\n});\nexport type HttpRequestContext = z.infer<typeof HttpRequestContextSchema>;\n\n/**\n * Action run context for approval/policy flows.\n * Sent by sdkapi when an action run is denied, stored by approvalsapi,\n * and used to build policy conditions.\n */\nexport const ActionRunContextSchema = z.object({\n request_type: z.literal(\"action_run\"),\n selected_api: z.string(),\n action_type: z.string(),\n action_key: z.string(),\n connection_id: z.string().optional(),\n inputs: JsonValueSchema.optional(),\n reason: z.string().optional(),\n});\nexport type ActionRunContext = z.infer<typeof ActionRunContextSchema>;\n\n/**\n * Discriminated union of all request context types.\n */\nexport const RequestContextSchema = z.discriminatedUnion(\"request_type\", [\n HttpRequestContextSchema,\n ActionRunContextSchema,\n]);\nexport type RequestContext = z.infer<typeof RequestContextSchema>;\n","// ABOUTME: Canonical set of headers to exclude when building request contexts.\n// ABOUTME: Shared between sdkapi (context creation) and approvalsapi (condition building).\n\n/**\n * Headers to exclude when building request contexts from raw HTTP requests.\n *\n * These are either sensitive (auth credentials), HTTP infrastructure headers\n * that vary per-request, or proxy-internal headers that are not meaningful\n * for policy decisions.\n */\nexport const IGNORED_HEADERS = new Set([\n // Auth / credentials — never include in contexts or policy conditions\n \"authorization\",\n \"x-relay-authorization\",\n \"x-relay-authentication-id\",\n \"x-api-key\",\n \"cookie\",\n \"set-cookie\",\n \"proxy-authorization\",\n\n // HTTP infrastructure — varies per-request, not policy-relevant\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"accept-encoding\",\n \"user-agent\",\n \"accept\",\n \"accept-language\",\n \"sec-fetch-mode\",\n\n // Proxy / forwarding — infrastructure, not meaningful for policy\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n \"x-real-ip\",\n\n // Proxy internal — sdkapi-specific headers\n \"x-is-interactive-session\",\n \"x-relay-callback-url\",\n]);\n","// ABOUTME: Canonical builders for creating request contexts from raw request parts.\n// ABOUTME: Used by sdkapi to build both approval contexts and policy eval contexts.\n\nimport { z } from \"zod\";\nimport {\n HttpRequestContextSchema,\n ActionRunContextSchema,\n JsonValueSchema,\n parseUrl,\n type HttpRequestContext,\n type ActionRunContext,\n} from \"./types.ts\";\nimport { IGNORED_HEADERS } from \"./constants.ts\";\n\nexport const BuildHttpRequestContextOptionsSchema = z.object({\n method: z.string(),\n /** Raw URL string. Will be normalized with https:// if no protocol present. */\n url: z.string(),\n /** Raw headers from the request. Will be filtered through IGNORED_HEADERS. */\n headers: z\n .record(\n z.string(),\n z.union([z.string(), z.array(z.string()), z.undefined()]),\n )\n .optional(),\n /** Raw body string */\n body: z.string().nullable().optional(),\n /** Pre-parsed JSON body (e.g. from Fastify's automatic JSON parsing) */\n body_json: JsonValueSchema.optional(),\n /** Connection ID associated with this request */\n connection_id: z.string().optional(),\n});\nexport type BuildHttpRequestContextOptions = z.infer<\n typeof BuildHttpRequestContextOptionsSchema\n>;\n\n/**\n * Build a canonical HttpRequestContext from raw request parts.\n *\n * This is the single source of truth for how HTTP request contexts are created.\n * Both sdkapi (for policy evaluation) and approvalsapi (for context storage)\n * should use this to ensure the context shape is consistent.\n *\n * Matches the behavior of createPolicyHttpRequest from @zapier/policy, with\n * the addition of header filtering through IGNORED_HEADERS.\n *\n * - Normalizes URL (adds https:// if missing) and parses into { scheme, host, port, path, query }\n * - Filters headers through IGNORED_HEADERS, lowercases keys, string values only\n * - Auto-parses body_json from body when content-type is JSON and body_json not provided\n * - body defaults to null (not undefined)\n */\nexport function buildHttpRequestContext(\n options: BuildHttpRequestContextOptions,\n): HttpRequestContext {\n // Normalize URL — SDK CLI strips the protocol\n const rawUrl = options.url.includes(\"://\")\n ? options.url\n : `https://${options.url}`;\n const url = parseUrl(rawUrl);\n\n // Filter headers: exclude ignored, lowercase keys, string values only\n const headers: Record<string, string> = {};\n if (options.headers) {\n for (const [key, value] of Object.entries(options.headers)) {\n const lowerKey = key.toLowerCase();\n if (!IGNORED_HEADERS.has(lowerKey) && typeof value === \"string\") {\n headers[lowerKey] = value;\n }\n }\n }\n\n // Auto-parse body_json from body when content-type is JSON\n // (matches createPolicyHttpRequest behavior from @zapier/policy)\n let body_json: unknown = null;\n if (options.body_json !== undefined) {\n body_json = options.body_json;\n } else if (options.body) {\n const contentType = headers[\"content-type\"];\n const isJson =\n typeof contentType === \"string\" &&\n (contentType.includes(\"application/json\") ||\n (contentType.includes(\"application/\") &&\n contentType.includes(\"+json\")));\n if (isJson) {\n try {\n body_json = JSON.parse(options.body);\n } catch {\n // Invalid JSON body — leave body_json as null\n }\n }\n }\n\n return HttpRequestContextSchema.parse({\n request_type: \"http_request\",\n method: options.method,\n url,\n headers,\n body: options.body ?? null,\n body_json,\n connection_id: options.connection_id,\n });\n}\n\nexport const BuildActionRunContextOptionsSchema = z.object({\n selected_api: z.string(),\n action_type: z.string(),\n action_key: z.string(),\n connection_id: z.string().optional(),\n inputs: JsonValueSchema.optional(),\n});\nexport type BuildActionRunContextOptions = z.infer<\n typeof BuildActionRunContextOptionsSchema\n>;\n\n/**\n * Build a canonical ActionRunContext from raw action parts.\n */\nexport function buildActionRunContext(\n options: BuildActionRunContextOptions,\n): ActionRunContext {\n return ActionRunContextSchema.parse({\n request_type: \"action_run\",\n selected_api: options.selected_api,\n action_type: options.action_type,\n action_key: options.action_key,\n connection_id: options.connection_id,\n inputs: options.inputs,\n });\n}\n","// ABOUTME: Builds policy conditions from stored request contexts.\n// ABOUTME: Used by approvalsapi's \"allow exact request\" and \"allow domain\" instant policy flows.\n\nimport type { Condition } from \"@zapier/policy-schema\";\nimport type { HttpRequestContext, ActionRunContext } from \"./types.ts\";\nimport { IGNORED_HEADERS } from \"./constants.ts\";\n\n/**\n * Build conditions that match an exact HTTP request.\n *\n * Handles the matches_url / query param split correctly:\n * - `matches_url` only supports scheme+host+port+path (no query string per spec)\n * - Query parameters are added as separate decomposed conditions on `url.query.<key>`\n *\n * @returns Condition[] for an http permission statement\n */\nexport function buildExactHttpConditions(\n context: HttpRequestContext,\n): Condition[] {\n const conditions: Condition[] = [\n { path: [\"method\"], operator: \"equals\", value: context.method },\n ];\n\n const { url } = context;\n\n // matches_url condition uses URL without query string (per @zapier/policy spec)\n const defaultPort =\n url.scheme === \"https\" ? 443 : url.scheme === \"http\" ? 80 : 0;\n const portString = url.port !== defaultPort ? `:${String(url.port)}` : \"\";\n const urlWithoutQuery = `${url.scheme}://${url.host}${portString}${url.path}`;\n conditions.push({\n path: [\"url\"],\n operator: \"matches_url\",\n value: urlWithoutQuery,\n });\n\n // Add decomposed conditions for each query parameter.\n for (const [key, values] of Object.entries(url.query)) {\n conditions.push({\n path: [\"url\", \"query\", key],\n operator: \"equals\",\n value: values,\n });\n }\n\n // body_json condition\n if (context.body_json !== null) {\n conditions.push({\n path: [\"body_json\"],\n operator: \"equals\",\n value: context.body_json,\n });\n }\n\n // Header conditions (filtered through IGNORED_HEADERS again for safety)\n for (const [key, value] of Object.entries(context.headers)) {\n if (!IGNORED_HEADERS.has(key.toLowerCase()) && typeof value === \"string\") {\n conditions.push({\n path: [\"headers\", key.toLowerCase()],\n operator: \"equals\",\n value,\n });\n }\n }\n\n return conditions;\n}\n\n/**\n * Build conditions that match any request to a given domain.\n * Uses the host from the parsed URL.\n *\n * @returns Condition[] for an http permission statement\n */\nexport function buildDomainHttpConditions(\n context: HttpRequestContext,\n): Condition[] {\n return [\n {\n path: [\"url\", \"host\"],\n operator: \"matches_host\",\n value: context.url.host,\n },\n ];\n}\n\n/**\n * Build conditions that match an exact action run (with inputs).\n *\n * @returns Condition[] for an action permission statement\n */\nexport function buildExactActionConditions(\n context: ActionRunContext,\n): Condition[] {\n const conditions: Condition[] = [];\n\n if (\n context.inputs !== undefined &&\n context.inputs !== null &&\n typeof context.inputs === \"object\"\n ) {\n conditions.push({\n path: [\"inputs\"],\n operator: \"equals\",\n value: context.inputs,\n });\n }\n\n return conditions;\n}\n\n/**\n * Build the resource string for an action.\n * Format: action/{selected_api}/{action_type}/{action_key}\n */\nexport function buildActionResource(context: ActionRunContext): string {\n return `action/${context.selected_api}/${context.action_type}/${context.action_key}`;\n}\n\n/**\n * Build a broad action resource that matches all actions for an app.\n * Format: action/{selected_api}/{wildcard}/{wildcard}\n */\nexport function buildBroadActionResource(context: ActionRunContext): string {\n return `action/${context.selected_api}/*/*`;\n}\n","// ABOUTME: Assembles complete Policy objects from request contexts.\n// ABOUTME: Single source of truth for \"exact request\" instant policies used by web UI and API.\n\nimport type { Policy, Statement } from \"@zapier/policy-schema\";\nimport type {\n RequestContext,\n HttpRequestContext,\n ActionRunContext,\n} from \"./types.ts\";\nimport {\n buildExactHttpConditions,\n buildExactActionConditions,\n buildActionResource,\n} from \"./conditions.ts\";\n\n/**\n * Build a `can_use` authentication statement, if the context has a connection_id.\n */\nfunction buildAuthStatement(authenticationId: string): Statement {\n return {\n effect: \"allow\",\n permissions: [\"can_use\"],\n resources: [`connection/${authenticationId}`],\n conditions: [],\n };\n}\n\n/**\n * Build an exact-match policy from an HTTP request context.\n *\n * Produces a policy that allows only the specific request described by the context:\n * - `can_use` statement for the authentication (if present)\n * - `can_execute` statement for `http` with conditions from `buildExactHttpConditions`\n * plus a `keys_in` guard restricting allowed query parameter keys\n */\nfunction httpContextToPolicy(context: HttpRequestContext): Policy {\n const statements: Statement[] = [];\n\n if (context.connection_id) {\n statements.push(buildAuthStatement(context.connection_id));\n }\n\n const conditions = buildExactHttpConditions(context);\n\n // Add a keys_in guard so only the query param keys present in the original\n // request are allowed — blocks injection of extra query params.\n conditions.push({\n path: [\"url\", \"query\"],\n operator: \"keys_in\",\n value: Object.keys(context.url.query),\n });\n\n statements.push({\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [\"http\"],\n conditions,\n });\n\n return { version: 2, statements };\n}\n\n/**\n * Build an exact-match policy from an action run context.\n *\n * Produces a policy that allows only the specific action described by the context:\n * - `can_use` statement for the authentication (if present)\n * - `can_execute` statement for the action resource with input conditions\n */\nfunction actionContextToPolicy(context: ActionRunContext): Policy {\n const statements: Statement[] = [];\n\n if (context.connection_id) {\n statements.push(buildAuthStatement(context.connection_id));\n }\n\n statements.push({\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [buildActionResource(context)],\n conditions: buildExactActionConditions(context),\n });\n\n return { version: 2, statements };\n}\n\n/**\n * Build an exact-match policy from any supported request context.\n *\n * This is the single source of truth for \"allow this exact request\" instant policies.\n * Used by the web UI and anywhere else that needs to produce an exact policy from a context.\n */\nexport function toExactPolicy(context: RequestContext): Policy {\n if (context.request_type === \"http_request\") {\n return httpContextToPolicy(context);\n }\n return actionContextToPolicy(context);\n}\n","// ABOUTME: Builds connection-level policies for the basic approvals MVP.\n// ABOUTME: Generates deterministic policies that allow read or read+write access scoped to a specific connection.\n\nimport { z } from \"zod\";\nimport type { Policy, Statement, Condition } from \"@zapier/policy-schema\";\n\nexport const AccessLevelSchema = z.enum([\"read\", \"read_write\"]);\nexport type AccessLevel = z.infer<typeof AccessLevelSchema>;\n\nconst READ_HTTP_METHODS = [\"GET\", \"HEAD\", \"OPTIONS\"];\nconst READ_ACTION_TYPES = [\"read\", \"search\"];\n\n/**\n * Build a connection-level policy that covers both HTTP and action access.\n *\n * Always produces three statements:\n * 1. `can_use` for the authentication\n * 2. `can_execute` on `http` scoped by connection_id (+ method filter for read)\n * 3. `can_execute` on `action/{selectedApi}/**` scoped by connection_id (+ action_type filter for read)\n */\nexport function buildConnectionPolicy(options: {\n connectionId: string;\n selectedApi: string;\n accessLevel: AccessLevel;\n}): Policy {\n const { connectionId, selectedApi, accessLevel } = options;\n\n const authStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_use\"],\n resources: [`connection/${connectionId}`],\n conditions: [],\n };\n\n const connectionCondition: Condition = {\n path: [\"connection_id\"],\n operator: \"equals\",\n value: connectionId,\n };\n\n const httpConditions: Condition[] = [connectionCondition];\n if (accessLevel === \"read\") {\n httpConditions.push({\n path: [\"method\"],\n operator: \"in\",\n value: READ_HTTP_METHODS,\n });\n }\n\n const httpStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [\"http\"],\n conditions: httpConditions,\n };\n\n const actionConditions: Condition[] = [connectionCondition];\n if (accessLevel === \"read\") {\n actionConditions.push({\n path: [\"action_type\"],\n operator: \"in\",\n value: READ_ACTION_TYPES,\n });\n }\n\n const actionStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [`action/${selectedApi}/*/*`],\n conditions: actionConditions,\n };\n\n return {\n version: 2,\n statements: [authStatement, httpStatement, actionStatement],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,iBAAkB;AAOX,IAAM,kBAAkB,aAAE,OAAkB;AAO5C,IAAM,kBAAkB,aAAE,OAAO;AAAA,EACtC,QAAQ,aAAE,OAAO;AAAA,EACjB,MAAM,aAAE,OAAO;AAAA,EACf,MAAM,aAAE,OAAO;AAAA,EACf,MAAM,aAAE,OAAO;AAAA,EACf,OAAO,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,MAAM,aAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAIM,IAAM,gBAAwC;AAAA,EACnD,MAAM;AAAA,EACN,OAAO;AACT;AAMO,SAAS,SAAS,KAAwB;AAC/C,QAAM,MAAM,IAAI,IAAI,GAAG;AACvB,QAAM,SAAS,I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AA,IACR,aAAa,CAAC,aAAa;AAAA,IAC3B,WAAW,CAAC,MAAM;AAAA,IAClB,YAAY;AAAA,EACd;AAEA,QAAM,mBAAgC,CAAC,mBAAmB;AAC1D,MAAI,gBAAgB,QAAQ;AAC1B,qBAAiB,KAAK;AAAA,MACpB,MAAM,CAAC,aAAa;AAAA,MACpB,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,kBAA6B;AAAA,IACjC,QAAQ;AAAA,IACR,aAAa,CAAC,aAAa;AAAA,IAC3B,WAAW,CAAC,UAAU,WAAW,MAAM;AAAA,IACvC,YAAY;AAAA,EACd;AAEA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAe,eAAe,eAAe;AAAA,EAC5D;AACF;","names":["import_zod","import_zod"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/constants.ts","../src/builders.ts","../src/conditions.ts","../src/policies.ts","../src/connection-policy.ts"],"sourcesContent":["// ABOUTME: Public API for @zapier/policy-context.\n// ABOUTME: Shared context types, builders, and condition generators for sdkapi + approvalsapi.\n\nexport {\n HttpRequestContextSchema,\n ActionRunContextSchema,\n ActionTypeSchema,\n RequestContextSchema,\n JsonValueSchema,\n ParsedUrlSchema,\n DEFAULT_PORTS,\n parseUrl,\n buildUrlString,\n parseActionResource,\n type HttpRequestContext,\n type ActionRunContext,\n type ActionType,\n type RequestContext,\n type ParsedUrl,\n} from \"./types.ts\";\n\nexport { IGNORED_HEADERS } from \"./constants.ts\";\n\nexport {\n buildHttpRequestContext,\n buildActionRunContext,\n BuildHttpRequestContextOptionsSchema,\n BuildActionRunContextOptionsSchema,\n type BuildHttpRequestContextOptions,\n type BuildActionRunContextOptions,\n} from \"./builders.ts\";\n\nexport {\n buildExactHttpConditions,\n buildDomainHttpConditions,\n buildExactActionConditions,\n buildActionResource,\n buildBroadActionResource,\n} from \"./conditions.ts\";\n\nexport { toExactPolicy } from \"./policies.ts\";\n\nexport {\n buildConnectionPolicy,\n isWriteRequest,\n AccessLevelSchema,\n READ_ACTION_TYPES,\n READ_HTTP_METHODS,\n type AccessLevel,\n} from \"./connection-policy.ts\";\n","// ABOUTME: Canonical request context types shared between sdkapi and approvalsapi.\n// ABOUTME: These define the contract for how requests are described in approval flows and policy evaluation.\n\nimport { z } from \"zod\";\nimport { extendZodWithOpenApi } from \"@asteasolutions/zod-to-openapi\";\nimport { JsonValueSchema } from \"@zapier/policy-schema\";\n\nextendZodWithOpenApi(z);\n\nexport { JsonValueSchema };\n\n/**\n * Parsed URL components for policy evaluation.\n * Matches the ParsedUrl shape from @zapier/policy-schema so that\n * evaluatePolicy condition paths like [\"url\", \"host\"] resolve correctly.\n */\nexport const ParsedUrlSchema = z\n .object({\n scheme: z.string().openapi({ description: 'URL scheme, e.g. \"https\"' }),\n host: z.string().openapi({ description: 'Hostname, e.g. \"api.example.com\"' }),\n port: z\n .number()\n .int()\n .openapi({\n description: \"Port number (defaults to 443 for https, 80 for http)\",\n }),\n path: z.string().openapi({ description: 'URL path, e.g. \"/v1/foo\"' }),\n query: z\n .record(z.string(), z.array(z.string()))\n .openapi({\n description: \"Query parameters as key to string array mapping\",\n }),\n })\n .openapi(\"ParsedUrl\");\nexport type ParsedUrl = z.infer<typeof ParsedUrlSchema>;\n\n/** Default ports by scheme, used when URL has no explicit port. */\nexport const DEFAULT_PORTS: Record<string, number> = {\n http: 80,\n https: 443,\n};\n\n/**\n * Parse a raw URL string into a ParsedUrl.\n * Same logic as parseUrlForPolicyContext in @zapier/policy.\n */\nexport function parseUrl(raw: string): ParsedUrl {\n const url = new URL(raw);\n const scheme = url.protocol.slice(0, -1).toLowerCase();\n const host = url.hostname.toLowerCase();\n const port = url.port ? parseInt(url.port, 10) : (DEFAULT_PORTS[scheme] ?? 0);\n const path = url.pathname || \"/\";\n const query: Record<string, string[]> = {};\n for (const [key, value] of url.searchParams) {\n if (!query[key]) {\n query[key] = [];\n }\n query[key].push(value);\n }\n return { scheme, host, port, path, query };\n}\n\n/**\n * Reconstruct a URL string from a ParsedUrl.\n * Same logic as buildUrl in @zapier/policy.\n */\nexport function buildUrlString(parsed: ParsedUrl): string {\n const { scheme, host, port, path, query } = parsed;\n const defaultPort = DEFAULT_PORTS[scheme];\n const portString = port !== defaultPort ? `:${String(port)}` : \"\";\n const params = new URLSearchParams();\n for (const [key, values] of Object.entries(query)) {\n for (const value of values) {\n params.append(key, value);\n }\n }\n const queryString = params.toString();\n return `${scheme}://${host}${portString}${path}${queryString ? \"?\" + queryString : \"\"}`;\n}\n\n/**\n * HTTP request context for approval/policy flows.\n * Sent by sdkapi when a relay request is denied, stored by approvalsapi,\n * and used for both policy evaluation and building policy conditions.\n *\n * The url field is a ParsedUrl object (matching @zapier/policy-schema's ParsedUrl)\n * so that evaluatePolicy conditions like [\"url\", \"host\"] resolve correctly.\n */\nexport const HttpRequestContextSchema = z\n .object({\n request_type: z.literal(\"http_request\"),\n method: z\n .string()\n .max(10)\n .transform((m) => m.toUpperCase()),\n /** Parsed URL components for policy condition matching */\n url: ParsedUrlSchema,\n /** Filtered headers (IGNORED_HEADERS excluded, keys lowercased) */\n headers: z\n .record(z.string(), z.string())\n .openapi({\n description: \"Filtered headers (IGNORED_HEADERS excluded, keys lowercased)\",\n }),\n /** Raw body string */\n body: z.string().max(65536).nullable(),\n /** Parsed JSON body */\n body_json: JsonValueSchema.nullable().openapi({\n // `type: 'object'` is a placeholder so zod-to-openapi short-circuits\n // introspection of the recursive JsonValueSchema (z.lazy). The\n // generator script strips this `type` after emit so the produced\n // schema matches the original \"any JSON value\" shape.\n type: \"object\",\n description: \"Parsed JSON body (if applicable)\",\n }),\n /** Zapier connection ID used for this request */\n connection_id: z\n .string()\n .max(255)\n .optional()\n .openapi({ description: \"Zapier connection ID used for this request\" }),\n /** Optional human-readable reason for the request */\n reason: z\n .string()\n .max(1024)\n .optional()\n .openapi({ description: \"Optional human-readable reason for the request\" }),\n })\n .openapi(\"HttpRequestContext\");\nexport type HttpRequestContext = z.infer<typeof HttpRequestContextSchema>;\n\n/**\n * Canonical Zapier action types.\n *\n * Mirrors the `action_type` enum in sdkapi's OpenAPI spec\n * (`packages/openapi-spec/openapi.d.ts` `action_type`). Single source of\n * truth for any code that branches on or filters by action_type — keeps\n * `ActionRunContextSchema`, `BuildActionRunContextOptionsSchema`, and the\n * `READ_ACTION_TYPES` allowlist in `connection-policy.ts` aligned.\n */\nexport const ActionTypeSchema = z\n .enum([\n \"filter\",\n \"read\",\n \"read_bulk\",\n \"run\",\n \"search\",\n \"search_and_write\",\n \"search_or_write\",\n \"write\",\n ])\n .openapi(\"action_type\", { description: \"Canonical Zapier action type.\" });\nexport type ActionType = z.infer<typeof ActionTypeSchema>;\n\n/**\n * Allowed character set for `selected_api` and `action_key` segments of\n * an action resource. Blocks `*`, `/`, whitespace, and other glob/path\n * metacharacters that would otherwise widen policy scope. Permits at\n * most one `@`, which `globSelectedApiVersion` treats as the\n * version separator.\n */\nexport const ACTION_RESOURCE_SEGMENT_PATTERN =\n /^[A-Za-z0-9._+-]+(?:@[A-Za-z0-9._+-]+)?$/;\n\n/**\n * Parse an action resource string of the form\n * `action/{selected_api}/{action_type}/{action_key}` into its parts.\n * Throws if the string doesn't match the canonical 4-segment shape or\n * if its `action_type` segment isn't one of the canonical 8 — every\n * action_run context that has been through `ActionRunContextSchema` is\n * guaranteed to parse cleanly, so a thrown error here means upstream\n * validation was bypassed.\n */\nexport function parseActionResource(resource: string): {\n selected_api: string;\n action_type: ActionType;\n action_key: string;\n} {\n const segments = resource.split(\"/\");\n if (segments.length !== 4 || segments[0] !== \"action\") {\n throw new Error(\n `action resource must be action/{selected_api}/{action_type}/{action_key}: got ${resource}`,\n );\n }\n const [, selectedApi, actionTypeRaw, actionKey] = segments;\n if (!selectedApi || !actionTypeRaw || !actionKey) {\n throw new Error(`action resource has empty segment: ${resource}`);\n }\n const actionType = ActionTypeSchema.safeParse(actionTypeRaw);\n if (!actionType.success) {\n throw new Error(\n `action resource has unknown action_type \"${actionTypeRaw}\": ${resource}`,\n );\n }\n if (!ACTION_RESOURCE_SEGMENT_PATTERN.test(selectedApi)) {\n throw new Error(\n `action resource has invalid selected_api segment \"${selectedApi}\": ${resource}`,\n );\n }\n if (!ACTION_RESOURCE_SEGMENT_PATTERN.test(actionKey)) {\n throw new Error(\n `action resource has invalid action_key segment \"${actionKey}\": ${resource}`,\n );\n }\n return {\n selected_api: selectedApi,\n action_type: actionType.data,\n action_key: actionKey,\n };\n}\n\n/**\n * Action run context for approval/policy flows.\n * Sent by sdkapi when an action run is denied, stored by approvalsapi,\n * and used to build policy conditions.\n *\n * Carries the action identity in a single canonical `resource` field of\n * the form `action/{selected_api}/{action_type}/{action_key}`, which is\n * also what the policy engine matches against. Use `parseActionResource`\n * to extract the individual parts when needed for display.\n *\n * Accepts either the canonical `resource` field or the legacy\n * `{selected_api, action_type, action_key}` triple on input — the\n * transform composes a canonical resource from the legacy fields when\n * needed, so downstream code only ever sees a single `resource`. Lets\n * sdkapi keep sending the old shape during the migration window.\n */\n/**\n * Raw input shape for `ActionRunContextSchema`, before the transform that\n * canonicalizes legacy fields into `resource`. Exposed for the OpenAPI\n * schema generator (which can't represent transforms) — runtime callers\n * should keep using `ActionRunContextSchema`.\n */\nexport const ActionRunContextInputSchema = z\n .object({\n request_type: z.literal(\"action_run\"),\n resource: z\n .string()\n .max(1024)\n .optional()\n .openapi({\n description:\n \"Canonical action resource, e.g. action/Slack@1.0.0/write/send_message\",\n }),\n selected_api: z\n .string()\n .max(255)\n .optional()\n .openapi({\n deprecated: true,\n description:\n \"Legacy: app identifier, e.g. Slack@1.0.0. Prefer `resource`.\",\n }),\n action_type: ActionTypeSchema.optional().openapi({\n deprecated: true,\n description: \"Legacy: canonical Zapier action type. Prefer `resource`.\",\n }),\n action_key: z\n .string()\n .max(255)\n .optional()\n .openapi({\n deprecated: true,\n description:\n \"Legacy: action key, e.g. send_message. Prefer `resource`.\",\n }),\n connection_id: z\n .string()\n .max(255)\n .optional()\n .openapi({ description: \"Zapier connection ID used for this request\" }),\n inputs: JsonValueSchema.optional().openapi({\n // `type: 'object'` is a placeholder so zod-to-openapi short-circuits\n // introspection of the recursive JsonValueSchema (z.lazy). The\n // generator script strips this `type` after emit so the produced\n // schema matches the original \"any inputs\" shape.\n type: \"object\",\n description: \"Action input parameters\",\n }),\n reason: z\n .string()\n .max(1024)\n .optional()\n .openapi({ description: \"Optional human-readable reason for the request\" }),\n })\n .openapi(\"ActionRunContext\", {\n description:\n \"Action run context. The canonical shape carries the action identity in a single `resource` field of the form `action/{selected_api}/{action_type}/{action_key}`. The legacy `{selected_api, action_type, action_key}` shape is also accepted on input during the migration window — approvalsapi normalizes it to the canonical form before storage.\",\n });\n\nexport const ActionRunContextSchema = ActionRunContextInputSchema.transform(\n (input, ctx) => {\n const resource =\n input.resource ??\n (input.selected_api && input.action_type && input.action_key\n ? `action/${input.selected_api}/${input.action_type}/${input.action_key}`\n : undefined);\n if (resource === undefined) {\n ctx.addIssue({\n code: \"custom\",\n message:\n \"action_run context requires either `resource` or all of `selected_api`/`action_type`/`action_key`\",\n });\n return z.NEVER;\n }\n try {\n parseActionResource(resource);\n } catch (err) {\n ctx.addIssue({\n code: \"custom\",\n message: err instanceof Error ? err.message : String(err),\n });\n return z.NEVER;\n }\n return {\n request_type: \"action_run\" as const,\n resource,\n ...(input.connection_id !== undefined && {\n connection_id: input.connection_id,\n }),\n ...(input.inputs !== undefined && { inputs: input.inputs }),\n ...(input.reason !== undefined && { reason: input.reason }),\n };\n },\n);\nexport type ActionRunContext = z.infer<typeof ActionRunContextSchema>;\n\n/**\n * Union of all request context types, keyed on `request_type`.\n *\n * Plain `z.union` (not `z.discriminatedUnion`) because\n * `ActionRunContextSchema` carries a `.transform` and discriminated\n * unions can't accept a `ZodEffects` member.\n */\nexport const RequestContextSchema = z\n .union([HttpRequestContextSchema, ActionRunContextSchema])\n .openapi(\"RequestContext\", {\n description: \"Discriminated union over request_type.\",\n });\nexport type RequestContext = z.infer<typeof RequestContextSchema>;\n","// ABOUTME: Canonical set of headers to exclude when building request contexts.\n// ABOUTME: Shared between sdkapi (context creation) and approvalsapi (condition building).\n\n/**\n * Headers to exclude when building request contexts from raw HTTP requests.\n *\n * These are either sensitive (auth credentials), HTTP infrastructure headers\n * that vary per-request, or proxy-internal headers that are not meaningful\n * for policy decisions.\n */\nexport const IGNORED_HEADERS = new Set([\n // Auth / credentials — never include in contexts or policy conditions\n \"authorization\",\n \"x-relay-authorization\",\n \"x-relay-authentication-id\",\n \"x-api-key\",\n \"cookie\",\n \"set-cookie\",\n \"proxy-authorization\",\n\n // HTTP infrastructure — varies per-request, not policy-relevant\n \"host\",\n \"connection\",\n \"content-length\",\n \"transfer-encoding\",\n \"accept-encoding\",\n \"user-agent\",\n \"accept\",\n \"accept-language\",\n \"sec-fetch-mode\",\n\n // Proxy / forwarding — infrastructure, not meaningful for policy\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n \"x-real-ip\",\n\n // Proxy internal — sdkapi-specific headers\n \"x-is-interactive-session\",\n \"x-relay-callback-url\",\n]);\n","// ABOUTME: Canonical builders for creating request contexts from raw request parts.\n// ABOUTME: Used by sdkapi to build both approval contexts and policy eval contexts.\n\nimport { z } from \"zod\";\nimport {\n HttpRequestContextSchema,\n ActionRunContextSchema,\n ActionTypeSchema,\n JsonValueSchema,\n parseUrl,\n ACTION_RESOURCE_SEGMENT_PATTERN,\n type HttpRequestContext,\n type ActionRunContext,\n} from \"./types.ts\";\nimport { buildActionResource } from \"./conditions.ts\";\nimport { IGNORED_HEADERS } from \"./constants.ts\";\n\nexport const BuildHttpRequestContextOptionsSchema = z.object({\n method: z.string(),\n /** Raw URL string. Will be normalized with https:// if no protocol present. */\n url: z.string(),\n /** Raw headers from the request. Will be filtered through IGNORED_HEADERS. */\n headers: z\n .record(\n z.string(),\n z.union([z.string(), z.array(z.string()), z.undefined()]),\n )\n .optional(),\n /** Raw body string */\n body: z.string().nullable().optional(),\n /** Pre-parsed JSON body (e.g. from Fastify's automatic JSON parsing) */\n body_json: JsonValueSchema.optional(),\n /** Connection ID associated with this request */\n connection_id: z.string().optional(),\n});\nexport type BuildHttpRequestContextOptions = z.infer<\n typeof BuildHttpRequestContextOptionsSchema\n>;\n\n/**\n * Build a canonical HttpRequestContext from raw request parts.\n *\n * This is the single source of truth for how HTTP request contexts are created.\n * Both sdkapi (for policy evaluation) and approvalsapi (for context storage)\n * should use this to ensure the context shape is consistent.\n *\n * Matches the behavior of createPolicyHttpRequest from @zapier/policy, with\n * the addition of header filtering through IGNORED_HEADERS.\n *\n * - Normalizes URL (adds https:// if missing) and parses into { scheme, host, port, path, query }\n * - Filters headers through IGNORED_HEADERS, lowercases keys, string values only\n * - Auto-parses body_json from body when content-type is JSON and body_json not provided\n * - body defaults to null (not undefined)\n */\nexport function buildHttpRequestContext(\n options: BuildHttpRequestContextOptions,\n): HttpRequestContext {\n // Validate options up-front so downstream string ops (e.g. method.toUpperCase)\n // see well-typed values. Mirrors the pattern in buildActionRunContext.\n const parsed = BuildHttpRequestContextOptionsSchema.parse(options);\n\n // Normalize URL — SDK CLI strips the protocol\n const rawUrl = parsed.url.includes(\"://\")\n ? parsed.url\n : `https://${parsed.url}`;\n const url = parseUrl(rawUrl);\n\n // Filter headers: exclude ignored, lowercase keys, string values only\n const headers: Record<string, string> = {};\n if (parsed.headers) {\n for (const [key, value] of Object.entries(parsed.headers)) {\n const lowerKey = key.toLowerCase();\n if (!IGNORED_HEADERS.has(lowerKey) && typeof value === \"string\") {\n headers[lowerKey] = value;\n }\n }\n }\n\n // Auto-parse body_json from body when content-type is JSON\n // (matches createPolicyHttpRequest behavior from @zapier/policy)\n let body_json: unknown = null;\n if (parsed.body_json !== undefined) {\n body_json = parsed.body_json;\n } else if (parsed.body) {\n const contentType = headers[\"content-type\"];\n const isJson =\n typeof contentType === \"string\" &&\n (contentType.includes(\"application/json\") ||\n (contentType.includes(\"application/\") &&\n contentType.includes(\"+json\")));\n if (isJson) {\n try {\n body_json = JSON.parse(parsed.body);\n } catch {\n // Invalid JSON body — leave body_json as null\n }\n }\n }\n\n return HttpRequestContextSchema.parse({\n request_type: \"http_request\",\n method: parsed.method.toUpperCase(),\n url,\n headers,\n body: parsed.body ?? null,\n body_json,\n connection_id: parsed.connection_id,\n });\n}\n\nexport const BuildActionRunContextOptionsSchema = z.object({\n selected_api: z.string().regex(ACTION_RESOURCE_SEGMENT_PATTERN, {\n message:\n \"selected_api must contain only [A-Za-z0-9._@+-] (no globs, slashes, or whitespace)\",\n }),\n action_type: ActionTypeSchema,\n action_key: z.string().regex(ACTION_RESOURCE_SEGMENT_PATTERN, {\n message:\n \"action_key must contain only [A-Za-z0-9._@+-] (no globs, slashes, or whitespace)\",\n }),\n connection_id: z.string().optional(),\n inputs: JsonValueSchema.optional(),\n reason: z.string().optional(),\n});\nexport type BuildActionRunContextOptions = z.infer<\n typeof BuildActionRunContextOptionsSchema\n>;\n\n/**\n * Build a canonical ActionRunContext from raw action parts.\n *\n * Callers pass the three identity fields separately for readability;\n * this validates them and collapses them into the canonical `resource`\n * string the schema stores.\n */\nexport function buildActionRunContext(\n options: BuildActionRunContextOptions,\n): ActionRunContext {\n const parsed = BuildActionRunContextOptionsSchema.parse(options);\n return ActionRunContextSchema.parse({\n request_type: \"action_run\",\n resource: buildActionResource({\n selected_api: parsed.selected_api,\n action_type: parsed.action_type,\n action_key: parsed.action_key,\n }),\n connection_id: parsed.connection_id,\n inputs: parsed.inputs,\n reason: parsed.reason,\n });\n}\n","// ABOUTME: Builds policy conditions from stored request contexts.\n// ABOUTME: Used by approvalsapi's \"allow exact request\" and \"allow domain\" instant policy flows.\n\nimport type { Condition } from \"@zapier/policy-schema\";\nimport type {\n HttpRequestContext,\n ActionRunContext,\n ActionType,\n} from \"./types.ts\";\nimport { IGNORED_HEADERS } from \"./constants.ts\";\n\n/**\n * Build conditions that match an exact HTTP request.\n *\n * Handles the matches_url / query param split correctly:\n * - `matches_url` only supports scheme+host+port+path (no query string per spec)\n * - Query parameters are added as separate decomposed conditions on `url.query.<key>`\n *\n * @returns Condition[] for an http permission statement\n */\nexport function buildExactHttpConditions(\n context: HttpRequestContext,\n): Condition[] {\n const conditions: Condition[] = [\n { path: [\"method\"], operator: \"equals\", value: context.method },\n ];\n\n const { url } = context;\n\n // matches_url condition uses URL without query string (per @zapier/policy spec)\n const defaultPort =\n url.scheme === \"https\" ? 443 : url.scheme === \"http\" ? 80 : 0;\n const portString = url.port !== defaultPort ? `:${String(url.port)}` : \"\";\n const urlWithoutQuery = `${url.scheme}://${url.host}${portString}${url.path}`;\n conditions.push({\n path: [\"url\"],\n operator: \"matches_url\",\n value: urlWithoutQuery,\n });\n\n // Add decomposed conditions for each query parameter.\n for (const [key, values] of Object.entries(url.query)) {\n conditions.push({\n path: [\"url\", \"query\", key],\n operator: \"equals\",\n value: values,\n });\n }\n\n // body_json condition\n if (context.body_json !== null) {\n conditions.push({\n path: [\"body_json\"],\n operator: \"equals\",\n value: context.body_json,\n });\n } else if (context.body !== null) {\n // Non-JSON body (text/plain, XML, form-encoded): pin the raw body so\n // exact-match policies actually match the originating request.\n conditions.push({\n path: [\"body\"],\n operator: \"equals\",\n value: context.body,\n });\n }\n\n // Header conditions (filtered through IGNORED_HEADERS again for safety)\n for (const [key, value] of Object.entries(context.headers)) {\n if (!IGNORED_HEADERS.has(key.toLowerCase()) && typeof value === \"string\") {\n conditions.push({\n path: [\"headers\", key.toLowerCase()],\n operator: \"equals\",\n value,\n });\n }\n }\n\n return conditions;\n}\n\n/**\n * Build conditions that match any request to a given domain.\n * Uses the host from the parsed URL.\n *\n * @returns Condition[] for an http permission statement\n */\nexport function buildDomainHttpConditions(\n context: HttpRequestContext,\n): Condition[] {\n return [\n {\n path: [\"url\", \"host\"],\n operator: \"matches_host\",\n value: context.url.host,\n },\n ];\n}\n\n/**\n * Build conditions that match an exact action run (with inputs).\n *\n * @returns Condition[] for an action permission statement\n */\nexport function buildExactActionConditions(\n context: ActionRunContext,\n): Condition[] {\n const conditions: Condition[] = [];\n\n if (context.inputs !== undefined && context.inputs !== null) {\n conditions.push({\n path: [\"inputs\"],\n operator: \"equals\",\n value: context.inputs,\n });\n }\n\n return conditions;\n}\n\n/**\n * The three identity fields that compose an action resource string.\n */\nexport interface ActionResourceParts {\n selected_api: string;\n action_type: ActionType;\n action_key: string;\n}\n\n/**\n * Build the resource string for an action.\n * Format: action/{selected_api}/{action_type}/{action_key}\n */\nexport function buildActionResource(parts: ActionResourceParts): string {\n return `action/${parts.selected_api}/${parts.action_type}/${parts.action_key}`;\n}\n\n/**\n * Build a broad action resource that matches all actions of the same type\n * for an app (e.g. all reads, all writes). Scopes on `action_type` to\n * avoid silently granting cross-type access.\n *\n * Format: action/{selected_api}/{action_type}/{wildcard}\n */\nexport function buildBroadActionResource(\n parts: Pick<ActionResourceParts, \"selected_api\" | \"action_type\">,\n): string {\n return `action/${parts.selected_api}/${parts.action_type}/*`;\n}\n","// ABOUTME: Assembles complete Policy objects from request contexts.\n// ABOUTME: Single source of truth for \"exact request\" instant policies used by web UI and API.\n\nimport type { Policy, Statement } from \"@zapier/policy-schema\";\nimport type {\n RequestContext,\n HttpRequestContext,\n ActionRunContext,\n} from \"./types.ts\";\nimport {\n buildExactHttpConditions,\n buildExactActionConditions,\n} from \"./conditions.ts\";\n\n/**\n * Build a `can_use` authentication statement, if the context has a connection_id.\n */\nfunction buildAuthStatement(authenticationId: string): Statement {\n return {\n effect: \"allow\",\n permissions: [\"can_use\"],\n resources: [`connection/${authenticationId}`],\n conditions: [],\n };\n}\n\n/**\n * Build an exact-match policy from an HTTP request context.\n *\n * Produces a policy that allows only the specific request described by the context:\n * - `can_use` statement for the authentication (if present)\n * - `can_execute` statement for `http` with conditions from `buildExactHttpConditions`\n * plus a `keys_in` guard restricting allowed query parameter keys\n */\nfunction httpContextToPolicy(context: HttpRequestContext): Policy {\n const statements: Statement[] = [];\n\n if (context.connection_id) {\n statements.push(buildAuthStatement(context.connection_id));\n }\n\n const conditions = buildExactHttpConditions(context);\n\n // Add a keys_in guard so only the query param keys present in the original\n // request are allowed — blocks injection of extra query params.\n conditions.push({\n path: [\"url\", \"query\"],\n operator: \"keys_in\",\n value: Object.keys(context.url.query),\n });\n\n statements.push({\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [\"http\"],\n conditions,\n });\n\n return { version: 2, statements };\n}\n\n/**\n * Build an exact-match policy from an action run context.\n *\n * Produces a policy that allows only the specific action described by the context:\n * - `can_use` statement for the authentication (if present)\n * - `can_execute` statement for the action resource with input conditions\n */\nfunction actionContextToPolicy(context: ActionRunContext): Policy {\n const statements: Statement[] = [];\n\n if (context.connection_id) {\n statements.push(buildAuthStatement(context.connection_id));\n }\n\n statements.push({\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [context.resource],\n conditions: buildExactActionConditions(context),\n });\n\n return { version: 2, statements };\n}\n\n/**\n * Build an exact-match policy from any supported request context.\n *\n * This is the single source of truth for \"allow this exact request\" instant policies.\n * Used by the web UI and anywhere else that needs to produce an exact policy from a context.\n */\nexport function toExactPolicy(context: RequestContext): Policy {\n if (context.request_type === \"http_request\") {\n return httpContextToPolicy(context);\n }\n return actionContextToPolicy(context);\n}\n","// ABOUTME: Builds connection-level policies for the basic approvals MVP.\n// ABOUTME: Generates deterministic policies that allow read or read+write access scoped to a specific connection.\n\nimport { z } from \"zod\";\nimport type { Policy, Statement, Condition } from \"@zapier/policy-schema\";\nimport {\n parseActionResource,\n type ActionType,\n type RequestContext,\n} from \"./types.ts\";\n\n/**\n * Replace the implementation-version suffix of a `selected_api` with a `@*`\n * wildcard so connection-level policies stay valid across version bumps. A\n * runtime request with `selected_api: \"App@2.7.3\"` matches a policy resource\n * scoped to `App@*` while still being distinguishable from a different app\n * (e.g. `App2@1.0.0`).\n *\n * No-op when the input has no `@` — assumed to be already version-less.\n */\nfunction globSelectedApiVersion(selectedApi: string): string {\n const at = selectedApi.indexOf(\"@\");\n return at === -1 ? selectedApi : selectedApi.slice(0, at) + \"@*\";\n}\n\nexport const AccessLevelSchema = z.enum([\"read\", \"read_write\"]);\nexport type AccessLevel = z.infer<typeof AccessLevelSchema>;\n\n/** HTTP methods that count as side-effect-free reads for connection-level policies. */\nexport const READ_HTTP_METHODS = [\"GET\", \"HEAD\", \"OPTIONS\"] as const;\n\n/**\n * Action types that count as side-effect-free reads for connection-level\n * policies. `read_bulk` is the paginated/bulk variant of `read` — same\n * external API semantics, no mutations. Widely used by major apps (Slack,\n * Gmail, Jira, Salesforce, etc.) via the public `bulkReads` schema key.\n * `filter` and `run` are excluded: neither has a runtime executor for\n * external apps, and `filter` actions don't carry a connection_id anyway,\n * so this allowlist has no effect on them.\n */\nexport const READ_ACTION_TYPES = [\n \"read\",\n \"read_bulk\",\n \"search\",\n] as const satisfies readonly ActionType[];\n\nconst READ_HTTP_METHOD_SET: ReadonlySet<string> = new Set(READ_HTTP_METHODS);\nconst READ_ACTION_TYPE_SET: ReadonlySet<ActionType> = new Set(\n READ_ACTION_TYPES,\n);\n\n/**\n * Returns true when the request needs write access (i.e. it is NOT a\n * side-effect-free read). Mirrors the logic encoded in `buildConnectionPolicy`\n * so UI surfaces that gate the read-vs-read_write choice stay consistent\n * with the policies they generate.\n */\nexport function isWriteRequest(context: RequestContext): boolean {\n if (context.request_type === \"http_request\") {\n // Method is uppercase by construction (buildHttpRequestContext canonicalizes\n // it on the way in), so no normalization is needed here.\n return !READ_HTTP_METHOD_SET.has(context.method);\n }\n const { action_type } = parseActionResource(context.resource);\n return !READ_ACTION_TYPE_SET.has(action_type);\n}\n\n/**\n * Build a connection-level policy that covers both HTTP and action access.\n *\n * Always produces three statements:\n * 1. `can_use` for the authentication\n * 2. `can_execute` on `http` scoped by connection_id (+ method filter for read)\n * 3. `can_execute` on `action/{selectedApi}/{action_type}/*` per allowed type,\n * scoped by connection_id. For read access, the resource list expands to\n * one entry per read action_type so the engine matches via the resource\n * string rather than a separate `path: [\"action_type\"]` condition.\n */\nexport function buildConnectionPolicy(options: {\n connectionId: string;\n selectedApi: string;\n accessLevel: AccessLevel;\n}): Policy {\n const { connectionId, selectedApi, accessLevel } = options;\n\n const authStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_use\"],\n resources: [`connection/${connectionId}`],\n conditions: [],\n };\n\n const connectionCondition: Condition = {\n path: [\"connection_id\"],\n operator: \"equals\",\n value: connectionId,\n };\n\n const httpConditions: Condition[] = [connectionCondition];\n if (accessLevel === \"read\") {\n httpConditions.push({\n path: [\"method\"],\n operator: \"in\",\n value: [...READ_HTTP_METHODS],\n });\n }\n\n const httpStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: [\"http\"],\n conditions: httpConditions,\n };\n\n const apiPattern = globSelectedApiVersion(selectedApi);\n const actionResources =\n accessLevel === \"read\"\n ? READ_ACTION_TYPES.map((t) => `action/${apiPattern}/${t}/*`)\n : [`action/${apiPattern}/*/*`];\n\n const actionStatement: Statement = {\n effect: \"allow\",\n permissions: [\"can_execute\"],\n resources: actionResources,\n conditions: [connectionCondition],\n };\n\n return {\n version: 2,\n statements: [authStatement, httpStatement, actionStatement],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,iBAAkB;AAClB,4BAAqC;AACrC,2BAAgC;AAAA,IAEhC,4CAAqB,YAAC;AASf,IAAM,kBAAkB,aAC5B,OAAO;AAAA,EACN,QAAQ,aAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,2BAA2B,CAAC;AAAA,EACtE,MAAM,aAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,mCAAmC,CAAC;AAAA,EAC5E,MAAM,aACH,OAAO,EACP,IAAI,EACJ,QAAQ;AAAA,IACP,aAAa;AAAA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AAA,IACrC,MAAM,CAAC,eAAe;AAAA,IACtB,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AAEA,QAAM,iBAA8B,CAAC,mBAAmB;AACxD,MAAI,gBAAgB,QAAQ;AAC1B,mBAAe,KAAK;AAAA,MAClB,MAAM,CAAC,QAAQ;AAAA,MACf,UAAU;AAAA,MACV,OAAO,CAAC,GAAG,iBAAiB;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,gBAA2B;AAAA,IAC/B,QAAQ;AAAA,IACR,aAAa,CAAC,aAAa;AAAA,IAC3B,WAAW,CAAC,MAAM;AAAA,IAClB,YAAY;AAAA,EACd;AAEA,QAAM,aAAa,uBAAuB,WAAW;AACrD,QAAM,kBACJ,gBAAgB,SACZ,kBAAkB,IAAI,CAAC,MAAM,UAAU,UAAU,IAAI,CAAC,IAAI,IAC1D,CAAC,UAAU,UAAU,MAAM;AAEjC,QAAM,kBAA6B;AAAA,IACjC,QAAQ;AAAA,IACR,aAAa,CAAC,aAAa;AAAA,IAC3B,WAAW;AAAA,IACX,YAAY,CAAC,mBAAmB;AAAA,EAClC;AAEA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAe,eAAe,eAAe;AAAA,EAC5D;AACF;","names":["import_zod","import_zod"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import * as _zapier_policy_schema from '@zapier/policy-schema';
|
|
3
|
-
import {
|
|
2
|
+
import { Condition, Policy } from '@zapier/policy-schema';
|
|
3
|
+
export { JsonValueSchema } from '@zapier/policy-schema';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Zod schema for arbitrary JSON values. Used across context schemas for
|
|
7
|
-
* unstructured fields like `body_json` and `inputs`.
|
|
8
|
-
*/
|
|
9
|
-
declare const JsonValueSchema: z.ZodCustom<JsonValue, JsonValue>;
|
|
10
6
|
/**
|
|
11
7
|
* Parsed URL components for policy evaluation.
|
|
12
8
|
* Matches the ParsedUrl shape from @zapier/policy-schema so that
|
|
@@ -42,7 +38,7 @@ declare function buildUrlString(parsed: ParsedUrl): string;
|
|
|
42
38
|
*/
|
|
43
39
|
declare const HttpRequestContextSchema: z.ZodObject<{
|
|
44
40
|
request_type: z.ZodLiteral<"http_request">;
|
|
45
|
-
method: z.ZodString
|
|
41
|
+
method: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
46
42
|
url: z.ZodObject<{
|
|
47
43
|
scheme: z.ZodString;
|
|
48
44
|
host: z.ZodString;
|
|
@@ -52,32 +48,90 @@ declare const HttpRequestContextSchema: z.ZodObject<{
|
|
|
52
48
|
}, z.core.$strip>;
|
|
53
49
|
headers: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
54
50
|
body: z.ZodNullable<z.ZodString>;
|
|
55
|
-
body_json: z.ZodNullable<z.
|
|
51
|
+
body_json: z.ZodNullable<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
56
52
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
57
53
|
reason: z.ZodOptional<z.ZodString>;
|
|
58
54
|
}, z.core.$strip>;
|
|
59
55
|
type HttpRequestContext = z.infer<typeof HttpRequestContextSchema>;
|
|
60
56
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
57
|
+
* Canonical Zapier action types.
|
|
58
|
+
*
|
|
59
|
+
* Mirrors the `action_type` enum in sdkapi's OpenAPI spec
|
|
60
|
+
* (`packages/openapi-spec/openapi.d.ts` `action_type`). Single source of
|
|
61
|
+
* truth for any code that branches on or filters by action_type — keeps
|
|
62
|
+
* `ActionRunContextSchema`, `BuildActionRunContextOptionsSchema`, and the
|
|
63
|
+
* `READ_ACTION_TYPES` allowlist in `connection-policy.ts` aligned.
|
|
64
64
|
*/
|
|
65
|
-
declare const
|
|
65
|
+
declare const ActionTypeSchema: z.ZodEnum<{
|
|
66
|
+
filter: "filter";
|
|
67
|
+
read: "read";
|
|
68
|
+
read_bulk: "read_bulk";
|
|
69
|
+
run: "run";
|
|
70
|
+
search: "search";
|
|
71
|
+
search_and_write: "search_and_write";
|
|
72
|
+
search_or_write: "search_or_write";
|
|
73
|
+
write: "write";
|
|
74
|
+
}>;
|
|
75
|
+
type ActionType = z.infer<typeof ActionTypeSchema>;
|
|
76
|
+
/**
|
|
77
|
+
* Parse an action resource string of the form
|
|
78
|
+
* `action/{selected_api}/{action_type}/{action_key}` into its parts.
|
|
79
|
+
* Throws if the string doesn't match the canonical 4-segment shape or
|
|
80
|
+
* if its `action_type` segment isn't one of the canonical 8 — every
|
|
81
|
+
* action_run context that has been through `ActionRunContextSchema` is
|
|
82
|
+
* guaranteed to parse cleanly, so a thrown error here means upstream
|
|
83
|
+
* validation was bypassed.
|
|
84
|
+
*/
|
|
85
|
+
declare function parseActionResource(resource: string): {
|
|
86
|
+
selected_api: string;
|
|
87
|
+
action_type: ActionType;
|
|
88
|
+
action_key: string;
|
|
89
|
+
};
|
|
90
|
+
declare const ActionRunContextSchema: z.ZodPipe<z.ZodObject<{
|
|
66
91
|
request_type: z.ZodLiteral<"action_run">;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
93
|
+
selected_api: z.ZodOptional<z.ZodString>;
|
|
94
|
+
action_type: z.ZodOptional<z.ZodEnum<{
|
|
95
|
+
filter: "filter";
|
|
96
|
+
read: "read";
|
|
97
|
+
read_bulk: "read_bulk";
|
|
98
|
+
run: "run";
|
|
99
|
+
search: "search";
|
|
100
|
+
search_and_write: "search_and_write";
|
|
101
|
+
search_or_write: "search_or_write";
|
|
102
|
+
write: "write";
|
|
103
|
+
}>>;
|
|
104
|
+
action_key: z.ZodOptional<z.ZodString>;
|
|
70
105
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
71
|
-
inputs: z.ZodOptional<z.
|
|
106
|
+
inputs: z.ZodOptional<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
72
107
|
reason: z.ZodOptional<z.ZodString>;
|
|
73
|
-
}, z.core.$strip
|
|
108
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
109
|
+
reason?: string | undefined;
|
|
110
|
+
inputs?: _zapier_policy_schema.JsonValue | undefined;
|
|
111
|
+
connection_id?: string | undefined;
|
|
112
|
+
request_type: "action_run";
|
|
113
|
+
resource: string;
|
|
114
|
+
}, {
|
|
115
|
+
request_type: "action_run";
|
|
116
|
+
resource?: string | undefined;
|
|
117
|
+
selected_api?: string | undefined;
|
|
118
|
+
action_type?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
|
|
119
|
+
action_key?: string | undefined;
|
|
120
|
+
connection_id?: string | undefined;
|
|
121
|
+
inputs?: _zapier_policy_schema.JsonValue | undefined;
|
|
122
|
+
reason?: string | undefined;
|
|
123
|
+
}>>;
|
|
74
124
|
type ActionRunContext = z.infer<typeof ActionRunContextSchema>;
|
|
75
125
|
/**
|
|
76
|
-
*
|
|
126
|
+
* Union of all request context types, keyed on `request_type`.
|
|
127
|
+
*
|
|
128
|
+
* Plain `z.union` (not `z.discriminatedUnion`) because
|
|
129
|
+
* `ActionRunContextSchema` carries a `.transform` and discriminated
|
|
130
|
+
* unions can't accept a `ZodEffects` member.
|
|
77
131
|
*/
|
|
78
|
-
declare const RequestContextSchema: z.
|
|
132
|
+
declare const RequestContextSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
79
133
|
request_type: z.ZodLiteral<"http_request">;
|
|
80
|
-
method: z.ZodString
|
|
134
|
+
method: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
81
135
|
url: z.ZodObject<{
|
|
82
136
|
scheme: z.ZodString;
|
|
83
137
|
host: z.ZodString;
|
|
@@ -87,18 +141,43 @@ declare const RequestContextSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
87
141
|
}, z.core.$strip>;
|
|
88
142
|
headers: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
89
143
|
body: z.ZodNullable<z.ZodString>;
|
|
90
|
-
body_json: z.ZodNullable<z.
|
|
144
|
+
body_json: z.ZodNullable<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
91
145
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
92
146
|
reason: z.ZodOptional<z.ZodString>;
|
|
93
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
147
|
+
}, z.core.$strip>, z.ZodPipe<z.ZodObject<{
|
|
94
148
|
request_type: z.ZodLiteral<"action_run">;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
149
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
150
|
+
selected_api: z.ZodOptional<z.ZodString>;
|
|
151
|
+
action_type: z.ZodOptional<z.ZodEnum<{
|
|
152
|
+
filter: "filter";
|
|
153
|
+
read: "read";
|
|
154
|
+
read_bulk: "read_bulk";
|
|
155
|
+
run: "run";
|
|
156
|
+
search: "search";
|
|
157
|
+
search_and_write: "search_and_write";
|
|
158
|
+
search_or_write: "search_or_write";
|
|
159
|
+
write: "write";
|
|
160
|
+
}>>;
|
|
161
|
+
action_key: z.ZodOptional<z.ZodString>;
|
|
98
162
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
99
|
-
inputs: z.ZodOptional<z.
|
|
163
|
+
inputs: z.ZodOptional<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
100
164
|
reason: z.ZodOptional<z.ZodString>;
|
|
101
|
-
}, z.core.$strip
|
|
165
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
166
|
+
reason?: string | undefined;
|
|
167
|
+
inputs?: _zapier_policy_schema.JsonValue | undefined;
|
|
168
|
+
connection_id?: string | undefined;
|
|
169
|
+
request_type: "action_run";
|
|
170
|
+
resource: string;
|
|
171
|
+
}, {
|
|
172
|
+
request_type: "action_run";
|
|
173
|
+
resource?: string | undefined;
|
|
174
|
+
selected_api?: string | undefined;
|
|
175
|
+
action_type?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
|
|
176
|
+
action_key?: string | undefined;
|
|
177
|
+
connection_id?: string | undefined;
|
|
178
|
+
inputs?: _zapier_policy_schema.JsonValue | undefined;
|
|
179
|
+
reason?: string | undefined;
|
|
180
|
+
}>>]>;
|
|
102
181
|
type RequestContext = z.infer<typeof RequestContextSchema>;
|
|
103
182
|
|
|
104
183
|
/**
|
|
@@ -115,7 +194,7 @@ declare const BuildHttpRequestContextOptionsSchema: z.ZodObject<{
|
|
|
115
194
|
url: z.ZodString;
|
|
116
195
|
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodUndefined]>>>;
|
|
117
196
|
body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
118
|
-
body_json: z.ZodOptional<z.
|
|
197
|
+
body_json: z.ZodOptional<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
119
198
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
120
199
|
}, z.core.$strip>;
|
|
121
200
|
type BuildHttpRequestContextOptions = z.infer<typeof BuildHttpRequestContextOptionsSchema>;
|
|
@@ -137,14 +216,28 @@ type BuildHttpRequestContextOptions = z.infer<typeof BuildHttpRequestContextOpti
|
|
|
137
216
|
declare function buildHttpRequestContext(options: BuildHttpRequestContextOptions): HttpRequestContext;
|
|
138
217
|
declare const BuildActionRunContextOptionsSchema: z.ZodObject<{
|
|
139
218
|
selected_api: z.ZodString;
|
|
140
|
-
action_type: z.
|
|
219
|
+
action_type: z.ZodEnum<{
|
|
220
|
+
filter: "filter";
|
|
221
|
+
read: "read";
|
|
222
|
+
read_bulk: "read_bulk";
|
|
223
|
+
run: "run";
|
|
224
|
+
search: "search";
|
|
225
|
+
search_and_write: "search_and_write";
|
|
226
|
+
search_or_write: "search_or_write";
|
|
227
|
+
write: "write";
|
|
228
|
+
}>;
|
|
141
229
|
action_key: z.ZodString;
|
|
142
230
|
connection_id: z.ZodOptional<z.ZodString>;
|
|
143
|
-
inputs: z.ZodOptional<z.
|
|
231
|
+
inputs: z.ZodOptional<z.ZodType<_zapier_policy_schema.JsonValue, unknown, z.core.$ZodTypeInternals<_zapier_policy_schema.JsonValue, unknown>>>;
|
|
232
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
144
233
|
}, z.core.$strip>;
|
|
145
234
|
type BuildActionRunContextOptions = z.infer<typeof BuildActionRunContextOptionsSchema>;
|
|
146
235
|
/**
|
|
147
236
|
* Build a canonical ActionRunContext from raw action parts.
|
|
237
|
+
*
|
|
238
|
+
* Callers pass the three identity fields separately for readability;
|
|
239
|
+
* this validates them and collapses them into the canonical `resource`
|
|
240
|
+
* string the schema stores.
|
|
148
241
|
*/
|
|
149
242
|
declare function buildActionRunContext(options: BuildActionRunContextOptions): ActionRunContext;
|
|
150
243
|
|
|
@@ -171,16 +264,27 @@ declare function buildDomainHttpConditions(context: HttpRequestContext): Conditi
|
|
|
171
264
|
* @returns Condition[] for an action permission statement
|
|
172
265
|
*/
|
|
173
266
|
declare function buildExactActionConditions(context: ActionRunContext): Condition[];
|
|
267
|
+
/**
|
|
268
|
+
* The three identity fields that compose an action resource string.
|
|
269
|
+
*/
|
|
270
|
+
interface ActionResourceParts {
|
|
271
|
+
selected_api: string;
|
|
272
|
+
action_type: ActionType;
|
|
273
|
+
action_key: string;
|
|
274
|
+
}
|
|
174
275
|
/**
|
|
175
276
|
* Build the resource string for an action.
|
|
176
277
|
* Format: action/{selected_api}/{action_type}/{action_key}
|
|
177
278
|
*/
|
|
178
|
-
declare function buildActionResource(
|
|
279
|
+
declare function buildActionResource(parts: ActionResourceParts): string;
|
|
179
280
|
/**
|
|
180
|
-
* Build a broad action resource that matches all actions
|
|
181
|
-
*
|
|
281
|
+
* Build a broad action resource that matches all actions of the same type
|
|
282
|
+
* for an app (e.g. all reads, all writes). Scopes on `action_type` to
|
|
283
|
+
* avoid silently granting cross-type access.
|
|
284
|
+
*
|
|
285
|
+
* Format: action/{selected_api}/{action_type}/{wildcard}
|
|
182
286
|
*/
|
|
183
|
-
declare function buildBroadActionResource(
|
|
287
|
+
declare function buildBroadActionResource(parts: Pick<ActionResourceParts, "selected_api" | "action_type">): string;
|
|
184
288
|
|
|
185
289
|
/**
|
|
186
290
|
* Build an exact-match policy from any supported request context.
|
|
@@ -195,13 +299,35 @@ declare const AccessLevelSchema: z.ZodEnum<{
|
|
|
195
299
|
read_write: "read_write";
|
|
196
300
|
}>;
|
|
197
301
|
type AccessLevel = z.infer<typeof AccessLevelSchema>;
|
|
302
|
+
/** HTTP methods that count as side-effect-free reads for connection-level policies. */
|
|
303
|
+
declare const READ_HTTP_METHODS: readonly ["GET", "HEAD", "OPTIONS"];
|
|
304
|
+
/**
|
|
305
|
+
* Action types that count as side-effect-free reads for connection-level
|
|
306
|
+
* policies. `read_bulk` is the paginated/bulk variant of `read` — same
|
|
307
|
+
* external API semantics, no mutations. Widely used by major apps (Slack,
|
|
308
|
+
* Gmail, Jira, Salesforce, etc.) via the public `bulkReads` schema key.
|
|
309
|
+
* `filter` and `run` are excluded: neither has a runtime executor for
|
|
310
|
+
* external apps, and `filter` actions don't carry a connection_id anyway,
|
|
311
|
+
* so this allowlist has no effect on them.
|
|
312
|
+
*/
|
|
313
|
+
declare const READ_ACTION_TYPES: readonly ["read", "read_bulk", "search"];
|
|
314
|
+
/**
|
|
315
|
+
* Returns true when the request needs write access (i.e. it is NOT a
|
|
316
|
+
* side-effect-free read). Mirrors the logic encoded in `buildConnectionPolicy`
|
|
317
|
+
* so UI surfaces that gate the read-vs-read_write choice stay consistent
|
|
318
|
+
* with the policies they generate.
|
|
319
|
+
*/
|
|
320
|
+
declare function isWriteRequest(context: RequestContext): boolean;
|
|
198
321
|
/**
|
|
199
322
|
* Build a connection-level policy that covers both HTTP and action access.
|
|
200
323
|
*
|
|
201
324
|
* Always produces three statements:
|
|
202
325
|
* 1. `can_use` for the authentication
|
|
203
326
|
* 2. `can_execute` on `http` scoped by connection_id (+ method filter for read)
|
|
204
|
-
* 3. `can_execute` on `action/{selectedApi}
|
|
327
|
+
* 3. `can_execute` on `action/{selectedApi}/{action_type}/*` per allowed type,
|
|
328
|
+
* scoped by connection_id. For read access, the resource list expands to
|
|
329
|
+
* one entry per read action_type so the engine matches via the resource
|
|
330
|
+
* string rather than a separate `path: ["action_type"]` condition.
|
|
205
331
|
*/
|
|
206
332
|
declare function buildConnectionPolicy(options: {
|
|
207
333
|
connectionId: string;
|
|
@@ -209,4 +335,4 @@ declare function buildConnectionPolicy(options: {
|
|
|
209
335
|
accessLevel: AccessLevel;
|
|
210
336
|
}): Policy;
|
|
211
337
|
|
|
212
|
-
export { type AccessLevel, AccessLevelSchema, type ActionRunContext, ActionRunContextSchema, type BuildActionRunContextOptions, BuildActionRunContextOptionsSchema, type BuildHttpRequestContextOptions, BuildHttpRequestContextOptionsSchema, DEFAULT_PORTS, type HttpRequestContext, HttpRequestContextSchema, IGNORED_HEADERS,
|
|
338
|
+
export { type AccessLevel, AccessLevelSchema, type ActionRunContext, ActionRunContextSchema, type ActionType, ActionTypeSchema, type BuildActionRunContextOptions, BuildActionRunContextOptionsSchema, type BuildHttpRequestContextOptions, BuildHttpRequestContextOptionsSchema, DEFAULT_PORTS, type HttpRequestContext, HttpRequestContextSchema, IGNORED_HEADERS, type ParsedUrl, ParsedUrlSchema, READ_ACTION_TYPES, READ_HTTP_METHODS, type RequestContext, RequestContextSchema, buildActionResource, buildActionRunContext, buildBroadActionResource, buildConnectionPolicy, buildDomainHttpConditions, buildExactActionConditions, buildExactHttpConditions, buildHttpRequestContext, buildUrlString, isWriteRequest, parseActionResource, parseUrl, toExactPolicy };
|