Skip to content

Commit

Permalink
Merge pull request #19 from NangoHQ/khaliq/nan-1762-fix-linting-issue…
Browse files Browse the repository at this point in the history
…s-in-the-integration-templates

fix(lint): [nan-1762] fix linting issues in the integration templates
  • Loading branch information
khaliqgant authored Oct 1, 2024
2 parents 62ce214 + 781eb27 commit 8f11de1
Show file tree
Hide file tree
Showing 78 changed files with 4,546 additions and 1,512 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"rules": {
"@nangohq/custom-integrations-linting/no-console-log": "error",
//"@nangohq/custom-integrations-linting/no-object-casting": "warn",
"@nangohq/custom-integrations-linting/no-object-casting": "warn",
"@nangohq/custom-integrations-linting/no-value-modification": "warn",
"@nangohq/custom-integrations-linting/no-while-true": "warn",
"@nangohq/custom-integrations-linting/proxy-call-retries": "error",
Expand Down
97 changes: 74 additions & 23 deletions flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,8 @@ integrations:
- https://www.googleapis.com/auth/admin.directory.user.readonly
workspace-users:
runs: every hour
input: Metadata
auto_start: false
output: User
sync_type: full
endpoint: GET /google/workspace-users
Expand All @@ -1613,6 +1615,11 @@ integrations:
- https://www.googleapis.com/auth/admin.directory.user.readonly
- https://www.googleapis.com/auth/admin.directory.user.security
models:
Metadata:
orgsToSync: OrgToSync[]
OrgToSync:
id: string
path: string
OrganizationalUnit:
id: string
name: string
Expand Down Expand Up @@ -2912,12 +2919,16 @@ integrations:
array of organization ids.
Details: full refresh, doesn't support deletes, goes back all time,
metadata is required.
input: Metadata
auto_start: false
output: User
sync_type: full
endpoint: GET /microsoft-teams/microsoft-users
scopes:
- User.Read.All
models:
Metadata:
orgsToSync: string[]
OrganizationalUnit:
id: string
name: string
Expand Down Expand Up @@ -3254,40 +3265,80 @@ integrations:
setPassword: boolean
notion:
syncs:
pages:
runs: every 6 hours
description: |
Sync pages, subpages, database entries, entries of
sub-databases and retrieve only the text content and ignores
images, files and other blocks that do not have
a `rich_text` property.
output: NotionPage
sync_type: incremental
endpoint: GET /notion/pages
rich-pages:
runs: every 6 hours
content-metadata:
runs: every 1h
track_deletes: true
description: |
Sync pages, subpages, database entries, entries of
sub-databases and maps to full markdown. It transforms
images, tables, uploaded files, etc into their markdown counterparts.
output: NotionRichPage
sync_type: incremental
endpoint: GET /notion/rich-pages
Sync pages and databases metadata to further fetch the content
using a dedicated action
output: ContentMetadata
sync_type: full
endpoint: GET /metadata
actions:
fetch-rich-page:
description: >
Fetch a specific page in Notion by passing a pageId. This action
fetches a page,
and its content and converts it into a full markdown. It transforms
images,
tables, uploaded files, etc., into their markdown counterparts,
providing a complete markdown.
input: RichPageInput
output: RichPage
endpoint: GET /fetch-rich-page
fetch-database:
description: >
Fetch a specific Notion database by passing in the database id. This
action fetches
the database and converts it into a CSV string.
input: DatabaseInput
output: Database
endpoint: GET /fetch-database
fetch-content-metadata:
description: >
Retrieve the entity type as well as an id for a Notion entity to later
call
fetch-database or fetch-rich-page based on the type.
input: UrlOrId
output: ContentMetadata
endpoint: GET /fetch-content-metadata
models:
NotionPage:
RichPageInput:
pageId: string
ContentMetadata:
id: string
url: string
content: string
parent_page_id: string | undefined
NotionRichPage:
path?: string
type: page | database
last_modified: string
title?: string
parent_id?: string | undefined
RichPage:
id: string
path: string
title: string
content: string
contentType: string
meta: object
last_modified: string
parent_id?: string | undefined
DatabaseInput:
databaseId: string
DatabaseEntry:
__string: string
Database:
id: string
path: string
title: string
meta: object
last_modified: string
entries: DatabaseEntry[]
UrlOrId:
url?: string
id?: string
pipedrive:
syncs:
activities:
Expand Down
2 changes: 1 addition & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export {};

declare global {
var vitest: {
NangoSyncMock: new (config: { name: string; Model: string }) => any;
NangoSyncMock: new (config: { dirname: string; name: string; Model: string }) => any;
};
}
23 changes: 22 additions & 1 deletion integrations/calendly/tests/calendly-event-invitees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@ describe("calendly event-invitees tests", () => {
name: "event-invitees",
Model: "EventInvitee"
});

const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave');

it("should get, map correctly the data and batchSave the result", async () => {
await fetchData(nangoMock);

const batchSaveData = await nangoMock.getBatchSaveData();
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventInvitee");

const totalCalls = batchSaveSpy.mock.calls.length;

if (totalCalls > 1) {
const splitSize = Math.ceil(batchSaveData.length / totalCalls);

const splitBatchSaveData = [];
for (let i = 0; i < totalCalls; i++) {
const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize);
splitBatchSaveData.push(chunk);
}

splitBatchSaveData.forEach((data, index) => {
expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data);
});

} else {
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventInvitee");
}
});

it('should get, map correctly the data and batchDelete the result', async () => {
Expand Down
23 changes: 22 additions & 1 deletion integrations/calendly/tests/calendly-event-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@ describe("calendly event-types tests", () => {
name: "event-types",
Model: "EventType"
});

const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave');

it("should get, map correctly the data and batchSave the result", async () => {
await fetchData(nangoMock);

const batchSaveData = await nangoMock.getBatchSaveData();
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventType");

const totalCalls = batchSaveSpy.mock.calls.length;

if (totalCalls > 1) {
const splitSize = Math.ceil(batchSaveData.length / totalCalls);

const splitBatchSaveData = [];
for (let i = 0; i < totalCalls; i++) {
const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize);
splitBatchSaveData.push(chunk);
}

splitBatchSaveData.forEach((data, index) => {
expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data);
});

} else {
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "EventType");
}
});

it('should get, map correctly the data and batchDelete the result', async () => {
Expand Down
23 changes: 22 additions & 1 deletion integrations/calendly/tests/calendly-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@ describe("calendly events tests", () => {
name: "events",
Model: "Event"
});

const batchSaveSpy = vi.spyOn(nangoMock, 'batchSave');

it("should get, map correctly the data and batchSave the result", async () => {
await fetchData(nangoMock);

const batchSaveData = await nangoMock.getBatchSaveData();
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Event");

const totalCalls = batchSaveSpy.mock.calls.length;

if (totalCalls > 1) {
const splitSize = Math.ceil(batchSaveData.length / totalCalls);

const splitBatchSaveData = [];
for (let i = 0; i < totalCalls; i++) {
const chunk = batchSaveData.slice(i * splitSize, (i + 1) * splitSize);
splitBatchSaveData.push(chunk);
}

splitBatchSaveData.forEach((data, index) => {
expect(batchSaveSpy?.mock.calls[index][0]).toEqual(data);
});

} else {
expect(nangoMock.batchSave).toHaveBeenCalledWith(batchSaveData, "Event");
}
});

it('should get, map correctly the data and batchDelete the result', async () => {
Expand Down
7 changes: 7 additions & 0 deletions integrations/google/nango.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ integrations:
- https://www.googleapis.com/auth/admin.directory.user.readonly
workspace-users:
runs: every hour
input: Metadata
auto_start: false
output: User
sync_type: full
endpoint: GET /google/workspace-users
Expand All @@ -24,6 +26,11 @@ integrations:
- https://www.googleapis.com/auth/admin.directory.user.readonly
- https://www.googleapis.com/auth/admin.directory.user.security
models:
Metadata:
orgsToSync: OrgToSync[]
OrgToSync:
id: string
path: string
OrganizationalUnit:
id: string
name: string
Expand Down
80 changes: 6 additions & 74 deletions integrations/google/syncs/workspace-users.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,5 @@
import type { NangoSync, User } from '../../models';

interface DirectoryUsersResponse {
kind: string;
etag: string;
users: DirectoryUser[];
}

interface DirectoryUser {
kind: string;
id: string;
etag: string;
primaryEmail: string;
name: Name;
isAdmin: boolean;
isDelegatedAdmin: boolean;
lastLoginTime: string;
creationTime: string;
deletionTime?: string;
agreedToTerms: boolean;
suspended: boolean;
archived: boolean;
changePasswordAtNextLogin: boolean;
ipWhitelisted: boolean;
emails: Email[];
languages: Language[];
aliases?: string[];
nonEditableAliases?: string[];
customerId: string;
orgUnitPath: string;
isMailboxSetup: boolean;
isEnrolledIn2Sv: boolean;
isEnforcedIn2Sv: boolean;
includeInGlobalAddressList: boolean;
thumbnailPhotoUrl?: string;
thumbnailPhotoEtag?: string;
recoveryEmail?: string;
recoveryPhone?: string;
phones?: Phone[];
}

interface Name {
givenName: string;
familyName: string;
fullName: string;
}

interface Email {
address: string;
type: string;
primary?: boolean;
}

interface Language {
languageCode: string;
preference: string;
}

interface Phone {
value: string;
type: string;
customType?: string;
}

interface OrgToSync {
id: string;
path: string;
}

interface Metadata {
orgsToSync: OrgToSync[];
}
import type { NangoSync, User, Metadata, OrgToSync } from '../../models';
import type { DirectoryUsersResponse } from '../types';

export default async function fetchData(nango: NangoSync) {
const metadata = await nango.getMetadata<Metadata>();
Expand Down Expand Up @@ -98,7 +28,7 @@ async function fetchAndUpdateUsers(nango: NangoSync, orgUnit: OrgToSync | null,

let pageToken: string = '';
do {
const suspendedUsers: User[] = [] as User[];
const suspendedUsers: User[] = [];

const params = {
customer: 'my_customer',
Expand Down Expand Up @@ -167,6 +97,8 @@ async function fetchAndUpdateUsers(nango: NangoSync, orgUnit: OrgToSync | null,
await nango.batchDelete<User>(suspendedUsers, 'User');
}
}
pageToken = data.nextPageToken as string;
if (data.nextPageToken) {
pageToken = data.nextPageToken;
}
} while (pageToken);
}
Loading

0 comments on commit 8f11de1

Please sign in to comment.