Skip to content

Commit

Permalink
avoid using versions object
Browse files Browse the repository at this point in the history
  • Loading branch information
talaharoni committed Oct 14, 2024
1 parent f884929 commit b8a627d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 94 deletions.
8 changes: 6 additions & 2 deletions packages/sdks/core-js-sdk/src/sdk/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -19,7 +19,9 @@ const withFlow = (httpClient: HttpClient) => ({
options?: Options,
conditionInteractionId?: string,
interactionId?: string,
flowVersions?: FlowVersions,
version?: number,
componentsVersion?: string,
flowVersions?: Record<string, number>,
input?: FlowInput,
): Promise<SdkResponse<FlowResponse>> =>
transformResponse(
Expand All @@ -28,6 +30,8 @@ const withFlow = (httpClient: HttpClient) => ({
options,
conditionInteractionId,
interactionId,
version,
componentsVersion,
flowVersions,
input,
}),
Expand Down
8 changes: 1 addition & 7 deletions packages/sdks/core-js-sdk/src/sdk/flow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ type JSONSerializable =
| null
| Array<JSONSerializable>;

export type FlowInput = Record<string, JSONSerializable>;

export type FlowVersions = {
version: number;
componentsVersion: string;
allVersions: Record<string, number>;
};
export type FlowInput = Record<string, JSONSerializable>;
23 changes: 11 additions & 12 deletions packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>,
),
};

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<string, number>,
);
const redirectAuth =
redirectAuthCallbackUrl && redirectAuthCodeChallenge
? {
Expand Down Expand Up @@ -291,6 +286,8 @@ class DescopeWc extends BaseDescopeWc {
},
conditionInteractionId,
'',
flowConfig.version,
projectConfig.componentsVersion,
flowVersions,
{
...this.formConfigValues,
Expand Down Expand Up @@ -516,6 +513,8 @@ class DescopeWc extends BaseDescopeWc {
},
conditionInteractionId,
interactionId,
version,
componentsVersion,
flowVersions,
{
...this.formConfigValues,
Expand Down
110 changes: 37 additions & 73 deletions packages/sdks/web-component/test/descope-wc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,10 @@ describe('web-component', () => {
},
undefined,
'submitterId',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{
email: '',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
{},
),
Expand Down Expand Up @@ -1901,12 +1897,10 @@ describe('web-component', () => {
}),
undefined,
'',
1,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 1,
"allVersions": {
"sign-in": 1,
},
},
{
email: 'test',
Expand Down Expand Up @@ -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' },
),
Expand Down Expand Up @@ -2373,12 +2365,10 @@ describe('web-component', () => {
},
undefined,
'',
1,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 1,
"allVersions": {
"sign-in": 1,
},
},
{
exchangeCode: 'code1',
Expand Down Expand Up @@ -2463,12 +2453,10 @@ describe('web-component', () => {
},
undefined,
'',
1,
undefined,
{
"componentsVersion": undefined,
"version": 1,
"allVersions": {
"sign-in": 1,
},
},
{
token: 'code1',
Expand Down Expand Up @@ -2548,12 +2536,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{},
),
Expand Down Expand Up @@ -2598,12 +2584,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{ token },
),
Expand Down Expand Up @@ -2640,12 +2624,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{},
),
Expand Down Expand Up @@ -2769,12 +2751,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{},
),
Expand Down Expand Up @@ -2812,12 +2792,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{},
),
Expand Down Expand Up @@ -2851,12 +2829,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{
idpInitiated: true,
Expand Down Expand Up @@ -2924,12 +2900,10 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"sign-in": 0,
},
},
{},
),
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -3032,13 +3004,11 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"otpSignInEmail": 1,
"versioned-flow": 1,
},
},
{},
),
Expand Down Expand Up @@ -3100,13 +3070,11 @@ describe('web-component', () => {
},
undefined,
'',
0,
"1.2.3",
{
"componentsVersion": "1.2.3",
"version": 0,
"allVersions": {
"otpSignInEmail": 1,
"versioned-flow": 1,
},
},
{},
),
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b8a627d

Please sign in to comment.