@sanity/blueprints 0.6.0 → 0.7.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 (99) hide show
  1. package/dist/definers/blueprints.d.ts +1 -22
  2. package/dist/definers/blueprints.js +3 -2
  3. package/dist/definers/blueprints.js.map +1 -1
  4. package/dist/definers/cors.d.ts +1 -15
  5. package/dist/definers/cors.js +5 -12
  6. package/dist/definers/cors.js.map +1 -1
  7. package/dist/definers/datasets.d.ts +1 -15
  8. package/dist/definers/datasets.js +5 -19
  9. package/dist/definers/datasets.js.map +1 -1
  10. package/dist/definers/functions.d.ts +4 -41
  11. package/dist/definers/functions.js +25 -32
  12. package/dist/definers/functions.js.map +1 -1
  13. package/dist/definers/resources.d.ts +1 -1
  14. package/dist/definers/resources.js +4 -8
  15. package/dist/definers/resources.js.map +1 -1
  16. package/dist/definers/roles.d.ts +4 -22
  17. package/dist/definers/roles.js +11 -21
  18. package/dist/definers/roles.js.map +1 -1
  19. package/dist/definers/webhooks.d.ts +1 -21
  20. package/dist/definers/webhooks.js +8 -64
  21. package/dist/definers/webhooks.js.map +1 -1
  22. package/dist/index.d.ts +15 -1
  23. package/dist/index.js +18 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/types/blueprints.d.ts +22 -0
  26. package/dist/types/blueprints.js +2 -0
  27. package/dist/types/blueprints.js.map +1 -0
  28. package/dist/types/cors.d.ts +15 -0
  29. package/dist/types/cors.js +2 -0
  30. package/dist/types/cors.js.map +1 -0
  31. package/dist/types/datasets.d.ts +15 -0
  32. package/dist/types/datasets.js +2 -0
  33. package/dist/types/datasets.js.map +1 -0
  34. package/dist/types/errors.d.ts +5 -0
  35. package/dist/types/errors.js +2 -0
  36. package/dist/types/errors.js.map +1 -0
  37. package/dist/types/functions.d.ts +41 -0
  38. package/dist/types/functions.js +2 -0
  39. package/dist/types/functions.js.map +1 -0
  40. package/dist/types/resources.js +2 -0
  41. package/dist/types/resources.js.map +1 -0
  42. package/dist/types/roles.d.ts +21 -0
  43. package/dist/types/roles.js +2 -0
  44. package/dist/types/roles.js.map +1 -0
  45. package/dist/types/webhooks.d.ts +21 -0
  46. package/dist/types/webhooks.js +2 -0
  47. package/dist/types/webhooks.js.map +1 -0
  48. package/dist/utils/validation.d.ts +2 -0
  49. package/dist/utils/validation.js +8 -0
  50. package/dist/utils/validation.js.map +1 -0
  51. package/dist/validation/blueprints.d.ts +2 -0
  52. package/dist/validation/blueprints.js +14 -0
  53. package/dist/validation/blueprints.js.map +1 -0
  54. package/dist/validation/cors.d.ts +2 -0
  55. package/dist/validation/cors.js +32 -0
  56. package/dist/validation/cors.js.map +1 -0
  57. package/dist/validation/datasets.d.ts +2 -0
  58. package/dist/validation/datasets.js +39 -0
  59. package/dist/validation/datasets.js.map +1 -0
  60. package/dist/validation/functions.d.ts +4 -0
  61. package/dist/validation/functions.js +125 -0
  62. package/dist/validation/functions.js.map +1 -0
  63. package/dist/validation/resources.d.ts +3 -0
  64. package/dist/validation/resources.js +25 -0
  65. package/dist/validation/resources.js.map +1 -0
  66. package/dist/validation/roles.d.ts +8 -0
  67. package/dist/validation/roles.js +57 -0
  68. package/dist/validation/roles.js.map +1 -0
  69. package/dist/validation/webhooks.d.ts +2 -0
  70. package/dist/validation/webhooks.js +110 -0
  71. package/dist/validation/webhooks.js.map +1 -0
  72. package/package.json +1 -1
  73. package/src/definers/blueprints.ts +3 -27
  74. package/src/definers/cors.ts +7 -34
  75. package/src/definers/datasets.ts +7 -42
  76. package/src/definers/functions.ts +62 -88
  77. package/src/definers/resources.ts +6 -8
  78. package/src/definers/roles.ts +20 -50
  79. package/src/definers/webhooks.ts +10 -95
  80. package/src/index.ts +20 -1
  81. package/src/types/blueprints.ts +26 -0
  82. package/src/types/cors.ts +18 -0
  83. package/src/types/datasets.ts +19 -0
  84. package/src/types/errors.ts +5 -0
  85. package/src/types/functions.ts +48 -0
  86. package/src/types/roles.ts +25 -0
  87. package/src/types/webhooks.ts +22 -0
  88. package/src/utils/validation.ts +9 -0
  89. package/src/validation/blueprints.ts +16 -0
  90. package/src/validation/cors.ts +34 -0
  91. package/src/validation/datasets.ts +41 -0
  92. package/src/validation/functions.ts +144 -0
  93. package/src/validation/resources.ts +27 -0
  94. package/src/validation/roles.ts +60 -0
  95. package/src/validation/webhooks.ts +109 -0
  96. package/dist/types.js +0 -2
  97. package/dist/types.js.map +0 -1
  98. /package/dist/{types.d.ts → types/resources.d.ts} +0 -0
  99. /package/src/{types.ts → types/resources.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './types.js';
1
+ // DEFINERS - helper functions to create resources
2
2
  export * from './definers/blueprints.js';
3
3
  export * from './definers/cors.js';
4
4
  export * from './definers/datasets.js';
@@ -6,4 +6,21 @@ export * from './definers/functions.js';
6
6
  export * from './definers/resources.js';
7
7
  export * from './definers/roles.js';
8
8
  export * from './definers/webhooks.js';
9
+ // TYPES - base types for all resources
10
+ export * from './types/blueprints.js';
11
+ export * from './types/cors.js';
12
+ export * from './types/datasets.js';
13
+ export * from './types/errors.js';
14
+ export * from './types/functions.js';
15
+ export * from './types/resources.js';
16
+ export * from './types/roles.js';
17
+ export * from './types/webhooks.js';
18
+ // VALIDATION - validation for all resources
19
+ export * from './validation/blueprints.js';
20
+ export * from './validation/cors.js';
21
+ export * from './validation/datasets.js';
22
+ export * from './validation/functions.js';
23
+ export * from './validation/resources.js';
24
+ export * from './validation/roles.js';
25
+ export * from './validation/webhooks.js';
9
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AAEtC,uCAAuC;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AAEnC,4CAA4C;AAC5C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ export interface BlueprintsApiConfig {
3
+ organizationId: string;
4
+ projectId: string;
5
+ stackId: string;
6
+ }
7
+ export interface BlueprintOutput {
8
+ name: string;
9
+ value: string;
10
+ }
11
+ export interface Blueprint {
12
+ $schema: string;
13
+ blueprintVersion: string;
14
+ resources?: BlueprintResource[];
15
+ values?: Record<string, unknown>;
16
+ outputs?: BlueprintOutput[];
17
+ }
18
+ export type BlueprintModule = ((args?: unknown) => Blueprint) & {
19
+ organizationId?: string;
20
+ projectId?: string;
21
+ stackId?: string;
22
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=blueprints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/types/blueprints.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ /**
3
+ * Represents a CORS Origin resource.
4
+ */
5
+ export interface BlueprintCorsOriginResource extends BlueprintResource {
6
+ type: 'sanity.project.cors';
7
+ origin: string;
8
+ allowCredentials?: boolean;
9
+ /** The `project` attribute must be defined if your blueprint is scoped to an organization. */
10
+ project?: string;
11
+ }
12
+ /** Configuration for a CORS Origin resource. */
13
+ export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
14
+ allowCredentials?: boolean;
15
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/types/cors.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ export type AclMode = 'public' | 'private' | 'custom';
3
+ /** Represents a Dataset resource. */
4
+ export interface BlueprintDatasetResource extends BlueprintResource {
5
+ type: 'sanity.project.dataset';
6
+ datasetName: string;
7
+ aclMode?: AclMode;
8
+ /** The `project` attribute must be defined if your blueprint is scoped to an organization. */
9
+ project?: string;
10
+ }
11
+ /** Configuration for a Dataset resource. */
12
+ export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
13
+ /** The name of the dataset, defaults to the name of the resource. */
14
+ datasetName?: string;
15
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=datasets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/types/datasets.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /** Standard error shape returned by validation functions */
2
+ export interface BlueprintError {
3
+ message: string;
4
+ type: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ export interface BlueprintFunctionBaseResourceEvent {
3
+ on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
4
+ filter?: string;
5
+ projection?: `{${string}}`;
6
+ includeDrafts?: boolean;
7
+ }
8
+ export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
9
+ includeAllVersions?: boolean;
10
+ resource?: BlueprintFunctionResourceEventResourceDataset;
11
+ }
12
+ export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
13
+ resource: BlueprintFunctionResourceEventResourceMediaLibrary;
14
+ }
15
+ export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent;
16
+ interface BlueprintFunctionResourceEventResourceDataset {
17
+ type: 'dataset';
18
+ /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
19
+ id: string;
20
+ }
21
+ interface BlueprintFunctionResourceEventResourceMediaLibrary {
22
+ type: 'media-library';
23
+ id: string;
24
+ }
25
+ type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
26
+ export interface BlueprintBaseFunctionResource extends BlueprintResource {
27
+ displayName?: string;
28
+ src: string;
29
+ timeout?: number;
30
+ memory?: number;
31
+ env?: Record<string, string>;
32
+ }
33
+ export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
34
+ type: 'sanity.function.document';
35
+ event: BlueprintDocumentFunctionResourceEvent;
36
+ }
37
+ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
38
+ type: 'sanity.function.media-library.asset';
39
+ event: BlueprintMediaLibraryFunctionResourceEvent;
40
+ }
41
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/types/resources.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ export interface RolePermission {
3
+ name: string;
4
+ action: string;
5
+ params?: Record<string, unknown>;
6
+ }
7
+ export interface BlueprintRoleConfig {
8
+ name: string;
9
+ title: string;
10
+ description?: string;
11
+ appliesToUsers: boolean;
12
+ appliesToRobots: boolean;
13
+ permissions: RolePermission[];
14
+ }
15
+ export interface BlueprintRoleResource extends BlueprintRoleConfig, BlueprintResource {
16
+ type: 'sanity.access.role';
17
+ }
18
+ export interface BlueprintProjectRoleResource extends BlueprintRoleResource {
19
+ resourceType: 'project';
20
+ resourceId: string;
21
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/types/roles.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { BlueprintResource } from '../index.js';
2
+ export type WebhookTrigger = 'create' | 'update' | 'delete';
3
+ export interface BlueprintDocumentWebhookResource extends BlueprintResource {
4
+ type: 'sanity.project.webhook';
5
+ project?: string;
6
+ displayName?: string;
7
+ description?: string | null;
8
+ url: string;
9
+ on: WebhookTrigger[];
10
+ filter?: string;
11
+ projection?: string;
12
+ status?: 'enabled' | 'disabled';
13
+ httpMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
14
+ headers?: Record<string, string>;
15
+ includeDrafts?: boolean;
16
+ includeAllVersions?: boolean;
17
+ secret?: string;
18
+ dataset?: string;
19
+ apiVersion?: string;
20
+ }
21
+ export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/types/webhooks.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import type { BlueprintError } from '../types/errors';
2
+ export declare function runValidation(validator: () => BlueprintError[]): void;
@@ -0,0 +1,8 @@
1
+ export function runValidation(validator) {
2
+ const errors = validator();
3
+ if (errors.length > 0) {
4
+ const message = errors.map((err) => err.message).join('\n');
5
+ throw new Error(message);
6
+ }
7
+ }
8
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,SAAiC;IAC7D,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC3D,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { BlueprintError } from '../index.js';
2
+ export declare function validateBlueprint(blueprintConfig: unknown): BlueprintError[];
@@ -0,0 +1,14 @@
1
+ export function validateBlueprint(blueprintConfig) {
2
+ if (!blueprintConfig)
3
+ return [{ type: 'invalid_value', message: 'blueprint config must be provided' }];
4
+ if (typeof blueprintConfig !== 'object')
5
+ return [{ type: 'invalid_type', message: 'blueprint config must be an object' }];
6
+ const errors = [];
7
+ if ('resources' in blueprintConfig) {
8
+ const { resources } = blueprintConfig;
9
+ if (resources && !Array.isArray(resources))
10
+ errors.push({ type: 'invalid_format', message: '`resources` must be an array' });
11
+ }
12
+ return errors;
13
+ }
14
+ //# sourceMappingURL=blueprints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/validation/blueprints.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,eAAwB;IACxD,IAAI,CAAC,eAAe;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IACpG,IAAI,OAAO,eAAe,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,oCAAoC,EAAC,CAAC,CAAA;IAEvH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IAAI,WAAW,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,EAAC,SAAS,EAAC,GAAG,eAAe,CAAA;QAEnC,IAAI,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,8BAA8B,EAAC,CAAC,CAAA;IAC5H,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { BlueprintError } from '../index.js';
2
+ export declare function validateCorsOrigin(resource: unknown): BlueprintError[];
@@ -0,0 +1,32 @@
1
+ export function validateCorsOrigin(resource) {
2
+ if (!resource)
3
+ return [{ type: 'invalid_value', message: 'CORS Origin config must be provided' }];
4
+ if (typeof resource !== 'object')
5
+ return [{ type: 'invalid_type', message: 'CORS Origin config must be an object' }];
6
+ const errors = [];
7
+ if (!('name' in resource) || !resource.name) {
8
+ errors.push({ type: 'missing_parameter', message: 'CORS Origin name is required' });
9
+ }
10
+ else if (typeof resource.name !== 'string') {
11
+ errors.push({ type: 'invalid_type', message: 'CORS Origin name must be a string' });
12
+ }
13
+ if (!('type' in resource)) {
14
+ errors.push({ type: 'missing_parameter', message: 'CORS Origin type is required' });
15
+ }
16
+ else if (resource.type !== 'sanity.project.cors') {
17
+ errors.push({ type: 'invalid_value', message: 'CORS Origin type must be `sanity.project.cors`' });
18
+ }
19
+ if (!('origin' in resource) || !resource.origin) {
20
+ errors.push({ type: 'missing_parameter', message: 'CORS Origin URL is required' });
21
+ }
22
+ else if (typeof resource.origin !== 'string') {
23
+ errors.push({ type: 'invalid_type', message: 'CORS Origin URL must be a string' });
24
+ }
25
+ if ('project' in resource) {
26
+ if (typeof resource.project !== 'string') {
27
+ errors.push({ type: 'invalid_type', message: 'CORS Origin project must be a string' });
28
+ }
29
+ }
30
+ return errors;
31
+ }
32
+ //# sourceMappingURL=cors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/validation/cors.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,QAAiB;IAClD,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,qCAAqC,EAAC,CAAC,CAAA;IAC/F,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,sCAAsC,EAAC,CAAC,CAAA;IAElH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,8BAA8B,EAAC,CAAC,CAAA;IACnF,CAAC;SAAM,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IACnF,CAAC;IAED,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,8BAA8B,EAAC,CAAC,CAAA;IACnF,CAAC;SAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,gDAAgD,EAAC,CAAC,CAAA;IACjG,CAAC;IAED,IAAI,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,6BAA6B,EAAC,CAAC,CAAA;IAClF,CAAC;SAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IAClF,CAAC;IAED,IAAI,SAAS,IAAI,QAAQ,EAAE,CAAC;QAC1B,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,sCAAsC,EAAC,CAAC,CAAA;QACtF,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { BlueprintError } from '../index.js';
2
+ export declare function validateDataset(resource: unknown): BlueprintError[];
@@ -0,0 +1,39 @@
1
+ export function validateDataset(resource) {
2
+ if (!resource)
3
+ return [{ type: 'invalid_value', message: 'Dataset config must be provided' }];
4
+ if (typeof resource !== 'object')
5
+ return [{ type: 'invalid_type', message: 'Dataset config must be an object' }];
6
+ const errors = [];
7
+ if (!('name' in resource) || !resource.name) {
8
+ errors.push({ type: 'missing_parameter', message: 'Dataset name is required' });
9
+ }
10
+ else if (typeof resource.name !== 'string') {
11
+ errors.push({ type: 'invalid_type', message: 'Dataset name must be a string' });
12
+ }
13
+ if (!('type' in resource)) {
14
+ errors.push({ type: 'missing_parameter', message: 'Dataset type is required' });
15
+ }
16
+ else if (resource.type !== 'sanity.project.dataset') {
17
+ errors.push({ type: 'invalid_value', message: 'Dataset type must be `sanity.project.dataset`' });
18
+ }
19
+ // validate ACL mode if provided
20
+ if ('aclMode' in resource) {
21
+ if (typeof resource.aclMode !== 'string') {
22
+ errors.push({ type: 'invalid_type', message: 'Dataset aclMode must be one of `custom`, `public`, or `private`' });
23
+ }
24
+ else {
25
+ const aclMode = resource.aclMode;
26
+ if (aclMode !== 'custom' && aclMode !== 'public' && aclMode !== 'private') {
27
+ errors.push({ type: 'invalid_value', message: 'Dataset aclMode must be one of `custom`, `public`, or `private`' });
28
+ }
29
+ }
30
+ }
31
+ // validate project if provided
32
+ if ('project' in resource) {
33
+ if (typeof resource.project !== 'string') {
34
+ errors.push({ type: 'invalid_type', message: 'Dataset project must be a string' });
35
+ }
36
+ }
37
+ return errors;
38
+ }
39
+ //# sourceMappingURL=datasets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/validation/datasets.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,QAAiB;IAC/C,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,iCAAiC,EAAC,CAAC,CAAA;IAC3F,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IAE9G,MAAM,MAAM,GAAqB,EAAE,CA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H,CAAC;IACH,CAAC;IAED,+BAA+B;IAC/B,IAAI,SAAS,IAAI,QAAQ,EAAE,CAAC;QAC1B,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;QAClF,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { BlueprintError } from '../index.js';
2
+ export declare function validateDocumentFunction(functionResource: unknown): BlueprintError[];
3
+ export declare function validateMediaLibraryAssetFunction(functionResource: unknown): BlueprintError[];
4
+ export declare function validateFunction(functionResource: unknown): BlueprintError[];
@@ -0,0 +1,125 @@
1
+ const BASE_EVENT_KEYS = new Set(['on', 'filter', 'projection', 'includeDrafts']);
2
+ const DOCUMENT_EVENT_KEYS = new Set(['includeAllVersions', 'resource', ...BASE_EVENT_KEYS.values()]);
3
+ const MEDIA_LIBRARY_EVENT_KEYS = new Set(['resource', ...BASE_EVENT_KEYS.values()]);
4
+ export function validateDocumentFunction(functionResource) {
5
+ if (!functionResource)
6
+ return [{ type: 'invalid_value', message: 'Function config must be provided' }];
7
+ if (typeof functionResource !== 'object')
8
+ return [{ type: 'invalid_type', message: 'Function config must be an object' }];
9
+ const errors = [];
10
+ // event validation
11
+ if ('event' in functionResource) {
12
+ // `event` was specified, but event keys (aggregated in `maybeEvent`) were also specified at the top level. ambiguous and deprecated usage.
13
+ const duplicateKeys = Array.from(DOCUMENT_EVENT_KEYS).filter((key) => key in functionResource);
14
+ if (duplicateKeys.length > 0) {
15
+ errors.push({
16
+ type: 'invalid_property',
17
+ message: `\`event\` properties should be specified under the \`event\` key - specifying them at the top level is deprecated. The following keys were specified at the top level: ${duplicateKeys.map((k) => `\`${k}\``).join(', ')}`,
18
+ });
19
+ }
20
+ else {
21
+ errors.push(...validateDocumentFunctionEvent(functionResource.event));
22
+ }
23
+ }
24
+ else {
25
+ errors.push(...validateDocumentFunctionEvent(functionResource));
26
+ }
27
+ if ('type' in functionResource && functionResource.type !== 'sanity.function.document') {
28
+ errors.push({ type: 'invalid_value', message: '`type` must be `sanity.function.document`' });
29
+ }
30
+ errors.push(...validateFunction(functionResource));
31
+ return errors;
32
+ }
33
+ export function validateMediaLibraryAssetFunction(functionResource) {
34
+ if (!functionResource)
35
+ return [{ type: 'invalid_value', message: 'Function config must be provided' }];
36
+ if (typeof functionResource !== 'object')
37
+ return [{ type: 'invalid_type', message: 'Function config must be an object' }];
38
+ const errors = [];
39
+ if ('event' in functionResource) {
40
+ errors.push(...validateMediaLibraryFunctionEvent(functionResource.event));
41
+ }
42
+ else {
43
+ errors.push({ type: 'missing_parameter', message: '`event` is required for a media library function' });
44
+ }
45
+ if ('type' in functionResource && functionResource.type !== 'sanity.function.media-library.asset') {
46
+ errors.push({ type: 'invalid_value', message: '`type` must be `sanity.function.media-library.asset`' });
47
+ }
48
+ errors.push(...validateFunction(functionResource));
49
+ return errors;
50
+ }
51
+ export function validateFunction(functionResource) {
52
+ if (!functionResource)
53
+ return [{ type: 'invalid_value', message: 'Function config must be provided' }];
54
+ if (typeof functionResource !== 'object')
55
+ return [{ type: 'invalid_type', message: 'Function config must be an object' }];
56
+ const errors = [];
57
+ if (!('name' in functionResource)) {
58
+ errors.push({ type: 'missing_parameter', message: '`name` is required' });
59
+ }
60
+ else if (typeof functionResource.name !== 'string') {
61
+ errors.push({ type: 'invalid_type', message: '`name` must be a string' });
62
+ }
63
+ if (!('type' in functionResource)) {
64
+ errors.push({ type: 'missing_parameter', message: '`type` is required' });
65
+ }
66
+ else if (typeof functionResource.type !== 'string') {
67
+ errors.push({ type: 'invalid_type', message: '`type` must be a string' });
68
+ }
69
+ // type validation
70
+ if ('memory' in functionResource) {
71
+ if (typeof functionResource.memory !== 'number' && typeof functionResource.memory !== 'undefined') {
72
+ errors.push({ type: 'invalid_type', message: '`memory` must be a number' });
73
+ }
74
+ }
75
+ if ('timeout' in functionResource) {
76
+ if (typeof functionResource.timeout !== 'number' && typeof functionResource.timeout !== 'undefined') {
77
+ errors.push({ type: 'invalid_type', message: '`timeout` must be a number' });
78
+ }
79
+ }
80
+ return errors;
81
+ }
82
+ function validateDocumentFunctionEvent(event) {
83
+ if (!event)
84
+ return [{ type: 'invalid_value', message: 'Function event must be provided' }];
85
+ if (typeof event !== 'object')
86
+ return [{ type: 'invalid_type', message: 'Function event must be an object' }];
87
+ const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => DOCUMENT_EVENT_KEYS.has(key)));
88
+ const errors = [];
89
+ const fullEvent = {
90
+ on: cleanEvent.on || ['publish'],
91
+ ...cleanEvent,
92
+ };
93
+ if (!Array.isArray(fullEvent.on))
94
+ errors.push({ type: 'invalid_type', message: '`event.on` must be an array' });
95
+ if (fullEvent.resource) {
96
+ if (!fullEvent.resource.type || fullEvent.resource.type !== 'dataset')
97
+ errors.push({ type: 'invalid_value', message: '`event.resource.type` must be "dataset"' });
98
+ if (!fullEvent.resource.id || fullEvent.resource.id.split('.').length !== 2)
99
+ errors.push({ type: 'invalid_format', message: '`event.resource.id` must be in the format <projectId>.<datasetName>' });
100
+ }
101
+ return errors;
102
+ }
103
+ function validateMediaLibraryFunctionEvent(event) {
104
+ if (!event)
105
+ return [{ type: 'invalid_value', message: 'Function event must be provided' }];
106
+ if (typeof event !== 'object')
107
+ return [{ type: 'invalid_type', message: 'Function event must be an object' }];
108
+ const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => MEDIA_LIBRARY_EVENT_KEYS.has(key)));
109
+ const errors = [];
110
+ const fullEvent = {
111
+ on: cleanEvent.on || ['publish'],
112
+ ...cleanEvent,
113
+ };
114
+ if (!Array.isArray(fullEvent.on))
115
+ errors.push({ type: 'invalid_type', message: '`event.on` must be an array' });
116
+ if (fullEvent.resource) {
117
+ if (!fullEvent.resource.type || fullEvent.resource.type !== 'media-library')
118
+ errors.push({ type: 'invalid_value', message: '`event.resource.type` must be "media-library"' });
119
+ }
120
+ else {
121
+ errors.push({ type: 'missing_parameter', message: '`resource` is required for a media library function' });
122
+ }
123
+ return errors;
124
+ }
125
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/validation/functions.ts"],"names":[],"mappings":"AAQA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;AAEtG,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B,CAAC,oBAAoB,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAE9H,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAA+B,CAAC,UAAU,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;AAEjH,MAAM,UAAU,wBAAwB,CAAC,gBAAyB;IAChE,IAAI,CAAC,gBAAgB;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IACpG,IAAI,OAAO,gBAAgB,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IAEvH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,mBAAmB;IACnB,IAAI,OAAO,IAAI,gBAAgB,EAAE,CAAC;QAChC,2IAA2I;QAC3I,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,gBAAgB,CAAC,CAAA;QAC9F,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,kBAAkB;gB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AE,CAAC,wBAAwB,CAAC,GAAG,CAAC,GAAmC,CAAC,CAAC,CAC7D,CAAA;IAC/C,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,MAAM,SAAS,GAAG;QAChB,EAAE,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC;QAChC,GAAG,UAAU;KACd,CAAA;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,6BAA6B,EAAC,CAAC,CAAA;IAC7G,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,eAAe;YACzE,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,+CAA+C,EAAC,CAAC,CAAA;IAClG,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,qDAAqD,EAAC,CAAC,CAAA;IAC1G,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { BlueprintError, BlueprintResource } from '../index.js';
2
+ export declare function validateResource(resourceConfig: unknown): BlueprintError[];
3
+ export declare function assertResource(resource: unknown): asserts resource is BlueprintResource;
@@ -0,0 +1,25 @@
1
+ import { runValidation } from '../utils/validation.js';
2
+ export function validateResource(resourceConfig) {
3
+ if (!resourceConfig)
4
+ return [{ type: 'invalid_value', message: 'Resource config must be provided' }];
5
+ if (typeof resourceConfig !== 'object')
6
+ return [{ type: 'invalid_type', message: 'Resource config must be an object' }];
7
+ const errors = [];
8
+ if (!('name' in resourceConfig)) {
9
+ errors.push({ type: 'missing_parameter', message: '`name` is required' });
10
+ }
11
+ else if (typeof resourceConfig.name !== 'string') {
12
+ errors.push({ type: 'invalid_type', message: '`name` must be a string' });
13
+ }
14
+ if (!('type' in resourceConfig)) {
15
+ errors.push({ type: 'missing_parameter', message: '`type` is required' });
16
+ }
17
+ else if (typeof resourceConfig.type !== 'string') {
18
+ errors.push({ type: 'invalid_type', message: '`type` must be a string' });
19
+ }
20
+ return errors;
21
+ }
22
+ export function assertResource(resource) {
23
+ runValidation(() => validateResource(resource));
24
+ }
25
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/validation/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD,MAAM,UAAU,gBAAgB,CAAC,cAAuB;IACtD,IAAI,CAAC,cAAc;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kCAAkC,EAAC,CAAC,CAAA;IAClG,IAAI,OAAO,cAAc,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mCAAmC,EAAC,CAAC,CAAA;IAErH,MAAM,MAAM,GAAqB,EAAE,CAAA;IAEnC,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,oBAAoB,EAAC,CAAC,CAAA;IACzE,CAAC;SAAM,IAAI,OAAO,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAC,CAAC,CAAA;IACzE,CAAC;IAED,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,oBAAoB,EAAC,CAAC,CAAA;IACzE,CAAC;SAAM,IAAI,OAAO,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAC,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAiB;IAC9C,aAAa,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { BlueprintError } from '../index.js';
2
+ /**
3
+ * Validates a role.
4
+ * @param parameters The configuration of the role
5
+ * @returns The errors
6
+ */
7
+ export declare function validateRole(parameters: unknown): BlueprintError[];
8
+ export declare function validateProjectRole(parameters: unknown): BlueprintError[];