@openfn/language-hubtel 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/dist/index.cjs ADDED
@@ -0,0 +1,137 @@
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
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
38
+ merge: () => import_language_common2.merge,
39
+ request: () => request2,
40
+ sendSMS: () => sendSMS,
41
+ sourceValue: () => import_language_common2.sourceValue
42
+ });
43
+ module.exports = __toCommonJS(src_exports);
44
+
45
+ // src/Adaptor.js
46
+ var Adaptor_exports = {};
47
+ __export(Adaptor_exports, {
48
+ cursor: () => import_language_common2.cursor,
49
+ dataPath: () => import_language_common2.dataPath,
50
+ dataValue: () => import_language_common2.dataValue,
51
+ dateFns: () => import_language_common2.dateFns,
52
+ each: () => import_language_common2.each,
53
+ field: () => import_language_common2.field,
54
+ fields: () => import_language_common2.fields,
55
+ fn: () => import_language_common2.fn,
56
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
57
+ merge: () => import_language_common2.merge,
58
+ request: () => request2,
59
+ sendSMS: () => sendSMS,
60
+ sourceValue: () => import_language_common2.sourceValue
61
+ });
62
+ var import_util2 = require("@openfn/language-common/util");
63
+
64
+ // src/Utils.js
65
+ var import_language_common = require("@openfn/language-common");
66
+ var import_util = require("@openfn/language-common/util");
67
+ var import_node_path = __toESM(require("path"), 1);
68
+ var prepareNextState = (state, response, callback = (s) => s) => {
69
+ const { body, ...responseWithoutBody } = response;
70
+ if (!state.references) {
71
+ state.references = [];
72
+ }
73
+ const nextState = {
74
+ ...(0, import_language_common.composeNextState)(state, response.body),
75
+ response: responseWithoutBody
76
+ };
77
+ return callback(nextState);
78
+ };
79
+ var request = (configuration = {}, method, path, options) => {
80
+ const { baseUrl, clientId, clientSecret } = configuration;
81
+ const headers = (0, import_util.makeBasicAuthHeader)(clientId, clientSecret);
82
+ const errors = {
83
+ 404: "Page not found"
84
+ };
85
+ const opts = {
86
+ parseAs: "json",
87
+ errors,
88
+ baseUrl,
89
+ ...options,
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ ...headers
93
+ }
94
+ };
95
+ const safePath = import_node_path.default.join(path);
96
+ return (0, import_util.request)(method, safePath, opts);
97
+ };
98
+
99
+ // src/Adaptor.js
100
+ var import_language_common2 = require("@openfn/language-common");
101
+ function sendSMS(data, options) {
102
+ return request2("POST", "/messages/send", data, options);
103
+ }
104
+ function request2(method, path, body, options = {}) {
105
+ return async (state) => {
106
+ const [resolvedMethod, resolvedPath, resolvedData, resolvedoptions] = (0, import_util2.expandReferences)(state, method, path, body, options);
107
+ const response = await request(
108
+ state.configuration,
109
+ resolvedMethod,
110
+ resolvedPath,
111
+ {
112
+ body: resolvedData,
113
+ ...resolvedoptions
114
+ }
115
+ );
116
+ return prepareNextState(state, response);
117
+ };
118
+ }
119
+
120
+ // src/index.js
121
+ var src_default = Adaptor_exports;
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ cursor,
125
+ dataPath,
126
+ dataValue,
127
+ dateFns,
128
+ each,
129
+ field,
130
+ fields,
131
+ fn,
132
+ lastReferenceValue,
133
+ merge,
134
+ request,
135
+ sendSMS,
136
+ sourceValue
137
+ });
package/dist/index.js ADDED
@@ -0,0 +1,115 @@
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
+ lastReferenceValue: () => lastReferenceValue,
19
+ merge: () => merge,
20
+ request: () => request2,
21
+ sendSMS: () => sendSMS,
22
+ sourceValue: () => sourceValue
23
+ });
24
+ import { expandReferences } from "@openfn/language-common/util";
25
+
26
+ // src/Utils.js
27
+ import { composeNextState } from "@openfn/language-common";
28
+ import {
29
+ request as commonRequest,
30
+ makeBasicAuthHeader,
31
+ assertRelativeUrl
32
+ } from "@openfn/language-common/util";
33
+ import nodepath from "path";
34
+ var prepareNextState = (state, response, callback = (s) => s) => {
35
+ const { body, ...responseWithoutBody } = response;
36
+ if (!state.references) {
37
+ state.references = [];
38
+ }
39
+ const nextState = {
40
+ ...composeNextState(state, response.body),
41
+ response: responseWithoutBody
42
+ };
43
+ return callback(nextState);
44
+ };
45
+ var request = (configuration = {}, method, path, options) => {
46
+ const { baseUrl, clientId, clientSecret } = configuration;
47
+ const headers = makeBasicAuthHeader(clientId, clientSecret);
48
+ const errors = {
49
+ 404: "Page not found"
50
+ };
51
+ const 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
+ return commonRequest(method, safePath, opts);
63
+ };
64
+
65
+ // src/Adaptor.js
66
+ import {
67
+ dataPath,
68
+ dataValue,
69
+ dateFns,
70
+ cursor,
71
+ each,
72
+ field,
73
+ fields,
74
+ fn,
75
+ lastReferenceValue,
76
+ merge,
77
+ sourceValue
78
+ } from "@openfn/language-common";
79
+ function sendSMS(data, options) {
80
+ return request2("POST", "/messages/send", data, options);
81
+ }
82
+ function request2(method, path, body, options = {}) {
83
+ return async (state) => {
84
+ const [resolvedMethod, resolvedPath, resolvedData, resolvedoptions] = expandReferences(state, method, path, body, options);
85
+ const response = await request(
86
+ state.configuration,
87
+ resolvedMethod,
88
+ resolvedPath,
89
+ {
90
+ body: resolvedData,
91
+ ...resolvedoptions
92
+ }
93
+ );
94
+ return prepareNextState(state, response);
95
+ };
96
+ }
97
+
98
+ // src/index.js
99
+ var src_default = Adaptor_exports;
100
+ export {
101
+ cursor,
102
+ dataPath,
103
+ dataValue,
104
+ dateFns,
105
+ src_default as default,
106
+ each,
107
+ field,
108
+ fields,
109
+ fn,
110
+ lastReferenceValue,
111
+ merge,
112
+ request2 as request,
113
+ sendSMS,
114
+ sourceValue
115
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@openfn/language-hubtel",
3
+ "version": "1.0.0",
4
+ "description": "OpenFn hubtel 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.0"
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 hubtel",
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,72 @@
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} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
15
+ * @property {object} query - An object of query parameters to be encoded into the URL.
16
+ * @property {object} headers - An object of headers to append to the request.
17
+ * @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
18
+ * @property {number} timeout - Request timeout in ms. Default: 300 seconds.
19
+ * @property {object} tls - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
20
+ */
21
+ /**
22
+ * Send an SMS
23
+ * @example
24
+ * sendSMS({
25
+ * from: 'OpenFn-Test-01',
26
+ * to: '233538675309',
27
+ * content: 'hi there, this is OpenFn using the new Hubtel adaptor',
28
+ * });
29
+ * @function
30
+ * @public
31
+ * @param {object} data - An object with `from`, `to`, and `content` attributes
32
+ * @param {RequestOptions} options - Optional hubtel options
33
+ * @returns {Operation}
34
+ * @state {HttpState}
35
+ */
36
+ export function sendSMS(data: object, options: RequestOptions): Operation;
37
+ /**
38
+ * Make a general HTTP request
39
+ * @example
40
+ * request("POST", "patient", { "name": "Bukayo" });
41
+ * @function
42
+ * @public
43
+ * @param {string} method - HTTP method to use
44
+ * @param {string} path - Path to resource
45
+ * @param {object} data - Object which will be attached to the POST body
46
+ * @param {RequestOptions} options - Optional request options
47
+ * @returns {Operation}
48
+ * @state {HttpState}
49
+ */
50
+ export function request(method: string, path: string, body: any, options?: RequestOptions): Operation;
51
+ /**
52
+ * State object
53
+ */
54
+ export type HttpState = {
55
+ /**
56
+ * - the parsed response body
57
+ */
58
+ data: any;
59
+ /**
60
+ * - the response from the HTTP server, including headers, statusCode, body, etc
61
+ */
62
+ response: any;
63
+ /**
64
+ * - an array of all previous data objects used in the Job
65
+ */
66
+ references: any;
67
+ };
68
+ /**
69
+ * Options provided to the HTTP request
70
+ */
71
+ export type RequestOptions = any;
72
+ export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
@@ -0,0 +1,2 @@
1
+ export function prepareNextState(state: any, response: any, callback?: (s: any) => any): any;
2
+ export function request(configuration: {}, method: any, path: any, options: any): any;
@@ -0,0 +1,3 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ import * as Adaptor from "./Adaptor";