Skip to content

Commit

Permalink
chore: run script to update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wallen committed Sep 23, 2024
1 parent 435c73d commit 86307de
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
30 changes: 3 additions & 27 deletions samples/client/petstore/zapier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ This generator generates a partial implementation of a zapier integration from a

It's a partial integration because you have to put in some code for it to be 100% complete, code that depends only on how your api is structured.

Here there are all the parts you need to complete by yourself:
Here there are all the parts you need to complete by yourself:

### 1) **utils/utils.js** isSearchAction method

This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).

```
const isSearchAction = (key) => {
// TODO: custom logic
Expand All @@ -20,7 +18,6 @@ const isSearchAction = (key) => {
```

### 2) **utils/utils.js** searchMiddleware method

This method has to return an array of resources (searches must return an array), if you have pagination or you api returns an array inside nested fields, here you have to extract the array.

```
Expand All @@ -30,34 +27,13 @@ const searchMiddleware = (action) => {
}
```

### 3) **utils/utils.js** isTrigger method

This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).

```
const isTrigger = (key) => {
// TODO: custom logic
return false
}
```

### 4) **utils/utils.js** searchMiddleware method

```
const triggerMiddleware = (action) => {
return action
}
```

### 3) **authentication.js**

This file must be written completely according to your api authentication, you can get it generated automatically by creating the integration on the zapier website and filling the requested data, or you can build it yourself following [this guide](https://platform.zapier.com/cli_tutorials/getting-started#adding-authentication).

## Samples
To get your app made public on zapier you must provide a sample (json example response) for each of your actions, these samples get automatically generated by this generator but you have to have actual response examples in you openapi file.

To get your app made public on zapier you must provide a sample (json example response) for each of your actions, these samples get automatically generated by this generator but you have to have actual response examples in you openapi file.

For example:
For example:

```
CreateUserResponse:
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/zapier/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const authentication = require('./authentication');
const { searchActions, createActions } = require('./operations/actions');
const { searchActions, createActions, triggers } = require('./operations/actions');

module.exports = {
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,
authentication: authentication,
searches: searchActions(),
creates: createActions(),
triggers: triggers(),
};
5 changes: 3 additions & 2 deletions samples/client/petstore/zapier/operations/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const PetApi = require('../apis/PetApi');
const StoreApi = require('../apis/StoreApi');
const UserApi = require('../apis/UserApi');
const { searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');

const actions = {
[PetApi.addPet.key]: PetApi.addPet,
Expand Down Expand Up @@ -29,4 +29,5 @@ const actions = {
module.exports = {
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
createActions: () => Object.entries(actions).reduce((actions, [key, value]) => !isSearchAction(key) ? {...actions, [key]: value} : actions, {}),
}
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
}
11 changes: 11 additions & 0 deletions samples/client/petstore/zapier/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const requestOptionsMiddleware = (z, bundle, requestOptions) => {
return requestOptions
}

const isTrigger = (key) => {
// TODO: custom logic
return false
}

const triggerMiddleware = (action) => {
return action
}

module.exports = {
replacePathParameters: replacePathParameters,
childMapping: childMapping,
Expand All @@ -39,4 +48,6 @@ module.exports = {
isSearchAction: isSearchAction,
searchMiddleware: searchMiddleware,
requestOptionsMiddleware: requestOptionsMiddleware,
isTrigger: isTrigger,
triggerMiddleware: triggerMiddleware,
}

0 comments on commit 86307de

Please sign in to comment.