@openfn/language-resourcemap 0.2.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 +53 -0
- package/ast.json +423 -0
- package/configuration-schema.json +31 -0
- package/dist/index.cjs +145 -0
- package/dist/index.js +122 -0
- package/package.json +49 -0
- package/types/Adaptor.d.ts +25 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
alterState: () => import_language_common2.alterState,
|
|
29
|
+
dataPath: () => import_language_common2.dataPath,
|
|
30
|
+
dataValue: () => import_language_common2.dataValue,
|
|
31
|
+
default: () => src_default,
|
|
32
|
+
each: () => import_language_common2.each,
|
|
33
|
+
execute: () => execute,
|
|
34
|
+
field: () => import_language_common2.field,
|
|
35
|
+
fields: () => import_language_common2.fields,
|
|
36
|
+
fn: () => import_language_common2.fn,
|
|
37
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
38
|
+
merge: () => import_language_common2.merge,
|
|
39
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
40
|
+
submitSite: () => submitSite
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
|
|
44
|
+
// src/Adaptor.js
|
|
45
|
+
var Adaptor_exports = {};
|
|
46
|
+
__export(Adaptor_exports, {
|
|
47
|
+
alterState: () => import_language_common2.alterState,
|
|
48
|
+
dataPath: () => import_language_common2.dataPath,
|
|
49
|
+
dataValue: () => import_language_common2.dataValue,
|
|
50
|
+
each: () => import_language_common2.each,
|
|
51
|
+
execute: () => execute,
|
|
52
|
+
field: () => import_language_common2.field,
|
|
53
|
+
fields: () => import_language_common2.fields,
|
|
54
|
+
fn: () => import_language_common2.fn,
|
|
55
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
56
|
+
merge: () => import_language_common2.merge,
|
|
57
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
58
|
+
submitSite: () => submitSite
|
|
59
|
+
});
|
|
60
|
+
var import_language_common = require("@openfn/language-common");
|
|
61
|
+
var import_request = __toESM(require("request"), 1);
|
|
62
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
63
|
+
function execute(...operations) {
|
|
64
|
+
const initialState = {
|
|
65
|
+
references: [],
|
|
66
|
+
data: null
|
|
67
|
+
};
|
|
68
|
+
return (state) => {
|
|
69
|
+
return (0, import_language_common.execute)(...operations)({ ...initialState, ...state });
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function submitSite(collection_id, submissionData) {
|
|
73
|
+
function assembleError({ response, error }) {
|
|
74
|
+
if ([200, 201, 202].indexOf(response.statusCode) > -1)
|
|
75
|
+
return false;
|
|
76
|
+
if (error)
|
|
77
|
+
return error;
|
|
78
|
+
return new Error(
|
|
79
|
+
`Server responded with ${response.statusCode}
|
|
80
|
+
${response.body}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return (state) => {
|
|
84
|
+
const body = (0, import_language_common.expandReferences)(submissionData)(state);
|
|
85
|
+
console.log(
|
|
86
|
+
"Submitting site to collection " + collection_id + ":\n" + JSON.stringify(body, null, 4) + "\n"
|
|
87
|
+
);
|
|
88
|
+
const { username, password, baseUrl } = state.configuration;
|
|
89
|
+
const url = resolveUrl(
|
|
90
|
+
baseUrl + "/",
|
|
91
|
+
"api/collections/" + collection_id + "/sites.json"
|
|
92
|
+
);
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
import_request.default.post(
|
|
95
|
+
{
|
|
96
|
+
url,
|
|
97
|
+
json: body,
|
|
98
|
+
auth: {
|
|
99
|
+
user: username,
|
|
100
|
+
pass: password,
|
|
101
|
+
sendImmediately: true
|
|
102
|
+
},
|
|
103
|
+
headers: {
|
|
104
|
+
"content-disposition": 'form-data; name=\\"site\\"'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
function(error, response, body2) {
|
|
108
|
+
error = assembleError({ error, response });
|
|
109
|
+
if (error) {
|
|
110
|
+
reject(error);
|
|
111
|
+
} else {
|
|
112
|
+
console.log("Printing response...\n");
|
|
113
|
+
console.log(JSON.stringify(response, null, 4) + "\n");
|
|
114
|
+
console.log("Site submission succeeded.");
|
|
115
|
+
resolve(body2);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
return import_request.default.post({
|
|
121
|
+
username,
|
|
122
|
+
password,
|
|
123
|
+
body,
|
|
124
|
+
url
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/index.js
|
|
130
|
+
var src_default = Adaptor_exports;
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
alterState,
|
|
134
|
+
dataPath,
|
|
135
|
+
dataValue,
|
|
136
|
+
each,
|
|
137
|
+
execute,
|
|
138
|
+
field,
|
|
139
|
+
fields,
|
|
140
|
+
fn,
|
|
141
|
+
lastReferenceValue,
|
|
142
|
+
merge,
|
|
143
|
+
sourceValue,
|
|
144
|
+
submitSite
|
|
145
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/Adaptor.js
|
|
8
|
+
var Adaptor_exports = {};
|
|
9
|
+
__export(Adaptor_exports, {
|
|
10
|
+
alterState: () => alterState,
|
|
11
|
+
dataPath: () => dataPath,
|
|
12
|
+
dataValue: () => dataValue,
|
|
13
|
+
each: () => each,
|
|
14
|
+
execute: () => execute,
|
|
15
|
+
field: () => field,
|
|
16
|
+
fields: () => fields,
|
|
17
|
+
fn: () => fn,
|
|
18
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
19
|
+
merge: () => merge,
|
|
20
|
+
sourceValue: () => sourceValue,
|
|
21
|
+
submitSite: () => submitSite
|
|
22
|
+
});
|
|
23
|
+
import {
|
|
24
|
+
execute as commonExecute,
|
|
25
|
+
expandReferences
|
|
26
|
+
} from "@openfn/language-common";
|
|
27
|
+
import request from "request";
|
|
28
|
+
import {
|
|
29
|
+
fn,
|
|
30
|
+
alterState,
|
|
31
|
+
field,
|
|
32
|
+
fields,
|
|
33
|
+
sourceValue,
|
|
34
|
+
merge,
|
|
35
|
+
each,
|
|
36
|
+
dataPath,
|
|
37
|
+
dataValue,
|
|
38
|
+
lastReferenceValue
|
|
39
|
+
} from "@openfn/language-common";
|
|
40
|
+
function execute(...operations) {
|
|
41
|
+
const initialState = {
|
|
42
|
+
references: [],
|
|
43
|
+
data: null
|
|
44
|
+
};
|
|
45
|
+
return (state) => {
|
|
46
|
+
return commonExecute(...operations)({ ...initialState, ...state });
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function submitSite(collection_id, submissionData) {
|
|
50
|
+
function assembleError({ response, error }) {
|
|
51
|
+
if ([200, 201, 202].indexOf(response.statusCode) > -1)
|
|
52
|
+
return false;
|
|
53
|
+
if (error)
|
|
54
|
+
return error;
|
|
55
|
+
return new Error(
|
|
56
|
+
`Server responded with ${response.statusCode}
|
|
57
|
+
${response.body}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return (state) => {
|
|
61
|
+
const body = expandReferences(submissionData)(state);
|
|
62
|
+
console.log(
|
|
63
|
+
"Submitting site to collection " + collection_id + ":\n" + JSON.stringify(body, null, 4) + "\n"
|
|
64
|
+
);
|
|
65
|
+
const { username, password, baseUrl } = state.configuration;
|
|
66
|
+
const url = resolveUrl(
|
|
67
|
+
baseUrl + "/",
|
|
68
|
+
"api/collections/" + collection_id + "/sites.json"
|
|
69
|
+
);
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
request.post(
|
|
72
|
+
{
|
|
73
|
+
url,
|
|
74
|
+
json: body,
|
|
75
|
+
auth: {
|
|
76
|
+
user: username,
|
|
77
|
+
pass: password,
|
|
78
|
+
sendImmediately: true
|
|
79
|
+
},
|
|
80
|
+
headers: {
|
|
81
|
+
"content-disposition": 'form-data; name=\\"site\\"'
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
function(error, response, body2) {
|
|
85
|
+
error = assembleError({ error, response });
|
|
86
|
+
if (error) {
|
|
87
|
+
reject(error);
|
|
88
|
+
} else {
|
|
89
|
+
console.log("Printing response...\n");
|
|
90
|
+
console.log(JSON.stringify(response, null, 4) + "\n");
|
|
91
|
+
console.log("Site submission succeeded.");
|
|
92
|
+
resolve(body2);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
return request.post({
|
|
98
|
+
username,
|
|
99
|
+
password,
|
|
100
|
+
body,
|
|
101
|
+
url
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/index.js
|
|
107
|
+
var src_default = Adaptor_exports;
|
|
108
|
+
export {
|
|
109
|
+
alterState,
|
|
110
|
+
dataPath,
|
|
111
|
+
dataValue,
|
|
112
|
+
src_default as default,
|
|
113
|
+
each,
|
|
114
|
+
execute,
|
|
115
|
+
field,
|
|
116
|
+
fields,
|
|
117
|
+
fn,
|
|
118
|
+
lastReferenceValue,
|
|
119
|
+
merge,
|
|
120
|
+
sourceValue,
|
|
121
|
+
submitSite
|
|
122
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-resourcemap",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Resourcemap Language Pack for OpenFn",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"author": "Open Function Group",
|
|
7
|
+
"license": "LGPLv3",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"types/",
|
|
11
|
+
"ast.json",
|
|
12
|
+
"configuration-schema.json"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@openfn/language-common": "^1.7.5",
|
|
16
|
+
"request": "^2.88.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@openfn/buildtools": "^1.0.2",
|
|
20
|
+
"@openfn/simple-ast": "0.4.1",
|
|
21
|
+
"assertion-error": "^2.0.0",
|
|
22
|
+
"chai": "^4.3.7",
|
|
23
|
+
"deep-eql": "^4.1.2",
|
|
24
|
+
"esno": "^0.16.3",
|
|
25
|
+
"mocha": "^10.1.0",
|
|
26
|
+
"rimraf": "^3.0.2",
|
|
27
|
+
"superagent-mock": "^1.12.0"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"types": "types/index.d.ts",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "pnpm clean && build-adaptor resourcemap",
|
|
44
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
45
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
46
|
+
"clean": "rimraf dist types docs",
|
|
47
|
+
"pack": "pnpm pack --pack-destination ../../dist"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a sequence of operations.
|
|
3
|
+
* Wraps `@openfn/language-common/execute`, and prepends initial state for resourcemap.
|
|
4
|
+
* @example
|
|
5
|
+
* execute(
|
|
6
|
+
* create('foo'),
|
|
7
|
+
* delete('bar')
|
|
8
|
+
* )(state)
|
|
9
|
+
* @function
|
|
10
|
+
* @param {Operations} operations - Operations to be performed.
|
|
11
|
+
* @returns {Operation}
|
|
12
|
+
*/
|
|
13
|
+
export function execute(...operations: Operations): Operation;
|
|
14
|
+
/**
|
|
15
|
+
* Create an event
|
|
16
|
+
* @example
|
|
17
|
+
* execute(
|
|
18
|
+
* event(eventData)
|
|
19
|
+
* )(state)
|
|
20
|
+
* @function
|
|
21
|
+
* @param {object} eventData - Payload data for the event
|
|
22
|
+
* @returns {Operation}
|
|
23
|
+
*/
|
|
24
|
+
export function submitSite(collection_id: any, submissionData: any): Operation;
|
|
25
|
+
export { fn, alterState, field, fields, sourceValue, merge, each, dataPath, dataValue, lastReferenceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED