@adminforth/bulk-ai-flow 1.14.2 → 1.14.4

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/build.log CHANGED
@@ -13,5 +13,5 @@ custom/package-lock.json
13
13
  custom/package.json
14
14
  custom/tsconfig.json
15
15
 
16
- sent 74,104 bytes received 172 bytes 148,552.00 bytes/sec
16
+ sent 74,113 bytes received 172 bytes 148,570.00 bytes/sec
17
17
  total size is 73,472 speedup is 0.99
package/dist/index.js CHANGED
@@ -49,8 +49,13 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
49
49
  checkRateLimit(field, fieldNameRateLimit, headers) {
50
50
  if (fieldNameRateLimit) {
51
51
  // rate limit
52
- const { error } = RateLimiter.checkRateLimit(field, fieldNameRateLimit, this.adminforth.auth.getClientIp(headers));
53
- if (error) {
52
+ // const { error } = RateLimiter.checkRateLimit(
53
+ // field,
54
+ // fieldNameRateLimit,
55
+ // this.adminforth.auth.getClientIp(headers),
56
+ // );
57
+ const rateLimiter = new RateLimiter(fieldNameRateLimit);
58
+ if (!rateLimiter.consume(`${field}-${this.adminforth.auth.getClientIp(headers)}`)) {
54
59
  return { error: "Rate limit exceeded" };
55
60
  }
56
61
  }
@@ -599,33 +604,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
599
604
  }
600
605
  }
601
606
  }
602
- try {
603
- const AuditLogPlugin = this.adminforth.getPluginByClassName('AuditLogPlugin');
604
- if (AuditLogPlugin) {
605
- for (const [key, value] of Object.entries(oldRecord)) {
606
- if (!(key in fieldsToUpdate[idx])) {
607
- delete oldRecord[key];
608
- }
609
- }
610
- const reorderedOldRecord = Object.keys(fieldsToUpdate[idx]).reduce((acc, key) => {
611
- if (key in oldRecord) {
612
- acc[key] = oldRecord[key];
613
- }
614
- return acc;
615
- }, {});
616
- AuditLogPlugin.logCustomAction({
617
- resourceId: this.resourceConfig.resourceId,
618
- recordId: ID,
619
- actionId: 'Bulk-ai-flow',
620
- oldData: reorderedOldRecord,
621
- data: fieldsToUpdate[idx],
622
- user: adminUser,
623
- headers: headers
624
- });
625
- }
626
- }
627
- catch (error) { }
628
- return this.adminforth.resource(this.resourceConfig.resourceId).update(ID, fieldsToUpdate[idx]);
607
+ const newRecord = Object.assign(Object.assign({}, oldRecord), fieldsToUpdate[idx]);
608
+ return this.adminforth.updateResourceRecord({
609
+ resource: this.resourceConfig,
610
+ recordId: ID,
611
+ oldRecord: oldRecord,
612
+ record: newRecord,
613
+ adminUser: adminUser,
614
+ });
629
615
  }));
630
616
  yield Promise.all(updates);
631
617
  return { ok: true };
package/index.ts CHANGED
@@ -57,12 +57,13 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
57
57
  private checkRateLimit(field: string,fieldNameRateLimit: string | undefined, headers: Record<string, string | string[] | undefined>): { error?: string } | void {
58
58
  if (fieldNameRateLimit) {
59
59
  // rate limit
60
- const { error } = RateLimiter.checkRateLimit(
61
- field,
62
- fieldNameRateLimit,
63
- this.adminforth.auth.getClientIp(headers),
64
- );
65
- if (error) {
60
+ // const { error } = RateLimiter.checkRateLimit(
61
+ // field,
62
+ // fieldNameRateLimit,
63
+ // this.adminforth.auth.getClientIp(headers),
64
+ // );
65
+ const rateLimiter = new RateLimiter(fieldNameRateLimit);
66
+ if (!rateLimiter.consume(`${field}-${this.adminforth.auth.getClientIp(headers)}`)) {
66
67
  return { error: "Rate limit exceeded" };
67
68
  }
68
69
  }
@@ -625,36 +626,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
625
626
  }
626
627
  }
627
628
  }
628
- try {
629
- const AuditLogPlugin:any = this.adminforth.getPluginByClassName('AuditLogPlugin');
630
- if (AuditLogPlugin) {
631
-
632
- for (const [key, value] of Object.entries(oldRecord)) {
633
- if (!(key in fieldsToUpdate[idx])) {
634
- delete oldRecord[key];
635
- }
636
- }
637
-
638
- const reorderedOldRecord = Object.keys(fieldsToUpdate[idx]).reduce((acc, key) => {
639
- if (key in oldRecord) {
640
- acc[key] = oldRecord[key];
641
- }
642
- return acc;
643
- }, {} as Record<string, unknown>);
644
-
645
- AuditLogPlugin.logCustomAction({
646
- resourceId: this.resourceConfig.resourceId,
647
- recordId: ID,
648
- actionId: 'Bulk-ai-flow',
649
- oldData: reorderedOldRecord,
650
- data: fieldsToUpdate[idx],
651
- user: adminUser,
652
- headers: headers
653
- });
654
- }
655
- } catch (error) { }
656
-
657
- return this.adminforth.resource(this.resourceConfig.resourceId).update(ID, fieldsToUpdate[idx])
629
+ const newRecord = {
630
+ ...oldRecord,
631
+ ...fieldsToUpdate[idx]
632
+ };
633
+ return this.adminforth.updateResourceRecord({
634
+ resource: this.resourceConfig,
635
+ recordId: ID,
636
+ oldRecord: oldRecord,
637
+ record: newRecord,
638
+ adminUser: adminUser,
639
+ })
658
640
  });
659
641
  await Promise.all(updates);
660
642
  return { ok: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.14.2",
3
+ "version": "1.14.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@types/handlebars": "^4.0.40",
30
- "adminforth": "^2.4.0-next.127",
30
+ "adminforth": "^2.4.0-next.222",
31
31
  "handlebars": "^4.7.8"
32
32
  },
33
33
  "release": {