@openfn/language-openboxes 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.
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "baseUrl": {
5
+ "title": "Base URL",
6
+ "description": "The base URL (http://www.example.com)",
7
+ "format": "uri",
8
+ "minLength": 1,
9
+ "examples": ["https://demo.openboxes.com/openboxes/api"]
10
+ },
11
+ "username": {
12
+ "title": "Username",
13
+ "type": "string",
14
+ "description": "Username",
15
+ "examples": ["test@openfn.org"]
16
+ },
17
+ "password": {
18
+ "title": "Password",
19
+ "type": "string",
20
+ "description": "Password",
21
+ "writeOnly": true,
22
+ "examples": ["@some(!)Str0ngp4ss0w0rd"]
23
+ }
24
+ },
25
+ "type": "object",
26
+ "additionalProperties": true,
27
+ "required": ["password", "username", "baseUrl"]
28
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,153 @@
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
+ cursor: () => import_language_common2.cursor,
29
+ dataPath: () => import_language_common2.dataPath,
30
+ dataValue: () => import_language_common2.dataValue,
31
+ dateFns: () => import_language_common2.dateFns,
32
+ default: () => src_default,
33
+ each: () => import_language_common2.each,
34
+ field: () => import_language_common2.field,
35
+ fields: () => import_language_common2.fields,
36
+ fn: () => import_language_common2.fn,
37
+ get: () => get,
38
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
39
+ merge: () => import_language_common2.merge,
40
+ post: () => post,
41
+ request: () => request2,
42
+ sourceValue: () => import_language_common2.sourceValue
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+
46
+ // src/Adaptor.js
47
+ var Adaptor_exports = {};
48
+ __export(Adaptor_exports, {
49
+ cursor: () => import_language_common2.cursor,
50
+ dataPath: () => import_language_common2.dataPath,
51
+ dataValue: () => import_language_common2.dataValue,
52
+ dateFns: () => import_language_common2.dateFns,
53
+ each: () => import_language_common2.each,
54
+ field: () => import_language_common2.field,
55
+ fields: () => import_language_common2.fields,
56
+ fn: () => import_language_common2.fn,
57
+ get: () => get,
58
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
59
+ merge: () => import_language_common2.merge,
60
+ post: () => post,
61
+ request: () => request2,
62
+ sourceValue: () => import_language_common2.sourceValue
63
+ });
64
+ var import_util2 = require("@openfn/language-common/util");
65
+
66
+ // src/Utils.js
67
+ var import_language_common = require("@openfn/language-common");
68
+ var import_util = require("@openfn/language-common/util");
69
+ var import_node_path = __toESM(require("path"), 1);
70
+ var cookie;
71
+ var prepareNextState = (state, response) => {
72
+ const { body, ...responseWithoutBody } = response;
73
+ if (!state.references) {
74
+ state.references = [];
75
+ }
76
+ return {
77
+ ...(0, import_language_common.composeNextState)(state, response.body),
78
+ response: responseWithoutBody
79
+ };
80
+ };
81
+ var authenticate = async (opts) => {
82
+ const response = await (0, import_util.request)("POST", "/login", opts);
83
+ return response.headers["set-cookie"].split(";")[0];
84
+ };
85
+ var request = async (state, method, path, options = {}) => {
86
+ var _a;
87
+ const { baseUrl, username, password } = state.configuration;
88
+ let headers = { "Cookie": cookie || ((_a = options.headers) == null ? void 0 : _a.Cookie) };
89
+ const errors = { 404: "Page not found" };
90
+ let opts = {
91
+ parseAs: "json",
92
+ errors,
93
+ baseUrl,
94
+ ...options,
95
+ headers: {
96
+ "content-type": "application/json",
97
+ ...headers
98
+ }
99
+ };
100
+ const safePath = import_node_path.default.join(path);
101
+ if (!opts.headers.Cookie && username && password) {
102
+ cookie = await authenticate({ ...opts, parseAs: "text/html", body: { username, password } });
103
+ opts = { ...opts, headers: { ...opts.headers, Cookie: cookie } };
104
+ }
105
+ return (0, import_util.request)(method, safePath, opts);
106
+ };
107
+
108
+ // src/Adaptor.js
109
+ var import_language_common2 = require("@openfn/language-common");
110
+ function get(path, options) {
111
+ return async (state) => {
112
+ const response = await request(state, "GET", path, options);
113
+ return prepareNextState(state, response);
114
+ };
115
+ }
116
+ function post(path, body, options) {
117
+ return async (state) => {
118
+ const response = await request(state, "POST", path, { ...options, body });
119
+ return prepareNextState(state, response);
120
+ };
121
+ }
122
+ function request2(method, path, options = {}) {
123
+ return async (state) => {
124
+ const [resolvedMethod, resolvedPath, resolvedoptions] = (0, import_util2.expandReferences)(state, method, path, options);
125
+ const response = await request(
126
+ state,
127
+ resolvedMethod,
128
+ resolvedPath,
129
+ resolvedoptions
130
+ );
131
+ return prepareNextState(state, response);
132
+ };
133
+ }
134
+
135
+ // src/index.js
136
+ var src_default = Adaptor_exports;
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ cursor,
140
+ dataPath,
141
+ dataValue,
142
+ dateFns,
143
+ each,
144
+ field,
145
+ fields,
146
+ fn,
147
+ get,
148
+ lastReferenceValue,
149
+ merge,
150
+ post,
151
+ request,
152
+ sourceValue
153
+ });
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
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
+ cursor: () => cursor,
11
+ dataPath: () => dataPath,
12
+ dataValue: () => dataValue,
13
+ dateFns: () => dateFns,
14
+ each: () => each,
15
+ field: () => field,
16
+ fields: () => fields,
17
+ fn: () => fn,
18
+ get: () => get,
19
+ lastReferenceValue: () => lastReferenceValue,
20
+ merge: () => merge,
21
+ post: () => post,
22
+ request: () => request2,
23
+ sourceValue: () => sourceValue
24
+ });
25
+ import { expandReferences } from "@openfn/language-common/util";
26
+
27
+ // src/Utils.js
28
+ import { composeNextState } from "@openfn/language-common";
29
+ import { request as commonRequest } from "@openfn/language-common/util";
30
+ import nodepath from "path";
31
+ var cookie;
32
+ var prepareNextState = (state, response) => {
33
+ const { body, ...responseWithoutBody } = response;
34
+ if (!state.references) {
35
+ state.references = [];
36
+ }
37
+ return {
38
+ ...composeNextState(state, response.body),
39
+ response: responseWithoutBody
40
+ };
41
+ };
42
+ var authenticate = async (opts) => {
43
+ const response = await commonRequest("POST", "/login", opts);
44
+ return response.headers["set-cookie"].split(";")[0];
45
+ };
46
+ var request = async (state, method, path, options = {}) => {
47
+ var _a;
48
+ const { baseUrl, username, password } = state.configuration;
49
+ let headers = { "Cookie": cookie || ((_a = options.headers) == null ? void 0 : _a.Cookie) };
50
+ const errors = { 404: "Page not found" };
51
+ let opts = {
52
+ parseAs: "json",
53
+ errors,
54
+ baseUrl,
55
+ ...options,
56
+ headers: {
57
+ "content-type": "application/json",
58
+ ...headers
59
+ }
60
+ };
61
+ const safePath = nodepath.join(path);
62
+ if (!opts.headers.Cookie && username && password) {
63
+ cookie = await authenticate({ ...opts, parseAs: "text/html", body: { username, password } });
64
+ opts = { ...opts, headers: { ...opts.headers, Cookie: cookie } };
65
+ }
66
+ return commonRequest(method, safePath, opts);
67
+ };
68
+
69
+ // src/Adaptor.js
70
+ import {
71
+ dataPath,
72
+ dataValue,
73
+ dateFns,
74
+ cursor,
75
+ each,
76
+ field,
77
+ fields,
78
+ fn,
79
+ lastReferenceValue,
80
+ merge,
81
+ sourceValue
82
+ } from "@openfn/language-common";
83
+ function get(path, options) {
84
+ return async (state) => {
85
+ const response = await request(state, "GET", path, options);
86
+ return prepareNextState(state, response);
87
+ };
88
+ }
89
+ function post(path, body, options) {
90
+ return async (state) => {
91
+ const response = await request(state, "POST", path, { ...options, body });
92
+ return prepareNextState(state, response);
93
+ };
94
+ }
95
+ function request2(method, path, options = {}) {
96
+ return async (state) => {
97
+ const [resolvedMethod, resolvedPath, resolvedoptions] = expandReferences(state, method, path, options);
98
+ const response = await request(
99
+ state,
100
+ resolvedMethod,
101
+ resolvedPath,
102
+ resolvedoptions
103
+ );
104
+ return prepareNextState(state, response);
105
+ };
106
+ }
107
+
108
+ // src/index.js
109
+ var src_default = Adaptor_exports;
110
+ export {
111
+ cursor,
112
+ dataPath,
113
+ dataValue,
114
+ dateFns,
115
+ src_default as default,
116
+ each,
117
+ field,
118
+ fields,
119
+ fn,
120
+ get,
121
+ lastReferenceValue,
122
+ merge,
123
+ post,
124
+ request2 as request,
125
+ sourceValue
126
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@openfn/language-openboxes",
3
+ "version": "1.0.0",
4
+ "description": "OpenFn openboxes adaptor",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./types/index.d.ts",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "author": "Open Function Group",
15
+ "license": "LGPLv3",
16
+ "files": [
17
+ "dist/",
18
+ "types/",
19
+ "ast.json",
20
+ "configuration-schema.json"
21
+ ],
22
+ "dependencies": {
23
+ "@openfn/language-common": "2.3.1"
24
+ },
25
+ "devDependencies": {
26
+ "assertion-error": "2.0.0",
27
+ "chai": "4.3.6",
28
+ "deep-eql": "4.1.1",
29
+ "esno": "^0.16.3",
30
+ "mocha": "^10.7.3",
31
+ "rimraf": "3.0.2",
32
+ "undici": "^5.22.1"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/openfn/adaptors.git"
37
+ },
38
+ "types": "types/index.d.ts",
39
+ "main": "dist/index.cjs",
40
+ "scripts": {
41
+ "build": "pnpm clean && build-adaptor openboxes",
42
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings",
43
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
44
+ "clean": "rimraf dist types docs",
45
+ "pack": "pnpm pack --pack-destination ../../dist",
46
+ "lint": "eslint src"
47
+ }
48
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * State object
3
+ * @typedef {Object} HttpState
4
+ * @property data - the parsed response body
5
+ * @property response - the response from the HTTP server, including headers, statusCode, body, etc
6
+ * @property references - an array of all previous data objects used in the Job
7
+ **/
8
+ /**
9
+ * Options provided to the HTTP request
10
+ * @typedef {Object} RequestOptions
11
+ * @public
12
+ * @property {object|string} body - body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
13
+ * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
14
+ * @property {object} query - An object of query parameters to be encoded into the URL.
15
+ * @property {object} headers - An object of headers to append to the request.
16
+ */
17
+ /**
18
+ * Make a GET request
19
+ * @example <caption>Get products</caption>
20
+ * get("products", { query: { max: 10 }});
21
+ * @function
22
+ * @public
23
+ * @param {string} path - Path to resource
24
+ * @param {RequestOptions} options - Optional request options
25
+ * @returns {Operation}
26
+ * @state {HttpState}
27
+ */
28
+ export function get(path: string, options: RequestOptions): Operation;
29
+ /**
30
+ * Make a POST request
31
+ * @example
32
+ post("products",
33
+ {
34
+ "id": "ff80818163e2de8d0163eba1b1e90002",
35
+ "productCode": null,
36
+ "name": "New product",
37
+ "category": {
38
+ "id": "ff80818163e2de8d0163eb93c5a00001",
39
+ "name": "New category"
40
+ },
41
+ "description": null,
42
+ "dateCreated": "2018-06-10T21:37:12Z",
43
+ "lastUpdated": "2018-06-10T21:37:12Z"
44
+ });
45
+ * @function
46
+ * @public
47
+ * @param {string} path - Path to resource
48
+ * @param {object} body - Object which will be attached to the POST body
49
+ * @param {RequestOptions} options - Optional request options
50
+ * @returns {Operation}
51
+ * @state {HttpState}
52
+ */
53
+ export function post(path: string, body: object, options: RequestOptions): Operation;
54
+ /**
55
+ * Make a general HTTP request
56
+ * @example <caption>Update stock movement</caption>
57
+ * request("POST", "/stockMovements/ff808181642fc9c101642fcccc420004",
58
+ * {
59
+ body: {
60
+ "name": "new stock movement",
61
+ "description": "new stock movement",
62
+ "origin.id": "1",
63
+ "destination.id": "2",
64
+ "requestedBy.id": "1",
65
+ "dateRequested": "06/23/2018"
66
+ }
67
+ });
68
+ @example <caption>Update a product</caption>
69
+ * request('POST', '/products/ff808181812576850182aee36930040b', { body: { name: 'Coffee', description: 'Arabica coffee from the highlands of Ethiopia' } });
70
+ * @function
71
+ * @public
72
+ * @param {string} method - HTTP method to use
73
+ * @param {string} path - Path to resource
74
+ * @param {RequestOptions} options - Optional request options
75
+ * @returns {Operation}
76
+ * @state {HttpState}
77
+ */
78
+ export function request(method: string, path: string, options?: RequestOptions): Operation;
79
+ /**
80
+ * State object
81
+ */
82
+ export type HttpState = {
83
+ /**
84
+ * - the parsed response body
85
+ */
86
+ data: any;
87
+ /**
88
+ * - the response from the HTTP server, including headers, statusCode, body, etc
89
+ */
90
+ response: any;
91
+ /**
92
+ * - an array of all previous data objects used in the Job
93
+ */
94
+ references: any;
95
+ };
96
+ /**
97
+ * Options provided to the HTTP request
98
+ */
99
+ export type RequestOptions = any;
100
+ export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
@@ -0,0 +1,3 @@
1
+ export function prepareNextState(state: any, response: any): any;
2
+ export function authenticate(opts: any): Promise<any>;
3
+ export function request(state: any, method: any, path: any, options?: {}): Promise<any>;
@@ -0,0 +1,3 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ import * as Adaptor from "./Adaptor";