From 3581db042f69ed71e72eb04b634a8436fd2d80ab Mon Sep 17 00:00:00 2001 From: Jesus Date: Tue, 30 Apr 2024 18:37:48 +0200 Subject: [PATCH] Updated with new webhook schema --- .changeset/witty-lizards-sleep.md | 5 + src/graphql/types.ts | 31 ++++ src/webhooks/webhook-schema.json | 289 ++++++++++++++++++++++++++++-- src/webhooks/webhook-schema.ts | 83 +++++++-- 4 files changed, 380 insertions(+), 28 deletions(-) create mode 100644 .changeset/witty-lizards-sleep.md diff --git a/.changeset/witty-lizards-sleep.md b/.changeset/witty-lizards-sleep.md new file mode 100644 index 0000000..a0506d4 --- /dev/null +++ b/.changeset/witty-lizards-sleep.md @@ -0,0 +1,5 @@ +--- +'@team-plain/typescript-sdk': patch +--- + +Updated webhook schema diff --git a/src/graphql/types.ts b/src/graphql/types.ts index f6541f5..0cab9a9 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -222,6 +222,22 @@ export type BreachActionInput = { onBreachAction?: InputMaybe; }; +export type BulkUpsertThreadFieldResult = { + __typename?: 'BulkUpsertThreadFieldResult'; + result: Maybe; + threadField: Maybe; +}; + +export type BulkUpsertThreadFieldsInput = { + inputs: Array; +}; + +export type BulkUpsertThreadFieldsOutput = { + __typename?: 'BulkUpsertThreadFieldsOutput'; + error: Maybe; + results: Array; +}; + /** * Represents the times in which you are open for business during a week. If a day is null, it means that day you are not * open for business. @@ -821,6 +837,13 @@ export type CreateThreadEventOutput = { threadEvent: Maybe; }; +export type CreateThreadFieldOnThreadInput = { + booleanValue?: InputMaybe; + key: Scalars['String']; + stringValue?: InputMaybe; + type: ThreadFieldSchemaType; +}; + export type CreateThreadFieldSchemaInput = { dependsOnThreadField?: InputMaybe; description: Scalars['String']; @@ -861,6 +884,8 @@ export type CreateThreadInput = { priority?: InputMaybe; /** A thread may be assigned to a specific tenant. */ tenantIdentifier?: InputMaybe; + /** An array of thread fields to attach to the thread upon creation. */ + threadFields?: InputMaybe>; /** The title of the thread. */ title: Scalars['String']; }; @@ -2122,6 +2147,7 @@ export type Mutation = { archiveLabelType: ArchiveLabelTypeOutput; assignRolesToUser: AssignRolesToUserOutput; assignThread: AssignThreadOutput; + bulkUpsertThreadFields: BulkUpsertThreadFieldsOutput; changeThreadPriority: ChangeThreadPriorityOutput; changeUserStatus: ChangeUserStatusOutput; completeServiceAuthorization: CompleteServiceAuthorizationOutput; @@ -2313,6 +2339,11 @@ export type MutationAssignThreadArgs = { }; +export type MutationBulkUpsertThreadFieldsArgs = { + input: BulkUpsertThreadFieldsInput; +}; + + export type MutationChangeThreadPriorityArgs = { input: ChangeThreadPriorityInput; }; diff --git a/src/webhooks/webhook-schema.json b/src/webhooks/webhook-schema.json index 49b348c..7b4b7b1 100644 --- a/src/webhooks/webhook-schema.json +++ b/src/webhooks/webhook-schema.json @@ -3,7 +3,7 @@ "type": "object", "properties": { "timestamp": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" }, "workspaceId": { "$ref": "#/definitions/id" @@ -55,6 +55,9 @@ { "$ref": "#/definitions/threadChatSentPublicEventPayload" }, + { + "$ref": "#/definitions/threadServiceLevelAgreementStatusTransitionedPayload" + }, { "$ref": "#/definitions/customerCreatedPublicEventPayload" }, @@ -84,6 +87,7 @@ "thread.thread_field_created", "thread.thread_field_updated", "thread.thread_field_deleted", + "thread.service_level_agreement_status_transitioned", "customer.customer_created", "customer.customer_updated", "customer.customer_deleted", @@ -1553,6 +1557,9 @@ ], "additionalProperties": false }, + "threadPriority": { + "type": "number" + }, "threadAssignee": { "anyOf": [ { @@ -1587,16 +1594,7 @@ "type": "object", "properties": { "timestamp": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "string", - "format": "date-time" - }, - {} - ] + "$ref": "#/definitions/datetime" }, "messageSource": { "type": "string", @@ -1624,7 +1622,7 @@ "const": "CREATED" }, "createdAt": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" } }, "required": [ @@ -1641,10 +1639,10 @@ "const": "SNOOZED" }, "snoozedAt": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" }, "snoozedUntil": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" } }, "required": [ @@ -1662,7 +1660,7 @@ "const": "UNSNOOZED" }, "snoozedAt": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" } }, "required": [ @@ -1679,7 +1677,7 @@ "const": "NEW_REPLY" }, "newReplyAt": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" } }, "required": [ @@ -1696,7 +1694,7 @@ "const": "LINK_LINEAR_UPDATED" }, "updatedAt": { - "$ref": "#/definitions/threadMessageInfo/properties/timestamp" + "$ref": "#/definitions/datetime" }, "linearIssueId": { "type": "string", @@ -1790,7 +1788,7 @@ "default": null }, "priority": { - "type": "number" + "$ref": "#/definitions/threadPriority" }, "externalId": { "anyOf": [ @@ -2253,6 +2251,232 @@ ], "additionalProperties": false }, + "tier": { + "type": "object", + "properties": { + "id": { + "$ref": "#/definitions/id" + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + "externalId": { + "anyOf": [ + { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + { + "type": "null" + } + ] + }, + "color": { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + "defaultThreadPriority": { + "$ref": "#/definitions/threadPriority", + "default": 2 + }, + "isDefault": { + "type": "boolean" + }, + "createdAt": { + "$ref": "#/definitions/datetime" + }, + "createdBy": { + "$ref": "#/definitions/internalActor" + }, + "updatedAt": { + "$ref": "#/definitions/datetime" + }, + "updatedBy": { + "$ref": "#/definitions/internalActor" + } + }, + "required": [ + "id", + "name", + "externalId", + "color", + "isDefault", + "createdAt", + "createdBy", + "updatedAt", + "updatedBy" + ], + "additionalProperties": false + }, + "serviceLevelAgreementStatusDetail": { + "anyOf": [ + { + "type": "object", + "properties": { + "breachTime": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "PENDING" + } + }, + "required": [ + "breachTime", + "status" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "achievedAt": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "ACHIEVED" + } + }, + "required": [ + "achievedAt", + "status" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "breachTime": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "IMMINENT_BREACH" + } + }, + "required": [ + "breachTime", + "status" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "breachedAt": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "BREACHING" + } + }, + "required": [ + "breachedAt", + "status" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "breachedAt": { + "$ref": "#/definitions/datetime" + }, + "completedAt": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "BREACHED" + } + }, + "required": [ + "breachedAt", + "completedAt", + "status" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "cancelledAt": { + "$ref": "#/definitions/datetime" + }, + "status": { + "type": "string", + "const": "CANCELLED" + } + }, + "required": [ + "cancelledAt", + "status" + ], + "additionalProperties": false + } + ] + }, + "serviceLevelAgreement": { + "type": "object", + "properties": { + "id": { + "$ref": "#/definitions/id" + }, + "type": { + "type": "string", + "enum": [ + "FIRST_RESPONSE_TIME" + ] + }, + "tier": { + "$ref": "#/definitions/tier" + }, + "firstResponseTimeMinutes": { + "type": "number" + }, + "useBusinessHoursOnly": { + "type": "boolean" + }, + "threadPriorityFilter": { + "type": "array", + "items": { + "$ref": "#/definitions/threadPriority" + }, + "minItems": 1 + }, + "createdAt": { + "$ref": "#/definitions/datetime" + }, + "createdBy": { + "$ref": "#/definitions/internalActor" + }, + "updatedAt": { + "$ref": "#/definitions/datetime" + }, + "updatedBy": { + "$ref": "#/definitions/internalActor" + } + }, + "required": [ + "id", + "type", + "tier", + "firstResponseTimeMinutes", + "useBusinessHoursOnly", + "threadPriorityFilter", + "createdAt", + "createdBy", + "updatedAt", + "updatedBy" + ], + "additionalProperties": false + }, "customerChangedPayload": { "type": "object", "properties": { @@ -2812,6 +3036,35 @@ ], "additionalProperties": false }, + "threadServiceLevelAgreementStatusTransitionedPayload": { + "type": "object", + "properties": { + "eventType": { + "type": "string", + "const": "thread.service_level_agreement_status_transitioned" + }, + "thread": { + "$ref": "#/definitions/thread" + }, + "serviceLevelAgreement": { + "$ref": "#/definitions/serviceLevelAgreement" + }, + "previousServiceLevelAgreementStatusDetail": { + "$ref": "#/definitions/serviceLevelAgreementStatusDetail" + }, + "serviceLevelAgreementStatusDetail": { + "$ref": "#/definitions/serviceLevelAgreementStatusDetail" + } + }, + "required": [ + "eventType", + "thread", + "serviceLevelAgreement", + "previousServiceLevelAgreementStatusDetail", + "serviceLevelAgreementStatusDetail" + ], + "additionalProperties": false + }, "customerCreatedPublicEventPayload": { "type": "object", "properties": { diff --git a/src/webhooks/webhook-schema.ts b/src/webhooks/webhook-schema.ts index af5b475..68c4129 100644 --- a/src/webhooks/webhook-schema.ts +++ b/src/webhooks/webhook-schema.ts @@ -5,9 +5,9 @@ * and run json-schema-to-typescript to regenerate this file. */ +export type Datetime = string; export type Id = string; export type EmailAddress = string; -export type Datetime = string; export type InternalActor = UserActor | MachineUserActor | SystemActor; export type CustomerGroupMemberships = CustomerGroupMembership[]; export type Actor = UserActor | MachineUserActor | SystemActor | CustomerActor; @@ -73,28 +73,29 @@ export type CustomerGroupChangedPayload = eventType: "customer.customer_group_changed"; previousCustomerGroup: CustomerGroup; }; +export type ThreadPriority = number; export type ThreadStatus = "TODO" | "DONE" | "SNOOZED"; export type ThreadStatusDetail = | { type: "CREATED"; - createdAt: string | string | unknown; + createdAt: Datetime; } | { type: "SNOOZED"; - snoozedAt: string | string | unknown; - snoozedUntil: string | string | unknown; + snoozedAt: Datetime; + snoozedUntil: Datetime; } | { type: "UNSNOOZED"; - snoozedAt: string | string | unknown; + snoozedAt: Datetime; } | { type: "NEW_REPLY"; - newReplyAt: string | string | unknown; + newReplyAt: Datetime; } | { type: "LINK_LINEAR_UPDATED"; - updatedAt: string | string | unknown; + updatedAt: Datetime; linearIssueId: string; }; export type ThreadAssignee = @@ -103,12 +104,38 @@ export type ThreadAssignee = | { id: string; }; +export type ServiceLevelAgreementStatusDetail = + | { + breachTime: Datetime; + status: "PENDING"; + } + | { + achievedAt: Datetime; + status: "ACHIEVED"; + } + | { + breachTime: Datetime; + status: "IMMINENT_BREACH"; + } + | { + breachedAt: Datetime; + status: "BREACHING"; + } + | { + breachedAt: Datetime; + completedAt: Datetime; + status: "BREACHED"; + } + | { + cancelledAt: Datetime; + status: "CANCELLED"; + }; /** * Webhook request */ export interface WebhooksSchemaDefinition { - timestamp: unknown; + timestamp: Datetime; workspaceId: Id; payload: | CustomerChangedPayload @@ -126,6 +153,7 @@ export interface WebhooksSchemaDefinition { | ThreadFieldUpdatedPublicEventPayload | ThreadFieldDeletedPublicEventPayload | ThreadChatSentPublicEventPayload + | ThreadServiceLevelAgreementStatusTransitionedPayload | CustomerCreatedPublicEventPayload | CustomerUpdatedPublicEventPayload | CustomerDeletedPublicEventPayload; @@ -143,6 +171,7 @@ export interface WebhooksSchemaDefinition { | "thread.thread_field_created" | "thread.thread_field_updated" | "thread.thread_field_deleted" + | "thread.service_level_agreement_status_transitioned" | "customer.customer_created" | "customer.customer_updated" | "customer.customer_deleted" @@ -425,7 +454,7 @@ export interface Thread { customer: Customer1; title: string; previewText?: string | null; - priority: number; + priority: ThreadPriority; externalId: string | null; status: ThreadStatus; statusChangedAt: Datetime | null; @@ -477,7 +506,7 @@ export interface LabelType { updatedBy: InternalActor; } export interface ThreadMessageInfo { - timestamp: string | string | unknown; + timestamp: Datetime; messageSource: "CHAT" | "EMAIL" | "API" | "SLACK"; } export interface ThreadStatusTransitionedPublicEventPayload { @@ -588,6 +617,40 @@ export interface Chat { updatedAt: Datetime; updatedBy: Actor; } +export interface ThreadServiceLevelAgreementStatusTransitionedPayload { + eventType: "thread.service_level_agreement_status_transitioned"; + thread: Thread; + serviceLevelAgreement: ServiceLevelAgreement; + previousServiceLevelAgreementStatusDetail: ServiceLevelAgreementStatusDetail; + serviceLevelAgreementStatusDetail: ServiceLevelAgreementStatusDetail; +} +export interface ServiceLevelAgreement { + id: Id; + type: "FIRST_RESPONSE_TIME"; + tier: Tier; + firstResponseTimeMinutes: number; + useBusinessHoursOnly: boolean; + /** + * @minItems 1 + */ + threadPriorityFilter: [ThreadPriority, ...ThreadPriority[]]; + createdAt: Datetime; + createdBy: InternalActor; + updatedAt: Datetime; + updatedBy: InternalActor; +} +export interface Tier { + id: Id; + name: string; + externalId: string | null; + color: string; + defaultThreadPriority?: number; + isDefault: boolean; + createdAt: Datetime; + createdBy: InternalActor; + updatedAt: Datetime; + updatedBy: InternalActor; +} /** * A customer has been created */