Skip to content

Commit 13b3ef0

Browse files
committed
feat: add-effects-package
Refactored some types to allow for better passing of types through and narrowing.
1 parent a4b53c0 commit 13b3ef0

30 files changed

+370
-84
lines changed

.changeset/config.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
],
99
"commit": false,
1010
"fixed": [["@forgerock/*"]],
11-
"privatePackages": false,
1211
"linked": [],
1312
"access": "public",
1413
"baseBranch": "main",

.changeset/lemon-rocks-dream.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@forgerock/davinci-client': minor
3+
'@forgerock/effects': minor
4+
---
5+
6+
add effects package

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ packages/**/coverage/
1717
node_modules/
1818
tests/**/app/index.js*
1919
tests/**/ie11/ie-bundle.js*
20+
**/out-tsc/*
2021
.swc
2122
.vite
2223

e2e/davinci-app/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const searchParams = new URLSearchParams(qs);
2121
const config: DaVinciConfig =
2222
serverConfigs[searchParams.get('clientId') || '724ec718-c41c-4d51-98b0-84a583f450f9'];
2323

24-
const requestMiddleware: RequestMiddleware[] = [
24+
const requestMiddleware: RequestMiddleware<'DAVINCI_NEXT' | 'DAVINCI_START'>[] = [
2525
(fetchArgs, action, next) => {
2626
if (action.type === 'DAVINCI_START') {
2727
fetchArgs.url.searchParams.set('start', 'true');

eslint.config.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default [
5757
{
5858
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
5959
rules: {
60+
'import/extensions': [2, 'ignorePackages'],
6061
'@nx/enforce-module-boundaries': [
6162
'warn',
6263
{
@@ -69,12 +70,16 @@ export default [
6970
},
7071
{
7172
sourceTag: 'scope:package',
72-
onlyDependOnLibsWithTags: [],
73+
onlyDependOnLibsWithTags: ['scope:effects'],
7374
},
7475
{
7576
sourceTag: 'scope:types',
7677
onlyDependOnLibsWithTags: [],
7778
},
79+
{
80+
sourceTag: 'scope:effects',
81+
onlyDependOnLibsWithTags: [],
82+
},
7883
],
7984
},
8085
],

nx.json

+17-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"!{projectRoot}/test-setup.[jt]s",
2626
"noEslintConfig",
2727
"noMarkdown",
28-
"workspaceRootIgnores"
28+
"workspaceRootIgnores",
29+
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)"
2930
],
3031
"noMarkdown": ["!{projectRoot}/*.md", "!{projectRoot}/**/*.md"],
3132
"noTests": [
@@ -69,7 +70,7 @@
6970
},
7071
"test": {
7172
"inputs": ["default", "^default", "noMarkdown", "^noMarkdown"],
72-
"dependsOn": ["^test"],
73+
"dependsOn": ["^test", "^build"],
7374
"outputs": ["{projectRoot}/coverage"],
7475
"cache": true
7576
},
@@ -152,6 +153,20 @@
152153
"typecheckTargetName": "typecheck"
153154
},
154155
"include": ["packages/**/**/*", "e2e/**/**/*"]
156+
},
157+
{
158+
"plugin": "@nx/vite/plugin",
159+
"options": {
160+
"buildTargetName": "vite:build",
161+
"testTargetName": "vite:test",
162+
"serveTargetName": "vite:serve",
163+
"devTargetName": "vite:dev",
164+
"previewTargetName": "vite:preview",
165+
"serveStaticTargetName": "vite:serve-static",
166+
"typecheckTargetName": "vite:typecheck",
167+
"buildDepsTargetName": "vite:build-deps",
168+
"watchDepsTargetName": "vite:watch-deps"
169+
}
155170
}
156171
],
157172
"parallel": 1,
@@ -161,7 +176,6 @@
161176
},
162177
"generators": {
163178
"@nx/js:library": {
164-
"publishable": true,
165179
"outDir": "{projectRoot}/dist",
166180
"bundler": "tsc",
167181
"linter": "eslint",

package.json

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
22
"name": "ping-javascript-sdk",
3+
"version": "0.0.0",
34
"private": true,
45
"description": "Ping JavaScript SDK",
5-
"packageManager": "[email protected]+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531",
6-
"engines": {
7-
"node": "^20 || ^22",
8-
"pnpm": "9.15.9"
6+
"homepage": "https://github.com/ForgeRock/ping-javascript-sdk#readme",
7+
"bugs": {
8+
"url": "https://github.com/ForgeRock/ping-javascript-sdk/issues"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/ForgeRock/ping-javascript-sdk.git"
913
},
14+
"author": "ForgeRock",
1015
"scripts": {
1116
"build": "nx affected --target=build",
12-
"clean": "shx rm -rf ./{coverage,dist,docs,node_modules,tmp}/ ./{packages,e2e}/*/{dist,node_modules}/ && git clean -fX -e \"!.env*,nx-cloud.env\"",
17+
"changeset": "changeset",
1318
"ci:release": "pnpm publish -r --no-git-checks && changeset tag",
1419
"ci:version": "changeset version && pnpm install --no-frozen-lockfile && pnpm format",
15-
"changeset": "changeset",
20+
"clean": "shx rm -rf ./{coverage,dist,docs,node_modules,tmp}/ ./{packages,e2e}/*/{dist,node_modules}/ && git clean -fX -e \"!.env*,nx-cloud.env\"",
1621
"commit": "git cz",
22+
"commitlint": "commitlint --edit",
1723
"create-package": "nx g @nx/js:library",
1824
"docs": "nx affected --target=typedoc",
1925
"format": "pnpm nx format:write",
@@ -24,9 +30,8 @@
2430
"serve": "nx serve",
2531
"test": "CI=true nx affected:test",
2632
"test:e2e": "CI=true nx affected:e2e",
27-
"watch": "nx watch-deps",
2833
"verdaccio": "nx local-registry",
29-
"commitlint": "commitlint --edit"
34+
"watch": "nx watch-deps"
3035
},
3136
"lint-staged": {
3237
"*": [
@@ -36,15 +41,12 @@
3641
"git add"
3742
]
3843
},
39-
"repository": {
40-
"type": "git",
41-
"url": "https://github.com/ForgeRock/ping-javascript-sdk.git"
42-
},
43-
"author": "ForgeRock",
44-
"bugs": {
45-
"url": "https://github.com/ForgeRock/ping-javascript-sdk/issues"
44+
"config": {
45+
"commitizen": {
46+
"path": "./node_modules/cz-conventional-changelog"
47+
}
4648
},
47-
"homepage": "https://github.com/ForgeRock/ping-javascript-sdk#readme",
49+
"dependencies": {},
4850
"devDependencies": {
4951
"@changesets/changelog-github": "^0.5.0",
5052
"@changesets/cli": "^2.27.9",
@@ -80,7 +82,7 @@
8082
"@types/node": "22.13.16",
8183
"@typescript-eslint/typescript-estree": "8.23.0",
8284
"@typescript-eslint/utils": "^8.13.0",
83-
"@vitest/coverage-v8": "3.0.4",
85+
"@vitest/coverage-v8": "^3.0.5",
8486
"@vitest/ui": "3.0.4",
8587
"conventional-changelog-conventionalcommits": "^8.0.0",
8688
"cz-conventional-changelog": "^3.3.0",
@@ -119,10 +121,10 @@
119121
"vitest": "3.0.5",
120122
"vitest-canvas-mock": "^0.3.3"
121123
},
122-
"config": {
123-
"commitizen": {
124-
"path": "./node_modules/cz-conventional-changelog"
125-
}
124+
"packageManager": "[email protected]+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531",
125+
"engines": {
126+
"node": "^20 || ^22",
127+
"pnpm": "9.15.9"
126128
},
127129
"nx": {
128130
"includedScripts": []

packages/davinci-client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test:watch": "pnpm nx nxTest --watch"
2323
},
2424
"dependencies": {
25+
"@forgerock/effects": "workspace:*",
2526
"@forgerock/javascript-sdk": "4.7.0",
2627
"@reduxjs/toolkit": "catalog:",
2728
"immer": "catalog:"

packages/davinci-client/src/lib/client.store.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { davinciApi } from './davinci.api.js';
77
import { configSlice } from './config.slice.js';
88
import { wellknownApi } from './wellknown.api.js';
99

10+
import type { RequestMiddleware } from '@forgerock/effects/types';
1011
/**
1112
* Import the DaVinciRequest types
1213
*/
@@ -25,7 +26,7 @@ import type {
2526
import type { InitFlow, Updater, Validator } from './client.types.js';
2627
import { returnValidator } from './collector.utils.js';
2728
import { authorize } from './davinci.utils.js';
28-
import type { RequestMiddleware } from './effects/request.effect.types.js';
29+
import { ActionTypes } from '@forgerock/effects/unions';
2930

3031
/**
3132
* Create a client function that returns a set of methods
@@ -35,12 +36,12 @@ import type { RequestMiddleware } from './effects/request.effect.types.js';
3536
* @param {ConfigurationOptions} options - the configuration options for the client
3637
* @returns {Observable} - an observable client for DaVinci flows
3738
*/
38-
export async function davinci({
39+
export async function davinci<ActionType extends ActionTypes = ActionTypes>({
3940
config,
4041
requestMiddleware,
4142
}: {
4243
config: DaVinciConfig;
43-
requestMiddleware?: RequestMiddleware[];
44+
requestMiddleware?: RequestMiddleware<ActionType>[];
4445
}) {
4546
const store = createClientStore({ requestMiddleware });
4647

packages/davinci-client/src/lib/client.store.utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { configureStore } from '@reduxjs/toolkit';
22

3+
import type { RequestMiddleware } from '@forgerock/effects/types';
34
import { configSlice } from './config.slice.js';
45
import { nodeSlice } from './node.slice.js';
56
import { davinciApi } from './davinci.api.js';
67
import { ErrorNode, ContinueNode, StartNode, SuccessNode } from '../types.js';
78
import { wellknownApi } from './wellknown.api.js';
9+
import { ActionTypes } from '@forgerock/effects/unions';
810

9-
import type { RequestMiddleware } from './effects/request.effect.types.js';
10-
11-
export function createClientStore({
11+
export function createClientStore<ActionType extends ActionTypes>({
1212
requestMiddleware,
1313
}: {
14-
requestMiddleware?: RequestMiddleware[];
14+
requestMiddleware?: RequestMiddleware<ActionType, unknown>[];
1515
}) {
1616
return configureStore({
1717
reducer: {

packages/davinci-client/src/lib/davinci.api.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
/**
1515
* Import internal modules
1616
*/
17+
import { initQuery } from '@forgerock/effects';
18+
import { RequestMiddleware } from '@forgerock/effects/types';
19+
1720
import { createAuthorizeUrl } from './authorize.utils.js';
1821
import { handleResponse, transformActionRequest, transformSubmitRequest } from './davinci.utils.js';
1922

@@ -29,15 +32,14 @@ import type {
2932
} from './davinci.types.js';
3033
import type { ContinueNode } from './node.types.js';
3134
import type { StartNode } from '../types.js';
32-
import { initQuery } from './effects/request.effect.utils.js';
33-
import { RequestMiddleware } from './effects/request.effect.types.js';
35+
import { ActionTypes } from '@forgerock/effects/unions';
3436

3537
type BaseQueryResponse = Promise<
3638
QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>
3739
>;
3840

39-
interface Extras {
40-
requestMiddleware: RequestMiddleware[];
41+
interface Extras<ActionType extends ActionTypes = ActionTypes, Payload = unknown> {
42+
requestMiddleware: RequestMiddleware<ActionType, Payload>[];
4143
}
4244

4345
/**

packages/davinci-client/src/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type * as collectors from './lib/collector.types.js';
44
import type * as config from './lib/config.types.js';
55
import type * as nodes from './lib/node.types.js';
66
import type * as client from './lib/client.types.js';
7-
import type * as effect from './lib/effects/request.effect.types.js';
7+
import type { RequestMiddleware } from '@forgerock/effects/types';
88

99
export type DaVinciConfig = config.DaVinciConfig;
1010

@@ -37,5 +37,4 @@ export type ValidatedTextCollector = collectors.ValidatedTextCollector;
3737
export type ReadOnlyCollector = collectors.ReadOnlyCollector;
3838
export type MultiSelectCollector = collectors.MultiSelectCollector;
3939
export type SingleSelectCollector = collectors.SingleSelectCollector;
40-
41-
export type RequestMiddleware = effect.RequestMiddleware;
40+
export type { RequestMiddleware };

packages/davinci-client/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
"noPropertyAccessFromIndexSignature": true,
88
"noImplicitReturns": true,
99
"noFallthroughCasesInSwitch": true,
10-
"resolveJsonModule": true
10+
"resolveJsonModule": true,
11+
"baseUrl": "."
1112
},
1213
"references": [
14+
{
15+
"path": "../effects"
16+
},
1317
{
1418
"path": "./tsconfig.lib.json"
1519
},

packages/davinci-client/tsconfig.lib.json

+5
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
"src/**/*.types.test-d.ts",
2929
"src/**/*.utils.test-d.ts",
3030
"src/lib/mock-data/*"
31+
],
32+
"references": [
33+
{
34+
"path": "../effects/tsconfig.lib.json"
35+
}
3136
]
3237
}

packages/effects/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# effects
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build effects` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test effects` to execute the unit tests via [Vitest](https://vitest.dev/).

packages/effects/eslint.config.mjs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import baseConfig from '../../eslint.config.mjs';
2+
3+
export default [
4+
...baseConfig,
5+
{
6+
files: ['**/*.json'],
7+
rules: {
8+
'@nx/dependency-checks': [
9+
'error',
10+
{
11+
ignoredFiles: [
12+
'{projectRoot}/*.test.{js,cjs,mjs,ts}',
13+
'{projectRoot}/eslint.config.{js,cjs,mjs}',
14+
'{projectRoot}/vite.config.ts',
15+
],
16+
},
17+
],
18+
},
19+
languageOptions: {
20+
parser: await import('jsonc-eslint-parser'),
21+
},
22+
},
23+
{
24+
ignores: [
25+
'**/*.md',
26+
'LICENSE',
27+
'.babelrc',
28+
'.env*',
29+
'.bin',
30+
'dist',
31+
'.eslintignore',
32+
'docs',
33+
'coverage',
34+
'vite.config.*.timestamp*',
35+
'*tsconfig.tsbuildinfo*',
36+
'**/**/mock-data/*.d.ts*',
37+
'out-tsc',
38+
'node_modules',
39+
],
40+
},
41+
];

0 commit comments

Comments
 (0)