@seliseblocks/client 0.1.1 → 0.1.3

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,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
- - 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
+ - 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.dms.*` for DMS file/folder helpers
104
+ - `blocks.data.utilities.*` for runtime utility helpers
105
+
106
+ Localization:
107
+
108
+ - `blocks.localization.languages()`
109
+ - `blocks.localization.modules()`
110
+ - `blocks.localization.languagesForCurrentTenant()`
111
+ - `blocks.localization.modulesForCurrentTenant()`
112
+ - `blocks.localization.translations(moduleName, language)`
113
+ - `blocks.localization.load(language, modules)`
114
+ - `blocks.localization.cloudTranslations(moduleName, language)`
115
+ - `blocks.localization.loadCloud(language, modules)`
116
+ - `blocks.localization.keysByNames(...)`
117
+ - `blocks.localization.t(key, fallback, options)`
118
+
119
+ HTTP fallback:
120
+
121
+ - Use `blocks.http.request("/service/v4/...")` only when no typed method exists.
122
+ - Use `blocks.http.external(url, ...)` only for external URLs such as pre-signed uploads.
123
+
124
+ Errors:
125
+
126
+ - 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.
127
+
128
+ ## Minimal Examples
129
+
130
+ ```ts
131
+ const me = await blocks.iam.me();
132
+ const schemas = await blocks.data.schemas.list({ pageNo: 1, pageSize: 20 });
133
+ const rows = await blocks.data.collection("Students").list({ pageNo: 1, pageSize: 20 });
134
+ await blocks.localization.load("en-US", ["common"]);
135
+ const label = blocks.localization.t("save", "Save");
136
+ ```
137
+
138
+ OIDC refresh with explicit client id:
139
+
140
+ ```ts
141
+ await blocks.auth.oidc.refreshToken({
142
+ clientId: env.OIDC_CLIENT_ID,
143
+ refreshToken: session.refreshToken
144
+ });
145
+ ```
146
+
147
+ Embedded refresh:
148
+
149
+ ```ts
150
+ await blocks.auth.refresh({
151
+ refreshToken: session.refreshToken
152
+ });
153
+ ```
154
+
155
+ ## Check Before Finishing
156
+
157
+ ```bash
158
+ npm test
159
+ npm run lint
160
+ npm pack --dry-run
161
+ rg -n "v4[/\\]api|iam[/\\]v4[/\\]api|data[/\\]v4[/\\]api|localization[/\\]v4[/\\]api" src README.md AI_USAGE_GUIDE.md test
162
+ ```
163
+
164
+ 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.