@m1212e/rumble 0.26.2 → 0.27.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.
package/out/index.d.cts CHANGED
@@ -14,6 +14,7 @@ import "@whatwg-node/fetch";
14
14
  import { EnvelopArmorPlugin } from "@escape.tech/graphql-armor";
15
15
  import { useSofa } from "@m1212e/sofa-api";
16
16
  import { ServerOptions } from "graphql-ws";
17
+ import { z } from "zod";
17
18
  import { PhoneNumber } from "libphonenumber-js";
18
19
  //#endregion
19
20
  //#region lib/types/drizzleInstanceType.d.ts
@@ -449,41 +450,6 @@ export declare const assertFirstEntryExists: <T>(value: T[]) => T;
449
450
  */
450
451
  export declare function mapNullFieldsToUndefined<T extends object>(obj: T): { [K in keyof T]: T[K] extends null ? undefined : Exclude<T[K], null>; };
451
452
  //#endregion
452
- //#region lib/scalars/address.d.ts
453
- /**
454
- * The shape of a postal address, modeled after the OIDC `address` claim
455
- * (https://openid.net/specs/openid-connect-core-1_0.html#AddressClaim) and schema.org's
456
- * `PostalAddress`.
457
- */
458
- type AddressShape = {
459
- /** The street address, which may be multiple lines separated by newlines. */
460
- streetAddress?: string | null;
461
- /** City or town. */
462
- locality?: string | null;
463
- /** State, province, prefecture or region. */
464
- region?: string | null;
465
- /** Postal or zip code. */
466
- postalCode?: string | null;
467
- /** ISO 3166-1 alpha-2 country code. */
468
- countryCode?: string | null;
469
- };
470
- /**
471
- * AddressInput's shape differs from AddressShape in that `countryCode` and `streetAddress` are
472
- * required. `countryCode`: without a country there is nothing for the validator to check
473
- * requiredness/format/region against, so a country-less "address" can't be verified as valid
474
- * for anywhere. `streetAddress`: checked against every one of the 252 countries in
475
- * libaddressinput's dataset — it is the one field required in literally all of them (unlike
476
- * e.g. city, which 13 countries including Japan and Singapore don't require, or state/zip,
477
- * required in barely a sixth to a third of countries) — so it's safe to require unconditionally
478
- * rather than only per-country. The remaining fields stay optional since their requiredness
479
- * genuinely varies by country; that's enforced dynamically by `addressValidationSchema` instead
480
- * of statically here.
481
- */
482
- type AddressInputShape = Omit<AddressShape, "countryCode" | "streetAddress"> & {
483
- countryCode: string;
484
- streetAddress: string;
485
- };
486
- //#endregion
487
453
  //#region lib/args/whereArgsImplementer.d.ts
488
454
  type NumberWhereInputArgument = {
489
455
  eq?: number;
@@ -4798,6 +4764,13 @@ export declare const rumble: <UserContext extends Record<string, any>, DB extend
4798
4764
  * https://the-guild.dev/graphql/yoga-server/docs#server
4799
4765
  */
4800
4766
  createYoga: (args?: (Omit<YogaServerOptions<RequestEvent, any>, "schema" | "context"> & {
4767
+ /**
4768
+ * Yoga's `cors` option, except that it defaults to `false` (no CORS headers at all)
4769
+ * rather than to Yoga's reflect-any-origin-with-credentials default. Pass the origins
4770
+ * that may call the API with their credentials when there are any, e.g.
4771
+ * `cors: { origin: ["https://app.example.org"], credentials: true }`.
4772
+ */
4773
+ cors?: YogaServerOptions<RequestEvent, any>["cors"];
4801
4774
  /**
4802
4775
  * Determines if the API should disclose various things about its structure.
4803
4776
  * Defaults to `process.env.NODE_ENV === "development"`.
@@ -5245,6 +5218,148 @@ export declare const rumble: <UserContext extends Record<string, any>, DB extend
5245
5218
  buildSchema: () => GraphQLSchema;
5246
5219
  };
5247
5220
  //#endregion
5221
+ //#region lib/scalars/address.d.ts
5222
+ /**
5223
+ * The shape of a postal address, modeled after the OIDC `address` claim
5224
+ * (https://openid.net/specs/openid-connect-core-1_0.html#AddressClaim) and schema.org's
5225
+ * `PostalAddress`.
5226
+ */
5227
+ type AddressShape = {
5228
+ /** The street address, which may be multiple lines separated by newlines. */
5229
+ streetAddress?: string | null;
5230
+ /** City or town. */
5231
+ locality?: string | null;
5232
+ /** State, province, prefecture or region. */
5233
+ region?: string | null;
5234
+ /** Postal or zip code. */
5235
+ postalCode?: string | null;
5236
+ /** ISO 3166-1 alpha-2 country code. */
5237
+ countryCode?: string | null;
5238
+ };
5239
+ /**
5240
+ * AddressInput's shape differs from AddressShape in that `countryCode` and `streetAddress` are
5241
+ * required. `countryCode`: without a country there is nothing for the validator to check
5242
+ * requiredness/format/region against, so a country-less "address" can't be verified as valid
5243
+ * for anywhere. `streetAddress`: checked against every one of the 252 countries in
5244
+ * libaddressinput's dataset — it is the one field required in literally all of them (unlike
5245
+ * e.g. city, which 13 countries including Japan and Singapore don't require, or state/zip,
5246
+ * required in barely a sixth to a third of countries) — so it's safe to require unconditionally
5247
+ * rather than only per-country. The remaining fields stay optional since their requiredness
5248
+ * genuinely varies by country; that's enforced dynamically by `addressValidationSchema` instead
5249
+ * of statically here.
5250
+ */
5251
+ type AddressInputShape = Omit<AddressShape, "countryCode" | "streetAddress"> & {
5252
+ countryCode: string;
5253
+ streetAddress: string;
5254
+ };
5255
+ //#endregion
5256
+ //#region lib/scalars/addressData.d.ts
5257
+ type RegionAddressRules = {
5258
+ /** Regex the postal code must start with. */
5259
+ zip?: string;
5260
+ /** Example postal code within the region. */
5261
+ zipex?: string;
5262
+ /** Other names the region is known by, e.g. "California" for CA. */
5263
+ names?: string[];
5264
+ };
5265
+ type CountryAddressRules = {
5266
+ /** One-letter codes of the required fields, see the libaddressinput metadata docs. */
5267
+ require: string;
5268
+ /** Regex the whole postal code must match. */
5269
+ zip?: string;
5270
+ /** Example postal code. */
5271
+ zipex?: string;
5272
+ /** Regions by their upper-cased code. */
5273
+ regions?: Record<string, RegionAddressRules>;
5274
+ };
5275
+ /*! Address data derived from Google's Address Data Service (https://github.com/google/libaddressinput),
5276
+ * licensed under CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/).
5277
+ * Changes: reduced to required fields, postal code patterns and examples, and regions with
5278
+ * their names, with region codes upper-cased and ISO 3166-2 ids used where available. */
5279
+ export declare const addressData: Record<string, CountryAddressRules>;
5280
+ //#endregion
5281
+ //#region lib/scalars/addressValidation.d.ts
5282
+ type AddressIssue = {
5283
+ path: keyof AddressShape;
5284
+ message: string;
5285
+ };
5286
+ type NormalizedAddress = {
5287
+ streetAddress: string | null;
5288
+ locality: string | null;
5289
+ region: string | null;
5290
+ postalCode: string | null;
5291
+ countryCode: string;
5292
+ };
5293
+ /**
5294
+ * One rule an address is checked against, e.g. `checkPostalCode`. It only runs for countries
5295
+ * that have rules, and returns an empty array when the address passes.
5296
+ */
5297
+ type AddressCheck = (args: {
5298
+ address: NormalizedAddress;
5299
+ rules: CountryAddressRules;
5300
+ }) => AddressIssue[];
5301
+ /** Flags fields the country requires but the address leaves empty. */
5302
+ export declare const checkRequiredFields: AddressCheck;
5303
+ /**
5304
+ * Flags a region that isn't in the country's region list. Countries without a list accept any
5305
+ * region. Expects the region already resolved by `normalizeAddress`.
5306
+ */
5307
+ export declare const checkRegion: AddressCheck;
5308
+ /**
5309
+ * Flags a postal code that doesn't match the country's format, or doesn't belong to the given
5310
+ * region (e.g. a Washington ZIP code for California). An empty postal code passes, since
5311
+ * `checkRequiredFields` covers that.
5312
+ */
5313
+ export declare const checkPostalCode: AddressCheck;
5314
+ /** The checks `validateAddress` runs, in order. */
5315
+ export declare const addressChecks: AddressCheck[];
5316
+ /**
5317
+ * Resolves a region code or any of its names, in any case, to the region code, e.g. "california"
5318
+ * to "CA" for the US. Returns undefined for unknown regions and countries without a region list.
5319
+ */
5320
+ export declare function findRegionCode({ countryCode, region }: {
5321
+ countryCode: string;
5322
+ region: string;
5323
+ }): string | undefined;
5324
+ /**
5325
+ * Fixes the unambiguous, purely-cosmetic issues (stray surrounding whitespace, wrong case)
5326
+ * instead of rejecting an address over them. Run it before `validateAddress`, which expects
5327
+ * its output.
5328
+ *
5329
+ * `countryCode` and `postalCode` are uppercased since their canonical forms always are (ISO
5330
+ * 3166-1 codes, and postal codes in every country that mixes letters and digits, e.g. GB/CA/NL).
5331
+ * A region that matches a known region code or name, like "california" in the US, is replaced
5332
+ * by its code. Any other region and the locality are only trimmed, since they're free text.
5333
+ */
5334
+ export declare function normalizeAddress(address: AddressShape): NormalizedAddress;
5335
+ /**
5336
+ * Checks a normalized address against its country's rules and returns every issue found, or an
5337
+ * empty array for a valid address.
5338
+ *
5339
+ * @example
5340
+ * ```ts
5341
+ * const issues = validateAddress(normalizeAddress(input));
5342
+ * ```
5343
+ */
5344
+ export declare function validateAddress(address: NormalizedAddress): AddressIssue[];
5345
+ /**
5346
+ * The schema `AddressInput` validates with. It normalizes the address, so parsing returns the
5347
+ * corrected value, and reports every issue on its field.
5348
+ */
5349
+ export declare const addressValidationSchema: z.ZodPipe<z.ZodObject<{
5350
+ streetAddress: z.ZodString;
5351
+ locality: z.ZodOptional<z.ZodNullable<z.ZodString>>;
5352
+ region: z.ZodOptional<z.ZodNullable<z.ZodString>>;
5353
+ postalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
5354
+ countryCode: z.ZodString;
5355
+ }, z.core.$strip>, z.ZodTransform<NormalizedAddress, {
5356
+ streetAddress: string;
5357
+ locality?: string | null | undefined;
5358
+ region?: string | null | undefined;
5359
+ postalCode?: string | null | undefined;
5360
+ countryCode: string;
5361
+ }>>;
5362
+ //#endregion
5248
5363
  //#region lib/scalars/emailAddress.d.ts
5249
5364
  /**
5250
5365
  * Validates an email address using graphql-scalars' own format check, then lowercases it, exactly
@@ -5290,4 +5405,5 @@ export declare class RumbleError extends Error {
5290
5405
  */
5291
5406
  export declare class RumbleErrorSafe extends GraphQLError {}
5292
5407
  //#endregion
5408
+ export type { AddressCheck, AddressInputShape, AddressIssue, AddressShape, CountryAddressRules, NormalizedAddress, RegionAddressRules };
5293
5409
  //# sourceMappingURL=index.d.cts.map