Skip to content

Commit

Permalink
Merge branch 'main' into oidc-client
Browse files Browse the repository at this point in the history
  • Loading branch information
asafshen committed Jan 15, 2025
2 parents 3c04ac0 + 656acd8 commit 7c3185d
Show file tree
Hide file tree
Showing 106 changed files with 3,508 additions and 2,530 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-next-react-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- fix/react-sdk-next

env:
NODE_VERSION: 18.10.0
Expand Down Expand Up @@ -49,7 +48,8 @@ jobs:
- name: Check if should run
id: 'check'
run: |
if $(npx nx show projects --affected --plain | grep -q "react-sdk"); then
# Check if the affected projects include "react-sdk" or "web-component" since the last commit
if $(npx nx show projects --affected --base HEAD~1 --head HEAD | grep -q "react-sdk\|web-component"); then
echo "run=true" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
Expand Down
23 changes: 23 additions & 0 deletions packages/libs/sdk-mixins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [0.6.0](https://github.com/descope/descope-js/compare/sdk-mixins-0.5.2...sdk-mixins-0.6.0) (2024-12-24)


### Features

* Content from base url ([#871](https://github.com/descope/descope-js/issues/871)) RELEASE ([f3e437e](https://github.com/descope/descope-js/commit/f3e437e0793507627b157317063fe39174600c80))

## [0.5.2](https://github.com/descope/descope-js/compare/sdk-mixins-0.5.1...sdk-mixins-0.5.2) (2024-12-22)


### Bug Fixes

* support react-19 ([#860](https://github.com/descope/descope-js/issues/860)) RELEASE ([efd6833](https://github.com/descope/descope-js/commit/efd6833dfefc854b7f461606084234603f2444e0))

## [0.5.1](https://github.com/descope/descope-js/compare/sdk-mixins-0.5.0...sdk-mixins-0.5.1) (2024-12-18)

## [0.5.0](https://github.com/descope/descope-js/compare/sdk-mixins-0.4.0...sdk-mixins-0.5.0) (2024-12-04)


### Features

* Status param & dynamic os theme ([#854](https://github.com/descope/descope-js/issues/854)) ([f3deea7](https://github.com/descope/descope-js/commit/f3deea70df62c19209866e918c8013427dc33700))

## [0.4.0](https://github.com/descope/descope-js/compare/sdk-mixins-0.3.2...sdk-mixins-0.4.0) (2024-11-10)


Expand Down
8 changes: 4 additions & 4 deletions packages/libs/sdk-mixins/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module.exports = {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
coverageThreshold: {
global: {
branches: 80,
functions: 93.5,
lines: 93.5,
statements: 93.5,
branches: 12,
functions: 17,
lines: 36,
statements: 36,
},
},
// A set of global variables that need to be available in all test environments
Expand Down
47 changes: 35 additions & 12 deletions packages/libs/sdk-mixins/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
{
"name": "@descope/sdk-mixins",
"version": "0.4.0",
"version": "0.6.0",
"author": "Descope Team <[email protected]>",
"homepage": "https://github.com/descope/sdk-mixins",
"bugs": {
"url": "https://github.com/descope/sdk-mixins/issues",
"email": "[email protected]"
},
"main": "dist/cjs/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/cjs/index.cjs.js"
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.esm.js"
"./theme-mixin": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/esm/mixins/themeMixin/index.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/cjs/mixins/themeMixin/index.js"
}
},
"./static-resources-mixin": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/esm/mixins/staticResourcesMixin/index.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/cjs/mixins/staticResourcesMixin/index.js"
}
}
},
"type": "module",
"description": "Descope JavaScript SDK mixins",
"scripts": {
"build": "rimraf dist && rollup -c",
"test": "echo no tests yet",
"test": "jest",
"lint": "eslint '+(src|test|examples)/**/*.ts'"
},
"license": "MIT",
Expand Down Expand Up @@ -83,7 +105,8 @@
"ts-node": "10.9.2",
"typescript": "^5.0.2",
"@reduxjs/toolkit": "^2.0.1",
"redux": "5.0.1"
"redux": "5.0.1",
"rollup-plugin-no-emit": "1.2.1"
},
"dependencies": {
"@descope/sdk-helpers": "workspace:*",
Expand Down
86 changes: 49 additions & 37 deletions packages/libs/sdk-mixins/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,72 @@ import del from 'rollup-plugin-delete';
import dts from 'rollup-plugin-dts';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import noEmit from 'rollup-plugin-no-emit';

import packageJson from './package.json' assert { type: 'json' };

const plugins = [
replace({
values: {
BUILD_VERSION: JSON.stringify(packageJson.version),
},
preventAssignment: true,
}),
typescript({
tsconfig: './tsconfig.json',
}),
commonjs(),
resolve(),
// terser(),
const input = [
'./src/index.ts',
'./src/mixins/themeMixin/index.ts',
'./src/mixins/staticResourcesMixin/index.ts',
];
const input = './src/index.ts';
const external = (id) =>
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');

export default [
{
input,
output: {
file: packageJson.main,
format: 'cjs',
sourcemap: true,
exports: 'named',
interop: 'compat',
inlineDynamicImports: true,
},
plugins,
external,
},
{
input,
output: {
file: packageJson.module,
format: 'esm',
sourcemap: true,
inlineDynamicImports: true,
},
plugins,
output: [
{
dir: './dist/cjs',
format: 'cjs',
sourcemap: true,
exports: 'named',
interop: 'compat',
inlineDynamicImports: false,
preserveModules: true,
},
{
dir: './dist/esm',
format: 'esm',
sourcemap: true,
inlineDynamicImports: false,
preserveModules: true,
},
],
plugins: [
del({ targets: 'dist/*' }),
replace({
values: {
BUILD_VERSION: JSON.stringify(packageJson.version),
},
preventAssignment: true,
}),
typescript({
tsconfig: './tsconfig.json',
}),
commonjs(),
resolve(),
// terser(),
],
external,
},
{
input: './dist/dts/src/index.d.ts',
output: [{ file: packageJson.types, format: 'esm' }],
input: input[0],
output: [{ dir: './dist', format: 'esm', inlineDynamicImports: true }],
plugins: [
typescript({
tsconfig: './tsconfig.json',
compilerOptions: {
declaration: true,
declarationDir: './dist/types',
},
}),
dts(),
del({ hook: 'buildEnd', targets: ['./dist/dts', './dist/cjs/dts'] }),
cjsPackage(),
noEmit({ match: (file) => file.endsWith('.js') }),
],
external,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export const configMixin = createSingletonMixin(

#fetchConfig = async () => {
try {
const { body, headers } = await this.fetchStaticResource(
CONFIG_FILENAME,
'json',
);
const {
body,
headers,
}: { body: ProjectConfiguration; headers: Record<string, any> } =
await (<any>this.fetchStaticResource(CONFIG_FILENAME, 'json'));
return {
projectConfig: body as ProjectConfiguration,
executionContext: { geo: headers['x-geo'] },
Expand Down
12 changes: 6 additions & 6 deletions packages/libs/sdk-mixins/src/mixins/configMixin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ type Operator =
| 'is-false'
| 'in'
| 'not-in';
export interface ClientCondition {
export type ClientCondition = {
operator: Operator;
key: string;
predicate?: string | number;
met: ClientConditionResult;
unmet?: ClientConditionResult;
}
};

export interface ClientConditionResult {
export type ClientConditionResult = {
screenId: string;
interactionId: string;
}
};

export type FlowConfig = {
startScreenId?: string;
Expand All @@ -46,7 +46,7 @@ export type FlowConfig = {
fingerprintKey?: string;
};

export interface ProjectConfiguration {
export type ProjectConfiguration = {
componentsVersion: string;
cssTemplate: {
dark: ThemeTemplate;
Expand All @@ -55,4 +55,4 @@ export interface ProjectConfiguration {
flows: {
[key: string]: FlowConfig; // dynamic key names for flows
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ const createValidateAttributesMixin =
}

async init() {
await super.init?.();

// check attributes initial values
mappingsNames.forEach((attr) =>
this.#handleError(attr, this.getAttribute(attr)),
);
await super.init?.();
}
};
};
Expand Down
1 change: 1 addition & 0 deletions packages/libs/sdk-mixins/src/mixins/loggerMixin/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './loggerMixin';
export type { Logger } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const loggerMixin = createSingletonMixin(
}, {}) as Logger;
}

set logger(logger: Partial<Logger>) {
this.#logger = this.#wrapLogger(logger);
set logger(logger: Partial<Logger> | undefined) {
this.#logger = this.#wrapLogger(logger || console);
}

get logger(): Logger {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Logger } from '../loggerMixin';

type FetchParams = Parameters<typeof fetch>;
const notLastMsgSuffix = 'Trying the next fallback URL...';

export const fetchWithFallbacks = async (
fallbacks: FetchParams['0'] | FetchParams['0'][],
init: FetchParams['1'],
{
logger,
onSuccess,
}: { logger?: Logger; onSuccess?: (urlIndex: number) => void },
): ReturnType<typeof fetch> => {
const fallbacksArr = Array.isArray(fallbacks) ? fallbacks : [fallbacks];

for (let index = 0; index < fallbacksArr.length; index++) {
const url = fallbacksArr[index];
const isLast = index === fallbacksArr.length - 1;

try {
const res = await fetch(url.toString(), init);
if (res.ok) {
onSuccess?.(index);
return res;
}

const errMsg = `Error fetching URL ${url} [${res.status}]`;

if (isLast) throw new Error(errMsg);

logger?.debug(`${errMsg}. ${notLastMsgSuffix}`);
} catch (e) {
const errMsg = `Error fetching URL ${url} [${e.message}]`;

if (isLast) throw new Error(errMsg);

logger?.debug(`${errMsg}. ${notLastMsgSuffix}`);
}
}
};
Loading

0 comments on commit 7c3185d

Please sign in to comment.