{"version":3,"sources":["../../../src/requests/typings/index.ts","../../../src/requests/typings/function.ts","../../../src/requests/typings/request.ts","../../../src/requests/typings/validators.ts"],"sourcesContent":["export * from './appAction'\nexport * from './event-payloads'\nexport * from './function'\nexport * from './request'\nexport * from './validators'\n","// Remove when this eslint rule covers all the cases\n// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md\n/*eslint-disable no-unused-vars*/\n\nimport { AppActionCategoryType, ClientOptions, PlainClientAPI } from 'contentful-management'\nimport { AppActionCategoryBodyMap, AppActionRequestBody } from './appAction'\nimport { AppEventPayloadMap } from './event-payloads'\nimport {\n  type ResourcesLookupRequest,\n  type ResourcesLookupResponse,\n  type ResourcesSearchRequest,\n  type ResourcesSearchResponse,\n} from './resources'\n\nexport enum FunctionTypeEnum {\n  GraphqlFieldMapping = 'graphql.field.mapping',\n  GraphqlResourceTypeMapping = 'graphql.resourcetype.mapping',\n  GraphqlQuery = 'graphql.query',\n  AppEventFilter = 'appevent.filter',\n  AppEventHandler = 'appevent.handler',\n  AppEventTransformation = 'appevent.transformation',\n  AppActionCall = 'appaction.call',\n  ResourcesSearch = 'resources.search',\n  ResourcesLookup = 'resources.lookup',\n}\n\ntype GraphQLFieldTypeMappingRequest = {\n  type: FunctionTypeEnum.GraphqlFieldMapping\n  fields: { contentTypeId: string; field: Field }[]\n}\n\ntype Field = {\n  id: string\n  type: string\n}\n\nexport type GraphQLFieldTypeMappingResponse = {\n  namespace: string\n  fields: GraphQLFieldTypeMapping[]\n}\n\nexport type GraphQLFieldTypeMapping = {\n  contentTypeId: string\n  fieldId: string\n  graphQLOutputType?: string\n  graphQLQueryField: string\n  graphQLQueryArguments: Record<string, string>\n}\n\ntype GraphQLResourceTypeMappingRequest = {\n  type: FunctionTypeEnum.GraphqlResourceTypeMapping\n  resourceTypes: {\n    resourceTypeId: string\n  }[]\n}\n\ntype GraphQLResourceTypeMappingResponse = {\n  resourceTypes: GraphQLResourceTypeMapping[]\n}\n\ntype GraphQLQueryArgumentMapping = {\n  [key: string]: GraphQLQueryArgumentMapping | string\n}\n\ntype GraphQLResourceTypeMapping = {\n  graphQLQueryField: string\n  graphQLQueryArguments: GraphQLQueryArgumentMapping\n  resourceTypeId: string\n  graphQLOutputType?: string\n}\n\ntype GraphQLQueryRequest = {\n  type: FunctionTypeEnum.GraphqlQuery\n  query: string\n  isIntrospectionQuery: boolean\n  variables: Record<string, unknown>\n  operationName?: string\n}\n\n/**\n * @see https://spec.graphql.org/October2021/#sec-Response\n */\nexport type GraphQLQueryResponse = {\n  data?: Record<string, any> | null\n  errors?: readonly Record<string, any>[]\n  extensions?: Record<string, unknown>\n}\n\ntype AppEventEntityName = keyof AppEventPayloadMap\ntype AppEventEntityActions<T extends AppEventEntityName> = keyof AppEventPayloadMap[T] & string\ntype AppEventEntityPayload<\n  T extends AppEventEntityName,\n  A extends AppEventEntityActions<T>,\n> = AppEventPayloadMap[T][A]\n\ntype AppEventBase<\n  EntityName extends AppEventEntityName,\n  EntityAction extends AppEventEntityActions<EntityName>,\n> = {\n  headers: Record<string, string | number> & {\n    'X-Contentful-Topic': `ContentManagement.${EntityName}.${EntityAction}`\n  }\n  body: AppEventEntityPayload<EntityName, EntityAction>\n  type:\n    | FunctionTypeEnum.AppEventHandler\n    | FunctionTypeEnum.AppEventTransformation\n    | FunctionTypeEnum.AppEventFilter\n}\n\nexport type AppEventContentType = {\n  [A in AppEventEntityActions<'ContentType'>]: AppEventBase<'ContentType', A>\n}[AppEventEntityActions<'ContentType'>]\n\nexport type AppEventEntry = {\n  [A in AppEventEntityActions<'Entry'>]: AppEventBase<'Entry', A>\n}[AppEventEntityActions<'Entry'>]\n\nexport type AppEventAsset = {\n  [A in AppEventEntityActions<'Asset'>]: AppEventBase<'Asset', A>\n}[AppEventEntityActions<'Asset'>]\n\nexport type AppEventAppInstallation = {\n  [A in AppEventEntityActions<'AppInstallation'>]: AppEventBase<'AppInstallation', A>\n}[AppEventEntityActions<'AppInstallation'>]\n\nexport type AppEventTask = {\n  [A in AppEventEntityActions<'Task'>]: AppEventBase<'Task', A>\n}[AppEventEntityActions<'Task'>]\n\nexport type AppEventComment = {\n  [A in AppEventEntityActions<'Comment'>]: AppEventBase<'Comment', A>\n}[AppEventEntityActions<'Comment'>]\n\nexport type AppEventRelease = {\n  [A in AppEventEntityActions<'Release'>]: AppEventBase<'Release', A>\n}[AppEventEntityActions<'Release'>]\n\nexport type AppEventReleaseAction = {\n  [A in AppEventEntityActions<'ReleaseAction'>]: AppEventBase<'ReleaseAction', A>\n}[AppEventEntityActions<'ReleaseAction'>]\n\nexport type AppEventScheduledAction = {\n  [A in AppEventEntityActions<'ScheduledAction'>]: AppEventBase<'ScheduledAction', A>\n}[AppEventEntityActions<'ScheduledAction'>]\n\nexport type AppEventBulkAction = {\n  [A in AppEventEntityActions<'BulkAction'>]: AppEventBase<'BulkAction', A>\n}[AppEventEntityActions<'BulkAction'>]\n\nexport type AppEventTemplateInstallation = {\n  [A in AppEventEntityActions<'TemplateInstallation'>]: AppEventBase<'TemplateInstallation', A>\n}[AppEventEntityActions<'TemplateInstallation'>]\n\nexport type AppEventWorkflow = {\n  [A in AppEventEntityActions<'Workflow'>]: AppEventBase<'Workflow', A>\n}[AppEventEntityActions<'Workflow'>]\n\nexport type AppEventRequest = {\n  [T in AppEventEntityName]: {\n    [A in AppEventEntityActions<T>]: AppEventBase<T, A>\n  }[AppEventEntityActions<T>]\n}[AppEventEntityName]\n\nexport type AppEventFilterResponse = {\n  result: boolean\n}\n\nexport type AppEventTransformationResponse = {\n  headers: Record<string, string | number>\n  body: Record<string, unknown>\n}\n\nexport type AppEventHandlerResponse = void\n\n/**\n * The app action request body will contain different parameters depending on the category of the app action\n *\n * Specify your app action category as the generic type `Category` to get the correct body type,\n * e.g. `const { body: { message, recipient }} = event as AppActionRequest<'Notification.v1.0'>`\n *\n * If you are using the Custom category, you can specify the parameter shape as the second generic type `CustomCategoryBody`,\n * e.g. `const { body: { myNumber }} = event as AppActionRequest<'Custom', { myNumber: number }>`\n */\nexport type AppActionRequest<\n  CategoryType extends AppActionCategoryType = 'Custom',\n  CustomCategoryBody = AppActionCategoryBodyMap['Custom'],\n> = {\n  headers: Record<string, string | number>\n  body: CategoryType extends 'Custom' ? CustomCategoryBody : AppActionRequestBody<CategoryType>\n  type: FunctionTypeEnum.AppActionCall\n}\n\nexport type AppActionResponse = void | Record<string, unknown>\n\n/**\n * P: Possibility to type app installation parameters\n */\nexport type FunctionEventContext<P extends Record<string, any> = Record<string, any>> = {\n  spaceId: string\n  environmentId: string\n  appInstallationParameters: P\n  cmaClientOptions?: ClientOptions\n  cma?: PlainClientAPI\n  originalRequest?: {\n    headers: Record<string, any>\n  }\n}\n\n/**\n * T: Possibility to type app action category\n * U: Possibility to type app action body (only applies to the Custom category)\n */\ntype FunctionEventHandlers<\n  T extends AppActionCategoryType = never,\n  U extends AppActionRequestBody<T> = never,\n> = {\n  [FunctionTypeEnum.GraphqlFieldMapping]: {\n    event: GraphQLFieldTypeMappingRequest\n    response: GraphQLFieldTypeMappingResponse\n  }\n  [FunctionTypeEnum.GraphqlResourceTypeMapping]: {\n    event: GraphQLResourceTypeMappingRequest\n    response: GraphQLResourceTypeMappingResponse\n  }\n  [FunctionTypeEnum.GraphqlQuery]: {\n    event: GraphQLQueryRequest\n    response: GraphQLQueryResponse\n  }\n  [FunctionTypeEnum.AppActionCall]: {\n    event: AppActionRequest<T, U>\n    response: AppActionResponse\n  }\n  [FunctionTypeEnum.AppEventFilter]: {\n    event: AppEventRequest\n    response: AppEventFilterResponse\n  }\n  [FunctionTypeEnum.AppEventHandler]: {\n    event: AppEventRequest\n    response: AppEventHandlerResponse\n  }\n  [FunctionTypeEnum.AppEventTransformation]: {\n    event: AppEventRequest\n    response: AppEventTransformationResponse\n  }\n  [FunctionTypeEnum.ResourcesSearch]: {\n    event: ResourcesSearchRequest\n    response: ResourcesSearchResponse\n  }\n  [FunctionTypeEnum.ResourcesLookup]: {\n    event: ResourcesLookupRequest\n    response: ResourcesLookupResponse\n  }\n}\n\nexport type FunctionEvent =\n  | GraphQLFieldTypeMappingRequest\n  | GraphQLResourceTypeMappingRequest\n  | GraphQLQueryRequest\n  | AppActionRequest\n  | AppEventRequest\n  | ResourcesSearchRequest\n  | ResourcesLookupRequest\nexport type FunctionEventType = keyof FunctionEventHandlers\n\n/**\n * Event handler type that needs to be exported as `handler` from your function.\n * e.g. `const handler: FunctionEventHandler = (event, context) => { ... }`\n *\n * This type can also be used to construct helper functions for specific events\n * e.g. `const queryHandler: FunctionEventHandler<'graphql.query'> = (event, context) => { ... }`\n */\nexport type FunctionEventHandler<\n  K extends FunctionEventType = FunctionEventType,\n  P extends Record<string, any> = Record<string, any>,\n> = (\n  event: FunctionEventHandlers[K]['event'],\n  context: FunctionEventContext<P>,\n) => Promise<FunctionEventHandlers[K]['response']> | FunctionEventHandlers[K]['response']\n","// Remove when this eslint rule covers all the cases\n// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md\n/*eslint-disable no-unused-vars*/\nimport { CanonicalRequest } from './validators'\n\nexport enum ContentfulHeader {\n  Timestamp = 'x-contentful-timestamp',\n  SignedHeaders = 'x-contentful-signed-headers',\n  Signature = 'x-contentful-signature',\n}\n\nexport enum ContentfulContextHeader {\n  CRN = 'x-contentful-crn',\n  SpaceId = 'x-contentful-space-id',\n  EnvironmentId = 'x-contentful-environment-id',\n  UserId = 'x-contentful-user-id',\n  AppId = 'x-contentful-app-id',\n}\n\nexport type NormalizedCanonicalRequest = {\n  method: CanonicalRequest['method']\n  path: CanonicalRequest['path']\n  headers: [key: string, value: string][]\n  body: CanonicalRequest['body']\n}\n\nexport type SubjectHeadersApp = { appId: string }\nexport type AppContextSignedHeaders = { [ContentfulContextHeader.AppId]: string }\nexport type SubjectHeadersUser = { userId: string }\nexport type UserContextSignedHeaders = { [ContentfulContextHeader.UserId]: string }\n\nexport type Context<SubjectContext> = {\n  crn?: string\n  spaceId: string\n  envId: string\n} & SubjectContext\n\ntype SignedHeadersWithoutSubject = {\n  [ContentfulContextHeader.CRN]?: string\n  [ContentfulContextHeader.SpaceId]: string\n  [ContentfulContextHeader.EnvironmentId]: string\n}\n\nexport type SignedContextHeaders<SubjectSignedHeaders> = SignedHeadersWithoutSubject &\n  SubjectSignedHeaders\n\nexport type SignedRequestWithoutContextHeaders = {\n  [key in ContentfulHeader]: string\n}\nexport type SignedRequestWithContextHeadersWithUser = SignedRequestWithoutContextHeaders &\n  SignedContextHeaders<UserContextSignedHeaders>\nexport type SignedRequestWithContextHeadersWithApp = SignedRequestWithoutContextHeaders &\n  SignedContextHeaders<AppContextSignedHeaders>\n\nexport type SignedRequestHeaders =\n  | SignedRequestWithContextHeadersWithUser\n  | SignedRequestWithContextHeadersWithApp\n  | SignedRequestWithoutContextHeaders\n","import * as runtypes from 'runtypes'\n\nconst MethodValidator = runtypes.Union(\n  runtypes.Literal('GET'),\n  runtypes.Literal('PATCH'),\n  runtypes.Literal('HEAD'),\n  runtypes.Literal('POST'),\n  runtypes.Literal('DELETE'),\n  runtypes.Literal('OPTIONS'),\n  runtypes.Literal('PUT'),\n)\n\nconst PathValidator = runtypes.String.withConstraint((s) => s.startsWith('/'), {\n  name: 'CanonicalURI',\n})\n\nconst SignatureValidator = runtypes.String.withConstraint((s) => s.length === 64, {\n  name: 'SignatureLength',\n})\n\nexport const CanonicalRequestValidator = runtypes\n  .Record({\n    method: MethodValidator,\n    path: PathValidator,\n  })\n  .And(\n    runtypes.Partial({\n      headers: runtypes.Dictionary(runtypes.String, 'string'),\n      body: runtypes.String,\n    }),\n  )\nexport type CanonicalRequest = runtypes.Static<typeof CanonicalRequestValidator>\n\nexport const SecretValidator = runtypes.String.withConstraint((s) => s.length === 64, {\n  name: 'SecretLength',\n})\nexport type Secret = runtypes.Static<typeof SecretValidator>\n\n// Only dates after 01-01-2020\nexport const TimestampValidator = runtypes.Number.withConstraint((n) => n > 1577836800000, {\n  name: 'TimestampAge',\n})\nexport type Timestamp = runtypes.Static<typeof TimestampValidator>\n\nconst SignedHeadersValidator = runtypes\n  .Array(runtypes.String)\n  .withConstraint((l) => l.length >= 2, { name: 'MissingTimestampOrSignedHeaders' })\n\nexport const RequestMetadataValidator = runtypes.Record({\n  signature: SignatureValidator,\n  timestamp: TimestampValidator,\n  signedHeaders: SignedHeadersValidator,\n})\nexport type RequestMetadata = runtypes.Static<typeof RequestMetadataValidator>\n\nexport const TimeToLiveValidator = runtypes.Number.withConstraint((n) => n >= 0, {\n  name: 'PositiveNumber',\n})\nexport type TimeToLive = runtypes.Static<typeof TimeToLiveValidator>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,yBAAsB;AACtB,EAAAA,kBAAA,gCAA6B;AAC7B,EAAAA,kBAAA,kBAAe;AACf,EAAAA,kBAAA,oBAAiB;AACjB,EAAAA,kBAAA,qBAAkB;AAClB,EAAAA,kBAAA,4BAAyB;AACzB,EAAAA,kBAAA,mBAAgB;AAChB,EAAAA,kBAAA,qBAAkB;AAClB,EAAAA,kBAAA,qBAAkB;AATR,SAAAA;AAAA,GAAA;;;ACTL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,mBAAgB;AAChB,EAAAA,kBAAA,eAAY;AAHF,SAAAA;AAAA,GAAA;AAML,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,SAAM;AACN,EAAAA,yBAAA,aAAU;AACV,EAAAA,yBAAA,mBAAgB;AAChB,EAAAA,yBAAA,YAAS;AACT,EAAAA,yBAAA,WAAQ;AALE,SAAAA;AAAA,GAAA;;;ACXZ,eAA0B;AAE1B,IAAM,kBAA2B;AAAA,EACtB,iBAAQ,KAAK;AAAA,EACb,iBAAQ,OAAO;AAAA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