@sanity/blueprints 0.10.0 → 0.11.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.
Files changed (98) hide show
  1. package/README.md +326 -14
  2. package/dist/definers/blueprints.d.ts +2 -0
  3. package/dist/definers/blueprints.js +2 -0
  4. package/dist/definers/blueprints.js.map +1 -1
  5. package/dist/definers/cors.d.ts +4 -0
  6. package/dist/definers/cors.js +4 -0
  7. package/dist/definers/cors.js.map +1 -1
  8. package/dist/definers/datasets.d.ts +5 -0
  9. package/dist/definers/datasets.js +5 -0
  10. package/dist/definers/datasets.js.map +1 -1
  11. package/dist/definers/functions.d.ts +41 -12
  12. package/dist/definers/functions.js +57 -16
  13. package/dist/definers/functions.js.map +1 -1
  14. package/dist/definers/resources.d.ts +2 -0
  15. package/dist/definers/resources.js +2 -0
  16. package/dist/definers/resources.js.map +1 -1
  17. package/dist/definers/robots.d.ts +4 -0
  18. package/dist/definers/robots.js +4 -0
  19. package/dist/definers/robots.js.map +1 -1
  20. package/dist/definers/roles.d.ts +6 -0
  21. package/dist/definers/roles.js +6 -0
  22. package/dist/definers/roles.js.map +1 -1
  23. package/dist/definers/webhooks.d.ts +4 -0
  24. package/dist/definers/webhooks.js +4 -0
  25. package/dist/definers/webhooks.js.map +1 -1
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.js +21 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/blueprints.d.ts +16 -4
  30. package/dist/types/cors.d.ts +4 -0
  31. package/dist/types/datasets.d.ts +14 -2
  32. package/dist/types/errors.d.ts +4 -1
  33. package/dist/types/functions.d.ts +76 -16
  34. package/dist/types/functions.js +5 -1
  35. package/dist/types/functions.js.map +1 -1
  36. package/dist/types/resources.d.ts +9 -0
  37. package/dist/types/robots.d.ts +12 -3
  38. package/dist/types/roles.d.ts +11 -3
  39. package/dist/types/webhooks.d.ts +17 -5
  40. package/dist/utils/schedule-parser.d.ts +42 -0
  41. package/dist/utils/schedule-parser.js +450 -0
  42. package/dist/utils/schedule-parser.js.map +1 -0
  43. package/dist/utils/validation.d.ts +1 -0
  44. package/dist/utils/validation.js +1 -0
  45. package/dist/utils/validation.js.map +1 -1
  46. package/dist/validation/blueprints.d.ts +1 -0
  47. package/dist/validation/blueprints.js +1 -0
  48. package/dist/validation/blueprints.js.map +1 -1
  49. package/dist/validation/cors.d.ts +1 -0
  50. package/dist/validation/cors.js +1 -0
  51. package/dist/validation/cors.js.map +1 -1
  52. package/dist/validation/datasets.d.ts +2 -0
  53. package/dist/validation/datasets.js +2 -0
  54. package/dist/validation/datasets.js.map +1 -1
  55. package/dist/validation/functions.d.ts +11 -0
  56. package/dist/validation/functions.js +37 -1
  57. package/dist/validation/functions.js.map +1 -1
  58. package/dist/validation/resources.d.ts +7 -1
  59. package/dist/validation/resources.js +20 -14
  60. package/dist/validation/resources.js.map +1 -1
  61. package/dist/validation/robots.d.ts +7 -0
  62. package/dist/validation/robots.js +7 -0
  63. package/dist/validation/robots.js.map +1 -1
  64. package/dist/validation/roles.d.ts +3 -1
  65. package/dist/validation/roles.js +3 -1
  66. package/dist/validation/roles.js.map +1 -1
  67. package/dist/validation/webhooks.d.ts +1 -0
  68. package/dist/validation/webhooks.js +1 -0
  69. package/dist/validation/webhooks.js.map +1 -1
  70. package/package.json +4 -1
  71. package/src/definers/blueprints.ts +2 -0
  72. package/src/definers/cors.ts +4 -0
  73. package/src/definers/datasets.ts +5 -0
  74. package/src/definers/functions.ts +62 -18
  75. package/src/definers/resources.ts +2 -0
  76. package/src/definers/robots.ts +4 -0
  77. package/src/definers/roles.ts +6 -0
  78. package/src/definers/webhooks.ts +4 -0
  79. package/src/index.ts +22 -0
  80. package/src/types/blueprints.ts +16 -4
  81. package/src/types/cors.ts +4 -0
  82. package/src/types/datasets.ts +14 -2
  83. package/src/types/errors.ts +4 -1
  84. package/src/types/functions.ts +87 -15
  85. package/src/types/resources.ts +9 -0
  86. package/src/types/robots.ts +12 -3
  87. package/src/types/roles.ts +11 -3
  88. package/src/types/webhooks.ts +17 -5
  89. package/src/utils/schedule-parser.ts +502 -0
  90. package/src/utils/validation.ts +1 -0
  91. package/src/validation/blueprints.ts +1 -0
  92. package/src/validation/cors.ts +1 -0
  93. package/src/validation/datasets.ts +2 -0
  94. package/src/validation/functions.ts +37 -0
  95. package/src/validation/resources.ts +20 -14
  96. package/src/validation/robots.ts +7 -0
  97. package/src/validation/roles.ts +3 -1
  98. package/src/validation/webhooks.ts +1 -0
@@ -1,5 +1,8 @@
1
1
  import type { BlueprintResource } from '../index.js';
2
- /** Base event configuration shared by document and media library function types */
2
+ /**
3
+ * Base event configuration shared by document and media library function types
4
+ * @category Functions Types
5
+ */
3
6
  export interface BlueprintFunctionBaseResourceEvent {
4
7
  /** Event types that trigger the function. Defaults to ['publish'] */
5
8
  on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
@@ -10,23 +13,33 @@ export interface BlueprintFunctionBaseResourceEvent {
10
13
  /** Include draft documents in addition to published documents */
11
14
  includeDrafts?: boolean;
12
15
  }
13
- /** Event configuration for document functions */
16
+ /**
17
+ * Event configuration for document functions
18
+ * @category Functions Types
19
+ */
14
20
  export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
15
21
  /** Include all versions of documents, not just the current version */
16
22
  includeAllVersions?: boolean;
17
23
  /** Optional dataset resource scoping for the function */
18
24
  resource?: BlueprintFunctionResourceEventResourceDataset;
19
25
  }
20
- /** Event configuration for media library asset functions */
26
+ /**
27
+ * Event configuration for media library asset functions
28
+ * @category Functions Types
29
+ */
21
30
  export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
22
31
  /** Media library resource scoping (required for media library functions) */
23
32
  resource: BlueprintFunctionResourceEventResourceMediaLibrary;
24
33
  }
25
- /** Union type of all function resource event configurations */
34
+ /**
35
+ * Union type of all function resource event configurations
36
+ * @category Functions Types
37
+ */
26
38
  export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent;
27
39
  /**
28
- * Dataset resource for scoping document functions to specific datasets
29
- * @example { type: 'dataset', id: 'my-project.production' }
40
+ * Explicit resource event for schedule functions to specific minutes, hours, days of month, months, and days of week
41
+ * @example { minute: '0', hour: '9', dayOfMonth: '1', month: '1', dayOfWeek: '1' }
42
+ * @category Functions Types
30
43
  */
31
44
  export interface BlueprintScheduleFunctionExplicitResourceEvent {
32
45
  minute: string;
@@ -35,23 +48,56 @@ export interface BlueprintScheduleFunctionExplicitResourceEvent {
35
48
  month: string;
36
49
  dayOfWeek: string;
37
50
  }
51
+ /**
52
+ * Expression resource for schedule functions to specific expressions
53
+ * @example { expression: '0 9 * * *' }
54
+ * @category Functions Types
55
+ */
38
56
  export interface BlueprintScheduleFunctionExpressionResourceEvent {
39
57
  expression: string;
40
58
  }
59
+ /**
60
+ * Union type of all schedule function resource event configurations
61
+ * @category Functions Types
62
+ */
41
63
  export type BlueprintScheduleFunctionResourceEvent = BlueprintScheduleFunctionExplicitResourceEvent | BlueprintScheduleFunctionExpressionResourceEvent;
42
- interface BlueprintFunctionResourceEventResourceDataset {
64
+ /**
65
+ * Dataset resource for scoping document functions to specific datasets
66
+ * @example { type: 'dataset', id: 'my-project.production' }
67
+ * @category Resource Types
68
+ */
69
+ export interface BlueprintFunctionResourceEventResourceDataset {
43
70
  type: 'dataset';
44
- /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
71
+ /** A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
45
72
  id: string;
46
73
  }
47
- /** Media library resource for scoping media library functions */
48
- interface BlueprintFunctionResourceEventResourceMediaLibrary {
74
+ /**
75
+ * Media library resource for scoping media library functions
76
+ * @category Functions Types
77
+ */
78
+ export interface BlueprintFunctionResourceEventResourceMediaLibrary {
49
79
  type: 'media-library';
50
80
  id: string;
51
81
  }
52
- /** Events that can trigger a function */
53
- type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
54
- /** Base function resource with common properties for all function types */
82
+ /**
83
+ * Events that can trigger a function
84
+ * @category Functions Types
85
+ */
86
+ export type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
87
+ /**
88
+ * Current support Function runtimes
89
+ * @category Functions Types
90
+ */
91
+ export declare const VALID_RUNTIMES: readonly ["node", "nodejs22.x", "nodejs24.x"];
92
+ /**
93
+ * Supported function runtimes
94
+ * @category Functions Types
95
+ */
96
+ export type FunctionRuntimes = (typeof VALID_RUNTIMES)[number];
97
+ /**
98
+ * Base function resource with common properties for all function types
99
+ * @category Functions Types
100
+ */
55
101
  export interface BlueprintBaseFunctionResource extends BlueprintResource {
56
102
  /** Human-readable display name for the function */
57
103
  displayName?: string;
@@ -70,22 +116,36 @@ export interface BlueprintBaseFunctionResource extends BlueprintResource {
70
116
  *
71
117
  * The `project` attribute must be defined if your blueprint is scoped to an organization. */
72
118
  project?: string;
119
+ /**
120
+ * The runtime environment for the function (currently only Node.js is supported)
121
+ * @default 'nodejs24.x'
122
+ */
123
+ runtime?: FunctionRuntimes;
73
124
  }
74
- /** A function resource triggered by document events in Sanity datasets */
125
+ /**
126
+ * A function resource triggered by document events in Sanity datasets
127
+ * @category Functions Types
128
+ */
75
129
  export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
76
130
  type: 'sanity.function.document';
77
131
  /** Event configuration specifying when and how the function is triggered */
78
132
  event: BlueprintDocumentFunctionResourceEvent;
79
133
  }
80
- /** A function resource triggered by media library asset events */
134
+ /**
135
+ * A function resource triggered by media library asset events
136
+ * @category Functions Types
137
+ */
81
138
  export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
82
139
  type: 'sanity.function.media-library.asset';
83
140
  /** Event configuration specifying when and how the function is triggered */
84
141
  event: BlueprintMediaLibraryFunctionResourceEvent;
85
142
  }
143
+ /**
144
+ * A function resource triggered by schedule events
145
+ * @category Functions Types
146
+ */
86
147
  export interface BlueprintScheduleFunctionResource extends BlueprintBaseFunctionResource {
87
148
  type: 'sanity.function.cron';
88
149
  event: BlueprintScheduleFunctionResourceEvent;
89
150
  timezone?: string;
90
151
  }
91
- export {};
@@ -1,2 +1,6 @@
1
- export {};
1
+ /**
2
+ * Current support Function runtimes
3
+ * @category Functions Types
4
+ */
5
+ export const VALID_RUNTIMES = ['node', 'nodejs22.x', 'nodejs24.x'];
2
6
  //# sourceMappingURL=functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":"AAqGA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAU,CAAA"}
@@ -5,10 +5,12 @@
5
5
  * - **replace** if a stack is deployed, the resource will be destroyed and created instead of performing an update. If the resource is removed from the blueprint, it will be destroyed. If the stack is destroyed, the resource will be destroyed.
6
6
  * - **allow** if a stack is destroyed, the resource will be destroyed along with it. If the resource is removed it will be destroyed
7
7
  * - **protect** if a stack is deployed the resource will not be updated. If the resource is removed from the blueprint or the stack is destroyed, deployment will fail.
8
+ * @category Blueprint Internals
8
9
  */
9
10
  export type BlueprintResourceDeletionPolicy = 'allow' | 'retain' | 'replace' | 'protect';
10
11
  /**
11
12
  * An ownership action that will cause the referenced resource to be attached to the current stack.
13
+ * @category Blueprint Internals
12
14
  */
13
15
  export interface BlueprintOwnershipAttachAction {
14
16
  type: 'attach';
@@ -17,16 +19,19 @@ export interface BlueprintOwnershipAttachAction {
17
19
  }
18
20
  /**
19
21
  * An ownership action that will cause the referenced resource to be detached from the current stack.
22
+ * @category Blueprint Internals
20
23
  */
21
24
  export interface BlueprintOwnershipDetachAction {
22
25
  type: 'detach';
23
26
  }
24
27
  /**
25
28
  * A union of all possible ownership actions.
29
+ * @category Blueprint Internals
26
30
  */
27
31
  export type BlueprintOwnershipAction = BlueprintOwnershipAttachAction | BlueprintOwnershipDetachAction;
28
32
  /**
29
33
  * An ownership action that will cause the referenced project-contained resource to be attached to the current stack.
34
+ * @category Blueprint Internals
30
35
  */
31
36
  export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershipAttachAction {
32
37
  /** The identifier of the project for resources contained in a project */
@@ -34,10 +39,12 @@ export interface BlueprintProjectOwnershipAttachAction extends BlueprintOwnershi
34
39
  }
35
40
  /**
36
41
  * A union of all possible ownership actions for resources belonging to projects.
42
+ * @category Blueprint Internals
37
43
  */
38
44
  export type BlueprintProjectOwnershipAction = BlueprintProjectOwnershipAttachAction;
39
45
  /**
40
46
  * Defines the lifcycle policy for this resource.
47
+ * @category Blueprint Internals
41
48
  */
42
49
  export interface BlueprintResourceLifecycle {
43
50
  deletionPolicy?: BlueprintResourceDeletionPolicy;
@@ -45,12 +52,14 @@ export interface BlueprintResourceLifecycle {
45
52
  }
46
53
  /**
47
54
  * Defines the lifcycle policy for this resource.
55
+ * @category Blueprint Internals
48
56
  */
49
57
  export interface BlueprintProjectResourceLifecycle extends BlueprintResourceLifecycle {
50
58
  ownershipAction?: BlueprintProjectOwnershipAction;
51
59
  }
52
60
  /**
53
61
  * The base type for all resources.
62
+ * @category Blueprint Internals
54
63
  */
55
64
  export interface BlueprintResource<Lifecycle extends BlueprintResourceLifecycle = BlueprintResourceLifecycle> {
56
65
  type: string;
@@ -1,8 +1,13 @@
1
- import type { BlueprintResource } from './resources';
2
- /** Resource types that robots can be attached to. */
1
+ import type { BlueprintProjectResourceLifecycle, BlueprintResource } from './resources';
2
+ /**
3
+ * Resource types that robots can be attached to.
4
+ * @internal
5
+ */
3
6
  export type RobotResourceType = 'organization' | 'project';
4
7
  /**
5
8
  * Defines the robot's roles within a given resource.
9
+ * @beta This feature is subject to breaking changes.
10
+ * @category Resource Types
6
11
  */
7
12
  export interface RobotMembership {
8
13
  resourceType: RobotResourceType;
@@ -12,8 +17,10 @@ export interface RobotMembership {
12
17
  /**
13
18
  * A robot that provides a token for automated access.
14
19
  * @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
20
+ * @beta This feature is subject to breaking changes.
21
+ * @category Resource Types
15
22
  */
16
- export interface BlueprintRobotResource extends BlueprintResource {
23
+ export interface BlueprintRobotResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
17
24
  type: 'sanity.access.robot';
18
25
  /** A descriptive label for the robot and its use case */
19
26
  label: string;
@@ -24,6 +31,8 @@ export interface BlueprintRobotResource extends BlueprintResource {
24
31
  /**
25
32
  * Configuration for a robot that provides a token for automated access.
26
33
  * @see https://www.sanity.io/docs/content-lake/http-auth#k4c21d7b829fe
34
+ * @beta This feature is subject to breaking changes.
35
+ * @category Resource Types
27
36
  */
28
37
  export type BlueprintRobotConfig = Omit<BlueprintRobotResource, 'type' | 'label' | 'token'> & {
29
38
  label?: string;
@@ -1,6 +1,8 @@
1
- import type { BlueprintResource } from '../index.js';
1
+ import type { BlueprintProjectResourceLifecycle, BlueprintResource } from '../index.js';
2
2
  /**
3
3
  * A permission definition for a role.
4
+ * @beta This feature is subject to breaking changes.
5
+ * @category Resource Types
4
6
  */
5
7
  export interface RolePermission {
6
8
  /** Predefined permission name (e.g., 'sanity-all-documents') */
@@ -12,8 +14,10 @@ export interface RolePermission {
12
14
  }
13
15
  /**
14
16
  * Configuration for a custom role.
17
+ * @beta This feature is subject to breaking changes.
18
+ * @category Resource Types
15
19
  */
16
- export interface BlueprintRoleConfig extends Omit<BlueprintResource, 'type'> {
20
+ export interface BlueprintRoleConfig extends Omit<BlueprintResource<BlueprintProjectResourceLifecycle>, 'type'> {
17
21
  title: string;
18
22
  description?: string;
19
23
  appliesToUsers: boolean;
@@ -22,12 +26,16 @@ export interface BlueprintRoleConfig extends Omit<BlueprintResource, 'type'> {
22
26
  }
23
27
  /**
24
28
  * A custom role resource
29
+ * @beta This feature is subject to breaking changes.
30
+ * @category Resource Types
25
31
  */
26
- export interface BlueprintRoleResource extends BlueprintRoleConfig, BlueprintResource {
32
+ export interface BlueprintRoleResource extends BlueprintRoleConfig, BlueprintResource<BlueprintProjectResourceLifecycle> {
27
33
  type: 'sanity.access.role';
28
34
  }
29
35
  /**
30
36
  * A custom role resource that is tied to a specific project
37
+ * @beta This feature is subject to breaking changes.
38
+ * @category Resource Types
31
39
  */
32
40
  export interface BlueprintProjectRoleResource extends BlueprintRoleResource {
33
41
  resourceType: 'project';
@@ -1,8 +1,16 @@
1
- import type { BlueprintResource } from '../index.js';
2
- /** Types of events that can trigger a webhook */
1
+ import type { BlueprintProjectResourceLifecycle, BlueprintResource } from '../index.js';
2
+ /**
3
+ * Types of events that can trigger a webhook
4
+ * @beta This feature is subject to breaking changes.
5
+ * @category Resource Types
6
+ */
3
7
  export type WebhookTrigger = 'create' | 'update' | 'delete';
4
- /** A webhook resource definition */
5
- export interface BlueprintDocumentWebhookResource extends BlueprintResource {
8
+ /**
9
+ * A webhook resource definition
10
+ * @beta This feature is subject to breaking changes.
11
+ * @category Resource Types
12
+ */
13
+ export interface BlueprintDocumentWebhookResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
6
14
  type: 'sanity.project.webhook';
7
15
  project?: string;
8
16
  displayName?: string;
@@ -20,5 +28,9 @@ export interface BlueprintDocumentWebhookResource extends BlueprintResource {
20
28
  dataset: string;
21
29
  apiVersion: string;
22
30
  }
23
- /** Configuration for a webhook */
31
+ /**
32
+ * Configuration for a webhook
33
+ * @beta This feature is subject to breaking changes.
34
+ * @category Resource Types
35
+ */
24
36
  export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>;
@@ -0,0 +1,42 @@
1
+ import type { BlueprintError } from '../types/errors.js';
2
+ /**
3
+ * Validates a schedule expression and returns any errors found.
4
+ *
5
+ * Checks for:
6
+ * - Empty expressions
7
+ * - Invalid time formats (hours, minutes out of range)
8
+ * - Invalid intervals (minutes, hours out of range)
9
+ * - Invalid day of month values
10
+ * - Unrecognizable expressions
11
+ *
12
+ * @param expression Natural language schedule or cron expression
13
+ * @returns Array of validation errors, empty if valid
14
+ * @internal
15
+ */
16
+ export declare function validateScheduleExpression(expression: string): BlueprintError[];
17
+ /**
18
+ * Parse a natural language schedule expression into a cron expression.
19
+ *
20
+ * The parser is **forgiving** and **freeform** - it extracts recognized parts
21
+ * (days, times, intervals) and ignores unrecognized tokens like "at", "on", "the".
22
+ *
23
+ * Supported patterns:
24
+ * - "every minute", "every 5 minutes", "every hour", "every 2 hours"
25
+ * - "every day at 9am", "daily 14:30", "9am daily"
26
+ * - "at midnight", "noon"
27
+ * - "morning", "evening"
28
+ * - "mondays 9am", "mon wed fri 9:00", "mon-fri 8am"
29
+ * - "9pm fridays and wed", "wednesday friday 9pm"
30
+ * - "weekdays 9am", "weekends 10am"
31
+ * - "first of the month 9am", "15th noon"
32
+ *
33
+ * If the input is already a valid cron expression, it is returned unchanged.
34
+ *
35
+ * This function assumes the expression has already been validated via
36
+ * `validateScheduleExpression`. For invalid input, behavior is undefined.
37
+ *
38
+ * @param expression Natural language schedule or cron expression
39
+ * @returns Cron expression string
40
+ * @internal
41
+ */
42
+ export declare function parseScheduleExpression(expression: string): string;