@webiny/api-headless-cms 0.0.0-unstable.9e825fd5fb → 0.0.0-unstable.ad3a7a4920
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/context.js +4 -3
- package/context.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +34 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +1 -1
- package/crud/contentEntry.crud.js +26 -90
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -5
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/validation.d.ts +48 -16
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +5 -190
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/schema/createFieldResolvers.js +2 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +44 -17
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/ref.js +7 -7
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +13 -9
- package/index.js.map +1 -1
- package/package.json +22 -22
- package/plugins/CmsModelPlugin.d.ts +3 -1
- package/plugins/CmsModelPlugin.js +5 -5
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +11 -0
- package/plugins/index.js.map +1 -1
- package/types.d.ts +43 -41
- package/types.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +19 -23
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.js +1 -2
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +2 -10
- package/utils/createTypeName.js.map +1 -1
|
@@ -59,14 +59,14 @@ const fieldSchema = _zod.default.object({
|
|
|
59
59
|
settings: _zod.default.object({}).passthrough().optional().nullish().transform(value => {
|
|
60
60
|
return value || {};
|
|
61
61
|
}).default({})
|
|
62
|
-
})).optional().default([]),
|
|
62
|
+
})).nullish().optional().default([]).transform(value => value || []),
|
|
63
63
|
listValidation: _zod.default.array(_zod.default.object({
|
|
64
64
|
name: shortString,
|
|
65
65
|
message: optionalShortString.default("Value is required."),
|
|
66
66
|
settings: _zod.default.object({}).passthrough().optional().nullish().transform(value => {
|
|
67
67
|
return value || {};
|
|
68
68
|
}).default({})
|
|
69
|
-
})).optional().default([]),
|
|
69
|
+
})).nullish().optional().default([]).transform(value => value || []),
|
|
70
70
|
settings: _zod.default.object({}).passthrough().optional().nullish().transform(value => {
|
|
71
71
|
return value || {};
|
|
72
72
|
}).default({})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fieldSystemFields","str","zod","string","trim","shortString","max","optionalShortString","optional","optionalNullishShortString","nullish","fieldSchema","object","id","storageId","transform","fieldId","regex","message","superRefine","value","ctx","includes","addIssue","code","ZodIssueCode","custom","path","label","helpText","default","placeholderText","nullable","type","tags","array","multipleValues","boolean","predefinedValues","enabled","values","selected","renderer","name","validation","settings","passthrough","listValidation","refinementValidation","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","createModelCreateValidation","modelId","singularApiName","refine","pluralApiName","description","group","icon","fields","layout","titleFieldId","descriptionFieldId","imageFieldId","defaultFields","createModelCreateFromValidation","locale","createModelUpdateValidation"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalNullishShortString = optionalShortString.nullish();\n\nconst fieldSchema = zod.object({\n id: shortString,\n storageId: zod\n .string()\n .optional()\n .transform(() => {\n return \"\";\n }),\n fieldId: shortString\n .max(100)\n .regex(/^!?[a-zA-Z]/, {\n message: `Provided value is not valid - must not start with a number.`\n })\n .regex(/^(^[a-zA-Z0-9]+)$/, {\n message: `Provided value is not valid - must be alphanumeric string.`\n })\n .superRefine((value, ctx) => {\n if (fieldSystemFields.includes(value)) {\n return ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `Provided ${value} is not valid - \"${value}\" is an auto-generated field.`,\n path: [\"fieldId\"]\n });\n }\n }),\n label: shortString,\n helpText: optionalShortString.optional().nullish().default(null),\n placeholderText: optionalShortString.optional().nullable().default(null),\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n multipleValues: zod\n .boolean()\n .optional()\n .nullish()\n .transform(value => {\n return !!value;\n })\n .default(false),\n predefinedValues: zod\n .object({\n enabled: zod.boolean(),\n values: zod\n .array(\n zod.object({\n value: shortString,\n label: shortString,\n selected: zod.boolean().optional().default(false)\n })\n )\n .default([])\n })\n .default({\n enabled: false,\n values: []\n })\n .optional(),\n renderer: zod\n .object({\n name: shortString\n })\n .optional(),\n validation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .optional()\n .default([]),\n listValidation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .optional()\n .default([]),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n});\n\nconst refinementValidation = (value: string): boolean => {\n return value === upperFirst(camelCase(value));\n};\nconst refinementSingularValidationMessage = (value?: string) => {\n return {\n message: `The Singular API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategory\" or \"CarMake\".`\n };\n};\nconst refinementPluralValidationMessage = (value?: string) => {\n return {\n message: `The Plural API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategories\" or \"CarMakes\".`\n };\n};\n\nexport const createModelCreateValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString,\n singularApiName: shortString.refine(\n refinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(refinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(shortString)).default([]),\n tags: zod.array(shortString).optional(),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n defaultFields: zod.boolean().nullish()\n });\n};\n\nexport const createModelCreateFromValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString,\n singularApiName: shortString.refine(\n refinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(refinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n locale: optionalShortString\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return refinementValidation(value);\n }, refinementSingularValidationMessage),\n pluralApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return refinementValidation(value);\n }, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(shortString)),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA,MAAMA,iBAA2B,GAAG,CAChC,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAED,MAAMC,GAAG,GAAGC,YAAG,CAACC,MAAM,EAAE,CAACC,IAAI,EAAE;AAC/B,MAAMC,WAAW,GAAGJ,GAAG,CAACK,GAAG,CAAC,GAAG,CAAC;AAChC,MAAMC,mBAAmB,GAAGF,WAAW,CAACG,QAAQ,EAAE;AAClD,MAAMC,0BAA0B,GAAGF,mBAAmB,CAACG,OAAO,EAAE;AAEhE,MAAMC,WAAW,GAAGT,YAAG,CAACU,MAAM,CA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AM,CAACpC,KAAK,IAAI;MACjD,IAAI,CAACA,KAAK,EAAE;QACR,OAAO,IAAI;MACf;MACA,OAAO4B,oBAAoB,CAAC5B,KAAK,CAAC;IACtC,CAAC,EAAE+B,mCAAmC,CAAC;IACvCM,aAAa,EAAElD,mBAAmB,CAACiD,MAAM,CAACpC,KAAK,IAAI;MAC/C,IAAI,CAACA,KAAK,EAAE;QACR,OAAO,IAAI;MACf;MACA,OAAO4B,oBAAoB,CAAC5B,KAAK,CAAC;IACtC,CAAC,EAAEgC,iCAAiC,CAAC;IACrCM,WAAW,EAAEjD,0BAA0B;IACvCkD,KAAK,EAAEpD,mBAAmB;IAC1BqD,IAAI,EAAEnD,0BAA0B;IAChCoD,MAAM,EAAE3D,YAAG,CAACiC,KAAK,CAACxB,WAAW,CAAC;IAC9BmD,MAAM,EAAE5D,YAAG,CAACiC,KAAK,CAACjC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAAC;IACzC0D,YAAY,EAAExD,mBAAmB,CAACG,OAAO,EAAE;IAC3CsD,kBAAkB,EAAEzD,mBAAmB,CAACG,OAAO,EAAE;IACjDuD,YAAY,EAAE1D,mBAAmB,CAACG,OAAO,EAAE;IAC3CwB,IAAI,EAAEhC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAACG,QAAQ;EACzC,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["fieldSystemFields","str","zod","string","trim","shortString","max","optionalShortString","optional","optionalNullishShortString","nullish","fieldSchema","object","id","storageId","transform","fieldId","regex","message","superRefine","value","ctx","includes","addIssue","code","ZodIssueCode","custom","path","label","helpText","default","placeholderText","nullable","type","tags","array","multipleValues","boolean","predefinedValues","enabled","values","selected","renderer","name","validation","settings","passthrough","listValidation","refinementValidation","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","createModelCreateValidation","modelId","singularApiName","refine","pluralApiName","description","group","icon","fields","layout","titleFieldId","descriptionFieldId","imageFieldId","defaultFields","createModelCreateFromValidation","locale","createModelUpdateValidation"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalNullishShortString = optionalShortString.nullish();\n\nconst fieldSchema = zod.object({\n id: shortString,\n storageId: zod\n .string()\n .optional()\n .transform(() => {\n return \"\";\n }),\n fieldId: shortString\n .max(100)\n .regex(/^!?[a-zA-Z]/, {\n message: `Provided value is not valid - must not start with a number.`\n })\n .regex(/^(^[a-zA-Z0-9]+)$/, {\n message: `Provided value is not valid - must be alphanumeric string.`\n })\n .superRefine((value, ctx) => {\n if (fieldSystemFields.includes(value)) {\n return ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `Provided ${value} is not valid - \"${value}\" is an auto-generated field.`,\n path: [\"fieldId\"]\n });\n }\n }),\n label: shortString,\n helpText: optionalShortString.optional().nullish().default(null),\n placeholderText: optionalShortString.optional().nullable().default(null),\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n multipleValues: zod\n .boolean()\n .optional()\n .nullish()\n .transform(value => {\n return !!value;\n })\n .default(false),\n predefinedValues: zod\n .object({\n enabled: zod.boolean(),\n values: zod\n .array(\n zod.object({\n value: shortString,\n label: shortString,\n selected: zod.boolean().optional().default(false)\n })\n )\n .default([])\n })\n .default({\n enabled: false,\n values: []\n })\n .optional(),\n renderer: zod\n .object({\n name: shortString\n })\n .optional(),\n validation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n listValidation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n});\n\nconst refinementValidation = (value: string): boolean => {\n return value === upperFirst(camelCase(value));\n};\nconst refinementSingularValidationMessage = (value?: string) => {\n return {\n message: `The Singular API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategory\" or \"CarMake\".`\n };\n};\nconst refinementPluralValidationMessage = (value?: string) => {\n return {\n message: `The Plural API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategories\" or \"CarMakes\".`\n };\n};\n\nexport const createModelCreateValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString,\n singularApiName: shortString.refine(\n refinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(refinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(shortString)).default([]),\n tags: zod.array(shortString).optional(),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n defaultFields: zod.boolean().nullish()\n });\n};\n\nexport const createModelCreateFromValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString,\n singularApiName: shortString.refine(\n refinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(refinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n locale: optionalShortString\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return refinementValidation(value);\n }, refinementSingularValidationMessage),\n pluralApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return refinementValidation(value);\n }, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(shortString)),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA,MAAMA,iBAA2B,GAAG,CAChC,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAED,MAAMC,GAAG,GAAGC,YAAG,CAACC,MAAM,EAAE,CAACC,IAAI,EAAE;AAC/B,MAAMC,WAAW,GAAGJ,GAAG,CAACK,GAAG,CAAC,GAAG,CAAC;AAChC,MAAMC,mBAAmB,GAAGF,WAAW,CAACG,QAAQ,EAAE;AAClD,MAAMC,0BAA0B,GAAGF,mBAAmB,CAACG,OAAO,EAAE;AAEhE,MAAMC,WAAW,GAAGT,YAAG,CAACU,MAAM,CAAC;EAC3BC,EAAE,EAAER,WAAW;EACfS,SAAS,EAAEZ,YAAG,CACTC,MAAM,EAAE,CACRK,QAAQ,EAAE,CACVO,SAAS,CAAC,MAAM;IACb,OAAO,EAAE;EACb,CAAC,CAAC;EACNC,OAAO,EAAEX,WAAW,CACfC,GAAG,CAAC,GAAG,CAAC,CACRW,KAAK,CAAC,aAAa,EAAE;IAClBC,OAAO,EAAG;EACd,CAAC,CAAC,CACDD,KAAK,CAAC,m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AAC;IACvCM,aAAa,EAAElD,mBAAmB,CAACiD,MAAM,CAACpC,KAAK,IAAI;MAC/C,IAAI,CAACA,KAAK,EAAE;QACR,OAAO,IAAI;MACf;MACA,OAAO4B,oBAAoB,CAAC5B,KAAK,CAAC;IACtC,CAAC,EAAEgC,iCAAiC,CAAC;IACrCM,WAAW,EAAEjD,0BAA0B;IACvCkD,KAAK,EAAEpD,mBAAmB;IAC1BqD,IAAI,EAAEnD,0BAA0B;IAChCoD,MAAM,EAAE3D,YAAG,CAACiC,KAAK,CAACxB,WAAW,CAAC;IAC9BmD,MAAM,EAAE5D,YAAG,CAACiC,KAAK,CAACjC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAAC;IACzC0D,YAAY,EAAExD,mBAAmB,CAACG,OAAO,EAAE;IAC3CsD,kBAAkB,EAAEzD,mBAAmB,CAACG,OAAO,EAAE;IACjDuD,YAAY,EAAE1D,mBAAmB,CAACG,OAAO,EAAE;IAC3CwB,IAAI,EAAEhC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAACG,QAAQ;EACzC,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkEndpointAccess = void 0;
|
|
7
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
8
|
+
const checkEndpointAccess = async context => {
|
|
9
|
+
const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
|
|
10
|
+
if (!permission) {
|
|
11
|
+
throw new _apiSecurity.NotAuthorizedError({
|
|
12
|
+
data: {
|
|
13
|
+
reason: `Not allowed to access "${context.cms.type}" endpoint.`
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.checkEndpointAccess = checkEndpointAccess;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["checkEndpointAccess","context","permission","security","getPermission","cms","type","NotAuthorizedError","data","reason"],"sources":["checkEndpointAccess.ts"],"sourcesContent":["import { CmsContext } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const checkEndpointAccess = async (context: CmsContext): Promise<void> => {\n const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access \"${context.cms.type}\" endpoint.`\n }\n });\n }\n};\n"],"mappings":";;;;;;AACA;AAEO,MAAMA,mBAAmB,GAAG,MAAOC,OAAmB,IAAoB;EAC7E,MAAMC,UAAU,GAAG,MAAMD,OAAO,CAACE,QAAQ,CAACC,aAAa,CAAE,gBAAeH,OAAO,CAACI,GAAG,CAACC,IAAK,EAAC,CAAC;EAC3F,IAAI,CAACJ,UAAU,EAAE;IACb,MAAM,IAAIK,+BAAkB,CAAC;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG,0BAAyBR,OAAO,CAACI,GAAG,CAACC,IAAK;MACvD;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRequestBody = void 0;
|
|
7
|
+
const createRequestBody = body => {
|
|
8
|
+
/**
|
|
9
|
+
* We are trusting that the body payload is correct.
|
|
10
|
+
* The `processRequestBody` will fail if it is not.
|
|
11
|
+
*/
|
|
12
|
+
return typeof body === "string" ? JSON.parse(body) : body;
|
|
13
|
+
};
|
|
14
|
+
exports.createRequestBody = createRequestBody;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createRequestBody","body","JSON","parse"],"sources":["createRequestBody.ts"],"sourcesContent":["import { GraphQLRequestBody } from \"@webiny/handler-graphql/types\";\n\nexport const createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,iBAAiB,GAAIC,IAAa,IAAgD;EAC3F;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatErrorPayload: (error: Error) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.formatErrorPayload = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const formatErrorPayload = error => {
|
|
10
|
+
if (error instanceof _error.default) {
|
|
11
|
+
return JSON.stringify({
|
|
12
|
+
type: "CmsGraphQLWebinyError",
|
|
13
|
+
message: error.message,
|
|
14
|
+
code: error.code,
|
|
15
|
+
data: error.data
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return JSON.stringify({
|
|
19
|
+
type: "Error",
|
|
20
|
+
name: error.name,
|
|
21
|
+
message: error.message,
|
|
22
|
+
stack: error.stack
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.formatErrorPayload = formatErrorPayload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatErrorPayload","error","WebinyError","JSON","stringify","type","message","code","data","name","stack"],"sources":["formatErrorPayload.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport const formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CmsGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,kBAAkB,GAAIC,KAAY,IAAa;EACxD,IAAIA,KAAK,YAAYC,cAAW,EAAE;IAC9B,OAAOC,IAAI,CAACC,SAAS,CAAC;MAClBC,IAAI,EAAE,uBAAuB;MAC7BC,OAAO,EAAEL,KAAK,CAACK,OAAO;MACtBC,IAAI,EAAEN,KAAK,CAACM,IAAI;MAChBC,IAAI,EAAEP,KAAK,CAACO;IAChB,CAAC,CAAC;EACN;EAEA,OAAOL,IAAI,CAACC,SAAS,CAAC;IAClBC,IAAI,EAAE,OAAO;IACbI,IAAI,EAAER,KAAK,CAACQ,IAAI;IAChBH,OAAO,EAAEL,KAAK,CAACK,OAAO;IACtBI,KAAK,EAAET,KAAK,CAACS;EACjB,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","log","plugins","register","schemaPlugins","byType","CmsGraphQLSchemaPlugin","type","createExecutableSchema"],"sources":["generateSchema.ts"],"sourcesContent":["import { CmsContext, CmsModel } from \"~/types\";\nimport { buildSchemaPlugins } from \"
|
|
1
|
+
{"version":3,"names":["generateSchema","params","context","models","generatedSchemaPlugins","buildSchemaPlugins","ex","console","log","plugins","register","schemaPlugins","byType","CmsGraphQLSchemaPlugin","type","createExecutableSchema"],"sources":["generateSchema.ts"],"sourcesContent":["import { CmsContext, CmsModel } from \"~/types\";\nimport { buildSchemaPlugins } from \"./buildSchemaPlugins\";\nimport { createExecutableSchema } from \"./createExecutableSchema\";\nimport { GraphQLSchema } from \"graphql/type\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\ninterface GenerateSchemaParams {\n context: CmsContext;\n models: CmsModel[];\n}\nexport const generateSchema = async (params: GenerateSchemaParams): Promise<GraphQLSchema> => {\n const { context, models } = params;\n\n let generatedSchemaPlugins: CmsGraphQLSchemaPlugin[] = [];\n try {\n generatedSchemaPlugins = await buildSchemaPlugins({ context, models });\n } catch (ex) {\n console.log(`Error while building schema plugins.`);\n throw ex;\n }\n\n context.plugins.register(generatedSchemaPlugins);\n\n const schemaPlugins = context.plugins.byType<CmsGraphQLSchemaPlugin>(\n CmsGraphQLSchemaPlugin.type\n );\n return createExecutableSchema({\n plugins: schemaPlugins\n });\n};\n"],"mappings":";;;;;;AACA;AACA;AAEA;AAMO,MAAMA,cAAc,GAAG,MAAOC,MAA4B,IAA6B;EAC1F,MAAM;IAAEC,OAAO;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAElC,IAAIG,sBAAgD,GAAG,EAAE;EACzD,IAAI;IACAA,sBAAsB,GAAG,MAAM,IAAAC,sCAAkB,EAAC;MAAEH,OAAO;MAAEC;IAAO,CAAC,CAAC;EAC1E,CAAC,CAAC,OAAOG,EAAE,EAAE;IACTC,OAAO,CAACC,GAAG,CAAE,sCAAqC,CAAC;IACnD,MAAMF,EAAE;EACZ;EAEAJ,OAAO,CAACO,OAAO,CAACC,QAAQ,CAACN,sBAAsB,CAAC;EAEhD,MAAMO,aAAa,GAAGT,OAAO,CAACO,OAAO,CAACG,MAAM,CACxCC,+BAAsB,CAACC,IAAI,CAC9B;EACD,OAAO,IAAAC,8CAAsB,EAAC;IAC1BN,OAAO,EAAEE;EACb,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiEndpoint, CmsContext } from "../types";
|
|
2
|
+
import { Tenant } from "@webiny/api-tenancy/types";
|
|
3
|
+
import { I18NLocale } from "@webiny/api-i18n/types";
|
|
4
|
+
import { GraphQLSchema } from "graphql";
|
|
5
|
+
interface GetSchemaParams {
|
|
6
|
+
context: CmsContext;
|
|
7
|
+
type: ApiEndpoint;
|
|
8
|
+
getLastModifiedTime: () => Promise<Date | null>;
|
|
9
|
+
getTenant: () => Tenant;
|
|
10
|
+
getLocale: () => I18NLocale;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets an existing schema or rewrites existing one or creates a completely new one
|
|
14
|
+
* depending on the schemaId created from type and locale parameters
|
|
15
|
+
*/
|
|
16
|
+
export declare const getSchema: (params: GetSchemaParams) => Promise<GraphQLSchema>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSchema = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _codeFrame = _interopRequireDefault(require("code-frame"));
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
var _generateSchema = require("./generateSchema");
|
|
12
|
+
// @ts-ignore `code-frame` has no types
|
|
13
|
+
|
|
14
|
+
const schemaList = new Map();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Method generates cache ID based on:
|
|
18
|
+
* - tenant
|
|
19
|
+
* - endpoint type
|
|
20
|
+
* - locale
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const generateCacheId = params => {
|
|
24
|
+
const {
|
|
25
|
+
getTenant,
|
|
26
|
+
type,
|
|
27
|
+
getLocale
|
|
28
|
+
} = params;
|
|
29
|
+
return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join("#");
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Method generates cache key based on last model change time.
|
|
33
|
+
* Or sets "unknown" - possible when no models in database.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const generateCacheKey = async params => {
|
|
37
|
+
const {
|
|
38
|
+
getLastModifiedTime
|
|
39
|
+
} = params;
|
|
40
|
+
const lastModelChange = await getLastModifiedTime();
|
|
41
|
+
if (!lastModelChange) {
|
|
42
|
+
return "unknown";
|
|
43
|
+
}
|
|
44
|
+
return lastModelChange.toISOString();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Gets an existing schema or rewrites existing one or creates a completely new one
|
|
49
|
+
* depending on the schemaId created from type and locale parameters
|
|
50
|
+
*/
|
|
51
|
+
const getSchema = async params => {
|
|
52
|
+
const {
|
|
53
|
+
context
|
|
54
|
+
} = params;
|
|
55
|
+
const cacheId = generateCacheId(params);
|
|
56
|
+
const cacheKey = await generateCacheKey(params);
|
|
57
|
+
const cachedSchema = schemaList.get(cacheId);
|
|
58
|
+
if ((cachedSchema === null || cachedSchema === void 0 ? void 0 : cachedSchema.key) === cacheKey) {
|
|
59
|
+
return cachedSchema.schema;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* We need all the API models.
|
|
64
|
+
* Private models are hidden in the GraphQL, so filter them out.
|
|
65
|
+
*/
|
|
66
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
67
|
+
return (await context.cms.listModels()).filter(model => {
|
|
68
|
+
return model.isPrivate !== true;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
const schema = await (0, _generateSchema.generateSchema)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
73
|
+
models
|
|
74
|
+
}));
|
|
75
|
+
schemaList.set(cacheId, {
|
|
76
|
+
key: cacheKey,
|
|
77
|
+
schema
|
|
78
|
+
});
|
|
79
|
+
return schema;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (!Array.isArray(err.locations)) {
|
|
82
|
+
throw new _error.default({
|
|
83
|
+
message: err.message,
|
|
84
|
+
code: err.code || "INVALID_GRAPHQL_SCHEMA_LOCATIONS",
|
|
85
|
+
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, err.data || {}), {}, {
|
|
86
|
+
locations: err.locations
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const [location] = err.locations;
|
|
91
|
+
throw new _error.default({
|
|
92
|
+
code: "INVALID_GRAPHQL_SCHEMA",
|
|
93
|
+
message: err.message,
|
|
94
|
+
data: {
|
|
95
|
+
invalidSegment: (0, _codeFrame.default)(err.source.body, location.line, location.column, {
|
|
96
|
+
frameSize: 15
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.getSchema = getSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["schemaList","Map","generateCacheId","params","getTenant","type","getLocale","id","code","join","generateCacheKey","getLastModifiedTime","lastModelChange","toISOString","getSchema","context","cacheId","cacheKey","cachedSchema","get","key","schema","models","security","withoutAuthorization","cms","listModels","filter","model","isPrivate","generateSchema","set","err","Array","isArray","locations","WebinyError","message","data","location","invalidSegment","codeFrame","source","body","line","column","frameSize"],"sources":["getSchema.ts"],"sourcesContent":["// @ts-ignore `code-frame` has no types\nimport codeFrame from \"code-frame\";\nimport WebinyError from \"@webiny/error\";\nimport { generateSchema } from \"./generateSchema\";\nimport { ApiEndpoint, CmsContext } from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { GraphQLSchema } from \"graphql\";\n\ninterface SchemaCache {\n key: string;\n schema: GraphQLSchema;\n}\n\ninterface GetSchemaParams {\n context: CmsContext;\n type: ApiEndpoint;\n getLastModifiedTime: () => Promise<Date | null>;\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n}\n\nconst schemaList = new Map<string, SchemaCache>();\n\n/**\n * Method generates cache ID based on:\n * - tenant\n * - endpoint type\n * - locale\n */\ntype GenerateCacheIdParams = Pick<GetSchemaParams, \"getTenant\" | \"getLocale\" | \"type\">;\nconst generateCacheId = (params: GenerateCacheIdParams): string => {\n const { getTenant, type, getLocale } = params;\n return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join(\"#\");\n};\n/**\n * Method generates cache key based on last model change time.\n * Or sets \"unknown\" - possible when no models in database.\n */\ntype GenerateCacheKeyParams = Pick<GetSchemaParams, \"getLastModifiedTime\">;\nconst generateCacheKey = async (params: GenerateCacheKeyParams): Promise<string> => {\n const { getLastModifiedTime } = params;\n const lastModelChange = await getLastModifiedTime();\n if (!lastModelChange) {\n return \"unknown\";\n }\n return lastModelChange.toISOString();\n};\n\n/**\n * Gets an existing schema or rewrites existing one or creates a completely new one\n * depending on the schemaId created from type and locale parameters\n */\nexport const getSchema = async (params: GetSchemaParams): Promise<GraphQLSchema> => {\n const { context } = params;\n\n const cacheId = generateCacheId(params);\n\n const cacheKey = await generateCacheKey(params);\n const cachedSchema = schemaList.get(cacheId);\n if (cachedSchema?.key === cacheKey) {\n return cachedSchema.schema;\n }\n\n /**\n * We need all the API models.\n * Private models are hidden in the GraphQL, so filter them out.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n return model.isPrivate !== true;\n });\n });\n try {\n const schema = await generateSchema({\n ...params,\n models\n });\n schemaList.set(cacheId, {\n key: cacheKey,\n schema\n });\n return schema;\n } catch (err) {\n if (!Array.isArray(err.locations)) {\n throw new WebinyError({\n message: err.message,\n code: err.code || \"INVALID_GRAPHQL_SCHEMA_LOCATIONS\",\n data: {\n ...(err.data || {}),\n locations: err.locations\n }\n });\n }\n const [location] = err.locations;\n\n throw new WebinyError({\n code: \"INVALID_GRAPHQL_SCHEMA\",\n message: err.message,\n data: {\n invalidSegment: codeFrame(err.source.body, location.line, location.column, {\n frameSize: 15\n })\n }\n });\n }\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAHA;;AAsBA,MAAMA,UAAU,GAAG,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K,CAACC,SAAS,KAAK,IAAI;IACnC,CAAC,CAAC;EACN,CAAC,CAAC;EACF,IAAI;IACA,MAAMR,MAAM,GAAG,MAAM,IAAAS,8BAAc,8DAC5B3B,MAAM;MACTmB;IAAM,GACR;IACFtB,UAAU,CAAC+B,GAAG,CAACf,OAAO,EAAE;MACpBI,GAAG,EAAEH,QAAQ;MACbI;IACJ,CAAC,CAAC;IACF,OAAOA,MAAM;EACjB,CAAC,CAAC,OAAOW,GAAG,EAAE;IACV,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,GAAG,CAACG,SAAS,CAAC,EAAE;MAC/B,MAAM,IAAIC,cAAW,CAAC;QAClBC,OAAO,EAAEL,GAAG,CAACK,OAAO;QACpB7B,IAAI,EAAEwB,GAAG,CAACxB,IAAI,IAAI,kCAAkC;QACpD8B,IAAI,8DACIN,GAAG,CAACM,IAAI,IAAI,CAAC,CAAC;UAClBH,SAAS,EAAEH,GAAG,CAACG;QAAS;MAEhC,CAAC,CAAC;IACN;IACA,MAAM,CAACI,QAAQ,CAAC,GAAGP,GAAG,CAACG,SAAS;IAEhC,MAAM,IAAIC,cAAW,CAAC;MAClB5B,IAAI,EAAE,wBAAwB;MAC9B6B,OAAO,EAAEL,GAAG,CAACK,OAAO;MACpBC,IAAI,EAAE;QACFE,cAAc,EAAE,IAAAC,kBAAS,EAACT,GAAG,CAACU,MAAM,CAACC,IAAI,EAAEJ,QAAQ,CAACK,IAAI,EAAEL,QAAQ,CAACM,MAAM,EAAE;UACvEC,SAAS,EAAE;QACf,CAAC;MACL;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC"}
|
|
@@ -5,205 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.graphQLHandlerFactory = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _codeFrame = _interopRequireDefault(require("code-frame"));
|
|
11
8
|
var _debugPlugins = _interopRequireDefault(require("@webiny/handler-graphql/debugPlugins"));
|
|
12
|
-
var _processRequestBody = _interopRequireDefault(require("@webiny/handler-graphql/processRequestBody"));
|
|
13
|
-
var _apiSecurity = require("@webiny/api-security");
|
|
14
9
|
var _handler = require("@webiny/handler");
|
|
15
|
-
var
|
|
16
|
-
// @ts-ignore `code-frame` has no types
|
|
17
|
-
|
|
18
|
-
const createRequestBody = body => {
|
|
19
|
-
/**
|
|
20
|
-
* We are trusting that the body payload is correct.
|
|
21
|
-
* The `processRequestBody` will fail if it is not.
|
|
22
|
-
*/
|
|
23
|
-
return typeof body === "string" ? JSON.parse(body) : body;
|
|
24
|
-
};
|
|
25
|
-
const schemaList = new Map();
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Method generates cache ID based on:
|
|
29
|
-
* - tenant
|
|
30
|
-
* - endpoint type
|
|
31
|
-
* - locale
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
const generateCacheId = params => {
|
|
35
|
-
const {
|
|
36
|
-
getTenant,
|
|
37
|
-
type,
|
|
38
|
-
getLocale
|
|
39
|
-
} = params;
|
|
40
|
-
return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join("#");
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Method generates cache key based on last model change time.
|
|
44
|
-
* Or sets "unknown" - possible when no models in database.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
const generateCacheKey = async params => {
|
|
48
|
-
const {
|
|
49
|
-
getLastModifiedTime
|
|
50
|
-
} = params;
|
|
51
|
-
const lastModelChange = await getLastModifiedTime();
|
|
52
|
-
if (!lastModelChange) {
|
|
53
|
-
return "unknown";
|
|
54
|
-
}
|
|
55
|
-
return lastModelChange.toISOString();
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Gets an existing schema or rewrites existing one or creates a completely new one
|
|
60
|
-
* depending on the schemaId created from type and locale parameters
|
|
61
|
-
*/
|
|
62
|
-
const getSchema = async params => {
|
|
63
|
-
const {
|
|
64
|
-
context
|
|
65
|
-
} = params;
|
|
66
|
-
const cacheId = generateCacheId(params);
|
|
67
|
-
const cacheKey = await generateCacheKey(params);
|
|
68
|
-
const cachedSchema = schemaList.get(cacheId);
|
|
69
|
-
if ((cachedSchema === null || cachedSchema === void 0 ? void 0 : cachedSchema.key) === cacheKey) {
|
|
70
|
-
return cachedSchema.schema;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* We need all the API models.
|
|
75
|
-
* Private models are hidden in the GraphQL, so filter them out.
|
|
76
|
-
*/
|
|
77
|
-
const models = await context.security.withoutAuthorization(async () => {
|
|
78
|
-
return (await context.cms.listModels()).filter(model => {
|
|
79
|
-
return model.isPrivate !== true;
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
try {
|
|
83
|
-
const schema = await (0, _generateSchema.generateSchema)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
84
|
-
models
|
|
85
|
-
}));
|
|
86
|
-
schemaList.set(cacheId, {
|
|
87
|
-
key: cacheKey,
|
|
88
|
-
schema
|
|
89
|
-
});
|
|
90
|
-
return schema;
|
|
91
|
-
} catch (err) {
|
|
92
|
-
if (!Array.isArray(err.locations)) {
|
|
93
|
-
throw new _error.default({
|
|
94
|
-
message: err.message,
|
|
95
|
-
code: err.code || "INVALID_GRAPHQL_SCHEMA_LOCATIONS",
|
|
96
|
-
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, err.data || {}), {}, {
|
|
97
|
-
locations: err.locations
|
|
98
|
-
})
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
const [location] = err.locations;
|
|
102
|
-
throw new _error.default({
|
|
103
|
-
code: "INVALID_GRAPHQL_SCHEMA",
|
|
104
|
-
message: err.message,
|
|
105
|
-
data: {
|
|
106
|
-
invalidSegment: (0, _codeFrame.default)(err.source.body, location.line, location.column, {
|
|
107
|
-
frameSize: 15
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const checkEndpointAccess = async context => {
|
|
114
|
-
const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);
|
|
115
|
-
if (!permission) {
|
|
116
|
-
throw new _apiSecurity.NotAuthorizedError({
|
|
117
|
-
data: {
|
|
118
|
-
reason: `Not allowed to access "${context.cms.type}" endpoint.`
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const formatErrorPayload = error => {
|
|
124
|
-
if (error instanceof _error.default) {
|
|
125
|
-
return JSON.stringify({
|
|
126
|
-
type: "CmsGraphQLWebinyError",
|
|
127
|
-
message: error.message,
|
|
128
|
-
code: error.code,
|
|
129
|
-
data: error.data
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return JSON.stringify({
|
|
133
|
-
type: "Error",
|
|
134
|
-
name: error.name,
|
|
135
|
-
message: error.message,
|
|
136
|
-
stack: error.stack
|
|
137
|
-
});
|
|
138
|
-
};
|
|
10
|
+
var _handleRequest = require("./handleRequest");
|
|
139
11
|
const cmsRoutes = new _handler.RoutePlugin(({
|
|
140
12
|
onPost,
|
|
141
13
|
onOptions,
|
|
142
14
|
context
|
|
143
15
|
}) => {
|
|
144
16
|
onPost("/cms/:type(^manage|preview|read$)/:locale", async (request, reply) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
data: null,
|
|
150
|
-
error: {
|
|
151
|
-
message: ex.message || "Not authorized!",
|
|
152
|
-
code: ex.code || "SECURITY_NOT_AUTHORIZED",
|
|
153
|
-
data: ex.data || null,
|
|
154
|
-
stack: null
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
const getTenant = () => {
|
|
159
|
-
return context.tenancy.getCurrentTenant();
|
|
160
|
-
};
|
|
161
|
-
const getLocale = () => {
|
|
162
|
-
return context.cms.getLocale();
|
|
163
|
-
};
|
|
164
|
-
const getLastModifiedTime = async () => {
|
|
165
|
-
return context.cms.getModelLastChange();
|
|
166
|
-
};
|
|
167
|
-
const schema = await context.benchmark.measure("headlessCms.graphql.getSchema", async () => {
|
|
168
|
-
try {
|
|
169
|
-
return await getSchema({
|
|
170
|
-
context,
|
|
171
|
-
getTenant,
|
|
172
|
-
getLastModifiedTime,
|
|
173
|
-
getLocale,
|
|
174
|
-
type: context.cms.type
|
|
175
|
-
});
|
|
176
|
-
} catch (ex) {
|
|
177
|
-
console.error(`Error while generating the schema.`);
|
|
178
|
-
console.error(formatErrorPayload(ex));
|
|
179
|
-
throw ex;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
const body = await context.benchmark.measure("headlessCms.graphql.createRequestBody", async () => {
|
|
183
|
-
try {
|
|
184
|
-
return createRequestBody(request.body);
|
|
185
|
-
} catch (ex) {
|
|
186
|
-
console.error(`Error while creating the body request.`);
|
|
187
|
-
console.error(formatErrorPayload(ex));
|
|
188
|
-
throw ex;
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* We need to store the processRequestBody result in a variable and output it after the measurement.
|
|
194
|
-
* Otherwise, the measurement will not be shown in the output.
|
|
195
|
-
*/
|
|
196
|
-
let result = null;
|
|
197
|
-
await context.benchmark.measure("headlessCms.graphql.processRequestBody", async () => {
|
|
198
|
-
try {
|
|
199
|
-
result = await (0, _processRequestBody.default)(body, schema, context);
|
|
200
|
-
} catch (ex) {
|
|
201
|
-
console.error(`Error while processing the body request.`);
|
|
202
|
-
console.error(formatErrorPayload(ex));
|
|
203
|
-
throw ex;
|
|
204
|
-
}
|
|
17
|
+
return (0, _handleRequest.handleRequest)({
|
|
18
|
+
context,
|
|
19
|
+
request,
|
|
20
|
+
reply
|
|
205
21
|
});
|
|
206
|
-
return reply.code(200).send(result);
|
|
207
22
|
});
|
|
208
23
|
onOptions("/cms/:type(^manage|preview|read$)/:locale", async (_, reply) => {
|
|
209
24
|
return reply.status(204).send({}).hijack();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createRequestBody","body","JSON","parse","schemaList","Map","generateCacheId","params","getTenant","type","getLocale","id","code","join","generateCacheKey","getLastModifiedTime","lastModelChange","toISOString","getSchema","context","cacheId","cacheKey","cachedSchema","get","key","schema","models","security","withoutAuthorization","cms","listModels","filter","model","isPrivate","generateSchema","set","err","Array","isArray","locations","WebinyError","message","data","location","invalidSegment","codeFrame","source","line","column","frameSize","checkEndpointAccess","permission","getPermission","NotAuthorizedError","reason","formatErrorPayload","error","stringify","name","stack","cmsRoutes","RoutePlugin","onPost","onOptions","request","reply","ex","send","tenancy","getCurrentTenant","getModelLastChange","benchmark","measure","console","result","processRequestBody","_","status","hijack","graphQLHandlerFactory","debug","debugPlugins"],"sources":["graphQLHandlerFactory.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n// @ts-ignore `code-frame` has no types\nimport codeFrame from \"code-frame\";\nimport debugPlugins from \"@webiny/handler-graphql/debugPlugins\";\nimport processRequestBody from \"@webiny/handler-graphql/processRequestBody\";\nimport { ExecutionResult, GraphQLSchema } from \"graphql\";\nimport { ApiEndpoint, CmsContext } from \"~/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { GraphQLRequestBody } from \"@webiny/handler-graphql/types\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport { generateSchema } from \"~/graphql/generateSchema\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\n\ninterface SchemaCache {\n key: string;\n schema: GraphQLSchema;\n}\n\ninterface GetSchemaParams {\n context: CmsContext;\n type: ApiEndpoint;\n getLastModifiedTime: () => Promise<Date | null>;\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n}\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst schemaList = new Map<string, SchemaCache>();\n\n/**\n * Method generates cache ID based on:\n * - tenant\n * - endpoint type\n * - locale\n */\ntype GenerateCacheIdParams = Pick<GetSchemaParams, \"getTenant\" | \"getLocale\" | \"type\">;\nconst generateCacheId = (params: GenerateCacheIdParams): string => {\n const { getTenant, type, getLocale } = params;\n return [`tenant:${getTenant().id}`, `endpoint:${type}`, `locale:${getLocale().code}`].join(\"#\");\n};\n/**\n * Method generates cache key based on last model change time.\n * Or sets \"unknown\" - possible when no models in database.\n */\ntype GenerateCacheKeyParams = Pick<GetSchemaParams, \"getLastModifiedTime\">;\nconst generateCacheKey = async (params: GenerateCacheKeyParams): Promise<string> => {\n const { getLastModifiedTime } = params;\n const lastModelChange = await getLastModifiedTime();\n if (!lastModelChange) {\n return \"unknown\";\n }\n return lastModelChange.toISOString();\n};\n\n/**\n * Gets an existing schema or rewrites existing one or creates a completely new one\n * depending on the schemaId created from type and locale parameters\n */\nconst getSchema = async (params: GetSchemaParams): Promise<GraphQLSchema> => {\n const { context } = params;\n\n const cacheId = generateCacheId(params);\n\n const cacheKey = await generateCacheKey(params);\n const cachedSchema = schemaList.get(cacheId);\n if (cachedSchema?.key === cacheKey) {\n return cachedSchema.schema;\n }\n\n /**\n * We need all the API models.\n * Private models are hidden in the GraphQL, so filter them out.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n return model.isPrivate !== true;\n });\n });\n try {\n const schema = await generateSchema({\n ...params,\n models\n });\n schemaList.set(cacheId, {\n key: cacheKey,\n schema\n });\n return schema;\n } catch (err) {\n if (!Array.isArray(err.locations)) {\n throw new WebinyError({\n message: err.message,\n code: err.code || \"INVALID_GRAPHQL_SCHEMA_LOCATIONS\",\n data: {\n ...(err.data || {}),\n locations: err.locations\n }\n });\n }\n const [location] = err.locations;\n\n throw new WebinyError({\n code: \"INVALID_GRAPHQL_SCHEMA\",\n message: err.message,\n data: {\n invalidSegment: codeFrame(err.source.body, location.line, location.column, {\n frameSize: 15\n })\n }\n });\n }\n};\n\nconst checkEndpointAccess = async (context: CmsContext): Promise<void> => {\n const permission = await context.security.getPermission(`cms.endpoint.${context.cms.type}`);\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access \"${context.cms.type}\" endpoint.`\n }\n });\n }\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CmsGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport interface GraphQLHandlerFactoryParams {\n debug?: boolean;\n}\n\nconst cmsRoutes = new RoutePlugin<CmsContext>(({ onPost, onOptions, context }) => {\n onPost(\"/cms/:type(^manage|preview|read$)/:locale\", async (request, reply) => {\n try {\n await checkEndpointAccess(context);\n } catch (ex) {\n return reply.code(401).send({\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n });\n }\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n const getLocale = () => {\n return context.cms.getLocale();\n };\n\n const getLastModifiedTime = async () => {\n return context.cms.getModelLastChange();\n };\n\n const schema = await context.benchmark.measure(\n \"headlessCms.graphql.getSchema\",\n async () => {\n try {\n return await getSchema({\n context,\n getTenant,\n getLastModifiedTime,\n getLocale,\n type: context.cms.type as ApiEndpoint\n });\n } catch (ex) {\n console.error(`Error while generating the schema.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n }\n );\n\n const body = await context.benchmark.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => {\n try {\n return createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n }\n );\n\n /**\n * We need to store the processRequestBody result in a variable and output it after the measurement.\n * Otherwise, the measurement will not be shown in the output.\n */\n let result: ExecutionResult[] | ExecutionResult | null = null;\n\n await context.benchmark.measure(\"headlessCms.graphql.processRequestBody\", async () => {\n try {\n result = await processRequestBody(body, schema, context);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n\n return reply.code(200).send(result);\n });\n\n onOptions(\"/cms/:type(^manage|preview|read$)/:locale\", async (_, reply) => {\n return reply.status(204).send({}).hijack();\n });\n});\n\ncmsRoutes.name = \"headless-cms.graphql.route.default\";\n\nexport const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): PluginCollection => {\n return [\n ...(debug ? debugPlugins() : []),\n cmsRoutes,\n {\n type: \"wcp-telemetry-tracker\"\n }\n ];\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AACA;AACA;AAIA;AAGA;AACA;AAXA;;AA2BA,MAAMA,iBAAiB,GAAIC,IAAa,IAAgD;EACpF;AACJ;AACA;AACA;EACI,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAAGC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC,GAAGA,IAAI;AAC7D,CAAC;AAED,MAAMG,UAAU,GAAG,IAAIC,GAAG,EAAuB;;AAEjD;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,eAAe,GAAIC,MAA6B,IAAa;EAC/D,MAAM;IAAEC,SAAS;IAAEC,IAAI;IAAEC;EAAU,CAAC,GAAGH,MAAM;EAC7C,OAAO,CAAE,UAASC,SAAS,EAAE,CAACG,EAAG,EAAC,EAAG,YAAWF,IAAK,EAAC,EAAG,UAASC,SAAS,EAAE,CAACE,IAAK,EAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;AACnG,CAAC;AAC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MAAM,CAAC;EACvC,CAAC,CAAC;EAEFX,SAAS,CAAC,2CAA2C,EAAE,OAAOa,CAAC,EAAEX,KAAK,KAAK;IACvE,OAAOA,KAAK,CAACY,MAAM,CAAC,GAAG,CAAC,CAACV,IAAI,CAAC,CAAC,CAAC,CAAC,CAACW,MAAM,EAAE;EAC9C,CAAC,CAAC;AACN,CAAC,CAAC;AAEFlB,SAAS,CAACF,IAAI,GAAG,oCAAoC;AAE9C,MAAMqB,qBAAqB,GAAG,CAAC;EAAEC;AAAmC,CAAC,KAAuB;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChCrB,SAAS,EACT;IACInD,IAAI,EAAE;EACV,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["cmsRoutes","RoutePlugin","onPost","onOptions","context","request","reply","handleRequest","_","status","send","hijack","name","graphQLHandlerFactory","debug","debugPlugins","type"],"sources":["graphQLHandlerFactory.ts"],"sourcesContent":["import debugPlugins from \"@webiny/handler-graphql/debugPlugins\";\nimport { CmsContext } from \"~/types\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport { handleRequest } from \"./handleRequest\";\n\nexport interface GraphQLHandlerFactoryParams {\n debug?: boolean;\n}\n\nconst cmsRoutes = new RoutePlugin<CmsContext>(({ onPost, onOptions, context }) => {\n onPost(\"/cms/:type(^manage|preview|read$)/:locale\", async (request, reply) => {\n return handleRequest({ context, request, reply });\n });\n\n onOptions(\"/cms/:type(^manage|preview|read$)/:locale\", async (_, reply) => {\n return reply.status(204).send({}).hijack();\n });\n});\n\ncmsRoutes.name = \"headless-cms.graphql.route.default\";\n\nexport const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): PluginCollection => {\n return [\n ...(debug ? debugPlugins() : []),\n cmsRoutes,\n {\n type: \"wcp-telemetry-tracker\"\n }\n ];\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AAMA,MAAMA,SAAS,GAAG,IAAIC,oBAAW,CAAa,CAAC;EAAEC,MAAM;EAAEC,SAAS;EAAEC;AAAQ,CAAC,KAAK;EAC9EF,MAAM,CAAC,2CAA2C,EAAE,OAAOG,OAAO,EAAEC,KAAK,KAAK;IAC1E,OAAO,IAAAC,4BAAa,EAAC;MAAEH,OAAO;MAAEC,OAAO;MAAEC;IAAM,CAAC,CAAC;EACrD,CAAC,CAAC;EAEFH,SAAS,CAAC,2CAA2C,EAAE,OAAOK,CAAC,EAAEF,KAAK,KAAK;IACvE,OAAOA,KAAK,CAACG,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC,CAAC,CAACC,MAAM,EAAE;EAC9C,CAAC,CAAC;AACN,CAAC,CAAC;AAEFX,SAAS,CAACY,IAAI,GAAG,oCAAoC;AAE9C,MAAMC,qBAAqB,GAAG,CAAC;EAAEC;AAAmC,CAAC,KAAuB;EAC/F,OAAO,CACH,IAAIA,KAAK,GAAG,IAAAC,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChCf,SAAS,EACT;IACIgB,IAAI,EAAE;EACV,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CmsContext } from "../types";
|
|
2
|
+
import { Reply, Request } from "@webiny/handler/types";
|
|
3
|
+
export interface HandleRequestParams {
|
|
4
|
+
context: CmsContext;
|
|
5
|
+
request: Request;
|
|
6
|
+
reply: Reply;
|
|
7
|
+
}
|
|
8
|
+
export interface HandleRequest {
|
|
9
|
+
(params: HandleRequestParams): Promise<Reply>;
|
|
10
|
+
}
|
|
11
|
+
export declare const handleRequest: HandleRequest;
|