From 8da6ca6b6e7a06305af47c59239591f9fedff347 Mon Sep 17 00:00:00 2001 From: Ben Sykes Date: Mon, 30 Dec 2024 15:26:26 -0800 Subject: [PATCH] Protect against null result --- lib/api.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/api.js b/lib/api.js index b92675c4..13e43bdd 100644 --- a/lib/api.js +++ b/lib/api.js @@ -46,16 +46,16 @@ const createZeroTrustList = (name, items) => /** * Patches an existing list. Remove/append entries to the list. - * + * * API docs: https://developers.cloudflare.com/api/operations/zero-trust-lists-patch-zero-trust-list * @param {string} listId The ID of the list to patch * @param {Object} patch The changes to make * @param {string[]} patch.remove A list of the item values you want to remove. * @param {Object[]} patch.append Items to add to the list. * @param {string} patch.append[].value The domain of an entry. - * @returns - */ -const patchExistingList = (listId, patch) => + * @returns + */ +const patchExistingList = (listId, patch) => requestGateway(`/lists/${listId}`, { method: "PATCH", body: JSON.stringify(patch), @@ -75,9 +75,9 @@ export const synchronizeZeroTrustLists = async (items) => { console.log("Checking existing lists..."); const { result: lists } = await getZeroTrustLists(); - const cgpsLists = lists.filter(({ name }) => name.startsWith("CGPS List")); + const cgpsLists = lists?.filter(({ name }) => name.startsWith("CGPS List")) || []; console.log(`Found ${cgpsLists.length} existing lists. Calculating diffs...`); - + const domainsByList = {}; // Do this sequentially to avoid rate-limits for (const list of cgpsLists) { @@ -293,9 +293,9 @@ export const createZeroTrustRule = async (wirefilterExpression, name = "CGPS Fil * Updates a Zero Trust rule. * * API docs: https://developers.cloudflare.com/api/operations/zero-trust-gateway-rules-update-zero-trust-gateway-rule - * @param {number} id The ID of the rule to be updated. + * @param {number} id The ID of the rule to be updated. * @param {string} wirefilterExpression The expression to be used for the rule. - * @param {string} name The name of the rule. + * @param {string} name The name of the rule. * @param {string[]} filters The filters to be used for the rule. * @returns {Promise} */