@m1212e/rumble 0.25.1 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/index.cjs CHANGED
@@ -216,7 +216,7 @@ function mapNullFieldsToUndefined(obj) {
216
216
  }
217
217
  //#endregion
218
218
  //#region package.json
219
- var version = "0.25.1";
219
+ var version = "0.25.2";
220
220
  //#endregion
221
221
  //#region lib/helpers/tableHelpers.ts
222
222
  const indexCache = /* @__PURE__ */ new WeakMap();
@@ -3115,9 +3115,13 @@ function implementDefaultAddressTypes(schemaBuilder) {
3115
3115
  //#endregion
3116
3116
  //#region lib/scalars/emailAddress.ts
3117
3117
  /**
3118
- * Validates an email address using graphql-scalars' own format check, then lowercases it.
3118
+ * Validates an email address using graphql-scalars' own format check, then lowercases it, exactly
3119
+ * as the `EmailAddress` scalar does. Exported for values that do not arrive as GraphQL input,
3120
+ * such as OIDC claims.
3121
+ *
3122
+ * @throws RumbleErrorSafe if the value is not a valid email address
3119
3123
  */
3120
- const normalize$1 = (value) => {
3124
+ const normalizeEmailAddress = (value) => {
3121
3125
  try {
3122
3126
  return graphql_scalars.EmailAddressResolver.parseValue(value).toLowerCase();
3123
3127
  } catch (error) {
@@ -3128,23 +3132,28 @@ const EmailAddressResolver = new graphql.GraphQLScalarType({
3128
3132
  name: "EmailAddress",
3129
3133
  description: `${graphql_scalars.EmailAddressResolver.description} Lowercased.`,
3130
3134
  specifiedByURL: graphql_scalars.EmailAddressResolver.specifiedByURL,
3131
- serialize: normalize$1,
3132
- parseValue: normalize$1,
3135
+ serialize: normalizeEmailAddress,
3136
+ parseValue: normalizeEmailAddress,
3133
3137
  parseLiteral(ast) {
3134
3138
  if (ast.kind !== graphql.Kind.STRING) throw new RumbleErrorSafe(`Can only validate strings as email addresses but got a: ${ast.kind}`);
3135
- return normalize$1(ast.value);
3139
+ return normalizeEmailAddress(ast.value);
3136
3140
  }
3137
3141
  });
3138
3142
  //#endregion
3139
3143
  //#region lib/scalars/personName.ts
3140
3144
  const MAX_LENGTH = 200;
3141
3145
  const NAME_REGEX = /^[\p{L}\p{M}]+(?:(?:[ '-]|\.\x20?)[\p{L}\p{M}]+)*\.?$/u;
3146
+ const APOSTROPHE_VARIANTS = /[\u2018\u2019\u02BC\u00B4\u0060]/gu;
3147
+ const HYPHEN_VARIANTS = /[\u2010-\u2015\u2212]/gu;
3142
3148
  /**
3143
- * Normalizes and validates a person's name.
3149
+ * Normalizes and validates a person's name, exactly as the `PersonName` scalar does. Exported
3150
+ * for values that do not arrive as GraphQL input, such as OIDC claims.
3151
+ *
3152
+ * @throws RumbleErrorSafe if the value is not a valid name
3144
3153
  */
3145
- const normalize = (value) => {
3154
+ const normalizePersonName = (value) => {
3146
3155
  if (typeof value !== "string") throw new RumbleErrorSafe(`Name value is not a string: ${value}`);
3147
- const normalized = value.normalize("NFC").replace(/[\p{Cc}\p{Cf}]/gu, "").replace(/\p{Zs}+/gu, " ").trim().replace(/([-'])\1+/gu, "$1").replace(/^[-']+|[-']+$/gu, "").trim();
3156
+ const normalized = value.normalize("NFC").replace(/[\p{Cc}\p{Cf}]/gu, "").replace(APOSTROPHE_VARIANTS, "'").replace(HYPHEN_VARIANTS, "-").replace(/\p{Zs}+/gu, " ").trim().replace(/ ?- ?/gu, "-").replace(/([-'])\1+/gu, "$1").replace(/^[-']+|[-']+$/gu, "").trim();
3148
3157
  if (normalized.length === 0) throw new RumbleErrorSafe("Name must not be empty.");
3149
3158
  if (normalized.length > MAX_LENGTH) throw new RumbleErrorSafe(`Name must not be longer than ${MAX_LENGTH} characters.`);
3150
3159
  if (!NAME_REGEX.test(normalized)) throw new RumbleErrorSafe(`Invalid name: ${value}. Names may only contain letters and the separators space, apostrophe, hyphen and period, and may not start with or repeat a separator.`);
@@ -3152,12 +3161,12 @@ const normalize = (value) => {
3152
3161
  };
3153
3162
  const PersonNameResolver = new graphql.GraphQLScalarType({
3154
3163
  name: "PersonName",
3155
- description: "A person's name. Unicode letters from any script are allowed, along with space, apostrophe, hyphen and period as separators between name parts. The value is Unicode NFC normalized, has invisible/control characters stripped, has its whitespace collapsed, and has unambiguous typos (a doubled or stray leading/trailing hyphen/apostrophe) silently corrected rather than rejected.",
3156
- serialize: normalize,
3157
- parseValue: normalize,
3164
+ description: "A person's name. Unicode letters from any script are allowed, along with space, apostrophe, hyphen and period as separators between name parts. The value is Unicode NFC normalized, has invisible/control characters stripped, has its whitespace collapsed, and has unambiguous typos (typographic apostrophe or dash variants, spaces around a hyphen, a doubled or stray leading/trailing hyphen/apostrophe) silently corrected rather than rejected.",
3165
+ serialize: normalizePersonName,
3166
+ parseValue: normalizePersonName,
3158
3167
  parseLiteral(ast) {
3159
3168
  if (ast.kind !== graphql.Kind.STRING) throw new RumbleErrorSafe(`Can only validate strings as names but got a: ${ast.kind}`);
3160
- return normalize(ast.value);
3169
+ return normalizePersonName(ast.value);
3161
3170
  }
3162
3171
  });
3163
3172
  //#endregion
@@ -3165,9 +3174,12 @@ const PersonNameResolver = new graphql.GraphQLScalarType({
3165
3174
  /**
3166
3175
  * Parses and validates a phone number using libphonenumber-js (Google's phone number metadata),
3167
3176
  * which checks real per-country validity (length, area code plausibility, ...) rather than just
3168
- * the E.164 shape.
3177
+ * the E.164 shape. This is what the `PhoneNumber` scalar does with its input; exported for values
3178
+ * that do not arrive as GraphQL input. `.number` of the result is the E.164 form.
3179
+ *
3180
+ * @throws RumbleErrorSafe if the value is not a valid phone number
3169
3181
  */
3170
- const parse = (value) => {
3182
+ const parsePhoneNumber = (value) => {
3171
3183
  if (typeof value !== "string") throw new RumbleErrorSafe(`Phone number value is not a string: ${value}`);
3172
3184
  const phoneNumber = (0, libphonenumber_js.parsePhoneNumberFromString)(value);
3173
3185
  if (!phoneNumber?.isValid()) throw new RumbleErrorSafe(`Invalid phone number: ${value}. Please provide a valid phone number including its country calling code, e.g. +4915123456789.`);
@@ -3183,16 +3195,16 @@ const serialize = (value) => {
3183
3195
  if (!phoneNumber.isValid()) throw new RumbleErrorSafe(`Invalid phone number: ${phoneNumber.number}`);
3184
3196
  return phoneNumber.number;
3185
3197
  }
3186
- return parse(value).number;
3198
+ return parsePhoneNumber(value).number;
3187
3199
  };
3188
3200
  const PhoneNumberResolver = new graphql.GraphQLScalarType({
3189
3201
  name: "PhoneNumber",
3190
3202
  description: "A phone number, validated using real per-country validity rules and represented as a parsed libphonenumber-js PhoneNumber. On the wire it is transported as the E.164 format (https://en.wikipedia.org/wiki/E.164), e.g. +4915123456789. The country calling code is required.",
3191
3203
  serialize,
3192
- parseValue: parse,
3204
+ parseValue: parsePhoneNumber,
3193
3205
  parseLiteral(ast) {
3194
3206
  if (ast.kind !== graphql.Kind.STRING) throw new RumbleErrorSafe(`Can only validate strings as phone numbers but got a: ${ast.kind}`);
3195
- return parse(ast.value);
3207
+ return parsePhoneNumber(ast.value);
3196
3208
  }
3197
3209
  });
3198
3210
  //#endregion
@@ -3614,6 +3626,9 @@ exports.RumbleErrorSafe = RumbleErrorSafe;
3614
3626
  exports.assertFindFirstExists = assertFindFirstExists;
3615
3627
  exports.assertFirstEntryExists = assertFirstEntryExists;
3616
3628
  exports.mapNullFieldsToUndefined = mapNullFieldsToUndefined;
3629
+ exports.normalizeEmailAddress = normalizeEmailAddress;
3630
+ exports.normalizePersonName = normalizePersonName;
3631
+ exports.parsePhoneNumber = parsePhoneNumber;
3617
3632
  exports.rumble = rumble;
3618
3633
 
3619
3634
  //# sourceMappingURL=index.cjs.map