Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gorgias): implement gorgias user provisioning using only the necessary User fields and add corresponding tests: #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4431,6 +4431,19 @@ integrations:
path: /tickets
group: Tickets
version: 1.0.1
users:
description: |
Fetches the list of users
endpoint:
method: GET
path: /users
group: Users
sync_type: full
track_deletes: true
runs: every 6 hours
output: GorgiasUser
scopes:
- users:read
actions:
create-ticket:
description: |
Expand All @@ -4446,7 +4459,35 @@ integrations:
path: /ticket
group: Tickets
output: Ticket
create-user:
description: >
Creates a new user with a role in Gorgias. Defaults to agent if a role
is not provided
input: GorgiasCreateUser
output: GorgiasUser
endpoint:
method: POST
path: /user
group: Users
scopes:
- users:write
delete-user:
description: Deletes a user in Gorgias
output: SuccessResponse
input: IdEntity
endpoint:
method: DELETE
path: /users
group: Users
scopes:
- users:write
models:
IdEntity:
id: string
SuccessResponse:
success: boolean
ActionResponseError:
message: string
Ticket:
id: number
assignee_user: AssigneeUser | null
Expand Down Expand Up @@ -4578,6 +4619,20 @@ integrations:
body_html: string
body_text: string
id: string
CreateUser:
firstName: string
lastName: string
email: string
GorgiasCreateUser:
firstName: string
lastName: string
email: string
role: admin | agent | basic-agent | lite-agent | observer-agent
GorgiasUser:
id: string
firstName: string
lastName: string
email: string
greenhouse-basic:
syncs:
applications:
Expand Down
53 changes: 53 additions & 0 deletions integrations/gorgias/actions/create-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!-- BEGIN GENERATED CONTENT -->
# Create User

## General Information

- **Description:** Creates a new user with a role in Gorgias. Defaults to agent if a role is not provided

- **Version:** 0.0.1
- **Group:** Users
- **Scopes:** `users:write`
- **Endpoint Type:** Action
- **Code:** [github.com](https://github.com/NangoHQ/integration-templates/tree/main/integrations/gorgias/actions/create-user.ts)


## Endpoint Reference

### Request Endpoint

`POST /user`

### Request Query Parameters

_No request parameters_

### Request Body

```json
{
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"role": "<admin | agent | basic-agent | lite-agent | observer-agent>"
}
```

### Request Response

```json
{
"id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>"
}
```

## Changelog

- [Script History](https://github.com/NangoHQ/integration-templates/commits/main/integrations/gorgias/actions/create-user.ts)
- [Documentation History](https://github.com/NangoHQ/integration-templates/commits/main/integrations/gorgias/actions/create-user.md)

<!-- END GENERATED CONTENT -->

52 changes: 52 additions & 0 deletions integrations/gorgias/actions/create-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { NangoAction, ProxyConfiguration, GorgiasCreateUser, GorgiasUser } from '../../models';
import { gorgiasCreateUserSchema } from '../schema.zod.js';
import type { GorgiasCreateUserReq, GorgiasUserResponse } from '../types';

/**
* Creates a new user in Gorgias.
*
* @param {NangoAction} nango - The Nango action instance.
* @param {GorgiasCreateUser} input - The input data for creating a user.
* @returns {Promise<GorgiasUser>} - A promise that resolves to the created Gorgias user.
* @throws {nango.ActionError} - Throws an error if the input validation fails.
*/
export default async function runAction(nango: NangoAction, input: GorgiasCreateUser): Promise<GorgiasUser> {
const parsedInput = gorgiasCreateUserSchema.safeParse(input);

if (!parsedInput.success) {
for (const error of parsedInput.error.errors) {
await nango.log(`Invalid input provided to create a user: ${error.message} at path ${error.path.join('.')}`, { level: 'error' });
}
throw new nango.ActionError({
message: 'Invalid input provided to create a user'
});
}

const data: GorgiasCreateUserReq = {
name: `${parsedInput.data.firstName} ${parsedInput.data.lastName}`,
email: parsedInput.data.email.toLowerCase(),
role: {
name: parsedInput.data.role || 'agent'
}
};

const config: ProxyConfiguration = {
// https://developers.gorgias.com/reference/create-user
endpoint: '/api/users',
retries: 10,
data
};

const response = await nango.post<GorgiasUserResponse>(config);

const { data: dataResponse } = response;

const user: GorgiasUser = {
id: dataResponse.id.toString(),
firstName: dataResponse.name.split(' ')[0] || '',
lastName: dataResponse.name.split(' ')[1] || '',
email: dataResponse.email
};

return user;
}
46 changes: 46 additions & 0 deletions integrations/gorgias/actions/delete-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- BEGIN GENERATED CONTENT -->
# Delete User

## General Information

- **Description:** Deletes a user in Gorgias
- **Version:** 0.0.1
- **Group:** Users
- **Scopes:** `users:write`
- **Endpoint Type:** Action
- **Code:** [github.com](https://github.com/NangoHQ/integration-templates/tree/main/integrations/gorgias/actions/delete-user.ts)


## Endpoint Reference

### Request Endpoint

`DELETE /users`

### Request Query Parameters

_No request parameters_

### Request Body

```json
{
"id": "<string>"
}
```

### Request Response

```json
{
"success": "<boolean>"
}
```

## Changelog

- [Script History](https://github.com/NangoHQ/integration-templates/commits/main/integrations/gorgias/actions/delete-user.ts)
- [Documentation History](https://github.com/NangoHQ/integration-templates/commits/main/integrations/gorgias/actions/delete-user.md)

<!-- END GENERATED CONTENT -->

30 changes: 30 additions & 0 deletions integrations/gorgias/actions/delete-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { NangoAction, ProxyConfiguration, SuccessResponse, IdEntity } from '../../models';

/**
* Deletes a user based on the provided email address.
*
* @param {NangoAction} nango - The Nango action instance.
* @param {EmailEntity} input - The input containing the email of the user to be deleted.
* @throws {nango.ActionError} - Throws an error if the email is not provided.
*
* {@link https://developers.gorgias.com/reference/delete-user} for more information on the Gorgias API endpoint.
*/
export default async function runAction(nango: NangoAction, input: IdEntity): Promise<SuccessResponse> {
if (!input.id) {
throw new nango.ActionError({
message: 'Id is required to delete a user'
});
}

const config: ProxyConfiguration = {
// https://developers.gorgias.com/reference/delete-user
endpoint: `/api/users/${input.id}`,
retries: 10
};

await nango.delete(config);

return {
success: true
};
}
6 changes: 6 additions & 0 deletions integrations/gorgias/fixtures/create-user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"email": "Johndo2l@testdomain.tld",
"firstName": "John",
"lastName": "Doe",
"role": "agent"
}
3 changes: 3 additions & 0 deletions integrations/gorgias/fixtures/delete-user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "455843658"
}
6 changes: 6 additions & 0 deletions integrations/gorgias/mocks/create-user/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"email": "Johndo2l@testdomain.tld",
"firstName": "John",
"lastName": "Doe",
"role": "agent"
}
6 changes: 6 additions & 0 deletions integrations/gorgias/mocks/create-user/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "455925547",
"firstName": "John",
"lastName": "Doe",
"email": "johndo2l@testdomain.tld"
}
3 changes: 3 additions & 0 deletions integrations/gorgias/mocks/delete-user/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": 455843658
}
3 changes: 3 additions & 0 deletions integrations/gorgias/mocks/delete-user/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"success": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"method": "delete",
"endpoint": "api/users/454003867",
"requestIdentityHash": "4541b3ef41998ebf4ba8bbdc07e5a0e661de7173",
"requestIdentity": {
"method": "delete",
"endpoint": "api/users/454003867",
"params": [],
"headers": []
},
"response": "",
"status": 204,
"headers": {
"date": "Thu, 16 Jan 2025 16:31:15 GMT",
"connection": "keep-alive",
"cf-ray": "902f7ea29d870372-NBO",
"cf-cache-status": "DYNAMIC",
"access-control-allow-origin": "*",
"strict-transport-security": "max-age=5184000; includeSubDomains",
"access-control-expose-headers": "Authorization, Etag, Content-Type, Content-Length, X-Nango-Signature, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset",
"content-security-policy-report-only": "default-src 'self' https://app.nango.dev https://api.nango.dev;child-src 'self';connect-src 'self' https://*.google-analytics.com https://*.sentry.io https://app.nango.dev https://api.nango.dev wss://api.nango.dev/ https://*.posthog.com https://bluegrass.nango.dev;font-src 'self' https://*.googleapis.com https://*.gstatic.com;frame-src 'self' https://accounts.google.com https://app.nango.dev https://api.nango.dev https://connect.nango.dev https://www.youtube.com;img-src 'self' data: https://app.nango.dev https://api.nango.dev https://*.google-analytics.com https://*.googleapis.com https://*.posthog.com https://img.logo.dev https://*.ytimg.com;manifest-src 'self';media-src 'self';object-src 'self';script-src 'self' 'unsafe-eval' 'unsafe-inline' https://app.nango.dev https://api.nango.dev https://*.google-analytics.com https://*.googleapis.com https://apis.google.com https://*.posthog.com https://www.youtube.com https://shoegaze.nango.dev;style-src blob: 'self' 'unsafe-inline' https://*.googleapis.com https://app.nango.dev https://api.nango.dev;worker-src blob: 'self' https://app.nango.dev https://api.nango.dev https://*.googleapis.com https://*.posthog.com;base-uri 'self';form-action 'self';frame-ancestors 'self';script-src-attr 'none';upgrade-insecure-requests",
"rndr-id": "6380cb49-dff3-478c",
"x-content-type-options": "nosniff",
"x-dns-prefetch-control": "off",
"x-download-options": "noopen",
"x-frame-options": "SAMEORIGIN",
"x-ratelimit-limit": "2400",
"x-ratelimit-remaining": "2383",
"x-ratelimit-reset": "1737045094",
"x-render-origin-server": "Render",
"x-xss-protection": "0",
"vary": "Accept-Encoding",
"server": "cloudflare",
"alt-svc": "h3=\":443\"; ma=86400"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"method": "delete",
"endpoint": "api/users/455843658",
"requestIdentityHash": "7dcd1de4b5f46d6b29659d53227eab98bb2f2729",
"requestIdentity": {
"method": "delete",
"endpoint": "api/users/455843658",
"params": [],
"headers": []
},
"response": "",
"status": 204,
"headers": {
"date": "Thu, 16 Jan 2025 17:48:09 GMT",
"connection": "keep-alive",
"cf-ray": "902fef4c4d4ab195-NBO",
"cf-cache-status": "DYNAMIC",
"access-control-allow-origin": "*",
"strict-transport-security": "max-age=5184000; includeSubDomains",
"access-control-expose-headers": "Authorization, Etag, Content-Type, Content-Length, X-Nango-Signature, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset",
"content-security-policy-report-only": "default-src 'self' https://app.nango.dev https://api.nango.dev;child-src 'self';connect-src 'self' https://*.google-analytics.com https://*.sentry.io https://app.nango.dev https://api.nango.dev wss://api.nango.dev/ https://*.posthog.com https://bluegrass.nango.dev;font-src 'self' https://*.googleapis.com https://*.gstatic.com;frame-src 'self' https://accounts.google.com https://app.nango.dev https://api.nango.dev https://connect.nango.dev https://www.youtube.com;img-src 'self' data: https://app.nango.dev https://api.nango.dev https://*.google-analytics.com https://*.googleapis.com https://*.posthog.com https://img.logo.dev https://*.ytimg.com;manifest-src 'self';media-src 'self';object-src 'self';script-src 'self' 'unsafe-eval' 'unsafe-inline' https://app.nango.dev https://api.nango.dev https://*.google-analytics.com https://*.googleapis.com https://apis.google.com https://*.posthog.com https://www.youtube.com https://shoegaze.nango.dev;style-src blob: 'self' 'unsafe-inline' https://*.googleapis.com https://app.nango.dev https://api.nango.dev;worker-src blob: 'self' https://app.nango.dev https://api.nango.dev https://*.googleapis.com https://*.posthog.com;base-uri 'self';form-action 'self';frame-ancestors 'self';script-src-attr 'none';upgrade-insecure-requests",
"rndr-id": "ffd3bd60-42a4-493f",
"x-content-type-options": "nosniff",
"x-dns-prefetch-control": "off",
"x-download-options": "noopen",
"x-frame-options": "SAMEORIGIN",
"x-ratelimit-limit": "2400",
"x-ratelimit-remaining": "2396",
"x-ratelimit-reset": "1737049745",
"x-render-origin-server": "Render",
"x-xss-protection": "0",
"vary": "Accept-Encoding",
"server": "cloudflare",
"alt-svc": "h3=\":443\"; ma=86400"
}
}
Loading
Loading