@seliseblocks/client 0.1.0-beta.0
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 +149 -0
- package/LICENSE +21 -0
- package/README.md +161 -0
- package/dist/auth/auth-client.d.ts +256 -0
- package/dist/auth/auth-client.js +427 -0
- package/dist/auth/types.d.ts +77 -0
- package/dist/auth/types.js +1 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.js +49 -0
- package/dist/data/data-client.d.ts +178 -0
- package/dist/data/data-client.js +385 -0
- package/dist/data/types.d.ts +148 -0
- package/dist/data/types.js +1 -0
- package/dist/http/errors.d.ts +6 -0
- package/dist/http/errors.js +23 -0
- package/dist/http/http-client.d.ts +11 -0
- package/dist/http/http-client.js +82 -0
- package/dist/iam/iam-client.d.ts +226 -0
- package/dist/iam/iam-client.js +230 -0
- package/dist/iam/types.d.ts +56 -0
- package/dist/iam/types.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +6 -0
- package/dist/localization/localization-client.d.ts +71 -0
- package/dist/localization/localization-client.js +148 -0
- package/dist/localization/types.d.ts +35 -0
- package/dist/localization/types.js +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/package.json +48 -0
|
@@ -0,0 +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.
|
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +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
|
+
```
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { RequiredConfig } from "../client.js";
|
|
2
|
+
import type { BlocksAuthJsonOptions, BlocksAuthLoginRequest, BlocksAuthPassThroughResponse, BlocksAuthResponse, BlocksClientCredentialsRequest, BlocksIdpCallbackRequest, BlocksIdpInitiateRequest, BlocksIdpInitiateResponse, BlocksLoginOption, BlocksLogoutRequest, BlocksOidcRefreshRequest, BlocksOidcUserInfo, BlocksRefreshRequest, BlocksSocialLoginRequest, BlocksSwitchOrganizationRequest } from "./types.js";
|
|
3
|
+
export type { BlocksAuthLoginRequest, BlocksAuthPassThroughResponse, BlocksAuthResponse, BlocksClientCredentialsRequest, BlocksIdpCallbackRequest, BlocksIdpInitiateRequest, BlocksIdpInitiateResponse, BlocksLoginOption, BlocksLogoutRequest, BlocksOidcRefreshRequest, BlocksOidcUserInfo, BlocksRefreshRequest, BlocksSocialLoginRequest, BlocksSwitchOrganizationRequest } from "./types.js";
|
|
4
|
+
export declare class BlocksAuthenticationClient {
|
|
5
|
+
private readonly clientConfig;
|
|
6
|
+
private readonly fetchImpl;
|
|
7
|
+
constructor(clientConfig: RequiredConfig, fetchImpl?: typeof fetch);
|
|
8
|
+
/**
|
|
9
|
+
* What: discovers tenant login options through `GET /iam/v4/auth/login-options`.
|
|
10
|
+
* Why: login screens need to know which login methods the tenant supports before rendering controls.
|
|
11
|
+
* How: call it before showing your login UI; it is public and still sends `x-blocks-key`.
|
|
12
|
+
*/
|
|
13
|
+
loginOptions(): Promise<BlocksLoginOption[]>;
|
|
14
|
+
/**
|
|
15
|
+
* What: executes username/password login through `POST /iam/v4/auth/login`.
|
|
16
|
+
* Why: apps that own their login UI need a direct AuthController login call.
|
|
17
|
+
* How: pass IAM's expected login payload; the SDK returns IAM's response as-is and does not store tokens.
|
|
18
|
+
*/
|
|
19
|
+
login(request: BlocksAuthLoginRequest): Promise<BlocksAuthResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* What: starts social login through `GET /iam/v4/auth/social/initiate`.
|
|
22
|
+
* Why: custom login screens may offer social providers while keeping the app in charge of UI.
|
|
23
|
+
* How: provide the public browser client id and redirect URI, then follow IAM's returned social-login response.
|
|
24
|
+
*/
|
|
25
|
+
socialInitiate(clientId: string, redirectUri: string): Promise<Record<string, unknown>>;
|
|
26
|
+
/**
|
|
27
|
+
* What: completes social login through `POST /iam/v4/auth/social/callback`.
|
|
28
|
+
* Why: the app receives the provider callback but IAM owns the token/session response contract.
|
|
29
|
+
* How: pass the callback payload your app received; store returned tokens in your app layer if IAM returns tokens.
|
|
30
|
+
*/
|
|
31
|
+
socialCallback(request: BlocksSocialLoginRequest): Promise<BlocksAuthResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* What: refreshes an AuthController token through `POST /iam/v4/auth/refresh`.
|
|
34
|
+
* Why: direct AuthController sessions refresh through AuthController instead of the OIDC token endpoint.
|
|
35
|
+
* How: pass the refresh payload your app owns; the SDK does not read or write token storage.
|
|
36
|
+
*/
|
|
37
|
+
refresh(request?: BlocksRefreshRequest): Promise<BlocksAuthResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* What: switches the active organization through `POST /iam/v4/auth/switch-org`.
|
|
40
|
+
* Why: multi-organization users need a new IAM response for the selected organization context.
|
|
41
|
+
* How: pass `organizationId` plus the refresh/session fields IAM expects; then replace app-owned session state with the response if needed.
|
|
42
|
+
*/
|
|
43
|
+
switchOrganization(request: BlocksSwitchOrganizationRequest): Promise<BlocksAuthResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* What: reads OIDC-style current-user info through `GET /iam/v4/auth/me`.
|
|
46
|
+
* Why: apps may need profile claims from AuthController, separate from full IAM `iam.me()`.
|
|
47
|
+
* How: call after `accessToken` is available on `createBlocksClient`.
|
|
48
|
+
*/
|
|
49
|
+
userInfo(): Promise<BlocksOidcUserInfo>;
|
|
50
|
+
/**
|
|
51
|
+
* What: logs out the current session through `POST /iam/v4/auth/logout`.
|
|
52
|
+
* Why: the app can ask IAM to invalidate the current session/refresh token while clearing its own local state.
|
|
53
|
+
* How: pass IAM's logout payload, commonly including `refreshToken`.
|
|
54
|
+
*/
|
|
55
|
+
logout(request?: BlocksLogoutRequest): Promise<Record<string, unknown>>;
|
|
56
|
+
/**
|
|
57
|
+
* What: logs out all supported sessions through `POST /iam/v4/auth/logout-all`.
|
|
58
|
+
* Why: security-sensitive apps may offer a sign-out-everywhere action.
|
|
59
|
+
* How: pass IAM's logout-all payload and clear app-owned session state after success.
|
|
60
|
+
*/
|
|
61
|
+
logoutAll(request?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
62
|
+
/**
|
|
63
|
+
* What: registers a user through `POST /iam/v4/auth/signup`.
|
|
64
|
+
* Why: apps may own their signup page while IAM owns account creation rules.
|
|
65
|
+
* How: send IAM's signup payload and render IAM's response/errors directly.
|
|
66
|
+
*/
|
|
67
|
+
signup(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
68
|
+
/**
|
|
69
|
+
* What: starts account/password recovery through `POST /iam/v4/auth/recover`.
|
|
70
|
+
* Why: apps need a public recovery entry point.
|
|
71
|
+
* How: pass the email or recovery payload IAM expects and return IAM's response to the UI.
|
|
72
|
+
*/
|
|
73
|
+
recover(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
74
|
+
/**
|
|
75
|
+
* What: completes password reset through `POST /iam/v4/auth/reset-password`.
|
|
76
|
+
* Why: IAM owns reset-token validation and password policy enforcement.
|
|
77
|
+
* How: pass the reset payload from your reset form and show IAM's response/errors.
|
|
78
|
+
*/
|
|
79
|
+
resetPassword(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
80
|
+
/**
|
|
81
|
+
* What: changes password through `POST /iam/v4/auth/change-password`.
|
|
82
|
+
* Why: authenticated users need an account-security action inside your app.
|
|
83
|
+
* How: pass IAM's change-password payload after an access token is available.
|
|
84
|
+
*/
|
|
85
|
+
changePassword(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
86
|
+
/**
|
|
87
|
+
* What: activates an account through `POST /iam/v4/auth/activate`.
|
|
88
|
+
* Why: signup or invitation flows may require an activation step.
|
|
89
|
+
* How: pass the activation code/token payload IAM expects.
|
|
90
|
+
*/
|
|
91
|
+
activate(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
92
|
+
/**
|
|
93
|
+
* What: requests another activation message through `POST /iam/v4/auth/resend-activation`.
|
|
94
|
+
* Why: users may need a new activation link/code.
|
|
95
|
+
* How: pass IAM's resend payload; this call uses the active bearer token when configured.
|
|
96
|
+
*/
|
|
97
|
+
resendActivation(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
98
|
+
/**
|
|
99
|
+
* What: validates an activation payload through `POST /iam/v4/auth/validate-activation`.
|
|
100
|
+
* Why: apps can check activation state before committing the final activation UI step.
|
|
101
|
+
* How: pass the activation validation payload and render IAM's response.
|
|
102
|
+
*/
|
|
103
|
+
validateActivation(request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
104
|
+
readonly idp: {
|
|
105
|
+
/**
|
|
106
|
+
* What: starts the Blocks IAM IdP-controller browser/provider flow through `GET /iam/v4/idp/initiate`.
|
|
107
|
+
* Why: hosted login should rely on IAM's IdP controller instead of manually constructing `oidc/authorize`.
|
|
108
|
+
* How: pass optional `clientId`, `redirectUri`, or `forwardedTo`; otherwise the SDK uses `createBlocksClient().oidc` defaults and returns IAM's redirect response.
|
|
109
|
+
*/
|
|
110
|
+
initiate: (request?: BlocksIdpInitiateRequest) => Promise<BlocksIdpInitiateResponse>;
|
|
111
|
+
/**
|
|
112
|
+
* What: starts hosted login and redirects the browser to IAM's returned provider URL.
|
|
113
|
+
* Why: browser apps often need one call that handles initiate plus navigation.
|
|
114
|
+
* How: call it from a login button handler; the function throws if IAM does not return `redirect_uri`.
|
|
115
|
+
*/
|
|
116
|
+
redirectToProvider: (request?: BlocksIdpInitiateRequest) => Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* What: completes the Blocks IAM IdP-controller callback through `GET /iam/v4/idp/callback`.
|
|
119
|
+
* Why: IAM owns the hosted callback contract and returns the auth response shape.
|
|
120
|
+
* How: pass `window.location.href` or an object with `code`, `state`, and optional OIDC error fields; store the returned tokens in your app layer if IAM returns tokens.
|
|
121
|
+
*/
|
|
122
|
+
callback: (callback: string | BlocksIdpCallbackRequest) => Promise<BlocksAuthResponse>;
|
|
123
|
+
/**
|
|
124
|
+
* What: reads public UI configuration from `GET /iam/v4/idp/oidc-ui-config`.
|
|
125
|
+
* Why: hosted auth pages may need tenant login settings such as captcha or UI config before authentication.
|
|
126
|
+
* How: call before rendering hosted-auth support UI; the SDK returns IAM's response body without reshaping.
|
|
127
|
+
*/
|
|
128
|
+
uiConfig: <T = Record<string, unknown>>() => Promise<T>;
|
|
129
|
+
};
|
|
130
|
+
readonly oidc: {
|
|
131
|
+
/**
|
|
132
|
+
* What: refreshes an OIDC-flow token through `POST /iam/v4/oidc/token` with `grant_type=refresh_token`.
|
|
133
|
+
* Why: hosted IdP login relies on IdPController for browser login, but token refresh still belongs to the OIDC token endpoint.
|
|
134
|
+
* How: pass the refresh token your app owns; the SDK always sends `client_id` from the request or client OIDC config and returns IAM's token response without storing it.
|
|
135
|
+
*/
|
|
136
|
+
refreshToken: (request?: BlocksOidcRefreshRequest) => Promise<BlocksAuthResponse>;
|
|
137
|
+
/**
|
|
138
|
+
* What: requests a machine token through `POST /iam/v4/oidc/token` with `grant_type=client_credentials`.
|
|
139
|
+
* Why: backend jobs or trusted server-side adapters may need service access to Blocks APIs.
|
|
140
|
+
* How: call only outside public browser code because it requires `clientSecret`.
|
|
141
|
+
*/
|
|
142
|
+
clientCredentials: (request: BlocksClientCredentialsRequest) => Promise<BlocksAuthResponse>;
|
|
143
|
+
};
|
|
144
|
+
readonly identityProviders: {
|
|
145
|
+
/**
|
|
146
|
+
* What: lists configured identity providers through `GET /iam/v4/auth/identity-providers`.
|
|
147
|
+
* Why: admin UI can show available IdP configurations.
|
|
148
|
+
* How: call with a type parameter when your app has a specific response model.
|
|
149
|
+
*/
|
|
150
|
+
list: <T = BlocksAuthPassThroughResponse>() => Promise<T>;
|
|
151
|
+
/**
|
|
152
|
+
* What: reads one identity provider through `GET /iam/v4/auth/identity-providers/{id}`.
|
|
153
|
+
* Why: admin UI needs one record before edit/detail rendering.
|
|
154
|
+
* How: pass the IdP id from IAM.
|
|
155
|
+
*/
|
|
156
|
+
get: <T = BlocksAuthPassThroughResponse>(id: string) => Promise<T>;
|
|
157
|
+
/**
|
|
158
|
+
* What: creates an identity provider through `POST /iam/v4/auth/identity-providers`.
|
|
159
|
+
* Why: authorized apps can configure tenant IdP options.
|
|
160
|
+
* How: pass IAM's IdP payload and receive IAM's response as-is.
|
|
161
|
+
*/
|
|
162
|
+
create: <T = BlocksAuthPassThroughResponse>(request: Record<string, unknown>) => Promise<T>;
|
|
163
|
+
/**
|
|
164
|
+
* What: updates an identity provider through `PUT /iam/v4/auth/identity-providers/{id}`.
|
|
165
|
+
* Why: authorized apps can edit tenant IdP options.
|
|
166
|
+
* How: pass the IdP id and IAM's update payload.
|
|
167
|
+
*/
|
|
168
|
+
update: <T = BlocksAuthPassThroughResponse>(id: string, request: Record<string, unknown>) => Promise<T>;
|
|
169
|
+
/**
|
|
170
|
+
* What: changes identity-provider status through `PATCH /iam/v4/auth/identity-providers/{id}/status`.
|
|
171
|
+
* Why: admin UI can enable or disable an IdP without editing the whole configuration.
|
|
172
|
+
* How: pass the IdP id and status payload IAM expects.
|
|
173
|
+
*/
|
|
174
|
+
updateStatus: <T = BlocksAuthPassThroughResponse>(id: string, request: Record<string, unknown>) => Promise<T>;
|
|
175
|
+
/**
|
|
176
|
+
* What: deletes an identity provider through `DELETE /iam/v4/auth/identity-providers/{id}`.
|
|
177
|
+
* Why: admin UI can remove tenant IdP configuration.
|
|
178
|
+
* How: pass the IdP id; IAM decides whether deletion is allowed.
|
|
179
|
+
*/
|
|
180
|
+
delete: <T = BlocksAuthPassThroughResponse>(id: string) => Promise<T>;
|
|
181
|
+
};
|
|
182
|
+
readonly config: {
|
|
183
|
+
/**
|
|
184
|
+
* What: reads auth configuration through `GET /iam/v4/auth/config`.
|
|
185
|
+
* Why: admin/settings UI can render current AuthController configuration.
|
|
186
|
+
* How: call after an authorized token is available.
|
|
187
|
+
*/
|
|
188
|
+
get: <T = BlocksAuthPassThroughResponse>() => Promise<T>;
|
|
189
|
+
/**
|
|
190
|
+
* What: saves auth configuration through `POST /iam/v4/auth/config`.
|
|
191
|
+
* Why: admin/settings UI can update AuthController behavior.
|
|
192
|
+
* How: pass IAM's config payload and receive IAM's response as-is.
|
|
193
|
+
*/
|
|
194
|
+
update: <T = BlocksAuthPassThroughResponse>(request: Record<string, unknown>) => Promise<T>;
|
|
195
|
+
};
|
|
196
|
+
readonly userCodes: {
|
|
197
|
+
/**
|
|
198
|
+
* What: lists user codes through `GET /iam/v4/auth/user-codes`.
|
|
199
|
+
* Why: apps using user-code auth/admin flows can show existing generated codes.
|
|
200
|
+
* How: call from an authorized surface.
|
|
201
|
+
*/
|
|
202
|
+
list: <T = BlocksAuthPassThroughResponse>() => Promise<T>;
|
|
203
|
+
/**
|
|
204
|
+
* What: generates a user code through `POST /iam/v4/auth/user-codes`.
|
|
205
|
+
* Why: apps using user-code flows need IAM to create the code.
|
|
206
|
+
* How: pass IAM's generation payload.
|
|
207
|
+
*/
|
|
208
|
+
generate: <T = BlocksAuthPassThroughResponse>(request: Record<string, unknown>) => Promise<T>;
|
|
209
|
+
};
|
|
210
|
+
readonly clientCredentials: {
|
|
211
|
+
/**
|
|
212
|
+
* What: lists client credentials through `GET /iam/v4/auth/client-credentials`.
|
|
213
|
+
* Why: authorized admin UIs can manage service credentials.
|
|
214
|
+
* How: call from a trusted/authorized management surface.
|
|
215
|
+
*/
|
|
216
|
+
list: <T = BlocksAuthPassThroughResponse>() => Promise<T>;
|
|
217
|
+
/**
|
|
218
|
+
* What: creates or updates client credentials through `POST /iam/v4/auth/client-credentials`.
|
|
219
|
+
* Why: authorized admin UIs can provision service credentials.
|
|
220
|
+
* How: pass IAM's credential payload; do not expose generated secrets in public UI longer than necessary.
|
|
221
|
+
*/
|
|
222
|
+
save: <T = BlocksAuthPassThroughResponse>(request: Record<string, unknown>) => Promise<T>;
|
|
223
|
+
/**
|
|
224
|
+
* What: deletes a client credential through `DELETE /iam/v4/auth/client-credentials/{id}`.
|
|
225
|
+
* Why: authorized admin UIs can revoke service credentials.
|
|
226
|
+
* How: pass the credential id from IAM.
|
|
227
|
+
*/
|
|
228
|
+
delete: <T = BlocksAuthPassThroughResponse>(id: string) => Promise<T>;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* What: resolves the caller-owned bearer token configured on `createBlocksClient`.
|
|
232
|
+
* Why: the SDK must not own browser sessions or token storage, but protected API calls still need the active token.
|
|
233
|
+
* How: provide `accessToken` as a string or callback in client config; call this when adapters need to inspect the resolved token.
|
|
234
|
+
*/
|
|
235
|
+
accessToken(): Promise<string | undefined>;
|
|
236
|
+
/**
|
|
237
|
+
* What: checks whether `accessToken()` currently resolves a non-empty token.
|
|
238
|
+
* Why: apps may need a lightweight UI/session guard before rendering protected areas.
|
|
239
|
+
* How: use it as a convenience only; real authorization still comes from Blocks API responses and IAM permissions.
|
|
240
|
+
*/
|
|
241
|
+
isAuthenticated(): Promise<boolean>;
|
|
242
|
+
/**
|
|
243
|
+
* What: sends a JSON Auth/IdPController request and returns the parsed response body.
|
|
244
|
+
* Why: auth endpoints can return protocol-shaped errors, so this layer intentionally does not reshape non-2xx bodies.
|
|
245
|
+
* How: SDK methods call this with the exact IAM route, method, query, and payload.
|
|
246
|
+
*/
|
|
247
|
+
json<T>(path: string, options?: BlocksAuthJsonOptions): Promise<T>;
|
|
248
|
+
/**
|
|
249
|
+
* What: sends an `application/x-www-form-urlencoded` OIDC token request.
|
|
250
|
+
* Why: `/iam/v4/oidc/token` follows OAuth/OIDC form-post semantics rather than JSON body semantics.
|
|
251
|
+
* How: OIDC token helpers pass grant fields here; the response body is returned exactly as IAM sends it.
|
|
252
|
+
*/
|
|
253
|
+
form<T>(path: string, form: Record<string, string | undefined>): Promise<T>;
|
|
254
|
+
private raw;
|
|
255
|
+
private get oidcDefaults();
|
|
256
|
+
}
|