@webiny/api-serverless-cms 0.0.0-unstable.39223eb3c1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @webiny/api-serverless-cms
2
+ [![](https://img.shields.io/npm/dw/@webiny/api-serverless-cms.svg)](https://www.npmjs.com/package/@webiny/api-serverless-cms)
3
+ [![](https://img.shields.io/npm/v/@webiny/api-serverless-cms.svg)](https://www.npmjs.com/package/@webiny/api-serverless-cms)
4
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
+
7
+ ## Install
8
+ ```
9
+ npm install --save @webiny/api-serverless-cms
10
+ ```
11
+
12
+ Or if you prefer yarn:
13
+ ```
14
+ yarn add @webiny/api-serverless-cms
15
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { ClientContext } from "@webiny/handler-client/types";
2
+ import type { TenancyContext } from "@webiny/api-tenancy/types";
3
+ import type { SecurityContext } from "@webiny/api-security/types";
4
+ import type { I18NContext } from "@webiny/api-i18n/types";
5
+ import type { I18NContentContext } from "@webiny/api-i18n-content/types";
6
+ import type { PrerenderingServiceClientContext } from "@webiny/api-prerendering-service/client/types";
7
+ import type { FileManagerContext } from "@webiny/api-file-manager/types";
8
+ import type { CmsContext } from "@webiny/api-headless-cms/types";
9
+ import type { AcoContext } from "@webiny/api-aco/types";
10
+ import type { ContextPluginCallable } from "@webiny/api";
11
+ import type { GraphQLSchemaPluginConfig } from "@webiny/handler-graphql";
12
+ import { createSecurityRolePlugin, createSecurityTeamPlugin } from "@webiny/api-security";
13
+ import type { MailerContext } from "@webiny/api-mailer/types";
14
+ import type { Context as LoggerContext } from "@webiny/api-log/types";
15
+ import type { WebsiteBuilderContext } from "@webiny/api-website-builder";
16
+ export interface Context extends ClientContext, MailerContext, TenancyContext, SecurityContext, I18NContext, I18NContentContext, PrerenderingServiceClientContext, FileManagerContext, AcoContext, LoggerContext, CmsContext, WebsiteBuilderContext {
17
+ }
18
+ export declare const createContextPlugin: <T extends Context = Context>(callable: ContextPluginCallable<T>) => import("@webiny/api").ContextPlugin<T>;
19
+ export declare const createGraphQLSchemaPlugin: <T extends Context = Context>(config: GraphQLSchemaPluginConfig<T>) => import("@webiny/handler-graphql").GraphQLSchemaPlugin<T>;
20
+ export { createSecurityRolePlugin, createSecurityTeamPlugin };
21
+ export * from "./tenancy/InstallTenant";
22
+ export { createModelGroupPlugin, createModelPlugin, createSingleEntryModelPlugin, createPrivateModelPlugin, createPrivateSingleEntryModelPlugin, createModelField, createCmsGraphQLSchemaPlugin, createStorageTransformPlugin } from "@webiny/api-headless-cms";
package/index.js ADDED
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ createContextPlugin: true,
8
+ createGraphQLSchemaPlugin: true,
9
+ createSecurityRolePlugin: true,
10
+ createSecurityTeamPlugin: true,
11
+ createModelGroupPlugin: true,
12
+ createModelPlugin: true,
13
+ createSingleEntryModelPlugin: true,
14
+ createPrivateModelPlugin: true,
15
+ createPrivateSingleEntryModelPlugin: true,
16
+ createModelField: true,
17
+ createCmsGraphQLSchemaPlugin: true,
18
+ createStorageTransformPlugin: true
19
+ };
20
+ Object.defineProperty(exports, "createCmsGraphQLSchemaPlugin", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _apiHeadlessCms.createCmsGraphQLSchemaPlugin;
24
+ }
25
+ });
26
+ exports.createGraphQLSchemaPlugin = exports.createContextPlugin = void 0;
27
+ Object.defineProperty(exports, "createModelField", {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _apiHeadlessCms.createModelField;
31
+ }
32
+ });
33
+ Object.defineProperty(exports, "createModelGroupPlugin", {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _apiHeadlessCms.createModelGroupPlugin;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "createModelPlugin", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _apiHeadlessCms.createModelPlugin;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "createPrivateModelPlugin", {
46
+ enumerable: true,
47
+ get: function () {
48
+ return _apiHeadlessCms.createPrivateModelPlugin;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "createPrivateSingleEntryModelPlugin", {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _apiHeadlessCms.createPrivateSingleEntryModelPlugin;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "createSecurityRolePlugin", {
58
+ enumerable: true,
59
+ get: function () {
60
+ return _apiSecurity.createSecurityRolePlugin;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, "createSecurityTeamPlugin", {
64
+ enumerable: true,
65
+ get: function () {
66
+ return _apiSecurity.createSecurityTeamPlugin;
67
+ }
68
+ });
69
+ Object.defineProperty(exports, "createSingleEntryModelPlugin", {
70
+ enumerable: true,
71
+ get: function () {
72
+ return _apiHeadlessCms.createSingleEntryModelPlugin;
73
+ }
74
+ });
75
+ Object.defineProperty(exports, "createStorageTransformPlugin", {
76
+ enumerable: true,
77
+ get: function () {
78
+ return _apiHeadlessCms.createStorageTransformPlugin;
79
+ }
80
+ });
81
+ var _api = require("@webiny/api");
82
+ var _handlerGraphql = require("@webiny/handler-graphql");
83
+ var _apiSecurity = require("@webiny/api-security");
84
+ var _InstallTenant = require("./tenancy/InstallTenant");
85
+ Object.keys(_InstallTenant).forEach(function (key) {
86
+ if (key === "default" || key === "__esModule") return;
87
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
88
+ if (key in exports && exports[key] === _InstallTenant[key]) return;
89
+ Object.defineProperty(exports, key, {
90
+ enumerable: true,
91
+ get: function () {
92
+ return _InstallTenant[key];
93
+ }
94
+ });
95
+ });
96
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
97
+ const createContextPlugin = callable => {
98
+ return (0, _api.createContextPlugin)(callable);
99
+ };
100
+ exports.createContextPlugin = createContextPlugin;
101
+ const createGraphQLSchemaPlugin = config => {
102
+ return (0, _handlerGraphql.createGraphQLSchemaPlugin)(config);
103
+ };
104
+ exports.createGraphQLSchemaPlugin = createGraphQLSchemaPlugin;
105
+
106
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_api","require","_handlerGraphql","_apiSecurity","_InstallTenant","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_apiHeadlessCms","createContextPlugin","callable","baseCreateContextPlugin","createGraphQLSchemaPlugin","config","baseCreateGraphQLSchemaPlugin"],"sources":["index.ts"],"sourcesContent":["import type { ClientContext } from \"@webiny/handler-client/types\";\nimport type { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport type { SecurityContext } from \"@webiny/api-security/types\";\nimport type { I18NContext } from \"@webiny/api-i18n/types\";\nimport type { I18NContentContext } from \"@webiny/api-i18n-content/types\";\nimport type { PrerenderingServiceClientContext } from \"@webiny/api-prerendering-service/client/types\";\nimport type { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport type { AcoContext } from \"@webiny/api-aco/types\";\nimport type { ContextPluginCallable } from \"@webiny/api\";\nimport { createContextPlugin as baseCreateContextPlugin } from \"@webiny/api\";\nimport type { GraphQLSchemaPluginConfig } from \"@webiny/handler-graphql\";\nimport { createGraphQLSchemaPlugin as baseCreateGraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { createSecurityRolePlugin, createSecurityTeamPlugin } from \"@webiny/api-security\";\nimport type { MailerContext } from \"@webiny/api-mailer/types\";\nimport type { Context as LoggerContext } from \"@webiny/api-log/types\";\nimport type { WebsiteBuilderContext } from \"@webiny/api-website-builder\";\n\nexport interface Context\n extends ClientContext,\n MailerContext,\n TenancyContext,\n SecurityContext,\n I18NContext,\n I18NContentContext,\n PrerenderingServiceClientContext,\n FileManagerContext,\n AcoContext,\n LoggerContext,\n CmsContext,\n WebsiteBuilderContext {}\n\nexport const createContextPlugin = <T extends Context = Context>(\n callable: ContextPluginCallable<T>\n) => {\n return baseCreateContextPlugin<T>(callable);\n};\n\nexport const createGraphQLSchemaPlugin = <T extends Context = Context>(\n config: GraphQLSchemaPluginConfig<T>\n) => {\n return baseCreateGraphQLSchemaPlugin<T>(config);\n};\n\nexport { createSecurityRolePlugin, createSecurityTeamPlugin };\n\nexport * from \"./tenancy/InstallTenant\";\n\nexport {\n // Model groups.\n createModelGroupPlugin,\n\n // Models.\n createModelPlugin,\n createSingleEntryModelPlugin,\n createPrivateModelPlugin,\n createPrivateSingleEntryModelPlugin,\n\n // Model fields (this is not a plugin factory, hence the missing `Plugin` suffix in the name).\n createModelField,\n\n // Other.\n createCmsGraphQLSchemaPlugin,\n createStorageTransformPlugin\n} from \"@webiny/api-headless-cms\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAiCA,IAAAG,cAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,cAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,cAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,cAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAEA,IAAAS,eAAA,GAAAhB,OAAA;AAhBO,MAAMiB,mBAAmB,GAC5BC,QAAkC,IACjC;EACD,OAAO,IAAAC,wBAAuB,EAAID,QAAQ,CAAC;AAC/C,CAAC;AAACN,OAAA,CAAAK,mBAAA,GAAAA,mBAAA;AAEK,MAAMG,yBAAyB,GAClCC,MAAoC,IACnC;EACD,OAAO,IAAAC,yCAA6B,EAAID,MAAM,CAAC;AACnD,CAAC;AAACT,OAAA,CAAAQ,yBAAA,GAAAA,yBAAA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@webiny/api-serverless-cms",
3
+ "version": "0.0.0-unstable.39223eb3c1",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "Core package for all of our API packages.",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@webiny/api": "0.0.0-unstable.39223eb3c1",
13
+ "@webiny/api-aco": "0.0.0-unstable.39223eb3c1",
14
+ "@webiny/api-file-manager": "0.0.0-unstable.39223eb3c1",
15
+ "@webiny/api-headless-cms": "0.0.0-unstable.39223eb3c1",
16
+ "@webiny/api-i18n": "0.0.0-unstable.39223eb3c1",
17
+ "@webiny/api-i18n-content": "0.0.0-unstable.39223eb3c1",
18
+ "@webiny/api-log": "0.0.0-unstable.39223eb3c1",
19
+ "@webiny/api-mailer": "0.0.0-unstable.39223eb3c1",
20
+ "@webiny/api-security": "0.0.0-unstable.39223eb3c1",
21
+ "@webiny/api-tenancy": "0.0.0-unstable.39223eb3c1",
22
+ "@webiny/api-website-builder": "0.0.0-unstable.39223eb3c1",
23
+ "@webiny/error": "0.0.0-unstable.39223eb3c1",
24
+ "@webiny/handler-client": "0.0.0-unstable.39223eb3c1",
25
+ "@webiny/handler-graphql": "0.0.0-unstable.39223eb3c1"
26
+ },
27
+ "devDependencies": {
28
+ "@webiny/api-admin-users": "0.0.0-unstable.39223eb3c1",
29
+ "@webiny/api-apw": "0.0.0-unstable.39223eb3c1",
30
+ "@webiny/api-audit-logs": "0.0.0-unstable.39223eb3c1",
31
+ "@webiny/api-form-builder": "0.0.0-unstable.39223eb3c1",
32
+ "@webiny/api-headless-cms-aco": "0.0.0-unstable.39223eb3c1",
33
+ "@webiny/api-headless-cms-tasks": "0.0.0-unstable.39223eb3c1",
34
+ "@webiny/api-page-builder": "0.0.0-unstable.39223eb3c1",
35
+ "@webiny/api-page-builder-aco": "0.0.0-unstable.39223eb3c1",
36
+ "@webiny/api-page-builder-import-export": "0.0.0-unstable.39223eb3c1",
37
+ "@webiny/api-page-builder-import-export-so-ddb": "0.0.0-unstable.39223eb3c1",
38
+ "@webiny/api-prerendering-service": "0.0.0-unstable.39223eb3c1",
39
+ "@webiny/api-record-locking": "0.0.0-unstable.39223eb3c1",
40
+ "@webiny/api-wcp": "0.0.0-unstable.39223eb3c1",
41
+ "@webiny/api-websockets": "0.0.0-unstable.39223eb3c1",
42
+ "@webiny/handler": "0.0.0-unstable.39223eb3c1",
43
+ "@webiny/handler-aws": "0.0.0-unstable.39223eb3c1",
44
+ "@webiny/plugins": "0.0.0-unstable.39223eb3c1",
45
+ "@webiny/project-utils": "0.0.0-unstable.39223eb3c1",
46
+ "@webiny/tasks": "0.0.0-unstable.39223eb3c1",
47
+ "@webiny/wcp": "0.0.0-unstable.39223eb3c1",
48
+ "graphql": "15.9.0",
49
+ "rimraf": "6.0.1",
50
+ "typescript": "5.3.3"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "directory": "dist"
55
+ },
56
+ "scripts": {
57
+ "build": "node ../cli/bin.js run build",
58
+ "watch": "node ../cli/bin.js run watch"
59
+ },
60
+ "gitHead": "39223eb3c19f7398d2cf6da389b33061a67b1075"
61
+ }
@@ -0,0 +1,33 @@
1
+ import type { Tenant } from "@webiny/api-tenancy/types";
2
+ import type { Context } from "../index";
3
+ export interface AdminUserInput {
4
+ firstName: string;
5
+ lastName: string;
6
+ email: string;
7
+ password: string;
8
+ group?: string;
9
+ }
10
+ export type AdminUsersInstallationConfig = AdminUserInput | undefined;
11
+ export interface I18nInstallationConfig {
12
+ defaultLocaleCode: string;
13
+ }
14
+ export interface FileManagerInstallationConfig {
15
+ /**
16
+ * Asset delivery origin. This usually points to the main Webiny API origin.
17
+ * E.g., https://some.domain.com/
18
+ *
19
+ * You can change this later in the tenant's File Manager settings.
20
+ */
21
+ assetDeliveryDomain: string;
22
+ }
23
+ export interface TenantConfig {
24
+ i18n: I18nInstallationConfig;
25
+ adminUsers?: AdminUsersInstallationConfig;
26
+ fileManager?: FileManagerInstallationConfig;
27
+ }
28
+ export declare class InstallTenant {
29
+ private readonly context;
30
+ constructor(context: Context);
31
+ execute(tenant: Tenant, config: TenantConfig): Promise<void>;
32
+ private runOrThrow;
33
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.InstallTenant = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ class InstallTenant {
10
+ constructor(context) {
11
+ this.context = context;
12
+ }
13
+ async execute(tenant, config) {
14
+ const currentTenant = this.context.tenancy.getCurrentTenant();
15
+
16
+ // Get current tenant's FileManager settings.
17
+ const fmSettings = await this.context.fileManager.getSettings();
18
+
19
+ // Switch tenant to the one being installed.
20
+ this.context.tenancy.setCurrentTenant(tenant);
21
+ try {
22
+ // TENANCY: Set the app version, as the tenant is already created.
23
+ await this.context.tenancy.setVersion(this.context.WEBINY_VERSION);
24
+
25
+ // SECURITY: Create initial security groups.
26
+ await this.runOrThrow(async () => {
27
+ const isInstalled = await this.context.security.getVersion();
28
+ if (!isInstalled) {
29
+ await this.context.security.install();
30
+ }
31
+ }, "SECURITY_INSTALL");
32
+
33
+ // ADMIN USERS: Optionally, create an admin user for this tenant.
34
+ await this.runOrThrow(async () => {
35
+ const isInstalled = await this.context.adminUsers.getVersion();
36
+ if (isInstalled) {
37
+ return;
38
+ }
39
+ if (config.adminUsers) {
40
+ await this.context.adminUsers.install(config.adminUsers);
41
+ } else {
42
+ // We always mark `adminUsers` as installed, regardless of the config.
43
+ await this.context.adminUsers.setVersion(this.context.WEBINY_VERSION);
44
+ }
45
+ }, "ADMIN_USERS_INSTALL");
46
+
47
+ // I18N: Create a default locale.
48
+ await this.runOrThrow(async () => {
49
+ const isInstalled = await this.context.i18n.system.getSystemVersion();
50
+ if (isInstalled) {
51
+ return;
52
+ }
53
+ await this.context.i18n.system.installSystem({
54
+ code: config.i18n.defaultLocaleCode
55
+ });
56
+ }, "I18N_INSTALL");
57
+
58
+ // CMS
59
+ await this.runOrThrow(async () => {
60
+ const isInstalled = await this.context.cms.getSystemVersion();
61
+ if (isInstalled) {
62
+ return;
63
+ }
64
+ await this.context.cms.installSystem();
65
+ }, "CMS_INSTALL");
66
+
67
+ // FILE MANAGER: Create File Manager settings.
68
+ const srcPrefix = config.fileManager ? `${new URL(config.fileManager.assetDeliveryDomain).origin}/files/` : fmSettings?.srcPrefix;
69
+ await this.runOrThrow(async () => {
70
+ const isInstalled = await this.context.fileManager.getVersion();
71
+ if (isInstalled) {
72
+ return;
73
+ }
74
+ await this.context.fileManager.install({
75
+ srcPrefix: srcPrefix || ""
76
+ });
77
+ }, "FILE_MANAGER_INSTALL");
78
+ } finally {
79
+ this.context.tenancy.setCurrentTenant(currentTenant);
80
+ }
81
+ }
82
+ async runOrThrow(cb, errorCode) {
83
+ try {
84
+ await cb();
85
+ } catch (err) {
86
+ throw new _error.default({
87
+ message: err.message,
88
+ code: `INSTALL_TENANT:${errorCode}`,
89
+ data: {
90
+ error: err
91
+ }
92
+ });
93
+ }
94
+ }
95
+ }
96
+ exports.InstallTenant = InstallTenant;
97
+
98
+ //# sourceMappingURL=InstallTenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","InstallTenant","constructor","context","execute","tenant","config","currentTenant","tenancy","getCurrentTenant","fmSettings","fileManager","getSettings","setCurrentTenant","setVersion","WEBINY_VERSION","runOrThrow","isInstalled","security","getVersion","install","adminUsers","i18n","system","getSystemVersion","installSystem","code","defaultLocaleCode","cms","srcPrefix","URL","assetDeliveryDomain","origin","cb","errorCode","err","Error","message","data","error","exports"],"sources":["InstallTenant.ts"],"sourcesContent":["import type { Tenant } from \"@webiny/api-tenancy/types\";\nimport Error from \"@webiny/error\";\nimport type { Context } from \"~/index\";\n\nexport interface AdminUserInput {\n firstName: string;\n lastName: string;\n email: string;\n password: string;\n group?: string;\n}\n\nexport type AdminUsersInstallationConfig = AdminUserInput | undefined;\n\nexport interface I18nInstallationConfig {\n defaultLocaleCode: string;\n}\n\nexport interface FileManagerInstallationConfig {\n /**\n * Asset delivery origin. This usually points to the main Webiny API origin.\n * E.g., https://some.domain.com/\n *\n * You can change this later in the tenant's File Manager settings.\n */\n assetDeliveryDomain: string;\n}\n\nexport interface TenantConfig {\n i18n: I18nInstallationConfig;\n adminUsers?: AdminUsersInstallationConfig;\n fileManager?: FileManagerInstallationConfig;\n}\n\nexport class InstallTenant {\n private readonly context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n async execute(tenant: Tenant, config: TenantConfig): Promise<void> {\n const currentTenant = this.context.tenancy.getCurrentTenant();\n\n // Get current tenant's FileManager settings.\n const fmSettings = await this.context.fileManager.getSettings();\n\n // Switch tenant to the one being installed.\n this.context.tenancy.setCurrentTenant(tenant);\n\n try {\n // TENANCY: Set the app version, as the tenant is already created.\n await this.context.tenancy.setVersion(this.context.WEBINY_VERSION);\n\n // SECURITY: Create initial security groups.\n await this.runOrThrow(async () => {\n const isInstalled = await this.context.security.getVersion();\n if (!isInstalled) {\n await this.context.security.install();\n }\n }, \"SECURITY_INSTALL\");\n\n // ADMIN USERS: Optionally, create an admin user for this tenant.\n await this.runOrThrow(async () => {\n const isInstalled = await this.context.adminUsers.getVersion();\n if (isInstalled) {\n return;\n }\n\n if (config.adminUsers) {\n await this.context.adminUsers.install(config.adminUsers);\n } else {\n // We always mark `adminUsers` as installed, regardless of the config.\n await this.context.adminUsers.setVersion(this.context.WEBINY_VERSION);\n }\n }, \"ADMIN_USERS_INSTALL\");\n\n // I18N: Create a default locale.\n await this.runOrThrow(async () => {\n const isInstalled = await this.context.i18n.system.getSystemVersion();\n if (isInstalled) {\n return;\n }\n\n await this.context.i18n.system.installSystem({\n code: config.i18n.defaultLocaleCode\n });\n }, \"I18N_INSTALL\");\n\n // CMS\n await this.runOrThrow(async () => {\n const isInstalled = await this.context.cms.getSystemVersion();\n if (isInstalled) {\n return;\n }\n await this.context.cms.installSystem();\n }, \"CMS_INSTALL\");\n\n // FILE MANAGER: Create File Manager settings.\n const srcPrefix = config.fileManager\n ? `${new URL(config.fileManager.assetDeliveryDomain).origin}/files/`\n : fmSettings?.srcPrefix;\n\n await this.runOrThrow(async () => {\n const isInstalled = await this.context.fileManager.getVersion();\n if (isInstalled) {\n return;\n }\n\n await this.context.fileManager.install({ srcPrefix: srcPrefix || \"\" });\n }, \"FILE_MANAGER_INSTALL\");\n } finally {\n this.context.tenancy.setCurrentTenant(currentTenant);\n }\n }\n\n private async runOrThrow(cb: () => Promise<void>, errorCode: string): Promise<void> {\n try {\n await cb();\n } catch (err) {\n throw new Error({\n message: err.message,\n code: `INSTALL_TENANT:${errorCode}`,\n data: {\n error: err\n }\n });\n }\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAiCO,MAAMC,aAAa,CAAC;EAGvBC,WAAWA,CAACC,OAAgB,EAAE;IAC1B,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,MAAc,EAAEC,MAAoB,EAAiB;IAC/D,MAAMC,aAAa,GAAG,IAAI,CAACJ,OAAO,CAACK,OAAO,CAACC,gBAAgB,CAAC,CAAC;;IAE7D;IACA,MAAMC,UAAU,GAAG,MAAM,IAAI,CAACP,OAAO,CAACQ,WAAW,CAACC,WAAW,CAAC,CAAC;;IAE/D;IACA,IAAI,CAACT,OAAO,CAACK,OAAO,CAACK,gBAAgB,CAACR,MAAM,CAAC;IAE7C,IAAI;MACA;MACA,MAAM,IAAI,CAACF,OAAO,CAACK,OAAO,CAACM,UAAU,CAAC,IAAI,CAACX,OAAO,CAACY,cAAc,CAAC;;MAElE;MACA,MAAM,IAAI,CAACC,UAAU,CAAC,YAAY;QAC9B,MAAMC,WAAW,GAAG,MAAM,IAAI,CAACd,OAAO,CAACe,QAAQ,CAACC,UAAU,CAAC,CAAC;QAC5D,IAAI,CAACF,WAAW,EAAE;UACd,MAAM,IAAI,C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