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 baseCdnUrl attribute in all packages #1014

Merged
merged 4 commits into from
Feb 11, 2025
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
4 changes: 2 additions & 2 deletions packages/libs/sdk-mixins/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = {
global: {
branches: 12,
functions: 16,
lines: 36,
statements: 36,
lines: 35,
statements: 35,
},
},
// A set of global variables that need to be available in all test environments
Expand Down
1 change: 0 additions & 1 deletion packages/libs/sdk-mixins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ export * from './mixins/initElementMixin';
export * from './mixins/initLifecycleMixin';
export * from './mixins/projectIdMixin';
export * from './mixins/baseUrlMixin';
export * from './mixins/baseStaticUrlMixin';
11 changes: 0 additions & 11 deletions packages/libs/sdk-mixins/src/mixins/baseStaticUrlMixin.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AccessKeyManagementComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() tenant: string;
@Input() widgetId: string;

Expand All @@ -29,6 +30,7 @@ export class AccessKeyManagementComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -50,6 +52,9 @@ export class AccessKeyManagementComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ApplicationsPortalComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() widgetId: string;

@Input() theme: 'light' | 'dark' | 'os';
Expand All @@ -38,6 +39,7 @@ export class ApplicationsPortalComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -58,6 +60,9 @@ export class ApplicationsPortalComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AuditManagementComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() tenant: string;
@Input() widgetId: string;

Expand All @@ -29,6 +30,7 @@ export class AuditManagementComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -50,6 +52,9 @@ export class AuditManagementComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DescopeComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
storeLastAuthenticatedUser?: boolean;
@Input() flowId: string;

Expand Down Expand Up @@ -58,6 +59,7 @@ export class DescopeComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
this.storeLastAuthenticatedUser = descopeConfig.storeLastAuthenticatedUser;
}

Expand Down Expand Up @@ -103,6 +105,9 @@ export class DescopeComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.storeLastAuthenticatedUser) {
this.webComponent.setAttribute(
'store-last-authenticated-user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class RoleManagementComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() tenant: string;
@Input() widgetId: string;

Expand All @@ -29,6 +30,7 @@ export class RoleManagementComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -50,6 +52,9 @@ export class RoleManagementComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class UserManagementComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() tenant: string;
@Input() widgetId: string;

Expand All @@ -29,6 +30,7 @@ export class UserManagementComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -51,6 +53,9 @@ export class UserManagementComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class UserProfileComponent implements OnInit, OnChanges {
projectId: string;
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
@Input() widgetId: string;

@Input() theme: 'light' | 'dark' | 'os';
Expand All @@ -38,6 +39,7 @@ export class UserProfileComponent implements OnInit, OnChanges {
this.projectId = descopeConfig.projectId;
this.baseUrl = descopeConfig.baseUrl;
this.baseStaticUrl = descopeConfig.baseStaticUrl;
this.baseCdnUrl = descopeConfig.baseCdnUrl;
}

ngOnInit() {
Expand All @@ -58,6 +60,9 @@ export class UserProfileComponent implements OnInit, OnChanges {
if (this.baseStaticUrl) {
this.webComponent.setAttribute('base-static-url', this.baseStaticUrl);
}
if (this.baseCdnUrl) {
this.webComponent.setAttribute('base-cdn-url', this.baseCdnUrl);
}
if (this.theme) {
this.webComponent.setAttribute('theme', this.theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class DescopeAuthConfig {
projectId = '';
baseUrl?: string;
baseStaticUrl?: string;
baseCdnUrl?: string;
// If true, tokens will be stored on local storage
persistTokens?: boolean;
sessionTokenViaCookie?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function initializeApp(authService: DescopeAuthService) {
projectId: environment.descopeProjectId,
baseUrl: environment.descopeBaseUrl || '',
baseStaticUrl: environment.descopeBaseStaticUrl || '',
baseCdnUrl: environment.descopeBaseCdnUrl || '',
sessionTokenViaCookie: true
})
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface Env {
descopeProjectId: string;
descopeBaseUrl?: string;
descopeBaseStaticUrl?: string;
descopeBaseCdnUrl?: string;
descopeFlowId?: string;
descopeDebugMode?: false;
descopeTheme?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const environment: Env = {
descopeProjectId: '',
descopeBaseUrl: '',
descopeBaseStaticUrl: '',
descopeBaseCdnUrl: '',
descopeFlowId: '',
descopeDebugMode: false,
descopeTheme: '',
Expand Down
76 changes: 38 additions & 38 deletions packages/sdks/core-js-sdk/src/createSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,47 @@ const withSdkConfigValidations = withValidations([
/** Add the ability to pass multiple hooks instead of one when creating an SDK instance */
const withMultipleHooks =
<T extends object>(createSdk: (config: SdkConfig) => T) =>
(
config: Omit<SdkConfig, 'hooks'> & {
hooks?: {
beforeRequest?: BeforeRequest | BeforeRequest[];
afterRequest?: AfterRequest | AfterRequest[];
transformResponse?: Hooks['transformResponse'];
(
config: Omit<SdkConfig, 'hooks'> & {
hooks?: {
beforeRequest?: BeforeRequest | BeforeRequest[];
afterRequest?: AfterRequest | AfterRequest[];
transformResponse?: Hooks['transformResponse'];
};
},
) => {
const beforeRequest: BeforeRequest = (conf) => {
// get the before hooks from the config while function is running
// because the hooks might change after sdk creation
const beforeRequestHooks = [].concat(config.hooks?.beforeRequest || []);
return beforeRequestHooks?.reduce((acc, fn) => fn(acc), conf);
};
},
) => {
const beforeRequest: BeforeRequest = (conf) => {
// get the before hooks from the config while function is running
// because the hooks might change after sdk creation
const beforeRequestHooks = [].concat(config.hooks?.beforeRequest || []);
return beforeRequestHooks?.reduce((acc, fn) => fn(acc), conf);
};

const afterRequest: AfterRequest = async (req, res) => {
// get the after hooks from the config while function is running
// because the hooks might change after sdk creation
const afterRequestHooks = [].concat(config.hooks?.afterRequest || []);
// do not remove this check - on old versions of react-native it is required
if (afterRequestHooks.length == 0) return;
const results = await Promise.allSettled(
afterRequestHooks?.map((fn) => fn(req, res?.clone())),
);
// eslint-disable-next-line no-console
results.forEach(
(result) =>
result.status === 'rejected' && config.logger?.error(result.reason),
);
};
const afterRequest: AfterRequest = async (req, res) => {
// get the after hooks from the config while function is running
// because the hooks might change after sdk creation
const afterRequestHooks = [].concat(config.hooks?.afterRequest || []);
// do not remove this check - on old versions of react-native it is required
if (afterRequestHooks.length == 0) return;
const results = await Promise.allSettled(
afterRequestHooks?.map((fn) => fn(req, res?.clone())),
);
// eslint-disable-next-line no-console
results.forEach(
(result) =>
result.status === 'rejected' && config.logger?.error(result.reason),
);
};

return createSdk({
...config,
hooks: {
beforeRequest,
afterRequest,
transformResponse: config.hooks?.transformResponse,
},
});
};
return createSdk({
...config,
hooks: {
beforeRequest,
afterRequest,
transformResponse: config.hooks?.transformResponse,
},
});
};

/** Descope SDK client */
export default withSdkConfigValidations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const AccessKeyManagement = React.forwardRef<

useImperativeHandle(ref, () => innerRef);

const { projectId, baseUrl, baseStaticUrl } = React.useContext(Context);
const { projectId, baseUrl, baseStaticUrl, baseCdnUrl } = React.useContext(Context);

return (
<Suspense fallback={null}>
Expand All @@ -34,6 +34,7 @@ const AccessKeyManagement = React.forwardRef<
tenant={tenant}
baseUrl={baseUrl}
baseStaticUrl={baseStaticUrl}
baseCdnUrl={baseCdnUrl}
innerRef={setInnerRef}
{...{
// attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ApplicationsPortal = React.forwardRef<

useImperativeHandle(ref, () => innerRef);

const { projectId, baseUrl, baseStaticUrl } = React.useContext(Context);
const { projectId, baseUrl, baseStaticUrl, baseCdnUrl } = React.useContext(Context);

return (
<Suspense fallback={null}>
Expand All @@ -33,6 +33,7 @@ const ApplicationsPortal = React.forwardRef<
widgetId={widgetId}
baseUrl={baseUrl}
baseStaticUrl={baseStaticUrl}
baseCdnUrl={baseCdnUrl}
innerRef={setInnerRef}
{...{
// attributes
Expand Down
3 changes: 2 additions & 1 deletion packages/sdks/react-sdk/src/components/AuditManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const AuditManagement = React.forwardRef<HTMLElement, AuditManagementProps>(

useImperativeHandle(ref, () => innerRef);

const { projectId, baseUrl, baseStaticUrl } = React.useContext(Context);
const { projectId, baseUrl, baseStaticUrl, baseCdnUrl } = React.useContext(Context);

return (
<Suspense fallback={null}>
Expand All @@ -32,6 +32,7 @@ const AuditManagement = React.forwardRef<HTMLElement, AuditManagementProps>(
tenant={tenant}
baseUrl={baseUrl}
baseStaticUrl={baseStaticUrl}
baseCdnUrl={baseCdnUrl}
innerRef={setInnerRef}
{...{
// attributes
Expand Down
Loading