@abgov/adsp-sdk-mcp-server 1.20.2 → 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.
Files changed (55) hide show
  1. package/README.md +5 -0
  2. package/assets/docs/platform/deployment.md +0 -1
  3. package/assets/docs/platform/getting-started.md +0 -1
  4. package/assets/docs/platform/operations.md +0 -1
  5. package/assets/docs/platform/platform-django-sdk.md +0 -1
  6. package/assets/docs/platform/platform-dotnet-sdk.md +0 -1
  7. package/assets/docs/platform/platform-flask-sdk.md +0 -1
  8. package/assets/docs/platform/platform-node-sdk.md +0 -1
  9. package/assets/docs/platform/platform-spring-sdk.md +0 -1
  10. package/assets/docs/services/access-service-backup-disaster-recovery.md +0 -1
  11. package/assets/docs/services/access-service.md +0 -1
  12. package/assets/docs/services/agent-service.md +0 -1
  13. package/assets/docs/services/cache-service.md +111 -24
  14. package/assets/docs/services/calendar-service.md +96 -18
  15. package/assets/docs/services/comment-service.md +179 -49
  16. package/assets/docs/services/configuration-service.md +0 -1
  17. package/assets/docs/services/directory-service.md +129 -16
  18. package/assets/docs/services/event-service.md +0 -1
  19. package/assets/docs/services/export-service.md +135 -0
  20. package/assets/docs/services/feedback-service.md +46 -10
  21. package/assets/docs/services/file-service.md +0 -1
  22. package/assets/docs/services/form-service.md +0 -1
  23. package/assets/docs/services/notification-service.md +0 -1
  24. package/assets/docs/services/pdf-service.md +113 -44
  25. package/assets/docs/services/pii-service.md +0 -1
  26. package/assets/docs/services/project-planner-service.md +215 -43
  27. package/assets/docs/services/push-service.md +159 -73
  28. package/assets/docs/services/status-service.md +0 -1
  29. package/assets/docs/services/task-service.md +262 -99
  30. package/assets/docs/services/tenant-service.md +113 -2
  31. package/assets/docs/services/token-handler.md +0 -1
  32. package/assets/docs/services/value-service.md +13 -1
  33. package/assets/docs/services/verify-service.md +60 -36
  34. package/assets/docs/tutorials/access-service/access-service.md +0 -1
  35. package/assets/docs/tutorials/feedback-service/feedback-service.md +0 -1
  36. package/assets/docs/tutorials/file-service/file-service.md +0 -1
  37. package/assets/docs/tutorials/form-service/form-service.md +0 -1
  38. package/assets/docs/tutorials/notification-service/notification-service.md +0 -1
  39. package/assets/docs/tutorials/pdf-service/building-a-template.md +2 -2
  40. package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +17 -10
  41. package/assets/docs/tutorials/pdf-service/pdf-service.md +0 -1
  42. package/assets/docs/tutorials/status-service/status-service.md +0 -1
  43. package/assets/docs/tutorials/task-service/introduction.md +1 -1
  44. package/assets/docs/tutorials/task-service/task-definitions.md +1 -1
  45. package/assets/docs/tutorials/task-service/task-queues.md +13 -11
  46. package/assets/docs/tutorials/task-service/task-service.md +0 -1
  47. package/package.json +1 -1
  48. package/src/http.d.ts +10 -0
  49. package/src/http.js +105 -0
  50. package/src/http.js.map +1 -0
  51. package/src/main.js +4 -82
  52. package/src/main.js.map +1 -1
  53. package/src/server.d.ts +6 -0
  54. package/src/server.js +17 -6
  55. package/src/server.js.map +1 -1
@@ -1,139 +1,302 @@
1
1
  ---
2
2
  layout: page
3
3
  title: Task service
4
- nav_order: 11
5
4
  parent: Services
6
5
  ---
7
6
 
8
7
  # Task service
9
- Task service provides a model for tasks, queues, and work assignment.
8
+
9
+ Task service provides a model for tasks, queues, and work assignment. Applications create tasks in a queue, and the
10
+ people who hold the queue's roles assign, start, and complete them. The [task app](../tutorials/task-service/task-app.md)
11
+ is a ready-made user interface for working on queued tasks.
10
12
 
11
13
  ## Client roles
14
+
12
15
  client `urn:ads:platform:task-service`
13
16
 
14
- | name | description |
15
- |:-|:-|
16
- | task-admin | Administrator role for task service. This role allows a user to read, updated, and assign tasks. |
17
- | task-writer | Writer role for task service. This role allows a user to update tasks. |
18
- | task-reader | Reader role for task service. This role allows a user to access tasks across queues. |
17
+ | name | description |
18
+ | :---------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | task-admin | Administrator role for tasks, definitions, and queues. Grants access to tasks in every queue, and allows a user to update, assign, prioritize, cancel, and delete tasks. Included in the tenant admin role. |
20
+ | task-writer | Writer role for creating and updating tasks. Allows a user or service account to create tasks in any queue, and to update and prioritize tasks they can access. |
21
+ | task-reader | Reader role for access tasks. Grants read access to tasks in every queue, and allows a user to cancel tasks. |
22
+
23
+ Access to the tasks of a queue is mostly controlled by roles in the queue's configuration rather than by these client
24
+ roles. Each queue has:
25
+
26
+ - `workerRoles`: roles that grant permission to view the queue's tasks, assign tasks to yourself, and start, update the
27
+ data of, complete, and cancel tasks that are unassigned or assigned to you.
28
+ - `assignerRoles`: roles that grant permission to view the queue's tasks, assign tasks to anyone (or unassign them), set
29
+ task priority, and cancel tasks.
30
+
31
+ Queue roles are tenant roles (for example `intake-assessor`) or client roles in the qualified form `<client ID>:<role>`
32
+ (for example `urn:ads:example:intake-app:assessor`). The task-admin role can do everything an assigner can, but working
33
+ on a task (start, update data, complete) always requires a worker role.
34
+
35
+ Two platform roles are also accepted for specific integrations: the directory service `resource-resolver` role can
36
+ retrieve a task by ID, and the export service `export-job` role can retrieve tasks.
37
+
38
+ ## Tenancy
19
39
 
20
- User access is primary controlled via configuration on each queue with `workerRoles` and `assignerRoles` representing: the roles that grant permission to assign and prioritize tasks; and roles that grant permission to self-assign, start, and complete tasks.
40
+ - **Which tenant is used?** Tenant users and service accounts always act on the tenant of their token, and any
41
+ `tenantId` query parameter is ignored. Core (platform) users and service accounts must set the `tenantId` query
42
+ parameter (for example `?tenantId=urn:ads:platform:tenant-service:v2:/tenants/{id}`).
43
+ - **Without a tenant context**, the `/tasks` endpoints and the endpoints for a specific queued task respond `400`. Other
44
+ queue endpoints don't respond with a clear error, so always set `tenantId` as a core user.
45
+ - **Queues** are tenant configuration. Each tenant configures its own queues, and there are no platform queues shared
46
+ with tenants.
47
+ - **Isolation**: tasks are stored per tenant. A task ID from another tenant responds `404`, as does a task ID used under
48
+ a queue path that isn't the task's queue.
49
+ - **Role scope**: the task service and queue roles must be held in the tenant of the task. Core users with one of the
50
+ roles that grant access to a queue (task-admin, task-reader, or a worker or assigner role) can read queue metrics,
51
+ queued tasks, and individual tasks, and cancel tasks; core users with task-admin or task-writer can create tasks. The
52
+ `GET /tasks` list accepts only the export service export-job role from core users. Only tenant users can update,
53
+ assign, work on, or delete tasks.
54
+ - **Assigners and workers lists** are read from the tenant's Keycloak realm with the caller's own token, so they only
55
+ work for tenant users who can view users of the realm.
56
+
57
+ ## API overview
58
+
59
+ All endpoints are under `https://task-service.adsp.alberta.ca/task/v1` and require a bearer token. See the
60
+ [API documentation](https://api.adsp.alberta.ca) for request and response schemas.
61
+
62
+ | Area | Endpoints | Required role |
63
+ | :----------- | :----------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
64
+ | Queues | `GET /queues`, `GET /queues/{namespace}/{name}` | Any authenticated user of the tenant |
65
+ | | `GET /queues/{namespace}/{name}/metrics`, `GET /queues/{namespace}/{name}/tasks` | task-admin, task-reader, or a worker or assigner role of the queue |
66
+ | | `GET /queues/{namespace}/{name}/assigners`, `GET /queues/{namespace}/{name}/workers` | None, but the user must be able to view users in Keycloak (realm-management view-users) |
67
+ | Create tasks | `POST /queues/{namespace}/{name}/tasks` | task-admin or task-writer |
68
+ | Tasks | `GET /tasks` | task-admin or task-reader (or the export service export-job role) |
69
+ | | `GET /tasks/{id}`, `GET /queues/{namespace}/{name}/tasks/{id}` | task-admin, task-reader, or a worker or assigner role of the queue |
70
+ | | `PATCH /tasks/{id}`, `PATCH /queues/{namespace}/{name}/tasks/{id}` | task-admin, or task-writer with access to the task |
71
+ | | `POST /tasks/{id}`, `POST /queues/{namespace}/{name}/tasks/{id}` (operations) | Depends on the operation; see [Task operations](#task-operations) |
72
+ | | `PATCH /tasks/{id}/data`, `PATCH /queues/{namespace}/{name}/tasks/{id}/data` | A worker role of the queue, on a task that is unassigned or assigned to the user |
73
+ | | `DELETE /tasks/{id}` | task-admin |
74
+
75
+ The queue paths for a specific task behave like the `/tasks/{id}` paths, but also check that the task is in that queue.
76
+ There are no endpoints for creating or deleting queues: queues are configured through the
77
+ [configuration service](configuration-service.md) (see [Configure a queue](#configure-a-queue)).
21
78
 
22
79
  ## Concepts
80
+
23
81
  ### Queue
24
- Queue represents a particular work unit with roles for works and assigners and a ordered stream of *tasks*. Tasks default to first in-first out order and tasks with a higher priority are promoted to the front. Queues are configured in the [configuration service](configuration-service.md) under the `platform:task-service` namespace and name.
82
+
83
+ Queue represents a particular work unit with roles for workers and assigners and an ordered stream of _tasks_. Tasks
84
+ are ordered with the highest priority first and, within each priority, oldest first. Queues are identified by a
85
+ `namespace` and `name` (each up to 50 characters), and configured in the
86
+ [configuration service](configuration-service.md) under the `platform:task-service` namespace and name, keyed by
87
+ `<namespace>:<name>`.
25
88
 
26
89
  ### Task
27
- Task represents a unit of work in a *queue*. Each task has basic name and description as well as a priority. Tasks have a basic lifecycle of: Pending -> In Progress -> Stopped (optional) -> Completed or Cancelled.
90
+
91
+ Task represents a unit of work in a _queue_. Each task has a name and description, a priority (`Normal`, `High`, or
92
+ `Urgent`), an optional `recordId` for cross-referencing an application record, and application-defined `context` and
93
+ `data`. Tasks have a basic lifecycle of: Pending -> In Progress -> Completed, or Cancelled from Pending or In Progress.
94
+ The `Stopped` status is part of the model and metrics, but no operation sets it.
28
95
 
29
96
  ### Assignment
30
- *Tasks* are assigned to people for completion. Each task can be assigned to one person at a time (sole responsibility). Workers can self-assign tasks and assigners can assign tasks to others.
97
+
98
+ _Tasks_ are assigned to people for completion. Each task can be assigned to one person at a time (sole
99
+ responsibility). Workers can self-assign tasks and assigners can assign tasks to others or unassign them. Completed and
100
+ cancelled tasks can't be assigned.
101
+
102
+ ### Task operations
103
+
104
+ Changes in a task's lifecycle are made by posting an operation to the task:
105
+
106
+ | Operation | Effect | Allowed for |
107
+ | :------------- | :----------------------------------------- | :------------------------------------------------------------------------------ |
108
+ | `assign` | Assigns (or with no `assignTo`, unassigns) | task-admin or an assigner role; a worker role to assign the task to themselves |
109
+ | `set-priority` | Sets `priority` to Normal, High, or Urgent | task-admin, task-writer, or an assigner role |
110
+ | `start` | Pending -> In Progress | A worker role, on a task that is unassigned or assigned to the user |
111
+ | `complete` | In Progress -> Completed | A worker role, on a task that is unassigned or assigned to the user |
112
+ | `cancel` | Pending or In Progress -> Cancelled | Any user who can access the task; an optional `reason` is included in the event |
113
+
114
+ In every case the user must first be able to access the task (task-admin, task-reader, or a worker or assigner role of
115
+ the queue). An operation that the task's status doesn't allow responds `400`.
116
+
117
+ ### Comments
118
+
119
+ When a task is created, the task service creates a [comment service](comment-service.md) topic for it, with the
120
+ `task-comments` topic type. Users with the task-reader role can comment, and task-admin can administer the topic.
121
+
122
+ ## Events
123
+
124
+ The task service sends the following domain events under the `task-service` namespace:
125
+
126
+ | Event | Description |
127
+ | :------------------ | :-------------------------------------------------------------- |
128
+ | `task-created` | A task was created. |
129
+ | `task-updated` | A task's name, description, context, priority, or data changed. |
130
+ | `task-data-updated` | A task's data was replaced through the data endpoint. |
131
+ | `task-priority-set` | A task's priority was set. |
132
+ | `task-assigned` | A task was assigned or unassigned. |
133
+ | `task-started` | A task was started. |
134
+ | `task-completed` | A task was completed. |
135
+ | `task-cancelled` | A task was cancelled. |
136
+ | `task-deleted` | A task was deleted. |
137
+
138
+ Events use the task's `recordId` (or its URN) as correlation ID, and include the queue in their context. The event
139
+ service records the time between `task-created` and `task-started` and between `task-started` and `task-completed`,
140
+ which the queue metrics endpoint reports. The `task-updates` stream of the [push service](push-service.md) delivers
141
+ all of these events to users with the task-reader or task-admin role.
142
+
143
+ The task service doesn't consume events.
31
144
 
32
145
  ## Code examples
146
+
33
147
  ### Configure a queue
34
- Queues are configured using the [configuration service](configuration-service.md). Note that new configuration may take up to 15 mins to apply.
148
+
149
+ Queues are configured using the [configuration service](configuration-service.md). The task service caches its
150
+ configuration and clears the cache when the configuration changes.
35
151
 
36
152
  ```typescript
37
- const configurationServiceUrl = 'https://configuration-service.adsp.alberta.ca';
38
-
39
- const namespace = 'my-service';
40
- const name = 'intake-submissions';
41
- const request = {
42
- operation: 'UPDATE',
43
- update: {
44
- queues: {
45
- [`${namespace}:${name}`]: {
46
- namespace,
47
- name,
48
- context: {},
49
- assignerRoles: ['intake-supervisors'],
50
- workerRoles: ['intake-assessors'],
51
- }
52
- }
53
- }
54
- }
55
-
56
- await fetch(
57
- `${configurationServiceUrl}/configuration/v2/configuration/platform/task-service`,
58
- {
59
- method: 'PATCH',
60
- headers: {
61
- 'Authorization': `Bearer ${accessToken}`,
62
- 'Content-Type': 'application/json'
153
+ const namespace = 'support';
154
+ const name = 'intake-processing';
155
+ const request = {
156
+ operation: 'UPDATE',
157
+ update: {
158
+ queues: {
159
+ [`${namespace}:${name}`]: {
160
+ namespace,
161
+ name,
162
+ displayName: 'Intake processing',
163
+ context: {},
164
+ assignerRoles: ['intake-supervisor'],
165
+ workerRoles: ['intake-assessor'],
63
166
  },
64
- body: JSON.stringify(request),
65
- }
66
- );
167
+ },
168
+ },
169
+ };
170
+
171
+ await fetch('https://configuration-service.adsp.alberta.ca/configuration/v2/configuration/platform/task-service', {
172
+ method: 'PATCH',
173
+ headers: {
174
+ Authorization: `Bearer ${accessToken}`,
175
+ 'Content-Type': 'application/json',
176
+ },
177
+ body: JSON.stringify(request),
178
+ });
67
179
  ```
68
180
 
69
181
  ### Create and queue a task
182
+
183
+ Requires the task-admin or task-writer role. The response is the created task, with status `Pending`.
184
+
70
185
  ```typescript
71
- const namespace = 'support';
72
- const name = 'intake-processing';
73
- const task = {
74
- name: 'process-application-123',
75
- description: 'Process Application 123',
76
- priority: 'Normal',
77
- recordId: 'f669be59-bd38-4ca4-8749-19248060fc63',
78
- }
79
-
80
- await fetch(
81
- `https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/tasks`,
82
- {
83
- method: 'POST',
84
- headers: {
85
- 'Authorization': `Bearer ${accessToken}`,
86
- 'Content-Type': 'application/json',
87
- },
88
- body: JSON.stringify(task),
89
- }
90
- );
186
+ const namespace = 'support';
187
+ const name = 'intake-processing';
188
+ const task = {
189
+ name: 'process-application-123',
190
+ description: 'Process application 123',
191
+ priority: 'Normal',
192
+ recordId: 'f669be59-bd38-4ca4-8749-19248060fc63',
193
+ context: { application: 'intake' },
194
+ };
195
+
196
+ const response = await fetch(`https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/tasks`, {
197
+ method: 'POST',
198
+ headers: {
199
+ Authorization: `Bearer ${accessToken}`,
200
+ 'Content-Type': 'application/json',
201
+ },
202
+ body: JSON.stringify(task),
203
+ });
204
+ const { id, urn, status } = await response.json();
91
205
  ```
92
206
 
93
207
  ### Get queued tasks
94
- Tasks are returned in order with highest priority tasks first and, within each priority, oldest tasks first.
208
+
209
+ Returns the tasks of the queue that are not completed or cancelled, with the highest priority tasks first and, within
210
+ each priority, oldest tasks first. Use `page.next` as the `after` parameter to get the next page.
211
+
95
212
  ```typescript
96
- const namespace = 'support';
97
- const name = 'intake-processing';
98
- const top = 20;
99
-
100
- await fetch(
101
- `https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/tasks?top=${top}`,
102
- {
103
- method: 'GET',
104
- headers: {
105
- Authorization: `Bearer ${accessToken}`,
106
- },
107
- }
108
- );
213
+ const namespace = 'support';
214
+ const name = 'intake-processing';
215
+ const top = 20;
216
+
217
+ const response = await fetch(
218
+ `https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/tasks?top=${top}`,
219
+ {
220
+ method: 'GET',
221
+ headers: {
222
+ Authorization: `Bearer ${accessToken}`,
223
+ },
224
+ },
225
+ );
226
+ const { results, page } = await response.json();
227
+ // results[0].id, results[0].priority, results[0].assignment; page.next
109
228
  ```
110
229
 
111
230
  ### Assign a task
112
- Tasks can be assigned by users with one of the assigner roles for the queue or self-assigned by users with one of the worker roles.
231
+
232
+ Tasks can be assigned by users with one of the assigner roles for the queue or self-assigned by users with one of the
233
+ worker roles. Use the workers endpoint to list the users who can be assigned.
113
234
 
114
235
  ```typescript
115
- const taskServiceUrl = 'https://task-service.adsp.alberta.ca';
116
- const taskId = 'b7aba911-7bd9-485e-b0e9-416506f025d9';
117
- const namespace = 'support';
118
- const name = 'intake-processing';
119
- const request = {
120
- operation: 'assign',
121
- assignTo: {
122
- id: 'ed2243ed-948a-4f84-a785-c9cf2d5f355e',
123
- email: 'a.n.other@gov.ab.ca',
124
- name: 'A. N. Other',
236
+ const taskId = 'b7aba911-7bd9-485e-b0e9-416506f025d9';
237
+ const namespace = 'support';
238
+ const name = 'intake-processing';
239
+ const request = {
240
+ operation: 'assign',
241
+ assignTo: {
242
+ id: 'ed2243ed-948a-4f84-a785-c9cf2d5f355e',
243
+ email: 'test.user@gov.ab.ca',
244
+ name: 'Test User',
245
+ },
246
+ };
247
+
248
+ const response = await fetch(
249
+ `https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/tasks/${taskId}`,
250
+ {
251
+ method: 'POST',
252
+ headers: {
253
+ Authorization: `Bearer ${accessToken}`,
254
+ 'Content-Type': 'application/json',
125
255
  },
126
- }
127
-
128
- await fetch(
129
- `${taskServiceUrl}/task/v1/queues/${namespace}/${name}/tasks/${taskId}`,
130
- {
131
- method: 'POST',
132
- headers: {
133
- 'Authorization': `Bearer ${accessToken}`,
134
- 'Content-Type': 'application/json',
135
- },
136
- body: JSON.stringify(request),
137
- }
138
- );
256
+ body: JSON.stringify(request),
257
+ },
258
+ );
259
+ const { assignment } = await response.json();
260
+ // assignment.assignedTo.id, assignment.assignedOn
261
+ ```
262
+
263
+ ### Start and complete a task
264
+
265
+ A worker starts a task, optionally records data while it is in progress, and then completes it.
266
+
267
+ ```typescript
268
+ const taskUrl = `https://task-service.adsp.alberta.ca/task/v1/tasks/${taskId}`;
269
+ const headers = {
270
+ Authorization: `Bearer ${accessToken}`,
271
+ 'Content-Type': 'application/json',
272
+ };
273
+
274
+ await fetch(taskUrl, { method: 'POST', headers, body: JSON.stringify({ operation: 'start' }) });
275
+
276
+ await fetch(`${taskUrl}/data`, {
277
+ method: 'PATCH',
278
+ headers,
279
+ body: JSON.stringify({ decision: 'approved', notes: 'All documents received.' }),
280
+ });
281
+
282
+ const response = await fetch(taskUrl, { method: 'POST', headers, body: JSON.stringify({ operation: 'complete' }) });
283
+ const { status, endedOn } = await response.json();
284
+ // status === 'Completed'
285
+ ```
286
+
287
+ ### Get queue metrics
288
+
289
+ Returns task counts by status, priority, and assigned user. With `includeEventMetrics=true`, it also returns the weekly
290
+ queue and completion durations (in seconds) and the number of tasks created, completed, and cancelled in the last 7
291
+ days.
292
+
293
+ ```typescript
294
+ const response = await fetch(
295
+ `https://task-service.adsp.alberta.ca/task/v1/queues/${namespace}/${name}/metrics?notEnded=true&includeEventMetrics=true`,
296
+ {
297
+ headers: { Authorization: `Bearer ${accessToken}` },
298
+ },
299
+ );
300
+ const { status, priority, assignedTo, queue, completion, rate } = await response.json();
301
+ // status.Pending, priority.Urgent, queue.avg, rate.created
139
302
  ```
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  layout: page
3
3
  title: Tenant service
4
- nav_order: 1
5
4
  parent: Services
6
5
  ---
7
6
 
@@ -15,7 +14,79 @@ client `urn:ads:platform:tenant-service`
15
14
 
16
15
  | name | description |
17
16
  |:-|:-|
18
- | tenant-admin | Administrator role for tenant service. This role grants a user access to tenant administration. It is also a composite role that includes roles for configuration of other platform services. |
17
+ | tenant-admin | Administrator role for tenant service. This role grants a user access to tenant administration. It is also a composite role that includes roles for configuration of other platform services. |
18
+ | platform-service | Service role for backend services that read tenants. |
19
+
20
+ Tenant service also checks two core realm roles. They are realm roles of the `core` realm, not client roles, and are not registered by tenant service:
21
+
22
+ | name | description |
23
+ |:-|:-|
24
+ | tenant-service-admin | Platform administrator role. Allows creating tenants for any administrator or with an existing realm, renaming tenants, and deleting tenants. |
25
+ | beta-tester | Allows a core user to create a tenant with a new realm, with themselves as the administrator. |
26
+
27
+ No API operation checks the `platform-service` role: any authenticated core user or service account can read tenants. Services usually read tenants through the `tenantService` of the [Node.js SDK](../platform/platform-node-sdk.md) instead of calling the API.
28
+
29
+ ## Tenancy
30
+ Tenant service manages the tenants themselves, so it doesn't use the `tenantId` query parameter of other services. Which tenants a request can see depends on who makes it:
31
+
32
+ - **Tenant users and service accounts** (with a token from a tenant realm) only find and retrieve their own tenant. `GET /api/tenant/v2/tenants` returns only their tenant, and `GET /api/tenant/v2/tenants/{id}` responds `403` for any other tenant ID.
33
+ - **Core users and service accounts** (with a token from the `core` realm) can find and retrieve any tenant. Creating, renaming, and deleting tenants require a core user with the roles above; tenant users are rejected even if they hold a role with the same name.
34
+ - **Anonymous requests** can search `GET /api/tenant/v2/tenants` by `name` or `realm`. Results don't include the administrator email. This is how applications resolve a tenant name to its realm before a user signs in.
35
+ - **Deprecated v1 lookups** (`GET /api/tenant/v1/{id}`, `GET /api/tenant/v1/realm/{realm}`, `POST /api/tenant/v1/email`, `POST /api/tenant/v1/name`) are available to any authenticated user and aren't limited to the user's own tenant. Use the v2 endpoints instead.
36
+
37
+ Search results only include `active` tenants. A tenant that is still `provisioning` can be retrieved by ID, but isn't found by search.
38
+
39
+ ## API overview
40
+ All endpoints are under `https://tenant-service.adsp.alberta.ca`. See the [API documentation](https://api.adsp.alberta.ca) for request and response schemas. Role checks in this API respond `401`, not `403`, when the user lacks the role.
41
+
42
+ | Endpoint | Purpose | Required role |
43
+ |:-|:-|:-|
44
+ | `GET /api/tenant/v2/tenants` | Search for tenants by name, realm, or administrator email. | None; anonymous with `name` or `realm` |
45
+ | `POST /api/tenant/v2/tenants` | Create a tenant. | core `beta-tester` or `tenant-service-admin` |
46
+ | `GET /api/tenant/v2/tenants/{id}` | Retrieve a tenant. | Any authenticated user; tenant users only their own tenant |
47
+ | `PATCH /api/tenant/v2/tenants/{id}/name` | Rename a tenant. Rate limited. | core `tenant-service-admin` |
48
+ | `DELETE /api/tenant/v2/tenants/{id}` | Delete a tenant and its realm. | core `tenant-service-admin` |
49
+
50
+ The following `/api/tenant/v1` endpoints are deprecated. They are documented in the API documentation so that existing callers can find their replacements:
51
+
52
+ | Deprecated endpoint | Required role | Replacement |
53
+ |:-|:-|:-|
54
+ | `POST /api/tenant/v1` | core `beta-tester` or `tenant-service-admin` | `POST /api/tenant/v2/tenants` |
55
+ | `GET /api/tenant/v1/{id}` | Any authenticated user | `GET /api/tenant/v2/tenants/{id}` |
56
+ | `DELETE /api/tenant/v1?realm={realm}` | core `tenant-service-admin` | `DELETE /api/tenant/v2/tenants/{id}` |
57
+ | `GET /api/tenant/v1/realm/{realm}` | Any authenticated user | `GET /api/tenant/v2/tenants?realm={realm}` |
58
+ | `POST /api/tenant/v1/email` | Any authenticated user | `GET /api/tenant/v2/tenants?adminEmail={email}` |
59
+ | `POST /api/tenant/v1/name` | Any authenticated user | `GET /api/tenant/v2/tenants?name={name}` |
60
+ | `GET /api/tenant/v1/realm/roles` | `tenant-admin` | None |
61
+
62
+ These `/api/tenant/v1` endpoints are not deprecated. They are internal endpoints used by the tenant admin app, and are rate limited:
63
+
64
+ | Endpoint | Purpose | Required role |
65
+ |:-|:-|:-|
66
+ | `GET /api/tenant/v1/user/id` | Look up the ID of a user by email in a realm. | `tenant-admin` |
67
+ | `GET /api/tenant/v1/user/default-idp` | Check if a core realm user is linked to the default identity provider. | `tenant-admin` |
68
+ | `DELETE /api/tenant/v1/user/idp` | Remove the link between a user and an identity provider. | `tenant-admin` |
69
+
70
+ ## Concepts
71
+ ### Tenant
72
+ A tenant represents a team or program area using ADSP. Its ID is a URN, for example `urn:ads:platform:tenant-service:v2:/tenants/61f2e3a8c9b1d2e3f4a5b6c7`; endpoints that take `{id}` use only the last segment. Other platform services store this ID on their records to isolate tenant data. Each tenant has a unique name (compared ignoring case), an administrator email, and a status:
73
+
74
+ - `provisioning`: the tenant was created and its realm is still being set up. `POST /api/tenant/v2/tenants` responds `202` with this status. If provisioning fails, the tenant is removed.
75
+ - `active`: the tenant and its realm are ready.
76
+
77
+ A user can be the administrator of only one tenant, unless a `tenant-service-admin` creates the tenant.
78
+
79
+ ### Realm
80
+ Each tenant has its own Keycloak realm, which signs the access tokens of the tenant's users and service accounts. Platform services read the token issuer to work out which tenant a request is for. A new realm is created when a tenant is created, with the administrator given the `tenant-admin` role and clients for the platform apps and services. A `tenant-service-admin` can instead associate a tenant with an existing realm. Deleting a tenant also deletes its realm.
81
+
82
+ ## Events
83
+ Tenant service sends the following domain events under the `tenant-service` namespace. It doesn't consume events.
84
+
85
+ | Event | Description |
86
+ |:-|:-|
87
+ | `tenant-created` | A tenant was created, either with an existing realm or once its new realm was provisioned. The payload includes the `tenant` and `createdBy`. |
88
+ | `tenant-deleted` | A tenant was deleted. The payload includes the `tenant` and `deletedBy`. |
89
+
19
90
 
20
91
  ## Audit actions
21
92
  Tenant service records audit events in the `tenant-service` namespace of the [audit service](audit-service.md). Records are written to the affected tenant, with the tenant as the resource (`{ type: 'tenant', id: <tenant URN> }`) and the tenant name and realm in the metadata.
@@ -29,3 +100,43 @@ Tenant service records audit events in the `tenant-service` namespace of the [au
29
100
  Because the audit service resolves the tenant of each event, `tenant.deleted` is recorded before the realm and tenant are removed. If the removal does not fully succeed, a further `tenant.deleted` event is recorded with `failure` or `error` status; it cannot be stored if the tenant record itself was already removed.
30
101
 
31
102
  Audit failures are logged by the SDK and do not roll back the tenant operation. The tenant service account requires the `audit-writer` role of `urn:ads:platform:audit-service`. Set `AUDIT_ENABLED=false` on tenant service to turn recording off; see [turn audit recording off](audit-service.md#turn-audit-recording-off).
103
+
104
+ ## Code examples
105
+ ### Look up a tenant by name
106
+ Anonymous requests can look up a tenant by name, for example to find the realm for signing in. Include a bearer token to also get the administrator email.
107
+
108
+ ```typescript
109
+ const tenantServiceUrl = 'https://tenant-service.adsp.alberta.ca';
110
+
111
+ const response = await fetch(`${tenantServiceUrl}/api/tenant/v2/tenants?name=${encodeURIComponent('My Tenant')}`);
112
+ const { results } = await response.json();
113
+ const [tenant] = results;
114
+ // tenant.id, tenant.realm, tenant.name, tenant.status
115
+ ```
116
+
117
+ ### Retrieve a tenant by ID
118
+ Tenant users can retrieve their own tenant. Core users can retrieve any tenant.
119
+
120
+ ```typescript
121
+ const id = tenant.id.split('/').pop();
122
+
123
+ const response = await fetch(`${tenantServiceUrl}/api/tenant/v2/tenants/${id}`, {
124
+ headers: { Authorization: `Bearer ${accessToken}` },
125
+ });
126
+ const { name, realm, adminEmail } = await response.json();
127
+ ```
128
+
129
+ ### Create a tenant
130
+ Core users with the `beta-tester` role create a tenant with a new realm and become its administrator. The response is `202` with `status: 'provisioning'`; search by name until the tenant is found, which means it is `active`.
131
+
132
+ ```typescript
133
+ const response = await fetch(`${tenantServiceUrl}/api/tenant/v2/tenants`, {
134
+ method: 'POST',
135
+ headers: {
136
+ Authorization: `Bearer ${accessToken}`,
137
+ 'Content-Type': 'application/json',
138
+ },
139
+ body: JSON.stringify({ name: 'My Tenant' }),
140
+ });
141
+ const { id, realm, status } = await response.json();
142
+ ```
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  layout: page
3
3
  title: Token handler
4
- nav_order: 17
5
4
  parent: Services
6
5
  ---
7
6
 
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  layout: page
3
3
  title: Value service
4
- nav_order: 6
5
4
  parent: Services
6
5
  ---
7
6
 
@@ -93,6 +92,19 @@ The job is off by default. Set `SERVICE_METRIC_ROLLUP_JOB_ENABLED=true` to run i
93
92
 
94
93
  A rollup can also be run on demand with `POST /value/v1/service-metric-rollups/run` and the `value-writer` role. The body can set `start` and `end` dates, which default to the trailing days. Core users can set `tenantId` or leave it out to roll up all tenants; tenant users always roll up their own tenant. The current partial day and future days are rejected.
95
94
 
95
+ ## Audit
96
+
97
+ Value service records audit events for administrative changes through the [audit service](audit-service.md), under the `value-service` namespace. Each record includes the actor and the affected resource. Actions do not set a retention class; the audit service derives it from the category (`compliance` for administrative and data-access actions, `standard` for runtime actions), as shown in the table.
98
+
99
+ | Action | Category | Severity | Retention | Recorded when |
100
+ |---|---|---|---|---|
101
+ | `value-definition.created` | administrative | info | compliance | A value definition is created. |
102
+ | `value-definition.updated` | administrative | info | compliance | A definition is updated; metadata lists the changed fields. |
103
+ | `value-definition.deleted` | administrative | warning | compliance | A value definition is deleted. |
104
+ | `value-definition.service-metric-rollup.triggered` | runtime | info | standard | A rollup is triggered manually via the API. A rollup across all tenants records one event per tenant rolled up. |
105
+
106
+ Value writes, the scheduled rollup job and read operations are not audited. Set `VALUE_AUDIT_ENABLED=false` to disable audit recording for the service; when unset, the SDK `AUDIT_ENABLED` setting applies (enabled by default).
107
+
96
108
  ## Code examples
97
109
 
98
110
  ### Write a value