UNPKG

@saleor/app-sdk

Version:

SDK for building great Saleor Apps

105 lines (95 loc) 5.96 kB
import { P as PlatformAdapterInterface, a as HTTPMethod, A as ActionHandlerResult, G as GenericCreateAppRegisterHandlerOptions, d as WebhookContext } from '../../saleor-webhook-De0XK_dM.js'; import { APIGatewayProxyEventV2, Context, APIGatewayProxyStructuredResultV2 } from 'aws-lambda'; import { C as CreateManifestHandlerOptions$1, P as ProtectedHandlerContext, G as GenericSaleorWebhook, a as GenericWebhookConfig } from '../../generic-saleor-webhook-wKiXRuB5.js'; import { APL } from '../../APL/index.js'; import { Permission, AsyncWebhookEventType, SyncWebhookEventType } from '../../types.js'; import '../../saleor-app.js'; import 'graphql'; import '../../verify-signature-mKf0fpOE.js'; type AwsLambdaHandlerInput = APIGatewayProxyEventV2; type AWSLambdaHandler = (event: APIGatewayProxyEventV2, context: Context) => Promise<APIGatewayProxyStructuredResultV2>; /** PlatformAdapter for AWS Lambda HTTP events * * Platform adapters are used in Actions to handle generic request logic * like getting body, headers, etc. * * Thanks to this Actions logic can be re-used for each platform * @see {PlatformAdapterInterface} * */ declare class AwsLambdaAdapter implements PlatformAdapterInterface<AwsLambdaHandlerInput> { private event; private context; request: AwsLambdaHandlerInput; constructor(event: APIGatewayProxyEventV2, context: Context); getHeader(requestedName: string): string | null; getBody(): Promise<unknown | null>; getRawBody(): Promise<string | null>; private DEFAULT_STAGE_NAME; getBaseUrl(): string; get method(): HTTPMethod; send(result: ActionHandlerResult): Promise<APIGatewayProxyStructuredResultV2>; } type CreateAppRegisterHandlerOptions = GenericCreateAppRegisterHandlerOptions<AwsLambdaHandlerInput>; /** * Returns API route handler for AWS Lambda HTTP triggered events * (created by Amazon API Gateway, Lambda Function URL) * that use signature: (event: APIGatewayProxyEventV2, context: Context) => APIGatewayProxyResultV2 * * Handler is for register endpoint that is called by Saleor when installing the app * * It verifies the request and stores `app_token` from Saleor * in APL and along with all required AuthData fields (jwks, saleorApiUrl, ...) * * **Recommended path**: `/api/register` * (configured in manifest handler) * * To learn more check Saleor docs * @see {@link https://docs.saleor.io/developer/extending/apps/architecture/app-requirements#register-url} * @see {@link https://www.npmjs.com/package/@types/aws-lambda} * */ declare const createAppRegisterHandler: (config: CreateAppRegisterHandlerOptions) => AWSLambdaHandler; type CreateManifestHandlerOptions = CreateManifestHandlerOptions$1<AwsLambdaHandlerInput>; /** Returns app manifest API route handler for AWS Lambda HTTP triggered events * (created by Amazon API Gateway, Lambda Function URL) * that use signature: (event: APIGatewayProxyEventV2, context: Context) => APIGatewayProxyResultV2 * * App manifest is an endpoint that Saleor will call your App metadata. * It has the App's name and description, as well as all the necessary information to * register webhooks, permissions, and extensions. * * **Recommended path**: `/api/manifest` * * To learn more check Saleor docs * @see {@link https://docs.saleor.io/developer/extending/apps/architecture/app-requirements#manifest-url} * */ declare const createManifestHandler: (config: CreateManifestHandlerOptions) => AWSLambdaHandler; type AwsLambdaProtectedHandler = (event: APIGatewayProxyEventV2, context: Context, saleorContext: ProtectedHandlerContext) => Promise<APIGatewayProxyStructuredResultV2> | APIGatewayProxyStructuredResultV2; /** * Wraps provided function, to ensure incoming request comes from Saleor Dashboard. * Also provides additional `saleorContext` object containing request properties. */ declare const createProtectedHandler: (handlerFn: AwsLambdaProtectedHandler, apl: APL, requiredPermissions?: Permission[]) => AWSLambdaHandler; type WebhookConfig<Event = AsyncWebhookEventType | SyncWebhookEventType> = GenericWebhookConfig<AwsLambdaHandlerInput, Event>; /** Function type provided by consumer in `SaleorWebApiWebhook.createHandler` */ type AwsLambdaWebhookHandler<TPayload = unknown> = (event: AwsLambdaHandlerInput, context: Context, ctx: WebhookContext<TPayload>) => Promise<APIGatewayProxyStructuredResultV2> | APIGatewayProxyStructuredResultV2; declare abstract class SaleorWebApiWebhook<TPayload = unknown> extends GenericSaleorWebhook<AwsLambdaHandlerInput, TPayload> { /** * Wraps provided function, to ensure incoming request comes from registered Saleor instance. * Also provides additional `context` object containing typed payload and request properties. */ createHandler(handlerFn: AwsLambdaWebhookHandler<TPayload>): AWSLambdaHandler; } declare class SaleorAsyncWebhook<TPayload = unknown> extends SaleorWebApiWebhook<TPayload> { readonly event: AsyncWebhookEventType; protected readonly eventType: "async"; constructor(configuration: WebhookConfig<AsyncWebhookEventType>); createHandler(handlerFn: AwsLambdaWebhookHandler<TPayload>): AWSLambdaHandler; } type AwsLambdaSyncWebhookHandler<TPayload> = AwsLambdaWebhookHandler<TPayload>; declare class SaleorSyncWebhook<TPayload = unknown, TEvent extends SyncWebhookEventType = SyncWebhookEventType> extends SaleorWebApiWebhook<TPayload> { readonly event: TEvent; protected readonly eventType: "sync"; constructor(configuration: WebhookConfig<TEvent>); createHandler(handlerFn: AwsLambdaSyncWebhookHandler<TPayload>): AWSLambdaHandler; } export { type AWSLambdaHandler, AwsLambdaAdapter, type AwsLambdaHandlerInput, type AwsLambdaProtectedHandler, type AwsLambdaSyncWebhookHandler, type CreateAppRegisterHandlerOptions, type CreateManifestHandlerOptions, SaleorAsyncWebhook, SaleorSyncWebhook, createAppRegisterHandler, createManifestHandler, createProtectedHandler };