@uniformdev/mesh-edgehancer-sdk 19.126.0 → 19.126.2-alpha.3
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/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.esm.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/webhooks/index.d.mts +88 -0
- package/dist/webhooks/index.d.ts +88 -0
- package/dist/webhooks/index.js +205 -0
- package/dist/webhooks/index.mjs +170 -0
- package/package.json +34 -8
package/dist/index.d.mts
CHANGED
@@ -82,6 +82,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
82
82
|
source?: string | undefined;
|
83
83
|
}>>>;
|
84
84
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
85
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
85
86
|
ttl: z.ZodOptional<z.ZodNumber>;
|
86
87
|
purgeKey: z.ZodOptional<z.ZodString>;
|
87
88
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -125,6 +126,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
125
126
|
source?: string | undefined;
|
126
127
|
}> | undefined;
|
127
128
|
custom?: Record<string, unknown> | undefined;
|
129
|
+
customPublic?: Record<string, unknown> | undefined;
|
128
130
|
ttl?: number | undefined;
|
129
131
|
purgeKey?: string | undefined;
|
130
132
|
localeMapping?: Record<string, string> | undefined;
|
@@ -162,6 +164,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
162
164
|
source?: string | undefined;
|
163
165
|
}> | undefined;
|
164
166
|
custom?: Record<string, unknown> | undefined;
|
167
|
+
customPublic?: Record<string, unknown> | undefined;
|
165
168
|
ttl?: number | undefined;
|
166
169
|
purgeKey?: string | undefined;
|
167
170
|
localeMapping?: Record<string, string> | undefined;
|
@@ -176,7 +179,7 @@ type CustomEdgehancerDefinition = z.infer<typeof customEdgehancerDefinitionSchem
|
|
176
179
|
/**
|
177
180
|
* The result of merging a data source with a data type into a single request object
|
178
181
|
*/
|
179
|
-
type MergedDataType = Omit<DataType, 'path' | 'dataSourceId'> & Pick<DataSource, 'connectorType' | 'localeMapping'> & {
|
182
|
+
type MergedDataType = Omit<DataType, 'path' | 'dataSourceId'> & Pick<DataSource, 'connectorType' | 'localeMapping' | 'customPublic'> & {
|
180
183
|
/** Merged base URL from the data source with the relative URL from the data type */
|
181
184
|
url: string;
|
182
185
|
/**
|
@@ -351,6 +354,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
351
354
|
source?: string | undefined;
|
352
355
|
}>>>;
|
353
356
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
357
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
354
358
|
ttl: z.ZodOptional<z.ZodNumber>;
|
355
359
|
purgeKey: z.ZodOptional<z.ZodString>;
|
356
360
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -382,6 +386,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
382
386
|
}[] | undefined;
|
383
387
|
body?: string | undefined;
|
384
388
|
custom?: Record<string, unknown> | undefined;
|
389
|
+
customPublic?: Record<string, unknown> | undefined;
|
385
390
|
ttl?: number | undefined;
|
386
391
|
localeMapping?: Record<string, string> | undefined;
|
387
392
|
uiBadgeText?: string | undefined;
|
@@ -402,6 +407,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
402
407
|
}[] | undefined;
|
403
408
|
body?: string | undefined;
|
404
409
|
custom?: Record<string, unknown> | undefined;
|
410
|
+
customPublic?: Record<string, unknown> | undefined;
|
405
411
|
ttl?: number | undefined;
|
406
412
|
localeMapping?: Record<string, string> | undefined;
|
407
413
|
uiBadgeText?: string | undefined;
|
@@ -483,6 +489,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
483
489
|
source?: string | undefined;
|
484
490
|
}>>>;
|
485
491
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
492
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
486
493
|
ttl: z.ZodOptional<z.ZodNumber>;
|
487
494
|
purgeKey: z.ZodOptional<z.ZodString>;
|
488
495
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -514,6 +521,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
514
521
|
}[] | undefined;
|
515
522
|
body?: string | undefined;
|
516
523
|
custom?: Record<string, unknown> | undefined;
|
524
|
+
customPublic?: Record<string, unknown> | undefined;
|
517
525
|
ttl?: number | undefined;
|
518
526
|
localeMapping?: Record<string, string> | undefined;
|
519
527
|
uiBadgeText?: string | undefined;
|
@@ -534,6 +542,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
534
542
|
}[] | undefined;
|
535
543
|
body?: string | undefined;
|
536
544
|
custom?: Record<string, unknown> | undefined;
|
545
|
+
customPublic?: Record<string, unknown> | undefined;
|
537
546
|
ttl?: number | undefined;
|
538
547
|
localeMapping?: Record<string, string> | undefined;
|
539
548
|
uiBadgeText?: string | undefined;
|
@@ -556,6 +565,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
556
565
|
}[] | undefined;
|
557
566
|
body?: string | undefined;
|
558
567
|
custom?: Record<string, unknown> | undefined;
|
568
|
+
customPublic?: Record<string, unknown> | undefined;
|
559
569
|
ttl?: number | undefined;
|
560
570
|
localeMapping?: Record<string, string> | undefined;
|
561
571
|
uiBadgeText?: string | undefined;
|
@@ -580,6 +590,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
580
590
|
}[] | undefined;
|
581
591
|
body?: string | undefined;
|
582
592
|
custom?: Record<string, unknown> | undefined;
|
593
|
+
customPublic?: Record<string, unknown> | undefined;
|
583
594
|
ttl?: number | undefined;
|
584
595
|
localeMapping?: Record<string, string> | undefined;
|
585
596
|
uiBadgeText?: string | undefined;
|
@@ -650,6 +661,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
650
661
|
source?: string | undefined;
|
651
662
|
}>>>;
|
652
663
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
664
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
653
665
|
ttl: z.ZodOptional<z.ZodNumber>;
|
654
666
|
purgeKey: z.ZodOptional<z.ZodString>;
|
655
667
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -681,6 +693,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
681
693
|
}[] | undefined;
|
682
694
|
body?: string | undefined;
|
683
695
|
custom?: Record<string, unknown> | undefined;
|
696
|
+
customPublic?: Record<string, unknown> | undefined;
|
684
697
|
ttl?: number | undefined;
|
685
698
|
localeMapping?: Record<string, string> | undefined;
|
686
699
|
uiBadgeText?: string | undefined;
|
@@ -701,6 +714,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
701
714
|
}[] | undefined;
|
702
715
|
body?: string | undefined;
|
703
716
|
custom?: Record<string, unknown> | undefined;
|
717
|
+
customPublic?: Record<string, unknown> | undefined;
|
704
718
|
ttl?: number | undefined;
|
705
719
|
localeMapping?: Record<string, string> | undefined;
|
706
720
|
uiBadgeText?: string | undefined;
|
@@ -723,6 +737,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
723
737
|
}[] | undefined;
|
724
738
|
body?: string | undefined;
|
725
739
|
custom?: Record<string, unknown> | undefined;
|
740
|
+
customPublic?: Record<string, unknown> | undefined;
|
726
741
|
ttl?: number | undefined;
|
727
742
|
localeMapping?: Record<string, string> | undefined;
|
728
743
|
uiBadgeText?: string | undefined;
|
@@ -747,6 +762,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
747
762
|
}[] | undefined;
|
748
763
|
body?: string | undefined;
|
749
764
|
custom?: Record<string, unknown> | undefined;
|
765
|
+
customPublic?: Record<string, unknown> | undefined;
|
750
766
|
ttl?: number | undefined;
|
751
767
|
localeMapping?: Record<string, string> | undefined;
|
752
768
|
uiBadgeText?: string | undefined;
|
@@ -773,6 +789,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
773
789
|
}[] | undefined;
|
774
790
|
body?: string | undefined;
|
775
791
|
custom?: Record<string, unknown> | undefined;
|
792
|
+
customPublic?: Record<string, unknown> | undefined;
|
776
793
|
ttl?: number | undefined;
|
777
794
|
localeMapping?: Record<string, string> | undefined;
|
778
795
|
uiBadgeText?: string | undefined;
|
@@ -799,6 +816,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
799
816
|
}[] | undefined;
|
800
817
|
body?: string | undefined;
|
801
818
|
custom?: Record<string, unknown> | undefined;
|
819
|
+
customPublic?: Record<string, unknown> | undefined;
|
802
820
|
ttl?: number | undefined;
|
803
821
|
localeMapping?: Record<string, string> | undefined;
|
804
822
|
uiBadgeText?: string | undefined;
|
package/dist/index.d.ts
CHANGED
@@ -82,6 +82,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
82
82
|
source?: string | undefined;
|
83
83
|
}>>>;
|
84
84
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
85
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
85
86
|
ttl: z.ZodOptional<z.ZodNumber>;
|
86
87
|
purgeKey: z.ZodOptional<z.ZodString>;
|
87
88
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -125,6 +126,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
125
126
|
source?: string | undefined;
|
126
127
|
}> | undefined;
|
127
128
|
custom?: Record<string, unknown> | undefined;
|
129
|
+
customPublic?: Record<string, unknown> | undefined;
|
128
130
|
ttl?: number | undefined;
|
129
131
|
purgeKey?: string | undefined;
|
130
132
|
localeMapping?: Record<string, string> | undefined;
|
@@ -162,6 +164,7 @@ declare const mergedDataTypeSchema: z.ZodObject<{
|
|
162
164
|
source?: string | undefined;
|
163
165
|
}> | undefined;
|
164
166
|
custom?: Record<string, unknown> | undefined;
|
167
|
+
customPublic?: Record<string, unknown> | undefined;
|
165
168
|
ttl?: number | undefined;
|
166
169
|
purgeKey?: string | undefined;
|
167
170
|
localeMapping?: Record<string, string> | undefined;
|
@@ -176,7 +179,7 @@ type CustomEdgehancerDefinition = z.infer<typeof customEdgehancerDefinitionSchem
|
|
176
179
|
/**
|
177
180
|
* The result of merging a data source with a data type into a single request object
|
178
181
|
*/
|
179
|
-
type MergedDataType = Omit<DataType, 'path' | 'dataSourceId'> & Pick<DataSource, 'connectorType' | 'localeMapping'> & {
|
182
|
+
type MergedDataType = Omit<DataType, 'path' | 'dataSourceId'> & Pick<DataSource, 'connectorType' | 'localeMapping' | 'customPublic'> & {
|
180
183
|
/** Merged base URL from the data source with the relative URL from the data type */
|
181
184
|
url: string;
|
182
185
|
/**
|
@@ -351,6 +354,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
351
354
|
source?: string | undefined;
|
352
355
|
}>>>;
|
353
356
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
357
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
354
358
|
ttl: z.ZodOptional<z.ZodNumber>;
|
355
359
|
purgeKey: z.ZodOptional<z.ZodString>;
|
356
360
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -382,6 +386,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
382
386
|
}[] | undefined;
|
383
387
|
body?: string | undefined;
|
384
388
|
custom?: Record<string, unknown> | undefined;
|
389
|
+
customPublic?: Record<string, unknown> | undefined;
|
385
390
|
ttl?: number | undefined;
|
386
391
|
localeMapping?: Record<string, string> | undefined;
|
387
392
|
uiBadgeText?: string | undefined;
|
@@ -402,6 +407,7 @@ declare const edgehancerMergedDataTypeSchema: z.ZodObject<Omit<{
|
|
402
407
|
}[] | undefined;
|
403
408
|
body?: string | undefined;
|
404
409
|
custom?: Record<string, unknown> | undefined;
|
410
|
+
customPublic?: Record<string, unknown> | undefined;
|
405
411
|
ttl?: number | undefined;
|
406
412
|
localeMapping?: Record<string, string> | undefined;
|
407
413
|
uiBadgeText?: string | undefined;
|
@@ -483,6 +489,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
483
489
|
source?: string | undefined;
|
484
490
|
}>>>;
|
485
491
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
492
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
486
493
|
ttl: z.ZodOptional<z.ZodNumber>;
|
487
494
|
purgeKey: z.ZodOptional<z.ZodString>;
|
488
495
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -514,6 +521,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
514
521
|
}[] | undefined;
|
515
522
|
body?: string | undefined;
|
516
523
|
custom?: Record<string, unknown> | undefined;
|
524
|
+
customPublic?: Record<string, unknown> | undefined;
|
517
525
|
ttl?: number | undefined;
|
518
526
|
localeMapping?: Record<string, string> | undefined;
|
519
527
|
uiBadgeText?: string | undefined;
|
@@ -534,6 +542,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
534
542
|
}[] | undefined;
|
535
543
|
body?: string | undefined;
|
536
544
|
custom?: Record<string, unknown> | undefined;
|
545
|
+
customPublic?: Record<string, unknown> | undefined;
|
537
546
|
ttl?: number | undefined;
|
538
547
|
localeMapping?: Record<string, string> | undefined;
|
539
548
|
uiBadgeText?: string | undefined;
|
@@ -556,6 +565,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
556
565
|
}[] | undefined;
|
557
566
|
body?: string | undefined;
|
558
567
|
custom?: Record<string, unknown> | undefined;
|
568
|
+
customPublic?: Record<string, unknown> | undefined;
|
559
569
|
ttl?: number | undefined;
|
560
570
|
localeMapping?: Record<string, string> | undefined;
|
561
571
|
uiBadgeText?: string | undefined;
|
@@ -580,6 +590,7 @@ declare const preRequestEdgehancerDataResourceResultSchema: z.ZodObject<{
|
|
580
590
|
}[] | undefined;
|
581
591
|
body?: string | undefined;
|
582
592
|
custom?: Record<string, unknown> | undefined;
|
593
|
+
customPublic?: Record<string, unknown> | undefined;
|
583
594
|
ttl?: number | undefined;
|
584
595
|
localeMapping?: Record<string, string> | undefined;
|
585
596
|
uiBadgeText?: string | undefined;
|
@@ -650,6 +661,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
650
661
|
source?: string | undefined;
|
651
662
|
}>>>;
|
652
663
|
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
664
|
+
customPublic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
653
665
|
ttl: z.ZodOptional<z.ZodNumber>;
|
654
666
|
purgeKey: z.ZodOptional<z.ZodString>;
|
655
667
|
localeMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
@@ -681,6 +693,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
681
693
|
}[] | undefined;
|
682
694
|
body?: string | undefined;
|
683
695
|
custom?: Record<string, unknown> | undefined;
|
696
|
+
customPublic?: Record<string, unknown> | undefined;
|
684
697
|
ttl?: number | undefined;
|
685
698
|
localeMapping?: Record<string, string> | undefined;
|
686
699
|
uiBadgeText?: string | undefined;
|
@@ -701,6 +714,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
701
714
|
}[] | undefined;
|
702
715
|
body?: string | undefined;
|
703
716
|
custom?: Record<string, unknown> | undefined;
|
717
|
+
customPublic?: Record<string, unknown> | undefined;
|
704
718
|
ttl?: number | undefined;
|
705
719
|
localeMapping?: Record<string, string> | undefined;
|
706
720
|
uiBadgeText?: string | undefined;
|
@@ -723,6 +737,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
723
737
|
}[] | undefined;
|
724
738
|
body?: string | undefined;
|
725
739
|
custom?: Record<string, unknown> | undefined;
|
740
|
+
customPublic?: Record<string, unknown> | undefined;
|
726
741
|
ttl?: number | undefined;
|
727
742
|
localeMapping?: Record<string, string> | undefined;
|
728
743
|
uiBadgeText?: string | undefined;
|
@@ -747,6 +762,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
747
762
|
}[] | undefined;
|
748
763
|
body?: string | undefined;
|
749
764
|
custom?: Record<string, unknown> | undefined;
|
765
|
+
customPublic?: Record<string, unknown> | undefined;
|
750
766
|
ttl?: number | undefined;
|
751
767
|
localeMapping?: Record<string, string> | undefined;
|
752
768
|
uiBadgeText?: string | undefined;
|
@@ -773,6 +789,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
773
789
|
}[] | undefined;
|
774
790
|
body?: string | undefined;
|
775
791
|
custom?: Record<string, unknown> | undefined;
|
792
|
+
customPublic?: Record<string, unknown> | undefined;
|
776
793
|
ttl?: number | undefined;
|
777
794
|
localeMapping?: Record<string, string> | undefined;
|
778
795
|
uiBadgeText?: string | undefined;
|
@@ -799,6 +816,7 @@ declare const preRequestEdgehancerResultSchema: z.ZodObject<{
|
|
799
816
|
}[] | undefined;
|
800
817
|
body?: string | undefined;
|
801
818
|
custom?: Record<string, unknown> | undefined;
|
819
|
+
customPublic?: Record<string, unknown> | undefined;
|
802
820
|
ttl?: number | undefined;
|
803
821
|
localeMapping?: Record<string, string> | undefined;
|
804
822
|
uiBadgeText?: string | undefined;
|
package/dist/index.esm.js
CHANGED
@@ -127,6 +127,7 @@ var mergedDataTypeSchema = z.object({
|
|
127
127
|
method: z.enum(["GET", "POST", "HEAD"]),
|
128
128
|
variables: z.record(variableDefinitionSchema).optional(),
|
129
129
|
custom: z.record(z.unknown()).optional(),
|
130
|
+
customPublic: z.record(z.unknown()).optional(),
|
130
131
|
ttl: z.number().optional(),
|
131
132
|
purgeKey: z.string().optional(),
|
132
133
|
localeMapping: z.record(z.string()).optional(),
|
package/dist/index.js
CHANGED
@@ -165,6 +165,7 @@ var mergedDataTypeSchema = import_zod.z.object({
|
|
165
165
|
method: import_zod.z.enum(["GET", "POST", "HEAD"]),
|
166
166
|
variables: import_zod.z.record(variableDefinitionSchema).optional(),
|
167
167
|
custom: import_zod.z.record(import_zod.z.unknown()).optional(),
|
168
|
+
customPublic: import_zod.z.record(import_zod.z.unknown()).optional(),
|
168
169
|
ttl: import_zod.z.number().optional(),
|
169
170
|
purgeKey: import_zod.z.string().optional(),
|
170
171
|
localeMapping: import_zod.z.record(import_zod.z.string()).optional(),
|
package/dist/index.mjs
CHANGED
@@ -127,6 +127,7 @@ var mergedDataTypeSchema = z.object({
|
|
127
127
|
method: z.enum(["GET", "POST", "HEAD"]),
|
128
128
|
variables: z.record(variableDefinitionSchema).optional(),
|
129
129
|
custom: z.record(z.unknown()).optional(),
|
130
|
+
customPublic: z.record(z.unknown()).optional(),
|
130
131
|
ttl: z.number().optional(),
|
131
132
|
purgeKey: z.string().optional(),
|
132
133
|
localeMapping: z.record(z.string()).optional(),
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
2
|
+
|
3
|
+
type InvalidationResponse = {
|
4
|
+
status: number;
|
5
|
+
text: string;
|
6
|
+
};
|
7
|
+
declare abstract class APIError extends Error {
|
8
|
+
abstract readonly status: number;
|
9
|
+
abstract readonly statusText: string;
|
10
|
+
}
|
11
|
+
declare class BadRequestError extends APIError {
|
12
|
+
status: number;
|
13
|
+
statusText: string;
|
14
|
+
constructor(message?: string);
|
15
|
+
}
|
16
|
+
declare class ForbiddenError extends APIError {
|
17
|
+
status: number;
|
18
|
+
statusText: string;
|
19
|
+
constructor(message?: string);
|
20
|
+
}
|
21
|
+
|
22
|
+
type Purger = {
|
23
|
+
/** Purge all caches for the Data Type */
|
24
|
+
purgeAllCachesForDataType(): Promise<InvalidationResponse>;
|
25
|
+
/** Purge caches by surrogate keys. Your Custom Edgehancer is responsible to set them up first */
|
26
|
+
purgeBySurrogateKeys(surrogateKeys: string[]): Promise<InvalidationResponse>;
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Returns Purger with two methods to invalidate cache for your Data Type.
|
30
|
+
* You should validate parameters before calling this function.
|
31
|
+
*/
|
32
|
+
declare const createPurger: ({ projectId, purgeKey, dataTypeId, edgeApiHost, logger, }: {
|
33
|
+
projectId: string;
|
34
|
+
purgeKey: string;
|
35
|
+
dataTypeId: string;
|
36
|
+
edgeApiHost?: string | undefined;
|
37
|
+
logger?: Console | undefined;
|
38
|
+
}) => Purger;
|
39
|
+
|
40
|
+
type handleNextJSWebhookRequestArgs = {
|
41
|
+
/** NextJS request object */
|
42
|
+
request: NextApiRequest;
|
43
|
+
/** NextJS response object */
|
44
|
+
response: NextApiResponse;
|
45
|
+
/**
|
46
|
+
* Your custom handler that will be called after request validation with purger instance
|
47
|
+
* that has methods to invalidate your Data Type cache
|
48
|
+
* */
|
49
|
+
handler: (args: {
|
50
|
+
request: NextApiRequest;
|
51
|
+
purger: Purger;
|
52
|
+
}) => Promise<InvalidationResponse>;
|
53
|
+
logger?: Console;
|
54
|
+
};
|
55
|
+
/**
|
56
|
+
* Handles the incoming webhook request via NextJS api route.
|
57
|
+
*
|
58
|
+
* It validates the request, handle exceptions,
|
59
|
+
* calls your custom handler and sends the response back to webhook caller.
|
60
|
+
*/
|
61
|
+
declare const handleNextJSWebhookRequest: ({ request, response, handler, logger, }: handleNextJSWebhookRequestArgs) => Promise<void>;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Reads the parameter from the Next.js api route request
|
65
|
+
*/
|
66
|
+
declare function getParam(query: NextApiRequest['query'], paramName: string): string | undefined;
|
67
|
+
/**
|
68
|
+
* Throws an BadRequestError exception if the parameter is not found in the request.
|
69
|
+
*/
|
70
|
+
declare function getRequiredParam(query: NextApiRequest['query'], paramName: string): string;
|
71
|
+
/**
|
72
|
+
* Reads and validates the request parameters required to perform cache invalidation.
|
73
|
+
* In case of invalid parameters, it throws an BadRequestError exception.
|
74
|
+
*
|
75
|
+
* URL example: https://my-nextjs-app.com/api/cache-invalidation?projectId=PROJECT_ID&dataTypeId=DATA_TYPE_ID&purgeKey=PURGE_KEY
|
76
|
+
*/
|
77
|
+
declare function validateParams(req: NextApiRequest): {
|
78
|
+
projectId: string;
|
79
|
+
dataTypeId: string;
|
80
|
+
purgeKey: string;
|
81
|
+
edgeApiHost: string | undefined;
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* Only allows Stable, Canary and PR edge API hosts.
|
85
|
+
*/
|
86
|
+
declare function isAllowedEdgeApiHost(edgeApiHost: string): boolean;
|
87
|
+
|
88
|
+
export { APIError, BadRequestError, ForbiddenError, type InvalidationResponse, type Purger, createPurger, getParam, getRequiredParam, handleNextJSWebhookRequest, type handleNextJSWebhookRequestArgs, isAllowedEdgeApiHost, validateParams };
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
2
|
+
|
3
|
+
type InvalidationResponse = {
|
4
|
+
status: number;
|
5
|
+
text: string;
|
6
|
+
};
|
7
|
+
declare abstract class APIError extends Error {
|
8
|
+
abstract readonly status: number;
|
9
|
+
abstract readonly statusText: string;
|
10
|
+
}
|
11
|
+
declare class BadRequestError extends APIError {
|
12
|
+
status: number;
|
13
|
+
statusText: string;
|
14
|
+
constructor(message?: string);
|
15
|
+
}
|
16
|
+
declare class ForbiddenError extends APIError {
|
17
|
+
status: number;
|
18
|
+
statusText: string;
|
19
|
+
constructor(message?: string);
|
20
|
+
}
|
21
|
+
|
22
|
+
type Purger = {
|
23
|
+
/** Purge all caches for the Data Type */
|
24
|
+
purgeAllCachesForDataType(): Promise<InvalidationResponse>;
|
25
|
+
/** Purge caches by surrogate keys. Your Custom Edgehancer is responsible to set them up first */
|
26
|
+
purgeBySurrogateKeys(surrogateKeys: string[]): Promise<InvalidationResponse>;
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Returns Purger with two methods to invalidate cache for your Data Type.
|
30
|
+
* You should validate parameters before calling this function.
|
31
|
+
*/
|
32
|
+
declare const createPurger: ({ projectId, purgeKey, dataTypeId, edgeApiHost, logger, }: {
|
33
|
+
projectId: string;
|
34
|
+
purgeKey: string;
|
35
|
+
dataTypeId: string;
|
36
|
+
edgeApiHost?: string | undefined;
|
37
|
+
logger?: Console | undefined;
|
38
|
+
}) => Purger;
|
39
|
+
|
40
|
+
type handleNextJSWebhookRequestArgs = {
|
41
|
+
/** NextJS request object */
|
42
|
+
request: NextApiRequest;
|
43
|
+
/** NextJS response object */
|
44
|
+
response: NextApiResponse;
|
45
|
+
/**
|
46
|
+
* Your custom handler that will be called after request validation with purger instance
|
47
|
+
* that has methods to invalidate your Data Type cache
|
48
|
+
* */
|
49
|
+
handler: (args: {
|
50
|
+
request: NextApiRequest;
|
51
|
+
purger: Purger;
|
52
|
+
}) => Promise<InvalidationResponse>;
|
53
|
+
logger?: Console;
|
54
|
+
};
|
55
|
+
/**
|
56
|
+
* Handles the incoming webhook request via NextJS api route.
|
57
|
+
*
|
58
|
+
* It validates the request, handle exceptions,
|
59
|
+
* calls your custom handler and sends the response back to webhook caller.
|
60
|
+
*/
|
61
|
+
declare const handleNextJSWebhookRequest: ({ request, response, handler, logger, }: handleNextJSWebhookRequestArgs) => Promise<void>;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Reads the parameter from the Next.js api route request
|
65
|
+
*/
|
66
|
+
declare function getParam(query: NextApiRequest['query'], paramName: string): string | undefined;
|
67
|
+
/**
|
68
|
+
* Throws an BadRequestError exception if the parameter is not found in the request.
|
69
|
+
*/
|
70
|
+
declare function getRequiredParam(query: NextApiRequest['query'], paramName: string): string;
|
71
|
+
/**
|
72
|
+
* Reads and validates the request parameters required to perform cache invalidation.
|
73
|
+
* In case of invalid parameters, it throws an BadRequestError exception.
|
74
|
+
*
|
75
|
+
* URL example: https://my-nextjs-app.com/api/cache-invalidation?projectId=PROJECT_ID&dataTypeId=DATA_TYPE_ID&purgeKey=PURGE_KEY
|
76
|
+
*/
|
77
|
+
declare function validateParams(req: NextApiRequest): {
|
78
|
+
projectId: string;
|
79
|
+
dataTypeId: string;
|
80
|
+
purgeKey: string;
|
81
|
+
edgeApiHost: string | undefined;
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* Only allows Stable, Canary and PR edge API hosts.
|
85
|
+
*/
|
86
|
+
declare function isAllowedEdgeApiHost(edgeApiHost: string): boolean;
|
87
|
+
|
88
|
+
export { APIError, BadRequestError, ForbiddenError, type InvalidationResponse, type Purger, createPurger, getParam, getRequiredParam, handleNextJSWebhookRequest, type handleNextJSWebhookRequestArgs, isAllowedEdgeApiHost, validateParams };
|
@@ -0,0 +1,205 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/webhooks/index.ts
|
21
|
+
var webhooks_exports = {};
|
22
|
+
__export(webhooks_exports, {
|
23
|
+
APIError: () => APIError,
|
24
|
+
BadRequestError: () => BadRequestError,
|
25
|
+
ForbiddenError: () => ForbiddenError,
|
26
|
+
createPurger: () => createPurger,
|
27
|
+
getParam: () => getParam,
|
28
|
+
getRequiredParam: () => getRequiredParam,
|
29
|
+
handleNextJSWebhookRequest: () => handleNextJSWebhookRequest,
|
30
|
+
isAllowedEdgeApiHost: () => isAllowedEdgeApiHost,
|
31
|
+
validateParams: () => validateParams
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(webhooks_exports);
|
34
|
+
|
35
|
+
// src/webhooks/purge.ts
|
36
|
+
var defaultLogger = console;
|
37
|
+
var createPurger = ({
|
38
|
+
projectId,
|
39
|
+
purgeKey,
|
40
|
+
dataTypeId,
|
41
|
+
edgeApiHost = "uniform.global",
|
42
|
+
logger = defaultLogger
|
43
|
+
}) => {
|
44
|
+
const invalidationEndpointUrl = new URL(`https://${edgeApiHost}/api/v1/invalidation`);
|
45
|
+
invalidationEndpointUrl.searchParams.set("projectId", projectId);
|
46
|
+
invalidationEndpointUrl.searchParams.set("dataTypeId", dataTypeId);
|
47
|
+
invalidationEndpointUrl.searchParams.set("purgeKey", purgeKey);
|
48
|
+
const purgeAllCachesForDataType = async () => {
|
49
|
+
logger.log(`[purgeAllCachesForDataType] call`, {
|
50
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString()
|
51
|
+
});
|
52
|
+
const res = await fetch(invalidationEndpointUrl, {
|
53
|
+
method: "GET"
|
54
|
+
});
|
55
|
+
return {
|
56
|
+
status: res.status,
|
57
|
+
text: await res.text()
|
58
|
+
};
|
59
|
+
};
|
60
|
+
const purgeBySurrogateKeys = async (surrogateKeys) => {
|
61
|
+
logger.log(`[purgeBySurrogateKeys] call`, {
|
62
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString(),
|
63
|
+
surrogateKeys
|
64
|
+
});
|
65
|
+
const body = {
|
66
|
+
surrogateKeys: surrogateKeys.filter((x) => x)
|
67
|
+
};
|
68
|
+
if (body.surrogateKeys.length > 0) {
|
69
|
+
const res = await fetch(invalidationEndpointUrl, {
|
70
|
+
method: "POST",
|
71
|
+
body: JSON.stringify(body)
|
72
|
+
});
|
73
|
+
return {
|
74
|
+
status: res.status,
|
75
|
+
text: await res.text()
|
76
|
+
};
|
77
|
+
} else {
|
78
|
+
logger.log(`[purgeBySurrogateKeys] No surrogate keys found.`, {
|
79
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString(),
|
80
|
+
surrogateKeys
|
81
|
+
});
|
82
|
+
return {
|
83
|
+
status: 200,
|
84
|
+
text: "No surrogate keys found."
|
85
|
+
};
|
86
|
+
}
|
87
|
+
};
|
88
|
+
return { purgeAllCachesForDataType, purgeBySurrogateKeys };
|
89
|
+
};
|
90
|
+
|
91
|
+
// src/webhooks/shared.ts
|
92
|
+
var APIError = class extends Error {
|
93
|
+
};
|
94
|
+
var BadRequestError = class _BadRequestError extends APIError {
|
95
|
+
constructor(message = "Invalid request received") {
|
96
|
+
super(message);
|
97
|
+
this.status = 400;
|
98
|
+
this.statusText = "Bad Request";
|
99
|
+
Object.setPrototypeOf(this, _BadRequestError.prototype);
|
100
|
+
}
|
101
|
+
};
|
102
|
+
var ForbiddenError = class _ForbiddenError extends APIError {
|
103
|
+
constructor(message = "This action is forbidden") {
|
104
|
+
super(message);
|
105
|
+
this.status = 403;
|
106
|
+
this.statusText = "Forbidden";
|
107
|
+
Object.setPrototypeOf(this, _ForbiddenError.prototype);
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
// src/webhooks/utils.ts
|
112
|
+
function getParam(query, paramName) {
|
113
|
+
const values = query[paramName];
|
114
|
+
if (!values) {
|
115
|
+
return void 0;
|
116
|
+
} else if (typeof values === "string") {
|
117
|
+
return values;
|
118
|
+
} else if (values.length === 1) {
|
119
|
+
return values[0];
|
120
|
+
} else {
|
121
|
+
throw new BadRequestError(`Multiple values for ${paramName} found in request parameters`);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
function getRequiredParam(query, paramName) {
|
125
|
+
const value = getParam(query, paramName);
|
126
|
+
if (!value) {
|
127
|
+
throw new BadRequestError(`${paramName} not found in request parameters`);
|
128
|
+
}
|
129
|
+
return value;
|
130
|
+
}
|
131
|
+
function validateParams(req) {
|
132
|
+
const edgeApiHost = getParam(req.query, "edgeApiHost");
|
133
|
+
if (edgeApiHost) {
|
134
|
+
if (!isAllowedEdgeApiHost(edgeApiHost)) {
|
135
|
+
throw new ForbiddenError(`Edge API hostname is not allowed: ${edgeApiHost}`);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
const projectId = getRequiredParam(req.query, "projectId");
|
139
|
+
const dataTypeId = getRequiredParam(req.query, "dataTypeId");
|
140
|
+
const purgeKey = getRequiredParam(req.query, "purgeKey");
|
141
|
+
return { projectId, dataTypeId, purgeKey, edgeApiHost };
|
142
|
+
}
|
143
|
+
function isAllowedEdgeApiHost(edgeApiHost) {
|
144
|
+
if (["uniform.global", "canary.uniform.global"].includes(edgeApiHost)) {
|
145
|
+
return true;
|
146
|
+
}
|
147
|
+
if (edgeApiHost.endsWith(".uniform.rocks")) {
|
148
|
+
return true;
|
149
|
+
}
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
|
153
|
+
// src/webhooks/handleNextJSWebhookRequest.ts
|
154
|
+
var ALLOWED_METHODS = ["POST", "GET"];
|
155
|
+
var defaultLogger2 = console;
|
156
|
+
var handleNextJSWebhookRequest = async ({
|
157
|
+
request,
|
158
|
+
response,
|
159
|
+
handler,
|
160
|
+
logger = defaultLogger2
|
161
|
+
}) => {
|
162
|
+
try {
|
163
|
+
logger.log(`request`, {
|
164
|
+
url: request.url,
|
165
|
+
method: request.method
|
166
|
+
});
|
167
|
+
if (!ALLOWED_METHODS.includes(request.method || "")) {
|
168
|
+
throw new BadRequestError(
|
169
|
+
`Expected ${ALLOWED_METHODS.join(" or ")} but was called with ${request.method}`
|
170
|
+
);
|
171
|
+
}
|
172
|
+
const { projectId, purgeKey, dataTypeId, edgeApiHost } = validateParams(request);
|
173
|
+
const purger = createPurger({ projectId, purgeKey, dataTypeId, edgeApiHost, logger });
|
174
|
+
const { status, text } = await handler({
|
175
|
+
request,
|
176
|
+
purger
|
177
|
+
});
|
178
|
+
response.status(status).send(text);
|
179
|
+
} catch (err) {
|
180
|
+
if (err instanceof APIError) {
|
181
|
+
logger.error(`APIError: [${err.status} ${err.statusText}] ${err.message}`);
|
182
|
+
response.status(err.status).json({
|
183
|
+
type: err.statusText,
|
184
|
+
errorMessage: err.message
|
185
|
+
});
|
186
|
+
} else {
|
187
|
+
logger.error(`Error`, err);
|
188
|
+
response.status(500).json({
|
189
|
+
errorMessage: err.message || "Unknown error"
|
190
|
+
});
|
191
|
+
}
|
192
|
+
}
|
193
|
+
};
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
195
|
+
0 && (module.exports = {
|
196
|
+
APIError,
|
197
|
+
BadRequestError,
|
198
|
+
ForbiddenError,
|
199
|
+
createPurger,
|
200
|
+
getParam,
|
201
|
+
getRequiredParam,
|
202
|
+
handleNextJSWebhookRequest,
|
203
|
+
isAllowedEdgeApiHost,
|
204
|
+
validateParams
|
205
|
+
});
|
@@ -0,0 +1,170 @@
|
|
1
|
+
// src/webhooks/purge.ts
|
2
|
+
var defaultLogger = console;
|
3
|
+
var createPurger = ({
|
4
|
+
projectId,
|
5
|
+
purgeKey,
|
6
|
+
dataTypeId,
|
7
|
+
edgeApiHost = "uniform.global",
|
8
|
+
logger = defaultLogger
|
9
|
+
}) => {
|
10
|
+
const invalidationEndpointUrl = new URL(`https://${edgeApiHost}/api/v1/invalidation`);
|
11
|
+
invalidationEndpointUrl.searchParams.set("projectId", projectId);
|
12
|
+
invalidationEndpointUrl.searchParams.set("dataTypeId", dataTypeId);
|
13
|
+
invalidationEndpointUrl.searchParams.set("purgeKey", purgeKey);
|
14
|
+
const purgeAllCachesForDataType = async () => {
|
15
|
+
logger.log(`[purgeAllCachesForDataType] call`, {
|
16
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString()
|
17
|
+
});
|
18
|
+
const res = await fetch(invalidationEndpointUrl, {
|
19
|
+
method: "GET"
|
20
|
+
});
|
21
|
+
return {
|
22
|
+
status: res.status,
|
23
|
+
text: await res.text()
|
24
|
+
};
|
25
|
+
};
|
26
|
+
const purgeBySurrogateKeys = async (surrogateKeys) => {
|
27
|
+
logger.log(`[purgeBySurrogateKeys] call`, {
|
28
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString(),
|
29
|
+
surrogateKeys
|
30
|
+
});
|
31
|
+
const body = {
|
32
|
+
surrogateKeys: surrogateKeys.filter((x) => x)
|
33
|
+
};
|
34
|
+
if (body.surrogateKeys.length > 0) {
|
35
|
+
const res = await fetch(invalidationEndpointUrl, {
|
36
|
+
method: "POST",
|
37
|
+
body: JSON.stringify(body)
|
38
|
+
});
|
39
|
+
return {
|
40
|
+
status: res.status,
|
41
|
+
text: await res.text()
|
42
|
+
};
|
43
|
+
} else {
|
44
|
+
logger.log(`[purgeBySurrogateKeys] No surrogate keys found.`, {
|
45
|
+
invalidationEndpointUrl: invalidationEndpointUrl.toString(),
|
46
|
+
surrogateKeys
|
47
|
+
});
|
48
|
+
return {
|
49
|
+
status: 200,
|
50
|
+
text: "No surrogate keys found."
|
51
|
+
};
|
52
|
+
}
|
53
|
+
};
|
54
|
+
return { purgeAllCachesForDataType, purgeBySurrogateKeys };
|
55
|
+
};
|
56
|
+
|
57
|
+
// src/webhooks/shared.ts
|
58
|
+
var APIError = class extends Error {
|
59
|
+
};
|
60
|
+
var BadRequestError = class _BadRequestError extends APIError {
|
61
|
+
constructor(message = "Invalid request received") {
|
62
|
+
super(message);
|
63
|
+
this.status = 400;
|
64
|
+
this.statusText = "Bad Request";
|
65
|
+
Object.setPrototypeOf(this, _BadRequestError.prototype);
|
66
|
+
}
|
67
|
+
};
|
68
|
+
var ForbiddenError = class _ForbiddenError extends APIError {
|
69
|
+
constructor(message = "This action is forbidden") {
|
70
|
+
super(message);
|
71
|
+
this.status = 403;
|
72
|
+
this.statusText = "Forbidden";
|
73
|
+
Object.setPrototypeOf(this, _ForbiddenError.prototype);
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
// src/webhooks/utils.ts
|
78
|
+
function getParam(query, paramName) {
|
79
|
+
const values = query[paramName];
|
80
|
+
if (!values) {
|
81
|
+
return void 0;
|
82
|
+
} else if (typeof values === "string") {
|
83
|
+
return values;
|
84
|
+
} else if (values.length === 1) {
|
85
|
+
return values[0];
|
86
|
+
} else {
|
87
|
+
throw new BadRequestError(`Multiple values for ${paramName} found in request parameters`);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
function getRequiredParam(query, paramName) {
|
91
|
+
const value = getParam(query, paramName);
|
92
|
+
if (!value) {
|
93
|
+
throw new BadRequestError(`${paramName} not found in request parameters`);
|
94
|
+
}
|
95
|
+
return value;
|
96
|
+
}
|
97
|
+
function validateParams(req) {
|
98
|
+
const edgeApiHost = getParam(req.query, "edgeApiHost");
|
99
|
+
if (edgeApiHost) {
|
100
|
+
if (!isAllowedEdgeApiHost(edgeApiHost)) {
|
101
|
+
throw new ForbiddenError(`Edge API hostname is not allowed: ${edgeApiHost}`);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
const projectId = getRequiredParam(req.query, "projectId");
|
105
|
+
const dataTypeId = getRequiredParam(req.query, "dataTypeId");
|
106
|
+
const purgeKey = getRequiredParam(req.query, "purgeKey");
|
107
|
+
return { projectId, dataTypeId, purgeKey, edgeApiHost };
|
108
|
+
}
|
109
|
+
function isAllowedEdgeApiHost(edgeApiHost) {
|
110
|
+
if (["uniform.global", "canary.uniform.global"].includes(edgeApiHost)) {
|
111
|
+
return true;
|
112
|
+
}
|
113
|
+
if (edgeApiHost.endsWith(".uniform.rocks")) {
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
|
119
|
+
// src/webhooks/handleNextJSWebhookRequest.ts
|
120
|
+
var ALLOWED_METHODS = ["POST", "GET"];
|
121
|
+
var defaultLogger2 = console;
|
122
|
+
var handleNextJSWebhookRequest = async ({
|
123
|
+
request,
|
124
|
+
response,
|
125
|
+
handler,
|
126
|
+
logger = defaultLogger2
|
127
|
+
}) => {
|
128
|
+
try {
|
129
|
+
logger.log(`request`, {
|
130
|
+
url: request.url,
|
131
|
+
method: request.method
|
132
|
+
});
|
133
|
+
if (!ALLOWED_METHODS.includes(request.method || "")) {
|
134
|
+
throw new BadRequestError(
|
135
|
+
`Expected ${ALLOWED_METHODS.join(" or ")} but was called with ${request.method}`
|
136
|
+
);
|
137
|
+
}
|
138
|
+
const { projectId, purgeKey, dataTypeId, edgeApiHost } = validateParams(request);
|
139
|
+
const purger = createPurger({ projectId, purgeKey, dataTypeId, edgeApiHost, logger });
|
140
|
+
const { status, text } = await handler({
|
141
|
+
request,
|
142
|
+
purger
|
143
|
+
});
|
144
|
+
response.status(status).send(text);
|
145
|
+
} catch (err) {
|
146
|
+
if (err instanceof APIError) {
|
147
|
+
logger.error(`APIError: [${err.status} ${err.statusText}] ${err.message}`);
|
148
|
+
response.status(err.status).json({
|
149
|
+
type: err.statusText,
|
150
|
+
errorMessage: err.message
|
151
|
+
});
|
152
|
+
} else {
|
153
|
+
logger.error(`Error`, err);
|
154
|
+
response.status(500).json({
|
155
|
+
errorMessage: err.message || "Unknown error"
|
156
|
+
});
|
157
|
+
}
|
158
|
+
}
|
159
|
+
};
|
160
|
+
export {
|
161
|
+
APIError,
|
162
|
+
BadRequestError,
|
163
|
+
ForbiddenError,
|
164
|
+
createPurger,
|
165
|
+
getParam,
|
166
|
+
getRequiredParam,
|
167
|
+
handleNextJSWebhookRequest,
|
168
|
+
isAllowedEdgeApiHost,
|
169
|
+
validateParams
|
170
|
+
};
|
package/package.json
CHANGED
@@ -1,19 +1,39 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/mesh-edgehancer-sdk",
|
3
|
-
"version": "19.126.
|
3
|
+
"version": "19.126.2-alpha.3+6fae78e8d1",
|
4
4
|
"description": "Uniform Mesh Edgehancer SDK",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
7
7
|
"module": "./dist/index.esm.js",
|
8
8
|
"exports": {
|
9
|
-
"
|
10
|
-
"
|
11
|
-
|
12
|
-
|
9
|
+
".": {
|
10
|
+
"import": {
|
11
|
+
"types": "./dist/index.d.mts",
|
12
|
+
"node": "./dist/index.mjs",
|
13
|
+
"default": "./dist/index.esm.js"
|
14
|
+
},
|
15
|
+
"require": "./dist/index.js"
|
13
16
|
},
|
14
|
-
"
|
17
|
+
"./webhooks": {
|
18
|
+
"import": {
|
19
|
+
"types": "./dist/webhooks/index.d.mts",
|
20
|
+
"node": "./dist/webhooks/index.mjs",
|
21
|
+
"default": "./dist/webhooks/index.esm.js"
|
22
|
+
},
|
23
|
+
"require": "./dist/webhooks/index.js"
|
24
|
+
}
|
15
25
|
},
|
16
26
|
"types": "./dist/index.d.ts",
|
27
|
+
"typesVersions": {
|
28
|
+
"*": {
|
29
|
+
"*": [
|
30
|
+
"./dist/index.d.ts"
|
31
|
+
],
|
32
|
+
"webhooks": [
|
33
|
+
"./dist/webhooks/index.d.ts"
|
34
|
+
]
|
35
|
+
}
|
36
|
+
},
|
17
37
|
"sideEffects": false,
|
18
38
|
"scripts": {
|
19
39
|
"build": "tsup",
|
@@ -28,12 +48,18 @@
|
|
28
48
|
"/dist"
|
29
49
|
],
|
30
50
|
"dependencies": {
|
31
|
-
"@uniformdev/canvas": "19.126.
|
51
|
+
"@uniformdev/canvas": "19.126.2-alpha.3+6fae78e8d1",
|
32
52
|
"tsafe": "1.6.5",
|
33
53
|
"zod": "3.22.4"
|
34
54
|
},
|
55
|
+
"devDependencies": {
|
56
|
+
"next": "13.4.12"
|
57
|
+
},
|
58
|
+
"peerDependencies": {
|
59
|
+
"next": ">13"
|
60
|
+
},
|
35
61
|
"publishConfig": {
|
36
62
|
"access": "public"
|
37
63
|
},
|
38
|
-
"gitHead": "
|
64
|
+
"gitHead": "6fae78e8d1439292dea82dc96c1d3510b43b39ef"
|
39
65
|
}
|