@webiny/api-aco 0.0.0-unstable.da99e0b846 → 0.0.0-unstable.de38392959
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/apps/AcoApp.d.ts +21 -0
- package/apps/AcoApp.js +143 -0
- package/apps/AcoApp.js.map +1 -0
- package/apps/AcoApps.d.ts +10 -0
- package/apps/AcoApps.js +75 -0
- package/apps/AcoApps.js.map +1 -0
- package/apps/app.gql.d.ts +3 -0
- package/apps/app.gql.js +60 -0
- package/apps/app.gql.js.map +1 -0
- package/apps/index.d.ts +2 -0
- package/apps/index.js +29 -0
- package/apps/index.js.map +1 -0
- package/createAcoContext.d.ts +5 -1
- package/createAcoContext.js +159 -28
- package/createAcoContext.js.map +1 -1
- package/createAcoGraphQL.d.ts +2 -2
- package/createAcoGraphQL.js +39 -6
- package/createAcoGraphQL.js.map +1 -1
- package/createAcoHooks.js +9 -3
- package/createAcoHooks.js.map +1 -1
- package/createAcoModels.js +6 -42
- package/createAcoModels.js.map +1 -1
- package/createAcoStorageOperations.d.ts +0 -1
- package/createAcoStorageOperations.js +10 -7
- package/createAcoStorageOperations.js.map +1 -1
- package/filter/filter.crud.d.ts +3 -0
- package/filter/filter.crud.js +94 -0
- package/filter/filter.crud.js.map +1 -0
- package/filter/filter.gql.d.ts +3 -0
- package/filter/filter.gql.js +153 -0
- package/filter/filter.gql.js.map +1 -0
- package/filter/filter.model.d.ts +2 -0
- package/filter/filter.model.js +125 -0
- package/filter/filter.model.js.map +1 -0
- package/filter/filter.so.d.ts +3 -0
- package/filter/filter.so.js +98 -0
- package/filter/filter.so.js.map +1 -0
- package/filter/filter.types.d.ts +95 -0
- package/filter/filter.types.js +14 -0
- package/filter/filter.types.js.map +1 -0
- package/folder/folder.crud.d.ts +8 -1
- package/folder/folder.crud.js +201 -4
- package/folder/folder.crud.js.map +1 -1
- package/folder/folder.gql.js +98 -6
- package/folder/folder.gql.js.map +1 -1
- package/folder/folder.model.d.ts +1 -3
- package/folder/folder.model.js +54 -25
- package/folder/folder.model.js.map +1 -1
- package/folder/folder.so.js +38 -18
- package/folder/folder.so.js.map +1 -1
- package/folder/folder.types.d.ts +35 -3
- package/folder/folder.types.js +3 -1
- package/folder/folder.types.js.map +1 -1
- package/folder/onFolderBeforeDeleteAco.hook.d.ts +2 -0
- package/folder/onFolderBeforeDeleteAco.hook.js +67 -0
- package/folder/onFolderBeforeDeleteAco.hook.js.map +1 -0
- package/folder/onFolderBeforeDeleteFm.hook.d.ts +2 -0
- package/folder/onFolderBeforeDeleteFm.hook.js +49 -0
- package/folder/onFolderBeforeDeleteFm.hook.js.map +1 -0
- package/folder/onFolderBeforeDeleteHcms.hook.d.ts +2 -0
- package/folder/onFolderBeforeDeleteHcms.hook.js +56 -0
- package/folder/onFolderBeforeDeleteHcms.hook.js.map +1 -0
- package/index.d.ts +9 -1
- package/index.js +56 -5
- package/index.js.map +1 -1
- package/package.json +38 -32
- package/plugins/AcoAppModifierPlugin.d.ts +43 -0
- package/plugins/AcoAppModifierPlugin.js +58 -0
- package/plugins/AcoAppModifierPlugin.js.map +1 -0
- package/plugins/AcoAppRegisterPlugin.d.ts +8 -0
- package/plugins/AcoAppRegisterPlugin.js +21 -0
- package/plugins/AcoAppRegisterPlugin.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +29 -0
- package/plugins/index.js.map +1 -0
- package/record/graphql/createAppResolvers.d.ts +14 -0
- package/record/graphql/createAppResolvers.js +115 -0
- package/record/graphql/createAppResolvers.js.map +1 -0
- package/record/graphql/createAppSchema.d.ts +9 -0
- package/record/graphql/createAppSchema.js +147 -0
- package/record/graphql/createAppSchema.js.map +1 -0
- package/record/record.crud.js +49 -13
- package/record/record.crud.js.map +1 -1
- package/record/record.gql.d.ts +8 -3
- package/record/record.gql.js +38 -112
- package/record/record.gql.js.map +1 -1
- package/record/record.model.d.ts +7 -3
- package/record/record.model.js +42 -13
- package/record/record.model.js.map +1 -1
- package/record/record.so.js +109 -37
- package/record/record.so.js.map +1 -1
- package/record/record.types.d.ts +71 -18
- package/record/record.types.js +3 -1
- package/record/record.types.js.map +1 -1
- package/types.d.ts +69 -8
- package/types.js +52 -4
- package/types.js.map +1 -1
- package/utils/FolderLevelPermissions.d.ts +71 -0
- package/utils/FolderLevelPermissions.js +353 -0
- package/utils/FolderLevelPermissions.js.map +1 -0
- package/utils/acoRecordId.d.ts +6 -0
- package/utils/acoRecordId.js +35 -0
- package/utils/acoRecordId.js.map +1 -0
- package/utils/createListSort.js +3 -1
- package/utils/createListSort.js.map +1 -1
- package/utils/createModelField.js +3 -1
- package/utils/createModelField.js.map +1 -1
- package/utils/createOperationsWrapper.js +3 -1
- package/utils/createOperationsWrapper.js.map +1 -1
- package/utils/decorators/CmsEntriesCrudDecorators.d.ts +11 -0
- package/utils/decorators/CmsEntriesCrudDecorators.js +190 -0
- package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -0
- package/utils/decorators/constants.d.ts +1 -0
- package/utils/decorators/constants.js +10 -0
- package/utils/decorators/constants.js.map +1 -0
- package/utils/decorators/createFolderType.d.ts +2 -0
- package/utils/decorators/createFolderType.js +18 -0
- package/utils/decorators/createFolderType.js.map +1 -0
- package/utils/decorators/filterEntriesByFolderFactory.d.ts +6 -0
- package/utils/decorators/filterEntriesByFolderFactory.js +37 -0
- package/utils/decorators/filterEntriesByFolderFactory.js.map +1 -0
- package/utils/decorators/isPageModel.d.ts +5 -0
- package/utils/decorators/isPageModel.js +20 -0
- package/utils/decorators/isPageModel.js.map +1 -0
- package/utils/decorators/where.d.ts +15 -0
- package/utils/decorators/where.js +60 -0
- package/utils/decorators/where.js.map +1 -0
- package/utils/ensureAuthentication.d.ts +2 -0
- package/utils/ensureAuthentication.js +16 -0
- package/utils/ensureAuthentication.js.map +1 -0
- package/utils/getFolderAndItsAncestors.d.ts +7 -0
- package/utils/getFolderAndItsAncestors.js +53 -0
- package/utils/getFolderAndItsAncestors.js.map +1 -0
- package/utils/isInstallationPending.js +3 -1
- package/utils/isInstallationPending.js.map +1 -1
- package/utils/modelFactory.d.ts +1 -3
- package/utils/modelFactory.js +7 -10
- package/utils/modelFactory.js.map +1 -1
- package/utils/pickEntryFieldValues.d.ts +3 -0
- package/utils/pickEntryFieldValues.js +31 -0
- package/utils/pickEntryFieldValues.js.map +1 -0
- package/utils/resolve.d.ts +3 -2
- package/utils/resolve.js +13 -2
- package/utils/resolve.js.map +1 -1
- package/context/folders.d.ts +0 -2
- package/context/folders.js +0 -261
- package/context/folders.js.map +0 -1
- package/context/index.d.ts +0 -2
- package/context/index.js +0 -22
- package/context/index.js.map +0 -1
- package/context/links.d.ts +0 -2
- package/context/links.js +0 -270
- package/context/links.js.map +0 -1
- package/createAcoCrud.d.ts +0 -2
- package/createAcoCrud.js +0 -17
- package/createAcoCrud.js.map +0 -1
- package/createAcoFields.d.ts +0 -2
- package/createAcoFields.js +0 -40
- package/createAcoFields.js.map +0 -1
- package/folder/onFolderBeforeDelete.hook.d.ts +0 -2
- package/folder/onFolderBeforeDelete.hook.js +0 -53
- package/folder/onFolderBeforeDelete.hook.js.map +0 -1
- package/graphql/base.gql.d.ts +0 -3
- package/graphql/base.gql.js +0 -63
- package/graphql/base.gql.js.map +0 -1
- package/graphql/folders.gql.d.ts +0 -3
- package/graphql/folders.gql.js +0 -126
- package/graphql/folders.gql.js.map +0 -1
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +0 -15
- package/graphql/index.js.map +0 -1
- package/graphql/links.gql.d.ts +0 -3
- package/graphql/links.gql.js +0 -123
- package/graphql/links.gql.js.map +0 -1
- package/subscriptions/afterFolderDelete.d.ts +0 -3
- package/subscriptions/afterFolderDelete.js +0 -62
- package/subscriptions/afterFolderDelete.js.map +0 -1
- package/subscriptions/index.d.ts +0 -3
- package/subscriptions/index.js +0 -14
- package/subscriptions/index.js.map +0 -1
- package/utils/fieldResolver.d.ts +0 -16
- package/utils/fieldResolver.js +0 -44
- package/utils/fieldResolver.js.map +0 -1
- package/utils/getFieldValues.d.ts +0 -2
- package/utils/getFieldValues.js +0 -19
- package/utils/getFieldValues.js.map +0 -1
package/apps/AcoApp.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AcoContext, AcoSearchRecordCrudBase, IAcoApp, IAcoAppModifyFieldCallableCallback, IAcoAppParams } from "../types";
|
|
2
|
+
import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
|
|
3
|
+
export declare class AcoApp implements IAcoApp {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly context: AcoContext;
|
|
6
|
+
readonly model: CmsModel;
|
|
7
|
+
private readonly fields;
|
|
8
|
+
private readonly onEntry?;
|
|
9
|
+
private readonly onEntryList?;
|
|
10
|
+
private readonly onAnyRequest?;
|
|
11
|
+
get search(): AcoSearchRecordCrudBase;
|
|
12
|
+
get folder(): import("../types").AcoFolderCrud;
|
|
13
|
+
private getModel;
|
|
14
|
+
private constructor();
|
|
15
|
+
static create(context: AcoContext, params: IAcoAppParams): AcoApp;
|
|
16
|
+
getFields(): CmsModelField[];
|
|
17
|
+
addField(field: CmsModelField): void;
|
|
18
|
+
removeField(id: string): void;
|
|
19
|
+
modifyField(id: string, cb: IAcoAppModifyFieldCallableCallback): void;
|
|
20
|
+
private execOnAnyRequest;
|
|
21
|
+
}
|
package/apps/AcoApp.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.AcoApp = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
10
|
+
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
11
|
+
var _record = require("../record/record.model");
|
|
12
|
+
const createApiName = name => {
|
|
13
|
+
return (0, _upperFirst.default)((0, _camelCase.default)(name));
|
|
14
|
+
};
|
|
15
|
+
class AcoApp {
|
|
16
|
+
get search() {
|
|
17
|
+
return {
|
|
18
|
+
create: async data => {
|
|
19
|
+
await this.execOnAnyRequest("create");
|
|
20
|
+
const result = await this.context.aco.search.create(this.getModel(), data);
|
|
21
|
+
if (!this.onEntry) {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
return this.onEntry(result);
|
|
25
|
+
},
|
|
26
|
+
update: async (id, data) => {
|
|
27
|
+
await this.execOnAnyRequest("update");
|
|
28
|
+
const result = await this.context.aco.search.update(this.getModel(), id, data);
|
|
29
|
+
if (!this.onEntry) {
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
return this.onEntry(result);
|
|
33
|
+
},
|
|
34
|
+
move: async (id, folderId) => {
|
|
35
|
+
await this.execOnAnyRequest("move");
|
|
36
|
+
return this.context.aco.search.move(this.getModel(), id, folderId);
|
|
37
|
+
},
|
|
38
|
+
get: async id => {
|
|
39
|
+
await this.execOnAnyRequest("fetch");
|
|
40
|
+
const result = await this.context.aco.search.get(this.getModel(), id);
|
|
41
|
+
if (!result || !this.onEntry) {
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return this.onEntry(result);
|
|
45
|
+
},
|
|
46
|
+
list: async params => {
|
|
47
|
+
await this.execOnAnyRequest("fetch");
|
|
48
|
+
const result = await this.context.aco.search.list(this.getModel(), params);
|
|
49
|
+
const onEntryList = this.onEntryList;
|
|
50
|
+
if (!onEntryList) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
const [entries, meta] = result;
|
|
54
|
+
const items = await onEntryList(entries);
|
|
55
|
+
return [items, meta];
|
|
56
|
+
},
|
|
57
|
+
delete: async id => {
|
|
58
|
+
await this.execOnAnyRequest("delete");
|
|
59
|
+
return this.context.aco.search.delete(this.getModel(), id);
|
|
60
|
+
},
|
|
61
|
+
listTags: async params => {
|
|
62
|
+
await this.execOnAnyRequest("fetch");
|
|
63
|
+
return this.context.aco.search.listTags(this.getModel(), params);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
get folder() {
|
|
68
|
+
return this.context.aco.folder;
|
|
69
|
+
}
|
|
70
|
+
getModel() {
|
|
71
|
+
const tenant = this.context.tenancy.getCurrentTenant().id;
|
|
72
|
+
const locale = this.context.i18n.getContentLocale().code;
|
|
73
|
+
return {
|
|
74
|
+
...this.model,
|
|
75
|
+
tenant,
|
|
76
|
+
locale
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
constructor(context, params) {
|
|
80
|
+
this.context = context;
|
|
81
|
+
this.name = params.name;
|
|
82
|
+
this.onEntry = params.onEntry;
|
|
83
|
+
this.onEntryList = params.onEntryList;
|
|
84
|
+
this.model = structuredClone(params.model);
|
|
85
|
+
/**
|
|
86
|
+
* We can safely define the api name of the model as we control everything here.
|
|
87
|
+
*/
|
|
88
|
+
this.model.name = `${this.model.name} ${this.name}`;
|
|
89
|
+
this.model.modelId = `${this.model.modelId}-${this.name.toLowerCase()}`;
|
|
90
|
+
const apiName = `AcoSearchRecord${createApiName(params.apiName)}`;
|
|
91
|
+
this.model.singularApiName = apiName;
|
|
92
|
+
this.model.pluralApiName = apiName;
|
|
93
|
+
const index = this.model.fields.findIndex(f => f.fieldId === "data");
|
|
94
|
+
if (index === -1) {
|
|
95
|
+
throw new _error.default(`The "data" field does not exist in model "${this.model.modelId}".`, "MODEL_DATA_FIELD_ERROR", {
|
|
96
|
+
modelId: this.model.modelId
|
|
97
|
+
});
|
|
98
|
+
} else if (!this.model.fields[index].settings?.fields) {
|
|
99
|
+
this.model.fields[index].settings.fields = [];
|
|
100
|
+
}
|
|
101
|
+
this.fields = this.model.fields[index].settings.fields;
|
|
102
|
+
this.fields.push(...params.fields);
|
|
103
|
+
}
|
|
104
|
+
static create(context, params) {
|
|
105
|
+
return new AcoApp(context, params);
|
|
106
|
+
}
|
|
107
|
+
getFields() {
|
|
108
|
+
return this.fields;
|
|
109
|
+
}
|
|
110
|
+
addField(field) {
|
|
111
|
+
this.fields.push(field);
|
|
112
|
+
}
|
|
113
|
+
removeField(id) {
|
|
114
|
+
if (_record.DEFAULT_FIELDS.includes(id)) {
|
|
115
|
+
throw new _error.default(`Cannot remove the default field from the ACO App.`, "REMOVE_DEFAULT_FIELD_ERROR", {
|
|
116
|
+
fieldId: id
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const index = this.fields.findIndex(field => field.id === id);
|
|
120
|
+
if (index === -1) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.fields.splice(index, 1);
|
|
124
|
+
}
|
|
125
|
+
modifyField(id, cb) {
|
|
126
|
+
const index = this.fields.findIndex(field => field.id === id);
|
|
127
|
+
if (index === -1) {
|
|
128
|
+
throw new _error.default(`There is no field "${id}" in app "${this.name}".`, "FIELD_NOT_FOUND_ERROR", {
|
|
129
|
+
id
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
this.fields[index] = cb(structuredClone(this.fields[index]));
|
|
133
|
+
}
|
|
134
|
+
async execOnAnyRequest(action) {
|
|
135
|
+
if (!this.onAnyRequest) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
await this.onAnyRequest(this.context, action);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.AcoApp = AcoApp;
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=AcoApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_upperFirst","_camelCase","_record","createApiName","name","lodashUpperFirst","lodashCamelCase","AcoApp","search","create","data","execOnAnyRequest","result","context","aco","getModel","onEntry","update","id","move","folderId","get","list","params","onEntryList","entries","meta","items","delete","listTags","folder","tenant","tenancy","getCurrentTenant","locale","i18n","getContentLocale","code","model","constructor","structuredClone","modelId","toLowerCase","apiName","singularApiName","pluralApiName","index","fields","findIndex","f","fieldId","WebinyError","settings","push","getFields","addField","field","removeField","DEFAULT_FIELDS","includes","splice","modifyField","cb","action","onAnyRequest","exports"],"sources":["AcoApp.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n AcoContext,\n AcoRequestAction,\n AcoSearchRecordCrudBase,\n CreateSearchRecordParams,\n IAcoApp,\n IAcoAppModifyFieldCallableCallback,\n IAcoAppOnAnyRequest,\n IAcoAppOnEntry,\n IAcoAppOnEntryList,\n IAcoAppParams,\n ListSearchRecordsParams,\n ListSearchRecordTagsParams,\n SearchRecord\n} from \"~/types\";\nimport { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport lodashUpperFirst from \"lodash/upperFirst\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport { DEFAULT_FIELDS } from \"~/record/record.model\";\n\nconst createApiName = (name: string) => {\n return lodashUpperFirst(lodashCamelCase(name));\n};\n\nexport class AcoApp implements IAcoApp {\n public readonly name: string;\n public readonly context: AcoContext;\n public readonly model: CmsModel;\n private readonly fields: CmsModelField[];\n private readonly onEntry?: IAcoAppOnEntry;\n private readonly onEntryList?: IAcoAppOnEntryList;\n private readonly onAnyRequest?: IAcoAppOnAnyRequest;\n\n public get search(): AcoSearchRecordCrudBase {\n return {\n create: async <TData>(data: CreateSearchRecordParams<TData>) => {\n await this.execOnAnyRequest(\"create\");\n const result = await this.context.aco.search.create<TData>(this.getModel(), data);\n if (!this.onEntry) {\n return result;\n }\n return this.onEntry(result);\n },\n update: async <TData>(id: string, data: SearchRecord<TData>) => {\n await this.execOnAnyRequest(\"update\");\n const result = await this.context.aco.search.update<TData>(\n this.getModel(),\n id,\n data\n );\n if (!this.onEntry) {\n return result;\n }\n return this.onEntry(result);\n },\n move: async (id: string, folderId?: string) => {\n await this.execOnAnyRequest(\"move\");\n return this.context.aco.search.move(this.getModel(), id, folderId);\n },\n get: async <TData>(id: string) => {\n await this.execOnAnyRequest(\"fetch\");\n const result = await this.context.aco.search.get<TData>(this.getModel(), id);\n if (!result || !this.onEntry) {\n return result;\n }\n return this.onEntry(result);\n },\n list: async <TData>(params: ListSearchRecordsParams) => {\n await this.execOnAnyRequest(\"fetch\");\n const result = await this.context.aco.search.list<TData>(this.getModel(), params);\n const onEntryList = this.onEntryList;\n if (!onEntryList) {\n return result;\n }\n const [entries, meta] = result;\n const items = await onEntryList(entries);\n return [items, meta];\n },\n delete: async (id: string): Promise<boolean> => {\n await this.execOnAnyRequest(\"delete\");\n return this.context.aco.search.delete(this.getModel(), id);\n },\n listTags: async (params: ListSearchRecordTagsParams) => {\n await this.execOnAnyRequest(\"fetch\");\n return this.context.aco.search.listTags(this.getModel(), params);\n }\n };\n }\n\n public get folder() {\n return this.context.aco.folder;\n }\n\n private getModel() {\n const tenant = this.context.tenancy.getCurrentTenant().id;\n const locale = this.context.i18n.getContentLocale()!.code;\n\n return { ...this.model, tenant, locale };\n }\n\n private constructor(context: AcoContext, params: IAcoAppParams) {\n this.context = context;\n this.name = params.name;\n this.onEntry = params.onEntry;\n this.onEntryList = params.onEntryList;\n this.model = structuredClone(params.model);\n /**\n * We can safely define the api name of the model as we control everything here.\n */\n this.model.name = `${this.model.name} ${this.name}`;\n this.model.modelId = `${this.model.modelId}-${this.name.toLowerCase()}`;\n const apiName = `AcoSearchRecord${createApiName(params.apiName)}`;\n this.model.singularApiName = apiName;\n this.model.pluralApiName = apiName;\n\n const index = this.model.fields.findIndex(f => f.fieldId === \"data\");\n if (index === -1) {\n throw new WebinyError(\n `The \"data\" field does not exist in model \"${this.model.modelId}\".`,\n \"MODEL_DATA_FIELD_ERROR\",\n {\n modelId: this.model.modelId\n }\n );\n } else if (!this.model.fields[index].settings?.fields) {\n this.model.fields[index].settings!.fields = [];\n }\n this.fields = this.model.fields[index].settings!.fields as CmsModelField[];\n this.fields.push(...params.fields);\n }\n\n public static create(context: AcoContext, params: IAcoAppParams) {\n return new AcoApp(context, params);\n }\n\n public getFields(): CmsModelField[] {\n return this.fields;\n }\n\n public addField(field: CmsModelField): void {\n this.fields.push(field);\n }\n\n public removeField(id: string): void {\n if (DEFAULT_FIELDS.includes(id)) {\n throw new WebinyError(\n `Cannot remove the default field from the ACO App.`,\n \"REMOVE_DEFAULT_FIELD_ERROR\",\n {\n fieldId: id\n }\n );\n }\n const index = this.fields.findIndex(field => field.id === id);\n if (index === -1) {\n return;\n }\n this.fields.splice(index, 1);\n }\n\n public modifyField(id: string, cb: IAcoAppModifyFieldCallableCallback): void {\n const index = this.fields.findIndex(field => field.id === id);\n if (index === -1) {\n throw new WebinyError(\n `There is no field \"${id}\" in app \"${this.name}\".`,\n \"FIELD_NOT_FOUND_ERROR\",\n {\n id\n }\n );\n }\n this.fields[index] = cb(structuredClone(this.fields[index]));\n }\n\n private async execOnAnyRequest(action: AcoRequestAction): Promise<void> {\n if (!this.onAnyRequest) {\n return;\n }\n await this.onAnyRequest(this.context, action);\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAiBA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,MAAMI,aAAa,GAAIC,IAAY,IAAK;EACpC,OAAO,IAAAC,mBAAgB,EAAC,IAAAC,kBAAe,EAACF,IAAI,CAAC,CAAC;AAClD,CAAC;AAEM,MAAMG,MAAM,CAAoB;EASnC,IAAWC,MAAMA,CAAA,EAA4B;IACzC,OAAO;MACHC,MAAM,EAAE,MAAcC,IAAqC,IAAK;QAC5D,MAAM,IAAI,CAACC,gBAAgB,CAAC,QAAQ,CAAC;QACrC,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACC,OAAO,CAACC,GAAG,CAACN,MAAM,CAACC,MAAM,CAAQ,IAAI,CAACM,QAAQ,CAAC,CAAC,EAAEL,IAAI,CAAC;QACjF,IAAI,CAAC,IAAI,CAACM,OAAO,EAAE;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,sBAAqBjC,EAAG,aAAY,IAAI,CAACd,IAAK,IAAG,EAClD,uBAAuB,EACvB;QACIc;MACJ,CACJ,CAAC;IACL;IACA,IAAI,CAAC6B,MAAM,CAACD,KAAK,CAAC,GAAGgB,EAAE,CAACtB,eAAe,CAAC,IAAI,CAACO,MAAM,CAACD,KAAK,CAAC,CAAC,CAAC;EAChE;EAEA,MAAcnC,gBAAgBA,CAACoD,MAAwB,EAAiB;IACpE,IAAI,CAAC,IAAI,CAACC,YAAY,EAAE;MACpB;IACJ;IACA,MAAM,IAAI,CAACA,YAAY,CAAC,IAAI,CAACnD,OAAO,EAAEkD,MAAM,CAAC;EACjD;AACJ;AAACE,OAAA,CAAA1D,MAAA,GAAAA,MAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AcoContext, IAcoApp, IAcoAppParams, IAcoApps, IAcoAppsOptions } from "../types";
|
|
2
|
+
export declare class AcoApps implements IAcoApps {
|
|
3
|
+
private readonly apps;
|
|
4
|
+
private readonly context;
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(context: AcoContext, options: IAcoAppsOptions);
|
|
7
|
+
get(name: string): IAcoApp;
|
|
8
|
+
list(): IAcoApp[];
|
|
9
|
+
register(options: IAcoAppParams): Promise<IAcoApp>;
|
|
10
|
+
}
|
package/apps/AcoApps.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.AcoApps = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _AcoApp = require("./AcoApp");
|
|
10
|
+
var _plugins = require("../plugins");
|
|
11
|
+
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
12
|
+
var _record = require("../record/record.gql");
|
|
13
|
+
class AcoApps {
|
|
14
|
+
apps = new Map();
|
|
15
|
+
constructor(context, options) {
|
|
16
|
+
this.context = context;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
get(name) {
|
|
20
|
+
const app = this.apps.get(name);
|
|
21
|
+
if (app) {
|
|
22
|
+
return app;
|
|
23
|
+
}
|
|
24
|
+
throw new _error.default(`App "${name}" is not registered.`, "APP_NOT_REGISTERED", {
|
|
25
|
+
name,
|
|
26
|
+
apps: Array.from(this.apps.keys())
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
list() {
|
|
30
|
+
return Array.from(this.apps.values());
|
|
31
|
+
}
|
|
32
|
+
async register(options) {
|
|
33
|
+
const exists = this.apps.has(options.name);
|
|
34
|
+
if (exists) {
|
|
35
|
+
throw new _error.default(`An app with the name "${options.name}" is already registered.`, "APP_EXISTS", {
|
|
36
|
+
name: options.name
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* We need to create the app and run the modifiers on it.
|
|
41
|
+
*/
|
|
42
|
+
const app = _AcoApp.AcoApp.create(this.context, options);
|
|
43
|
+
const modifiers = this.context.plugins.byType(_plugins.AcoAppModifierPlugin.type);
|
|
44
|
+
for (const modifier of modifiers) {
|
|
45
|
+
if (modifier.canUse(app) === false) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await modifier.modify({
|
|
49
|
+
context: this.context,
|
|
50
|
+
app
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Also, we need to register the app model as the plugin one, so it can be used in the CMS.
|
|
55
|
+
* We do not need to validate model or show it in the API.
|
|
56
|
+
*/
|
|
57
|
+
this.context.plugins.register(new _apiHeadlessCms.CmsModelPlugin({
|
|
58
|
+
...app.model,
|
|
59
|
+
singularApiName: undefined,
|
|
60
|
+
pluralApiName: undefined,
|
|
61
|
+
isPrivate: true,
|
|
62
|
+
noValidate: true
|
|
63
|
+
}));
|
|
64
|
+
this.apps.set(app.name, app);
|
|
65
|
+
const searchRecordSchema = await (0, _record.createSchema)({
|
|
66
|
+
context: this.context,
|
|
67
|
+
app
|
|
68
|
+
});
|
|
69
|
+
this.context.plugins.register(searchRecordSchema);
|
|
70
|
+
return app;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.AcoApps = AcoApps;
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=AcoApps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_AcoApp","_plugins","_apiHeadlessCms","_record","AcoApps","apps","Map","constructor","context","options","get","name","app","WebinyError","Array","from","keys","list","values","register","exists","has","AcoApp","create","modifiers","plugins","byType","AcoAppModifierPlugin","type","modifier","canUse","modify","CmsModelPlugin","model","singularApiName","undefined","pluralApiName","isPrivate","noValidate","set","searchRecordSchema","createSchema","exports"],"sources":["AcoApps.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { AcoApp } from \"./AcoApp\";\nimport { AcoAppModifierPlugin } from \"~/plugins\";\nimport { AcoContext, IAcoApp, IAcoAppParams, IAcoApps, IAcoAppsOptions } from \"~/types\";\nimport { CmsModelPlugin } from \"@webiny/api-headless-cms\";\nimport { createSchema } from \"~/record/record.gql\";\n\nexport class AcoApps implements IAcoApps {\n private readonly apps: Map<string, IAcoApp> = new Map();\n private readonly context: AcoContext;\n private readonly options: IAcoAppsOptions;\n\n public constructor(context: AcoContext, options: IAcoAppsOptions) {\n this.context = context;\n this.options = options;\n }\n\n public get(name: string): IAcoApp {\n const app = this.apps.get(name);\n if (app) {\n return app;\n }\n throw new WebinyError(`App \"${name}\" is not registered.`, \"APP_NOT_REGISTERED\", {\n name,\n apps: Array.from(this.apps.keys())\n });\n }\n\n public list(): IAcoApp[] {\n return Array.from(this.apps.values());\n }\n\n public async register(options: IAcoAppParams): Promise<IAcoApp> {\n const exists = this.apps.has(options.name);\n if (exists) {\n throw new WebinyError(\n `An app with the name \"${options.name}\" is already registered.`,\n \"APP_EXISTS\",\n {\n name: options.name\n }\n );\n }\n /**\n * We need to create the app and run the modifiers on it.\n */\n const app = AcoApp.create(this.context, options);\n const modifiers = this.context.plugins.byType<AcoAppModifierPlugin>(\n AcoAppModifierPlugin.type\n );\n for (const modifier of modifiers) {\n if (modifier.canUse(app) === false) {\n continue;\n }\n await modifier.modify({\n context: this.context,\n app\n });\n }\n /**\n * Also, we need to register the app model as the plugin one, so it can be used in the CMS.\n * We do not need to validate model or show it in the API.\n */\n this.context.plugins.register(\n new CmsModelPlugin({\n ...app.model,\n singularApiName: undefined,\n pluralApiName: undefined,\n isPrivate: true,\n noValidate: true\n })\n );\n this.apps.set(app.name, app);\n\n const searchRecordSchema = await createSchema({\n context: this.context,\n app\n });\n this.context.plugins.register(searchRecordSchema);\n\n return app;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEO,MAAMK,OAAO,CAAqB;EACpBC,IAAI,GAAyB,IAAIC,GAAG,CAAC,CAAC;EAIhDC,WAAWA,CAACC,OAAmB,EAAEC,OAAwB,EAAE;IAC9D,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEOC,GAAGA,CAACC,IAAY,EAAW;IAC9B,MAAMC,GAAG,GAAG,IAAI,CAACP,IAAI,CAACK,GAAG,CAACC,IAAI,CAAC;IAC/B,IAAIC,GAAG,EAAE;MACL,OAAOA,GAAG;IACd;IACA,MAAM,IAAIC,cAAW,CAAE,QAAOF,IAAK,sBAAqB,EAAE,oBAAoB,EAAE;MAC5EA,IAAI;MACJN,IAAI,EAAES,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,IAAI,CAACW,IA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MAAM4B,kBAAkB,GAAG,MAAM,IAAAC,oBAAY,EAAC;MAC1CjC,OAAO,EAAE,IAAI,CAACA,OAAO;MACrBI;IACJ,CAAC,CAAC;IACF,IAAI,CAACJ,OAAO,CAACiB,OAAO,CAACN,QAAQ,CAACqB,kBAAkB,CAAC;IAEjD,OAAO5B,GAAG;EACd;AACJ;AAAC8B,OAAA,CAAAtC,OAAA,GAAAA,OAAA"}
|
package/apps/app.gql.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.appGql = void 0;
|
|
8
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
9
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
10
|
+
var _ensureAuthentication = require("../utils/ensureAuthentication");
|
|
11
|
+
var _resolve = require("../utils/resolve");
|
|
12
|
+
const cleanModel = model => {
|
|
13
|
+
return (0, _omit.default)(model, ["webinyVersion", "tags", "locale", "tenant", "layout", "group", "description", "isPrivate"]);
|
|
14
|
+
};
|
|
15
|
+
const appGql = new _handlerGraphql.GraphQLSchemaPlugin({
|
|
16
|
+
typeDefs: /* GraphQL */`
|
|
17
|
+
type AcoApp {
|
|
18
|
+
id: ID!
|
|
19
|
+
name: String!
|
|
20
|
+
model: JSON!
|
|
21
|
+
}
|
|
22
|
+
type GetAppResponse {
|
|
23
|
+
data: AcoApp
|
|
24
|
+
error: AcoError
|
|
25
|
+
}
|
|
26
|
+
type GetAppModelResponse {
|
|
27
|
+
data: JSON
|
|
28
|
+
error: AcoError
|
|
29
|
+
}
|
|
30
|
+
extend type AcoQuery {
|
|
31
|
+
getApp(id: ID!): GetAppResponse!
|
|
32
|
+
getAppModel(id: ID!): GetAppModelResponse!
|
|
33
|
+
}
|
|
34
|
+
`,
|
|
35
|
+
resolvers: {
|
|
36
|
+
AcoQuery: {
|
|
37
|
+
getApp: async (_, args, context) => {
|
|
38
|
+
return (0, _resolve.resolve)(async () => {
|
|
39
|
+
(0, _ensureAuthentication.ensureAuthentication)(context);
|
|
40
|
+
const app = context.aco.getApp(args.id);
|
|
41
|
+
return {
|
|
42
|
+
id: args.id,
|
|
43
|
+
name: app.name,
|
|
44
|
+
model: cleanModel(app.model)
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
getAppModel: async (_, args, context) => {
|
|
49
|
+
return (0, _resolve.resolve)(async () => {
|
|
50
|
+
(0, _ensureAuthentication.ensureAuthentication)(context);
|
|
51
|
+
const app = context.aco.getApp(args.id);
|
|
52
|
+
return cleanModel(app.model);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
exports.appGql = appGql;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=app.gql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handlerGraphql","require","_omit","_interopRequireDefault","_ensureAuthentication","_resolve","cleanModel","model","lodashOmit","appGql","GraphQLSchemaPlugin","typeDefs","resolvers","AcoQuery","getApp","_","args","context","resolve","ensureAuthentication","app","aco","id","name","getAppModel","exports"],"sources":["app.gql.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { AcoContext } from \"~/types\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport lodashOmit from \"lodash/omit\";\nimport { ensureAuthentication } from \"~/utils/ensureAuthentication\";\nimport { resolve } from \"~/utils/resolve\";\n\nconst cleanModel = (model: CmsModel): Partial<CmsModel> => {\n return lodashOmit(model, [\n \"webinyVersion\",\n \"tags\",\n \"locale\",\n \"tenant\",\n \"layout\",\n \"group\",\n \"description\",\n \"isPrivate\"\n ]);\n};\n\nexport const appGql = new GraphQLSchemaPlugin<AcoContext>({\n typeDefs: /* GraphQL */ `\n type AcoApp {\n id: ID!\n name: String!\n model: JSON!\n }\n type GetAppResponse {\n data: AcoApp\n error: AcoError\n }\n type GetAppModelResponse {\n data: JSON\n error: AcoError\n }\n extend type AcoQuery {\n getApp(id: ID!): GetAppResponse!\n getAppModel(id: ID!): GetAppModelResponse!\n }\n `,\n resolvers: {\n AcoQuery: {\n getApp: async (_, args, context) => {\n return resolve(async () => {\n ensureAuthentication(context);\n const app = context.aco.getApp(args.id);\n return {\n id: args.id,\n name: app.name,\n model: cleanModel(app.model)\n };\n });\n },\n getAppModel: async (_, args, context) => {\n return resolve(async () => {\n ensureAuthentication(context);\n const app = context.aco.getApp(args.id);\n return cleanModel(app.model);\n });\n }\n }\n }\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,MAAMK,UAAU,GAAIC,KAAe,IAAwB;EACvD,OAAO,IAAAC,aAAU,EAACD,KAAK,EAAE,CACrB,eAAe,EACf,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,aAAa,EACb,WAAW,CACd,CAAC;AACN,CAAC;AAEM,MAAME,MAAM,GAAG,IAAIC,mCAAmB,CAAa;EACtDC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,QAAQ,EAAE;MACNC,MAAM,EAAE,MAAAA,CAAOC,CAAC,EAAEC,IAAI,EAAEC,OAAO,KAAK;QAChC,OAAO,IAAAC,gBAAO,EAAC,YAAY;UACvB,IAAAC,0CAAoB,EAACF,OAAO,CAAC;UAC7B,MAAMG,GAAG,GAAGH,OAAO,CAACI,GAAG,CAACP,MAAM,CAACE,IAAI,CAACM,EAAE,CAAC;UACvC,OAAO;YACHA,EAAE,EAAEN,IAAI,CAACM,EAAE;YACXC,IAAI,EAAEH,GAAG,CAACG,IAAI;YACdhB,KAAK,EAAED,UAAU,CAACc,GAAG,CAACb,KAAK;UAC/B,CAAC;QACL,CAAC,CAAC;MACN,CAAC;MACDiB,WAAW,EAAE,MAAAA,CAAOT,CAAC,EAAEC,IAAI,EAAEC,OAAO,KAAK;QACrC,OAAO,IAAAC,gBAAO,EAAC,YAAY;UACvB,IAAAC,0CAAoB,EAACF,OAAO,CAAC;UAC7B,MAAMG,GAAG,GAAGH,OAAO,CAACI,GAAG,CAACP,MAAM,CAACE,IAAI,CAACM,EAAE,CAAC;UACvC,OAAOhB,UAAU,CAACc,GAAG,CAACb,KAAK,CAAC;QAChC,CAAC,CAAC;MACN;IACJ;EACJ;AACJ,CAAC,CAAC;AAACkB,OAAA,CAAAhB,MAAA,GAAAA,MAAA"}
|
package/apps/index.d.ts
ADDED
package/apps/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _AcoApp = require("./AcoApp");
|
|
7
|
+
Object.keys(_AcoApp).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _AcoApp[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _AcoApp[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _AcoApps = require("./AcoApps");
|
|
18
|
+
Object.keys(_AcoApps).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _AcoApps[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _AcoApps[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_AcoApp","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_AcoApps"],"sources":["index.ts"],"sourcesContent":["export * from \"./AcoApp\";\nexport * from \"./AcoApps\";\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
|
package/createAcoContext.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
|
2
2
|
import { AcoContext } from "./types";
|
|
3
|
-
|
|
3
|
+
interface CreateAcoContextParams {
|
|
4
|
+
useFolderLevelPermissions?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const createAcoContext: (params?: CreateAcoContextParams) => ContextPlugin<AcoContext>;
|
|
7
|
+
export {};
|
package/createAcoContext.js
CHANGED
|
@@ -5,24 +5,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createAcoContext = void 0;
|
|
8
|
-
var _api = require("@webiny/api");
|
|
9
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var
|
|
9
|
+
var _api = require("@webiny/api");
|
|
11
10
|
var _createAcoHooks = require("./createAcoHooks");
|
|
12
11
|
var _createAcoStorageOperations = require("./createAcoStorageOperations");
|
|
13
12
|
var _isInstallationPending = require("./utils/isInstallationPending");
|
|
14
|
-
|
|
13
|
+
var _folder = require("./folder/folder.crud");
|
|
14
|
+
var _record = require("./record/record.crud");
|
|
15
|
+
var _apps = require("./apps");
|
|
16
|
+
var _record2 = require("./record/record.model");
|
|
17
|
+
var _plugins = require("./plugins");
|
|
18
|
+
var _FolderLevelPermissions = require("./utils/FolderLevelPermissions");
|
|
19
|
+
var _CmsEntriesCrudDecorators = require("./utils/decorators/CmsEntriesCrudDecorators");
|
|
20
|
+
var _folder2 = require("./folder/folder.model");
|
|
21
|
+
var _createOperationsWrapper = require("./utils/createOperationsWrapper");
|
|
22
|
+
var _pickEntryFieldValues = require("./utils/pickEntryFieldValues");
|
|
23
|
+
var _filter = require("./filter/filter.crud");
|
|
24
|
+
const setupAcoContext = async (context, setupAcoContextParams) => {
|
|
15
25
|
const {
|
|
16
26
|
tenancy,
|
|
17
27
|
security,
|
|
18
28
|
i18n
|
|
19
29
|
} = context;
|
|
20
|
-
if ((0, _isInstallationPending.isInstallationPending)({
|
|
21
|
-
tenancy,
|
|
22
|
-
i18n
|
|
23
|
-
})) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
30
|
const getLocale = () => {
|
|
27
31
|
const locale = i18n.getContentLocale();
|
|
28
32
|
if (!locale) {
|
|
@@ -33,31 +37,158 @@ const setupAcoContext = context => {
|
|
|
33
37
|
const getTenant = () => {
|
|
34
38
|
return tenancy.getCurrentTenant();
|
|
35
39
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
40
|
+
const storageOperations = (0, _createAcoStorageOperations.createAcoStorageOperations)({
|
|
41
|
+
/**
|
|
42
|
+
* TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
|
|
43
|
+
*/
|
|
44
|
+
cms: context.cms,
|
|
45
|
+
/**
|
|
46
|
+
* TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
|
|
47
|
+
*/
|
|
48
|
+
getCmsContext: () => context,
|
|
49
|
+
security
|
|
50
|
+
});
|
|
51
|
+
const folderLevelPermissions = new _FolderLevelPermissions.FolderLevelPermissions({
|
|
52
|
+
getIdentity: () => security.getIdentity(),
|
|
53
|
+
getIdentityTeam: async () => {
|
|
54
|
+
return security.withoutAuthorization(async () => {
|
|
55
|
+
const identity = security.getIdentity();
|
|
56
|
+
if (!identity) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const adminUser = await context.adminUsers.getUser({
|
|
60
|
+
where: {
|
|
61
|
+
id: identity.id
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (!adminUser) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (!adminUser.team) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return context.security.getTeam({
|
|
71
|
+
where: {
|
|
72
|
+
id: adminUser.team
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
listPermissions: () => security.listPermissions(),
|
|
78
|
+
listAllFolders: type => {
|
|
79
|
+
// When retrieving a list of all folders, we want to do it in the
|
|
80
|
+
// fastest way and that is by directly using CMS's storage operations.
|
|
81
|
+
const {
|
|
82
|
+
withModel
|
|
83
|
+
} = (0, _createOperationsWrapper.createOperationsWrapper)({
|
|
84
|
+
modelName: _folder2.FOLDER_MODEL_ID,
|
|
85
|
+
cms: context.cms,
|
|
86
|
+
getCmsContext: () => context,
|
|
87
|
+
security
|
|
88
|
+
});
|
|
89
|
+
return withModel(async model => {
|
|
90
|
+
const results = await context.cms.storageOperations.entries.list(model, {
|
|
91
|
+
limit: 100_000,
|
|
92
|
+
where: {
|
|
93
|
+
type,
|
|
94
|
+
// Folders always work with latest entries. We never publish them.
|
|
95
|
+
latest: true
|
|
96
|
+
},
|
|
97
|
+
sort: ["title_ASC"]
|
|
98
|
+
});
|
|
99
|
+
return results.items.map(_pickEntryFieldValues.pickEntryFieldValues);
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
canUseTeams: () => context.wcp.canUseTeams(),
|
|
103
|
+
canUseFolderLevelPermissions: () => {
|
|
104
|
+
if (setupAcoContextParams.useFolderLevelPermissions === false) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return context.wcp.canUseFolderLevelPermissions();
|
|
108
|
+
},
|
|
109
|
+
isAuthorizationEnabled: () => context.security.isAuthorizationEnabled()
|
|
110
|
+
});
|
|
111
|
+
const params = {
|
|
38
112
|
getLocale,
|
|
39
|
-
getIdentity,
|
|
40
113
|
getTenant,
|
|
41
|
-
storageOperations
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
|
|
48
|
-
*/
|
|
49
|
-
getCmsContext: () => context,
|
|
50
|
-
security
|
|
51
|
-
})
|
|
114
|
+
storageOperations,
|
|
115
|
+
folderLevelPermissions
|
|
116
|
+
};
|
|
117
|
+
const defaultRecordModel = await context.security.withoutAuthorization(async () => {
|
|
118
|
+
return context.cms.getModel(_record2.SEARCH_RECORD_MODEL_ID);
|
|
52
119
|
});
|
|
120
|
+
if (!defaultRecordModel) {
|
|
121
|
+
throw new _error.default(`There is no default record model in ${_record2.SEARCH_RECORD_MODEL_ID}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* First we need to create all the apps.
|
|
126
|
+
*/
|
|
127
|
+
const apps = new _apps.AcoApps(context, params);
|
|
128
|
+
const plugins = context.plugins.byType(_plugins.AcoAppRegisterPlugin.type);
|
|
129
|
+
for (const plugin of plugins) {
|
|
130
|
+
await apps.register({
|
|
131
|
+
model: defaultRecordModel,
|
|
132
|
+
...plugin.app
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const listAdminUsers = () => {
|
|
136
|
+
return security.withoutAuthorization(async () => {
|
|
137
|
+
return context.adminUsers.listUsers();
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const listTeams = () => {
|
|
141
|
+
return security.withoutAuthorization(async () => {
|
|
142
|
+
return context.security.listTeams();
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
context.aco = {
|
|
146
|
+
folder: (0, _folder.createFolderCrudMethods)({
|
|
147
|
+
...params,
|
|
148
|
+
listAdminUsers,
|
|
149
|
+
listTeams
|
|
150
|
+
}),
|
|
151
|
+
search: (0, _record.createSearchRecordCrudMethods)(params),
|
|
152
|
+
folderLevelPermissions,
|
|
153
|
+
filter: (0, _filter.createFilterCrudMethods)(params),
|
|
154
|
+
apps,
|
|
155
|
+
getApp: name => apps.get(name),
|
|
156
|
+
listApps: () => apps.list(),
|
|
157
|
+
registerApp: async params => {
|
|
158
|
+
return apps.register({
|
|
159
|
+
model: defaultRecordModel,
|
|
160
|
+
...params
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
if (context.wcp.canUseFolderLevelPermissions()) {
|
|
165
|
+
new _CmsEntriesCrudDecorators.CmsEntriesCrudDecorators({
|
|
166
|
+
context
|
|
167
|
+
}).decorate();
|
|
168
|
+
|
|
169
|
+
// PB decorators registered here: packages/api-page-builder-aco/src/index.ts
|
|
170
|
+
// new PageBuilderCrudDecorators({ context }).decorate();
|
|
171
|
+
}
|
|
53
172
|
};
|
|
54
|
-
|
|
55
|
-
|
|
173
|
+
|
|
174
|
+
const createAcoContext = (params = {}) => {
|
|
175
|
+
const plugin = new _api.ContextPlugin(async context => {
|
|
176
|
+
/**
|
|
177
|
+
* We can skip the ACO initialization if the installation is pending.
|
|
178
|
+
*/
|
|
56
179
|
if ((0, _isInstallationPending.isInstallationPending)(context)) {
|
|
57
180
|
return;
|
|
58
181
|
}
|
|
59
|
-
await
|
|
60
|
-
|
|
182
|
+
await context.benchmark.measure("aco.context.setup", async () => {
|
|
183
|
+
await setupAcoContext(context, params);
|
|
184
|
+
});
|
|
185
|
+
await context.benchmark.measure("aco.context.hooks", async () => {
|
|
186
|
+
await (0, _createAcoHooks.createAcoHooks)(context);
|
|
187
|
+
});
|
|
61
188
|
});
|
|
189
|
+
plugin.name = "aco.createContext";
|
|
190
|
+
return plugin;
|
|
62
191
|
};
|
|
63
|
-
exports.createAcoContext = createAcoContext;
|
|
192
|
+
exports.createAcoContext = createAcoContext;
|
|
193
|
+
|
|
194
|
+
//# sourceMappingURL=createAcoContext.js.map
|