@localazy/strapi-plugin 1.0.0-beta.1 → 1.0.0-beta.3
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/dist/_chunks/{App-BSFfgZKU.mjs → App-1cXVSnL0.mjs} +59 -32
- package/dist/_chunks/{App-D1QaIMHX.js → App-CU_T8iLT.js} +66 -39
- package/dist/_chunks/{ContentTransferSetup-DtjcF_jM.mjs → ContentTransferSetup-D2R15gJS.mjs} +27 -8
- package/dist/_chunks/{ContentTransferSetup-DHXJIxAp.js → ContentTransferSetup-DTcnul1w.js} +27 -8
- package/dist/_chunks/{GlobalSettings-BcdibqNS.mjs → GlobalSettings-7pI5vIna.mjs} +8 -5
- package/dist/_chunks/{GlobalSettings-BON3kjHK.js → GlobalSettings-D_jeqPWF.js} +8 -5
- package/dist/_chunks/{LanguagesSelector-fyAIUp7M.mjs → LanguagesSelector-D2AP7FE0.mjs} +2 -2
- package/dist/_chunks/{LanguagesSelector-BeijBEjg.js → LanguagesSelector-DU5YJVQa.js} +2 -2
- package/dist/_chunks/{has-model-changed-BMCQX2Dd.js → has-model-changed-9PCipZvK.js} +2 -2
- package/dist/_chunks/{has-model-changed-Dvtzpc9v.mjs → has-model-changed-wAFZY5Ma.mjs} +2 -2
- package/dist/_chunks/{index-CN3Gyh5F.mjs → index-CT0CH6N8.mjs} +19 -43
- package/dist/_chunks/{index-BQw2qi2G.js → index-Ca5_8RSo.js} +18 -42
- package/dist/_chunks/{isEqual-B-YVnzrp.js → isEqual--zmPN5yr.js} +1 -1
- package/dist/_chunks/{isEqual-CEyT97-3.mjs → isEqual-DPUlu6B0.mjs} +1 -1
- package/dist/_chunks/{set-DulHAQhq.mjs → set-BkLLlpnD.mjs} +4 -1
- package/dist/_chunks/{set-DUdH3vE5.js → set-DDy9ZASU.js} +4 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/modules/@common/utils/iso-locales-utils.d.ts +3 -3
- package/dist/admin/src/modules/plugin-settings/locale/en.d.ts +3 -0
- package/dist/admin/src/modules/plugin-settings/models/admin-panel-user.d.ts +11 -0
- package/dist/admin/src/modules/plugin-settings/services/strapi-users-service.d.ts +2 -1
- package/dist/admin/src/state/localazy-identity.d.ts +2 -0
- package/dist/server/index.js +236 -159
- package/dist/server/index.mjs +236 -159
- package/dist/server/src/core/index.d.ts +3 -3
- package/dist/server/src/index.d.ts +20 -5
- package/dist/server/src/lifecycles/deprecate-event-entry-in-localazy-hook.d.ts +2 -1
- package/dist/server/src/lifecycles/upload-event-entry-to-localazy-hook.d.ts +2 -1
- package/dist/server/src/middlewares/index.d.ts +5 -1
- package/dist/server/src/middlewares/verify-webhook.d.ts +5 -0
- package/dist/server/src/models/plugin/hook-params.d.ts +6 -0
- package/dist/server/src/routes/index.d.ts +12 -1
- package/dist/server/src/routes/localazy-public-transfer-routes.d.ts +11 -0
- package/dist/server/src/services/index.d.ts +3 -3
- package/dist/server/src/services/localazy-pubapi-service.d.ts +6 -5
- package/dist/server/src/utils/get-picked-flatten-keys-for-hook-entry.d.ts +4 -2
- package/package.json +1 -1
- package/dist/admin/src/modules/@common/utils/is-plugin-route.d.ts +0 -2
package/dist/server/index.mjs
CHANGED
|
@@ -9,34 +9,6 @@ import require$$0$2 from "crypto";
|
|
|
9
9
|
import require$$0$3 from "events";
|
|
10
10
|
import require$$2 from "timers";
|
|
11
11
|
import require$$8, { WebSocketServer } from "ws";
|
|
12
|
-
class RequestInitiatorHelper {
|
|
13
|
-
constructor(strapi2) {
|
|
14
|
-
this.strapi = strapi2;
|
|
15
|
-
this.ctx = strapi2.requestContext.get();
|
|
16
|
-
}
|
|
17
|
-
isInitiatedByLocalazyWebhook() {
|
|
18
|
-
if (typeof this.ctx !== "undefined") {
|
|
19
|
-
const ctxHeaders = this.ctx.headers;
|
|
20
|
-
const xLocalazyHmac = ctxHeaders["x-localazy-hmac"];
|
|
21
|
-
const xLocalazyTimestamp = ctxHeaders["x-localazy-timestamp"];
|
|
22
|
-
if (!!xLocalazyHmac && !!xLocalazyTimestamp) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
isInitiatedByLocalazyPluginUI() {
|
|
29
|
-
if (typeof this.ctx !== "undefined") {
|
|
30
|
-
const ctxHeaders = this.ctx.headers;
|
|
31
|
-
const xLocalazyInitiatedBy = ctxHeaders["x-localazy-initiated-by"];
|
|
32
|
-
if (!xLocalazyInitiatedBy) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return xLocalazyInitiatedBy === "strapi-plugin-localazy";
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
12
|
var objectProto$r = Object.prototype;
|
|
41
13
|
function isPrototype$4(value) {
|
|
42
14
|
var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto$r;
|
|
@@ -826,7 +798,7 @@ var merge = createAssigner(function(object, source, srcIndex) {
|
|
|
826
798
|
baseMerge(object, source, srcIndex);
|
|
827
799
|
});
|
|
828
800
|
const name = "@localazy/strapi-plugin";
|
|
829
|
-
const version$1 = "1.0.0-beta.
|
|
801
|
+
const version$1 = "1.0.0-beta.2";
|
|
830
802
|
const description = "The official Strapi Plugin by Localazy.";
|
|
831
803
|
const keywords = [
|
|
832
804
|
"strapi",
|
|
@@ -21667,6 +21639,31 @@ const require$$18 = {
|
|
|
21667
21639
|
var distExports = dist$1.exports;
|
|
21668
21640
|
const io = /* @__PURE__ */ getDefaultExportFromCjs(distExports);
|
|
21669
21641
|
const { Server: Server2, Namespace, Socket: Socket3 } = io;
|
|
21642
|
+
const bootstrap = ({ strapi: strapi2 }) => {
|
|
21643
|
+
strapi2.db.lifecycles.subscribe(async (event) => {
|
|
21644
|
+
const action = event.action;
|
|
21645
|
+
switch (action) {
|
|
21646
|
+
case "beforeFindMany":
|
|
21647
|
+
case "beforeFindOne": {
|
|
21648
|
+
deepPopulateHook(event);
|
|
21649
|
+
break;
|
|
21650
|
+
}
|
|
21651
|
+
}
|
|
21652
|
+
});
|
|
21653
|
+
process.nextTick(async () => {
|
|
21654
|
+
const io2 = new Server2(strapi2.server.httpServer, {
|
|
21655
|
+
cors: {
|
|
21656
|
+
origin: "*",
|
|
21657
|
+
methods: ["GET", "POST"]
|
|
21658
|
+
},
|
|
21659
|
+
// this must be a constructor
|
|
21660
|
+
wsEngine: WebSocketServer
|
|
21661
|
+
});
|
|
21662
|
+
strapi2.StrapIO = io2;
|
|
21663
|
+
});
|
|
21664
|
+
};
|
|
21665
|
+
const destroy = ({ strapi: strapi2 }) => {
|
|
21666
|
+
};
|
|
21670
21667
|
const isoStrapiToLocalazy = (isoStrapi) => {
|
|
21671
21668
|
if (!isoStrapi) {
|
|
21672
21669
|
return null;
|
|
@@ -22951,41 +22948,25 @@ class PluginSettingsServiceHelper {
|
|
|
22951
22948
|
return this.pluginSettings?.download?.uiLanguages || [];
|
|
22952
22949
|
}
|
|
22953
22950
|
}
|
|
22954
|
-
const shouldProcessEntry = (contentTransferSetup,
|
|
22951
|
+
const shouldProcessEntry = (contentTransferSetup, contextModel) => {
|
|
22955
22952
|
let key;
|
|
22956
22953
|
const modelContentTransferSetup = contentTransferSetup.setup.find((model) => {
|
|
22957
22954
|
key = Object.keys(model)[0];
|
|
22958
|
-
return key ===
|
|
22955
|
+
return key === contextModel;
|
|
22959
22956
|
});
|
|
22960
22957
|
if (!modelContentTransferSetup) {
|
|
22961
22958
|
return void 0;
|
|
22962
22959
|
}
|
|
22963
22960
|
return !!modelContentTransferSetup[key].__model__;
|
|
22964
22961
|
};
|
|
22965
|
-
const getEventEntries = async (
|
|
22966
|
-
|
|
22967
|
-
|
|
22968
|
-
case "
|
|
22969
|
-
|
|
22970
|
-
|
|
22971
|
-
documentId: event.result.documentId,
|
|
22972
|
-
locUploadPLevel: 6
|
|
22973
|
-
})
|
|
22974
|
-
];
|
|
22975
|
-
return entry;
|
|
22976
|
-
}
|
|
22977
|
-
case "beforeDelete": {
|
|
22978
|
-
const whereId = event.params.where.id;
|
|
22979
|
-
const entryById = await strapi.entityService.findOne(event.model.uid, whereId);
|
|
22980
|
-
if (!entryById) {
|
|
22981
|
-
return [];
|
|
22982
|
-
}
|
|
22983
|
-
if (entryById.id !== whereId) {
|
|
22984
|
-
return [];
|
|
22985
|
-
}
|
|
22986
|
-
const documentId = entryById.documentId;
|
|
22962
|
+
const getEventEntries = async (params) => {
|
|
22963
|
+
const { context, documentId } = params;
|
|
22964
|
+
switch (context.action) {
|
|
22965
|
+
case "create":
|
|
22966
|
+
case "update":
|
|
22967
|
+
case "delete": {
|
|
22987
22968
|
const entry = [
|
|
22988
|
-
await strapi.documents(
|
|
22969
|
+
await strapi.documents(context.contentType.uid).findOne({
|
|
22989
22970
|
documentId,
|
|
22990
22971
|
locUploadPLevel: 6
|
|
22991
22972
|
})
|
|
@@ -22997,29 +22978,31 @@ const getEventEntries = async (event) => {
|
|
|
22997
22978
|
}
|
|
22998
22979
|
}
|
|
22999
22980
|
};
|
|
23000
|
-
const shouldSkipAction = async (
|
|
22981
|
+
const shouldSkipAction = async (context) => {
|
|
23001
22982
|
const PluginSettingsServiceHelperInstance = new PluginSettingsServiceHelper();
|
|
23002
22983
|
await PluginSettingsServiceHelperInstance.setup();
|
|
23003
|
-
switch (
|
|
23004
|
-
case "
|
|
22984
|
+
switch (context.action) {
|
|
22985
|
+
case "create": {
|
|
23005
22986
|
if (!PluginSettingsServiceHelperInstance.shouldAllowAutomatedCreatedTrigger()) {
|
|
23006
22987
|
strapi.log.info(
|
|
23007
|
-
`Localazy Plugin: Skipping ${
|
|
22988
|
+
`Localazy Plugin: Skipping ${context.action} hook because automated created trigger is disabled.`
|
|
23008
22989
|
);
|
|
23009
22990
|
return true;
|
|
23010
22991
|
}
|
|
23011
22992
|
return false;
|
|
23012
22993
|
}
|
|
23013
|
-
case "
|
|
22994
|
+
case "update": {
|
|
23014
22995
|
if (!PluginSettingsServiceHelperInstance.shouldAllowAutomatedUpdatedTrigger()) {
|
|
23015
|
-
strapi.log.info(
|
|
22996
|
+
strapi.log.info(
|
|
22997
|
+
`Localazy Plugin: Skipping ${context.action} hook because automated update trigger is disabled.`
|
|
22998
|
+
);
|
|
23016
22999
|
return true;
|
|
23017
23000
|
}
|
|
23018
23001
|
return false;
|
|
23019
23002
|
}
|
|
23020
|
-
case "
|
|
23003
|
+
case "delete": {
|
|
23021
23004
|
if (!PluginSettingsServiceHelperInstance.shouldAllowDeprecateOnDeletion()) {
|
|
23022
|
-
strapi.log.info(`Localazy Plugin: Skipping ${
|
|
23005
|
+
strapi.log.info(`Localazy Plugin: Skipping ${context.action} hook because deprecate on deletion is disabled.`);
|
|
23023
23006
|
return true;
|
|
23024
23007
|
}
|
|
23025
23008
|
return false;
|
|
@@ -23029,19 +23012,21 @@ const shouldSkipAction = async (event) => {
|
|
|
23029
23012
|
}
|
|
23030
23013
|
}
|
|
23031
23014
|
};
|
|
23032
|
-
const getPickedFlattenKeysForHookEntry = async (
|
|
23015
|
+
const getPickedFlattenKeysForHookEntry = async (params) => {
|
|
23016
|
+
const { context, locale } = params;
|
|
23017
|
+
const eventEntryLocale = locale;
|
|
23033
23018
|
const LocalazyUserService2 = getLocalazyUserService();
|
|
23034
23019
|
const LocalazyPubAPIService2 = getLocalazyPubAPIService();
|
|
23035
23020
|
const StrapiI18nService2 = getStrapiI18nService();
|
|
23036
23021
|
const contentTransferSetup = await getPluginSettingsService().getContentTransferSetup();
|
|
23037
|
-
const
|
|
23038
|
-
strapi.log.info(`${
|
|
23022
|
+
const contextAction = context.action;
|
|
23023
|
+
strapi.log.info(`${contextAction} triggered`);
|
|
23039
23024
|
if (!contentTransferSetup.has_setup) {
|
|
23040
23025
|
strapi.log.warn("Localazy Plugin: Content Transfer Setup is not set up; the operation won't proceed");
|
|
23041
23026
|
return;
|
|
23042
23027
|
}
|
|
23043
|
-
const
|
|
23044
|
-
const shouldProcess = shouldProcessEntry(contentTransferSetup,
|
|
23028
|
+
const contextModel = context.contentType.collectionName;
|
|
23029
|
+
const shouldProcess = shouldProcessEntry(contentTransferSetup, contextModel);
|
|
23045
23030
|
if (typeof shouldProcess === "undefined") {
|
|
23046
23031
|
return;
|
|
23047
23032
|
}
|
|
@@ -23055,7 +23040,7 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23055
23040
|
strapi.log.error("Localazy Plugin: Localazy user is not logged in; the operation won't proceed");
|
|
23056
23041
|
return;
|
|
23057
23042
|
}
|
|
23058
|
-
if (await shouldSkipAction(
|
|
23043
|
+
if (await shouldSkipAction(context)) {
|
|
23059
23044
|
strapi.log.info("Localazy Plugin: Automated action skipped");
|
|
23060
23045
|
return;
|
|
23061
23046
|
}
|
|
@@ -23065,28 +23050,29 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23065
23050
|
const sourceLanguage = projectLanguages.find((language3) => language3.id === projectSourceLanguageId);
|
|
23066
23051
|
const projectSourceLanguageCode = sourceLanguage.code;
|
|
23067
23052
|
const strapiLocales = await StrapiI18nService2.getLocales();
|
|
23068
|
-
const defaultLocale = strapiLocales.find((
|
|
23053
|
+
const defaultLocale = strapiLocales.find((locale2) => locale2.isDefault);
|
|
23069
23054
|
const strapiDefaultLocale = defaultLocale ? isoStrapiToLocalazy(defaultLocale.code) : config.default.LOCALAZY_DEFAULT_LOCALE;
|
|
23070
23055
|
if (strapiDefaultLocale !== projectSourceLanguageCode) {
|
|
23071
23056
|
strapi.log.warn("Localazy Plugin: Source locales do not match; the operation won't proceed");
|
|
23072
23057
|
return;
|
|
23073
23058
|
}
|
|
23074
|
-
|
|
23075
|
-
|
|
23076
|
-
|
|
23059
|
+
if (eventEntryLocale !== "*" && isoStrapiToLocalazy(eventEntryLocale) !== projectSourceLanguageCode) {
|
|
23060
|
+
strapi.log.info(
|
|
23061
|
+
"Localazy Plugin: Triggered locale is not in Localazy source language; the operation won't proceed"
|
|
23062
|
+
);
|
|
23077
23063
|
return;
|
|
23078
23064
|
}
|
|
23079
|
-
const
|
|
23080
|
-
|
|
23081
|
-
|
|
23065
|
+
const modelUid = context.contentType.uid;
|
|
23066
|
+
const entries = await getEventEntries(params);
|
|
23067
|
+
if (entries.length === 0) {
|
|
23082
23068
|
return;
|
|
23083
23069
|
}
|
|
23084
23070
|
const reducedEntries = omitDeep(entries, ["locale", "createdAt", "updatedAt", "publishedAt"]);
|
|
23085
|
-
const transferSetupModel = findSetupModelByCollectionName(contentTransferSetup.setup,
|
|
23086
|
-
const currentTransferSetupModel = transferSetupModel[
|
|
23071
|
+
const transferSetupModel = findSetupModelByCollectionName(contentTransferSetup.setup, contextModel);
|
|
23072
|
+
const currentTransferSetupModel = transferSetupModel[contextModel];
|
|
23087
23073
|
const pickPaths = getPickPaths(currentTransferSetupModel);
|
|
23088
23074
|
if (!pickPaths.length) {
|
|
23089
|
-
strapi.log.warn(`No fields for collection ${
|
|
23075
|
+
strapi.log.warn(`No fields for collection ${contextModel} transfer are enabled.`);
|
|
23090
23076
|
return;
|
|
23091
23077
|
}
|
|
23092
23078
|
const pickPathsWithUid = pickPaths.map((pickPath) => `${modelUid}.${pickPath}`);
|
|
@@ -23102,11 +23088,12 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23102
23088
|
const pickedFlatten = pickEntries(flatten, pickPathsWithUid);
|
|
23103
23089
|
return {
|
|
23104
23090
|
pickedFlatten,
|
|
23105
|
-
eventEntryLocale
|
|
23091
|
+
eventEntryLocale,
|
|
23092
|
+
projectSourceLanguageCode
|
|
23106
23093
|
};
|
|
23107
23094
|
};
|
|
23108
|
-
const uploadEventEntryToLocalazyHook = async (
|
|
23109
|
-
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(
|
|
23095
|
+
const uploadEventEntryToLocalazyHook = async (params) => {
|
|
23096
|
+
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(params);
|
|
23110
23097
|
if (typeof pickedFlattedResult === "undefined") {
|
|
23111
23098
|
return;
|
|
23112
23099
|
}
|
|
@@ -23850,12 +23837,12 @@ const LocalazyApiClientFactory = async () => {
|
|
|
23850
23837
|
return api;
|
|
23851
23838
|
};
|
|
23852
23839
|
const delay = (ms2 = 150) => new Promise((resolve) => setTimeout(resolve, ms2));
|
|
23853
|
-
const deprecateEventEntryInLocalazyHook = async (
|
|
23854
|
-
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(
|
|
23840
|
+
const deprecateEventEntryInLocalazyHook = async (params) => {
|
|
23841
|
+
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(params);
|
|
23855
23842
|
if (typeof pickedFlattedResult === "undefined") {
|
|
23856
23843
|
return;
|
|
23857
23844
|
}
|
|
23858
|
-
const { pickedFlatten,
|
|
23845
|
+
const { pickedFlatten, projectSourceLanguageCode } = pickedFlattedResult;
|
|
23859
23846
|
const LocalazyUserService2 = getLocalazyUserService();
|
|
23860
23847
|
const LocalazyPubApiService = getLocalazyPubAPIService();
|
|
23861
23848
|
const user = await LocalazyUserService2.getUser();
|
|
@@ -23868,7 +23855,7 @@ const deprecateEventEntryInLocalazyHook = async (event) => {
|
|
|
23868
23855
|
const projectKeys = await LocalazyApi.files.listKeys({
|
|
23869
23856
|
project: user.project.id,
|
|
23870
23857
|
file: strapiFile.id,
|
|
23871
|
-
lang:
|
|
23858
|
+
lang: projectSourceLanguageCode
|
|
23872
23859
|
});
|
|
23873
23860
|
if (!projectKeys) {
|
|
23874
23861
|
strapi.log.error(`Keys not found for file ${strapiFile.id}`);
|
|
@@ -23894,65 +23881,50 @@ const deprecateEventEntryInLocalazyHook = async (event) => {
|
|
|
23894
23881
|
success: true
|
|
23895
23882
|
};
|
|
23896
23883
|
};
|
|
23897
|
-
const
|
|
23898
|
-
strapi2.
|
|
23899
|
-
|
|
23900
|
-
|
|
23901
|
-
|
|
23902
|
-
case "
|
|
23903
|
-
case "beforeFindOne": {
|
|
23904
|
-
deepPopulateHook(event);
|
|
23905
|
-
break;
|
|
23906
|
-
}
|
|
23907
|
-
case "afterCreate":
|
|
23908
|
-
case "afterUpdate": {
|
|
23884
|
+
const register = ({ strapi: strapi2 }) => {
|
|
23885
|
+
strapi2.documents.use(async (context, next) => {
|
|
23886
|
+
let result;
|
|
23887
|
+
switch (context.action) {
|
|
23888
|
+
case "create":
|
|
23889
|
+
case "update":
|
|
23909
23890
|
try {
|
|
23910
|
-
|
|
23911
|
-
|
|
23912
|
-
|
|
23913
|
-
|
|
23914
|
-
|
|
23915
|
-
strapi2.log.info(`${action} hook result: ${JSON.stringify(result)}`);
|
|
23916
|
-
}
|
|
23891
|
+
result = await next();
|
|
23892
|
+
const hookResult = await uploadEventEntryToLocalazyHook({
|
|
23893
|
+
context,
|
|
23894
|
+
documentId: result.documentId,
|
|
23895
|
+
locale: context.params.locale || context["locale"]
|
|
23917
23896
|
});
|
|
23897
|
+
if (typeof hookResult !== "undefined") {
|
|
23898
|
+
strapi2.log.info(`${context.action} hook result: ${JSON.stringify(hookResult)}`);
|
|
23899
|
+
}
|
|
23918
23900
|
} catch (e3) {
|
|
23919
23901
|
strapi2.log.error(e3);
|
|
23920
23902
|
} finally {
|
|
23921
23903
|
break;
|
|
23922
23904
|
}
|
|
23923
|
-
|
|
23924
|
-
case "beforeDelete": {
|
|
23905
|
+
case "delete": {
|
|
23925
23906
|
try {
|
|
23926
|
-
|
|
23927
|
-
|
|
23928
|
-
|
|
23929
|
-
|
|
23930
|
-
|
|
23931
|
-
|
|
23907
|
+
const hookResult = await deprecateEventEntryInLocalazyHook({
|
|
23908
|
+
context,
|
|
23909
|
+
documentId: context.params.documentId,
|
|
23910
|
+
locale: context.params.locale || context["locale"]
|
|
23911
|
+
});
|
|
23912
|
+
if (typeof hookResult !== "undefined") {
|
|
23913
|
+
strapi2.log.info(`${context.action} hook result: ${JSON.stringify(hookResult)}`);
|
|
23932
23914
|
}
|
|
23915
|
+
result = await next();
|
|
23933
23916
|
} catch (e3) {
|
|
23934
23917
|
strapi2.log.error(e3);
|
|
23935
23918
|
} finally {
|
|
23936
23919
|
break;
|
|
23937
23920
|
}
|
|
23938
23921
|
}
|
|
23922
|
+
default:
|
|
23923
|
+
result = await next();
|
|
23924
|
+
break;
|
|
23939
23925
|
}
|
|
23926
|
+
return result;
|
|
23940
23927
|
});
|
|
23941
|
-
process.nextTick(async () => {
|
|
23942
|
-
const io2 = new Server2(strapi2.server.httpServer, {
|
|
23943
|
-
cors: {
|
|
23944
|
-
origin: "*",
|
|
23945
|
-
methods: ["GET", "POST"]
|
|
23946
|
-
},
|
|
23947
|
-
// this must be a constructor
|
|
23948
|
-
wsEngine: WebSocketServer
|
|
23949
|
-
});
|
|
23950
|
-
strapi2.StrapIO = io2;
|
|
23951
|
-
});
|
|
23952
|
-
};
|
|
23953
|
-
const destroy = ({ strapi: strapi2 }) => {
|
|
23954
|
-
};
|
|
23955
|
-
const register = ({ strapi: strapi2 }) => {
|
|
23956
23928
|
};
|
|
23957
23929
|
const contentTypes = {};
|
|
23958
23930
|
const LocalazyUserController = ({ strapi: strapi2 }) => ({
|
|
@@ -24195,13 +24167,66 @@ const controllers = {
|
|
|
24195
24167
|
PluginSettingsController,
|
|
24196
24168
|
LocalazyTransferController
|
|
24197
24169
|
};
|
|
24198
|
-
const
|
|
24170
|
+
const verifyWebhook = (config2, { strapi: strapi2 }) => {
|
|
24171
|
+
return async (ctx, next) => {
|
|
24172
|
+
try {
|
|
24173
|
+
const pluginSettingsServiceHelper = new PluginSettingsServiceHelper();
|
|
24174
|
+
await pluginSettingsServiceHelper.setup();
|
|
24175
|
+
if (!pluginSettingsServiceHelper.shouldAllowWebhookDownloadProcess()) {
|
|
24176
|
+
throw new Error("Localazy Plugin: Webhook download process is disabled; terminating execution");
|
|
24177
|
+
}
|
|
24178
|
+
const requestBody = ctx.request.body;
|
|
24179
|
+
strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure started`);
|
|
24180
|
+
const LocalazyPubApiService = getLocalazyPubAPIService();
|
|
24181
|
+
const LocalazyUserService2 = getLocalazyUserService();
|
|
24182
|
+
const user = await LocalazyUserService2.getUser();
|
|
24183
|
+
const secret = await LocalazyPubApiService.getWebhooksSecret(user.project.id);
|
|
24184
|
+
const xLocalazyHmac = ctx.request.header["x-localazy-hmac"];
|
|
24185
|
+
const xLocalazyTimestamp = ctx.request.header["x-localazy-timestamp"];
|
|
24186
|
+
const THRESHOLD = 9e5;
|
|
24187
|
+
const intXLocalazyTimestamp = parseInt(xLocalazyTimestamp);
|
|
24188
|
+
if (Number.isNaN(intXLocalazyTimestamp)) {
|
|
24189
|
+
throw new Error("Localazy Plugin: Webhook request invalid timestamp provided; terminating execution");
|
|
24190
|
+
}
|
|
24191
|
+
if (intXLocalazyTimestamp * 1e3 + THRESHOLD < Date.now()) {
|
|
24192
|
+
throw new Error("Localazy Plugin: Webhook request is older than threshold; terminating execution");
|
|
24193
|
+
}
|
|
24194
|
+
const strapiHmac = require$$0$2.createHmac("sha256", secret);
|
|
24195
|
+
const signedMessage = strapiHmac.update(`${xLocalazyTimestamp}-${JSON.stringify(requestBody)}`).digest("hex");
|
|
24196
|
+
if (xLocalazyHmac !== signedMessage) {
|
|
24197
|
+
throw new Error("Localazy Plugin: Webhook verification did not pass; terminating execution");
|
|
24198
|
+
} else {
|
|
24199
|
+
strapi2.log.info("Localazy Plugin: Webhook verification passed");
|
|
24200
|
+
}
|
|
24201
|
+
if (!ctx.state.user) {
|
|
24202
|
+
const webhookAuthorId = pluginSettingsServiceHelper.getWebhookAuthorId();
|
|
24203
|
+
if (Number.isNaN(webhookAuthorId)) {
|
|
24204
|
+
throw new Error("Localazy Plugin: Webhook author is not set; terminating execution");
|
|
24205
|
+
}
|
|
24206
|
+
ctx.state.user = {
|
|
24207
|
+
id: webhookAuthorId
|
|
24208
|
+
};
|
|
24209
|
+
}
|
|
24210
|
+
await next();
|
|
24211
|
+
strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure finished`);
|
|
24212
|
+
} catch (e3) {
|
|
24213
|
+
strapi2.log.warn(e3.message);
|
|
24214
|
+
ctx.body = {
|
|
24215
|
+
success: false,
|
|
24216
|
+
message: e3.message
|
|
24217
|
+
};
|
|
24218
|
+
}
|
|
24219
|
+
};
|
|
24220
|
+
};
|
|
24221
|
+
const middlewares = {
|
|
24222
|
+
verifyWebhook
|
|
24223
|
+
};
|
|
24199
24224
|
const policies = {};
|
|
24200
|
-
const ROUTE_PREFIX$
|
|
24225
|
+
const ROUTE_PREFIX$6 = "/user";
|
|
24201
24226
|
const LocalazyUserRoutes = [
|
|
24202
24227
|
{
|
|
24203
24228
|
method: "GET",
|
|
24204
|
-
path: `${ROUTE_PREFIX$
|
|
24229
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24205
24230
|
handler: "LocalazyUserController.getUser",
|
|
24206
24231
|
config: {
|
|
24207
24232
|
policies: []
|
|
@@ -24209,7 +24234,7 @@ const LocalazyUserRoutes = [
|
|
|
24209
24234
|
},
|
|
24210
24235
|
{
|
|
24211
24236
|
method: "PUT",
|
|
24212
|
-
path: `${ROUTE_PREFIX$
|
|
24237
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24213
24238
|
handler: "LocalazyUserController.updateUser",
|
|
24214
24239
|
config: {
|
|
24215
24240
|
policies: []
|
|
@@ -24217,18 +24242,18 @@ const LocalazyUserRoutes = [
|
|
|
24217
24242
|
},
|
|
24218
24243
|
{
|
|
24219
24244
|
method: "DELETE",
|
|
24220
|
-
path: `${ROUTE_PREFIX$
|
|
24245
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24221
24246
|
handler: "LocalazyUserController.deleteUser",
|
|
24222
24247
|
config: {
|
|
24223
24248
|
policies: []
|
|
24224
24249
|
}
|
|
24225
24250
|
}
|
|
24226
24251
|
];
|
|
24227
|
-
const ROUTE_PREFIX$
|
|
24252
|
+
const ROUTE_PREFIX$5 = "/auth";
|
|
24228
24253
|
const LocalazyAuthRoutes = [
|
|
24229
24254
|
{
|
|
24230
24255
|
method: "GET",
|
|
24231
|
-
path: `${ROUTE_PREFIX$
|
|
24256
|
+
path: `${ROUTE_PREFIX$5}/generate-keys`,
|
|
24232
24257
|
handler: "LocalazyAuthController.generateKeys",
|
|
24233
24258
|
config: {
|
|
24234
24259
|
policies: []
|
|
@@ -24236,18 +24261,18 @@ const LocalazyAuthRoutes = [
|
|
|
24236
24261
|
},
|
|
24237
24262
|
{
|
|
24238
24263
|
method: "GET",
|
|
24239
|
-
path: `${ROUTE_PREFIX$
|
|
24264
|
+
path: `${ROUTE_PREFIX$5}/continuous-poll`,
|
|
24240
24265
|
handler: "LocalazyAuthController.continuousPoll",
|
|
24241
24266
|
config: {
|
|
24242
24267
|
policies: []
|
|
24243
24268
|
}
|
|
24244
24269
|
}
|
|
24245
24270
|
];
|
|
24246
|
-
const ROUTE_PREFIX$
|
|
24271
|
+
const ROUTE_PREFIX$4 = "/plugin-settings";
|
|
24247
24272
|
const PluginSettingsRoutes = [
|
|
24248
24273
|
{
|
|
24249
24274
|
method: "GET",
|
|
24250
|
-
path: `${ROUTE_PREFIX$
|
|
24275
|
+
path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
|
|
24251
24276
|
handler: "PluginSettingsController.getContentTransferSetup",
|
|
24252
24277
|
config: {
|
|
24253
24278
|
policies: []
|
|
@@ -24255,7 +24280,7 @@ const PluginSettingsRoutes = [
|
|
|
24255
24280
|
},
|
|
24256
24281
|
{
|
|
24257
24282
|
method: "PUT",
|
|
24258
|
-
path: `${ROUTE_PREFIX$
|
|
24283
|
+
path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
|
|
24259
24284
|
handler: "PluginSettingsController.updateContentTransferSetup",
|
|
24260
24285
|
config: {
|
|
24261
24286
|
policies: []
|
|
@@ -24263,7 +24288,7 @@ const PluginSettingsRoutes = [
|
|
|
24263
24288
|
},
|
|
24264
24289
|
{
|
|
24265
24290
|
method: "GET",
|
|
24266
|
-
path: `${ROUTE_PREFIX$
|
|
24291
|
+
path: `${ROUTE_PREFIX$4}/plugin-settings`,
|
|
24267
24292
|
handler: "PluginSettingsController.getPluginSettings",
|
|
24268
24293
|
config: {
|
|
24269
24294
|
policies: []
|
|
@@ -24271,18 +24296,18 @@ const PluginSettingsRoutes = [
|
|
|
24271
24296
|
},
|
|
24272
24297
|
{
|
|
24273
24298
|
method: "PUT",
|
|
24274
|
-
path: `${ROUTE_PREFIX$
|
|
24299
|
+
path: `${ROUTE_PREFIX$4}/plugin-settings`,
|
|
24275
24300
|
handler: "PluginSettingsController.updatePluginSettings",
|
|
24276
24301
|
config: {
|
|
24277
24302
|
policies: []
|
|
24278
24303
|
}
|
|
24279
24304
|
}
|
|
24280
24305
|
];
|
|
24281
|
-
const ROUTE_PREFIX$
|
|
24306
|
+
const ROUTE_PREFIX$3 = "/strapi";
|
|
24282
24307
|
const StrapiRoutes = [
|
|
24283
24308
|
{
|
|
24284
24309
|
method: "GET",
|
|
24285
|
-
path: `${ROUTE_PREFIX$
|
|
24310
|
+
path: `${ROUTE_PREFIX$3}/models`,
|
|
24286
24311
|
handler: "StrapiController.getModels",
|
|
24287
24312
|
config: {
|
|
24288
24313
|
policies: []
|
|
@@ -24290,7 +24315,7 @@ const StrapiRoutes = [
|
|
|
24290
24315
|
},
|
|
24291
24316
|
{
|
|
24292
24317
|
method: "GET",
|
|
24293
|
-
path: `${ROUTE_PREFIX$
|
|
24318
|
+
path: `${ROUTE_PREFIX$3}/localizable-models`,
|
|
24294
24319
|
handler: "StrapiController.getLocalizableModels",
|
|
24295
24320
|
config: {
|
|
24296
24321
|
policies: []
|
|
@@ -24298,7 +24323,7 @@ const StrapiRoutes = [
|
|
|
24298
24323
|
},
|
|
24299
24324
|
{
|
|
24300
24325
|
method: "POST",
|
|
24301
|
-
path: `${ROUTE_PREFIX$
|
|
24326
|
+
path: `${ROUTE_PREFIX$3}/lifecycle/localazy-webhooks`,
|
|
24302
24327
|
handler: "StrapiController.postLifecycleLocalazyWebhooks",
|
|
24303
24328
|
config: {
|
|
24304
24329
|
policies: []
|
|
@@ -24306,18 +24331,18 @@ const StrapiRoutes = [
|
|
|
24306
24331
|
},
|
|
24307
24332
|
{
|
|
24308
24333
|
method: "GET",
|
|
24309
|
-
path: `${ROUTE_PREFIX$
|
|
24334
|
+
path: `${ROUTE_PREFIX$3}/version`,
|
|
24310
24335
|
handler: "StrapiController.getPluginVersion",
|
|
24311
24336
|
config: {
|
|
24312
24337
|
policies: []
|
|
24313
24338
|
}
|
|
24314
24339
|
}
|
|
24315
24340
|
];
|
|
24316
|
-
const ROUTE_PREFIX$
|
|
24341
|
+
const ROUTE_PREFIX$2 = "/transfer";
|
|
24317
24342
|
const LocalazyTransferRoutes = [
|
|
24318
24343
|
{
|
|
24319
24344
|
method: "POST",
|
|
24320
|
-
path: `${ROUTE_PREFIX$
|
|
24345
|
+
path: `${ROUTE_PREFIX$2}/upload`,
|
|
24321
24346
|
handler: "LocalazyTransferController.upload",
|
|
24322
24347
|
config: {
|
|
24323
24348
|
policies: []
|
|
@@ -24325,27 +24350,40 @@ const LocalazyTransferRoutes = [
|
|
|
24325
24350
|
},
|
|
24326
24351
|
{
|
|
24327
24352
|
method: "POST",
|
|
24328
|
-
path: `${ROUTE_PREFIX$
|
|
24353
|
+
path: `${ROUTE_PREFIX$2}/download`,
|
|
24329
24354
|
handler: "LocalazyTransferController.download",
|
|
24330
24355
|
config: {
|
|
24331
24356
|
policies: []
|
|
24332
24357
|
}
|
|
24333
24358
|
}
|
|
24334
24359
|
];
|
|
24335
|
-
const ROUTE_PREFIX = "/project";
|
|
24360
|
+
const ROUTE_PREFIX$1 = "/project";
|
|
24336
24361
|
const LocalazyProjectRoutes = [
|
|
24337
24362
|
{
|
|
24338
24363
|
method: "GET",
|
|
24339
|
-
path: `${ROUTE_PREFIX}`,
|
|
24364
|
+
path: `${ROUTE_PREFIX$1}`,
|
|
24340
24365
|
handler: "LocalazyProjectController.getConnectedProject",
|
|
24341
24366
|
config: {
|
|
24342
24367
|
policies: []
|
|
24343
24368
|
}
|
|
24344
24369
|
}
|
|
24345
24370
|
];
|
|
24371
|
+
const ROUTE_PREFIX = "/public/transfer";
|
|
24372
|
+
const LocalazyPublicTransferRoutes = [
|
|
24373
|
+
{
|
|
24374
|
+
method: "POST",
|
|
24375
|
+
path: `${ROUTE_PREFIX}/download`,
|
|
24376
|
+
handler: "LocalazyTransferController.download",
|
|
24377
|
+
config: {
|
|
24378
|
+
policies: [],
|
|
24379
|
+
auth: false,
|
|
24380
|
+
// make the route public
|
|
24381
|
+
middlewares: [`plugin::${PLUGIN_NAME}.verifyWebhook`]
|
|
24382
|
+
}
|
|
24383
|
+
}
|
|
24384
|
+
];
|
|
24346
24385
|
const routes = {
|
|
24347
24386
|
"content-api": {
|
|
24348
|
-
type: "content-api",
|
|
24349
24387
|
routes: [...StrapiRoutes]
|
|
24350
24388
|
},
|
|
24351
24389
|
admin: {
|
|
@@ -24358,8 +24396,10 @@ const routes = {
|
|
|
24358
24396
|
...LocalazyTransferRoutes,
|
|
24359
24397
|
...LocalazyProjectRoutes
|
|
24360
24398
|
]
|
|
24399
|
+
},
|
|
24400
|
+
LocalazyPublicTransferRoutes: {
|
|
24401
|
+
routes: [...LocalazyPublicTransferRoutes]
|
|
24361
24402
|
}
|
|
24362
|
-
// localazyPublicTransferRoutes,
|
|
24363
24403
|
};
|
|
24364
24404
|
const KEY$2 = "identity";
|
|
24365
24405
|
const emptyIdentity = {
|
|
@@ -24499,13 +24539,23 @@ const LocalazyPubAPIService = ({ strapi: strapi2 }) => ({
|
|
|
24499
24539
|
}
|
|
24500
24540
|
},
|
|
24501
24541
|
async getProject(projectId, addOrganization = true, addLanguages = true) {
|
|
24502
|
-
|
|
24503
|
-
|
|
24542
|
+
try {
|
|
24543
|
+
const projects = await this.listProjects(addOrganization, addLanguages);
|
|
24544
|
+
return projects.find((project) => project.id === projectId) || null;
|
|
24545
|
+
} catch (e3) {
|
|
24546
|
+
strapi2.log.error(e3);
|
|
24547
|
+
return null;
|
|
24548
|
+
}
|
|
24504
24549
|
},
|
|
24505
24550
|
async getWebhooksSecret(projectId) {
|
|
24506
|
-
|
|
24507
|
-
|
|
24508
|
-
|
|
24551
|
+
try {
|
|
24552
|
+
const LocalazyApi = await LocalazyApiClientFactory();
|
|
24553
|
+
const result = await LocalazyApi.webhooks.getSecret({ project: projectId });
|
|
24554
|
+
return result;
|
|
24555
|
+
} catch (e3) {
|
|
24556
|
+
strapi2.log.error(e3);
|
|
24557
|
+
return null;
|
|
24558
|
+
}
|
|
24509
24559
|
}
|
|
24510
24560
|
});
|
|
24511
24561
|
const KEY$1 = "content-transfer-setup";
|
|
@@ -25041,6 +25091,34 @@ const shouldSetDownloadedProperty = (modelContentTransferSetup, parsedKeyRest) =
|
|
|
25041
25091
|
return "no";
|
|
25042
25092
|
}
|
|
25043
25093
|
};
|
|
25094
|
+
class RequestInitiatorHelper {
|
|
25095
|
+
constructor(strapi2) {
|
|
25096
|
+
this.strapi = strapi2;
|
|
25097
|
+
this.ctx = strapi2.requestContext.get();
|
|
25098
|
+
}
|
|
25099
|
+
isInitiatedByLocalazyWebhook() {
|
|
25100
|
+
if (typeof this.ctx !== "undefined") {
|
|
25101
|
+
const ctxHeaders = this.ctx.headers;
|
|
25102
|
+
const xLocalazyHmac = ctxHeaders["x-localazy-hmac"];
|
|
25103
|
+
const xLocalazyTimestamp = ctxHeaders["x-localazy-timestamp"];
|
|
25104
|
+
if (!!xLocalazyHmac && !!xLocalazyTimestamp) {
|
|
25105
|
+
return true;
|
|
25106
|
+
}
|
|
25107
|
+
}
|
|
25108
|
+
return false;
|
|
25109
|
+
}
|
|
25110
|
+
isInitiatedByLocalazyPluginUI() {
|
|
25111
|
+
if (typeof this.ctx !== "undefined") {
|
|
25112
|
+
const ctxHeaders = this.ctx.headers;
|
|
25113
|
+
const xLocalazyInitiatedBy = ctxHeaders["x-localazy-initiated-by"];
|
|
25114
|
+
if (!xLocalazyInitiatedBy) {
|
|
25115
|
+
return false;
|
|
25116
|
+
}
|
|
25117
|
+
return xLocalazyInitiatedBy === "strapi-plugin-localazy";
|
|
25118
|
+
}
|
|
25119
|
+
return false;
|
|
25120
|
+
}
|
|
25121
|
+
}
|
|
25044
25122
|
const getFilteredLanguagesCodesForDownload = async (languagesCodes) => {
|
|
25045
25123
|
const pluginSettingsServiceHelper = new PluginSettingsServiceHelper();
|
|
25046
25124
|
const requestInitiatorHelper = new RequestInitiatorHelper(strapi);
|
|
@@ -25951,11 +26029,10 @@ const StrapiLocalazyI18nService = ({ strapi: strapi2 }) => ({
|
|
|
25951
26029
|
uid,
|
|
25952
26030
|
isoStrapi
|
|
25953
26031
|
);
|
|
25954
|
-
const filteredUpdateEntry = dropPropertyDeep(updateEntry, "documentId");
|
|
25955
26032
|
const updatedEntry = await StrapiI18nService2.updateLocalizationForAnExistingEntry(
|
|
25956
26033
|
uid,
|
|
25957
26034
|
localizedDocumentId,
|
|
25958
|
-
|
|
26035
|
+
updateEntry,
|
|
25959
26036
|
isoStrapi
|
|
25960
26037
|
);
|
|
25961
26038
|
return updatedEntry;
|