import {z} from 'zod' export type RouteExposureDescriptorId = string; export type StringMap = {[key: string]: string}; export type PartyRef = {partyId?: string | undefined, externalId?: string | undefined, partyType?: string | undefined, displayName?: string | undefined, metadata?: StringMap | undefined}; export type SemanticReference = {referenceType: string, referenceId: string, iri?: string | undefined, version?: string | undefined}; export type ConnectorFieldSelector = {canonicalFieldPath?: string | undefined, connectorField?: string | undefined, protocolClaimPath?: string | undefined, dcqlCredentialQueryId?: string | undefined, dcqlClaimId?: string | undefined, formFieldPath?: string | undefined, proofRef?: string | undefined, statusRef?: string | undefined, tokenRef?: string | undefined, sourceFieldPath?: string | undefined, dataProductFieldScope?: string | undefined, contractAgreementTargetRef?: string | undefined, semanticReference?: SemanticReference | undefined, required?: boolean | undefined}; export type ConnectorFieldMapping = {source: ConnectorFieldSelector, target: ConnectorFieldSelector, required?: boolean | undefined}; export type RetentionDeleteAction = 'DELETE' | 'ANONYMIZE' | 'PSEUDONYMIZE' | 'TOMBSTONE' | 'REVIEW'; export type RetentionSpec = {purpose?: string | undefined, legalBasis?: string | undefined, retentionPeriod?: string | undefined, deleteAction?: RetentionDeleteAction | undefined, metadata?: StringMap | undefined}; export type ConnectorIntegrityReference = {originalPayloadHash?: string | undefined, canonicalPayloadHash?: string | undefined, transformationHash?: string | undefined, evidenceRef?: string | undefined, vaultRef?: string | undefined, signatureRef?: string | undefined, sealRef?: string | undefined, timestampRef?: string | undefined, sourceAuthenticityVerdict?: string | undefined, outputManifestHash?: string | undefined}; export type ConnectorGovernanceEnvelope = {classification?: string | undefined, sensitivity?: string | undefined, specialCategory?: boolean | undefined, legalBasis?: string | undefined, purpose?: string | undefined, b2bUsagePurpose?: string | undefined, frameworkAgreementRef?: string | undefined, contractReference?: string | undefined, minimizationStatus?: ('NOT_EVALUATED' | 'MINIMIZED' | 'REDACTED' | 'FULL_DATASET' | 'EXCESSIVE') | undefined, retentionProfileId?: string | undefined, retention?: RetentionSpec | undefined, crossBorderRestriction?: ('NONE' | 'SAME_COUNTRY' | 'EEA_ONLY' | 'APPROVED_COUNTRIES' | 'CONTRACT_REQUIRED' | 'BLOCKED') | undefined, encryptionRequirement?: ('NONE' | 'IN_TRANSIT' | 'AT_REST' | 'AT_REST_AND_IN_TRANSIT' | 'CUSTOMER_MANAGED_KEY') | undefined, dpiaRequired?: boolean | undefined, integrity?: ConnectorIntegrityReference | undefined, policyDecisionId?: string | undefined, relianceVerdict?: ('NOT_EVALUATED' | 'RELIABLE' | 'CONDITIONAL' | 'NOT_RELIABLE') | undefined, auditCategory?: ('PROTOCOL_ISSUANCE' | 'PROTOCOL_VERIFICATION' | 'FORM' | 'PORTAL' | 'WORKFLOW' | 'DATASPACE' | 'INDUSTRIAL' | 'EXTERNAL_EXCHANGE' | 'VAULT' | 'SYSTEM_CATALOG') | undefined}; export type RelationshipCandidate = {relationshipType: string, fromParty: PartyRef, toParty: PartyRef, confidence?: string | undefined, sourceRef?: string | undefined}; export type ConnectorEntityMaterializationIntent = 'REFERENCE_ONLY' | 'EXISTING_PARTY' | 'NEW_PARTY_CANDIDATE' | 'RELATIONSHIP_CANDIDATE' | 'SEMANTIC_VALUE' | 'EVENT' | 'DPP_RECORD'; export type PartyProjectionCandidate = {candidateId: string, entityKind: string, party?: PartyRef | undefined, relationships?: Array | undefined, materializationIntent?: ConnectorEntityMaterializationIntent | undefined, semanticClassifications?: Array<{[key: string]: unknown}> | undefined, canonicalFields?: {[key: string]: unknown} | undefined}; export type RouteExposureExternalWriteRequest = {authMethod: string, callerParty: PartyRef, payload: {[key: string]: unknown}, fieldMappings: Array, governance?: ConnectorGovernanceEnvelope | undefined, idempotencyKey?: string | undefined, partyProjectionCandidates?: Array | undefined}; export type CreateApiRouteExposuresExposureDescriptorIdWriteArgs = {exposureDescriptorId: RouteExposureDescriptorId, body: RouteExposureExternalWriteRequest}; export type CreateApiRouteExposuresExposureDescriptorIdWriteOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const connectorGovernedIngressStatus = z.enum(["ACCEPTED", "MINIMIZED", "REDACTED", "QUARANTINED", "REJECTED"]); export const connectorRunId = z.string(); export const routeExposureDescriptorId = z.string(); export const logicalConnectionBindingId = z.string(); export const connectorOwnerSurface = z.enum(["OID4VCI", "OID4VP", "FORM", "PORTAL", "WORKFLOW", "APPLICATION"]); export const connectorExternalWriteReceipt = z.object({state: connectorGovernedIngressStatus, runId: connectorRunId.optional(), exposureDescriptorId: routeExposureDescriptorId, logicalConnectionBindingId: logicalConnectionBindingId, canonicalFields: z.record(z.string(), z.unknown()), projectionCandidateIds: z.array(z.string()), policyDecisionId: z.string(), idempotencyResult: z.string(), payloadHash: z.string(), laterUseAvailabilityScope: z.array(connectorOwnerSurface)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Execute an externally initiated route exposure write * * POST /route/exposures/{exposureDescriptorId}/write */ export const createApiRouteExposuresExposureDescriptorIdWrite = async (args: CreateApiRouteExposuresExposureDescriptorIdWriteArgs, options?: CreateApiRouteExposuresExposureDescriptorIdWriteOptions) => { const {baseUrl = "https://api.example.com/api/connector/v1", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/route/exposures/${encodeURIComponent(String(args.exposureDescriptorId))}/write${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(connectorExternalWriteReceipt, await res.json()) };