@sanity/blueprints 0.4.2 → 0.5.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.
@@ -1,2 +1,23 @@
1
- import type { Blueprint, BlueprintModule, BlueprintsApiConfig } from '../types.js';
1
+ import type { BlueprintResource } from '../types.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
+ };
2
23
  export declare function defineBlueprint(blueprintConfig: Partial<Blueprint> & Partial<BlueprintsApiConfig>): BlueprintModule;
@@ -1 +1 @@
1
- {"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/definers/blueprints.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,eAAkE;IAChG,MAAM,EAAC,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAC,GAAG,eAAe,CAAA;IAE1G,IAAI,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAE3F,SAAS,SAAS;QAChB,OAAO;YACL,OAAO,EAAE,wEAAwE;YACjF,gBAAgB,EAAE,gBAAgB,IAAI,YAAY;YAClD,SAAS;YACT,MAAM;YACN,OAAO;SACR,CAAA;IACH,CAAC;IAED,SAAS,CAAC,cAAc,GAAG,cAAc,CAAA;IACzC,SAAS,CAAC,SAAS,GAAG,SAAS,CAAA;IAC/B,SAAS,CAAC,OAAO,GAAG,OAAO,CAAA;IAE3B,OAAO,SAAS,CAAA;AAClB,CAAC"}
1
+ {"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/definers/blueprints.ts"],"names":[],"mappings":"AA2BA,MAAM,UAAU,eAAe,CAAC,eAAkE;IAChG,MAAM,EAAC,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAC,GAAG,eAAe,CAAA;IAE1G,IAAI,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAE3F,SAAS,SAAS;QAChB,OAAO;YACL,OAAO,EAAE,wEAAwE;YACjF,gBAAgB,EAAE,gBAAgB,IAAI,YAAY;YAClD,SAAS;YACT,MAAM;YACN,OAAO;SACR,CAAA;IACH,CAAC;IAED,SAAS,CAAC,cAAc,GAAG,cAAc,CAAA;IACzC,SAAS,CAAC,SAAS,GAAG,SAAS,CAAA;IAC/B,SAAS,CAAC,OAAO,GAAG,OAAO,CAAA;IAE3B,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -1,2 +1,16 @@
1
- import type { BlueprintCorsOriginConfig, BlueprintCorsOriginResource } from '../types';
1
+ import type { BlueprintResource } from '../types';
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
+ };
2
16
  export declare function defineCorsOrigin(parameters: BlueprintCorsOriginConfig): BlueprintCorsOriginResource;
@@ -1 +1 @@
1
- {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/definers/cors.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,UAAqC;IACpE,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IAC5C,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,IAAI,KAAK;QACtD,IAAI,EAAE,qBAAqB;KAC5B,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/definers/cors.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,gBAAgB,CAAC,UAAqC;IACpE,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IAC5C,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,IAAI,KAAK;QACtD,IAAI,EAAE,qBAAqB;KAC5B,CAAA;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { BlueprintResource } from '../types';
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
+ };
16
+ export declare function defineDataset(parameters: BlueprintDatasetConfig): BlueprintDatasetResource;
@@ -0,0 +1,28 @@
1
+ export function defineDataset(parameters) {
2
+ const errors = [];
3
+ // default dataset name
4
+ const datasetName = parameters.datasetName || parameters.name;
5
+ // validate ACL mode if provided
6
+ if (typeof parameters.aclMode !== 'undefined') {
7
+ const aclMode = parameters.aclMode;
8
+ if (aclMode !== 'custom' && aclMode !== 'public' && aclMode !== 'private') {
9
+ errors.push('aclMode must be one of `custom`, `public`, or `private`');
10
+ }
11
+ }
12
+ // validate project if provided
13
+ if (parameters.project) {
14
+ if (typeof parameters.project !== 'string') {
15
+ errors.push('project must be a string');
16
+ }
17
+ }
18
+ if (errors.length > 0) {
19
+ const message = errors.join('\n');
20
+ throw new Error(message);
21
+ }
22
+ return {
23
+ ...parameters,
24
+ datasetName,
25
+ type: 'sanity.project.dataset',
26
+ };
27
+ }
28
+ //# sourceMappingURL=datasets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/definers/datasets.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,aAAa,CAAC,UAAkC;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,uBAAuB;IACvB,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,IAAI,CAAA;IAE7D,gCAAgC;IAChC,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAW,UAAU,CAAC,OAAO,CAAA;QAC1C,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1E,MAAM,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAA;QACxE,CAAC;IACH,CAAC;IAED,+BAA+B;IAC/B,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,WAAW;QACX,IAAI,EAAE,wBAAwB;KAC/B,CAAA;AACH,CAAC"}
@@ -1,6 +1,49 @@
1
- import type { BlueprintBaseFunctionResource, BlueprintDocumentFunctionResource, BlueprintDocumentFunctionResourceEvent, BlueprintMediaLibraryAssetFunctionResource, BlueprintMediaLibraryFunctionResourceEvent } from '../types.js';
2
- export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource>): BlueprintDocumentFunctionResource;
1
+ import type { BlueprintResource } from '../types';
2
+ export interface BlueprintFunctionBaseResourceEvent {
3
+ on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
4
+ filter?: string;
5
+ projection?: `{${string}}`;
6
+ }
7
+ export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
8
+ includeDrafts?: boolean;
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
+ interface RequiredFunctionProperties {
27
+ name: string;
28
+ }
29
+ export interface BlueprintBaseFunctionResource extends BlueprintResource {
30
+ displayName?: string;
31
+ src: string;
32
+ timeout?: number;
33
+ memory?: number;
34
+ env?: Record<string, string>;
35
+ }
36
+ export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
37
+ type: 'sanity.function.document';
38
+ event: BlueprintDocumentFunctionResourceEvent;
39
+ }
40
+ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
41
+ type: 'sanity.function.media-library.asset';
42
+ event: BlueprintMediaLibraryFunctionResourceEvent;
43
+ }
44
+ export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties): BlueprintDocumentFunctionResource;
3
45
  /** @deprecated Define event properties under the 'event' key instead of specifying them at the top level */
4
- export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource> & Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResource;
5
- export declare function defineMediaLibraryAssetFunction(functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> & Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> & Partial<BlueprintMediaLibraryFunctionResourceEvent>): BlueprintMediaLibraryAssetFunctionResource;
6
- export declare function defineFunction(functionConfig: Partial<BlueprintBaseFunctionResource>): BlueprintBaseFunctionResource;
46
+ export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResource;
47
+ export declare function defineMediaLibraryAssetFunction(functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> & RequiredFunctionProperties & Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> & Partial<BlueprintMediaLibraryFunctionResourceEvent>): BlueprintMediaLibraryAssetFunctionResource;
48
+ export declare function defineFunction(functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties): BlueprintBaseFunctionResource;
49
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"AAUA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAA;AAErF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B;IAC5D,eAAe;IACf,oBAAoB;IACpB,UAAU;IACV,GAAG,eAAe,CAAC,MAAM,EAAE;CAC5B,CAAC,CAAA;AAEF,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAA+B,CAAC,UA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,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAChF,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { BlueprintResource } from '../types';
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
+ }
22
+ /**
23
+ * Defines a role that is scoped to the same resource as the blueprint.
24
+ * @param parameters The configuration of the role
25
+ * @returns The role resource
26
+ */
27
+ export declare function defineRole(parameters: BlueprintRoleConfig): BlueprintRoleResource;
28
+ /**
29
+ * Defines a role that is scoped to the specified project.
30
+ * @param projectId The ID of the project to which the role will be scoped
31
+ * @param parameters The configuration of the role
32
+ * @returns The role resource
33
+ */
34
+ export declare function defineProjectRole(projectId: string, parameters: BlueprintRoleConfig): BlueprintProjectRoleResource;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Defines a role that is scoped to the same resource as the blueprint.
3
+ * @param parameters The configuration of the role
4
+ * @returns The role resource
5
+ */
6
+ export function defineRole(parameters) {
7
+ const errors = [];
8
+ if (!parameters.name || parameters.name.trim() === '') {
9
+ errors.push('Role name is required');
10
+ }
11
+ if (!parameters.title || parameters.title.trim() === '') {
12
+ errors.push('Role title is required');
13
+ }
14
+ else if (parameters.title.length > 100) {
15
+ errors.push('Role title must be 100 characters or less');
16
+ }
17
+ if (!parameters.permissions || parameters.permissions.length < 1) {
18
+ errors.push('Role must have at least one permission');
19
+ }
20
+ if (errors.length > 0) {
21
+ const message = errors.join('\n');
22
+ throw new Error(message);
23
+ }
24
+ return {
25
+ name: parameters.name,
26
+ type: 'sanity.access.role',
27
+ title: parameters.title,
28
+ description: parameters.description,
29
+ appliesToUsers: parameters.appliesToUsers,
30
+ appliesToRobots: parameters.appliesToRobots,
31
+ permissions: parameters.permissions,
32
+ };
33
+ }
34
+ /**
35
+ * Defines a role that is scoped to the specified project.
36
+ * @param projectId The ID of the project to which the role will be scoped
37
+ * @param parameters The configuration of the role
38
+ * @returns The role resource
39
+ */
40
+ export function defineProjectRole(projectId, parameters) {
41
+ const roleResource = defineRole(parameters);
42
+ return {
43
+ ...roleResource,
44
+ resourceType: 'project',
45
+ resourceId: projectId,
46
+ };
47
+ }
48
+ //# sourceMappingURL=roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/definers/roles.ts"],"names":[],"mappings":"AA0BA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,UAA+B;IACxD,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACvC,CAAC;SAAM,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAA;IAC1D,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjE,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAA;IACvD,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,cAAc,EAAE,UAAU,CAAC,cAAc;QACzC,eAAe,EAAE,UAAU,CAAC,eAAe;QAC3C,WAAW,EAAE,UAAU,CAAC,WAAW;KACpC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,UAA+B;IAClF,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAE3C,OAAO;QACL,GAAG,YAAY;QACf,YAAY,EAAE,SAAS;QACvB,UAAU,EAAE,SAAS;KACtB,CAAA;AACH,CAAC"}
@@ -1,2 +1,22 @@
1
- import type { BlueprintDocumentWebhookConfig, BlueprintDocumentWebhookResource } from '../types';
1
+ import type { BlueprintResource } from '../types';
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'>;
2
22
  export declare function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource;
@@ -1 +1 @@
1
- {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/definers/webhooks.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CAAC,UAA0C;IAC9E,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IACzC,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAC3B,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC7D,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IACxC,CAAC;IAED,sBAAsB;IACtB,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAA;IAChD,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAA;IAC5E,CAAC;IAED,uBAAuB;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YAC3D,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,IAAI,EAAE,wBAAwB;KAC/B,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './types.js';
2
2
  export * from './definers/blueprints.js';
3
3
  export * from './definers/cors.js';
4
+ export * from './definers/datasets.js';
4
5
  export * from './definers/functions.js';
5
6
  export * from './definers/resources.js';
7
+ export * from './definers/roles.js';
6
8
  export * from './definers/webhooks.js';
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './types.js';
2
2
  export * from './definers/blueprints.js';
3
3
  export * from './definers/cors.js';
4
+ export * from './definers/datasets.js';
4
5
  export * from './definers/functions.js';
5
6
  export * from './definers/resources.js';
7
+ export * from './definers/roles.js';
6
8
  export * from './definers/webhooks.js';
7
9
  //# 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,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA"}
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"}
package/dist/types.d.ts CHANGED
@@ -1,93 +1,7 @@
1
+ /**
2
+ * The base type for all resources.
3
+ */
1
4
  export interface BlueprintResource {
2
5
  type: string;
3
6
  name: string;
4
7
  }
5
- export interface BlueprintCorsOriginResource extends BlueprintResource {
6
- type: 'sanity.project.cors';
7
- project?: string;
8
- origin: string;
9
- allowCredentials: boolean;
10
- }
11
- export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
12
- allowCredentials?: boolean;
13
- };
14
- export interface BlueprintFunctionBaseResourceEvent {
15
- on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]];
16
- filter?: string;
17
- projection?: `{${string}}`;
18
- }
19
- export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
20
- includeDrafts?: boolean;
21
- includeAllVersions?: boolean;
22
- resource?: BlueprintFunctionResourceEventResourceDataset;
23
- }
24
- export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
25
- resource: BlueprintFunctionResourceEventResourceMediaLibrary;
26
- }
27
- export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent;
28
- interface BlueprintFunctionResourceEventResourceDataset {
29
- type: 'dataset';
30
- /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
31
- id: string;
32
- }
33
- interface BlueprintFunctionResourceEventResourceMediaLibrary {
34
- type: 'media-library';
35
- id: string;
36
- }
37
- type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update';
38
- export interface BlueprintBaseFunctionResource extends BlueprintResource {
39
- src: string;
40
- timeout?: number;
41
- memory?: number;
42
- env?: Record<string, string>;
43
- }
44
- export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
45
- type: 'sanity.function.document';
46
- event: BlueprintDocumentFunctionResourceEvent;
47
- }
48
- export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
49
- type: 'sanity.function.media-library.asset';
50
- event: BlueprintMediaLibraryFunctionResourceEvent;
51
- }
52
- export type WebhookTrigger = 'create' | 'update' | 'delete';
53
- export interface BlueprintDocumentWebhookResource extends BlueprintResource {
54
- type: 'sanity.project.webhook';
55
- project?: string;
56
- displayName?: string;
57
- description?: string | null;
58
- url: string;
59
- on: WebhookTrigger[];
60
- filter?: string;
61
- projection?: string;
62
- status?: 'enabled' | 'disabled';
63
- httpMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
64
- headers?: Record<string, string>;
65
- includeDrafts?: boolean;
66
- includeAllVersions?: boolean;
67
- secret?: string;
68
- dataset?: string;
69
- apiVersion?: string;
70
- }
71
- export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>;
72
- export interface BlueprintOutput {
73
- name: string;
74
- value: string;
75
- }
76
- export interface Blueprint {
77
- $schema: string;
78
- blueprintVersion: string;
79
- resources?: BlueprintResource[];
80
- values?: Record<string, unknown>;
81
- outputs?: BlueprintOutput[];
82
- }
83
- export interface BlueprintsApiConfig {
84
- organizationId: string;
85
- projectId: string;
86
- stackId: string;
87
- }
88
- export type BlueprintModule = ((args?: unknown) => Blueprint) & {
89
- organizationId?: string;
90
- projectId?: string;
91
- stackId?: string;
92
- };
93
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/blueprints",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Helper methods and type definitions for Sanity Blueprints",
5
5
  "keywords": [
6
6
  "sanity",
@@ -41,8 +41,9 @@
41
41
  "posttest": "npm run lint",
42
42
  "prepare": "npm run build",
43
43
  "pretest": "npm run typecheck",
44
- "test": "vitest run --typecheck --reporter=verbose",
45
- "test:watch": "vitest --typecheck --reporter=verbose",
44
+ "test": "npm run test:unit && npm run test:integration",
45
+ "test:integration": "cd test/integration && npm install && npm run typecheck && npm run test",
46
+ "test:unit": "vitest run --typecheck --reporter=verbose",
46
47
  "typecheck": "tsc --noEmit --project tsconfig.test.json"
47
48
  },
48
49
  "devDependencies": {
@@ -1,4 +1,29 @@
1
- import type {Blueprint, BlueprintModule, BlueprintsApiConfig} from '../types.js'
1
+ import type {BlueprintResource} from '../types.js'
2
+
3
+ export interface BlueprintsApiConfig {
4
+ organizationId: string
5
+ projectId: string
6
+ stackId: string
7
+ }
8
+
9
+ export interface BlueprintOutput {
10
+ name: string
11
+ value: string
12
+ }
13
+
14
+ export interface Blueprint {
15
+ $schema: string
16
+ blueprintVersion: string
17
+ resources?: BlueprintResource[]
18
+ values?: Record<string, unknown>
19
+ outputs?: BlueprintOutput[]
20
+ }
21
+
22
+ export type BlueprintModule = ((args?: unknown) => Blueprint) & {
23
+ organizationId?: string
24
+ projectId?: string
25
+ stackId?: string
26
+ }
2
27
 
3
28
  export function defineBlueprint(blueprintConfig: Partial<Blueprint> & Partial<BlueprintsApiConfig>): BlueprintModule {
4
29
  const {organizationId, projectId, stackId, blueprintVersion, resources, values, outputs} = blueprintConfig
@@ -1,4 +1,21 @@
1
- import type {BlueprintCorsOriginConfig, BlueprintCorsOriginResource} from '../types'
1
+ import type {BlueprintResource} from '../types'
2
+
3
+ /**
4
+ * Represents a CORS Origin resource.
5
+ */
6
+ export interface BlueprintCorsOriginResource extends BlueprintResource {
7
+ type: 'sanity.project.cors'
8
+ origin: string
9
+ allowCredentials: boolean
10
+
11
+ /** The `project` attribute must be defined if your blueprint is scoped to an organization. */
12
+ project?: string
13
+ }
14
+
15
+ /** Configuration for a CORS Origin resource. */
16
+ export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
17
+ allowCredentials?: boolean
18
+ }
2
19
 
3
20
  export function defineCorsOrigin(parameters: BlueprintCorsOriginConfig): BlueprintCorsOriginResource {
4
21
  const errors: string[] = []
@@ -0,0 +1,52 @@
1
+ import type {BlueprintResource} from '../types'
2
+
3
+ export type AclMode = 'public' | 'private' | 'custom'
4
+
5
+ /** Represents a Dataset resource. */
6
+ export interface BlueprintDatasetResource extends BlueprintResource {
7
+ type: 'sanity.project.dataset'
8
+ datasetName: string
9
+ aclMode?: AclMode
10
+
11
+ /** The `project` attribute must be defined if your blueprint is scoped to an organization. */
12
+ project?: string
13
+ }
14
+
15
+ /** Configuration for a Dataset resource. */
16
+ export type BlueprintDatasetConfig = Omit<BlueprintDatasetResource, 'type' | 'datasetName'> & {
17
+ /** The name of the dataset, defaults to the name of the resource. */
18
+ datasetName?: string
19
+ }
20
+
21
+ export function defineDataset(parameters: BlueprintDatasetConfig): BlueprintDatasetResource {
22
+ const errors: string[] = []
23
+
24
+ // default dataset name
25
+ const datasetName = parameters.datasetName || parameters.name
26
+
27
+ // validate ACL mode if provided
28
+ if (typeof parameters.aclMode !== 'undefined') {
29
+ const aclMode: string = parameters.aclMode
30
+ if (aclMode !== 'custom' && aclMode !== 'public' && aclMode !== 'private') {
31
+ errors.push('aclMode must be one of `custom`, `public`, or `private`')
32
+ }
33
+ }
34
+
35
+ // validate project if provided
36
+ if (parameters.project) {
37
+ if (typeof parameters.project !== 'string') {
38
+ errors.push('project must be a string')
39
+ }
40
+ }
41
+
42
+ if (errors.length > 0) {
43
+ const message = errors.join('\n')
44
+ throw new Error(message)
45
+ }
46
+
47
+ return {
48
+ ...parameters,
49
+ datasetName,
50
+ type: 'sanity.project.dataset',
51
+ }
52
+ }
@@ -1,11 +1,33 @@
1
- import type {
2
- BlueprintBaseFunctionResource,
3
- BlueprintDocumentFunctionResource,
4
- BlueprintDocumentFunctionResourceEvent,
5
- BlueprintFunctionBaseResourceEvent,
6
- BlueprintMediaLibraryAssetFunctionResource,
7
- BlueprintMediaLibraryFunctionResourceEvent,
8
- } from '../types.js'
1
+ import type {BlueprintResource} from '../types'
2
+
3
+ // --- Function Event Types ---
4
+
5
+ export interface BlueprintFunctionBaseResourceEvent {
6
+ on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
7
+ filter?: string
8
+ projection?: `{${string}}`
9
+ }
10
+ export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
11
+ includeDrafts?: boolean
12
+ includeAllVersions?: boolean
13
+ resource?: BlueprintFunctionResourceEventResourceDataset
14
+ }
15
+ export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
16
+ resource: BlueprintFunctionResourceEventResourceMediaLibrary
17
+ }
18
+ export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
19
+
20
+ interface BlueprintFunctionResourceEventResourceDataset {
21
+ type: 'dataset'
22
+ /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
23
+ id: string
24
+ }
25
+ interface BlueprintFunctionResourceEventResourceMediaLibrary {
26
+ type: 'media-library'
27
+ id: string
28
+ }
29
+
30
+ type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
9
31
 
10
32
  type BaseFunctionEventKey = keyof BlueprintFunctionBaseResourceEvent
11
33
  const BASE_EVENT_KEYS = new Set<BaseFunctionEventKey>(['on', 'filter', 'projection'])
@@ -19,15 +41,38 @@ const DOCUMENT_EVENT_KEYS = new Set<DocumentFunctionEventKey>([
19
41
  type MediaLibraryFunctionEventKey = keyof BlueprintMediaLibraryFunctionResourceEvent
20
42
  const MEDIA_LIBRARY_EVENT_KEYS = new Set<MediaLibraryFunctionEventKey>(['resource', ...BASE_EVENT_KEYS.values()])
21
43
 
22
- export function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource>): BlueprintDocumentFunctionResource
44
+ // --- Main Function Types ---
45
+
46
+ interface RequiredFunctionProperties {
47
+ name: string
48
+ }
49
+ export interface BlueprintBaseFunctionResource extends BlueprintResource {
50
+ displayName?: string
51
+ src: string
52
+ timeout?: number
53
+ memory?: number
54
+ env?: Record<string, string>
55
+ }
56
+ export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
57
+ type: 'sanity.function.document'
58
+ event: BlueprintDocumentFunctionResourceEvent
59
+ }
60
+ export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
61
+ type: 'sanity.function.media-library.asset'
62
+ event: BlueprintMediaLibraryFunctionResourceEvent
63
+ }
64
+
65
+ export function defineDocumentFunction(
66
+ functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties,
67
+ ): BlueprintDocumentFunctionResource
23
68
 
24
69
  /** @deprecated Define event properties under the 'event' key instead of specifying them at the top level */
25
70
  export function defineDocumentFunction(
26
- functionConfig: Partial<BlueprintDocumentFunctionResource> & Partial<BlueprintDocumentFunctionResourceEvent>,
71
+ functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
27
72
  ): BlueprintDocumentFunctionResource
28
73
 
29
74
  export function defineDocumentFunction(
30
- functionConfig: Partial<BlueprintDocumentFunctionResource> & Partial<BlueprintDocumentFunctionResourceEvent>,
75
+ functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>,
31
76
  ): BlueprintDocumentFunctionResource {
32
77
  let {name, src, event, timeout, memory, env, type, ...maybeEvent} = functionConfig
33
78
  if (!type) type = 'sanity.function.document'
@@ -65,6 +110,7 @@ export function defineDocumentFunction(
65
110
 
66
111
  export function defineMediaLibraryAssetFunction(
67
112
  functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> &
113
+ RequiredFunctionProperties &
68
114
  Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> &
69
115
  Partial<BlueprintMediaLibraryFunctionResourceEvent>,
70
116
  ): BlueprintMediaLibraryAssetFunctionResource {
@@ -83,7 +129,9 @@ export function defineMediaLibraryAssetFunction(
83
129
  event: validateMediaLibraryFunctionEvent(event),
84
130
  }
85
131
  }
86
- export function defineFunction(functionConfig: Partial<BlueprintBaseFunctionResource>): BlueprintBaseFunctionResource {
132
+ export function defineFunction(
133
+ functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties,
134
+ ): BlueprintBaseFunctionResource {
87
135
  let {name, src, timeout, memory, env, type} = functionConfig
88
136
 
89
137
  if (!name) throw new Error('`name` is required')
@@ -0,0 +1,79 @@
1
+ import type {BlueprintResource} from '../types'
2
+
3
+ export interface RolePermission {
4
+ name: string // Required: predefined permission name (e.g., 'sanity-all-documents')
5
+ action: string // Required: permission action (e.g., 'read', 'mode')
6
+ params?: Record<string, unknown> // Optional: additional parameters for the permission
7
+ }
8
+
9
+ export interface BlueprintRoleConfig {
10
+ name: string
11
+ title: string
12
+ description?: string
13
+ appliesToUsers: boolean
14
+ appliesToRobots: boolean
15
+ permissions: RolePermission[]
16
+ }
17
+
18
+ export interface BlueprintRoleResource extends BlueprintRoleConfig, BlueprintResource {
19
+ type: 'sanity.access.role'
20
+ }
21
+
22
+ export interface BlueprintProjectRoleResource extends BlueprintRoleResource {
23
+ resourceType: 'project'
24
+ resourceId: string
25
+ }
26
+
27
+ /**
28
+ * Defines a role that is scoped to the same resource as the blueprint.
29
+ * @param parameters The configuration of the role
30
+ * @returns The role resource
31
+ */
32
+ export function defineRole(parameters: BlueprintRoleConfig): BlueprintRoleResource {
33
+ const errors: string[] = []
34
+
35
+ if (!parameters.name || parameters.name.trim() === '') {
36
+ errors.push('Role name is required')
37
+ }
38
+
39
+ if (!parameters.title || parameters.title.trim() === '') {
40
+ errors.push('Role title is required')
41
+ } else if (parameters.title.length > 100) {
42
+ errors.push('Role title must be 100 characters or less')
43
+ }
44
+
45
+ if (!parameters.permissions || parameters.permissions.length < 1) {
46
+ errors.push('Role must have at least one permission')
47
+ }
48
+
49
+ if (errors.length > 0) {
50
+ const message = errors.join('\n')
51
+ throw new Error(message)
52
+ }
53
+
54
+ return {
55
+ name: parameters.name,
56
+ type: 'sanity.access.role',
57
+ title: parameters.title,
58
+ description: parameters.description,
59
+ appliesToUsers: parameters.appliesToUsers,
60
+ appliesToRobots: parameters.appliesToRobots,
61
+ permissions: parameters.permissions,
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Defines a role that is scoped to the specified project.
67
+ * @param projectId The ID of the project to which the role will be scoped
68
+ * @param parameters The configuration of the role
69
+ * @returns The role resource
70
+ */
71
+ export function defineProjectRole(projectId: string, parameters: BlueprintRoleConfig): BlueprintProjectRoleResource {
72
+ const roleResource = defineRole(parameters)
73
+
74
+ return {
75
+ ...roleResource,
76
+ resourceType: 'project',
77
+ resourceId: projectId,
78
+ }
79
+ }
@@ -1,4 +1,25 @@
1
- import type {BlueprintDocumentWebhookConfig, BlueprintDocumentWebhookResource} from '../types'
1
+ import type {BlueprintResource} from '../types'
2
+
3
+ export type WebhookTrigger = 'create' | 'update' | 'delete'
4
+ export interface BlueprintDocumentWebhookResource extends BlueprintResource {
5
+ type: 'sanity.project.webhook'
6
+ project?: string
7
+ displayName?: string
8
+ description?: string | null
9
+ url: string
10
+ on: WebhookTrigger[]
11
+ filter?: string
12
+ projection?: string
13
+ status?: 'enabled' | 'disabled'
14
+ httpMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET'
15
+ headers?: Record<string, string>
16
+ includeDrafts?: boolean
17
+ includeAllVersions?: boolean
18
+ secret?: string
19
+ dataset?: string
20
+ apiVersion?: string
21
+ }
22
+ export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>
2
23
 
3
24
  export function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource {
4
25
  const errors: string[] = []
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './types.js'
2
2
  export * from './definers/blueprints.js'
3
3
  export * from './definers/cors.js'
4
+ export * from './definers/datasets.js'
4
5
  export * from './definers/functions.js'
5
6
  export * from './definers/resources.js'
7
+ export * from './definers/roles.js'
6
8
  export * from './definers/webhooks.js'
package/src/types.ts CHANGED
@@ -1,102 +1,7 @@
1
+ /**
2
+ * The base type for all resources.
3
+ */
1
4
  export interface BlueprintResource {
2
5
  type: string
3
6
  name: string
4
7
  }
5
-
6
- export interface BlueprintCorsOriginResource extends BlueprintResource {
7
- type: 'sanity.project.cors'
8
- project?: string
9
- origin: string
10
- allowCredentials: boolean
11
- }
12
- export type BlueprintCorsOriginConfig = Omit<BlueprintCorsOriginResource, 'type' | 'allowCredentials'> & {
13
- allowCredentials?: boolean
14
- }
15
-
16
- export interface BlueprintFunctionBaseResourceEvent {
17
- on?: [BlueprintFunctionResourceEventName, ...BlueprintFunctionResourceEventName[]]
18
- filter?: string
19
- projection?: `{${string}}`
20
- }
21
- export interface BlueprintDocumentFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
22
- includeDrafts?: boolean
23
- includeAllVersions?: boolean
24
- resource?: BlueprintFunctionResourceEventResourceDataset
25
- }
26
- export interface BlueprintMediaLibraryFunctionResourceEvent extends BlueprintFunctionBaseResourceEvent {
27
- resource: BlueprintFunctionResourceEventResourceMediaLibrary
28
- }
29
- export type BlueprintFunctionResourceEvent = BlueprintDocumentFunctionResourceEvent | BlueprintMediaLibraryFunctionResourceEvent
30
-
31
- interface BlueprintFunctionResourceEventResourceDataset {
32
- type: 'dataset'
33
- /** @description A dataset ID in the format <projectId>.<datasetName>. <datasetName> can be `*` to signify "all datasets in project with ID <projectId>." */
34
- id: string
35
- }
36
- interface BlueprintFunctionResourceEventResourceMediaLibrary {
37
- type: 'media-library'
38
- id: string
39
- }
40
-
41
- type BlueprintFunctionResourceEventName = 'publish' | 'create' | 'delete' | 'update'
42
-
43
- export interface BlueprintBaseFunctionResource extends BlueprintResource {
44
- src: string
45
- timeout?: number
46
- memory?: number
47
- env?: Record<string, string>
48
- }
49
- export interface BlueprintDocumentFunctionResource extends BlueprintBaseFunctionResource {
50
- type: 'sanity.function.document'
51
- event: BlueprintDocumentFunctionResourceEvent
52
- }
53
- export interface BlueprintMediaLibraryAssetFunctionResource extends BlueprintBaseFunctionResource {
54
- type: 'sanity.function.media-library.asset'
55
- event: BlueprintMediaLibraryFunctionResourceEvent
56
- }
57
-
58
- export type WebhookTrigger = 'create' | 'update' | 'delete'
59
- export interface BlueprintDocumentWebhookResource extends BlueprintResource {
60
- type: 'sanity.project.webhook'
61
- project?: string
62
- displayName?: string
63
- description?: string | null
64
- url: string
65
- on: WebhookTrigger[]
66
- filter?: string
67
- projection?: string
68
- status?: 'enabled' | 'disabled'
69
- httpMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET'
70
- headers?: Record<string, string>
71
- includeDrafts?: boolean
72
- includeAllVersions?: boolean
73
- secret?: string
74
- dataset?: string
75
- apiVersion?: string
76
- }
77
- export type BlueprintDocumentWebhookConfig = Omit<BlueprintDocumentWebhookResource, 'type'>
78
-
79
- export interface BlueprintOutput {
80
- name: string
81
- value: string
82
- }
83
-
84
- export interface Blueprint {
85
- $schema: string
86
- blueprintVersion: string
87
- resources?: BlueprintResource[]
88
- values?: Record<string, unknown>
89
- outputs?: BlueprintOutput[]
90
- }
91
-
92
- export interface BlueprintsApiConfig {
93
- organizationId: string
94
- projectId: string
95
- stackId: string
96
- }
97
-
98
- export type BlueprintModule = ((args?: unknown) => Blueprint) & {
99
- organizationId?: string
100
- projectId?: string
101
- stackId?: string
102
- }