Skip to content
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
45 changes: 0 additions & 45 deletions src/integrationTests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,51 +910,6 @@ testCookieAndLocalStorage(() => {
});
});

describe('abort()', () => {
test('should not clear cookie', () => {
const identity = makeIdentityV2();
setUid2(identity, useCookie);
uid2.abort();
expect(getUid2(useCookie).advertising_token).toBe(identity.advertising_token);
});
test('should abort refresh timer', () => {
uid2.init({
callback: callback,
identity: makeIdentityV2(),
useCookie: useCookie,
});
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(clearTimeout).not.toHaveBeenCalled();
uid2.abort();
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(clearTimeout).toHaveBeenCalledTimes(1);
});
test('should not abort refresh timer if not timer is set', () => {
uid2.init({
callback: callback,
identity: makeIdentityV2({ refresh_from: Date.now() - 100000 }),
useCookie: useCookie,
});
expect(setTimeout).not.toHaveBeenCalled();
expect(clearTimeout).not.toHaveBeenCalled();
uid2.abort();
expect(setTimeout).not.toHaveBeenCalled();
expect(clearTimeout).not.toHaveBeenCalled();
});
test('should abort refresh token request', () => {
uid2.init({
callback: callback,
identity: makeIdentityV2({ refresh_from: Date.now() - 100000 }),
useCookie: useCookie,
});
expect(xhrMock.send).toHaveBeenCalledTimes(1);
expect(xhrMock.abort).not.toHaveBeenCalled();
uid2.abort();
expect(xhrMock.send).toHaveBeenCalledTimes(1);
expect(xhrMock.abort).toHaveBeenCalledTimes(1);
});
});

describe('disconnect()', () => {
test('should clear cookie', () => {
setUid2(makeIdentityV2(), useCookie);
Expand Down
13 changes: 10 additions & 3 deletions src/sdkBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ export abstract class SdkBase {
}

public disconnect() {
this.abort(`${this._product.name} SDK disconnected.`);
this._tokenPromiseHandler.rejectAllPromises(new Error(`${this._product.name} SDK aborted.`));
if (this._refreshTimerId) {
clearTimeout(this._refreshTimerId);
this._refreshTimerId = null;
}
if (this._apiClient) this._apiClient.abortActiveRequests();
// Note: This silently fails to clear the cookie if init hasn't been called and a cookieDomain is used!
if (this._storageManager) this._storageManager.removeValues();
else
Expand All @@ -215,6 +220,9 @@ export abstract class SdkBase {
}

// Note: This doesn't invoke callbacks. It's a hard, silent reset.
/**
* @deprecated abort() is deprecated in version 3.10.0. Will be removed in June 2025. Use disconnect() instead
*/
public abort(reason?: string) {
this._tokenPromiseHandler.rejectAllPromises(
reason ?? new Error(`${this._product.name} SDK aborted.`)
Expand Down Expand Up @@ -403,8 +411,7 @@ export abstract class SdkBase {
} else if (validity.status === IdentityStatus.OPTOUT || status === IdentityStatus.OPTOUT) {
this._storageManager.setOptout();
} else {
this.abort();
this._storageManager.removeValues();
this.disconnect();
}

this._identity = this._storageManager.loadIdentity();
Expand Down
Loading