@logto/api 1.44.0-beta.0 → 1.44.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.
- package/README.md +31 -6
- package/lib/client-credentials.d.ts +1 -1
- package/lib/client-credentials.js +1 -1
- package/lib/generated-types/management.d.ts +361 -28
- package/lib/management.d.ts +29 -14
- package/lib/management.js +32 -49
- package/lib/pagination.d.ts +37 -0
- package/lib/pagination.js +66 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -27,8 +27,8 @@ For detailed setup instructions, visit: https://a.logto.io/m2m-mapi
|
|
|
27
27
|
```ts
|
|
28
28
|
import { createManagementApi } from '@logto/api/management';
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const { apiClient } = createManagementApi({
|
|
31
|
+
tenantId: 'your-tenant-id',
|
|
32
32
|
clientId: 'your-client-id',
|
|
33
33
|
clientSecret: 'your-client-secret',
|
|
34
34
|
});
|
|
@@ -39,19 +39,44 @@ const response = await apiClient.get('/api/users');
|
|
|
39
39
|
console.log(response.data);
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
The positional `createManagementApi(tenantId, options)` form remains supported.
|
|
43
|
+
|
|
44
|
+
#### Pagination
|
|
45
|
+
|
|
46
|
+
Use `paginate()` to iterate over items from a paginated `GET` endpoint. The path, query parameters,
|
|
47
|
+
path parameters, headers, and signal use the same generated types as `get()`.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
for await (const user of apiClient.paginate('/api/users')) {
|
|
51
|
+
console.log(user);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The iterator follows the Management API pagination headers and stops when there are no more items.
|
|
56
|
+
It requests 100 items per page unless `page_size` is provided. When an audit log endpoint reports a
|
|
57
|
+
capped total, the iterator continues until it receives an empty page because the final page is
|
|
58
|
+
unknown. Breaking out of the loop stops further requests.
|
|
59
|
+
|
|
60
|
+
API error responses throw `ManagementApiPaginationError`, which exposes `status`, response metadata
|
|
61
|
+
and headers through `response`, and the parsed API error body as `cause`. The response body has
|
|
62
|
+
already been read. Network, timeout, and abort errors propagate unchanged.
|
|
63
|
+
|
|
42
64
|
#### Self-hosted / OSS
|
|
43
65
|
|
|
44
66
|
```ts
|
|
45
67
|
import { createManagementApi } from '@logto/api/management';
|
|
46
68
|
|
|
47
|
-
const { apiClient } = createManagementApi(
|
|
69
|
+
const { apiClient } = createManagementApi({
|
|
70
|
+
tenantId: 'default',
|
|
48
71
|
clientId: 'your-client-id',
|
|
49
72
|
clientSecret: 'your-client-secret',
|
|
50
73
|
baseUrl: 'https://your-logto-instance.com',
|
|
51
|
-
apiIndicator: 'https://your-logto-instance.com/api',
|
|
52
74
|
});
|
|
53
75
|
```
|
|
54
76
|
|
|
77
|
+
If the Management API indicator cannot be derived from a tenant ID, omit `tenantId` and provide
|
|
78
|
+
both `baseUrl` and `apiIndicator`.
|
|
79
|
+
|
|
55
80
|
#### Timeouts
|
|
56
81
|
|
|
57
82
|
Token fetches and Management API network requests have separate 10-second timeouts. The API request
|
|
@@ -67,8 +92,8 @@ custom cancellation reject the API call instead of returning a response object.
|
|
|
67
92
|
#### Token refresh
|
|
68
93
|
|
|
69
94
|
After a Management API request returns `401`, the next request fetches a new token. If the replacement
|
|
70
|
-
token also receives a `401`, it remains cached until a
|
|
71
|
-
does not automatically retry the failed API request.
|
|
95
|
+
token also receives a `401`, it remains cached until the API returns a non-`401` response or the token
|
|
96
|
+
expires. The SDK does not automatically retry the failed API request.
|
|
72
97
|
|
|
73
98
|
#### Custom authentication
|
|
74
99
|
|
|
@@ -56,7 +56,7 @@ export declare class ClientCredentials {
|
|
|
56
56
|
* A delayed response for an older token must not invalidate a newer cached token.
|
|
57
57
|
*/
|
|
58
58
|
invalidateAccessToken(token: string): void;
|
|
59
|
-
/** Allows a future 401 to invalidate the token after
|
|
59
|
+
/** Allows a future 401 to invalidate the token after the API accepts it. */
|
|
60
60
|
markAccessTokenAsValid(token: string): void;
|
|
61
61
|
private fetchAccessToken;
|
|
62
62
|
private requestAccessToken;
|
|
@@ -77,7 +77,7 @@ export class ClientCredentials {
|
|
|
77
77
|
this.awaitingValidationAfterRefresh = true;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
/** Allows a future 401 to invalidate the token after
|
|
80
|
+
/** Allows a future 401 to invalidate the token after the API accepts it. */
|
|
81
81
|
markAccessTokenAsValid(token) {
|
|
82
82
|
if (this.accessToken?.value === token) {
|
|
83
83
|
this.awaitingValidationAfterRefresh = false;
|