diff --git a/packages/sdks/core-js-sdk/src/sdk/flow/index.ts b/packages/sdks/core-js-sdk/src/sdk/flow/index.ts index f228c9bbe..f6c066de6 100644 --- a/packages/sdks/core-js-sdk/src/sdk/flow/index.ts +++ b/packages/sdks/core-js-sdk/src/sdk/flow/index.ts @@ -3,7 +3,7 @@ import { HttpClient } from '../../httpClient'; import { transformResponse } from '../helpers'; import { FlowResponse, Options, SdkResponse } from '../types'; import { stringNonEmpty, withValidations } from '../validations'; -import { FlowInput, FlowVersions } from './types'; +import { FlowInput } from './types'; const withStartValidations = withValidations(stringNonEmpty('flowId')); const withNextValidations = withValidations( @@ -19,7 +19,9 @@ const withFlow = (httpClient: HttpClient) => ({ options?: Options, conditionInteractionId?: string, interactionId?: string, - flowVersions?: FlowVersions, + version?: number, + componentsVersion?: string, + flowVersions?: Record, input?: FlowInput, ): Promise> => transformResponse( @@ -28,6 +30,8 @@ const withFlow = (httpClient: HttpClient) => ({ options, conditionInteractionId, interactionId, + version, + componentsVersion, flowVersions, input, }), diff --git a/packages/sdks/core-js-sdk/src/sdk/flow/types.ts b/packages/sdks/core-js-sdk/src/sdk/flow/types.ts index 26df8d519..d3b643f53 100644 --- a/packages/sdks/core-js-sdk/src/sdk/flow/types.ts +++ b/packages/sdks/core-js-sdk/src/sdk/flow/types.ts @@ -5,10 +5,4 @@ type JSONSerializable = | null | Array; -export type FlowInput = Record; - -export type FlowVersions = { - version: number; - componentsVersion: string; - allVersions: Record; -}; +export type FlowInput = Record; \ No newline at end of file diff --git a/packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts b/packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts index 0aa99b576..f94496018 100644 --- a/packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts +++ b/packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts @@ -226,18 +226,13 @@ class DescopeWc extends BaseDescopeWc { const loginId = this.sdk.getLastUserLoginId(); const flowConfig = await this.getFlowConfig(); const projectConfig = await this.getProjectConfig(); - const flowVersions = { - version: flowConfig.version, - componentsVersion: projectConfig.componentsVersion, - allVersions: Object.entries(projectConfig.flows || {}).reduce( // pass also current versions for all flows, it may be used as a part of the current flow - (acc, [key, value]) => { - acc[key] = value.version; - return acc; - }, - {} as Record, - ), - }; - + const flowVersions = Object.entries(projectConfig.flows || {}).reduce( // pass also current versions for all flows, it may be used as a part of the current flow + (acc, [key, value]) => { + acc[key] = value.version; + return acc; + }, + {} as Record, + ); const redirectAuth = redirectAuthCallbackUrl && redirectAuthCodeChallenge ? { @@ -291,6 +286,8 @@ class DescopeWc extends BaseDescopeWc { }, conditionInteractionId, '', + flowConfig.version, + projectConfig.componentsVersion, flowVersions, { ...this.formConfigValues, @@ -516,6 +513,8 @@ class DescopeWc extends BaseDescopeWc { }, conditionInteractionId, interactionId, + version, + componentsVersion, flowVersions, { ...this.formConfigValues, diff --git a/packages/sdks/web-component/test/descope-wc.test.ts b/packages/sdks/web-component/test/descope-wc.test.ts index 84e22e07a..9a9aaa2d5 100644 --- a/packages/sdks/web-component/test/descope-wc.test.ts +++ b/packages/sdks/web-component/test/descope-wc.test.ts @@ -673,12 +673,10 @@ describe('web-component', () => { }, undefined, 'submitterId', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, { email: '', @@ -1730,7 +1728,7 @@ describe('web-component', () => { // Get start input is the 6th argument of the first call to start // ensure the result is passed to the start input - const startInput = startMock.mock.calls[0][5]; + const startInput = startMock.mock.calls[0][7]; expect(startInput).toEqual( expect.objectContaining({ [`${SDK_SCRIPT_RESULTS_KEY}.${scriptId}_${resultKey}`]: resultValue, @@ -1861,13 +1859,11 @@ describe('web-component', () => { expect.objectContaining({ redirectUrl: 'http://custom.url' }), undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "otpSignInEmail": 1, "versioned-flow": 1, - }, }, {}, ), @@ -1901,12 +1897,10 @@ describe('web-component', () => { }), undefined, '', + 1, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { email: 'test', @@ -2325,12 +2319,10 @@ describe('web-component', () => { }, conditionInteractionId, 'interactionId', + 1, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { origin: 'http://localhost' }, ), @@ -2373,12 +2365,10 @@ describe('web-component', () => { }, undefined, '', + 1, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { exchangeCode: 'code1', @@ -2463,12 +2453,10 @@ describe('web-component', () => { }, undefined, '', + 1, + undefined, { - "componentsVersion": undefined, - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { token: 'code1', @@ -2548,12 +2536,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, {}, ), @@ -2598,12 +2584,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, { token }, ), @@ -2640,12 +2624,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, {}, ), @@ -2769,12 +2751,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, {}, ), @@ -2812,12 +2792,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, {}, ), @@ -2851,12 +2829,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, { idpInitiated: true, @@ -2924,12 +2900,10 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "sign-in": 0, - }, }, {}, ), @@ -2963,13 +2937,11 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "otpSignInEmail": 1, "versioned-flow": 1, - }, }, { externalId: 'dummyUser', @@ -3032,13 +3004,11 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "otpSignInEmail": 1, "versioned-flow": 1, - }, }, {}, ), @@ -3100,13 +3070,11 @@ describe('web-component', () => { }, undefined, '', + 0, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 0, - "allVersions": { "otpSignInEmail": 1, "versioned-flow": 1, - }, }, {}, ), @@ -3177,12 +3145,10 @@ describe('web-component', () => { defaultOptionsValues, undefined, '', + 1, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { exchangeCode: 'code1', @@ -3235,12 +3201,10 @@ describe('web-component', () => { defaultOptionsValues, undefined, '', + 1, + "1.2.3", { - "componentsVersion": "1.2.3", - "version": 1, - "allVersions": { "sign-in": 1, - }, }, { exchangeCode: 'code1',