Skip to content

Commit

Permalink
Rename environment config.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 1, 2024
1 parent fdcd991 commit 2fe0cd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
9 changes: 0 additions & 9 deletions src/environments.ts

This file was deleted.

19 changes: 11 additions & 8 deletions src/wrapper/SquidexClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as environments from "../environments";
import {
AppsApi,
AppsApiInterface,
Expand Down Expand Up @@ -69,12 +68,12 @@ export interface SquidexOptions {
/**
* Custom headers to be added to each request.
*/
customHeader?: Record<string, string>;
customHeaders?: Record<string, string>;

/**
* The URL to your Squidex installation (cloud by default).
*/
environment?: environments.SquidexEnvironment | string;
url?: string;

/**
* A custom fetcher for normal requests.
Expand Down Expand Up @@ -240,8 +239,8 @@ export class SquidexClients {
/**
* The current URL to the Squidex installation.
*/
public get environment() {
return this.clientOptions.environment || environments.SquidexEnvironment.Default;
public get url() {
return this.clientOptions.url!;
}

constructor(readonly clientOptions: SquidexOptions) {
Expand All @@ -257,6 +256,10 @@ export class SquidexClients {
throw new Error("Configuration 'appName' is required.");
}

clientOptions.url ||= 'https://cloud.squidex.io';

Object.freeze(clientOptions);

this.tokenStore = this.clientOptions.tokenStore || new InMemoryTokenStore();

const fetchCore = this.clientOptions.fetcher || fetch;
Expand Down Expand Up @@ -303,7 +306,7 @@ export class SquidexClients {
};

const parameters: ConfigurationParameters = {
basePath: clientOptions.environment || "https://cloud.squidex.io",
basePath: clientOptions.url || "https://cloud.squidex.io",
fetchApi,
};

Expand All @@ -330,8 +333,8 @@ function addOptions(init: RequestInit, clientOptions: SquidexOptions) {
init.signal = AbortSignal.timeout(clientOptions.timeout);
}

if (clientOptions.customHeader) {
for (const [key, value] of Object.entries(clientOptions.customHeader)) {
if (clientOptions.customHeaders) {
for (const [key, value] of Object.entries(clientOptions.customHeaders)) {
addHeader(init, key, value);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getClient() {
const appName = getEnvironment("CONFIG__APP__NAME", "integrations-tests");
const clientId = getEnvironment("CONFIG__CLIENT__ID", "root");
const clientSecret = getEnvironment("CONFIG__CLIENT__SECRET", "xeLd6jFxqbXJrfmNLlO2j1apagGGGSyZJhFnIuHp4I0=");
const environment = getEnvironment("CONFIG__SERVER__URL", "https://localhost:5001");
const url = getEnvironment("CONFIG__SERVER__URL", "https://localhost:5001");

const middleware: SquidexOptions["middleware"] = {
pre: async (params) => {
Expand All @@ -32,7 +32,7 @@ export function getClient() {
appName,
clientId,
clientSecret,
environment,
url,
middleware,
});

Expand All @@ -41,7 +41,7 @@ export function getClient() {
appName: app,
clientId,
clientSecret,
environment,
url,
middleware,
});
};
Expand Down

0 comments on commit 2fe0cd4

Please sign in to comment.