-
Notifications
You must be signed in to change notification settings - Fork 73
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
Events v2: Skeleton GraphQL resolvers for basic operations #8033
Merged
Merged
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1b7d031
add some basic operations and unit tests for interfacing with events
rikukissa 9f83721
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into ocrv…
rikukissa f259bc3
feat(events): create first draft of types
makelicious d2a03f8
feat(events): unify and clean up types
makelicious 5d1351f
add basic structure for graphql endpoints
rikukissa a05906d
add tennic club membership example data
rikukissa 68f8adb
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa a9f98a9
implement initial graphql resolvers for basic event operations
rikukissa 7914c63
implement authorisation and first GraphQL -> MongoDB request chain
rikukissa 81f470f
add license headers to all files
rikukissa d8addb9
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa 55a2d63
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa 1f90403
fix tests
rikukissa 269970d
add events package to gateway build
rikukissa e8add12
fix the test pipeline to not remove events package if its used in pac…
rikukissa 307a04f
cleanup
rikukissa d31792f
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa a5e2c8d
fix docker build dependencies
rikukissa e04fef8
trick knip not to complain about duplicate exports
rikukissa d031ed5
remove unused export
rikukissa 6d7b57b
update docker compose config
rikukissa c3c97ac
Merge branch 'feat/event-types' into ocrvs-7824-b
rikukissa c604312
Merge branch 'develop' into ocrvs-7824-b
rikukissa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { z } from 'zod' | ||
import { GetValues, NonEmptyArray } from '../types' | ||
import { Form } from './Form' | ||
import { Label } from './utils' | ||
|
||
/** | ||
* Actions recognized by the system | ||
*/ | ||
export const ActionType = { | ||
CREATE: 'CREATE', | ||
ASSIGN: 'ASSIGN', | ||
UNASSIGN: 'UNASSIGN', | ||
REGISTER: 'REGISTER', | ||
VALIDATE: 'VALIDATE', | ||
CORRECT: 'CORRECT', | ||
DETECT_DUPLICATE: 'DETECT_DUPLICATE', | ||
NOTIFY: 'NOTIFY', | ||
DECLARE: 'DECLARE' | ||
} as const | ||
|
||
export const actionTypes = Object.values(ActionType) | ||
export type ActionType = GetValues<typeof ActionType> | ||
|
||
/** | ||
* Configuration of action performed on an event. | ||
* Includes roles that can perform the action, label and forms involved. | ||
*/ | ||
export const ActionConfig = z.object({ | ||
type: z.enum(actionTypes as NonEmptyArray<ActionType>), | ||
label: Label, | ||
forms: z.array(Form) | ||
}) | ||
|
||
export const ActionInputBase = z.object({ | ||
type: z.enum(actionTypes as NonEmptyArray<ActionType>), | ||
createdAt: z.date(), | ||
createdBy: z.string(), | ||
fields: z.array( | ||
z.object({ | ||
id: z.string(), | ||
value: z.union([ | ||
z.string(), | ||
z.number(), | ||
z.array( | ||
z.object({ | ||
optionValues: z.array(z.string()), | ||
type: z.string(), | ||
data: z.string(), | ||
fileSize: z.number() | ||
}) | ||
) | ||
]) | ||
}) | ||
) | ||
}) | ||
|
||
export const ActionInput = z.union([ | ||
ActionInputBase.extend({ | ||
type: z.enum([ActionType.CREATE]) | ||
}), | ||
ActionInputBase.extend({ | ||
type: z.enum([ActionType.REGISTER]), | ||
identifiers: z.object({ | ||
trackingId: z.string(), | ||
registrationNumber: z.string() | ||
}) | ||
}) | ||
]) | ||
|
||
export type ActionInput = z.infer<typeof ActionInput> | ||
|
||
export const Action = ActionInput.and( | ||
z.object({ | ||
createdAt: z.date(), | ||
createdBy: z.string() | ||
}) | ||
) | ||
|
||
export type Action = z.infer<typeof Action> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { z } from 'zod' | ||
import { Action, ActionConfig, ActionType } from './Action' | ||
import { Label, Summary } from './utils' | ||
|
||
/** | ||
* A subset of an event. Describes fields that can be sent to the system with the intention of either creating or mutating a an event | ||
*/ | ||
export const EventInput = z.object({ | ||
type: z.string() | ||
}) | ||
export type EventInput = z.infer<typeof EventInput> | ||
|
||
/** | ||
* Description of event features defined by the country. Includes configuration for process steps and forms involved. | ||
*/ | ||
export const EventConfig = z.object({ | ||
id: z.string(), | ||
label: Label, | ||
summary: Summary, | ||
actions: z.array(ActionConfig) | ||
}) | ||
|
||
export type EventConfig = z.infer<typeof EventConfig> | ||
|
||
/** | ||
* A subset of an event. Describes how the event is stored in the search index. Contains static fields shared by all event types and custom fields defined by event configuration | ||
*/ | ||
|
||
export const EventIndex = z.object({ | ||
id: z.string(), | ||
event: z.string(), | ||
status: z.enum([ActionType.CREATE]), | ||
createdAt: z.date(), | ||
createdBy: z.string(), | ||
createdAtLocation: z.string(), // uuid | ||
modifiedAt: z.date(), | ||
assignedTo: z.string(), | ||
updatedBy: z.string(), | ||
data: z.object({}) | ||
}) | ||
|
||
export type EventIndex = z.infer<typeof EventIndex> | ||
|
||
export const Event = EventInput.extend({ | ||
id: z.string(), | ||
type: z.string(), // Should be replaced by a reference to a form version | ||
createdAt: z.date(), | ||
updatedAt: z.date(), | ||
actions: z.array(Action) | ||
}) | ||
|
||
export type Event = z.infer<typeof Event> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { z } from 'zod' | ||
import { Field, Label } from './utils' | ||
|
||
export const FormGroupField = Field.extend({ | ||
id: z.string(), | ||
type: z.string(), // @TODO: Get enums from somewhere, field types | ||
required: z.boolean(), | ||
searchable: z.boolean().optional(), | ||
analytics: z.boolean().optional() | ||
}) | ||
|
||
export const FormSection = z.object({ | ||
title: Label, | ||
groups: z.array(FormGroupField) | ||
}) | ||
|
||
export const Form = z.object({ | ||
active: z.boolean(), | ||
version: z.object({ | ||
id: z.string(), | ||
label: Label | ||
}), | ||
form: z.array(FormSection) | ||
}) |
122 changes: 122 additions & 0 deletions
122
packages/commons/src/events/fixtures/tennis-club-membership-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { type EventConfig } from '../Event' | ||
|
||
export const tennisClubMembershipEvent: EventConfig = { | ||
id: 'TENNIS_CLUB_MEMBERSHIP', | ||
summary: { | ||
title: { | ||
defaultMessage: 'Tennis club membership application', | ||
description: 'This is the title of the form', | ||
id: 'event.tennis-club-membership.summary.title' | ||
}, | ||
fields: [] | ||
}, | ||
label: { | ||
defaultMessage: 'Tennis club membership application', | ||
description: 'This is what this event is referred as in the system', | ||
id: 'event.tennis-club-membership.label' | ||
}, | ||
actions: [ | ||
{ | ||
type: 'DECLARE', | ||
label: { | ||
defaultMessage: 'Send an application', | ||
description: | ||
'This is shown as the action name anywhere the user can trigger the action from', | ||
id: 'event.tennis-club-membership.action.declare.label' | ||
}, | ||
forms: [ | ||
{ | ||
active: true, | ||
version: { | ||
id: '1', | ||
label: { | ||
defaultMessage: 'Version 1', | ||
description: 'This is the first version of the form', | ||
id: 'event.tennis-club-membership.action.declare.form.version.1' | ||
} | ||
}, | ||
form: [ | ||
{ | ||
title: { | ||
id: 'event.tennis-club-membership.action.declare.form.section.who.title', | ||
defaultMessage: 'Who is applying for the membership?', | ||
description: 'This is the title of the section' | ||
}, | ||
groups: [ | ||
{ | ||
id: 'applicant.firstname', | ||
type: 'TEXT', | ||
required: true, | ||
label: { | ||
defaultMessage: "Applicant's first name", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.who.field.firstname.label' | ||
} | ||
}, | ||
{ | ||
id: 'applicant.surname', | ||
type: 'TEXT', | ||
required: true, | ||
label: { | ||
defaultMessage: "Applicant's surname", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.who.field.surname.label' | ||
} | ||
}, | ||
{ | ||
id: 'applicant.dob', | ||
type: 'DATE', | ||
required: true, | ||
label: { | ||
defaultMessage: "Applicant's date of birth", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.who.field.dob.label' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
title: { | ||
id: 'event.tennis-club-membership.action.declare.form.section.recommender.title', | ||
defaultMessage: 'Who is recommending the applicant?', | ||
description: 'This is the title of the section' | ||
}, | ||
groups: [ | ||
{ | ||
id: 'recommender.firstname', | ||
type: 'TEXT', | ||
required: true, | ||
label: { | ||
defaultMessage: "Recommender's first name", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.firstname.label' | ||
} | ||
}, | ||
{ | ||
id: 'recommender.surname', | ||
type: 'TEXT', | ||
required: true, | ||
label: { | ||
defaultMessage: "Recommender's surname", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.surname.label' | ||
} | ||
}, | ||
{ | ||
id: 'recommender.id', | ||
type: 'TEXT', | ||
required: true, | ||
label: { | ||
defaultMessage: "Recommender's membership ID", | ||
description: 'This is the label for the field', | ||
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.id.label' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './Action' | ||
export * from './Event' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { GetValues } from '../types' | ||
import { z } from 'zod' | ||
|
||
export const Label = z.object({ | ||
defaultMessage: z.string(), | ||
description: z.string(), | ||
id: z.string() | ||
}) | ||
|
||
// Ask whether these are always together | ||
export const Field = z.object({ | ||
label: Label | ||
}) | ||
|
||
export const Summary = z.object({ | ||
title: Label, | ||
fields: z.array(Field) | ||
}) | ||
|
||
// @TODO | ||
export const Query = z.object({ | ||
requester: z.object({ | ||
phone: z.object({ | ||
check: z.string() | ||
}), | ||
name: z.object({ | ||
check: z.string() | ||
}) | ||
}) | ||
}) | ||
|
||
export const SystemRoleType = { | ||
FieldAgent: 'FIELD_AGENT', | ||
LocalRegistrar: 'LOCAL_REGISTRAR', | ||
LocalSystemAdmin: 'LOCAL_SYSTEM_ADMIN', | ||
NationalRegistrar: 'NATIONAL_REGISTRAR', | ||
NationalSystemAdmin: 'NATIONAL_SYSTEM_ADMIN', | ||
PerformanceManagement: 'PERFORMANCE_MANAGEMENT', | ||
RegistrationAgent: 'REGISTRATION_AGENT' | ||
} as const | ||
|
||
export type SystemRoleType = GetValues<typeof SystemRoleType> | ||
export const systemRoleTypes = Object.values(SystemRoleType) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only field the user can really send at the point of Event creation is
type
if we take on the approach of only submitting actions likeregisterEvent(eventId, registrationData)
from the client