@seliseblocks/client 0.1.5 → 0.2.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.
@@ -1,165 +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.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.
1
+ # Blocks Client Guide for AI Agents
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 AGENT_GUIDE.md test
163
+ ```
164
+
165
+ Only negative route-guard tests should match.
package/CHANGELOG.md ADDED
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@seliseblocks/client`.
4
+
5
+ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+ Versions before 0.2.0 were released without a changelog; their history is in the
7
+ repository's git log.
8
+
9
+ ## 0.2.0
10
+
11
+ ### Breaking
12
+
13
+ - `blocks.config` no longer carries `accessToken` or `onUnauthorized`. Both are
14
+ callables that reach a live session, and this package's stated boundary is that
15
+ it never becomes somewhere to read one from. Use
16
+ `await blocks.auth.accessToken()` for the token; the hook stays available to
17
+ the client internally. Everything else on `config` (`apiUrl`, `xBlocksKey`,
18
+ `appDomain`, `oidc`) is unchanged, and its type is now `BlocksPublicConfig`.
19
+ - `http.request()` refuses an absolute URL whose origin is not the configured
20
+ `apiUrl`. It attaches the bearer token, `x-blocks-key`, and cookies, so a
21
+ foreign origin would have received a live session. `http.external(url)` is the
22
+ path for third-party URLs and sends no Blocks credentials. An absolute URL on
23
+ the configured API still works.
24
+
25
+ ### Added
26
+
27
+ - Types that were reachable in the public surface but not importable by name are
28
+ now exported: `BlocksHttpClient`, `BlocksDataSchema`,
29
+ `BlocksDataCollectionOptions`, `BlocksDataGetOptions`,
30
+ `BlocksDataDeleteOptions`, `BlocksAuthJsonOptions`,
31
+ `BlocksExternalRequestOptions`, and `BlocksPublicConfig`.
32
+
33
+ ### Changed
34
+
35
+ - `RequiredConfig` is renamed `BlocksResolvedConfig`, matching every other
36
+ exported name. `RequiredConfig` remains as a deprecated alias.
37
+ - Documented the IAM enums the typings previously called opaque:
38
+ `mfaType`/`UserMfaType` (0 None, 1 TOTP, 2 Email, 3 Sms, 4 WhatsApp — only 1
39
+ and 2 have a provider, and `setMethod` turns MFA *off* for any other value)
40
+ and the notifier sort order (1 CreatedTime newest-first, 2 ReadStatus; any
41
+ other value, including an omitted 0, returns an empty list).
42
+
43
+ ### Fixed
44
+
45
+ - A non-2xx response whose body is not valid JSON despite an
46
+ `application/json` content type now throws `BlocksApiError` carrying the status
47
+ and the raw text. It previously threw a bare `SyntaxError` before the status
48
+ was ever checked, which lost the status and broke the documented contract that
49
+ every non-2xx response surfaces as a `BlocksApiError` — the case that matters
50
+ most, since a proxy or WAF error page is exactly what arrives mislabelled.
51
+ - The README's MFA examples were stranded under the Auth heading with no heading
52
+ of their own.
53
+
54
+ ### Package metadata
55
+
56
+ - Added `repository`, `homepage`, `bugs`, and `author`.
57
+ - `LICENSE` now matches the repository's copyright line.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) SELISE Blocks
3
+ Copyright (c) 2026 SELISE Digital Platforms
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal