Skip to content

Commit

Permalink
fix: make sure to use stable version for link to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcuva committed Jan 8, 2024
1 parent 0457eef commit 1bb39d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ interface GetUserFunction {
(params: GetUserParams): Promise<GroupingObject | void>;
}

interface ReadMeVersion {
is_stable: boolean;
version: string;
}

// See comment at the auth definition below
let readmeAPIKey = '';
let readmeProjectData: GetProjectResponse200 | undefined;
let readmeVersionData: ReadMeVersion[] | undefined;

const readme = (
userFunction: (req: Request, getUser: GetUserFunction) => Promise<GroupingObject | void>,
Expand Down Expand Up @@ -116,6 +122,7 @@ const readme = (
readmeSdk.auth(readmeAPIKey);
try {
readmeProjectData = (await readmeSdk.getProject()).data;
readmeVersionData = (await readmeSdk.getVersions()).data as ReadMeVersion[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
// TODO: Maybe send this to sentry?
Expand Down Expand Up @@ -143,6 +150,7 @@ const readme = (
const setupHtml = buildSetupView({
baseUrl,
subdomain: readmeProjectData.subdomain as string,
stableVersion: readmeVersionData?.find(version => version.is_stable)?.version || '1.0',
readmeAPIKey,
disableMetrics: options.disableMetrics,
disableWebhook: options.disableWebhook,
Expand Down
4 changes: 3 additions & 1 deletion packages/node/src/lib/setup-readme-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function buildSetupView({
baseUrl,
readmeAPIKey,
subdomain,
stableVersion,
disableWebhook,
disableMetrics,
}: {
Expand All @@ -14,8 +15,9 @@ export function buildSetupView({
disableMetrics?: boolean;
disableWebhook?: boolean;
subdomain: string;
stableVersion: string;
}) {
const dashUrl = `https://dash.readme.com/project/${subdomain}/v1.0/metrics/developers`;
const dashUrl = `https://dash.readme.com/project/${subdomain}/v${stableVersion}/metrics/developers`;
let webhookScriptHtml = `
var form = document.getElementById("testWebhookForm");
form.addEventListener('submit', testWebhook);
Expand Down

0 comments on commit 1bb39d1

Please sign in to comment.