diff --git a/js/axios/api-keys/fetchKeys.js b/js/axios/api-keys/fetchKeys.js index 7a7996c..d85dfdd 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.length === 0 ? "YOUR_NAME_FILTER" : 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); })(); 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, diff --git a/js/npm/api-keys/fetchKeys.js b/js/npm/api-keys/fetchKeys.js index 4abac0c..c07dab6 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.length === 0 ? "YOUR_NAME_FILTER" : 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(); })(); -