adminforth 1.3.4 → 1.3.6

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.
@@ -250,7 +250,12 @@ export default class ConfigValidator {
250
250
  yield Promise.all(selectedIds.map((recordId) => __awaiter(this, void 0, void 0, function* () {
251
251
  const record = yield connector.getRecordByPrimaryKey(res, recordId);
252
252
  yield Promise.all(res.hooks.delete.beforeSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
253
- const resp = yield hook({ resource: res, record, adminUser });
253
+ const resp = yield hook({
254
+ primaryKey: recordId,
255
+ resource: res,
256
+ record,
257
+ adminUser
258
+ });
254
259
  if (!error && resp.error) {
255
260
  error = resp.error;
256
261
  }
@@ -261,7 +266,10 @@ export default class ConfigValidator {
261
266
  yield connector.deleteRecord({ resource: res, recordId });
262
267
  // call afterDelete hook
263
268
  yield Promise.all(res.hooks.delete.afterSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
264
- yield hook({ resource: res, record, adminUser });
269
+ yield hook({
270
+ resource: res, record, adminUser,
271
+ primaryKey: recordId
272
+ });
265
273
  })));
266
274
  })));
267
275
  if (error) {
@@ -518,7 +518,12 @@ export default class AdminForthRestAPI {
518
518
  }
519
519
  // execute hook if needed
520
520
  for (const hook of listify((_5 = (_4 = resource.hooks) === null || _4 === void 0 ? void 0 : _4.edit) === null || _5 === void 0 ? void 0 : _5.beforeSave)) {
521
- const resp = yield hook({ resource, record, adminUser });
521
+ const resp = yield hook({
522
+ primaryKey: recordId,
523
+ resource,
524
+ record,
525
+ adminUser
526
+ });
522
527
  if (!resp || (!resp.ok && !resp.error)) {
523
528
  throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
524
529
  }
@@ -545,7 +550,13 @@ export default class AdminForthRestAPI {
545
550
  }
546
551
  // execute hook if needed
547
552
  for (const hook of listify((_7 = (_6 = resource.hooks) === null || _6 === void 0 ? void 0 : _6.edit) === null || _7 === void 0 ? void 0 : _7.afterSave)) {
548
- const resp = yield hook({ resource, record, adminUser, oldRecord });
553
+ const resp = yield hook({
554
+ resource,
555
+ record,
556
+ adminUser,
557
+ oldRecord,
558
+ primaryKey: recordId,
559
+ });
549
560
  if (!resp || (!resp.ok && !resp.error)) {
550
561
  throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
551
562
  }
@@ -581,7 +592,12 @@ export default class AdminForthRestAPI {
581
592
  }
582
593
  // execute hook if needed
583
594
  for (const hook of listify((_10 = (_9 = resource.hooks) === null || _9 === void 0 ? void 0 : _9.delete) === null || _10 === void 0 ? void 0 : _10.beforeSave)) {
584
- const resp = yield hook({ resource, record, adminUser });
595
+ const resp = yield hook({
596
+ resource,
597
+ record,
598
+ adminUser,
599
+ recordId: body['primaryKey']
600
+ });
585
601
  if (!resp || (!resp.ok && !resp.error)) {
586
602
  throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
587
603
  }
@@ -593,7 +609,12 @@ export default class AdminForthRestAPI {
593
609
  yield connector.deleteRecord({ resource, recordId: body['primaryKey'] });
594
610
  // execute hook if needed
595
611
  for (const hook of listify((_12 = (_11 = resource.hooks) === null || _11 === void 0 ? void 0 : _11.delete) === null || _12 === void 0 ? void 0 : _12.afterSave)) {
596
- const resp = yield hook({ resource, record, adminUser });
612
+ const resp = yield hook({
613
+ resource,
614
+ record,
615
+ adminUser,
616
+ primaryKey: body['primaryKey']
617
+ });
597
618
  if (!resp || (!resp.ok && !resp.error)) {
598
619
  throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
599
620
  }
@@ -277,7 +277,12 @@ export default class ConfigValidator implements IConfigValidator {
277
277
  await Promise.all(
278
278
  (res.hooks.delete.beforeSave as AfterSaveFunction[]).map(
279
279
  async (hook) => {
280
- const resp = await hook({ resource: res, record, adminUser });
280
+ const resp = await hook({
281
+ primaryKey: recordId,
282
+ resource: res,
283
+ record,
284
+ adminUser
285
+ });
281
286
  if (!error && resp.error) {
282
287
  error = resp.error;
283
288
  }
@@ -294,7 +299,10 @@ export default class ConfigValidator implements IConfigValidator {
294
299
  await Promise.all(
295
300
  (res.hooks.delete.afterSave as AfterSaveFunction[]).map(
296
301
  async (hook) => {
297
- await hook({ resource: res, record, adminUser });
302
+ await hook({
303
+ resource: res, record, adminUser,
304
+ primaryKey: recordId
305
+ });
298
306
  }
299
307
  )
300
308
  )
@@ -604,7 +604,12 @@ export default class AdminForthRestAPI {
604
604
 
605
605
  // execute hook if needed
606
606
  for (const hook of listify(resource.hooks?.edit?.beforeSave as BeforeSaveFunction[])) {
607
- const resp = await hook({ resource, record, adminUser });
607
+ const resp = await hook({
608
+ primaryKey: recordId,
609
+ resource,
610
+ record,
611
+ adminUser
612
+ });
608
613
  if (!resp || (!resp.ok && !resp.error)) {
609
614
  throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
610
615
  }
@@ -634,7 +639,13 @@ export default class AdminForthRestAPI {
634
639
 
635
640
  // execute hook if needed
636
641
  for (const hook of listify(resource.hooks?.edit?.afterSave as AfterSaveFunction[])) {
637
- const resp = await hook({ resource, record, adminUser, oldRecord });
642
+ const resp = await hook({
643
+ resource,
644
+ record,
645
+ adminUser,
646
+ oldRecord,
647
+ primaryKey: recordId,
648
+ });
638
649
  if (!resp || (!resp.ok && !resp.error)) {
639
650
  throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
640
651
  }
@@ -674,7 +685,12 @@ export default class AdminForthRestAPI {
674
685
 
675
686
  // execute hook if needed
676
687
  for (const hook of listify(resource.hooks?.delete?.beforeSave as BeforeSaveFunction[])) {
677
- const resp = await hook({ resource, record, adminUser });
688
+ const resp = await hook({
689
+ resource,
690
+ record,
691
+ adminUser,
692
+ recordId: body['primaryKey']
693
+ });
678
694
  if (!resp || (!resp.ok && !resp.error)) {
679
695
  throw new Error(`Hook beforeSave must return object with {ok: true} or { error: 'Error' } `);
680
696
  }
@@ -689,7 +705,12 @@ export default class AdminForthRestAPI {
689
705
 
690
706
  // execute hook if needed
691
707
  for (const hook of listify(resource.hooks?.delete?.afterSave as BeforeSaveFunction[])) {
692
- const resp = await hook({ resource, record, adminUser });
708
+ const resp = await hook({
709
+ resource,
710
+ record,
711
+ adminUser,
712
+ primaryKey: body['primaryKey']
713
+ });
693
714
  if (!resp || (!resp.ok && !resp.error)) {
694
715
  throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
695
716
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -690,13 +690,13 @@ export type AfterDataSourceResponseFunction = (params: {resource: AdminForthReso
690
690
  * Modify record to change how data is saved to database.
691
691
  * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
692
692
  */
693
- export type BeforeSaveFunction = (params:{resource: AdminForthResource, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
693
+ export type BeforeSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
694
694
 
695
695
  /**
696
696
  * Modify record to change how data is saved to database.
697
697
  * Return ok: false and error: string to stop execution and show error message to user. Return ok: true to continue execution.
698
698
  */
699
- export type AfterSaveFunction = (params: {resource: AdminForthResource, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
699
+ export type AfterSaveFunction = (params: {resource: AdminForthResource, recordId: any, adminUser: AdminUser, record: any}) => Promise<{ok: boolean, error?: string}>;
700
700
 
701
701
  /**
702
702
  * Allow to get user data before login confirmation, will triger when user try to login.