@atproto/oauth-types 0.6.3 → 0.7.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 (107) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/atproto-loopback-client-id.js +17 -21
  3. package/dist/atproto-loopback-client-id.js.map +1 -1
  4. package/dist/atproto-loopback-client-metadata.js +6 -10
  5. package/dist/atproto-loopback-client-metadata.js.map +1 -1
  6. package/dist/atproto-loopback-client-redirect-uris.js +1 -4
  7. package/dist/atproto-loopback-client-redirect-uris.js.map +1 -1
  8. package/dist/atproto-oauth-scope.js +11 -17
  9. package/dist/atproto-oauth-scope.js.map +1 -1
  10. package/dist/atproto-oauth-token-response.d.ts +3 -3
  11. package/dist/atproto-oauth-token-response.js +9 -12
  12. package/dist/atproto-oauth-token-response.js.map +1 -1
  13. package/dist/constants.js +1 -4
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.js +49 -65
  16. package/dist/index.js.map +1 -1
  17. package/dist/oauth-access-token.js +2 -5
  18. package/dist/oauth-access-token.js.map +1 -1
  19. package/dist/oauth-authorization-code-grant-token-request.js +7 -10
  20. package/dist/oauth-authorization-code-grant-token-request.js.map +1 -1
  21. package/dist/oauth-authorization-details.js +10 -13
  22. package/dist/oauth-authorization-details.js.map +1 -1
  23. package/dist/oauth-authorization-request-jar.js +4 -7
  24. package/dist/oauth-authorization-request-jar.js.map +1 -1
  25. package/dist/oauth-authorization-request-par.js +6 -9
  26. package/dist/oauth-authorization-request-par.js.map +1 -1
  27. package/dist/oauth-authorization-request-parameters.js +35 -38
  28. package/dist/oauth-authorization-request-parameters.js.map +1 -1
  29. package/dist/oauth-authorization-request-query.js +11 -14
  30. package/dist/oauth-authorization-request-query.js.map +1 -1
  31. package/dist/oauth-authorization-request-uri.js +4 -7
  32. package/dist/oauth-authorization-request-uri.js.map +1 -1
  33. package/dist/oauth-authorization-response-error.js +2 -5
  34. package/dist/oauth-authorization-response-error.js.map +1 -1
  35. package/dist/oauth-authorization-server-metadata.js +52 -55
  36. package/dist/oauth-authorization-server-metadata.js.map +1 -1
  37. package/dist/oauth-client-credentials-grant-token-request.js +3 -6
  38. package/dist/oauth-client-credentials-grant-token-request.js.map +1 -1
  39. package/dist/oauth-client-credentials.js +17 -20
  40. package/dist/oauth-client-credentials.js.map +1 -1
  41. package/dist/oauth-client-id-discoverable.js +26 -33
  42. package/dist/oauth-client-id-discoverable.js.map +1 -1
  43. package/dist/oauth-client-id-loopback.js +20 -29
  44. package/dist/oauth-client-id-loopback.js.map +1 -1
  45. package/dist/oauth-client-id.js +2 -5
  46. package/dist/oauth-client-id.js.map +1 -1
  47. package/dist/oauth-client-metadata.d.ts.map +1 -1
  48. package/dist/oauth-client-metadata.js +41 -44
  49. package/dist/oauth-client-metadata.js.map +1 -1
  50. package/dist/oauth-code-challenge-method.js +2 -5
  51. package/dist/oauth-code-challenge-method.js.map +1 -1
  52. package/dist/oauth-endpoint-auth-method.js +2 -5
  53. package/dist/oauth-endpoint-auth-method.js.map +1 -1
  54. package/dist/oauth-endpoint-name.js +1 -4
  55. package/dist/oauth-endpoint-name.js.map +1 -1
  56. package/dist/oauth-grant-type.js +2 -5
  57. package/dist/oauth-grant-type.js.map +1 -1
  58. package/dist/oauth-introspection-response.js +1 -2
  59. package/dist/oauth-issuer-identifier.js +7 -10
  60. package/dist/oauth-issuer-identifier.js.map +1 -1
  61. package/dist/oauth-par-response.js +4 -7
  62. package/dist/oauth-par-response.js.map +1 -1
  63. package/dist/oauth-password-grant-token-request.js +5 -8
  64. package/dist/oauth-password-grant-token-request.js.map +1 -1
  65. package/dist/oauth-prompt-mode.js +2 -5
  66. package/dist/oauth-prompt-mode.js.map +1 -1
  67. package/dist/oauth-protected-resource-metadata.js +14 -17
  68. package/dist/oauth-protected-resource-metadata.js.map +1 -1
  69. package/dist/oauth-redirect-uri.js +10 -13
  70. package/dist/oauth-redirect-uri.js.map +1 -1
  71. package/dist/oauth-refresh-token-grant-token-request.js +5 -8
  72. package/dist/oauth-refresh-token-grant-token-request.js.map +1 -1
  73. package/dist/oauth-refresh-token.js +2 -5
  74. package/dist/oauth-refresh-token.js.map +1 -1
  75. package/dist/oauth-request-uri.js +2 -5
  76. package/dist/oauth-request-uri.js.map +1 -1
  77. package/dist/oauth-response-mode.js +2 -5
  78. package/dist/oauth-response-mode.js.map +1 -1
  79. package/dist/oauth-response-type.js +2 -5
  80. package/dist/oauth-response-type.js.map +1 -1
  81. package/dist/oauth-scope.js +4 -8
  82. package/dist/oauth-scope.js.map +1 -1
  83. package/dist/oauth-token-identification.js +6 -9
  84. package/dist/oauth-token-identification.js.map +1 -1
  85. package/dist/oauth-token-request.js +10 -13
  86. package/dist/oauth-token-request.js.map +1 -1
  87. package/dist/oauth-token-response.js +12 -15
  88. package/dist/oauth-token-response.js.map +1 -1
  89. package/dist/oauth-token-type.js +4 -7
  90. package/dist/oauth-token-type.js.map +1 -1
  91. package/dist/oidc-authorization-error-response.js +2 -5
  92. package/dist/oidc-authorization-error-response.js.map +1 -1
  93. package/dist/oidc-claims-parameter.js +2 -5
  94. package/dist/oidc-claims-parameter.js.map +1 -1
  95. package/dist/oidc-claims-properties.js +5 -8
  96. package/dist/oidc-claims-properties.js.map +1 -1
  97. package/dist/oidc-entity-type.js +2 -5
  98. package/dist/oidc-entity-type.js.map +1 -1
  99. package/dist/oidc-userinfo.js +10 -13
  100. package/dist/oidc-userinfo.js.map +1 -1
  101. package/dist/uri.js +25 -28
  102. package/dist/uri.js.map +1 -1
  103. package/dist/util.js +12 -26
  104. package/dist/util.js.map +1 -1
  105. package/package.json +8 -7
  106. package/src/atproto-oauth-token-response.ts +1 -1
  107. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oauthTokenTypeSchema = void 0;
4
- const zod_1 = require("zod");
1
+ import { z } from 'zod';
5
2
  // Case insensitive input, normalized output
6
- exports.oauthTokenTypeSchema = zod_1.z.union([
7
- zod_1.z
3
+ export const oauthTokenTypeSchema = z.union([
4
+ z
8
5
  .string()
9
6
  .regex(/^DPoP$/i)
10
7
  .transform(() => 'DPoP'),
11
- zod_1.z
8
+ z
12
9
  .string()
13
10
  .regex(/^Bearer$/i)
14
11
  .transform(() => 'Bearer'),
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-token-type.js","sourceRoot":"","sources":["../src/oauth-token-type.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEvB,4CAA4C;AAC/B,QAAA,oBAAoB,GAAG,OAAC,CAAC,KAAK,CAAC;IAC1C,OAAC;SACE,MAAM,EAAE;SACR,KAAK,CAAC,SAAS,CAAC;SAChB,SAAS,CAAC,GAAG,EAAE,CAAC,MAAe,CAAC;IACnC,OAAC;SACE,MAAM,EAAE;SACR,KAAK,CAAC,WAAW,CAAC;SAClB,SAAS,CAAC,GAAG,EAAE,CAAC,QAAiB,CAAC;CACtC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\n// Case insensitive input, normalized output\nexport const oauthTokenTypeSchema = z.union([\n z\n .string()\n .regex(/^DPoP$/i)\n .transform(() => 'DPoP' as const),\n z\n .string()\n .regex(/^Bearer$/i)\n .transform(() => 'Bearer' as const),\n])\n\nexport type OAuthTokenType = z.infer<typeof oauthTokenTypeSchema>\n"]}
1
+ {"version":3,"file":"oauth-token-type.js","sourceRoot":"","sources":["../src/oauth-token-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,4CAA4C;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;SACE,MAAM,EAAE;SACR,KAAK,CAAC,SAAS,CAAC;SAChB,SAAS,CAAC,GAAG,EAAE,CAAC,MAAe,CAAC;IACnC,CAAC;SACE,MAAM,EAAE;SACR,KAAK,CAAC,WAAW,CAAC;SAClB,SAAS,CAAC,GAAG,EAAE,CAAC,QAAiB,CAAC;CACtC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\n// Case insensitive input, normalized output\nexport const oauthTokenTypeSchema = z.union([\n z\n .string()\n .regex(/^DPoP$/i)\n .transform(() => 'DPoP' as const),\n z\n .string()\n .regex(/^Bearer$/i)\n .transform(() => 'Bearer' as const),\n])\n\nexport type OAuthTokenType = z.infer<typeof oauthTokenTypeSchema>\n"]}
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oidcAuthorizationResponseErrorSchema = void 0;
4
- const zod_1 = require("zod");
1
+ import { z } from 'zod';
5
2
  /**
6
3
  * @see {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthError}
7
4
  */
8
- exports.oidcAuthorizationResponseErrorSchema = zod_1.z.enum([
5
+ export const oidcAuthorizationResponseErrorSchema = z.enum([
9
6
  // The Authorization Server requires End-User interaction of some form to proceed. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User interaction.
10
7
  'interaction_required',
11
8
  // The Authorization Server requires End-User authentication. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User authentication.
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-authorization-error-response.js","sourceRoot":"","sources":["../src/oidc-authorization-error-response.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEvB;;GAEG;AACU,QAAA,oCAAoC,GAAG,OAAC,CAAC,IAAI,CAAC;IACzD,qSAAqS;IACrS,sBAAsB;IACtB,mRAAmR;IACnR,gBAAgB;IAChB,kbAAkb;IAClb,4BAA4B;IAC5B,qQAAqQ;IACrQ,kBAAkB;IAClB,0FAA0F;IAC1F,qBAAqB;IACrB,4DAA4D;IAC5D,wBAAwB;IACxB,6EAA6E;IAC7E,uBAAuB;IACvB,iFAAiF;IACjF,2BAA2B;IAC3B,sFAAsF;IACtF,4BAA4B;CAC7B,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\n/**\n * @see {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthError}\n */\nexport const oidcAuthorizationResponseErrorSchema = z.enum([\n // The Authorization Server requires End-User interaction of some form to proceed. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User interaction.\n 'interaction_required',\n // The Authorization Server requires End-User authentication. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User authentication.\n 'login_required',\n // The End-User is REQUIRED to select a session at the Authorization Server. The End-User MAY be authenticated at the Authorization Server with different associated accounts, but the End-User did not select a session. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface to prompt for a session to use.\n 'account_selection_required',\n // The Authorization Server requires End-User consent. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User consent.\n 'consent_required',\n // The request_uri in the Authorization Request returns an error or contains invalid data.\n 'invalid_request_uri',\n // The request parameter contains an invalid Request Object.\n 'invalid_request_object',\n // The OP does not support use of the request parameter defined in Section 6.\n 'request_not_supported',\n // The OP does not support use of the request_uri parameter defined in Section 6.\n 'request_uri_not_supported',\n // The OP does not support use of the registration parameter defined in Section 7.2.1.\n 'registration_not_supported',\n])\n\nexport type OidcAuthorizationResponseError = z.infer<\n typeof oidcAuthorizationResponseErrorSchema\n>\n"]}
1
+ {"version":3,"file":"oidc-authorization-error-response.js","sourceRoot":"","sources":["../src/oidc-authorization-error-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAC,IAAI,CAAC;IACzD,qSAAqS;IACrS,sBAAsB;IACtB,mRAAmR;IACnR,gBAAgB;IAChB,kbAAkb;IAClb,4BAA4B;IAC5B,qQAAqQ;IACrQ,kBAAkB;IAClB,0FAA0F;IAC1F,qBAAqB;IACrB,4DAA4D;IAC5D,wBAAwB;IACxB,6EAA6E;IAC7E,uBAAuB;IACvB,iFAAiF;IACjF,2BAA2B;IAC3B,sFAAsF;IACtF,4BAA4B;CAC7B,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\n/**\n * @see {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthError}\n */\nexport const oidcAuthorizationResponseErrorSchema = z.enum([\n // The Authorization Server requires End-User interaction of some form to proceed. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User interaction.\n 'interaction_required',\n // The Authorization Server requires End-User authentication. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User authentication.\n 'login_required',\n // The End-User is REQUIRED to select a session at the Authorization Server. The End-User MAY be authenticated at the Authorization Server with different associated accounts, but the End-User did not select a session. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface to prompt for a session to use.\n 'account_selection_required',\n // The Authorization Server requires End-User consent. This error MAY be returned when the prompt parameter value in the Authentication Request is none, but the Authentication Request cannot be completed without displaying a user interface for End-User consent.\n 'consent_required',\n // The request_uri in the Authorization Request returns an error or contains invalid data.\n 'invalid_request_uri',\n // The request parameter contains an invalid Request Object.\n 'invalid_request_object',\n // The OP does not support use of the request parameter defined in Section 6.\n 'request_not_supported',\n // The OP does not support use of the request_uri parameter defined in Section 6.\n 'request_uri_not_supported',\n // The OP does not support use of the registration parameter defined in Section 7.2.1.\n 'registration_not_supported',\n])\n\nexport type OidcAuthorizationResponseError = z.infer<\n typeof oidcAuthorizationResponseErrorSchema\n>\n"]}
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oidcClaimsParameterSchema = void 0;
4
- const zod_1 = require("zod");
5
- exports.oidcClaimsParameterSchema = zod_1.z.enum([
1
+ import { z } from 'zod';
2
+ export const oidcClaimsParameterSchema = z.enum([
6
3
  // https://openid.net/specs/openid-provider-authentication-policy-extension-1_0.html#rfc.section.5.2
7
4
  // if client metadata "require_auth_time" is true, this *must* be provided
8
5
  'auth_time',
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-claims-parameter.js","sourceRoot":"","sources":["../src/oidc-claims-parameter.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,yBAAyB,GAAG,OAAC,CAAC,IAAI,CAAC;IAC9C,oGAAoG;IACpG,0EAA0E;IAC1E,WAAW;IAEX,OAAO;IACP,OAAO;IACP,KAAK;IAEL,0BAA0B;IAC1B,MAAM;IACN,aAAa;IACb,YAAY;IACZ,aAAa;IACb,UAAU;IACV,oBAAoB;IACpB,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,WAAW;IACX,UAAU;IACV,QAAQ;IACR,YAAY;IAEZ,wBAAwB;IACxB,OAAO;IACP,gBAAgB;IAEhB,wBAAwB;IACxB,cAAc;IACd,uBAAuB;IAEvB,0BAA0B;IAC1B,SAAS;CACV,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcClaimsParameterSchema = z.enum([\n // https://openid.net/specs/openid-provider-authentication-policy-extension-1_0.html#rfc.section.5.2\n // if client metadata \"require_auth_time\" is true, this *must* be provided\n 'auth_time',\n\n // OIDC\n 'nonce',\n 'acr',\n\n // OpenID: \"profile\" scope\n 'name',\n 'family_name',\n 'given_name',\n 'middle_name',\n 'nickname',\n 'preferred_username',\n 'gender',\n 'picture',\n 'profile',\n 'website',\n 'birthdate',\n 'zoneinfo',\n 'locale',\n 'updated_at',\n\n // OpenID: \"email\" scope\n 'email',\n 'email_verified',\n\n // OpenID: \"phone\" scope\n 'phone_number',\n 'phone_number_verified',\n\n // OpenID: \"address\" scope\n 'address',\n])\n\nexport type OidcClaimsParameter = z.infer<typeof oidcClaimsParameterSchema>\n"]}
1
+ {"version":3,"file":"oidc-claims-parameter.js","sourceRoot":"","sources":["../src/oidc-claims-parameter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC9C,oGAAoG;IACpG,0EAA0E;IAC1E,WAAW;IAEX,OAAO;IACP,OAAO;IACP,KAAK;IAEL,0BAA0B;IAC1B,MAAM;IACN,aAAa;IACb,YAAY;IACZ,aAAa;IACb,UAAU;IACV,oBAAoB;IACpB,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,WAAW;IACX,UAAU;IACV,QAAQ;IACR,YAAY;IAEZ,wBAAwB;IACxB,OAAO;IACP,gBAAgB;IAEhB,wBAAwB;IACxB,cAAc;IACd,uBAAuB;IAEvB,0BAA0B;IAC1B,SAAS;CACV,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcClaimsParameterSchema = z.enum([\n // https://openid.net/specs/openid-provider-authentication-policy-extension-1_0.html#rfc.section.5.2\n // if client metadata \"require_auth_time\" is true, this *must* be provided\n 'auth_time',\n\n // OIDC\n 'nonce',\n 'acr',\n\n // OpenID: \"profile\" scope\n 'name',\n 'family_name',\n 'given_name',\n 'middle_name',\n 'nickname',\n 'preferred_username',\n 'gender',\n 'picture',\n 'profile',\n 'website',\n 'birthdate',\n 'zoneinfo',\n 'locale',\n 'updated_at',\n\n // OpenID: \"email\" scope\n 'email',\n 'email_verified',\n\n // OpenID: \"phone\" scope\n 'phone_number',\n 'phone_number_verified',\n\n // OpenID: \"address\" scope\n 'address',\n])\n\nexport type OidcClaimsParameter = z.infer<typeof oidcClaimsParameterSchema>\n"]}
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oidcClaimsPropertiesSchema = void 0;
4
- const zod_1 = require("zod");
5
- const oidcClaimsValueSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]);
6
- exports.oidcClaimsPropertiesSchema = zod_1.z.object({
7
- essential: zod_1.z.boolean().optional(),
1
+ import { z } from 'zod';
2
+ const oidcClaimsValueSchema = z.union([z.string(), z.number(), z.boolean()]);
3
+ export const oidcClaimsPropertiesSchema = z.object({
4
+ essential: z.boolean().optional(),
8
5
  value: oidcClaimsValueSchema.optional(),
9
- values: zod_1.z.array(oidcClaimsValueSchema).optional(),
6
+ values: z.array(oidcClaimsValueSchema).optional(),
10
7
  });
11
8
  //# sourceMappingURL=oidc-claims-properties.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-claims-properties.js","sourceRoot":"","sources":["../src/oidc-claims-properties.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEvB,MAAM,qBAAqB,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AAE/D,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IACjD,SAAS,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,KAAK,EAAE,qBAAqB,CAAC,QAAQ,EAAE;IACvC,MAAM,EAAE,OAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nconst oidcClaimsValueSchema = z.union([z.string(), z.number(), z.boolean()])\n\nexport const oidcClaimsPropertiesSchema = z.object({\n essential: z.boolean().optional(),\n value: oidcClaimsValueSchema.optional(),\n values: z.array(oidcClaimsValueSchema).optional(),\n})\n\nexport type OidcClaimsProperties = z.infer<typeof oidcClaimsPropertiesSchema>\n"]}
1
+ {"version":3,"file":"oidc-claims-properties.js","sourceRoot":"","sources":["../src/oidc-claims-properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AAE5E,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,KAAK,EAAE,qBAAqB,CAAC,QAAQ,EAAE;IACvC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nconst oidcClaimsValueSchema = z.union([z.string(), z.number(), z.boolean()])\n\nexport const oidcClaimsPropertiesSchema = z.object({\n essential: z.boolean().optional(),\n value: oidcClaimsValueSchema.optional(),\n values: z.array(oidcClaimsValueSchema).optional(),\n})\n\nexport type OidcClaimsProperties = z.infer<typeof oidcClaimsPropertiesSchema>\n"]}
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oidcEntityTypeSchema = void 0;
4
- const zod_1 = require("zod");
5
- exports.oidcEntityTypeSchema = zod_1.z.enum(['userinfo', 'id_token']);
1
+ import { z } from 'zod';
2
+ export const oidcEntityTypeSchema = z.enum(['userinfo', 'id_token']);
6
3
  //# sourceMappingURL=oidc-entity-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-entity-type.js","sourceRoot":"","sources":["../src/oidc-entity-type.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,oBAAoB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcEntityTypeSchema = z.enum(['userinfo', 'id_token'])\n\nexport type OidcEntityType = z.infer<typeof oidcEntityTypeSchema>\n"]}
1
+ {"version":3,"file":"oidc-entity-type.js","sourceRoot":"","sources":["../src/oidc-entity-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcEntityTypeSchema = z.enum(['userinfo', 'id_token'])\n\nexport type OidcEntityType = z.infer<typeof oidcEntityTypeSchema>\n"]}
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oidcUserinfoSchema = void 0;
4
- const zod_1 = require("zod");
5
- exports.oidcUserinfoSchema = zod_1.z.object({
6
- sub: zod_1.z.string(),
7
- iss: zod_1.z.string().url().optional(),
8
- aud: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string()).min(1)]).optional(),
9
- email: zod_1.z.string().email().optional(),
10
- email_verified: zod_1.z.boolean().optional(),
11
- name: zod_1.z.string().optional(),
12
- preferred_username: zod_1.z.string().optional(),
13
- picture: zod_1.z.string().url().optional(),
1
+ import { z } from 'zod';
2
+ export const oidcUserinfoSchema = z.object({
3
+ sub: z.string(),
4
+ iss: z.string().url().optional(),
5
+ aud: z.union([z.string(), z.array(z.string()).min(1)]).optional(),
6
+ email: z.string().email().optional(),
7
+ email_verified: z.boolean().optional(),
8
+ name: z.string().optional(),
9
+ preferred_username: z.string().optional(),
10
+ picture: z.string().url().optional(),
14
11
  });
15
12
  //# sourceMappingURL=oidc-userinfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-userinfo.js","sourceRoot":"","sources":["../src/oidc-userinfo.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,GAAG,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAEjE,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,kBAAkB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcUserinfoSchema = z.object({\n sub: z.string(),\n iss: z.string().url().optional(),\n aud: z.union([z.string(), z.array(z.string()).min(1)]).optional(),\n\n email: z.string().email().optional(),\n email_verified: z.boolean().optional(),\n name: z.string().optional(),\n preferred_username: z.string().optional(),\n picture: z.string().url().optional(),\n})\n\nexport type OidcUserinfo = z.infer<typeof oidcUserinfoSchema>\n"]}
1
+ {"version":3,"file":"oidc-userinfo.js","sourceRoot":"","sources":["../src/oidc-userinfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAEjE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAA","sourcesContent":["import { z } from 'zod'\n\nexport const oidcUserinfoSchema = z.object({\n sub: z.string(),\n iss: z.string().url().optional(),\n aud: z.union([z.string(), z.array(z.string()).min(1)]).optional(),\n\n email: z.string().email().optional(),\n email_verified: z.boolean().optional(),\n name: z.string().optional(),\n preferred_username: z.string().optional(),\n picture: z.string().url().optional(),\n})\n\nexport type OidcUserinfo = z.infer<typeof oidcUserinfoSchema>\n"]}
package/dist/uri.js CHANGED
@@ -1,55 +1,52 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.privateUseUriSchema = exports.webUriSchema = exports.httpsUriSchema = exports.loopbackUriSchema = exports.dangerousUriSchema = void 0;
4
- const zod_1 = require("zod");
5
- const util_js_1 = require("./util.js");
1
+ import { ZodIssueCode, z } from 'zod';
2
+ import { canParseUrl, isHostnameIP, isLocalHostname, isLoopbackHost, } from './util.js';
6
3
  /**
7
4
  * Valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).
8
5
  *
9
6
  * Any value that matches this schema is safe to parse using `new URL()`.
10
7
  */
11
- exports.dangerousUriSchema = zod_1.z
8
+ export const dangerousUriSchema = z
12
9
  .string()
13
- .refine((data) => data.includes(':') && (0, util_js_1.canParseUrl)(data), {
10
+ .refine((data) => data.includes(':') && canParseUrl(data), {
14
11
  message: 'Invalid URL',
15
12
  });
16
- exports.loopbackUriSchema = exports.dangerousUriSchema.superRefine((value, ctx) => {
13
+ export const loopbackUriSchema = dangerousUriSchema.superRefine((value, ctx) => {
17
14
  // Loopback url must use the "http:" protocol
18
15
  if (!value.startsWith('http://')) {
19
16
  ctx.addIssue({
20
- code: zod_1.ZodIssueCode.custom,
17
+ code: ZodIssueCode.custom,
21
18
  message: 'URL must use the "http:" protocol',
22
19
  });
23
20
  return false;
24
21
  }
25
22
  const url = new URL(value);
26
- if (!(0, util_js_1.isLoopbackHost)(url.hostname)) {
23
+ if (!isLoopbackHost(url.hostname)) {
27
24
  ctx.addIssue({
28
- code: zod_1.ZodIssueCode.custom,
25
+ code: ZodIssueCode.custom,
29
26
  message: 'URL must use "localhost", "127.0.0.1" or "[::1]" as hostname',
30
27
  });
31
28
  return false;
32
29
  }
33
30
  return true;
34
31
  });
35
- exports.httpsUriSchema = exports.dangerousUriSchema.superRefine((value, ctx) => {
32
+ export const httpsUriSchema = dangerousUriSchema.superRefine((value, ctx) => {
36
33
  if (!value.startsWith('https://')) {
37
34
  ctx.addIssue({
38
- code: zod_1.ZodIssueCode.custom,
35
+ code: ZodIssueCode.custom,
39
36
  message: 'URL must use the "https:" protocol',
40
37
  });
41
38
  return false;
42
39
  }
43
40
  const url = new URL(value);
44
41
  // Disallow loopback URLs with the `https:` protocol
45
- if ((0, util_js_1.isLoopbackHost)(url.hostname)) {
42
+ if (isLoopbackHost(url.hostname)) {
46
43
  ctx.addIssue({
47
- code: zod_1.ZodIssueCode.custom,
44
+ code: ZodIssueCode.custom,
48
45
  message: 'https: URL must not use a loopback host',
49
46
  });
50
47
  return false;
51
48
  }
52
- if ((0, util_js_1.isHostnameIP)(url.hostname)) {
49
+ if (isHostnameIP(url.hostname)) {
53
50
  // Hostname is an IP address
54
51
  }
55
52
  else {
@@ -57,14 +54,14 @@ exports.httpsUriSchema = exports.dangerousUriSchema.superRefine((value, ctx) =>
57
54
  if (!url.hostname.includes('.')) {
58
55
  // we don't depend on PSL here, so we only check for a dot
59
56
  ctx.addIssue({
60
- code: zod_1.ZodIssueCode.custom,
57
+ code: ZodIssueCode.custom,
61
58
  message: 'Domain name must contain at least two segments',
62
59
  });
63
60
  return false;
64
61
  }
65
62
  if (url.hostname.endsWith('.local')) {
66
63
  ctx.addIssue({
67
- code: zod_1.ZodIssueCode.custom,
64
+ code: ZodIssueCode.custom,
68
65
  message: 'Domain name must not end with ".local"',
69
66
  });
70
67
  return false;
@@ -72,35 +69,35 @@ exports.httpsUriSchema = exports.dangerousUriSchema.superRefine((value, ctx) =>
72
69
  }
73
70
  return true;
74
71
  });
75
- exports.webUriSchema = zod_1.z
72
+ export const webUriSchema = z
76
73
  .string()
77
74
  .superRefine((value, ctx) => {
78
75
  // discriminated union of `loopbackUriSchema` and `httpsUriSchema`
79
76
  if (value.startsWith('http://')) {
80
- const result = exports.loopbackUriSchema.safeParse(value);
77
+ const result = loopbackUriSchema.safeParse(value);
81
78
  if (!result.success)
82
79
  result.error.issues.forEach(ctx.addIssue, ctx);
83
80
  return result.success;
84
81
  }
85
82
  if (value.startsWith('https://')) {
86
- const result = exports.httpsUriSchema.safeParse(value);
83
+ const result = httpsUriSchema.safeParse(value);
87
84
  if (!result.success)
88
85
  result.error.issues.forEach(ctx.addIssue, ctx);
89
86
  return result.success;
90
87
  }
91
88
  ctx.addIssue({
92
- code: zod_1.ZodIssueCode.custom,
89
+ code: ZodIssueCode.custom,
93
90
  message: 'URL must use the "http:" or "https:" protocol',
94
91
  });
95
92
  return false;
96
93
  });
97
- exports.privateUseUriSchema = exports.dangerousUriSchema.superRefine((value, ctx) => {
94
+ export const privateUseUriSchema = dangerousUriSchema.superRefine((value, ctx) => {
98
95
  const dotIdx = value.indexOf('.');
99
96
  const colonIdx = value.indexOf(':');
100
97
  // Optimization: avoid parsing the URL if the protocol does not contain a "."
101
98
  if (dotIdx === -1 || colonIdx === -1 || dotIdx > colonIdx) {
102
99
  ctx.addIssue({
103
- code: zod_1.ZodIssueCode.custom,
100
+ code: ZodIssueCode.custom,
104
101
  message: 'Private-use URI scheme requires a "." as part of the protocol',
105
102
  });
106
103
  return false;
@@ -109,7 +106,7 @@ exports.privateUseUriSchema = exports.dangerousUriSchema.superRefine((value, ctx
109
106
  // Should be covered by the check before, but let's be extra sure
110
107
  if (!url.protocol.includes('.')) {
111
108
  ctx.addIssue({
112
- code: zod_1.ZodIssueCode.custom,
109
+ code: ZodIssueCode.custom,
113
110
  message: 'Invalid private-use URI scheme',
114
111
  });
115
112
  return false;
@@ -140,9 +137,9 @@ exports.privateUseUriSchema = exports.dangerousUriSchema.superRefine((value, ctx
140
137
  // no concept of `client_id` in this context).
141
138
  const uriScheme = url.protocol.slice(0, -1); // remove trailing ":"
142
139
  const urlDomain = uriScheme.split('.').reverse().join('.');
143
- if ((0, util_js_1.isLocalHostname)(urlDomain)) {
140
+ if (isLocalHostname(urlDomain)) {
144
141
  ctx.addIssue({
145
- code: zod_1.ZodIssueCode.custom,
142
+ code: ZodIssueCode.custom,
146
143
  message: `Private-use URI Scheme redirect URI must not be a local hostname`,
147
144
  });
148
145
  }
@@ -157,7 +154,7 @@ exports.privateUseUriSchema = exports.dangerousUriSchema.superRefine((value, ctx
157
154
  url.hostname ||
158
155
  url.port) {
159
156
  ctx.addIssue({
160
- code: zod_1.ZodIssueCode.custom,
157
+ code: ZodIssueCode.custom,
161
158
  message: 'Private-Use URI Scheme must be in the form <scheme>:/{path} (notice the single slash!) as per RFC 8252',
162
159
  });
163
160
  return false;
package/dist/uri.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"uri.js","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":";;;AAAA,6BAA6C;AAC7C,uCAKkB;AAElB;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,OAAC;KAChC,MAAM,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CAAA","sourcesContent":["import { TypeOf, ZodIssueCode, z } from 'zod'\nimport {\n canParseUrl,\n isHostnameIP,\n isLocalHostname,\n isLoopbackHost,\n} from './util.js'\n\n/**\n * Valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).\n *\n * Any value that matches this schema is safe to parse using `new URL()`.\n */\nexport const dangerousUriSchema = z\n .string()\n .refine(\n (data): data is `${string}:${string}` =>\n data.includes(':') && canParseUrl(data),\n {\n message: 'Invalid URL',\n },\n )\n\n/**\n * Valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).\n */\nexport type DangerousUrl = TypeOf<typeof dangerousUriSchema>\n\nexport const loopbackUriSchema = dangerousUriSchema.superRefine(\n (\n value,\n ctx,\n ): value is\n | `http://[::1]${string}`\n | `http://localhost${'' | `${':' | '/' | '?' | '#'}${string}`}`\n | `http://127.0.0.1${'' | `${':' | '/' | '?' | '#'}${string}`}` => {\n // Loopback url must use the \"http:\" protocol\n if (!value.startsWith('http://')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"http:\" protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n if (!isLoopbackHost(url.hostname)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use \"localhost\", \"127.0.0.1\" or \"[::1]\" as hostname',\n })\n return false\n }\n\n return true\n },\n)\n\nexport type LoopbackUri = TypeOf<typeof loopbackUriSchema>\n\nexport const httpsUriSchema = dangerousUriSchema.superRefine(\n (value, ctx): value is `https://${string}` => {\n if (!value.startsWith('https://')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"https:\" protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n // Disallow loopback URLs with the `https:` protocol\n if (isLoopbackHost(url.hostname)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'https: URL must not use a loopback host',\n })\n return false\n }\n\n if (isHostnameIP(url.hostname)) {\n // Hostname is an IP address\n } else {\n // Hostname is a domain name\n if (!url.hostname.includes('.')) {\n // we don't depend on PSL here, so we only check for a dot\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Domain name must contain at least two segments',\n })\n return false\n }\n\n if (url.hostname.endsWith('.local')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Domain name must not end with \".local\"',\n })\n return false\n }\n }\n\n return true\n },\n)\n\nexport type HttpsUri = TypeOf<typeof httpsUriSchema>\n\nexport const webUriSchema = z\n .string()\n .superRefine((value, ctx): value is LoopbackUri | HttpsUri => {\n // discriminated union of `loopbackUriSchema` and `httpsUriSchema`\n if (value.startsWith('http://')) {\n const result = loopbackUriSchema.safeParse(value)\n if (!result.success) result.error.issues.forEach(ctx.addIssue, ctx)\n return result.success\n }\n\n if (value.startsWith('https://')) {\n const result = httpsUriSchema.safeParse(value)\n if (!result.success) result.error.issues.forEach(ctx.addIssue, ctx)\n return result.success\n }\n\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"http:\" or \"https:\" protocol',\n })\n return false\n })\n\nexport type WebUri = TypeOf<typeof webUriSchema>\n\nexport const privateUseUriSchema = dangerousUriSchema.superRefine(\n (value, ctx): value is `${string}.${string}:/${string}` => {\n const dotIdx = value.indexOf('.')\n const colonIdx = value.indexOf(':')\n\n // Optimization: avoid parsing the URL if the protocol does not contain a \".\"\n if (dotIdx === -1 || colonIdx === -1 || dotIdx > colonIdx) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message:\n 'Private-use URI scheme requires a \".\" as part of the protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n // Should be covered by the check before, but let's be extra sure\n if (!url.protocol.includes('.')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Invalid private-use URI scheme',\n })\n return false\n }\n\n // https://datatracker.ietf.org/doc/html/rfc8252#section-7.1\n //\n // > When choosing a URI scheme to associate with the app, apps MUST use a\n // > URI scheme based on a domain name under their control, expressed in\n // > reverse order\n //\n // https://datatracker.ietf.org/doc/html/rfc8252#section-8.4\n //\n // > In addition to the collision-resistant properties, requiring a URI\n // > scheme based on a domain name that is under the control of the app can\n // > help to prove ownership in the event of a dispute where two apps claim\n // > the same private-use URI scheme (where one app is acting maliciously).\n //\n // We can't check for ownership here (as there is no concept of proven\n // ownership in a generic validation logic), besides excluding local domains\n // as they can't be controlled/owned by the app.\n //\n // https://atproto.com/specs/oauth\n //\n // > Any custom scheme must match the `client_id` hostname in reverse-domain\n // > order.\n //\n // This ATPROTO specific requirement cannot be enforced here, (as there is\n // no concept of `client_id` in this context).\n\n const uriScheme = url.protocol.slice(0, -1) // remove trailing \":\"\n const urlDomain = uriScheme.split('.').reverse().join('.')\n\n if (isLocalHostname(urlDomain)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Private-use URI Scheme redirect URI must not be a local hostname`,\n })\n }\n\n // https://datatracker.ietf.org/doc/html/rfc8252#section-7.1\n //\n // > Following the requirements of Section 3.2 of [RFC3986], as there is no\n // > naming authority for private-use URI scheme redirects, only a single\n // > slash (\"/\") appears after the scheme component.\n if (\n url.href.startsWith(`${url.protocol}//`) ||\n url.username ||\n url.password ||\n url.hostname ||\n url.port\n ) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message:\n 'Private-Use URI Scheme must be in the form <scheme>:/{path} (notice the single slash!) as per RFC 8252',\n })\n return false\n }\n\n return true\n },\n)\n\nexport type PrivateUseUri = TypeOf<typeof privateUseUriSchema>\n"]}
1
+ {"version":3,"file":"uri.js","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,cAAc,GACf,MAAM,WAAW,CAAA;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,EAAE;KACR,MAAM,CACL,CAAC,IAAI,EAAiC,EAAE,CACtC,IAAI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,\n isHostnameIP,\n isLocalHostname,\n isLoopbackHost,\n} from './util.js'\n\n/**\n * Valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).\n *\n * Any value that matches this schema is safe to parse using `new URL()`.\n */\nexport const dangerousUriSchema = z\n .string()\n .refine(\n (data): data is `${string}:${string}` =>\n data.includes(':') && canParseUrl(data),\n {\n message: 'Invalid URL',\n },\n )\n\n/**\n * Valid, but potentially dangerous URL (`data:`, `file:`, `javascript:`, etc.).\n */\nexport type DangerousUrl = TypeOf<typeof dangerousUriSchema>\n\nexport const loopbackUriSchema = dangerousUriSchema.superRefine(\n (\n value,\n ctx,\n ): value is\n | `http://[::1]${string}`\n | `http://localhost${'' | `${':' | '/' | '?' | '#'}${string}`}`\n | `http://127.0.0.1${'' | `${':' | '/' | '?' | '#'}${string}`}` => {\n // Loopback url must use the \"http:\" protocol\n if (!value.startsWith('http://')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"http:\" protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n if (!isLoopbackHost(url.hostname)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use \"localhost\", \"127.0.0.1\" or \"[::1]\" as hostname',\n })\n return false\n }\n\n return true\n },\n)\n\nexport type LoopbackUri = TypeOf<typeof loopbackUriSchema>\n\nexport const httpsUriSchema = dangerousUriSchema.superRefine(\n (value, ctx): value is `https://${string}` => {\n if (!value.startsWith('https://')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"https:\" protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n // Disallow loopback URLs with the `https:` protocol\n if (isLoopbackHost(url.hostname)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'https: URL must not use a loopback host',\n })\n return false\n }\n\n if (isHostnameIP(url.hostname)) {\n // Hostname is an IP address\n } else {\n // Hostname is a domain name\n if (!url.hostname.includes('.')) {\n // we don't depend on PSL here, so we only check for a dot\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Domain name must contain at least two segments',\n })\n return false\n }\n\n if (url.hostname.endsWith('.local')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Domain name must not end with \".local\"',\n })\n return false\n }\n }\n\n return true\n },\n)\n\nexport type HttpsUri = TypeOf<typeof httpsUriSchema>\n\nexport const webUriSchema = z\n .string()\n .superRefine((value, ctx): value is LoopbackUri | HttpsUri => {\n // discriminated union of `loopbackUriSchema` and `httpsUriSchema`\n if (value.startsWith('http://')) {\n const result = loopbackUriSchema.safeParse(value)\n if (!result.success) result.error.issues.forEach(ctx.addIssue, ctx)\n return result.success\n }\n\n if (value.startsWith('https://')) {\n const result = httpsUriSchema.safeParse(value)\n if (!result.success) result.error.issues.forEach(ctx.addIssue, ctx)\n return result.success\n }\n\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'URL must use the \"http:\" or \"https:\" protocol',\n })\n return false\n })\n\nexport type WebUri = TypeOf<typeof webUriSchema>\n\nexport const privateUseUriSchema = dangerousUriSchema.superRefine(\n (value, ctx): value is `${string}.${string}:/${string}` => {\n const dotIdx = value.indexOf('.')\n const colonIdx = value.indexOf(':')\n\n // Optimization: avoid parsing the URL if the protocol does not contain a \".\"\n if (dotIdx === -1 || colonIdx === -1 || dotIdx > colonIdx) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message:\n 'Private-use URI scheme requires a \".\" as part of the protocol',\n })\n return false\n }\n\n const url = new URL(value)\n\n // Should be covered by the check before, but let's be extra sure\n if (!url.protocol.includes('.')) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: 'Invalid private-use URI scheme',\n })\n return false\n }\n\n // https://datatracker.ietf.org/doc/html/rfc8252#section-7.1\n //\n // > When choosing a URI scheme to associate with the app, apps MUST use a\n // > URI scheme based on a domain name under their control, expressed in\n // > reverse order\n //\n // https://datatracker.ietf.org/doc/html/rfc8252#section-8.4\n //\n // > In addition to the collision-resistant properties, requiring a URI\n // > scheme based on a domain name that is under the control of the app can\n // > help to prove ownership in the event of a dispute where two apps claim\n // > the same private-use URI scheme (where one app is acting maliciously).\n //\n // We can't check for ownership here (as there is no concept of proven\n // ownership in a generic validation logic), besides excluding local domains\n // as they can't be controlled/owned by the app.\n //\n // https://atproto.com/specs/oauth\n //\n // > Any custom scheme must match the `client_id` hostname in reverse-domain\n // > order.\n //\n // This ATPROTO specific requirement cannot be enforced here, (as there is\n // no concept of `client_id` in this context).\n\n const uriScheme = url.protocol.slice(0, -1) // remove trailing \":\"\n const urlDomain = uriScheme.split('.').reverse().join('.')\n\n if (isLocalHostname(urlDomain)) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message: `Private-use URI Scheme redirect URI must not be a local hostname`,\n })\n }\n\n // https://datatracker.ietf.org/doc/html/rfc8252#section-7.1\n //\n // > Following the requirements of Section 3.2 of [RFC3986], as there is no\n // > naming authority for private-use URI scheme redirects, only a single\n // > slash (\"/\") appears after the scheme component.\n if (\n url.href.startsWith(`${url.protocol}//`) ||\n url.username ||\n url.password ||\n url.hostname ||\n url.port\n ) {\n ctx.addIssue({\n code: ZodIssueCode.custom,\n message:\n 'Private-Use URI Scheme must be in the form <scheme>:/{path} (notice the single slash!) as per RFC 8252',\n })\n return false\n }\n\n return true\n },\n)\n\nexport type PrivateUseUri = TypeOf<typeof privateUseUriSchema>\n"]}
package/dist/util.js CHANGED
@@ -1,15 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSpaceSeparatedValue = exports.numberPreprocess = exports.jsonObjectPreprocess = exports.canParseUrl = void 0;
4
- exports.isHostnameIP = isHostnameIP;
5
- exports.isLoopbackHost = isLoopbackHost;
6
- exports.isLocalHostname = isLocalHostname;
7
- exports.safeUrl = safeUrl;
8
- exports.extractUrlPath = extractUrlPath;
9
- exports.arrayEquivalent = arrayEquivalent;
10
- exports.includedIn = includedIn;
11
- exports.asArray = asArray;
12
- exports.canParseUrl =
1
+ export const canParseUrl =
13
2
  // eslint-disable-next-line n/no-unsupported-features/node-builtins
14
3
  URL.canParse?.bind(URL) ??
15
4
  // URL.canParse is not available in Node.js < 18.7.0
@@ -22,7 +11,7 @@ URL.canParse?.bind(URL) ??
22
11
  return false;
23
12
  }
24
13
  });
25
- function isHostnameIP(hostname) {
14
+ export function isHostnameIP(hostname) {
26
15
  // IPv4
27
16
  if (hostname.match(/^\d+\.\d+\.\d+\.\d+$/))
28
17
  return true;
@@ -31,10 +20,10 @@ function isHostnameIP(hostname) {
31
20
  return true;
32
21
  return false;
33
22
  }
34
- function isLoopbackHost(host) {
23
+ export function isLoopbackHost(host) {
35
24
  return host === 'localhost' || host === '127.0.0.1' || host === '[::1]';
36
25
  }
37
- function isLocalHostname(hostname) {
26
+ export function isLocalHostname(hostname) {
38
27
  const parts = hostname.split('.');
39
28
  if (parts.length < 2)
40
29
  return true;
@@ -45,7 +34,7 @@ function isLocalHostname(hostname) {
45
34
  tld === 'invalid' ||
46
35
  tld === 'example');
47
36
  }
48
- function safeUrl(input) {
37
+ export function safeUrl(input) {
49
38
  try {
50
39
  return new URL(input);
51
40
  }
@@ -53,7 +42,7 @@ function safeUrl(input) {
53
42
  return null;
54
43
  }
55
44
  }
56
- function extractUrlPath(url) {
45
+ export function extractUrlPath(url) {
57
46
  // Extracts the path from a URL, without relying on the URL constructor
58
47
  // (because it normalizes the URL)
59
48
  const endOfProtocol = url.startsWith('https://')
@@ -83,7 +72,7 @@ function extractUrlPath(url) {
83
72
  }
84
73
  return url.substring(pathStart, pathEnd);
85
74
  }
86
- const jsonObjectPreprocess = (val) => {
75
+ export const jsonObjectPreprocess = (val) => {
87
76
  if (typeof val === 'string' && val.startsWith('{') && val.endsWith('}')) {
88
77
  try {
89
78
  return JSON.parse(val);
@@ -94,8 +83,7 @@ const jsonObjectPreprocess = (val) => {
94
83
  }
95
84
  return val;
96
85
  };
97
- exports.jsonObjectPreprocess = jsonObjectPreprocess;
98
- const numberPreprocess = (val) => {
86
+ export const numberPreprocess = (val) => {
99
87
  if (typeof val === 'string') {
100
88
  const number = Number(val);
101
89
  if (!Number.isNaN(number))
@@ -103,27 +91,26 @@ const numberPreprocess = (val) => {
103
91
  }
104
92
  return val;
105
93
  };
106
- exports.numberPreprocess = numberPreprocess;
107
94
  /**
108
95
  * Returns true if the two arrays contain the same elements, regardless of order
109
96
  * or duplicates.
110
97
  */
111
- function arrayEquivalent(a, b) {
98
+ export function arrayEquivalent(a, b) {
112
99
  if (a === b)
113
100
  return true;
114
101
  return a.every(includedIn, b) && b.every(includedIn, a);
115
102
  }
116
- function includedIn(item) {
103
+ export function includedIn(item) {
117
104
  return this.includes(item);
118
105
  }
119
- function asArray(value) {
106
+ export function asArray(value) {
120
107
  if (value == null)
121
108
  return undefined;
122
109
  if (Array.isArray(value))
123
110
  return value; // already a (possibly readonly) array
124
111
  return Array.from(value);
125
112
  }
126
- const isSpaceSeparatedValue = (value, input) => {
113
+ export const isSpaceSeparatedValue = (value, input) => {
127
114
  if (value.length === 0)
128
115
  throw new TypeError('Value cannot be empty');
129
116
  if (value.includes(' '))
@@ -149,5 +136,4 @@ const isSpaceSeparatedValue = (value, input) => {
149
136
  }
150
137
  return false;
151
138
  };
152
- exports.isSpaceSeparatedValue = isSpaceSeparatedValue;
153
139
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAaA,oCAQC;AAID,wCAEC;AAED,0CAYC;AAED,0BAMC;AAED,wCAsCC;AA0BD,0CAGC;AAED,gCAEC;AAED,0BAMC;AAlIY,QAAA,WAAW;AACtB,mEAAmE;AACnE,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC;IACvB,oDAAoD;IACpD,CAAC,CAAC,MAAc,EAAW,EAAE;QAC3B,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;YACf,OAAO,IAAI,CAAA;QACb,CAAC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AK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC;AAKM,MAAM,qBAAqB,GAAG,CACnC,KAAY,EACZ,KAAa,EACwB,EAAE;IACvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAA;IACpE,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;IAE3E,wBAAwB;IACxB,0CAA0C;IAE1C,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAChC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;IAEhC,IAAI,WAAW,GAAG,WAAW;QAAE,OAAO,KAAK,CAAA;IAE3C,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9B,IAAI,MAAc,CAAA;IAElB,OAAO,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,GAAG,WAAW,CAAA;QAE1B;QACE,oCAAoC;QACpC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;YAC/C,8BAA8B;YAC9B,CAAC,MAAM,KAAK,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAC3D,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAlCY,QAAA,qBAAqB,yBAkCjC","sourcesContent":["export const canParseUrl =\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n URL.canParse?.bind(URL) ??\n // URL.canParse is not available in Node.js < 18.7.0\n ((urlStr: string): boolean => {\n try {\n new URL(urlStr)\n return true\n } catch {\n return false\n }\n })\n\nexport function isHostnameIP(hostname: string) {\n // IPv4\n if (hostname.match(/^\\d+\\.\\d+\\.\\d+\\.\\d+$/)) return true\n\n // IPv6\n if (hostname.startsWith('[') && hostname.endsWith(']')) return true\n\n return false\n}\n\nexport type LoopbackHost = 'localhost' | '127.0.0.1' | '[::1]'\n\nexport function isLoopbackHost(host: unknown): host is LoopbackHost {\n return host === 'localhost' || host === '127.0.0.1' || host === '[::1]'\n}\n\nexport function isLocalHostname(hostname: string): boolean {\n const parts = hostname.split('.')\n if (parts.length < 2) return true\n\n const tld = parts.at(-1)!.toLowerCase()\n return (\n tld === 'test' ||\n tld === 'local' ||\n tld === 'localhost' ||\n tld === 'invalid' ||\n tld === 'example'\n )\n}\n\nexport function safeUrl(input: URL | string): URL | null {\n try {\n return new URL(input)\n } catch {\n return null\n }\n}\n\nexport function extractUrlPath(url) {\n // Extracts the path from a URL, without relying on the URL constructor\n // (because it normalizes the URL)\n const endOfProtocol = url.startsWith('https://')\n ? 8\n : url.startsWith('http://')\n ? 7\n : -1\n if (endOfProtocol === -1) {\n throw new TypeError('URL must use the \"https:\" or \"http:\" protocol')\n }\n\n const hashIdx = url.indexOf('#', endOfProtocol)\n const questionIdx = url.indexOf('?', endOfProtocol)\n\n const queryStrIdx =\n questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx)\n ? questionIdx\n : -1\n\n const pathEnd =\n hashIdx === -1\n ? queryStrIdx === -1\n ? url.length\n : queryStrIdx\n : queryStrIdx === -1\n ? hashIdx\n : Math.min(hashIdx, queryStrIdx)\n\n const slashIdx = url.indexOf('/', endOfProtocol)\n\n const pathStart = slashIdx === -1 || slashIdx > pathEnd ? pathEnd : slashIdx\n\n if (endOfProtocol === pathStart) {\n throw new TypeError('URL must contain a host')\n }\n\n return url.substring(pathStart, pathEnd)\n}\n\nexport const jsonObjectPreprocess = (val: unknown) => {\n if (typeof val === 'string' && val.startsWith('{') && val.endsWith('}')) {\n try {\n return JSON.parse(val)\n } catch {\n return val\n }\n }\n\n return val\n}\n\nexport const numberPreprocess = (val: unknown): unknown => {\n if (typeof val === 'string') {\n const number = Number(val)\n if (!Number.isNaN(number)) return number\n }\n return val\n}\n\n/**\n * Returns true if the two arrays contain the same elements, regardless of order\n * or duplicates.\n */\nexport function arrayEquivalent<T>(a: readonly T[], b: readonly T[]) {\n if (a === b) return true\n return a.every(includedIn, b) && b.every(includedIn, a)\n}\n\nexport function includedIn<T>(this: readonly T[], item: T) {\n return this.includes(item)\n}\n\nexport function asArray<T>(\n value: Iterable<T> | undefined,\n): undefined | readonly T[] {\n if (value == null) return undefined\n if (Array.isArray(value)) return value // already a (possibly readonly) array\n return Array.from(value)\n}\n\nexport type SpaceSeparatedValue<Value extends string> =\n `${'' | `${string} `}${Value}${'' | ` ${string}`}`\n\nexport const isSpaceSeparatedValue = <Value extends string>(\n value: Value,\n input: string,\n): input is SpaceSeparatedValue<Value> => {\n if (value.length === 0) throw new TypeError('Value cannot be empty')\n if (value.includes(' ')) throw new TypeError('Value cannot contain spaces')\n\n // Optimized version of:\n // return input.split(' ').includes(value)\n\n const inputLength = input.length\n const valueLength = value.length\n\n if (inputLength < valueLength) return false\n\n let idx = input.indexOf(value)\n let idxEnd: number\n\n while (idx !== -1) {\n idxEnd = idx + valueLength\n\n if (\n // at beginning or preceded by space\n (idx === 0 || input.charCodeAt(idx - 1) === 32) &&\n // at end or followed by space\n (idxEnd === inputLength || input.charCodeAt(idxEnd) === 32)\n ) {\n return true\n }\n\n idx = input.indexOf(value, idxEnd + 1)\n }\n\n return false\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW;AACtB,mEAAmE;AACnE,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC;IACvB,oDAAoD;IACpD,CAAC,CAAC,MAAc,EAAW,EAAE;QAC3B,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-features/node-builtins\n URL.canParse?.bind(URL) ??\n // URL.canParse is not available in Node.js < 18.7.0\n ((urlStr: string): boolean => {\n try {\n new URL(urlStr)\n return true\n } catch {\n return false\n }\n })\n\nexport function isHostnameIP(hostname: string) {\n // IPv4\n if (hostname.match(/^\\d+\\.\\d+\\.\\d+\\.\\d+$/)) return true\n\n // IPv6\n if (hostname.startsWith('[') && hostname.endsWith(']')) return true\n\n return false\n}\n\nexport type LoopbackHost = 'localhost' | '127.0.0.1' | '[::1]'\n\nexport function isLoopbackHost(host: unknown): host is LoopbackHost {\n return host === 'localhost' || host === '127.0.0.1' || host === '[::1]'\n}\n\nexport function isLocalHostname(hostname: string): boolean {\n const parts = hostname.split('.')\n if (parts.length < 2) return true\n\n const tld = parts.at(-1)!.toLowerCase()\n return (\n tld === 'test' ||\n tld === 'local' ||\n tld === 'localhost' ||\n tld === 'invalid' ||\n tld === 'example'\n )\n}\n\nexport function safeUrl(input: URL | string): URL | null {\n try {\n return new URL(input)\n } catch {\n return null\n }\n}\n\nexport function extractUrlPath(url) {\n // Extracts the path from a URL, without relying on the URL constructor\n // (because it normalizes the URL)\n const endOfProtocol = url.startsWith('https://')\n ? 8\n : url.startsWith('http://')\n ? 7\n : -1\n if (endOfProtocol === -1) {\n throw new TypeError('URL must use the \"https:\" or \"http:\" protocol')\n }\n\n const hashIdx = url.indexOf('#', endOfProtocol)\n const questionIdx = url.indexOf('?', endOfProtocol)\n\n const queryStrIdx =\n questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx)\n ? questionIdx\n : -1\n\n const pathEnd =\n hashIdx === -1\n ? queryStrIdx === -1\n ? url.length\n : queryStrIdx\n : queryStrIdx === -1\n ? hashIdx\n : Math.min(hashIdx, queryStrIdx)\n\n const slashIdx = url.indexOf('/', endOfProtocol)\n\n const pathStart = slashIdx === -1 || slashIdx > pathEnd ? pathEnd : slashIdx\n\n if (endOfProtocol === pathStart) {\n throw new TypeError('URL must contain a host')\n }\n\n return url.substring(pathStart, pathEnd)\n}\n\nexport const jsonObjectPreprocess = (val: unknown) => {\n if (typeof val === 'string' && val.startsWith('{') && val.endsWith('}')) {\n try {\n return JSON.parse(val)\n } catch {\n return val\n }\n }\n\n return val\n}\n\nexport const numberPreprocess = (val: unknown): unknown => {\n if (typeof val === 'string') {\n const number = Number(val)\n if (!Number.isNaN(number)) return number\n }\n return val\n}\n\n/**\n * Returns true if the two arrays contain the same elements, regardless of order\n * or duplicates.\n */\nexport function arrayEquivalent<T>(a: readonly T[], b: readonly T[]) {\n if (a === b) return true\n return a.every(includedIn, b) && b.every(includedIn, a)\n}\n\nexport function includedIn<T>(this: readonly T[], item: T) {\n return this.includes(item)\n}\n\nexport function asArray<T>(\n value: Iterable<T> | undefined,\n): undefined | readonly T[] {\n if (value == null) return undefined\n if (Array.isArray(value)) return value // already a (possibly readonly) array\n return Array.from(value)\n}\n\nexport type SpaceSeparatedValue<Value extends string> =\n `${'' | `${string} `}${Value}${'' | ` ${string}`}`\n\nexport const isSpaceSeparatedValue = <Value extends string>(\n value: Value,\n input: string,\n): input is SpaceSeparatedValue<Value> => {\n if (value.length === 0) throw new TypeError('Value cannot be empty')\n if (value.includes(' ')) throw new TypeError('Value cannot contain spaces')\n\n // Optimized version of:\n // return input.split(' ').includes(value)\n\n const inputLength = input.length\n const valueLength = value.length\n\n if (inputLength < valueLength) return false\n\n let idx = input.indexOf(value)\n let idxEnd: number\n\n while (idx !== -1) {\n idxEnd = idx + valueLength\n\n if (\n // at beginning or preceded by space\n (idx === 0 || input.charCodeAt(idx - 1) === 32) &&\n // at end or followed by space\n (idxEnd === inputLength || input.charCodeAt(idxEnd) === 32)\n ) {\n return true\n }\n\n idx = input.indexOf(value, idxEnd + 1)\n }\n\n return false\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@atproto/oauth-types",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
+ "engines": {
5
+ "node": ">=22"
6
+ },
4
7
  "license": "MIT",
5
8
  "description": "OAuth typing & validation library",
6
9
  "keywords": [
@@ -15,9 +18,7 @@
15
18
  "url": "https://github.com/bluesky-social/atproto",
16
19
  "directory": "packages/oauth/oauth-types"
17
20
  },
18
- "type": "commonjs",
19
- "main": "dist/index.js",
20
- "types": "dist/index.d.ts",
21
+ "type": "module",
21
22
  "exports": {
22
23
  ".": {
23
24
  "types": "./dist/index.d.ts",
@@ -26,11 +27,11 @@
26
27
  },
27
28
  "dependencies": {
28
29
  "zod": "^3.23.8",
29
- "@atproto/did": "^0.3.0",
30
- "@atproto/jwk": "^0.6.0"
30
+ "@atproto/did": "^0.4.0",
31
+ "@atproto/jwk": "^0.7.0"
31
32
  },
32
33
  "devDependencies": {
33
- "typescript": "^5.6.3"
34
+ "typescript": "^6.0.3"
34
35
  },
35
36
  "scripts": {
36
37
  "build": "tsc --build tsconfig.build.json"
@@ -1,6 +1,6 @@
1
1
  import { TypeOf, z } from 'zod'
2
2
  import { atprotoDidSchema } from '@atproto/did'
3
- import { atprotoOAuthScopeSchema } from './atproto-oauth-scope'
3
+ import { atprotoOAuthScopeSchema } from './atproto-oauth-scope.js'
4
4
  import { oauthTokenResponseSchema } from './oauth-token-response.js'
5
5
 
6
6
  export const atprotoOAuthTokenResponseSchema = oauthTokenResponseSchema.extend({
@@ -1 +1 @@
1
- {"root":["./src/atproto-loopback-client-id.ts","./src/atproto-loopback-client-metadata.ts","./src/atproto-loopback-client-redirect-uris.ts","./src/atproto-oauth-scope.ts","./src/atproto-oauth-token-response.ts","./src/constants.ts","./src/index.ts","./src/oauth-access-token.ts","./src/oauth-authorization-code-grant-token-request.ts","./src/oauth-authorization-details.ts","./src/oauth-authorization-request-jar.ts","./src/oauth-authorization-request-par.ts","./src/oauth-authorization-request-parameters.ts","./src/oauth-authorization-request-query.ts","./src/oauth-authorization-request-uri.ts","./src/oauth-authorization-response-error.ts","./src/oauth-authorization-server-metadata.ts","./src/oauth-client-credentials-grant-token-request.ts","./src/oauth-client-credentials.ts","./src/oauth-client-id-discoverable.ts","./src/oauth-client-id-loopback.ts","./src/oauth-client-id.ts","./src/oauth-client-metadata.ts","./src/oauth-code-challenge-method.ts","./src/oauth-endpoint-auth-method.ts","./src/oauth-endpoint-name.ts","./src/oauth-grant-type.ts","./src/oauth-introspection-response.ts","./src/oauth-issuer-identifier.ts","./src/oauth-par-response.ts","./src/oauth-password-grant-token-request.ts","./src/oauth-prompt-mode.ts","./src/oauth-protected-resource-metadata.ts","./src/oauth-redirect-uri.ts","./src/oauth-refresh-token-grant-token-request.ts","./src/oauth-refresh-token.ts","./src/oauth-request-uri.ts","./src/oauth-response-mode.ts","./src/oauth-response-type.ts","./src/oauth-scope.ts","./src/oauth-token-identification.ts","./src/oauth-token-request.ts","./src/oauth-token-response.ts","./src/oauth-token-type.ts","./src/oidc-authorization-error-response.ts","./src/oidc-claims-parameter.ts","./src/oidc-claims-properties.ts","./src/oidc-entity-type.ts","./src/oidc-userinfo.ts","./src/uri.ts","./src/util.ts"],"version":"5.8.2"}
1
+ {"root":["./src/atproto-loopback-client-id.ts","./src/atproto-loopback-client-metadata.ts","./src/atproto-loopback-client-redirect-uris.ts","./src/atproto-oauth-scope.ts","./src/atproto-oauth-token-response.ts","./src/constants.ts","./src/index.ts","./src/oauth-access-token.ts","./src/oauth-authorization-code-grant-token-request.ts","./src/oauth-authorization-details.ts","./src/oauth-authorization-request-jar.ts","./src/oauth-authorization-request-par.ts","./src/oauth-authorization-request-parameters.ts","./src/oauth-authorization-request-query.ts","./src/oauth-authorization-request-uri.ts","./src/oauth-authorization-response-error.ts","./src/oauth-authorization-server-metadata.ts","./src/oauth-client-credentials-grant-token-request.ts","./src/oauth-client-credentials.ts","./src/oauth-client-id-discoverable.ts","./src/oauth-client-id-loopback.ts","./src/oauth-client-id.ts","./src/oauth-client-metadata.ts","./src/oauth-code-challenge-method.ts","./src/oauth-endpoint-auth-method.ts","./src/oauth-endpoint-name.ts","./src/oauth-grant-type.ts","./src/oauth-introspection-response.ts","./src/oauth-issuer-identifier.ts","./src/oauth-par-response.ts","./src/oauth-password-grant-token-request.ts","./src/oauth-prompt-mode.ts","./src/oauth-protected-resource-metadata.ts","./src/oauth-redirect-uri.ts","./src/oauth-refresh-token-grant-token-request.ts","./src/oauth-refresh-token.ts","./src/oauth-request-uri.ts","./src/oauth-response-mode.ts","./src/oauth-response-type.ts","./src/oauth-scope.ts","./src/oauth-token-identification.ts","./src/oauth-token-request.ts","./src/oauth-token-response.ts","./src/oauth-token-type.ts","./src/oidc-authorization-error-response.ts","./src/oidc-claims-parameter.ts","./src/oidc-claims-properties.ts","./src/oidc-entity-type.ts","./src/oidc-userinfo.ts","./src/uri.ts","./src/util.ts"],"version":"6.0.3"}