@abgov/adsp-sdk-mcp-server 1.20.1 → 1.21.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.
- package/README.md +5 -0
- package/assets/docs/platform/deployment.md +0 -1
- package/assets/docs/platform/getting-started.md +0 -1
- package/assets/docs/platform/operations.md +0 -1
- package/assets/docs/platform/platform-django-sdk.md +0 -1
- package/assets/docs/platform/platform-dotnet-sdk.md +0 -1
- package/assets/docs/platform/platform-flask-sdk.md +0 -1
- package/assets/docs/platform/platform-node-sdk.md +0 -1
- package/assets/docs/platform/platform-spring-sdk.md +0 -1
- package/assets/docs/services/access-service-backup-disaster-recovery.md +0 -1
- package/assets/docs/services/access-service.md +0 -1
- package/assets/docs/services/agent-service.md +28 -1
- package/assets/docs/services/audit-service.md +8 -2
- package/assets/docs/services/cache-service.md +111 -24
- package/assets/docs/services/calendar-service.md +96 -18
- package/assets/docs/services/comment-service.md +179 -49
- package/assets/docs/services/configuration-service.md +5 -1
- package/assets/docs/services/directory-service.md +134 -16
- package/assets/docs/services/event-service.md +0 -1
- package/assets/docs/services/export-service.md +135 -0
- package/assets/docs/services/feedback-service.md +46 -10
- package/assets/docs/services/file-service.md +0 -1
- package/assets/docs/services/form-service.md +30 -1
- package/assets/docs/services/notification-service.md +251 -2
- package/assets/docs/services/pdf-service.md +113 -44
- package/assets/docs/services/pii-service.md +0 -1
- package/assets/docs/services/project-planner-service.md +215 -43
- package/assets/docs/services/push-service.md +159 -73
- package/assets/docs/services/status-service.md +1 -2
- package/assets/docs/services/task-service.md +262 -99
- package/assets/docs/services/tenant-service.md +113 -2
- package/assets/docs/services/token-handler.md +0 -1
- package/assets/docs/services/value-service.md +13 -1
- package/assets/docs/services/verify-service.md +60 -36
- package/assets/docs/tutorials/access-service/access-service.md +0 -1
- package/assets/docs/tutorials/feedback-service/feedback-service.md +0 -1
- package/assets/docs/tutorials/file-service/file-service.md +0 -1
- package/assets/docs/tutorials/form-service/form-service.md +0 -1
- package/assets/docs/tutorials/notification-service/notification-service.md +0 -1
- package/assets/docs/tutorials/pdf-service/building-a-template.md +2 -2
- package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +17 -10
- package/assets/docs/tutorials/pdf-service/pdf-service.md +0 -1
- package/assets/docs/tutorials/status-service/notifications.md +1 -1
- package/assets/docs/tutorials/status-service/status-service.md +0 -1
- package/assets/docs/tutorials/task-service/introduction.md +1 -1
- package/assets/docs/tutorials/task-service/task-definitions.md +1 -1
- package/assets/docs/tutorials/task-service/task-queues.md +13 -11
- package/assets/docs/tutorials/task-service/task-service.md +0 -1
- package/package.json +1 -1
- package/src/http.d.ts +10 -0
- package/src/http.js +105 -0
- package/src/http.js.map +1 -0
- package/src/main.js +4 -82
- package/src/main.js.map +1 -1
- package/src/sdk-reference/reference.js +21 -2
- package/src/sdk-reference/reference.js.map +1 -1
- package/src/server.d.ts +6 -0
- package/src/server.js +17 -6
- package/src/server.js.map +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: Feedback service
|
|
4
|
-
nav_order: 18
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
@@ -13,12 +12,34 @@ Feedback service allows users to submit feedback regarding their service interac
|
|
|
13
12
|
|
|
14
13
|
client `urn:ads:platform:feedback-service`
|
|
15
14
|
|
|
16
|
-
| name | description
|
|
17
|
-
| :---------------- |
|
|
18
|
-
| feedback-provider | Provider role that allows a user to send feedback.
|
|
15
|
+
| name | description |
|
|
16
|
+
| :---------------- | :------------------------------------------------------- |
|
|
17
|
+
| feedback-provider | Provider role that allows a user to send feedback. |
|
|
18
|
+
| feedback-reader | Allows a user to access feedback submitted by end-users. |
|
|
19
19
|
|
|
20
20
|
_Sites_ can be configured to allow anonymous feedback and in that case the send feedback request is not expected to include any credential. For _sites_ that don't allow anonymous feedback, the request must be in the context of a user with the `urn:ads:platform:feedback-service:feedback-provider` client role. In order to allow feedback from all authenticated users of an application, the associated client can include a hardcode role mapper to add the role to access tokens.
|
|
21
21
|
|
|
22
|
+
## Tenancy
|
|
23
|
+
|
|
24
|
+
- **Sending feedback.** Authenticated users send feedback to the tenant of their token, and need the `feedback-provider` role in that tenant. Anonymous requests name the tenant in the `tenant` field of the body (tenant name or tenant URN); without it the request is rejected with 400. Anonymous feedback is only accepted for sites configured with `allowAnonymous`, and is rate limited to 5 requests per 5 minutes per client.
|
|
25
|
+
- **Reading feedback.** Tenant users with the `feedback-reader` role read the feedback of their own tenant. Core users with the role set the `tenantId` query parameter to read a tenant's feedback; without it, `GET /feedback/v1/feedback` reads the feedback of all tenants. Core users must set `tenantId` for the feedback summary.
|
|
26
|
+
- **Sites.** Sites are tenant configuration. `GET /feedback/v1/sites` lists or counts sites across tenants, and is intended for core users.
|
|
27
|
+
|
|
28
|
+
## API overview
|
|
29
|
+
|
|
30
|
+
All endpoints are under `https://feedback-service.adsp.alberta.ca/feedback/v1`. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
|
|
31
|
+
|
|
32
|
+
| Endpoint | Purpose | Required role |
|
|
33
|
+
| :---------------------------------------- | :------------------------------------------------- | :-------------------------------------------------------- |
|
|
34
|
+
| `POST /feedback/v1/feedback` | Send feedback for a site. | `feedback-provider`, or anonymous for sites that allow it |
|
|
35
|
+
| `GET /feedback/v1/feedback` | Read submitted feedback, newest first. | `feedback-reader` |
|
|
36
|
+
| `GET /feedback/v1/feedback/summary` | Summarize the feedback for a site and time period. | `feedback-reader` |
|
|
37
|
+
| `GET /feedback/v1/sites` | List or count configured sites. | `feedback-reader` (core) |
|
|
38
|
+
| `GET /feedback/v1/script/adspFeedback.js` | Download the feedback widget script. | Anonymous |
|
|
39
|
+
| `GET /feedback/v1/script/integrity` | Get the script digest for Subresource Integrity. | Anonymous |
|
|
40
|
+
|
|
41
|
+
Sites are configured through the [configuration service](configuration-service.md); feedback service has no endpoints of its own for them.
|
|
42
|
+
|
|
22
43
|
## Concepts
|
|
23
44
|
|
|
24
45
|
### Site
|
|
@@ -29,6 +50,10 @@ A site represents a website against which feedback can be provided. A site can b
|
|
|
29
50
|
|
|
30
51
|
The feedback service processes text content of submitted feedback using the [PII service](pii-service.md) to remove personally identifiable information.
|
|
31
52
|
|
|
53
|
+
## Events
|
|
54
|
+
|
|
55
|
+
Feedback service does not send or consume domain events. Received feedback is queued, processed, and then written as `feedback` values to the [value service](value-service.md) under the `feedback-service` namespace.
|
|
56
|
+
|
|
32
57
|
## Code examples
|
|
33
58
|
|
|
34
59
|
### Configure a site
|
|
@@ -138,20 +163,31 @@ await fetch(`https://feedback-service.adsp.alberta.ca/feedback/v1/feedback`, {
|
|
|
138
163
|
|
|
139
164
|
### Retrieving feedback
|
|
140
165
|
|
|
141
|
-
|
|
166
|
+
Users with the `feedback-reader` role can read feedback, after anonymization, from the feedback API. Use `page.next` from the response as `after` to read the next page.
|
|
142
167
|
|
|
143
168
|
```typescript
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const timestampMin = `2024-10-10T12:00:00Z`;
|
|
169
|
+
const feedbackServiceUrl = 'https://feedback-service.adsp.alberta.ca';
|
|
170
|
+
const site = encodeURIComponent('https://my-application.alberta.ca');
|
|
147
171
|
|
|
148
172
|
const response = await fetch(
|
|
149
|
-
`${
|
|
173
|
+
`${feedbackServiceUrl}/feedback/v1/feedback?site=${site}&top=50&start=2024-10-10T12:00:00Z`,
|
|
150
174
|
{
|
|
151
175
|
method: 'GET',
|
|
152
176
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
153
177
|
},
|
|
154
178
|
);
|
|
155
179
|
|
|
156
|
-
const {
|
|
180
|
+
const { feedback, page } = await response.json();
|
|
181
|
+
// feedback[0].value.rating, feedback[0].value.comment, page.next
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Summarize feedback for a site
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const response = await fetch(`${feedbackServiceUrl}/feedback/v1/feedback/summary?site=${site}`, {
|
|
188
|
+
method: 'GET',
|
|
189
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const { totalResponses, averageRating, responsesWithComments, responsesWithIssues } = await response.json();
|
|
157
193
|
```
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: Form service
|
|
4
|
-
nav_order: 14
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
@@ -68,6 +67,36 @@ Registers are returned as `{ namespace: 'data-register', name, description, entr
|
|
|
68
67
|
|
|
69
68
|
Form service does not emit its own events for data registers. Configuration service emits `configuration-updated` and `configuration-deleted` for the underlying configuration.
|
|
70
69
|
|
|
70
|
+
## Audit actions
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
| action | category | severity | retention class | recorded when |
|
|
74
|
+
|:-|:-|:-|:-|:-|
|
|
75
|
+
| form.created | administrative | info | compliance | A draft form is created, with `hasApplicant` in the metadata. |
|
|
76
|
+
| 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. |
|
|
77
|
+
| 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. |
|
|
78
|
+
| form.locked | administrative | warning | compliance | The draft expiry job locks an inactive draft, with `reason: 'inactivity'` and `lastAccessed` in the metadata. |
|
|
79
|
+
| form.unlocked | administrative | warning | compliance | An administrator unlocks a locked form, with the previous `locked` time in the metadata. |
|
|
80
|
+
| form.set-to-draft | administrative | warning | compliance | A submitted form is set back to draft. |
|
|
81
|
+
| form.archived | administrative | info | compliance | A form is archived. |
|
|
82
|
+
| 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). |
|
|
83
|
+
| 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. |
|
|
84
|
+
| form.accessed-with-code | security | info | security | Form data is read using a verified access code. |
|
|
85
|
+
| 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. |
|
|
86
|
+
| data-register.created | administrative | info | standard | A data register is created, with its `entryCount`. |
|
|
87
|
+
| data-register.updated | administrative | info | standard | A data register is updated, with the `updatedFields` and the `entryCount`. |
|
|
88
|
+
| data-register.deleted | administrative | warning | standard | A data register is deleted. |
|
|
89
|
+
|
|
90
|
+
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.
|
|
91
|
+
|
|
92
|
+
Operations that an intake application performs for an anonymous applicant are recorded with the actor `{ id: 'anonymous-applicant', type: 'user', name: 'Anonymous applicant' }` and the intake application's service account ID as `callerId` in the metadata. The draft expiry job is recorded with the system actor `form-service-job`. Other operations are recorded with the signed-in user or service account.
|
|
93
|
+
|
|
94
|
+
Reading forms, submissions or form data (other than by access code) is not audited. Submission disposition and notes are not audited. Denied and failed operations are not recorded. Changes to form definitions are not recorded by form service, since form definitions are managed in the [configuration service](configuration-service.md); audit records of those changes are in the `configuration-service` namespace.
|
|
95
|
+
|
|
96
|
+
Draft data is saved frequently, so form service sends audit events in batches of up to 100 events. On shutdown, it waits for in-flight requests to complete and then delivers the buffered events before exiting. Audit failures are logged by the SDK and do not fail the form operation. The form service account requires the `audit-writer` role of `urn:ads:platform:audit-service`.
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
71
100
|
## Code examples
|
|
72
101
|
### Create a draft form for an anonymous applicant
|
|
73
102
|
```typescript
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: Notification service
|
|
4
|
-
nav_order: 9
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
@@ -17,6 +16,36 @@ client `urn:ads:platform:notification-service`
|
|
|
17
16
|
|:-|:-|
|
|
18
17
|
| subscription-admin | Administrator role for notification service subscriptions. This role grants read and write of subscriptions. For example, a user with this role can remove subscriptions and delete subscribers. |
|
|
19
18
|
| subscription-app | Subscription application role for the notification service. This role is used to grant service accounts permission to manage subscribers and subscriptions. |
|
|
19
|
+
| code-sender | Role for service accounts that send and check verification codes for any subscriber of the tenant. It does not allow verifying the channel. |
|
|
20
|
+
|
|
21
|
+
The `configuration-admin` role of the [configuration service](configuration-service.md) can also manage notification types and the tenant contact.
|
|
22
|
+
|
|
23
|
+
## Tenancy
|
|
24
|
+
Every notification service resource belongs to one tenant. Notification types, subscribers, subscriptions, and the contact information are all stored and read per tenant.
|
|
25
|
+
|
|
26
|
+
- **Tenant users and service accounts** always act on the tenant of their token. Any `tenantId` query parameter is ignored.
|
|
27
|
+
- **Core (platform) users and service accounts** have no tenant of their own, so they must set the `tenantId` query parameter (for example, `?tenantId=urn:ads:platform:tenant-service:v2:/tenants/{id}`). Endpoints that change configuration (`/types` writes and `/contact`) respond `400` when there is no tenant context. Other endpoints may fail without a clear error, so always include it. Only operations on a specific subscriber (`/subscribers/{subscriber}` and its sub-paths) can find the subscriber without it.
|
|
28
|
+
- **Notification types** combine *platform* types (configured by ADSP for all tenants) with the tenant's own types. A tenant type with the same ID as a platform type is a *customization*: only its event templates replace the platform templates. Use `GET /types?source=tenant` or `GET /types?source=core` to see the definitions separately.
|
|
29
|
+
- **Subscribers and subscriptions** are never shared across tenants. The same person subscribing in two tenants has two subscribers. A subscriber ID from one tenant responds `404` in another.
|
|
30
|
+
- **Events** trigger notifications only for the tenant that sent the event. A platform type that includes an event generates notifications for subscribers of the tenant the event was sent for.
|
|
31
|
+
|
|
32
|
+
## API overview
|
|
33
|
+
All endpoints are under `https://notification-service.adsp.alberta.ca/subscription/v1` and require a bearer token. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
|
|
34
|
+
|
|
35
|
+
| Area | Endpoints | Required role |
|
|
36
|
+
|:-|:-|:-|
|
|
37
|
+
| Notification types and templates | `GET /types`, `GET /types/{type}` | Any authenticated user |
|
|
38
|
+
| | `GET /types?source=tenant\|core`, `POST /types`, `PATCH /types/{type}`, `DELETE /types/{type}` | subscription-admin or configuration-admin |
|
|
39
|
+
| Contact | `GET /contact`, `PATCH /contact` | subscription-admin or configuration-admin |
|
|
40
|
+
| Subscriptions | `GET /types/{type}/subscriptions` | subscription-admin or subscription-app |
|
|
41
|
+
| | `POST /types/{type}/subscriptions`, `POST\|DELETE /types/{type}/subscriptions/{subscriber}`, `DELETE /types/{type}/subscriptions/{subscriber}/criteria` | subscription-admin, subscription-app, or the subscriber's own user when the type allows it |
|
|
42
|
+
| | `GET /types/{type}/subscriptions/{subscriber}` | subscription-admin |
|
|
43
|
+
| Subscribers (recipients) | `GET /subscribers` | subscription-admin |
|
|
44
|
+
| | `POST /subscribers`, `GET\|PATCH\|DELETE /subscribers/{subscriber}`, `GET /subscribers/{subscriber}/subscriptions`, `GET /subscribers/{subscriber}/types/{type}/channels` | subscription-admin, subscription-app, or the subscriber's own user |
|
|
45
|
+
| | `POST /subscribers/{subscriber}` (verification operations) | As above, or code-sender for `send-code`, `send-code-with-link`, and `check-code` |
|
|
46
|
+
| | `GET /subscribers/my-subscriber` | Any authenticated user |
|
|
47
|
+
|
|
48
|
+
There are no separate template or event endpoints. Templates are part of each notification type's `events`, and events are sent through the [event service](event-service.md).
|
|
20
49
|
|
|
21
50
|
## Concepts
|
|
22
51
|
### Notification type
|
|
@@ -31,8 +60,118 @@ A subscriber represents a receiver of notifications. Subscriber is not a represe
|
|
|
31
60
|
### Subscription
|
|
32
61
|
*Subscribers* have subscriptions to *notification types*. Each subscription relates a subscriber to a notification type and optionally includes criteria. The subscription criteria filters events that result in notifications to the associated subscriber. For example, in the case of 'Application Progress', the applicant is only subscribed to notifications regarding their specific application and this is handled as a subscription criteria.
|
|
33
62
|
|
|
63
|
+
### Template
|
|
64
|
+
Each event of a notification type has a template per channel (`email`, `sms`, `bot`, `mail`), with a `subject` and `body`. Templates use [Handlebars](https://handlebarsjs.com/) syntax, and email bodies are wrapped in the standard email layout. The following values are available in templates:
|
|
65
|
+
|
|
66
|
+
| Value | Description |
|
|
67
|
+
|:-|:-|
|
|
68
|
+
| `event` | The triggering domain event, including `namespace`, `name`, `timestamp`, `correlationId`, `context`, and `payload`. |
|
|
69
|
+
| `subscriber` | The subscriber's `id`, `userId`, and `addressAs`. |
|
|
70
|
+
| `tenant` | The tenant the event was sent for, including `name`. |
|
|
71
|
+
| `managementUrl` | Link to the subscriber app, where the subscriber can manage their subscriptions. |
|
|
72
|
+
|
|
73
|
+
## Events
|
|
74
|
+
Notifications are triggered by domain events from other services. A notification type lists the events (`namespace` and `name`) that it sends notifications for. Events in the `notification-service` namespace never trigger notifications, to avoid loops.
|
|
75
|
+
|
|
76
|
+
The notification service sends the following domain events under the `notification-service` namespace:
|
|
77
|
+
|
|
78
|
+
| Event | Description |
|
|
79
|
+
|:-|:-|
|
|
80
|
+
| `notifications-generated` | Notifications were generated for an event. |
|
|
81
|
+
| `notification-generation-failed` | Generation of notifications for an event failed. |
|
|
82
|
+
| `notification-sent` | A notification was sent. |
|
|
83
|
+
| `notification-send-failed` | Sending a notification failed. |
|
|
84
|
+
| `notification-config-retried` | Generation retried reading configuration because the tenant's from email was not yet set. |
|
|
85
|
+
| `subscriber-created` | A subscriber was created. |
|
|
86
|
+
| `subscriber-updated` | A subscriber was updated, including verification of a channel. |
|
|
87
|
+
| `subscriber-deleted` | A subscriber was deleted. |
|
|
88
|
+
| `subscription-set` | A subscription was created or its criteria changed. |
|
|
89
|
+
| `subscription-deleted` | A subscription was deleted. |
|
|
90
|
+
|
|
34
91
|
## Code examples
|
|
35
|
-
###
|
|
92
|
+
### Create a notification type
|
|
93
|
+
Users with the subscription-admin or configuration-admin role can create notification types for their tenant. The definition is validated, including its channels, events, and templates. The service responds `409` if a type with the ID already exists.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const response = await fetch(
|
|
97
|
+
'https://notification-service.adsp.alberta.ca/subscription/v1/types',
|
|
98
|
+
{
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: {
|
|
101
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify({
|
|
105
|
+
id: 'application-status',
|
|
106
|
+
name: 'Application status',
|
|
107
|
+
description: 'Notifications about changes to an application.',
|
|
108
|
+
manageSubscribe: true,
|
|
109
|
+
publicSubscribe: false,
|
|
110
|
+
subscriberRoles: ['applicant'],
|
|
111
|
+
channels: ['email'],
|
|
112
|
+
events: [
|
|
113
|
+
{
|
|
114
|
+
namespace: 'application-service',
|
|
115
|
+
name: 'application-status-changed',
|
|
116
|
+
templates: {
|
|
117
|
+
email: {
|
|
118
|
+
subject: 'Your application status changed',
|
|
119
|
+
body: '<p>Hi {{ subscriber.addressAs }}, your application is now {{ event.payload.status }}.</p>',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
}),
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const { id, events } = await response.json();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Customize a platform notification type template
|
|
132
|
+
Updating a platform type saves a tenant customization of it. Only the event templates in the customization apply. Deleting the customization with `DELETE /types/{type}` reverts to the platform templates.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
await fetch(
|
|
136
|
+
'https://notification-service.adsp.alberta.ca/subscription/v1/types/application-health-updates',
|
|
137
|
+
{
|
|
138
|
+
method: 'PATCH',
|
|
139
|
+
headers: {
|
|
140
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
141
|
+
'Content-Type': 'application/json',
|
|
142
|
+
},
|
|
143
|
+
body: JSON.stringify({
|
|
144
|
+
events: [
|
|
145
|
+
{
|
|
146
|
+
namespace: 'status-service',
|
|
147
|
+
name: 'health-check-started',
|
|
148
|
+
templates: {
|
|
149
|
+
email: {
|
|
150
|
+
subject: '{{ event.payload.application.name }} is being monitored',
|
|
151
|
+
body: '<p>Health checks started for {{ event.payload.application.name }}.</p>',
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
}),
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Act on a tenant as a platform service account
|
|
162
|
+
Core service accounts set the `tenantId` query parameter on every request.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const tenantId = 'urn:ads:platform:tenant-service:v2:/tenants/61f2e3a8c9b1d2e3f4a5b6c7';
|
|
166
|
+
const response = await fetch(
|
|
167
|
+
`https://notification-service.adsp.alberta.ca/subscription/v1/types?tenantId=${encodeURIComponent(tenantId)}`,
|
|
168
|
+
{ headers: { 'Authorization': `Bearer ${coreAccessToken}` } }
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const types = await response.json();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Configure a notification type in the configuration service
|
|
36
175
|
Notification types are configured using the [configuration service](configuration-service.md).
|
|
37
176
|
|
|
38
177
|
```typescript
|
|
@@ -106,6 +245,116 @@ For this type of subscription request, the user must have a subscriber role.
|
|
|
106
245
|
} = await response.json();
|
|
107
246
|
```
|
|
108
247
|
|
|
248
|
+
### Subscribe a subscriber from an application
|
|
249
|
+
Service accounts with the subscription-app role can subscribe anyone. A subscriber is created if no subscriber exists for the `userId` (or `id`) in the request.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const response = await fetch(
|
|
253
|
+
`https://notification-service.adsp.alberta.ca/subscription/v1/types/${typeId}/subscriptions`,
|
|
254
|
+
{
|
|
255
|
+
method: 'POST',
|
|
256
|
+
headers: {
|
|
257
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
258
|
+
'Content-Type': 'application/json',
|
|
259
|
+
},
|
|
260
|
+
body: JSON.stringify({
|
|
261
|
+
userId,
|
|
262
|
+
addressAs: 'A.N.Other',
|
|
263
|
+
channels: [{ channel: 'email', address: 'a.n.other@acme.org' }],
|
|
264
|
+
criteria: { correlationId: 'application-1234' },
|
|
265
|
+
}),
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
const { subscriberId, criteria } = await response.json();
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Find subscriptions to a notification type
|
|
273
|
+
Service accounts can check whether anyone is subscribed before sending an event. Results are paged; pass `page.next` as `after` to get the next page.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const subscriptionMatch = encodeURIComponent(JSON.stringify({ correlationId: 'application-1234' }));
|
|
277
|
+
const response = await fetch(
|
|
278
|
+
`https://notification-service.adsp.alberta.ca/subscription/v1/types/${typeId}/subscriptions?top=50&subscriptionMatch=${subscriptionMatch}`,
|
|
279
|
+
{ headers: { 'Authorization': `Bearer ${accessToken}` } }
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const { results, page } = await response.json();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Remove one subscription criteria
|
|
286
|
+
Removes the criteria that match. The subscription is deleted when its last criteria is removed.
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
const criteria = encodeURIComponent(JSON.stringify({ correlationId: 'application-1234' }));
|
|
290
|
+
const response = await fetch(
|
|
291
|
+
`https://notification-service.adsp.alberta.ca/subscription/v1/types/${typeId}/subscriptions/${subscriberId}/criteria?criteria=${criteria}`,
|
|
292
|
+
{
|
|
293
|
+
method: 'DELETE',
|
|
294
|
+
headers: { 'Authorization': `Bearer ${accessToken}` },
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const { deleted } = await response.json();
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Get the current user's subscriber
|
|
302
|
+
```typescript
|
|
303
|
+
const response = await fetch(
|
|
304
|
+
'https://notification-service.adsp.alberta.ca/subscription/v1/subscribers/my-subscriber?includeSubscriptions=true',
|
|
305
|
+
{ headers: { 'Authorization': `Bearer ${accessToken}` } }
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const { id, channels, subscriptions } = await response.json();
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Search subscribers
|
|
312
|
+
Users with the subscription-admin role can search subscribers of their tenant by name, email, or SMS number.
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
const response = await fetch(
|
|
316
|
+
'https://notification-service.adsp.alberta.ca/subscription/v1/subscribers?search=other&sortBy=created&sortDirection=desc',
|
|
317
|
+
{ headers: { 'Authorization': `Bearer ${accessToken}` } }
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const { results, page: { total, next } } = await response.json();
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Verify a subscriber channel
|
|
324
|
+
Send a code to the channel address, then verify the channel with the code the subscriber received.
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
const subscriberUrl = `https://notification-service.adsp.alberta.ca/subscription/v1/subscribers/${subscriberId}`;
|
|
328
|
+
const headers = {
|
|
329
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
330
|
+
'Content-Type': 'application/json',
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
await fetch(subscriberUrl, {
|
|
334
|
+
method: 'POST',
|
|
335
|
+
headers,
|
|
336
|
+
body: JSON.stringify({
|
|
337
|
+
operation: 'send-code',
|
|
338
|
+
channel: 'email',
|
|
339
|
+
address: 'a.n.other@acme.org',
|
|
340
|
+
reason: 'Verify your email address.',
|
|
341
|
+
}),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const response = await fetch(subscriberUrl, {
|
|
345
|
+
method: 'POST',
|
|
346
|
+
headers,
|
|
347
|
+
body: JSON.stringify({
|
|
348
|
+
operation: 'verify-channel',
|
|
349
|
+
channel: 'email',
|
|
350
|
+
address: 'a.n.other@acme.org',
|
|
351
|
+
code,
|
|
352
|
+
}),
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const { verified } = await response.json();
|
|
356
|
+
```
|
|
357
|
+
|
|
109
358
|
### Update subscriber (notification preferences)
|
|
110
359
|
Users can update their subscriber preferences including the channels of notification. The order of channels represents the preferred channels for notifications.
|
|
111
360
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: page
|
|
3
3
|
title: PDF service
|
|
4
|
-
nav_order: 15
|
|
5
4
|
parent: Services
|
|
6
5
|
---
|
|
7
6
|
|
|
@@ -13,25 +12,98 @@ PDF service provides utility PDF operations like generation of PDFs from templat
|
|
|
13
12
|
|
|
14
13
|
client `urn:ads:platform:pdf-service`
|
|
15
14
|
|
|
16
|
-
| name | description
|
|
17
|
-
| :------------ |
|
|
18
|
-
| pdf-
|
|
15
|
+
| name | description |
|
|
16
|
+
| :------------ | :------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| pdf-admin | Administrator role for the PDF service. This role grants the ability to create, update, and delete PDF templates. |
|
|
18
|
+
| pdf-generator | Generator role for the PDF service. This role grants the ability to generate PDF files from templates and read jobs. |
|
|
19
|
+
|
|
20
|
+
Both roles are included in the tenant admin role. Reading templates does not need a role: any authenticated user of the tenant can list and get them.
|
|
21
|
+
|
|
22
|
+
## Tenancy
|
|
23
|
+
|
|
24
|
+
Templates and jobs belong to a tenant.
|
|
25
|
+
|
|
26
|
+
- **Tenant users and service accounts** always act on the tenant of their token. Any `tenantId` query parameter is ignored.
|
|
27
|
+
- **Core (platform) users and service accounts** act on the tenant given by the `tenantId` query parameter (for example, `?tenantId=urn:ads:platform:tenant-service:v2:/tenants/{id}`). They must set it when creating, updating, or deleting templates, and when generating PDFs. Without it, listing and getting templates returns only platform templates.
|
|
28
|
+
- **Platform versus tenant templates.** The templates available to a tenant combine the tenant's own templates with _platform_ templates configured by ADSP for all tenants. A platform template replaces a tenant template with the same ID, and creating a template with the ID of a platform template responds `409`.
|
|
29
|
+
- **Isolation.** A template ID that exists only in another tenant responds `404`. A job of another tenant responds `403`.
|
|
30
|
+
- **Role scope.** pdf-admin and pdf-generator can be held in the tenant, or by a core user, for template management and generation. Reading a job (`GET /jobs/{jobId}`) requires pdf-generator in the job's tenant; core users can't read jobs, and should use the job events instead.
|
|
31
|
+
|
|
32
|
+
## API overview
|
|
33
|
+
|
|
34
|
+
All endpoints are under `https://pdf-service.adsp.alberta.ca/pdf/v1` and require a bearer token. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
|
|
35
|
+
|
|
36
|
+
| Area | Endpoints | Required role |
|
|
37
|
+
| :-------- | :----------------------------------------------------------------------------------- | :-------------------------------- |
|
|
38
|
+
| Templates | `GET /templates`, `GET /templates/{templateId}` | Any authenticated user |
|
|
39
|
+
| | `POST /templates`, `PATCH /templates/{templateId}`, `DELETE /templates/{templateId}` | pdf-admin |
|
|
40
|
+
| Jobs | `POST /jobs` | pdf-generator |
|
|
41
|
+
| | `GET /jobs/{jobId}` | pdf-generator in the job's tenant |
|
|
42
|
+
|
|
43
|
+
Templates can also be managed directly in the [configuration service](configuration-service.md) under `platform:pdf-service`, or in the tenant admin app. Generated PDFs are downloaded through the [file service](file-service.md); the PDF service has no download endpoint.
|
|
19
44
|
|
|
20
45
|
## Concepts
|
|
21
46
|
|
|
22
47
|
### PDF template
|
|
23
48
|
|
|
24
|
-
_Templates_ represent a standard PDF document with template variables for its contents.
|
|
49
|
+
_Templates_ represent a standard PDF document with template variables for its contents. A template has a body (`template`), and optional `header`, `footer`, and `additionalStyles` (CSS shared by the body, header, and footer). Content is HTML with [Handlebars](/adsp-monorepo/tutorials/pdf-service/handlebars.html) expressions, evaluated with a context of `{ data }`, so variables look like {% raw %}`{{ data.myProperty }}`{% endraw %}. Templates are stored in the configuration service. The template ID is derived from its name when it is created through the API.
|
|
25
50
|
|
|
26
51
|
### Job
|
|
27
52
|
|
|
28
|
-
PDF service
|
|
53
|
+
PDF service generates PDFs asynchronously using a job queue. _Jobs_ represent the state of a generation request:
|
|
54
|
+
|
|
55
|
+
1. `POST /jobs` checks the template, the role, and the optional file type, then creates a job with status `queued`, puts it on the work queue, and sends `pdf-generation-queued`. It responds with the job straight away.
|
|
56
|
+
2. A worker renders the template with the request's `data` using [Puppeteer](/adsp-monorepo/tutorials/pdf-service/puppeteer.html), and uploads the PDF to the [file service](file-service.md). The file name's extension is replaced with `.pdf`, and the file's record ID is the request's `recordId`, or the job ID.
|
|
57
|
+
3. When the upload succeeds, the job status changes to `completed` with a `result` that holds the file `id`, `urn`, and `filename`, and `pdf-generated` is sent.
|
|
58
|
+
4. If generation fails, the work item may be retried. When it fails without a retry, the job status changes to `failed` and `pdf-generation-failed` is sent with the error.
|
|
59
|
+
|
|
60
|
+
Job state is kept for about 24 hours after its last update; after that `GET /jobs/{jobId}` responds `404`. The generated file is kept by the file service according to its file type.
|
|
61
|
+
|
|
62
|
+
### File type
|
|
63
|
+
|
|
64
|
+
Generated PDFs are uploaded as the `generated-pdf` file type by default. It is readable by pdf-generator, and its files are deleted after 30 days. To keep PDFs longer or control who can read them, create your own file type in the file service and set `fileType` in the request. The PDF service uploads with a platform service account, so the file type needs `urn:ads:platform:tenant-service:platform-service` in its update roles. The service also registers `pdf-template-assets`, an anonymously readable file type for images used in templates.
|
|
65
|
+
|
|
66
|
+
## Events
|
|
67
|
+
|
|
68
|
+
The PDF service sends the following domain events under the `pdf-service` namespace. Each event's `correlationId` is the job ID, and its `context` is the request's `context` plus `jobId` and `templateId`.
|
|
69
|
+
|
|
70
|
+
| Event | Description |
|
|
71
|
+
| :---------------------- | :---------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `pdf-generation-queued` | A generation job was queued. Payload has `jobId`, `templateId`, and `requestedBy`. |
|
|
73
|
+
| `pdf-generated` | A PDF was generated and uploaded. Payload also has `file` with the `id`, `urn`, and `filename`. |
|
|
74
|
+
| `pdf-generation-failed` | A generation job failed. Payload has `jobId`, `templateId`, `requestedBy`, and `error`. |
|
|
75
|
+
|
|
76
|
+
These events are available on the [push service](push-service.md) stream `pdf-generation-updates`, for subscribers with the pdf-generator role. The PDF service doesn't consume events from other services.
|
|
29
77
|
|
|
30
78
|
## Code examples
|
|
31
79
|
|
|
32
80
|
### Configure a template
|
|
33
81
|
|
|
34
|
-
|
|
82
|
+
Users with the pdf-admin role can create a template. The ID is derived from the name, so this creates `submission-summary`.
|
|
83
|
+
|
|
84
|
+
{% raw %}
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const response = await fetch('https://pdf-service.adsp.alberta.ca/pdf/v1/templates', {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: {
|
|
90
|
+
Authorization: `Bearer ${accessToken}`,
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
name: 'Submission summary',
|
|
95
|
+
description: 'Provides a summary of the submission',
|
|
96
|
+
// HTML with handlebars template string
|
|
97
|
+
template: '<p>Submitted by {{ data.applicant.name }}</p>',
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const { id } = await response.json();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
{% endraw %}
|
|
105
|
+
|
|
106
|
+
Templates can also be configured using the [configuration service](configuration-service.md).
|
|
35
107
|
|
|
36
108
|
```typescript
|
|
37
109
|
const configurationServiceUrl = 'https://configuration-service.adsp.alberta.ca';
|
|
@@ -60,57 +132,54 @@ await fetch(`${configurationServiceUrl}/configuration/v2/configuration/platform/
|
|
|
60
132
|
|
|
61
133
|
### Create a PDF generation job
|
|
62
134
|
|
|
63
|
-
Generated PDFs are uploaded to the [file service](file-service.md) and the _file type_ used can be specified in the request. This allows you to generate a PDF file that can be directly downloaded by authorized users.
|
|
135
|
+
Generated PDFs are uploaded to the [file service](file-service.md) and the _file type_ used can be specified in the request. This allows you to generate a PDF file that can be directly downloaded by authorized users. The service responds `400` if the file type doesn't exist.
|
|
136
|
+
|
|
137
|
+
{% raw %}
|
|
64
138
|
|
|
65
139
|
```typescript
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const {
|
|
88
|
-
urn,
|
|
89
|
-
id,
|
|
90
|
-
status,
|
|
91
|
-
} = await response.json();
|
|
140
|
+
const request = {
|
|
141
|
+
operation: 'generate',
|
|
142
|
+
templateId: 'submission-summary',
|
|
143
|
+
filename: 'my-submission-summary.pdf',
|
|
144
|
+
fileType: 'submission-documents',
|
|
145
|
+
// Template is hydrated with a context of { data }; variables in the template should look like {{ data.myProperty }}.
|
|
146
|
+
data: { applicant: { name: 'Test User' } },
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const response = await fetch('https://pdf-service.adsp.alberta.ca/pdf/v1/jobs', {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: {
|
|
152
|
+
Authorization: `Bearer ${accessToken}`,
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify(request),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const { urn, id: jobId, status } = await response.json();
|
|
92
159
|
```
|
|
93
160
|
|
|
161
|
+
{% endraw %}
|
|
162
|
+
|
|
94
163
|
### Retrieving the generated PDF
|
|
95
164
|
|
|
96
|
-
|
|
165
|
+
Poll the job until its status is `completed` (or `failed`), then download the file from the file service.
|
|
97
166
|
|
|
98
167
|
```typescript
|
|
99
168
|
const response = await fetch(`https://pdf-service.adsp.alberta.ca/pdf/v1/jobs/${jobId}`, {
|
|
100
169
|
method: 'GET',
|
|
101
170
|
headers: {
|
|
102
171
|
Authorization: `Bearer ${accessToken}`,
|
|
103
|
-
'Content-Type': 'application/json',
|
|
104
172
|
},
|
|
105
173
|
});
|
|
106
174
|
|
|
107
|
-
const {
|
|
108
|
-
status,
|
|
109
|
-
result: { urn, id: fileId },
|
|
110
|
-
} = await response.json();
|
|
175
|
+
const { status, result } = await response.json();
|
|
111
176
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
177
|
+
if (status === 'completed') {
|
|
178
|
+
await fetch(`https://file-service.adsp.alberta.ca/file/v1/files/${result.id}/download`, {
|
|
179
|
+
method: 'GET',
|
|
180
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
181
|
+
});
|
|
182
|
+
}
|
|
116
183
|
```
|
|
184
|
+
|
|
185
|
+
Instead of polling, you can listen for `pdf-service:pdf-generated` on the `pdf-generation-updates` stream of the [push service](push-service.md), and read the file ID from `event.payload.file.id`.
|