@openfn/language-kobotoolbox 1.0.4 → 1.1.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 +7 -6
- package/configuration-schema.json +45 -0
- package/dist/index.cjs +105 -0
- package/dist/index.js +101 -0
- package/package.json +25 -19
- package/types/Adaptor.d.ts +41 -0
- package/types/index.d.ts +3 -0
- package/lib/Adaptor.js +0 -190
- package/lib/index.js +0 -19
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Language Pack for building expressions and operations to interact with the
|
|
|
21
21
|
#### Get the list of forms
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
getForms(state => {
|
|
24
|
+
getForms({}, state => {
|
|
25
25
|
console.log(state.data);
|
|
26
26
|
return state;
|
|
27
27
|
});
|
|
@@ -33,8 +33,7 @@ A query can be used to filter results.
|
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
35
|
getSubmissions(
|
|
36
|
-
'aXecHjmbATuF6iGFmvBLBX',
|
|
37
|
-
{ query: { end: { $gte: '2020-11-20' } } },
|
|
36
|
+
{ formId: 'aXecHjmbATuF6iGFmvBLBX', query: { end: { $gte: '2020-11-20' } } },
|
|
38
37
|
state => {
|
|
39
38
|
console.log(state.data);
|
|
40
39
|
return state;
|
|
@@ -44,8 +43,10 @@ getSubmissions(
|
|
|
44
43
|
|
|
45
44
|
## Development
|
|
46
45
|
|
|
47
|
-
Clone the
|
|
46
|
+
Clone the [adaptors monorepo](https://github.com/OpenFn/adaptors). Follow the `Getting Started` guide inside to get set up.
|
|
48
47
|
|
|
49
|
-
Run tests using `
|
|
48
|
+
Run tests using `pnpm run test` or `pnpm run test:watch`
|
|
50
49
|
|
|
51
|
-
Build the project using `
|
|
50
|
+
Build the project using `pnpm build`.
|
|
51
|
+
|
|
52
|
+
To just build the docs run `pnpm build docs`
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"properties": {
|
|
4
|
+
"baseURL": {
|
|
5
|
+
"title": "Base URL",
|
|
6
|
+
"type": "string",
|
|
7
|
+
"default": "https://kf.kobotoolbox.org",
|
|
8
|
+
"description": "Kobotoolbox URL",
|
|
9
|
+
"format": "uri",
|
|
10
|
+
"minLength": 1
|
|
11
|
+
},
|
|
12
|
+
"username": {
|
|
13
|
+
"title": "Username",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Kobotoolbox username",
|
|
16
|
+
"minLength": 1
|
|
17
|
+
},
|
|
18
|
+
"password": {
|
|
19
|
+
"title": "Password",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Kobotoolbox password",
|
|
22
|
+
"writeOnly": true,
|
|
23
|
+
"minLength": 1
|
|
24
|
+
},
|
|
25
|
+
"apiVersion": {
|
|
26
|
+
"title": "API Version",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"default": "v2",
|
|
29
|
+
"description": "Kobotoolbox API version to use",
|
|
30
|
+
"enum": [
|
|
31
|
+
"v1",
|
|
32
|
+
"v2"
|
|
33
|
+
],
|
|
34
|
+
"minLength": 1
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"type": "object",
|
|
38
|
+
"additionalProperties": true,
|
|
39
|
+
"required": [
|
|
40
|
+
"username",
|
|
41
|
+
"baseURL",
|
|
42
|
+
"password",
|
|
43
|
+
"apiVersion"
|
|
44
|
+
]
|
|
45
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.js
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
Adaptor: () => Adaptor_exports,
|
|
23
|
+
default: () => src_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/Adaptor.js
|
|
28
|
+
var Adaptor_exports = {};
|
|
29
|
+
__export(Adaptor_exports, {
|
|
30
|
+
alterState: () => import_language_common2.alterState,
|
|
31
|
+
dataPath: () => import_language_common2.dataPath,
|
|
32
|
+
dataValue: () => import_language_common2.dataValue,
|
|
33
|
+
each: () => import_language_common2.each,
|
|
34
|
+
execute: () => execute,
|
|
35
|
+
field: () => import_language_common2.field,
|
|
36
|
+
fields: () => import_language_common2.fields,
|
|
37
|
+
getForms: () => getForms,
|
|
38
|
+
getSubmissions: () => getSubmissions,
|
|
39
|
+
http: () => import_language_common2.http,
|
|
40
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
41
|
+
merge: () => import_language_common2.merge,
|
|
42
|
+
sourceValue: () => import_language_common2.sourceValue
|
|
43
|
+
});
|
|
44
|
+
var import_language_common = require("@openfn/language-common");
|
|
45
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
46
|
+
function execute(...operations) {
|
|
47
|
+
const initialState = {
|
|
48
|
+
references: [],
|
|
49
|
+
data: null
|
|
50
|
+
};
|
|
51
|
+
return (state) => {
|
|
52
|
+
return (0, import_language_common.execute)(...operations)({
|
|
53
|
+
...initialState,
|
|
54
|
+
...state
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getForms(params, callback) {
|
|
59
|
+
return (state) => {
|
|
60
|
+
params = (0, import_language_common.expandReferences)(params)(state);
|
|
61
|
+
const { baseURL, apiVersion, username, password } = state.configuration;
|
|
62
|
+
const url = `${baseURL}/api/${apiVersion}/assets/?format=json`;
|
|
63
|
+
const auth = { username, password };
|
|
64
|
+
const config = {
|
|
65
|
+
url,
|
|
66
|
+
params,
|
|
67
|
+
auth
|
|
68
|
+
};
|
|
69
|
+
return import_language_common.http.get(config)(state).then((response) => {
|
|
70
|
+
console.log("\u2713", response.data.count, "forms fetched.");
|
|
71
|
+
const nextState = (0, import_language_common.composeNextState)(state, response.data);
|
|
72
|
+
if (callback)
|
|
73
|
+
return callback(nextState);
|
|
74
|
+
return nextState;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getSubmissions(params, callback) {
|
|
79
|
+
return (state) => {
|
|
80
|
+
params = (0, import_language_common.expandReferences)(params)(state);
|
|
81
|
+
const { baseURL, apiVersion, username, password } = state.configuration;
|
|
82
|
+
const { formId } = params;
|
|
83
|
+
const url = `${baseURL}/api/${apiVersion}/assets/${formId}/data/?format=json`;
|
|
84
|
+
const auth = { username, password };
|
|
85
|
+
const config = {
|
|
86
|
+
url,
|
|
87
|
+
params: params.query,
|
|
88
|
+
auth
|
|
89
|
+
};
|
|
90
|
+
return import_language_common.http.get(config)(state).then((response) => {
|
|
91
|
+
console.log("\u2713", response.data.count, "submissions fetched.");
|
|
92
|
+
const nextState = (0, import_language_common.composeNextState)(state, response.data);
|
|
93
|
+
if (callback)
|
|
94
|
+
return callback(nextState);
|
|
95
|
+
return nextState;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/index.js
|
|
101
|
+
var src_default = Adaptor_exports;
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
Adaptor
|
|
105
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
getForms: () => getForms,
|
|
18
|
+
getSubmissions: () => getSubmissions,
|
|
19
|
+
http: () => http2,
|
|
20
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
21
|
+
merge: () => merge,
|
|
22
|
+
sourceValue: () => sourceValue
|
|
23
|
+
});
|
|
24
|
+
import {
|
|
25
|
+
execute as commonExecute,
|
|
26
|
+
composeNextState,
|
|
27
|
+
expandReferences,
|
|
28
|
+
http
|
|
29
|
+
} from "@openfn/language-common";
|
|
30
|
+
import {
|
|
31
|
+
alterState,
|
|
32
|
+
dataPath,
|
|
33
|
+
dataValue,
|
|
34
|
+
each,
|
|
35
|
+
field,
|
|
36
|
+
fields,
|
|
37
|
+
http as http2,
|
|
38
|
+
lastReferenceValue,
|
|
39
|
+
merge,
|
|
40
|
+
sourceValue
|
|
41
|
+
} from "@openfn/language-common";
|
|
42
|
+
function execute(...operations) {
|
|
43
|
+
const initialState = {
|
|
44
|
+
references: [],
|
|
45
|
+
data: null
|
|
46
|
+
};
|
|
47
|
+
return (state) => {
|
|
48
|
+
return commonExecute(...operations)({
|
|
49
|
+
...initialState,
|
|
50
|
+
...state
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function getForms(params, callback) {
|
|
55
|
+
return (state) => {
|
|
56
|
+
params = expandReferences(params)(state);
|
|
57
|
+
const { baseURL, apiVersion, username, password } = state.configuration;
|
|
58
|
+
const url = `${baseURL}/api/${apiVersion}/assets/?format=json`;
|
|
59
|
+
const auth = { username, password };
|
|
60
|
+
const config = {
|
|
61
|
+
url,
|
|
62
|
+
params,
|
|
63
|
+
auth
|
|
64
|
+
};
|
|
65
|
+
return http.get(config)(state).then((response) => {
|
|
66
|
+
console.log("\u2713", response.data.count, "forms fetched.");
|
|
67
|
+
const nextState = composeNextState(state, response.data);
|
|
68
|
+
if (callback)
|
|
69
|
+
return callback(nextState);
|
|
70
|
+
return nextState;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function getSubmissions(params, callback) {
|
|
75
|
+
return (state) => {
|
|
76
|
+
params = expandReferences(params)(state);
|
|
77
|
+
const { baseURL, apiVersion, username, password } = state.configuration;
|
|
78
|
+
const { formId } = params;
|
|
79
|
+
const url = `${baseURL}/api/${apiVersion}/assets/${formId}/data/?format=json`;
|
|
80
|
+
const auth = { username, password };
|
|
81
|
+
const config = {
|
|
82
|
+
url,
|
|
83
|
+
params: params.query,
|
|
84
|
+
auth
|
|
85
|
+
};
|
|
86
|
+
return http.get(config)(state).then((response) => {
|
|
87
|
+
console.log("\u2713", response.data.count, "submissions fetched.");
|
|
88
|
+
const nextState = composeNextState(state, response.data);
|
|
89
|
+
if (callback)
|
|
90
|
+
return callback(nextState);
|
|
91
|
+
return nextState;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/index.js
|
|
97
|
+
var src_default = Adaptor_exports;
|
|
98
|
+
export {
|
|
99
|
+
Adaptor_exports as Adaptor,
|
|
100
|
+
src_default as default
|
|
101
|
+
};
|
package/package.json
CHANGED
|
@@ -1,39 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-kobotoolbox",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A Kobo Toolbox Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/openfn/
|
|
9
|
-
},
|
|
10
|
-
"main": "lib/index.js",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "make",
|
|
13
|
-
"test": "mocha --require @babel/register",
|
|
14
|
-
"test:watch": "mocha -w --require @babel/register"
|
|
8
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
15
9
|
},
|
|
10
|
+
"main": "dist/index.cjs",
|
|
16
11
|
"author": "Open Function Group",
|
|
17
12
|
"license": "LGPLv3",
|
|
18
13
|
"files": [
|
|
19
|
-
"
|
|
14
|
+
"dist/",
|
|
15
|
+
"types/",
|
|
16
|
+
"ast.json",
|
|
17
|
+
"configuration-schema.json"
|
|
20
18
|
],
|
|
21
19
|
"dependencies": {
|
|
22
|
-
"@openfn/language-common": "1.
|
|
20
|
+
"@openfn/language-common": "1.7.4"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@babel/core": "^7.9.0",
|
|
27
|
-
"@babel/plugin-proposal-function-bind": "^7.8.3",
|
|
28
|
-
"@babel/preset-env": "^7.9.5",
|
|
29
|
-
"@babel/preset-stage-0": "^7.8.3",
|
|
30
|
-
"@babel/register": "^7.9.0",
|
|
23
|
+
"@openfn/buildtools": "^1.0.2",
|
|
31
24
|
"assertion-error": "^1.0.1",
|
|
32
25
|
"chai": "^3.4.0",
|
|
33
26
|
"deep-eql": "^0.1.3",
|
|
34
|
-
"
|
|
27
|
+
"esno": "^0.16.3",
|
|
35
28
|
"mocha": "^7.1.1",
|
|
36
29
|
"nock": "^12.0.3",
|
|
37
|
-
"
|
|
30
|
+
"rimraf": "^3.0.2"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"types": "types/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"require": "./dist/index.cjs"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "pnpm clean && build-adaptor kobotoolbox",
|
|
40
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
41
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
42
|
+
"clean": "rimraf dist types docs",
|
|
43
|
+
"pack": "pnpm pack --pack-destination ../../dist"
|
|
38
44
|
}
|
|
39
|
-
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a sequence of operations.
|
|
3
|
+
* Wraps `language-common/execute`, and prepends initial state for http.
|
|
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
|
+
* Make a request to get the list of forms
|
|
16
|
+
* @public
|
|
17
|
+
* @example
|
|
18
|
+
* getForms({}, state => {
|
|
19
|
+
* console.log(state.data);
|
|
20
|
+
* return state;
|
|
21
|
+
* });
|
|
22
|
+
* @function
|
|
23
|
+
* @param {object} params - Query, Headers and Authentication parameters
|
|
24
|
+
* @param {function} callback - (Optional) Callback function to execute after fetching form list
|
|
25
|
+
* @returns {Operation}
|
|
26
|
+
*/
|
|
27
|
+
export function getForms(params: object, callback: Function): Operation;
|
|
28
|
+
/**
|
|
29
|
+
* Get submissions for a specific form
|
|
30
|
+
* @example
|
|
31
|
+
* getSubmissions({formId: 'aXecHjmbATuF6iGFmvBLBX'}, state => {
|
|
32
|
+
* console.log(state.data);
|
|
33
|
+
* return state;
|
|
34
|
+
* });
|
|
35
|
+
* @function
|
|
36
|
+
* @param {object} params - Form Id and data to make the fetch or filter
|
|
37
|
+
* @param {function} callback - (Optional) Callback function to execute after fetching form submissions
|
|
38
|
+
* @returns {Operation}
|
|
39
|
+
*/
|
|
40
|
+
export function getSubmissions(params: object, callback: Function): Operation;
|
|
41
|
+
export { alterState, dataPath, dataValue, each, field, fields, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED
package/lib/Adaptor.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.execute = execute;
|
|
7
|
-
exports.getForms = getForms;
|
|
8
|
-
exports.getSubmissions = getSubmissions;
|
|
9
|
-
Object.defineProperty(exports, "alterState", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function get() {
|
|
12
|
-
return _languageCommon.alterState;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "dataPath", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function get() {
|
|
18
|
-
return _languageCommon.dataPath;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "dataValue", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _languageCommon.dataValue;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "each", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function get() {
|
|
30
|
-
return _languageCommon.each;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "field", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function get() {
|
|
36
|
-
return _languageCommon.field;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(exports, "fields", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function get() {
|
|
42
|
-
return _languageCommon.fields;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(exports, "http", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function get() {
|
|
48
|
-
return _languageCommon.http;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, "lastReferenceValue", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function get() {
|
|
54
|
-
return _languageCommon.lastReferenceValue;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(exports, "merge", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
get: function get() {
|
|
60
|
-
return _languageCommon.merge;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(exports, "sourceValue", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
get: function get() {
|
|
66
|
-
return _languageCommon.sourceValue;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
var _languageCommon = require("@openfn/language-common");
|
|
71
|
-
|
|
72
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
73
|
-
|
|
74
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
75
|
-
|
|
76
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Execute a sequence of operations.
|
|
80
|
-
* Wraps `language-common/execute`, and prepends initial state for http.
|
|
81
|
-
* @example
|
|
82
|
-
* execute(
|
|
83
|
-
* create('foo'),
|
|
84
|
-
* delete('bar')
|
|
85
|
-
* )(state)
|
|
86
|
-
* @function
|
|
87
|
-
* @param {Operations} operations - Operations to be performed.
|
|
88
|
-
* @returns {Operation}
|
|
89
|
-
*/
|
|
90
|
-
function execute() {
|
|
91
|
-
for (var _len = arguments.length, operations = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
92
|
-
operations[_key] = arguments[_key];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
var initialState = {
|
|
96
|
-
references: [],
|
|
97
|
-
data: null
|
|
98
|
-
};
|
|
99
|
-
return function (state) {
|
|
100
|
-
return _languageCommon.execute.apply(void 0, operations)(_objectSpread(_objectSpread({}, initialState), state));
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Make a request to get the list of forms
|
|
105
|
-
* @public
|
|
106
|
-
* @example
|
|
107
|
-
* getForms(state => {
|
|
108
|
-
* console.log(state.data);
|
|
109
|
-
* return state;
|
|
110
|
-
* });
|
|
111
|
-
* @function
|
|
112
|
-
* @param {function} callback - callback to execute after fetching form list
|
|
113
|
-
* @returns {Operation}
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
function getForms(callback) {
|
|
118
|
-
return function (state) {
|
|
119
|
-
var _state$configuration = state.configuration,
|
|
120
|
-
baseURL = _state$configuration.baseURL,
|
|
121
|
-
apiVersion = _state$configuration.apiVersion,
|
|
122
|
-
username = _state$configuration.username,
|
|
123
|
-
password = _state$configuration.password;
|
|
124
|
-
return _languageCommon.http.get({
|
|
125
|
-
baseURL: baseURL,
|
|
126
|
-
url: "api/".concat(apiVersion, "/assets/?format=json"),
|
|
127
|
-
auth: {
|
|
128
|
-
username: username,
|
|
129
|
-
password: password
|
|
130
|
-
}
|
|
131
|
-
})(state).then(function (response) {
|
|
132
|
-
console.log('✓', response.data.count, 'forms fetched.');
|
|
133
|
-
var nextState = (0, _languageCommon.composeNextState)(state, response.data);
|
|
134
|
-
if (callback) return callback(nextState);
|
|
135
|
-
return nextState;
|
|
136
|
-
})["catch"](function (error) {
|
|
137
|
-
console.log(error);
|
|
138
|
-
return error;
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get submissions for a specific form
|
|
144
|
-
* @example
|
|
145
|
-
* getSubmissions('aXecHjmbATuF6iGFmvBLBX', {}, state => {
|
|
146
|
-
* console.log(state.data);
|
|
147
|
-
* return state;
|
|
148
|
-
* });
|
|
149
|
-
* @function
|
|
150
|
-
* @param {string} formId - id of the form
|
|
151
|
-
* @param {object} params - data to make the fetch or filter
|
|
152
|
-
* @param {function} callback - callback to execute after fetching form submissions.
|
|
153
|
-
* @returns {Operation}
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
function getSubmissions(formId, params, callback) {
|
|
158
|
-
return function (state) {
|
|
159
|
-
var _state$configuration2 = state.configuration,
|
|
160
|
-
baseURL = _state$configuration2.baseURL,
|
|
161
|
-
apiVersion = _state$configuration2.apiVersion,
|
|
162
|
-
username = _state$configuration2.username,
|
|
163
|
-
password = _state$configuration2.password;
|
|
164
|
-
|
|
165
|
-
var _expandReferences = (0, _languageCommon.expandReferences)(params)(state),
|
|
166
|
-
body = _expandReferences.body,
|
|
167
|
-
headers = _expandReferences.headers,
|
|
168
|
-
query = _expandReferences.query;
|
|
169
|
-
|
|
170
|
-
return _languageCommon.http.get({
|
|
171
|
-
baseURL: baseURL,
|
|
172
|
-
url: "api/".concat(apiVersion, "/assets/").concat(formId, "/data/?format=json"),
|
|
173
|
-
auth: {
|
|
174
|
-
username: username,
|
|
175
|
-
password: password
|
|
176
|
-
},
|
|
177
|
-
params: {
|
|
178
|
-
query: JSON.stringify(query)
|
|
179
|
-
}
|
|
180
|
-
})(state).then(function (response) {
|
|
181
|
-
console.log('✓', response.data.count, 'submissions fetched.');
|
|
182
|
-
var nextState = (0, _languageCommon.composeNextState)(state, response.data);
|
|
183
|
-
if (callback) return callback(nextState);
|
|
184
|
-
return nextState;
|
|
185
|
-
})["catch"](function (error) {
|
|
186
|
-
console.log(error);
|
|
187
|
-
return error;
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.Adaptor = exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var Adaptor = _interopRequireWildcard(require("./Adaptor"));
|
|
11
|
-
|
|
12
|
-
exports.Adaptor = Adaptor;
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
var _default = Adaptor;
|
|
19
|
-
exports["default"] = _default;
|