-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(airtable): [nan-1909] add airtable operations (#68)
## Describe your changes Adds airtable syncs, actions. ## Issue ticket number and link NAN-1909 ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] External API requests have `retries` - [ ] Pagination is used where appropriate - [ ] The built in `nango.paginate` call is used instead of a `while (true)` loop - [ ] Third party requests are NOT parallelized (this can cause issues with rate limits) - [ ] If a sync requires metadata the `nango.yaml` has `auto_start: false` - [ ] If the sync is a `full` sync then `track_deletes: true` is set
- Loading branch information
1 parent
258306d
commit 5d31fe1
Showing
42 changed files
with
1,252 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { NangoAction, ProxyConfiguration, CreateWebhook, WebhookCreated } from '../../models'; | ||
import type { AirtableWebhookCreatedResponse } from '../types'; | ||
import { createWebhookSchema } from '../schema.zod.js'; | ||
|
||
export default async function runAction(nango: NangoAction, input: CreateWebhook): Promise<WebhookCreated> { | ||
const parsedInput = createWebhookSchema.safeParse(input); | ||
|
||
if (!parsedInput.success) { | ||
for (const error of parsedInput.error.errors) { | ||
await nango.log(`Invalid input provided to create a webhook: ${error.message} at path ${error.path.join('.')}`, { level: 'error' }); | ||
} | ||
|
||
throw new nango.ActionError({ | ||
message: 'Invalid input provided to create a webhook' | ||
}); | ||
} | ||
|
||
const { baseId, specification } = parsedInput.data; | ||
const webhookUrl = await nango.getWebhookURL(); | ||
|
||
const config: ProxyConfiguration = { | ||
// https://airtable.com/developers/web/api/create-a-webhook | ||
endpoint: `/v0/bases/${baseId}/webhooks`, | ||
data: { | ||
notificationUrl: webhookUrl, | ||
specification | ||
}, | ||
retries: 10 | ||
}; | ||
|
||
const response = await nango.post<AirtableWebhookCreatedResponse>(config); | ||
|
||
const { data } = response; | ||
|
||
const { expirationTime, id, macSecretBase64 } = data; | ||
|
||
const metadata = await nango.getMetadata(); | ||
|
||
if (metadata?.['webhooks']) { | ||
await nango.updateMetadata({ | ||
webhooks: { | ||
...metadata['webhooks'], | ||
[id]: macSecretBase64 | ||
} | ||
}); | ||
} else { | ||
await nango.updateMetadata({ | ||
webhooks: { | ||
[id]: macSecretBase64 | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
id, | ||
expirationTime | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { NangoAction, ProxyConfiguration, DeleteWebhook, SuccessResponse } from '../../models'; | ||
import { deleteWebhookSchema } from '../schema.zod.js'; | ||
|
||
interface WebhookMetadata { | ||
webhooks: Record<string, string>; | ||
} | ||
|
||
export default async function runAction(nango: NangoAction, input: DeleteWebhook): Promise<SuccessResponse> { | ||
const parsedInput = deleteWebhookSchema.safeParse(input); | ||
|
||
if (!parsedInput.success) { | ||
for (const error of parsedInput.error.errors) { | ||
await nango.log(`Invalid input provided to delete a webhook: ${error.message} at path ${error.path.join('.')}`, { level: 'error' }); | ||
} | ||
|
||
throw new nango.ActionError({ | ||
message: 'Invalid input provided to delete a webhook' | ||
}); | ||
} | ||
|
||
const config: ProxyConfiguration = { | ||
// https://airtable.com/developers/web/api/delete-a-webhook | ||
endpoint: `/v0/bases/${input.baseId}/webhooks/${input.webhookId}`, | ||
retries: 10 | ||
}; | ||
|
||
await nango.delete(config); | ||
|
||
const metadata = await nango.getMetadata<WebhookMetadata>(); | ||
|
||
if (metadata?.['webhooks']) { | ||
const { [input.webhookId]: _, ...rest } = metadata['webhooks']; | ||
|
||
await nango.updateMetadata({ | ||
webhooks: rest | ||
}); | ||
} | ||
|
||
return { | ||
success: true | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { NangoAction, ProxyConfiguration, BaseId, Webhook, WebhookResponse } from '../../models'; | ||
import type { AirtableWebhook, AirtableWebhookResponse } from '../types'; | ||
|
||
export default async function runAction(nango: NangoAction, input: BaseId): Promise<WebhookResponse> { | ||
if (!input.baseId) { | ||
throw new nango.ActionError({ | ||
message: 'Base ID is required' | ||
}); | ||
} | ||
|
||
const config: ProxyConfiguration = { | ||
// https://airtable.com/developers/web/api/list-webhooks | ||
endpoint: `/v0/bases/${input.baseId}/webhooks`, | ||
retries: 10 | ||
}; | ||
|
||
const response = await nango.get<AirtableWebhookResponse>(config); | ||
|
||
const { data } = response; | ||
|
||
const webhookOutput = data.webhooks.map((aWebhook: AirtableWebhook) => { | ||
const webhook: Webhook = { | ||
id: aWebhook.id, | ||
specification: aWebhook.specification, | ||
cursorForNextPayload: aWebhook.cursorForNextPayload, | ||
lastNotificationResult: aWebhook.lastNotificationResult, | ||
areNotificationsEnabled: aWebhook.areNotificationsEnabled, | ||
lastSuccessfulNotificationTime: aWebhook.lastSuccessfulNotificationTime, | ||
isHookEnabled: aWebhook.isHookEnabled, | ||
expirationTime: aWebhook.expirationTime | ||
}; | ||
|
||
return webhook; | ||
}); | ||
|
||
return { webhooks: webhookOutput }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"baseId": "appaYNlX7K9HdmkDr", | ||
"specification": { | ||
"options": { | ||
"filters": { | ||
"dataTypes": ["tableData"], | ||
"recordChangeScope": "tblQJ3WoaYyxPxm2F" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"id": "apphIX0IHnt7uTvOp", | ||
"name": "Untitled Base", | ||
"permissionLevel": "create" | ||
}, | ||
{ | ||
"id": "appaYNlX7K9HdmkDr", | ||
"name": "Nango Base", | ||
"permissionLevel": "create" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"baseId": "appaYNlX7K9HdmkDr", | ||
"specification": { | ||
"options": { | ||
"filters": { | ||
"dataTypes": ["tableData"], | ||
"recordChangeScope": "tblQJ3WoaYyxPxm2F" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"id": "achNJQRW9mCgVdRPG", | ||
"expirationTime": "2024-10-29T19:38:20.793Z" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"baseId": "appaYNlX7K9HdmkDr", | ||
"webhookId": "achNJQRW9mCgVdRPG" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"success": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"baseId": "appaYNlX7K9HdmkDr" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"webhooks": [ | ||
{ | ||
"id": "achQfrhelikFY4IKb", | ||
"specification": { | ||
"options": { | ||
"filters": { | ||
"recordChangeScope": "tblQJ3WoaYyxPxm2F", | ||
"dataTypes": ["tableData"] | ||
} | ||
} | ||
}, | ||
"cursorForNextPayload": 6, | ||
"lastNotificationResult": { | ||
"success": true, | ||
"completionTimestamp": "2024-10-22T13:18:33.391Z", | ||
"durationMs": 2578.119457, | ||
"retryNumber": 0 | ||
}, | ||
"areNotificationsEnabled": true, | ||
"lastSuccessfulNotificationTime": "2024-10-22T13:18:33.000Z", | ||
"isHookEnabled": true, | ||
"expirationTime": "2024-10-29T13:18:13.002Z" | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
...go/delete/proxy/v0/bases/appaYNlX7K9HdmkDr/webhooks/achNJQRW9mCgVdRPG/delete-webhook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
11 changes: 11 additions & 0 deletions
11
integrations/airtable/mocks/nango/get/integrations/airtable/create-webhook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"data": { | ||
"unique_key": "airtable", | ||
"provider": "airtable", | ||
"display_name": "Airtable", | ||
"logo": "https://app.nango.dev/images/template-logos/airtable.svg", | ||
"webhook_url": null, | ||
"created_at": "2024-10-22T07:50:33.861Z", | ||
"updated_at": "2024-10-22T07:50:33.861Z" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ons/airtable/mocks/nango/get/proxy/v0/bases/appaYNlX7K9HdmkDr/webhooks/list-webhooks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"webhooks": [ | ||
{ | ||
"id": "achQfrhelikFY4IKb", | ||
"specification": { | ||
"options": { | ||
"filters": { | ||
"recordChangeScope": "tblQJ3WoaYyxPxm2F", | ||
"dataTypes": ["tableData"] | ||
} | ||
} | ||
}, | ||
"notificationUrl": "https://h0xqcc9zj1.sharedwithexpose.com/webhook/f790632d-810e-4cbe-a234-ad656418fc70/airtable", | ||
"cursorForNextPayload": 6, | ||
"lastNotificationResult": { | ||
"success": true, | ||
"completionTimestamp": "2024-10-22T13:18:33.391Z", | ||
"durationMs": 2578.119457, | ||
"retryNumber": 0 | ||
}, | ||
"areNotificationsEnabled": true, | ||
"lastSuccessfulNotificationTime": "2024-10-22T13:18:33.000Z", | ||
"isHookEnabled": true, | ||
"expirationTime": "2024-10-29T13:18:13.002Z" | ||
} | ||
] | ||
} |
Oops, something went wrong.