Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename environment config. #60

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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