@seliseblocks/client 0.1.4 → 0.1.5
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 +165 -164
- package/LICENSE +21 -21
- package/README.md +213 -209
- package/dist/data/data-client.d.ts +36 -41
- package/dist/data/data-client.js +116 -85
- package/dist/data/types.d.ts +124 -33
- package/dist/index.d.ts +1 -1
- package/package.json +48 -48
package/AI_USAGE_GUIDE.md
CHANGED
|
@@ -1,164 +1,165 @@
|
|
|
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
|
-
- MFA: `src/mfa/mfa-client.ts`
|
|
13
|
-
- HTTP/errors: `src/http/http-client.ts`, `src/http/errors.ts`
|
|
14
|
-
|
|
15
|
-
## Non-Negotiable Rules
|
|
16
|
-
|
|
17
|
-
- Configure `xBlocksKey`; SDK sends it as `x-blocks-key`.
|
|
18
|
-
- Do not send `ProjectKey` or `projectKey`.
|
|
19
|
-
- Do not add `/api` after `/v4`.
|
|
20
|
-
- Valid route shapes: `/iam/v4/...`, `/data/v4/...`, `/localization/v4/...`.
|
|
21
|
-
- SDK does not store tokens. App owns access token, refresh token, storage, and logout cleanup.
|
|
22
|
-
- Frontend code must not contain client secrets.
|
|
23
|
-
- Do not add impersonation, release deploy, schema/rules mutation, or localization authoring/admin APIs.
|
|
24
|
-
|
|
25
|
-
## Create Client
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { createBlocksClient } from "@seliseblocks/client";
|
|
29
|
-
|
|
30
|
-
export const blocks = createBlocksClient({
|
|
31
|
-
apiUrl: "https://api.seliseblocks.com",
|
|
32
|
-
xBlocksKey: env.BLOCKS_KEY,
|
|
33
|
-
accessToken: () => session.accessToken,
|
|
34
|
-
oidc: {
|
|
35
|
-
url: "https://iam.seliseblocks.com",
|
|
36
|
-
clientId: env.OIDC_CLIENT_ID,
|
|
37
|
-
redirectUri: env.OIDC_REDIRECT_URI ?? `${window.location.origin}/login/callback`
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Use `accessToken` only for the current token resolver. Do not add SDK token storage.
|
|
43
|
-
Use a configured `redirectUri` when available; the current-origin `/login/callback` URL is only a browser fallback.
|
|
44
|
-
|
|
45
|
-
## Auth Decision
|
|
46
|
-
|
|
47
|
-
There are two auth flows.
|
|
48
|
-
|
|
49
|
-
OIDC/hosted IAM flow:
|
|
50
|
-
|
|
51
|
-
- Login: `blocks.auth.idp.initiate()`, `blocks.auth.idp.redirectToProvider()`, `blocks.auth.idp.callback(...)`
|
|
52
|
-
- Refresh: `blocks.auth.oidc.refreshToken({ refreshToken })`
|
|
53
|
-
- Refresh route: `POST /iam/v4/oidc/token`
|
|
54
|
-
- Must send `client_id`; SDK uses `request.clientId` or configured `oidc.clientId`.
|
|
55
|
-
- Do not manually build `oidc/authorize`.
|
|
56
|
-
|
|
57
|
-
Embedded/app-owned flow:
|
|
58
|
-
|
|
59
|
-
- Login: `blocks.auth.login(...)`
|
|
60
|
-
- Social: `blocks.auth.socialInitiate(clientId, redirectUri)` (two positional strings), `blocks.auth.socialCallback(request)` (object)
|
|
61
|
-
- Refresh: `blocks.auth.refresh({ refreshToken })`
|
|
62
|
-
- Routes: `/iam/v4/auth/login`, `/iam/v4/auth/social/*`, `/iam/v4/auth/refresh`
|
|
63
|
-
|
|
64
|
-
Shared auth methods for both flows:
|
|
65
|
-
|
|
66
|
-
- `userInfo()`
|
|
67
|
-
- `switchOrganization(...)`
|
|
68
|
-
- `logout(...)`, `logoutAll(...)`
|
|
69
|
-
- `signup(...)`, `recover(...)`, `resetPassword(...)`
|
|
70
|
-
- `changePassword(...)`
|
|
71
|
-
- `activate(...)`, `resendActivation(...)`, `validateActivation(...)`
|
|
72
|
-
- `identityProviders.*`, `config.*`, `userCodes.*`, `clientCredentials.*` when app has permission
|
|
73
|
-
- `accessToken()` - resolves the caller-owned bearer token configured on `createBlocksClient`.
|
|
74
|
-
- `isAuthenticated()` - checks the session against IAM via `GET /iam/v4/auth/me`, returns a boolean from the raw response status. Prefer this over `userInfo()` for a true/false check, since a hosted-IdP session may live in a cookie with no local `accessToken` to inspect.
|
|
75
|
-
|
|
76
|
-
## Service Map
|
|
77
|
-
|
|
78
|
-
IAM:
|
|
79
|
-
|
|
80
|
-
- `blocks.iam.me()`
|
|
81
|
-
- `blocks.iam.users.*`
|
|
82
|
-
- `blocks.iam.roles.*`
|
|
83
|
-
- `blocks.iam.permissions.*`
|
|
84
|
-
- `blocks.iam.resources.*`
|
|
85
|
-
- `blocks.iam.organizations.*`
|
|
86
|
-
- `blocks.iam.signupSettings.get()` / `.save(...)`
|
|
87
|
-
|
|
88
|
-
MFA:
|
|
89
|
-
|
|
90
|
-
- `blocks.mfa.config()` / `.saveConfig(...)` - tenant MFA policy
|
|
91
|
-
- `blocks.mfa.totp.setup()` / `.verifySetup({ code })` - TOTP enrollment
|
|
92
|
-
- `blocks.mfa.generate(...)` / `.resend(...)` / `.verify(...)` - OTP challenge flow
|
|
93
|
-
- `blocks.mfa.setMethod({ mfaType })`, `.disable()`
|
|
94
|
-
- `blocks.mfa.backupCodes.list()` / `.generate()` / `.use({ code, userId })`
|
|
95
|
-
|
|
96
|
-
Data:
|
|
97
|
-
|
|
98
|
-
- `blocks.data.schemas.*` for schema reads only
|
|
99
|
-
- `blocks.data.validations.*` for validation reads
|
|
100
|
-
- `blocks.data.collection("Name").list/get/create/update/delete`
|
|
101
|
-
- `blocks.data.graphql(...)`
|
|
102
|
-
- `blocks.data.files.*` for file/storage helpers
|
|
103
|
-
- `blocks.data.
|
|
104
|
-
- `blocks.data.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
- `blocks.localization.
|
|
110
|
-
- `blocks.localization.
|
|
111
|
-
- `blocks.localization.
|
|
112
|
-
- `blocks.localization.
|
|
113
|
-
- `blocks.localization.
|
|
114
|
-
- `blocks.localization.
|
|
115
|
-
- `blocks.localization.
|
|
116
|
-
- `blocks.localization.
|
|
117
|
-
- `blocks.localization.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
- Use `blocks.http.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
await blocks.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
npm
|
|
160
|
-
npm
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
+
- MFA: `src/mfa/mfa-client.ts`
|
|
13
|
+
- HTTP/errors: `src/http/http-client.ts`, `src/http/errors.ts`
|
|
14
|
+
|
|
15
|
+
## Non-Negotiable Rules
|
|
16
|
+
|
|
17
|
+
- Configure `xBlocksKey`; SDK sends it as `x-blocks-key`.
|
|
18
|
+
- Do not send `ProjectKey` or `projectKey`.
|
|
19
|
+
- Do not add `/api` after `/v4`.
|
|
20
|
+
- Valid route shapes: `/iam/v4/...`, `/data/v4/...`, `/localization/v4/...`.
|
|
21
|
+
- SDK does not store tokens. App owns access token, refresh token, storage, and logout cleanup.
|
|
22
|
+
- Frontend code must not contain client secrets.
|
|
23
|
+
- Do not add impersonation, release deploy, schema/rules mutation, or localization authoring/admin APIs.
|
|
24
|
+
|
|
25
|
+
## Create Client
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createBlocksClient } from "@seliseblocks/client";
|
|
29
|
+
|
|
30
|
+
export const blocks = createBlocksClient({
|
|
31
|
+
apiUrl: "https://api.seliseblocks.com",
|
|
32
|
+
xBlocksKey: env.BLOCKS_KEY,
|
|
33
|
+
accessToken: () => session.accessToken,
|
|
34
|
+
oidc: {
|
|
35
|
+
url: "https://iam.seliseblocks.com",
|
|
36
|
+
clientId: env.OIDC_CLIENT_ID,
|
|
37
|
+
redirectUri: env.OIDC_REDIRECT_URI ?? `${window.location.origin}/login/callback`
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Use `accessToken` only for the current token resolver. Do not add SDK token storage.
|
|
43
|
+
Use a configured `redirectUri` when available; the current-origin `/login/callback` URL is only a browser fallback.
|
|
44
|
+
|
|
45
|
+
## Auth Decision
|
|
46
|
+
|
|
47
|
+
There are two auth flows.
|
|
48
|
+
|
|
49
|
+
OIDC/hosted IAM flow:
|
|
50
|
+
|
|
51
|
+
- Login: `blocks.auth.idp.initiate()`, `blocks.auth.idp.redirectToProvider()`, `blocks.auth.idp.callback(...)`
|
|
52
|
+
- Refresh: `blocks.auth.oidc.refreshToken({ refreshToken })`
|
|
53
|
+
- Refresh route: `POST /iam/v4/oidc/token`
|
|
54
|
+
- Must send `client_id`; SDK uses `request.clientId` or configured `oidc.clientId`.
|
|
55
|
+
- Do not manually build `oidc/authorize`.
|
|
56
|
+
|
|
57
|
+
Embedded/app-owned flow:
|
|
58
|
+
|
|
59
|
+
- Login: `blocks.auth.login(...)`
|
|
60
|
+
- Social: `blocks.auth.socialInitiate(clientId, redirectUri)` (two positional strings), `blocks.auth.socialCallback(request)` (object)
|
|
61
|
+
- Refresh: `blocks.auth.refresh({ refreshToken })`
|
|
62
|
+
- Routes: `/iam/v4/auth/login`, `/iam/v4/auth/social/*`, `/iam/v4/auth/refresh`
|
|
63
|
+
|
|
64
|
+
Shared auth methods for both flows:
|
|
65
|
+
|
|
66
|
+
- `userInfo()`
|
|
67
|
+
- `switchOrganization(...)`
|
|
68
|
+
- `logout(...)`, `logoutAll(...)`
|
|
69
|
+
- `signup(...)`, `recover(...)`, `resetPassword(...)`
|
|
70
|
+
- `changePassword(...)`
|
|
71
|
+
- `activate(...)`, `resendActivation(...)`, `validateActivation(...)`
|
|
72
|
+
- `identityProviders.*`, `config.*`, `userCodes.*`, `clientCredentials.*` when app has permission
|
|
73
|
+
- `accessToken()` - resolves the caller-owned bearer token configured on `createBlocksClient`.
|
|
74
|
+
- `isAuthenticated()` - checks the session against IAM via `GET /iam/v4/auth/me`, returns a boolean from the raw response status. Prefer this over `userInfo()` for a true/false check, since a hosted-IdP session may live in a cookie with no local `accessToken` to inspect.
|
|
75
|
+
|
|
76
|
+
## Service Map
|
|
77
|
+
|
|
78
|
+
IAM:
|
|
79
|
+
|
|
80
|
+
- `blocks.iam.me()`
|
|
81
|
+
- `blocks.iam.users.*`
|
|
82
|
+
- `blocks.iam.roles.*`
|
|
83
|
+
- `blocks.iam.permissions.*`
|
|
84
|
+
- `blocks.iam.resources.*`
|
|
85
|
+
- `blocks.iam.organizations.*`
|
|
86
|
+
- `blocks.iam.signupSettings.get()` / `.save(...)`
|
|
87
|
+
|
|
88
|
+
MFA:
|
|
89
|
+
|
|
90
|
+
- `blocks.mfa.config()` / `.saveConfig(...)` - tenant MFA policy
|
|
91
|
+
- `blocks.mfa.totp.setup()` / `.verifySetup({ code })` - TOTP enrollment
|
|
92
|
+
- `blocks.mfa.generate(...)` / `.resend(...)` / `.verify(...)` - OTP challenge flow
|
|
93
|
+
- `blocks.mfa.setMethod({ mfaType })`, `.disable()`
|
|
94
|
+
- `blocks.mfa.backupCodes.list()` / `.generate()` / `.use({ code, userId })`
|
|
95
|
+
|
|
96
|
+
Data:
|
|
97
|
+
|
|
98
|
+
- `blocks.data.schemas.*` for schema reads only
|
|
99
|
+
- `blocks.data.validations.*` for validation reads
|
|
100
|
+
- `blocks.data.collection("Name").list/get/create/update/delete`
|
|
101
|
+
- `blocks.data.graphql(...)`
|
|
102
|
+
- `blocks.data.files.*` for file/storage helpers
|
|
103
|
+
- `blocks.data.directories.*` for directory create/get/update/delete/move
|
|
104
|
+
- `blocks.data.objects.*` for browse/search/trash/shared/restore/share/access/inheritance
|
|
105
|
+
- `blocks.data.utilities.*` for runtime utility helpers
|
|
106
|
+
|
|
107
|
+
Localization:
|
|
108
|
+
|
|
109
|
+
- `blocks.localization.languages()`
|
|
110
|
+
- `blocks.localization.modules()`
|
|
111
|
+
- `blocks.localization.languagesForCurrentTenant()`
|
|
112
|
+
- `blocks.localization.modulesForCurrentTenant()`
|
|
113
|
+
- `blocks.localization.translations(moduleName, language)`
|
|
114
|
+
- `blocks.localization.load(language, modules)`
|
|
115
|
+
- `blocks.localization.cloudTranslations(moduleName, language)`
|
|
116
|
+
- `blocks.localization.loadCloud(language, modules)`
|
|
117
|
+
- `blocks.localization.keysByNames(...)`
|
|
118
|
+
- `blocks.localization.t(key, fallback, options)`
|
|
119
|
+
|
|
120
|
+
HTTP fallback:
|
|
121
|
+
|
|
122
|
+
- Use `blocks.http.request("/service/v4/...")` only when no typed method exists.
|
|
123
|
+
- Use `blocks.http.external(url, ...)` only for external URLs such as pre-signed uploads.
|
|
124
|
+
|
|
125
|
+
Errors:
|
|
126
|
+
|
|
127
|
+
- Every non-2xx response from `http.request`/`http.external` throws `BlocksApiError` (`status`, `statusText`, `body`). Catch it with `instanceof BlocksApiError` rather than assuming a generic `Error` shape.
|
|
128
|
+
|
|
129
|
+
## Minimal Examples
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
const me = await blocks.iam.me();
|
|
133
|
+
const schemas = await blocks.data.schemas.list({ pageNo: 1, pageSize: 20 });
|
|
134
|
+
const rows = await blocks.data.collection("Students").list({ pageNo: 1, pageSize: 20 });
|
|
135
|
+
await blocks.localization.load("en-US", ["common"]);
|
|
136
|
+
const label = blocks.localization.t("save", "Save");
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
OIDC refresh with explicit client id:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
await blocks.auth.oidc.refreshToken({
|
|
143
|
+
clientId: env.OIDC_CLIENT_ID,
|
|
144
|
+
refreshToken: session.refreshToken
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Embedded refresh:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
await blocks.auth.refresh({
|
|
152
|
+
refreshToken: session.refreshToken
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Check Before Finishing
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm test
|
|
160
|
+
npm run lint
|
|
161
|
+
npm pack --dry-run
|
|
162
|
+
rg -n "v4[/\\]api|iam[/\\]v4[/\\]api|data[/\\]v4[/\\]api|localization[/\\]v4[/\\]api" src README.md AI_USAGE_GUIDE.md test
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
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.
|