Skip to content

Commit

Permalink
add flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nirgur committed Oct 15, 2024
1 parent e7624d3 commit 88ba4ae
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ class BaseDescopeWc extends BaseClass {
this.#componentsContext = { ...this.#componentsContext, ...e.detail };
}

get isRestartOnError() {
return this.getAttribute('restart-on-error') === 'true';
}

async getExecutionContext() {
const { executionContext } = await this.getConfig();

Expand Down
21 changes: 11 additions & 10 deletions packages/sdks/web-component/src/lib/descope-wc/DescopeWc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ class DescopeWc extends BaseDescopeWc {
return null;
}

async #handleFlowReload() {
this.loggerWrapper.debug('Trying to reload the flow');
async #handleFlowRestart() {
this.loggerWrapper.debug('Trying to restart the flow');
const prevCompVersion = await this.getComponentsVersion();
this.getConfig.reset();
const compVersion = await this.getComponentsVersion();

if (prevCompVersion === compVersion) {
this.loggerWrapper.debug(
'Components version was not changed, reloading flow',
'Components version was not changed, restarting flow',
);
this.flowState.update({
stepId: null,
Expand Down Expand Up @@ -250,10 +250,10 @@ class DescopeWc extends BaseDescopeWc {
const redirectAuth =
redirectAuthCallbackUrl && redirectAuthCodeChallenge
? {
callbackUrl: redirectAuthCallbackUrl,
codeChallenge: redirectAuthCodeChallenge,
backupCallbackUri: redirectAuthBackupCallbackUri,
}
callbackUrl: redirectAuthCallbackUrl,
codeChallenge: redirectAuthCodeChallenge,
backupCallbackUri: redirectAuthBackupCallbackUri,
}
: undefined;

// if there is no execution id we should start a new flow
Expand Down Expand Up @@ -634,11 +634,12 @@ class DescopeWc extends BaseDescopeWc {

// E102004 = Flow requested is in old version
// E103205 = Flow timed out
const errorCode = sdkResp?.error?.errorCode
if (
sdkResp?.error?.errorCode === 'E102004' ||
sdkResp?.error?.errorCode === 'E103205'
(errorCode === 'E102004' || errorCode === 'E103205') &&
this.isRestartOnError
) {
this.#handleFlowReload();
this.#handleFlowRestart();
}
return;
}
Expand Down
11 changes: 5 additions & 6 deletions packages/sdks/web-component/test/helpers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
handleAutoFocus,
isChromium,
setRunIdsOnUrl,
withMemCache
withMemCache,
} from '../../src/lib/helpers/helpers';

const mockFetch = jest.fn();
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('withMemCache', () => {
const myFnWithMemCache = withMemCache(myFn);

expect(myFnWithMemCache()).toBe('result');
})
});

it('should cache the fn result', () => {
const myFn = jest.fn(() => 'result');
Expand All @@ -238,7 +238,7 @@ describe('withMemCache', () => {
myFnWithMemCache();

expect(myFn).toHaveBeenCalledTimes(1);
})
});

it('should reset the cache when the reset function is called', () => {
const myFn = jest.fn(() => 'result');
Expand All @@ -249,6 +249,5 @@ describe('withMemCache', () => {
myFnWithMemCache();

expect(myFn).toHaveBeenCalledTimes(2);
})

})
});
});
Loading

0 comments on commit 88ba4ae

Please sign in to comment.