@seliseblocks/client 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AI_USAGE_GUIDE.md CHANGED
@@ -1,149 +1,149 @@
1
- # AI Usage Guide
2
-
3
- Use this file only for `@seliseblocks/client` app-code work. For full method details, read the source docstrings.
4
-
5
- Source refs:
6
-
7
- - Client setup: `src/client.ts`
8
- - Auth: `src/auth/auth-client.ts`
9
- - IAM: `src/iam/iam-client.ts`
10
- - Data: `src/data/data-client.ts`
11
- - Localization: `src/localization/localization-client.ts`
12
- - HTTP/errors: `src/http/http-client.ts`, `src/http/errors.ts`
13
-
14
- ## Non-Negotiable Rules
15
-
16
- - Configure `xBlocksKey`; SDK sends it as `x-blocks-key`.
17
- - Do not send `ProjectKey` or `projectKey`.
18
- - Do not add `/api` after `/v4`.
19
- - Valid route shapes: `/iam/v4/...`, `/data/v4/...`, `/localization/v4/...`.
20
- - SDK does not store tokens. App owns access token, refresh token, storage, and logout cleanup.
21
- - Frontend code must not contain client secrets.
22
- - Do not add impersonation, release deploy, schema/rules mutation, or localization authoring/admin APIs.
23
-
24
- ## Create Client
25
-
26
- ```ts
27
- import { createBlocksClient } from "@seliseblocks/client";
28
-
29
- export const blocks = createBlocksClient({
30
- apiUrl: "https://api.seliseblocks.com",
31
- xBlocksKey: env.BLOCKS_KEY,
32
- accessToken: () => session.accessToken,
33
- oidc: {
34
- url: "https://iam.seliseblocks.com",
35
- clientId: env.OIDC_CLIENT_ID,
36
- redirectUri: env.OIDC_REDIRECT_URI ?? `${window.location.origin}/login/callback`
37
- }
38
- });
39
- ```
40
-
41
- Use `accessToken` only for the current token resolver. Do not add SDK token storage.
42
- Use a configured `redirectUri` when available; the current-origin `/login/callback` URL is only a browser fallback.
43
-
44
- ## Auth Decision
45
-
46
- There are two auth flows.
47
-
48
- OIDC/hosted IAM flow:
49
-
50
- - Login: `blocks.auth.idp.initiate()`, `blocks.auth.idp.redirectToProvider()`, `blocks.auth.idp.callback(...)`
51
- - Refresh: `blocks.auth.oidc.refreshToken({ refreshToken })`
52
- - Refresh route: `POST /iam/v4/oidc/token`
53
- - Must send `client_id`; SDK uses `request.clientId` or configured `oidc.clientId`.
54
- - Do not manually build `oidc/authorize`.
55
-
56
- Embedded/app-owned flow:
57
-
58
- - Login: `blocks.auth.login(...)`
59
- - Social: `blocks.auth.socialInitiate(...)`, `blocks.auth.socialCallback(...)`
60
- - Refresh: `blocks.auth.refresh({ refreshToken })`
61
- - Routes: `/iam/v4/auth/login`, `/iam/v4/auth/social/*`, `/iam/v4/auth/refresh`
62
-
63
- Shared auth methods for both flows:
64
-
65
- - `userInfo()`
66
- - `switchOrganization(...)`
67
- - `logout(...)`, `logoutAll(...)`
68
- - `signup(...)`, `recover(...)`, `resetPassword(...)`
69
- - `changePassword(...)`
70
- - `activate(...)`, `resendActivation(...)`, `validateActivation(...)`
71
- - `identityProviders.*`, `config.*`, `userCodes.*`, `clientCredentials.*` when app has permission
72
-
73
- ## Service Map
74
-
75
- IAM:
76
-
77
- - `blocks.iam.me()`
78
- - `blocks.iam.users.*`
79
- - `blocks.iam.roles.*`
80
- - `blocks.iam.permissions.*`
81
- - `blocks.iam.resources.*`
82
- - `blocks.iam.organizations.*`
83
- - `blocks.iam.signup.*`
84
-
85
- Data:
86
-
87
- - `blocks.data.schemas.*` for schema reads only
88
- - `blocks.data.validations.*` for validation reads
89
- - `blocks.data.collection("Name").list/get/create/update/delete`
90
- - `blocks.data.graphql(...)`
91
- - `blocks.data.files.*` for file/storage helpers
92
- - `blocks.data.dms.*` for DMS file/folder helpers
93
- - `blocks.data.utilities.*` for runtime utility helpers
94
-
95
- Localization:
96
-
97
- - `blocks.localization.languages()`
98
- - `blocks.localization.modules()`
99
- - `blocks.localization.languagesForCurrentTenant()`
100
- - `blocks.localization.modulesForCurrentTenant()`
101
- - `blocks.localization.translations(moduleName, language)`
102
- - `blocks.localization.load(language, modules)`
103
- - `blocks.localization.cloudTranslations(moduleName, language)`
104
- - `blocks.localization.loadCloud(language, modules)`
105
- - `blocks.localization.keysByNames(...)`
106
- - `blocks.localization.t(key, fallback, options)`
107
-
108
- HTTP fallback:
109
-
110
- - Use `blocks.http.request("/service/v4/...")` only when no typed method exists.
111
- - Use `blocks.http.external(url, ...)` only for external URLs such as pre-signed uploads.
112
-
113
- ## Minimal Examples
114
-
115
- ```ts
116
- const me = await blocks.iam.me();
117
- const schemas = await blocks.data.schemas.list({ pageNo: 1, pageSize: 20 });
118
- const rows = await blocks.data.collection("Students").list({ pageNo: 1, pageSize: 20 });
119
- await blocks.localization.load("en-US", ["common"]);
120
- const label = blocks.localization.t("save", "Save");
121
- ```
122
-
123
- OIDC refresh with explicit client id:
124
-
125
- ```ts
126
- await blocks.auth.oidc.refreshToken({
127
- clientId: env.OIDC_CLIENT_ID,
128
- refreshToken: session.refreshToken
129
- });
130
- ```
131
-
132
- Embedded refresh:
133
-
134
- ```ts
135
- await blocks.auth.refresh({
136
- refreshToken: session.refreshToken
137
- });
138
- ```
139
-
140
- ## Check Before Finishing
141
-
142
- ```bash
143
- npm test
144
- npm run lint
145
- npm pack --dry-run
146
- rg -n "v4[/\\]api|iam[/\\]v4[/\\]api|data[/\\]v4[/\\]api|localization[/\\]v4[/\\]api" src README.md AI_USAGE_GUIDE.md test
147
- ```
148
-
149
- Only negative route-guard tests should match.
1
+ # AI Usage Guide
2
+
3
+ Use this file only for `@seliseblocks/client` app-code work. For full method details, read the source docstrings.
4
+
5
+ Source refs:
6
+
7
+ - Client setup: `src/client.ts`
8
+ - Auth: `src/auth/auth-client.ts`
9
+ - IAM: `src/iam/iam-client.ts`
10
+ - Data: `src/data/data-client.ts`
11
+ - Localization: `src/localization/localization-client.ts`
12
+ - HTTP/errors: `src/http/http-client.ts`, `src/http/errors.ts`
13
+
14
+ ## Non-Negotiable Rules
15
+
16
+ - Configure `xBlocksKey`; SDK sends it as `x-blocks-key`.
17
+ - Do not send `ProjectKey` or `projectKey`.
18
+ - Do not add `/api` after `/v4`.
19
+ - Valid route shapes: `/iam/v4/...`, `/data/v4/...`, `/localization/v4/...`.
20
+ - SDK does not store tokens. App owns access token, refresh token, storage, and logout cleanup.
21
+ - Frontend code must not contain client secrets.
22
+ - Do not add impersonation, release deploy, schema/rules mutation, or localization authoring/admin APIs.
23
+
24
+ ## Create Client
25
+
26
+ ```ts
27
+ import { createBlocksClient } from "@seliseblocks/client";
28
+
29
+ export const blocks = createBlocksClient({
30
+ apiUrl: "https://api.seliseblocks.com",
31
+ xBlocksKey: env.BLOCKS_KEY,
32
+ accessToken: () => session.accessToken,
33
+ oidc: {
34
+ url: "https://iam.seliseblocks.com",
35
+ clientId: env.OIDC_CLIENT_ID,
36
+ redirectUri: env.OIDC_REDIRECT_URI ?? `${window.location.origin}/login/callback`
37
+ }
38
+ });
39
+ ```
40
+
41
+ Use `accessToken` only for the current token resolver. Do not add SDK token storage.
42
+ Use a configured `redirectUri` when available; the current-origin `/login/callback` URL is only a browser fallback.
43
+
44
+ ## Auth Decision
45
+
46
+ There are two auth flows.
47
+
48
+ OIDC/hosted IAM flow:
49
+
50
+ - Login: `blocks.auth.idp.initiate()`, `blocks.auth.idp.redirectToProvider()`, `blocks.auth.idp.callback(...)`
51
+ - Refresh: `blocks.auth.oidc.refreshToken({ refreshToken })`
52
+ - Refresh route: `POST /iam/v4/oidc/token`
53
+ - Must send `client_id`; SDK uses `request.clientId` or configured `oidc.clientId`.
54
+ - Do not manually build `oidc/authorize`.
55
+
56
+ Embedded/app-owned flow:
57
+
58
+ - Login: `blocks.auth.login(...)`
59
+ - Social: `blocks.auth.socialInitiate(...)`, `blocks.auth.socialCallback(...)`
60
+ - Refresh: `blocks.auth.refresh({ refreshToken })`
61
+ - Routes: `/iam/v4/auth/login`, `/iam/v4/auth/social/*`, `/iam/v4/auth/refresh`
62
+
63
+ Shared auth methods for both flows:
64
+
65
+ - `userInfo()`
66
+ - `switchOrganization(...)`
67
+ - `logout(...)`, `logoutAll(...)`
68
+ - `signup(...)`, `recover(...)`, `resetPassword(...)`
69
+ - `changePassword(...)`
70
+ - `activate(...)`, `resendActivation(...)`, `validateActivation(...)`
71
+ - `identityProviders.*`, `config.*`, `userCodes.*`, `clientCredentials.*` when app has permission
72
+
73
+ ## Service Map
74
+
75
+ IAM:
76
+
77
+ - `blocks.iam.me()`
78
+ - `blocks.iam.users.*`
79
+ - `blocks.iam.roles.*`
80
+ - `blocks.iam.permissions.*`
81
+ - `blocks.iam.resources.*`
82
+ - `blocks.iam.organizations.*`
83
+ - `blocks.iam.signup.*`
84
+
85
+ Data:
86
+
87
+ - `blocks.data.schemas.*` for schema reads only
88
+ - `blocks.data.validations.*` for validation reads
89
+ - `blocks.data.collection("Name").list/get/create/update/delete`
90
+ - `blocks.data.graphql(...)`
91
+ - `blocks.data.files.*` for file/storage helpers
92
+ - `blocks.data.dms.*` for DMS file/folder helpers
93
+ - `blocks.data.utilities.*` for runtime utility helpers
94
+
95
+ Localization:
96
+
97
+ - `blocks.localization.languages()`
98
+ - `blocks.localization.modules()`
99
+ - `blocks.localization.languagesForCurrentTenant()`
100
+ - `blocks.localization.modulesForCurrentTenant()`
101
+ - `blocks.localization.translations(moduleName, language)`
102
+ - `blocks.localization.load(language, modules)`
103
+ - `blocks.localization.cloudTranslations(moduleName, language)`
104
+ - `blocks.localization.loadCloud(language, modules)`
105
+ - `blocks.localization.keysByNames(...)`
106
+ - `blocks.localization.t(key, fallback, options)`
107
+
108
+ HTTP fallback:
109
+
110
+ - Use `blocks.http.request("/service/v4/...")` only when no typed method exists.
111
+ - Use `blocks.http.external(url, ...)` only for external URLs such as pre-signed uploads.
112
+
113
+ ## Minimal Examples
114
+
115
+ ```ts
116
+ const me = await blocks.iam.me();
117
+ const schemas = await blocks.data.schemas.list({ pageNo: 1, pageSize: 20 });
118
+ const rows = await blocks.data.collection("Students").list({ pageNo: 1, pageSize: 20 });
119
+ await blocks.localization.load("en-US", ["common"]);
120
+ const label = blocks.localization.t("save", "Save");
121
+ ```
122
+
123
+ OIDC refresh with explicit client id:
124
+
125
+ ```ts
126
+ await blocks.auth.oidc.refreshToken({
127
+ clientId: env.OIDC_CLIENT_ID,
128
+ refreshToken: session.refreshToken
129
+ });
130
+ ```
131
+
132
+ Embedded refresh:
133
+
134
+ ```ts
135
+ await blocks.auth.refresh({
136
+ refreshToken: session.refreshToken
137
+ });
138
+ ```
139
+
140
+ ## Check Before Finishing
141
+
142
+ ```bash
143
+ npm test
144
+ npm run lint
145
+ npm pack --dry-run
146
+ rg -n "v4[/\\]api|iam[/\\]v4[/\\]api|data[/\\]v4[/\\]api|localization[/\\]v4[/\\]api" src README.md AI_USAGE_GUIDE.md test
147
+ ```
148
+
149
+ Only negative route-guard tests should match.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) SELISE Blocks
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) SELISE Blocks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,161 +1,161 @@
1
- # Blocks Client
2
-
3
- Framework-neutral TypeScript SDK for SELISE Blocks frontend and app-runtime code.
4
-
5
- `@seliseblocks/client` gives consumer apps a small, typed wrapper around the Blocks APIs they normally call at runtime: Auth/IAM, Data, Localization, and shared HTTP configuration. Detailed `what / why / how` descriptions are kept on the SDK functions themselves so editors and generated typings show the guidance where developers use the API.
6
-
7
- Admin/control-plane work belongs in `@seliseblocks/cli-os`: project setup, schema/rules deploy, release deploy, and AI/admin terminal workflows.
8
-
9
- For AI agents and automation, see [AI_USAGE_GUIDE.md](AI_USAGE_GUIDE.md).
10
-
11
- ## Install
12
-
13
- ```bash
14
- npm install @seliseblocks/client
15
- ```
16
-
17
- Requires Node.js 20+ or a browser/runtime with `fetch`.
18
-
19
- ## Create A Client
20
-
21
- ```ts
22
- import { createBlocksClient } from "@seliseblocks/client";
23
-
24
- const blocks = createBlocksClient({
25
- apiUrl: "https://api.seliseblocks.com",
26
- xBlocksKey: "<blocks-key>",
27
- accessToken: () => currentUserSession?.accessToken,
28
- oidc: {
29
- url: "https://iam.seliseblocks.com",
30
- clientId: "<public-browser-client-id>",
31
- redirectUri: configuredRedirectUri ?? `${window.location.origin}/login/callback`
32
- }
33
- });
34
- ```
35
-
36
- `xBlocksKey` is always sent as the `x-blocks-key` header. Do not send `ProjectKey` or `projectKey` in request query/body payloads.
37
-
38
- The SDK does not store tokens. Your app owns login state, refresh scheduling, storage, and logout cleanup.
39
-
40
- Use a configured OIDC redirect URI when your app has one. The current-origin `/login/callback` URL is only a browser fallback.
41
-
42
- ## Auth
43
-
44
- Auth has two login flows.
45
-
46
- OIDC/hosted IAM login uses `auth.idp`. The SDK relies on Blocks IAM `IdpController`, sends the configured public `clientId`, and does not manually build `oidc/authorize` URLs. Refresh OIDC sessions with `auth.oidc.refreshToken()`, which calls `/iam/v4/oidc/token` and sends `client_id`.
47
-
48
- ```ts
49
- await blocks.auth.idp.redirectToProvider();
50
-
51
- const result = await blocks.auth.idp.callback(window.location.href);
52
-
53
- const refreshed = await blocks.auth.oidc.refreshToken({
54
- refreshToken: result.refresh_token,
55
- clientId: "<public-browser-client-id>"
56
- });
57
- ```
58
-
59
- Embedded/app-owned login UI uses AuthController methods directly on `auth`: `auth.login()`, `auth.socialInitiate()`, `auth.socialCallback()`, and `auth.refresh()`.
60
-
61
- ```ts
62
- const login = await blocks.auth.login({
63
- username: "user@example.com",
64
- password: "password"
65
- });
66
-
67
- const refreshed = await blocks.auth.refresh({
68
- refreshToken: login.refresh_token
69
- });
70
- ```
71
-
72
- Other auth APIs, such as user info, organization switch, logout, signup, recovery, activation, auth config, user codes, client credentials, and identity providers, can be used by either flow when the app has the required token/permission.
73
-
74
- `auth.oidc.clientCredentials()` is for trusted non-browser runtimes only because it requires a client secret.
75
-
76
- ## Common Runtime Calls
77
-
78
- ```ts
79
- const me = await blocks.iam.me();
80
- const orgs = await blocks.iam.organizations.my();
81
- const features = await blocks.iam.resources.features();
82
- ```
83
-
84
- ```ts
85
- const schemas = await blocks.data.schemas.list();
86
- const schemaInfo = await blocks.data.schemas.infoByName("Student");
87
- const schemaRules = await blocks.data.validations.bySchemaId("schema-id");
88
-
89
- const students = blocks.data.collection("Students");
90
- const rows = await students.list({ pageNo: 1, pageSize: 20 });
91
- await students.create({ firstName: "Test" });
92
-
93
- const graph = await blocks.data.graphql({
94
- query: "{ students { items { itemId firstName } } }"
95
- });
96
- ```
97
-
98
- ```ts
99
- const upload = await blocks.data.files.presignedUploadUrl({
100
- name: "avatar.png",
101
- configurationName: "default",
102
- parentDirectoryId: "root",
103
- accessModifier: "Private"
104
- });
105
-
106
- await blocks.data.files.uploadToUrl({
107
- url: upload.uploadUrl,
108
- body: file,
109
- contentType: file.type
110
- });
111
-
112
- const items = await blocks.data.dms.list({
113
- configurationName: "default",
114
- parentId: "root",
115
- skip: 0,
116
- take: 20
117
- });
118
- ```
119
-
120
- ```ts
121
- await blocks.localization.load("en-US", ["common", "dashboard"]);
122
- const label = blocks.localization.t("dashboard.title", "Dashboard");
123
-
124
- const tenantLanguages = await blocks.localization.languagesForCurrentTenant();
125
- const selectedKeys = await blocks.localization.keysByNames({
126
- keyNames: ["dashboard.title"]
127
- });
128
- ```
129
-
130
- ## API Surface
131
-
132
- - `blocks.auth`: AuthController login, social login, refresh, org switch, logout, signup, recovery, activation, auth config, user codes, client credentials, identity providers.
133
- - `blocks.auth.idp`: hosted IdP initiate, browser redirect, callback, UI config.
134
- - `blocks.auth.oidc`: refresh-token and client-credentials token endpoint helpers.
135
- - `blocks.iam`: current user, users, roles, permissions, resources, organizations, signup settings.
136
- - `blocks.data`: schema reads, validation reads, GraphQL gateway execution, file/storage helpers, DMS file/folder helpers, runtime collection CRUD.
137
- - `blocks.localization`: tenant language/module discovery, UILM dictionary loading, selected key lookup, simple `t()` lookup.
138
-
139
- Professional class names are exported for advanced typing and adapters: `BlocksAuthenticationClient`, `BlocksIAMClient`, `BlocksDataClient`, and `BlocksLocalizationClient`.
140
-
141
- ## Boundaries
142
-
143
- This package must not contain:
144
-
145
- - CLI client secrets
146
- - impersonation APIs
147
- - project create/list/use
148
- - schema/rules deploy
149
- - release deploy
150
- - token/session/PKCE storage
151
- - Node filesystem or OS credential storage
152
- - framework UI components
153
- - Localization authoring/admin endpoints
154
- - Data schema/rules mutation endpoints
155
-
156
- ## Package Checks
157
-
158
- ```bash
159
- npm test
160
- npm pack --dry-run
161
- ```
1
+ # Blocks Client
2
+
3
+ Framework-neutral TypeScript SDK for SELISE Blocks frontend and app-runtime code.
4
+
5
+ `@seliseblocks/client` gives consumer apps a small, typed wrapper around the Blocks APIs they normally call at runtime: Auth/IAM, Data, Localization, and shared HTTP configuration. Detailed `what / why / how` descriptions are kept on the SDK functions themselves so editors and generated typings show the guidance where developers use the API.
6
+
7
+ Admin/control-plane work belongs in `@seliseblocks/cli-os`: project setup, schema/rules deploy, release deploy, and AI/admin terminal workflows.
8
+
9
+ For AI agents and automation, see [AI_USAGE_GUIDE.md](AI_USAGE_GUIDE.md).
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @seliseblocks/client
15
+ ```
16
+
17
+ Requires Node.js 20+ or a browser/runtime with `fetch`.
18
+
19
+ ## Create A Client
20
+
21
+ ```ts
22
+ import { createBlocksClient } from "@seliseblocks/client";
23
+
24
+ const blocks = createBlocksClient({
25
+ apiUrl: "https://api.seliseblocks.com",
26
+ xBlocksKey: "<blocks-key>",
27
+ accessToken: () => currentUserSession?.accessToken,
28
+ oidc: {
29
+ url: "https://iam.seliseblocks.com",
30
+ clientId: "<public-browser-client-id>",
31
+ redirectUri: configuredRedirectUri ?? `${window.location.origin}/login/callback`
32
+ }
33
+ });
34
+ ```
35
+
36
+ `xBlocksKey` is always sent as the `x-blocks-key` header. Do not send `ProjectKey` or `projectKey` in request query/body payloads.
37
+
38
+ The SDK does not store tokens. Your app owns login state, refresh scheduling, storage, and logout cleanup.
39
+
40
+ Use a configured OIDC redirect URI when your app has one. The current-origin `/login/callback` URL is only a browser fallback.
41
+
42
+ ## Auth
43
+
44
+ Auth has two login flows.
45
+
46
+ OIDC/hosted IAM login uses `auth.idp`. The SDK relies on Blocks IAM `IdpController`, sends the configured public `clientId`, and does not manually build `oidc/authorize` URLs. Refresh OIDC sessions with `auth.oidc.refreshToken()`, which calls `/iam/v4/oidc/token` and sends `client_id`.
47
+
48
+ ```ts
49
+ await blocks.auth.idp.redirectToProvider();
50
+
51
+ const result = await blocks.auth.idp.callback(window.location.href);
52
+
53
+ const refreshed = await blocks.auth.oidc.refreshToken({
54
+ refreshToken: result.refresh_token,
55
+ clientId: "<public-browser-client-id>"
56
+ });
57
+ ```
58
+
59
+ Embedded/app-owned login UI uses AuthController methods directly on `auth`: `auth.login()`, `auth.socialInitiate()`, `auth.socialCallback()`, and `auth.refresh()`.
60
+
61
+ ```ts
62
+ const login = await blocks.auth.login({
63
+ username: "user@example.com",
64
+ password: "password"
65
+ });
66
+
67
+ const refreshed = await blocks.auth.refresh({
68
+ refreshToken: login.refresh_token
69
+ });
70
+ ```
71
+
72
+ Other auth APIs, such as user info, organization switch, logout, signup, recovery, activation, auth config, user codes, client credentials, and identity providers, can be used by either flow when the app has the required token/permission.
73
+
74
+ `auth.oidc.clientCredentials()` is for trusted non-browser runtimes only because it requires a client secret.
75
+
76
+ ## Common Runtime Calls
77
+
78
+ ```ts
79
+ const me = await blocks.iam.me();
80
+ const orgs = await blocks.iam.organizations.my();
81
+ const features = await blocks.iam.resources.features();
82
+ ```
83
+
84
+ ```ts
85
+ const schemas = await blocks.data.schemas.list();
86
+ const schemaInfo = await blocks.data.schemas.infoByName("Student");
87
+ const schemaRules = await blocks.data.validations.bySchemaId("schema-id");
88
+
89
+ const students = blocks.data.collection("Students");
90
+ const rows = await students.list({ pageNo: 1, pageSize: 20 });
91
+ await students.create({ firstName: "Test" });
92
+
93
+ const graph = await blocks.data.graphql({
94
+ query: "{ students { items { itemId firstName } } }"
95
+ });
96
+ ```
97
+
98
+ ```ts
99
+ const upload = await blocks.data.files.presignedUploadUrl({
100
+ name: "avatar.png",
101
+ configurationName: "default",
102
+ parentDirectoryId: "root",
103
+ accessModifier: "Private"
104
+ });
105
+
106
+ await blocks.data.files.uploadToUrl({
107
+ url: upload.uploadUrl,
108
+ body: file,
109
+ contentType: file.type
110
+ });
111
+
112
+ const items = await blocks.data.dms.list({
113
+ configurationName: "default",
114
+ parentId: "root",
115
+ skip: 0,
116
+ take: 20
117
+ });
118
+ ```
119
+
120
+ ```ts
121
+ await blocks.localization.load("en-US", ["common", "dashboard"]);
122
+ const label = blocks.localization.t("dashboard.title", "Dashboard");
123
+
124
+ const tenantLanguages = await blocks.localization.languagesForCurrentTenant();
125
+ const selectedKeys = await blocks.localization.keysByNames({
126
+ keyNames: ["dashboard.title"]
127
+ });
128
+ ```
129
+
130
+ ## API Surface
131
+
132
+ - `blocks.auth`: AuthController login, social login, refresh, org switch, logout, signup, recovery, activation, auth config, user codes, client credentials, identity providers.
133
+ - `blocks.auth.idp`: hosted IdP initiate, browser redirect, callback, UI config.
134
+ - `blocks.auth.oidc`: refresh-token and client-credentials token endpoint helpers.
135
+ - `blocks.iam`: current user, users, roles, permissions, resources, organizations, signup settings.
136
+ - `blocks.data`: schema reads, validation reads, GraphQL gateway execution, file/storage helpers, DMS file/folder helpers, runtime collection CRUD.
137
+ - `blocks.localization`: tenant language/module discovery, UILM dictionary loading, selected key lookup, simple `t()` lookup.
138
+
139
+ Professional class names are exported for advanced typing and adapters: `BlocksAuthenticationClient`, `BlocksIAMClient`, `BlocksDataClient`, and `BlocksLocalizationClient`.
140
+
141
+ ## Boundaries
142
+
143
+ This package must not contain:
144
+
145
+ - CLI client secrets
146
+ - impersonation APIs
147
+ - project create/list/use
148
+ - schema/rules deploy
149
+ - release deploy
150
+ - token/session/PKCE storage
151
+ - Node filesystem or OS credential storage
152
+ - framework UI components
153
+ - Localization authoring/admin endpoints
154
+ - Data schema/rules mutation endpoints
155
+
156
+ ## Package Checks
157
+
158
+ ```bash
159
+ npm test
160
+ npm pack --dry-run
161
+ ```
package/dist/client.d.ts CHANGED
@@ -3,6 +3,7 @@ import { BlocksDataClient } from "./data/data-client.js";
3
3
  import { BlocksHttpClient } from "./http/http-client.js";
4
4
  import { BlocksIAMClient } from "./iam/iam-client.js";
5
5
  import { BlocksLocalizationClient } from "./localization/localization-client.js";
6
+ import { BlocksMfaClient } from "./mfa/mfa-client.js";
6
7
  export type BlocksOidcConfig = {
7
8
  /**
8
9
  * Public browser OIDC client id used by Blocks IAM IdpController and refresh-token calls.
@@ -55,6 +56,7 @@ export type BlocksClient = {
55
56
  http: BlocksHttpClient;
56
57
  iam: BlocksIAMClient;
57
58
  localization: BlocksLocalizationClient;
59
+ mfa: BlocksMfaClient;
58
60
  };
59
61
  export type RequiredConfig = {
60
62
  accessToken?: string | (() => Promise<string | undefined> | string | undefined);
package/dist/client.js CHANGED
@@ -3,6 +3,7 @@ import { BlocksDataClient } from "./data/data-client.js";
3
3
  import { BlocksHttpClient } from "./http/http-client.js";
4
4
  import { BlocksIAMClient } from "./iam/iam-client.js";
5
5
  import { BlocksLocalizationClient } from "./localization/localization-client.js";
6
+ import { BlocksMfaClient } from "./mfa/mfa-client.js";
6
7
  /**
7
8
  * What: creates a framework-neutral Blocks SDK instance for one tenant/app runtime.
8
9
  * Why: frontend code needs a single configured entry point for IAM, Auth, Data, and Localization APIs.
@@ -18,7 +19,8 @@ export function createBlocksClient(config) {
18
19
  data: new BlocksDataClient(http),
19
20
  http,
20
21
  iam: new BlocksIAMClient(http),
21
- localization: new BlocksLocalizationClient(http)
22
+ localization: new BlocksLocalizationClient(http),
23
+ mfa: new BlocksMfaClient(http)
22
24
  };
23
25
  }
24
26
  function normalizeConfig(config) {
@@ -85,7 +85,7 @@ export declare class BlocksDataClient {
85
85
  */
86
86
  delete: (request: BlocksFileDeleteRequest) => Promise<unknown>;
87
87
  /**
88
- * What: updates file additional properties through `POST /data/v4/Files/updateFileAdditionalInfo`.
88
+ * What: updates file additional properties through `POST /data/v4/Files/UpdateFileAdditionalInfo`.
89
89
  * Why: apps often need to attach searchable metadata such as agent status or business references to a file.
90
90
  * How: pass `itemId` and `additionalProperties`; the SDK forwards the request as-is except for not adding project fields.
91
91
  */
@@ -124,11 +124,11 @@ export class BlocksDataClient {
124
124
  body: withoutProjectKey(request)
125
125
  }),
126
126
  /**
127
- * What: updates file additional properties through `POST /data/v4/Files/updateFileAdditionalInfo`.
127
+ * What: updates file additional properties through `POST /data/v4/Files/UpdateFileAdditionalInfo`.
128
128
  * Why: apps often need to attach searchable metadata such as agent status or business references to a file.
129
129
  * How: pass `itemId` and `additionalProperties`; the SDK forwards the request as-is except for not adding project fields.
130
130
  */
131
- updateAdditionalInfo: (request) => this.http.request(`${DATA_API}/Files/updateFileAdditionalInfo`, {
131
+ updateAdditionalInfo: (request) => this.http.request(`${DATA_API}/Files/UpdateFileAdditionalInfo`, {
132
132
  body: withoutProjectKey(request)
133
133
  }),
134
134
  /**
@@ -258,13 +258,13 @@ export class BlocksDataClient {
258
258
  */
259
259
  create: (payload) => this.graphql({
260
260
  operationName: createField,
261
- query: `mutation ${createField}($input: ${schemaName}InsertInput!) {
262
- ${createField}(input: $input) {
263
- acknowledged
264
- itemId
265
- message
266
- totalImpactedData
267
- }
261
+ query: `mutation ${createField}($input: ${schemaName}InsertInput!) {
262
+ ${createField}(input: $input) {
263
+ acknowledged
264
+ itemId
265
+ message
266
+ totalImpactedData
267
+ }
268
268
  }`,
269
269
  variables: { input: payload }
270
270
  }),
@@ -275,13 +275,13 @@ export class BlocksDataClient {
275
275
  */
276
276
  delete: (itemId, deleteOptions = {}) => this.graphql({
277
277
  operationName: deleteField,
278
- query: `mutation ${deleteField}($filter: String, $input: ${schemaName}DeleteInput!) {
279
- ${deleteField}(filter: $filter, input: $input) {
280
- acknowledged
281
- itemId
282
- message
283
- totalImpactedData
284
- }
278
+ query: `mutation ${deleteField}($filter: String, $input: ${schemaName}DeleteInput!) {
279
+ ${deleteField}(filter: $filter, input: $input) {
280
+ acknowledged
281
+ itemId
282
+ message
283
+ totalImpactedData
284
+ }
285
285
  }`,
286
286
  variables: {
287
287
  filter: itemIdFilter(itemId),
@@ -323,13 +323,13 @@ export class BlocksDataClient {
323
323
  */
324
324
  update: (itemId, payload) => this.graphql({
325
325
  operationName: updateField,
326
- query: `mutation ${updateField}($filter: String, $input: ${schemaName}UpdateInput!) {
327
- ${updateField}(filter: $filter, input: $input) {
328
- acknowledged
329
- itemId
330
- message
331
- totalImpactedData
332
- }
326
+ query: `mutation ${updateField}($filter: String, $input: ${schemaName}UpdateInput!) {
327
+ ${updateField}(filter: $filter, input: $input) {
328
+ acknowledged
329
+ itemId
330
+ message
331
+ totalImpactedData
332
+ }
333
333
  }`,
334
334
  variables: {
335
335
  filter: itemIdFilter(itemId),
@@ -441,18 +441,18 @@ function dynamicQueryInput(options) {
441
441
  };
442
442
  }
443
443
  function collectionListQuery(fieldName, selection) {
444
- return `query ${fieldName}($input: DynamicQueryInput) {
445
- ${fieldName}(input: $input) {
446
- items {
447
- ${indent(selection, 6)}
448
- }
449
- totalCount
450
- pageNo
451
- pageSize
452
- totalPages
453
- hasNextPage
454
- hasPreviousPage
455
- }
444
+ return `query ${fieldName}($input: DynamicQueryInput) {
445
+ ${fieldName}(input: $input) {
446
+ items {
447
+ ${indent(selection, 6)}
448
+ }
449
+ totalCount
450
+ pageNo
451
+ pageSize
452
+ totalPages
453
+ hasNextPage
454
+ hasPreviousPage
455
+ }
456
456
  }`;
457
457
  }
458
458
  function selectionFor(fields) {
package/dist/index.d.ts CHANGED
@@ -5,8 +5,10 @@ export type { BlocksClient, BlocksClientConfig, BlocksOidcConfig } from "./clien
5
5
  export { BlocksApiError } from "./http/errors.js";
6
6
  export { BlocksIAMClient } from "./iam/iam-client.js";
7
7
  export { BlocksLocalizationClient } from "./localization/localization-client.js";
8
+ export { BlocksMfaClient } from "./mfa/mfa-client.js";
8
9
  export type { BlocksAuthPassThroughResponse, BlocksAuthResponse, BlocksClientCredentialsRequest, BlocksAuthLoginRequest, BlocksIdpCallbackRequest, BlocksIdpInitiateRequest, BlocksIdpInitiateResponse, BlocksLoginOption, BlocksLogoutRequest, BlocksOidcRefreshRequest, BlocksOidcUserInfo, BlocksRefreshRequest, BlocksSocialLoginRequest, BlocksSwitchOrganizationRequest } from "./auth/auth-client.js";
9
10
  export type { BlocksRequestOptions } from "./types.js";
10
11
  export type { BlocksBaseResponse, BlocksGetMyOrganizationsResponse, BlocksGetOrganizationResponse, BlocksGetOrganizationsResponse, BlocksGetPermissionResponse, BlocksGetPermissionsResponse, BlocksGetRoleResponse, BlocksGetRolesResponse, BlocksGetUserResponse, BlocksGetUsersResponse, BlocksIamListRequest, BlocksMeResponse, BlocksOrganization, BlocksPermission, BlocksQueryListResponse, BlocksQueryResponse, BlocksRole, BlocksUser } from "./iam/types.js";
11
12
  export type { BlocksDataCollection, BlocksDataListOptions, BlocksDmsCreateFolderRequest, BlocksDmsListRequest, BlocksDmsMetaDataValue, BlocksDmsUploadItem, BlocksDmsUploadRequest, BlocksFileDeleteRequest, BlocksFileGetOptions, BlocksFileInfoListRequest, BlocksFileListRequest, BlocksFileUpdateAdditionalInfoRequest, BlocksFileUploadRequest, BlocksFolderDeleteRequest, BlocksGraphqlRequest, BlocksLocalStorageUploadRequest, BlocksPagedResult, BlocksRegexGenerateRequest, BlocksSchemaFieldValidationOptions, BlocksSchemaListOptions, BlocksSchemaValidationListOptions, BlocksUploadToUrlRequest } from "./data/types.js";
12
- export type { BlocksLocalizationDictionary, BlocksLocalizationKey, BlocksLocalizationKeysByNamesRequest, BlocksLocalizationKeysByNamesResponse, BlocksLocalizationLanguage, BlocksLocalizationModule, BlocksLocalizationTranslationOptions } from "./localization/types.js";
13
+ export type { BlocksLocalizationDictionary, BlocksLocalizationKey, BlocksLocalizationKeyResource, BlocksLocalizationKeysByNamesRequest, BlocksLocalizationKeysByNamesResponse, BlocksLocalizationLanguage, BlocksLocalizationModule, BlocksLocalizationTranslationOptions } from "./localization/types.js";
14
+ export type { BlocksMfaBackupCodeUseRequest, BlocksMfaConfig, BlocksMfaGenerateRequest, BlocksMfaPassThroughResponse, BlocksMfaResendRequest, BlocksMfaSetMethodRequest, BlocksMfaVerifyRequest, BlocksMfaVerifyTotpSetupRequest } from "./mfa/types.js";
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { BlocksDataClient } from "./data/data-client.js";
4
4
  export { BlocksApiError } from "./http/errors.js";
5
5
  export { BlocksIAMClient } from "./iam/iam-client.js";
6
6
  export { BlocksLocalizationClient } from "./localization/localization-client.js";
7
+ export { BlocksMfaClient } from "./mfa/mfa-client.js";
@@ -18,12 +18,20 @@ export type BlocksLocalizationTranslationOptions = {
18
18
  language: string;
19
19
  moduleName: string;
20
20
  };
21
+ export type BlocksLocalizationKeyResource = {
22
+ characterLength?: number;
23
+ culture?: string;
24
+ value?: string;
25
+ };
21
26
  export type BlocksLocalizationKey = Record<string, unknown> & {
27
+ context?: string;
28
+ isNewKey?: boolean;
29
+ isPartiallyTranslated?: boolean;
22
30
  itemId?: string;
23
31
  keyName?: string;
24
32
  moduleId?: string;
25
- moduleName?: string;
26
- values?: Record<string, unknown>;
33
+ resources?: BlocksLocalizationKeyResource[];
34
+ routes?: string[];
27
35
  };
28
36
  export type BlocksLocalizationKeysByNamesRequest = {
29
37
  keyNames: string[];
@@ -0,0 +1,82 @@
1
+ import { BlocksHttpClient } from "../http/http-client.js";
2
+ import { BlocksMfaBackupCodeUseRequest, BlocksMfaConfig, BlocksMfaGenerateRequest, BlocksMfaPassThroughResponse, BlocksMfaResendRequest, BlocksMfaSetMethodRequest, BlocksMfaVerifyRequest, BlocksMfaVerifyTotpSetupRequest } from "./types.js";
3
+ /**
4
+ * Consumer-facing MFA surface: enroll, verify, switch, or disable the signed-in user's own MFA,
5
+ * and manage their own backup codes. Tenant-wide MFA policy (`POST /iam/v4/mfa/config`) is
6
+ * deliberately not exposed here -- that's an admin/tenant-settings action, not a user self-service
7
+ * flow, the same distinction the SDK already draws for `identityProviders` admin methods.
8
+ */
9
+ export declare class BlocksMfaClient {
10
+ private readonly http;
11
+ constructor(http: BlocksHttpClient);
12
+ /**
13
+ * What: reads the tenant's current MFA policy through `GET /iam/v4/mfa/config`.
14
+ * Why: consumer apps can check whether MFA is enabled/required before prompting enrollment.
15
+ * How: call with an authorized token; the SDK returns IAM's policy shape as-is.
16
+ */
17
+ config(): Promise<BlocksMfaConfig>;
18
+ readonly totp: {
19
+ /**
20
+ * What: starts TOTP enrollment through `POST /iam/v4/mfa/totp/setup`.
21
+ * Why: authenticator-app enrollment needs a secret/QR payload from IAM before the user can scan it.
22
+ * How: call for the signed-in user, then render IAM's returned secret/QR data in your enrollment UI.
23
+ */
24
+ setup: () => Promise<BlocksMfaPassThroughResponse>;
25
+ /**
26
+ * What: confirms TOTP enrollment through `POST /iam/v4/mfa/totp/verify-setup`.
27
+ * Why: IAM must confirm the user's authenticator app is correctly configured before enabling TOTP.
28
+ * How: pass the 6-digit `code` the user typed from their authenticator app.
29
+ */
30
+ verifySetup: (request: BlocksMfaVerifyTotpSetupRequest) => Promise<BlocksMfaPassThroughResponse>;
31
+ };
32
+ /**
33
+ * What: sends an OTP challenge through `POST /iam/v4/mfa/generate`.
34
+ * Why: email/SMS-based MFA needs IAM to issue and deliver a one-time code before verification.
35
+ * How: pass the target `mfaType`; IAM returns an `mfaId` to pass to `verify`/`resend`.
36
+ */
37
+ generate(request: BlocksMfaGenerateRequest): Promise<BlocksMfaPassThroughResponse>;
38
+ /**
39
+ * What: resends a pending OTP through `POST /iam/v4/mfa/resend`.
40
+ * Why: users may not receive the first code (SMS delay, spam filtering) and need a retry.
41
+ * How: pass the `mfaId` returned from `generate`.
42
+ */
43
+ resend(request: BlocksMfaResendRequest): Promise<BlocksMfaPassThroughResponse>;
44
+ /**
45
+ * What: verifies an OTP or step-up challenge through `POST /iam/v4/mfa/verify`.
46
+ * Why: login and sensitive in-app actions need this to confirm the code the user entered.
47
+ * How: pass `mfaId`, `verificationCode`, and `authType`; set `isFromTokenCall` when verifying as part of a token/login exchange rather than a standalone check.
48
+ */
49
+ verify(request: BlocksMfaVerifyRequest): Promise<BlocksMfaPassThroughResponse>;
50
+ /**
51
+ * What: sets the signed-in user's active MFA method through `PUT /iam/v4/mfa/method`.
52
+ * Why: users who have enrolled more than one method need to switch which one is active.
53
+ * How: pass the `mfaType` to activate; enroll it first (e.g. via `totp.setup`/`verifySetup`) if it isn't already.
54
+ */
55
+ setMethod(request: BlocksMfaSetMethodRequest): Promise<BlocksMfaPassThroughResponse>;
56
+ /**
57
+ * What: disables MFA for the signed-in user through `POST /iam/v4/mfa/disable`.
58
+ * Why: users need a self-service way to turn MFA off when the tenant's policy allows opt-out.
59
+ * How: call with an authorized token; IAM enforces whether opt-out is permitted for this tenant/role.
60
+ */
61
+ disable(): Promise<BlocksMfaPassThroughResponse>;
62
+ readonly backupCodes: {
63
+ /**
64
+ * What: lists the signed-in user's backup codes through `GET /iam/v4/mfa/backup-codes`.
65
+ * Why: account-security screens need to show how many unused recovery codes remain.
66
+ * How: call with an authorized token.
67
+ */
68
+ list: () => Promise<BlocksMfaPassThroughResponse>;
69
+ /**
70
+ * What: generates a fresh set of backup codes through `POST /iam/v4/mfa/backup-codes/generate`.
71
+ * Why: users need recovery codes for when their primary MFA method is unavailable.
72
+ * How: call once TOTP/OTP is enrolled; treat the response as sensitive and show it to the user only once.
73
+ */
74
+ generate: () => Promise<BlocksMfaPassThroughResponse>;
75
+ /**
76
+ * What: consumes one backup code through `POST /iam/v4/mfa/backup-codes/use`.
77
+ * Why: lets a user complete login/step-up when their primary MFA method is unavailable.
78
+ * How: pass the signed-in `userId` and the backup `code` the user entered; each code is single-use.
79
+ */
80
+ use: (request: BlocksMfaBackupCodeUseRequest) => Promise<BlocksMfaPassThroughResponse>;
81
+ };
82
+ }
@@ -0,0 +1,98 @@
1
+ const MFA_API = "/iam/v4/mfa";
2
+ /**
3
+ * Consumer-facing MFA surface: enroll, verify, switch, or disable the signed-in user's own MFA,
4
+ * and manage their own backup codes. Tenant-wide MFA policy (`POST /iam/v4/mfa/config`) is
5
+ * deliberately not exposed here -- that's an admin/tenant-settings action, not a user self-service
6
+ * flow, the same distinction the SDK already draws for `identityProviders` admin methods.
7
+ */
8
+ export class BlocksMfaClient {
9
+ http;
10
+ constructor(http) {
11
+ this.http = http;
12
+ }
13
+ /**
14
+ * What: reads the tenant's current MFA policy through `GET /iam/v4/mfa/config`.
15
+ * Why: consumer apps can check whether MFA is enabled/required before prompting enrollment.
16
+ * How: call with an authorized token; the SDK returns IAM's policy shape as-is.
17
+ */
18
+ config() {
19
+ return this.http.request(`${MFA_API}/config`);
20
+ }
21
+ totp = {
22
+ /**
23
+ * What: starts TOTP enrollment through `POST /iam/v4/mfa/totp/setup`.
24
+ * Why: authenticator-app enrollment needs a secret/QR payload from IAM before the user can scan it.
25
+ * How: call for the signed-in user, then render IAM's returned secret/QR data in your enrollment UI.
26
+ */
27
+ setup: () => this.http.request(`${MFA_API}/totp/setup`, { method: "POST" }),
28
+ /**
29
+ * What: confirms TOTP enrollment through `POST /iam/v4/mfa/totp/verify-setup`.
30
+ * Why: IAM must confirm the user's authenticator app is correctly configured before enabling TOTP.
31
+ * How: pass the 6-digit `code` the user typed from their authenticator app.
32
+ */
33
+ verifySetup: (request) => this.http.request(`${MFA_API}/totp/verify-setup`, { body: request })
34
+ };
35
+ /**
36
+ * What: sends an OTP challenge through `POST /iam/v4/mfa/generate`.
37
+ * Why: email/SMS-based MFA needs IAM to issue and deliver a one-time code before verification.
38
+ * How: pass the target `mfaType`; IAM returns an `mfaId` to pass to `verify`/`resend`.
39
+ */
40
+ generate(request) {
41
+ return this.http.request(`${MFA_API}/generate`, { body: request });
42
+ }
43
+ /**
44
+ * What: resends a pending OTP through `POST /iam/v4/mfa/resend`.
45
+ * Why: users may not receive the first code (SMS delay, spam filtering) and need a retry.
46
+ * How: pass the `mfaId` returned from `generate`.
47
+ */
48
+ resend(request) {
49
+ return this.http.request(`${MFA_API}/resend`, { body: request });
50
+ }
51
+ /**
52
+ * What: verifies an OTP or step-up challenge through `POST /iam/v4/mfa/verify`.
53
+ * Why: login and sensitive in-app actions need this to confirm the code the user entered.
54
+ * How: pass `mfaId`, `verificationCode`, and `authType`; set `isFromTokenCall` when verifying as part of a token/login exchange rather than a standalone check.
55
+ */
56
+ verify(request) {
57
+ return this.http.request(`${MFA_API}/verify`, { body: request });
58
+ }
59
+ /**
60
+ * What: sets the signed-in user's active MFA method through `PUT /iam/v4/mfa/method`.
61
+ * Why: users who have enrolled more than one method need to switch which one is active.
62
+ * How: pass the `mfaType` to activate; enroll it first (e.g. via `totp.setup`/`verifySetup`) if it isn't already.
63
+ */
64
+ setMethod(request) {
65
+ return this.http.request(`${MFA_API}/method`, {
66
+ body: request,
67
+ method: "PUT"
68
+ });
69
+ }
70
+ /**
71
+ * What: disables MFA for the signed-in user through `POST /iam/v4/mfa/disable`.
72
+ * Why: users need a self-service way to turn MFA off when the tenant's policy allows opt-out.
73
+ * How: call with an authorized token; IAM enforces whether opt-out is permitted for this tenant/role.
74
+ */
75
+ disable() {
76
+ return this.http.request(`${MFA_API}/disable`, { method: "POST" });
77
+ }
78
+ backupCodes = {
79
+ /**
80
+ * What: lists the signed-in user's backup codes through `GET /iam/v4/mfa/backup-codes`.
81
+ * Why: account-security screens need to show how many unused recovery codes remain.
82
+ * How: call with an authorized token.
83
+ */
84
+ list: () => this.http.request(`${MFA_API}/backup-codes`),
85
+ /**
86
+ * What: generates a fresh set of backup codes through `POST /iam/v4/mfa/backup-codes/generate`.
87
+ * Why: users need recovery codes for when their primary MFA method is unavailable.
88
+ * How: call once TOTP/OTP is enrolled; treat the response as sensitive and show it to the user only once.
89
+ */
90
+ generate: () => this.http.request(`${MFA_API}/backup-codes/generate`, { method: "POST" }),
91
+ /**
92
+ * What: consumes one backup code through `POST /iam/v4/mfa/backup-codes/use`.
93
+ * Why: lets a user complete login/step-up when their primary MFA method is unavailable.
94
+ * How: pass the signed-in `userId` and the backup `code` the user entered; each code is single-use.
95
+ */
96
+ use: (request) => this.http.request(`${MFA_API}/backup-codes/use`, { body: request })
97
+ };
98
+ }
@@ -0,0 +1,34 @@
1
+ export type BlocksMfaConfig = Record<string, unknown> & {
2
+ allowBackupCodes?: boolean;
3
+ allowUserOptOut?: boolean;
4
+ backupCodesCount?: number;
5
+ enableMfa?: boolean;
6
+ requireMfaForAllUsers?: boolean;
7
+ userMfaType?: number[];
8
+ };
9
+ export type BlocksMfaGenerateRequest = {
10
+ /** IAM-defined numeric MFA method (its enum names aren't in the swagger contract -- treat as opaque). */
11
+ mfaType: number;
12
+ sendPhoneNumberAsEmailDomain?: string;
13
+ };
14
+ export type BlocksMfaResendRequest = {
15
+ mfaId: string;
16
+ sendPhoneNumberAsEmailDomain?: string;
17
+ };
18
+ export type BlocksMfaVerifyRequest = {
19
+ authType: number;
20
+ isFromTokenCall?: boolean;
21
+ mfaId: string;
22
+ verificationCode: string;
23
+ };
24
+ export type BlocksMfaSetMethodRequest = {
25
+ mfaType: number;
26
+ };
27
+ export type BlocksMfaVerifyTotpSetupRequest = {
28
+ code: string;
29
+ };
30
+ export type BlocksMfaBackupCodeUseRequest = {
31
+ code: string;
32
+ userId: string;
33
+ };
34
+ export type BlocksMfaPassThroughResponse = Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
- {
2
- "name": "@seliseblocks/client",
3
- "version": "0.1.1",
4
- "description": "Framework-neutral TypeScript client SDK for SELISE Blocks frontend applications.",
5
- "license": "MIT",
6
- "type": "module",
7
- "keywords": [
8
- "selise",
9
- "blocks",
10
- "sdk",
11
- "typescript",
12
- "frontend"
13
- ],
14
- "main": "./dist/index.js",
15
- "types": "./dist/index.d.ts",
16
- "exports": {
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.js"
20
- },
21
- "./package.json": "./package.json"
22
- },
23
- "publishConfig": {
24
- "access": "public"
25
- },
26
- "sideEffects": false,
27
- "files": [
28
- "dist",
29
- "README.md",
30
- "AI_USAGE_GUIDE.md",
31
- "LICENSE"
32
- ],
33
- "scripts": {
34
- "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
35
- "build": "npm run clean && tsc -p tsconfig.json",
36
- "lint": "tsc -p tsconfig.json --noEmit",
37
- "test": "npm run build && node --test test/*.test.mjs",
38
- "prepack": "npm run build",
39
- "prepublishOnly": "npm test"
40
- },
41
- "engines": {
42
- "node": ">=20"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^22.0.0",
46
- "typescript": "^5.5.0"
47
- }
48
- }
1
+ {
2
+ "name": "@seliseblocks/client",
3
+ "version": "0.1.2",
4
+ "description": "Framework-neutral TypeScript client SDK for SELISE Blocks frontend applications.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "keywords": [
8
+ "selise",
9
+ "blocks",
10
+ "sdk",
11
+ "typescript",
12
+ "frontend"
13
+ ],
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "sideEffects": false,
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "AI_USAGE_GUIDE.md",
31
+ "LICENSE"
32
+ ],
33
+ "scripts": {
34
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
35
+ "build": "npm run clean && tsc -p tsconfig.json",
36
+ "lint": "tsc -p tsconfig.json --noEmit",
37
+ "test": "npm run build && node --test test/*.test.mjs",
38
+ "prepack": "npm run build",
39
+ "prepublishOnly": "npm test"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^22.0.0",
46
+ "typescript": "^5.5.0"
47
+ }
48
+ }