@vercel/config 0.0.13 → 0.0.16

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/dist/router.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Redirect, Rewrite } from './types';
1
2
  /**
2
3
  * Helper function to reference a path parameter in transforms.
3
4
  * Path parameters are extracted from the route pattern (e.g., :userId).
@@ -544,102 +545,52 @@ export declare class Router {
544
545
  */
545
546
  private createEnvProxy;
546
547
  /**
547
- * Helper to extract environment variable names from a string or string array.
548
- * Environment variables are identified by the pattern $VAR_NAME where VAR_NAME
549
- * is typically uppercase with underscores (e.g., $API_KEY, $BEARER_TOKEN).
550
- */
551
- private extractEnvVars;
552
- /**
548
+ * @deprecated No longer used after refactor to return schema objects directly
553
549
  * Internal helper to convert TransformOptions to Transform array
554
550
  * @param options Transform options to convert
555
551
  * @param trackedEnvVars Optional set of environment variables that were accessed via the env proxy
556
552
  */
557
- private transformOptionsToTransforms;
558
553
  /**
559
- * Adds a single rewrite rule (synchronous).
560
- * Automatically enables rewrite caching by adding the x-vercel-enable-rewrite-caching header.
554
+ * Creates a rewrite rule. Returns either a Rewrite object (simple case) or Route with transforms.
561
555
  *
562
556
  * @example
563
557
  * // Simple rewrite
564
558
  * router.rewrite('/api/(.*)', 'https://old-on-prem.com/$1')
565
559
  *
566
- * // With transforms using callback
560
+ * // With transforms
567
561
  * router.rewrite('/users/:userId', 'https://api.example.com/users/$1', ({userId, env}) => ({
568
- * requestHeaders: {
569
- * 'x-user-id': userId,
570
- * 'authorization': `Bearer ${env.API_TOKEN}`
571
- * }
572
- * }));
573
- *
574
- * // With transforms using object (legacy)
575
- * router.rewrite('/users/:userId', 'https://api.example.com/users/$1', {
576
- * requestHeaders: {
577
- * 'x-user-id': param('userId')
578
- * }
579
- * });
562
+ * requestHeaders: { 'x-user-id': userId }
563
+ * }))
564
+ * @internal Can return Route with transforms internally
580
565
  */
581
566
  rewrite(source: string, destination: string, optionsOrCallback?: {
582
- methods?: string[];
583
- status?: number;
584
567
  has?: Condition[];
585
568
  missing?: Condition[];
586
569
  requestHeaders?: Record<string, string | string[]>;
587
570
  responseHeaders?: Record<string, string | string[]>;
588
571
  requestQuery?: Record<string, string | string[]>;
589
- appendRequestHeaders?: Record<string, string | string[]>;
590
- appendResponseHeaders?: Record<string, string | string[]>;
591
- appendRequestQuery?: Record<string, string | string[]>;
592
- deleteRequestHeaders?: string[];
593
- deleteResponseHeaders?: string[];
594
- deleteRequestQuery?: string[];
595
572
  } | ((params: Record<string, string> & {
596
573
  env: any;
597
574
  }) => {
598
- methods?: string[];
599
- status?: number;
600
575
  has?: Condition[];
601
576
  missing?: Condition[];
602
577
  requestHeaders?: Record<string, string | string[]>;
603
578
  responseHeaders?: Record<string, string | string[]>;
604
579
  requestQuery?: Record<string, string | string[]>;
605
- appendRequestHeaders?: Record<string, string | string[]>;
606
- appendResponseHeaders?: Record<string, string | string[]>;
607
- appendRequestQuery?: Record<string, string | string[]>;
608
- deleteRequestHeaders?: string[];
609
- deleteResponseHeaders?: string[];
610
- deleteRequestQuery?: string[];
611
- })): this;
612
- /**
613
- * Loads rewrite rules asynchronously and appends them.
614
- * Automatically enables rewrite caching for all loaded rules by adding the x-vercel-enable-rewrite-caching header.
615
- *
616
- * @example
617
- * // This will automatically enable caching for all rewrites
618
- * await router.rewrites(() => fetchRewriteRulesFromDB());
619
- */
620
- rewrites(provider: RewriteProvider): Promise<this>;
580
+ })): Rewrite | Route;
621
581
  /**
622
- * Adds a single redirect rule (synchronous).
582
+ * Creates a redirect rule. Returns either a Redirect object (simple case) or Route with transforms.
583
+ *
623
584
  * @example
624
585
  * // Simple redirect
625
586
  * router.redirect('/old-path', '/new-path', { permanent: true })
626
587
  *
627
- * // With transforms using callback
588
+ * // With transforms
628
589
  * router.redirect('/users/:userId', '/new-users/$1', ({userId, env}) => ({
629
590
  * permanent: true,
630
- * requestHeaders: {
631
- * 'x-user-id': userId,
632
- * 'x-api-key': env.API_KEY
633
- * }
591
+ * requestHeaders: { 'x-user-id': userId }
634
592
  * }))
635
- *
636
- * // With transforms using object (legacy)
637
- * router.redirect('/users/:userId', '/new-users/$1', {
638
- * permanent: true,
639
- * requestHeaders: {
640
- * 'x-user-id': param('userId')
641
- * }
642
- * })
593
+ * @internal Can return Route with transforms internally
643
594
  */
644
595
  redirect(source: string, destination: string, optionsOrCallback?: {
645
596
  permanent?: boolean;
@@ -647,14 +598,6 @@ export declare class Router {
647
598
  has?: Condition[];
648
599
  missing?: Condition[];
649
600
  requestHeaders?: Record<string, string | string[]>;
650
- responseHeaders?: Record<string, string | string[]>;
651
- requestQuery?: Record<string, string | string[]>;
652
- appendRequestHeaders?: Record<string, string | string[]>;
653
- appendResponseHeaders?: Record<string, string | string[]>;
654
- appendRequestQuery?: Record<string, string | string[]>;
655
- deleteRequestHeaders?: string[];
656
- deleteResponseHeaders?: string[];
657
- deleteRequestQuery?: string[];
658
601
  } | ((params: Record<string, string> & {
659
602
  env: any;
660
603
  }) => {
@@ -663,46 +606,41 @@ export declare class Router {
663
606
  has?: Condition[];
664
607
  missing?: Condition[];
665
608
  requestHeaders?: Record<string, string | string[]>;
666
- responseHeaders?: Record<string, string | string[]>;
667
- requestQuery?: Record<string, string | string[]>;
668
- appendRequestHeaders?: Record<string, string | string[]>;
669
- appendResponseHeaders?: Record<string, string | string[]>;
670
- appendRequestQuery?: Record<string, string | string[]>;
671
- deleteRequestHeaders?: string[];
672
- deleteResponseHeaders?: string[];
673
- deleteRequestQuery?: string[];
674
- })): this;
609
+ })): Redirect | Route;
675
610
  /**
676
- * Loads redirect rules asynchronously and appends them.
677
- */
678
- redirects(provider: RedirectProvider): Promise<this>;
679
- /**
680
- * Adds a single header rule (synchronous).
611
+ * Creates a header rule matching the vercel.json schema.
681
612
  * @example
682
613
  * router.header('/api/(.*)', [{ key: 'X-Custom', value: 'HelloWorld' }])
683
614
  */
684
615
  header(source: string, headers: Header[], options?: {
685
616
  has?: Condition[];
686
617
  missing?: Condition[];
687
- }): this;
688
- /**
689
- * Loads header rules asynchronously and appends them.
690
- */
691
- headers(provider: HeaderProvider): Promise<this>;
618
+ }): {
619
+ source: string;
620
+ headers: Header[];
621
+ has?: Condition[];
622
+ missing?: Condition[];
623
+ };
692
624
  /**
693
- * Adds a typed "Cache-Control" header, leveraging `pretty-cache-header`.
694
- * This method is purely for convenience, so you can do:
625
+ * Creates a Cache-Control header rule, leveraging `pretty-cache-header`.
626
+ * Returns a HeaderRule matching the vercel.json schema.
695
627
  *
696
- * router.cacheControl('/my-page', {
697
- * public: true,
698
- * maxAge: '1week',
699
- * staleWhileRevalidate: '1year'
700
- * });
628
+ * @example
629
+ * router.cacheControl('/my-page', {
630
+ * public: true,
631
+ * maxAge: '1week',
632
+ * staleWhileRevalidate: '1year'
633
+ * })
701
634
  */
702
635
  cacheControl(source: string, cacheOptions: CacheOptions, options?: {
703
636
  has?: Condition[];
704
637
  missing?: Condition[];
705
- }): this;
638
+ }): {
639
+ source: string;
640
+ headers: Header[];
641
+ has?: Condition[];
642
+ missing?: Condition[];
643
+ };
706
644
  /**
707
645
  * Adds a route with transforms support.
708
646
  * This is the newer, more powerful routing format that supports transforms.