Skip to content

Commit a16b794

Browse files
authored
Merge pull request #299 from ForgeRock/type-client
feat: add-davinci-client-type
2 parents 8d50e40 + a2c6b78 commit a16b794

23 files changed

Lines changed: 81 additions & 55 deletions

File tree

.changeset/deep-hornets-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
## '@forgerock/davinci-client': minor
4+
5+
provide a client type that handles the awaiting of the davinci client initalization and a type for handling getClient call so consumers have the type available easily

e2e/davinci-app/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import './style.css';
88

99
import { Config, FRUser, TokenManager } from '@forgerock/javascript-sdk';
1010
import { davinci } from '@forgerock/davinci-client';
11-
import type { DaVinciConfig, RequestMiddleware } from '@forgerock/davinci-client/types';
11+
import type {
12+
DaVinciConfig,
13+
RequestMiddleware,
14+
DavinciClient,
15+
GetClient,
16+
} from '@forgerock/davinci-client/types';
1217

1318
import textComponent from './components/text.js';
1419
import passwordComponent from './components/password.js';
@@ -48,7 +53,7 @@ const requestMiddleware: RequestMiddleware<'DAVINCI_NEXT' | 'DAVINCI_START'>[] =
4853
const urlParams = new URLSearchParams(window.location.search);
4954

5055
(async () => {
51-
const davinciClient = await davinci({ config, requestMiddleware });
56+
const davinciClient: DavinciClient = await davinci({ config, requestMiddleware });
5257
const continueToken = urlParams.get('continueToken');
5358
const formEl = document.getElementById('form') as HTMLFormElement;
5459
let resumed: any;
@@ -62,7 +67,7 @@ const urlParams = new URLSearchParams(window.location.search);
6267
}
6368

6469
function renderComplete() {
65-
const clientInfo = davinciClient.getClient();
70+
const clientInfo: GetClient = davinciClient.getClient();
6671
const serverInfo = davinciClient.getServer();
6772

6873
let code = '';

e2e/mock-api-v2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"type": "module",
77
"main": "./dist/index.js",
88
"scripts": {
9+
"build": "pnpm nx nxBuild",
910
"lint": "pnpm nx nxLint",
1011
"serve": "node dist/e2e/mock-api-v2/src/main.js",
1112
"serve:dev": "nodemon dist/e2e/mock-api-v2/src/main.js",

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"targetName": "typecheck"
122122
},
123123
"build": {
124-
"targetName": "build",
124+
"targetName": "nxBuild",
125125
"configName": "tsconfig.lib.json"
126126
}
127127
},

packages/davinci-client/package.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"typings": "./dist/src/index.d.ts",
1818
"files": ["dist", "!dist/tsconfig.lib.tsbuildinfo", "./LICENSE"],
1919
"scripts": {
20+
"build": "pnpm nx nxBuild",
2021
"lint": "pnpm nx nxLint",
2122
"test": "pnpm nx nxTest",
2223
"test:watch": "pnpm nx nxTest --watch"
@@ -35,19 +36,6 @@
3536
"access": "public"
3637
},
3738
"nx": {
38-
"tags": ["scope:package"],
39-
"targets": {
40-
"build": {
41-
"executor": "@nx/js:tsc",
42-
"outputs": ["{options.outputPath}"],
43-
"options": {
44-
"outputPath": "packages/davinci-client/dist",
45-
"main": "packages/davinci-client/src/index.ts",
46-
"tsConfig": "packages/davinci-client/tsconfig.lib.json",
47-
"generatePackageJson": false,
48-
"assets": []
49-
}
50-
}
51-
}
39+
"tags": ["scope:package"]
5240
}
5341
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import type {
3131
ObjectValueCollectors,
3232
PhoneNumberInputValue,
3333
} from './collector.types.js';
34-
import type { InitFlow, Updater, Validator } from './client.types.js';
34+
import type { InitFlow, NodeStates, Updater, Validator } from './client.types.js';
3535
import { returnValidator } from './collector.utils.js';
3636
import { authorize } from './davinci.utils.js';
37-
import { NodeStates, StartNode } from '../types.js';
37+
import { StartNode } from './node.types.js';
3838

3939
/**
4040
* Create a client function that returns a set of methods

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ export type Validator = (value: string) =>
3030
};
3131
type: string;
3232
};
33+
34+
export type NodeStates = StartNode | ContinueNode | ErrorNode | SuccessNode | FailureNode;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/* eslint-disable @typescript-eslint/no-unused-vars */
88
import { describe, expectTypeOf, it } from 'vitest';
99
import type {
10-
NodeStates,
1110
StartNode,
1211
ContinueNode,
1312
ErrorNode,
@@ -23,6 +22,7 @@ import type {
2322
} from './types.js';
2423
import type * as Types from './types.js';
2524
import { DaVinciError } from './lib/node.types.js';
25+
import { NodeStates } from './lib/client.types.js';
2626

2727
describe('Type exports', () => {
2828
it('should validate all types are exported', () => {

packages/davinci-client/src/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ import type * as collectors from './lib/collector.types.js';
1111
import type * as config from './lib/config.types.js';
1212
import type * as nodes from './lib/node.types.js';
1313
import type * as client from './lib/client.types.js';
14+
import { davinci } from './lib/client.store.js';
15+
import { nodeSlice } from './lib/node.slice.js';
1416

1517
export type DaVinciConfig = config.DaVinciConfig;
1618

19+
export type DavinciClient = Awaited<ReturnType<typeof davinci>>;
1720
export type Updater = client.Updater;
1821
export type InitFlow = client.InitFlow;
1922
export type Validator = client.Validator;
20-
23+
export type GetClient = ReturnType<typeof nodeSlice.selectors.selectClient>;
2124
export type StartNode = nodes.StartNode;
2225
export type ContinueNode = nodes.ContinueNode;
2326
export type ErrorNode = nodes.ErrorNode;
2427
export type SuccessNode = nodes.SuccessNode;
2528
export type FailureNode = nodes.FailureNode;
2629

27-
export type NodeStates = StartNode | ContinueNode | ErrorNode | SuccessNode | FailureNode;
28-
2930
export type Collectors = nodes.Collectors;
3031
export type DaVinciValidationError = nodes.DaVinciError;
3132

packages/device-client/package.json

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"typings": "./dist/index.d.ts",
2121
"files": ["./dist"],
2222
"scripts": {
23+
"build": "pnpm nx nxBuild",
2324
"lint": "pnpm nx nxLint",
2425
"test": "pnpm nx nxTest",
2526
"test:watch": "pnpm nx nxTest --watch"
@@ -32,18 +33,6 @@
3233
"msw": "^2.5.1"
3334
},
3435
"nx": {
35-
"targets": {
36-
"build": {
37-
"executor": "@nx/js:tsc",
38-
"outputs": ["{options.outputPath}"],
39-
"options": {
40-
"outputPath": "packages/device-client/dist",
41-
"main": "packages/device-client/src/index.ts",
42-
"tsConfig": "packages/device-client/tsconfig.lib.json",
43-
"generatePackageJson": false,
44-
"assets": []
45-
}
46-
}
47-
}
36+
"tags": ["scope:package"]
4837
}
4938
}

0 commit comments

Comments
 (0)