@wix/bex-core 2.325.0 → 2.327.0
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/cjs/hooks/useImport.js +4 -0
- package/dist/cjs/hooks/useImport.js.map +1 -1
- package/dist/cjs/hooks/useImportConfig.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportState.js +181 -10
- package/dist/cjs/state/ImportState/ImportState.js.map +1 -1
- package/dist/cjs/state/ImportState/detectFieldType.js +140 -0
- package/dist/cjs/state/ImportState/detectFieldType.js.map +1 -0
- package/dist/cjs/state/ImportState/index.js +6 -0
- package/dist/cjs/state/ImportState/index.js.map +1 -1
- package/dist/esm/hooks/useImport.js +4 -2
- package/dist/esm/hooks/useImport.js.map +1 -1
- package/dist/esm/hooks/useImportConfig.js.map +1 -1
- package/dist/esm/state/ImportState/ImportState.js +146 -10
- package/dist/esm/state/ImportState/ImportState.js.map +1 -1
- package/dist/esm/state/ImportState/detectFieldType.js +125 -0
- package/dist/esm/state/ImportState/detectFieldType.js.map +1 -0
- package/dist/esm/state/ImportState/index.js +1 -0
- package/dist/esm/state/ImportState/index.js.map +1 -1
- package/dist/types/hooks/useImport.d.ts +3 -1
- package/dist/types/hooks/useImport.d.ts.map +1 -1
- package/dist/types/hooks/useImportConfig.d.ts +2 -1
- package/dist/types/hooks/useImportConfig.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportState.d.ts +57 -2
- package/dist/types/state/ImportState/ImportState.d.ts.map +1 -1
- package/dist/types/state/ImportState/detectFieldType.d.ts +21 -0
- package/dist/types/state/ImportState/detectFieldType.d.ts.map +1 -0
- package/dist/types/state/ImportState/index.d.ts +1 -0
- package/dist/types/state/ImportState/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Field-type detection for new fields created during CSV import (CAIRO-4131).
|
|
2
|
+
//
|
|
3
|
+
// Ported from cm-import (`wix-data-client/cm-import`):
|
|
4
|
+
// - per-cell rules from `src/field-configuration/detectFieldConfig.js`
|
|
5
|
+
// (`detectPrimitiveType`) and `src/types/validators/{number,url}.js`
|
|
6
|
+
// - the column-level majority vote from
|
|
7
|
+
// `src/field-configuration/guessFieldConfigFromSamples.js`
|
|
8
|
+
//
|
|
9
|
+
// This module owns the shared `NewFieldType` vocabulary and the primitive
|
|
10
|
+
// detector (number / date / boolean / url, else text). Media detection (image /
|
|
11
|
+
// video / document / audio) lives in `@wix/patterns-fields` — it needs the media
|
|
12
|
+
// URI parser, which core must not depend on — and is injected into `ImportState`
|
|
13
|
+
// via `detectColumnType` (see `ImportStateProps`). `detectColumnType` here takes
|
|
14
|
+
// the per-value detector as a parameter so the fields detector reuses this
|
|
15
|
+
// sampling/majority logic instead of re-implementing it.
|
|
16
|
+
// Column-detection sampling: look at the first `TYPE_SAMPLE_SIZE` values and
|
|
17
|
+
// require a >= `MAJORITY` share to agree on a non-text type. We use the same 2/3
|
|
18
|
+
// vote as cm-import but a **larger sample** — cm-import's `constants.sampleSize`
|
|
19
|
+
// is 6; we deliberately sample more so the inference is steadier on messy
|
|
20
|
+
// columns. Exported so callers pass only the head of a column to
|
|
21
|
+
// `detectColumnType` instead of copying it whole.
|
|
22
|
+
export const TYPE_SAMPLE_SIZE = 50;
|
|
23
|
+
const MAJORITY = 2 / 3;
|
|
24
|
+
// cm-import `validators/number.js` `validateString`.
|
|
25
|
+
const NUMBER_RE = /^[+-]?(?:\d+\.?\d*)?$/;
|
|
26
|
+
// cm-import `detectFieldConfig.js` date patterns.
|
|
27
|
+
const SLASH_DATE_RE = /^\d{1,2}\/\d{1,2}\/\d{4}(?: \d{1,2}:\d{1,2})?$/;
|
|
28
|
+
const ISO_DATE_RE = /\d{4}-\d{2}-\d{2}/;
|
|
29
|
+
// Approximates cm-import `validators/url.js` (website / email / phone / relative
|
|
30
|
+
// links). cm-import delegates structural validation to `@wix/santa-core-utils`
|
|
31
|
+
// `isValidUrl`/`isValidEmail`, which aren't available here — so website URLs are
|
|
32
|
+
// validated with the platform `URL` parser instead (rejects empty/whitespace/
|
|
33
|
+
// malformed authorities). It's still an approximation: `URL` accepts some
|
|
34
|
+
// odd-but-parseable hosts santa would reject.
|
|
35
|
+
const WEBSITE_PROTOCOLS = ['http:', 'https:', 'ftp:'];
|
|
36
|
+
const EMAIL_PROTOCOL = 'mailto:';
|
|
37
|
+
const PHONE_PROTOCOLS = ['sms:', 'tel:'];
|
|
38
|
+
const RELATIVE_PREFIXES = ['/', '#', '?'];
|
|
39
|
+
const PHONE_RE = /^[\s\d()+\-/_]+$/;
|
|
40
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
41
|
+
const startsWithAny = (value, prefixes) => prefixes.some((prefix) => value.startsWith(prefix));
|
|
42
|
+
const isValidWebsiteUrl = (value) => {
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = new URL(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return WEBSITE_PROTOCOLS.includes(parsed.protocol);
|
|
51
|
+
};
|
|
52
|
+
const isEmailUrl = (value) => value.startsWith(EMAIL_PROTOCOL) &&
|
|
53
|
+
EMAIL_RE.test(value.slice(EMAIL_PROTOCOL.length));
|
|
54
|
+
const isPhoneUrl = (value) => PHONE_PROTOCOLS.some((protocol) => value.startsWith(protocol) && PHONE_RE.test(value.slice(protocol.length)));
|
|
55
|
+
const isUrl = (value) => isValidWebsiteUrl(value) ||
|
|
56
|
+
isEmailUrl(value) ||
|
|
57
|
+
isPhoneUrl(value) ||
|
|
58
|
+
startsWithAny(value, RELATIVE_PREFIXES);
|
|
59
|
+
const isDate = (value) => {
|
|
60
|
+
if (SLASH_DATE_RE.test(value)) {
|
|
61
|
+
if (!Number.isNaN(new Date(value).getTime())) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
// cm-import also accepts dd/mm/yyyy by swapping day and month.
|
|
65
|
+
const swapped = value.replace(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, '$2/$1/$3');
|
|
66
|
+
if (!Number.isNaN(new Date(swapped).getTime())) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return ISO_DATE_RE.test(value) && !Number.isNaN(new Date(value).getTime());
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Infer the field type of a single CSV cell, in cm-import's order:
|
|
74
|
+
* empty → number → boolean → date → url, else text.
|
|
75
|
+
*/
|
|
76
|
+
export function detectValueType(value) {
|
|
77
|
+
if (value === '') {
|
|
78
|
+
return 'text';
|
|
79
|
+
}
|
|
80
|
+
if (NUMBER_RE.test(value)) {
|
|
81
|
+
return 'number';
|
|
82
|
+
}
|
|
83
|
+
const lower = value.toLowerCase();
|
|
84
|
+
if (lower === 'true' || lower === 'false') {
|
|
85
|
+
return 'boolean';
|
|
86
|
+
}
|
|
87
|
+
if (isDate(value)) {
|
|
88
|
+
return 'date';
|
|
89
|
+
}
|
|
90
|
+
if (isUrl(value)) {
|
|
91
|
+
return 'url';
|
|
92
|
+
}
|
|
93
|
+
return 'text';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Infer a column's field type from its first values: the most common detected
|
|
97
|
+
* type, but only when it covers at least two-thirds of the samples (otherwise
|
|
98
|
+
* `text`). Same majority-vote algorithm as cm-import
|
|
99
|
+
* `guessFieldConfigFromSamples`, with a larger sample (see `TYPE_SAMPLE_SIZE`).
|
|
100
|
+
*
|
|
101
|
+
* `detectValue` defaults to the primitive {@link detectValueType}; the fields
|
|
102
|
+
* detector passes a media-aware variant so it reuses this sampling/majority
|
|
103
|
+
* logic.
|
|
104
|
+
*/
|
|
105
|
+
export function detectColumnType(values, detectValue = detectValueType) {
|
|
106
|
+
const samples = values.slice(0, TYPE_SAMPLE_SIZE);
|
|
107
|
+
if (samples.length === 0) {
|
|
108
|
+
return 'text';
|
|
109
|
+
}
|
|
110
|
+
const counts = new Map();
|
|
111
|
+
samples.forEach((value) => {
|
|
112
|
+
const type = detectValue(value);
|
|
113
|
+
counts.set(type, (counts.get(type) ?? 0) + 1);
|
|
114
|
+
});
|
|
115
|
+
let best = 'text';
|
|
116
|
+
let bestCount = 0;
|
|
117
|
+
counts.forEach((count, type) => {
|
|
118
|
+
if (count > bestCount) {
|
|
119
|
+
best = type;
|
|
120
|
+
bestCount = count;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return bestCount >= samples.length * MAJORITY ? best : 'text';
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=detectFieldType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectFieldType.js","sourceRoot":"","sources":["../../../../src/state/ImportState/detectFieldType.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,uDAAuD;AACvD,yEAAyE;AACzE,yEAAyE;AACzE,0CAA0C;AAC1C,+DAA+D;AAC/D,EAAE;AACF,0EAA0E;AAC1E,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,2EAA2E;AAC3E,yDAAyD;AAsBzD,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,0EAA0E;AAC1E,iEAAiE;AACjE,kDAAkD;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;AAEvB,qDAAqD;AACrD,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAE1C,kDAAkD;AAClD,MAAM,aAAa,GAAG,gDAAgD,CAAC;AACvE,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,8EAA8E;AAC9E,0EAA0E;AAC1E,8CAA8C;AAC9C,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACtD,M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;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAgB,EAChB,cAA+B,eAAe;IAE9C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,MAAM,CAAC;KACf;IAED,MAAM,MAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,IAAI,IAAI,GAAiB,MAAM,CAAC;IAChC,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7B,IAAI,KAAK,GAAG,SAAS,EAAE;YACrB,IAAI,GAAG,IAAI,CAAC;YACZ,SAAS,GAAG,KAAK,CAAC;SACnB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAChE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/state/ImportState/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/state/ImportState/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ModalState, ImportState, BackupFn, BulkUploadItemsFn } from '../state';
|
|
1
|
+
import { ModalState, ImportState, BackupFn, BulkUploadItemsFn, UpdateSchemaFn, DetectColumnType } from '../state';
|
|
2
2
|
import { CreateExportAsyncJobRequest } from '@wix/bex-utils/@wix/ambassador-fedinfra-exportservice-v1-export-async-job/types';
|
|
3
3
|
import { FiltersMap } from '../model';
|
|
4
4
|
export interface UseImportParams {
|
|
5
5
|
fields: CreateExportAsyncJobRequest['fields'];
|
|
6
6
|
bulkUploadItems: BulkUploadItemsFn;
|
|
7
7
|
backup?: BackupFn;
|
|
8
|
+
updateSchema?: UpdateSchemaFn;
|
|
9
|
+
detectColumnType?: DetectColumnType;
|
|
8
10
|
importModalState: ModalState;
|
|
9
11
|
batchSize?: number;
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImport.d.ts","sourceRoot":"","sources":["../../../src/hooks/useImport.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"useImport.d.ts","sourceRoot":"","sources":["../../../src/hooks/useImport.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,2BAA2B,EAAE,MAAM,iFAAiF,CAAC;AAC9H,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC9C,eAAe,EAAE,iBAAiB,CAAC;IACnC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gBAAgB,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,UAAU,EAC5E,MAAM,EAAE,eAAe,qBAoCxB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CreateExportAsyncJobRequest } from '@wix/bex-utils/@wix/ambassador-fedinfra-exportservice-v1-export-async-job/types';
|
|
2
|
-
import { BackupFn, BulkUploadItemsFn } from '../state';
|
|
2
|
+
import { BackupFn, BulkUploadItemsFn, UpdateSchemaFn } from '../state';
|
|
3
3
|
export interface UseImportConfigParams {
|
|
4
4
|
fields: CreateExportAsyncJobRequest['fields'];
|
|
5
5
|
bulkUploadItems: BulkUploadItemsFn;
|
|
6
6
|
backup?: BackupFn;
|
|
7
|
+
updateSchema?: UpdateSchemaFn;
|
|
7
8
|
batchSize?: number;
|
|
8
9
|
}
|
|
9
10
|
export declare function useImportConfig(params: UseImportConfigParams): UseImportConfigParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImportConfig.d.ts","sourceRoot":"","sources":["../../../src/hooks/useImportConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iFAAiF,CAAC;AAC9H,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"useImportConfig.d.ts","sourceRoot":"","sources":["../../../src/hooks/useImportConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iFAAiF,CAAC;AAC9H,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEvE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC9C,eAAe,EAAE,iBAAiB,CAAC;IACnC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,yBAI5D"}
|
|
@@ -3,6 +3,7 @@ import { Translate } from '../../services';
|
|
|
3
3
|
import { ModalState } from '../ModalState';
|
|
4
4
|
import { ConditionalModalState } from '../ConditionalModalState';
|
|
5
5
|
import { CreateExportAsyncJobRequest } from '@wix/bex-utils/@wix/ambassador-fedinfra-exportservice-v1-export-async-job/types';
|
|
6
|
+
import { type DetectColumnType, type NewFieldType } from './detectFieldType';
|
|
6
7
|
export interface ImportCollection {
|
|
7
8
|
clearResultAndMoveToStart(params?: {
|
|
8
9
|
force?: boolean;
|
|
@@ -26,10 +27,46 @@ export interface BackupResult {
|
|
|
26
27
|
export type BackupFn = (signal: AbortSignal) => Promise<BackupResult | void>;
|
|
27
28
|
export type DownloadCsvFn = (content: string, fileName: string) => void;
|
|
28
29
|
export type ImportField = NonNullable<CreateExportAsyncJobRequest['fields']>[number];
|
|
30
|
+
export interface NewFieldDefinition {
|
|
31
|
+
key: string;
|
|
32
|
+
type: NewFieldType;
|
|
33
|
+
displayName: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Consumer-supplied callback that adds the given new fields to the collection
|
|
37
|
+
* schema in a single call, before the rows are uploaded. Mirrors the cm-import
|
|
38
|
+
* `beforeImport`/`updateSchema` flow: Cairo decides the fields (and their keys),
|
|
39
|
+
* the consumer performs one schema mutation (e.g. `updateSchema(collectionId,
|
|
40
|
+
* ...addField(key, config))`). Its presence is also the opt-in for the "create
|
|
41
|
+
* new field" default — see `getDefaultMapping`.
|
|
42
|
+
*/
|
|
43
|
+
export type UpdateSchemaFn = (fields: NewFieldDefinition[]) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* How a CSV column is mapped:
|
|
46
|
+
* - `existing` — into an existing collection field by id
|
|
47
|
+
* - `new` — into a new field created during import (always text for now)
|
|
48
|
+
* - `null` — don't import (skip)
|
|
49
|
+
*/
|
|
50
|
+
export type ColumnMapping = {
|
|
51
|
+
kind: 'existing';
|
|
52
|
+
fieldId: string;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'new';
|
|
55
|
+
fieldType: NewFieldType;
|
|
56
|
+
} | null;
|
|
29
57
|
export interface ImportStateProps {
|
|
30
58
|
fields: CreateExportAsyncJobRequest['fields'];
|
|
31
59
|
bulkUploadItems: BulkUploadItemsFn;
|
|
32
60
|
backup?: BackupFn;
|
|
61
|
+
updateSchema?: UpdateSchemaFn;
|
|
62
|
+
/**
|
|
63
|
+
* Infers a new field's type from its column data. Defaults to the primitive
|
|
64
|
+
* detector (number / date / boolean / url / text). `@wix/patterns` injects a
|
|
65
|
+
* media-aware detector from `@wix/patterns-fields` (image / video / document /
|
|
66
|
+
* audio) — that detection needs the media URI parser, which core can't depend
|
|
67
|
+
* on.
|
|
68
|
+
*/
|
|
69
|
+
detectColumnType?: DetectColumnType;
|
|
33
70
|
collection: ImportCollection;
|
|
34
71
|
importModalState: ModalState;
|
|
35
72
|
translate: Translate;
|
|
@@ -43,6 +80,7 @@ export declare class ImportState {
|
|
|
43
80
|
readonly fields: ImportField[];
|
|
44
81
|
readonly bulkUploadItems: BulkUploadItemsFn;
|
|
45
82
|
readonly backup?: BackupFn;
|
|
83
|
+
readonly updateSchema?: UpdateSchemaFn;
|
|
46
84
|
readonly collection: ImportCollection;
|
|
47
85
|
readonly importModalState: ModalState;
|
|
48
86
|
readonly translate: Translate;
|
|
@@ -50,13 +88,14 @@ export declare class ImportState {
|
|
|
50
88
|
readonly showToast?: ShowToast;
|
|
51
89
|
readonly downloadCsv?: DownloadCsvFn;
|
|
52
90
|
readonly batchSize: number;
|
|
91
|
+
private readonly _detectColumnType;
|
|
53
92
|
readonly discardChangesModal: ConditionalModalState<"close" | "goBack">;
|
|
54
93
|
currentStep: ImportStep;
|
|
55
94
|
importStatus: TaskStatus<BulkUploadResults, unknown>;
|
|
56
95
|
fileName: string;
|
|
57
96
|
csvHeaders: string[];
|
|
58
97
|
csvRows: string[][];
|
|
59
|
-
mappingByHeader: Record<string,
|
|
98
|
+
mappingByHeader: Record<string, ColumnMapping>;
|
|
60
99
|
processedCount: number;
|
|
61
100
|
totalCount: number;
|
|
62
101
|
result: BulkUploadResults;
|
|
@@ -79,7 +118,13 @@ export declare class ImportState {
|
|
|
79
118
|
*/
|
|
80
119
|
get hasNoMappedData(): boolean;
|
|
81
120
|
get selectedFieldIds(): Set<string>;
|
|
82
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Whether columns may be mapped to a brand-new field created during import.
|
|
123
|
+
* Driven purely by the presence of the `updateSchema` callback — providing the
|
|
124
|
+
* capability is the opt-in (see `getDefaultMapping`). Never changes after
|
|
125
|
+
* construction, so it isn't an observable.
|
|
126
|
+
*/
|
|
127
|
+
get canCreateNewField(): boolean;
|
|
83
128
|
reset(): void;
|
|
84
129
|
close(): Promise<void>;
|
|
85
130
|
private _restoreBackup;
|
|
@@ -88,6 +133,7 @@ export declare class ImportState {
|
|
|
88
133
|
discardAndClose(): Promise<void>;
|
|
89
134
|
onUploadContinue(): void;
|
|
90
135
|
private getDefaultMapping;
|
|
136
|
+
private _columnValues;
|
|
91
137
|
private applyParsedCsv;
|
|
92
138
|
onFileSelected(file: File | null): Promise<void>;
|
|
93
139
|
private _readFileBytes;
|
|
@@ -97,9 +143,18 @@ export declare class ImportState {
|
|
|
97
143
|
private _showPartialSuccessToast;
|
|
98
144
|
private _downloadFailedRows;
|
|
99
145
|
setMapping(header: string, fieldId: string | null): void;
|
|
146
|
+
setNewFieldMapping(header: string): void;
|
|
100
147
|
private _uploadBatches;
|
|
101
148
|
private _runBackup;
|
|
102
149
|
private _lingerOnCompletion;
|
|
150
|
+
/**
|
|
151
|
+
* Resolves every column to the final destination key used in the upload
|
|
152
|
+
* payload: an existing field id, a new field's (Cairo-decided) key, or `null`
|
|
153
|
+
* to skip. All new fields are added to the schema in a single `updateSchema`
|
|
154
|
+
* call before the rows upload — mirroring the cm-import `beforeImport` flow.
|
|
155
|
+
* `updateSchema` may throw — `startImport` surfaces that as the error state.
|
|
156
|
+
*/
|
|
157
|
+
private _resolveFieldMapping;
|
|
103
158
|
private _createRowsBatches;
|
|
104
159
|
startImport(): Promise<void>;
|
|
105
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportState.d.ts","sourceRoot":"","sources":["../../../../src/state/ImportState/ImportState.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,SAAS,EACT,UAAU,EACV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iFAAiF,CAAC;
|
|
1
|
+
{"version":3,"file":"ImportState.d.ts","sourceRoot":"","sources":["../../../../src/state/ImportState/ImportState.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,SAAS,EACT,UAAU,EACV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iFAAiF,CAAC;AAE9H,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC/D;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CA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AAmB;IAM3B;;;;;;OAMG;YACW,oBAAoB;IA4ClC,OAAO,CAAC,kBAAkB;IAUpB,WAAW;CA6GlB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type NewFieldType = 'text' | 'number' | 'date' | 'boolean' | 'url' | 'image' | 'video' | 'document' | 'audio';
|
|
2
|
+
export type DetectColumnType = (values: string[]) => NewFieldType;
|
|
3
|
+
export type DetectValueType = (value: string) => NewFieldType;
|
|
4
|
+
export declare const TYPE_SAMPLE_SIZE = 50;
|
|
5
|
+
/**
|
|
6
|
+
* Infer the field type of a single CSV cell, in cm-import's order:
|
|
7
|
+
* empty → number → boolean → date → url, else text.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectValueType(value: string): NewFieldType;
|
|
10
|
+
/**
|
|
11
|
+
* Infer a column's field type from its first values: the most common detected
|
|
12
|
+
* type, but only when it covers at least two-thirds of the samples (otherwise
|
|
13
|
+
* `text`). Same majority-vote algorithm as cm-import
|
|
14
|
+
* `guessFieldConfigFromSamples`, with a larger sample (see `TYPE_SAMPLE_SIZE`).
|
|
15
|
+
*
|
|
16
|
+
* `detectValue` defaults to the primitive {@link detectValueType}; the fields
|
|
17
|
+
* detector passes a media-aware variant so it reuses this sampling/majority
|
|
18
|
+
* logic.
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectColumnType(values: string[], detectValue?: DetectValueType): NewFieldType;
|
|
21
|
+
//# sourceMappingURL=detectFieldType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectFieldType.d.ts","sourceRoot":"","sources":["../../../../src/state/ImportState/detectFieldType.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,QAAQ,GACR,MAAM,GACN,SAAS,GACT,KAAK,GACL,OAAO,GACP,OAAO,GACP,UAAU,GACV,OAAO,CAAC;AAGZ,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,YAAY,CAAC;AAGlE,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;AAQ9D,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAkEnC;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAkB3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EAAE,EAChB,WAAW,GAAE,eAAiC,GAC7C,YAAY,CAsBd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/state/ImportState/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/state/ImportState/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/bex-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.327.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kobi",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"exports"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wix/bex-utils": "2.
|
|
44
|
+
"@wix/bex-utils": "2.114.0",
|
|
45
45
|
"chance": "^1.0.0",
|
|
46
46
|
"events": "^3.0.0",
|
|
47
47
|
"formstate": "^2.1.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@types/react": "^16.0.0",
|
|
64
64
|
"@wix/auto-crud": "^1.0.108",
|
|
65
65
|
"@wix/babel-cli": "^1.11.0",
|
|
66
|
-
"@wix/cairo-integration-utils": "1.
|
|
66
|
+
"@wix/cairo-integration-utils": "1.89.0",
|
|
67
67
|
"@wix/eslint-config-yoshi": "^6.74.0",
|
|
68
68
|
"@wix/fe-essentials": "^1.233.0",
|
|
69
69
|
"@wix/fe-essentials-standalone": "^1.374.0",
|
|
@@ -169,5 +169,5 @@
|
|
|
169
169
|
"wallaby": {
|
|
170
170
|
"autoDetect": true
|
|
171
171
|
},
|
|
172
|
-
"falconPackageHash": "
|
|
172
|
+
"falconPackageHash": "6c5687da76f292d8e76a0834ce75a642941a5cb2f9e442bd777403e2"
|
|
173
173
|
}
|