@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.js
CHANGED
|
@@ -22,34 +22,6 @@ const require$$0__default = /* @__PURE__ */ _interopDefault(require$$0$2);
|
|
|
22
22
|
const require$$0__default$1 = /* @__PURE__ */ _interopDefault(require$$0$3);
|
|
23
23
|
const require$$2__default = /* @__PURE__ */ _interopDefault(require$$2);
|
|
24
24
|
const require$$8__default = /* @__PURE__ */ _interopDefault(require$$8);
|
|
25
|
-
class RequestInitiatorHelper {
|
|
26
|
-
constructor(strapi2) {
|
|
27
|
-
this.strapi = strapi2;
|
|
28
|
-
this.ctx = strapi2.requestContext.get();
|
|
29
|
-
}
|
|
30
|
-
isInitiatedByLocalazyWebhook() {
|
|
31
|
-
if (typeof this.ctx !== "undefined") {
|
|
32
|
-
const ctxHeaders = this.ctx.headers;
|
|
33
|
-
const xLocalazyHmac = ctxHeaders["x-localazy-hmac"];
|
|
34
|
-
const xLocalazyTimestamp = ctxHeaders["x-localazy-timestamp"];
|
|
35
|
-
if (!!xLocalazyHmac && !!xLocalazyTimestamp) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
isInitiatedByLocalazyPluginUI() {
|
|
42
|
-
if (typeof this.ctx !== "undefined") {
|
|
43
|
-
const ctxHeaders = this.ctx.headers;
|
|
44
|
-
const xLocalazyInitiatedBy = ctxHeaders["x-localazy-initiated-by"];
|
|
45
|
-
if (!xLocalazyInitiatedBy) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return xLocalazyInitiatedBy === "strapi-plugin-localazy";
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
25
|
var objectProto$r = Object.prototype;
|
|
54
26
|
function isPrototype$4(value) {
|
|
55
27
|
var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto$r;
|
|
@@ -839,7 +811,7 @@ var merge = createAssigner(function(object, source, srcIndex) {
|
|
|
839
811
|
baseMerge(object, source, srcIndex);
|
|
840
812
|
});
|
|
841
813
|
const name = "@localazy/strapi-plugin";
|
|
842
|
-
const version$1 = "1.0.0-beta.
|
|
814
|
+
const version$1 = "1.0.0-beta.2";
|
|
843
815
|
const description = "The official Strapi Plugin by Localazy.";
|
|
844
816
|
const keywords = [
|
|
845
817
|
"strapi",
|
|
@@ -21680,6 +21652,31 @@ const require$$18 = {
|
|
|
21680
21652
|
var distExports = dist$1.exports;
|
|
21681
21653
|
const io = /* @__PURE__ */ getDefaultExportFromCjs(distExports);
|
|
21682
21654
|
const { Server: Server2, Namespace, Socket: Socket3 } = io;
|
|
21655
|
+
const bootstrap = ({ strapi: strapi2 }) => {
|
|
21656
|
+
strapi2.db.lifecycles.subscribe(async (event) => {
|
|
21657
|
+
const action = event.action;
|
|
21658
|
+
switch (action) {
|
|
21659
|
+
case "beforeFindMany":
|
|
21660
|
+
case "beforeFindOne": {
|
|
21661
|
+
deepPopulateHook(event);
|
|
21662
|
+
break;
|
|
21663
|
+
}
|
|
21664
|
+
}
|
|
21665
|
+
});
|
|
21666
|
+
process.nextTick(async () => {
|
|
21667
|
+
const io2 = new Server2(strapi2.server.httpServer, {
|
|
21668
|
+
cors: {
|
|
21669
|
+
origin: "*",
|
|
21670
|
+
methods: ["GET", "POST"]
|
|
21671
|
+
},
|
|
21672
|
+
// this must be a constructor
|
|
21673
|
+
wsEngine: require$$8.WebSocketServer
|
|
21674
|
+
});
|
|
21675
|
+
strapi2.StrapIO = io2;
|
|
21676
|
+
});
|
|
21677
|
+
};
|
|
21678
|
+
const destroy = ({ strapi: strapi2 }) => {
|
|
21679
|
+
};
|
|
21683
21680
|
const isoStrapiToLocalazy = (isoStrapi) => {
|
|
21684
21681
|
if (!isoStrapi) {
|
|
21685
21682
|
return null;
|
|
@@ -22964,41 +22961,25 @@ class PluginSettingsServiceHelper {
|
|
|
22964
22961
|
return this.pluginSettings?.download?.uiLanguages || [];
|
|
22965
22962
|
}
|
|
22966
22963
|
}
|
|
22967
|
-
const shouldProcessEntry = (contentTransferSetup,
|
|
22964
|
+
const shouldProcessEntry = (contentTransferSetup, contextModel) => {
|
|
22968
22965
|
let key;
|
|
22969
22966
|
const modelContentTransferSetup = contentTransferSetup.setup.find((model) => {
|
|
22970
22967
|
key = Object.keys(model)[0];
|
|
22971
|
-
return key ===
|
|
22968
|
+
return key === contextModel;
|
|
22972
22969
|
});
|
|
22973
22970
|
if (!modelContentTransferSetup) {
|
|
22974
22971
|
return void 0;
|
|
22975
22972
|
}
|
|
22976
22973
|
return !!modelContentTransferSetup[key].__model__;
|
|
22977
22974
|
};
|
|
22978
|
-
const getEventEntries = async (
|
|
22979
|
-
|
|
22980
|
-
|
|
22981
|
-
case "
|
|
22982
|
-
|
|
22983
|
-
|
|
22984
|
-
documentId: event.result.documentId,
|
|
22985
|
-
locUploadPLevel: 6
|
|
22986
|
-
})
|
|
22987
|
-
];
|
|
22988
|
-
return entry;
|
|
22989
|
-
}
|
|
22990
|
-
case "beforeDelete": {
|
|
22991
|
-
const whereId = event.params.where.id;
|
|
22992
|
-
const entryById = await strapi.entityService.findOne(event.model.uid, whereId);
|
|
22993
|
-
if (!entryById) {
|
|
22994
|
-
return [];
|
|
22995
|
-
}
|
|
22996
|
-
if (entryById.id !== whereId) {
|
|
22997
|
-
return [];
|
|
22998
|
-
}
|
|
22999
|
-
const documentId = entryById.documentId;
|
|
22975
|
+
const getEventEntries = async (params) => {
|
|
22976
|
+
const { context, documentId } = params;
|
|
22977
|
+
switch (context.action) {
|
|
22978
|
+
case "create":
|
|
22979
|
+
case "update":
|
|
22980
|
+
case "delete": {
|
|
23000
22981
|
const entry = [
|
|
23001
|
-
await strapi.documents(
|
|
22982
|
+
await strapi.documents(context.contentType.uid).findOne({
|
|
23002
22983
|
documentId,
|
|
23003
22984
|
locUploadPLevel: 6
|
|
23004
22985
|
})
|
|
@@ -23010,29 +22991,31 @@ const getEventEntries = async (event) => {
|
|
|
23010
22991
|
}
|
|
23011
22992
|
}
|
|
23012
22993
|
};
|
|
23013
|
-
const shouldSkipAction = async (
|
|
22994
|
+
const shouldSkipAction = async (context) => {
|
|
23014
22995
|
const PluginSettingsServiceHelperInstance = new PluginSettingsServiceHelper();
|
|
23015
22996
|
await PluginSettingsServiceHelperInstance.setup();
|
|
23016
|
-
switch (
|
|
23017
|
-
case "
|
|
22997
|
+
switch (context.action) {
|
|
22998
|
+
case "create": {
|
|
23018
22999
|
if (!PluginSettingsServiceHelperInstance.shouldAllowAutomatedCreatedTrigger()) {
|
|
23019
23000
|
strapi.log.info(
|
|
23020
|
-
`Localazy Plugin: Skipping ${
|
|
23001
|
+
`Localazy Plugin: Skipping ${context.action} hook because automated created trigger is disabled.`
|
|
23021
23002
|
);
|
|
23022
23003
|
return true;
|
|
23023
23004
|
}
|
|
23024
23005
|
return false;
|
|
23025
23006
|
}
|
|
23026
|
-
case "
|
|
23007
|
+
case "update": {
|
|
23027
23008
|
if (!PluginSettingsServiceHelperInstance.shouldAllowAutomatedUpdatedTrigger()) {
|
|
23028
|
-
strapi.log.info(
|
|
23009
|
+
strapi.log.info(
|
|
23010
|
+
`Localazy Plugin: Skipping ${context.action} hook because automated update trigger is disabled.`
|
|
23011
|
+
);
|
|
23029
23012
|
return true;
|
|
23030
23013
|
}
|
|
23031
23014
|
return false;
|
|
23032
23015
|
}
|
|
23033
|
-
case "
|
|
23016
|
+
case "delete": {
|
|
23034
23017
|
if (!PluginSettingsServiceHelperInstance.shouldAllowDeprecateOnDeletion()) {
|
|
23035
|
-
strapi.log.info(`Localazy Plugin: Skipping ${
|
|
23018
|
+
strapi.log.info(`Localazy Plugin: Skipping ${context.action} hook because deprecate on deletion is disabled.`);
|
|
23036
23019
|
return true;
|
|
23037
23020
|
}
|
|
23038
23021
|
return false;
|
|
@@ -23042,19 +23025,21 @@ const shouldSkipAction = async (event) => {
|
|
|
23042
23025
|
}
|
|
23043
23026
|
}
|
|
23044
23027
|
};
|
|
23045
|
-
const getPickedFlattenKeysForHookEntry = async (
|
|
23028
|
+
const getPickedFlattenKeysForHookEntry = async (params) => {
|
|
23029
|
+
const { context, locale } = params;
|
|
23030
|
+
const eventEntryLocale = locale;
|
|
23046
23031
|
const LocalazyUserService2 = getLocalazyUserService();
|
|
23047
23032
|
const LocalazyPubAPIService2 = getLocalazyPubAPIService();
|
|
23048
23033
|
const StrapiI18nService2 = getStrapiI18nService();
|
|
23049
23034
|
const contentTransferSetup = await getPluginSettingsService().getContentTransferSetup();
|
|
23050
|
-
const
|
|
23051
|
-
strapi.log.info(`${
|
|
23035
|
+
const contextAction = context.action;
|
|
23036
|
+
strapi.log.info(`${contextAction} triggered`);
|
|
23052
23037
|
if (!contentTransferSetup.has_setup) {
|
|
23053
23038
|
strapi.log.warn("Localazy Plugin: Content Transfer Setup is not set up; the operation won't proceed");
|
|
23054
23039
|
return;
|
|
23055
23040
|
}
|
|
23056
|
-
const
|
|
23057
|
-
const shouldProcess = shouldProcessEntry(contentTransferSetup,
|
|
23041
|
+
const contextModel = context.contentType.collectionName;
|
|
23042
|
+
const shouldProcess = shouldProcessEntry(contentTransferSetup, contextModel);
|
|
23058
23043
|
if (typeof shouldProcess === "undefined") {
|
|
23059
23044
|
return;
|
|
23060
23045
|
}
|
|
@@ -23068,7 +23053,7 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23068
23053
|
strapi.log.error("Localazy Plugin: Localazy user is not logged in; the operation won't proceed");
|
|
23069
23054
|
return;
|
|
23070
23055
|
}
|
|
23071
|
-
if (await shouldSkipAction(
|
|
23056
|
+
if (await shouldSkipAction(context)) {
|
|
23072
23057
|
strapi.log.info("Localazy Plugin: Automated action skipped");
|
|
23073
23058
|
return;
|
|
23074
23059
|
}
|
|
@@ -23078,28 +23063,29 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23078
23063
|
const sourceLanguage = projectLanguages.find((language3) => language3.id === projectSourceLanguageId);
|
|
23079
23064
|
const projectSourceLanguageCode = sourceLanguage.code;
|
|
23080
23065
|
const strapiLocales = await StrapiI18nService2.getLocales();
|
|
23081
|
-
const defaultLocale = strapiLocales.find((
|
|
23066
|
+
const defaultLocale = strapiLocales.find((locale2) => locale2.isDefault);
|
|
23082
23067
|
const strapiDefaultLocale = defaultLocale ? isoStrapiToLocalazy(defaultLocale.code) : config.default.LOCALAZY_DEFAULT_LOCALE;
|
|
23083
23068
|
if (strapiDefaultLocale !== projectSourceLanguageCode) {
|
|
23084
23069
|
strapi.log.warn("Localazy Plugin: Source locales do not match; the operation won't proceed");
|
|
23085
23070
|
return;
|
|
23086
23071
|
}
|
|
23087
|
-
|
|
23088
|
-
|
|
23089
|
-
|
|
23072
|
+
if (eventEntryLocale !== "*" && isoStrapiToLocalazy(eventEntryLocale) !== projectSourceLanguageCode) {
|
|
23073
|
+
strapi.log.info(
|
|
23074
|
+
"Localazy Plugin: Triggered locale is not in Localazy source language; the operation won't proceed"
|
|
23075
|
+
);
|
|
23090
23076
|
return;
|
|
23091
23077
|
}
|
|
23092
|
-
const
|
|
23093
|
-
|
|
23094
|
-
|
|
23078
|
+
const modelUid = context.contentType.uid;
|
|
23079
|
+
const entries = await getEventEntries(params);
|
|
23080
|
+
if (entries.length === 0) {
|
|
23095
23081
|
return;
|
|
23096
23082
|
}
|
|
23097
23083
|
const reducedEntries = omitDeep(entries, ["locale", "createdAt", "updatedAt", "publishedAt"]);
|
|
23098
|
-
const transferSetupModel = findSetupModelByCollectionName(contentTransferSetup.setup,
|
|
23099
|
-
const currentTransferSetupModel = transferSetupModel[
|
|
23084
|
+
const transferSetupModel = findSetupModelByCollectionName(contentTransferSetup.setup, contextModel);
|
|
23085
|
+
const currentTransferSetupModel = transferSetupModel[contextModel];
|
|
23100
23086
|
const pickPaths = getPickPaths(currentTransferSetupModel);
|
|
23101
23087
|
if (!pickPaths.length) {
|
|
23102
|
-
strapi.log.warn(`No fields for collection ${
|
|
23088
|
+
strapi.log.warn(`No fields for collection ${contextModel} transfer are enabled.`);
|
|
23103
23089
|
return;
|
|
23104
23090
|
}
|
|
23105
23091
|
const pickPathsWithUid = pickPaths.map((pickPath) => `${modelUid}.${pickPath}`);
|
|
@@ -23115,11 +23101,12 @@ const getPickedFlattenKeysForHookEntry = async (event) => {
|
|
|
23115
23101
|
const pickedFlatten = pickEntries(flatten, pickPathsWithUid);
|
|
23116
23102
|
return {
|
|
23117
23103
|
pickedFlatten,
|
|
23118
|
-
eventEntryLocale
|
|
23104
|
+
eventEntryLocale,
|
|
23105
|
+
projectSourceLanguageCode
|
|
23119
23106
|
};
|
|
23120
23107
|
};
|
|
23121
|
-
const uploadEventEntryToLocalazyHook = async (
|
|
23122
|
-
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(
|
|
23108
|
+
const uploadEventEntryToLocalazyHook = async (params) => {
|
|
23109
|
+
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(params);
|
|
23123
23110
|
if (typeof pickedFlattedResult === "undefined") {
|
|
23124
23111
|
return;
|
|
23125
23112
|
}
|
|
@@ -23863,12 +23850,12 @@ const LocalazyApiClientFactory = async () => {
|
|
|
23863
23850
|
return api;
|
|
23864
23851
|
};
|
|
23865
23852
|
const delay = (ms2 = 150) => new Promise((resolve) => setTimeout(resolve, ms2));
|
|
23866
|
-
const deprecateEventEntryInLocalazyHook = async (
|
|
23867
|
-
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(
|
|
23853
|
+
const deprecateEventEntryInLocalazyHook = async (params) => {
|
|
23854
|
+
const pickedFlattedResult = await getPickedFlattenKeysForHookEntry(params);
|
|
23868
23855
|
if (typeof pickedFlattedResult === "undefined") {
|
|
23869
23856
|
return;
|
|
23870
23857
|
}
|
|
23871
|
-
const { pickedFlatten,
|
|
23858
|
+
const { pickedFlatten, projectSourceLanguageCode } = pickedFlattedResult;
|
|
23872
23859
|
const LocalazyUserService2 = getLocalazyUserService();
|
|
23873
23860
|
const LocalazyPubApiService = getLocalazyPubAPIService();
|
|
23874
23861
|
const user = await LocalazyUserService2.getUser();
|
|
@@ -23881,7 +23868,7 @@ const deprecateEventEntryInLocalazyHook = async (event) => {
|
|
|
23881
23868
|
const projectKeys = await LocalazyApi.files.listKeys({
|
|
23882
23869
|
project: user.project.id,
|
|
23883
23870
|
file: strapiFile.id,
|
|
23884
|
-
lang:
|
|
23871
|
+
lang: projectSourceLanguageCode
|
|
23885
23872
|
});
|
|
23886
23873
|
if (!projectKeys) {
|
|
23887
23874
|
strapi.log.error(`Keys not found for file ${strapiFile.id}`);
|
|
@@ -23907,65 +23894,50 @@ const deprecateEventEntryInLocalazyHook = async (event) => {
|
|
|
23907
23894
|
success: true
|
|
23908
23895
|
};
|
|
23909
23896
|
};
|
|
23910
|
-
const
|
|
23911
|
-
strapi2.
|
|
23912
|
-
|
|
23913
|
-
|
|
23914
|
-
|
|
23915
|
-
case "
|
|
23916
|
-
case "beforeFindOne": {
|
|
23917
|
-
deepPopulateHook(event);
|
|
23918
|
-
break;
|
|
23919
|
-
}
|
|
23920
|
-
case "afterCreate":
|
|
23921
|
-
case "afterUpdate": {
|
|
23897
|
+
const register = ({ strapi: strapi2 }) => {
|
|
23898
|
+
strapi2.documents.use(async (context, next) => {
|
|
23899
|
+
let result;
|
|
23900
|
+
switch (context.action) {
|
|
23901
|
+
case "create":
|
|
23902
|
+
case "update":
|
|
23922
23903
|
try {
|
|
23923
|
-
|
|
23924
|
-
|
|
23925
|
-
|
|
23926
|
-
|
|
23927
|
-
|
|
23928
|
-
strapi2.log.info(`${action} hook result: ${JSON.stringify(result)}`);
|
|
23929
|
-
}
|
|
23904
|
+
result = await next();
|
|
23905
|
+
const hookResult = await uploadEventEntryToLocalazyHook({
|
|
23906
|
+
context,
|
|
23907
|
+
documentId: result.documentId,
|
|
23908
|
+
locale: context.params.locale || context["locale"]
|
|
23930
23909
|
});
|
|
23910
|
+
if (typeof hookResult !== "undefined") {
|
|
23911
|
+
strapi2.log.info(`${context.action} hook result: ${JSON.stringify(hookResult)}`);
|
|
23912
|
+
}
|
|
23931
23913
|
} catch (e3) {
|
|
23932
23914
|
strapi2.log.error(e3);
|
|
23933
23915
|
} finally {
|
|
23934
23916
|
break;
|
|
23935
23917
|
}
|
|
23936
|
-
|
|
23937
|
-
case "beforeDelete": {
|
|
23918
|
+
case "delete": {
|
|
23938
23919
|
try {
|
|
23939
|
-
|
|
23940
|
-
|
|
23941
|
-
|
|
23942
|
-
|
|
23943
|
-
|
|
23944
|
-
|
|
23920
|
+
const hookResult = await deprecateEventEntryInLocalazyHook({
|
|
23921
|
+
context,
|
|
23922
|
+
documentId: context.params.documentId,
|
|
23923
|
+
locale: context.params.locale || context["locale"]
|
|
23924
|
+
});
|
|
23925
|
+
if (typeof hookResult !== "undefined") {
|
|
23926
|
+
strapi2.log.info(`${context.action} hook result: ${JSON.stringify(hookResult)}`);
|
|
23945
23927
|
}
|
|
23928
|
+
result = await next();
|
|
23946
23929
|
} catch (e3) {
|
|
23947
23930
|
strapi2.log.error(e3);
|
|
23948
23931
|
} finally {
|
|
23949
23932
|
break;
|
|
23950
23933
|
}
|
|
23951
23934
|
}
|
|
23935
|
+
default:
|
|
23936
|
+
result = await next();
|
|
23937
|
+
break;
|
|
23952
23938
|
}
|
|
23939
|
+
return result;
|
|
23953
23940
|
});
|
|
23954
|
-
process.nextTick(async () => {
|
|
23955
|
-
const io2 = new Server2(strapi2.server.httpServer, {
|
|
23956
|
-
cors: {
|
|
23957
|
-
origin: "*",
|
|
23958
|
-
methods: ["GET", "POST"]
|
|
23959
|
-
},
|
|
23960
|
-
// this must be a constructor
|
|
23961
|
-
wsEngine: require$$8.WebSocketServer
|
|
23962
|
-
});
|
|
23963
|
-
strapi2.StrapIO = io2;
|
|
23964
|
-
});
|
|
23965
|
-
};
|
|
23966
|
-
const destroy = ({ strapi: strapi2 }) => {
|
|
23967
|
-
};
|
|
23968
|
-
const register = ({ strapi: strapi2 }) => {
|
|
23969
23941
|
};
|
|
23970
23942
|
const contentTypes = {};
|
|
23971
23943
|
const LocalazyUserController = ({ strapi: strapi2 }) => ({
|
|
@@ -24208,13 +24180,66 @@ const controllers = {
|
|
|
24208
24180
|
PluginSettingsController,
|
|
24209
24181
|
LocalazyTransferController
|
|
24210
24182
|
};
|
|
24211
|
-
const
|
|
24183
|
+
const verifyWebhook = (config2, { strapi: strapi2 }) => {
|
|
24184
|
+
return async (ctx, next) => {
|
|
24185
|
+
try {
|
|
24186
|
+
const pluginSettingsServiceHelper = new PluginSettingsServiceHelper();
|
|
24187
|
+
await pluginSettingsServiceHelper.setup();
|
|
24188
|
+
if (!pluginSettingsServiceHelper.shouldAllowWebhookDownloadProcess()) {
|
|
24189
|
+
throw new Error("Localazy Plugin: Webhook download process is disabled; terminating execution");
|
|
24190
|
+
}
|
|
24191
|
+
const requestBody = ctx.request.body;
|
|
24192
|
+
strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure started`);
|
|
24193
|
+
const LocalazyPubApiService = getLocalazyPubAPIService();
|
|
24194
|
+
const LocalazyUserService2 = getLocalazyUserService();
|
|
24195
|
+
const user = await LocalazyUserService2.getUser();
|
|
24196
|
+
const secret = await LocalazyPubApiService.getWebhooksSecret(user.project.id);
|
|
24197
|
+
const xLocalazyHmac = ctx.request.header["x-localazy-hmac"];
|
|
24198
|
+
const xLocalazyTimestamp = ctx.request.header["x-localazy-timestamp"];
|
|
24199
|
+
const THRESHOLD = 9e5;
|
|
24200
|
+
const intXLocalazyTimestamp = parseInt(xLocalazyTimestamp);
|
|
24201
|
+
if (Number.isNaN(intXLocalazyTimestamp)) {
|
|
24202
|
+
throw new Error("Localazy Plugin: Webhook request invalid timestamp provided; terminating execution");
|
|
24203
|
+
}
|
|
24204
|
+
if (intXLocalazyTimestamp * 1e3 + THRESHOLD < Date.now()) {
|
|
24205
|
+
throw new Error("Localazy Plugin: Webhook request is older than threshold; terminating execution");
|
|
24206
|
+
}
|
|
24207
|
+
const strapiHmac = require$$0__default.default.createHmac("sha256", secret);
|
|
24208
|
+
const signedMessage = strapiHmac.update(`${xLocalazyTimestamp}-${JSON.stringify(requestBody)}`).digest("hex");
|
|
24209
|
+
if (xLocalazyHmac !== signedMessage) {
|
|
24210
|
+
throw new Error("Localazy Plugin: Webhook verification did not pass; terminating execution");
|
|
24211
|
+
} else {
|
|
24212
|
+
strapi2.log.info("Localazy Plugin: Webhook verification passed");
|
|
24213
|
+
}
|
|
24214
|
+
if (!ctx.state.user) {
|
|
24215
|
+
const webhookAuthorId = pluginSettingsServiceHelper.getWebhookAuthorId();
|
|
24216
|
+
if (Number.isNaN(webhookAuthorId)) {
|
|
24217
|
+
throw new Error("Localazy Plugin: Webhook author is not set; terminating execution");
|
|
24218
|
+
}
|
|
24219
|
+
ctx.state.user = {
|
|
24220
|
+
id: webhookAuthorId
|
|
24221
|
+
};
|
|
24222
|
+
}
|
|
24223
|
+
await next();
|
|
24224
|
+
strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure finished`);
|
|
24225
|
+
} catch (e3) {
|
|
24226
|
+
strapi2.log.warn(e3.message);
|
|
24227
|
+
ctx.body = {
|
|
24228
|
+
success: false,
|
|
24229
|
+
message: e3.message
|
|
24230
|
+
};
|
|
24231
|
+
}
|
|
24232
|
+
};
|
|
24233
|
+
};
|
|
24234
|
+
const middlewares = {
|
|
24235
|
+
verifyWebhook
|
|
24236
|
+
};
|
|
24212
24237
|
const policies = {};
|
|
24213
|
-
const ROUTE_PREFIX$
|
|
24238
|
+
const ROUTE_PREFIX$6 = "/user";
|
|
24214
24239
|
const LocalazyUserRoutes = [
|
|
24215
24240
|
{
|
|
24216
24241
|
method: "GET",
|
|
24217
|
-
path: `${ROUTE_PREFIX$
|
|
24242
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24218
24243
|
handler: "LocalazyUserController.getUser",
|
|
24219
24244
|
config: {
|
|
24220
24245
|
policies: []
|
|
@@ -24222,7 +24247,7 @@ const LocalazyUserRoutes = [
|
|
|
24222
24247
|
},
|
|
24223
24248
|
{
|
|
24224
24249
|
method: "PUT",
|
|
24225
|
-
path: `${ROUTE_PREFIX$
|
|
24250
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24226
24251
|
handler: "LocalazyUserController.updateUser",
|
|
24227
24252
|
config: {
|
|
24228
24253
|
policies: []
|
|
@@ -24230,18 +24255,18 @@ const LocalazyUserRoutes = [
|
|
|
24230
24255
|
},
|
|
24231
24256
|
{
|
|
24232
24257
|
method: "DELETE",
|
|
24233
|
-
path: `${ROUTE_PREFIX$
|
|
24258
|
+
path: `${ROUTE_PREFIX$6}`,
|
|
24234
24259
|
handler: "LocalazyUserController.deleteUser",
|
|
24235
24260
|
config: {
|
|
24236
24261
|
policies: []
|
|
24237
24262
|
}
|
|
24238
24263
|
}
|
|
24239
24264
|
];
|
|
24240
|
-
const ROUTE_PREFIX$
|
|
24265
|
+
const ROUTE_PREFIX$5 = "/auth";
|
|
24241
24266
|
const LocalazyAuthRoutes = [
|
|
24242
24267
|
{
|
|
24243
24268
|
method: "GET",
|
|
24244
|
-
path: `${ROUTE_PREFIX$
|
|
24269
|
+
path: `${ROUTE_PREFIX$5}/generate-keys`,
|
|
24245
24270
|
handler: "LocalazyAuthController.generateKeys",
|
|
24246
24271
|
config: {
|
|
24247
24272
|
policies: []
|
|
@@ -24249,18 +24274,18 @@ const LocalazyAuthRoutes = [
|
|
|
24249
24274
|
},
|
|
24250
24275
|
{
|
|
24251
24276
|
method: "GET",
|
|
24252
|
-
path: `${ROUTE_PREFIX$
|
|
24277
|
+
path: `${ROUTE_PREFIX$5}/continuous-poll`,
|
|
24253
24278
|
handler: "LocalazyAuthController.continuousPoll",
|
|
24254
24279
|
config: {
|
|
24255
24280
|
policies: []
|
|
24256
24281
|
}
|
|
24257
24282
|
}
|
|
24258
24283
|
];
|
|
24259
|
-
const ROUTE_PREFIX$
|
|
24284
|
+
const ROUTE_PREFIX$4 = "/plugin-settings";
|
|
24260
24285
|
const PluginSettingsRoutes = [
|
|
24261
24286
|
{
|
|
24262
24287
|
method: "GET",
|
|
24263
|
-
path: `${ROUTE_PREFIX$
|
|
24288
|
+
path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
|
|
24264
24289
|
handler: "PluginSettingsController.getContentTransferSetup",
|
|
24265
24290
|
config: {
|
|
24266
24291
|
policies: []
|
|
@@ -24268,7 +24293,7 @@ const PluginSettingsRoutes = [
|
|
|
24268
24293
|
},
|
|
24269
24294
|
{
|
|
24270
24295
|
method: "PUT",
|
|
24271
|
-
path: `${ROUTE_PREFIX$
|
|
24296
|
+
path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
|
|
24272
24297
|
handler: "PluginSettingsController.updateContentTransferSetup",
|
|
24273
24298
|
config: {
|
|
24274
24299
|
policies: []
|
|
@@ -24276,7 +24301,7 @@ const PluginSettingsRoutes = [
|
|
|
24276
24301
|
},
|
|
24277
24302
|
{
|
|
24278
24303
|
method: "GET",
|
|
24279
|
-
path: `${ROUTE_PREFIX$
|
|
24304
|
+
path: `${ROUTE_PREFIX$4}/plugin-settings`,
|
|
24280
24305
|
handler: "PluginSettingsController.getPluginSettings",
|
|
24281
24306
|
config: {
|
|
24282
24307
|
policies: []
|
|
@@ -24284,18 +24309,18 @@ const PluginSettingsRoutes = [
|
|
|
24284
24309
|
},
|
|
24285
24310
|
{
|
|
24286
24311
|
method: "PUT",
|
|
24287
|
-
path: `${ROUTE_PREFIX$
|
|
24312
|
+
path: `${ROUTE_PREFIX$4}/plugin-settings`,
|
|
24288
24313
|
handler: "PluginSettingsController.updatePluginSettings",
|
|
24289
24314
|
config: {
|
|
24290
24315
|
policies: []
|
|
24291
24316
|
}
|
|
24292
24317
|
}
|
|
24293
24318
|
];
|
|
24294
|
-
const ROUTE_PREFIX$
|
|
24319
|
+
const ROUTE_PREFIX$3 = "/strapi";
|
|
24295
24320
|
const StrapiRoutes = [
|
|
24296
24321
|
{
|
|
24297
24322
|
method: "GET",
|
|
24298
|
-
path: `${ROUTE_PREFIX$
|
|
24323
|
+
path: `${ROUTE_PREFIX$3}/models`,
|
|
24299
24324
|
handler: "StrapiController.getModels",
|
|
24300
24325
|
config: {
|
|
24301
24326
|
policies: []
|
|
@@ -24303,7 +24328,7 @@ const StrapiRoutes = [
|
|
|
24303
24328
|
},
|
|
24304
24329
|
{
|
|
24305
24330
|
method: "GET",
|
|
24306
|
-
path: `${ROUTE_PREFIX$
|
|
24331
|
+
path: `${ROUTE_PREFIX$3}/localizable-models`,
|
|
24307
24332
|
handler: "StrapiController.getLocalizableModels",
|
|
24308
24333
|
config: {
|
|
24309
24334
|
policies: []
|
|
@@ -24311,7 +24336,7 @@ const StrapiRoutes = [
|
|
|
24311
24336
|
},
|
|
24312
24337
|
{
|
|
24313
24338
|
method: "POST",
|
|
24314
|
-
path: `${ROUTE_PREFIX$
|
|
24339
|
+
path: `${ROUTE_PREFIX$3}/lifecycle/localazy-webhooks`,
|
|
24315
24340
|
handler: "StrapiController.postLifecycleLocalazyWebhooks",
|
|
24316
24341
|
config: {
|
|
24317
24342
|
policies: []
|
|
@@ -24319,18 +24344,18 @@ const StrapiRoutes = [
|
|
|
24319
24344
|
},
|
|
24320
24345
|
{
|
|
24321
24346
|
method: "GET",
|
|
24322
|
-
path: `${ROUTE_PREFIX$
|
|
24347
|
+
path: `${ROUTE_PREFIX$3}/version`,
|
|
24323
24348
|
handler: "StrapiController.getPluginVersion",
|
|
24324
24349
|
config: {
|
|
24325
24350
|
policies: []
|
|
24326
24351
|
}
|
|
24327
24352
|
}
|
|
24328
24353
|
];
|
|
24329
|
-
const ROUTE_PREFIX$
|
|
24354
|
+
const ROUTE_PREFIX$2 = "/transfer";
|
|
24330
24355
|
const LocalazyTransferRoutes = [
|
|
24331
24356
|
{
|
|
24332
24357
|
method: "POST",
|
|
24333
|
-
path: `${ROUTE_PREFIX$
|
|
24358
|
+
path: `${ROUTE_PREFIX$2}/upload`,
|
|
24334
24359
|
handler: "LocalazyTransferController.upload",
|
|
24335
24360
|
config: {
|
|
24336
24361
|
policies: []
|
|
@@ -24338,27 +24363,40 @@ const LocalazyTransferRoutes = [
|
|
|
24338
24363
|
},
|
|
24339
24364
|
{
|
|
24340
24365
|
method: "POST",
|
|
24341
|
-
path: `${ROUTE_PREFIX$
|
|
24366
|
+
path: `${ROUTE_PREFIX$2}/download`,
|
|
24342
24367
|
handler: "LocalazyTransferController.download",
|
|
24343
24368
|
config: {
|
|
24344
24369
|
policies: []
|
|
24345
24370
|
}
|
|
24346
24371
|
}
|
|
24347
24372
|
];
|
|
24348
|
-
const ROUTE_PREFIX = "/project";
|
|
24373
|
+
const ROUTE_PREFIX$1 = "/project";
|
|
24349
24374
|
const LocalazyProjectRoutes = [
|
|
24350
24375
|
{
|
|
24351
24376
|
method: "GET",
|
|
24352
|
-
path: `${ROUTE_PREFIX}`,
|
|
24377
|
+
path: `${ROUTE_PREFIX$1}`,
|
|
24353
24378
|
handler: "LocalazyProjectController.getConnectedProject",
|
|
24354
24379
|
config: {
|
|
24355
24380
|
policies: []
|
|
24356
24381
|
}
|
|
24357
24382
|
}
|
|
24358
24383
|
];
|
|
24384
|
+
const ROUTE_PREFIX = "/public/transfer";
|
|
24385
|
+
const LocalazyPublicTransferRoutes = [
|
|
24386
|
+
{
|
|
24387
|
+
method: "POST",
|
|
24388
|
+
path: `${ROUTE_PREFIX}/download`,
|
|
24389
|
+
handler: "LocalazyTransferController.download",
|
|
24390
|
+
config: {
|
|
24391
|
+
policies: [],
|
|
24392
|
+
auth: false,
|
|
24393
|
+
// make the route public
|
|
24394
|
+
middlewares: [`plugin::${PLUGIN_NAME}.verifyWebhook`]
|
|
24395
|
+
}
|
|
24396
|
+
}
|
|
24397
|
+
];
|
|
24359
24398
|
const routes = {
|
|
24360
24399
|
"content-api": {
|
|
24361
|
-
type: "content-api",
|
|
24362
24400
|
routes: [...StrapiRoutes]
|
|
24363
24401
|
},
|
|
24364
24402
|
admin: {
|
|
@@ -24371,8 +24409,10 @@ const routes = {
|
|
|
24371
24409
|
...LocalazyTransferRoutes,
|
|
24372
24410
|
...LocalazyProjectRoutes
|
|
24373
24411
|
]
|
|
24412
|
+
},
|
|
24413
|
+
LocalazyPublicTransferRoutes: {
|
|
24414
|
+
routes: [...LocalazyPublicTransferRoutes]
|
|
24374
24415
|
}
|
|
24375
|
-
// localazyPublicTransferRoutes,
|
|
24376
24416
|
};
|
|
24377
24417
|
const KEY$2 = "identity";
|
|
24378
24418
|
const emptyIdentity = {
|
|
@@ -24512,13 +24552,23 @@ const LocalazyPubAPIService = ({ strapi: strapi2 }) => ({
|
|
|
24512
24552
|
}
|
|
24513
24553
|
},
|
|
24514
24554
|
async getProject(projectId, addOrganization = true, addLanguages = true) {
|
|
24515
|
-
|
|
24516
|
-
|
|
24555
|
+
try {
|
|
24556
|
+
const projects = await this.listProjects(addOrganization, addLanguages);
|
|
24557
|
+
return projects.find((project) => project.id === projectId) || null;
|
|
24558
|
+
} catch (e3) {
|
|
24559
|
+
strapi2.log.error(e3);
|
|
24560
|
+
return null;
|
|
24561
|
+
}
|
|
24517
24562
|
},
|
|
24518
24563
|
async getWebhooksSecret(projectId) {
|
|
24519
|
-
|
|
24520
|
-
|
|
24521
|
-
|
|
24564
|
+
try {
|
|
24565
|
+
const LocalazyApi = await LocalazyApiClientFactory();
|
|
24566
|
+
const result = await LocalazyApi.webhooks.getSecret({ project: projectId });
|
|
24567
|
+
return result;
|
|
24568
|
+
} catch (e3) {
|
|
24569
|
+
strapi2.log.error(e3);
|
|
24570
|
+
return null;
|
|
24571
|
+
}
|
|
24522
24572
|
}
|
|
24523
24573
|
});
|
|
24524
24574
|
const KEY$1 = "content-transfer-setup";
|
|
@@ -25054,6 +25104,34 @@ const shouldSetDownloadedProperty = (modelContentTransferSetup, parsedKeyRest) =
|
|
|
25054
25104
|
return "no";
|
|
25055
25105
|
}
|
|
25056
25106
|
};
|
|
25107
|
+
class RequestInitiatorHelper {
|
|
25108
|
+
constructor(strapi2) {
|
|
25109
|
+
this.strapi = strapi2;
|
|
25110
|
+
this.ctx = strapi2.requestContext.get();
|
|
25111
|
+
}
|
|
25112
|
+
isInitiatedByLocalazyWebhook() {
|
|
25113
|
+
if (typeof this.ctx !== "undefined") {
|
|
25114
|
+
const ctxHeaders = this.ctx.headers;
|
|
25115
|
+
const xLocalazyHmac = ctxHeaders["x-localazy-hmac"];
|
|
25116
|
+
const xLocalazyTimestamp = ctxHeaders["x-localazy-timestamp"];
|
|
25117
|
+
if (!!xLocalazyHmac && !!xLocalazyTimestamp) {
|
|
25118
|
+
return true;
|
|
25119
|
+
}
|
|
25120
|
+
}
|
|
25121
|
+
return false;
|
|
25122
|
+
}
|
|
25123
|
+
isInitiatedByLocalazyPluginUI() {
|
|
25124
|
+
if (typeof this.ctx !== "undefined") {
|
|
25125
|
+
const ctxHeaders = this.ctx.headers;
|
|
25126
|
+
const xLocalazyInitiatedBy = ctxHeaders["x-localazy-initiated-by"];
|
|
25127
|
+
if (!xLocalazyInitiatedBy) {
|
|
25128
|
+
return false;
|
|
25129
|
+
}
|
|
25130
|
+
return xLocalazyInitiatedBy === "strapi-plugin-localazy";
|
|
25131
|
+
}
|
|
25132
|
+
return false;
|
|
25133
|
+
}
|
|
25134
|
+
}
|
|
25057
25135
|
const getFilteredLanguagesCodesForDownload = async (languagesCodes) => {
|
|
25058
25136
|
const pluginSettingsServiceHelper = new PluginSettingsServiceHelper();
|
|
25059
25137
|
const requestInitiatorHelper = new RequestInitiatorHelper(strapi);
|
|
@@ -25964,11 +26042,10 @@ const StrapiLocalazyI18nService = ({ strapi: strapi2 }) => ({
|
|
|
25964
26042
|
uid,
|
|
25965
26043
|
isoStrapi
|
|
25966
26044
|
);
|
|
25967
|
-
const filteredUpdateEntry = dropPropertyDeep(updateEntry, "documentId");
|
|
25968
26045
|
const updatedEntry = await StrapiI18nService2.updateLocalizationForAnExistingEntry(
|
|
25969
26046
|
uid,
|
|
25970
26047
|
localizedDocumentId,
|
|
25971
|
-
|
|
26048
|
+
updateEntry,
|
|
25972
26049
|
isoStrapi
|
|
25973
26050
|
);
|
|
25974
26051
|
return updatedEntry;
|