@openfn/language-msgraph 0.2.0 → 0.3.1

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/ast.json CHANGED
@@ -125,6 +125,207 @@
125
125
  ]
126
126
  },
127
127
  "valid": true
128
+ },
129
+ {
130
+ "name": "getDrive",
131
+ "params": [
132
+ "specifier",
133
+ "name",
134
+ "callback"
135
+ ],
136
+ "docs": {
137
+ "description": "Get a Drive or SharePoint document library. The drive metadata will be written\nto state.drives, where it can be used by other adaptor functions.\nPass { id } to get a drive by id or { id, owner } to get default drive for\nsome parent resource, like a group",
138
+ "tags": [
139
+ {
140
+ "title": "public",
141
+ "description": null,
142
+ "type": null
143
+ },
144
+ {
145
+ "title": "example",
146
+ "description": "getDrive({ id: \"YXzpkoLwR06bxC8tNdg71m\" })",
147
+ "caption": "Get a drive by ID"
148
+ },
149
+ {
150
+ "title": "example",
151
+ "description": "getDrive({ id: \"openfn.sharepoint.com\", owner: \"sites\" })",
152
+ "caption": "Get the default drive for a site"
153
+ },
154
+ {
155
+ "title": "param",
156
+ "description": "{Object} - A definition of the drive to retrieve\n - id {string} - The ID of the resource or owner.\n - owner {string} - The type of drive owner (e.g. sites, groups).",
157
+ "type": null,
158
+ "name": "specifier"
159
+ },
160
+ {
161
+ "title": "param",
162
+ "description": "The local name of the drive used to write to state.drives, ie, state.drives[name]",
163
+ "type": {
164
+ "type": "NameExpression",
165
+ "name": "string"
166
+ },
167
+ "name": "name"
168
+ },
169
+ {
170
+ "title": "param",
171
+ "description": "(Optional) Callback function",
172
+ "type": {
173
+ "type": "OptionalType",
174
+ "expression": {
175
+ "type": "NameExpression",
176
+ "name": "function"
177
+ }
178
+ },
179
+ "name": "callback",
180
+ "default": "s=>s"
181
+ },
182
+ {
183
+ "title": "return",
184
+ "description": null,
185
+ "type": {
186
+ "type": "NameExpression",
187
+ "name": "Operation"
188
+ }
189
+ }
190
+ ]
191
+ },
192
+ "valid": true
193
+ },
194
+ {
195
+ "name": "getFolder",
196
+ "params": [
197
+ "pathOrId",
198
+ "options",
199
+ "callback"
200
+ ],
201
+ "docs": {
202
+ "description": "Get the contents or metadata of a folder.",
203
+ "tags": [
204
+ {
205
+ "title": "public",
206
+ "description": null,
207
+ "type": null
208
+ },
209
+ {
210
+ "title": "example",
211
+ "description": "getFolder('01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3')",
212
+ "caption": "Get a folder by ID"
213
+ },
214
+ {
215
+ "title": "example",
216
+ "description": "getFolder(\"01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3\",{ driveName: \"mydrive\"})",
217
+ "caption": "Get a folder for a named drive by id"
218
+ },
219
+ {
220
+ "title": "param",
221
+ "description": "A path to a folder or folder id",
222
+ "type": {
223
+ "type": "NameExpression",
224
+ "name": "string"
225
+ },
226
+ "name": "pathOrId"
227
+ },
228
+ {
229
+ "title": "param",
230
+ "description": "(Optional) Query parameters",
231
+ "type": {
232
+ "type": "NameExpression",
233
+ "name": "object"
234
+ },
235
+ "name": "options"
236
+ },
237
+ {
238
+ "title": "param",
239
+ "description": "(Optional) Callback function",
240
+ "type": {
241
+ "type": "OptionalType",
242
+ "expression": {
243
+ "type": "NameExpression",
244
+ "name": "function"
245
+ }
246
+ },
247
+ "name": "callback",
248
+ "default": "s=>s"
249
+ },
250
+ {
251
+ "title": "return",
252
+ "description": null,
253
+ "type": {
254
+ "type": "NameExpression",
255
+ "name": "Operation"
256
+ }
257
+ }
258
+ ]
259
+ },
260
+ "valid": true
261
+ },
262
+ {
263
+ "name": "getFile",
264
+ "params": [
265
+ "pathOrId",
266
+ "options",
267
+ "callback"
268
+ ],
269
+ "docs": {
270
+ "description": "Get file metadata or file content.",
271
+ "tags": [
272
+ {
273
+ "title": "public",
274
+ "description": null,
275
+ "type": null
276
+ },
277
+ {
278
+ "title": "example",
279
+ "description": "getFile('01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW')",
280
+ "caption": "Get a file by ID"
281
+ },
282
+ {
283
+ "title": "example",
284
+ "description": "getFile(\"01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW\",{ driveName: \"mydrive\"})",
285
+ "caption": "Get a file for a named drive by id"
286
+ },
287
+ {
288
+ "title": "param",
289
+ "description": "A path to a file or file id",
290
+ "type": {
291
+ "type": "NameExpression",
292
+ "name": "string"
293
+ },
294
+ "name": "pathOrId"
295
+ },
296
+ {
297
+ "title": "param",
298
+ "description": "(Optional) Query parameters",
299
+ "type": {
300
+ "type": "NameExpression",
301
+ "name": "object"
302
+ },
303
+ "name": "options"
304
+ },
305
+ {
306
+ "title": "param",
307
+ "description": "(Optional) Callback function",
308
+ "type": {
309
+ "type": "OptionalType",
310
+ "expression": {
311
+ "type": "NameExpression",
312
+ "name": "function"
313
+ }
314
+ },
315
+ "name": "callback",
316
+ "default": "s=>s"
317
+ },
318
+ {
319
+ "title": "return",
320
+ "description": null,
321
+ "type": {
322
+ "type": "NameExpression",
323
+ "name": "Operation"
324
+ }
325
+ }
326
+ ]
327
+ },
328
+ "valid": true
128
329
  }
129
330
  ],
130
331
  "exports": [],
package/dist/index.cjs CHANGED
@@ -30,6 +30,9 @@ __export(src_exports, {
30
30
  fields: () => import_language_common3.fields,
31
31
  fn: () => import_language_common3.fn,
32
32
  get: () => get,
33
+ getDrive: () => getDrive,
34
+ getFile: () => getFile,
35
+ getFolder: () => getFolder,
33
36
  lastReferenceValue: () => import_language_common3.lastReferenceValue,
34
37
  merge: () => import_language_common3.merge,
35
38
  parseCsv: () => import_language_common3.parseCsv,
@@ -51,6 +54,9 @@ __export(Adaptor_exports, {
51
54
  fields: () => import_language_common3.fields,
52
55
  fn: () => import_language_common3.fn,
53
56
  get: () => get,
57
+ getDrive: () => getDrive,
58
+ getFile: () => getFile,
59
+ getFolder: () => getFolder,
54
60
  lastReferenceValue: () => import_language_common3.lastReferenceValue,
55
61
  merge: () => import_language_common3.merge,
56
62
  parseCsv: () => import_language_common3.parseCsv,
@@ -58,14 +64,25 @@ __export(Adaptor_exports, {
58
64
  sourceValue: () => import_language_common3.sourceValue
59
65
  });
60
66
  var import_language_common2 = require("@openfn/language-common");
67
+ var import_util = require("@openfn/language-common/util");
61
68
 
62
69
  // src/Utils.js
70
+ var import_undici = require("undici");
63
71
  var import_language_common = require("@openfn/language-common");
64
- function setUrl(urlParams) {
65
- const { apiVersion, resolvePath } = urlParams;
66
- if (isValidHttpUrl(resolvePath))
67
- return resolvePath;
68
- const pathSuffix = apiVersion ? `${apiVersion}/${resolvePath}` : `v1.0/${resolvePath}`;
72
+ function assertDrive(state, driveName) {
73
+ if (!state.drives[driveName]) {
74
+ const errorString = [
75
+ `Drive is not defined.`,
76
+ `At the top of your job you should define all the drives you want to use.`,
77
+ `eg: getDrive({ id: "openfn.sharepoint.com", owner: "sites"})`
78
+ ].join("\n \u221F ");
79
+ throw new Error(errorString);
80
+ }
81
+ }
82
+ function getUrl(resource, apiVersion) {
83
+ if (isValidHttpUrl(resource))
84
+ return resource;
85
+ const pathSuffix = apiVersion ? `${apiVersion}/${resource}` : `v1.0/${resource}`;
69
86
  return `https://graph.microsoft.com/${pathSuffix}`;
70
87
  }
71
88
  function isValidHttpUrl(string) {
@@ -77,7 +94,7 @@ function isValidHttpUrl(string) {
77
94
  }
78
95
  return url.protocol === "http:" || url.protocol === "https:";
79
96
  }
80
- function setAuth(token) {
97
+ function getAuth(token) {
81
98
  return token ? { headers: { Authorization: `Bearer ${token}` } } : null;
82
99
  }
83
100
  function handleResponse(response, state, callback) {
@@ -116,7 +133,7 @@ var request = async (urlString, params = {}, method = "GET") => {
116
133
  } else {
117
134
  options.body = JSON.stringify(params);
118
135
  }
119
- const response = await fetch(url, options);
136
+ const response = await (0, import_undici.fetch)(url, options);
120
137
  const contentType = response.headers.get("Content-Type");
121
138
  const data = (contentType == null ? void 0 : contentType.includes("application/json")) ? await response.json() : await response.text();
122
139
  handleResponseError(response, data, method);
@@ -128,25 +145,36 @@ var import_language_common3 = require("@openfn/language-common");
128
145
  function execute(...operations) {
129
146
  const initialState = {
130
147
  references: [],
131
- data: null
148
+ data: null,
149
+ drives: {}
150
+ };
151
+ const cleanup = (finalState) => {
152
+ const { drives, ...rest } = finalState;
153
+ return rest;
132
154
  };
133
155
  return (state) => {
134
156
  return (0, import_language_common2.execute)(...operations)({
135
157
  ...initialState,
136
158
  ...state
159
+ }).then(cleanup).catch((error) => {
160
+ cleanup(state);
161
+ throw error;
137
162
  });
138
163
  };
139
164
  }
140
165
  function create(resource, data, callback) {
141
166
  return (state) => {
142
- const resolveResource = (0, import_language_common2.expandReferences)(resource)(state);
143
- const resolveData = (0, import_language_common2.expandReferences)(data)(state);
167
+ const [resolvedResource, resolvedData] = (0, import_util.expandReferences)(
168
+ state,
169
+ resource,
170
+ data
171
+ );
144
172
  const { accessToken, apiVersion } = state.configuration;
145
- const url = setUrl({ apiVersion, resolveResource });
146
- const auth = setAuth(accessToken);
173
+ const url = getUrl({ apiVersion, resolvedResource });
174
+ const auth = getAuth(accessToken);
147
175
  const options = {
148
176
  auth,
149
- ...resolveData
177
+ ...resolvedData
150
178
  };
151
179
  return request(url, options, "POST").then(
152
180
  (response) => handleResponse(response, state, callback)
@@ -155,12 +183,103 @@ function create(resource, data, callback) {
155
183
  }
156
184
  function get(path, query, callback = false) {
157
185
  return (state) => {
158
- const resolvePath = (0, import_language_common2.expandReferences)(path)(state);
159
- const resolveQuery = (0, import_language_common2.expandReferences)(query)(state);
160
186
  const { accessToken, apiVersion } = state.configuration;
161
- const url = setUrl({ apiVersion, resolvePath });
162
- const auth = setAuth(accessToken);
163
- return request(url, { ...resolveQuery, ...auth }).then(
187
+ const [resolvedPath, resolvedQuery] = (0, import_util.expandReferences)(state, path, query);
188
+ const url = getUrl(resolvedPath, apiVersion);
189
+ const auth = getAuth(accessToken);
190
+ return request(url, { ...resolvedQuery, ...auth }).then(
191
+ (response) => handleResponse(response, state, callback)
192
+ );
193
+ };
194
+ }
195
+ function getDrive(specifier, name = "default", callback = (s) => s) {
196
+ return (state) => {
197
+ const { accessToken, apiVersion } = state.configuration;
198
+ const [resolvedSpecifier, resolvedName] = (0, import_util.expandReferences)(
199
+ state,
200
+ specifier,
201
+ name
202
+ );
203
+ const { id, owner = "drive" } = resolvedSpecifier;
204
+ let resource;
205
+ if (owner === "drive") {
206
+ resource = `drives/${id}`;
207
+ } else {
208
+ resource = `${owner}/${id}/drive`;
209
+ }
210
+ const url = getUrl(resource, apiVersion);
211
+ const auth = getAuth(accessToken);
212
+ return request(url, { ...auth }).then((response) => {
213
+ state.drives[resolvedName] = response;
214
+ return callback(state);
215
+ });
216
+ };
217
+ }
218
+ function getFolder(pathOrId, options, callback = (s) => s) {
219
+ return async (state) => {
220
+ const defaultOptions = {
221
+ driveName: "default",
222
+ metadata: false
223
+ };
224
+ const { accessToken, apiVersion } = state.configuration;
225
+ const [resolvedPathOrId, resolvedOptions] = (0, import_util.expandReferences)(
226
+ state,
227
+ pathOrId,
228
+ options
229
+ );
230
+ const { driveName, metadata } = { ...defaultOptions, ...resolvedOptions };
231
+ assertDrive(state, driveName);
232
+ const { id: driveId } = state.drives[driveName];
233
+ let resource;
234
+ if (resolvedPathOrId.startsWith("/")) {
235
+ resource = `drives/${driveId}/root:/${encodeURIComponent(
236
+ resolvedPathOrId
237
+ )}`;
238
+ } else {
239
+ resource = `drives/${driveId}/items/${resolvedPathOrId}`;
240
+ }
241
+ if (!metadata) {
242
+ resource += resolvedPathOrId.startsWith("/") ? ":/children" : "/children";
243
+ }
244
+ const url = getUrl(resource, apiVersion);
245
+ const auth = getAuth(accessToken);
246
+ return request(url, { ...auth }).then(
247
+ (response) => handleResponse(response, state, callback)
248
+ );
249
+ };
250
+ }
251
+ function getFile(pathOrId, options, callback = (s) => s) {
252
+ return async (state) => {
253
+ const defaultOptions = {
254
+ driveName: "default",
255
+ metadata: false
256
+ };
257
+ const { accessToken, apiVersion } = state.configuration;
258
+ const [resolvedPathOrId, resolvedOptions] = (0, import_util.expandReferences)(
259
+ state,
260
+ pathOrId,
261
+ options
262
+ );
263
+ const { driveName, metadata } = {
264
+ ...defaultOptions,
265
+ ...resolvedOptions
266
+ };
267
+ assertDrive(state, driveName);
268
+ const { id: driveId } = state.drives[driveName];
269
+ let resource;
270
+ if (resolvedPathOrId.startsWith("/")) {
271
+ resource = `drives/${driveId}/root:/${encodeURIComponent(
272
+ resolvedPathOrId
273
+ )}`;
274
+ } else {
275
+ resource = `drives/${driveId}/items/${resolvedPathOrId}`;
276
+ }
277
+ if (!metadata) {
278
+ resource += resolvedPathOrId.startsWith("/") ? ":/content" : "/content";
279
+ }
280
+ const url = getUrl(resource, apiVersion);
281
+ const auth = getAuth(accessToken);
282
+ return request(url, { ...auth }).then(
164
283
  (response) => handleResponse(response, state, callback)
165
284
  );
166
285
  };
@@ -180,6 +299,9 @@ var src_default = Adaptor_exports;
180
299
  fields,
181
300
  fn,
182
301
  get,
302
+ getDrive,
303
+ getFile,
304
+ getFolder,
183
305
  lastReferenceValue,
184
306
  merge,
185
307
  parseCsv,
package/dist/index.js CHANGED
@@ -17,24 +17,35 @@ __export(Adaptor_exports, {
17
17
  fields: () => fields,
18
18
  fn: () => fn,
19
19
  get: () => get,
20
+ getDrive: () => getDrive,
21
+ getFile: () => getFile,
22
+ getFolder: () => getFolder,
20
23
  lastReferenceValue: () => lastReferenceValue,
21
24
  merge: () => merge,
22
25
  parseCsv: () => parseCsv,
23
26
  request: () => request,
24
27
  sourceValue: () => sourceValue
25
28
  });
26
- import {
27
- execute as commonExecute,
28
- expandReferences
29
- } from "@openfn/language-common";
29
+ import { execute as commonExecute } from "@openfn/language-common";
30
+ import { expandReferences } from "@openfn/language-common/util";
30
31
 
31
32
  // src/Utils.js
33
+ import { fetch } from "undici";
32
34
  import { composeNextState } from "@openfn/language-common";
33
- function setUrl(urlParams) {
34
- const { apiVersion, resolvePath } = urlParams;
35
- if (isValidHttpUrl(resolvePath))
36
- return resolvePath;
37
- const pathSuffix = apiVersion ? `${apiVersion}/${resolvePath}` : `v1.0/${resolvePath}`;
35
+ function assertDrive(state, driveName) {
36
+ if (!state.drives[driveName]) {
37
+ const errorString = [
38
+ `Drive is not defined.`,
39
+ `At the top of your job you should define all the drives you want to use.`,
40
+ `eg: getDrive({ id: "openfn.sharepoint.com", owner: "sites"})`
41
+ ].join("\n \u221F ");
42
+ throw new Error(errorString);
43
+ }
44
+ }
45
+ function getUrl(resource, apiVersion) {
46
+ if (isValidHttpUrl(resource))
47
+ return resource;
48
+ const pathSuffix = apiVersion ? `${apiVersion}/${resource}` : `v1.0/${resource}`;
38
49
  return `https://graph.microsoft.com/${pathSuffix}`;
39
50
  }
40
51
  function isValidHttpUrl(string) {
@@ -46,7 +57,7 @@ function isValidHttpUrl(string) {
46
57
  }
47
58
  return url.protocol === "http:" || url.protocol === "https:";
48
59
  }
49
- function setAuth(token) {
60
+ function getAuth(token) {
50
61
  return token ? { headers: { Authorization: `Bearer ${token}` } } : null;
51
62
  }
52
63
  function handleResponse(response, state, callback) {
@@ -109,25 +120,36 @@ import {
109
120
  function execute(...operations) {
110
121
  const initialState = {
111
122
  references: [],
112
- data: null
123
+ data: null,
124
+ drives: {}
125
+ };
126
+ const cleanup = (finalState) => {
127
+ const { drives, ...rest } = finalState;
128
+ return rest;
113
129
  };
114
130
  return (state) => {
115
131
  return commonExecute(...operations)({
116
132
  ...initialState,
117
133
  ...state
134
+ }).then(cleanup).catch((error) => {
135
+ cleanup(state);
136
+ throw error;
118
137
  });
119
138
  };
120
139
  }
121
140
  function create(resource, data, callback) {
122
141
  return (state) => {
123
- const resolveResource = expandReferences(resource)(state);
124
- const resolveData = expandReferences(data)(state);
142
+ const [resolvedResource, resolvedData] = expandReferences(
143
+ state,
144
+ resource,
145
+ data
146
+ );
125
147
  const { accessToken, apiVersion } = state.configuration;
126
- const url = setUrl({ apiVersion, resolveResource });
127
- const auth = setAuth(accessToken);
148
+ const url = getUrl({ apiVersion, resolvedResource });
149
+ const auth = getAuth(accessToken);
128
150
  const options = {
129
151
  auth,
130
- ...resolveData
152
+ ...resolvedData
131
153
  };
132
154
  return request(url, options, "POST").then(
133
155
  (response) => handleResponse(response, state, callback)
@@ -136,12 +158,103 @@ function create(resource, data, callback) {
136
158
  }
137
159
  function get(path, query, callback = false) {
138
160
  return (state) => {
139
- const resolvePath = expandReferences(path)(state);
140
- const resolveQuery = expandReferences(query)(state);
141
161
  const { accessToken, apiVersion } = state.configuration;
142
- const url = setUrl({ apiVersion, resolvePath });
143
- const auth = setAuth(accessToken);
144
- return request(url, { ...resolveQuery, ...auth }).then(
162
+ const [resolvedPath, resolvedQuery] = expandReferences(state, path, query);
163
+ const url = getUrl(resolvedPath, apiVersion);
164
+ const auth = getAuth(accessToken);
165
+ return request(url, { ...resolvedQuery, ...auth }).then(
166
+ (response) => handleResponse(response, state, callback)
167
+ );
168
+ };
169
+ }
170
+ function getDrive(specifier, name = "default", callback = (s) => s) {
171
+ return (state) => {
172
+ const { accessToken, apiVersion } = state.configuration;
173
+ const [resolvedSpecifier, resolvedName] = expandReferences(
174
+ state,
175
+ specifier,
176
+ name
177
+ );
178
+ const { id, owner = "drive" } = resolvedSpecifier;
179
+ let resource;
180
+ if (owner === "drive") {
181
+ resource = `drives/${id}`;
182
+ } else {
183
+ resource = `${owner}/${id}/drive`;
184
+ }
185
+ const url = getUrl(resource, apiVersion);
186
+ const auth = getAuth(accessToken);
187
+ return request(url, { ...auth }).then((response) => {
188
+ state.drives[resolvedName] = response;
189
+ return callback(state);
190
+ });
191
+ };
192
+ }
193
+ function getFolder(pathOrId, options, callback = (s) => s) {
194
+ return async (state) => {
195
+ const defaultOptions = {
196
+ driveName: "default",
197
+ metadata: false
198
+ };
199
+ const { accessToken, apiVersion } = state.configuration;
200
+ const [resolvedPathOrId, resolvedOptions] = expandReferences(
201
+ state,
202
+ pathOrId,
203
+ options
204
+ );
205
+ const { driveName, metadata } = { ...defaultOptions, ...resolvedOptions };
206
+ assertDrive(state, driveName);
207
+ const { id: driveId } = state.drives[driveName];
208
+ let resource;
209
+ if (resolvedPathOrId.startsWith("/")) {
210
+ resource = `drives/${driveId}/root:/${encodeURIComponent(
211
+ resolvedPathOrId
212
+ )}`;
213
+ } else {
214
+ resource = `drives/${driveId}/items/${resolvedPathOrId}`;
215
+ }
216
+ if (!metadata) {
217
+ resource += resolvedPathOrId.startsWith("/") ? ":/children" : "/children";
218
+ }
219
+ const url = getUrl(resource, apiVersion);
220
+ const auth = getAuth(accessToken);
221
+ return request(url, { ...auth }).then(
222
+ (response) => handleResponse(response, state, callback)
223
+ );
224
+ };
225
+ }
226
+ function getFile(pathOrId, options, callback = (s) => s) {
227
+ return async (state) => {
228
+ const defaultOptions = {
229
+ driveName: "default",
230
+ metadata: false
231
+ };
232
+ const { accessToken, apiVersion } = state.configuration;
233
+ const [resolvedPathOrId, resolvedOptions] = expandReferences(
234
+ state,
235
+ pathOrId,
236
+ options
237
+ );
238
+ const { driveName, metadata } = {
239
+ ...defaultOptions,
240
+ ...resolvedOptions
241
+ };
242
+ assertDrive(state, driveName);
243
+ const { id: driveId } = state.drives[driveName];
244
+ let resource;
245
+ if (resolvedPathOrId.startsWith("/")) {
246
+ resource = `drives/${driveId}/root:/${encodeURIComponent(
247
+ resolvedPathOrId
248
+ )}`;
249
+ } else {
250
+ resource = `drives/${driveId}/items/${resolvedPathOrId}`;
251
+ }
252
+ if (!metadata) {
253
+ resource += resolvedPathOrId.startsWith("/") ? ":/content" : "/content";
254
+ }
255
+ const url = getUrl(resource, apiVersion);
256
+ const auth = getAuth(accessToken);
257
+ return request(url, { ...auth }).then(
145
258
  (response) => handleResponse(response, state, callback)
146
259
  );
147
260
  };
@@ -161,6 +274,9 @@ export {
161
274
  fields,
162
275
  fn,
163
276
  get,
277
+ getDrive,
278
+ getFile,
279
+ getFolder,
164
280
  lastReferenceValue,
165
281
  merge,
166
282
  parseCsv,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-msgraph",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Microsoft Graph Language Pack for OpenFn",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,8 @@
19
19
  "configuration-schema.json"
20
20
  ],
21
21
  "dependencies": {
22
- "@openfn/language-common": "^1.10.1"
22
+ "@openfn/language-common": "^1.10.1",
23
+ "undici": "^5.22.1"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@openfn/buildtools": "^1.0.2",
@@ -29,8 +30,7 @@
29
30
  "deep-eql": "4.1.1",
30
31
  "esno": "^0.16.3",
31
32
  "mocha": "9.2.2",
32
- "rimraf": "3.0.2",
33
- "undici": "^5.22.1"
33
+ "rimraf": "3.0.2"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
@@ -35,5 +35,49 @@ export function create(resource: string, data: object, callback: Function): Oper
35
35
  * @returns {Operation}
36
36
  */
37
37
  export function get(path: string, query: object, callback?: Function): Operation;
38
+ /**
39
+ * Get a Drive or SharePoint document library. The drive metadata will be written
40
+ * to state.drives, where it can be used by other adaptor functions.
41
+ * Pass { id } to get a drive by id or { id, owner } to get default drive for
42
+ * some parent resource, like a group
43
+ * @public
44
+ * @example <caption>Get a drive by ID</caption>
45
+ * getDrive({ id: "YXzpkoLwR06bxC8tNdg71m" })
46
+ * @example <caption>Get the default drive for a site</caption>
47
+ * getDrive({ id: "openfn.sharepoint.com", owner: "sites" })
48
+ * @param specifier {Object} - A definition of the drive to retrieve
49
+ * - id {string} - The ID of the resource or owner.
50
+ * - owner {string} - The type of drive owner (e.g. sites, groups).
51
+ * @param {string} name - The local name of the drive used to write to state.drives, ie, state.drives[name]
52
+ * @param {function} [callback = s => s] (Optional) Callback function
53
+ * @return {Operation}
54
+ */
55
+ export function getDrive(specifier: any, name?: string, callback?: Function): Operation;
56
+ /**
57
+ * Get the contents or metadata of a folder.
58
+ * @public
59
+ * @example <caption>Get a folder by ID</caption>
60
+ * getFolder('01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3')
61
+ * @example <caption>Get a folder for a named drive by id</caption>
62
+ * getFolder("01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3",{ driveName: "mydrive"})
63
+ * @param {string} pathOrId - A path to a folder or folder id
64
+ * @param {object} options - (Optional) Query parameters
65
+ * @param {function} [callback = s => s] (Optional) Callback function
66
+ * @return {Operation}
67
+ */
68
+ export function getFolder(pathOrId: string, options: object, callback?: Function): Operation;
69
+ /**
70
+ * Get file metadata or file content.
71
+ * @public
72
+ * @example <caption>Get a file by ID</caption>
73
+ * getFile('01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW')
74
+ * @example <caption>Get a file for a named drive by id</caption>
75
+ * getFile("01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW",{ driveName: "mydrive"})
76
+ * @param {string} pathOrId - A path to a file or file id
77
+ * @param {object} options - (Optional) Query parameters
78
+ * @param {function} [callback = s => s] (Optional) Callback function
79
+ * @return {Operation}
80
+ */
81
+ export function getFile(pathOrId: string, options: object, callback?: Function): Operation;
38
82
  export { request } from "./Utils";
39
83
  export { dataPath, dataValue, dateFns, each, field, fields, fn, lastReferenceValue, merge, sourceValue, parseCsv } from "@openfn/language-common";
package/types/Utils.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export function setUrl(urlParams: any): any;
2
- export function setAuth(token: any): {
1
+ export function assertDrive(state: any, driveName: any): void;
2
+ export function getUrl(resource: any, apiVersion: any): any;
3
+ export function getAuth(token: any): {
3
4
  headers: {
4
5
  Authorization: string;
5
6
  };
6
7
  };
7
8
  export function handleResponse(response: any, state: any, callback: any): any;
8
9
  export function handleResponseError(response: any, data: any, method: any): void;
9
- export function request(urlString: any, params?: object, method?: string): Promise<any>;
10
+ export function request(urlString: any, params?: object, method?: string): Promise<unknown>;