Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(analytics-js-plugins): add backward compatibility for storage api #1669

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { StorageType } from '@rudderstack/analytics-js-common/types/Storage
import type { Nullable } from '@rudderstack/analytics-js-common/types/Nullable';
import type { ILogger } from '@rudderstack/analytics-js-common/types/Logger';
import type { BatchOpts, QueueOpts } from '@rudderstack/analytics-js-common/types/LoadOptions';
import { isDefined, isNullOrUndefined } from '@rudderstack/analytics-js-common/utilities/checks';
import { isDefined, isFunction, isNullOrUndefined } from '@rudderstack/analytics-js-common/utilities/checks';
import { LOCAL_STORAGE } from '@rudderstack/analytics-js-common/constants/storages';
import { generateUUID } from '@rudderstack/analytics-js-common/utilities/uuId';
import type {
Expand Down Expand Up @@ -705,7 +705,21 @@ class RetryQueue implements IQueue<QueueItemData> {
};
const findOtherQueues = (name: string): IStore[] => {
const res: IStore[] = [];
const storageKeys = this.store.getOriginalEngine().keys();
const storageEngine = this.store.getOriginalEngine();
let storageKeys = [];
// 'keys' API is not supported by all the core SDK versions
// Hence, we need this backward compatibility check
if (isFunction(storageEngine.keys)) {
storageKeys = storageEngine.keys();
} else {
for (let i = 0; i < storageEngine.length; i++) {
const key = storageEngine.key(i);
if (key) {
storageKeys.push(key);
}
}
}

storageKeys.forEach((k: string) => {
const keyParts: string[] = k ? k.split('.') : [];

Expand Down