@openfn/language-msgraph 0.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/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +26 -0
- package/ast.json +550 -0
- package/configuration-schema.json +38 -0
- package/dist/index.cjs +185 -0
- package/dist/index.js +166 -0
- package/package.json +49 -0
- package/types/Adaptor.d.ts +39 -0
- package/types/Utils.d.ts +9 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
create: () => create,
|
|
23
|
+
dataPath: () => import_language_common3.dataPath,
|
|
24
|
+
dataValue: () => import_language_common3.dataValue,
|
|
25
|
+
dateFns: () => import_language_common3.dateFns,
|
|
26
|
+
default: () => src_default,
|
|
27
|
+
each: () => import_language_common3.each,
|
|
28
|
+
execute: () => execute,
|
|
29
|
+
field: () => import_language_common3.field,
|
|
30
|
+
fields: () => import_language_common3.fields,
|
|
31
|
+
fn: () => import_language_common3.fn,
|
|
32
|
+
get: () => get,
|
|
33
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
34
|
+
merge: () => import_language_common3.merge,
|
|
35
|
+
request: () => request,
|
|
36
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
|
|
40
|
+
// src/Adaptor.js
|
|
41
|
+
var Adaptor_exports = {};
|
|
42
|
+
__export(Adaptor_exports, {
|
|
43
|
+
create: () => create,
|
|
44
|
+
dataPath: () => import_language_common3.dataPath,
|
|
45
|
+
dataValue: () => import_language_common3.dataValue,
|
|
46
|
+
dateFns: () => import_language_common3.dateFns,
|
|
47
|
+
each: () => import_language_common3.each,
|
|
48
|
+
execute: () => execute,
|
|
49
|
+
field: () => import_language_common3.field,
|
|
50
|
+
fields: () => import_language_common3.fields,
|
|
51
|
+
fn: () => import_language_common3.fn,
|
|
52
|
+
get: () => get,
|
|
53
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
54
|
+
merge: () => import_language_common3.merge,
|
|
55
|
+
request: () => request,
|
|
56
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
57
|
+
});
|
|
58
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
59
|
+
|
|
60
|
+
// src/Utils.js
|
|
61
|
+
var import_language_common = require("@openfn/language-common");
|
|
62
|
+
function setUrl(urlParams) {
|
|
63
|
+
const { apiVersion, resolvePath } = urlParams;
|
|
64
|
+
if (isValidHttpUrl(resolvePath))
|
|
65
|
+
return resolvePath;
|
|
66
|
+
const pathSuffix = apiVersion ? `${apiVersion}/${resolvePath}` : `v1.0/${resolvePath}`;
|
|
67
|
+
return `https://graph.microsoft.com/${pathSuffix}`;
|
|
68
|
+
}
|
|
69
|
+
function isValidHttpUrl(string) {
|
|
70
|
+
let url;
|
|
71
|
+
try {
|
|
72
|
+
url = new URL(string);
|
|
73
|
+
} catch (_) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
77
|
+
}
|
|
78
|
+
function setAuth(token) {
|
|
79
|
+
return token ? { headers: { Authorization: `Bearer ${token}` } } : null;
|
|
80
|
+
}
|
|
81
|
+
function handleResponse(response, state, callback) {
|
|
82
|
+
const nextState = {
|
|
83
|
+
...(0, import_language_common.composeNextState)(state, response),
|
|
84
|
+
response
|
|
85
|
+
};
|
|
86
|
+
if (callback)
|
|
87
|
+
return callback(nextState);
|
|
88
|
+
return nextState;
|
|
89
|
+
}
|
|
90
|
+
function handleResponseError(response, data, method) {
|
|
91
|
+
const { status, statusText, url } = response;
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
const errorString = [
|
|
94
|
+
`Message: ${statusText}`,
|
|
95
|
+
`Request: ${method} ${url}`,
|
|
96
|
+
`Status: ${status}`,
|
|
97
|
+
`Body: ${JSON.stringify(data, null, 2).replace(/\n/g, "\n ")}`
|
|
98
|
+
].join("\n \u221F ");
|
|
99
|
+
throw new Error(errorString);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var request = async (urlString, params = {}, method = "GET") => {
|
|
103
|
+
let url;
|
|
104
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
105
|
+
const { headers } = params;
|
|
106
|
+
const setHeaders = { ...headers, ...defaultHeaders };
|
|
107
|
+
delete params.headers;
|
|
108
|
+
let options = {
|
|
109
|
+
method,
|
|
110
|
+
headers: setHeaders
|
|
111
|
+
};
|
|
112
|
+
if ("GET" === method) {
|
|
113
|
+
url = `${urlString}?${new URLSearchParams(params).toString()}`;
|
|
114
|
+
} else {
|
|
115
|
+
options.body = JSON.stringify(params);
|
|
116
|
+
}
|
|
117
|
+
const response = await fetch(url, options);
|
|
118
|
+
const contentType = response.headers.get("Content-Type");
|
|
119
|
+
const data = (contentType == null ? void 0 : contentType.includes("application/json")) ? await response.json() : await response.text();
|
|
120
|
+
handleResponseError(response, data, method);
|
|
121
|
+
return data;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/Adaptor.js
|
|
125
|
+
var import_language_common3 = require("@openfn/language-common");
|
|
126
|
+
function execute(...operations) {
|
|
127
|
+
const initialState = {
|
|
128
|
+
references: [],
|
|
129
|
+
data: null
|
|
130
|
+
};
|
|
131
|
+
return (state) => {
|
|
132
|
+
return (0, import_language_common2.execute)(...operations)({
|
|
133
|
+
...initialState,
|
|
134
|
+
...state
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function create(resource, data, callback) {
|
|
139
|
+
return (state) => {
|
|
140
|
+
const resolveResource = (0, import_language_common2.expandReferences)(resource)(state);
|
|
141
|
+
const resolveData = (0, import_language_common2.expandReferences)(data)(state);
|
|
142
|
+
const { accessToken, apiVersion } = state.configuration;
|
|
143
|
+
const url = setUrl({ apiVersion, resolveResource });
|
|
144
|
+
const auth = setAuth(accessToken);
|
|
145
|
+
const options = {
|
|
146
|
+
auth,
|
|
147
|
+
...resolveData
|
|
148
|
+
};
|
|
149
|
+
return request(url, options, "POST").then(
|
|
150
|
+
(response) => handleResponse(response, state, callback)
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function get(path, query, callback = false) {
|
|
155
|
+
return (state) => {
|
|
156
|
+
const resolvePath = (0, import_language_common2.expandReferences)(path)(state);
|
|
157
|
+
const resolveQuery = (0, import_language_common2.expandReferences)(query)(state);
|
|
158
|
+
const { accessToken, apiVersion } = state.configuration;
|
|
159
|
+
const url = setUrl({ apiVersion, resolvePath });
|
|
160
|
+
const auth = setAuth(accessToken);
|
|
161
|
+
return request(url, { ...resolveQuery, ...auth }).then(
|
|
162
|
+
(response) => handleResponse(response, state, callback)
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/index.js
|
|
168
|
+
var src_default = Adaptor_exports;
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
create,
|
|
172
|
+
dataPath,
|
|
173
|
+
dataValue,
|
|
174
|
+
dateFns,
|
|
175
|
+
each,
|
|
176
|
+
execute,
|
|
177
|
+
field,
|
|
178
|
+
fields,
|
|
179
|
+
fn,
|
|
180
|
+
get,
|
|
181
|
+
lastReferenceValue,
|
|
182
|
+
merge,
|
|
183
|
+
request,
|
|
184
|
+
sourceValue
|
|
185
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
create: () => create,
|
|
11
|
+
dataPath: () => dataPath,
|
|
12
|
+
dataValue: () => dataValue,
|
|
13
|
+
dateFns: () => dateFns,
|
|
14
|
+
each: () => each,
|
|
15
|
+
execute: () => execute,
|
|
16
|
+
field: () => field,
|
|
17
|
+
fields: () => fields,
|
|
18
|
+
fn: () => fn,
|
|
19
|
+
get: () => get,
|
|
20
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
21
|
+
merge: () => merge,
|
|
22
|
+
request: () => request,
|
|
23
|
+
sourceValue: () => sourceValue
|
|
24
|
+
});
|
|
25
|
+
import {
|
|
26
|
+
execute as commonExecute,
|
|
27
|
+
expandReferences
|
|
28
|
+
} from "@openfn/language-common";
|
|
29
|
+
|
|
30
|
+
// src/Utils.js
|
|
31
|
+
import { composeNextState } from "@openfn/language-common";
|
|
32
|
+
function setUrl(urlParams) {
|
|
33
|
+
const { apiVersion, resolvePath } = urlParams;
|
|
34
|
+
if (isValidHttpUrl(resolvePath))
|
|
35
|
+
return resolvePath;
|
|
36
|
+
const pathSuffix = apiVersion ? `${apiVersion}/${resolvePath}` : `v1.0/${resolvePath}`;
|
|
37
|
+
return `https://graph.microsoft.com/${pathSuffix}`;
|
|
38
|
+
}
|
|
39
|
+
function isValidHttpUrl(string) {
|
|
40
|
+
let url;
|
|
41
|
+
try {
|
|
42
|
+
url = new URL(string);
|
|
43
|
+
} catch (_) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
47
|
+
}
|
|
48
|
+
function setAuth(token) {
|
|
49
|
+
return token ? { headers: { Authorization: `Bearer ${token}` } } : null;
|
|
50
|
+
}
|
|
51
|
+
function handleResponse(response, state, callback) {
|
|
52
|
+
const nextState = {
|
|
53
|
+
...composeNextState(state, response),
|
|
54
|
+
response
|
|
55
|
+
};
|
|
56
|
+
if (callback)
|
|
57
|
+
return callback(nextState);
|
|
58
|
+
return nextState;
|
|
59
|
+
}
|
|
60
|
+
function handleResponseError(response, data, method) {
|
|
61
|
+
const { status, statusText, url } = response;
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
const errorString = [
|
|
64
|
+
`Message: ${statusText}`,
|
|
65
|
+
`Request: ${method} ${url}`,
|
|
66
|
+
`Status: ${status}`,
|
|
67
|
+
`Body: ${JSON.stringify(data, null, 2).replace(/\n/g, "\n ")}`
|
|
68
|
+
].join("\n \u221F ");
|
|
69
|
+
throw new Error(errorString);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var request = async (urlString, params = {}, method = "GET") => {
|
|
73
|
+
let url;
|
|
74
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
75
|
+
const { headers } = params;
|
|
76
|
+
const setHeaders = { ...headers, ...defaultHeaders };
|
|
77
|
+
delete params.headers;
|
|
78
|
+
let options = {
|
|
79
|
+
method,
|
|
80
|
+
headers: setHeaders
|
|
81
|
+
};
|
|
82
|
+
if ("GET" === method) {
|
|
83
|
+
url = `${urlString}?${new URLSearchParams(params).toString()}`;
|
|
84
|
+
} else {
|
|
85
|
+
options.body = JSON.stringify(params);
|
|
86
|
+
}
|
|
87
|
+
const response = await fetch(url, options);
|
|
88
|
+
const contentType = response.headers.get("Content-Type");
|
|
89
|
+
const data = (contentType == null ? void 0 : contentType.includes("application/json")) ? await response.json() : await response.text();
|
|
90
|
+
handleResponseError(response, data, method);
|
|
91
|
+
return data;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/Adaptor.js
|
|
95
|
+
import {
|
|
96
|
+
dataPath,
|
|
97
|
+
dataValue,
|
|
98
|
+
dateFns,
|
|
99
|
+
each,
|
|
100
|
+
field,
|
|
101
|
+
fields,
|
|
102
|
+
fn,
|
|
103
|
+
lastReferenceValue,
|
|
104
|
+
merge,
|
|
105
|
+
sourceValue
|
|
106
|
+
} from "@openfn/language-common";
|
|
107
|
+
function execute(...operations) {
|
|
108
|
+
const initialState = {
|
|
109
|
+
references: [],
|
|
110
|
+
data: null
|
|
111
|
+
};
|
|
112
|
+
return (state) => {
|
|
113
|
+
return commonExecute(...operations)({
|
|
114
|
+
...initialState,
|
|
115
|
+
...state
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function create(resource, data, callback) {
|
|
120
|
+
return (state) => {
|
|
121
|
+
const resolveResource = expandReferences(resource)(state);
|
|
122
|
+
const resolveData = expandReferences(data)(state);
|
|
123
|
+
const { accessToken, apiVersion } = state.configuration;
|
|
124
|
+
const url = setUrl({ apiVersion, resolveResource });
|
|
125
|
+
const auth = setAuth(accessToken);
|
|
126
|
+
const options = {
|
|
127
|
+
auth,
|
|
128
|
+
...resolveData
|
|
129
|
+
};
|
|
130
|
+
return request(url, options, "POST").then(
|
|
131
|
+
(response) => handleResponse(response, state, callback)
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function get(path, query, callback = false) {
|
|
136
|
+
return (state) => {
|
|
137
|
+
const resolvePath = expandReferences(path)(state);
|
|
138
|
+
const resolveQuery = expandReferences(query)(state);
|
|
139
|
+
const { accessToken, apiVersion } = state.configuration;
|
|
140
|
+
const url = setUrl({ apiVersion, resolvePath });
|
|
141
|
+
const auth = setAuth(accessToken);
|
|
142
|
+
return request(url, { ...resolveQuery, ...auth }).then(
|
|
143
|
+
(response) => handleResponse(response, state, callback)
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/index.js
|
|
149
|
+
var src_default = Adaptor_exports;
|
|
150
|
+
export {
|
|
151
|
+
create,
|
|
152
|
+
dataPath,
|
|
153
|
+
dataValue,
|
|
154
|
+
dateFns,
|
|
155
|
+
src_default as default,
|
|
156
|
+
each,
|
|
157
|
+
execute,
|
|
158
|
+
field,
|
|
159
|
+
fields,
|
|
160
|
+
fn,
|
|
161
|
+
get,
|
|
162
|
+
lastReferenceValue,
|
|
163
|
+
merge,
|
|
164
|
+
request,
|
|
165
|
+
sourceValue
|
|
166
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-msgraph",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Microsoft Graph Language Pack for OpenFn",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"author": "Open Function Group",
|
|
14
|
+
"license": "LGPLv3",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"types/",
|
|
18
|
+
"ast.json",
|
|
19
|
+
"configuration-schema.json"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@openfn/language-common": "^1.9.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@openfn/buildtools": "^1.0.2",
|
|
26
|
+
"@openfn/simple-ast": "0.4.1",
|
|
27
|
+
"assertion-error": "2.0.0",
|
|
28
|
+
"chai": "4.3.6",
|
|
29
|
+
"deep-eql": "4.1.1",
|
|
30
|
+
"esno": "^0.16.3",
|
|
31
|
+
"mocha": "9.2.2",
|
|
32
|
+
"rimraf": "3.0.2",
|
|
33
|
+
"undici": "^5.22.1"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
38
|
+
},
|
|
39
|
+
"types": "types/index.d.ts",
|
|
40
|
+
"main": "dist/index.cjs",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm clean && build-adaptor msgraph",
|
|
43
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
44
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
45
|
+
"clean": "rimraf dist types docs",
|
|
46
|
+
"pack": "pnpm pack --pack-destination ../../dist",
|
|
47
|
+
"lint": "eslint src"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a sequence of operations.
|
|
3
|
+
* Wraps `language-common/execute` to make working with this API easier.
|
|
4
|
+
* @example
|
|
5
|
+
* execute(
|
|
6
|
+
* create('foo'),
|
|
7
|
+
* delete('bar')
|
|
8
|
+
* )(state)
|
|
9
|
+
* @private
|
|
10
|
+
* @param {Operations} operations - Operations to be performed.
|
|
11
|
+
* @returns {Operation}
|
|
12
|
+
*/
|
|
13
|
+
export function execute(...operations: Operations): Operation;
|
|
14
|
+
/**
|
|
15
|
+
* Create some resource in msgraph
|
|
16
|
+
* @public
|
|
17
|
+
* @example
|
|
18
|
+
* create("applications", {"displayName": "My App"})
|
|
19
|
+
* @function
|
|
20
|
+
* @param {string} resource - The type of entity that will be created
|
|
21
|
+
* @param {object} data - The data to create the new resource
|
|
22
|
+
* @param {function} callback - An optional callback function
|
|
23
|
+
* @returns {Operation}
|
|
24
|
+
*/
|
|
25
|
+
export function create(resource: string, data: object, callback: Function): Operation;
|
|
26
|
+
/**
|
|
27
|
+
* Make a GET request to msgraph resource
|
|
28
|
+
* @public
|
|
29
|
+
* @example
|
|
30
|
+
* get('sites/root/lists')
|
|
31
|
+
* @function
|
|
32
|
+
* @param {string} path - Path to resource
|
|
33
|
+
* @param {object} query - Query, Headers and Authentication parameters
|
|
34
|
+
* @param {function} callback - (Optional) Callback function
|
|
35
|
+
* @returns {Operation}
|
|
36
|
+
*/
|
|
37
|
+
export function get(path: string, query: object, callback?: Function): Operation;
|
|
38
|
+
export { request } from "./Utils";
|
|
39
|
+
export { dataPath, dataValue, dateFns, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/Utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function setUrl(urlParams: any): any;
|
|
2
|
+
export function setAuth(token: any): {
|
|
3
|
+
headers: {
|
|
4
|
+
Authorization: string;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export function handleResponse(response: any, state: any, callback: any): any;
|
|
8
|
+
export function handleResponseError(response: any, data: any, method: any): void;
|
|
9
|
+
export function request(urlString: any, params?: object, method?: string): Promise<any>;
|
package/types/index.d.ts
ADDED