@webiny/api-page-builder-so-ddb-es 5.28.0 → 5.29.0-beta.2
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/operations/settings/index.js +32 -23
- package/operations/settings/index.js.map +1 -1
- package/package.json +18 -18
|
@@ -17,25 +17,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
17
17
|
|
|
18
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
19
|
|
|
20
|
-
const extractFromStorage = settings => {
|
|
21
|
-
return _objectSpread(_objectSpread({}, settings), {}, {
|
|
22
|
-
tenant: !settings.tenant ? false : settings.tenant,
|
|
23
|
-
locale: !settings.locale ? false : settings.locale
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const prepareForStorage = settings => {
|
|
28
|
-
return _objectSpread(_objectSpread({}, settings), {}, {
|
|
29
|
-
tenant: !settings.tenant ? null : settings.tenant,
|
|
30
|
-
locale: !settings.locale ? null : settings.locale
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Because it is a possibility that tenant and locale are set as false (for the global settings) we must take
|
|
35
|
-
* it in consideration and create the partition key for the global settings.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
20
|
const createPartitionKey = params => {
|
|
40
21
|
const {
|
|
41
22
|
tenant,
|
|
@@ -83,6 +64,34 @@ const createType = () => {
|
|
|
83
64
|
const createSettingsStorageOperations = ({
|
|
84
65
|
entity
|
|
85
66
|
}) => {
|
|
67
|
+
const getDefaults = async () => {
|
|
68
|
+
const keys = {
|
|
69
|
+
PK: "PS#SETTINGS",
|
|
70
|
+
SK: "default"
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const result = await entity.get(keys);
|
|
75
|
+
|
|
76
|
+
if (!result || !result.Item) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
appUrl,
|
|
82
|
+
deliveryUrl
|
|
83
|
+
} = result.Item.data;
|
|
84
|
+
return {
|
|
85
|
+
websiteUrl: deliveryUrl,
|
|
86
|
+
websitePreviewUrl: appUrl
|
|
87
|
+
};
|
|
88
|
+
} catch (ex) {
|
|
89
|
+
throw new _error.default(ex.message || "Could not load default settings record.", ex.code || "DEFAULT_SETTINGS_GET_ERROR", {
|
|
90
|
+
keys
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
86
95
|
const get = async params => {
|
|
87
96
|
const {
|
|
88
97
|
where
|
|
@@ -99,8 +108,7 @@ const createSettingsStorageOperations = ({
|
|
|
99
108
|
return null;
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
return extractFromStorage(settings);
|
|
111
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
104
112
|
} catch (ex) {
|
|
105
113
|
throw new _error.default(ex.message || "Could not load settings record.", ex.code || "SETTINGS_GET_ERROR", {
|
|
106
114
|
keys
|
|
@@ -118,7 +126,7 @@ const createSettingsStorageOperations = ({
|
|
|
118
126
|
};
|
|
119
127
|
|
|
120
128
|
try {
|
|
121
|
-
await entity.put(_objectSpread(_objectSpread({},
|
|
129
|
+
await entity.put(_objectSpread(_objectSpread({}, settings), {}, {
|
|
122
130
|
TYPE: createType()
|
|
123
131
|
}, keys));
|
|
124
132
|
return settings;
|
|
@@ -141,7 +149,7 @@ const createSettingsStorageOperations = ({
|
|
|
141
149
|
};
|
|
142
150
|
|
|
143
151
|
try {
|
|
144
|
-
await entity.put(_objectSpread(_objectSpread({},
|
|
152
|
+
await entity.put(_objectSpread(_objectSpread({}, settings), {}, {
|
|
145
153
|
TYPE: createType()
|
|
146
154
|
}, keys));
|
|
147
155
|
return settings;
|
|
@@ -164,6 +172,7 @@ const createSettingsStorageOperations = ({
|
|
|
164
172
|
|
|
165
173
|
return {
|
|
166
174
|
get,
|
|
175
|
+
getDefaults,
|
|
167
176
|
create,
|
|
168
177
|
update,
|
|
169
178
|
createCacheKey
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","parts","push","join","createSortKey","type","WebinyError","createType","createSettingsStorageOperations","entity","getDefaults","keys","PK","SK","result","get","Item","appUrl","deliveryUrl","data","websiteUrl","websitePreviewUrl","ex","message","code","where","cleanupItem","create","settings","put","TYPE","update","original","createCacheKey"],"sources":["index.ts"],"sourcesContent":["import {\n DefaultSettings,\n DefaultSettingsCrudOptions,\n SettingsStorageOperations,\n SettingsStorageOperationsCreateParams,\n SettingsStorageOperationsGetParams,\n SettingsStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport WebinyError from \"@webiny/error\";\n\n/**\n * Because it is a possibility that tenant and locale are set as false (for the global settings) we must take\n * it in consideration and create the partition key for the global settings.\n */\ninterface PartitionKeyParams {\n tenant: string | boolean | undefined;\n locale: string | boolean | undefined;\n}\n\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n const parts: string[] = [];\n if (tenant !== false) {\n parts.push(`T#${tenant}`);\n }\n if (locale !== false) {\n parts.push(`L#${locale}`);\n }\n parts.push(\"PB#SETTINGS\");\n\n return parts.join(\"#\");\n};\n\n/**\n * We expect any object that has type property in it.\n * This way we can either receive a settings object or where conditions\n */\ninterface SortKeyParams {\n type: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n const { type } = params;\n switch (type) {\n case \"default\":\n return type;\n default:\n throw new WebinyError(\"Unsupported type for the sort key.\", \"UNSUPPORTED_TYPE\", {\n type\n });\n }\n};\n\nconst createType = (): string => {\n return \"pb.settings\";\n};\n\nexport interface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n}\n\nexport const createSettingsStorageOperations = ({\n entity\n}: CreateSettingsStorageOperationsParams): SettingsStorageOperations => {\n const getDefaults = async (): Promise<DefaultSettings | null> => {\n const keys = {\n PK: \"PS#SETTINGS\",\n SK: \"default\"\n };\n\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n\n const { appUrl, deliveryUrl } = result.Item.data;\n\n return { websiteUrl: deliveryUrl, websitePreviewUrl: appUrl };\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load default settings record.\",\n ex.code || \"DEFAULT_SETTINGS_GET_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const get = async (params: SettingsStorageOperationsGetParams) => {\n const { where } = params;\n\n const keys = {\n PK: createPartitionKey(where),\n SK: createSortKey(where)\n };\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load settings record.\",\n ex.code || \"SETTINGS_GET_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const create = async (params: SettingsStorageOperationsCreateParams) => {\n const { settings } = params;\n const keys = {\n PK: createPartitionKey(settings),\n SK: createSortKey(settings)\n };\n try {\n await entity.put({\n ...settings,\n TYPE: createType(),\n ...keys\n });\n\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create settings record.\",\n ex.code || \"SETTINGS_CREATE_ERROR\",\n {\n settings,\n keys\n }\n );\n }\n };\n\n const update = async (params: SettingsStorageOperationsUpdateParams) => {\n const { original, settings } = params;\n const keys = {\n PK: createPartitionKey(settings),\n SK: createSortKey(settings)\n };\n try {\n await entity.put({\n ...settings,\n TYPE: createType(),\n ...keys\n });\n\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update settings record.\",\n ex.code || \"SETTINGS_UPDATE_ERROR\",\n {\n original,\n settings,\n keys\n }\n );\n }\n };\n /**\n * We can simply return the partition key for this storage operations.\n */\n const createCacheKey = (params: DefaultSettingsCrudOptions): string => {\n return createPartitionKey(params);\n };\n\n return {\n get,\n getDefaults,\n create,\n update,\n createCacheKey\n };\n};\n"],"mappings":";;;;;;;;;;;AASA;;AACA;;;;;;AAWA,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EAC/D,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,MAAMG,KAAe,GAAG,EAAxB;;EACA,IAAIF,MAAM,KAAK,KAAf,EAAsB;IAClBE,KAAK,CAACC,IAAN,CAAY,KAAIH,MAAO,EAAvB;EACH;;EACD,IAAIC,MAAM,KAAK,KAAf,EAAsB;IAClBC,KAAK,CAACC,IAAN,CAAY,KAAIF,MAAO,EAAvB;EACH;;EACDC,KAAK,CAACC,IAAN,CAAW,aAAX;EAEA,OAAOD,KAAK,CAACE,IAAN,CAAW,GAAX,CAAP;AACH,CAZD;AAcA;AACA;AACA;AACA;;;AAIA,MAAMC,aAAa,GAAIN,MAAD,IAAmC;EACrD,MAAM;IAAEO;EAAF,IAAWP,MAAjB;;EACA,QAAQO,IAAR;IACI,KAAK,SAAL;MACI,OAAOA,IAAP;;IACJ;MACI,MAAM,IAAIC,cAAJ,CAAgB,oCAAhB,EAAsD,kBAAtD,EAA0E;QAC5ED;MAD4E,CAA1E,CAAN;EAJR;AAQH,CAVD;;AAYA,MAAME,UAAU,GAAG,MAAc;EAC7B,OAAO,aAAP;AACH,CAFD;;AAQO,MAAMC,+BAA+B,GAAG,CAAC;EAC5CC;AAD4C,CAAD,KAEyB;EACpE,MAAMC,WAAW,GAAG,YAA6C;IAC7D,MAAMC,IAAI,GAAG;MACTC,EAA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L,WAFG;IAGHiB,MAHG;IAIHI,MAJG;IAKHE;EALG,CAAP;AAOH,CAvHM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-page-builder-so-ddb-es",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.29.0-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-page-builder",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "7.18.3",
|
|
21
|
-
"@webiny/api-elasticsearch": "5.
|
|
22
|
-
"@webiny/api-page-builder": "5.
|
|
23
|
-
"@webiny/api-upgrade": "5.
|
|
24
|
-
"@webiny/db-dynamodb": "5.
|
|
25
|
-
"@webiny/error": "5.
|
|
26
|
-
"@webiny/handler-db": "5.
|
|
27
|
-
"@webiny/plugins": "5.
|
|
28
|
-
"@webiny/utils": "5.
|
|
21
|
+
"@webiny/api-elasticsearch": "5.29.0-beta.2",
|
|
22
|
+
"@webiny/api-page-builder": "5.29.0-beta.2",
|
|
23
|
+
"@webiny/api-upgrade": "5.29.0-beta.2",
|
|
24
|
+
"@webiny/db-dynamodb": "5.29.0-beta.2",
|
|
25
|
+
"@webiny/error": "5.29.0-beta.2",
|
|
26
|
+
"@webiny/handler-db": "5.29.0-beta.2",
|
|
27
|
+
"@webiny/plugins": "5.29.0-beta.2",
|
|
28
|
+
"@webiny/utils": "5.29.0-beta.2",
|
|
29
29
|
"dataloader": "2.1.0",
|
|
30
30
|
"dynamodb-toolbox": "0.3.5",
|
|
31
31
|
"elastic-ts": "0.7.0",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"@babel/preset-typescript": "^7.16.0",
|
|
39
39
|
"@elastic/elasticsearch": "7.12.0",
|
|
40
40
|
"@elastic/elasticsearch-mock": "0.3.0",
|
|
41
|
-
"@webiny/api-dynamodb-to-elasticsearch": "^5.
|
|
42
|
-
"@webiny/api-security": "^5.
|
|
43
|
-
"@webiny/api-tenancy": "^5.
|
|
44
|
-
"@webiny/cli": "^5.
|
|
45
|
-
"@webiny/handler": "^5.
|
|
46
|
-
"@webiny/handler-aws": "^5.
|
|
47
|
-
"@webiny/handler-graphql": "^5.
|
|
48
|
-
"@webiny/project-utils": "^5.
|
|
41
|
+
"@webiny/api-dynamodb-to-elasticsearch": "^5.29.0-beta.2",
|
|
42
|
+
"@webiny/api-security": "^5.29.0-beta.2",
|
|
43
|
+
"@webiny/api-tenancy": "^5.29.0-beta.2",
|
|
44
|
+
"@webiny/cli": "^5.29.0-beta.2",
|
|
45
|
+
"@webiny/handler": "^5.29.0-beta.2",
|
|
46
|
+
"@webiny/handler-aws": "^5.29.0-beta.2",
|
|
47
|
+
"@webiny/handler-graphql": "^5.29.0-beta.2",
|
|
48
|
+
"@webiny/project-utils": "^5.29.0-beta.2",
|
|
49
49
|
"jest": "^26.6.3",
|
|
50
50
|
"jest-dynalite": "^3.2.0",
|
|
51
51
|
"jest-environment-node": "^27.0.6",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"build": "yarn webiny run build",
|
|
62
62
|
"watch": "yarn webiny run watch"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "3a8c701139cca39dc1316d2452c6a3afdd7c1867"
|
|
65
65
|
}
|