@openfn/language-varo 1.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/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +243 -0
- package/ast.json +670 -0
- package/configuration-schema.json +7 -0
- package/dist/index.cjs +392 -0
- package/dist/index.js +373 -0
- package/package.json +47 -0
- package/types/Adaptor.d.ts +19 -0
- package/types/FridgeTagUtils.d.ts +5 -0
- package/types/Utils.d.ts +1 -0
- package/types/VaroEmsUtils.d.ts +23 -0
- package/types/index.d.ts +3 -0
package/LICENSE.LESSER
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# language-varo <img src='./assets/square.png' width="30" height="30"/>
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Setup the primary workflow and jobs
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
The workflow requires some pre-configuration, namely the Gmail `access_token` and the OpenFn `collection_token`.
|
|
10
|
+
|
|
11
|
+
### Token configuration
|
|
12
|
+
|
|
13
|
+
#### Gmail token
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
#### OpenFn collections token
|
|
18
|
+
|
|
19
|
+
The workflow tracks the previously processed messages by storing the processed IDs in an OpenFn collection. OpenFn requires authorization to access a given collection.
|
|
20
|
+
|
|
21
|
+
1. Access the [Collections](http://localhost:4000/settings/collections) configuration in the administration area.
|
|
22
|
+
1. Ensure the collection named `gmail-processed-ids` exists.
|
|
23
|
+
1. Create a new token in the [Personal Access Tokens](http://localhost:4000/profile/tokens) configuration.
|
|
24
|
+
|
|
25
|
+
### Workflow
|
|
26
|
+
|
|
27
|
+
Place these files in the openfn/adaptors/workflows folder
|
|
28
|
+
|
|
29
|
+
#### workflow.json
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
{
|
|
33
|
+
"options": {
|
|
34
|
+
"start": "getContentsFromMessages"
|
|
35
|
+
},
|
|
36
|
+
"workflow": {
|
|
37
|
+
"steps": [
|
|
38
|
+
{
|
|
39
|
+
"id": "getContentsFromMessages",
|
|
40
|
+
"adaptors": [
|
|
41
|
+
"gmail",
|
|
42
|
+
"collections"
|
|
43
|
+
],
|
|
44
|
+
"expression": "jobGmail.js",
|
|
45
|
+
"configuration": {
|
|
46
|
+
"access_token": "[redacted]"
|
|
47
|
+
},
|
|
48
|
+
"next": {
|
|
49
|
+
"convertToEms": "Array.isArray(state.data) && state.data.length > 0"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "convertToEms",
|
|
54
|
+
"adaptor": "varo",
|
|
55
|
+
"expression": "jobVaro.js",
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"credentials": {
|
|
59
|
+
"collections_endpoint": "http://localhost:4000/collections",
|
|
60
|
+
"collections_token": "[redacted]"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Jobs
|
|
67
|
+
|
|
68
|
+
#### jobGmail.js
|
|
69
|
+
|
|
70
|
+
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.
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
const contents = [
|
|
74
|
+
{ name: "metadata", file: /\d{12}_\d{8}T\d{6}Z\.json$/ },
|
|
75
|
+
{ name: "data", file: /_CURRENT_DATA_.*\.json$/ },
|
|
76
|
+
{
|
|
77
|
+
name: "data",
|
|
78
|
+
archive: /_varo_data\.zip$/,
|
|
79
|
+
file: /_CURRENT_DATA_.*\.json$/,
|
|
80
|
+
},
|
|
81
|
+
{ name: "fridgeTag", file: /\d{12}_\d{12}_\d{8}T\d{6}Z\.txt$/ },
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
const collectionName = "gmail-processed-ids";
|
|
85
|
+
const itemName = "processedIds";
|
|
86
|
+
|
|
87
|
+
collections.get(collectionName, itemName);
|
|
88
|
+
|
|
89
|
+
getContentsFromMessages({
|
|
90
|
+
contents,
|
|
91
|
+
processedIds: $.data,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
fnIf(
|
|
95
|
+
(state) => Array.isArray(state.processedIds),
|
|
96
|
+
collections.set(collectionName, itemName, $.processedIds)
|
|
97
|
+
);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### jobVaro.js
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
Expected data structure:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
metadata: {
|
|
110
|
+
content: '',
|
|
111
|
+
filename: '',
|
|
112
|
+
},
|
|
113
|
+
data: {
|
|
114
|
+
content: '',
|
|
115
|
+
filename: '',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
convertToEms($.data);
|
|
124
|
+
|
|
125
|
+
fn((state) => {
|
|
126
|
+
console.log(state.data);
|
|
127
|
+
return state;
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Running the workflow
|
|
132
|
+
|
|
133
|
+
The `-m` flag tells OpenFn to use the monorepo instead of its own adaptor cache.
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
cd openfn/adaptors/workflows
|
|
137
|
+
openfn workflow.json -m
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Advanced workflow operation
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
### Cache Gmail adaptor output
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
- `-m` Use the monorepo.
|
|
149
|
+
- `--cache-steps` Direct the CLI to cache the job output.
|
|
150
|
+
- `--only getContentsFromMessages` Execute only the getContentsFromMessage step.
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
openfn workflow.json -m --cache-steps --only getContentsFromMessages
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Running the workflow with cached Gmail adaptor output
|
|
157
|
+
|
|
158
|
+
- `-m` Use the monorepo.
|
|
159
|
+
- `--only convertToEms` Execute only the convertToEms step.
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
openfn workflow.json -m --only convertToEms
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
# Enhancing/developing the Varo adaptor
|
|
166
|
+
|
|
167
|
+
These instructions will illustrate how to install OpenFn and the adaptor monorepo. The monorepo gives you access to in-development versions of the adaptors.
|
|
168
|
+
|
|
169
|
+
Recommended folder structure:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
openfn
|
|
173
|
+
├── lightning
|
|
174
|
+
└── adaptors
|
|
175
|
+
├── adaptors
|
|
176
|
+
└── workflows
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## Install OpenFn
|
|
181
|
+
|
|
182
|
+
Prerequisite is Docker in installed, up-to-date, and running on your computer.
|
|
183
|
+
|
|
184
|
+
### Clone the Lightning repository
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
cd openfn
|
|
188
|
+
git clone https://github.com/OpenFn/lightning.git
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Build the containers
|
|
192
|
+
|
|
193
|
+
This will build three docker containers:
|
|
194
|
+
|
|
195
|
+
1. lightning-web
|
|
196
|
+
1. postgres
|
|
197
|
+
1. ws-worker
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
docker compose build && docker compose run --rm web mix ecto.migrate
|
|
201
|
+
docker compose up -d
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The web application will be running on [localhost port 4000](http://localhost:4000).
|
|
205
|
+
|
|
206
|
+
## Install the monorepo
|
|
207
|
+
|
|
208
|
+
To use the monorepo locally you'll need some prerequesite build tools installed.
|
|
209
|
+
|
|
210
|
+
### Prerequesites
|
|
211
|
+
|
|
212
|
+
asdf, nodejs, pnpm
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
|
|
216
|
+
|
|
217
|
+
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
|
|
218
|
+
asdf plugin-add pnpm
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Clone the monorepo repository
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
cd openfn/adaptors
|
|
225
|
+
git clone https://github.com/OpenFn/adaptors.git
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Install the build tools
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
asdf install # Install tool versions
|
|
232
|
+
pnpm install
|
|
233
|
+
pnpm build
|
|
234
|
+
pnpm run setup
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Switch to the working branch of the varo adaptor
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
cd openfn/adaptors/adaptors
|
|
241
|
+
git checkout nhgh-varo
|
|
242
|
+
```
|
|
243
|
+
|