Skip to content

Commit

Permalink
use fetch from undici
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchi committed Jul 18, 2023
1 parent 97b20f7 commit 43fef71
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/msgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"configuration-schema.json"
],
"dependencies": {
"@openfn/language-common": "^1.10.1"
"@openfn/language-common": "^1.10.1",
"undici": "^5.22.1"
},
"devDependencies": {
"@openfn/buildtools": "workspace:^1.0.2",
Expand All @@ -37,8 +38,7 @@
"deep-eql": "4.1.1",
"esno": "^0.16.3",
"mocha": "9.2.2",
"rimraf": "3.0.2",
"undici": "^5.22.1"
"rimraf": "3.0.2"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions packages/msgraph/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execute as commonExecute } from '@openfn/language-common';
import { expandReferences } from '@openfn/language-common/util';

import { request, setAuth, setUrl, handleResponse } from './Utils';
import { request, setAuth, getUrl, handleResponse } from './Utils';

/**
* Execute a sequence of operations.
Expand Down Expand Up @@ -51,7 +51,7 @@ export function create(resource, data, callback) {

const { accessToken, apiVersion } = state.configuration;

const url = setUrl({ apiVersion, resolveResource });
const url = getUrl({ apiVersion, resolveResource });
const auth = setAuth(accessToken);

const options = {
Expand Down Expand Up @@ -81,7 +81,7 @@ export function get(path, query, callback = false) {
const { accessToken, apiVersion } = state.configuration;
const [resolvePath, resolveQuery] = expandReferences(state, path, query);

const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });
const auth = setAuth(accessToken);

return request(url, { ...resolveQuery, ...auth }).then(response =>
Expand Down Expand Up @@ -128,7 +128,7 @@ export function getDrive(drive, callback) {
resolvePath = `${resource}/${resourceId}/drive`;
}

const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });
const auth = setAuth(accessToken);

return request(url, { ...auth }).then(response =>
Expand Down Expand Up @@ -170,7 +170,7 @@ export function listDrives(resource, callback) {
resolvePath = `${resource}/${resourceId}/drives`;
}

const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });
const auth = setAuth(accessToken);

return request(url, { ...auth }).then(response =>
Expand Down
8 changes: 4 additions & 4 deletions packages/msgraph/src/Sharepoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expandReferences } from '@openfn/language-common/util';

import { request, setAuth, setUrl, handleResponse } from './Utils';
import { request, setAuth, getUrl, handleResponse } from './Utils';

/**
* Get a SharePoint site using msgraph API
Expand All @@ -22,7 +22,7 @@ export function getSites(sharepointSite, callback = s => s) {
const resolvePath = resolvedRootSite
? `sites/${resolvedRootSite}`
: 'sites/root';
const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });

const auth = setAuth(accessToken);

Expand Down Expand Up @@ -62,7 +62,7 @@ export function getLists(
? `sites/${siteId}/lists/${listId}`
: `sites/${siteId}/lists`;

const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });

const auth = setAuth(accessToken);
return request(url, { ...auth }).then(response =>
Expand Down Expand Up @@ -109,7 +109,7 @@ export function getItems(
? `sites/${siteId}/drive/items/${itemId}${content}`
: `sites/${siteId}/lists/${listId}/items`;

const url = setUrl({ apiVersion, resolvePath });
const url = getUrl({ apiVersion, resolvePath });

const auth = setAuth(accessToken);

Expand Down
3 changes: 2 additions & 1 deletion packages/msgraph/src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fetch } from 'undici';
import { composeNextState } from '@openfn/language-common';

export function setUrl(urlParams) {
export function getUrl(urlParams) {
const { apiVersion, resolvePath } = urlParams;

if (isValidHttpUrl(resolvePath)) return resolvePath;
Expand Down
5 changes: 1 addition & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43fef71

Please sign in to comment.