Skip to content

Commit

Permalink
fix: remove publicAccess flag
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly committed Jul 14, 2024
1 parent d5f7cef commit 0e138f9
Show file tree
Hide file tree
Showing 38 changed files with 36 additions and 59 deletions.
18 changes: 4 additions & 14 deletions packages/sdk/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@ export type RequestOption = {

export class InstillAPIClient {
baseURL: string;
apiToken: string;
publicAccess?: boolean;
apiToken: string | undefined;

constructor({
baseURL,
apiToken,
publicAccess,
}: {
baseURL: string;
apiToken: string;
publicAccess?: boolean;
}) {
constructor({ baseURL, apiToken }: { baseURL: string; apiToken?: string }) {
this.baseURL = baseURL;
this.apiToken = apiToken;
this.publicAccess = publicAccess;
}

async get<Rsp>(path: string, opt?: RequestOption): Promise<Rsp> {
Expand Down Expand Up @@ -66,14 +56,14 @@ export class InstillAPIClient {
try {
const response = await fetch(`${this.baseURL}${path}`, {
method,
headers: this.publicAccess
headers: this.apiToken
? {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiToken}`,
...opt?.additionalHeaders,
}
: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiToken}`,
...opt?.additionalHeaders,
},
body: opt?.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function useCreditConsumptionChartRecords({
return Promise.reject(new Error("owner not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({
accessToken,
});

const data =
await client.core.metric.listInstillCreditConsumptionTimeChart({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function usePipelineTriggerComputationTimeCharts({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const triggers =
await client.core.metric.listPipelineTriggerComputationTimeCharts({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function usePipelineTriggerMetric({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const triggerMetric = await client.core.metric.listPipelineTriggerMetric({
pageSize: env("NEXT_PUBLIC_QUERY_PAGE_SIZE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function usePipelineTriggers({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const triggers = await client.core.metric.listPipelineTriggers({
pageSize: env("NEXT_PUBLIC_QUERY_PAGE_SIZE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function fetchApiTokens({
}

try {
const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const apiTokens = await client.core.token.listAPITokens({
pageSize: env("NEXT_PUBLIC_QUERY_PAGE_SIZE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function fetchAuthenticatedUser({
}

try {
const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const user = await client.core.user.getAuthenticatedUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function fetchNamespaceType({
try {
const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const type = await client.core.utils.checkNamespaceType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function fetchUser({
}

try {
const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const user = await client.core.user.getUser({ userName });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useApiToken({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const token = await client.core.token.getApiToken({
tokenName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useAuthenticatedUserSubscription({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const subscription =
await client.core.subscription.getAuthenticatedUserSubscription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useCreateApiToken() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const token = await client.core.token.createApiToken(payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useDeleteApiToken() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

await client.core.token.deleteApiToken({ tokenName });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function useNamespacesRemainingCredit({

const remainingCredits: NamespaceRemainingCredit[] = [];

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

for (const namespaceName of namespaceNames) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useRemainingCredit({
return Promise.reject(new Error("ownerName not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const remainingCredit =
await client.core.credit.getRemainingInstillCredit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function useUpdateAuthenticatedUser() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const user = await client.core.user.updateAuthenticatedUser(payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useUsers({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const users = await client.core.user.listUsers({
pageSize: env("NEXT_PUBLIC_QUERY_PAGE_SIZE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export async function fetchNamespacePipelineReleases({
try {
const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipelineReleases =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export async function fetchNamespacePipeline({
try {
const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipeline = await client.vdp.pipeline.getNamespacePipeline({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export async function fetchNamespacePipelines({
try {
const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipelines = await client.vdp.pipeline.listNamespacePipelines({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function fetchNamespaceSecret({
}

try {
const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const userSecret = await client.vdp.secret.getNamespaceSecret({
namespaceSecretName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function fetchNamespaceSecrets({
}

try {
const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const userSecrets = await client.vdp.secret.listNamespaceSecrets({
pageSize: pageSize ?? env("NEXT_PUBLIC_QUERY_PAGE_SIZE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useCloneNamespacePipeline() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

await client.vdp.pipeline.cloneNamespacePipeline(payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useCreateNamespacePipeline() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const pipeline =
await client.vdp.pipeline.createNamespacePipeline(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useCreateNamespacePipelineRelease() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const pipelineRelease =
await client.vdp.release.createNamespacePipelineRelease(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function useCreateNamespaceSecret() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const secret = await client.vdp.secret.createNamespaceSecret(payload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useDeleteNamespacePipeline() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

await client.vdp.pipeline.deleteNamespacePipeline({
namespacePipelineName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useDeleteNamespacePipelineRelease() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

await client.vdp.release.deleteNamespacePipelineRelease({
namespacePipelineReleaseName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useDeleteNamespaceSecret() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

await client.vdp.secret.deleteNamespaceSecret({
namespaceSecretName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export function useInfiniteNamespacePipelines({

const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipelines = await client.vdp.pipeline.listNamespacePipelines({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function useInfinitePipelines({
queryFn: async ({ pageParam }) => {
const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipelines = await client.vdp.pipeline.listAccessiblePipelines({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useOperatorDefinition({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const operatorDefinition =
await client.vdp.component.getOperatorDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useOperatorDefinitions({
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const operatorDefinitions =
await client.vdp.component.listOperatorDefinitions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useRenameNamespacePipeline() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const pipeline =
await client.vdp.pipeline.renameNamespacePipeline(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function useTriggerNamespacePipeline() {

const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function useTriggerNamespacePipelineRelease() {

const client = getInstillAPIClient({
accessToken: accessToken ?? undefined,
publicAccess: accessToken ? false : true,
});

const pipelineRelease =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useUpdateNamespacePipeline() {
return Promise.reject(new Error("accessToken not provided"));
}

const client = getInstillAPIClient({ accessToken, publicAccess: false });
const client = getInstillAPIClient({ accessToken });

const pipeline =
await client.vdp.pipeline.updateNamespacePipeline(payload);
Expand Down
11 changes: 2 additions & 9 deletions packages/toolkit/src/lib/vdp-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ export * from "./helper";

let instillAPIClient: Nullable<InstillAPIClient> = null;

export function getInstillAPIClient({
accessToken,
publicAccess,
}: {
accessToken?: string;
publicAccess: boolean;
}) {
export function getInstillAPIClient({ accessToken }: { accessToken?: string }) {
if (!instillAPIClient) {
const baseURL = `${
process.env.NEXT_SERVER_API_GATEWAY_URL ??
Expand All @@ -35,8 +29,7 @@ export function getInstillAPIClient({
baseURL,

// When non logged in user is viewing some pages, accessToken will be null
apiToken: accessToken ?? "",
publicAccess,
apiToken: accessToken,
});
}

Expand Down

0 comments on commit 0e138f9

Please sign in to comment.