@amaster.ai/client 1.1.72 → 1.1.73
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/README.md +57 -0
- package/dist/index.cjs +897 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +897 -30
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/types/auth/index.d.ts +1 -0
- package/types/common.d.ts +3 -0
- package/types/http.d.ts +8 -130
- package/types/index.d.ts +40 -12
package/README.md
CHANGED
|
@@ -5,6 +5,56 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@amaster.ai/client)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
+
## Application tenancy
|
|
9
|
+
|
|
10
|
+
The backend resolves the application, environment and tenancy mode from the application domain. No SDK mode switch or application/environment constants are required:
|
|
11
|
+
|
|
12
|
+
`createClient` has no `tenancy` initializer option; tenant selection uses `client.tenancy` after backend discovery.
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
const client = createClient();
|
|
16
|
+
const login = await client.auth.login({ email, password });
|
|
17
|
+
if (login.error) throw login.error;
|
|
18
|
+
await client.ready();
|
|
19
|
+
if (client.tenancy.enabled) {
|
|
20
|
+
const candidates = await client.tenancy.listAccessible({ limit: 20 });
|
|
21
|
+
if (candidates.error) throw candidates.error;
|
|
22
|
+
// Render candidates.data?.items in a tenant picker.
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function onTenantSelected(appTenantId: string) {
|
|
26
|
+
const selected = await client.tenancy.selectTenant(appTenantId);
|
|
27
|
+
if (selected.error) return selected;
|
|
28
|
+
const result = await client.entity.list("default", "orders");
|
|
29
|
+
if (!result.error && result.scopeCapture && client.tenancy.isCurrent(result.scopeCapture)) {
|
|
30
|
+
// Apply result.data to this page's state.
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> The formal managed publication scope is one default MySQL source with application-shared entities by default and explicitly declared tenant entities. Existing public calls remain the compatibility contract; custom data sources, permission filters and untested engine/deployment variants are outside the verified scope. See the validation matrix for actual results and limits.
|
|
37
|
+
|
|
38
|
+
`createClient()` remains synchronous. It automatically requests the public, non-cached `GET /api/auth/context` through the existing domain route before starting authentication, refresh timers or business requests. Login and ordinary API methods wait for the same initialization. A verified `tenancyEnabled: false` selects ordinary application behavior; malformed or unavailable context fails the request. The application deployment provides the matching Runtime and SDK.
|
|
39
|
+
|
|
40
|
+
Ordinary applications retain synchronous local login/token reads and cached permission hints during discovery. These hints only describe the existing local legacy session: they do not determine application mode, authorize requests, or migrate credentials into a tenancy namespace. Manual token replacement/clear invalidates cached hints, and failed discovery hides them. `client.tenancy.enabled` remains `null` until the backend confirms its boolean value. Use `await client.ready()` when the UI needs that authoritative mode; ordinary API calls wait internally. Copilot/ASR/TTS factories may be called synchronously before readiness, with local state reads and subscriptions available immediately. Their execution waits for discovery using the original application-account boundary for personal Copilot history and the original speech APIs; closing/destroying a pending instance cancels its queued work. No business request, refresh, recording or WebSocket connection starts before discovery succeeds.
|
|
41
|
+
|
|
42
|
+
The application domain determines the target application and environment. User code does not configure application/environment headers or a tenancy switch. Existing legacy headers remain checked for consistency with the backend response; contradictory scopes are rejected before business execution.
|
|
43
|
+
|
|
44
|
+
`account()` verifies the full server identity. Tenant choices use the authentication storage adapter, bound to application, environment and identity realm/UID. Browsers default to localStorage; explicit custom adapters and mini-program storage follow the same credential storage. Credential replacement or logout clears the verified context. `current()` validates current admission; `authorize(permission)` asks the server every time using an actual permission code from the application's published catalog. `snapshot` is last-observed context, not an authorization grant. Permission-dependent caches must also include security-policy and authorization revisions.
|
|
45
|
+
|
|
46
|
+
`current()` returns `data.tenantAuthorizationRevision` when supplied by Runtime. This is the selected tenant's management write revision, distinct from the application/environment `authorizationRevision`. Do not substitute one revision for the other. Use the AdminSDK for writes.
|
|
47
|
+
|
|
48
|
+
Page reloads can recover an expired access credential using the consumer's refresh cookie before the first account is bound. A successful rotation is kept separately in the same application/environment auth storage until the backend account check succeeds; unverified credentials never become the business token. A transient verification failure preserves this candidate for the next read/explicit refresh, including after another reload. Timer-driven renewal retries verification after 30 seconds. Logout, explicit credential replacement and a 401/403 verification rejection clear it. Writes are never replayed by this recovery flow.
|
|
49
|
+
|
|
50
|
+
Requests capture their original scope, including across a verified same-subject refresh. Switching tenant cancels old waiters and stale responses; check `scopeCapture` again before writing UI state. Automatic refresh replay is limited to GET/HEAD/OPTIONS and the known read-only authorization endpoint, once per request. Ordinary writes are not automatically replayed after 401. Entity business date strings and actual `Date` objects retain their original serialization; identity fields and account/authorization protocol values remain opaque.
|
|
51
|
+
|
|
52
|
+
Use `client.tenancy.account()` for account data and `authorize()` for consumer permissions. Existing synchronous `auth.hasRole`, `hasPermission`, `hasAnyPermission`, and `hasAllPermissions` read only the current verified tenant authorization snapshot. `auth.getMe()` retains the familiar `User` fields and current verified roles/permissions; unavailable verification never grants access. These local hints do not replace server authorization. Account operations use an explicit integrated-route allowlist; other operations return `422 capability_unsupported`. The original BPM, Workflow and Function HTTP APIs use the verified tenant automatically and preserve their business response format. Chatflow retains its original blocking/streaming APIs, binds streams to the selected tenant and rejects old chunks after a switch or account change. Copilot keeps the original application-account history across tenant switches; account changes abort old streams and reject late frames. ASR/TTS retain their original stateless speech APIs; Knowledge and S3 retain their original visibility and permissions, with sharing/isolation owned by business code; uncovered engine and deployment variants are listed in the validation matrix. Regular function publication now has a real Git/Function TCC activation check. Real private-service SDK tests cover BPM/Workflow/Function HTTP calls across enable, disable and re-enable; they do not replace deployed gateway/TLS verification.
|
|
53
|
+
|
|
54
|
+
Use the server-side [Admin SDK](../admin-sdk/README.md#tenant-administration) for tenant member, role, permission and optional department administration. After the management backend responds, call `client.tenancy.current()` for the updated tenant and permission snapshot. Apply the result only if the user's original tenant selection is still current.
|
|
55
|
+
|
|
56
|
+
The default client automatically follows the backend mode. See [functionality and validation scope](../../docs/app-tenancy-implementation.md) for verified paths and remaining limits. SDK coverage does not establish that every custom application, browser or deployment topology is supported.
|
|
57
|
+
|
|
8
58
|
## 🤖 AI-Friendly Documentation
|
|
9
59
|
|
|
10
60
|
This package is designed with AI tools (GitHub Copilot, Cursor, etc.) in mind:
|
|
@@ -887,6 +937,13 @@ All these packages are now integrated into `@amaster.ai/client`:
|
|
|
887
937
|
|
|
888
938
|
API design inspired by [Supabase](https://supabase.com) - aiming for the same level of developer experience and simplicity.
|
|
889
939
|
|
|
940
|
+
## Tenant organization and role inclusion
|
|
941
|
+
|
|
942
|
+
Business tenants are application-defined customers, stores, projects or workspaces, independent of the platform organization. Existing departments, teams and positions remain optional structures inside a tenant. Management belongs to admin-sdk: `admin.tenancy.forTenant(...).departments/roles/permissions` reuse the existing concepts and contracts. Role inclusion remains the original role-assignment operation; no second inheritance API is added.
|
|
943
|
+
|
|
944
|
+
## 原引擎 HTTP 调用兼容
|
|
945
|
+
|
|
946
|
+
租户模式沿用 `client.bpm`、`client.workflow` 和 `client.function.invoke()` 的原参数;统一请求层核验并携带当前作用域,不需要业务增加租户参数。登录态恢复后可直接选择租户,不要求先调用 `account()`;临时初始化失败可在后续调用恢复。业务 JSON 包装、HTTP 状态和日期处理保留,写入失败不自动重放。知识库/文件保留原范围与权限,由业务决定共享或隔离。Chatflow 旧流在切换后失效。其余执行与部署入口的验证边界见 [当前支持范围](../../docs/app-tenancy-implementation.md)。
|
|
890
947
|
## Browser hosts on another origin
|
|
891
948
|
|
|
892
949
|
`createClient` forwards the optional `withCredentials` and `storage` settings to its authentication client. Use `createMemoryStorage()` per embedded application and `client.auth.restoreSession()` before rendering protected pages. `completeOAuthPopup()` is also re-exported for a generic application-origin completion page. The host owns popup orchestration; all API requests and application permissions remain on `baseURL`.
|