mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-16 01:46:38 +00:00
Merge branch 'dev' into refactor/save-button-positions
This commit is contained in:
13
src/lib/api/getCachedOrgUser.ts
Normal file
13
src/lib/api/getCachedOrgUser.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { GetOrgResponse } from "@server/routers/org";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { cache } from "react";
|
||||
import { authCookieHeader } from "./cookies";
|
||||
import { internal } from ".";
|
||||
import type { GetOrgUserResponse } from "@server/routers/user";
|
||||
|
||||
export const getCachedOrgUser = cache(async (orgId: string, userId: string) =>
|
||||
internal.get<AxiosResponse<GetOrgUserResponse>>(
|
||||
`/org/${orgId}/user/${userId}`,
|
||||
await authCookieHeader()
|
||||
)
|
||||
);
|
||||
8
src/lib/api/getCachedSubscription.ts
Normal file
8
src/lib/api/getCachedSubscription.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { cache } from "react";
|
||||
import { priv } from ".";
|
||||
import type { GetOrgTierResponse } from "@server/routers/billing/types";
|
||||
|
||||
export const getCachedSubscription = cache(async (orgId: string) =>
|
||||
priv.get<AxiosResponse<GetOrgTierResponse>>(`/org/${orgId}/billing/tier`)
|
||||
);
|
||||
30
src/lib/api/isOrgSubscribed.ts
Normal file
30
src/lib/api/isOrgSubscribed.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { build } from "@server/build";
|
||||
import { TierId } from "@server/lib/billing/tiers";
|
||||
import { cache } from "react";
|
||||
import { getCachedSubscription } from "./getCachedSubscription";
|
||||
import { priv } from ".";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { GetLicenseStatusResponse } from "@server/routers/license/types";
|
||||
|
||||
export const isOrgSubscribed = cache(async (orgId: string) => {
|
||||
let subscribed = false;
|
||||
|
||||
if (build === "enterprise") {
|
||||
try {
|
||||
const licenseStatusRes =
|
||||
await priv.get<AxiosResponse<GetLicenseStatusResponse>>(
|
||||
"/license/status"
|
||||
);
|
||||
subscribed = licenseStatusRes.data.data.isLicenseValid;
|
||||
} catch (error) {}
|
||||
} else if (build === "saas") {
|
||||
try {
|
||||
const subRes = await getCachedSubscription(orgId);
|
||||
subscribed =
|
||||
subRes.data.data.tier === TierId.STANDARD &&
|
||||
subRes.data.data.active;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return subscribed;
|
||||
});
|
||||
@@ -3,8 +3,9 @@ import { authCookieHeader } from "@app/lib/api/cookies";
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { pullEnv } from "../pullEnv";
|
||||
import { cache } from "react";
|
||||
|
||||
export async function verifySession({
|
||||
export const verifySession = cache(async function ({
|
||||
skipCheckVerifyEmail,
|
||||
forceLogin
|
||||
}: {
|
||||
@@ -14,8 +15,12 @@ export async function verifySession({
|
||||
const env = pullEnv();
|
||||
|
||||
try {
|
||||
const search = new URLSearchParams();
|
||||
if (forceLogin) {
|
||||
search.set("forceLogin", "true");
|
||||
}
|
||||
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||
`/user${forceLogin ? "?forceLogin=true" : ""}`,
|
||||
`/user?${search.toString()}`,
|
||||
await authCookieHeader()
|
||||
);
|
||||
|
||||
@@ -37,4 +42,4 @@ export async function verifySession({
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ export const productUpdatesQueries = {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
enabled: enabled && (build === "oss" || build === "enterprise") // disabled in cloud version
|
||||
enabled: enabled && build !== "saas" // disabled in cloud version
|
||||
// because we don't need to listen for new versions there
|
||||
})
|
||||
};
|
||||
|
||||
17
src/lib/replacePlaceholder.ts
Normal file
17
src/lib/replacePlaceholder.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export function replacePlaceholder(
|
||||
stringWithPlaceholder: string,
|
||||
data: Record<string, string>
|
||||
) {
|
||||
let newString = stringWithPlaceholder;
|
||||
|
||||
const keys = Object.keys(data);
|
||||
|
||||
for (const key of keys) {
|
||||
newString = newString.replace(
|
||||
new RegExp(`{{${key}}}`, "gm"),
|
||||
data[key]
|
||||
);
|
||||
}
|
||||
|
||||
return newString;
|
||||
}
|
||||
Reference in New Issue
Block a user