@seliseblocks/client 0.1.0 → 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 +149 -149
- package/LICENSE +21 -21
- package/README.md +161 -161
- package/dist/client.d.ts +2 -0
- package/dist/client.js +3 -1
- package/dist/data/data-client.d.ts +5 -5
- package/dist/data/data-client.js +123 -27
- package/dist/data/types.d.ts +18 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/localization/types.d.ts +10 -2
- package/dist/mfa/mfa-client.d.ts +82 -0
- package/dist/mfa/mfa-client.js +98 -0
- package/dist/mfa/types.d.ts +34 -0
- package/dist/mfa/types.js +1 -0
- package/package.json +48 -48
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
|
+
```
|