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

Testing ocrvrs 7824 b #8042

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1b7d031
add some basic operations and unit tests for interfacing with events
rikukissa Nov 18, 2024
9f83721
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into ocrv…
rikukissa Nov 19, 2024
f259bc3
feat(events): create first draft of types
makelicious Nov 18, 2024
d2a03f8
feat(events): unify and clean up types
makelicious Nov 19, 2024
5d1351f
add basic structure for graphql endpoints
rikukissa Nov 20, 2024
a05906d
add tennic club membership example data
rikukissa Nov 20, 2024
68f8adb
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa Nov 20, 2024
a9f98a9
implement initial graphql resolvers for basic event operations
rikukissa Nov 20, 2024
7914c63
implement authorisation and first GraphQL -> MongoDB request chain
rikukissa Nov 20, 2024
81f470f
add license headers to all files
rikukissa Nov 21, 2024
d8addb9
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa Nov 21, 2024
0b7f354
feat(events): create first draft of types
makelicious Nov 18, 2024
5c8496f
feat(events): unify and clean up types
makelicious Nov 19, 2024
ea36eab
add tennic club membership example data
rikukissa Nov 20, 2024
79cb779
add license headers to all files
rikukissa Nov 21, 2024
9b3742c
feat(types): expose event types from commons through npm toolki
makelicious Nov 21, 2024
b12d637
feat(types): build commons when build is run
makelicious Nov 21, 2024
2a46d72
feat(types): add initial read me
makelicious Nov 21, 2024
d97d86a
fix(toolkit): exclude node_modules from tsconfig
makelicious Nov 21, 2024
5416e31
fix(events): use types from commons in tests
makelicious Nov 21, 2024
13a1bef
feat(events): expose defineConfig
makelicious Nov 21, 2024
f6100d4
chore(toolkit): update package version
makelicious Nov 21, 2024
55a2d63
Merge branch 'feat/event-types' of github.com:opencrvs/opencrvs-core …
rikukissa Nov 21, 2024
1f90403
fix tests
rikukissa Nov 21, 2024
93e2e68
fix: update package references
makelicious Nov 21, 2024
85c4caa
fix(events): bind gateway to events package
makelicious Nov 21, 2024
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
6 changes: 4 additions & 2 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"./http": "./build/dist/common/http.js",
"./fixtures": "./build/dist/common/fixtures.js",
"./assignment": "./build/dist/common/assignment.js",
"./client": "./build/dist/esm/client.js"
"./client": "./build/dist/esm/client.js",
"./events": "./build/dist/common/events/index.js"
},
"scripts": {
"start": "yarn build:watch",
Expand Down Expand Up @@ -42,10 +43,11 @@
"jwt-decode": "^3.0.0",
"lodash": "^4.17.10",
"node-fetch": "^2.6.7",
"pino": "^7.0.0",
"pkg-up": "^3.1.0",
"typescript": "5.6.3",
"uuid": "^9.0.0",
"pino": "^7.0.0"
"zod": "^3.23.8"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.5.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/commons/src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ export const getTokenPayload = (token: string): ITokenPayload => {
}
return decoded
}

export const getUserId = (token: string): string => {
const tokenPayload = getTokenPayload(token.split(' ')[1])
return tokenPayload.sub
}
96 changes: 96 additions & 0 deletions packages/commons/src/events/Action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
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({
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 CreateActionInput = ActionInputBase
export const NotifyActionInput = ActionInputBase
export const DeclareActionInput = ActionInputBase
export const RegisterActionInput = ActionInputBase.extend({
identifiers: z.object({
trackingId: z.string(),
registrationNumber: z.string()
})
})

export const ActionInput = z
.union([
CreateActionInput.extend({ type: z.enum([ActionType.CREATE]) }),
NotifyActionInput.extend({ type: z.enum([ActionType.NOTIFY]) }),
DeclareActionInput.extend({ type: z.enum([ActionType.DECLARE]) }),
RegisterActionInput.extend({ type: z.enum([ActionType.REGISTER]) })
])
.and(
z.object({
createdBy: 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>
69 changes: 69 additions & 0 deletions packages/commons/src/events/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
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>

/**
* Builds a validated configuration for an event
* @param config - Event specific configuration
*/
export const defineConfig = (config: EventConfig) =>
EventConfig.safeParse(config)
34 changes: 34 additions & 0 deletions packages/commons/src/events/Form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
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)
})
132 changes: 132 additions & 0 deletions packages/commons/src/events/fixtures/tennis-club-membership-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
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'
}
}
]
}
]
}
]
}
]
}
14 changes: 14 additions & 0 deletions packages/commons/src/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
export * from './Action'
export * from './Event'
export * from './Form'
export * from './utils'
Loading
Loading