Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@analytics/remote-storage-utils

DavidWells188MIT0.4.22

Storage utilities for cross domain localStorage access, with permissions

analytics, analytics-project, analytics-util, storage, remote, cross-domain, localStorage, persistance

readme

Analytics Remote Storage Utils

Utilities for cross domain localStorage access.

Basic Usage

import RemoteStorage from '@analytics/remote-storage-utils'

// Connect to remote storage domain
const storage = new RemoteStorage('https://remote-site.com/storage.html')

// Get item
storage.getItem('the_remote_local_storage_key').then((value) => {
  console.log('value', value)
})

// Set item
storage.setItem({
  key: 'the_remote_local_storage_key',
  value: 'foobar'
}).then(() => {
  console.log('Value set')
})

API

getItem

Get localStorage from another domain

import { RemoteStorage } from '@analytics/remote-storage-utils'

const remoteStorage = new RemoteStorage('https://remote-site.com/storage.html')

remoteStorage.getItem('the_remote_local_storage_key').then(() => {
  console.log('remote value is', value)
})

getRemoteItem

You can also use the standalone getRemoteItem function with a cross storage client instance passed into it.

import { getRemoteItem, CrossStorageClient } from '@analytics/remote-storage-utils'

// Create an instance to use in standalone functions
const storageInstance = new CrossStorageClient('https://remote-site.com/storage.html')

const localStorageKeys = [
  'the_remote_local_storage_key',
  'another_remote_local_storage_key',
  'xyz',
]

getRemoteItem(localStorageKeys, storageInstance).then((values) => {
  console.log('remote values', values)
})

setItem

Set a localStorage value in remote domain

import { RemoteStorage } from '@analytics/remote-storage-utils'

const remoteStorage = new RemoteStorage('https://remote-site.com/storage.html')

remoteStorage.setItem('the_remote_local_storage_key', 'foobar').then(() => {
  console.log('remote value stored')
})

You can also use the standalone setRemoteItem function with a cross storage client instance passed into it.

import { setRemoteItem, CrossStorageClient } from '@analytics/remote-storage-utils'

// Create an instance to use in standalone functions
const storageInstance = new CrossStorageClient('https://remote-site.com/storage.html')

// Set remote value
setRemoteItem({
  key: 'foobar',
  value: JSON.stringify(userId)
}, storageInstance)

// Handler if values are different
function customConflictResolver(localValue, remoteValue) {
  if (localValue === remoteValue) {
    // Return empty to abort setting remote value
    return
  }
  if (remoteValue === 'cool') {
    // Return empty to abort setting remote value
    return
  }
  // Return value to set in remote
  return 'this-value-will-be-set'
}

setRemoteItem({
  key: 'baz',
  value: 123,
  resolve: customConflictResolver
}, crossStorage)

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.4.22 (2024-12-12)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.21 (2024-12-11)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.20 (2023-05-27)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.19 (2023-05-27)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.18 (2022-03-18)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.17 (2022-02-05)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.16 (2022-01-03)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.15 (2022-01-02)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.14 (2021-12-12)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.13 (2021-10-24)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.12 (2021-10-17)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.11 (2021-08-27)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.10 (2021-08-05)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.9 (2021-08-05)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.8 (2021-07-31)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.7 (2021-07-28)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.6 (2021-07-26)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.5 (2021-07-20)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.4 (2021-07-20)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.3 (2021-04-06)

Bug Fixes

0.4.2 (2021-03-20)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.1 (2021-03-11)

Note: Version bump only for package @analytics/remote-storage-utils

0.4.0 (2021-02-08)

Features

0.3.0 (2021-02-02)

Features

  • support options in remote storage (22d8713)

0.2.1 (2021-01-05)

Bug Fixes

0.2.0 (2021-01-05)

Bug Fixes

Features

0.1.0 (2020-12-09)

Features

  • add remote storage utility (806322c)