From e1203107eec3be2aad6c0107045a1dcee6e781af Mon Sep 17 00:00:00 2001 From: refarer <14077091+refarer@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:06:16 +1300 Subject: [PATCH 1/4] fix tags --- scripts/generate.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/generate.ts b/scripts/generate.ts index 5860f89..b99c79d 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -38,6 +38,14 @@ function importTypes(operationIds: string[]) { return output; } +function convertTag(tag: string) { + const [fst, ...rest] = tag.toLowerCase().split(" "); + return ( + fst.toLowerCase() + + rest.map((x) => x.charAt(0).toUpperCase() + x.slice(1)).join("") + ); +} + function functionDocs( summary?: string, description?: string, @@ -193,7 +201,7 @@ export async function generate(): Promise { const { paths, tags } = spec; const classes = tags.reduce((prev: any, next: { name: string }) => { - const name = next.name.toLowerCase(); + const name = convertTag(next.name); return { ...prev, [name]: { functions: [], ...next }, @@ -254,7 +262,7 @@ import { OAuth2Bearer } from "../auth";\n\n`; operationIds.push(operationId); if (!tags?.length) throw "No tags found"; - const tag = tags[0].toLowerCase(); + const tag = convertTag(tags[0]); classes[tag].functions.push( functionDocs( summary, From c9cf828336dd96fd9e49d300e4eb02f44bb65048 Mon Sep 17 00:00:00 2001 From: refarer <14077091+refarer@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:06:28 +1300 Subject: [PATCH 2/4] openapi-2.55-update --- src/gen/Client.ts | 157 ++++++++++++++++- src/gen/openapi-types.ts | 367 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 522 insertions(+), 2 deletions(-) diff --git a/src/gen/Client.ts b/src/gen/Client.ts index 7f9c98c..e0a91d3 100644 --- a/src/gen/Client.ts +++ b/src/gen/Client.ts @@ -20,6 +20,12 @@ import { listBatchComplianceJobs, createBatchComplianceJob, getBatchComplianceJob, + dmConversationIdCreate, + getDmConversationsWithParticipantIdDmEvents, + dmConversationWithUserEventIdCreate, + dmConversationByIdEventIdCreate, + getDmConversationsIdDmEvents, + getDmEvents, listIdCreate, listIdDelete, listIdGet, @@ -108,8 +114,8 @@ export class Client { auth: string | AuthClient, requestOptions?: Partial ) { - this.version = "1.2.1"; - this.twitterApiOpenApiVersion = "2.54"; + this.version = "1.3.0"; + this.twitterApiOpenApiVersion = "2.55"; this.#auth = typeof auth === "string" ? new OAuth2Bearer(auth) : auth; this.#defaultRequestOptions = { ...requestOptions, @@ -334,6 +340,153 @@ export class Client { method: "GET", }), }; + /** + * Direct Messages + * + * Endpoints related to retrieving, managing Direct Messages + * + * Find out more + * https://developer.twitter.com/en/docs/twitter-api/direct-messages + */ + public readonly directMessages = { + /** + * Create a new DM Conversation + * + + * Creates a new DM Conversation. + * @param request_body - The request_body for dmConversationIdCreate + * @param request_options - Customize the options for this request + */ + dmConversationIdCreate: ( + request_body: TwitterBody, + request_options?: Partial + ): Promise> => + rest>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_conversations`, + request_body, + method: "POST", + }), + + /** + * Get DM Events for a DM Conversation + * + + * Returns DM Events for a DM Conversation + * @param participant_id - The ID of the participant user for the One to One DM conversation. + * @param params - The params for getDmConversationsWithParticipantIdDmEvents + * @param request_options - Customize the options for this request + */ + getDmConversationsWithParticipantIdDmEvents: ( + participant_id: string, + params: TwitterParams = {}, + request_options?: Partial + ): TwitterPaginatedResponse< + TwitterResponse + > => + paginate>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_conversations/with/${participant_id}/dm_events`, + params, + method: "GET", + }), + + /** + * Send a new message to a user + * + + * Creates a new message for a DM Conversation with a participant user by ID + * @param participant_id - The ID of the recipient user that will receive the DM. + * @param request_body - The request_body for dmConversationWithUserEventIdCreate + * @param request_options - Customize the options for this request + */ + dmConversationWithUserEventIdCreate: ( + participant_id: string, + request_body: TwitterBody, + request_options?: Partial + ): Promise> => + rest>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_conversations/with/${participant_id}/messages`, + request_body, + method: "POST", + }), + + /** + * Send a new message to a DM Conversation + * + + * Creates a new message for a DM Conversation specified by DM Conversation ID + * @param dm_conversation_id - The DM Conversation ID. + * @param request_body - The request_body for dmConversationByIdEventIdCreate + * @param request_options - Customize the options for this request + */ + dmConversationByIdEventIdCreate: ( + dm_conversation_id: string, + request_body: TwitterBody, + request_options?: Partial + ): Promise> => + rest>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_conversations/${dm_conversation_id}/messages`, + request_body, + method: "POST", + }), + + /** + * Get DM Events for a DM Conversation + * + + * Returns DM Events for a DM Conversation + * @param id - The DM Conversation ID. + * @param params - The params for getDmConversationsIdDmEvents + * @param request_options - Customize the options for this request + */ + getDmConversationsIdDmEvents: ( + id: string, + params: TwitterParams = {}, + request_options?: Partial + ): TwitterPaginatedResponse< + TwitterResponse + > => + paginate>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_conversations/${id}/dm_events`, + params, + method: "GET", + }), + + /** + * Get recent DM Events + * + + * Returns recent DM Events across DM conversations + * @param params - The params for getDmEvents + * @param request_options - Customize the options for this request + */ + getDmEvents: ( + params: TwitterParams = {}, + request_options?: Partial + ): TwitterPaginatedResponse> => + paginate>({ + auth: this.#auth, + ...this.#defaultRequestOptions, + ...request_options, + endpoint: `/2/dm_events`, + params, + method: "GET", + }), + }; /** * General * diff --git a/src/gen/openapi-types.ts b/src/gen/openapi-types.ts index 808906a..fa1d673 100644 --- a/src/gen/openapi-types.ts +++ b/src/gen/openapi-types.ts @@ -17,6 +17,30 @@ export interface paths { /** Returns a single Compliance Job by ID */ get: operations["getBatchComplianceJob"]; }; + "/2/dm_conversations": { + /** Creates a new DM Conversation. */ + post: operations["dmConversationIdCreate"]; + }; + "/2/dm_conversations/with/{participant_id}/dm_events": { + /** Returns DM Events for a DM Conversation */ + get: operations["getDmConversationsWithParticipantIdDmEvents"]; + }; + "/2/dm_conversations/with/{participant_id}/messages": { + /** Creates a new message for a DM Conversation with a participant user by ID */ + post: operations["dmConversationWithUserEventIdCreate"]; + }; + "/2/dm_conversations/{dm_conversation_id}/messages": { + /** Creates a new message for a DM Conversation specified by DM Conversation ID */ + post: operations["dmConversationByIdEventIdCreate"]; + }; + "/2/dm_conversations/{id}/dm_events": { + /** Returns DM Events for a DM Conversation */ + get: operations["getDmConversationsIdDmEvents"]; + }; + "/2/dm_events": { + /** Returns recent DM Events across DM conversations */ + get: operations["getDmEvents"]; + }; "/2/lists": { /** Creates a new List. */ post: operations["listIdCreate"]; @@ -409,6 +433,11 @@ export interface components { * @example US */ CountryCode: string; + CreateAttachmentsMessageRequest: { + attachments: components["schemas"]["DmAttachments"]; + /** @description Text of the message. */ + text?: string; + }; /** @description A request to create a new batch compliance job. */ CreateComplianceJobRequest: { name?: components["schemas"]["ComplianceJobName"]; @@ -424,6 +453,31 @@ export interface components { data?: components["schemas"]["ComplianceJob"]; errors?: components["schemas"]["Problem"][]; }; + CreateDmConversationRequest: { + /** + * @description The conversation type that is being created. + * @enum {string} + */ + conversation_type: "Group"; + message: components["schemas"]["CreateMessageRequest"]; + participant_ids: components["schemas"]["DmParticipants"]; + }; + CreateDmEventResponse: { + data?: { + dm_conversation_id: components["schemas"]["DmConversationId"]; + dm_event_id: components["schemas"]["DmEventId"]; + }; + errors?: components["schemas"]["Problem"][]; + }; + CreateMessageRequest: Partial< + components["schemas"]["CreateTextMessageRequest"] + > & + Partial; + CreateTextMessageRequest: { + attachments?: components["schemas"]["DmAttachments"]; + /** @description Text of the message. */ + text: string; + }; /** * Format: date-time * @description Creation time of the compliance job. @@ -448,6 +502,46 @@ export interface components { /** @enum {string} */ section: "data" | "includes"; }; + /** @description Attachments to a DM Event. */ + DmAttachments: components["schemas"]["DmMediaAttachment"][]; + /** + * @description Unique identifier of a DM conversation. This can either be a numeric string, or a pair of numeric strings separated by a '-' character in the case of one-on-one DM Conversations. + * @example 123123123-456456456 + */ + DmConversationId: string; + DmEvent: { + /** @description Specifies the type of attachments (if any) present in this DM. */ + attachments?: { + /** @description A list of card IDs (if cards are attached). */ + card_ids?: string[]; + /** @description A list of Media Keys for each one of the media attachments (if media are attached). */ + media_keys?: components["schemas"]["MediaKey"][]; + }; + /** Format: date-time */ + created_at?: string; + dm_conversation_id?: components["schemas"]["DmConversationId"]; + /** @example MessageCreate */ + event_type: string; + id: components["schemas"]["DmEventId"]; + /** @description A list of participants for a ParticipantsJoin or ParticipantsLeave event_type. */ + participant_ids?: components["schemas"]["UserId"][]; + /** @description A list of Tweets this DM refers to. */ + referenced_tweets?: { + id: components["schemas"]["TweetId"]; + }[]; + sender_id?: components["schemas"]["UserId"]; + text?: string; + }; + /** + * @description Unique identifier of a DM Event. + * @example 1146654567674912769 + */ + DmEventId: string; + DmMediaAttachment: { + media_id: components["schemas"]["MediaId"]; + }; + /** @description Participants for the DM Conversation. */ + DmParticipants: components["schemas"]["UserId"][]; /** * Format: date-time * @description Expiration time of the download URL. @@ -578,6 +672,36 @@ export interface components { result_count?: components["schemas"]["ResultCount"]; }; }; + Get2DmConversationsIdDmEventsResponse: { + data?: components["schemas"]["DmEvent"][]; + errors?: components["schemas"]["Problem"][]; + includes?: components["schemas"]["Expansions"]; + meta?: { + next_token?: components["schemas"]["NextToken"]; + previous_token?: components["schemas"]["PreviousToken"]; + result_count?: components["schemas"]["ResultCount"]; + }; + }; + Get2DmConversationsWithParticipantIdDmEventsResponse: { + data?: components["schemas"]["DmEvent"][]; + errors?: components["schemas"]["Problem"][]; + includes?: components["schemas"]["Expansions"]; + meta?: { + next_token?: components["schemas"]["NextToken"]; + previous_token?: components["schemas"]["PreviousToken"]; + result_count?: components["schemas"]["ResultCount"]; + }; + }; + Get2DmEventsResponse: { + data?: components["schemas"]["DmEvent"][]; + errors?: components["schemas"]["Problem"][]; + includes?: components["schemas"]["Expansions"]; + meta?: { + next_token?: components["schemas"]["NextToken"]; + previous_token?: components["schemas"]["PreviousToken"]; + result_count?: components["schemas"]["ResultCount"]; + }; + }; Get2ListsIdFollowersResponse: { data?: components["schemas"]["User"][]; errors?: components["schemas"]["Problem"][]; @@ -2195,6 +2319,27 @@ export interface components { | "upload_expires_at" | "upload_url" )[]; + /** @description A comma separated list of DmConversation fields to display. */ + DmConversationFieldsParameter: "id"[]; + /** @description A comma separated list of fields to expand. */ + DmEventExpansionsParameter: ( + | "attachments.media_keys" + | "participant_ids" + | "referenced_tweets.id" + | "sender_id" + )[]; + /** @description A comma separated list of DmEvent fields to display. */ + DmEventFieldsParameter: ( + | "attachments" + | "created_at" + | "dm_conversation_id" + | "event_type" + | "id" + | "participant_ids" + | "referenced_tweets" + | "sender_id" + | "text" + )[]; /** @description A comma separated list of fields to expand. */ ListExpansionsParameter: "owner_id"[]; /** @description A comma separated list of List fields to display. */ @@ -2415,6 +2560,222 @@ export interface operations { }; }; }; + /** Creates a new DM Conversation. */ + dmConversationIdCreate: { + parameters: {}; + responses: { + /** The request has succeeded. */ + 201: { + content: { + "application/json": components["schemas"]["CreateDmEventResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["CreateDmConversationRequest"]; + }; + }; + }; + /** Returns DM Events for a DM Conversation */ + getDmConversationsWithParticipantIdDmEvents: { + parameters: { + path: { + /** The ID of the participant user for the One to One DM conversation. */ + participant_id: components["schemas"]["UserId"]; + }; + query: { + /** The maximum number of results. */ + max_results?: number; + /** This parameter is used to get a specified 'page' of results. */ + pagination_token?: components["schemas"]["PaginationToken32"]; + /** The set of event_types to include in the results. */ + event_types?: ( + | "MessageCreate" + | "ParticipantsJoin" + | "ParticipantsLeave" + )[]; + /** A comma separated list of DmEvent fields to display. */ + "dm_event.fields"?: components["parameters"]["DmEventFieldsParameter"]; + /** A comma separated list of fields to expand. */ + expansions?: components["parameters"]["DmEventExpansionsParameter"]; + /** A comma separated list of Media fields to display. */ + "media.fields"?: components["parameters"]["MediaFieldsParameter"]; + /** A comma separated list of User fields to display. */ + "user.fields"?: components["parameters"]["UserFieldsParameter"]; + /** A comma separated list of Tweet fields to display. */ + "tweet.fields"?: components["parameters"]["TweetFieldsParameter"]; + }; + }; + responses: { + /** The request has succeeded. */ + 200: { + content: { + "application/json": components["schemas"]["Get2DmConversationsWithParticipantIdDmEventsResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + }; + /** Creates a new message for a DM Conversation with a participant user by ID */ + dmConversationWithUserEventIdCreate: { + parameters: { + path: { + /** The ID of the recipient user that will receive the DM. */ + participant_id: components["schemas"]["UserId"]; + }; + }; + responses: { + /** The request has succeeded. */ + 201: { + content: { + "application/json": components["schemas"]["CreateDmEventResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["CreateMessageRequest"]; + }; + }; + }; + /** Creates a new message for a DM Conversation specified by DM Conversation ID */ + dmConversationByIdEventIdCreate: { + parameters: { + path: { + /** The DM Conversation ID. */ + dm_conversation_id: string; + }; + }; + responses: { + /** The request has succeeded. */ + 201: { + content: { + "application/json": components["schemas"]["CreateDmEventResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["CreateMessageRequest"]; + }; + }; + }; + /** Returns DM Events for a DM Conversation */ + getDmConversationsIdDmEvents: { + parameters: { + path: { + /** The DM Conversation ID. */ + id: components["schemas"]["DmConversationId"]; + }; + query: { + /** The maximum number of results. */ + max_results?: number; + /** This parameter is used to get a specified 'page' of results. */ + pagination_token?: components["schemas"]["PaginationToken32"]; + /** The set of event_types to include in the results. */ + event_types?: ( + | "MessageCreate" + | "ParticipantsJoin" + | "ParticipantsLeave" + )[]; + /** A comma separated list of DmEvent fields to display. */ + "dm_event.fields"?: components["parameters"]["DmEventFieldsParameter"]; + /** A comma separated list of fields to expand. */ + expansions?: components["parameters"]["DmEventExpansionsParameter"]; + /** A comma separated list of Media fields to display. */ + "media.fields"?: components["parameters"]["MediaFieldsParameter"]; + /** A comma separated list of User fields to display. */ + "user.fields"?: components["parameters"]["UserFieldsParameter"]; + /** A comma separated list of Tweet fields to display. */ + "tweet.fields"?: components["parameters"]["TweetFieldsParameter"]; + }; + }; + responses: { + /** The request has succeeded. */ + 200: { + content: { + "application/json": components["schemas"]["Get2DmConversationsIdDmEventsResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + }; + /** Returns recent DM Events across DM conversations */ + getDmEvents: { + parameters: { + query: { + /** The maximum number of results. */ + max_results?: number; + /** This parameter is used to get a specified 'page' of results. */ + pagination_token?: components["schemas"]["PaginationToken32"]; + /** The set of event_types to include in the results. */ + event_types?: ( + | "MessageCreate" + | "ParticipantsJoin" + | "ParticipantsLeave" + )[]; + /** A comma separated list of DmEvent fields to display. */ + "dm_event.fields"?: components["parameters"]["DmEventFieldsParameter"]; + /** A comma separated list of fields to expand. */ + expansions?: components["parameters"]["DmEventExpansionsParameter"]; + /** A comma separated list of Media fields to display. */ + "media.fields"?: components["parameters"]["MediaFieldsParameter"]; + /** A comma separated list of User fields to display. */ + "user.fields"?: components["parameters"]["UserFieldsParameter"]; + /** A comma separated list of Tweet fields to display. */ + "tweet.fields"?: components["parameters"]["TweetFieldsParameter"]; + }; + }; + responses: { + /** The request has succeeded. */ + 200: { + content: { + "application/json": components["schemas"]["Get2DmEventsResponse"]; + }; + }; + /** The request has failed. */ + default: { + content: { + "application/json": components["schemas"]["Error"]; + "application/problem+json": components["schemas"]["Problem"]; + }; + }; + }; + }; /** Creates a new List. */ listIdCreate: { parameters: {}; @@ -4791,6 +5152,12 @@ export interface external {} export type listBatchComplianceJobs = operations['listBatchComplianceJobs'] export type createBatchComplianceJob = operations['createBatchComplianceJob'] export type getBatchComplianceJob = operations['getBatchComplianceJob'] +export type dmConversationIdCreate = operations['dmConversationIdCreate'] +export type getDmConversationsWithParticipantIdDmEvents = operations['getDmConversationsWithParticipantIdDmEvents'] +export type dmConversationWithUserEventIdCreate = operations['dmConversationWithUserEventIdCreate'] +export type dmConversationByIdEventIdCreate = operations['dmConversationByIdEventIdCreate'] +export type getDmConversationsIdDmEvents = operations['getDmConversationsIdDmEvents'] +export type getDmEvents = operations['getDmEvents'] export type listIdCreate = operations['listIdCreate'] export type listIdDelete = operations['listIdDelete'] export type listIdGet = operations['listIdGet'] From 488ae2a9e9d20d4688cadc9b5b546ff1504eecf8 Mon Sep 17 00:00:00 2001 From: refarer <14077091+refarer@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:05:34 +1300 Subject: [PATCH 3/4] update dependencies --- package.json | 4 ++-- yarn.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f979c8d..dfd4bd3 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "@types/node-fetch": "^2.6.1", "jest": "^27.5.1", "nock": "^13.2.4", - "openapi-typescript": "^5.4.0", + "openapi-typescript": "^5.4.1", "ts-jest": "^27.0.3", - "ts-node": "^10.8.2", + "ts-node": "^10.9.1", "typescript": "^4.4.4" }, "jest": { diff --git a/yarn.lock b/yarn.lock index 0ae93c9..ceda8a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2152,7 +2152,7 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" -openapi-typescript@^5.4.0: +openapi-typescript@^5.4.1: version "5.4.1" resolved "https://registry.npmjs.org/openapi-typescript/-/openapi-typescript-5.4.1.tgz#38b4b45244acc1361f3c444537833a9e9cb03bf6" integrity sha512-AGB2QiZPz4rE7zIwV3dRHtoUC/CWHhUjuzGXvtmMQN2AFV8xCTLKcZUHLcdPQmt/83i22nRE7+TxXOXkK+gf4Q== @@ -2595,7 +2595,7 @@ ts-jest@^27.0.3: semver "7.x" yargs-parser "20.x" -ts-node@^10.8.2: +ts-node@^10.9.1: version "10.9.1" resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== From 8c1be9cf29e6b12f257729a1a266976a0954b5a4 Mon Sep 17 00:00:00 2001 From: refarer <14077091+refarer@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:11:27 +1300 Subject: [PATCH 4/4] v1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dfd4bd3..9165217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "twitter-api-sdk", - "version": "1.2.1", + "version": "1.3.0", "description": "A TypeScript SDK for the Twitter API", "main": "dist/index.js", "types": "dist/index.d.ts",