@schemavaults/auth-server-sdk 0.41.1 → 0.42.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 +14 -1
- package/dist/auth-session-route/index.d.ts +1 -0
- package/dist/auth-session-route/index.js.map +1 -1
- package/dist/auth-session-route/token-route.d.ts +15 -2
- package/dist/auth-session-route/token-route.js +16 -3
- package/dist/auth-session-route/token-route.js.map +1 -1
- package/dist/cli.cjs +2 -2
- package/dist/codegen-templates/auth/auth-provider.tsx +9 -0
- package/dist/confidential-client/exchange-token-for-delegated-token.d.ts +6 -5
- package/dist/confidential-client/exchange-token-for-delegated-token.js +11 -6
- package/dist/confidential-client/exchange-token-for-delegated-token.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -168,6 +168,15 @@ app's `authorization_code` and `refresh_token` grants.
|
|
|
168
168
|
The auth server rate-limits refresh grants per IP; proxied through the token
|
|
169
169
|
route, they count against the app server's IP.
|
|
170
170
|
|
|
171
|
+
An app with a client secret is a confidential client: the auth server then
|
|
172
|
+
refuses every token request of the app that does not authenticate with the
|
|
173
|
+
secret, its users' sign-ins included. Set `SCHEMAVAULTS_CLIENT_SECRET` (or
|
|
174
|
+
pass `client_secret` to `createAuthSessionTokenRoute()`) and the token route
|
|
175
|
+
authenticates the code and refresh grants it forwards with it
|
|
176
|
+
(`client_secret_basic`); the secret never reaches the browser. That is how an
|
|
177
|
+
app whose backend mints delegated tokens for its agents (below) keeps signing
|
|
178
|
+
its users in through these routes.
|
|
179
|
+
|
|
171
180
|
## Accepting resource-URL token audiences
|
|
172
181
|
|
|
173
182
|
Access tokens are normally minted with your API server id as their `aud`.
|
|
@@ -332,7 +341,7 @@ const delegated = await exchangeTokenForDelegatedToken({
|
|
|
332
341
|
scope: ["notes:read"], // optional: a subset of its scope (default: all of it)
|
|
333
342
|
});
|
|
334
343
|
delegated.access_token; // give this to the agent
|
|
335
|
-
delegated.expires_in; // seconds
|
|
344
|
+
delegated.expires_in; // seconds: what the subject token had left. No refresh token: renew the user's token and exchange again
|
|
336
345
|
delegated.scope; // the granted scope
|
|
337
346
|
|
|
338
347
|
// When the agent's session ends:
|
|
@@ -347,6 +356,10 @@ await revokeToken({ ...client, token: delegated.access_token });
|
|
|
347
356
|
Other refusals: `invalid_request` (the subject token is expired, revoked, already
|
|
348
357
|
delegated, issued to another client, or the user withdrew the app's access) and
|
|
349
358
|
`invalid_scope` (more scope than the subject token holds).
|
|
359
|
+
- A delegated token expires when its subject token does, so exchange a freshly
|
|
360
|
+
renewed access token of the user's (a subject token with under 30 seconds left is
|
|
361
|
+
refused with `invalid_request`). It also ends with the user's session it came from:
|
|
362
|
+
revoking that session's refresh token (or the user logging out) revokes it.
|
|
350
363
|
- Revoking makes introspection and resource servers with an `isTokenRevoked` hook
|
|
351
364
|
refuse the token at once; resource servers that only verify tokens locally stop
|
|
352
365
|
accepting it when it expires.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createAuthSessionTokenRoute } from "./token-route";
|
|
2
|
+
export type { AuthSessionTokenRouteOptions } from "./token-route";
|
|
2
3
|
export { createAuthSessionWhoamiRoute } from "./whoami-route";
|
|
3
4
|
export { createAuthSessionLogoutRoute } from "./logout-route";
|
|
4
5
|
export type { AuthSessionRouteHandler, AuthSessionRouteOptions, AuthSessionUpstreamFetch, } from "./session-route-context";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth-session-route/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth-session-route/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { type AuthSessionRouteHandler, type AuthSessionRouteOptions } from "./session-route-context";
|
|
2
|
+
export interface AuthSessionTokenRouteOptions extends AuthSessionRouteOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The app's client secret, when it is a confidential client (e.g. its
|
|
5
|
+
* backend exchanges its users' tokens for its agents' delegated tokens):
|
|
6
|
+
* the route then authenticates the code and refresh grants it forwards
|
|
7
|
+
* with it (`client_secret_basic`), which the auth server requires of every
|
|
8
|
+
* token request of an app with a secret. It never reaches the browser.
|
|
9
|
+
* Default: `SCHEMAVAULTS_CLIENT_SECRET`; unset, the app is a public client.
|
|
10
|
+
*/
|
|
11
|
+
client_secret?: string;
|
|
12
|
+
}
|
|
2
13
|
/**
|
|
3
14
|
* The token session route (`POST`): the SDK's authorization code and refresh grants.
|
|
4
15
|
* Forwarded to the auth server's token endpoint; the refresh token goes into
|
|
5
16
|
* the session cookie (a refresh grant presents the cookie's), never into the
|
|
6
|
-
* response body.
|
|
17
|
+
* response body. A confidential client's grants are authenticated with its
|
|
18
|
+
* client secret (`client_secret`, default `SCHEMAVAULTS_CLIENT_SECRET`). In
|
|
19
|
+
* Next.js, `app/auth/session/token/route.ts`:
|
|
7
20
|
*
|
|
8
21
|
* ```ts
|
|
9
22
|
* export const { POST } = createAuthSessionTokenRoute();
|
|
10
23
|
* ```
|
|
11
24
|
*/
|
|
12
|
-
export declare function createAuthSessionTokenRoute(options?:
|
|
25
|
+
export declare function createAuthSessionTokenRoute(options?: AuthSessionTokenRouteOptions): {
|
|
13
26
|
POST: AuthSessionRouteHandler;
|
|
14
27
|
};
|
|
15
28
|
export default createAuthSessionTokenRoute;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { MaximumBrowserCookieSize, OIDC_TOKEN_REFRESH_TOKEN_DELIVERY_PARAM, getOidcEndpointUrl, } from "@schemavaults/auth-common";
|
|
2
2
|
import getStringByteSize from "../getStringByteSize";
|
|
3
|
+
import { clientSecretBasicAuthorization } from "../confidential-client/shared";
|
|
3
4
|
import { serializeClearedSessionCookie, serializeSessionCookie } from "./session-cookie";
|
|
4
5
|
import { createSessionRoute, json, } from "./session-route-context";
|
|
5
6
|
function oauthError(status, error, error_description) {
|
|
6
7
|
return json(status, { error, error_description });
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** The configured client secret (read per request: env vars may be unset at build time). */
|
|
10
|
+
function resolveClientSecret(options) {
|
|
11
|
+
const client_secret = options.client_secret ?? process.env.SCHEMAVAULTS_CLIENT_SECRET;
|
|
12
|
+
return typeof client_secret === "string" && client_secret.length > 0 ? client_secret : null;
|
|
13
|
+
}
|
|
14
|
+
async function handleToken({ request, config, cookie, refresh_token, callAuthServer }, client_secret) {
|
|
9
15
|
const form = new URLSearchParams(await request.text());
|
|
10
16
|
if (form.get("client_id") !== config.client_app_id) {
|
|
11
17
|
return oauthError(400, "invalid_client", "This session route serves another client.");
|
|
@@ -34,6 +40,9 @@ async function handleToken({ request, config, cookie, refresh_token, callAuthSer
|
|
|
34
40
|
const origin = request.headers.get("origin");
|
|
35
41
|
if (origin)
|
|
36
42
|
headers.set("Origin", origin);
|
|
43
|
+
if (client_secret) {
|
|
44
|
+
headers.set("Authorization", clientSecretBasicAuthorization({ client_id: config.client_app_id, client_secret }));
|
|
45
|
+
}
|
|
37
46
|
let upstream;
|
|
38
47
|
let body;
|
|
39
48
|
try {
|
|
@@ -77,14 +86,18 @@ async function handleToken({ request, config, cookie, refresh_token, callAuthSer
|
|
|
77
86
|
* The token session route (`POST`): the SDK's authorization code and refresh grants.
|
|
78
87
|
* Forwarded to the auth server's token endpoint; the refresh token goes into
|
|
79
88
|
* the session cookie (a refresh grant presents the cookie's), never into the
|
|
80
|
-
* response body.
|
|
89
|
+
* response body. A confidential client's grants are authenticated with its
|
|
90
|
+
* client secret (`client_secret`, default `SCHEMAVAULTS_CLIENT_SECRET`). In
|
|
91
|
+
* Next.js, `app/auth/session/token/route.ts`:
|
|
81
92
|
*
|
|
82
93
|
* ```ts
|
|
83
94
|
* export const { POST } = createAuthSessionTokenRoute();
|
|
84
95
|
* ```
|
|
85
96
|
*/
|
|
86
97
|
export function createAuthSessionTokenRoute(options = {}) {
|
|
87
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
POST: createSessionRoute(options, (route) => handleToken(route, resolveClientSecret(options))),
|
|
100
|
+
};
|
|
88
101
|
}
|
|
89
102
|
export default createAuthSessionTokenRoute;
|
|
90
103
|
//# sourceMappingURL=token-route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-route.js","sourceRoot":"","sources":["../../src/auth-session-route/token-route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uCAAuC,EACvC,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAIL,kBAAkB,EAClB,IAAI,GACL,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"token-route.js","sourceRoot":"","sources":["../../src/auth-session-route/token-route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uCAAuC,EACvC,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAIL,kBAAkB,EAClB,IAAI,GACL,MAAM,yBAAyB,CAAC;AAcjC,SAAS,UAAU,CAAC,MAAc,EAAE,KAAa,EAAE,iBAAyB;IAC1E,OAAO,IAAI,CAAC,M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ACD,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAwC,EAAE;IAE1C,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;KAC/F,CAAC;AACJ,CAAC;AAED,eAAe,2BAA2B,CAAC"}
|
package/dist/cli.cjs
CHANGED
|
@@ -89,7 +89,7 @@ var init_resolve_codegen_templates_directory = __esm({
|
|
|
89
89
|
|
|
90
90
|
// src/NextjsAppDirectoryPlugin/codegen-marker.ts
|
|
91
91
|
function getCodegenMarkerComment() {
|
|
92
|
-
const version2 = true ? "0.
|
|
92
|
+
const version2 = true ? "0.42.0" : "unknown";
|
|
93
93
|
return `${CODEGEN_MARKER_PREFIX}${version2}`;
|
|
94
94
|
}
|
|
95
95
|
function hasCodegenMarker(firstLine) {
|
|
@@ -23384,7 +23384,7 @@ async function main() {
|
|
|
23384
23384
|
return;
|
|
23385
23385
|
}
|
|
23386
23386
|
if (args.includes("--version") || args.includes("-v")) {
|
|
23387
|
-
console.log(`${PACKAGE_NAME}@${"0.
|
|
23387
|
+
console.log(`${PACKAGE_NAME}@${"0.42.0"}`);
|
|
23388
23388
|
return;
|
|
23389
23389
|
}
|
|
23390
23390
|
const command = findCommand(args, FLAGS_WITH_VALUES) ?? "codegen";
|
|
@@ -24,6 +24,14 @@ export interface IAppAuthProviderProps extends PropsWithChildren {
|
|
|
24
24
|
*/
|
|
25
25
|
auth_server_url?: string;
|
|
26
26
|
default_audiences: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* The authorization request every sign-in makes, e.g. your API's scopes:
|
|
29
|
+
* `{ scope: "openid email profile notes:read", resource: "my-notes-api" }`
|
|
30
|
+
* (see `SchemaVaultsAuthProviderProps.authorization_params`). Sessions
|
|
31
|
+
* whose sign-in asked for less are sent through the flow again. Define it
|
|
32
|
+
* at module level so it stays stable.
|
|
33
|
+
*/
|
|
34
|
+
authorization_params?: SchemaVaultsAuthProviderProps["authorization_params"];
|
|
27
35
|
debug?: boolean;
|
|
28
36
|
authed_on_unauthed_redirect_uri: string;
|
|
29
37
|
unauthed_on_authed_redirect_uri: string;
|
|
@@ -76,6 +84,7 @@ export default function AppAuthProvider({
|
|
|
76
84
|
router={router}
|
|
77
85
|
path={path}
|
|
78
86
|
default_audiences={props.default_audiences}
|
|
87
|
+
authorization_params={props.authorization_params}
|
|
79
88
|
autoreacquire_access_tokens={
|
|
80
89
|
typeof props.autoreacquire_access_tokens === "boolean"
|
|
81
90
|
? props.autoreacquire_access_tokens
|
|
@@ -43,13 +43,14 @@ export type DelegatedTokenResponse = z.infer<typeof delegatedTokenResponseSchema
|
|
|
43
43
|
* Only confidential clients can exchange (they authenticate with
|
|
44
44
|
* `client_secret_basic` here), and only for API servers whose managers
|
|
45
45
|
* accept delegated tokens (otherwise `invalid_target`). The response holds
|
|
46
|
-
* an access token alone
|
|
47
|
-
*
|
|
46
|
+
* an access token alone, which expires when the subject token does (auth
|
|
47
|
+
* server >= 0.67.8): when it expires, exchange a fresh access token of the
|
|
48
|
+
* user's again. End the delegation early with `revokeToken()`.
|
|
48
49
|
*
|
|
49
50
|
* @throws {OAuthEndpointError} when the auth server refuses the exchange.
|
|
50
|
-
* Notable codes: `invalid_request` (the subject token is invalid, expired
|
|
51
|
-
* revoked, already delegated, or the user's access behind it
|
|
52
|
-
* withdrawn), `invalid_scope` (wider than the subject token's), and
|
|
51
|
+
* Notable codes: `invalid_request` (the subject token is invalid, expired
|
|
52
|
+
* or about to, revoked, already delegated, or the user's access behind it
|
|
53
|
+
* was withdrawn), `invalid_scope` (wider than the subject token's), and
|
|
53
54
|
* `invalid_target` (another audience, or an API server that does not
|
|
54
55
|
* accept delegated tokens).
|
|
55
56
|
*/
|
|
@@ -7,7 +7,11 @@ export const delegatedTokenResponseSchema = z.looseObject({
|
|
|
7
7
|
access_token: z.string().min(1),
|
|
8
8
|
issued_token_type: z.literal(OAUTH_ACCESS_TOKEN_TYPE),
|
|
9
9
|
token_type: z.literal("Bearer"),
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Lifetime in seconds: what the subject token had left (a delegated token
|
|
12
|
+
* expires with it). To keep the agent going, renew the user's access token
|
|
13
|
+
* and exchange the new one; there is no refresh token.
|
|
14
|
+
*/
|
|
11
15
|
expires_in: z.number().int().positive(),
|
|
12
16
|
/** Space-delimited granted scope; absent when the token carries none. */
|
|
13
17
|
scope: z.string().optional(),
|
|
@@ -33,13 +37,14 @@ function serializeScope(scope) {
|
|
|
33
37
|
* Only confidential clients can exchange (they authenticate with
|
|
34
38
|
* `client_secret_basic` here), and only for API servers whose managers
|
|
35
39
|
* accept delegated tokens (otherwise `invalid_target`). The response holds
|
|
36
|
-
* an access token alone
|
|
37
|
-
*
|
|
40
|
+
* an access token alone, which expires when the subject token does (auth
|
|
41
|
+
* server >= 0.67.8): when it expires, exchange a fresh access token of the
|
|
42
|
+
* user's again. End the delegation early with `revokeToken()`.
|
|
38
43
|
*
|
|
39
44
|
* @throws {OAuthEndpointError} when the auth server refuses the exchange.
|
|
40
|
-
* Notable codes: `invalid_request` (the subject token is invalid, expired
|
|
41
|
-
* revoked, already delegated, or the user's access behind it
|
|
42
|
-
* withdrawn), `invalid_scope` (wider than the subject token's), and
|
|
45
|
+
* Notable codes: `invalid_request` (the subject token is invalid, expired
|
|
46
|
+
* or about to, revoked, already delegated, or the user's access behind it
|
|
47
|
+
* was withdrawn), `invalid_scope` (wider than the subject token's), and
|
|
43
48
|
* `invalid_target` (another audience, or an API server that does not
|
|
44
49
|
* accept delegated tokens).
|
|
45
50
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange-token-for-delegated-token.js","sourceRoot":"","sources":["../../src/confidential-client/exchange-token-for-delegated-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,wBAAwB,GACzB,MAAM,UAAU,CAAC;AA0BlB,iEAAiE;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CAAC;IACxD,wDAAwD;IACxD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IACrD,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B
|
|
1
|
+
{"version":3,"file":"exchange-token-for-delegated-token.js","sourceRoot":"","sources":["../../src/confidential-client/exchange-token-for-delegated-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,wBAAwB,GACzB,MAAM,UAAU,CAAC;AA0BlB,iEAAiE;AACjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,WAAW,CAAC;IACxD,wDAAwD;IACxD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IACrD,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B;;;;OAIG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvC,yEAAyE;IACzE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC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CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,QAAQ,GAAa,MAAM,wBAAwB,CACvD,WAAW,EACX,OAAO,EACP,kBAAkB,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,EACxD,IAAI,CACL,CAAC;IAEF,MAAM,MAAM,GAAG,4BAA4B,CAAC,SAAS,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,qEAAqE,EACrE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CACxB,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,eAAe,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-server-sdk",
|
|
3
3
|
"description": "TypeScript SDK for building authenticated endpoints/middlewares for the Auth Server and Resource Servers",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.42.0",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"zod": "4.6.7",
|
|
21
|
-
"@schemavaults/jwt": "0.
|
|
21
|
+
"@schemavaults/jwt": "0.17.0",
|
|
22
22
|
"@schemavaults/auth-common": "0.38.0",
|
|
23
23
|
"@schemavaults/app-definitions": "0.17.0"
|
|
24
24
|
},
|