From 1e1b573c52484b54e5e08817f38ffa313e6ac761 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 1 Aug 2022 19:34:19 +0800 Subject: [PATCH 01/25] Add integrations table in db --- .../db/migrations/0090.do.integrations.sql | 23 +++++++++++++++++++ .../db/migrations/0090.undo.integrations.sql | 9 ++++++++ 2 files changed, 32 insertions(+) create mode 100755 packages/db/migrations/0090.do.integrations.sql create mode 100755 packages/db/migrations/0090.undo.integrations.sql diff --git a/packages/db/migrations/0090.do.integrations.sql b/packages/db/migrations/0090.do.integrations.sql new file mode 100755 index 000000000..ebe0c368e --- /dev/null +++ b/packages/db/migrations/0090.do.integrations.sql @@ -0,0 +1,23 @@ +-- Type: DO +-- Name: integrations +-- Description: Create integrations table + +BEGIN; + +CREATE TABLE omnivore.integrations ( + id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(), + user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE, + name varchar(50) NOT NULL, + token varchar(255) NOT NULL, + enabled boolean NOT NULL DEFAULT true, + description varchar(255), + url varchar(255), + created_at timestamptz NOT NULL DEFAULT current_timestamp, + updated_at timestamptz NOT NULL DEFAULT current_timestamp, + UNIQUE (user_id, name) +); + +CREATE TRIGGER update_integration_modtime BEFORE UPDATE ON omnivore.integrations + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); + +COMMIT; diff --git a/packages/db/migrations/0090.undo.integrations.sql b/packages/db/migrations/0090.undo.integrations.sql new file mode 100755 index 000000000..00835639a --- /dev/null +++ b/packages/db/migrations/0090.undo.integrations.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: integrations +-- Description: Create integrations table + +BEGIN; + +DROP TABLE IF EXISTS omnivore.integrations; + +COMMIT; From db27ac7d59cd98b01cb27c666b588a0f26e5a383 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 1 Aug 2022 19:40:10 +0800 Subject: [PATCH 02/25] Add integration entity --- packages/api/src/entity/integration.ts | 35 +++++++++++++++++++ .../db/migrations/0090.do.integrations.sql | 2 -- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 packages/api/src/entity/integration.ts diff --git a/packages/api/src/entity/integration.ts b/packages/api/src/entity/integration.ts new file mode 100644 index 000000000..406e820db --- /dev/null +++ b/packages/api/src/entity/integration.ts @@ -0,0 +1,35 @@ +import { + Column, + CreateDateColumn, + Entity, + JoinColumn, + ManyToOne, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from 'typeorm' +import { User } from './user' + +@Entity({ name: 'integrations' }) +export class Integration { + @PrimaryGeneratedColumn('uuid') + id!: string + + @ManyToOne(() => User, { onDelete: 'CASCADE' }) + @JoinColumn({ name: 'user_id' }) + user!: User + + @Column('varchar') + name!: string + + @Column('varchar') + token!: string + + @Column('boolean', { default: true }) + enabled!: boolean + + @CreateDateColumn({ default: () => 'CURRENT_TIMESTAMP' }) + createdAt!: Date + + @UpdateDateColumn({ default: () => 'CURRENT_TIMESTAMP' }) + updatedAt!: Date +} diff --git a/packages/db/migrations/0090.do.integrations.sql b/packages/db/migrations/0090.do.integrations.sql index ebe0c368e..5f5c836ca 100755 --- a/packages/db/migrations/0090.do.integrations.sql +++ b/packages/db/migrations/0090.do.integrations.sql @@ -10,8 +10,6 @@ CREATE TABLE omnivore.integrations ( name varchar(50) NOT NULL, token varchar(255) NOT NULL, enabled boolean NOT NULL DEFAULT true, - description varchar(255), - url varchar(255), created_at timestamptz NOT NULL DEFAULT current_timestamp, updated_at timestamptz NOT NULL DEFAULT current_timestamp, UNIQUE (user_id, name) From e66d047d5104d3df77210b4f3c3fed7920edc1cf Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 1 Aug 2022 21:53:39 +0800 Subject: [PATCH 03/25] Add createIntegration API to the GQL schema --- packages/api/src/entity/integration.ts | 8 +- packages/api/src/generated/graphql.ts | 83 +++++++++++++++++++ packages/api/src/generated/schema.graphql | 35 ++++++++ packages/api/src/schema.ts | 37 +++++++++ .../db/migrations/0090.do.integrations.sql | 8 +- .../db/migrations/0090.undo.integrations.sql | 2 + 6 files changed, 168 insertions(+), 5 deletions(-) diff --git a/packages/api/src/entity/integration.ts b/packages/api/src/entity/integration.ts index 406e820db..c4d2bbc88 100644 --- a/packages/api/src/entity/integration.ts +++ b/packages/api/src/entity/integration.ts @@ -9,6 +9,10 @@ import { } from 'typeorm' import { User } from './user' +export enum IntegrationType { + Readwise = 'READWISE', +} + @Entity({ name: 'integrations' }) export class Integration { @PrimaryGeneratedColumn('uuid') @@ -18,8 +22,8 @@ export class Integration { @JoinColumn({ name: 'user_id' }) user!: User - @Column('varchar') - name!: string + @Column('enum', { enum: IntegrationType }) + type!: IntegrationType @Column('varchar') token!: string diff --git a/packages/api/src/generated/graphql.ts b/packages/api/src/generated/graphql.ts index 1ce355cbd..3a8ca3dc9 100644 --- a/packages/api/src/generated/graphql.ts +++ b/packages/api/src/generated/graphql.ts @@ -331,6 +331,30 @@ export type CreateHighlightSuccess = { highlight: Highlight; }; +export type CreateIntegrationError = { + __typename?: 'CreateIntegrationError'; + errorCodes: Array; +}; + +export enum CreateIntegrationErrorCode { + BadRequest = 'BAD_REQUEST', + InvalidToken = 'INVALID_TOKEN', + NotFound = 'NOT_FOUND', + Unauthorized = 'UNAUTHORIZED' +} + +export type CreateIntegrationInput = { + token: Scalars['String']; + type: IntegrationType; +}; + +export type CreateIntegrationResult = CreateIntegrationError | CreateIntegrationSuccess; + +export type CreateIntegrationSuccess = { + __typename?: 'CreateIntegrationSuccess'; + integration: Integration; +}; + export type CreateLabelError = { __typename?: 'CreateLabelError'; errorCodes: Array; @@ -745,6 +769,19 @@ export type HighlightStats = { highlightCount: Scalars['Int']; }; +export type Integration = { + __typename?: 'Integration'; + createdAt: Scalars['Date']; + enabled: Scalars['Boolean']; + id: Scalars['ID']; + type: IntegrationType; + updatedAt: Scalars['Date']; +}; + +export enum IntegrationType { + Readwise = 'READWISE' +} + export type Label = { __typename?: 'Label'; color: Scalars['String']; @@ -897,6 +934,7 @@ export type Mutation = { createArticleSavingRequest: CreateArticleSavingRequestResult; createHighlight: CreateHighlightResult; createHighlightReply: CreateHighlightReplyResult; + createIntegration: CreateIntegrationResult; createLabel: CreateLabelResult; createNewsletterEmail: CreateNewsletterEmailResult; createReaction: CreateReactionResult; @@ -971,6 +1009,11 @@ export type MutationCreateHighlightReplyArgs = { }; +export type MutationCreateIntegrationArgs = { + input: CreateIntegrationInput; +}; + + export type MutationCreateLabelArgs = { input: CreateLabelInput; }; @@ -2505,6 +2548,11 @@ export type ResolversTypes = { CreateHighlightReplySuccess: ResolverTypeWrapper; CreateHighlightResult: ResolversTypes['CreateHighlightError'] | ResolversTypes['CreateHighlightSuccess']; CreateHighlightSuccess: ResolverTypeWrapper; + CreateIntegrationError: ResolverTypeWrapper; + CreateIntegrationErrorCode: CreateIntegrationErrorCode; + CreateIntegrationInput: CreateIntegrationInput; + CreateIntegrationResult: ResolversTypes['CreateIntegrationError'] | ResolversTypes['CreateIntegrationSuccess']; + CreateIntegrationSuccess: ResolverTypeWrapper; CreateLabelError: ResolverTypeWrapper; CreateLabelErrorCode: CreateLabelErrorCode; CreateLabelInput: CreateLabelInput; @@ -2592,6 +2640,8 @@ export type ResolversTypes = { HighlightStats: ResolverTypeWrapper; ID: ResolverTypeWrapper; Int: ResolverTypeWrapper; + Integration: ResolverTypeWrapper; + IntegrationType: IntegrationType; Label: ResolverTypeWrapper