import type { SchemaBase } from './dsl.js'; import type { DtoMessage } from './dto.js'; import type { ExceptionSchema } from './exception.js'; import type { ProjectApiSchema, ThirdApiSchema } from './project.js'; /** A third-party integration service (e.g. tenpay wechat pay). * Distinct from ServiceSchema (backend service bound to an app) and * ThirdApiSchema (project topology: the dir the integration lives in). * Describes the adapter class contract: constructor config + methods. * `callbacks` are the inbound half — push messages the third party sends to * this platform (e.g. audit-result notify), rendered as @Public controllers. */ /** Wire data format of the third-party gateway. 'form' (urlencoded) and * 'json' are built-in in @pylonts/sandbox; any other string is a custom * format the sandbox encoder parses itself. The client and the sandbox are * mirror images of one protocol — the format declared here is the single * source both generated sides read. */ export type ThirdServiceFormat = 'form' | 'json' | string; export interface ThirdServiceSchema extends SchemaBase { type: 'thirdService'; /** The third-party system this service integrates (topology reference). */ schema: ThirdApiSchema; /** Wire data format of the gateway (see ThirdServiceFormat). Default 'json'. */ format?: ThirdServiceFormat; /** Methods keyed by name — the map key is written back as the method name. */ methods: Record; /** Callbacks (third-party push → platform) keyed by name. Empty when the * integration is outbound-only. */ callbacks: Record; } /** A method of a third-party integration service. Same contract shape as * ServiceMethodSchema minus flow — the implementation lives in the external * system, there is nothing to model. Kept separate so a third method can * never bind a flow. */ export interface ThirdServiceMethodSchema extends SchemaBase { type: 'method'; schema: ThirdServiceSchema; /** Wire service name sent to the third-party gateway. Defaults to the method * key — declare explicitly when the wire value differs (e.g. camelCase key * vs snake_case wire: uploadImage → 'pic_upload'). Both the client and the * sandbox read this field, so the mirror pair stays in sync. */ service?: string; /** Input message. */ args: DtoMessage; /** Output message. */ results: DtoMessage; /** Exceptions this method may throw (e.g. IOException, CodeException). */ throws?: ExceptionSchema[]; } /** Method input for defineThirdService: name/schema are set by the builder. */ export type ThirdServiceMethodDef = Omit; /** An inbound callback of a third-party service. The third party pushes a * payload (e.g. audit-result notify) to a platform endpoint; the platform * verifies the third party's own signature/decrypts (hand-written in the * generated controller body) and answers with `response`. * `api` selects the backend the endpoint is generated into: * {api}/src/modules/{thirdApi.name}/controller/ — the only module location * whitelisted for @Public (lint controller), because a third party never * holds an appKey. */ export interface ThirdCallbackSchema extends SchemaBase { type: 'thirdCallback'; schema: ThirdServiceSchema; /** Backend API the callback controller is generated into. */ api: ProjectApiSchema; /** The third-party push service name (e.g. 'apply_notify', 'alter_notify'). */ service: string; /** Push message (third party → platform). */ payload: DtoMessage; /** Platform answer message (platform → third party). */ response: DtoMessage; } /** Callback input for defineThirdService: name/schema are set by the builder. */ export type ThirdCallbackDef = Omit; /** Builds one callback entry for `defineThirdService({ callbacks })`. The * callback name (map key in the callbacks object) becomes the controller * method name; everything else is declared here. */ export declare function defineThirdCallback(options: { /** Backend API the callback controller is generated into. */ api: ProjectApiSchema; /** The third-party push service name (e.g. 'apply_notify', 'alter_notify'). */ service: string; /** Push message (third party → platform). */ payload: DtoMessage; /** Platform answer message (platform → third party). */ response: DtoMessage; description?: string; }): ThirdCallbackDef; export declare function defineThirdService(options: { schema: ThirdApiSchema; name: string; format?: ThirdServiceFormat; methods: Record; callbacks?: Record; description?: string; }): ThirdServiceSchema;