Skip to content

Commit

Permalink
feat: add app event filter type to functions [EXT-5089] (#566)
Browse files Browse the repository at this point in the history
* feat: add app event filter type

* fix: app event filter types

* rm unnneeded imports

* update app event filter type

* chore: clean up TODOs for app event request type

* adding addition event types, removing errors

* Update src/requests/typings/function.ts

Co-authored-by: Tyler Collins <104802020+t-col@users.noreply.github.com>

* Update src/requests/typings/function.ts

Co-authored-by: Tyler Collins <104802020+t-col@users.noreply.github.com>

---------

Co-authored-by: Mitch Goudy <mitchell.goudy@contentful.com>
Co-authored-by: david shibley <david.shibley@contentful.com>
Co-authored-by: david-shibley-contentful <149433784+david-shibley-contentful@users.noreply.github.com>
Co-authored-by: Tyler Collins <104802020+t-col@users.noreply.github.com>
  • Loading branch information
5 people authored Mar 27, 2024
1 parent 1e58771 commit f8ea2cb
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion src/requests/typings/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md
/*eslint-disable no-unused-vars*/

import {
AppInstallationProps,
AssetProps,
BulkActionProps,
CommentProps,
ContentTypeProps,
EntryProps,
EnvironmentTemplateInstallationProps,
ReleaseActionProps,
ReleaseProps,
ScheduledActionProps,
TaskProps,
} from 'contentful-management'

const GRAPHQL_FIELD_MAPPING_EVENT = 'graphql.field.mapping'
const GRAPHQL_QUERY_EVENT = 'graphql.query'
const APP_EVENT_FILTER = 'appevent.filter'

type GraphQLFieldTypeMappingRequest = {
type: typeof GRAPHQL_FIELD_MAPPING_EVENT
Expand Down Expand Up @@ -45,6 +60,89 @@ export type GraphQLQueryResponse = {
extensions?: Record<string, unknown>
}

type ContentTypeActions = 'create' | 'save' | 'publish' | 'unpublish' | 'delete'
type EntryActions =
| 'create'
| 'save'
| 'auto_save'
| 'publish'
| 'unpublish'
| 'archive'
| 'unarchive'
| 'delete'
type AssetActions =
| 'create'
| 'save'
| 'auto_save'
| 'publish'
| 'unpublish'
| 'archive'
| 'unarchive'
| 'delete'
type AppInstallationActions = 'create' | 'save' | 'delete'
type TaskActions = 'create' | 'save' | 'delete'
type CommentActions = 'create' | 'delete'
type ReleaseActions = 'create' | 'save' | 'delete'
type ReleaseActionActions = 'create' | 'execute'
type ScheduledActionActions = 'create' | 'save' | 'delete' | 'execute'
type BulkActionActions = 'create' | 'execute'
type TemplateInstallationActions = 'complete'

type AppEventFilter<EntityProps, EntityActions> = {
type: typeof APP_EVENT_FILTER
entityProps: EntityProps
entityAction: EntityActions // 'create' | 'publish' etc etc.
}
export type AppEventContentTypeFilter = {
entityType: 'ContentType'
} & AppEventFilter<ContentTypeProps, ContentTypeActions>
export type AppEventEntryFilter = {
entityType: 'Entry'
} & AppEventFilter<EntryProps, EntryActions>
export type AppEventAssetFilter = {
entityType: 'Asset'
} & AppEventFilter<AssetProps, AssetActions>
export type AppEventAppInstallationFilter = {
entityType: 'AppInstallation' // is this AppInstallation or App Installation?
} & AppEventFilter<AppInstallationProps, AppInstallationActions>
export type AppEventTaskFilter = {
entityType: 'Task'
} & AppEventFilter<TaskProps, TaskActions>
export type AppEventCommentFilter = {
entityType: 'Comment'
} & AppEventFilter<CommentProps, CommentActions>
export type AppEventReleaseFilter = {
entityType: 'Release'
} & AppEventFilter<ReleaseProps, ReleaseActions>
export type AppEventReleaseActionFilter = {
entityType: 'ReleaseAction' // is this ReleaseAction or Release action?
} & AppEventFilter<ReleaseActionProps, ReleaseActionActions>
export type AppEventScheduledActionFilter = {
entityType: 'ScheduledAction' // is this ScheduledAction or Scheduled action?
} & AppEventFilter<ScheduledActionProps, ScheduledActionActions>
export type AppEventBulkActionFilter = {
entityType: 'BulkAction' // is this ScheduledAction or Scheduled action?
} & AppEventFilter<BulkActionProps, BulkActionActions>
export type AppEventTemplateInstallationFilter = {
entityType: 'TemplateInstallation' // is this ScheduledAction or Scheduled action?
} & AppEventFilter<EnvironmentTemplateInstallationProps, TemplateInstallationActions>
export type AppEventFilterRequest =
| AppEventEntryFilter
| AppEventAssetFilter
| AppEventContentTypeFilter
| AppEventAppInstallationFilter
| AppEventTaskFilter
| AppEventCommentFilter
| AppEventReleaseFilter
| AppEventReleaseActionFilter
| AppEventScheduledActionFilter
| AppEventBulkActionFilter
| AppEventTemplateInstallationFilter

export type AppEventFilterResponse = {
result: boolean
}

/**
* P: Possibility to type app installation parameters
*/
Expand All @@ -63,9 +161,16 @@ type FunctionEventHandlers = {
event: GraphQLQueryRequest
response: GraphQLQueryResponse
}
[APP_EVENT_FILTER]: {
event: AppEventFilterRequest
response: AppEventFilterResponse
}
}

export type FunctionEvent = GraphQLFieldTypeMappingRequest | GraphQLQueryRequest
export type FunctionEvent =
| GraphQLFieldTypeMappingRequest
| GraphQLQueryRequest
| AppEventFilterRequest
export type FunctionEventType = keyof FunctionEventHandlers

/**
Expand Down

0 comments on commit f8ea2cb

Please sign in to comment.