Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use functions-types as source of NER events definitions #705

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"runtypes": "^5.0.1"
},
"devDependencies": {
"@contentful/functions-types": "^1.3.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/jsonwebtoken": "9.0.6",
Expand Down
117 changes: 13 additions & 104 deletions src/requests/typings/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md
/*eslint-disable no-unused-vars*/

import type {
FunctionEventContext,
FunctionEventHandlers,
FunctionEventType,
} from '@contentful/functions-types'

import {
AppActionCategoryType,
AppInstallationProps,
Expand All @@ -11,69 +17,19 @@ import {
ContentTypeProps,
EntryProps,
EnvironmentTemplateInstallationProps,
PlainClientAPI,
ReleaseActionProps,
ReleaseProps,
ScheduledActionProps,
TaskProps,
} from 'contentful-management'
import {
RESOURCES_SEARCH_EVENT,
RESOURCES_LOOKUP_EVENT,
type ResourcesLookupRequest,
type ResourcesLookupResponse,
type ResourcesSearchRequest,
type ResourcesSearchResponse,
} from './resources'

import { AppActionCategoryBodyMap, AppActionRequestBody } from './appAction'

const GRAPHQL_FIELD_MAPPING_EVENT = 'graphql.field.mapping'
const GRAPHQL_QUERY_EVENT = 'graphql.query'
const APP_EVENT_FILTER = 'appevent.filter'
const APP_EVENT_HANDLER = 'appevent.handler'
const APP_EVENT_TRANSFORMATION = 'appevent.transformation'
const APP_ACTION_CALL = 'appaction.call'

type GraphQLFieldTypeMappingRequest = {
type: typeof GRAPHQL_FIELD_MAPPING_EVENT
fields: { contentTypeId: string; field: Field }[]
}

type Field = {
id: string
type: string
}

export type GraphQLFieldTypeMappingResponse = {
namespace: string
fields: GraphQLFieldTypeMapping[]
}

export type GraphQLFieldTypeMapping = {
contentTypeId: string
fieldId: string
graphQLOutputType?: string
graphQLQueryField: string
graphQLQueryArguments: Record<string, string>
}

type GraphQLQueryRequest = {
type: typeof GRAPHQL_QUERY_EVENT
query: string
isIntrospectionQuery: boolean
variables: Record<string, unknown>
operationName?: string
}

/**
* @see https://spec.graphql.org/October2021/#sec-Response
*/
export type GraphQLQueryResponse = {
data?: Record<string, any> | null
errors?: readonly Record<string, any>[]
extensions?: Record<string, unknown>
}

type ContentTypeActions = 'create' | 'save' | 'publish' | 'unpublish' | 'delete'
type EntryActions =
| 'create'
Expand Down Expand Up @@ -180,59 +136,12 @@ export type AppActionRequest<

export type AppActionResponse = void | Record<string, unknown>

/**
* P: Possibility to type app installation parameters
*/
export type FunctionEventContext<P extends Record<string, any> = Record<string, any>> = {
spaceId: string
environmentId: string
appInstallationParameters: P
cma?: PlainClientAPI
}

type FunctionEventHandlers = {
[GRAPHQL_FIELD_MAPPING_EVENT]: {
event: GraphQLFieldTypeMappingRequest
response: GraphQLFieldTypeMappingResponse
}
[GRAPHQL_QUERY_EVENT]: {
event: GraphQLQueryRequest
response: GraphQLQueryResponse
}
[APP_ACTION_CALL]: {
event: AppActionRequest<AppActionCategoryType>
response: AppActionResponse
}
[APP_EVENT_FILTER]: {
event: AppEventRequest
response: AppEventFilterResponse
}
[APP_EVENT_HANDLER]: {
event: AppEventRequest
response: AppEventHandlerResponse
}
[APP_EVENT_TRANSFORMATION]: {
event: AppEventRequest
response: AppEventTransformationResponse
}
[RESOURCES_SEARCH_EVENT]: {
event: ResourcesSearchRequest
response: ResourcesSearchResponse
}
[RESOURCES_LOOKUP_EVENT]: {
event: ResourcesLookupRequest
response: ResourcesLookupResponse
}
}

export type FunctionEvent =
| GraphQLFieldTypeMappingRequest
| GraphQLQueryRequest
| AppActionRequest
| AppEventRequest
| ResourcesSearchRequest
| ResourcesLookupRequest
export type FunctionEventType = keyof FunctionEventHandlers
export type {
FunctionEvent,
FunctionEventContext,
FunctionEventType,
GraphqlQueryResponse,
} from '@contentful/functions-types'

/**
* Event handler type that needs to be exported as `handler` from your function.
Expand Down
39 changes: 0 additions & 39 deletions src/requests/typings/resources.ts

This file was deleted.