From 393ce6d0c25f90684ff443dca437ce726a5dcedf Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Thu, 2 Jan 2025 13:48:49 -0500 Subject: [PATCH 1/6] chore: update schema --- src/generated/schema.json | 61 +++++++++++++++++++++++++++++++++++++++ src/generated/schemas.ts | 48 ++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/src/generated/schema.json b/src/generated/schema.json index 48a3c25..5d8242c 100644 --- a/src/generated/schema.json +++ b/src/generated/schema.json @@ -148,5 +148,66 @@ "required": ["participants"], "additionalProperties": false } + }, + "SHARE_INTERACTION": { + "request": { + "type": "object", + "properties": { + "command": {"type": "string"}, + "content": {"type": "string", "maxLength": 2000}, + "preview_image": { + "type": "object", + "properties": {"height": {"type": "number"}, "url": {"type": "string"}, "width": {"type": "number"}}, + "required": ["height", "url", "width"], + "additionalProperties": false + }, + "components": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": {"const": 1}, + "components": { + "type": "array", + "maxItems": 5, + "items": { + "type": "object", + "properties": { + "type": {"const": 2}, + "style": {"type": "number", "minimum": 1, "maximum": 5}, + "label": {"type": "string", "description": "Text that appears on the button", "maxLength": 80}, + "custom_id": { + "type": "string", + "description": "Developer-defined identifier for the button; max 100 characters", + "maxLength": 100 + } + }, + "required": ["type", "style"], + "additionalProperties": false + } + } + }, + "required": ["type"], + "additionalProperties": false + } + } + }, + "required": ["command"], + "additionalProperties": false + }, + "response": null + }, + "SHARE_LINK": { + "request": { + "type": "object", + "properties": { + "referrer_id": {"type": "string", "maxLength": 64}, + "custom_id": {"type": "string", "maxLength": 64}, + "message": {"type": "string", "maxLength": 1000} + }, + "required": ["message"], + "additionalProperties": false + }, + "response": null } } diff --git a/src/generated/schemas.ts b/src/generated/schemas.ts index 4c561a9..8611a39 100644 --- a/src/generated/schemas.ts +++ b/src/generated/schemas.ts @@ -113,6 +113,44 @@ export type GetActivityInstanceConnectedParticipantsResponse = zInfer< typeof GetActivityInstanceConnectedParticipantsResponseSchema >; +// SHARE_INTERACTION +export const ShareInteractionRequestSchema = z.object({ + command: z.string(), + content: z.string().max(2000).optional(), + preview_image: z.object({height: z.number(), url: z.string(), width: z.number()}).optional(), + components: z + .array( + z.object({ + type: z.literal(1), + components: z + .array( + z.object({ + type: z.literal(2), + style: z.number().gte(1).lte(5), + label: z.string().max(80).optional(), + custom_id: z + .string() + .max(100) + .describe('Developer-defined identifier for the button; max 100 characters') + .optional(), + }), + ) + .max(5) + .optional(), + }), + ) + .optional(), +}); +export type ShareInteractionRequest = zInfer; + +// SHARE_LINK +export const ShareLinkRequestSchema = z.object({ + referrer_id: z.string().max(64).optional(), + custom_id: z.string().max(64).optional(), + message: z.string().max(1000), +}); +export type ShareLinkRequest = zInfer; + /** * RPC Commands which support schemas. */ @@ -121,6 +159,8 @@ export enum Command { OPEN_SHARE_MOMENT_DIALOG = 'OPEN_SHARE_MOMENT_DIALOG', AUTHENTICATE = 'AUTHENTICATE', GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS = 'GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS', + SHARE_INTERACTION = 'SHARE_INTERACTION', + SHARE_LINK = 'SHARE_LINK', } const emptyResponseSchema = z.object({}).optional().nullable(); @@ -146,4 +186,12 @@ export const Schemas = { request: emptyRequestSchema, response: GetActivityInstanceConnectedParticipantsResponseSchema, }, + [Command.SHARE_INTERACTION]: { + request: ShareInteractionRequestSchema, + response: emptyResponseSchema, + }, + [Command.SHARE_LINK]: { + request: ShareLinkRequestSchema, + response: emptyResponseSchema, + }, } as const; From 547286ecf70289a4d45817d25fb638992c3637d5 Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Thu, 2 Jan 2025 13:49:07 -0500 Subject: [PATCH 2/6] feat: add shareLink command --- src/commands/index.ts | 2 ++ src/commands/shareLink.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/commands/shareLink.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index 28c629a..a6f280e 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -15,6 +15,7 @@ import {openShareMomentDialog} from './openShareMomentDialog'; import {setActivity, SetActivity} from './setActivity'; import {setConfig} from './setConfig'; import {setOrientationLockState} from './setOrientationLockState'; +import {shareLink} from './shareLink'; import {startPurchase} from './startPurchase'; import {userSettingsGetLocale} from './userSettingsGetLocale'; import {initiateImageUpload} from './initiateImageUpload'; @@ -40,6 +41,7 @@ function commands(sendCommand: TSendCommand) { setActivity: setActivity(sendCommand), setConfig: setConfig(sendCommand), setOrientationLockState: setOrientationLockState(sendCommand), + shareLink: shareLink(sendCommand), startPurchase: startPurchase(sendCommand), userSettingsGetLocale: userSettingsGetLocale(sendCommand), initiateImageUpload: initiateImageUpload(sendCommand), diff --git a/src/commands/shareLink.ts b/src/commands/shareLink.ts new file mode 100644 index 0000000..d1d46bf --- /dev/null +++ b/src/commands/shareLink.ts @@ -0,0 +1,13 @@ +import {Command} from '../generated/schemas'; +import {schemaCommandFactory} from '../utils/commandFactory'; + +/** + * Opens a modal in the user's client to share the Activity link. + * + * @param {string} referrer_id + * @param {string} custom_id + * @param {string} message - message sent alongside link when shared. + * @returns {Promise} + */ + +export const shareLink = schemaCommandFactory(Command.SHARE_LINK); From ff2d665d3478ab43c37d63b9d7910a6859dc6564 Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Thu, 2 Jan 2025 13:56:18 -0500 Subject: [PATCH 3/6] chore: add mock --- src/mock.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mock.ts b/src/mock.ts index 8a589f3..ab2c3f3 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -134,6 +134,7 @@ export const commandsMockDefault: IDiscordSDK['commands'] = { }), getChannelPermissions: () => Promise.resolve({permissions: bigInt(1234567890) as unknown as bigint}), openShareMomentDialog: () => Promise.resolve(null), + shareLink: () => Promise.resolve(null), initiateImageUpload: () => Promise.resolve({ image_url: From 4c9a12929f4363aaa02366d04bbc694253bdf8f9 Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Thu, 2 Jan 2025 15:15:49 -0500 Subject: [PATCH 4/6] fix: shareLink jsdoc --- src/commands/shareLink.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/shareLink.ts b/src/commands/shareLink.ts index d1d46bf..990d821 100644 --- a/src/commands/shareLink.ts +++ b/src/commands/shareLink.ts @@ -9,5 +9,4 @@ import {schemaCommandFactory} from '../utils/commandFactory'; * @param {string} message - message sent alongside link when shared. * @returns {Promise} */ - export const shareLink = schemaCommandFactory(Command.SHARE_LINK); From 673389caffbc1d9fcdc59d2dcf5fbfb8bb767e5e Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Thu, 2 Jan 2025 15:18:47 -0500 Subject: [PATCH 5/6] fix: share link command response --- src/schema/common.ts | 1 + src/schema/responses.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/schema/common.ts b/src/schema/common.ts index 8ea7710..fedc5e4 100644 --- a/src/schema/common.ts +++ b/src/schema/common.ts @@ -36,6 +36,7 @@ export enum Commands { OPEN_SHARE_MOMENT_DIALOG = 'OPEN_SHARE_MOMENT_DIALOG', INITIATE_IMAGE_UPLOAD = 'INITIATE_IMAGE_UPLOAD', GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS = 'GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS', + SHARE_LINK = 'SHARE_LINK', } export const ReceiveFramePayload = zod diff --git a/src/schema/responses.ts b/src/schema/responses.ts index 922b289..e34fd84 100644 --- a/src/schema/responses.ts +++ b/src/schema/responses.ts @@ -182,6 +182,7 @@ function parseResponseData({cmd, data}: zod.infer) { case Commands.INITIATE_IMAGE_UPLOAD: case Commands.OPEN_SHARE_MOMENT_DIALOG: case Commands.GET_ACTIVITY_INSTANCE_CONNECTED_PARTICIPANTS: + case Commands.SHARE_LINK: const {response} = Schemas[cmd]; return response.parse(data); default: From e2d0a120f407f394d70383d91342686738a5eb02 Mon Sep 17 00:00:00 2001 From: Andrew Giel Date: Tue, 7 Jan 2025 15:28:19 -0500 Subject: [PATCH 6/6] feat: add response to schema --- src/commands/shareLink.ts | 2 +- src/generated/schema.json | 7 ++++++- src/generated/schemas.ts | 4 +++- src/mock.ts | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/commands/shareLink.ts b/src/commands/shareLink.ts index 990d821..1d842fa 100644 --- a/src/commands/shareLink.ts +++ b/src/commands/shareLink.ts @@ -7,6 +7,6 @@ import {schemaCommandFactory} from '../utils/commandFactory'; * @param {string} referrer_id * @param {string} custom_id * @param {string} message - message sent alongside link when shared. - * @returns {Promise} + * @returns {Promise<{success: boolean>} whether or not the user shared the link to someone */ export const shareLink = schemaCommandFactory(Command.SHARE_LINK); diff --git a/src/generated/schema.json b/src/generated/schema.json index 5d8242c..1ab2ed3 100644 --- a/src/generated/schema.json +++ b/src/generated/schema.json @@ -208,6 +208,11 @@ "required": ["message"], "additionalProperties": false }, - "response": null + "response": { + "type": "object", + "properties": {"success": {"type": "boolean"}}, + "required": ["success"], + "additionalProperties": false + } } } diff --git a/src/generated/schemas.ts b/src/generated/schemas.ts index 8611a39..2d4f843 100644 --- a/src/generated/schemas.ts +++ b/src/generated/schemas.ts @@ -150,6 +150,8 @@ export const ShareLinkRequestSchema = z.object({ message: z.string().max(1000), }); export type ShareLinkRequest = zInfer; +export const ShareLinkResponseSchema = z.object({success: z.boolean()}); +export type ShareLinkResponse = zInfer; /** * RPC Commands which support schemas. @@ -192,6 +194,6 @@ export const Schemas = { }, [Command.SHARE_LINK]: { request: ShareLinkRequestSchema, - response: emptyResponseSchema, + response: ShareLinkResponseSchema, }, } as const; diff --git a/src/mock.ts b/src/mock.ts index ab2c3f3..ca93207 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -134,7 +134,7 @@ export const commandsMockDefault: IDiscordSDK['commands'] = { }), getChannelPermissions: () => Promise.resolve({permissions: bigInt(1234567890) as unknown as bigint}), openShareMomentDialog: () => Promise.resolve(null), - shareLink: () => Promise.resolve(null), + shareLink: () => Promise.resolve({success: false}), initiateImageUpload: () => Promise.resolve({ image_url: