@atcute/oauth-types 0.1.1 → 1.0.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.
Files changed (153) hide show
  1. package/README.md +6 -5
  2. package/dist/build-client-metadata.d.ts +5 -320
  3. package/dist/build-client-metadata.d.ts.map +1 -1
  4. package/dist/build-client-metadata.js +3 -2
  5. package/dist/build-client-metadata.js.map +1 -1
  6. package/dist/index.d.ts +31 -31
  7. package/dist/schemas/atcute-client-shared.d.ts +8 -0
  8. package/dist/schemas/atcute-client-shared.d.ts.map +1 -0
  9. package/dist/schemas/atcute-client-shared.js +15 -0
  10. package/dist/schemas/atcute-client-shared.js.map +1 -0
  11. package/dist/schemas/atcute-confidential-client-metadata.d.ts +228 -4
  12. package/dist/schemas/atcute-confidential-client-metadata.d.ts.map +1 -1
  13. package/dist/schemas/atcute-confidential-client-metadata.js +48 -88
  14. package/dist/schemas/atcute-confidential-client-metadata.js.map +1 -1
  15. package/dist/schemas/atcute-public-client-metadata.d.ts +75 -35
  16. package/dist/schemas/atcute-public-client-metadata.d.ts.map +1 -1
  17. package/dist/schemas/atcute-public-client-metadata.js +25 -110
  18. package/dist/schemas/atcute-public-client-metadata.js.map +1 -1
  19. package/dist/schemas/atproto-authorization-server-metadata.d.ts +786 -4
  20. package/dist/schemas/atproto-authorization-server-metadata.d.ts.map +1 -1
  21. package/dist/schemas/atproto-authorization-server-metadata.js +2 -18
  22. package/dist/schemas/atproto-authorization-server-metadata.js.map +1 -1
  23. package/dist/schemas/atproto-oauth-scope.d.ts +3 -3
  24. package/dist/schemas/atproto-oauth-scope.d.ts.map +1 -1
  25. package/dist/schemas/atproto-oauth-scope.js +2 -2
  26. package/dist/schemas/atproto-oauth-scope.js.map +1 -1
  27. package/dist/schemas/atproto-oauth-token-response.d.ts +17 -17
  28. package/dist/schemas/atproto-oauth-token-response.d.ts.map +1 -1
  29. package/dist/schemas/atproto-oauth-token-response.js +6 -6
  30. package/dist/schemas/atproto-oauth-token-response.js.map +1 -1
  31. package/dist/schemas/atproto-protected-resource-metadata.d.ts +100 -4
  32. package/dist/schemas/atproto-protected-resource-metadata.d.ts.map +1 -1
  33. package/dist/schemas/atproto-protected-resource-metadata.js +2 -11
  34. package/dist/schemas/atproto-protected-resource-metadata.js.map +1 -1
  35. package/dist/schemas/jwk.d.ts +4289 -42
  36. package/dist/schemas/jwk.d.ts.map +1 -1
  37. package/dist/schemas/jwk.js +58 -91
  38. package/dist/schemas/jwk.js.map +1 -1
  39. package/dist/schemas/jwks.d.ts +87 -42
  40. package/dist/schemas/jwks.d.ts.map +1 -1
  41. package/dist/schemas/jwks.js +13 -29
  42. package/dist/schemas/jwks.js.map +1 -1
  43. package/dist/schemas/oauth-authorization-details.d.ts +18 -18
  44. package/dist/schemas/oauth-authorization-details.d.ts.map +1 -1
  45. package/dist/schemas/oauth-authorization-details.js +7 -7
  46. package/dist/schemas/oauth-authorization-details.js.map +1 -1
  47. package/dist/schemas/oauth-authorization-server-metadata.d.ts +462 -48
  48. package/dist/schemas/oauth-authorization-server-metadata.d.ts.map +1 -1
  49. package/dist/schemas/oauth-authorization-server-metadata.js +46 -65
  50. package/dist/schemas/oauth-authorization-server-metadata.js.map +1 -1
  51. package/dist/schemas/oauth-client-id-discoverable.d.ts +2 -2
  52. package/dist/schemas/oauth-client-id-discoverable.d.ts.map +1 -1
  53. package/dist/schemas/oauth-client-id-discoverable.js +20 -22
  54. package/dist/schemas/oauth-client-id-discoverable.js.map +1 -1
  55. package/dist/schemas/oauth-client-id.d.ts +3 -3
  56. package/dist/schemas/oauth-client-id.d.ts.map +1 -1
  57. package/dist/schemas/oauth-client-id.js +2 -2
  58. package/dist/schemas/oauth-client-id.js.map +1 -1
  59. package/dist/schemas/oauth-client-metadata.d.ts +73 -51
  60. package/dist/schemas/oauth-client-metadata.d.ts.map +1 -1
  61. package/dist/schemas/oauth-client-metadata.js +33 -40
  62. package/dist/schemas/oauth-client-metadata.js.map +1 -1
  63. package/dist/schemas/oauth-code-challenge-method.d.ts +3 -3
  64. package/dist/schemas/oauth-code-challenge-method.d.ts.map +1 -1
  65. package/dist/schemas/oauth-code-challenge-method.js +2 -2
  66. package/dist/schemas/oauth-code-challenge-method.js.map +1 -1
  67. package/dist/schemas/oauth-endpoint-auth-method.d.ts +3 -3
  68. package/dist/schemas/oauth-endpoint-auth-method.d.ts.map +1 -1
  69. package/dist/schemas/oauth-endpoint-auth-method.js +10 -2
  70. package/dist/schemas/oauth-endpoint-auth-method.js.map +1 -1
  71. package/dist/schemas/oauth-grant-type.d.ts +3 -3
  72. package/dist/schemas/oauth-grant-type.d.ts.map +1 -1
  73. package/dist/schemas/oauth-grant-type.js +10 -3
  74. package/dist/schemas/oauth-grant-type.js.map +1 -1
  75. package/dist/schemas/oauth-issuer-identifier.d.ts +3 -3
  76. package/dist/schemas/oauth-issuer-identifier.d.ts.map +1 -1
  77. package/dist/schemas/oauth-issuer-identifier.js +16 -9
  78. package/dist/schemas/oauth-issuer-identifier.js.map +1 -1
  79. package/dist/schemas/oauth-par-response.d.ts +5 -5
  80. package/dist/schemas/oauth-par-response.d.ts.map +1 -1
  81. package/dist/schemas/oauth-par-response.js +3 -3
  82. package/dist/schemas/oauth-par-response.js.map +1 -1
  83. package/dist/schemas/oauth-prompt.d.ts +3 -3
  84. package/dist/schemas/oauth-prompt.d.ts.map +1 -1
  85. package/dist/schemas/oauth-prompt.js +2 -2
  86. package/dist/schemas/oauth-prompt.js.map +1 -1
  87. package/dist/schemas/oauth-protected-resource-metadata.d.ts +88 -16
  88. package/dist/schemas/oauth-protected-resource-metadata.d.ts.map +1 -1
  89. package/dist/schemas/oauth-protected-resource-metadata.js +14 -26
  90. package/dist/schemas/oauth-protected-resource-metadata.js.map +1 -1
  91. package/dist/schemas/oauth-redirect-uri.d.ts +5 -5
  92. package/dist/schemas/oauth-redirect-uri.d.ts.map +1 -1
  93. package/dist/schemas/oauth-redirect-uri.js +3 -16
  94. package/dist/schemas/oauth-redirect-uri.js.map +1 -1
  95. package/dist/schemas/oauth-response-mode.d.ts +3 -3
  96. package/dist/schemas/oauth-response-mode.d.ts.map +1 -1
  97. package/dist/schemas/oauth-response-mode.js +2 -2
  98. package/dist/schemas/oauth-response-mode.js.map +1 -1
  99. package/dist/schemas/oauth-response-type.d.ts +3 -3
  100. package/dist/schemas/oauth-response-type.d.ts.map +1 -1
  101. package/dist/schemas/oauth-response-type.js +13 -7
  102. package/dist/schemas/oauth-response-type.js.map +1 -1
  103. package/dist/schemas/oauth-scope.d.ts +3 -3
  104. package/dist/schemas/oauth-scope.d.ts.map +1 -1
  105. package/dist/schemas/oauth-scope.js +2 -2
  106. package/dist/schemas/oauth-scope.js.map +1 -1
  107. package/dist/schemas/oauth-token-response.d.ts +17 -17
  108. package/dist/schemas/oauth-token-response.d.ts.map +1 -1
  109. package/dist/schemas/oauth-token-response.js +7 -7
  110. package/dist/schemas/oauth-token-response.js.map +1 -1
  111. package/dist/schemas/oauth-token-type.d.ts +3 -3
  112. package/dist/schemas/oauth-token-type.d.ts.map +1 -1
  113. package/dist/schemas/oauth-token-type.js +8 -7
  114. package/dist/schemas/oauth-token-type.js.map +1 -1
  115. package/dist/schemas/uri.d.ts +7 -7
  116. package/dist/schemas/uri.d.ts.map +1 -1
  117. package/dist/schemas/uri.js +44 -44
  118. package/dist/schemas/uri.js.map +1 -1
  119. package/dist/schemas/utils.d.ts.map +1 -1
  120. package/dist/schemas/utils.js.map +1 -1
  121. package/dist/scope.d.ts.map +1 -1
  122. package/dist/scope.js.map +1 -1
  123. package/lib/build-client-metadata.ts +9 -7
  124. package/lib/index.ts +31 -31
  125. package/lib/schemas/atcute-client-shared.ts +25 -0
  126. package/lib/schemas/atcute-confidential-client-metadata.ts +81 -111
  127. package/lib/schemas/atcute-public-client-metadata.ts +70 -166
  128. package/lib/schemas/atproto-authorization-server-metadata.ts +22 -23
  129. package/lib/schemas/atproto-oauth-scope.ts +8 -5
  130. package/lib/schemas/atproto-oauth-token-response.ts +10 -9
  131. package/lib/schemas/atproto-protected-resource-metadata.ts +15 -15
  132. package/lib/schemas/jwk.ts +104 -120
  133. package/lib/schemas/jwks.ts +28 -40
  134. package/lib/schemas/oauth-authorization-details.ts +10 -10
  135. package/lib/schemas/oauth-authorization-server-metadata.ts +72 -74
  136. package/lib/schemas/oauth-client-id-discoverable.ts +43 -48
  137. package/lib/schemas/oauth-client-id.ts +3 -3
  138. package/lib/schemas/oauth-client-metadata.ts +45 -49
  139. package/lib/schemas/oauth-code-challenge-method.ts +3 -3
  140. package/lib/schemas/oauth-endpoint-auth-method.ts +11 -11
  141. package/lib/schemas/oauth-grant-type.ts +11 -11
  142. package/lib/schemas/oauth-issuer-identifier.ts +35 -27
  143. package/lib/schemas/oauth-par-response.ts +4 -4
  144. package/lib/schemas/oauth-prompt.ts +3 -9
  145. package/lib/schemas/oauth-protected-resource-metadata.ts +26 -35
  146. package/lib/schemas/oauth-redirect-uri.ts +15 -23
  147. package/lib/schemas/oauth-response-mode.ts +3 -7
  148. package/lib/schemas/oauth-response-type.ts +12 -12
  149. package/lib/schemas/oauth-scope.ts +3 -3
  150. package/lib/schemas/oauth-token-response.ts +10 -10
  151. package/lib/schemas/oauth-token-type.ts +16 -12
  152. package/lib/schemas/uri.ts +89 -76
  153. package/package.json +9 -8
@@ -1,22 +1,22 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { oauthAuthorizationDetailsSchema } from './oauth-authorization-details.js';
4
- import { oauthTokenTypeSchema } from './oauth-token-type.js';
3
+ import { oauthAuthorizationDetailsSchema } from './oauth-authorization-details.ts';
4
+ import { oauthTokenTypeSchema } from './oauth-token-type.ts';
5
5
 
6
6
  /**
7
7
  * @see {@link https://www.rfc-editor.org/rfc/rfc6749.html#section-5.1 | RFC 6749 (OAuth2), Section 5.1}
8
8
  */
9
- export const oauthTokenResponseSchema = v.object({
9
+ export const oauthTokenResponseSchema = v.looseObject({
10
10
  // https://www.rfc-editor.org/rfc/rfc6749.html#section-5.1
11
11
  access_token: v.string(),
12
12
  token_type: oauthTokenTypeSchema,
13
- scope: v.string().optional(),
14
- refresh_token: v.string().optional(),
15
- expires_in: v.number().optional(),
13
+ scope: v.optional(v.string()),
14
+ refresh_token: v.optional(v.string()),
15
+ expires_in: v.optional(v.number()),
16
16
  // https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse
17
- id_token: v.string().optional(),
17
+ id_token: v.optional(v.string()),
18
18
  // https://datatracker.ietf.org/doc/html/rfc9396#name-enriched-authorization-deta
19
- authorization_details: oauthAuthorizationDetailsSchema.optional(),
19
+ authorization_details: v.optional(oauthAuthorizationDetailsSchema),
20
20
  });
21
21
 
22
- export type OAuthTokenResponse = v.Infer<typeof oauthTokenResponseSchema>;
22
+ export type OAuthTokenResponse = v.InferOutput<typeof oauthTokenResponseSchema>;
@@ -1,15 +1,19 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
3
  /** token type (case-insensitive input, normalized output) */
4
- export const oauthTokenTypeSchema = v.string().chain((input) => {
5
- const lower = input.toLowerCase();
6
- if (lower === 'dpop') {
7
- return v.ok('DPoP');
8
- }
9
- if (lower === 'bearer') {
10
- return v.ok('Bearer');
11
- }
12
- return v.err(`must be "DPoP" or "Bearer"`);
13
- });
4
+ export const oauthTokenTypeSchema = v.pipe(
5
+ v.string(),
6
+ v.rawTransform<string, 'DPoP' | 'Bearer'>(({ dataset, addIssue, NEVER }) => {
7
+ const lower = dataset.value.toLowerCase();
8
+ if (lower === 'dpop') {
9
+ return 'DPoP';
10
+ }
11
+ if (lower === 'bearer') {
12
+ return 'Bearer';
13
+ }
14
+ addIssue({ message: `must be "DPoP" or "Bearer"` });
15
+ return NEVER;
16
+ }),
17
+ );
14
18
 
15
- export type OAuthTokenType = v.Infer<typeof oauthTokenTypeSchema>;
19
+ export type OAuthTokenType = v.InferOutput<typeof oauthTokenTypeSchema>;
@@ -1,100 +1,113 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { isHostnameIP, isLocalHostname, isLoopbackHost } from './utils.js';
3
+ import { isHostnameIP, isLocalHostname, isLoopbackHost } from './utils.ts';
4
4
 
5
5
  /**
6
6
  * valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).
7
7
  *
8
8
  * any value that matches this schema is safe to parse using `new URL()`.
9
9
  */
10
- export const urlSchema = v.string().chain((input) => {
11
- if (input.includes(':') && URL.canParse(input)) {
12
- return v.ok(input);
13
- }
14
- return v.err(`must be a valid url`);
15
- });
10
+ export const urlSchema = v.pipe(
11
+ v.string(),
12
+ v.check((input) => input.includes(':') && URL.canParse(input), `must be a valid url`),
13
+ );
16
14
 
17
15
  /** loopback URL (http://localhost, http://127.0.0.1, http://[::1]) */
18
- export const loopbackUriSchema = urlSchema.chain((input) => {
19
- if (!input.startsWith('http://')) {
20
- return v.err(`loopback url must use http: protocol`);
21
- }
22
-
23
- const url = new URL(input);
24
- if (!isLoopbackHost(url.hostname)) {
25
- return v.err(`loopback url must use localhost, 127.0.0.1, or [::1] as hostname`);
26
- }
27
-
28
- return v.ok(input);
29
- });
16
+ export const loopbackUriSchema = v.pipe(
17
+ urlSchema,
18
+ v.rawCheck(({ dataset, addIssue }) => {
19
+ if (!dataset.typed) {
20
+ return;
21
+ }
22
+ const input = dataset.value;
23
+ if (!input.startsWith('http://')) {
24
+ addIssue({ message: `loopback url must use http: protocol` });
25
+ return;
26
+ }
27
+ if (!isLoopbackHost(new URL(input).hostname)) {
28
+ addIssue({ message: `loopback url must use localhost, 127.0.0.1, or [::1] as hostname` });
29
+ }
30
+ }),
31
+ );
30
32
 
31
33
  /** HTTPS URL with additional restrictions */
32
- export const httpsUriSchema = urlSchema.chain((input) => {
33
- if (!input.startsWith('https://')) {
34
- return v.err(`url must use https: protocol`);
35
- }
36
-
37
- const url = new URL(input);
38
-
39
- if (isLoopbackHost(url.hostname)) {
40
- return v.err(`https url must not use a loopback host`);
41
- }
42
-
43
- if (!isHostnameIP(url.hostname)) {
44
- if (!url.hostname.includes('.')) {
45
- return v.err(`domain name must contain at least two segments`);
34
+ export const httpsUriSchema = v.pipe(
35
+ urlSchema,
36
+ v.rawCheck(({ dataset, addIssue }) => {
37
+ if (!dataset.typed) {
38
+ return;
46
39
  }
47
- if (url.hostname.endsWith('.local')) {
48
- return v.err(`domain name must not end with .local`);
40
+ const input = dataset.value;
41
+ if (!input.startsWith('https://')) {
42
+ addIssue({ message: `url must use https: protocol` });
43
+ return;
49
44
  }
50
- }
51
45
 
52
- return v.ok(input);
53
- });
46
+ const url = new URL(input);
54
47
 
55
- /** web URL (either loopback http or https) */
56
- export const webUriSchema = urlSchema.chain((input, options) => {
57
- if (input.startsWith('http://')) {
58
- return loopbackUriSchema.try(input, options);
59
- }
48
+ if (isLoopbackHost(url.hostname)) {
49
+ addIssue({ message: `https url must not use a loopback host` });
50
+ return;
51
+ }
60
52
 
61
- if (input.startsWith('https://')) {
62
- return httpsUriSchema.try(input, options);
63
- }
53
+ if (!isHostnameIP(url.hostname)) {
54
+ if (!url.hostname.includes('.')) {
55
+ addIssue({ message: `domain name must contain at least two segments` });
56
+ return;
57
+ }
58
+ if (url.hostname.endsWith('.local')) {
59
+ addIssue({ message: `domain name must not end with .local` });
60
+ }
61
+ }
62
+ }),
63
+ );
64
64
 
65
- return v.err(`url must use http: or https: protocol`);
66
- });
65
+ /** web URL (either loopback http or https) */
66
+ export const webUriSchema = v.union(
67
+ [loopbackUriSchema, httpsUriSchema],
68
+ `url must use http: or https: protocol`,
69
+ );
67
70
 
68
71
  /** web URL with a non-local hostname */
69
- export const nonLocalWebUriSchema = webUriSchema.chain((input) => {
70
- const url = new URL(input);
71
- if (isLocalHostname(url.hostname)) {
72
- return v.err(`hostname is invalid`);
73
- }
74
- return v.ok(input);
75
- });
72
+ export const nonLocalWebUriSchema = v.pipe(
73
+ webUriSchema,
74
+ v.check((input) => !isLocalHostname(new URL(input).hostname), `hostname is invalid`),
75
+ );
76
76
 
77
77
  /** private-use URI scheme (e.g., com.example.app:/callback) */
78
- export const privateUseUriSchema = urlSchema.chain((input) => {
79
- const dotIdx = input.indexOf('.');
80
- const colonIdx = input.indexOf(':');
81
-
82
- if (dotIdx === -1 || colonIdx === -1 || dotIdx > colonIdx) {
83
- return v.err(`private-use uri scheme must contain a dot in the protocol`);
84
- }
85
-
86
- const url = new URL(input);
87
- const scheme = url.protocol.slice(0, -1);
88
- const domain = scheme.split('.').reverse().join('.');
78
+ export const privateUseUriSchema = v.pipe(
79
+ urlSchema,
80
+ v.rawCheck(({ dataset, addIssue }) => {
81
+ if (!dataset.typed) {
82
+ return;
83
+ }
84
+ const input = dataset.value;
89
85
 
90
- if (isLocalHostname(domain)) {
91
- return v.err(`private-use uri scheme must not be a local hostname`);
92
- }
86
+ const dotIdx = input.indexOf('.');
87
+ const colonIdx = input.indexOf(':');
88
+ if (dotIdx === -1 || colonIdx === -1 || dotIdx > colonIdx) {
89
+ addIssue({ message: `private-use uri scheme must contain a dot in the protocol` });
90
+ return;
91
+ }
93
92
 
94
- // RFC 8252: private-use URIs must use single slash after scheme
95
- if (url.href.startsWith(`${url.protocol}//`) || url.username || url.password || url.hostname || url.port) {
96
- return v.err(`private-use uri must be in the form scheme:/<path>`);
97
- }
93
+ const url = new URL(input);
94
+ const scheme = url.protocol.slice(0, -1);
95
+ // oxlint-disable-next-line unicorn/no-array-reverse -- split already clones
96
+ const domain = scheme.split('.').reverse().join('.');
97
+ if (isLocalHostname(domain)) {
98
+ addIssue({ message: `private-use uri scheme must not be a local hostname` });
99
+ return;
100
+ }
98
101
 
99
- return v.ok(input);
100
- });
102
+ // RFC 8252: private-use URIs must use single slash after scheme
103
+ if (
104
+ url.href.startsWith(`${url.protocol}//`) ||
105
+ url.username ||
106
+ url.password ||
107
+ url.hostname ||
108
+ url.port
109
+ ) {
110
+ addIssue({ message: `private-use uri must be in the form scheme:/<path>` });
111
+ }
112
+ }),
113
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atcute/oauth-types",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "description": "OAuth types and schemas for AT Protocol",
5
5
  "license": "0BSD",
6
6
  "repository": {
@@ -11,7 +11,8 @@
11
11
  "dist/",
12
12
  "lib/",
13
13
  "!lib/**/*.bench.ts",
14
- "!lib/**/*.test.ts"
14
+ "!lib/**/*.test.ts",
15
+ "!dist/**/*.{test,bench}.*"
15
16
  ],
16
17
  "type": "module",
17
18
  "sideEffects": false,
@@ -22,16 +23,16 @@
22
23
  "access": "public"
23
24
  },
24
25
  "dependencies": {
25
- "@badrap/valita": "^0.4.6",
26
- "@atcute/identity": "^1.1.3",
27
- "@atcute/lexicons": "^1.2.7",
28
- "@atcute/oauth-keyset": "^0.1.0"
26
+ "valibot": "^1.4.0",
27
+ "@atcute/lexicons": "^2.0.0",
28
+ "@atcute/identity": "^2.0.0",
29
+ "@atcute/oauth-keyset": "^0.1.1"
29
30
  },
30
31
  "devDependencies": {
31
- "vitest": "^4.0.16"
32
+ "vitest": "^4.1.5"
32
33
  },
33
34
  "scripts": {
34
- "build": "tsgo --project tsconfig.build.json",
35
+ "build": "tsgo",
35
36
  "test": "vitest",
36
37
  "prepublish": "rm -rf dist; pnpm run build"
37
38
  }