@adminforth/i18n 2.0.31 → 2.1.1

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/index.d.ts CHANGED
@@ -61,7 +61,7 @@ export default class I18nPlugin extends AdminForthPlugin {
61
61
  tryProcessAndWatch(adminforth: IAdminForth): Promise<void>;
62
62
  validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
63
63
  applyPluralization(str: string, number: number, lang: string): string;
64
- slavicPluralRule(choice: any, choicesLength: any): 0 | 2 | 1 | 3;
64
+ slavicPluralRule(choice: any, choicesLength: any): 3 | 0 | 2 | 1;
65
65
  instanceUniqueRepresentation(pluginOptions: any): string;
66
66
  getCategoryTranslations(category: string, lang: string): Promise<Record<string, string>>;
67
67
  languagesList(): Promise<{
package/dist/index.js CHANGED
@@ -8,7 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
11
+ import { z } from "zod";
11
12
  import iso6391 from 'iso-639-1';
13
+ const updateFieldBodySchema = z.object({
14
+ resourceId: z.string(),
15
+ recordId: z.union([z.string(), z.number()]),
16
+ field: z.string(),
17
+ value: z.unknown(),
18
+ reviewed: z.boolean().nullish(),
19
+ }).strict();
20
+ const translateSelectedBodySchema = z.object({
21
+ selectedLanguages: z.array(z.string()).optional(),
22
+ selectedIds: z.array(z.union([z.string(), z.number()])),
23
+ }).strict();
24
+ const getFilteredIdsBodySchema = z.object({
25
+ filters: z.any(),
26
+ }).passthrough();
12
27
  import path from 'path';
13
28
  import fs from 'fs-extra';
14
29
  import chokidar from 'chokidar';
@@ -1021,8 +1036,10 @@ export default class I18nPlugin extends AdminForthPlugin {
1021
1036
  server.endpoint({
1022
1037
  method: 'POST',
1023
1038
  path: `/plugin/${this.pluginInstanceId}/update-field`,
1024
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
1025
- const { resourceId, recordId, field, value, reviewed } = body;
1039
+ request_schema: updateFieldBodySchema,
1040
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
1041
+ const data = body;
1042
+ const { resourceId, recordId, field, value, reviewed } = data;
1026
1043
  if (resourceId !== this.resourceConfig.resourceId) {
1027
1044
  return { error: 'Invalid resourceId' };
1028
1045
  }
@@ -1076,13 +1093,19 @@ export default class I18nPlugin extends AdminForthPlugin {
1076
1093
  method: 'POST',
1077
1094
  path: `/plugin/${this.pluginInstanceId}/translate-selected-to-languages`,
1078
1095
  noAuth: false,
1079
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, tr, adminUser }) {
1080
- const selectedLanguages = body.selectedLanguages;
1081
- const selectedIds = body.selectedIds;
1096
+ request_schema: translateSelectedBodySchema,
1097
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, tr, adminUser, response }) {
1098
+ const data = body;
1099
+ const selectedLanguages = data.selectedLanguages;
1100
+ const selectedIds = data.selectedIds;
1082
1101
  if (!Array.isArray(selectedIds) || selectedIds.length === 0) {
1083
1102
  return { ok: false, error: 'No records selected' };
1084
1103
  }
1085
- const jobId = yield this.bulkTranslate({ selectedIds, selectedLanguages, adminUser });
1104
+ const jobId = yield this.bulkTranslate({
1105
+ selectedIds: selectedIds,
1106
+ selectedLanguages: selectedLanguages,
1107
+ adminUser,
1108
+ });
1086
1109
  return {
1087
1110
  ok: true,
1088
1111
  jobId: jobId,
@@ -1092,7 +1115,8 @@ export default class I18nPlugin extends AdminForthPlugin {
1092
1115
  server.endpoint({
1093
1116
  method: 'POST',
1094
1117
  path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
1095
- handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, query, cookies, requestUrl }) {
1118
+ request_schema: getFilteredIdsBodySchema,
1119
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, query, cookies, requestUrl, response }) {
1096
1120
  var _b, _c;
1097
1121
  const resource = this.resourceConfig;
1098
1122
  for (const hook of ((_c = (_b = resource.hooks) === null || _b === void 0 ? void 0 : _b.list) === null || _c === void 0 ? void 0 : _c.beforeDatasourceRequest) || []) {
package/index.ts CHANGED
@@ -1,7 +1,25 @@
1
1
  import AdminForth, { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock, filtersTools, AdminForthFilterOperators } from "adminforth";
2
2
  import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResourceColumn, AdminForthResource, BeforeLoginConfirmationFunction, AdminForthConfigMenuItem, AdminUser } from "adminforth";
3
3
  import type { PluginOptions, SupportedLanguage } from './types.js';
4
+ import { z } from "zod";
4
5
  import iso6391 from 'iso-639-1';
6
+
7
+ const updateFieldBodySchema = z.object({
8
+ resourceId: z.string(),
9
+ recordId: z.union([z.string(), z.number()]),
10
+ field: z.string(),
11
+ value: z.unknown(),
12
+ reviewed: z.boolean().nullish(),
13
+ }).strict();
14
+
15
+ const translateSelectedBodySchema = z.object({
16
+ selectedLanguages: z.array(z.string()).optional(),
17
+ selectedIds: z.array(z.union([z.string(), z.number()])),
18
+ }).strict();
19
+
20
+ const getFilteredIdsBodySchema = z.object({
21
+ filters: z.any(),
22
+ }).passthrough();
5
23
  import { iso31661Alpha2ToAlpha3 } from 'iso-3166';
6
24
  import path from 'path';
7
25
  import fs from 'fs-extra';
@@ -1252,8 +1270,10 @@ export default class I18nPlugin extends AdminForthPlugin {
1252
1270
  server.endpoint({
1253
1271
  method: 'POST',
1254
1272
  path: `/plugin/${this.pluginInstanceId}/update-field`,
1255
- handler: async ({ body, adminUser, headers }) => {
1256
- const { resourceId, recordId, field, value, reviewed } = body;
1273
+ request_schema: updateFieldBodySchema,
1274
+ handler: async ({ body, adminUser, headers, response }) => {
1275
+ const data = body as z.infer<typeof updateFieldBodySchema>;
1276
+ const { resourceId, recordId, field, value, reviewed } = data;
1257
1277
  if (resourceId !== this.resourceConfig.resourceId) {
1258
1278
  return { error: 'Invalid resourceId' };
1259
1279
  }
@@ -1274,7 +1294,7 @@ export default class I18nPlugin extends AdminForthPlugin {
1274
1294
  let result;
1275
1295
  await lock.run(`edit-trans-${recordId}`, async () => {
1276
1296
  // put into lock so 2 editors will not update the same record at the same time
1277
- oldRecord = await connector.getRecordByPrimaryKey(resource, recordId)
1297
+ oldRecord = await connector.getRecordByPrimaryKey(resource, recordId as string)
1278
1298
 
1279
1299
  if (!oldRecord) {
1280
1300
  result = { error: 'Record not found' };
@@ -1305,7 +1325,7 @@ export default class I18nPlugin extends AdminForthPlugin {
1305
1325
  return { error: result.error };
1306
1326
  }
1307
1327
 
1308
- const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId);
1328
+ const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId as string);
1309
1329
 
1310
1330
  return { record: updatedRecord };
1311
1331
  }
@@ -1315,15 +1335,21 @@ export default class I18nPlugin extends AdminForthPlugin {
1315
1335
  method: 'POST',
1316
1336
  path: `/plugin/${this.pluginInstanceId}/translate-selected-to-languages`,
1317
1337
  noAuth: false,
1318
- handler: async ({ body, tr, adminUser }) => {
1319
- const selectedLanguages = body.selectedLanguages;
1320
- const selectedIds = body.selectedIds;
1338
+ request_schema: translateSelectedBodySchema,
1339
+ handler: async ({ body, tr, adminUser, response }) => {
1340
+ const data = body as z.infer<typeof translateSelectedBodySchema>;
1341
+ const selectedLanguages = data.selectedLanguages;
1342
+ const selectedIds = data.selectedIds;
1321
1343
 
1322
1344
  if (!Array.isArray(selectedIds) || selectedIds.length === 0) {
1323
1345
  return { ok: false, error: 'No records selected' };
1324
1346
  }
1325
1347
 
1326
- const jobId = await this.bulkTranslate({ selectedIds, selectedLanguages, adminUser });
1348
+ const jobId = await this.bulkTranslate({
1349
+ selectedIds: selectedIds as string[],
1350
+ selectedLanguages: selectedLanguages as SupportedLanguage[] | undefined,
1351
+ adminUser,
1352
+ });
1327
1353
 
1328
1354
  return {
1329
1355
  ok: true,
@@ -1335,7 +1361,8 @@ export default class I18nPlugin extends AdminForthPlugin {
1335
1361
  server.endpoint({
1336
1362
  method: 'POST',
1337
1363
  path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
1338
- handler: async ({ body, adminUser, headers, query, cookies, requestUrl }) => {
1364
+ request_schema: getFilteredIdsBodySchema,
1365
+ handler: async ({ body, adminUser, headers, query, cookies, requestUrl, response }) => {
1339
1366
  const resource = this.resourceConfig;
1340
1367
 
1341
1368
  for (const hook of resource.hooks?.list?.beforeDatasourceRequest || []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "2.0.31",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -35,14 +35,15 @@
35
35
  "fs-extra": "^11.3.2",
36
36
  "iso-3166": "^4.3.0",
37
37
  "iso-639-1": "^3.1.3",
38
- "p-limit": "^7.3.0"
38
+ "p-limit": "^7.3.0",
39
+ "zod": "^4.3.6"
39
40
  },
40
41
  "peerDependencies": {
41
- "adminforth": "^3.6.21"
42
+ "adminforth": "^3.8.2"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@types/node": "^22.10.7",
45
- "adminforth": "^3.6.21",
46
+ "adminforth": "^3.8.2",
46
47
  "i18n-iso-countries": "^7.13.0",
47
48
  "semantic-release": "^24.2.1",
48
49
  "semantic-release-slack-bot": "^4.0.2",