mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-04 18:49:39 -06:00
added cache no-store when formbricksDebug is enabled
This commit is contained in:
@@ -6,10 +6,11 @@ import { makeRequest } from "../../utils/make-request";
|
||||
export class AttributeAPI {
|
||||
private appUrl: string;
|
||||
private environmentId: string;
|
||||
|
||||
constructor(appUrl: string, environmentId: string) {
|
||||
private isDebug: boolean;
|
||||
constructor(appUrl: string, environmentId: string, isDebug: boolean) {
|
||||
this.appUrl = appUrl;
|
||||
this.environmentId = environmentId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
|
||||
async update(
|
||||
@@ -25,7 +26,8 @@ export class AttributeAPI {
|
||||
this.appUrl,
|
||||
`/api/v1/client/${this.environmentId}/contacts/${attributeUpdateInput.userId}/attributes`,
|
||||
"PUT",
|
||||
{ attributes }
|
||||
{ attributes },
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,23 @@ import { makeRequest } from "../../utils/make-request";
|
||||
export class DisplayAPI {
|
||||
private appUrl: string;
|
||||
private environmentId: string;
|
||||
private isDebug: boolean;
|
||||
|
||||
constructor(appUrl: string, environmentId: string) {
|
||||
constructor(appUrl: string, environmentId: string, isDebug: boolean) {
|
||||
this.appUrl = appUrl;
|
||||
this.environmentId = environmentId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
|
||||
async create(
|
||||
displayInput: Omit<TDisplayCreateInput, "environmentId">
|
||||
): Promise<Result<{ id: string }, ApiErrorResponse>> {
|
||||
return makeRequest(this.appUrl, `/api/v1/client/${this.environmentId}/displays`, "POST", displayInput);
|
||||
return makeRequest(
|
||||
this.appUrl,
|
||||
`/api/v1/client/${this.environmentId}/displays`,
|
||||
"POST",
|
||||
displayInput,
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,21 @@ import { makeRequest } from "../../utils/make-request";
|
||||
export class EnvironmentAPI {
|
||||
private appUrl: string;
|
||||
private environmentId: string;
|
||||
private isDebug: boolean;
|
||||
|
||||
constructor(appUrl: string, environmentId: string) {
|
||||
constructor(appUrl: string, environmentId: string, isDebug: boolean) {
|
||||
this.appUrl = appUrl;
|
||||
this.environmentId = environmentId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
|
||||
async getState(): Promise<Result<TJsEnvironmentState, ApiErrorResponse>> {
|
||||
return makeRequest(this.appUrl, `/api/v1/client/${this.environmentId}/environment`, "GET");
|
||||
return makeRequest(
|
||||
this.appUrl,
|
||||
`/api/v1/client/${this.environmentId}/environment`,
|
||||
"GET",
|
||||
undefined,
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,14 @@ export class Client {
|
||||
environment: EnvironmentAPI;
|
||||
|
||||
constructor(options: ApiConfig) {
|
||||
const { appUrl, environmentId } = options;
|
||||
const { appUrl, environmentId, isDebug } = options;
|
||||
const isDebugMode = isDebug ?? false;
|
||||
|
||||
this.response = new ResponseAPI(appUrl, environmentId);
|
||||
this.display = new DisplayAPI(appUrl, environmentId);
|
||||
this.attribute = new AttributeAPI(appUrl, environmentId);
|
||||
this.response = new ResponseAPI(appUrl, environmentId, isDebugMode);
|
||||
this.display = new DisplayAPI(appUrl, environmentId, isDebugMode);
|
||||
this.attribute = new AttributeAPI(appUrl, environmentId, isDebugMode);
|
||||
this.storage = new StorageAPI(appUrl, environmentId);
|
||||
this.user = new UserAPI(appUrl, environmentId);
|
||||
this.environment = new EnvironmentAPI(appUrl, environmentId);
|
||||
this.user = new UserAPI(appUrl, environmentId, isDebugMode);
|
||||
this.environment = new EnvironmentAPI(appUrl, environmentId, isDebugMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,23 @@ type TResponseUpdateInputWithResponseId = TResponseUpdateInput & { responseId: s
|
||||
export class ResponseAPI {
|
||||
private appUrl: string;
|
||||
private environmentId: string;
|
||||
|
||||
constructor(appUrl: string, environmentId: string) {
|
||||
private isDebug: boolean;
|
||||
constructor(appUrl: string, environmentId: string, isDebug: boolean) {
|
||||
this.appUrl = appUrl;
|
||||
this.environmentId = environmentId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
|
||||
async create(
|
||||
responseInput: Omit<TResponseInput, "environmentId">
|
||||
): Promise<Result<{ id: string }, ApiErrorResponse>> {
|
||||
return makeRequest(this.appUrl, `/api/v1/client/${this.environmentId}/responses`, "POST", responseInput);
|
||||
return makeRequest(
|
||||
this.appUrl,
|
||||
`/api/v1/client/${this.environmentId}/responses`,
|
||||
"POST",
|
||||
responseInput,
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
|
||||
async update({
|
||||
@@ -29,13 +36,19 @@ export class ResponseAPI {
|
||||
variables,
|
||||
language,
|
||||
}: TResponseUpdateInputWithResponseId): Promise<Result<object, ApiErrorResponse>> {
|
||||
return makeRequest(this.appUrl, `/api/v1/client/${this.environmentId}/responses/${responseId}`, "PUT", {
|
||||
finished,
|
||||
endingId,
|
||||
data,
|
||||
ttc,
|
||||
variables,
|
||||
language,
|
||||
});
|
||||
return makeRequest(
|
||||
this.appUrl,
|
||||
`/api/v1/client/${this.environmentId}/responses/${responseId}`,
|
||||
"PUT",
|
||||
{
|
||||
finished,
|
||||
endingId,
|
||||
data,
|
||||
ttc,
|
||||
variables,
|
||||
language,
|
||||
},
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import { makeRequest } from "../../utils/make-request";
|
||||
export class UserAPI {
|
||||
private appUrl: string;
|
||||
private environmentId: string;
|
||||
private isDebug: boolean;
|
||||
|
||||
constructor(appUrl: string, environmentId: string) {
|
||||
constructor(appUrl: string, environmentId: string, isDebug: boolean) {
|
||||
this.appUrl = appUrl;
|
||||
this.environmentId = environmentId;
|
||||
this.isDebug = isDebug;
|
||||
}
|
||||
|
||||
async createOrUpdate(userUpdateInput: { userId: string; attributes?: Record<string, string> }): Promise<
|
||||
@@ -37,9 +39,15 @@ export class UserAPI {
|
||||
attributes[key] = String(userUpdateInput.attributes[key]);
|
||||
}
|
||||
|
||||
return makeRequest(this.appUrl, `/api/v2/client/${this.environmentId}/user`, "POST", {
|
||||
userId: userUpdateInput.userId,
|
||||
attributes,
|
||||
});
|
||||
return makeRequest(
|
||||
this.appUrl,
|
||||
`/api/v2/client/${this.environmentId}/user`,
|
||||
"POST",
|
||||
{
|
||||
userId: userUpdateInput.userId,
|
||||
attributes,
|
||||
},
|
||||
this.isDebug
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type ApiErrorResponse } from "@formbricks/types/errors";
|
||||
export interface ApiConfig {
|
||||
environmentId: string;
|
||||
appUrl: string;
|
||||
isDebug?: boolean;
|
||||
}
|
||||
|
||||
export type ApiResponse = ApiSuccessResponse | ApiErrorResponse;
|
||||
|
||||
@@ -6,16 +6,17 @@ export const makeRequest = async <T>(
|
||||
appUrl: string,
|
||||
endpoint: string,
|
||||
method: "GET" | "POST" | "PUT" | "DELETE",
|
||||
data?: unknown
|
||||
data?: unknown,
|
||||
isDebug?: boolean
|
||||
): Promise<Result<T, ApiErrorResponse>> => {
|
||||
const url = new URL(appUrl + endpoint);
|
||||
const body = data ? JSON.stringify(data) : undefined;
|
||||
|
||||
const res = await wrapThrowsAsync(fetch)(url.toString(), {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
...(isDebug && { cache: "no-store" }),
|
||||
body,
|
||||
});
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ export const setup = async (
|
||||
addWidgetContainer();
|
||||
|
||||
if (
|
||||
!isDebug &&
|
||||
existingConfig?.environment &&
|
||||
existingConfig.environmentId === configInput.environmentId &&
|
||||
existingConfig.appUrl === configInput.appUrl
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { FormbricksAPI } from "@formbricks/api";
|
||||
import { Config } from "@/lib/common/config";
|
||||
import { Logger } from "@/lib/common/logger";
|
||||
import { filterSurveys } from "@/lib/common/utils";
|
||||
import { filterSurveys , getIsDebug } from "@/lib/common/utils";
|
||||
import type { TConfigInput, TEnvironmentState } from "@/types/config";
|
||||
import { type ApiErrorResponse, type Result, err, ok } from "@/types/error";
|
||||
|
||||
@@ -20,7 +20,7 @@ export const fetchEnvironmentState = async ({
|
||||
environmentId,
|
||||
}: TConfigInput): Promise<Result<TEnvironmentState, ApiErrorResponse>> => {
|
||||
const url = `${appUrl}/api/v1/client/${environmentId}/environment`;
|
||||
const api = new FormbricksAPI({ appUrl, environmentId });
|
||||
const api = new FormbricksAPI({ appUrl, environmentId, isDebug: getIsDebug() });
|
||||
|
||||
try {
|
||||
const response = await api.client.environment.getState();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { FormbricksAPI } from "@formbricks/api";
|
||||
import { Config } from "@/lib/common/config";
|
||||
import { Logger } from "@/lib/common/logger";
|
||||
import { filterSurveys } from "@/lib/common/utils";
|
||||
import { filterSurveys , getIsDebug } from "@/lib/common/utils";
|
||||
import { type TUpdates, type TUserState } from "@/types/config";
|
||||
import { type ApiErrorResponse, type Result, type ResultError, err, ok, okVoid } from "@/types/error";
|
||||
|
||||
@@ -26,7 +26,7 @@ export const sendUpdatesToBackend = async ({
|
||||
const url = `${appUrl}/api/v1/client/${environmentId}/user`;
|
||||
|
||||
try {
|
||||
const api = new FormbricksAPI({ appUrl, environmentId });
|
||||
const api = new FormbricksAPI({ appUrl, environmentId, isDebug: getIsDebug() });
|
||||
|
||||
const response = await api.client.user.createOrUpdate({
|
||||
userId: updates.userId,
|
||||
|
||||
Reference in New Issue
Block a user