@nocobase/plugin-action-import 1.6.22 → 1.6.23

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.
@@ -10,23 +10,23 @@
10
10
  module.exports = {
11
11
  "@emotion/css": "11.13.0",
12
12
  "@formily/react": "2.3.0",
13
- "@nocobase/client": "1.6.22",
13
+ "@nocobase/client": "1.6.23",
14
14
  "react": "18.2.0",
15
15
  "react-i18next": "11.18.6",
16
16
  "@ant-design/icons": "5.6.1",
17
17
  "@formily/shared": "2.3.2",
18
18
  "antd": "5.12.8",
19
- "@nocobase/utils": "1.6.22",
19
+ "@nocobase/utils": "1.6.23",
20
20
  "@formily/antd-v5": "1.1.9",
21
21
  "file-saver": "2.0.5",
22
22
  "react-dom": "18.2.0",
23
23
  "lodash": "4.17.21",
24
24
  "@formily/core": "2.3.0",
25
- "@nocobase/server": "1.6.22",
26
- "@nocobase/actions": "1.6.22",
27
- "@nocobase/database": "1.6.22",
25
+ "@nocobase/server": "1.6.23",
26
+ "@nocobase/actions": "1.6.23",
27
+ "@nocobase/database": "1.6.23",
28
28
  "async-mutex": "0.5.0",
29
- "@nocobase/data-source-manager": "1.6.22",
29
+ "@nocobase/data-source-manager": "1.6.23",
30
30
  "sequelize": "6.35.2",
31
31
  "mathjs": "10.6.4"
32
32
  };
@@ -1 +1 @@
1
- {"name":"exceljs","version":"4.4.0","description":"Excel Workbook Manager - Read and Write xlsx and csv Files.","private":false,"license":"MIT","author":{"name":"Guyon Roche","email":"guyon@live.com"},"repository":{"type":"git","url":"https://github.com/exceljs/exceljs.git"},"engines":{"node":">=8.3.0"},"main":"./excel.js","browser":"./dist/exceljs.min.js","types":"./index.d.ts","files":["dist","lib","excel.js","LICENSE","README.md","README_zh.md","index.ts","index.d.ts"],"scripts":{"test":"npm run test:full","test:es5":"export EXCEL_BUILD=es5 && npm run test:full","test:full":"npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine","test:version":"npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:browser && npm run test:dist","test:all":"npm run test:native && npm run test:es5","test:native":"npm run test:full","test:unit":"mocha --require spec/config/setup --require spec/config/setup-unit spec/unit --recursive","test:integration":"mocha --require spec/config/setup spec/integration --recursive","test:end-to-end":"mocha --require spec/config/setup spec/end-to-end --recursive","test:browser":"if [ ! -f .disable-test-browser ]; then npm run build && npm run test:jasmine; fi","test:jasmine":"grunt jasmine","test:unit:es5":"export EXCEL_BUILD=es5 && npm run test:unit","test:integration:es5":"export EXCEL_BUILD=es5 && npm run test:integration","test:end-to-end:es5":"export EXCEL_BUILD=es5 && npm run test:end-to-end","test:dist":"mocha --require spec/config/setup spec/dist --recursive","test:manual":"node spec/manual/app.js","test:typescript":"mocha -r ts-node/register spec/typescript/**/*.spec.ts","clean-build":"npm run clean && npm run build","lint":"eslint --format node_modules/eslint-friendly-formatter .","lint:fix":"prettier-eslint --write $(pwd)'/**/*.js'","lint:staged":"lint-staged","clean":"rm -rf build/ && rm -rf dist","benchmark":"node --expose-gc benchmark","benchmark:debug":"node --expose-gc --inspect-brk --trace-deopt benchmark","build":"grunt build","install-build":"npm install && grunt build","preversion":"npm run clean && npm run build && npm run test:version","postversion":"git push --no-verify && git push --tags --no-verify"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.js":["prettier-eslint --write","eslint --format node_modules/eslint-friendly-formatter","git add"]},"keywords":["xlsx","json","csv","excel","font","border","fill","number","format","number format","alignment","office","spreadsheet","workbook","defined names","data validations","rich text","in-cell format","outlineLevel","views","frozen","split","pageSetup"],"dependencies":{"archiver":"^5.0.0","dayjs":"^1.8.34","fast-csv":"^4.3.1","jszip":"^3.10.1","readable-stream":"^3.6.0","saxes":"^5.0.1","tmp":"^0.2.0","unzipper":"^0.10.11","uuid":"^8.3.0"},"devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","@types/chai":"^4.2.12","@types/mocha":"^8.0.3","@types/node":"^14.11.2","babelify":"^10.0.0","browserify":"^16.5.2","chai":"^4.2.0","chai-datetime":"^1.7.0","chai-xml":"^0.3.2","core-js":"^3.6.5","dirty-chai":"^2.0.1","eslint":"^6.5.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.12.0","eslint-friendly-formatter":"^4.0.1","eslint-plugin-import":"^2.22.0","eslint-plugin-node":"^11.1.0","express":"^4.16.4","got":"^9.0.0","grunt":"^1.3.0","grunt-babel":"^8.0.0","grunt-browserify":"^5.3.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-jasmine":"^2.2.0","grunt-contrib-watch":"^1.1.0","grunt-exorcise":"^2.1.1","grunt-terser":"^1.0.0","husky":"^4.3.0","lint-staged":"^10.2.13","mocha":"^7.2.0","prettier-eslint":"^11.0.0","prettier-eslint-cli":"^5.0.0","regenerator-runtime":"^0.13.7","sax":"^1.2.4","ts-node":"^8.10.2","typescript":"^3.9.7"},"_lastModified":"2025-04-22T09:54:04.281Z"}
1
+ {"name":"exceljs","version":"4.4.0","description":"Excel Workbook Manager - Read and Write xlsx and csv Files.","private":false,"license":"MIT","author":{"name":"Guyon Roche","email":"guyon@live.com"},"repository":{"type":"git","url":"https://github.com/exceljs/exceljs.git"},"engines":{"node":">=8.3.0"},"main":"./excel.js","browser":"./dist/exceljs.min.js","types":"./index.d.ts","files":["dist","lib","excel.js","LICENSE","README.md","README_zh.md","index.ts","index.d.ts"],"scripts":{"test":"npm run test:full","test:es5":"export EXCEL_BUILD=es5 && npm run test:full","test:full":"npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine","test:version":"npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:browser && npm run test:dist","test:all":"npm run test:native && npm run test:es5","test:native":"npm run test:full","test:unit":"mocha --require spec/config/setup --require spec/config/setup-unit spec/unit --recursive","test:integration":"mocha --require spec/config/setup spec/integration --recursive","test:end-to-end":"mocha --require spec/config/setup spec/end-to-end --recursive","test:browser":"if [ ! -f .disable-test-browser ]; then npm run build && npm run test:jasmine; fi","test:jasmine":"grunt jasmine","test:unit:es5":"export EXCEL_BUILD=es5 && npm run test:unit","test:integration:es5":"export EXCEL_BUILD=es5 && npm run test:integration","test:end-to-end:es5":"export EXCEL_BUILD=es5 && npm run test:end-to-end","test:dist":"mocha --require spec/config/setup spec/dist --recursive","test:manual":"node spec/manual/app.js","test:typescript":"mocha -r ts-node/register spec/typescript/**/*.spec.ts","clean-build":"npm run clean && npm run build","lint":"eslint --format node_modules/eslint-friendly-formatter .","lint:fix":"prettier-eslint --write $(pwd)'/**/*.js'","lint:staged":"lint-staged","clean":"rm -rf build/ && rm -rf dist","benchmark":"node --expose-gc benchmark","benchmark:debug":"node --expose-gc --inspect-brk --trace-deopt benchmark","build":"grunt build","install-build":"npm install && grunt build","preversion":"npm run clean && npm run build && npm run test:version","postversion":"git push --no-verify && git push --tags --no-verify"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.js":["prettier-eslint --write","eslint --format node_modules/eslint-friendly-formatter","git add"]},"keywords":["xlsx","json","csv","excel","font","border","fill","number","format","number format","alignment","office","spreadsheet","workbook","defined names","data validations","rich text","in-cell format","outlineLevel","views","frozen","split","pageSetup"],"dependencies":{"archiver":"^5.0.0","dayjs":"^1.8.34","fast-csv":"^4.3.1","jszip":"^3.10.1","readable-stream":"^3.6.0","saxes":"^5.0.1","tmp":"^0.2.0","unzipper":"^0.10.11","uuid":"^8.3.0"},"devDependencies":{"@babel/cli":"^7.10.5","@babel/core":"^7.11.4","@babel/preset-env":"^7.11.0","@types/chai":"^4.2.12","@types/mocha":"^8.0.3","@types/node":"^14.11.2","babelify":"^10.0.0","browserify":"^16.5.2","chai":"^4.2.0","chai-datetime":"^1.7.0","chai-xml":"^0.3.2","core-js":"^3.6.5","dirty-chai":"^2.0.1","eslint":"^6.5.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.12.0","eslint-friendly-formatter":"^4.0.1","eslint-plugin-import":"^2.22.0","eslint-plugin-node":"^11.1.0","express":"^4.16.4","got":"^9.0.0","grunt":"^1.3.0","grunt-babel":"^8.0.0","grunt-browserify":"^5.3.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-jasmine":"^2.2.0","grunt-contrib-watch":"^1.1.0","grunt-exorcise":"^2.1.1","grunt-terser":"^1.0.0","husky":"^4.3.0","lint-staged":"^10.2.13","mocha":"^7.2.0","prettier-eslint":"^11.0.0","prettier-eslint-cli":"^5.0.0","regenerator-runtime":"^0.13.7","sax":"^1.2.4","ts-node":"^8.10.2","typescript":"^3.9.7"},"_lastModified":"2025-04-23T15:15:56.706Z"}
@@ -1 +1 @@
1
- {"name":"xlsx","version":"0.20.2","author":"sheetjs","description":"SheetJS Spreadsheet data parser and writer","keywords":["excel","xls","xlsx","xlsb","xlsm","ods","csv","dbf","dif","sylk","office","spreadsheet"],"bin":{"xlsx":"./bin/xlsx.njs"},"main":"xlsx.js","module":"xlsx.mjs","unpkg":"dist/xlsx.full.min.js","jsdelivr":"dist/xlsx.full.min.js","types":"types/index.d.ts","exports":{".":{"import":"./xlsx.mjs","require":"./xlsx.js","types":"./types/index.d.ts"},"./xlsx.mjs":{"import":"./xlsx.mjs","types":"./types/index.d.ts"},"./xlsx.js":{"require":"./xlsx.js","types":"./types/index.d.ts"},"./dist/xlsx.core.min":{"import":"./dist/xlsx.core.min.js","require":"./dist/xlsx.core.min.js","types":"./types/index.d.ts"},"./dist/xlsx.core.min.js":{"import":"./dist/xlsx.core.min.js","require":"./dist/xlsx.core.min.js","types":"./types/index.d.ts"},"./dist/xlsx.full.min":{"import":"./dist/xlsx.full.min.js","require":"./dist/xlsx.full.min.js","types":"./types/index.d.ts"},"./dist/xlsx.full.min.js":{"import":"./dist/xlsx.full.min.js","require":"./dist/xlsx.full.min.js","types":"./types/index.d.ts"},"./dist/xlsx.mini.min":{"import":"./dist/xlsx.mini.min.js","require":"./dist/xlsx.mini.min.js","types":"./types/index.d.ts"},"./dist/xlsx.mini.min.js":{"import":"./dist/xlsx.mini.min.js","require":"./dist/xlsx.mini.min.js","types":"./types/index.d.ts"},"./dist/xlsx.zahl":{"import":"./dist/xlsx.zahl.mjs","require":"./dist/xlsx.zahl.js","types":"./dist/zahl.d.ts"},"./dist/xlsx.zahl.mjs":{"import":"./dist/xlsx.zahl.mjs","types":"./dist/zahl.d.ts"},"./dist/xlsx.zahl.js":{"require":"./dist/xlsx.zahl.js","types":"./dist/zahl.d.ts"},"./dist/cpexcel":{"import":"./dist/cpexcel.full.mjs","require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.js":{"require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.full":{"import":"./dist/cpexcel.full.mjs","require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.full.mjs":{"import":"./dist/cpexcel.full.mjs","types":"./dist/cpexcel.d.ts"}},"browser":{"buffer":false,"crypto":false,"stream":false,"process":false,"fs":false},"sideEffects":false,"dependencies":{},"devDependencies":{"@sheetjs/uglify-js":"~2.7.3","@types/node":"^8.5.9","acorn":"7.4.1","adler-32":"~1.3.1","alex":"8.1.1","blanket":"~1.2.3","cfb":"~1.2.2","codepage":"~1.15.0","commander":"~2.17.1","crc-32":"~1.2.2","dtslint":"^0.1.2","eslint":"7.23.0","eslint-plugin-html":"^6.1.2","eslint-plugin-json":"^2.1.2","exit-on-epipe":"~1.0.1","fflate":"^0.7.1","jsdom":"~11.1.0","markdown-spellcheck":"^1.3.1","mocha":"~2.5.3","sinon":"^1.17.7","ssf":"~0.11.2","typescript":"2.2.0","wmf":"~1.0.1","word":"~0.3.0"},"repository":{"type":"git","url":"https://git.sheetjs.com/SheetJS/sheetjs"},"scripts":{"pretest":"npm run lint","test":"npm run tests-only","pretest-only":"git submodule init && git submodule update","tests-only":"make travis","build":"make","lint":"make fullint","dtslint":"dtslint types"},"config":{"blanket":{"pattern":"xlsx.js"}},"alex":{"allow":["chinese","special","simple","just","crash","wtf","holes"]},"homepage":"https://sheetjs.com/","files":["CHANGELOG.md","LICENSE","README.md","bower.json","package.json","xlsx.js","xlsx.mjs","xlsxworker.js","bin/xlsx.njs","dist/LICENSE","dist/*.mjs","dist/*.js","dist/*.map","dist/*.d.ts","types/index.d.ts","types/tsconfig.json"],"bugs":{"url":"https://git.sheetjs.com/SheetJS/sheetjs/issues"},"license":"Apache-2.0","engines":{"node":">=0.8"},"_lastModified":"2025-04-22T09:54:05.973Z"}
1
+ {"name":"xlsx","version":"0.20.2","author":"sheetjs","description":"SheetJS Spreadsheet data parser and writer","keywords":["excel","xls","xlsx","xlsb","xlsm","ods","csv","dbf","dif","sylk","office","spreadsheet"],"bin":{"xlsx":"./bin/xlsx.njs"},"main":"xlsx.js","module":"xlsx.mjs","unpkg":"dist/xlsx.full.min.js","jsdelivr":"dist/xlsx.full.min.js","types":"types/index.d.ts","exports":{".":{"import":"./xlsx.mjs","require":"./xlsx.js","types":"./types/index.d.ts"},"./xlsx.mjs":{"import":"./xlsx.mjs","types":"./types/index.d.ts"},"./xlsx.js":{"require":"./xlsx.js","types":"./types/index.d.ts"},"./dist/xlsx.core.min":{"import":"./dist/xlsx.core.min.js","require":"./dist/xlsx.core.min.js","types":"./types/index.d.ts"},"./dist/xlsx.core.min.js":{"import":"./dist/xlsx.core.min.js","require":"./dist/xlsx.core.min.js","types":"./types/index.d.ts"},"./dist/xlsx.full.min":{"import":"./dist/xlsx.full.min.js","require":"./dist/xlsx.full.min.js","types":"./types/index.d.ts"},"./dist/xlsx.full.min.js":{"import":"./dist/xlsx.full.min.js","require":"./dist/xlsx.full.min.js","types":"./types/index.d.ts"},"./dist/xlsx.mini.min":{"import":"./dist/xlsx.mini.min.js","require":"./dist/xlsx.mini.min.js","types":"./types/index.d.ts"},"./dist/xlsx.mini.min.js":{"import":"./dist/xlsx.mini.min.js","require":"./dist/xlsx.mini.min.js","types":"./types/index.d.ts"},"./dist/xlsx.zahl":{"import":"./dist/xlsx.zahl.mjs","require":"./dist/xlsx.zahl.js","types":"./dist/zahl.d.ts"},"./dist/xlsx.zahl.mjs":{"import":"./dist/xlsx.zahl.mjs","types":"./dist/zahl.d.ts"},"./dist/xlsx.zahl.js":{"require":"./dist/xlsx.zahl.js","types":"./dist/zahl.d.ts"},"./dist/cpexcel":{"import":"./dist/cpexcel.full.mjs","require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.js":{"require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.full":{"import":"./dist/cpexcel.full.mjs","require":"./dist/cpexcel.js","types":"./dist/cpexcel.d.ts"},"./dist/cpexcel.full.mjs":{"import":"./dist/cpexcel.full.mjs","types":"./dist/cpexcel.d.ts"}},"browser":{"buffer":false,"crypto":false,"stream":false,"process":false,"fs":false},"sideEffects":false,"dependencies":{},"devDependencies":{"@sheetjs/uglify-js":"~2.7.3","@types/node":"^8.5.9","acorn":"7.4.1","adler-32":"~1.3.1","alex":"8.1.1","blanket":"~1.2.3","cfb":"~1.2.2","codepage":"~1.15.0","commander":"~2.17.1","crc-32":"~1.2.2","dtslint":"^0.1.2","eslint":"7.23.0","eslint-plugin-html":"^6.1.2","eslint-plugin-json":"^2.1.2","exit-on-epipe":"~1.0.1","fflate":"^0.7.1","jsdom":"~11.1.0","markdown-spellcheck":"^1.3.1","mocha":"~2.5.3","sinon":"^1.17.7","ssf":"~0.11.2","typescript":"2.2.0","wmf":"~1.0.1","word":"~0.3.0"},"repository":{"type":"git","url":"https://git.sheetjs.com/SheetJS/sheetjs"},"scripts":{"pretest":"npm run lint","test":"npm run tests-only","pretest-only":"git submodule init && git submodule update","tests-only":"make travis","build":"make","lint":"make fullint","dtslint":"dtslint types"},"config":{"blanket":{"pattern":"xlsx.js"}},"alex":{"allow":["chinese","special","simple","just","crash","wtf","holes"]},"homepage":"https://sheetjs.com/","files":["CHANGELOG.md","LICENSE","README.md","bower.json","package.json","xlsx.js","xlsx.mjs","xlsxworker.js","bin/xlsx.njs","dist/LICENSE","dist/*.mjs","dist/*.js","dist/*.map","dist/*.d.ts","types/index.d.ts","types/tsconfig.json"],"bugs":{"url":"https://git.sheetjs.com/SheetJS/sheetjs/issues"},"license":"Apache-2.0","engines":{"node":">=0.8"},"_lastModified":"2025-04-23T15:15:58.291Z"}
@@ -10,6 +10,7 @@
10
10
  import { ICollection, ICollectionManager } from '@nocobase/data-source-manager';
11
11
  import { Transaction } from 'sequelize';
12
12
  import EventEmitter from 'events';
13
+ import { Context } from '@nocobase/actions';
13
14
  export type ImportColumn = {
14
15
  dataIndex: Array<string>;
15
16
  defaultTitle: string;
@@ -33,9 +34,10 @@ export declare class XlsxImporter extends EventEmitter {
33
34
  protected options: ImporterOptions;
34
35
  private repository;
35
36
  constructor(options: ImporterOptions);
36
- validate(): Promise<string[][]>;
37
+ validate(ctx?: Context): Promise<string[][]>;
37
38
  run(options?: RunOptions): Promise<any>;
38
39
  resetSeq(options?: RunOptions): Promise<void>;
40
+ private getColumnsByPermission;
39
41
  performImport(options?: RunOptions): Promise<any>;
40
42
  performInsert(insertOptions: {
41
43
  values: any;
@@ -46,6 +48,7 @@ export declare class XlsxImporter extends EventEmitter {
46
48
  renderErrorMessage(error: any): any;
47
49
  trimString(str: string): string;
48
50
  private getExpectedHeaders;
49
- getData(): Promise<string[][]>;
51
+ getData(ctx?: Context): Promise<string[][]>;
52
+ private alignWithHeaders;
50
53
  private findAndValidateHeaders;
51
54
  }
@@ -43,6 +43,7 @@ var XLSX = __toESM(require("xlsx"));
43
43
  var import_lodash = __toESM(require("lodash"));
44
44
  var import_events = __toESM(require("events"));
45
45
  var import_errors = require("../errors");
46
+ var import_lodash2 = __toESM(require("lodash"));
46
47
  class XlsxImporter extends import_events.default {
47
48
  constructor(options) {
48
49
  super();
@@ -56,8 +57,9 @@ class XlsxImporter extends import_events.default {
56
57
  this.repository = options.repository ? options.repository : options.collection.repository;
57
58
  }
58
59
  repository;
59
- async validate() {
60
- if (this.options.columns.length == 0) {
60
+ async validate(ctx) {
61
+ const columns = this.getColumnsByPermission(ctx);
62
+ if (columns.length == 0) {
61
63
  throw new import_errors.ImportValidationError("Columns configuration is empty");
62
64
  }
63
65
  for (const column of this.options.columns) {
@@ -66,7 +68,7 @@ class XlsxImporter extends import_events.default {
66
68
  throw new import_errors.ImportValidationError("Field not found: {{field}}", { field: column.dataIndex[0] });
67
69
  }
68
70
  }
69
- const data = await this.getData();
71
+ const data = await this.getData(ctx);
70
72
  return data;
71
73
  }
72
74
  async run(options = {}) {
@@ -75,7 +77,7 @@ class XlsxImporter extends import_events.default {
75
77
  transaction = options.transaction = await this.options.collectionManager.db.sequelize.transaction();
76
78
  }
77
79
  try {
78
- await this.validate();
80
+ await this.validate(options.context);
79
81
  const imported = await this.performImport(options);
80
82
  if (this.options.collectionManager.db) {
81
83
  await this.resetSeq(options);
@@ -96,7 +98,7 @@ class XlsxImporter extends import_events.default {
96
98
  return;
97
99
  }
98
100
  let hasImportedAutoIncrementPrimary = false;
99
- for (const importedDataIndex of this.options.columns) {
101
+ for (const importedDataIndex of this.getColumnsByPermission(options == null ? void 0 : options.context)) {
100
102
  if (importedDataIndex.dataIndex[0] === autoIncrementAttribute) {
101
103
  hasImportedAutoIncrementPrimary = true;
102
104
  break;
@@ -127,9 +129,18 @@ class XlsxImporter extends import_events.default {
127
129
  });
128
130
  this.emit("seqReset", { maxVal, seqName: autoIncrInfo.seqName });
129
131
  }
132
+ getColumnsByPermission(ctx) {
133
+ const columns = this.options.columns;
134
+ return columns.filter(
135
+ (x) => {
136
+ var _a, _b, _c, _d, _e;
137
+ return import_lodash2.default.isEmpty((_b = (_a = ctx == null ? void 0 : ctx.permission) == null ? void 0 : _a.can) == null ? void 0 : _b.params) ? true : import_lodash2.default.includes(((_e = (_d = (_c = ctx == null ? void 0 : ctx.permission) == null ? void 0 : _c.can) == null ? void 0 : _d.params) == null ? void 0 : _e.fields) || [], x.dataIndex[0]);
138
+ }
139
+ );
140
+ }
130
141
  async performImport(options) {
131
142
  const transaction = options == null ? void 0 : options.transaction;
132
- const data = await this.getData();
143
+ const data = await this.getData(options == null ? void 0 : options.context);
133
144
  const chunks = import_lodash.default.chunk(data.slice(1), this.options.chunkSize || 200);
134
145
  let handingRowIndex = 1;
135
146
  let imported = 0;
@@ -216,52 +227,44 @@ class XlsxImporter extends import_events.default {
216
227
  }
217
228
  return str;
218
229
  }
219
- getExpectedHeaders() {
220
- return this.options.columns.map((col) => col.title || col.defaultTitle);
230
+ getExpectedHeaders(ctx) {
231
+ const columns = this.getColumnsByPermission(ctx);
232
+ return columns.map((col) => col.title || col.defaultTitle);
221
233
  }
222
- async getData() {
234
+ async getData(ctx) {
223
235
  const workbook = this.options.workbook;
224
236
  const worksheet = workbook.Sheets[workbook.SheetNames[0]];
225
- const data = XLSX.utils.sheet_to_json(worksheet, { header: 1, defval: null });
226
- const expectedHeaders = this.getExpectedHeaders();
227
- const { headerRowIndex, headers } = this.findAndValidateHeaders(data);
237
+ let data = XLSX.utils.sheet_to_json(worksheet, { header: 1, defval: null });
238
+ const expectedHeaders = this.getExpectedHeaders(ctx);
239
+ const { headerRowIndex, headers } = this.findAndValidateHeaders({ data, expectedHeaders });
228
240
  if (headerRowIndex === -1) {
229
241
  throw new import_errors.ImportValidationError("Headers not found. Expected headers: {{headers}}", {
230
242
  headers: expectedHeaders.join(", ")
231
243
  });
232
244
  }
245
+ data = this.alignWithHeaders({ data, expectedHeaders, headers });
233
246
  const rows = data.slice(headerRowIndex + 1);
234
247
  if (rows.length === 0) {
235
248
  throw new import_errors.ImportValidationError("No data to import");
236
249
  }
237
250
  return [headers, ...rows];
238
251
  }
239
- findAndValidateHeaders(data) {
240
- const expectedHeaders = this.getExpectedHeaders();
252
+ alignWithHeaders(params) {
253
+ const { expectedHeaders, headers, data } = params;
254
+ const keepCols = headers.map((x, i) => expectedHeaders.includes(x) ? i : -1).filter((i) => i > -1);
255
+ return data.map((row) => keepCols.map((i) => row[i]));
256
+ }
257
+ findAndValidateHeaders(options) {
258
+ const { data, expectedHeaders } = options;
241
259
  for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
242
260
  const row = data[rowIndex];
243
261
  const actualHeaders = row.filter((cell) => cell !== null && cell !== "");
244
262
  const allHeadersFound = expectedHeaders.every((header) => actualHeaders.includes(header));
245
- const noExtraHeaders = actualHeaders.length === expectedHeaders.length;
246
- if (allHeadersFound && noExtraHeaders) {
247
- const mismatchIndex = expectedHeaders.findIndex((title, index) => actualHeaders[index] !== title);
248
- if (mismatchIndex === -1) {
249
- return { headerRowIndex: rowIndex, headers: actualHeaders };
250
- } else {
251
- throw new import_errors.ImportValidationError(
252
- 'Header mismatch at column {{column}}: expected "{{expected}}", but got "{{actual}}"',
253
- {
254
- column: mismatchIndex + 1,
255
- expected: expectedHeaders[mismatchIndex],
256
- actual: actualHeaders[mismatchIndex] || "empty"
257
- }
258
- );
259
- }
263
+ if (allHeadersFound) {
264
+ const orderedHeaders = expectedHeaders.filter((h) => actualHeaders.includes(h));
265
+ return { headerRowIndex: rowIndex, headers: orderedHeaders };
260
266
  }
261
267
  }
262
- throw new import_errors.ImportValidationError("Headers not found. Expected headers: {{headers}}", {
263
- headers: expectedHeaders.join(", ")
264
- });
265
268
  }
266
269
  }
267
270
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "操作:导入记录",
5
5
  "description": "Import records using excel templates. You can configure which fields to import and templates will be generated automatically.",
6
6
  "description.zh-CN": "使用 Excel 模板导入数据,可以配置导入哪些字段,自动生成模板。",
7
- "version": "1.6.22",
7
+ "version": "1.6.23",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/action-import",
@@ -36,7 +36,7 @@
36
36
  "@nocobase/test": "1.x",
37
37
  "@nocobase/utils": "1.x"
38
38
  },
39
- "gitHead": "321c0effa18670c0c3edfa09c79d535351ef2b0d",
39
+ "gitHead": "2ec917c09dc303978bdd33893d27c775d532c8f9",
40
40
  "keywords": [
41
41
  "Actions"
42
42
  ]