@abgov/adsp-sdk-mcp-server 0.0.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 +51 -0
- package/assets/docs/architecture.md +79 -0
- package/assets/docs/getting-started.md +118 -0
- package/assets/docs/important-notes.md +47 -0
- package/assets/docs/index.md +9 -0
- package/assets/docs/platform/deployment.md +80 -0
- package/assets/docs/platform/getting-started.md +66 -0
- package/assets/docs/platform/operations.md +8 -0
- package/assets/docs/platform/platform-django-sdk.md +330 -0
- package/assets/docs/platform/platform-dotnet-sdk.md +457 -0
- package/assets/docs/platform/platform-flask-sdk.md +355 -0
- package/assets/docs/platform/platform-node-sdk.md +433 -0
- package/assets/docs/platform/platform-spring-sdk.md +344 -0
- package/assets/docs/platform/platform.md +8 -0
- package/assets/docs/services/access-service.md +75 -0
- package/assets/docs/services/agent-service.md +316 -0
- package/assets/docs/services/cache-service.md +61 -0
- package/assets/docs/services/calendar-service.md +86 -0
- package/assets/docs/services/comment-service.md +87 -0
- package/assets/docs/services/configuration-service.md +92 -0
- package/assets/docs/services/directory-service.md +57 -0
- package/assets/docs/services/event-service.md +122 -0
- package/assets/docs/services/feedback-service.md +152 -0
- package/assets/docs/services/file-service.md +164 -0
- package/assets/docs/services/form-service.md +149 -0
- package/assets/docs/services/notification-service.md +151 -0
- package/assets/docs/services/pdf-service.md +116 -0
- package/assets/docs/services/pii-service.md +45 -0
- package/assets/docs/services/push-service.md +106 -0
- package/assets/docs/services/services.md +6 -0
- package/assets/docs/services/status-service.md +29 -0
- package/assets/docs/services/task-service.md +139 -0
- package/assets/docs/services/tenant-service.md +18 -0
- package/assets/docs/services/token-handler.md +135 -0
- package/assets/docs/services/value-service.md +80 -0
- package/assets/docs/services/verify-service.md +61 -0
- package/assets/docs/tutorials/access-service/access-service.md +9 -0
- package/assets/docs/tutorials/access-service/adsp-clients.md +29 -0
- package/assets/docs/tutorials/access-service/application-clients.md +61 -0
- package/assets/docs/tutorials/access-service/front-end-access.md +53 -0
- package/assets/docs/tutorials/access-service/introduction.md +33 -0
- package/assets/docs/tutorials/access-service/tenants.md +68 -0
- package/assets/docs/tutorials/access-service/themes.md +43 -0
- package/assets/docs/tutorials/feedback-service/accessing-data.md +41 -0
- package/assets/docs/tutorials/feedback-service/feedback-service.md +9 -0
- package/assets/docs/tutorials/feedback-service/installation.md +142 -0
- package/assets/docs/tutorials/feedback-service/introduction.md +28 -0
- package/assets/docs/tutorials/feedback-service/security.md +40 -0
- package/assets/docs/tutorials/feedback-service/triggering.md +21 -0
- package/assets/docs/tutorials/file-service/file-service.md +9 -0
- package/assets/docs/tutorials/file-service/file-types.md +35 -0
- package/assets/docs/tutorials/file-service/introduction.md +34 -0
- package/assets/docs/tutorials/file-service/security.md +31 -0
- package/assets/docs/tutorials/file-service/working-with.md +65 -0
- package/assets/docs/tutorials/form-service/Integration.md +31 -0
- package/assets/docs/tutorials/form-service/ai-agent.md +450 -0
- package/assets/docs/tutorials/form-service/building-forms.md +264 -0
- package/assets/docs/tutorials/form-service/cheat-sheet.md +1461 -0
- package/assets/docs/tutorials/form-service/custom-error-messages.md +87 -0
- package/assets/docs/tutorials/form-service/data-registers.md +204 -0
- package/assets/docs/tutorials/form-service/file-uploader.md +81 -0
- package/assets/docs/tutorials/form-service/form-app.md +72 -0
- package/assets/docs/tutorials/form-service/form-editor.md +62 -0
- package/assets/docs/tutorials/form-service/form-service.md +9 -0
- package/assets/docs/tutorials/form-service/form-submissions.md +77 -0
- package/assets/docs/tutorials/form-service/instructions.md +173 -0
- package/assets/docs/tutorials/form-service/introduction.md +66 -0
- package/assets/docs/tutorials/form-service/repeated-items.md +87 -0
- package/assets/docs/tutorials/form-service/security.md +36 -0
- package/assets/docs/tutorials/form-service/steppers.md +237 -0
- package/assets/docs/tutorials/notification-service/emailAttachment.md +75 -0
- package/assets/docs/tutorials/notification-service/events.md +20 -0
- package/assets/docs/tutorials/notification-service/introduction.md +37 -0
- package/assets/docs/tutorials/notification-service/notification-service.md +9 -0
- package/assets/docs/tutorials/notification-service/notification-types.md +86 -0
- package/assets/docs/tutorials/notification-service/subscribers.md +33 -0
- package/assets/docs/tutorials/pdf-service/building-a-template.md +339 -0
- package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +150 -0
- package/assets/docs/tutorials/pdf-service/handlebars.md +51 -0
- package/assets/docs/tutorials/pdf-service/introduction.md +26 -0
- package/assets/docs/tutorials/pdf-service/pdf-service.md +9 -0
- package/assets/docs/tutorials/pdf-service/puppeteer.md +25 -0
- package/assets/docs/tutorials/pdf-service/video.md +18 -0
- package/assets/docs/tutorials/status-service/Introduction.md +46 -0
- package/assets/docs/tutorials/status-service/health.md +51 -0
- package/assets/docs/tutorials/status-service/notices.md +34 -0
- package/assets/docs/tutorials/status-service/notifications.md +107 -0
- package/assets/docs/tutorials/status-service/status-service.md +9 -0
- package/assets/docs/tutorials/status-service/status.md +35 -0
- package/assets/docs/tutorials/status-service/webhooks.md +24 -0
- package/assets/docs/tutorials/task-service/introduction.md +23 -0
- package/assets/docs/tutorials/task-service/task-app.md +43 -0
- package/assets/docs/tutorials/task-service/task-definitions.md +49 -0
- package/assets/docs/tutorials/task-service/task-queues.md +67 -0
- package/assets/docs/tutorials/task-service/task-service.md +9 -0
- package/assets/docs/tutorials/tutorials.md +8 -0
- package/package.json +18 -0
- package/src/docs/docsRepository.d.ts +22 -0
- package/src/docs/docsRepository.js +110 -0
- package/src/docs/docsRepository.js.map +1 -0
- package/src/main.d.ts +2 -0
- package/src/main.js +16 -0
- package/src/main.js.map +1 -0
- package/src/sdk-reference/reference.d.ts +17 -0
- package/src/sdk-reference/reference.js +547 -0
- package/src/sdk-reference/reference.js.map +1 -0
- package/src/sdk-reference/search.d.ts +6 -0
- package/src/sdk-reference/search.js +41 -0
- package/src/sdk-reference/search.js.map +1 -0
- package/src/server.d.ts +6 -0
- package/src/server.js +30 -0
- package/src/server.js.map +1 -0
- package/src/tools/registerDocsTools.d.ts +3 -0
- package/src/tools/registerDocsTools.js +66 -0
- package/src/tools/registerDocsTools.js.map +1 -0
- package/src/tools/registerQuickstartTool.d.ts +2 -0
- package/src/tools/registerQuickstartTool.js +82 -0
- package/src/tools/registerQuickstartTool.js.map +1 -0
- package/src/tools/registerSdkTools.d.ts +2 -0
- package/src/tools/registerSdkTools.js +43 -0
- package/src/tools/registerSdkTools.js.map +1 -0
- package/src/tools/types.d.ts +12 -0
- package/src/tools/types.js +3 -0
- package/src/tools/types.js.map +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Events
|
|
3
|
+
layout: page
|
|
4
|
+
nav_order: 4
|
|
5
|
+
parent: Notification Service
|
|
6
|
+
grand_parent: Tutorials
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Events
|
|
10
|
+
|
|
11
|
+
You can configure notifications for your particular needs by first defining one or more [domain events](/adsp-monorepo/tutorials/notification-service/events.html) for your application using the [Tenant admin Webapp](https://adsp-uat.alberta.ca/admin/services/event). A _domain event_ consists of a name, id, description, and a Json Schema describing the data that gets posted (event payload) along with it. For notifications, the data you want to post contains values for the _email template placeholders_ defined in the [notification type](/adsp-monorepo/tutorials/notification-service/notification-types.html).
|
|
12
|
+
|
|
13
|
+
## Triggering Events
|
|
14
|
+
|
|
15
|
+
The events you define when configuring your notifications are triggered in your application logic via ADSP's [Event Service APIs](https://api.adsp-uat.alberta.ca/autotest/?urls.primaryName=Event%20service). When ADSP receives one, it will
|
|
16
|
+
|
|
17
|
+
- match the _domain event_ with a _notification type_,
|
|
18
|
+
- determine who needs to be notified, based on subscribers and notification criteria,
|
|
19
|
+
- combine the information in the event payload with the message template's placeholders, and
|
|
20
|
+
- send a notification through the appropriate channel.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Introduction
|
|
3
|
+
layout: page
|
|
4
|
+
nav_order: 1
|
|
5
|
+
parent: Notification Service
|
|
6
|
+
grand_parent: Tutorials
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Introduction
|
|
10
|
+
|
|
11
|
+
The _Notification Service_ enables applications to quickly implement features for notifying users about significant events, or milestones, that occur when processing their applications or other submissions. It includes:
|
|
12
|
+
|
|
13
|
+
- capabilities for defining _domain events_, which an application uses to trigger the notifications,
|
|
14
|
+
- capabilities for designing message templates, which are used to send customized notifications to subscribers,
|
|
15
|
+
- API's for subscribing users to receive notifications,
|
|
16
|
+
- API's for triggering notifications via the _domain events_, and
|
|
17
|
+
- application defined criteria for determining exactly which subscribers get notified.
|
|
18
|
+
|
|
19
|
+
For example, you may want a user to be notified when their application for money has been accepted or rejected. To do this you might
|
|
20
|
+
|
|
21
|
+
- define two domain events; application-approved, and application-rejected,
|
|
22
|
+
- define a text message template: "Your application has been {{ application-status }}", where _application-status_ is a placeholder that is filled in when the notification is sent,
|
|
23
|
+
- add some logic and API calls to your application to subscribe a user to the notifications when their application is submitted,
|
|
24
|
+
- add some logic and API calls to trigger _application-accepted_ when the application has been approved.
|
|
25
|
+
|
|
26
|
+
The process looks something like this:
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
Defining events and message templates is an easy, one step, process done through the [Tenant Admin Webapp](https://adsp-uat.alberta.ca/admin/services/notification). Adding API calls for subscribing users and sending events to your code requires a bit more work, but there are only a few of them, each with minimal complexity.
|
|
31
|
+
|
|
32
|
+
## Learn More
|
|
33
|
+
|
|
34
|
+
- Learn how to [configure notifications](/adsp-monorepo/tutorials/notification-service/notification-types.html)
|
|
35
|
+
- Learn how to [manage subscribers](/adsp-monorepo/tutorials/notification-service/subscribers.html)
|
|
36
|
+
- Learn how to [configure and trigger domain events](/adsp-monorepo/tutorials/notification-service/events.html)
|
|
37
|
+
- Learn how to [add an email attachment to your notification](/adsp-monorepo/tutorials/notification-service/emailAttachment.html)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Notification Types
|
|
3
|
+
layout: page
|
|
4
|
+
nav_order: 2
|
|
5
|
+
parent: Notification Service
|
|
6
|
+
grand_parent: Tutorials
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Notification Types
|
|
10
|
+
|
|
11
|
+
_Notification types_ are objects that encapsulate all the information ADSP needs to notify subscribers when one or more [domain events](/adsp-monorepo/tutorials/notification-service/events.html) are triggered by an application. The objects contain such information as:
|
|
12
|
+
|
|
13
|
+
- a name and description, for reference,
|
|
14
|
+
- how the user should be notified (email, sms, bot),
|
|
15
|
+
- the events that will trigger the notification,
|
|
16
|
+
- the roles needed for someone to be subscribed,
|
|
17
|
+
- the message sent to users when a notification is triggered, and
|
|
18
|
+
- the criteria to use when determining which subscribers to notify.
|
|
19
|
+
|
|
20
|
+
They are at the heart of the _Notification Service_. End-users are _subscribed_ to _Notification Types_, which contain a set of _domain events_ that when triggered, result in notifications being sent to users. The relationships between the various entities looks like this:
|
|
21
|
+
|
|
22
|
+
{: width="300" }
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
Lets take a look at an example. Before you can create a _notification type_ you first have to decide on a set of _domain events_ and create those through the Event Service, as [described here](/adsp-monorepo/tutorials/notification-service/events.html). Then select the notification service from left hand menu and click on the _Add notification type_ button. You will see the following modal:
|
|
27
|
+
|
|
28
|
+
{: width="400" }
|
|
29
|
+
|
|
30
|
+
The name and description fields are for your information, to be able to distinguish between several notification types. The Id is automatically generated based on the name, and is very important for use when subscribing users to the type. You will need to use it in the API calls. In our case the Notification Type will be called "Application Status", as it will be used to inform grant applicants of status changes in their applications.
|
|
31
|
+
|
|
32
|
+
### Notification Channels
|
|
33
|
+
|
|
34
|
+
The _Notification Channels_ tell the system how to send the notifications. Your choices are through email, as a text message, or through a bot. The latter can be used to send messages via Slack, or Teams. You can use any combination of the channels. In this case we allow users to choose email and/or text messages.
|
|
35
|
+
|
|
36
|
+
The next checkbox tells the system how you want to manage your subscribers. They can be self managed, in which they would use ADSP's Subscriber App, or they can be managed by an application through the use of the [Notification Service APIs](https://api.adsp-uat.alberta.ca/autotest/?urls.primaryName=Notification%20service). In this example we want the application to manage the subscriptions, so the box is left unchecked.
|
|
37
|
+
|
|
38
|
+
The final checkbox allows anyone - i.e. the public - to subscribe for notifications. Again, in this example, the box is left unchecked. Only registered grant-applicants will need notifications.
|
|
39
|
+
|
|
40
|
+
Save your changes, and scroll down the alphabetical list of notification types till you find the one you just created. It should look something like this:
|
|
41
|
+
|
|
42
|
+
{: width="400" }
|
|
43
|
+
|
|
44
|
+
Notice that all the information you entered is displayed in the widget. You can always edit and update this information as you progress in your application development. But the notification type is not yet finished. You still need to tell the system which events will trigger these notification, and what the messages will look like.
|
|
45
|
+
|
|
46
|
+
### Add Events
|
|
47
|
+
|
|
48
|
+
Click on the "Select an event" button to bring up the modal:
|
|
49
|
+
|
|
50
|
+
{: width="400" }
|
|
51
|
+
|
|
52
|
+
Select an event from the dropdown list and press next. You will be brought to the notification editor where you will be prompted to enter the message that is sent when the notification is triggered. Depending on which _Notification Channels_ you selected when creating the _Notification Type_, you will be presented with one or more tabs for creating messages.
|
|
53
|
+
|
|
54
|
+
### Choose Notification Method
|
|
55
|
+
|
|
56
|
+
Notifications can be sent either to [Subscribers, or directly to an email address](/adsp-monorepo/tutorials/notification-service/subscribers.html).
|
|
57
|
+
|
|
58
|
+
### Add Notification Messages
|
|
59
|
+
|
|
60
|
+
In this example, we've chosen to add an Email message:
|
|
61
|
+
|
|
62
|
+
{: width="600" }
|
|
63
|
+
|
|
64
|
+
You can fully customize the email's layout with HTML, as shown. However, the success of the layout is dependent on the email client of the receiver, and care should be used when developing your template. Consider following best practices for email template development, such as using inline styles, using tables for layout, testing across various clients, providing a plain text version of your email, and using tools like [Litmus Scope](https://litmus.com/scope/) to preview how your templates will render in different clients, particularly _Outlook_.
|
|
65
|
+
|
|
66
|
+
### Customize your Messages
|
|
67
|
+
|
|
68
|
+
You can also customize the text of your messages using the [Handlebars Template tool](https://handlebarsjs.com/guide/). Handlebars work with key value pairs: you embed keys into your template, which will then be replaced by values specified in the [domain event](/adsp-monorepo/tutorials/notification-service/events.html) that gets triggered by your application. Here's an example. Suppose that instead of hard coding the value of the Grant in our example you wanted to make the amount variable, depending on the qualifications in the application. You could do this using Handlebars, using the following syntax for the message:
|
|
69
|
+
|
|
70
|
+
{: width="400" }
|
|
71
|
+
|
|
72
|
+
The _event.payload_ prefix tells the notification service that this particular key refers to the _domain event_ triggered, and the payload object it is triggered with i.e. the API call triggering the event has a payload object associated with it. In this example, the payload object would have an _amount_ property with an appropriate value, like 5¢, or $5 if you're feeling generous. Before the email is sent the template is processed to substitute its keys with the values in the payload. You can learn more about events and payloads [here](/adsp-monorepo/tutorials/notification-service/events.html).
|
|
73
|
+
|
|
74
|
+
### Text Messages
|
|
75
|
+
|
|
76
|
+
Unlike email, you cannot format text messages. You can, however, customize text messages with Handlebars, just as you would with the email templates.
|
|
77
|
+
|
|
78
|
+
## Security
|
|
79
|
+
|
|
80
|
+
As with most ADSP products, the _Notification Service_ security is based on keycloak roles. In particular, subscribers can only be added to a non-public _Notification Type_ if they have the correct roles. You can specify which roles a subscriber must have when creating the Notification Type, i.e.
|
|
81
|
+
|
|
82
|
+
{: width="300" }
|
|
83
|
+
|
|
84
|
+
Subscriptions can also be public, requiring no roles, for anonymous users. Just check the "Make notification public" box when creating the notification type. Anyone, then, can be a subscriber.
|
|
85
|
+
|
|
86
|
+
Note: when using the direct notifications, where only an email address is needed, the notification type is always public.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Subscribers
|
|
3
|
+
layout: page
|
|
4
|
+
nav_order: 3
|
|
5
|
+
parent: Notification Service
|
|
6
|
+
grand_parent: Tutorials
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Subscribers
|
|
10
|
+
|
|
11
|
+
Subscribers and subscriptions are created by your application through the [Notification Service APIs](https://api.adsp-uat.alberta.ca/autotest/?urls.primaryName=Notification%20service), or you can allow your users to manage their own subscriptions through the ADSP _Subscriber App_. Either way, your subscribers will be notified whenever your application triggers a _domain event_ that is associated with the _notification type_.
|
|
12
|
+
|
|
13
|
+
## Anonymous Users
|
|
14
|
+
|
|
15
|
+
To create a subscription you need subscribers, and subscribers are users that have logged in to your application and have known userId's and email addresses. But what about applications whose users don't log in, those that cater to anonymous users? You can still use the notification service. When you create a notification type you can configure it to notify subscribers, or to send the notification directly to an email address:
|
|
16
|
+
|
|
17
|
+
{: width="300" }
|
|
18
|
+
|
|
19
|
+
If you have a known user that is to receive notification, you can input their email address directly here. This is useful for situations where there is a single individual responsible for, say, reviewing submitted applications. However, you may not know the user's email address until runtime. In this case you would want to be able to supply the email address dynamically. Here's what you do:
|
|
20
|
+
|
|
21
|
+
Create a new event type with a payload that includes the user's email address:
|
|
22
|
+
|
|
23
|
+
{: width="300" }
|
|
24
|
+
|
|
25
|
+
Then, when creating a new _Notification Type_ you would add the name of the property to the _Address Path_ input field, e.g. with the above example the _Address Path_ would contain _userEmailAddress_.
|
|
26
|
+
|
|
27
|
+
Finally, when you want to trigger a notification you would POST the event with the following payload:
|
|
28
|
+
|
|
29
|
+
```JSON
|
|
30
|
+
{
|
|
31
|
+
userEmailAddress: "example@example.com"
|
|
32
|
+
}
|
|
33
|
+
```
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Building a Template
|
|
3
|
+
layout: page
|
|
4
|
+
nav_order: 4
|
|
5
|
+
parent: PDF Service
|
|
6
|
+
grand_parent: Tutorials
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
To explore the full capability of the PDF Service and to show how to build a sophisticated template, a real-world example from Child Services is presented; the Intervention Record Check. The CS application is required to handle requests from Albertans for their child intervention records, often used as supporting documentation for employment opportunities. The application will gather data from various sources and, when ready, present the record check to the applicant as a downloadable PDF.
|
|
12
|
+
|
|
13
|
+
The PDF service is ideal for these kinds of requirements, as it enables developers to
|
|
14
|
+
|
|
15
|
+
- build a PDF template, with placeholders for dynamic data
|
|
16
|
+
- generate fully customized PDF documents on demand, and
|
|
17
|
+
- present the final document for the user to view or download.
|
|
18
|
+
|
|
19
|
+
A template - consisting of page headers, page footers, some boiler-plate text, placeholders for customization - is built via the [Template Editor](https://adsp-uat.alberta.ca) within the PDF service, using HTML and CSS for page formatting. Proficiency in those technologies is necessary for anyone wanting to build anything more than a trivial template.
|
|
20
|
+
|
|
21
|
+
Generating the final document, and providing access to it, is done through a series of RESTful API calls to the [PDF service](https://api.adsp.alberta.ca/autotest/?urls.primaryName=PDF%20service) in the language of your choice. The examples given here are written with NodeJS.
|
|
22
|
+
|
|
23
|
+
You will also need to have access to GOA's Keycloak platform. These are needed
|
|
24
|
+
|
|
25
|
+
- by the template designer to login to ADSP's Tenant Admin webapp, to access the PDF template editor, and
|
|
26
|
+
- by the application using the template to acquire access tokens for the API calls.
|
|
27
|
+
|
|
28
|
+
The following discussion will guide you through the steps needed to build a fairly complex template. There are a few pitfalls to navigate through, as Puppeteer can be a bit quirky, and we take full advantage of the [Handlebars](/adsp-monorepo/tutorials/pdf-service/handlebars.html) template engine. If you want to follow along and try it yourself, login to our [Template Editor](https://adsp.alberta.ca) and use the following set of HTML, CSS and test data files:
|
|
29
|
+
|
|
30
|
+
- <a href="/adsp-monorepo/assets/pdf/header.html" download>Header</a>
|
|
31
|
+
- <a href="/adsp-monorepo/assets/pdf/footer.html" download>Footer</a>
|
|
32
|
+
- <a href="/adsp-monorepo/assets/pdf/body.html" download>Body</a>
|
|
33
|
+
- <a href="/adsp-monorepo/assets/pdf/style.html" download>CSS</a>
|
|
34
|
+
- <a href="/adsp-monorepo/assets/pdf/test_data.json" download>Test Data</a>
|
|
35
|
+
|
|
36
|
+
## The Template Editor
|
|
37
|
+
|
|
38
|
+
Template editing is done through the PDF Service's [Template Editor](https://adsp.alberta.ca). Your team will need to have access to a tenant (i.e. a realm on Keycloak) in production, and your GOA user given the tenant admin role. You may need your team lead to set you up with this. And if your team needs to set up a new tenant, please follow [these instructions](/adsp-monorepo/getting-started.html).
|
|
39
|
+
|
|
40
|
+
Once you are able to log in, select PDF on the left menu, and then the Templates tab. Click on the Add Template button to begin building your template. There are six tabs in the editor:
|
|
41
|
+
|
|
42
|
+
- **Header**: to design the document's header's in HTML,
|
|
43
|
+
- **Footer**: to design the document's footer's in HTML,
|
|
44
|
+
- **Body**: to design the main content of the document in HTML,
|
|
45
|
+
- **CSS**: to specify styles that are common to all three components of the document; header, footer, and body
|
|
46
|
+
- **Test Data**: to specify typical values for the Handlebars variables used in the template, for when you are testing to see how a document actually looks, and
|
|
47
|
+
- **File History**: a collection of PDF documents generated, for testing purposes, during your current session.
|
|
48
|
+
|
|
49
|
+
#### The Default Template
|
|
50
|
+
|
|
51
|
+
To give template designers a head start, when a new template is created it will be populated with some default HTML/CSS. It contains a typical GOA header and footer, and some guidelines for things one might find in the body. You can customize this template to suite your needs, or you can delete it and build your own from scratch. In this tutorial we will be building a template from scratch.
|
|
52
|
+
|
|
53
|
+
#### Testing Your Design
|
|
54
|
+
|
|
55
|
+
When building a complex template it is important to be able to visualize how it is looking as you progress in your work, much like with web-design. The right-hand pane of the Template Editor contains an area for previewing PDF's. When you want to check your progress you can specify "typical" values for your [Handlebars](/adsp-monorepo/tutorials/pdf-service/handlebars.html) variables on the _Test Data_ tab, then click Generate PDF on the top right. It may take a few seconds, but the PDF will soon show up in the pane.
|
|
56
|
+
|
|
57
|
+
The editor also keeps a list of the last few PDF files generated in your session, on the _File History_ tab, so you can look back at them if the need arises. The list is short, and temporary, so please download any files you may want to keep around for prosperity.
|
|
58
|
+
|
|
59
|
+
## Define Page Attributes
|
|
60
|
+
|
|
61
|
+
The first step is to define the boundaries for the page. [Puppeteer](/adsp-monorepo/tutorials/pdf-service/puppeteer.html) – the PDF generation engine used by the PDF service – allocates room for headers and footers via page margins. The header defaults to 10px in height. Since the IRC header is much higher than 10px these margins must be changed, or the lower portion of the header block will be obscured with body content. We can do this by setting the page margins on the body tab:
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
@page {
|
|
65
|
+
margin: 220px 0 100px 0;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Notice that the units are in pixels, rather than centimeters or other common CSS units. This is _mandatory_. Puppeteer does not recognize any other units of measure. In this case the side margins are zero, giving us more room, if needed, for the component blocks. The top margin is set to 220px, a value derived from the ol' **test to see what works** algorithm.
|
|
70
|
+
|
|
71
|
+
The template also uses the GOA colours for highlights. We need to explicitly tell puppeteer to render colours exactly, otherwise they come out as grey tones;
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
html {
|
|
75
|
+
-webkit-print-color-adjust: exact;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Build the Page Header
|
|
80
|
+
|
|
81
|
+
The page header for the IRC document consists of
|
|
82
|
+
|
|
83
|
+
- The Government of Alberta logo
|
|
84
|
+
- The document title
|
|
85
|
+
- Applicant identification
|
|
86
|
+
|
|
87
|
+

|
|
88
|
+
|
|
89
|
+
The HTML for the header is quite simple;
|
|
90
|
+
|
|
91
|
+
{% raw %}
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<div class="header-wrapper">
|
|
95
|
+
<div class="logo"></div>
|
|
96
|
+
<p>Children's Services</p>
|
|
97
|
+
<div class="subtitle"><span>Intervention Record Check</span><span>Protected B</span></div>
|
|
98
|
+
<div class="clear" />
|
|
99
|
+
<div class="client-info">
|
|
100
|
+
<div>{{data.date}}</div>
|
|
101
|
+
<div class="uppercase">To: {{data.applicant.lastName}}, {{data.applicant.firstName}}</div>
|
|
102
|
+
<div class="uppercase">Aliases: {{data.applicant.lastName}}, {{data.applicant.alias}}</div>
|
|
103
|
+
<div class="uppercase">Dob: {{data.applicant.dob}}</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
{% endraw %}
|
|
109
|
+
|
|
110
|
+
#### Handlebars Placeholders
|
|
111
|
+
|
|
112
|
+
Notice the code-like constructs between double curly braces. Each page of the PDF is required to have the applicant's identification – name, alias and date of birth – so it makes sense to put the information into the header. But the information is supplied dynamically, since it is different for each user. This is where a component of the PDF service comes in handy – [Handlebars](/adsp-monorepo/tutorials/pdf-service/handlebars.html)! It’s a template tool that allows us to specify placeholders for the real data. When the PDF is generated, you provide the system with actual values as a JSON object, thereby customizing the document. The JSON object for this example might look something like this:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"date": "Jan 21, 2023",
|
|
117
|
+
"applicant": { "firstName": "Bob", "lastName": "Bing", "alias": "Billy", "dob": "Oct 31, 1989" }
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
In our example, we have handlebars for the applicants name, alias, and date of birth, as well as the current date. Notice that the placeholder names always have a _data._ prefix. This is _very important_, as without the prefix the handlebar will be ignored. _Equally important_ though, is the fact that the JSON data does not have the _data._ prefix. With it, the data will be ignored. Its a quirk of our system. The rest of the name in the handlebar is used as a key, to map it to actual data when the PDF is generated.
|
|
122
|
+
|
|
123
|
+
#### General Page Layout
|
|
124
|
+
|
|
125
|
+
Styling the HTML also has some interesting features. First, define a container for the header and set its width at ~60% of the page width of 210mm (a4). This was determined empirically, and changes may require a bit of back and forth testing to find the best fit.
|
|
126
|
+
|
|
127
|
+
```css
|
|
128
|
+
.header-wrapper {
|
|
129
|
+
padding: 0 0 0 2cm;
|
|
130
|
+
margin: 0;
|
|
131
|
+
width: 130mm;
|
|
132
|
+
}
|
|
133
|
+
.header-wrapper p,
|
|
134
|
+
div {
|
|
135
|
+
margin: 0;
|
|
136
|
+
padding: 0;
|
|
137
|
+
font-size: 8pt;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
It is also _very important_ to explicitly set the font-size of the header content. Otherwise, at times, randomly it seems, puppeteer sets the font size to zero and your content appears to have vanished.
|
|
142
|
+
|
|
143
|
+
The rest is pretty much standard CSS for managing layout, as you would normally do for any webpage.
|
|
144
|
+
|
|
145
|
+
## Build the Page Footer
|
|
146
|
+
|
|
147
|
+
The page footer also has some features worth discussing.
|
|
148
|
+
|
|
149
|
+

|
|
150
|
+
|
|
151
|
+
Again, the HTML is quite simple
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<div class="footer-wrapper">
|
|
155
|
+
<span class="copyright">© 2023 Government of Alberta</span>
|
|
156
|
+
page <span class="pageNumber" /> of <span class="totalPages" />
|
|
157
|
+
<div class="logo-wrapper"><div class="logo"></div></div>
|
|
158
|
+
</div>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Anchoring the footer
|
|
162
|
+
|
|
163
|
+
In spite of setting the page margins to 0 Puppeteer still needs some coaxing to get the footer flush with the bottom of the page. To force the issue set the position to relative and push the wrapper down a bit. Trial and error found 7.6mm worked in this instance. This value depends on the height of the header and will need adjusting as the latter changes.
|
|
164
|
+
|
|
165
|
+
```css
|
|
166
|
+
.footer-wrapper {
|
|
167
|
+
width: 210mm;
|
|
168
|
+
border-bottom: 2mm solid #00aad2;
|
|
169
|
+
padding: 5mm 0 5mm 1cm;
|
|
170
|
+
font-size: 10pt;
|
|
171
|
+
background-color: lightgrey;
|
|
172
|
+
position: relative;
|
|
173
|
+
top: 7.6mm;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Also, in this case, we set the width to the full width of the a4 letter size, to ensure the coloured background covers everything.
|
|
178
|
+
|
|
179
|
+
#### Displaying Page Numbers
|
|
180
|
+
|
|
181
|
+
Another requirement for the IRC template was to have the page number displayed on each page – i.e. page 1 of 5. Fortunately, Puppeteer provides some variables to help us with this; pageNumber and totalPages. You can access the values through a tag's class attribute e.g.
|
|
182
|
+
|
|
183
|
+
```html
|
|
184
|
+
<span class="pageNumber" />
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Puppeteer treats this as a placeholder and will substitute the actual page number when the PDF is generated.
|
|
188
|
+
|
|
189
|
+
## Build the Body
|
|
190
|
+
|
|
191
|
+
There is not a lot of boilerplate text in the IRC body. Most of it is input by the applicant when they're applying for a record check. The bulk of it consists of the applicant's history, which can be quite extensive, and it's compiled into a series of blocks, each with a title and content.
|
|
192
|
+
|
|
193
|
+
#### Handlebars Iterators
|
|
194
|
+
|
|
195
|
+
Since we don't know how much history there is going to be, this is a perfect opportunity to utilize [handlebars iterator](https://handlebarsjs.com/guide/builtin-helpers.html#each) construct, which looks like this:
|
|
196
|
+
|
|
197
|
+
{% raw %}
|
|
198
|
+
|
|
199
|
+
```html
|
|
200
|
+
{{#each data.history}}
|
|
201
|
+
<div class="history">
|
|
202
|
+
<div class="title">{{this.title}}</div>
|
|
203
|
+
<div class="content">
|
|
204
|
+
<p>
|
|
205
|
+
{{#each this.content}}
|
|
206
|
+
<p>{{this}}</p>
|
|
207
|
+
{{/each}}
|
|
208
|
+
</p>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
{{/each}}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
{% endraw %}
|
|
215
|
+
|
|
216
|
+
Applying the following Json to the template
|
|
217
|
+
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"history": [
|
|
221
|
+
{ "title": "First Title", "content": ["paragraph 1a", "paragraph 2a", "paragraph 3a"] },
|
|
222
|
+
{ "title": "Second Title", "content": ["paragraph 1b", "paragraph 2b", "paragraph 3b"] },
|
|
223
|
+
{ "title": "Third Title", "content": ["paragraph 1c", "paragraph 2c", "paragraph 3c"] }
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
would yield three history blocks, each looking something like
|
|
229
|
+
|
|
230
|
+

|
|
231
|
+
|
|
232
|
+
The #each iterator operates on JSON arrays, allowing you to easily collect and process lists of data.
|
|
233
|
+
|
|
234
|
+
#### Adding Images
|
|
235
|
+
|
|
236
|
+
Although you can source an image from anywhere, the PDF service makes it easy to use images uploaded to the [File Service](/adsp-monorepo/tutorials/file-service/introduction.html)
|
|
237
|
+
in your documents. You can refer to an image through handlebars by its file ID (e.g. _27d6c5f2-924f-4dd3-9225-10d019ca23b6_), as follows:
|
|
238
|
+
|
|
239
|
+
- {% raw %} {{ fileId "27d6c5f2-924f-4dd3-9225-10d019ca23b6" }} {% endraw %},
|
|
240
|
+
- {% raw %} {{ fileId data.27d6c5f2-924f-4dd3-9225-10d019ca23b6 }} {% endraw %}, or
|
|
241
|
+
- {% raw %} {{ fileId "urn:ads:platform:file-service:/files/27d6c5f2-924f-4dd3-9225-10d019ca23b6" }} {% endraw %}
|
|
242
|
+
|
|
243
|
+
For example, if you upload the GOA _Alberta_ logo to the file service, you can display it in your PDF by ID like this:
|
|
244
|
+
{% raw %}
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
<img src="{{ fileId "27d6c5f2-924f-4dd3-9225-10d019ca23b6" }}" alt="Alberta logo" />
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
{% endraw %}
|
|
251
|
+
|
|
252
|
+
Note: the image must be uploaded in the same environment as the PDF service; i.e. PROD does not look for images uploaded in the UAT environment and vise versa.
|
|
253
|
+
|
|
254
|
+
#### Avoiding Page Breaks
|
|
255
|
+
|
|
256
|
+
One of the goals for the IRC template was to avoid page breaks over the history blocks. That is, if a block can fit on one page, make it do so. Pagination is controlled by Puppeteer, and it pays attention to CSS @[media directives](https://www.smashingmagazine.com/2018/05/print-stylesheets-in-2018/).
|
|
257
|
+
|
|
258
|
+
```css
|
|
259
|
+
@media print {
|
|
260
|
+
.history {
|
|
261
|
+
page-break-inside: avoid;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
By wrapping each history block in a <div> tag with class history, Puppeteer will endeavor to place each one on a single page. Of course, if the content of a block spans more than one, this is not possible.
|
|
267
|
+
|
|
268
|
+
#### Repeating Table Headers
|
|
269
|
+
|
|
270
|
+
Another interesting requirement was the placement of a title on each page that had a history block on it, namely _Summary of your involvement up to today_. We couldn't put it in the header, because not every page has a history block. So how can we tell Puppeteer to do this? Well, it turns out that it has a very nice feature; when a table spans more than one page the headers are repeated at the top of each one. By wrapping the history blocks in a table, with the above sentence as a table header, the requirement is met!
|
|
271
|
+
|
|
272
|
+
{% raw %}
|
|
273
|
+
|
|
274
|
+
```html
|
|
275
|
+
<div class="history">
|
|
276
|
+
<table>
|
|
277
|
+
<thead>
|
|
278
|
+
<tr>
|
|
279
|
+
<th>Summary of your involvement up to today.</th>
|
|
280
|
+
</tr>
|
|
281
|
+
</thead>
|
|
282
|
+
<tbody>
|
|
283
|
+
{{#each data.history}}
|
|
284
|
+
<tr>
|
|
285
|
+
<td>
|
|
286
|
+
<div class="title">{{this.title}}</div>
|
|
287
|
+
<div class="content">
|
|
288
|
+
{{#each this.content}}
|
|
289
|
+
<p>{{this}}</p>
|
|
290
|
+
{{/each}}
|
|
291
|
+
</div>
|
|
292
|
+
</td>
|
|
293
|
+
</tr>
|
|
294
|
+
{{/each}}
|
|
295
|
+
</tbody>
|
|
296
|
+
</table>
|
|
297
|
+
</div>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
{% endraw %}
|
|
301
|
+
|
|
302
|
+

|
|
303
|
+
|
|
304
|
+
#### Watermarks
|
|
305
|
+
|
|
306
|
+
You can add watermarks to your PDF pages, which can be important for identification and security purposes. This can be done entirely through CSS:
|
|
307
|
+
|
|
308
|
+
```css
|
|
309
|
+
.body-wrapper:before {
|
|
310
|
+
content: 'Government of Alberta Confidential';
|
|
311
|
+
position: fixed;
|
|
312
|
+
top: 0;
|
|
313
|
+
bottom: 120px;
|
|
314
|
+
left: 0;
|
|
315
|
+
right: 0;
|
|
316
|
+
z-index: -1;
|
|
317
|
+
|
|
318
|
+
color: #00aad2;
|
|
319
|
+
font-size: 80pt;
|
|
320
|
+
font-weight: 500px;
|
|
321
|
+
display: grid;
|
|
322
|
+
justify-content: center;
|
|
323
|
+
align-content: center;
|
|
324
|
+
opacity: 0.1;
|
|
325
|
+
transform: rotate(-45deg);
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
In this example we've used text, but it's easy enough to place a background image instead, if desired. The body, with the above watermark, will look something like the following:
|
|
330
|
+
|
|
331
|
+

|
|
332
|
+
|
|
333
|
+
## Wrapping Up
|
|
334
|
+
|
|
335
|
+
There are still things to learn about [Puppeteer](https://pptr.dev/) and [Handlebars](https://handlebarsjs.com/guide/), but the information presented here will give you a good starting point for developing your own templates. Starting with the _default template_ that initially populates your design, you should be able to craft one, or more, to suit your application needs.
|
|
336
|
+
|
|
337
|
+
## Learn More
|
|
338
|
+
|
|
339
|
+
- Learn how to [generate a PDF from a template](/adsp-monorepo/tutorials/pdf-service/generate-a-pdf.html)
|