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

fix: add base-static-url param RELEASE #596

Merged
merged 1 commit into from
May 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const staticResourcesMixin = createSingletonMixin(
const resourceUrl = getResourceUrl({
projectId: this.projectId,
filename,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
dorsha marked this conversation as resolved.
Show resolved Hide resolved
});
const res = await fetch(resourceUrl, { cache: 'default' });
if (!res.ok) {
Expand All @@ -60,6 +60,10 @@ export const staticResourcesMixin = createSingletonMixin(
headers: Object.fromEntries(res.headers.entries()),
};
}

get baseStaticUrl() {
return this.getAttribute('base-static-url');
}
};
},
);
10 changes: 7 additions & 3 deletions packages/web-component/src/lib/descope-wc/BaseDescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ class BaseDescopeWc extends HTMLElement {
return this.getAttribute('base-url') || undefined;
}

get baseStaticUrl() {
return this.getAttribute('base-static-url');
}

get tenant() {
return this.getAttribute('tenant') || undefined;
}
Expand Down Expand Up @@ -332,7 +336,7 @@ class BaseDescopeWc extends HTMLElement {
projectId: this.projectId,
filename: CONFIG_FILENAME,
assetsFolder: PREV_VER_ASSETS_FOLDER,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
});
try {
await fetchContent(prevVerConfigUrl, 'json');
Expand All @@ -347,7 +351,7 @@ class BaseDescopeWc extends HTMLElement {
const configUrl = getContentUrl({
projectId: this.projectId,
filename: CONFIG_FILENAME,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
});
try {
const { body, headers } = await fetchContent(configUrl, 'json');
Expand All @@ -364,7 +368,7 @@ class BaseDescopeWc extends HTMLElement {
const themeUrl = getContentUrl({
projectId: this.projectId,
filename: THEME_FILENAME,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
});
try {
const { body } = await fetchContent(themeUrl, 'json');
Expand Down
4 changes: 2 additions & 2 deletions packages/web-component/src/lib/descope-wc/DescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ class DescopeWc extends BaseDescopeWc {
htmlUrl: getContentUrl({
projectId,
filename: `${readyScreenId}.html`,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
}),
htmlLocaleUrl:
filenameWithLocale &&
getContentUrl({
projectId,
filename: filenameWithLocale,
baseUrl: this.baseUrl,
baseUrl: this.baseStaticUrl,
}),
samlIdpUsername,
oidcLoginHint,
Expand Down
4 changes: 2 additions & 2 deletions packages/web-component/src/lib/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export function getContentUrl({
projectId,
filename,
assetsFolder = ASSETS_FOLDER,
baseUrl = BASE_CONTENT_URL,
baseUrl,
}: {
projectId: string;
filename: string;
assetsFolder?: string;
baseUrl?: string;
}) {
const url = new URL(OVERRIDE_CONTENT_URL || baseUrl);
const url = new URL(OVERRIDE_CONTENT_URL || baseUrl || BASE_CONTENT_URL);
url.pathname = pathJoin(url.pathname, projectId, assetsFolder, filename);

return url.toString();
Expand Down
6 changes: 3 additions & 3 deletions packages/web-component/test/descope-wc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,19 @@ describe('web-component', () => {
);
});

it('should fetch the data from the correct base url', async () => {
it('should fetch the data from the correct base static url', async () => {
startMock.mockReturnValue(generateSdkResponse());

pageContent = '<input id="email"></input><span>It works!</span>';

document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc project-id="1" flow-id="otpSignInEmail" base-url="http:https://base.url"></descope-wc>`;
document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc project-id="1" flow-id="otpSignInEmail" base-static-url="http:https://base.url/pages"></descope-wc>`;

await waitFor(() => screen.getByShadowText('It works!'), {
timeout: WAIT_TIMEOUT,
});

expect(fetchMock).toHaveBeenCalledWith(
expect.stringMatching(/^http:\/\/base.url\/.*\.html/),
expect.stringMatching(/^http:\/\/base.url\/pages.*\.html/),
expect.any(Object),
);
});
Expand Down
Loading