@schemavaults/auth-common 0.39.0 → 0.40.1

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.
@@ -19,6 +19,7 @@ export declare const MAX_API_SCOPE_DESCRIPTION_LENGTH: 256;
19
19
  export declare const MAX_API_SCOPES_PER_API_SERVER: 100;
20
20
  /**
21
21
  * One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
22
+ * The same rule as `SCOPE_TOKEN_REGEX` (scope definitions).
22
23
  */
23
24
  export declare const API_SCOPE_VALUE_REGEX: RegExp;
24
25
  /**
@@ -15,14 +15,18 @@
15
15
  import { z } from "zod";
16
16
  import { apiServerIdSchema } from "@schemavaults/app-definitions";
17
17
  import { isOidcReservedScope } from "../oidc/scope";
18
- export const MAX_API_SCOPE_VALUE_LENGTH = 128;
19
- export const MAX_API_SCOPE_DESCRIPTION_LENGTH = 256;
18
+ import { MAX_SCOPE_DESCRIPTION_LENGTH, MAX_SCOPE_VALUE_LENGTH, SCOPE_TOKEN_REGEX, } from "../scopes/scope-definition";
19
+ // The same limits as scope definitions (`defineScope()`), so every
20
+ // definition can be defined on the auth server as it is.
21
+ export const MAX_API_SCOPE_VALUE_LENGTH = MAX_SCOPE_VALUE_LENGTH;
22
+ export const MAX_API_SCOPE_DESCRIPTION_LENGTH = MAX_SCOPE_DESCRIPTION_LENGTH;
20
23
  /** Upper bound on the scopes one API server may define. */
21
24
  export const MAX_API_SCOPES_PER_API_SERVER = 100;
22
25
  /**
23
26
  * One RFC 6749 §3.3 scope-token: printable ASCII except SP, `"` and `\`.
27
+ * The same rule as `SCOPE_TOKEN_REGEX` (scope definitions).
24
28
  */
25
- export const API_SCOPE_VALUE_REGEX = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
29
+ export const API_SCOPE_VALUE_REGEX = SCOPE_TOKEN_REGEX;
26
30
  /**
27
31
  * A scope value an API server may define: a single RFC 6749 scope-token
28
32
  * that is not one of the OIDC scope names.
@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"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ export * from "./oidc";
15
15
  export type * from "./oidc";
16
16
  export * from "./api-scopes";
17
17
  export type * from "./api-scopes";
18
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, oidcScopes, parseScope, formatScope, missingFromScope, scopeIncludes, } from "./scopes";
19
+ export type { DefinedScopes, GrantedScopeInput, ScopeDefinition, ScopeInput, ScopeRequirement, } from "./scopes";
18
20
  export { sha256_base64url } from "./sha256_digest";
19
21
  export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, type AuthenticateResult, type AuthenticatedAuthenticateResult, type MfaRequiredAuthenticateResult, type AuthenticateFailureResult, type ChallengeExpiredAuthenticateResult, type EmailVerificationRequiredAuthenticateResult, type AvailableMfaFactor, } from "./authenticate_result";
20
22
  export * from "./mfa";
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export * from "./middleware";
8
8
  export * from "./pkce";
9
9
  export * from "./oidc";
10
10
  export * from "./api-scopes";
11
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, oidcScopes, parseScope, formatScope, missingFromScope, scopeIncludes, } from "./scopes";
11
12
  export { sha256_base64url } from "./sha256_digest";
12
13
  export { authenticateResultSchema, authenticatedAuthenticateResultSchema, mfaRequiredAuthenticateResultSchema, authenticateFailureResultSchema, challengeExpiredAuthenticateResultSchema, emailVerificationRequiredAuthenticateResultSchema, availableMfaFactorSchema, collapseWebauthnFactors, } from "./authenticate_result";
13
14
  export * from "./mfa";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,mCAAmC,EACnC,qCAAqC,GACtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EAIvB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,8BAA8B,EAC9B,yBAAyB,GAK1B,MAAM,aAAa,CAAC;AAErB,cAAc,eAAe,CAAC;AAG9B,mBAAmB;AACnB,cAAc,cAAc,CAAC;AAM7B,cAAc,cAAc,CAAC;AAG7B,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ,CAAC;AAGvB,cAAc,cAAc,CAAC;AAG7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EACL,wBAAwB,EACxB,qCAAqC,EACrC,mCAAmC,EACnC,+BAA+B,EAC/B,wCAAwC,EACxC,iDAAiD,EACjD,wBAAwB,EACxB,uBAAuB,GAQxB,MAAM,uBAAuB,CAAC;AAE/B,cAAc,OAAO,CAAC;AACtB,OAAO,EACL,+BAA+B,EAE/B,6CAA6C,GAE9C,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,sBAAsB,EACtB,0BAA0B,GAC3B,MA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EACL,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
@@ -1,5 +1,5 @@
1
- export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
2
- export type { OidcSupportedScope, OidcScope, ParsedOidcScopes, GrantedScopes, } from "./scope";
1
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, MAX_OIDC_SCOPE_LENGTH, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
2
+ export type { OidcReservedScope, OidcSupportedScope, OidcScope, ParsedOidcScopes, GrantedScopes, } from "./scope";
3
3
  export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
4
4
  export type { OidcNonce } from "./nonce";
5
5
  export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
@@ -1,4 +1,4 @@
1
- export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
1
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, DEFAULT_AUTH_SCOPE, OIDC_SCOPE_REGEX, MAX_OIDC_SCOPE_LENGTH, oidcScopeSchema, parseAndGrantScopes, grantRequestedScopes, partitionGrantedScopes, serializeOidcScopes, serializeOidcScopesOrNull, } from "./scope";
2
2
  export { oidcNonceSchema, OIDC_NONCE_VSCHAR_REGEX, parseOidcNonce, OidcNonceValidationError, } from "./nonce";
3
3
  export { OIDC_SUB_CLAIM_DELIMITER, formatOidcSubClaim, parseOidcSubClaim, } from "./sub-claim";
4
4
  export { buildOidcProfileClaims } from "./profile-claims";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAQjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,GACvC,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oidc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AASjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,yBAAyB,EACzB,uCAAuC,EACvC,iCAAiC,EACjC,kCAAkC,EAClC,wCAAwC,EACxC,yCAAyC,EACzC,iCAAiC,GAClC,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAMhE,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,0CAA0C,EAC1C,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,GACvC,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const OIDC_OPENID_SCOPE: "openid";
2
+ export declare const OIDC_SUPPORTED_SCOPES: readonly ["openid", "email", "profile"];
3
+ /**
4
+ * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
5
+ * server may define one of them as an API scope (even those this server
6
+ * does not support yet), so a granted scope string always splits
7
+ * unambiguously into its OIDC part and its API part
8
+ * (`partitionGrantedScopes`).
9
+ */
10
+ export declare const OIDC_RESERVED_SCOPES: readonly ["openid", "profile", "email", "address", "phone", "offline_access"];
11
+ export type OidcReservedScope = (typeof OIDC_RESERVED_SCOPES)[number];
12
+ export declare function isOidcReservedScope(scope: string): boolean;
@@ -0,0 +1,23 @@
1
+ // The OpenID Connect scope names, without zod: imported by the
2
+ // dependency-free `scopes/` module as well as `./scope`.
3
+ export const OIDC_OPENID_SCOPE = "openid";
4
+ export const OIDC_SUPPORTED_SCOPES = ["openid", "email", "profile"];
5
+ /**
6
+ * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
7
+ * server may define one of them as an API scope (even those this server
8
+ * does not support yet), so a granted scope string always splits
9
+ * unambiguously into its OIDC part and its API part
10
+ * (`partitionGrantedScopes`).
11
+ */
12
+ export const OIDC_RESERVED_SCOPES = [
13
+ "openid",
14
+ "profile",
15
+ "email",
16
+ "address",
17
+ "phone",
18
+ "offline_access",
19
+ ];
20
+ export function isOidcReservedScope(scope) {
21
+ return OIDC_RESERVED_SCOPES.includes(scope);
22
+ }
23
+ //# sourceMappingURL=scope-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-names.js","sourceRoot":"","sources":["../../src/oidc/scope-names.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,yDAAyD;AAEzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;CACR,CAAC;AAIX,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
@@ -25,17 +25,9 @@
25
25
  * unknown scopes and dropped exactly as before.
26
26
  */
27
27
  import { z } from "zod";
28
- export declare const OIDC_OPENID_SCOPE: "openid";
29
- export declare const OIDC_SUPPORTED_SCOPES: readonly ["openid", "email", "profile"];
30
- /**
31
- * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
32
- * server may define one of them as an API scope (even those this server
33
- * does not support yet), so a granted scope string always splits
34
- * unambiguously into its OIDC part and its API part
35
- * (`partitionGrantedScopes`).
36
- */
37
- export declare const OIDC_RESERVED_SCOPES: readonly ["openid", "profile", "email", "address", "phone", "offline_access"];
38
- export declare function isOidcReservedScope(scope: string): boolean;
28
+ import { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope } from "./scope-names";
29
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope };
30
+ export type { OidcReservedScope } from "./scope-names";
39
31
  /**
40
32
  * Scope requested by default when a flow does not name one explicitly:
41
33
  * the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
@@ -43,6 +35,22 @@ export declare function isOidcReservedScope(scope: string): boolean;
43
35
  * `scope` parameter (e.g. the auth server's own /account flow).
44
36
  */
45
37
  export declare const DEFAULT_AUTH_SCOPE: "openid email profile";
38
+ /**
39
+ * Upper bound on a `scope` value: the request parameter (authorize, login,
40
+ * register, token grants) and the `scope` claim of the tokens it grants
41
+ * (`@schemavaults/jwt`'s payload schema), which never exceeds what was
42
+ * asked for.
43
+ *
44
+ * Room for an API server's whole scope list beside the OIDC scopes (a
45
+ * resource server with three dozen `area:action` scopes asks for ~600
46
+ * characters at sign-in), while a refresh token carrying a scope this long
47
+ * still fits the 4 KB cookie the server SDK keeps it in
48
+ * (`MaximumBrowserCookieSize`; ~3.7 KB at this length, ~5 KB at twice it).
49
+ * The same as the longest `scope` a dynamically registered client may
50
+ * register (`DYNAMIC_CLIENT_SCOPE_MAX_LENGTH`), so such a client can ask
51
+ * for all of it.
52
+ */
53
+ export declare const MAX_OIDC_SCOPE_LENGTH: 1024;
46
54
  /**
47
55
  * RFC 6749 §3.3 wire format for the `scope` parameter:
48
56
  * scope = scope-token *( SP scope-token )
@@ -25,26 +25,10 @@
25
25
  * unknown scopes and dropped exactly as before.
26
26
  */
27
27
  import { z } from "zod";
28
- export const OIDC_OPENID_SCOPE = "openid";
29
- export const OIDC_SUPPORTED_SCOPES = ["openid", "email", "profile"];
30
- /**
31
- * The scope values OpenID Connect Core §5.4 / §11 standardize. No API
32
- * server may define one of them as an API scope (even those this server
33
- * does not support yet), so a granted scope string always splits
34
- * unambiguously into its OIDC part and its API part
35
- * (`partitionGrantedScopes`).
36
- */
37
- export const OIDC_RESERVED_SCOPES = [
38
- "openid",
39
- "profile",
40
- "email",
41
- "address",
42
- "phone",
43
- "offline_access",
44
- ];
45
- export function isOidcReservedScope(scope) {
46
- return OIDC_RESERVED_SCOPES.includes(scope);
47
- }
28
+ import { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "./scope-names";
29
+ // The scope names live in ./scope-names (no zod) so the dependency-free
30
+ // `@schemavaults/auth-common/scopes` entry point can build on them.
31
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope };
48
32
  /**
49
33
  * Scope requested by default when a flow does not name one explicitly:
50
34
  * the SDK's `authenticateWithRedirect`/`sendAuthenticateRequest`
@@ -52,7 +36,22 @@ export function isOidcReservedScope(scope) {
52
36
  * `scope` parameter (e.g. the auth server's own /account flow).
53
37
  */
54
38
  export const DEFAULT_AUTH_SCOPE = "openid email profile";
55
- const MAX_OIDC_SCOPE_LENGTH = 256;
39
+ /**
40
+ * Upper bound on a `scope` value: the request parameter (authorize, login,
41
+ * register, token grants) and the `scope` claim of the tokens it grants
42
+ * (`@schemavaults/jwt`'s payload schema), which never exceeds what was
43
+ * asked for.
44
+ *
45
+ * Room for an API server's whole scope list beside the OIDC scopes (a
46
+ * resource server with three dozen `area:action` scopes asks for ~600
47
+ * characters at sign-in), while a refresh token carrying a scope this long
48
+ * still fits the 4 KB cookie the server SDK keeps it in
49
+ * (`MaximumBrowserCookieSize`; ~3.7 KB at this length, ~5 KB at twice it).
50
+ * The same as the longest `scope` a dynamically registered client may
51
+ * register (`DYNAMIC_CLIENT_SCOPE_MAX_LENGTH`), so such a client can ask
52
+ * for all of it.
53
+ */
54
+ export const MAX_OIDC_SCOPE_LENGTH = 1024;
56
55
  /**
57
56
  * RFC 6749 §3.3 wire format for the `scope` parameter:
58
57
  * scope = scope-token *( SP scope-token )
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/oidc/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;CACR,CAAC;AAEX,MAAM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AK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/D,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAyB;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAyB;IAEzB,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, } from "./scope-definition";
2
+ export type { DefinedScopes, ScopeDefinition, ScopeRequirement } from "./scope-definition";
3
+ export { oidcScopes } from "./oidc-scopes";
4
+ export { parseScope, formatScope, missingFromScope, scopeIncludes } from "./scope-string";
5
+ export type { GrantedScopeInput, ScopeInput } from "./scope-string";
6
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "../oidc/scope-names";
7
+ export type { OidcReservedScope } from "../oidc/scope-names";
@@ -0,0 +1,7 @@
1
+ // `@schemavaults/auth-common/scopes`: scope definitions and scope-string
2
+ // helpers with no runtime dependencies (no zod), safe in client bundles.
3
+ export { SCOPE_TOKEN_REGEX, isScopeToken, isScopeDefinition, scopeDefinitionProblem, MAX_SCOPE_VALUE_LENGTH, MAX_SCOPE_DESCRIPTION_LENGTH, scopeValue, scopeValues, defineScope, defineScopes, } from "./scope-definition";
4
+ export { oidcScopes } from "./oidc-scopes";
5
+ export { parseScope, formatScope, missingFromScope, scopeIncludes } from "./scope-string";
6
+ export { OIDC_OPENID_SCOPE, OIDC_SUPPORTED_SCOPES, OIDC_RESERVED_SCOPES, isOidcReservedScope, } from "../oidc/scope-names";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1F,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type OidcReservedScope } from "../oidc/scope-names";
2
+ import { type ScopeDefinition } from "./scope-definition";
3
+ /**
4
+ * The OpenID Connect scopes (`OIDC_RESERVED_SCOPES`, OpenID Connect Core
5
+ * §5.4, §11) as definitions, keyed by their value: `oidcScopes.email`.
6
+ *
7
+ * Their values are reserved, so they never belong in an API server's scope
8
+ * manifest: sync your own `defineScopes()` catalogue, not these.
9
+ */
10
+ export declare const oidcScopes: {
11
+ readonly [K in OidcReservedScope]: ScopeDefinition<K>;
12
+ };
@@ -0,0 +1,23 @@
1
+ import { OIDC_RESERVED_SCOPES } from "../oidc/scope-names";
2
+ import { defineScopes } from "./scope-definition";
3
+ /** What each OpenID Connect scope allows, as a person granting it reads it. */
4
+ const OIDC_SCOPE_DESCRIPTIONS = {
5
+ openid: "Sign you in with OpenID Connect",
6
+ profile: "Read your basic profile, such as your name",
7
+ email: "Read your email address",
8
+ address: "Read your postal address",
9
+ phone: "Read your phone number",
10
+ offline_access: "Keep access while you are not using the app (refresh tokens)",
11
+ };
12
+ /**
13
+ * The OpenID Connect scopes (`OIDC_RESERVED_SCOPES`, OpenID Connect Core
14
+ * §5.4, §11) as definitions, keyed by their value: `oidcScopes.email`.
15
+ *
16
+ * Their values are reserved, so they never belong in an API server's scope
17
+ * manifest: sync your own `defineScopes()` catalogue, not these.
18
+ */
19
+ export const oidcScopes = defineScopes(Object.fromEntries(OIDC_RESERVED_SCOPES.map((scope) => [
20
+ scope,
21
+ { scope, description: OIDC_SCOPE_DESCRIPTIONS[scope] },
22
+ ])));
23
+ //# sourceMappingURL=oidc-scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc-scopes.js","sourceRoot":"","sources":["../../src/scopes/oidc-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAwB,MAAM,oBAAoB,CAAC;AAExE,+EAA+E;AAC/E,MAAM,uBAAuB,GAAG;IAC9B,MAAM,EAAE,iCAAiC;IACzC,OAAO,EAAE,4CAA4C;IACrD,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,wBAAwB;IAC/B,cAAc,EAAE,8DAA8D;CAC1B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAA8D,YAAY,CAC/F,MAAM,CAAC,WAAW,CAChB,oBAAoB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IAClC,KAAK;IACL,EAAE,KAAK,EAAE,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,EAAE;CACvD,CAAC,CAC0D,CAC/D,CAAC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * OAuth 2.0 scopes as first-class values: a scope is declared once, as a
3
+ * {@link ScopeDefinition} saying what it allows, and that definition is
4
+ * what everything else takes:
5
+ *
6
+ * - `@schemavaults/openapi-operations`: `requireAuth({ requiredScopes })`,
7
+ * the OpenAPI document's `x-schemavaults-scopes` and the docs UI;
8
+ * - `@schemavaults/auth-client-sdk`: `login({ scope })` / `register()`, the
9
+ * client's `authorization_params.scope`, `sendAuthenticateRequest()`;
10
+ * - `@schemavaults/auth-server-sdk`: route guards' `required_scopes`,
11
+ * `exchangeTokenForDelegatedToken({ scope })`, and a scope manifest
12
+ * (`syncApiServerScopes({ scopes })`), whose entries definitions are.
13
+ *
14
+ * Bare scope strings are accepted wherever a definition is. This module
15
+ * (`@schemavaults/auth-common/scopes`) has no runtime dependencies, so
16
+ * client components can import a scope catalogue without pulling zod in.
17
+ */
18
+ /**
19
+ * RFC 6749 §3.3 `scope-token`: one or more printable ASCII characters other
20
+ * than space, `"` and `\`. A token's `scope` claim is a space separated list
21
+ * of them, so a required scope outside this grammar could never be granted.
22
+ */
23
+ export declare const SCOPE_TOKEN_REGEX: RegExp;
24
+ /** Whether `value` is a single RFC 6749 scope-token (e.g. `notes:read`, `email`). */
25
+ export declare function isScopeToken(value: unknown): value is string;
26
+ /**
27
+ * Longest scope value a definition may have: the most an API server may
28
+ * define on the auth server (`MAX_API_SCOPE_VALUE_LENGTH` is this value).
29
+ */
30
+ export declare const MAX_SCOPE_VALUE_LENGTH: 128;
31
+ /**
32
+ * Longest description a definition may have, once trimmed: the most a
33
+ * consent screen shows (`MAX_API_SCOPE_DESCRIPTION_LENGTH` is this value).
34
+ */
35
+ export declare const MAX_SCOPE_DESCRIPTION_LENGTH: 256;
36
+ /**
37
+ * A scope value plus what it allows. Exactly `{ scope, description }`, the
38
+ * shape of a SchemaVaults scope manifest entry, so a list of definitions can
39
+ * be handed to `syncApiServerScopes({ scopes })` from
40
+ * `@schemavaults/auth-server-sdk/api-scopes` as it is.
41
+ */
42
+ export interface ScopeDefinition<TScope extends string = string> {
43
+ /** The scope value as it appears in a token's space separated `scope` claim. */
44
+ readonly scope: TScope;
45
+ /**
46
+ * What the scope lets a token do, written for the person granting it
47
+ * ("Read your notes"): shown in API docs and, once synced, on the auth
48
+ * server's consent screen.
49
+ */
50
+ readonly description: string;
51
+ }
52
+ /** A required scope: a bare scope value, or a {@link ScopeDefinition} describing it. */
53
+ export type ScopeRequirement<TScope extends string = string> = TScope | ScopeDefinition<TScope>;
54
+ /**
55
+ * Why `value` is not a valid scope definition, or null when it is one: an
56
+ * object whose `scope` is a single RFC 6749 scope-token of at most
57
+ * {@link MAX_SCOPE_VALUE_LENGTH} characters and whose `description`, once
58
+ * trimmed, has 1 to {@link MAX_SCOPE_DESCRIPTION_LENGTH} characters (the
59
+ * rules the auth server applies to the scopes an API server defines).
60
+ * `defineScope()` throws this message; {@link isScopeDefinition} is it as a
61
+ * type guard.
62
+ */
63
+ export declare function scopeDefinitionProblem(value: unknown): string | null;
64
+ /**
65
+ * Whether `value` is a valid {@link ScopeDefinition}: see
66
+ * {@link scopeDefinitionProblem} for the rules. Every definition
67
+ * `defineScope()` returns passes it, and so does a hand-written
68
+ * `{ scope, description }` that follows the same rules.
69
+ */
70
+ export declare function isScopeDefinition(value: unknown): value is ScopeDefinition;
71
+ /** The scope value of a requirement. */
72
+ export declare function scopeValue(requirement: ScopeRequirement): string;
73
+ /** The scope values of a list of requirements, in order (empty for `undefined`). */
74
+ export declare function scopeValues(requirements: readonly ScopeRequirement[] | undefined): string[];
75
+ /**
76
+ * Declares one scope. Throws a `TypeError` naming the problem when the
77
+ * definition breaks the rules of {@link scopeDefinitionProblem} (a single
78
+ * RFC 6749 scope-token of at most 128 characters, a description of 1 to 256
79
+ * characters once trimmed); the description is stored trimmed.
80
+ *
81
+ * ```ts
82
+ * export const notesRead = defineScope({ scope: "notes:read", description: "Read your notes" });
83
+ * ```
84
+ */
85
+ export declare function defineScope<const TScope extends string>(definition: ScopeDefinition<TScope>): ScopeDefinition<TScope>;
86
+ /** The result of {@link defineScopes}: the same keys, each a frozen {@link ScopeDefinition}. */
87
+ export type DefinedScopes<T extends Readonly<Record<string, ScopeDefinition>>> = {
88
+ readonly [K in keyof T]: ScopeDefinition<T[K]["scope"]>;
89
+ };
90
+ /**
91
+ * Declares an API's scopes at once, keyed by a name of your choosing, and
92
+ * refuses a scope value listed twice:
93
+ *
94
+ * ```ts
95
+ * export const notesScopes = defineScopes({
96
+ * read: { scope: "notes:read", description: "Read your notes" },
97
+ * write: { scope: "notes:write", description: "Create and edit your notes" },
98
+ * });
99
+ *
100
+ * requireAuth({ schemes, requiredScopes: [notesScopes.read] });
101
+ * ```
102
+ *
103
+ * `Object.values(notesScopes)` lists them all, e.g. for
104
+ * `buildOpenApiDocument({ additionalScopes })` or a scope manifest.
105
+ */
106
+ export declare function defineScopes<const T extends Readonly<Record<string, ScopeDefinition>>>(definitions: T): DefinedScopes<T>;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * OAuth 2.0 scopes as first-class values: a scope is declared once, as a
3
+ * {@link ScopeDefinition} saying what it allows, and that definition is
4
+ * what everything else takes:
5
+ *
6
+ * - `@schemavaults/openapi-operations`: `requireAuth({ requiredScopes })`,
7
+ * the OpenAPI document's `x-schemavaults-scopes` and the docs UI;
8
+ * - `@schemavaults/auth-client-sdk`: `login({ scope })` / `register()`, the
9
+ * client's `authorization_params.scope`, `sendAuthenticateRequest()`;
10
+ * - `@schemavaults/auth-server-sdk`: route guards' `required_scopes`,
11
+ * `exchangeTokenForDelegatedToken({ scope })`, and a scope manifest
12
+ * (`syncApiServerScopes({ scopes })`), whose entries definitions are.
13
+ *
14
+ * Bare scope strings are accepted wherever a definition is. This module
15
+ * (`@schemavaults/auth-common/scopes`) has no runtime dependencies, so
16
+ * client components can import a scope catalogue without pulling zod in.
17
+ */
18
+ /**
19
+ * RFC 6749 §3.3 `scope-token`: one or more printable ASCII characters other
20
+ * than space, `"` and `\`. A token's `scope` claim is a space separated list
21
+ * of them, so a required scope outside this grammar could never be granted.
22
+ */
23
+ export const SCOPE_TOKEN_REGEX = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
24
+ /** Whether `value` is a single RFC 6749 scope-token (e.g. `notes:read`, `email`). */
25
+ export function isScopeToken(value) {
26
+ return typeof value === "string" && SCOPE_TOKEN_REGEX.test(value);
27
+ }
28
+ /**
29
+ * Longest scope value a definition may have: the most an API server may
30
+ * define on the auth server (`MAX_API_SCOPE_VALUE_LENGTH` is this value).
31
+ */
32
+ export const MAX_SCOPE_VALUE_LENGTH = 128;
33
+ /**
34
+ * Longest description a definition may have, once trimmed: the most a
35
+ * consent screen shows (`MAX_API_SCOPE_DESCRIPTION_LENGTH` is this value).
36
+ */
37
+ export const MAX_SCOPE_DESCRIPTION_LENGTH = 256;
38
+ /** A scope value shortened for an error message. */
39
+ function quoteScope(scope) {
40
+ return scope.length > 64 ? `"${scope.slice(0, 64)}…"` : `"${scope}"`;
41
+ }
42
+ /**
43
+ * Why `value` is not a valid scope definition, or null when it is one: an
44
+ * object whose `scope` is a single RFC 6749 scope-token of at most
45
+ * {@link MAX_SCOPE_VALUE_LENGTH} characters and whose `description`, once
46
+ * trimmed, has 1 to {@link MAX_SCOPE_DESCRIPTION_LENGTH} characters (the
47
+ * rules the auth server applies to the scopes an API server defines).
48
+ * `defineScope()` throws this message; {@link isScopeDefinition} is it as a
49
+ * type guard.
50
+ */
51
+ export function scopeDefinitionProblem(value) {
52
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
53
+ return "A scope definition must be an object { scope, description }";
54
+ }
55
+ const { scope, description } = value;
56
+ if (typeof scope !== "string") {
57
+ return "A scope definition's scope must be a string";
58
+ }
59
+ if (!isScopeToken(scope)) {
60
+ return `Scope ${quoteScope(scope)} is not a single RFC 6749 scope-token (printable ASCII without spaces, '"' or '\\')`;
61
+ }
62
+ if (scope.length > MAX_SCOPE_VALUE_LENGTH) {
63
+ return `Scope ${quoteScope(scope)} is ${scope.length} characters long; a scope is at most ${MAX_SCOPE_VALUE_LENGTH}`;
64
+ }
65
+ if (typeof description !== "string" || description.trim().length === 0) {
66
+ return `Scope "${scope}" needs a non-empty description`;
67
+ }
68
+ const trimmed = description.trim().length;
69
+ if (trimmed > MAX_SCOPE_DESCRIPTION_LENGTH) {
70
+ return `The description of scope "${scope}" is ${trimmed} characters long; a description is at most ${MAX_SCOPE_DESCRIPTION_LENGTH}`;
71
+ }
72
+ return null;
73
+ }
74
+ /**
75
+ * Whether `value` is a valid {@link ScopeDefinition}: see
76
+ * {@link scopeDefinitionProblem} for the rules. Every definition
77
+ * `defineScope()` returns passes it, and so does a hand-written
78
+ * `{ scope, description }` that follows the same rules.
79
+ */
80
+ export function isScopeDefinition(value) {
81
+ return scopeDefinitionProblem(value) === null;
82
+ }
83
+ /** The scope value of a requirement. */
84
+ export function scopeValue(requirement) {
85
+ return typeof requirement === "string" ? requirement : requirement.scope;
86
+ }
87
+ /** The scope values of a list of requirements, in order (empty for `undefined`). */
88
+ export function scopeValues(requirements) {
89
+ return (requirements ?? []).map(scopeValue);
90
+ }
91
+ /**
92
+ * Declares one scope. Throws a `TypeError` naming the problem when the
93
+ * definition breaks the rules of {@link scopeDefinitionProblem} (a single
94
+ * RFC 6749 scope-token of at most 128 characters, a description of 1 to 256
95
+ * characters once trimmed); the description is stored trimmed.
96
+ *
97
+ * ```ts
98
+ * export const notesRead = defineScope({ scope: "notes:read", description: "Read your notes" });
99
+ * ```
100
+ */
101
+ export function defineScope(definition) {
102
+ const problem = scopeDefinitionProblem(definition);
103
+ if (problem !== null) {
104
+ throw new TypeError(problem);
105
+ }
106
+ return Object.freeze({ scope: definition.scope, description: definition.description.trim() });
107
+ }
108
+ /**
109
+ * Declares an API's scopes at once, keyed by a name of your choosing, and
110
+ * refuses a scope value listed twice:
111
+ *
112
+ * ```ts
113
+ * export const notesScopes = defineScopes({
114
+ * read: { scope: "notes:read", description: "Read your notes" },
115
+ * write: { scope: "notes:write", description: "Create and edit your notes" },
116
+ * });
117
+ *
118
+ * requireAuth({ schemes, requiredScopes: [notesScopes.read] });
119
+ * ```
120
+ *
121
+ * `Object.values(notesScopes)` lists them all, e.g. for
122
+ * `buildOpenApiDocument({ additionalScopes })` or a scope manifest.
123
+ */
124
+ export function defineScopes(definitions) {
125
+ const seen = new Map();
126
+ const result = {};
127
+ for (const [key, definition] of Object.entries(definitions)) {
128
+ const defined = defineScope(definition);
129
+ const previous = seen.get(defined.scope);
130
+ if (previous !== undefined) {
131
+ throw new TypeError(`Scope "${defined.scope}" is defined twice (as "${previous}" and "${key}")`);
132
+ }
133
+ seen.set(defined.scope, key);
134
+ result[key] = defined;
135
+ }
136
+ return Object.freeze(result);
137
+ }
138
+ //# sourceMappingURL=scope-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-definition.js","sourceRoot":"","sources":["../../src/scopes/scope-definition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW,6BAA6B,CAAC;AAEvE,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAY,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAY,CAAC;AAsBzD,oDAAoD;AACpD,SAAS,UA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M,IAAI,SAAS,CACjB,UAAU,OAAO,CAAC,KAAK,2BAA2B,QAAQ,UAAU,GAAG,IAAI,CAC5E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAqB,CAAC;AACnD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type ScopeRequirement } from "./scope-definition";
2
+ /**
3
+ * A scope as SDK options take it: the space-delimited wire form
4
+ * (`"openid notes:read"`), or a list of scope values and definitions
5
+ * (`[oidcScopes.openid, notesScopes.read]`).
6
+ */
7
+ export type ScopeInput = string | readonly ScopeRequirement[];
8
+ /** A granted scope: a token's space-delimited `scope` claim, or its values. */
9
+ export type GrantedScopeInput = string | readonly string[] | null | undefined;
10
+ /**
11
+ * The values of a scope, in order and each once: a space-delimited string
12
+ * (RFC 6749 §3.3) is split, a list is taken as it is. `null` / `undefined`
13
+ * (a token without a `scope` claim) is the empty scope.
14
+ */
15
+ export declare function parseScope(scope: GrantedScopeInput): string[];
16
+ /**
17
+ * The space-delimited wire form of a scope (RFC 6749 §3.3): its values
18
+ * joined by single spaces, in order, each once. An empty list is `""`.
19
+ *
20
+ * ```ts
21
+ * formatScope([oidcScopes.openid, notesScopes.read, "email"]); // "openid notes:read email"
22
+ * ```
23
+ */
24
+ export declare function formatScope(scope: ScopeInput): string;
25
+ /** The `required` scope values the granted scope lacks, in order. */
26
+ export declare function missingFromScope(granted: GrantedScopeInput, required: readonly ScopeRequirement[]): string[];
27
+ /**
28
+ * Whether the granted scope includes every one of the required scopes
29
+ * (values or definitions). With none required it is true, even for a token
30
+ * without a scope claim.
31
+ */
32
+ export declare function scopeIncludes(granted: GrantedScopeInput, ...required: readonly ScopeRequirement[]): boolean;
@@ -0,0 +1,42 @@
1
+ import { scopeValues } from "./scope-definition";
2
+ function splitScope(value) {
3
+ return value.split(/\s+/).filter((token) => token.length > 0);
4
+ }
5
+ function unique(values) {
6
+ return [...new Set(values)];
7
+ }
8
+ /**
9
+ * The values of a scope, in order and each once: a space-delimited string
10
+ * (RFC 6749 §3.3) is split, a list is taken as it is. `null` / `undefined`
11
+ * (a token without a `scope` claim) is the empty scope.
12
+ */
13
+ export function parseScope(scope) {
14
+ if (scope === null || scope === undefined)
15
+ return [];
16
+ return unique(typeof scope === "string" ? splitScope(scope) : scope.flatMap(splitScope));
17
+ }
18
+ /**
19
+ * The space-delimited wire form of a scope (RFC 6749 §3.3): its values
20
+ * joined by single spaces, in order, each once. An empty list is `""`.
21
+ *
22
+ * ```ts
23
+ * formatScope([oidcScopes.openid, notesScopes.read, "email"]); // "openid notes:read email"
24
+ * ```
25
+ */
26
+ export function formatScope(scope) {
27
+ return parseScope(typeof scope === "string" ? scope : scopeValues(scope)).join(" ");
28
+ }
29
+ /** The `required` scope values the granted scope lacks, in order. */
30
+ export function missingFromScope(granted, required) {
31
+ const values = new Set(parseScope(granted));
32
+ return scopeValues(required).filter((scope) => !values.has(scope));
33
+ }
34
+ /**
35
+ * Whether the granted scope includes every one of the required scopes
36
+ * (values or definitions). With none required it is true, even for a token
37
+ * without a scope claim.
38
+ */
39
+ export function scopeIncludes(granted, ...required) {
40
+ return missingFromScope(granted, required).length === 0;
41
+ }
42
+ //# sourceMappingURL=scope-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-string.js","sourceRoot":"","sources":["../../src/scopes/scope-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,oBAAoB,CAAC;AAYxE,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,MAAM,CAAC,MAAyB;IACvC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,UAAU,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAC9B,OAA0B,EAC1B,QAAqC;IAErC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA0B,EAC1B,GAAG,QAAqC;IAExC,OAAO,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC1D,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schemavaults/auth-common",
3
3
  "description": "Types and utility functions for authentication and authorization",
4
- "version": "0.39.0",
4
+ "version": "0.40.1",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "repository": {
@@ -72,6 +72,11 @@
72
72
  "import": "./dist/auth-error-message-catalog.js",
73
73
  "require": "./dist/auth-error-message-catalog.js"
74
74
  },
75
+ "./scopes": {
76
+ "types": "./dist/scopes/index.d.ts",
77
+ "import": "./dist/scopes/index.js",
78
+ "require": "./dist/scopes/index.js"
79
+ },
75
80
  "./organizations": {
76
81
  "types": "./dist/organizations/index.d.ts",
77
82
  "import": "./dist/organizations/index.js",