@abgov/adsp-sdk-mcp-server 1.26.0 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +53 -7
  2. package/assets/api-specs/agent-service.json +1 -0
  3. package/assets/api-specs/audit-service.json +1 -0
  4. package/assets/api-specs/cache-service.json +1 -0
  5. package/assets/api-specs/calendar-service.json +1 -0
  6. package/assets/api-specs/comment-service.json +1 -0
  7. package/assets/api-specs/configuration-service.json +1 -0
  8. package/assets/api-specs/directory-service.json +1 -0
  9. package/assets/api-specs/event-service.json +1 -0
  10. package/assets/api-specs/export-service.json +1 -0
  11. package/assets/api-specs/feedback-service.json +1 -0
  12. package/assets/api-specs/file-service.json +1 -0
  13. package/assets/api-specs/form-service.json +1 -0
  14. package/assets/api-specs/index.json +186 -0
  15. package/assets/api-specs/notification-service.json +1 -0
  16. package/assets/api-specs/pdf-service.json +1 -0
  17. package/assets/api-specs/pii-service.json +1 -0
  18. package/assets/api-specs/project-planner-service.json +1 -0
  19. package/assets/api-specs/push-service.json +1 -0
  20. package/assets/api-specs/status-service.json +1 -0
  21. package/assets/api-specs/task-service.json +1 -0
  22. package/assets/api-specs/tenant-management-api.json +1 -0
  23. package/assets/api-specs/token-handler.json +1 -0
  24. package/assets/api-specs/value-service.json +1 -0
  25. package/assets/api-specs/verify-service.json +1 -0
  26. package/assets/docs/services/agent-service.md +31 -0
  27. package/assets/docs/services/form-service.md +301 -233
  28. package/assets/docs/services/notification-service.md +23 -0
  29. package/assets/docs/services/value-service.md +16 -0
  30. package/package.json +1 -1
  31. package/provenance.json +4 -4
  32. package/src/api-specs/apiSpecsRepository.d.ts +44 -0
  33. package/src/api-specs/apiSpecsRepository.js +113 -0
  34. package/src/api-specs/apiSpecsRepository.js.map +1 -0
  35. package/src/config.d.ts +2 -0
  36. package/src/config.js +7 -0
  37. package/src/config.js.map +1 -1
  38. package/src/hosted.d.ts +20 -0
  39. package/src/hosted.js +30 -0
  40. package/src/hosted.js.map +1 -0
  41. package/src/http.d.ts +4 -1
  42. package/src/http.js +22 -1
  43. package/src/http.js.map +1 -1
  44. package/src/index.d.ts +2 -0
  45. package/src/index.js +3 -1
  46. package/src/index.js.map +1 -1
  47. package/src/lifecycle.d.ts +18 -0
  48. package/src/lifecycle.js +52 -0
  49. package/src/lifecycle.js.map +1 -0
  50. package/src/main.js +2 -22
  51. package/src/main.js.map +1 -1
  52. package/src/metrics.js +7 -1
  53. package/src/metrics.js.map +1 -1
  54. package/src/server.d.ts +2 -0
  55. package/src/server.js +13 -3
  56. package/src/server.js.map +1 -1
  57. package/src/tools/registerApiTools.d.ts +7 -0
  58. package/src/tools/registerApiTools.js +110 -0
  59. package/src/tools/registerApiTools.js.map +1 -0
@@ -5,101 +5,134 @@ parent: Services
5
5
  ---
6
6
 
7
7
  # Form service
8
+
8
9
  Form service provides for temporary storage of draft forms with support for verify code based access. This permits applicants to draft and submit forms without a user account.
9
10
 
10
- The form service also includes a set of *events* and a *notification type* for keeping applicants updated on the status of their submission.
11
+ The form service also includes a set of _events_ and a _notification type_ for keeping applicants updated on the status of their submission.
11
12
 
12
13
  ## Client roles
14
+
13
15
  client `urn:ads:platform:form-service`
14
16
 
15
- | name | description |
16
- |:-|:-|
17
- | form-admin | Administrator role for form service. This role allows a user to manage form definitions, find and read all forms and submissions of the tenant, unlock, archive and delete forms, delete submissions, and manage data registers. |
18
- | intake-application | Intake application role for form service. This role is used to grant a service account the ability to retrieve draft forms and submit forms on behalf of an anonymous applicant. |
19
- | form-applicant | Applicant role for form service that allows a user to apply from the form app. It permits subscribing to the submitted form PDF and form question update streams. |
20
- | form-support | Support role for viewing and responding to form question topics. It is a commenter role of the form questions comment topic type, and a subscriber role of the form message reviewer notifications. |
21
- | form-file-reader | File reader role that allows assessors and clerks to review uploaded supporting documents. |
22
- | form-file-uploader | File uploader role that allows applicants to upload supporting documents for the form. |
23
- | form-tester | Tester role for form service that allows access to forms without open intakes. |
24
- | form-service | Form service role used to permit deletion of orphaned form support document files. |
17
+ | name | description |
18
+ | :-------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | form-admin | Administrator role for form service. This role allows a user to manage form definitions, find and read all forms and submissions of the tenant, unlock, archive and delete forms, delete submissions, manage data registers, and submit, read, approve and deny access requests. |
20
+ | intake-application | Intake application role for form service. This role is used to grant a service account the ability to retrieve draft forms and submit forms on behalf of an anonymous applicant. |
21
+ | form-applicant | Applicant role for form service that allows a user to apply from the form app. It permits subscribing to the submitted form PDF and form question update streams. |
22
+ | form-support | Support role for viewing and responding to form question topics. It is a commenter role of the form questions comment topic type, and a subscriber role of the form message reviewer notifications. |
23
+ | form-file-reader | File reader role that allows assessors and clerks to review uploaded supporting documents. |
24
+ | form-file-uploader | File uploader role that allows applicants to upload supporting documents for the form. |
25
+ | form-tester | Tester role for form service that allows access to forms without open intakes. |
26
+ | form-service | Form service role used to permit deletion of orphaned form support document files. |
27
+ | form-access-requester | Registration requester role that allows submitting a request for access to a restricted form, and reading your own request. |
28
+ | form-access-reader | Registration reader role that allows reading the access requests of restricted forms. |
29
+ | form-access-writer | Registration writer role that allows reading, approving and denying the access requests of restricted forms. |
25
30
 
26
31
  The data register API also accepts the configuration service role `urn:ads:platform:configuration-service:configuration-admin`, which tenant administrators have by default. Form and submission searches also accept the export service role `urn:ads:platform:export-service:export-job`.
27
32
 
28
33
  Each form definition also names its own **applicant**, **clerk** and **assessor** roles. These are tenant roles, and they control who can create and fill in forms of the definition, and who can review its submissions.
29
34
 
30
35
  ## Tenancy
36
+
31
37
  - **Which tenant is used.** Tenant users and service accounts act on the tenant of their token. Core (platform) users set the `tenantId` query parameter to choose the tenant. The form definition, form, submission, data register and intake schedule endpoints act on one tenant, so core users must set `tenantId` on them.
32
38
  - **Anonymous requests.** Only `GET /form/v1/definitions/{definitionId}` allows anonymous requests, for definitions that allow anonymous applications. Anonymous requests have no token to determine the tenant from, so they must include `tenantId`; without it the request responds 400.
33
39
  - **Form definitions.** Form definitions are tenant configuration in the [configuration service](configuration-service.md). Form service uses the tenant's own definitions and does not fall back to platform definitions.
34
- - **Isolation.** Forms and submissions are stored with the ID of their tenant. A form or submission ID from another tenant responds 404, not 403.
40
+ - **Isolation.** Forms and submissions are stored with the ID of their tenant. A form or submission ID from another tenant responds 404, not 403. Access requests are stored with the ID of their tenant and form definition; a request ID of another tenant or definition also responds 404.
35
41
  - **Role scope.** The roles of a form definition must be held in the tenant. Most `form-admin` checks also accept a core user with the role, but listing definitions, reading a definition, finding submissions and setting a form back to draft need the role in the tenant. The `export-job` role is accepted from core service accounts.
36
42
 
37
43
  ## API overview
44
+
38
45
  All endpoints are under `https://form-service.adsp.alberta.ca/form/v1`. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
39
46
 
40
- | Endpoint | Purpose | Required role |
41
- |:-|:-|:-|
42
- | `GET /form/v1/definitions` | List and search form definitions. | `form-admin` |
43
- | `POST /form/v1/definitions` | Create a form definition from a name and description. | `form-admin` |
44
- | `GET /form/v1/definitions/{definitionId}` | Read a form definition and its current intake. | `form-admin`, `intake-application`, or the definition's applicant or clerk roles; anonymous for definitions that allow anonymous applications |
45
- | `PUT`, `PATCH`, `DELETE /form/v1/definitions/{definitionId}` | Replace, update or delete a form definition. | `form-admin` |
46
- | `PUT /form/v1/definitions/{definitionId}/schemas` | Update the data and UI schemas. | `form-admin` |
47
- | `PUT /form/v1/definitions/{definitionId}/roles` | Replace the applicant, assessor and clerk roles. | `form-admin` |
48
- | `PATCH /form/v1/definitions/{definitionId}/lifecycle` | Update the anonymous application, applicant limit, support topic and security classification settings. | `form-admin` |
49
- | `PATCH /form/v1/definitions/{definitionId}/submission-actions` | Update what happens when a form is submitted. | `form-admin` |
50
- | `PUT /form/v1/definitions/{definitionId}/schedule` | Update the scheduled intake period. | `form-admin` |
51
- | `GET /form/v1/forms` | Find forms. | Any signed-in user; `form-admin` and `export-job` find all forms, assessors find the submitted forms of their definition, and other users find the forms they created |
52
- | `POST /form/v1/forms` | Create a draft form, and optionally submit it. | The definition's applicant or clerk roles; `intake-application` for definitions that allow anonymous applications |
53
- | `GET /form/v1/forms/{formId}` | Read a form. | `form-admin`, `intake-application`, the definition's clerk or assessor roles, or the applicant who created it |
54
- | `POST /form/v1/forms/{formId}` | Run a form operation: `send-code`, `unlock`, `submit`, `to-draft` or `archive`. | Depends on the operation (see the API documentation) |
55
- | `DELETE /form/v1/forms/{formId}` | Delete a form and its files. | `form-admin`; the definition's clerk roles or the applicant who created it, for draft forms |
56
- | `GET`, `PUT /form/v1/forms/{formId}/data` | Read or update the form data. | The applicant who created it or the definition's clerk roles; reading also allows `form-admin`, assessors of submitted forms, and `intake-application` with a verification code |
57
- | `GET /form/v1/submissions`, `GET /form/v1/forms/{formId}/submissions` | Find submissions. | `form-admin`, `export-job`, or the definition's assessor roles |
58
- | `GET /form/v1/submissions/{submissionId}`, `GET /form/v1/forms/{formId}/submissions/{submissionId}` | Read a submission. | `form-admin` or the definition's assessor roles |
59
- | `POST /form/v1/forms/{formId}/submissions/{submissionId}` | Disposition a submission. | `form-admin` or the definition's assessor roles |
60
- | `POST /form/v1/forms/{formId}/submissions/{submissionId}/notes`, `DELETE .../notes/{noteId}` | Add or remove a reviewer note. | `form-admin` or the definition's assessor roles |
61
- | `DELETE /form/v1/submissions/{submissionId}` | Delete a submission. | `form-admin` |
62
- | `/form/v1/registers` | Manage data registers (see [Data registers](#data-registers)). | `form-admin` or `configuration-admin` |
47
+ | Endpoint | Purpose | Required role |
48
+ | :-------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
49
+ | `GET /form/v1/definitions` | List and search form definitions. | `form-admin` |
50
+ | `POST /form/v1/definitions` | Create a form definition from a name and description. | `form-admin` |
51
+ | `GET /form/v1/definitions/{definitionId}` | Read a form definition and its current intake. | `form-admin`, `intake-application`, or the definition's applicant or clerk roles; anonymous for definitions that allow anonymous applications |
52
+ | `PUT`, `PATCH`, `DELETE /form/v1/definitions/{definitionId}` | Replace, update or delete a form definition. | `form-admin` |
53
+ | `PUT /form/v1/definitions/{definitionId}/schemas` | Update the data and UI schemas. | `form-admin` |
54
+ | `PUT /form/v1/definitions/{definitionId}/roles` | Replace the applicant, assessor and clerk roles. | `form-admin` |
55
+ | `PATCH /form/v1/definitions/{definitionId}/lifecycle` | Update the anonymous application, applicant limit, support topic and security classification settings. | `form-admin` |
56
+ | `PATCH /form/v1/definitions/{definitionId}/submission-actions` | Update what happens when a form is submitted. | `form-admin` |
57
+ | `PUT /form/v1/definitions/{definitionId}/schedule` | Update the scheduled intake period. | `form-admin` |
58
+ | `POST /form/v1/definitions/{definitionId}/access-requests` | Request access to a restricted form. | `form-access-requester` or `form-admin` |
59
+ | `GET /form/v1/definitions/{definitionId}/access-requests` | Find the access requests of a form, by status, newest first. | `form-access-reader`, `form-access-writer` or `form-admin` |
60
+ | `GET /form/v1/definitions/{definitionId}/access-requests/{email}` | Read the latest access request of an email address. | The user with that email address, `form-access-reader`, `form-access-writer` or `form-admin` |
61
+ | `PATCH /form/v1/definitions/{definitionId}/access-requests/{requestId}` | Approve or deny a pending access request. | `form-access-writer` or `form-admin` |
62
+ | `GET /form/v1/forms` | Find forms. | Any signed-in user; `form-admin` and `export-job` find all forms, assessors find the submitted forms of their definition, and other users find the forms they created |
63
+ | `POST /form/v1/forms` | Create a draft form, and optionally submit it. | The definition's applicant or clerk roles; `intake-application` for definitions that allow anonymous applications |
64
+ | `GET /form/v1/forms/{formId}` | Read a form. | `form-admin`, `intake-application`, the definition's clerk or assessor roles, or the applicant who created it |
65
+ | `POST /form/v1/forms/{formId}` | Run a form operation: `send-code`, `unlock`, `submit`, `to-draft` or `archive`. | Depends on the operation (see the API documentation) |
66
+ | `DELETE /form/v1/forms/{formId}` | Delete a form and its files. | `form-admin`; the definition's clerk roles or the applicant who created it, for draft forms |
67
+ | `GET`, `PUT /form/v1/forms/{formId}/data` | Read or update the form data. | The applicant who created it or the definition's clerk roles; reading also allows `form-admin`, assessors of submitted forms, and `intake-application` with a verification code |
68
+ | `GET /form/v1/submissions`, `GET /form/v1/forms/{formId}/submissions` | Find submissions. | `form-admin`, `export-job`, or the definition's assessor roles |
69
+ | `GET /form/v1/submissions/{submissionId}`, `GET /form/v1/forms/{formId}/submissions/{submissionId}` | Read a submission. | `form-admin` or the definition's assessor roles |
70
+ | `POST /form/v1/forms/{formId}/submissions/{submissionId}` | Disposition a submission. | `form-admin` or the definition's assessor roles |
71
+ | `POST /form/v1/forms/{formId}/submissions/{submissionId}/notes`, `DELETE .../notes/{noteId}` | Add or remove a reviewer note. | `form-admin` or the definition's assessor roles |
72
+ | `DELETE /form/v1/submissions/{submissionId}` | Delete a submission. | `form-admin` |
73
+ | `/form/v1/registers` | Manage data registers (see [Data registers](#data-registers)). | `form-admin` or `configuration-admin` |
63
74
 
64
75
  Form definitions are stored in the configuration service, so they can also be managed through the configuration service API.
65
76
 
66
77
  ## Concepts
78
+
67
79
  ### Form definition
80
+
68
81
  Form definition describes a type of form including the allowed applicant and assessor roles and whether anonymous applicants are permitted. Form definitions are configured in the [configuration service](configuration-service.md) under the `form-service` namespace, with the definition ID as the name.
69
82
 
70
83
  ### Form
71
- Form represents a particular instance of an application including the information entered by the *applicant*. Each form is associated with a *definition* and has a status. Statuses represent the lifecycle steps of the form and include: Draft, Locked, Submitted, and Archived.
84
+
85
+ Form represents a particular instance of an application including the information entered by the _applicant_. Each form is associated with a _definition_ and has a status. Statuses represent the lifecycle steps of the form and include: Draft, Locked, Submitted, and Archived.
72
86
 
73
87
  ### Submission
74
- When a form is submitted and its definition has submission records enabled, form service creates a *submission* with a copy of the form data. Assessors review submissions, add notes, and record a *disposition* using one of the definition's disposition states. A form that is set back to draft and submitted again gets a new submission.
88
+
89
+ When a form is submitted and its definition has submission records enabled, form service creates a _submission_ with a copy of the form data. Assessors review submissions, add notes, and record a _disposition_ using one of the definition's disposition states. A form that is set back to draft and submitted again gets a new submission.
75
90
 
76
91
  ### Draft expiry
92
+
77
93
  Draft forms include an expiry process so that information entered into draft forms are purged if the draft is abandoned. If a draft form is not accessed for some expiry period, the form is locked and the applicant is notified. In this state, the form cannot be accessed by the applicant but can be unlocked by an administrator. If the form remains in a locked state for some additional expiry period, the form is deleted so that applicant information is not unnecessarily retained.
78
94
 
79
95
  ### Data register
96
+
80
97
  Data register is a named list of values used to populate drop downs and other choice controls in forms. Each value is either a string or an object, such as a `label` and `value` pair. Forms reference a register by its URN in the UI schema. See the [data registers tutorial](../tutorials/form-service/data-registers.md) for how to use registers in a form.
81
98
 
99
+ ### Access request
100
+
101
+ Some forms are restricted to a segment of the population, for example to physicians and nurses in Alberta. A form definition is restricted by its `registration` configuration:
102
+
103
+ - `enabled`: whether the form is restricted and accepts access requests.
104
+ - `dataSchema` and `uiSchema`: the registration questions that help a reviewer decide whether the applicant meets the criteria. The questions can't define `firstName`, `lastName` or `email`, since every request includes them.
105
+ - `accessGroup`: the Keycloak group containing the roles needed to access the form. It is not returned by the form APIs.
106
+
107
+ An applicant submits an _access request_ with their name, email address and answers. Answers are validated against the registration questions, and answers to questions that aren't defined are rejected. The request starts as `pending`, and an administrator then approves or denies it. Each email address can have only one pending request per form; after a request is reviewed, the applicant can submit a new one. Approved or denied requests can't be reviewed again.
108
+
109
+ Form service only records requests and reviews. It doesn't create Keycloak accounts, add users to the access group, or notify the applicant.
110
+
82
111
  ## Data registers
112
+
83
113
  Form service provides an API to manage the data registers of a tenant. Tenant administrators can also manage them in the tenant management webapp under Form service → Register data.
84
114
 
85
115
  Form service stores each register in the [configuration service](configuration-service.md) in two parts:
116
+
86
117
  - **Definition**: the `data-register:<name>` entry in the tenant's `platform:configuration-service` configuration. It holds the register's schema and description.
87
118
  - **Entries**: the configuration with namespace `data-register` and the register's name. It holds the array of values.
88
119
 
89
120
  ### Endpoints
121
+
90
122
  All endpoints require a user with the `urn:ads:platform:form-service:form-admin` role or the `urn:ads:platform:configuration-service:configuration-admin` role, in the context of a tenant. A core user must specify the tenant with the `tenantId` query parameter. Every endpoint returns 401 if the user is not authenticated, 403 if the user has neither role, and 502 if configuration service fails.
91
123
 
92
- | Method | Path | Description | Responses |
93
- |:-|:-|:-|:-|
94
- | GET | `/form/v1/registers` | Lists the tenant's data registers. | 200 |
95
- | GET | `/form/v1/registers/{name}` | Gets a data register. | 200, 404 |
96
- | POST | `/form/v1/registers` | Creates a data register from `name`, `description` and `entries`. `entries` defaults to an empty array. | 201, 400, 409 |
97
- | PATCH | `/form/v1/registers/{name}` | Updates `description` and/or `entries`. A field that is not sent is left unchanged. | 200, 400, 404 |
98
- | DELETE | `/form/v1/registers/{name}` | Deletes the data register's entries and definition. | 204, 404 |
124
+ | Method | Path | Description | Responses |
125
+ | :----- | :-------------------------- | :------------------------------------------------------------------------------------------------------ | :------------ |
126
+ | GET | `/form/v1/registers` | Lists the tenant's data registers. | 200 |
127
+ | GET | `/form/v1/registers/{name}` | Gets a data register. | 200, 404 |
128
+ | POST | `/form/v1/registers` | Creates a data register from `name`, `description` and `entries`. `entries` defaults to an empty array. | 201, 400, 409 |
129
+ | PATCH | `/form/v1/registers/{name}` | Updates `description` and/or `entries`. A field that is not sent is left unchanged. | 200, 400, 404 |
130
+ | DELETE | `/form/v1/registers/{name}` | Deletes the data register's entries and definition. | 204, 404 |
99
131
 
100
132
  Registers are returned as `{ namespace: 'data-register', name, description, entries }`.
101
133
 
102
134
  ### Rules
135
+
103
136
  - **Existence**: a register exists only when both its definition (with an array schema) and its entries exist. A register missing either part is not listed. It returns 404 and does not block a create with the same name. This means a create or delete can be retried after a partial failure.
104
137
  - **Active revision**: `entries` come from the active revision of the configuration, or from the latest revision if none is active. The form app uses the same revision at runtime.
105
138
  - **Writing entries publishes them**: configuration service only writes to the latest revision. When a create or update writes `entries` and an older revision is pinned as active, the pin moves to the revision just written, so the change is live straight away. The older revision stays in the revision history and can be pinned again in configuration service. Updating only `description` leaves the pin alone.
@@ -114,22 +147,27 @@ Registers are returned as `{ namespace: 'data-register', name, description, entr
114
147
  Form service does not emit its own events for data registers. Configuration service emits `configuration-updated` and `configuration-deleted` for the underlying configuration.
115
148
 
116
149
  ## Events
150
+
117
151
  Form service sends these domain events in the `form-service` namespace. Form events use the form ID as the correlation ID.
118
152
 
119
- | name | sent when |
120
- |:-|:-|
121
- | form-created | A draft form is created. When a form is created with `submit: true`, `form-submitted` is sent instead. |
122
- | form-locked | The draft expiry job locks a draft that has not been accessed. |
123
- | form-unlocked | An administrator unlocks a locked form. |
124
- | form-submitted | A form is submitted. The form data is included when the definition sets `includeDataInSubmission`. |
125
- | form-to-draft | A submitted form is set back to draft. |
126
- | form-archived | A form is archived. |
127
- | form-deleted | A form is deleted through the API or by the draft expiry job. |
128
- | submission-dispositioned | A submission is dispositioned. |
129
- | submission-deleted | A submission is deleted. |
130
- | form-message-to-applicant | A reviewer posts a message on a form's questions topic. |
131
- | form-message-to-reviewer | An applicant posts a message and a reviewer is part of the conversation. |
132
- | form-message-forwarded | An applicant posts a message, no reviewer is part of the conversation, and the definition sets an address to forward questions to. |
153
+ | name | sent when |
154
+ | :------------------------ | :--------------------------------------------------------------------------------------------------------------------------------- |
155
+ | form-created | A draft form is created. When a form is created with `submit: true`, `form-submitted` is sent instead. |
156
+ | form-locked | The draft expiry job locks a draft that has not been accessed. |
157
+ | form-unlocked | An administrator unlocks a locked form. |
158
+ | form-submitted | A form is submitted. The form data is included when the definition sets `includeDataInSubmission`. |
159
+ | form-to-draft | A submitted form is set back to draft. |
160
+ | form-archived | A form is archived. |
161
+ | form-deleted | A form is deleted through the API or by the draft expiry job. |
162
+ | submission-dispositioned | A submission is dispositioned. |
163
+ | submission-deleted | A submission is deleted. |
164
+ | form-message-to-applicant | A reviewer posts a message on a form's questions topic. |
165
+ | form-message-to-reviewer | An applicant posts a message and a reviewer is part of the conversation. |
166
+ | form-message-forwarded | An applicant posts a message, no reviewer is part of the conversation, and the definition sets an address to forward questions to. |
167
+ | registration-submitted | An access request for a restricted form is submitted. |
168
+ | registration-reviewed | An access request is approved or denied. |
169
+
170
+ Access request events use the request ID as the correlation ID, and include its `id`, `formDefinitionId`, `status`, `submittedAt`, `reviewedAt` and `reviewedBy`. The applicant's name, email address and answers are not included.
133
171
 
134
172
  When a definition sets a custom submission event (`event` in the submission actions), form service also sends that event, in the namespace and with the name it configures, each time a form is submitted.
135
173
 
@@ -138,24 +176,29 @@ Form service registers the `form-status-updates`, `form-message-notifications` a
138
176
  Form service consumes the comment service `comment-created` event for form question topics to send the message events above.
139
177
 
140
178
  ## Audit actions
179
+
141
180
  Form service records audit events in the `form-service` namespace of the [audit service](audit-service.md). Records are written to the tenant of the form, submission or data register. Form records use the form as the resource (`{ type: 'form', id: <form ID> }`) and correlation ID, with the form `definitionId`, `status` (after the operation), `anonymousApplicant` and `dryRun` in the metadata. Form data and applicant details are never recorded. All actions are version 1.
142
181
 
143
- | action | category | severity | retention class | recorded when |
144
- |:-|:-|:-|:-|:-|
145
- | form.created | administrative | info | compliance | A draft form is created, with `hasApplicant` in the metadata. |
146
- | form.data-updated | data-access | info | standard | Form data is written, including data sent when creating a form. Drafts are autosaved as the applicant types, so updates are recorded at most once per form and caller in 15 minutes (tracked by each service instance). Only `fileCount` is recorded about the data. |
147
- | form.submitted | administrative | info | compliance | A form is submitted, including when it is created with `submit: true`, with the `submissionId` if a submission record is created. |
148
- | form.locked | administrative | warning | compliance | The draft expiry job locks an inactive draft, with `reason: 'inactivity'` and `lastAccessed` in the metadata. |
149
- | form.unlocked | administrative | warning | compliance | An administrator unlocks a locked form, with the previous `locked` time in the metadata. |
150
- | form.set-to-draft | administrative | warning | compliance | A submitted form is set back to draft. |
151
- | form.archived | administrative | info | compliance | A form is archived. |
152
- | form.deleted | administrative | warning | compliance | A form and its files are deleted through the API, or by the draft expiry job (with `reason: 'lock-expired'` and the `locked` time in the metadata). |
153
- | form.access-code-sent | security | info | security | An access code is sent to the applicant of a form, with the notification `channels` types in the metadata. |
154
- | form.accessed-with-code | security | info | security | Form data is read using a verified access code. |
155
- | submission.deleted | administrative | warning | compliance | A form submission is deleted. The resource is `{ type: 'submission', id: <submission ID> }` and the correlation ID is the form ID. |
156
- | data-register.created | administrative | info | standard | A data register is created, with its `entryCount`. |
157
- | data-register.updated | administrative | info | standard | A data register is updated, with the `updatedFields` and the `entryCount`. |
158
- | data-register.deleted | administrative | warning | standard | A data register is deleted. |
182
+ | action | category | severity | retention class | recorded when |
183
+ | :---------------------- | :------------- | :------- | :-------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
184
+ | form.created | administrative | info | compliance | A draft form is created, with `hasApplicant` in the metadata. |
185
+ | form.data-updated | data-access | info | standard | Form data is written, including data sent when creating a form. Drafts are autosaved as the applicant types, so updates are recorded at most once per form and caller in 15 minutes (tracked by each service instance). Only `fileCount` is recorded about the data. |
186
+ | form.submitted | administrative | info | compliance | A form is submitted, including when it is created with `submit: true`, with the `submissionId` if a submission record is created. |
187
+ | form.locked | administrative | warning | compliance | The draft expiry job locks an inactive draft, with `reason: 'inactivity'` and `lastAccessed` in the metadata. |
188
+ | form.unlocked | administrative | warning | compliance | An administrator unlocks a locked form, with the previous `locked` time in the metadata. |
189
+ | form.set-to-draft | administrative | warning | compliance | A submitted form is set back to draft. |
190
+ | form.archived | administrative | info | compliance | A form is archived. |
191
+ | form.deleted | administrative | warning | compliance | A form and its files are deleted through the API, or by the draft expiry job (with `reason: 'lock-expired'` and the `locked` time in the metadata). |
192
+ | form.access-code-sent | security | info | security | An access code is sent to the applicant of a form, with the notification `channels` types in the metadata. |
193
+ | form.accessed-with-code | security | info | security | Form data is read using a verified access code. |
194
+ | submission.deleted | administrative | warning | compliance | A form submission is deleted. The resource is `{ type: 'submission', id: <submission ID> }` and the correlation ID is the form ID. |
195
+ | data-register.created | administrative | info | standard | A data register is created, with its `entryCount`. |
196
+ | data-register.updated | administrative | info | standard | A data register is updated, with the `updatedFields` and the `entryCount`. |
197
+ | data-register.deleted | administrative | warning | standard | A data register is deleted. |
198
+ | registration.submitted | administrative | info | standard | An access request is submitted. |
199
+ | registration.reviewed | administrative | info | compliance | An access request is approved or denied. |
200
+
201
+ Access request records use `{ type: 'registration', id: <request ID> }` as the resource and the request ID as the correlation ID, with the `definitionId` and `status` in the metadata.
159
202
 
160
203
  Data register records use `{ type: 'data-register', id: <name>, name: <name> }` as the resource and the register name as the correlation ID. Configuration service also records `configuration.updated` and `configuration.deleted` for the underlying configuration, attributed to the form service account; the form service records identify the user who made the change.
161
204
 
@@ -168,190 +211,215 @@ Draft data is saved frequently, so form service sends audit events in batches of
168
211
  Audit recording is on by default. Set the environment variable `FORM_AUDIT_ENABLED=false` on form service to turn it off, or `true` to turn it on regardless of the SDK `AUDIT_ENABLED` variable, which applies when `FORM_AUDIT_ENABLED` is not set. The action catalog is still registered while recording is off, so turning it back on needs only a restart.
169
212
 
170
213
  ## Code examples
214
+
171
215
  ### Create a form definition
216
+
172
217
  ```typescript
173
- const response = await fetch(
174
- 'https://form-service.adsp.alberta.ca/form/v1/definitions',
175
- {
176
- method: 'POST',
177
- headers: {
178
- 'Authorization': `Bearer ${accessToken}`,
179
- 'Content-Type': 'application/json',
180
- },
181
- body: JSON.stringify({
182
- name: 'Business licence application',
183
- description: 'Application for a municipal business licence.',
184
- }),
185
- }
186
- );
187
-
188
- // The ID is generated from the name, for example 'business-licence-application'.
189
- const { id, revision } = await response.json();
190
-
191
- // Set who can apply and who can assess submissions.
192
- await fetch(
193
- `https://form-service.adsp.alberta.ca/form/v1/definitions/${id}/roles`,
194
- {
195
- method: 'PUT',
196
- headers: {
197
- 'Authorization': `Bearer ${accessToken}`,
198
- 'Content-Type': 'application/json',
199
- },
200
- body: JSON.stringify({
201
- applicantRoles: ['business-licence-applicant'],
202
- assessorRoles: ['business-licence-assessor'],
203
- }),
204
- }
205
- );
218
+ const response = await fetch('https://form-service.adsp.alberta.ca/form/v1/definitions', {
219
+ method: 'POST',
220
+ headers: {
221
+ Authorization: `Bearer ${accessToken}`,
222
+ 'Content-Type': 'application/json',
223
+ },
224
+ body: JSON.stringify({
225
+ name: 'Business licence application',
226
+ description: 'Application for a municipal business licence.',
227
+ }),
228
+ });
229
+
230
+ // The ID is generated from the name, for example 'business-licence-application'.
231
+ const { id, revision } = await response.json();
232
+
233
+ // Set who can apply and who can assess submissions.
234
+ await fetch(`https://form-service.adsp.alberta.ca/form/v1/definitions/${id}/roles`, {
235
+ method: 'PUT',
236
+ headers: {
237
+ Authorization: `Bearer ${accessToken}`,
238
+ 'Content-Type': 'application/json',
239
+ },
240
+ body: JSON.stringify({
241
+ applicantRoles: ['business-licence-applicant'],
242
+ assessorRoles: ['business-licence-assessor'],
243
+ }),
244
+ });
206
245
  ```
207
246
 
208
247
  ### Create a draft form for an anonymous applicant
248
+
209
249
  ```typescript
210
- const form = {
211
- definitionId,
212
- applicant: {
213
- addressAs: 'A.N.Other',
214
- channels: [{
250
+ const form = {
251
+ definitionId,
252
+ applicant: {
253
+ addressAs: 'A.N.Other',
254
+ channels: [
255
+ {
215
256
  channel: 'email',
216
- address: 'a.n.other@acme.org'
217
- }]
218
- }
219
- }
220
-
221
- const response = await fetch(
222
- 'https://form-service.adsp.alberta.ca/form/v1/forms',
223
- {
224
- method: 'POST',
225
- headers: {
226
- 'Authorization': `Bearer ${accessToken}`,
227
- 'Content-Type': 'application/json',
257
+ address: 'a.n.other@acme.org',
228
258
  },
229
- body: JSON.stringify(form),
230
- }
231
- );
232
-
233
- const {
234
- id,
235
- definition,
236
- status,
237
- created,
238
- createdBy,
239
- lastAccessed,
240
- } = await response.json();
259
+ ],
260
+ },
261
+ };
262
+
263
+ const response = await fetch('https://form-service.adsp.alberta.ca/form/v1/forms', {
264
+ method: 'POST',
265
+ headers: {
266
+ Authorization: `Bearer ${accessToken}`,
267
+ 'Content-Type': 'application/json',
268
+ },
269
+ body: JSON.stringify(form),
270
+ });
271
+
272
+ const { id, definition, status, created, createdBy, lastAccessed } = await response.json();
241
273
  ```
242
274
 
243
275
  ### Access form data using a time limited code.
276
+
244
277
  Intake applications can retrieve form data on behalf of anonymous applicants by requesting a time limited code to be sent to the applicant. The code is provided to the API and verified when requesting the form data.
278
+
245
279
  ```typescript
246
- // Send a code to the applicant.
247
- await fetch(
248
- `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}`,
249
- {
250
- method: 'POST',
251
- headers: {
252
- 'Authorization': `Bearer ${accessToken}`,
253
- 'Content-Type': 'application/json',
254
- },
255
- body: JSON.stringify({
256
- operation: 'send-code',
257
- }),
258
- }
259
- );
260
-
261
- // Get the code via user input and send it to the API to access the form data.
262
- const response = await fetch(
263
- `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/data?code=${code}`,
264
- {
265
- method: 'GET',
266
- headers: { Authorization: `Bearer ${accessToken}` },
267
- }
268
- );
269
-
270
- const {
271
- data,
272
- files,
273
- } = await response.json();
280
+ // Send a code to the applicant.
281
+ await fetch(`https://form-service.adsp.alberta.ca/form/v1/forms/${formId}`, {
282
+ method: 'POST',
283
+ headers: {
284
+ Authorization: `Bearer ${accessToken}`,
285
+ 'Content-Type': 'application/json',
286
+ },
287
+ body: JSON.stringify({
288
+ operation: 'send-code',
289
+ }),
290
+ });
291
+
292
+ // Get the code via user input and send it to the API to access the form data.
293
+ const response = await fetch(`https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/data?code=${code}`, {
294
+ method: 'GET',
295
+ headers: { Authorization: `Bearer ${accessToken}` },
296
+ });
297
+
298
+ const { data, files } = await response.json();
274
299
  ```
275
300
 
276
301
  ### Update data in a draft form
302
+
277
303
  Files are referenced by their file service URN in the data. Form service finds the file references using the data schema, and returns them in `files`.
304
+
278
305
  ```typescript
279
- const formData = {
280
- data: {
281
- businessName: 'Example Bakery Ltd.',
282
- proofOfStatus: fileUrn,
283
- },
284
- }
285
-
286
- const response = await fetch(
287
- `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/data`,
288
- {
289
- method: 'PUT',
290
- headers: {
291
- 'Authorization': `Bearer ${accessToken}`,
292
- 'Content-Type': 'application/json',
293
- },
294
- body: JSON.stringify(formData),
295
- }
296
- );
297
-
298
- const {
299
- data,
300
- files,
301
- } = await response.json();
306
+ const formData = {
307
+ data: {
308
+ businessName: 'Example Bakery Ltd.',
309
+ proofOfStatus: fileUrn,
310
+ },
311
+ };
312
+
313
+ const response = await fetch(`https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/data`, {
314
+ method: 'PUT',
315
+ headers: {
316
+ Authorization: `Bearer ${accessToken}`,
317
+ 'Content-Type': 'application/json',
318
+ },
319
+ body: JSON.stringify(formData),
320
+ });
321
+
322
+ const { data, files } = await response.json();
302
323
  ```
303
324
 
304
325
  ### Submit a form
326
+
305
327
  ```typescript
306
- const response = await fetch(
307
- `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}`,
308
- {
309
- method: 'POST',
310
- headers: {
311
- 'Authorization': `Bearer ${accessToken}`,
312
- 'Content-Type': 'application/json',
313
- },
314
- body: JSON.stringify({
315
- operation: 'submit'
316
- }),
317
- }
318
- );
319
-
320
- const {
321
- id,
322
- status,
323
- submitted,
324
- submission,
325
- } = await response.json();
328
+ const response = await fetch(`https://form-service.adsp.alberta.ca/form/v1/forms/${formId}`, {
329
+ method: 'POST',
330
+ headers: {
331
+ Authorization: `Bearer ${accessToken}`,
332
+ 'Content-Type': 'application/json',
333
+ },
334
+ body: JSON.stringify({
335
+ operation: 'submit',
336
+ }),
337
+ });
338
+
339
+ const { id, status, submitted, submission } = await response.json();
326
340
  ```
327
341
 
328
342
  ### Disposition a submission
343
+
329
344
  Assessors find the submissions of a definition that are waiting for a decision, and record a disposition using one of the definition's disposition states.
345
+
330
346
  ```typescript
331
- const criteria = JSON.stringify({ definitionIdEquals: definitionId, dispositioned: false });
332
- const response = await fetch(
333
- `https://form-service.adsp.alberta.ca/form/v1/submissions?criteria=${encodeURIComponent(criteria)}`,
334
- {
335
- headers: { Authorization: `Bearer ${accessToken}` },
336
- }
337
- );
338
- const { results, page } = await response.json();
339
-
340
- const [{ id: submissionId, formId }] = results;
341
- const dispositionResponse = await fetch(
342
- `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/submissions/${submissionId}`,
343
- {
344
- method: 'POST',
345
- headers: {
346
- 'Authorization': `Bearer ${accessToken}`,
347
- 'Content-Type': 'application/json',
348
- },
349
- body: JSON.stringify({
350
- dispositionStatus: 'Approved',
351
- dispositionReason: 'Application meets all eligibility criteria.',
352
- }),
353
- }
354
- );
355
-
356
- const { disposition } = await dispositionResponse.json();
347
+ const criteria = JSON.stringify({ definitionIdEquals: definitionId, dispositioned: false });
348
+ const response = await fetch(
349
+ `https://form-service.adsp.alberta.ca/form/v1/submissions?criteria=${encodeURIComponent(criteria)}`,
350
+ {
351
+ headers: { Authorization: `Bearer ${accessToken}` },
352
+ },
353
+ );
354
+ const { results, page } = await response.json();
355
+
356
+ const [{ id: submissionId, formId }] = results;
357
+ const dispositionResponse = await fetch(
358
+ `https://form-service.adsp.alberta.ca/form/v1/forms/${formId}/submissions/${submissionId}`,
359
+ {
360
+ method: 'POST',
361
+ headers: {
362
+ Authorization: `Bearer ${accessToken}`,
363
+ 'Content-Type': 'application/json',
364
+ },
365
+ body: JSON.stringify({
366
+ dispositionStatus: 'Approved',
367
+ dispositionReason: 'Application meets all eligibility criteria.',
368
+ }),
369
+ },
370
+ );
371
+
372
+ const { disposition } = await dispositionResponse.json();
373
+ ```
374
+
375
+ ### Request and review access to a restricted form
376
+
377
+ An applicant with the `form-access-requester` role requests access to a form whose definition has registration enabled.
378
+
379
+ ```typescript
380
+ const response = await fetch(
381
+ `https://form-service.adsp.alberta.ca/form/v1/definitions/${definitionId}/access-requests`,
382
+ {
383
+ method: 'POST',
384
+ headers: {
385
+ Authorization: `Bearer ${accessToken}`,
386
+ 'Content-Type': 'application/json',
387
+ },
388
+ body: JSON.stringify({
389
+ firstName: 'Test',
390
+ lastName: 'User',
391
+ email: 'test.user@gov.ab.ca',
392
+ data: { profession: 'physician', registrationNumber: '12345' },
393
+ }),
394
+ },
395
+ );
396
+
397
+ const { id, status } = await response.json();
398
+ ```
399
+
400
+ An administrator with the `form-access-writer` role finds the pending requests and approves one.
401
+
402
+ ```typescript
403
+ const response = await fetch(
404
+ `https://form-service.adsp.alberta.ca/form/v1/definitions/${definitionId}/access-requests?status=pending`,
405
+ {
406
+ headers: { Authorization: `Bearer ${accessToken}` },
407
+ },
408
+ );
409
+ const { results, page } = await response.json();
410
+
411
+ const [{ id: requestId }] = results;
412
+ const reviewResponse = await fetch(
413
+ `https://form-service.adsp.alberta.ca/form/v1/definitions/${definitionId}/access-requests/${requestId}`,
414
+ {
415
+ method: 'PATCH',
416
+ headers: {
417
+ Authorization: `Bearer ${accessToken}`,
418
+ 'Content-Type': 'application/json',
419
+ },
420
+ body: JSON.stringify({ status: 'approved' }),
421
+ },
422
+ );
423
+
424
+ const { status, reviewedAt, reviewedBy } = await reviewResponse.json();
357
425
  ```