Skip to content

Commit

Permalink
Bump sdk versions to v1.7.0 (#38)
Browse files Browse the repository at this point in the history
* Bump sdk versions to v1.7.0

* patch mock sdk
  • Loading branch information
matthova authored Nov 21, 2024
1 parent 8442e1b commit ff4401b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion discord-activity-starter/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "vite build"
},
"dependencies": {
"@discord/embedded-app-sdk": "^1.4.2"
"@discord/embedded-app-sdk": "^1.7.0"
},
"devDependencies": {
"vite": "^5.2.9"
Expand Down
4 changes: 2 additions & 2 deletions nested-messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Discord",
"license": "MIT",
"dependencies": {
"@discord/embedded-app-sdk": "^1.4.2",
"@discord/embedded-app-sdk": "^1.7.0",
"dotenv": "^16.0.3",
"esbuild": "^0.24.0",
"eventemitter3": "^5.0.0",
Expand All @@ -23,4 +23,4 @@
"nodemon": "^3.1.0",
"typescript": "~5.6.0"
}
}
}
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk-playground/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"tsc": "tsc"
},
"dependencies": {
"@discord/embedded-app-sdk": "^1.5.0",
"@discord/embedded-app-sdk": "^1.7.0",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-scroll-area": "^1.0.1",
"@stitches/react": "^1.2.1",
Expand Down
42 changes: 28 additions & 14 deletions sdk-playground/packages/client/src/discordSdk.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
import {DiscordSDK, DiscordSDKMock, IDiscordSDK, patchUrlMappings} from '@discord/embedded-app-sdk';
import {
DiscordSDK,
DiscordSDKMock,
IDiscordSDK,
patchUrlMappings,
} from "@discord/embedded-app-sdk";

const queryParams = new URLSearchParams(window.location.search);
const isEmbedded = queryParams.get('frame_id') != null;
const isEmbedded = queryParams.get("frame_id") != null;

let discordSdk: IDiscordSDK;

if (isEmbedded) {
discordSdk = new DiscordSDK(import.meta.env.VITE_CLIENT_ID, {disableConsoleLogOverride: true});
discordSdk = new DiscordSDK(import.meta.env.VITE_CLIENT_ID, {
disableConsoleLogOverride: true,
});
patchUrlMappings([]);
} else {
discordSdk = new DiscordSDKMock(import.meta.env.VITE_CLIENT_ID, null, null);
discordSdk = new DiscordSDKMock(
import.meta.env.VITE_CLIENT_ID,
null,
null,
null
);
// @ts-expect-error
discordSdk.channelId = 'test_channel_id';
let storedUserId = sessionStorage.getItem('user_id');
discordSdk.channelId = "test_channel_id";
let storedUserId = sessionStorage.getItem("user_id");
if (storedUserId == null) {
// Set user_id to a random 8-character string, this gives us a consistent user id
storedUserId = Math.random().toString(36).slice(2, 10);
sessionStorage.setItem('user_id', storedUserId);
sessionStorage.setItem("user_id", storedUserId);
}
const queryParamsUserId = new URLSearchParams(window.location.search).get('user_id');
const queryParamsUserId = new URLSearchParams(window.location.search).get(
"user_id"
);

const userId = queryParamsUserId ?? storedUserId ?? '';
const userId = queryParamsUserId ?? storedUserId ?? "";
const discriminator = String(userId.charCodeAt(0) % 5);

(discordSdk as DiscordSDKMock)._updateCommandMocks({
authenticate: () =>
Promise.resolve({
access_token: 'mock_token',
access_token: "mock_token",
user: {
username: userId,
discriminator,
Expand All @@ -37,10 +51,10 @@ if (isEmbedded) {
scopes: [],
expires: new Date(2112, 1, 1).toString(),
application: {
description: 'mock_app_description',
icon: 'mock_app_icon',
id: 'mock_app_id',
name: 'mock_app_name',
description: "mock_app_description",
icon: "mock_app_icon",
id: "mock_app_id",
name: "mock_app_name",
},
}),
});
Expand Down

0 comments on commit ff4401b

Please sign in to comment.