@atproto/oauth-client 0.0.0-spaces-alpha-20260818021221

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 (112) hide show
  1. package/CHANGELOG.md +810 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +387 -0
  4. package/dist/constants.d.ts +5 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/constants.js +5 -0
  7. package/dist/constants.js.map +1 -0
  8. package/dist/errors/auth-method-unsatisfiable-error.d.ts +3 -0
  9. package/dist/errors/auth-method-unsatisfiable-error.d.ts.map +1 -0
  10. package/dist/errors/auth-method-unsatisfiable-error.js +3 -0
  11. package/dist/errors/auth-method-unsatisfiable-error.js.map +1 -0
  12. package/dist/errors/token-invalid-error.d.ts +7 -0
  13. package/dist/errors/token-invalid-error.d.ts.map +1 -0
  14. package/dist/errors/token-invalid-error.js +7 -0
  15. package/dist/errors/token-invalid-error.js.map +1 -0
  16. package/dist/errors/token-refresh-error.d.ts +7 -0
  17. package/dist/errors/token-refresh-error.d.ts.map +1 -0
  18. package/dist/errors/token-refresh-error.js +7 -0
  19. package/dist/errors/token-refresh-error.js.map +1 -0
  20. package/dist/errors/token-revoked-error.d.ts +7 -0
  21. package/dist/errors/token-revoked-error.d.ts.map +1 -0
  22. package/dist/errors/token-revoked-error.js +7 -0
  23. package/dist/errors/token-revoked-error.js.map +1 -0
  24. package/dist/fetch-dpop.d.ts +20 -0
  25. package/dist/fetch-dpop.d.ts.map +1 -0
  26. package/dist/fetch-dpop.js +176 -0
  27. package/dist/fetch-dpop.js.map +1 -0
  28. package/dist/identity-resolver.d.ts +2 -0
  29. package/dist/identity-resolver.d.ts.map +1 -0
  30. package/dist/identity-resolver.js +21 -0
  31. package/dist/identity-resolver.js.map +1 -0
  32. package/dist/index.d.ts +25 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +25 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/lock.d.ts +3 -0
  37. package/dist/lock.d.ts.map +1 -0
  38. package/dist/lock.js +29 -0
  39. package/dist/lock.js.map +1 -0
  40. package/dist/oauth-authorization-server-metadata-resolver.d.ts +25 -0
  41. package/dist/oauth-authorization-server-metadata-resolver.d.ts.map +1 -0
  42. package/dist/oauth-authorization-server-metadata-resolver.js +54 -0
  43. package/dist/oauth-authorization-server-metadata-resolver.js.map +1 -0
  44. package/dist/oauth-callback-error.d.ts +7 -0
  45. package/dist/oauth-callback-error.d.ts.map +1 -0
  46. package/dist/oauth-callback-error.js +14 -0
  47. package/dist/oauth-callback-error.js.map +1 -0
  48. package/dist/oauth-client-auth.d.ts +23 -0
  49. package/dist/oauth-client-auth.d.ts.map +1 -0
  50. package/dist/oauth-client-auth.js +126 -0
  51. package/dist/oauth-client-auth.js.map +1 -0
  52. package/dist/oauth-client.d.ts +338 -0
  53. package/dist/oauth-client.d.ts.map +1 -0
  54. package/dist/oauth-client.js +274 -0
  55. package/dist/oauth-client.js.map +1 -0
  56. package/dist/oauth-protected-resource-metadata-resolver.d.ts +25 -0
  57. package/dist/oauth-protected-resource-metadata-resolver.d.ts.map +1 -0
  58. package/dist/oauth-protected-resource-metadata-resolver.js +54 -0
  59. package/dist/oauth-protected-resource-metadata-resolver.js.map +1 -0
  60. package/dist/oauth-resolver-error.d.ts +7 -0
  61. package/dist/oauth-resolver-error.d.ts.map +1 -0
  62. package/dist/oauth-resolver-error.js +19 -0
  63. package/dist/oauth-resolver-error.js.map +1 -0
  64. package/dist/oauth-resolver.d.ts +73 -0
  65. package/dist/oauth-resolver.d.ts.map +1 -0
  66. package/dist/oauth-resolver.js +99 -0
  67. package/dist/oauth-resolver.js.map +1 -0
  68. package/dist/oauth-response-error.d.ts +11 -0
  69. package/dist/oauth-response-error.d.ts.map +1 -0
  70. package/dist/oauth-response-error.js +22 -0
  71. package/dist/oauth-response-error.js.map +1 -0
  72. package/dist/oauth-server-agent.d.ts +55 -0
  73. package/dist/oauth-server-agent.d.ts.map +1 -0
  74. package/dist/oauth-server-agent.js +189 -0
  75. package/dist/oauth-server-agent.js.map +1 -0
  76. package/dist/oauth-server-factory.d.ts +33 -0
  77. package/dist/oauth-server-factory.d.ts.map +1 -0
  78. package/dist/oauth-server-factory.js +31 -0
  79. package/dist/oauth-server-factory.js.map +1 -0
  80. package/dist/oauth-session.d.ts +34 -0
  81. package/dist/oauth-session.d.ts.map +1 -0
  82. package/dist/oauth-session.js +120 -0
  83. package/dist/oauth-session.js.map +1 -0
  84. package/dist/runtime-implementation.d.ts +17 -0
  85. package/dist/runtime-implementation.d.ts.map +1 -0
  86. package/dist/runtime-implementation.js +2 -0
  87. package/dist/runtime-implementation.js.map +1 -0
  88. package/dist/runtime.d.ts +26 -0
  89. package/dist/runtime.d.ts.map +1 -0
  90. package/dist/runtime.js +100 -0
  91. package/dist/runtime.js.map +1 -0
  92. package/dist/session-getter.d.ts +44 -0
  93. package/dist/session-getter.d.ts.map +1 -0
  94. package/dist/session-getter.js +265 -0
  95. package/dist/session-getter.js.map +1 -0
  96. package/dist/state-store.d.ts +23 -0
  97. package/dist/state-store.d.ts.map +1 -0
  98. package/dist/state-store.js +2 -0
  99. package/dist/state-store.js.map +1 -0
  100. package/dist/types.d.ts +430 -0
  101. package/dist/types.d.ts.map +1 -0
  102. package/dist/types.js +9 -0
  103. package/dist/types.js.map +1 -0
  104. package/dist/util.d.ts +20 -0
  105. package/dist/util.d.ts.map +1 -0
  106. package/dist/util.js +68 -0
  107. package/dist/util.js.map +1 -0
  108. package/dist/validate-client-metadata.d.ts +5 -0
  109. package/dist/validate-client-metadata.d.ts.map +1 -0
  110. package/dist/validate-client-metadata.js +76 -0
  111. package/dist/validate-client-metadata.js.map +1 -0
  112. package/package.json +55 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-getter.js","sourceRoot":"","sources":["../src/session-getter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,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AAI,GAAG,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YACjC,uDAAuD;YACvD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAC9D,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,GAAe,EAAE,OAAO,GAAqB,MAAM;QAClE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;YACnB,OAAO,EAAE,OAAO,KAAK,IAAI;YACzB,UAAU,EAAE,OAAO,KAAK,KAAK;SAC9B,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import type { AtprotoDid } from '@atproto/did'\nimport type { Key } from '@atproto/jwk'\nimport {\n CachedGetter,\n type GetCachedOptions,\n type SimpleStore,\n} from '@atproto-labs/simple-store'\nimport { AuthMethodUnsatisfiableError } from './errors/auth-method-unsatisfiable-error.js'\nimport { TokenInvalidError } from './errors/token-invalid-error.js'\nimport { TokenRefreshError } from './errors/token-refresh-error.js'\nimport { TokenRevokedError } from './errors/token-revoked-error.js'\nimport type { ClientAuthMethod } from './oauth-client-auth.js'\nimport { OAuthResponseError } from './oauth-response-error.js'\nimport type { TokenSet } from './oauth-server-agent.js'\nimport type { OAuthServerFactory } from './oauth-server-factory.js'\nimport type { Runtime } from './runtime.js'\nimport { combineSignals, timeoutSignal } from './util.js'\n\nexport type Session = {\n dpopKey: Key\n authMethod: ClientAuthMethod\n tokenSet: TokenSet\n}\n\nexport type SessionStore = SimpleStore<string, Session>\n\nexport type SessionGetterOptions = {\n onSessionUpdated?: (sub: AtprotoDid, session: Session) => void\n onSessionDeleted?: (\n sub: AtprotoDid,\n cause: TokenRefreshError | TokenRevokedError | TokenInvalidError | unknown,\n ) => void\n}\n\nexport function isExpectedSessionError(err: unknown) {\n return (\n err instanceof TokenRefreshError ||\n err instanceof TokenRevokedError ||\n err instanceof TokenInvalidError ||\n err instanceof AuthMethodUnsatisfiableError ||\n // The stored session is invalid (e.g. missing properties) and cannot\n // be used properly\n err instanceof TypeError\n )\n}\n\n/**\n * There are several advantages to wrapping the sessionStore in a (single)\n * CachedGetter, the main of which is that the cached getter will ensure that at\n * most one fresh call is ever being made. Another advantage, is that it\n * contains the logic for reading from the cache which, if the cache is based on\n * localStorage/indexedDB, will sync across multiple tabs (for a given sub).\n */\nexport class SessionGetter extends CachedGetter<AtprotoDid, Session> {\n readonly #serverFactory: OAuthServerFactory\n readonly #runtime: Runtime\n readonly #options: SessionGetterOptions\n\n constructor(\n sessionStore: SessionStore,\n serverFactory: OAuthServerFactory,\n runtime: Runtime,\n options: SessionGetterOptions = {},\n ) {\n super(\n async (sub, { signal }, storedSession) => {\n // There needs to be a previous session to be able to refresh. If\n // storedSession is undefined, it means that the store does not contain\n // a session for the given sub.\n if (storedSession === undefined) {\n // Because the session is not in the store, this.delStored() method\n // will not be called by the CachedGetter class (because there is\n // nothing to delete). This would typically happen if there is no\n // synchronization mechanism between instances of this class. Let's\n // make sure an event is dispatched here if this occurs.\n const msg = 'The session was deleted by another process'\n const cause = new TokenRefreshError(sub, msg)\n await options.onSessionDeleted?.call(null, sub, cause)\n throw cause\n }\n\n // @NOTE Throwing a TokenRefreshError (or any other error class defined\n // in the deleteOnError options) will result in this.delStored() being\n // called.\n\n const { dpopKey, authMethod, tokenSet } = storedSession\n\n if (sub !== tokenSet.sub) {\n // Fool-proofing (e.g. against invalid session storage)\n throw new TokenRefreshError(sub, 'Stored session sub mismatch')\n }\n\n if (!tokenSet.refresh_token) {\n throw new TokenRefreshError(sub, 'No refresh token available')\n }\n\n const server = await serverFactory.fromIssuer(\n tokenSet.iss,\n authMethod,\n dpopKey,\n { signal },\n )\n\n // Because refresh tokens can only be used once, we must not use the\n // \"signal\" to abort the refresh, or throw any abort error beyond this\n // point. Any thrown error beyond this point will prevent the\n // TokenGetter from obtaining, and storing, the new token set,\n // effectively rendering the currently saved session unusable.\n signal?.throwIfAborted()\n\n try {\n const newTokenSet = await server.refresh(tokenSet)\n\n if (sub !== newTokenSet.sub) {\n // The server returned another sub. Was the tokenSet manipulated?\n throw new TokenRefreshError(sub, 'Token set sub mismatch')\n }\n\n return {\n dpopKey,\n tokenSet: newTokenSet,\n authMethod: server.authMethod,\n }\n } catch (cause) {\n // Since refresh tokens can only be used once, we might run into\n // concurrency issues if multiple instances (e.g. browser tabs) are\n // trying to refresh the same token simultaneously. The chances of\n // this happening when multiple instances are started simultaneously\n // is reduced by randomizing the expiry time (see isStale() below).\n // The best solution is to use a mutex/lock to ensure that only one\n // instance is refreshing the token at a time (runtime.usingLock) but\n // that is not always possible. Let's try to recover from concurrency\n // issues, or force the session to be deleted by throwing a\n // TokenRefreshError.\n if (\n cause instanceof OAuthResponseError &&\n cause.status === 400 &&\n cause.error === 'invalid_grant'\n ) {\n // In case there is no lock implementation in the runtime, we will\n // wait for a short time to give the other concurrent instances a\n // chance to finish their refreshing of the token. If a concurrent\n // refresh did occur, we will pretend that this one succeeded.\n if (!runtime.hasImplementationLock) {\n await new Promise((r) => setTimeout(r, 1000))\n\n const stored = await this.getStored(sub)\n if (stored === undefined) {\n // A concurrent refresh occurred and caused the session to be\n // deleted (for a reason we can't know at this point).\n\n // Using a distinct error message mainly for debugging\n // purposes. Also, throwing a TokenRefreshError to trigger\n // deletion through the deleteOnError callback.\n const msg = 'The session was deleted by another process'\n throw new TokenRefreshError(sub, msg, { cause })\n } else if (\n stored.tokenSet.access_token !== tokenSet.access_token ||\n stored.tokenSet.refresh_token !== tokenSet.refresh_token\n ) {\n // A concurrent refresh occurred. Pretend this one succeeded.\n return stored\n } else {\n // There were no concurrent refresh. The token is (likely)\n // simply no longer valid.\n }\n }\n\n // Make sure the session gets deleted from the store\n const msg = cause.errorDescription ?? 'The session was revoked'\n throw new TokenRefreshError(sub, msg, { cause })\n }\n\n throw cause\n }\n },\n sessionStore,\n {\n isStale: (sub, { tokenSet }) => {\n return (\n tokenSet.expires_at != null &&\n new Date(tokenSet.expires_at).getTime() <\n Date.now() +\n // Add some lee way to ensure the token is not expired when it\n // reaches the server.\n 10e3 +\n // Add some randomness to reduce the chances of multiple\n // instances trying to refresh the token at the same.\n 30e3 * Math.random()\n )\n },\n deleteOnError: isExpectedSessionError,\n },\n )\n\n this.#serverFactory = serverFactory\n this.#runtime = runtime\n this.#options = options\n }\n\n override async setStored(sub: AtprotoDid, session: Session) {\n // Prevent tampering with the stored value\n if (sub !== session.tokenSet.sub) {\n throw new Error('Token set does not match the expected sub')\n }\n\n try {\n await super.setStored(sub, session)\n } catch (err) {\n // If we fail to persist the session, we assume that we won't be able to\n // fetch it again. We don't want to leave the session in a \"limbo\" state,\n // so we proactively revoke the session and delete it from the store.\n\n const errors: unknown[] = [err]\n\n try {\n const { tokenSet, dpopKey, authMethod } = session\n const server = await this.#serverFactory.fromIssuer(\n tokenSet.iss,\n authMethod,\n dpopKey,\n )\n await server.revoke(tokenSet.refresh_token ?? tokenSet.access_token)\n } catch (err) {\n errors.push(err)\n }\n\n try {\n await this.delStored(sub, err)\n } catch (err) {\n errors.push(err)\n }\n\n throw new AggregateError(errors, `Failed to store session for ${sub}`)\n }\n\n await this.#options.onSessionUpdated?.call(null, sub, session)\n }\n\n override async delStored(sub: AtprotoDid, cause?: unknown): Promise<void> {\n await super.delStored(sub, cause)\n await this.#options.onSessionDeleted?.call(null, sub, cause)\n }\n\n override async get(\n sub: AtprotoDid,\n options?: GetCachedOptions,\n ): Promise<Session> {\n const session = await this.#runtime.usingLock(\n `@atproto-oauth-client-${sub}`,\n async () => {\n // Make sure, even if there is no signal in the options, that the\n // request will be cancelled after at most 30 seconds.\n const signal = timeoutSignal(30e3)\n\n using abortController = combineSignals([options?.signal, signal])\n\n return await super.get(sub, {\n ...options,\n signal: abortController.signal,\n })\n },\n )\n\n if (sub !== session.tokenSet.sub) {\n // Fool-proofing (e.g. against invalid session storage)\n throw new Error('Token set does not match the expected sub')\n }\n\n return session\n }\n\n /**\n * @param refresh When `true`, the credentials will be refreshed even if they\n * are not expired. When `false`, the credentials will not be refreshed even\n * if they are expired. When `undefined`, the credentials will be refreshed\n * if, and only if, they are (about to be) expired. Defaults to `undefined`.\n */\n async getSession(sub: AtprotoDid, refresh: boolean | 'auto' = 'auto') {\n return this.get(sub, {\n noCache: refresh === true,\n allowStale: refresh === false,\n })\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { Key } from '@atproto/jwk';
2
+ import type { SimpleStore } from '@atproto-labs/simple-store';
3
+ import type { ClientAuthMethod } from './oauth-client-auth.js';
4
+ export type InternalStateData = {
5
+ iss: string;
6
+ dpopKey: Key;
7
+ authMethod: ClientAuthMethod;
8
+ verifier: string;
9
+ appState?: string;
10
+ };
11
+ /**
12
+ * A store pending oauth authorization flows. The key is the "state" parameter
13
+ * used in the authorization request, and the value is an object containing the
14
+ * necessary information to complete the flow once the user is redirected back
15
+ * to the client.
16
+ *
17
+ * @note The data stored in this store is typically short-lived. It should be
18
+ * automatically cleared after a certain period of time (e.g. 1 hour) to prevent
19
+ * the store from growing indefinitely. It is up to the implementation to
20
+ * implement this cleanup mechanism.
21
+ */
22
+ export type StateStore = SimpleStore<string, InternalStateData>;
23
+ //# sourceMappingURL=state-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,GAAG,CAAA;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=state-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-store.js","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"","sourcesContent":["import type { Key } from '@atproto/jwk'\nimport type { SimpleStore } from '@atproto-labs/simple-store'\nimport type { ClientAuthMethod } from './oauth-client-auth.js'\n\nexport type InternalStateData = {\n iss: string\n dpopKey: Key\n authMethod: ClientAuthMethod\n verifier: string\n appState?: string\n}\n\n/**\n * A store pending oauth authorization flows. The key is the \"state\" parameter\n * used in the authorization request, and the value is an object containing the\n * necessary information to complete the flow once the user is redirected back\n * to the client.\n *\n * @note The data stored in this store is typically short-lived. It should be\n * automatically cleared after a certain period of time (e.g. 1 hour) to prevent\n * the store from growing indefinitely. It is up to the implementation to\n * implement this cleanup mechanism.\n */\nexport type StateStore = SimpleStore<string, InternalStateData>\n"]}
@@ -0,0 +1,430 @@
1
+ import { type TypeOf, z } from 'zod';
2
+ import { type OAuthAuthorizationRequestParameters } from '@atproto/oauth-types';
3
+ import type { Simplify } from './util.js';
4
+ export type AuthorizeOptions = Simplify<Omit<OAuthAuthorizationRequestParameters, 'client_id' | 'response_mode' | 'response_type' | 'login_hint' | 'code_challenge' | 'code_challenge_method'> & {
5
+ signal?: AbortSignal;
6
+ }>;
7
+ export type CallbackOptions = Simplify<Partial<Pick<OAuthAuthorizationRequestParameters, 'redirect_uri'>>>;
8
+ export declare const clientMetadataSchema: z.ZodObject<z.objectUtil.extendShape<{
9
+ redirect_uris: z.ZodArray<z.ZodEffects<z.ZodString, "http://127.0.0.1" | `${string}.${string}:/${string}` | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `https://${string}`, string>, "atleastone">;
10
+ response_types: z.ZodDefault<z.ZodArray<z.ZodEnum<["code", "token", "none", "code id_token token", "code id_token", "code token", "id_token token", "id_token"]>, "atleastone">>;
11
+ grant_types: z.ZodDefault<z.ZodArray<z.ZodEnum<["authorization_code", "implicit", "refresh_token", "password", "client_credentials", "urn:ietf:params:oauth:grant-type:jwt-bearer", "urn:ietf:params:oauth:grant-type:saml2-bearer"]>, "atleastone">>;
12
+ scope: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
13
+ token_endpoint_auth_method: z.ZodDefault<z.ZodEnum<["client_secret_basic", "client_secret_jwt", "client_secret_post", "none", "private_key_jwt", "self_signed_tls_client_auth", "tls_client_auth"]>>;
14
+ token_endpoint_auth_signing_alg: z.ZodOptional<z.ZodString>;
15
+ userinfo_signed_response_alg: z.ZodOptional<z.ZodString>;
16
+ userinfo_encrypted_response_alg: z.ZodOptional<z.ZodString>;
17
+ jwks_uri: z.ZodOptional<z.ZodEffects<z.ZodString, "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}`, string>>;
18
+ jwks: z.ZodOptional<z.ZodObject<{
19
+ keys: z.ZodEffects<z.ZodArray<z.ZodUnknown, "many">, ((({
20
+ kid?: string | undefined;
21
+ use?: "enc" | "sig" | undefined;
22
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
23
+ x5c?: string[] | undefined;
24
+ x5t?: string | undefined;
25
+ 'x5t#S256'?: string | undefined;
26
+ x5u?: string | undefined;
27
+ ext?: boolean | undefined;
28
+ iat?: number | undefined;
29
+ exp?: number | undefined;
30
+ nbf?: number | undefined;
31
+ revoked?: {
32
+ revoked_at: number;
33
+ reason?: string | undefined;
34
+ } | undefined;
35
+ kty: "RSA";
36
+ alg?: "PS256" | "PS384" | "PS512" | "RS256" | "RS384" | "RS512" | undefined;
37
+ n: string;
38
+ e: string;
39
+ d?: string | undefined;
40
+ p?: string | undefined;
41
+ q?: string | undefined;
42
+ dp?: string | undefined;
43
+ dq?: string | undefined;
44
+ qi?: string | undefined;
45
+ oth?: {
46
+ r?: string | undefined;
47
+ d?: string | undefined;
48
+ t?: string | undefined;
49
+ }[] | undefined;
50
+ } & {
51
+ kid: NonNullable<unknown>;
52
+ }) | ({
53
+ kid?: string | undefined;
54
+ use?: "enc" | "sig" | undefined;
55
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
56
+ x5c?: string[] | undefined;
57
+ x5t?: string | undefined;
58
+ 'x5t#S256'?: string | undefined;
59
+ x5u?: string | undefined;
60
+ ext?: boolean | undefined;
61
+ iat?: number | undefined;
62
+ exp?: number | undefined;
63
+ nbf?: number | undefined;
64
+ revoked?: {
65
+ revoked_at: number;
66
+ reason?: string | undefined;
67
+ } | undefined;
68
+ kty: "EC";
69
+ alg?: "ES256" | "ES384" | "ES512" | undefined;
70
+ crv: "P-256" | "P-384" | "P-521";
71
+ x: string;
72
+ y: string;
73
+ d?: string | undefined;
74
+ } & {
75
+ kid: NonNullable<unknown>;
76
+ }) | ({
77
+ kid?: string | undefined;
78
+ use?: "enc" | "sig" | undefined;
79
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
80
+ x5c?: string[] | undefined;
81
+ x5t?: string | undefined;
82
+ 'x5t#S256'?: string | undefined;
83
+ x5u?: string | undefined;
84
+ ext?: boolean | undefined;
85
+ iat?: number | undefined;
86
+ exp?: number | undefined;
87
+ nbf?: number | undefined;
88
+ revoked?: {
89
+ revoked_at: number;
90
+ reason?: string | undefined;
91
+ } | undefined;
92
+ kty: "EC";
93
+ alg?: "ES256K" | undefined;
94
+ crv: "secp256k1";
95
+ x: string;
96
+ y: string;
97
+ d?: string | undefined;
98
+ } & {
99
+ kid: NonNullable<unknown>;
100
+ }) | ({
101
+ kid?: string | undefined;
102
+ use?: "enc" | "sig" | undefined;
103
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
104
+ x5c?: string[] | undefined;
105
+ x5t?: string | undefined;
106
+ 'x5t#S256'?: string | undefined;
107
+ x5u?: string | undefined;
108
+ ext?: boolean | undefined;
109
+ iat?: number | undefined;
110
+ exp?: number | undefined;
111
+ nbf?: number | undefined;
112
+ revoked?: {
113
+ revoked_at: number;
114
+ reason?: string | undefined;
115
+ } | undefined;
116
+ kty: "OKP";
117
+ alg?: "EdDSA" | undefined;
118
+ crv: "Ed25519" | "Ed448";
119
+ x: string;
120
+ d?: string | undefined;
121
+ } & {
122
+ kid: NonNullable<unknown>;
123
+ })) & {
124
+ d?: never;
125
+ })[], unknown[]>;
126
+ }, "strip", z.ZodTypeAny, {
127
+ keys: ((({
128
+ kid?: string | undefined;
129
+ use?: "enc" | "sig" | undefined;
130
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
131
+ x5c?: string[] | undefined;
132
+ x5t?: string | undefined;
133
+ 'x5t#S256'?: string | undefined;
134
+ x5u?: string | undefined;
135
+ ext?: boolean | undefined;
136
+ iat?: number | undefined;
137
+ exp?: number | undefined;
138
+ nbf?: number | undefined;
139
+ revoked?: {
140
+ revoked_at: number;
141
+ reason?: string | undefined;
142
+ } | undefined;
143
+ kty: "RSA";
144
+ alg?: "PS256" | "PS384" | "PS512" | "RS256" | "RS384" | "RS512" | undefined;
145
+ n: string;
146
+ e: string;
147
+ d?: string | undefined;
148
+ p?: string | undefined;
149
+ q?: string | undefined;
150
+ dp?: string | undefined;
151
+ dq?: string | undefined;
152
+ qi?: string | undefined;
153
+ oth?: {
154
+ r?: string | undefined;
155
+ d?: string | undefined;
156
+ t?: string | undefined;
157
+ }[] | undefined;
158
+ } & {
159
+ kid: NonNullable<unknown>;
160
+ }) | ({
161
+ kid?: string | undefined;
162
+ use?: "enc" | "sig" | undefined;
163
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
164
+ x5c?: string[] | undefined;
165
+ x5t?: string | undefined;
166
+ 'x5t#S256'?: string | undefined;
167
+ x5u?: string | undefined;
168
+ ext?: boolean | undefined;
169
+ iat?: number | undefined;
170
+ exp?: number | undefined;
171
+ nbf?: number | undefined;
172
+ revoked?: {
173
+ revoked_at: number;
174
+ reason?: string | undefined;
175
+ } | undefined;
176
+ kty: "EC";
177
+ alg?: "ES256" | "ES384" | "ES512" | undefined;
178
+ crv: "P-256" | "P-384" | "P-521";
179
+ x: string;
180
+ y: string;
181
+ d?: string | undefined;
182
+ } & {
183
+ kid: NonNullable<unknown>;
184
+ }) | ({
185
+ kid?: string | undefined;
186
+ use?: "enc" | "sig" | undefined;
187
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
188
+ x5c?: string[] | undefined;
189
+ x5t?: string | undefined;
190
+ 'x5t#S256'?: string | undefined;
191
+ x5u?: string | undefined;
192
+ ext?: boolean | undefined;
193
+ iat?: number | undefined;
194
+ exp?: number | undefined;
195
+ nbf?: number | undefined;
196
+ revoked?: {
197
+ revoked_at: number;
198
+ reason?: string | undefined;
199
+ } | undefined;
200
+ kty: "EC";
201
+ alg?: "ES256K" | undefined;
202
+ crv: "secp256k1";
203
+ x: string;
204
+ y: string;
205
+ d?: string | undefined;
206
+ } & {
207
+ kid: NonNullable<unknown>;
208
+ }) | ({
209
+ kid?: string | undefined;
210
+ use?: "enc" | "sig" | undefined;
211
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
212
+ x5c?: string[] | undefined;
213
+ x5t?: string | undefined;
214
+ 'x5t#S256'?: string | undefined;
215
+ x5u?: string | undefined;
216
+ ext?: boolean | undefined;
217
+ iat?: number | undefined;
218
+ exp?: number | undefined;
219
+ nbf?: number | undefined;
220
+ revoked?: {
221
+ revoked_at: number;
222
+ reason?: string | undefined;
223
+ } | undefined;
224
+ kty: "OKP";
225
+ alg?: "EdDSA" | undefined;
226
+ crv: "Ed25519" | "Ed448";
227
+ x: string;
228
+ d?: string | undefined;
229
+ } & {
230
+ kid: NonNullable<unknown>;
231
+ })) & {
232
+ d?: never;
233
+ })[];
234
+ }, {
235
+ keys: unknown[];
236
+ }>>;
237
+ application_type: z.ZodDefault<z.ZodEnum<["web", "native"]>>;
238
+ subject_type: z.ZodDefault<z.ZodEnum<["public", "pairwise"]>>;
239
+ request_object_signing_alg: z.ZodOptional<z.ZodString>;
240
+ id_token_signed_response_alg: z.ZodOptional<z.ZodString>;
241
+ authorization_signed_response_alg: z.ZodDefault<z.ZodString>;
242
+ authorization_encrypted_response_enc: z.ZodOptional<z.ZodEnum<["A128CBC-HS256"]>>;
243
+ authorization_encrypted_response_alg: z.ZodOptional<z.ZodString>;
244
+ client_id: z.ZodOptional<z.ZodString>;
245
+ client_name: z.ZodOptional<z.ZodString>;
246
+ client_uri: z.ZodOptional<z.ZodEffects<z.ZodString, "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}`, string>>;
247
+ policy_uri: z.ZodOptional<z.ZodEffects<z.ZodString, "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}`, string>>;
248
+ tos_uri: z.ZodOptional<z.ZodEffects<z.ZodString, "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}`, string>>;
249
+ logo_uri: z.ZodOptional<z.ZodEffects<z.ZodString, "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}`, string>>;
250
+ default_max_age: z.ZodOptional<z.ZodNumber>;
251
+ require_auth_time: z.ZodOptional<z.ZodBoolean>;
252
+ contacts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
253
+ tls_client_certificate_bound_access_tokens: z.ZodOptional<z.ZodBoolean>;
254
+ dpop_bound_access_tokens: z.ZodOptional<z.ZodBoolean>;
255
+ authorization_details_types: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
256
+ }, {
257
+ client_id: z.ZodUnion<[z.ZodEffects<z.ZodIntersection<z.ZodString, z.ZodEffects<z.ZodEffects<z.ZodString, `${string}:${string}`, string>, `https://${string}`, string>>, `https://${string}/${string}`, string>, z.ZodEffects<z.ZodString, "http://localhost" | "http://localhost/" | `http://localhost/?${string}` | `http://localhost?${string}`, string>]>;
258
+ }>, "strip", z.ZodTypeAny, {
259
+ redirect_uris: ["http://127.0.0.1" | `${string}.${string}:/${string}` | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `https://${string}`, ...("http://127.0.0.1" | `${string}.${string}:/${string}` | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `https://${string}`)[]];
260
+ response_types: ["code" | "code id_token" | "code id_token token" | "code token" | "id_token" | "id_token token" | "none" | "token", ...("code" | "code id_token" | "code id_token token" | "code token" | "id_token" | "id_token token" | "none" | "token")[]];
261
+ grant_types: ["authorization_code" | "client_credentials" | "implicit" | "password" | "refresh_token" | "urn:ietf:params:oauth:grant-type:jwt-bearer" | "urn:ietf:params:oauth:grant-type:saml2-bearer", ...("authorization_code" | "client_credentials" | "implicit" | "password" | "refresh_token" | "urn:ietf:params:oauth:grant-type:jwt-bearer" | "urn:ietf:params:oauth:grant-type:saml2-bearer")[]];
262
+ scope?: string | undefined;
263
+ token_endpoint_auth_method: "client_secret_basic" | "client_secret_jwt" | "client_secret_post" | "none" | "private_key_jwt" | "self_signed_tls_client_auth" | "tls_client_auth";
264
+ token_endpoint_auth_signing_alg?: string | undefined;
265
+ userinfo_signed_response_alg?: string | undefined;
266
+ userinfo_encrypted_response_alg?: string | undefined;
267
+ jwks_uri?: "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}` | undefined;
268
+ jwks?: {
269
+ keys: ((({
270
+ kid?: string | undefined;
271
+ use?: "enc" | "sig" | undefined;
272
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
273
+ x5c?: string[] | undefined;
274
+ x5t?: string | undefined;
275
+ 'x5t#S256'?: string | undefined;
276
+ x5u?: string | undefined;
277
+ ext?: boolean | undefined;
278
+ iat?: number | undefined;
279
+ exp?: number | undefined;
280
+ nbf?: number | undefined;
281
+ revoked?: {
282
+ revoked_at: number;
283
+ reason?: string | undefined;
284
+ } | undefined;
285
+ kty: "RSA";
286
+ alg?: "PS256" | "PS384" | "PS512" | "RS256" | "RS384" | "RS512" | undefined;
287
+ n: string;
288
+ e: string;
289
+ d?: string | undefined;
290
+ p?: string | undefined;
291
+ q?: string | undefined;
292
+ dp?: string | undefined;
293
+ dq?: string | undefined;
294
+ qi?: string | undefined;
295
+ oth?: {
296
+ r?: string | undefined;
297
+ d?: string | undefined;
298
+ t?: string | undefined;
299
+ }[] | undefined;
300
+ } & {
301
+ kid: NonNullable<unknown>;
302
+ }) | ({
303
+ kid?: string | undefined;
304
+ use?: "enc" | "sig" | undefined;
305
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
306
+ x5c?: string[] | undefined;
307
+ x5t?: string | undefined;
308
+ 'x5t#S256'?: string | undefined;
309
+ x5u?: string | undefined;
310
+ ext?: boolean | undefined;
311
+ iat?: number | undefined;
312
+ exp?: number | undefined;
313
+ nbf?: number | undefined;
314
+ revoked?: {
315
+ revoked_at: number;
316
+ reason?: string | undefined;
317
+ } | undefined;
318
+ kty: "EC";
319
+ alg?: "ES256" | "ES384" | "ES512" | undefined;
320
+ crv: "P-256" | "P-384" | "P-521";
321
+ x: string;
322
+ y: string;
323
+ d?: string | undefined;
324
+ } & {
325
+ kid: NonNullable<unknown>;
326
+ }) | ({
327
+ kid?: string | undefined;
328
+ use?: "enc" | "sig" | undefined;
329
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
330
+ x5c?: string[] | undefined;
331
+ x5t?: string | undefined;
332
+ 'x5t#S256'?: string | undefined;
333
+ x5u?: string | undefined;
334
+ ext?: boolean | undefined;
335
+ iat?: number | undefined;
336
+ exp?: number | undefined;
337
+ nbf?: number | undefined;
338
+ revoked?: {
339
+ revoked_at: number;
340
+ reason?: string | undefined;
341
+ } | undefined;
342
+ kty: "EC";
343
+ alg?: "ES256K" | undefined;
344
+ crv: "secp256k1";
345
+ x: string;
346
+ y: string;
347
+ d?: string | undefined;
348
+ } & {
349
+ kid: NonNullable<unknown>;
350
+ }) | ({
351
+ kid?: string | undefined;
352
+ use?: "enc" | "sig" | undefined;
353
+ key_ops?: ("decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey")[] | undefined;
354
+ x5c?: string[] | undefined;
355
+ x5t?: string | undefined;
356
+ 'x5t#S256'?: string | undefined;
357
+ x5u?: string | undefined;
358
+ ext?: boolean | undefined;
359
+ iat?: number | undefined;
360
+ exp?: number | undefined;
361
+ nbf?: number | undefined;
362
+ revoked?: {
363
+ revoked_at: number;
364
+ reason?: string | undefined;
365
+ } | undefined;
366
+ kty: "OKP";
367
+ alg?: "EdDSA" | undefined;
368
+ crv: "Ed25519" | "Ed448";
369
+ x: string;
370
+ d?: string | undefined;
371
+ } & {
372
+ kid: NonNullable<unknown>;
373
+ })) & {
374
+ d?: never;
375
+ })[];
376
+ } | undefined;
377
+ application_type: "native" | "web";
378
+ subject_type: "pairwise" | "public";
379
+ request_object_signing_alg?: string | undefined;
380
+ id_token_signed_response_alg?: string | undefined;
381
+ authorization_signed_response_alg: string;
382
+ authorization_encrypted_response_enc?: "A128CBC-HS256" | undefined;
383
+ authorization_encrypted_response_alg?: string | undefined;
384
+ client_name?: string | undefined;
385
+ client_uri?: "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}` | undefined;
386
+ policy_uri?: "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}` | undefined;
387
+ tos_uri?: "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}` | undefined;
388
+ logo_uri?: "http://127.0.0.1" | "http://localhost" | `http://127.0.0.1#${string}` | `http://127.0.0.1/${string}` | `http://127.0.0.1:${string}` | `http://127.0.0.1?${string}` | `http://[::1]${string}` | `http://localhost#${string}` | `http://localhost/${string}` | `http://localhost:${string}` | `http://localhost?${string}` | `https://${string}` | undefined;
389
+ default_max_age?: number | undefined;
390
+ require_auth_time?: boolean | undefined;
391
+ contacts?: string[] | undefined;
392
+ tls_client_certificate_bound_access_tokens?: boolean | undefined;
393
+ dpop_bound_access_tokens?: boolean | undefined;
394
+ authorization_details_types?: string[] | undefined;
395
+ client_id: "http://localhost" | "http://localhost/" | `http://localhost/?${string}` | `http://localhost?${string}` | `https://${string}/${string}`;
396
+ }, {
397
+ redirect_uris: [string, ...string[]];
398
+ response_types?: ["code" | "code id_token" | "code id_token token" | "code token" | "id_token" | "id_token token" | "none" | "token", ...("code" | "code id_token" | "code id_token token" | "code token" | "id_token" | "id_token token" | "none" | "token")[]] | undefined;
399
+ grant_types?: ["authorization_code" | "client_credentials" | "implicit" | "password" | "refresh_token" | "urn:ietf:params:oauth:grant-type:jwt-bearer" | "urn:ietf:params:oauth:grant-type:saml2-bearer", ...("authorization_code" | "client_credentials" | "implicit" | "password" | "refresh_token" | "urn:ietf:params:oauth:grant-type:jwt-bearer" | "urn:ietf:params:oauth:grant-type:saml2-bearer")[]] | undefined;
400
+ scope?: string | undefined;
401
+ token_endpoint_auth_method?: "client_secret_basic" | "client_secret_jwt" | "client_secret_post" | "none" | "private_key_jwt" | "self_signed_tls_client_auth" | "tls_client_auth" | undefined;
402
+ token_endpoint_auth_signing_alg?: string | undefined;
403
+ userinfo_signed_response_alg?: string | undefined;
404
+ userinfo_encrypted_response_alg?: string | undefined;
405
+ jwks_uri?: string | undefined;
406
+ jwks?: {
407
+ keys: unknown[];
408
+ } | undefined;
409
+ application_type?: "native" | "web" | undefined;
410
+ subject_type?: "pairwise" | "public" | undefined;
411
+ request_object_signing_alg?: string | undefined;
412
+ id_token_signed_response_alg?: string | undefined;
413
+ authorization_signed_response_alg?: string | undefined;
414
+ authorization_encrypted_response_enc?: "A128CBC-HS256" | undefined;
415
+ authorization_encrypted_response_alg?: string | undefined;
416
+ client_name?: string | undefined;
417
+ client_uri?: string | undefined;
418
+ policy_uri?: string | undefined;
419
+ tos_uri?: string | undefined;
420
+ logo_uri?: string | undefined;
421
+ default_max_age?: number | undefined;
422
+ require_auth_time?: boolean | undefined;
423
+ contacts?: string[] | undefined;
424
+ tls_client_certificate_bound_access_tokens?: boolean | undefined;
425
+ dpop_bound_access_tokens?: boolean | undefined;
426
+ authorization_details_types?: string[] | undefined;
427
+ client_id: string;
428
+ }>;
429
+ export type ClientMetadata = TypeOf<typeof clientMetadataSchema>;
430
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,EACL,KAAK,mCAAmC,EAIzC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAMzC,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,IAAI,CACF,mCAAmC,EACjC,WAAW,GACX,eAAe,GACf,eAAe,GACf,YAAY,GACZ,gBAAgB,GAChB,uBAAuB,CAC1B,GAAG;IACF,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,CACF,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,QAAQ,CACpC,OAAO,CAAC,IAAI,CAAC,mCAAmC,EAAE,cAAc,CAAC,CAAC,CACnE,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ import { oauthClientIdDiscoverableSchema, oauthClientIdLoopbackSchema, oauthClientMetadataSchema, } from '@atproto/oauth-types';
3
+ export const clientMetadataSchema = oauthClientMetadataSchema.extend({
4
+ client_id: z.union([
5
+ oauthClientIdDiscoverableSchema,
6
+ oauthClientIdLoopbackSchema,
7
+ ]),
8
+ });
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,CAAC,EAAE,MAAM,KAAK,CAAA;AACpC,OAAO,EAEL,+BAA+B,EAC/B,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAyB7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,yBAAyB,CAAC,MAAM,CAAC;IACnE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC;QACjB,+BAA+B;QAC/B,2BAA2B;KAC5B,CAAC;CACH,CAAC,CAAA","sourcesContent":["import { type TypeOf, z } from 'zod'\nimport {\n type OAuthAuthorizationRequestParameters,\n oauthClientIdDiscoverableSchema,\n oauthClientIdLoopbackSchema,\n oauthClientMetadataSchema,\n} from '@atproto/oauth-types'\nimport type { Simplify } from './util.js'\n\n// Note: These types are not prefixed with `OAuth` because they are not specific\n// to OAuth. They are specific to this packages. OAuth specific types are in\n// `@atproto/oauth-types`.\n\nexport type AuthorizeOptions = Simplify<\n Omit<\n OAuthAuthorizationRequestParameters,\n | 'client_id'\n | 'response_mode'\n | 'response_type'\n | 'login_hint'\n | 'code_challenge'\n | 'code_challenge_method'\n > & {\n signal?: AbortSignal\n }\n>\n\nexport type CallbackOptions = Simplify<\n Partial<Pick<OAuthAuthorizationRequestParameters, 'redirect_uri'>>\n>\n\nexport const clientMetadataSchema = oauthClientMetadataSchema.extend({\n client_id: z.union([\n oauthClientIdDiscoverableSchema,\n oauthClientIdLoopbackSchema,\n ]),\n})\n\nexport type ClientMetadata = TypeOf<typeof clientMetadataSchema>\n"]}
package/dist/util.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export type Awaitable<T> = T | PromiseLike<T>;
2
+ export type Simplify<T> = {
3
+ [K in keyof T]: T[K];
4
+ } & NonNullable<unknown>;
5
+ export declare const ifString: <V>(v: V) => (V & string) | undefined;
6
+ export declare function contentMime(headers: Headers): string | undefined;
7
+ /**
8
+ * Returns an {@link AbortSignal} that aborts after `ms` milliseconds.
9
+ *
10
+ * Uses the native {@link AbortSignal.timeout} when available, and otherwise
11
+ * falls back to an {@link AbortController} + `setTimeout`. The static
12
+ * `AbortSignal.timeout` method is not implemented in every runtime this package
13
+ * targets (notably React Native / Expo), so relying on it directly throws a
14
+ * `TypeError: AbortSignal.timeout is not a function` at runtime.
15
+ *
16
+ * @see {@link https://github.com/facebook/react-native/issues/42042}
17
+ */
18
+ export declare function timeoutSignal(ms: number): AbortSignal;
19
+ export declare function combineSignals(signals: readonly (AbortSignal | undefined)[]): AbortController & Disposable;
20
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AAC7C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AAEzE,eAAO,MAAM,QAAQ,GAAI,CAAC,KAAK,CAAC,6BAA4C,CAAA;AAE5E,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAQrD;AAgBD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,GAC5C,eAAe,GAAG,UAAU,CAwB9B"}
package/dist/util.js ADDED
@@ -0,0 +1,68 @@
1
+ export const ifString = (v) => (typeof v === 'string' ? v : undefined);
2
+ export function contentMime(headers) {
3
+ return headers.get('content-type')?.split(';')[0].trim();
4
+ }
5
+ /**
6
+ * Returns an {@link AbortSignal} that aborts after `ms` milliseconds.
7
+ *
8
+ * Uses the native {@link AbortSignal.timeout} when available, and otherwise
9
+ * falls back to an {@link AbortController} + `setTimeout`. The static
10
+ * `AbortSignal.timeout` method is not implemented in every runtime this package
11
+ * targets (notably React Native / Expo), so relying on it directly throws a
12
+ * `TypeError: AbortSignal.timeout is not a function` at runtime.
13
+ *
14
+ * @see {@link https://github.com/facebook/react-native/issues/42042}
15
+ */
16
+ export function timeoutSignal(ms) {
17
+ if (typeof AbortSignal.timeout === 'function') {
18
+ return AbortSignal.timeout(ms);
19
+ }
20
+ const controller = new AbortController();
21
+ setTimeout(() => controller.abort(timeoutError(ms)), ms);
22
+ return controller.signal;
23
+ }
24
+ /**
25
+ * Builds the reason used to abort a {@link timeoutSignal} fallback. Mirrors the
26
+ * native `AbortSignal.timeout` behaviour (a `TimeoutError` `DOMException`) when
27
+ * `DOMException` is available, and degrades to a plain `Error` in runtimes that
28
+ * lack it.
29
+ */
30
+ function timeoutError(ms) {
31
+ const message = `The operation timed out after ${ms} ms`;
32
+ if (typeof DOMException === 'function') {
33
+ return new DOMException(message, 'TimeoutError');
34
+ }
35
+ return new Error(message);
36
+ }
37
+ export function combineSignals(signals) {
38
+ const controller = new DisposableAbortController();
39
+ const onAbort = function (_event) {
40
+ const reason = new Error('This operation was aborted', {
41
+ cause: this.reason,
42
+ });
43
+ controller.abort(reason);
44
+ };
45
+ try {
46
+ for (const sig of signals) {
47
+ if (sig) {
48
+ sig.throwIfAborted();
49
+ sig.addEventListener('abort', onAbort, { signal: controller.signal });
50
+ }
51
+ }
52
+ return controller;
53
+ }
54
+ catch (err) {
55
+ controller.abort(err);
56
+ throw err;
57
+ }
58
+ }
59
+ /**
60
+ * Allows using {@link AbortController} with the `using` keyword, in order to
61
+ * automatically abort them once the execution block ends.
62
+ */
63
+ class DisposableAbortController extends AbortController {
64
+ [Symbol.dispose]() {
65
+ this.abort(new Error('AbortController was disposed'));
66
+ }
67
+ }
68
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,CAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAE5E,MAAM,UAAU,WA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G,CAAC,cAAc,EAAE,CAAA;gBACpB,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACrB,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,yBAA0B,SAAQ,eAAe;IACrD,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAA;IACvD,CAAC;CACF","sourcesContent":["export type Awaitable<T> = T | PromiseLike<T>\nexport type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>\n\nexport const ifString = <V>(v: V) => (typeof v === 'string' ? v : undefined)\n\nexport function contentMime(headers: Headers): string | undefined {\n return headers.get('content-type')?.split(';')[0]!.trim()\n}\n\n/**\n * Returns an {@link AbortSignal} that aborts after `ms` milliseconds.\n *\n * Uses the native {@link AbortSignal.timeout} when available, and otherwise\n * falls back to an {@link AbortController} + `setTimeout`. The static\n * `AbortSignal.timeout` method is not implemented in every runtime this package\n * targets (notably React Native / Expo), so relying on it directly throws a\n * `TypeError: AbortSignal.timeout is not a function` at runtime.\n *\n * @see {@link https://github.com/facebook/react-native/issues/42042}\n */\nexport function timeoutSignal(ms: number): AbortSignal {\n if (typeof AbortSignal.timeout === 'function') {\n return AbortSignal.timeout(ms)\n }\n\n const controller = new AbortController()\n setTimeout(() => controller.abort(timeoutError(ms)), ms)\n return controller.signal\n}\n\n/**\n * Builds the reason used to abort a {@link timeoutSignal} fallback. Mirrors the\n * native `AbortSignal.timeout` behaviour (a `TimeoutError` `DOMException`) when\n * `DOMException` is available, and degrades to a plain `Error` in runtimes that\n * lack it.\n */\nfunction timeoutError(ms: number): unknown {\n const message = `The operation timed out after ${ms} ms`\n if (typeof DOMException === 'function') {\n return new DOMException(message, 'TimeoutError')\n }\n return new Error(message)\n}\n\nexport function combineSignals(\n signals: readonly (AbortSignal | undefined)[],\n): AbortController & Disposable {\n const controller = new DisposableAbortController()\n\n const onAbort = function (this: AbortSignal, _event: Event) {\n const reason = new Error('This operation was aborted', {\n cause: this.reason,\n })\n\n controller.abort(reason)\n }\n\n try {\n for (const sig of signals) {\n if (sig) {\n sig.throwIfAborted()\n sig.addEventListener('abort', onAbort, { signal: controller.signal })\n }\n }\n\n return controller\n } catch (err) {\n controller.abort(err)\n throw err\n }\n}\n\n/**\n * Allows using {@link AbortController} with the `using` keyword, in order to\n * automatically abort them once the execution block ends.\n */\nclass DisposableAbortController extends AbortController implements Disposable {\n [Symbol.dispose]() {\n this.abort(new Error('AbortController was disposed'))\n }\n}\n"]}