-
Notifications
You must be signed in to change notification settings - Fork 12
Varo packager #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
decarteret
wants to merge
8
commits into
main
Choose a base branch
from
varo-packager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Varo packager #1152
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8d8f483
added emsMapper
d0f0642
add functionality to create varo package assets
151566c
marked description property as optional.
fd1c4f6
Simplified definitions.
539588e
Refactored for modularity.
d1778d8
Enhanced readme.
fc5aec6
Fixed broken test after function signature change broke it.
6ca9ebb
Added generated timestamp to report.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@openfn/language-varo': minor | ||
--- | ||
|
||
Added components to support converting collection data into Varo message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just copy and paste this into the root |
||
packages. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
# language-varo <img src='./assets/square.png' width="30" height="30"/> | ||
|
||
The Varo adaptor works in conjunction with the Gmail adaptor. It takes proprietary data formats found in `state.data` and attempts to convert them to EMS format. | ||
The Varo adaptor is designed to work in conjunction with the Gmail adaptor. | ||
|
||
## Setup the primary workflow and jobs | ||
The following workflows have been illustrated: | ||
- Gmail -> EMS report | ||
Take proprietary data formats found in Gmail messages and convert them to EMS-compliant format. | ||
- CCDX data collection -> Gmail | ||
Retrieve data found in an OpenFn collection, convert it to a EMS report, assemble it as a Varo package and send it to a Varo inbox to be processed by Pogo LT. | ||
|
||
# Gmail -> EMS report | ||
|
||
This will demonstrate how to pull messages from a Gmail account and pass them to the Varo adaptor which will convert them into EMS format to be used for downstream consumers in the workflow. | ||
|
||
The workflow requires some pre-configuration, namely the Gmail `access_token` and the OpenFn `collection_token`. | ||
|
||
### Token configuration | ||
|
||
#### Gmail token | ||
|
||
Use Postman to retrieve an access token. This is a short-lived token will last 60 minutes and will have to be manually retrieved. See the documentation in the [Gmail adaptor readme](https://docs.openfn.org/adaptors/packages/gmail-readme#use-the-postman-application-to-query-the-oauth-enpoint-and-retrieve-an-access-token) for a guide on how to configure Postman to retrieve the access token. | ||
|
||
#### OpenFn collections token | ||
## Example workflow | ||
|
||
The workflow tracks the previously processed messages by storing the processed IDs in an OpenFn collection. OpenFn requires authorization to access a given collection. | ||
|
||
1. Access the [Collections](http://localhost:4000/settings/collections) configuration in the administration area. | ||
1. Ensure the collection named `gmail-processed-ids` exists. | ||
1. Create a new token in the [Personal Access Tokens](http://localhost:4000/profile/tokens) configuration. | ||
Place these files in the openfn/adaptors/workflows/readVaroPackages folder. | ||
|
||
### Workflow | ||
### workflow.json | ||
|
||
Place these files in the openfn/adaptors/workflows folder | ||
|
||
#### workflow.json | ||
|
||
``` | ||
```js | ||
{ | ||
"options": { | ||
"start": "getContentsFromMessages" | ||
|
@@ -63,13 +55,11 @@ Place these files in the openfn/adaptors/workflows folder | |
} | ||
``` | ||
|
||
### Jobs | ||
|
||
#### jobGmail.js | ||
### jobGmail.js | ||
|
||
This job will define message parts of interest including: metadata, data and fridgeTag. Also important is a collection of previously-processed messageIds. This job will grab ids from the `gmail-processed-ids` collection and pass them into the request. Once the request is complete, the new, processed messageIds are placed into the collection for future retrieval. | ||
|
||
``` | ||
```js | ||
const contents = [ | ||
{ name: "metadata", file: /\d{12}_\d{8}T\d{6}Z\.json$/ }, | ||
{ name: "data", file: /_CURRENT_DATA_.*\.json$/ }, | ||
|
@@ -97,13 +87,13 @@ fnIf( | |
); | ||
``` | ||
|
||
#### jobVaro.js | ||
### jobVaro.js | ||
|
||
The function `convertToEms` expects an array of message contents. This property contains text files in EMS-like Varo format or FridgeTag format and transforms them into EMS-structured data. Tip: This format is automatically provided by the Gmail adaptor. | ||
|
||
Expected data structure: | ||
|
||
``` | ||
```js | ||
[ | ||
{ | ||
metadata: { | ||
|
@@ -119,7 +109,7 @@ Expected data structure: | |
``` | ||
|
||
|
||
``` | ||
```js | ||
convertToEms($.data); | ||
|
||
fn((state) => { | ||
|
@@ -128,20 +118,103 @@ fn((state) => { | |
}); | ||
``` | ||
|
||
### Running the workflow | ||
# CCDX data collection -> Gmail | ||
|
||
Following is an example demonstrating how to retrieve data found in an OpenFn collection, convert it to a EMS report, assemble it as a Varo package and send it to a Varo inbox to be processed by Pogo LT. | ||
|
||
## Example workflow | ||
|
||
Place these files in the openfn/adaptors/workflows/sendVaroPackage folder. | ||
|
||
### workflow.js | ||
```js | ||
{ | ||
"workflow": { | ||
"steps": [ | ||
{ | ||
"id": "convertRecordsToMessageContent", | ||
"adaptor": "varo", | ||
"expression": "jobVaro.js", | ||
"next": { | ||
"sendMessage": "state.data != null" | ||
} | ||
}, | ||
{ | ||
"id": "sendMessage", | ||
"adaptor": "gmail", | ||
"expression": "jobGmail.js", | ||
"configuration": { | ||
"access_token": "[redacted]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### jobVaro.js | ||
|
||
```js | ||
// Pull the data from the collection into the state. | ||
collections.get("ccdx-ems", "*"); | ||
|
||
// Convert the raw collection records into an EMS report. | ||
convertRecordsToReport($.data); | ||
|
||
// Convert the EMS report to message contents (subject, data file). | ||
convertReportToMessageContent($.data, "ems"); | ||
``` | ||
|
||
### jobGmail.js | ||
|
||
```js | ||
fn((state) => { | ||
const { subject, data } = state.data; | ||
|
||
/* | ||
subject = "OpenFn | EMS"; | ||
data = { | ||
filename: "data.json", | ||
content: "{ ... EMS report converted to JSON string ... }", | ||
}; | ||
*/ | ||
|
||
// Compress the data.json file into a ZIP file. | ||
const dataArchive = { | ||
filename: "data.zip", | ||
archive: [data], | ||
}; | ||
|
||
state.data = { | ||
to: "[email protected]", | ||
subject, | ||
attachments: [dataArchive], | ||
}; | ||
|
||
return state; | ||
}); | ||
|
||
sendMessage($.data); | ||
``` | ||
|
||
# Running workflow | ||
|
||
We can look in more detail at the Gmail -> EMS report workflow and illustrate some advanced techniques to enhance the development experience and operation. | ||
|
||
## Basics | ||
|
||
The `-m` flag tells OpenFn to use the monorepo instead of its own adaptor cache. | ||
|
||
``` | ||
cd openfn/adaptors/workflows | ||
cd openfn/adaptors/workflows/readVaroPackages | ||
openfn workflow.json -m | ||
``` | ||
|
||
## Advanced workflow operation | ||
|
||
It's beneficial to isolate the Varo adaptor during development to avoid the redundant step of repeatedly querying Gmail which also requires refreshing the access token each hour. We can use advanced functionality of the OpenFn CLI to cache the output of the Gmail step which will enable us reuse its output while we are enhancing the Varo adaptor. | ||
|
||
### Cache Gmail adaptor output | ||
### Cache the output from a step | ||
|
||
We can configure the workflow to retrieve this message content from a local file which will bypass the need to use the Gmail adaptor to retrieve this information. | ||
|
||
|
@@ -153,7 +226,7 @@ We can configure the workflow to retrieve this message content from a local file | |
openfn workflow.json -m --cache-steps --only getContentsFromMessages | ||
``` | ||
|
||
### Running the workflow with cached Gmail adaptor output | ||
### Running with a cached step | ||
|
||
- `-m` Use the monorepo. | ||
- `--only convertToEms` Execute only the convertToEms step. | ||
|
@@ -162,6 +235,22 @@ openfn workflow.json -m --cache-steps --only getContentsFromMessages | |
openfn workflow.json -m --only convertToEms | ||
``` | ||
|
||
# Token configuration | ||
|
||
Some workflows required authorization to access the resources. | ||
|
||
## Gmail token | ||
|
||
Use Postman to retrieve an access token. This is a short-lived token will last 60 minutes and will have to be manually retrieved. See the documentation in the [Gmail adaptor readme](https://docs.openfn.org/adaptors/packages/gmail-readme#use-the-postman-application-to-query-the-oauth-enpoint-and-retrieve-an-access-token) for a guide on how to configure Postman to retrieve the access token. | ||
|
||
## OpenFn collections token | ||
|
||
A workflow may track the previously processed messages by storing the processed IDs in an OpenFn collection. OpenFn requires authorization to access a given collection. | ||
|
||
1. Access the [Collections](http://localhost:4000/settings/collections) configuration in the administration area. | ||
1. Ensure the collection named `gmail-processed-ids` exists. | ||
1. Create a new token in the [Personal Access Tokens](http://localhost:4000/profile/tokens) configuration. | ||
|
||
# Enhancing/developing the Varo adaptor | ||
|
||
These instructions will illustrate how to install OpenFn and the adaptor monorepo. The monorepo gives you access to in-development versions of the adaptors. | ||
|
@@ -176,7 +265,6 @@ openfn | |
└── workflows | ||
``` | ||
|
||
|
||
## Install OpenFn | ||
|
||
Prerequisite is Docker in installed, up-to-date, and running on your computer. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is wrong here - all this changeset stuff needs removing
I think you needed to run
pnpm changeset
from the root dir, not the varo folder