Skip to content

Commit 87c200b

Browse files
authored
Merge pull request #251 from ForgeRock/storage-package
feat: storage-package
2 parents d428a76 + 6ec1f15 commit 87c200b

20 files changed

Lines changed: 760 additions & 28 deletions

.changeset/orange-baths-vanish.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@forgerock/sdk-types': minor
3+
'@forgerock/storage': minor
4+
---
5+
6+
created sdk-storage module, which includes session,local, and token storage

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
3+
*
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
17
import { FlatCompat } from '@eslint/eslintrc';
28
import { dirname } from 'path';
39
import { fileURLToPath } from 'url';

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
"test": {
7272
"inputs": ["default", "^default", "noMarkdown", "^noMarkdown"],
73-
"dependsOn": ["^test", "^build", "^build", "^build", "^build"],
73+
"dependsOn": ["^test", "^build"],
7474
"outputs": ["{projectRoot}/coverage"],
7575
"cache": true
7676
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,6 @@
132132
},
133133
"nx": {
134134
"includedScripts": []
135-
}
135+
},
136+
"dependencies": {}
136137
}

packages/davinci-client/src/lib/config.types.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77
import { describe, expectTypeOf, it } from 'vitest';
88
import type { DaVinciConfig, InternalDaVinciConfig } from './config.types.js';
9-
import type { AsyncConfigOptions } from '@forgerock/sdk-types';
9+
import type { AsyncLegacyConfigOptions } from '@forgerock/sdk-types';
1010
import type { WellknownResponse } from './wellknown.types.js';
1111

1212
describe('Config Types', () => {
1313
describe('DaVinciConfig', () => {
14-
it('should extend AsyncConfigOptions', () => {
15-
expectTypeOf<DaVinciConfig>().toMatchTypeOf<AsyncConfigOptions>();
14+
it('should extend AsyncLegacyConfigOptions', () => {
15+
expectTypeOf<DaVinciConfig>().toMatchTypeOf<AsyncLegacyConfigOptions>();
1616
});
1717

1818
it('should have optional responseType', () => {
@@ -24,7 +24,7 @@ describe('Config Types', () => {
2424
expectTypeOf<DaVinciConfig>().toHaveProperty('responseType').toBeNullable();
2525
});
2626

27-
it('should allow AsyncConfigOptions properties', () => {
27+
it('should allow AsyncLegacyConfigOptions properties', () => {
2828
const config: DaVinciConfig = {
2929
clientId: 'test-client',
3030
scope: 'openid profile',

packages/davinci-client/src/lib/config.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* of the MIT license. See the LICENSE file for details.
66
*/
77
/**
8-
* Import ConfigOptions type from the JavaScript SDK
8+
* Import LegacyConfigOptions type from the JavaScript SDK
99
*/
10-
import type { AsyncConfigOptions } from '@forgerock/sdk-types';
10+
import type { AsyncLegacyConfigOptions } from '@forgerock/sdk-types';
1111
import { WellknownResponse } from './wellknown.types.js';
1212

13-
export interface DaVinciConfig extends AsyncConfigOptions {
13+
export interface DaVinciConfig extends AsyncLegacyConfigOptions {
1414
responseType?: string;
1515
}
1616

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# ForgeRock SDK Effects - Storage
2+
3+
This package provides a storage effect for managing token storage within the ForgeRock JavaScript SDK ecosystem.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @forgerock/sdk-effects-storage
9+
# or
10+
yarn add @forgerock/sdk-effects-storage
11+
```
12+
13+
## Usage
14+
15+
The `storage` effect facilitates getting, setting, and removing items from browser storage (`localStorage` or `sessionStorage`) or a custom token store implementation.
16+
17+
```typescript
18+
import { storage } from '@forgerock/sdk-effects-storage';
19+
import { TokenStoreObject } from '@forgerock/sdk-types';
20+
21+
// Example using localStorage
22+
const storageEffect = storage({
23+
tokenStore: 'localStorage',
24+
prefix: 'fr-auth',
25+
clientId: 'my-client-id',
26+
});
27+
28+
const storageApi = storageEffect();
29+
30+
async function manageTokens() {
31+
// Set a token
32+
await storageApi.set('someTokenValue');
33+
34+
// Get a token
35+
const token = await storageApi.get();
36+
console.log(token); // Output: 'someTokenValue'
37+
38+
// Remove a token
39+
await storageApi.remove();
40+
41+
// Verify removal
42+
const removedToken = await storageApi.get();
43+
console.log(removedToken); // Output: null
44+
}
45+
46+
// Example using a custom token store
47+
const myCustomStore: TokenStoreObject = {
48+
get: async (key) => {
49+
/* ... custom logic ... */ return null;
50+
},
51+
set: async (key, value) => {
52+
/* ... custom logic ... */
53+
},
54+
remove: async (key) => {
55+
/* ... custom logic ... */
56+
},
57+
};
58+
59+
const customStorageEffect = storage(
60+
{
61+
tokenStore: 'localStorage', // This is ignored when customTokenStore is provided
62+
prefix: 'fr-auth',
63+
clientId: 'my-client-id',
64+
},
65+
myCustomStore,
66+
);
67+
68+
const customStorageApi = customStorageEffect();
69+
// Use customStorageApi.get(), .set(), .remove() as above
70+
```
71+
72+
## Configuration
73+
74+
The `storage` function accepts a configuration object with the following properties:
75+
76+
- `tokenStore`: Specifies the storage mechanism. Can be `'localStorage'`, `'sessionStorage'`, or a custom object conforming to the `TokenStoreObject` interface.
77+
- `prefix`: A string prefix used in generating the storage key.
78+
- `clientId`: The client ID, also used in generating the storage key.
79+
80+
An optional second argument allows providing a `customTokenStore` object directly, which overrides the `tokenStore` configuration property if provided.
81+
82+
The storage key is generated as \`\` `${prefix}-${clientId}`
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
3+
*
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
import baseConfig from '../../../eslint.config.mjs';
8+
9+
export default [
10+
...baseConfig,
11+
{
12+
files: ['**/*.json'],
13+
rules: {
14+
'@nx/dependency-checks': [
15+
'error',
16+
{
17+
ignoredFiles: [
18+
'{projectRoot}/eslint.config.{js,cjs,mjs}',
19+
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
20+
],
21+
},
22+
],
23+
},
24+
languageOptions: {
25+
parser: await import('jsonc-eslint-parser'),
26+
},
27+
},
28+
];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@forgerock/storage",
3+
"version": "0.0.1",
4+
"private": false,
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/ForgeRock/ping-javascript-sdk.git",
8+
"directory": "packages/sdk-effects/storage"
9+
},
10+
"type": "module",
11+
"main": "./dist/src/index.js",
12+
"module": "./dist/src/index.js",
13+
"types": "./dist/src/index.d.ts",
14+
"exports": {
15+
"./package.json": "./package.json",
16+
".": {
17+
"types": "./dist/src/index.d.ts",
18+
"import": "./dist/src/index.js",
19+
"default": "./dist/src/index.js"
20+
}
21+
},
22+
"dependencies": {
23+
"@forgerock/sdk-types": "workspace:*",
24+
"tslib": "^2.3.0"
25+
},
26+
"nx": {
27+
"tags": ["scope:sdk-effects"]
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
3+
*
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
export * from './lib/storage.effects.js';

0 commit comments

Comments
 (0)