@sanity/blueprints 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/definers/blueprints.d.ts +1 -22
- package/dist/definers/blueprints.js +3 -2
- package/dist/definers/blueprints.js.map +1 -1
- package/dist/definers/cors.d.ts +1 -15
- package/dist/definers/cors.js +5 -12
- package/dist/definers/cors.js.map +1 -1
- package/dist/definers/datasets.d.ts +1 -15
- package/dist/definers/datasets.js +5 -19
- package/dist/definers/datasets.js.map +1 -1
- package/dist/definers/functions.d.ts +4 -41
- package/dist/definers/functions.js +25 -32
- package/dist/definers/functions.js.map +1 -1
- package/dist/definers/resources.d.ts +1 -1
- package/dist/definers/resources.js +4 -8
- package/dist/definers/resources.js.map +1 -1
- package/dist/definers/roles.d.ts +4 -22
- package/dist/definers/roles.js +11 -21
- package/dist/definers/roles.js.map +1 -1
- package/dist/definers/webhooks.d.ts +1 -21
- package/dist/definers/webhooks.js +8 -64
- package/dist/definers/webhooks.js.map +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/types/blueprints.d.ts +22 -0
- package/dist/types/blueprints.js +2 -0
- package/dist/types/blueprints.js.map +1 -0
- package/dist/types/cors.d.ts +15 -0
- package/dist/types/cors.js +2 -0
- package/dist/types/cors.js.map +1 -0
- package/dist/types/datasets.d.ts +15 -0
- package/dist/types/datasets.js +2 -0
- package/dist/types/datasets.js.map +1 -0
- package/dist/types/errors.d.ts +5 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/functions.d.ts +41 -0
- package/dist/types/functions.js +2 -0
- package/dist/types/functions.js.map +1 -0
- package/dist/types/resources.js +2 -0
- package/dist/types/resources.js.map +1 -0
- package/dist/types/roles.d.ts +21 -0
- package/dist/types/roles.js +2 -0
- package/dist/types/roles.js.map +1 -0
- package/dist/types/webhooks.d.ts +21 -0
- package/dist/types/webhooks.js +2 -0
- package/dist/types/webhooks.js.map +1 -0
- package/dist/utils/validation.d.ts +2 -0
- package/dist/utils/validation.js +8 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/validation/blueprints.d.ts +2 -0
- package/dist/validation/blueprints.js +14 -0
- package/dist/validation/blueprints.js.map +1 -0
- package/dist/validation/cors.d.ts +2 -0
- package/dist/validation/cors.js +32 -0
- package/dist/validation/cors.js.map +1 -0
- package/dist/validation/datasets.d.ts +2 -0
- package/dist/validation/datasets.js +39 -0
- package/dist/validation/datasets.js.map +1 -0
- package/dist/validation/functions.d.ts +4 -0
- package/dist/validation/functions.js +125 -0
- package/dist/validation/functions.js.map +1 -0
- package/dist/validation/resources.d.ts +3 -0
- package/dist/validation/resources.js +25 -0
- package/dist/validation/resources.js.map +1 -0
- package/dist/validation/roles.d.ts +8 -0
- package/dist/validation/roles.js +57 -0
- package/dist/validation/roles.js.map +1 -0
- package/dist/validation/webhooks.d.ts +2 -0
- package/dist/validation/webhooks.js +110 -0
- package/dist/validation/webhooks.js.map +1 -0
- package/package.json +1 -1
- package/src/definers/blueprints.ts +3 -27
- package/src/definers/cors.ts +7 -34
- package/src/definers/datasets.ts +7 -42
- package/src/definers/functions.ts +62 -88
- package/src/definers/resources.ts +6 -8
- package/src/definers/roles.ts +20 -50
- package/src/definers/webhooks.ts +10 -95
- package/src/index.ts +20 -1
- package/src/types/blueprints.ts +26 -0
- package/src/types/cors.ts +18 -0
- package/src/types/datasets.ts +19 -0
- package/src/types/errors.ts +5 -0
- package/src/types/functions.ts +48 -0
- package/src/types/roles.ts +25 -0
- package/src/types/webhooks.ts +22 -0
- package/src/utils/validation.ts +9 -0
- package/src/validation/blueprints.ts +16 -0
- package/src/validation/cors.ts +34 -0
- package/src/validation/datasets.ts +41 -0
- package/src/validation/functions.ts +144 -0
- package/src/validation/resources.ts +27 -0
- package/src/validation/roles.ts +60 -0
- package/src/validation/webhooks.ts +109 -0
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- /package/dist/{types.d.ts → types/resources.d.ts} +0 -0
- /package/src/{types.ts → types/resources.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import type
|
|
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
|
-
};
|
|
1
|
+
import { type Blueprint, type BlueprintModule, type BlueprintsApiConfig } from '../index.js';
|
|
23
2
|
export declare function defineBlueprint(blueprintConfig: Partial<Blueprint> & Partial<BlueprintsApiConfig>): BlueprintModule;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { validateBlueprint } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
export function defineBlueprint(blueprintConfig) {
|
|
2
4
|
const { organizationId, projectId, stackId, blueprintVersion, resources, values, outputs } = blueprintConfig;
|
|
3
|
-
|
|
4
|
-
throw new Error('`resources` must be an array');
|
|
5
|
+
runValidation(() => validateBlueprint(blueprintConfig));
|
|
5
6
|
function blueprint() {
|
|
6
7
|
return {
|
|
7
8
|
$schema: 'https://schemas.sanity.io/blueprints/v2024-10-01/blueprint.schema.json',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/definers/blueprints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blueprints.js","sourceRoot":"","sources":["../../src/definers/blueprints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiE,iBAAiB,EAAC,MAAM,aAAa,CAAA;AAC7G,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD,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,aAAa,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAA;IAEvD,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"}
|
package/dist/definers/cors.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import type
|
|
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
|
-
};
|
|
1
|
+
import { type BlueprintCorsOriginConfig, type BlueprintCorsOriginResource } from '../index.js';
|
|
16
2
|
export declare function defineCorsOrigin(parameters: BlueprintCorsOriginConfig): BlueprintCorsOriginResource;
|
package/dist/definers/cors.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
+
import { validateCorsOrigin } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
export function defineCorsOrigin(parameters) {
|
|
2
|
-
const
|
|
3
|
-
if (!parameters.name || parameters.name.trim() === '') {
|
|
4
|
-
errors.push('CORS Origin name is required');
|
|
5
|
-
}
|
|
6
|
-
if (!parameters.origin || parameters.origin.trim() === '') {
|
|
7
|
-
errors.push('CORS Origin URL is required');
|
|
8
|
-
}
|
|
9
|
-
if (errors.length > 0) {
|
|
10
|
-
const message = errors.join('\n');
|
|
11
|
-
throw new Error(message);
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
4
|
+
const corsResource = {
|
|
14
5
|
...parameters,
|
|
15
6
|
allowCredentials: parameters.allowCredentials || false,
|
|
16
7
|
type: 'sanity.project.cors',
|
|
17
8
|
};
|
|
9
|
+
runValidation(() => validateCorsOrigin(corsResource));
|
|
10
|
+
return corsResource;
|
|
18
11
|
}
|
|
19
12
|
//# sourceMappingURL=cors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/definers/cors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/definers/cors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AAChH,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD,MAAM,UAAU,gBAAgB,CAAC,UAAqC;IACpE,MAAM,YAAY,GAAgC;QAChD,GAAG,UAAU;QACb,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,IAAI,KAAK;QACtD,IAAI,EAAE,qBAAqB;KAC5B,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAA;IAErD,OAAO,YAAY,CAAA;AACrB,CAAC"}
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import type
|
|
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
|
-
};
|
|
1
|
+
import { type BlueprintDatasetConfig, type BlueprintDatasetResource } from '../index.js';
|
|
16
2
|
export declare function defineDataset(parameters: BlueprintDatasetConfig): BlueprintDatasetResource;
|
|
@@ -1,28 +1,14 @@
|
|
|
1
|
+
import { validateDataset } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
export function defineDataset(parameters) {
|
|
2
|
-
const errors = [];
|
|
3
4
|
// default dataset name
|
|
4
5
|
const datasetName = parameters.datasetName || parameters.name;
|
|
5
|
-
|
|
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 {
|
|
6
|
+
const datasetResource = {
|
|
23
7
|
...parameters,
|
|
24
8
|
datasetName,
|
|
25
9
|
type: 'sanity.project.dataset',
|
|
26
10
|
};
|
|
11
|
+
runValidation(() => validateDataset(datasetResource));
|
|
12
|
+
return datasetResource;
|
|
27
13
|
}
|
|
28
14
|
//# sourceMappingURL=datasets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/definers/datasets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datasets.js","sourceRoot":"","sources":["../../src/definers/datasets.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6D,eAAe,EAAC,MAAM,aAAa,CAAA;AACvG,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD,MAAM,UAAU,aAAa,CAAC,UAAkC;IAC9D,uBAAuB;IACvB,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,IAAI,CAAA;IAE7D,MAAM,eAAe,GAA6B;QAChD,GAAG,UAAU;QACb,WAAW;QACX,IAAI,EAAE,wBAAwB;KAC/B,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAA;IAErD,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -1,49 +1,12 @@
|
|
|
1
|
-
import type
|
|
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';
|
|
1
|
+
import { type BlueprintBaseFunctionResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentFunctionResourceEvent, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintMediaLibraryFunctionResourceEvent } from '../index.js';
|
|
26
2
|
interface RequiredFunctionProperties {
|
|
27
3
|
name: string;
|
|
28
4
|
}
|
|
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
5
|
export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties): BlueprintDocumentFunctionResource;
|
|
45
6
|
/** @deprecated Define event properties under the 'event' key instead of specifying them at the top level */
|
|
46
7
|
export declare function defineDocumentFunction(functionConfig: Partial<BlueprintDocumentFunctionResource> & RequiredFunctionProperties & Partial<BlueprintDocumentFunctionResourceEvent>): BlueprintDocumentFunctionResource;
|
|
47
8
|
export declare function defineMediaLibraryAssetFunction(functionConfig: Partial<BlueprintMediaLibraryAssetFunctionResource> & RequiredFunctionProperties & Pick<BlueprintMediaLibraryAssetFunctionResource, 'event'> & Partial<BlueprintMediaLibraryFunctionResourceEvent>): BlueprintMediaLibraryAssetFunctionResource;
|
|
48
|
-
export declare function defineFunction(functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties
|
|
9
|
+
export declare function defineFunction(functionConfig: Partial<BlueprintBaseFunctionResource> & RequiredFunctionProperties, options?: {
|
|
10
|
+
skipValidation?: boolean;
|
|
11
|
+
}): BlueprintBaseFunctionResource;
|
|
49
12
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { validateDocumentFunction, validateFunction, validateMediaLibraryAssetFunction, } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
const BASE_EVENT_KEYS = new Set(['on', 'filter', 'projection', 'includeDrafts']);
|
|
2
4
|
const DOCUMENT_EVENT_KEYS = new Set(['includeAllVersions', 'resource', ...BASE_EVENT_KEYS.values()]);
|
|
3
5
|
const MEDIA_LIBRARY_EVENT_KEYS = new Set(['resource', ...BASE_EVENT_KEYS.values()]);
|
|
@@ -5,63 +7,64 @@ export function defineDocumentFunction(functionConfig) {
|
|
|
5
7
|
let { name, src, event, timeout, memory, env, type, ...maybeEvent } = functionConfig;
|
|
6
8
|
if (!type)
|
|
7
9
|
type = 'sanity.function.document';
|
|
8
|
-
// event validation
|
|
10
|
+
// event validation and normalization
|
|
9
11
|
if (event) {
|
|
10
12
|
// `event` was specified, but event keys (aggregated in `maybeEvent`) were also specified at the top level. ambiguous and deprecated usage.
|
|
11
|
-
const duplicateKeys =
|
|
13
|
+
const duplicateKeys = Array.from(DOCUMENT_EVENT_KEYS).filter((key) => key in maybeEvent);
|
|
12
14
|
if (duplicateKeys.length > 0) {
|
|
13
15
|
throw new Error(`\`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(', ')}`);
|
|
14
16
|
}
|
|
15
|
-
event =
|
|
17
|
+
event = buildDocumentFunctionEvent(event);
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
|
-
event =
|
|
20
|
+
event = buildDocumentFunctionEvent(maybeEvent);
|
|
19
21
|
// deprecated usage of putting event properties at the top level, warn about this.
|
|
20
22
|
console.warn('⚠️ Deprecated usage of `defineDocumentFunction`: prefer to put `event` properties under the `event` key rather than at the top level.');
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
const functionResource = {
|
|
23
25
|
...defineFunction({
|
|
24
26
|
name,
|
|
25
27
|
src,
|
|
26
28
|
timeout,
|
|
27
29
|
memory,
|
|
28
30
|
env,
|
|
31
|
+
}, {
|
|
32
|
+
skipValidation: true, // already done below
|
|
29
33
|
}),
|
|
30
34
|
type,
|
|
31
35
|
event,
|
|
32
36
|
};
|
|
37
|
+
runValidation(() => validateDocumentFunction(functionResource));
|
|
38
|
+
return functionResource;
|
|
33
39
|
}
|
|
34
40
|
export function defineMediaLibraryAssetFunction(functionConfig) {
|
|
35
41
|
let { name, src, event, timeout, memory, env, type } = functionConfig;
|
|
36
42
|
if (!type)
|
|
37
43
|
type = 'sanity.function.media-library.asset';
|
|
38
|
-
|
|
44
|
+
const functionResource = {
|
|
39
45
|
...defineFunction({
|
|
40
46
|
name,
|
|
41
47
|
src,
|
|
42
48
|
timeout,
|
|
43
49
|
memory,
|
|
44
50
|
env,
|
|
51
|
+
}, {
|
|
52
|
+
skipValidation: true, // already done below
|
|
45
53
|
}),
|
|
46
54
|
type,
|
|
47
|
-
event:
|
|
55
|
+
event: buildMediaLibraryFunctionEvent(event),
|
|
48
56
|
};
|
|
57
|
+
runValidation(() => validateMediaLibraryAssetFunction(functionResource));
|
|
58
|
+
return functionResource;
|
|
49
59
|
}
|
|
50
|
-
export function defineFunction(functionConfig) {
|
|
60
|
+
export function defineFunction(functionConfig, options) {
|
|
51
61
|
let { name, src, timeout, memory, env, type } = functionConfig;
|
|
52
|
-
if (!name)
|
|
53
|
-
throw new Error('`name` is required');
|
|
54
62
|
// defaults
|
|
55
63
|
if (!src)
|
|
56
64
|
src = `functions/${name}`;
|
|
57
65
|
if (!type)
|
|
58
66
|
type = 'sanity.function.document';
|
|
59
|
-
|
|
60
|
-
if (memory && typeof memory !== 'number')
|
|
61
|
-
throw new Error('`memory` must be a number');
|
|
62
|
-
if (timeout && typeof timeout !== 'number')
|
|
63
|
-
throw new Error('`timeout` must be a number');
|
|
64
|
-
return {
|
|
67
|
+
const functionResource = {
|
|
65
68
|
type,
|
|
66
69
|
name,
|
|
67
70
|
src,
|
|
@@ -69,33 +72,23 @@ export function defineFunction(functionConfig) {
|
|
|
69
72
|
memory,
|
|
70
73
|
env,
|
|
71
74
|
};
|
|
75
|
+
if (options?.skipValidation !== true)
|
|
76
|
+
runValidation(() => validateFunction(functionResource));
|
|
77
|
+
return functionResource;
|
|
72
78
|
}
|
|
73
|
-
function
|
|
79
|
+
function buildDocumentFunctionEvent(event) {
|
|
74
80
|
const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => DOCUMENT_EVENT_KEYS.has(key)));
|
|
75
|
-
|
|
81
|
+
return {
|
|
76
82
|
on: cleanEvent.on || ['publish'],
|
|
77
83
|
...cleanEvent,
|
|
78
84
|
};
|
|
79
|
-
if (!Array.isArray(fullEvent.on))
|
|
80
|
-
throw new Error('`event.on` must be an array');
|
|
81
|
-
if (fullEvent.resource) {
|
|
82
|
-
if (!fullEvent.resource.type || fullEvent.resource.type !== 'dataset')
|
|
83
|
-
throw new Error('`event.resource.type` must be "dataset"');
|
|
84
|
-
if (!fullEvent.resource.id || fullEvent.resource.id.split('.').length !== 2)
|
|
85
|
-
throw new Error('`event.resource.id` must be in the format <projectId>.<datasetName>');
|
|
86
|
-
}
|
|
87
|
-
return fullEvent;
|
|
88
85
|
}
|
|
89
|
-
function
|
|
86
|
+
function buildMediaLibraryFunctionEvent(event) {
|
|
90
87
|
const cleanEvent = Object.fromEntries(Object.entries(event).filter(([key]) => MEDIA_LIBRARY_EVENT_KEYS.has(key)));
|
|
91
88
|
const fullEvent = {
|
|
92
89
|
on: cleanEvent.on || ['publish'],
|
|
93
90
|
...cleanEvent,
|
|
94
91
|
};
|
|
95
|
-
if (!Array.isArray(fullEvent.on))
|
|
96
|
-
throw new Error('`event.on` must be an array');
|
|
97
|
-
if (!fullEvent.resource.type || fullEvent.resource.type !== 'media-library')
|
|
98
|
-
throw new Error('`event.resource.type` must be "media-library"');
|
|
99
92
|
return fullEvent;
|
|
100
93
|
}
|
|
101
94
|
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/definers/functions.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BlueprintResource } from '../index.js';
|
|
2
2
|
export declare function defineResource(resourceConfig: Partial<BlueprintResource>): BlueprintResource;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
+
import { assertResource } from '../index.js';
|
|
1
2
|
export function defineResource(resourceConfig) {
|
|
2
|
-
const
|
|
3
|
-
if (!name)
|
|
4
|
-
throw new Error('`name` is required');
|
|
5
|
-
if (!type)
|
|
6
|
-
throw new Error('`type` is required');
|
|
7
|
-
return {
|
|
3
|
+
const resource = {
|
|
8
4
|
...resourceConfig,
|
|
9
|
-
type,
|
|
10
|
-
name,
|
|
11
5
|
};
|
|
6
|
+
assertResource(resource);
|
|
7
|
+
return resource;
|
|
12
8
|
}
|
|
13
9
|
//# sourceMappingURL=resources.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/definers/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAC,MAAM,aAAa,CAAA;AAElE,MAAM,UAAU,cAAc,CAAC,cAA0C;IACvE,MAAM,QAAQ,GAAG;QACf,GAAG,cAAc;KAClB,CAAA;IAED,cAAc,CAAC,QAAQ,CAAC,CAAA;IAExB,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/dist/definers/roles.d.ts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import type
|
|
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
|
-
}
|
|
1
|
+
import { type BlueprintProjectRoleResource, type BlueprintRoleConfig, type BlueprintRoleResource } from '../index.js';
|
|
22
2
|
/**
|
|
23
3
|
* Defines a role that is scoped to the same resource as the blueprint.
|
|
24
4
|
* @param parameters The configuration of the role
|
|
25
5
|
* @returns The role resource
|
|
26
6
|
*/
|
|
27
|
-
export declare function defineRole(parameters: BlueprintRoleConfig
|
|
7
|
+
export declare function defineRole(parameters: BlueprintRoleConfig, options?: {
|
|
8
|
+
skipValidation?: boolean;
|
|
9
|
+
}): BlueprintRoleResource;
|
|
28
10
|
/**
|
|
29
11
|
* Defines a role that is scoped to the specified project.
|
|
30
12
|
* @param projectId The ID of the project to which the role will be scoped
|
package/dist/definers/roles.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
+
import { validateProjectRole, validateRole, } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
/**
|
|
2
4
|
* Defines a role that is scoped to the same resource as the blueprint.
|
|
3
5
|
* @param parameters The configuration of the role
|
|
4
6
|
* @returns The role resource
|
|
5
7
|
*/
|
|
6
|
-
export function defineRole(parameters) {
|
|
7
|
-
const
|
|
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 {
|
|
8
|
+
export function defineRole(parameters, options) {
|
|
9
|
+
const roleResource = {
|
|
25
10
|
name: parameters.name,
|
|
26
11
|
type: 'sanity.access.role',
|
|
27
12
|
title: parameters.title,
|
|
@@ -30,6 +15,9 @@ export function defineRole(parameters) {
|
|
|
30
15
|
appliesToRobots: parameters.appliesToRobots,
|
|
31
16
|
permissions: parameters.permissions,
|
|
32
17
|
};
|
|
18
|
+
if (options?.skipValidation !== true)
|
|
19
|
+
runValidation(() => validateRole(roleResource));
|
|
20
|
+
return roleResource;
|
|
33
21
|
}
|
|
34
22
|
/**
|
|
35
23
|
* Defines a role that is scoped to the specified project.
|
|
@@ -38,11 +26,13 @@ export function defineRole(parameters) {
|
|
|
38
26
|
* @returns The role resource
|
|
39
27
|
*/
|
|
40
28
|
export function defineProjectRole(projectId, parameters) {
|
|
41
|
-
const roleResource = defineRole(parameters);
|
|
42
|
-
|
|
29
|
+
const roleResource = defineRole(parameters, { skipValidation: true });
|
|
30
|
+
const projectRoleResource = {
|
|
43
31
|
...roleResource,
|
|
44
32
|
resourceType: 'project',
|
|
45
33
|
resourceId: projectId,
|
|
46
34
|
};
|
|
35
|
+
runValidation(() => validateProjectRole(projectRoleResource));
|
|
36
|
+
return projectRoleResource;
|
|
47
37
|
}
|
|
48
38
|
//# sourceMappingURL=roles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/definers/roles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/definers/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,EACnB,YAAY,GACb,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,UAA+B,EAAE,OAAoC;IAC9F,MAAM,YAAY,GAA0B;QAC1C,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;IAED,IAAI,OAAO,EAAE,cAAc,KAAK,IAAI;QAAE,aAAa,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAA;IAErF,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,UAA+B;IAClF,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,EAAE,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC,CAAA;IAEnE,MAAM,mBAAmB,GAAiC;QACxD,GAAG,YAAY;QACf,YAAY,EAAE,SAAS;QACvB,UAAU,EAAE,SAAS;KACtB,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC,CAAA;IAE7D,OAAO,mBAAmB,CAAA;AAC5B,CAAC"}
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import type
|
|
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'>;
|
|
1
|
+
import { type BlueprintDocumentWebhookConfig, type BlueprintDocumentWebhookResource } from '../index.js';
|
|
22
2
|
export declare function defineDocumentWebhook(parameters: BlueprintDocumentWebhookConfig): BlueprintDocumentWebhookResource;
|
|
@@ -1,71 +1,15 @@
|
|
|
1
|
+
import { validateDocumentWebhook } from '../index.js';
|
|
2
|
+
import { runValidation } from '../utils/validation.js';
|
|
1
3
|
export function defineDocumentWebhook(parameters) {
|
|
2
|
-
|
|
3
|
-
if (!parameters.
|
|
4
|
-
|
|
4
|
+
// default the display name
|
|
5
|
+
if (!parameters.displayName) {
|
|
6
|
+
parameters.displayName = parameters.name.substring(0, 100);
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
if (parameters.displayName.length > 100) {
|
|
8
|
-
errors.push('Display name must be 100 characters or less');
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
parameters.displayName = parameters.name?.substring(0, 100);
|
|
13
|
-
}
|
|
14
|
-
if (!parameters.url || parameters.url.trim() === '') {
|
|
15
|
-
errors.push('Webhook URL is required');
|
|
16
|
-
}
|
|
17
|
-
// Validate URL format
|
|
18
|
-
try {
|
|
19
|
-
new URL(parameters.url);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
errors.push('Webhook URL must be a valid URL');
|
|
23
|
-
}
|
|
24
|
-
if (!parameters.on || parameters.on.length === 0) {
|
|
25
|
-
errors.push('At least one event type must be specified in the "on" field');
|
|
26
|
-
}
|
|
27
|
-
// Validate event types
|
|
28
|
-
const validEvents = ['create', 'update', 'delete'];
|
|
29
|
-
if (parameters.on) {
|
|
30
|
-
const invalidEvents = parameters.on.filter((event) => !validEvents.includes(event));
|
|
31
|
-
if (invalidEvents.length > 0) {
|
|
32
|
-
errors.push(`Invalid event types: ${invalidEvents.join(', ')}. Valid events are: ${validEvents.join(', ')}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Validate dataset pattern
|
|
36
|
-
if (!parameters.dataset || !/^[a-z0-9-_]+$/.test(parameters.dataset)) {
|
|
37
|
-
errors.push('Dataset must match pattern: ^[a-z0-9-_]+$');
|
|
38
|
-
}
|
|
39
|
-
// Validate HTTP method
|
|
40
|
-
if (parameters.httpMethod) {
|
|
41
|
-
const validMethods = ['POST', 'PUT', 'PATCH', 'DELETE', 'GET'];
|
|
42
|
-
if (!validMethods.includes(parameters.httpMethod)) {
|
|
43
|
-
errors.push(`Invalid HTTP method: ${parameters.httpMethod}. Valid methods are: ${validMethods.join(', ')}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Validate status
|
|
47
|
-
if (parameters.status && !['enabled', 'disabled'].includes(parameters.status)) {
|
|
48
|
-
errors.push('Status must be either "enabled" or "disabled"');
|
|
49
|
-
}
|
|
50
|
-
// Validate headers pattern
|
|
51
|
-
if (parameters.headers) {
|
|
52
|
-
const headerNamePattern = /^[a-zA-Z][a-zA-Z0-9-_]*$/;
|
|
53
|
-
for (const [key, value] of Object.entries(parameters.headers)) {
|
|
54
|
-
if (!headerNamePattern.test(key)) {
|
|
55
|
-
errors.push(`Header key "${key}" must match pattern: ${headerNamePattern.source}`);
|
|
56
|
-
}
|
|
57
|
-
if (typeof value !== 'string') {
|
|
58
|
-
errors.push(`Header value for "${key}" must be a string`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (errors.length > 0) {
|
|
63
|
-
const message = errors.join('\n');
|
|
64
|
-
throw new Error(message);
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
8
|
+
const webhookResource = {
|
|
67
9
|
...parameters,
|
|
68
10
|
type: 'sanity.project.webhook',
|
|
69
11
|
};
|
|
12
|
+
runValidation(() => validateDocumentWebhook(webhookResource));
|
|
13
|
+
return webhookResource;
|
|
70
14
|
}
|
|
71
15
|
//# sourceMappingURL=webhooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/definers/webhooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/definers/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6E,uBAAuB,EAAC,MAAM,aAAa,CAAA;AAC/H,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAEpD,MAAM,UAAU,qBAAqB,CAAC,UAA0C;IAC9E,2BAA2B;IAC3B,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;QAC5B,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,eAAe,GAAqC;QACxD,GAAG,UAAU;QACb,IAAI,EAAE,wBAAwB;KAC/B,CAAA;IAED,aAAa,CAAC,GAAG,EAAE,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC,CAAA;IAE7D,OAAO,eAAe,CAAA;AACxB,CAAC"}
|