From 533f707b72dfa39f4a150ba40196ace8ea4326d0 Mon Sep 17 00:00:00 2001 From: Nick W Forsberg <456363+seventy6@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:44:02 +0100 Subject: [PATCH 1/5] fixed date issue --- js/npm/api-keys/createKey.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/npm/api-keys/createKey.js b/js/npm/api-keys/createKey.js index c5ae981..e293857 100644 --- a/js/npm/api-keys/createKey.js +++ b/js/npm/api-keys/createKey.js @@ -17,7 +17,7 @@ async function createApiKeySample() { featureFlagOne: true, featureFlagTwo: false, }, - expiry: new Date("2023-09-01 00:00:00"), // optional expiry date + expiry: "2023-09-01 00:00:00", // optional expiry date rateLimitConfigs: { rateLimit: 60, rateLimitTtl: 60, From 3a769754c20fb6032119fbfeeaa7f1385aee18da Mon Sep 17 00:00:00 2001 From: Nick W Forsberg <456363+seventy6@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:49:56 +0100 Subject: [PATCH 2/5] - needed to use a more dynamic name example - null needs to be "null" on customUserId --- js/npm/api-keys/fetchKeys.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/js/npm/api-keys/fetchKeys.js b/js/npm/api-keys/fetchKeys.js index 4abac0c..611e02b 100644 --- a/js/npm/api-keys/fetchKeys.js +++ b/js/npm/api-keys/fetchKeys.js @@ -2,36 +2,34 @@ require("dotenv").config(); const TheAuthAPI = require("theauthapi").default; const apiUrl = process.env.production - ? "https://api.theauthapi.com" - : process.env.TESTING_URL; + ? "https://api.theauthapi.com" + : process.env.TESTING_URL; const theAuthAPI = new TheAuthAPI(process.env.ACCESS_TOKEN, { host: apiUrl }); - async function fetchKeysSample() { // fetch all api keys const apiKeys = await theAuthAPI.apiKeys.getKeys(); - console.log('all keys', apiKeys); + console.log("all keys", apiKeys); - // fetch keys with a specific name + // fetch keys with a specific name (1st one from the list returned previously) const nameFilteredKeys = await theAuthAPI.apiKeys.getKeys({ - name: "new api key" + name: apiKeys[0].name, }); - console.log('Keys filtered using name', nameFilteredKeys); + console.log("Keys filtered using name", nameFilteredKeys); // fetch keys where customUserId is null const customUserIdFilteredKey = await theAuthAPI.apiKeys.getKeys({ - customUserId: null, - }) - console.log('Keys filtered using customUserId', customUserIdFilteredKey); + customUserId: "null", + }); + console.log("Keys filtered using customUserId", customUserIdFilteredKey); // fetch inactive (revoked) keys const inactiveKeys = await theAuthAPI.apiKeys.getKeys({ isActive: false, - }) - console.log('Inactive (revoked) keys', inactiveKeys); + }); + console.log("Inactive (revoked) keys", inactiveKeys); } (async () => { await fetchKeysSample(); })(); - From 21f7bfabb26f721847d454b515f80331aa9d52b0 Mon Sep 17 00:00:00 2001 From: Nick W Forsberg <456363+seventy6@users.noreply.github.com> Date: Mon, 12 Sep 2022 13:52:32 +0100 Subject: [PATCH 3/5] made the name search dynamic --- js/axios/api-keys/fetchKeys.js | 47 ++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/js/axios/api-keys/fetchKeys.js b/js/axios/api-keys/fetchKeys.js index 7a7996c..694f927 100644 --- a/js/axios/api-keys/fetchKeys.js +++ b/js/axios/api-keys/fetchKeys.js @@ -9,13 +9,15 @@ const projectId = process.env.PROJECT_ID; async function fetchApiKeys(filters) { try { - const {data} = await axios - .get(`${apiUrl}/api-keys${filters ? `?${filters}` : ''}`, { + const { data } = await axios.get( + `${apiUrl}/api-keys${filters ? `?${filters}` : ""}`, + { headers: { ContentType: "application/json", "x-api-key": accessKey, }, - }); + } + ); return data; } catch (error) { if (error.response) { @@ -27,8 +29,9 @@ async function fetchApiKeys(filters) { } function getFiltersQuery(filters) { - return Object.entries(filters).map(([key, value]) => `${key}=${value}`) - .join('&'); + return Object.entries(filters) + .map(([key, value]) => `${key}=${value}`) + .join("&"); } const filters = ""; @@ -40,23 +43,29 @@ const filters = ""; (async () => { // fetch all keys const apiKeys = await fetchApiKeys(filters); - console.log('All Keys', apiKeys); + console.log("All Keys", apiKeys); - // get keys with a specific name - const nameFilteredKeys = await fetchApiKeys(getFiltersQuery({ - name: "new api key", - })); - console.log('Keys filtered using name', nameFilteredKeys); + // fetch keys with a specific name (1st one from the list returned previously) + const nameFilteredKeys = await fetchApiKeys( + getFiltersQuery({ + name: apiKeys[0].name, + }) + ); + console.log("Keys filtered using name", nameFilteredKeys); // fetch keys where customUserId is null - const customUserIdFilteredKey = await fetchApiKeys(getFiltersQuery({ - customUserId: null, - })); - console.log('Keys filtered using customUserId', customUserIdFilteredKey); + const customUserIdFilteredKey = await fetchApiKeys( + getFiltersQuery({ + customUserId: null, + }) + ); + console.log("Keys filtered using customUserId", customUserIdFilteredKey); // fetch inactive (revoked) keys - const inactiveKeys = await fetchApiKeys(getFiltersQuery({ - isActive: false, - })); - console.log('Inactive (revoked) keys', inactiveKeys); + const inactiveKeys = await fetchApiKeys( + getFiltersQuery({ + isActive: false, + }) + ); + console.log("Inactive (revoked) keys", inactiveKeys); })(); From 9731188961329d5ad832944c1580c04ed32c4736 Mon Sep 17 00:00:00 2001 From: Nick W Forsberg <456363+seventy6@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:40:24 +0100 Subject: [PATCH 4/5] fixed issue https://github.com/thatapicompany/theauthapi-code-samples/pull/2/files/21f7bfabb26f721847d454b515f80331aa9d52b0#r968409392 --- js/axios/api-keys/fetchKeys.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/axios/api-keys/fetchKeys.js b/js/axios/api-keys/fetchKeys.js index 694f927..a668de4 100644 --- a/js/axios/api-keys/fetchKeys.js +++ b/js/axios/api-keys/fetchKeys.js @@ -48,7 +48,8 @@ const filters = ""; // fetch keys with a specific name (1st one from the list returned previously) const nameFilteredKeys = await fetchApiKeys( getFiltersQuery({ - name: apiKeys[0].name, + //name: apiKeys[0].name, + name: apiKeys.length === 0 ? "YOUR_NAME_FILTER" : apiKeys[0].name, }) ); console.log("Keys filtered using name", nameFilteredKeys); From 68392236213dc684f5ba0a817f6660fc7a31702c Mon Sep 17 00:00:00 2001 From: Nick W Forsberg <456363+seventy6@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:42:10 +0100 Subject: [PATCH 5/5] resolved empty name issue --- js/axios/api-keys/fetchKeys.js | 1 - js/npm/api-keys/fetchKeys.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/axios/api-keys/fetchKeys.js b/js/axios/api-keys/fetchKeys.js index a668de4..d85dfdd 100644 --- a/js/axios/api-keys/fetchKeys.js +++ b/js/axios/api-keys/fetchKeys.js @@ -48,7 +48,6 @@ const filters = ""; // fetch keys with a specific name (1st one from the list returned previously) const nameFilteredKeys = await fetchApiKeys( getFiltersQuery({ - //name: apiKeys[0].name, name: apiKeys.length === 0 ? "YOUR_NAME_FILTER" : apiKeys[0].name, }) ); diff --git a/js/npm/api-keys/fetchKeys.js b/js/npm/api-keys/fetchKeys.js index 611e02b..c07dab6 100644 --- a/js/npm/api-keys/fetchKeys.js +++ b/js/npm/api-keys/fetchKeys.js @@ -13,7 +13,7 @@ async function fetchKeysSample() { // fetch keys with a specific name (1st one from the list returned previously) const nameFilteredKeys = await theAuthAPI.apiKeys.getKeys({ - name: apiKeys[0].name, + name: apiKeys.length === 0 ? "YOUR_NAME_FILTER" : apiKeys[0].name, }); console.log("Keys filtered using name", nameFilteredKeys);