From 2faa9325c4f02a5ede225bb6ef164d9503f9461e Mon Sep 17 00:00:00 2001 From: Hamza Hutchinson Date: Thu, 14 Nov 2024 11:38:30 -0800 Subject: [PATCH 1/4] Add a response type for openExternalLink that returns a boolean opened value --- package.json | 2 +- src/commands/openExternalLink.ts | 8 ++++++-- src/mock.ts | 2 +- src/schema/responses.ts | 7 ++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 35df3592..4b543c70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@discord/embedded-app-sdk", - "version": "1.7.0", + "version": "1.7.1", "description": "@discord/embedded-app-sdk enables you to build rich, multiplayer experiences inside Discord.", "author": "Discord", "license": "MIT", diff --git a/src/commands/openExternalLink.ts b/src/commands/openExternalLink.ts index 8c3a2d10..690865fd 100644 --- a/src/commands/openExternalLink.ts +++ b/src/commands/openExternalLink.ts @@ -1,5 +1,5 @@ import {Commands} from '../schema/common'; -import {EmptyResponse} from '../schema/responses'; +import {OpenExternalLinkResponse} from '../schema/responses'; import {TSendCommand} from '../schema/types'; import {commandFactory} from '../utils/commandFactory'; @@ -11,4 +11,8 @@ export interface OpenExternalLinkInput { * */ export const openExternalLink = (sendCommand: TSendCommand) => - commandFactory(sendCommand, Commands.OPEN_EXTERNAL_LINK, EmptyResponse); + commandFactory( + sendCommand, + Commands.OPEN_EXTERNAL_LINK, + OpenExternalLinkResponse, + ); diff --git a/src/mock.ts b/src/mock.ts index 58bdf306..03f63298 100644 --- a/src/mock.ts +++ b/src/mock.ts @@ -119,7 +119,7 @@ export const commandsMockDefault: IDiscordSDK['commands'] = { startPurchase: () => Promise.resolve([]), setConfig: () => Promise.resolve({use_interactive_pip: false}), userSettingsGetLocale: () => Promise.resolve({locale: ''}), - openExternalLink: () => Promise.resolve(null), + openExternalLink: () => Promise.resolve({opened: false}), encourageHardwareAcceleration: () => Promise.resolve({enabled: true}), captureLog: () => Promise.resolve(null), setOrientationLockState: () => Promise.resolve(null), diff --git a/src/schema/responses.ts b/src/schema/responses.ts index d3e9b9e0..e04fa60c 100644 --- a/src/schema/responses.ts +++ b/src/schema/responses.ts @@ -106,6 +106,10 @@ export const GetChannelPermissionsResponse = zod.object({ permissions: zod.bigint().or(zod.string()), }); +export const OpenExternalLinkResponse = zod.object({ + opened: zod.boolean(), +}); + export {InitiateImageUploadResponseSchema as InitiateImageUploadResponse}; /** @@ -162,8 +166,9 @@ function parseResponseData({cmd, data}: zod.infer) { return SubscribeResponse.parse(data); case Commands.USER_SETTINGS_GET_LOCALE: return UserSettingsGetLocaleResponse.parse(data); - // Empty Responses case Commands.OPEN_EXTERNAL_LINK: + return OpenExternalLinkResponse.parse(data); + // Empty Responses case Commands.SET_ORIENTATION_LOCK_STATE: case Commands.SET_CERTIFIED_DEVICES: case Commands.SEND_ANALYTICS_EVENT: From 73a6285797e0f5b704e77ada0b6c4faa50ed0167 Mon Sep 17 00:00:00 2001 From: Hamza Hutchinson Date: Mon, 18 Nov 2024 12:41:45 -0800 Subject: [PATCH 2/4] revert the package version change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b543c70..35df3592 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@discord/embedded-app-sdk", - "version": "1.7.1", + "version": "1.7.0", "description": "@discord/embedded-app-sdk enables you to build rich, multiplayer experiences inside Discord.", "author": "Discord", "license": "MIT", From 13e5550b6b2963249e5b61d75f5ad7b547969a72 Mon Sep 17 00:00:00 2001 From: Hamza Hutchinson Date: Mon, 18 Nov 2024 13:29:34 -0800 Subject: [PATCH 3/4] adding a fallback to OpenExternalLinkResponse for older clients --- src/schema/responses.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schema/responses.ts b/src/schema/responses.ts index e04fa60c..828e117b 100644 --- a/src/schema/responses.ts +++ b/src/schema/responses.ts @@ -14,7 +14,7 @@ import { ChannelTypesObject, ReceiveFramePayload, } from './common'; -import {zodCoerceUnhandledValue} from '../utils/zodUtils'; +import {fallbackToDefault, zodCoerceUnhandledValue} from '../utils/zodUtils'; import {Schemas, AuthenticateResponseSchema, InitiateImageUploadResponseSchema} from '../generated/schemas'; import assertUnreachable from '../utils/assertUnreachable'; @@ -106,9 +106,9 @@ export const GetChannelPermissionsResponse = zod.object({ permissions: zod.bigint().or(zod.string()), }); -export const OpenExternalLinkResponse = zod.object({ - opened: zod.boolean(), -}); +export const OpenExternalLinkResponse = fallbackToDefault(zod.object({ + opened: zod.boolean().or(zod.null()), +}).default({opened: null})); export {InitiateImageUploadResponseSchema as InitiateImageUploadResponse}; From 0bdbc6c8ba1e926e8a674460d2efc1a44c75882c Mon Sep 17 00:00:00 2001 From: Hamza Hutchinson Date: Mon, 18 Nov 2024 16:46:57 -0800 Subject: [PATCH 4/4] fix: linting fix --- src/schema/responses.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/schema/responses.ts b/src/schema/responses.ts index 828e117b..922b289f 100644 --- a/src/schema/responses.ts +++ b/src/schema/responses.ts @@ -106,9 +106,9 @@ export const GetChannelPermissionsResponse = zod.object({ permissions: zod.bigint().or(zod.string()), }); -export const OpenExternalLinkResponse = fallbackToDefault(zod.object({ - opened: zod.boolean().or(zod.null()), -}).default({opened: null})); +export const OpenExternalLinkResponse = fallbackToDefault( + zod.object({opened: zod.boolean().or(zod.null())}).default({opened: null}), +); export {InitiateImageUploadResponseSchema as InitiateImageUploadResponse};