Update dependencies of gatsby-source-directus (#7523)

* basic gatsby source plugin fix

* update import of sdk

* remove tar

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
Jacob Rienstra
2021-08-20 09:45:37 -04:00
committed by GitHub
parent 301db2e120
commit cbefa74070
2 changed files with 16 additions and 34 deletions

View File

@@ -1,28 +1,11 @@
const invariant = require('invariant');
const Directus = require('@directus/sdk-js');
const { sourceNodes } = require('@lnfusion/gatsby-source-graphql');
const { Directus } = require('@directus/sdk');
const { sourceNodes } = require('gatsby-source-graphql/gatsby-node');
const { createRemoteFileNode } = require('gatsby-source-filesystem');
const ms = require('ms');
const chalk = require('chalk');
/**
* Stores authentication data in memory
*/
class MemoryStore {
constructor() {
this.values = {};
}
async getItem(key) {
return this.values[key];
}
async setItem(key, value) {
this.values[key] = value;
}
}
/**
* Normalizes Directus urls.
*/
@@ -114,17 +97,12 @@ exports.sourceNodes = async (gatsby, options) => {
`can be either a number (seconds) or a string (5s, 1m, ...)`
);
const directus = new Directus(endpoints.base, {
auth: {
mode: 'json',
autoRefresh: true,
storage: new MemoryStore(),
},
});
const directus = new Directus(endpoints.base);
let authResult;
if (hasAuth && !hasToken) {
try {
await directus.auth.login({
authResult = await directus.auth.login({
email: auth?.email,
password: auth?.password,
});
@@ -141,13 +119,17 @@ exports.sourceNodes = async (gatsby, options) => {
Object.assign(obj, (await graphql?.headers()) || {});
}
if (!hasToken) {
return obj;
if (hasToken) {
return Object.assign(obj, {
Authorization: `Bearer ${auth?.token}`,
});
}
return Object.assign(obj, {
Authorization: `Bearer ${auth?.token}`,
});
if (authResult?.access_token) {
return Object.assign(obj, {
Authorization: `Bearer ${authResult?.access_token}`,
});
}
};
return await sourceNodes(gatsby, {

View File

@@ -10,10 +10,10 @@
"directus"
],
"dependencies": {
"@directus/sdk-js": "9.0.0-rc.53",
"@lnfusion/gatsby-source-graphql": "0.0.4",
"@directus/sdk": "^9.0.0-rc.90",
"chalk": "4.1.2",
"gatsby-source-filesystem": "3.12.0",
"gatsby-source-graphql": "^3.12.0",
"invariant": "2.2.4",
"ms": "2.1.3"
},