@sanity/blueprints 0.34.0 → 0.35.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/dist/definers/agents.d.ts +3 -1
- package/dist/definers/agents.js +3 -1
- package/dist/definers/agents.js.map +1 -1
- package/dist/definers/applications.d.ts +30 -18
- package/dist/definers/applications.js +30 -18
- package/dist/definers/applications.js.map +1 -1
- package/dist/definers/blueprints.d.ts +1 -0
- package/dist/definers/blueprints.js +1 -25
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/context.d.ts +6 -2
- package/dist/definers/context.js +6 -2
- package/dist/definers/context.js.map +1 -1
- package/dist/definers/cors.d.ts +11 -1
- package/dist/definers/cors.js +10 -12
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +12 -2
- package/dist/definers/datasets.js +11 -14
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions/document.d.ts +30 -0
- package/dist/definers/functions/document.js.map +1 -1
- package/dist/definers/functions/durable.d.ts +4 -3
- package/dist/definers/functions/durable.js +4 -3
- package/dist/definers/functions/durable.js.map +1 -1
- package/dist/definers/functions/media-library.d.ts +31 -0
- package/dist/definers/functions/media-library.js +18 -19
- package/dist/definers/functions/media-library.js.map +1 -1
- package/dist/definers/functions/pubsub.d.ts +2 -3
- package/dist/definers/functions/pubsub.js +2 -3
- package/dist/definers/functions/pubsub.js.map +1 -1
- package/dist/definers/functions/queue.d.ts +15 -4
- package/dist/definers/functions/queue.js +19 -6
- package/dist/definers/functions/queue.js.map +1 -1
- package/dist/definers/functions/scheduled.d.ts +7 -6
- package/dist/definers/functions/scheduled.js +7 -6
- package/dist/definers/functions/scheduled.js.map +1 -1
- package/dist/definers/functions/sync-tag-invalidate.d.ts +5 -2
- package/dist/definers/functions/sync-tag-invalidate.js +5 -2
- package/dist/definers/functions/sync-tag-invalidate.js.map +1 -1
- package/dist/definers/installation-config.d.ts +4 -2
- package/dist/definers/installation-config.js +4 -2
- package/dist/definers/installation-config.js.map +1 -1
- package/dist/definers/permissions.d.ts +8 -2
- package/dist/definers/permissions.js +8 -2
- package/dist/definers/permissions.js.map +1 -1
- package/dist/definers/projects.d.ts +3 -4
- package/dist/definers/projects.js +3 -4
- package/dist/definers/projects.js.map +1 -1
- package/dist/definers/resources.d.ts +1 -0
- package/dist/definers/resources.js +1 -11
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/robotTokens.d.ts +22 -3
- package/dist/definers/robotTokens.js +17 -18
- package/dist/definers/robotTokens.js.map +1 -1
- package/dist/definers/roles.d.ts +53 -5
- package/dist/definers/roles.js +38 -40
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/studios.d.ts +5 -3
- package/dist/definers/studios.js +5 -3
- package/dist/definers/studios.js.map +1 -1
- package/dist/definers/webhooks.d.ts +19 -1
- package/dist/definers/webhooks.js +15 -17
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +19 -20
- package/dist/index.js.map +1 -1
- package/dist/resolve/index.d.ts +2 -3
- package/dist/resolve/index.js +2 -3
- package/dist/resolve/index.js.map +1 -1
- package/dist/types/agents.d.ts +7 -3
- package/dist/types/applications.d.ts +67 -49
- package/dist/types/applications.js +9 -6
- package/dist/types/applications.js.map +1 -1
- package/dist/types/context.d.ts +17 -7
- package/dist/types/cors.d.ts +0 -2
- package/dist/types/datasets.d.ts +0 -6
- package/dist/types/functions/index.d.ts +64 -14
- package/dist/types/functions/index.js +2 -1
- package/dist/types/functions/index.js.map +1 -1
- package/dist/types/installation-config.d.ts +13 -10
- package/dist/types/permissions.d.ts +8 -4
- package/dist/types/projects.d.ts +5 -4
- package/dist/types/robotTokens.d.ts +0 -3
- package/dist/types/roles.d.ts +0 -4
- package/dist/types/studios.d.ts +28 -15
- package/dist/types/studios.js +3 -2
- package/dist/types/studios.js.map +1 -1
- package/dist/types/webhooks.d.ts +0 -3
- package/dist/utils/debounce.d.ts +0 -11
- package/dist/utils/debounce.js +0 -22
- package/dist/utils/debounce.js.map +1 -1
- package/dist/utils/parse-duration.d.ts +13 -0
- package/dist/utils/parse-duration.js +24 -0
- package/dist/utils/parse-duration.js.map +1 -1
- package/dist/utils/throttle.d.ts +9 -0
- package/dist/utils/throttle.js +22 -0
- package/dist/utils/throttle.js.map +1 -0
- package/dist/validation/applications.js +7 -2
- package/dist/validation/applications.js.map +1 -1
- package/dist/validation/functions.d.ts +10 -0
- package/dist/validation/functions.js +112 -12
- package/dist/validation/functions.js.map +1 -1
- package/dist/validation/projects.js +3 -0
- package/dist/validation/projects.js.map +1 -1
- package/dist/validation/studios.js +4 -5
- package/dist/validation/studios.js.map +1 -1
- package/package.json +1 -1
- package/src/definers/agents.ts +3 -1
- package/src/definers/applications.ts +30 -18
- package/src/definers/blueprints.ts +1 -25
- package/src/definers/context.ts +6 -2
- package/src/definers/cors.ts +10 -12
- package/src/definers/datasets.ts +11 -14
- package/src/definers/functions/document.ts +17 -24
- package/src/definers/functions/durable.ts +4 -3
- package/src/definers/functions/media-library.ts +18 -19
- package/src/definers/functions/pubsub.ts +2 -3
- package/src/definers/functions/queue.ts +19 -6
- package/src/definers/functions/scheduled.ts +7 -6
- package/src/definers/functions/sync-tag-invalidate.ts +5 -2
- package/src/definers/installation-config.ts +4 -2
- package/src/definers/permissions.ts +8 -2
- package/src/definers/projects.ts +3 -4
- package/src/definers/resources.ts +1 -11
- package/src/definers/robotTokens.ts +17 -18
- package/src/definers/roles.ts +38 -40
- package/src/definers/studios.ts +5 -3
- package/src/definers/webhooks.ts +15 -17
- package/src/index.ts +20 -21
- package/src/resolve/index.ts +2 -4
- package/src/types/agents.ts +7 -3
- package/src/types/applications.ts +67 -49
- package/src/types/context.ts +17 -7
- package/src/types/cors.ts +0 -2
- package/src/types/datasets.ts +0 -6
- package/src/types/functions/index.ts +67 -14
- package/src/types/installation-config.ts +13 -10
- package/src/types/permissions.ts +8 -4
- package/src/types/projects.ts +6 -4
- package/src/types/robotTokens.ts +0 -3
- package/src/types/roles.ts +0 -4
- package/src/types/studios.ts +28 -16
- package/src/types/webhooks.ts +0 -3
- package/src/utils/debounce.ts +0 -25
- package/src/utils/parse-duration.ts +27 -0
- package/src/utils/throttle.ts +25 -0
- package/src/validation/applications.ts +6 -2
- package/src/validation/functions.ts +123 -12
- package/src/validation/projects.ts +4 -0
- package/src/validation/studios.ts +3 -6
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {ThrottleConfig, ThrottleConfigInput} from '../types/functions/index.js'
|
|
2
|
+
import {parseDuration} from './parse-duration.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the throttle config accepted by a definer into the shape held by a resource,
|
|
6
|
+
* parsing `period` into seconds.
|
|
7
|
+
* @param throttle The throttle config to normalize
|
|
8
|
+
* @internal
|
|
9
|
+
* @returns The throttle config, with `period` in seconds
|
|
10
|
+
*/
|
|
11
|
+
export function createThrottleObject(throttle: ThrottleConfigInput): ThrottleConfig {
|
|
12
|
+
const {limit, period, burst, key} = throttle
|
|
13
|
+
|
|
14
|
+
// `period` is required, so there is nothing sensible to parse without it
|
|
15
|
+
if (period === undefined) {
|
|
16
|
+
throw new Error('Invalid throttle config: `period` must be provided')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
limit,
|
|
21
|
+
period: parseDuration(period, 's'),
|
|
22
|
+
...(burst !== undefined && {burst}),
|
|
23
|
+
...(key !== undefined && {key}),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -284,8 +284,12 @@ export function validateApplication(resource: unknown): BlueprintError[] {
|
|
|
284
284
|
errors.push({type: 'invalid_value', message: 'Application root must be a relative path within the blueprint directory'})
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
if ('icon' in resource
|
|
288
|
-
|
|
287
|
+
if ('icon' in resource) {
|
|
288
|
+
if (typeof resource.icon !== 'string') {
|
|
289
|
+
errors.push({type: 'invalid_type', message: 'Application icon must be a string'})
|
|
290
|
+
} else if (!isReference(resource.icon) && !isContainedRelativePath(resource.icon)) {
|
|
291
|
+
errors.push({type: 'invalid_value', message: 'Application icon must be a relative path within the application root'})
|
|
292
|
+
}
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
if (
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
VALID_RUNTIMES,
|
|
8
8
|
validateResource,
|
|
9
9
|
} from '../index.js'
|
|
10
|
-
import {
|
|
10
|
+
import {resolveDuration} from '../utils/parse-duration.js'
|
|
11
11
|
import {isReference} from '../utils/validation.js'
|
|
12
12
|
|
|
13
13
|
type BaseFunctionEventKey = keyof BlueprintFunctionBaseResourceEvent
|
|
@@ -462,9 +462,6 @@ export function validateQueueFunction(functionResource: unknown): BlueprintError
|
|
|
462
462
|
if ('fifo' in functionResource && typeof functionResource.fifo !== 'boolean') {
|
|
463
463
|
errors.push({type: 'invalid_type', message: '`fifo` must be a boolean'})
|
|
464
464
|
}
|
|
465
|
-
if ('dlq' in functionResource && typeof functionResource.dlq !== 'boolean') {
|
|
466
|
-
errors.push({type: 'invalid_type', message: '`dlq` must be a boolean'})
|
|
467
|
-
}
|
|
468
465
|
|
|
469
466
|
if ('event' in functionResource && typeof functionResource.event !== 'undefined') {
|
|
470
467
|
errors.push(...validateFunctionContentLakeEvent(functionResource.event))
|
|
@@ -474,6 +471,22 @@ export function validateQueueFunction(functionResource: unknown): BlueprintError
|
|
|
474
471
|
errors.push(...validateDebounceConfig(functionResource.debounce))
|
|
475
472
|
}
|
|
476
473
|
|
|
474
|
+
if ('throttle' in functionResource) {
|
|
475
|
+
errors.push(...validateThrottleConfig(functionResource.throttle))
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if ('maxAttempts' in functionResource) {
|
|
479
|
+
const maxAttemptsErrors = validatePositiveInteger('maxAttempts', functionResource.maxAttempts)
|
|
480
|
+
errors.push(...maxAttemptsErrors)
|
|
481
|
+
if (
|
|
482
|
+
maxAttemptsErrors.length === 0 &&
|
|
483
|
+
typeof functionResource.maxAttempts === 'number' &&
|
|
484
|
+
functionResource.maxAttempts > MAX_QUEUE_ATTEMPTS
|
|
485
|
+
) {
|
|
486
|
+
errors.push({type: 'invalid_value', message: `\`maxAttempts\` must be at most ${MAX_QUEUE_ATTEMPTS}`})
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
477
490
|
errors.push(...validateFunction(functionResource))
|
|
478
491
|
|
|
479
492
|
return errors
|
|
@@ -601,7 +614,7 @@ export function validateDebounceConfig(debounce: unknown): BlueprintError[] {
|
|
|
601
614
|
|
|
602
615
|
// A bare duration is shorthand for `{window: <duration>}`
|
|
603
616
|
if (typeof debounce === 'string' || typeof debounce === 'number') {
|
|
604
|
-
const resolved =
|
|
617
|
+
const resolved = resolveDuration('debounce', debounce)
|
|
605
618
|
return resolved.seconds === undefined ? resolved.errors : validateDebounceConfig({window: resolved.seconds})
|
|
606
619
|
}
|
|
607
620
|
|
|
@@ -618,7 +631,7 @@ export function validateDebounceConfig(debounce: unknown): BlueprintError[] {
|
|
|
618
631
|
}
|
|
619
632
|
|
|
620
633
|
if ('window' in debounce) {
|
|
621
|
-
const resolved =
|
|
634
|
+
const resolved = resolveDuration('window', debounce.window)
|
|
622
635
|
errors.push(...resolved.errors)
|
|
623
636
|
|
|
624
637
|
if (resolved.seconds !== undefined) {
|
|
@@ -631,7 +644,7 @@ export function validateDebounceConfig(debounce: unknown): BlueprintError[] {
|
|
|
631
644
|
}
|
|
632
645
|
|
|
633
646
|
if ('maxWindow' in debounce) {
|
|
634
|
-
const resolved =
|
|
647
|
+
const resolved = resolveDuration('maxWindow', debounce.maxWindow)
|
|
635
648
|
errors.push(...resolved.errors)
|
|
636
649
|
|
|
637
650
|
if (resolved.seconds !== undefined) {
|
|
@@ -643,14 +656,112 @@ export function validateDebounceConfig(debounce: unknown): BlueprintError[] {
|
|
|
643
656
|
}
|
|
644
657
|
}
|
|
645
658
|
|
|
646
|
-
// `maxWindow` caps how far `window` can be extended from the first event, so it
|
|
647
|
-
if (window !== undefined && maxWindow !== undefined && maxWindow
|
|
648
|
-
errors.push({type: 'invalid_value', message: '`maxWindow` must be greater than `window`'})
|
|
659
|
+
// `maxWindow` caps how far `window` can be extended from the first event, so it can't be shorter than `window`
|
|
660
|
+
if (window !== undefined && maxWindow !== undefined && maxWindow < window) {
|
|
661
|
+
errors.push({type: 'invalid_value', message: '`maxWindow` must be greater than or equal to `window`'})
|
|
649
662
|
}
|
|
650
663
|
|
|
651
|
-
if ('key' in debounce
|
|
652
|
-
errors.push(
|
|
664
|
+
if ('key' in debounce) {
|
|
665
|
+
errors.push(...validateKeyPath(debounce.key))
|
|
653
666
|
}
|
|
654
667
|
|
|
655
668
|
return errors
|
|
656
669
|
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Validates a throttle config.
|
|
673
|
+
* Only checks shape; rate and period ceilings are enforced by the functions service.
|
|
674
|
+
* @param throttle The config to validate
|
|
675
|
+
* @alpha
|
|
676
|
+
* @hidden
|
|
677
|
+
* @category Functions Types
|
|
678
|
+
* @returns Array of validation errors, empty if valid
|
|
679
|
+
*/
|
|
680
|
+
export function validateThrottleConfig(throttle: unknown): BlueprintError[] {
|
|
681
|
+
if (throttle === undefined || throttle === null) {
|
|
682
|
+
return [{type: 'invalid_value', message: 'Throttle config must be provided'}]
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (typeof throttle !== 'object') return [{type: 'invalid_type', message: 'Throttle config must be an object'}]
|
|
686
|
+
|
|
687
|
+
const errors: BlueprintError[] = []
|
|
688
|
+
|
|
689
|
+
// `limit` is only kept when it is valid, so the `burst` comparison below doesn't pile onto an existing error
|
|
690
|
+
let limit: number | undefined
|
|
691
|
+
|
|
692
|
+
if (!('limit' in throttle)) {
|
|
693
|
+
errors.push({type: 'missing_parameter', message: '`limit` must be provided'})
|
|
694
|
+
} else {
|
|
695
|
+
const limitErrors = validatePositiveInteger('limit', throttle.limit)
|
|
696
|
+
errors.push(...limitErrors)
|
|
697
|
+
if (limitErrors.length === 0 && typeof throttle.limit === 'number') limit = throttle.limit
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (!('period' in throttle)) {
|
|
701
|
+
errors.push({type: 'missing_parameter', message: '`period` must be provided'})
|
|
702
|
+
} else {
|
|
703
|
+
const resolved = resolveDuration('period', throttle.period)
|
|
704
|
+
errors.push(...resolved.errors)
|
|
705
|
+
|
|
706
|
+
if (resolved.seconds !== undefined && (!Number.isInteger(resolved.seconds) || resolved.seconds < 1)) {
|
|
707
|
+
errors.push({type: 'invalid_value', message: '`period` must be a whole number of seconds, at least 1'})
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if ('burst' in throttle) {
|
|
712
|
+
const burstErrors = validatePositiveInteger('burst', throttle.burst)
|
|
713
|
+
errors.push(...burstErrors)
|
|
714
|
+
if (burstErrors.length === 0 && limit !== undefined && typeof throttle.burst === 'number' && throttle.burst > limit) {
|
|
715
|
+
errors.push({type: 'invalid_value', message: '`burst` must be less than or equal to `limit`'})
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if ('key' in throttle) {
|
|
720
|
+
errors.push(...validateKeyPath(throttle.key))
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return errors
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Validates a whole number of at least 1, e.g. a count or a number of attempts.
|
|
728
|
+
* @param field The name of the field being validated, used in error messages
|
|
729
|
+
* @param value The value to validate
|
|
730
|
+
* @returns Array of validation errors, empty if valid
|
|
731
|
+
*/
|
|
732
|
+
function validatePositiveInteger(field: string, value: unknown): BlueprintError[] {
|
|
733
|
+
if (typeof value !== 'number') return [{type: 'invalid_type', message: `\`${field}\` must be a number`}]
|
|
734
|
+
if (!Number.isInteger(value) || value < 1) return [{type: 'invalid_value', message: `\`${field}\` must be a whole number of at least 1`}]
|
|
735
|
+
return []
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* SQS's hard limit on how many times a message can be received before it is moved to a Dead Letter Queue.
|
|
740
|
+
* The functions service may set a lower limit.
|
|
741
|
+
*/
|
|
742
|
+
const MAX_QUEUE_ATTEMPTS = 1000
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Dotted path into the `{event, context}` envelope a queue feature reads its grouping key from, e.g. `event.data.documentId`.
|
|
746
|
+
* Each segment after the root is a JavaScript identifier, so non-ASCII property names such as `event.data.vær` are allowed.
|
|
747
|
+
*/
|
|
748
|
+
const KEY_PATH_PATTERN = /^(context|event)(\.[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*)+$/u
|
|
749
|
+
const MAX_KEY_PATH_LENGTH = 256
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Validates the `key` of a debounce or throttle config.
|
|
753
|
+
* @param key The key to validate
|
|
754
|
+
* @returns Array of validation errors, empty if valid
|
|
755
|
+
*/
|
|
756
|
+
function validateKeyPath(key: unknown): BlueprintError[] {
|
|
757
|
+
if (typeof key !== 'string') return [{type: 'invalid_type', message: '`key` must be a string'}]
|
|
758
|
+
if (key.length > MAX_KEY_PATH_LENGTH) {
|
|
759
|
+
return [{type: 'invalid_value', message: `\`key\` must be at most ${MAX_KEY_PATH_LENGTH} characters`}]
|
|
760
|
+
}
|
|
761
|
+
if (!KEY_PATH_PATTERN.test(key)) {
|
|
762
|
+
return [
|
|
763
|
+
{type: 'invalid_format', message: '`key` must be a dotted path starting with `event.` or `context.`, e.g. `event.data.documentId`'},
|
|
764
|
+
]
|
|
765
|
+
}
|
|
766
|
+
return []
|
|
767
|
+
}
|
|
@@ -17,5 +17,9 @@ export function validateProject(resource: unknown): BlueprintError[] {
|
|
|
17
17
|
errors.push({type: 'invalid_value', message: 'Project type must be `sanity.project`'})
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if ('logo' in resource && typeof resource.logo !== 'string') {
|
|
21
|
+
errors.push({type: 'invalid_type', message: 'Project logo must be a string'})
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
return errors
|
|
21
25
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {BlueprintError} from '../types/errors.js'
|
|
2
2
|
import {APPLICATION_VISIBILITIES} from '../types/studios.js'
|
|
3
3
|
import {isReference, validateStringField} from '../utils/validation.js'
|
|
4
|
+
import {isContainedRelativePath} from './applications.js'
|
|
4
5
|
import {validateResource} from './resources.js'
|
|
5
6
|
|
|
6
7
|
/** hostname validity pattern */
|
|
@@ -52,6 +53,8 @@ export function validateStudio(resource: unknown): BlueprintError[] {
|
|
|
52
53
|
if ('icon' in resource) {
|
|
53
54
|
if (typeof resource.icon !== 'string') {
|
|
54
55
|
errors.push({type: 'invalid_type', message: 'Studio icon must be a string'})
|
|
56
|
+
} else if (!isReference(resource.icon) && !isContainedRelativePath(resource.icon)) {
|
|
57
|
+
errors.push({type: 'invalid_value', message: 'Studio icon must be a relative path within the studio root'})
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -81,12 +84,6 @@ export function validateStudio(resource: unknown): BlueprintError[] {
|
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
if ('basePath' in resource) {
|
|
85
|
-
if (typeof resource.basePath !== 'string') {
|
|
86
|
-
errors.push({type: 'invalid_type', message: 'Studio basePath must be a string'})
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
87
|
if ('minify' in resource) {
|
|
91
88
|
if (typeof resource.minify !== 'boolean') {
|
|
92
89
|
errors.push({type: 'invalid_type', message: 'Studio minify must be a boolean'})
|