From 22e22ae591de670361a53081dde5ecfe7a6abb79 Mon Sep 17 00:00:00 2001 From: Chang-Hung Liang Date: Tue, 17 Dec 2024 15:42:36 +0800 Subject: [PATCH] Move swapi.dev to swapi.info --- example-apps/dynamic-dropdown/.gitignore | 1 + example-apps/dynamic-dropdown/README.md | 2 +- example-apps/dynamic-dropdown/package.json | 2 +- example-apps/dynamic-dropdown/triggers/people.js | 11 ++++++++--- example-apps/dynamic-dropdown/triggers/species.js | 4 ++-- .../generators/templates/dynamic-dropdown/README.md | 2 +- .../templates/dynamic-dropdown/triggers/people.js | 4 ++-- .../templates/dynamic-dropdown/triggers/species.js | 4 ++-- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/example-apps/dynamic-dropdown/.gitignore b/example-apps/dynamic-dropdown/.gitignore index 32dd95d8b..ae6ff4e5e 100644 --- a/example-apps/dynamic-dropdown/.gitignore +++ b/example-apps/dynamic-dropdown/.gitignore @@ -31,6 +31,7 @@ bower_components # Compiled binary addons (https://nodejs.org/api/addons.html) build/ +dist/ # Dependency directories node_modules/ diff --git a/example-apps/dynamic-dropdown/README.md b/example-apps/dynamic-dropdown/README.md index f9fda4be4..b0b35d2a6 100644 --- a/example-apps/dynamic-dropdown/README.md +++ b/example-apps/dynamic-dropdown/README.md @@ -25,6 +25,6 @@ Find out more on the latest docs: https://github.com/zapier/zapier-platform/blob # The "dynamic-dropdown" Template -This example integration uses the [Star Wars API](https://swapi.dev/) to provide a dynamic listing of choices for an `inputField` in a trigger. +This example integration uses the [Star Wars API](https://swapi.info/) to provide a dynamic listing of choices for an `inputField` in a trigger. ![](https://cdn.zappy.app/d985065c5098089795d9b60c77791e12.png) diff --git a/example-apps/dynamic-dropdown/package.json b/example-apps/dynamic-dropdown/package.json index afb1fcc1c..6a15f3889 100644 --- a/example-apps/dynamic-dropdown/package.json +++ b/example-apps/dynamic-dropdown/package.json @@ -10,7 +10,7 @@ "zapier-platform-core": "16.0.0" }, "devDependencies": { - "jest": "^25.5.3" + "jest": "^29.6.0" }, "private": true } diff --git a/example-apps/dynamic-dropdown/triggers/people.js b/example-apps/dynamic-dropdown/triggers/people.js index 6cd801dc8..e61abc4d8 100644 --- a/example-apps/dynamic-dropdown/triggers/people.js +++ b/example-apps/dynamic-dropdown/triggers/people.js @@ -5,15 +5,20 @@ const perform = async (z, bundle) => { // Ideally, we should poll through all the pages of results, but in this // example we're going to omit that part. Thus, this trigger only "see" the // people in their first page of results. - const response = await z.request({ url: 'https://swapi.dev/api/people/' }); - let peopleArray = response.data.results; + const response = await z.request({ url: 'https://swapi.info/api/people/' }); + let peopleArray = response.data; if (bundle.inputData.species_id) { // The Zap's setup has requested a specific species of person. Since the // API/endpoint can't perform the filtering, we'll perform it here, within // the integration, and return the matching objects/records back to Zapier. peopleArray = peopleArray.filter((person) => { - const speciesID = extractID(person.species[0]); + let speciesID; + if (!person.species || !person.species.length) { + speciesID = 1; // Assume human if species is not provided + } else { + speciesID = extractID(person.species[0]); + } return speciesID === bundle.inputData.species_id; }); } diff --git a/example-apps/dynamic-dropdown/triggers/species.js b/example-apps/dynamic-dropdown/triggers/species.js index 8317071dc..73acc60e0 100644 --- a/example-apps/dynamic-dropdown/triggers/species.js +++ b/example-apps/dynamic-dropdown/triggers/species.js @@ -3,7 +3,7 @@ const { extractID } = require('../utils'); // Fetches a list of records from the endpoint const perform = async (z, bundle) => { const request = { - url: 'https://swapi.dev/api/species/', + url: 'https://swapi.info/api/species/', params: {}, }; @@ -13,7 +13,7 @@ const perform = async (z, bundle) => { } const response = await z.request(request); - const speciesArray = response.data.results; + const speciesArray = response.data; return speciesArray.map((species) => { species.id = extractID(species.url); return species; diff --git a/packages/cli/src/generators/templates/dynamic-dropdown/README.md b/packages/cli/src/generators/templates/dynamic-dropdown/README.md index 8566f1ab5..b477ec8d3 100644 --- a/packages/cli/src/generators/templates/dynamic-dropdown/README.md +++ b/packages/cli/src/generators/templates/dynamic-dropdown/README.md @@ -1,5 +1,5 @@ # The "dynamic-dropdown" Template -This example integration uses the [Star Wars API](https://swapi.dev/) to provide a dynamic listing of choices for an `inputField` in a trigger. +This example integration uses the [Star Wars API](https://swapi.info/) to provide a dynamic listing of choices for an `inputField` in a trigger. ![](https://cdn.zappy.app/d985065c5098089795d9b60c77791e12.png) diff --git a/packages/cli/src/generators/templates/dynamic-dropdown/triggers/people.js b/packages/cli/src/generators/templates/dynamic-dropdown/triggers/people.js index 8f264da7e..e61abc4d8 100644 --- a/packages/cli/src/generators/templates/dynamic-dropdown/triggers/people.js +++ b/packages/cli/src/generators/templates/dynamic-dropdown/triggers/people.js @@ -5,8 +5,8 @@ const perform = async (z, bundle) => { // Ideally, we should poll through all the pages of results, but in this // example we're going to omit that part. Thus, this trigger only "see" the // people in their first page of results. - const response = await z.request({ url: 'https://swapi.dev/api/people/' }); - let peopleArray = response.data.results; + const response = await z.request({ url: 'https://swapi.info/api/people/' }); + let peopleArray = response.data; if (bundle.inputData.species_id) { // The Zap's setup has requested a specific species of person. Since the diff --git a/packages/cli/src/generators/templates/dynamic-dropdown/triggers/species.js b/packages/cli/src/generators/templates/dynamic-dropdown/triggers/species.js index 8317071dc..73acc60e0 100644 --- a/packages/cli/src/generators/templates/dynamic-dropdown/triggers/species.js +++ b/packages/cli/src/generators/templates/dynamic-dropdown/triggers/species.js @@ -3,7 +3,7 @@ const { extractID } = require('../utils'); // Fetches a list of records from the endpoint const perform = async (z, bundle) => { const request = { - url: 'https://swapi.dev/api/species/', + url: 'https://swapi.info/api/species/', params: {}, }; @@ -13,7 +13,7 @@ const perform = async (z, bundle) => { } const response = await z.request(request); - const speciesArray = response.data.results; + const speciesArray = response.data; return speciesArray.map((species) => { species.id = extractID(species.url); return species;