From 9fbeaceeb29ae8ba5de422a8e86cc30f71ed38ed Mon Sep 17 00:00:00 2001 From: Mathias Vagni Date: Thu, 19 Sep 2024 07:54:52 +0200 Subject: [PATCH 1/3] Add support for creating label types --- .changeset/nice-phones-battle.md | 5 + src/client.ts | 2263 +++++++++++---------- src/graphql/mutations/createLabelType.gql | 10 + src/graphql/types.ts | 8 + src/webhooks/webhook-schema.json | 4 +- src/webhooks/webhook-schema.ts | 2 +- 6 files changed, 1183 insertions(+), 1109 deletions(-) create mode 100644 .changeset/nice-phones-battle.md create mode 100644 src/graphql/mutations/createLabelType.gql diff --git a/.changeset/nice-phones-battle.md b/.changeset/nice-phones-battle.md new file mode 100644 index 0000000..9b385ac --- /dev/null +++ b/.changeset/nice-phones-battle.md @@ -0,0 +1,5 @@ +--- +'@team-plain/typescript-sdk': minor +--- + +add support for creating label types (createLabelType) diff --git a/src/client.ts b/src/client.ts index 3ad71d7..f1adcdf 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,1125 +1,1176 @@ -import type { VariablesOf } from '@graphql-typed-document-node/core'; +import type { VariablesOf } from "@graphql-typed-document-node/core"; -import type { Context } from './context'; -import type { PlainSDKError } from './error'; +import type { Context } from "./context"; +import type { PlainSDKError } from "./error"; import { - AddCustomerToCustomerGroupsDocument, - AddCustomerToTenantsDocument, - AddLabelsDocument, - AddMembersToTierDocument, - ArchiveLabelTypeDocument, - AssignThreadDocument, - type AttachmentUploadUrlPartsFragment, - ChangeThreadPriorityDocument, - CompaniesDocument, - type CompanyPartsFragment, - type CompanyTierMembershipPartsFragment, - CreateAttachmentUploadUrlDocument, - CreateCustomerCardConfigDocument, - CreateCustomerEventDocument, - CreateNoteDocument, - CreateThreadDocument, - CreateThreadEventDocument, - CreateWebhookTargetDocument, - CustomerByEmailDocument, - CustomerByIdDocument, - type CustomerCardConfigPartsFragment, - CustomerCustomerGroupsDocument, - type CustomerEventPartsFragment, - CustomerGroupByIdDocument, - type CustomerGroupMembershipPartsFragment, - type CustomerGroupPartsFragment, - CustomerGroupsDocument, - type CustomerPartsFragment, - CustomersDocument, - type CustomerTenantMembershipPartsFragment, - CustomerTenantsDocument, - DeleteCustomerCardConfigDocument, - DeleteCustomerDocument, - DeleteThreadFieldDocument, - DeleteWebhookTargetDocument, - type EmailPartsFragment, - type LabelPartsFragment, - LabelTypeDocument, - type LabelTypePartsFragment, - LabelTypesDocument, - MarkThreadAsDoneDocument, - MarkThreadAsTodoDocument, - MyWorkspaceDocument, - type NotePartsFragment, - type PageInfo, - type PageInfoPartsFragment, - RemoveCustomerFromCustomerGroupsDocument, - RemoveCustomerFromTenantsDocument, - RemoveLabelsDocument, - RemoveMembersFromTierDocument, - ReplyToEmailDocument, - ReplyToThreadDocument, - SearchCompaniesDocument, - SearchTenantsDocument, - SendNewEmailDocument, - SetCustomerTenantsDocument, - SnoozeThreadDocument, - TenantDocument, - type TenantPartsFragment, - TenantsDocument, - type TenantTierMembershipPartsFragment, - ThreadByExternalIdDocument, - ThreadDocument, - type ThreadEventPartsFragment, - type ThreadFieldPartsFragment, - type ThreadPartsFragment, - ThreadsDocument, - TierDocument, - type TierMembershipPartsFragment, - type TierPartsFragment, - TiersDocument, - UnassignThreadDocument, - UpdateCompanyTierDocument, - UpdateCustomerCardConfigDocument, - UpdateCustomerCompanyDocument, - UpdateTenantTierDocument, - UpdateThreadTenantDocument, - UpdateWebhookTargetDocument, - UpsertCompanyDocument, - UpsertCustomerDocument, - type UpsertResult, - UpsertTenantDocument, - UpsertThreadFieldDocument, - UserByEmailDocument, - type UserPartsFragment, - WebhookTargetDocument, - type WebhookTargetPartsFragment, - WebhookTargetsDocument, - type WorkspacePartsFragment, -} from './graphql/types'; -import { request } from './request'; -import type { Result } from './result'; + AddCustomerToCustomerGroupsDocument, + AddCustomerToTenantsDocument, + AddLabelsDocument, + AddMembersToTierDocument, + ArchiveLabelTypeDocument, + AssignThreadDocument, + type AttachmentUploadUrlPartsFragment, + ChangeThreadPriorityDocument, + CompaniesDocument, + type CompanyPartsFragment, + type CompanyTierMembershipPartsFragment, + CreateAttachmentUploadUrlDocument, + CreateCustomerCardConfigDocument, + CreateCustomerEventDocument, + CreateLabelTypeDocument, + CreateNoteDocument, + CreateThreadDocument, + CreateThreadEventDocument, + CreateWebhookTargetDocument, + CustomerByEmailDocument, + CustomerByIdDocument, + type CustomerCardConfigPartsFragment, + CustomerCustomerGroupsDocument, + type CustomerEventPartsFragment, + CustomerGroupByIdDocument, + type CustomerGroupMembershipPartsFragment, + type CustomerGroupPartsFragment, + CustomerGroupsDocument, + type CustomerPartsFragment, + CustomersDocument, + type CustomerTenantMembershipPartsFragment, + CustomerTenantsDocument, + DeleteCustomerCardConfigDocument, + DeleteCustomerDocument, + DeleteThreadFieldDocument, + DeleteWebhookTargetDocument, + type EmailPartsFragment, + type LabelPartsFragment, + LabelTypeDocument, + type LabelTypePartsFragment, + LabelTypesDocument, + MarkThreadAsDoneDocument, + MarkThreadAsTodoDocument, + MyWorkspaceDocument, + type NotePartsFragment, + type PageInfo, + type PageInfoPartsFragment, + RemoveCustomerFromCustomerGroupsDocument, + RemoveCustomerFromTenantsDocument, + RemoveLabelsDocument, + RemoveMembersFromTierDocument, + ReplyToEmailDocument, + ReplyToThreadDocument, + SearchCompaniesDocument, + SearchTenantsDocument, + SendNewEmailDocument, + SetCustomerTenantsDocument, + SnoozeThreadDocument, + TenantDocument, + type TenantPartsFragment, + TenantsDocument, + type TenantTierMembershipPartsFragment, + ThreadByExternalIdDocument, + ThreadDocument, + type ThreadEventPartsFragment, + type ThreadFieldPartsFragment, + type ThreadPartsFragment, + ThreadsDocument, + TierDocument, + type TierMembershipPartsFragment, + type TierPartsFragment, + TiersDocument, + UnassignThreadDocument, + UpdateCompanyTierDocument, + UpdateCustomerCardConfigDocument, + UpdateCustomerCompanyDocument, + UpdateTenantTierDocument, + UpdateThreadTenantDocument, + UpdateWebhookTargetDocument, + UpsertCompanyDocument, + UpsertCustomerDocument, + type UpsertResult, + UpsertTenantDocument, + UpsertThreadFieldDocument, + UserByEmailDocument, + type UserPartsFragment, + WebhookTargetDocument, + type WebhookTargetPartsFragment, + WebhookTargetsDocument, + type WorkspacePartsFragment, +} from "./graphql/types"; +import { request } from "./request"; +import type { Result } from "./result"; type SDKResult = Promise>; function nonNullable(x: T | null | undefined): T { - if (x === null || x === undefined) { - throw new Error(`Expected value to be non nullable`); - } + if (x === null || x === undefined) { + throw new Error(`Expected value to be non nullable`); + } - return x; + return x; } function unwrapData( - result: Result, - unwrapFn: (data: T) => X + result: Result, + unwrapFn: (data: T) => X, ): Result { - if (result.error) { - return { - error: result.error, - }; - } else { - return { - data: unwrapFn(result.data), - }; - } + if (result.error) { + return { + error: result.error, + }; + } else { + return { + data: unwrapFn(result.data), + }; + } } type ConstructorOptions = { - // The Plain API key - apiKey: string; + // The Plain API key + apiKey: string; - // Useful if you want to point to a different Plain environment - // as a Plain team-member - apiUrl?: string; + // Useful if you want to point to a different Plain environment + // as a Plain team-member + apiUrl?: string; }; export class PlainClient { - #ctx: Context; - - constructor(options: ConstructorOptions) { - this.#ctx = { - apiKey: options.apiKey, - apiUrl: options.apiUrl, - }; - } - - /** - * If you need to do something custom you can use this method to do - */ - async rawRequest(args: { - query: string; - variables: Record; - }): SDKResult { - return request(this.#ctx, { - query: args.query, - variables: args.variables, - }); - } - - /** - * Get a paginated list of customers. - * @deprecated "use `getUserByEmail" instead - */ - async userByEmail( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: UserByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => q.userByEmail || null); - } - - /** - * Get a paginated list of customers. - */ - async getUserByEmail( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: UserByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => q.userByEmail || null); - } - - /** - * Get a paginated list of customers. - */ - async getCustomers(variables: VariablesOf): SDKResult<{ - customers: CustomerPartsFragment[]; - pageInfo: PageInfoPartsFragment; - totalCount: number; - }> { - const res = await request(this.#ctx, { - query: CustomersDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.customers.pageInfo, - customers: q.customers.edges.map((edge) => edge.node), - totalCount: q.customers.totalCount, - })); - } - - /** - * If the customer is not found this will return null. - */ - async getCustomerById( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerByIdDocument, - variables, - }); - - return unwrapData(res, (q) => { - if (!q.customer) { - return null; - } - return q.customer; - }); - } - - /** - * If the customer is not found this will return null. - */ - async getCustomerByEmail( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => { - if (!q.customerByEmail) { - return null; - } - - return q.customerByEmail; - }); - } - - /** - * Allows you to create or update a customer. If you need to get the customer id - * for a customer in Plain, this is typically your first step. - */ - async upsertCustomer( - input: VariablesOf['input'] - ): SDKResult<{ result: UpsertResult; customer: CustomerPartsFragment }> { - const res = await request(this.#ctx, { - query: UpsertCustomerDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - const customer = nonNullable(q.upsertCustomer.customer); - return { - result: nonNullable(q.upsertCustomer.result), - customer, - }; - }); - } - - async deleteCustomer( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteCustomerDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * If the customer group is not found this will return null. - */ - async getCustomerGroupById( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerGroupByIdDocument, - variables, - }); - - return unwrapData(res, (q) => q.customerGroup); - } - - /** - * Get a paginated list of customer groups. - */ - async getCustomerGroups( - variables: VariablesOf - ): SDKResult<{ customerGroups: CustomerGroupPartsFragment[]; pageInfo: PageInfo }> { - const res = await request(this.#ctx, { - query: CustomerGroupsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.customerGroups.pageInfo, - customerGroups: q.customerGroups.edges.map((edge) => edge.node), - })); - } - - /** - * Adds a customer to a customer groups. - */ - async addCustomerToCustomerGroups( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: AddCustomerToCustomerGroupsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.addCustomerToCustomerGroups.customerGroupMemberships) - ); - } - - /** - * Remove a customer from customer groups. - */ - async removeCustomerFromCustomerGroups( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveCustomerFromCustomerGroupsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async getCustomerCustomerGroupMemberships( - variables: VariablesOf - ): SDKResult<{ - customerGroupMemberships: CustomerGroupMembershipPartsFragment[]; - pageInfo: PageInfo | null; - }> { - const res = await request(this.#ctx, { - query: CustomerCustomerGroupsDocument, - variables, - }); - - return unwrapData(res, (q) => { - return { - customerGroupMemberships: q.customer - ? q.customer.customerGroupMemberships.edges.map((e) => e.node) - : [], - pageInfo: q.customer ? q.customer.customerGroupMemberships.pageInfo : null, - }; - }); - } - - async getCustomerTenantMemberships( - variables: VariablesOf - ): SDKResult<{ - tenantMemberships: CustomerTenantMembershipPartsFragment[]; - pageInfo: PageInfo | null; - }> { - const res = await request(this.#ctx, { - query: CustomerTenantsDocument, - variables, - }); - - return unwrapData(res, (q) => { - return { - tenantMemberships: q.customer ? q.customer.tenantMemberships.edges.map((e) => e.node) : [], - pageInfo: q.customer ? q.customer.tenantMemberships.pageInfo : null, - }; - }); - } - - async sendNewEmail( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: SendNewEmailDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.sendNewEmail.email); - }); - } - - async replyToEmail( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: ReplyToEmailDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.replyToEmail.email); - }); - } - - async replyToThread(input: VariablesOf['input']): SDKResult { - const res = await request(this.#ctx, { - query: ReplyToThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async createAttachmentUploadUrl( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateAttachmentUploadUrlDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl); - }); - } - - /** - * Fetch the workspace for the authenticated API key. - */ - async getMyWorkspace(): SDKResult { - const res = await request(this.#ctx, { - query: MyWorkspaceDocument, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.myWorkspace); - }); - } - - /** - * Creates the configuration for a Customer Card. Useful if you want - * to programatically set up a customer card vs using the settings UI - */ - async createCustomerCardConfig( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.createCustomerCardConfig.customerCardConfig); - }); - } - - /** - * Updates the configuration for a Customer Card. - */ - async updateCustomerCardConfig( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.updateCustomerCardConfig.customerCardConfig); - }); - } - - /** - * Delete the configuration for a Customer Card. - */ - async deleteCustomerCardConfig( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * Get a paginated list of threads - */ - async getThreads(variables: VariablesOf): SDKResult<{ - threads: ThreadPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: ThreadsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - threads: q.threads.edges.map((edge) => edge.node), - pageInfo: q.threads.pageInfo, - })); - } - - /** - * Get a single thread by id - */ - async getThread( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: ThreadDocument, - variables, - }); - - return unwrapData(res, (q) => q.thread); - } - - /** - * Get a single thread by external id. A thread's external id is unique per customer, - * hence why the customer id is also required. - */ - async getThreadByExternalId( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: ThreadByExternalIdDocument, - variables, - }); - - return unwrapData(res, (q) => q.threadByExternalId); - } - - /** - * Create a thread (e.g. when a contact form is submitted) - */ - async createThread( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createThread.thread)); - } - - /** - * Assign a thread to a user or machine user - */ - async assignThread( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: AssignThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.assignThread.thread)); - } - - /** - * Unassign a thread - */ - async unassignThread( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UnassignThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.unassignThread.thread)); - } - - /** - * Change a thread's priority - */ - async changeThreadPriority( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: ChangeThreadPriorityDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.changeThreadPriority.thread)); - } - - /** - * Update a thread's tenant - */ - async updateThreadTenant( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateThreadTenantDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.updateThreadTenant.thread)); - } - - /** - * Add labels to a thread - */ - async addLabels( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: AddLabelsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => q.addLabels.labels); - } - - /** - * Remove labels from a thread - */ - async removeLabels(input: VariablesOf['input']): SDKResult { - const res = await request(this.#ctx, { - query: RemoveLabelsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * Mark a thread as done - */ - async markThreadAsDone( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: MarkThreadAsDoneDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.markThreadAsDone.thread)); - } - - /** - * Snooze thread for a duration defined in seconds - */ - async snoozeThread( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: SnoozeThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.snoozeThread.thread)); - } - - /** - * Mark a thread as Todo (e.g. Unsnooze) - */ - async markThreadAsTodo( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: MarkThreadAsTodoDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.markThreadAsTodo.thread)); - } - - /** - * Archive a label type - */ - async archiveLabelType( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: ArchiveLabelTypeDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.archiveLabelType.labelType)); - } - - /** - * Get a paginated list of label types - */ - async getLabelTypes(variables: VariablesOf): SDKResult<{ - labelTypes: LabelTypePartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: LabelTypesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - labelTypes: q.labelTypes.edges.map((edge) => edge.node), - pageInfo: q.labelTypes.pageInfo, - })); - } - - /** - * Get a label type by id - */ - async getLabelType( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: LabelTypeDocument, - variables, - }); - - return unwrapData(res, (q) => q.labelType); - } - - /** Create a Customer Event */ - async createCustomerEvent( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateCustomerEventDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createCustomerEvent.customerEvent)); - } - - /** Create a Thread Event */ - async createThreadEvent( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateThreadEventDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createThreadEvent.threadEvent)); - } - - async upsertThreadField( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertThreadFieldDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertThreadField.threadField)); - } - - async deleteThreadField( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteThreadFieldDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async createWebhookTarget( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createWebhookTarget.webhookTarget)); - } - - async updateWebhookTarget( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.updateWebhookTarget.webhookTarget)); - } - - async deleteWebhookTarget( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async getWebhookTargets(variables: VariablesOf): SDKResult<{ - webhookTargets: WebhookTargetPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: WebhookTargetsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.webhookTargets.pageInfo, - webhookTargets: q.webhookTargets.edges.map((edge) => edge.node), - })); - } - - /** - * If the webhook target is not found it will return null - */ - async getWebhookTargetById( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: WebhookTargetDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.webhookTarget; - }); - } - - /** Create a note on a thread */ - async createNote( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateNoteDocument, - variables: { input }, - }); - - return unwrapData(res, (d) => nonNullable(d.createNote.note)); - } - async getTenantById( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: TenantDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.tenant; - }); - } - - async getTenants(variables: VariablesOf): SDKResult<{ - tenants: TenantPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: TenantsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.tenants.edges.map((edge) => edge.node), - pageInfo: q.tenants.pageInfo, - })); - } - - async searchTenants(variables: VariablesOf): SDKResult<{ - tenants: TenantPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: SearchTenantsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.searchTenants.edges.map((edge) => edge.node.tenant), - pageInfo: q.searchTenants.pageInfo, - })); - } - - async upsertTenant( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertTenantDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertTenant.tenant)); - } - - async setCustomerTenants( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: SetCustomerTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async addCustomerToTenants( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: AddCustomerToTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async removeCustomerFromTenants( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveCustomerFromTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async upsertCompany( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertCompanyDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertCompany.company)); - } - - async getCompanies(variables: VariablesOf): SDKResult<{ - companies: CompanyPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: CompaniesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - companies: q.companies.edges.map((edge) => edge.node), - pageInfo: q.companies.pageInfo, - })); - } - - async searchCompanies(variables: VariablesOf): SDKResult<{ - tenants: CompanyPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: SearchCompaniesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.searchCompanies.edges.map((edge) => edge.node.company), - pageInfo: q.searchCompanies.pageInfo, - })); - } - - async updateCustomerCompany( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCustomerCompanyDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (res) => nonNullable(res.updateCustomerCompany.customer)); - } - - async getTierById( - variables: VariablesOf - ): SDKResult { - const res = await request(this.#ctx, { - query: TierDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.tier; - }); - } - - async getTiers(variables: VariablesOf): SDKResult<{ - tiers: TierPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: TiersDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tiers: q.tiers.edges.map((edge) => edge.node), - pageInfo: q.tiers.pageInfo, - })); - } - - async addMembersToTier( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: AddMembersToTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => q.addMembersToTier.memberships); - } - - async removeMembersFromTier( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveMembersFromTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async updateTenantTier( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateTenantTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.updateTenantTier.tenantTierMembership)); - } - - async updateCompanyTier( - input: VariablesOf['input'] - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCompanyTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.updateCompanyTier.companyTierMembership)); - } + #ctx: Context; + + constructor(options: ConstructorOptions) { + this.#ctx = { + apiKey: options.apiKey, + apiUrl: options.apiUrl, + }; + } + + /** + * If you need to do something custom you can use this method to do + */ + async rawRequest(args: { + query: string; + variables: Record; + }): SDKResult { + return request(this.#ctx, { + query: args.query, + variables: args.variables, + }); + } + + /** + * Get a paginated list of customers. + * @deprecated "use `getUserByEmail" instead + */ + async userByEmail( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: UserByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => q.userByEmail || null); + } + + /** + * Get a paginated list of customers. + */ + async getUserByEmail( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: UserByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => q.userByEmail || null); + } + + /** + * Get a paginated list of customers. + */ + async getCustomers( + variables: VariablesOf, + ): SDKResult<{ + customers: CustomerPartsFragment[]; + pageInfo: PageInfoPartsFragment; + totalCount: number; + }> { + const res = await request(this.#ctx, { + query: CustomersDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.customers.pageInfo, + customers: q.customers.edges.map((edge) => edge.node), + totalCount: q.customers.totalCount, + })); + } + + /** + * If the customer is not found this will return null. + */ + async getCustomerById( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerByIdDocument, + variables, + }); + + return unwrapData(res, (q) => { + if (!q.customer) { + return null; + } + return q.customer; + }); + } + + /** + * If the customer is not found this will return null. + */ + async getCustomerByEmail( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => { + if (!q.customerByEmail) { + return null; + } + + return q.customerByEmail; + }); + } + + /** + * Allows you to create or update a customer. If you need to get the customer id + * for a customer in Plain, this is typically your first step. + */ + async upsertCustomer( + input: VariablesOf["input"], + ): SDKResult<{ result: UpsertResult; customer: CustomerPartsFragment }> { + const res = await request(this.#ctx, { + query: UpsertCustomerDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + const customer = nonNullable(q.upsertCustomer.customer); + return { + result: nonNullable(q.upsertCustomer.result), + customer, + }; + }); + } + + async deleteCustomer( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteCustomerDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * If the customer group is not found this will return null. + */ + async getCustomerGroupById( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerGroupByIdDocument, + variables, + }); + + return unwrapData(res, (q) => q.customerGroup); + } + + /** + * Get a paginated list of customer groups. + */ + async getCustomerGroups( + variables: VariablesOf, + ): SDKResult<{ + customerGroups: CustomerGroupPartsFragment[]; + pageInfo: PageInfo; + }> { + const res = await request(this.#ctx, { + query: CustomerGroupsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.customerGroups.pageInfo, + customerGroups: q.customerGroups.edges.map((edge) => edge.node), + })); + } + + /** + * Adds a customer to a customer groups. + */ + async addCustomerToCustomerGroups( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: AddCustomerToCustomerGroupsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.addCustomerToCustomerGroups.customerGroupMemberships), + ); + } + + /** + * Remove a customer from customer groups. + */ + async removeCustomerFromCustomerGroups( + input: VariablesOf< + typeof RemoveCustomerFromCustomerGroupsDocument + >["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveCustomerFromCustomerGroupsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async getCustomerCustomerGroupMemberships( + variables: VariablesOf, + ): SDKResult<{ + customerGroupMemberships: CustomerGroupMembershipPartsFragment[]; + pageInfo: PageInfo | null; + }> { + const res = await request(this.#ctx, { + query: CustomerCustomerGroupsDocument, + variables, + }); + + return unwrapData(res, (q) => { + return { + customerGroupMemberships: q.customer + ? q.customer.customerGroupMemberships.edges.map((e) => e.node) + : [], + pageInfo: q.customer + ? q.customer.customerGroupMemberships.pageInfo + : null, + }; + }); + } + + async getCustomerTenantMemberships( + variables: VariablesOf, + ): SDKResult<{ + tenantMemberships: CustomerTenantMembershipPartsFragment[]; + pageInfo: PageInfo | null; + }> { + const res = await request(this.#ctx, { + query: CustomerTenantsDocument, + variables, + }); + + return unwrapData(res, (q) => { + return { + tenantMemberships: q.customer + ? q.customer.tenantMemberships.edges.map((e) => e.node) + : [], + pageInfo: q.customer ? q.customer.tenantMemberships.pageInfo : null, + }; + }); + } + + async sendNewEmail( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: SendNewEmailDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.sendNewEmail.email); + }); + } + + async replyToEmail( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: ReplyToEmailDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.replyToEmail.email); + }); + } + + async replyToThread( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: ReplyToThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async createAttachmentUploadUrl( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateAttachmentUploadUrlDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl); + }); + } + + /** + * Fetch the workspace for the authenticated API key. + */ + async getMyWorkspace(): SDKResult { + const res = await request(this.#ctx, { + query: MyWorkspaceDocument, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.myWorkspace); + }); + } + + /** + * Creates the configuration for a Customer Card. Useful if you want + * to programatically set up a customer card vs using the settings UI + */ + async createCustomerCardConfig( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.createCustomerCardConfig.customerCardConfig); + }); + } + + /** + * Updates the configuration for a Customer Card. + */ + async updateCustomerCardConfig( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.updateCustomerCardConfig.customerCardConfig); + }); + } + + /** + * Delete the configuration for a Customer Card. + */ + async deleteCustomerCardConfig( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * Get a paginated list of threads + */ + async getThreads(variables: VariablesOf): SDKResult<{ + threads: ThreadPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: ThreadsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + threads: q.threads.edges.map((edge) => edge.node), + pageInfo: q.threads.pageInfo, + })); + } + + /** + * Get a single thread by id + */ + async getThread( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: ThreadDocument, + variables, + }); + + return unwrapData(res, (q) => q.thread); + } + + /** + * Get a single thread by external id. A thread's external id is unique per customer, + * hence why the customer id is also required. + */ + async getThreadByExternalId( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: ThreadByExternalIdDocument, + variables, + }); + + return unwrapData(res, (q) => q.threadByExternalId); + } + + /** + * Create a thread (e.g. when a contact form is submitted) + */ + async createThread( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createThread.thread)); + } + + /** + * Assign a thread to a user or machine user + */ + async assignThread( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: AssignThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.assignThread.thread)); + } + + /** + * Unassign a thread + */ + async unassignThread( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UnassignThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.unassignThread.thread)); + } + + /** + * Change a thread's priority + */ + async changeThreadPriority( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: ChangeThreadPriorityDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.changeThreadPriority.thread)); + } + + /** + * Update a thread's tenant + */ + async updateThreadTenant( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateThreadTenantDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.updateThreadTenant.thread)); + } + + /** + * Add labels to a thread + */ + async addLabels( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: AddLabelsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => q.addLabels.labels); + } + + /** + * Remove labels from a thread + */ + async removeLabels( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveLabelsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * Mark a thread as done + */ + async markThreadAsDone( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: MarkThreadAsDoneDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.markThreadAsDone.thread)); + } + + /** + * Snooze thread for a duration defined in seconds + */ + async snoozeThread( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: SnoozeThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.snoozeThread.thread)); + } + + /** + * Mark a thread as Todo (e.g. Unsnooze) + */ + async markThreadAsTodo( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: MarkThreadAsTodoDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.markThreadAsTodo.thread)); + } + + /** + * Archive a label type + */ + async archiveLabelType( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: ArchiveLabelTypeDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.archiveLabelType.labelType)); + } + + /** + * Get a paginated list of label types + */ + async getLabelTypes( + variables: VariablesOf, + ): SDKResult<{ + labelTypes: LabelTypePartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: LabelTypesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + labelTypes: q.labelTypes.edges.map((edge) => edge.node), + pageInfo: q.labelTypes.pageInfo, + })); + } + + /** + * Get a label type by id + */ + async getLabelType( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: LabelTypeDocument, + variables, + }); + + return unwrapData(res, (q) => q.labelType); + } + + /** Create a Customer Event */ + async createCustomerEvent( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateCustomerEventDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.createCustomerEvent.customerEvent), + ); + } + + /** Create a Thread Event */ + async createThreadEvent( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateThreadEventDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createThreadEvent.threadEvent)); + } + + async upsertThreadField( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertThreadFieldDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertThreadField.threadField)); + } + + async deleteThreadField( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteThreadFieldDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async createWebhookTarget( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.createWebhookTarget.webhookTarget), + ); + } + + async updateWebhookTarget( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.updateWebhookTarget.webhookTarget), + ); + } + + async deleteWebhookTarget( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async getWebhookTargets( + variables: VariablesOf, + ): SDKResult<{ + webhookTargets: WebhookTargetPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: WebhookTargetsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.webhookTargets.pageInfo, + webhookTargets: q.webhookTargets.edges.map((edge) => edge.node), + })); + } + + /** + * If the webhook target is not found it will return null + */ + async getWebhookTargetById( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: WebhookTargetDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.webhookTarget; + }); + } + + /** Create a note on a thread */ + async createNote( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateNoteDocument, + variables: { input }, + }); + + return unwrapData(res, (d) => nonNullable(d.createNote.note)); + } + async getTenantById( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: TenantDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.tenant; + }); + } + + async getTenants(variables: VariablesOf): SDKResult<{ + tenants: TenantPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: TenantsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.tenants.edges.map((edge) => edge.node), + pageInfo: q.tenants.pageInfo, + })); + } + + async searchTenants( + variables: VariablesOf, + ): SDKResult<{ + tenants: TenantPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: SearchTenantsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.searchTenants.edges.map((edge) => edge.node.tenant), + pageInfo: q.searchTenants.pageInfo, + })); + } + + async upsertTenant( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertTenantDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertTenant.tenant)); + } + + async setCustomerTenants( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: SetCustomerTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async addCustomerToTenants( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: AddCustomerToTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async removeCustomerFromTenants( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveCustomerFromTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async upsertCompany( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertCompanyDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertCompany.company)); + } + + async getCompanies( + variables: VariablesOf, + ): SDKResult<{ + companies: CompanyPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: CompaniesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + companies: q.companies.edges.map((edge) => edge.node), + pageInfo: q.companies.pageInfo, + })); + } + + async searchCompanies( + variables: VariablesOf, + ): SDKResult<{ + tenants: CompanyPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: SearchCompaniesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.searchCompanies.edges.map((edge) => edge.node.company), + pageInfo: q.searchCompanies.pageInfo, + })); + } + + async updateCustomerCompany( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCustomerCompanyDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (res) => + nonNullable(res.updateCustomerCompany.customer), + ); + } + + async getTierById( + variables: VariablesOf, + ): SDKResult { + const res = await request(this.#ctx, { + query: TierDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.tier; + }); + } + + async getTiers(variables: VariablesOf): SDKResult<{ + tiers: TierPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: TiersDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tiers: q.tiers.edges.map((edge) => edge.node), + pageInfo: q.tiers.pageInfo, + })); + } + + async addMembersToTier( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: AddMembersToTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => q.addMembersToTier.memberships); + } + + async removeMembersFromTier( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveMembersFromTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async updateTenantTier( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateTenantTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.updateTenantTier.tenantTierMembership), + ); + } + + async updateCompanyTier( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCompanyTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.updateCompanyTier.companyTierMembership), + ); + } + + async createLabelType( + input: VariablesOf["input"], + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateLabelTypeDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createLabelType.labelType)); + } } diff --git a/src/graphql/mutations/createLabelType.gql b/src/graphql/mutations/createLabelType.gql new file mode 100644 index 0000000..1e719e4 --- /dev/null +++ b/src/graphql/mutations/createLabelType.gql @@ -0,0 +1,10 @@ +mutation createLabelType($input: CreateLabelTypeInput!) { + createLabelType(input: $input) { + labelType { + ...LabelTypeParts + } + error { + ...MutationErrorParts + } + } +} \ No newline at end of file diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 96b887f..b9e7d6d 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -6791,6 +6791,13 @@ export type CreateCustomerEventMutationVariables = Exact<{ export type CreateCustomerEventMutation = { __typename?: 'Mutation', createCustomerEvent: { __typename?: 'CreateCustomerEventOutput', customerEvent: { __typename: 'CustomerEvent', id: string, customerId: string, title: string, createdAt: { __typename: 'DateTime', iso8601: string, unixTimestamp: string }, createdBy: { __typename: 'CustomerActor', customerId: string } | { __typename: 'DeletedCustomerActor', customerId: string } | { __typename: 'MachineUserActor', machineUserId: string } | { __typename: 'SystemActor', systemId: string } | { __typename: 'UserActor', userId: string }, updatedAt: { __typename: 'DateTime', iso8601: string, unixTimestamp: string }, updatedBy: { __typename: 'CustomerActor', customerId: string } | { __typename: 'DeletedCustomerActor', customerId: string } | { __typename: 'MachineUserActor', machineUserId: string } | { __typename: 'SystemActor', systemId: string } | { __typename: 'UserActor', userId: string } } | null, error: { __typename: 'MutationError', message: string, type: MutationErrorType, code: string, fields: Array<{ __typename?: 'MutationFieldError', field: string, message: string, type: MutationFieldErrorType }> } | null } }; +export type CreateLabelTypeMutationVariables = Exact<{ + input: CreateLabelTypeInput; +}>; + + +export type CreateLabelTypeMutation = { __typename?: 'Mutation', createLabelType: { __typename?: 'CreateLabelTypeOutput', labelType: { __typename: 'LabelType', id: string, name: string, icon: string | null, isArchived: boolean, archivedAt: { __typename: 'DateTime', iso8601: string, unixTimestamp: string } | null, archivedBy: { __typename: 'MachineUserActor', machineUserId: string } | { __typename: 'SystemActor', systemId: string } | { __typename: 'UserActor', userId: string } | null, createdAt: { __typename: 'DateTime', iso8601: string, unixTimestamp: string }, createdBy: { __typename: 'MachineUserActor', machineUserId: string } | { __typename: 'SystemActor', systemId: string } | { __typename: 'UserActor', userId: string }, updatedAt: { __typename: 'DateTime', iso8601: string, unixTimestamp: string }, updatedBy: { __typename: 'MachineUserActor', machineUserId: string } | { __typename: 'SystemActor', systemId: string } | { __typename: 'UserActor', userId: string } } | null, error: { __typename: 'MutationError', message: string, type: MutationErrorType, code: string, fields: Array<{ __typename?: 'MutationFieldError', field: string, message: string, type: MutationFieldErrorType }> } | null } }; + export type CreateNoteMutationVariables = Exact<{ input: CreateNoteInput; }>; @@ -7258,6 +7265,7 @@ export const ChangeThreadPriorityDocument = {"kind":"Document","definitions":[{" export const CreateAttachmentUploadUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createAttachmentUploadUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateAttachmentUploadUrlInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createAttachmentUploadUrl"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"attachmentUploadUrl"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AttachmentUploadUrlParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FileSizeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"FileSize"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"kiloBytes"}},{"kind":"Field","name":{"kind":"Name","value":"megaBytes"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AttachmentParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Attachment"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fileName"}},{"kind":"Field","name":{"kind":"Name","value":"fileSize"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FileSizeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"fileExtension"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AttachmentUploadUrlParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AttachmentUploadUrl"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"attachment"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AttachmentParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"uploadFormUrl"}},{"kind":"Field","name":{"kind":"Name","value":"uploadFormData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; export const CreateCustomerCardConfigDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createCustomerCardConfig"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateCustomerCardConfigInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createCustomerCardConfig"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customerCardConfig"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerCardConfigParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerCardConfigParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerCardConfig"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"defaultTimeToLiveSeconds"}},{"kind":"Field","name":{"kind":"Name","value":"apiUrl"}},{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"apiHeaders"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"isEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; export const CreateCustomerEventDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createCustomerEvent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateCustomerEventInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createCustomerEvent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customerEvent"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerEventParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"userId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SystemActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"systemId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MachineUserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"machineUserId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DeletedCustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Actor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DeletedCustomerActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerEventParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerEvent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; +export const CreateLabelTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createLabelType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateLabelTypeInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createLabelType"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"labelType"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"LabelTypeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"userId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SystemActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"systemId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MachineUserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"machineUserId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DeletedCustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Actor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DeletedCustomerActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"LabelTypeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"LabelType"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isArchived"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"archivedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; export const CreateNoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createNote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateNoteInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createNote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"note"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"NoteParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"NoteParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Note"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"markdown"}},{"kind":"Field","name":{"kind":"Name","value":"text"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; export const CreateThreadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createThread"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateThreadInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createThread"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"thread"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ThreadParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"userId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SystemActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"systemId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MachineUserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"machineUserId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DeletedCustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Actor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DeletedCustomerActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"LabelTypeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"LabelType"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isArchived"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"archivedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"LabelParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Label"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"labelType"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"LabelTypeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"InternalActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Actor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ThreadFieldParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ThreadField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"stringValue"}},{"kind":"Field","name":{"kind":"Name","value":"booleanValue"}},{"kind":"Field","name":{"kind":"Name","value":"isAiGenerated"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"InternalActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"InternalActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"User"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fullName"}},{"kind":"Field","name":{"kind":"Name","value":"publicName"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MachineUserParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUser"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fullName"}},{"kind":"Field","name":{"kind":"Name","value":"publicName"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SystemParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"System"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ThreadAssigneeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ThreadAssignee"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"User"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUser"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"System"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ThreadParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Thread"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"externalId"}},{"kind":"Field","name":{"kind":"Name","value":"customer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"statusChangedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"previewText"}},{"kind":"Field","name":{"kind":"Name","value":"priority"}},{"kind":"Field","name":{"kind":"Name","value":"labels"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"LabelParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"threadFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ThreadFieldParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"assignedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"assignedTo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ThreadAssigneeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; export const CreateThreadEventDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"createThreadEvent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateThreadEventInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createThreadEvent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"threadEvent"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ThreadEventParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MutationErrorParts"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DateTimeParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"iso8601"}},{"kind":"Field","name":{"kind":"Name","value":"unixTimestamp"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"userId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SystemActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"systemId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MachineUserActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"machineUserId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DeletedCustomerActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ActorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Actor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"UserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SystemActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SystemActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MachineUserActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"MachineUserActorParts"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedCustomerActor"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DeletedCustomerActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ThreadEventParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ThreadEvent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"customerId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DateTimeParts"}}]}},{"kind":"Field","name":{"kind":"Name","value":"updatedBy"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ActorParts"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"MutationErrorParts"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"MutationError"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"type"}}]}}]}}]} as unknown as DocumentNode; diff --git a/src/webhooks/webhook-schema.json b/src/webhooks/webhook-schema.json index 7a873dc..c7b9f92 100644 --- a/src/webhooks/webhook-schema.json +++ b/src/webhooks/webhook-schema.json @@ -1,5 +1,5 @@ { - "title": "Webhooks schema definition", + "title": "Plain Webhooks Schema (unversioned)", "type": "object", "properties": { "timestamp": { @@ -141,7 +141,7 @@ }, { "type": "string", - "pattern": "^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|([^-]([a-zA-Z0-9-]*\\.)+[a-zA-Z]{2,}))$" + "pattern": "^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|([^-]([a-zA-Z0-9-]*\\.)+[a-zA-Z]{2,}))$" } ] }, diff --git a/src/webhooks/webhook-schema.ts b/src/webhooks/webhook-schema.ts index 9c9f2bd..c1a25a5 100644 --- a/src/webhooks/webhook-schema.ts +++ b/src/webhooks/webhook-schema.ts @@ -160,7 +160,7 @@ export type ServiceLevelAgreementStatusDetail = /** * Webhook request */ -export interface WebhooksSchemaDefinition { +export interface PlainWebhooksSchemaUnversioned { timestamp: Datetime; workspaceId: Id; payload: From 5406480ccdf38b0d6afc918bc24e8be559d9e6de Mon Sep 17 00:00:00 2001 From: Mathias Vagni Date: Thu, 19 Sep 2024 11:04:28 +0200 Subject: [PATCH 2/3] revert changes to webhooks --- src/webhooks/webhook-schema.json | 4 ++-- src/webhooks/webhook-schema.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webhooks/webhook-schema.json b/src/webhooks/webhook-schema.json index c7b9f92..7a873dc 100644 --- a/src/webhooks/webhook-schema.json +++ b/src/webhooks/webhook-schema.json @@ -1,5 +1,5 @@ { - "title": "Plain Webhooks Schema (unversioned)", + "title": "Webhooks schema definition", "type": "object", "properties": { "timestamp": { @@ -141,7 +141,7 @@ }, { "type": "string", - "pattern": "^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|([^-]([a-zA-Z0-9-]*\\.)+[a-zA-Z]{2,}))$" + "pattern": "^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|([^-]([a-zA-Z0-9-]*\\.)+[a-zA-Z]{2,}))$" } ] }, diff --git a/src/webhooks/webhook-schema.ts b/src/webhooks/webhook-schema.ts index c1a25a5..9c9f2bd 100644 --- a/src/webhooks/webhook-schema.ts +++ b/src/webhooks/webhook-schema.ts @@ -160,7 +160,7 @@ export type ServiceLevelAgreementStatusDetail = /** * Webhook request */ -export interface PlainWebhooksSchemaUnversioned { +export interface WebhooksSchemaDefinition { timestamp: Datetime; workspaceId: Id; payload: From 6a87d03d28c8b801b8f1f9ab2bf9e7c7d670e291 Mon Sep 17 00:00:00 2001 From: Mathias Vagni Date: Thu, 19 Sep 2024 16:50:28 +0200 Subject: [PATCH 3/3] lint --- src/client.ts | 2278 ++++++++++----------- src/graphql/mutations/createLabelType.gql | 2 +- 2 files changed, 1122 insertions(+), 1158 deletions(-) diff --git a/src/client.ts b/src/client.ts index f1adcdf..ddaa335 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,1176 +1,1140 @@ -import type { VariablesOf } from "@graphql-typed-document-node/core"; +import type { VariablesOf } from '@graphql-typed-document-node/core'; -import type { Context } from "./context"; -import type { PlainSDKError } from "./error"; +import type { Context } from './context'; +import type { PlainSDKError } from './error'; import { - AddCustomerToCustomerGroupsDocument, - AddCustomerToTenantsDocument, - AddLabelsDocument, - AddMembersToTierDocument, - ArchiveLabelTypeDocument, - AssignThreadDocument, - type AttachmentUploadUrlPartsFragment, - ChangeThreadPriorityDocument, - CompaniesDocument, - type CompanyPartsFragment, - type CompanyTierMembershipPartsFragment, - CreateAttachmentUploadUrlDocument, - CreateCustomerCardConfigDocument, - CreateCustomerEventDocument, - CreateLabelTypeDocument, - CreateNoteDocument, - CreateThreadDocument, - CreateThreadEventDocument, - CreateWebhookTargetDocument, - CustomerByEmailDocument, - CustomerByIdDocument, - type CustomerCardConfigPartsFragment, - CustomerCustomerGroupsDocument, - type CustomerEventPartsFragment, - CustomerGroupByIdDocument, - type CustomerGroupMembershipPartsFragment, - type CustomerGroupPartsFragment, - CustomerGroupsDocument, - type CustomerPartsFragment, - CustomersDocument, - type CustomerTenantMembershipPartsFragment, - CustomerTenantsDocument, - DeleteCustomerCardConfigDocument, - DeleteCustomerDocument, - DeleteThreadFieldDocument, - DeleteWebhookTargetDocument, - type EmailPartsFragment, - type LabelPartsFragment, - LabelTypeDocument, - type LabelTypePartsFragment, - LabelTypesDocument, - MarkThreadAsDoneDocument, - MarkThreadAsTodoDocument, - MyWorkspaceDocument, - type NotePartsFragment, - type PageInfo, - type PageInfoPartsFragment, - RemoveCustomerFromCustomerGroupsDocument, - RemoveCustomerFromTenantsDocument, - RemoveLabelsDocument, - RemoveMembersFromTierDocument, - ReplyToEmailDocument, - ReplyToThreadDocument, - SearchCompaniesDocument, - SearchTenantsDocument, - SendNewEmailDocument, - SetCustomerTenantsDocument, - SnoozeThreadDocument, - TenantDocument, - type TenantPartsFragment, - TenantsDocument, - type TenantTierMembershipPartsFragment, - ThreadByExternalIdDocument, - ThreadDocument, - type ThreadEventPartsFragment, - type ThreadFieldPartsFragment, - type ThreadPartsFragment, - ThreadsDocument, - TierDocument, - type TierMembershipPartsFragment, - type TierPartsFragment, - TiersDocument, - UnassignThreadDocument, - UpdateCompanyTierDocument, - UpdateCustomerCardConfigDocument, - UpdateCustomerCompanyDocument, - UpdateTenantTierDocument, - UpdateThreadTenantDocument, - UpdateWebhookTargetDocument, - UpsertCompanyDocument, - UpsertCustomerDocument, - type UpsertResult, - UpsertTenantDocument, - UpsertThreadFieldDocument, - UserByEmailDocument, - type UserPartsFragment, - WebhookTargetDocument, - type WebhookTargetPartsFragment, - WebhookTargetsDocument, - type WorkspacePartsFragment, -} from "./graphql/types"; -import { request } from "./request"; -import type { Result } from "./result"; + AddCustomerToCustomerGroupsDocument, + AddCustomerToTenantsDocument, + AddLabelsDocument, + AddMembersToTierDocument, + ArchiveLabelTypeDocument, + AssignThreadDocument, + type AttachmentUploadUrlPartsFragment, + ChangeThreadPriorityDocument, + CompaniesDocument, + type CompanyPartsFragment, + type CompanyTierMembershipPartsFragment, + CreateAttachmentUploadUrlDocument, + CreateCustomerCardConfigDocument, + CreateCustomerEventDocument, + CreateLabelTypeDocument, + CreateNoteDocument, + CreateThreadDocument, + CreateThreadEventDocument, + CreateWebhookTargetDocument, + CustomerByEmailDocument, + CustomerByIdDocument, + type CustomerCardConfigPartsFragment, + CustomerCustomerGroupsDocument, + type CustomerEventPartsFragment, + CustomerGroupByIdDocument, + type CustomerGroupMembershipPartsFragment, + type CustomerGroupPartsFragment, + CustomerGroupsDocument, + type CustomerPartsFragment, + CustomersDocument, + type CustomerTenantMembershipPartsFragment, + CustomerTenantsDocument, + DeleteCustomerCardConfigDocument, + DeleteCustomerDocument, + DeleteThreadFieldDocument, + DeleteWebhookTargetDocument, + type EmailPartsFragment, + type LabelPartsFragment, + LabelTypeDocument, + type LabelTypePartsFragment, + LabelTypesDocument, + MarkThreadAsDoneDocument, + MarkThreadAsTodoDocument, + MyWorkspaceDocument, + type NotePartsFragment, + type PageInfo, + type PageInfoPartsFragment, + RemoveCustomerFromCustomerGroupsDocument, + RemoveCustomerFromTenantsDocument, + RemoveLabelsDocument, + RemoveMembersFromTierDocument, + ReplyToEmailDocument, + ReplyToThreadDocument, + SearchCompaniesDocument, + SearchTenantsDocument, + SendNewEmailDocument, + SetCustomerTenantsDocument, + SnoozeThreadDocument, + TenantDocument, + type TenantPartsFragment, + TenantsDocument, + type TenantTierMembershipPartsFragment, + ThreadByExternalIdDocument, + ThreadDocument, + type ThreadEventPartsFragment, + type ThreadFieldPartsFragment, + type ThreadPartsFragment, + ThreadsDocument, + TierDocument, + type TierMembershipPartsFragment, + type TierPartsFragment, + TiersDocument, + UnassignThreadDocument, + UpdateCompanyTierDocument, + UpdateCustomerCardConfigDocument, + UpdateCustomerCompanyDocument, + UpdateTenantTierDocument, + UpdateThreadTenantDocument, + UpdateWebhookTargetDocument, + UpsertCompanyDocument, + UpsertCustomerDocument, + type UpsertResult, + UpsertTenantDocument, + UpsertThreadFieldDocument, + UserByEmailDocument, + type UserPartsFragment, + WebhookTargetDocument, + type WebhookTargetPartsFragment, + WebhookTargetsDocument, + type WorkspacePartsFragment, +} from './graphql/types'; +import { request } from './request'; +import type { Result } from './result'; type SDKResult = Promise>; function nonNullable(x: T | null | undefined): T { - if (x === null || x === undefined) { - throw new Error(`Expected value to be non nullable`); - } + if (x === null || x === undefined) { + throw new Error(`Expected value to be non nullable`); + } - return x; + return x; } function unwrapData( - result: Result, - unwrapFn: (data: T) => X, + result: Result, + unwrapFn: (data: T) => X ): Result { - if (result.error) { - return { - error: result.error, - }; - } else { - return { - data: unwrapFn(result.data), - }; - } + if (result.error) { + return { + error: result.error, + }; + } else { + return { + data: unwrapFn(result.data), + }; + } } type ConstructorOptions = { - // The Plain API key - apiKey: string; + // The Plain API key + apiKey: string; - // Useful if you want to point to a different Plain environment - // as a Plain team-member - apiUrl?: string; + // Useful if you want to point to a different Plain environment + // as a Plain team-member + apiUrl?: string; }; export class PlainClient { - #ctx: Context; - - constructor(options: ConstructorOptions) { - this.#ctx = { - apiKey: options.apiKey, - apiUrl: options.apiUrl, - }; - } - - /** - * If you need to do something custom you can use this method to do - */ - async rawRequest(args: { - query: string; - variables: Record; - }): SDKResult { - return request(this.#ctx, { - query: args.query, - variables: args.variables, - }); - } - - /** - * Get a paginated list of customers. - * @deprecated "use `getUserByEmail" instead - */ - async userByEmail( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: UserByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => q.userByEmail || null); - } - - /** - * Get a paginated list of customers. - */ - async getUserByEmail( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: UserByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => q.userByEmail || null); - } - - /** - * Get a paginated list of customers. - */ - async getCustomers( - variables: VariablesOf, - ): SDKResult<{ - customers: CustomerPartsFragment[]; - pageInfo: PageInfoPartsFragment; - totalCount: number; - }> { - const res = await request(this.#ctx, { - query: CustomersDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.customers.pageInfo, - customers: q.customers.edges.map((edge) => edge.node), - totalCount: q.customers.totalCount, - })); - } - - /** - * If the customer is not found this will return null. - */ - async getCustomerById( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerByIdDocument, - variables, - }); - - return unwrapData(res, (q) => { - if (!q.customer) { - return null; - } - return q.customer; - }); - } - - /** - * If the customer is not found this will return null. - */ - async getCustomerByEmail( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerByEmailDocument, - variables, - }); - - return unwrapData(res, (q) => { - if (!q.customerByEmail) { - return null; - } - - return q.customerByEmail; - }); - } - - /** - * Allows you to create or update a customer. If you need to get the customer id - * for a customer in Plain, this is typically your first step. - */ - async upsertCustomer( - input: VariablesOf["input"], - ): SDKResult<{ result: UpsertResult; customer: CustomerPartsFragment }> { - const res = await request(this.#ctx, { - query: UpsertCustomerDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - const customer = nonNullable(q.upsertCustomer.customer); - return { - result: nonNullable(q.upsertCustomer.result), - customer, - }; - }); - } - - async deleteCustomer( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteCustomerDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * If the customer group is not found this will return null. - */ - async getCustomerGroupById( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: CustomerGroupByIdDocument, - variables, - }); - - return unwrapData(res, (q) => q.customerGroup); - } - - /** - * Get a paginated list of customer groups. - */ - async getCustomerGroups( - variables: VariablesOf, - ): SDKResult<{ - customerGroups: CustomerGroupPartsFragment[]; - pageInfo: PageInfo; - }> { - const res = await request(this.#ctx, { - query: CustomerGroupsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.customerGroups.pageInfo, - customerGroups: q.customerGroups.edges.map((edge) => edge.node), - })); - } - - /** - * Adds a customer to a customer groups. - */ - async addCustomerToCustomerGroups( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: AddCustomerToCustomerGroupsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.addCustomerToCustomerGroups.customerGroupMemberships), - ); - } - - /** - * Remove a customer from customer groups. - */ - async removeCustomerFromCustomerGroups( - input: VariablesOf< - typeof RemoveCustomerFromCustomerGroupsDocument - >["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveCustomerFromCustomerGroupsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async getCustomerCustomerGroupMemberships( - variables: VariablesOf, - ): SDKResult<{ - customerGroupMemberships: CustomerGroupMembershipPartsFragment[]; - pageInfo: PageInfo | null; - }> { - const res = await request(this.#ctx, { - query: CustomerCustomerGroupsDocument, - variables, - }); - - return unwrapData(res, (q) => { - return { - customerGroupMemberships: q.customer - ? q.customer.customerGroupMemberships.edges.map((e) => e.node) - : [], - pageInfo: q.customer - ? q.customer.customerGroupMemberships.pageInfo - : null, - }; - }); - } - - async getCustomerTenantMemberships( - variables: VariablesOf, - ): SDKResult<{ - tenantMemberships: CustomerTenantMembershipPartsFragment[]; - pageInfo: PageInfo | null; - }> { - const res = await request(this.#ctx, { - query: CustomerTenantsDocument, - variables, - }); - - return unwrapData(res, (q) => { - return { - tenantMemberships: q.customer - ? q.customer.tenantMemberships.edges.map((e) => e.node) - : [], - pageInfo: q.customer ? q.customer.tenantMemberships.pageInfo : null, - }; - }); - } - - async sendNewEmail( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: SendNewEmailDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.sendNewEmail.email); - }); - } - - async replyToEmail( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: ReplyToEmailDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.replyToEmail.email); - }); - } - - async replyToThread( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: ReplyToThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async createAttachmentUploadUrl( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateAttachmentUploadUrlDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl); - }); - } - - /** - * Fetch the workspace for the authenticated API key. - */ - async getMyWorkspace(): SDKResult { - const res = await request(this.#ctx, { - query: MyWorkspaceDocument, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.myWorkspace); - }); - } - - /** - * Creates the configuration for a Customer Card. Useful if you want - * to programatically set up a customer card vs using the settings UI - */ - async createCustomerCardConfig( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.createCustomerCardConfig.customerCardConfig); - }); - } - - /** - * Updates the configuration for a Customer Card. - */ - async updateCustomerCardConfig( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => { - return nonNullable(q.updateCustomerCardConfig.customerCardConfig); - }); - } - - /** - * Delete the configuration for a Customer Card. - */ - async deleteCustomerCardConfig( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteCustomerCardConfigDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * Get a paginated list of threads - */ - async getThreads(variables: VariablesOf): SDKResult<{ - threads: ThreadPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: ThreadsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - threads: q.threads.edges.map((edge) => edge.node), - pageInfo: q.threads.pageInfo, - })); - } - - /** - * Get a single thread by id - */ - async getThread( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: ThreadDocument, - variables, - }); - - return unwrapData(res, (q) => q.thread); - } - - /** - * Get a single thread by external id. A thread's external id is unique per customer, - * hence why the customer id is also required. - */ - async getThreadByExternalId( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: ThreadByExternalIdDocument, - variables, - }); - - return unwrapData(res, (q) => q.threadByExternalId); - } - - /** - * Create a thread (e.g. when a contact form is submitted) - */ - async createThread( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createThread.thread)); - } - - /** - * Assign a thread to a user or machine user - */ - async assignThread( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: AssignThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.assignThread.thread)); - } - - /** - * Unassign a thread - */ - async unassignThread( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UnassignThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.unassignThread.thread)); - } - - /** - * Change a thread's priority - */ - async changeThreadPriority( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: ChangeThreadPriorityDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.changeThreadPriority.thread)); - } - - /** - * Update a thread's tenant - */ - async updateThreadTenant( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateThreadTenantDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.updateThreadTenant.thread)); - } - - /** - * Add labels to a thread - */ - async addLabels( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: AddLabelsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => q.addLabels.labels); - } - - /** - * Remove labels from a thread - */ - async removeLabels( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveLabelsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - /** - * Mark a thread as done - */ - async markThreadAsDone( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: MarkThreadAsDoneDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.markThreadAsDone.thread)); - } - - /** - * Snooze thread for a duration defined in seconds - */ - async snoozeThread( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: SnoozeThreadDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.snoozeThread.thread)); - } - - /** - * Mark a thread as Todo (e.g. Unsnooze) - */ - async markThreadAsTodo( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: MarkThreadAsTodoDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (d) => nonNullable(d.markThreadAsTodo.thread)); - } - - /** - * Archive a label type - */ - async archiveLabelType( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: ArchiveLabelTypeDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.archiveLabelType.labelType)); - } - - /** - * Get a paginated list of label types - */ - async getLabelTypes( - variables: VariablesOf, - ): SDKResult<{ - labelTypes: LabelTypePartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: LabelTypesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - labelTypes: q.labelTypes.edges.map((edge) => edge.node), - pageInfo: q.labelTypes.pageInfo, - })); - } - - /** - * Get a label type by id - */ - async getLabelType( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: LabelTypeDocument, - variables, - }); - - return unwrapData(res, (q) => q.labelType); - } - - /** Create a Customer Event */ - async createCustomerEvent( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateCustomerEventDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.createCustomerEvent.customerEvent), - ); - } - - /** Create a Thread Event */ - async createThreadEvent( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateThreadEventDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createThreadEvent.threadEvent)); - } - - async upsertThreadField( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertThreadFieldDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertThreadField.threadField)); - } - - async deleteThreadField( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteThreadFieldDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async createWebhookTarget( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.createWebhookTarget.webhookTarget), - ); - } - - async updateWebhookTarget( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.updateWebhookTarget.webhookTarget), - ); - } - - async deleteWebhookTarget( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: DeleteWebhookTargetDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async getWebhookTargets( - variables: VariablesOf, - ): SDKResult<{ - webhookTargets: WebhookTargetPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: WebhookTargetsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - pageInfo: q.webhookTargets.pageInfo, - webhookTargets: q.webhookTargets.edges.map((edge) => edge.node), - })); - } - - /** - * If the webhook target is not found it will return null - */ - async getWebhookTargetById( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: WebhookTargetDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.webhookTarget; - }); - } - - /** Create a note on a thread */ - async createNote( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateNoteDocument, - variables: { input }, - }); - - return unwrapData(res, (d) => nonNullable(d.createNote.note)); - } - async getTenantById( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: TenantDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.tenant; - }); - } - - async getTenants(variables: VariablesOf): SDKResult<{ - tenants: TenantPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: TenantsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.tenants.edges.map((edge) => edge.node), - pageInfo: q.tenants.pageInfo, - })); - } - - async searchTenants( - variables: VariablesOf, - ): SDKResult<{ - tenants: TenantPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: SearchTenantsDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.searchTenants.edges.map((edge) => edge.node.tenant), - pageInfo: q.searchTenants.pageInfo, - })); - } - - async upsertTenant( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertTenantDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertTenant.tenant)); - } - - async setCustomerTenants( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: SetCustomerTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async addCustomerToTenants( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: AddCustomerToTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async removeCustomerFromTenants( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveCustomerFromTenantsDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async upsertCompany( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpsertCompanyDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.upsertCompany.company)); - } - - async getCompanies( - variables: VariablesOf, - ): SDKResult<{ - companies: CompanyPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: CompaniesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - companies: q.companies.edges.map((edge) => edge.node), - pageInfo: q.companies.pageInfo, - })); - } - - async searchCompanies( - variables: VariablesOf, - ): SDKResult<{ - tenants: CompanyPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: SearchCompaniesDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tenants: q.searchCompanies.edges.map((edge) => edge.node.company), - pageInfo: q.searchCompanies.pageInfo, - })); - } - - async updateCustomerCompany( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCustomerCompanyDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (res) => - nonNullable(res.updateCustomerCompany.customer), - ); - } - - async getTierById( - variables: VariablesOf, - ): SDKResult { - const res = await request(this.#ctx, { - query: TierDocument, - variables, - }); - - return unwrapData(res, (q) => { - return q.tier; - }); - } - - async getTiers(variables: VariablesOf): SDKResult<{ - tiers: TierPartsFragment[]; - pageInfo: PageInfoPartsFragment; - }> { - const res = await request(this.#ctx, { - query: TiersDocument, - variables, - }); - - return unwrapData(res, (q) => ({ - tiers: q.tiers.edges.map((edge) => edge.node), - pageInfo: q.tiers.pageInfo, - })); - } - - async addMembersToTier( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: AddMembersToTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => q.addMembersToTier.memberships); - } - - async removeMembersFromTier( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: RemoveMembersFromTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, () => null); - } - - async updateTenantTier( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateTenantTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.updateTenantTier.tenantTierMembership), - ); - } - - async updateCompanyTier( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: UpdateCompanyTierDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => - nonNullable(q.updateCompanyTier.companyTierMembership), - ); - } - - async createLabelType( - input: VariablesOf["input"], - ): SDKResult { - const res = await request(this.#ctx, { - query: CreateLabelTypeDocument, - variables: { - input, - }, - }); - - return unwrapData(res, (q) => nonNullable(q.createLabelType.labelType)); - } + #ctx: Context; + + constructor(options: ConstructorOptions) { + this.#ctx = { + apiKey: options.apiKey, + apiUrl: options.apiUrl, + }; + } + + /** + * If you need to do something custom you can use this method to do + */ + async rawRequest(args: { + query: string; + variables: Record; + }): SDKResult { + return request(this.#ctx, { + query: args.query, + variables: args.variables, + }); + } + + /** + * Get a paginated list of customers. + * @deprecated "use `getUserByEmail" instead + */ + async userByEmail( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: UserByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => q.userByEmail || null); + } + + /** + * Get a paginated list of customers. + */ + async getUserByEmail( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: UserByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => q.userByEmail || null); + } + + /** + * Get a paginated list of customers. + */ + async getCustomers(variables: VariablesOf): SDKResult<{ + customers: CustomerPartsFragment[]; + pageInfo: PageInfoPartsFragment; + totalCount: number; + }> { + const res = await request(this.#ctx, { + query: CustomersDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.customers.pageInfo, + customers: q.customers.edges.map((edge) => edge.node), + totalCount: q.customers.totalCount, + })); + } + + /** + * If the customer is not found this will return null. + */ + async getCustomerById( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerByIdDocument, + variables, + }); + + return unwrapData(res, (q) => { + if (!q.customer) { + return null; + } + return q.customer; + }); + } + + /** + * If the customer is not found this will return null. + */ + async getCustomerByEmail( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerByEmailDocument, + variables, + }); + + return unwrapData(res, (q) => { + if (!q.customerByEmail) { + return null; + } + + return q.customerByEmail; + }); + } + + /** + * Allows you to create or update a customer. If you need to get the customer id + * for a customer in Plain, this is typically your first step. + */ + async upsertCustomer( + input: VariablesOf['input'] + ): SDKResult<{ result: UpsertResult; customer: CustomerPartsFragment }> { + const res = await request(this.#ctx, { + query: UpsertCustomerDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + const customer = nonNullable(q.upsertCustomer.customer); + return { + result: nonNullable(q.upsertCustomer.result), + customer, + }; + }); + } + + async deleteCustomer( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteCustomerDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * If the customer group is not found this will return null. + */ + async getCustomerGroupById( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: CustomerGroupByIdDocument, + variables, + }); + + return unwrapData(res, (q) => q.customerGroup); + } + + /** + * Get a paginated list of customer groups. + */ + async getCustomerGroups(variables: VariablesOf): SDKResult<{ + customerGroups: CustomerGroupPartsFragment[]; + pageInfo: PageInfo; + }> { + const res = await request(this.#ctx, { + query: CustomerGroupsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.customerGroups.pageInfo, + customerGroups: q.customerGroups.edges.map((edge) => edge.node), + })); + } + + /** + * Adds a customer to a customer groups. + */ + async addCustomerToCustomerGroups( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: AddCustomerToCustomerGroupsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => + nonNullable(q.addCustomerToCustomerGroups.customerGroupMemberships) + ); + } + + /** + * Remove a customer from customer groups. + */ + async removeCustomerFromCustomerGroups( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveCustomerFromCustomerGroupsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async getCustomerCustomerGroupMemberships( + variables: VariablesOf + ): SDKResult<{ + customerGroupMemberships: CustomerGroupMembershipPartsFragment[]; + pageInfo: PageInfo | null; + }> { + const res = await request(this.#ctx, { + query: CustomerCustomerGroupsDocument, + variables, + }); + + return unwrapData(res, (q) => { + return { + customerGroupMemberships: q.customer + ? q.customer.customerGroupMemberships.edges.map((e) => e.node) + : [], + pageInfo: q.customer ? q.customer.customerGroupMemberships.pageInfo : null, + }; + }); + } + + async getCustomerTenantMemberships( + variables: VariablesOf + ): SDKResult<{ + tenantMemberships: CustomerTenantMembershipPartsFragment[]; + pageInfo: PageInfo | null; + }> { + const res = await request(this.#ctx, { + query: CustomerTenantsDocument, + variables, + }); + + return unwrapData(res, (q) => { + return { + tenantMemberships: q.customer ? q.customer.tenantMemberships.edges.map((e) => e.node) : [], + pageInfo: q.customer ? q.customer.tenantMemberships.pageInfo : null, + }; + }); + } + + async sendNewEmail( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: SendNewEmailDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.sendNewEmail.email); + }); + } + + async replyToEmail( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: ReplyToEmailDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.replyToEmail.email); + }); + } + + async replyToThread(input: VariablesOf['input']): SDKResult { + const res = await request(this.#ctx, { + query: ReplyToThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async createAttachmentUploadUrl( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateAttachmentUploadUrlDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl); + }); + } + + /** + * Fetch the workspace for the authenticated API key. + */ + async getMyWorkspace(): SDKResult { + const res = await request(this.#ctx, { + query: MyWorkspaceDocument, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.myWorkspace); + }); + } + + /** + * Creates the configuration for a Customer Card. Useful if you want + * to programatically set up a customer card vs using the settings UI + */ + async createCustomerCardConfig( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.createCustomerCardConfig.customerCardConfig); + }); + } + + /** + * Updates the configuration for a Customer Card. + */ + async updateCustomerCardConfig( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => { + return nonNullable(q.updateCustomerCardConfig.customerCardConfig); + }); + } + + /** + * Delete the configuration for a Customer Card. + */ + async deleteCustomerCardConfig( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteCustomerCardConfigDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * Get a paginated list of threads + */ + async getThreads(variables: VariablesOf): SDKResult<{ + threads: ThreadPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: ThreadsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + threads: q.threads.edges.map((edge) => edge.node), + pageInfo: q.threads.pageInfo, + })); + } + + /** + * Get a single thread by id + */ + async getThread( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: ThreadDocument, + variables, + }); + + return unwrapData(res, (q) => q.thread); + } + + /** + * Get a single thread by external id. A thread's external id is unique per customer, + * hence why the customer id is also required. + */ + async getThreadByExternalId( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: ThreadByExternalIdDocument, + variables, + }); + + return unwrapData(res, (q) => q.threadByExternalId); + } + + /** + * Create a thread (e.g. when a contact form is submitted) + */ + async createThread( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createThread.thread)); + } + + /** + * Assign a thread to a user or machine user + */ + async assignThread( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: AssignThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.assignThread.thread)); + } + + /** + * Unassign a thread + */ + async unassignThread( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UnassignThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.unassignThread.thread)); + } + + /** + * Change a thread's priority + */ + async changeThreadPriority( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: ChangeThreadPriorityDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.changeThreadPriority.thread)); + } + + /** + * Update a thread's tenant + */ + async updateThreadTenant( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateThreadTenantDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.updateThreadTenant.thread)); + } + + /** + * Add labels to a thread + */ + async addLabels( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: AddLabelsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => q.addLabels.labels); + } + + /** + * Remove labels from a thread + */ + async removeLabels(input: VariablesOf['input']): SDKResult { + const res = await request(this.#ctx, { + query: RemoveLabelsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + /** + * Mark a thread as done + */ + async markThreadAsDone( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: MarkThreadAsDoneDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.markThreadAsDone.thread)); + } + + /** + * Snooze thread for a duration defined in seconds + */ + async snoozeThread( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: SnoozeThreadDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.snoozeThread.thread)); + } + + /** + * Mark a thread as Todo (e.g. Unsnooze) + */ + async markThreadAsTodo( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: MarkThreadAsTodoDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (d) => nonNullable(d.markThreadAsTodo.thread)); + } + + /** + * Archive a label type + */ + async archiveLabelType( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: ArchiveLabelTypeDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.archiveLabelType.labelType)); + } + + /** + * Get a paginated list of label types + */ + async getLabelTypes(variables: VariablesOf): SDKResult<{ + labelTypes: LabelTypePartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: LabelTypesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + labelTypes: q.labelTypes.edges.map((edge) => edge.node), + pageInfo: q.labelTypes.pageInfo, + })); + } + + /** + * Get a label type by id + */ + async getLabelType( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: LabelTypeDocument, + variables, + }); + + return unwrapData(res, (q) => q.labelType); + } + + /** Create a Customer Event */ + async createCustomerEvent( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateCustomerEventDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createCustomerEvent.customerEvent)); + } + + /** Create a Thread Event */ + async createThreadEvent( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateThreadEventDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createThreadEvent.threadEvent)); + } + + async upsertThreadField( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertThreadFieldDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertThreadField.threadField)); + } + + async deleteThreadField( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteThreadFieldDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async createWebhookTarget( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createWebhookTarget.webhookTarget)); + } + + async updateWebhookTarget( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.updateWebhookTarget.webhookTarget)); + } + + async deleteWebhookTarget( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: DeleteWebhookTargetDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async getWebhookTargets(variables: VariablesOf): SDKResult<{ + webhookTargets: WebhookTargetPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: WebhookTargetsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + pageInfo: q.webhookTargets.pageInfo, + webhookTargets: q.webhookTargets.edges.map((edge) => edge.node), + })); + } + + /** + * If the webhook target is not found it will return null + */ + async getWebhookTargetById( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: WebhookTargetDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.webhookTarget; + }); + } + + /** Create a note on a thread */ + async createNote( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateNoteDocument, + variables: { input }, + }); + + return unwrapData(res, (d) => nonNullable(d.createNote.note)); + } + async getTenantById( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: TenantDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.tenant; + }); + } + + async getTenants(variables: VariablesOf): SDKResult<{ + tenants: TenantPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: TenantsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.tenants.edges.map((edge) => edge.node), + pageInfo: q.tenants.pageInfo, + })); + } + + async searchTenants(variables: VariablesOf): SDKResult<{ + tenants: TenantPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: SearchTenantsDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.searchTenants.edges.map((edge) => edge.node.tenant), + pageInfo: q.searchTenants.pageInfo, + })); + } + + async upsertTenant( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertTenantDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertTenant.tenant)); + } + + async setCustomerTenants( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: SetCustomerTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async addCustomerToTenants( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: AddCustomerToTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async removeCustomerFromTenants( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveCustomerFromTenantsDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async upsertCompany( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpsertCompanyDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.upsertCompany.company)); + } + + async getCompanies(variables: VariablesOf): SDKResult<{ + companies: CompanyPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: CompaniesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + companies: q.companies.edges.map((edge) => edge.node), + pageInfo: q.companies.pageInfo, + })); + } + + async searchCompanies(variables: VariablesOf): SDKResult<{ + tenants: CompanyPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: SearchCompaniesDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tenants: q.searchCompanies.edges.map((edge) => edge.node.company), + pageInfo: q.searchCompanies.pageInfo, + })); + } + + async updateCustomerCompany( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCustomerCompanyDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (res) => nonNullable(res.updateCustomerCompany.customer)); + } + + async getTierById( + variables: VariablesOf + ): SDKResult { + const res = await request(this.#ctx, { + query: TierDocument, + variables, + }); + + return unwrapData(res, (q) => { + return q.tier; + }); + } + + async getTiers(variables: VariablesOf): SDKResult<{ + tiers: TierPartsFragment[]; + pageInfo: PageInfoPartsFragment; + }> { + const res = await request(this.#ctx, { + query: TiersDocument, + variables, + }); + + return unwrapData(res, (q) => ({ + tiers: q.tiers.edges.map((edge) => edge.node), + pageInfo: q.tiers.pageInfo, + })); + } + + async addMembersToTier( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: AddMembersToTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => q.addMembersToTier.memberships); + } + + async removeMembersFromTier( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: RemoveMembersFromTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, () => null); + } + + async updateTenantTier( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateTenantTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.updateTenantTier.tenantTierMembership)); + } + + async updateCompanyTier( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: UpdateCompanyTierDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.updateCompanyTier.companyTierMembership)); + } + + async createLabelType( + input: VariablesOf['input'] + ): SDKResult { + const res = await request(this.#ctx, { + query: CreateLabelTypeDocument, + variables: { + input, + }, + }); + + return unwrapData(res, (q) => nonNullable(q.createLabelType.labelType)); + } } diff --git a/src/graphql/mutations/createLabelType.gql b/src/graphql/mutations/createLabelType.gql index 1e719e4..8256365 100644 --- a/src/graphql/mutations/createLabelType.gql +++ b/src/graphql/mutations/createLabelType.gql @@ -7,4 +7,4 @@ mutation createLabelType($input: CreateLabelTypeInput!) { ...MutationErrorParts } } -} \ No newline at end of file +}