Skip to content

Commit

Permalink
Protect against null result
Browse files Browse the repository at this point in the history
  • Loading branch information
bsyk committed Dec 30, 2024
1 parent 8fd9ab4 commit 8da6ca6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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) {
Expand Down Expand Up @@ -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<Object>}
*/
Expand Down

0 comments on commit 8da6ca6

Please sign in to comment.