mirror of
https://github.com/directus/directus.git
synced 2026-02-04 00:05:02 -05:00
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:
@@ -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, {
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user