Skip to content

Commit

Permalink
fix(config): allow optional config
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Jan 9, 2024
1 parent f1d62da commit efab99f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/js-client/src/core/remote-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { HEADER_REMOTE_STORAGE_INSTANCE_ID, HEADER_REMOTE_STORAGE_USER_ID } from

const apiPrefix = `/entities/`

interface RemoteStorageProps {
interface RemoteStorageConfig {
/**
* The server address to use for remote storage. Defaults to https://rs.frigade.com
*/
serverAddress: string
serverAddress?: string
/**
* The user ID to use for remote storage. Defaults to a random UUID if not provided.
*/
Expand All @@ -25,7 +25,8 @@ export class RemoteStorage {
private readonly instanceId: string
private readonly userId: string

constructor({ serverAddress, userId, instanceId }: RemoteStorageProps) {
constructor(config?: RemoteStorageConfig) {
const { serverAddress, instanceId, userId } = config ?? {}
this.serverAddress = serverAddress ?? 'https://rs.frigade.com'
this.instanceId = instanceId ?? 'default'
this.userId = userId ?? this.getUserId()
Expand Down
7 changes: 7 additions & 0 deletions packages/js-client/test/remote-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ describe('global storage', () => {
const value = await remoteStorage.getItem<{ foo: string }>('key')
expect(value).toEqual({ foo: 'bar' })
})

it('works without setting server address', async () => {
const remoteStorage = new RemoteStorage()
await remoteStorage.setItem('key', 'value')
const value = await remoteStorage.getItem('key')
expect(value).toEqual('value')
})
})

0 comments on commit efab99f

Please sign in to comment.