@rowslint/importer-js 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -1,8 +1,20 @@
1
1
  # @rowslint/importer-js
2
2
 
3
- The Rowslint JavaScript script provides access to the prebuilt importer component. The package interacts directly with the Rowslint APIs using your API key.
3
+ # JavaScript
4
4
 
5
- ## Usage
5
+ The Rowslint JavaScript package provides access to the prebuilt widget importer component. The package interacts directly with the Rowslint APIs using your API key.
6
+
7
+ ## Installation
8
+
9
+ There are 2 ways to use the importer, either using the `@rowslint/importer-js` npm package or directly from the CDN.
10
+
11
+ ### npm package module (recommended)
12
+
13
+ ```
14
+ npm install @rowslint/importer-js
15
+ ```
16
+
17
+ ### CDN
6
18
 
7
19
  Include a script tag with the import statement pointing to the CDN URL where the `@rowslint/importer-js` package is hosted:
8
20
 
@@ -10,41 +22,45 @@ Include a script tag with the import statement pointing to the CDN URL where the
10
22
  <script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
11
23
  ```
12
24
 
13
- Import TypeScript interfaces from the `@rowslint/importer-js/dist/models/importer.model` path if you are using TypeScript:
25
+ ## Usage
14
26
 
15
- ```ts
16
- import { RowslintConfig } from '@rowslint/importer-js/dist/models/importer.model';
17
- ```
27
+ :::info
18
28
 
19
- Call the `launch()` method with the organization API key and the template key parameters to display the importer UI.
29
+ In the following examples we will use the npm package. if you wish to use the CDN script, simply change `launchRowslint({})` by `rowslint.launchRowslint({})`.
20
30
 
21
- ```jsx
22
- <script>
23
- const launch = () => {
24
- rowslint.launch({
25
- // Your organization API key here.
26
- apiKey: "ORGANIZATION_API_KEY",
27
- config: {
28
- // Your template key here.
29
- templateKey: "TEMPLATE_KEY"
30
- }
31
- });
32
- }
33
- </script>
31
+ :::
34
32
 
35
- <button onclick="launch()">Launch</button>
33
+ Call the `launchRowslint()` method with the [organization API key](https://app.rowslint.io/settings/organization) and the template key parameters to display the importer UI.
34
+
35
+ Get the template key from the "**Settings**" tab in the template edit page.
36
+
37
+ ```jsx
38
+ import { launchRowslint } from '@rowslint/importer-js';
39
+
40
+ const launch = () => {
41
+ launchRowslint({
42
+ // Your organization API key here.
43
+ apiKey: 'ORGANIZATION_API_KEY',
44
+ config: {
45
+ // Your template key here.
46
+ templateKey: 'TEMPLATE_KEY',
47
+ },
48
+ });
49
+ };
50
+
51
+ <button onclick="launch()">Launch</button>;
36
52
  ```
37
53
 
38
- #### Headless UI
54
+ ### Headless UI
39
55
 
40
- You can also use your custom upload UI and then use Rowslint importer only to format and validate data (this will display the import modal without the first upload step). To do so, call the `launch()` method with the uploaded XLSX or CSV file (in `File` type).
56
+ You can also use your custom upload UI and then use Rowslint importer SDK only to format and validate data (this will display the import modal without the first upload step). To do so, call the `launchRowslint()` method with the uploaded XLSX or CSV file (in `File` type).
41
57
 
42
58
  ```jsx
43
- rowslint.launch({
59
+ launchRowslint({
44
60
  apiKey: 'ORGANIZATION_API_KEY',
45
61
  config: {
46
62
  templateKey: 'TEMPLATE_KEY',
47
- // `inputFile` in `file` type.
63
+ // `inputFile` in `File` type.
48
64
  file: inputFile,
49
65
  },
50
66
  });
@@ -52,12 +68,15 @@ rowslint.launch({
52
68
 
53
69
  ### Events
54
70
 
55
- The `launch()` method provide a callback parameter which is triggered on the importer modal closes. You can use it to handle the closing of the importer after the import has been completed.
71
+ The `launchRowslint()` method provide a callback parameter which is triggered on the importer modal closes. You can use it to handle the closing of the importer after the import has been completed.
72
+
73
+ See an example of the return format [here](#get-data).
56
74
 
57
75
  ```jsx
58
- rowslint.launch({
76
+ launchRowslint({
59
77
  apiKey: 'ORGANIZATION_API_KEY',
60
78
  config: { templateKey: 'TEMPLATE_KEY' },
79
+ // Callback.
61
80
  onImport: (result) => {
62
81
  switch (result.status) {
63
82
  case 'success':
@@ -76,7 +95,7 @@ rowslint.launch({
76
95
 
77
96
  ## Parameters
78
97
 
79
- The `launch()` method take one object parameter with 4 properties:
98
+ The `launchRowslint()` method take one object parameter with 4 properties:
80
99
 
81
100
  | Name | Type | Required | Description |
82
101
  | -------- | ---------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
@@ -119,30 +138,27 @@ Represents the return of the importer after the modal is closed.
119
138
 
120
139
  ### Importer UI
121
140
 
122
- This example demonstrates how to use the importer by displaying the importer UI and listening on the event when the import process is complete.
141
+ This example demonstrates how to use the importer by displaying the importer modal and trigger the `onImport` callback when the import process is complete.
123
142
 
124
143
  ```jsx
125
- <body>
126
- <script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
127
- <script>
128
- const launch = () => {
129
- rowslint.launch({
130
- apiKey: 'ORGANIZATION_API_KEY',
131
- config: {
132
- templateKey: 'TEMPLATE_KEY',
133
- returnType: 'json'
134
- },
135
- onImport: (result) => {
136
- if (result.status === 'success' && result.metadata?.is_valid) {
137
- // Continue the import process.
138
- }
139
- },
140
- });
141
- };
142
- </script>
143
-
144
- <button onclick="launch()">Launch</button>
145
- </body>
144
+ import { launchRowslint } from '@rowslint/importer-js';
145
+
146
+ const launch = () => {
147
+ launchRowslint({
148
+ apiKey: 'ORGANIZATION_API_KEY',
149
+ config: {
150
+ templateKey: 'TEMPLATE_KEY',
151
+ returnType: 'json',
152
+ },
153
+ onImport: (result) => {
154
+ if (result.status === 'success' && result.metadata?.is_valid) {
155
+ // Continue the import process.
156
+ }
157
+ },
158
+ });
159
+ };
160
+
161
+ <button onclick="launch()">Launch</button>;
146
162
  ```
147
163
 
148
164
  ### Headless importer UI
@@ -150,112 +166,144 @@ This example demonstrates how to use the importer by displaying the importer UI
150
166
  In this example, we will use the importer in the headless mode without the first upload step. To do so, we will use our custom file input field to upload the file, then we will set it to the importer.
151
167
 
152
168
  ```jsx
153
- <body>
154
- <script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
155
- <script>
156
- const launch = () => {
157
- const inputFile = document.getElementById('file');
158
- rowslint.launch({
159
- apiKey: 'ORGANIZATION_API_KEY',
160
- config: {
161
- templateKey: 'TEMPLATE_KEY',
162
- returnType: 'xslx',
163
- },
164
- file: inputFile.files[0],
165
- onImport: (result) => {
166
- // Continue the import process.
167
- },
168
- });
169
- };
170
- </script>
171
-
172
- <input id="file" type="file" />
173
- <button onclick="launch()">Launch</button>
174
- </body>
169
+ import { launchRowslint } from '@rowslint/importer-js';
170
+
171
+ const launch = () => {
172
+ const inputFile = document.getElementById('file');
173
+ launchRowslint({
174
+ apiKey: 'ORGANIZATION_API_KEY',
175
+ config: {
176
+ templateKey: 'TEMPLATE_KEY',
177
+ returnType: 'xslx',
178
+ },
179
+ file: inputFile.files[0],
180
+ onImport: (result) => {
181
+ // Continue the import process.
182
+ },
183
+ });
184
+ };
185
+
186
+ <input id="file" type="file" />
187
+ <button onclick="launch()">Launch</button>
175
188
  ```
176
189
 
177
190
  ### Custom validations
178
191
 
179
- We can define a custom configuration of validations from the code. Let's say our template has a "firstname" column. In this example, we will customize the validation of this column to accept only values starting with the letter "A".
192
+ We can define a custom configuration of validations from the code. Let's say our template has a "firstname" column. In this example, we will set a custom the validation of this column to accept only values starting with the letter "A".
180
193
 
181
194
  ```jsx
182
- <body>
183
- <script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
184
- <script>
185
- const launch = () => {
186
- rowslint.launch({
187
- apiKey: 'ORGANIZATION_API_KEY',
188
- config: {
189
- templateKey: 'TEMPLATE_KEY'
190
- },
191
- customValidators: {
192
- 'firstname': (columnValue) => {
193
- if (typeof columnValue === 'string' && columnValue.startsWith('A')) {
194
- // Return `true` if the value is valid.
195
- return true;
196
- }
197
- // Return custom message if the value is invalid.
198
- return {
199
- message: 'Must start with the letter "A".',
200
- };
201
- },
202
- },
203
- onImport: (result) => {
204
- // Continue the import process.
205
- },
206
- });
207
- };
208
- </script>
209
-
210
- <button onclick="launch()">Launch</button>
211
- </body>
195
+ import { launchRowslint } from '@rowslint/importer-js';
196
+
197
+ const launch = () => {
198
+ launchRowslint({
199
+ apiKey: 'ORGANIZATION_API_KEY',
200
+ config: {
201
+ templateKey: 'TEMPLATE_KEY',
202
+ },
203
+ customValidators: {
204
+ firstname: (columnValue) => {
205
+ if (typeof columnValue === 'string' && columnValue.startsWith('A')) {
206
+ // Return `true` if the value is valid.
207
+ return true;
208
+ }
209
+ // Return custom message if the value is invalid.
210
+ return {
211
+ message: 'Must start with the letter "A".',
212
+ };
213
+ },
214
+ },
215
+ onImport: (result) => {
216
+ // Continue the import process.
217
+ },
218
+ });
219
+ };
220
+
221
+ <button onclick="launch()">Launch</button>;
212
222
  ```
213
223
 
214
224
  Note that:
215
225
 
216
226
  - `firstname` property is the column name and must already be added to the template columns.
217
- - By defining a column custom validation, this will override the column validation type already defined in the template edition page.
227
+ - By defining a custom column validation, this will override the column validation type already defined in the template edition page.
218
228
 
219
229
  We can also return a list of valid values to be displayed in a select field.
220
230
 
221
231
  ```jsx
222
- <body>
223
- <script src="https://cdn.jsdelivr.net/npm/@rowslint/importer-js@latest/dist/rowslint.js"></script>
224
- <script>
225
- const validValues = ['A', 'B'];
226
- const launch = () => {
227
- rowslint.launch({
228
- apiKey: 'ORGANIZATION_API_KEY',
229
- config: {
230
- templateKey: 'TEMPLATE_KEY'
231
- },
232
- customValidators: {
233
- 'firstname': (columnValue) => {
234
- if (typeof columnValue === 'string' && validValues.includes(columnValue)) {
235
- // Return `true` if the value is valid.
236
- return true;
237
- }
238
- // Return custom message if the value is invalid.
239
- return {
240
- message: 'Must be "A" or "B".',
241
- validationType: 'choiceList',
242
- validationOptions: {
243
- list: validValues,
244
- },
245
- };
246
- }
247
- },
248
- onImport: (result) => {
249
- // Continue the import process.
250
- },
251
- });
252
- };
253
- </script>
254
-
255
- <button onclick="launch()">Launch</button>
256
- </body>
232
+ import { launchRowslint } from '@rowslint/importer-js';
233
+
234
+ const validValues = ['A', 'B'];
235
+ const launch = () => {
236
+ launchRowslint({
237
+ apiKey: 'ORGANIZATION_API_KEY',
238
+ config: {
239
+ templateKey: 'TEMPLATE_KEY',
240
+ },
241
+ customValidators: {
242
+ firstname: (columnValue) => {
243
+ if (typeof columnValue === 'string' && validValues.includes(columnValue)) {
244
+ // Return `true` if the value is valid.
245
+ return true;
246
+ }
247
+ // Return custom message if the value is invalid.
248
+ return {
249
+ message: 'Must be "A" or "B".',
250
+ validationType: 'choiceList',
251
+ validationOptions: {
252
+ list: validValues,
253
+ },
254
+ };
255
+ },
256
+ },
257
+ onImport: (result) => {
258
+ // Continue the import process.
259
+ },
260
+ });
261
+ };
262
+
263
+ <button onclick="launch()">Launch</button>;
257
264
  ```
258
265
 
259
- ## Documentation
266
+ ## Get data
267
+
268
+ The SDK data return type of the `onImport` callback is:
260
269
 
261
- To see the latest documentation, [please click here](https://docs.rowslint.dev)
270
+ ```ts
271
+ export interface RowslintImportResult {
272
+ status: RowslintImportResultStatus;
273
+ data?: {
274
+ file?: File;
275
+ rows?: Array<Record<string, unknown>>;
276
+ };
277
+ metadata?: {
278
+ is_valid: boolean;
279
+ file_name: string;
280
+ sheet_name?: string;
281
+ };
282
+ }
283
+
284
+ enum RowslintImportResultStatus {
285
+ SUCCESS = 'success',
286
+ ERROR = 'error',
287
+ CANCELLED = 'cancelled',
288
+ }
289
+ ```
290
+
291
+ Here's an example:
292
+
293
+ ```js
294
+ {
295
+ status: "success",
296
+ metadata: {
297
+ is_valid: true,
298
+ file_name: "myFile.xlsx",
299
+ sheet_name: "Sheet1"
300
+ },
301
+ rows: [
302
+ {
303
+ firstname: "Jean",
304
+ lastname: "Pierre",
305
+ email: "jean@pierre.com"
306
+ }
307
+ ]
308
+ }
309
+ ```
package/dist/rowslint.js CHANGED
@@ -8,12 +8,12 @@ const d = (t) => {
8
8
  "No API key provided to Rowslint. You may have forgotten to provide a valid API key to finish initializing Rowslint."
9
9
  );
10
10
  const e = document.createElement("rowslint-element");
11
- e.apiKey = t.apiKey, e.config = t.config, e.file = t.file ?? null, e.showButton = !1, e.addEventListener("import", function o(i) {
11
+ e.apiKey = t.apiKey, e.config = t.config, e.file = t.file ?? null, e.addEventListener("import", function o(i) {
12
12
  var n;
13
- const s = i;
14
- (n = t.onImport) == null || n.call(t, s.detail), l(), window.removeEventListener("import", o, !1);
13
+ const l = i;
14
+ (n = t.onImport) == null || n.call(t, l.detail), s(), window.removeEventListener("import", o, !1);
15
15
  }), document.body.appendChild(e);
16
- }, l = () => {
16
+ }, s = () => {
17
17
  const t = document.querySelector("rowslint-element");
18
18
  t == null || t.remove();
19
19
  };
@@ -1 +1 @@
1
- (function(t,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(t=typeof globalThis<"u"?globalThis:t||self,o(t.rowslint={}))})(this,function(t){"use strict";(()=>{const e=document.createElement("script");e.src="https://cdn.jsdelivr.net/npm/@rowslint/importer@latest/browser/rowslint-element.js",document.head.appendChild(e)})();const o=e=>{if(!e.apiKey)throw new Error("No API key provided to Rowslint. You may have forgotten to provide a valid API key to finish initializing Rowslint.");const n=document.createElement("rowslint-element");n.apiKey=e.apiKey,n.config=e.config,n.file=e.file??null,n.showButton=!1,n.addEventListener("import",function l(d){var i;const m=d;(i=e.onImport)==null||i.call(e,m.detail),s(),window.removeEventListener("import",l,!1)}),document.body.appendChild(n)},s=()=>{const e=document.querySelector("rowslint-element");e==null||e.remove()};t.launchRowslint=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.rowslint={}))})(this,function(t){"use strict";(()=>{const e=document.createElement("script");e.src="https://cdn.jsdelivr.net/npm/@rowslint/importer@latest/browser/rowslint-element.js",document.head.appendChild(e)})();const n=e=>{if(!e.apiKey)throw new Error("No API key provided to Rowslint. You may have forgotten to provide a valid API key to finish initializing Rowslint.");const o=document.createElement("rowslint-element");o.apiKey=e.apiKey,o.config=e.config,o.file=e.file??null,o.addEventListener("import",function l(d){var i;const m=d;(i=e.onImport)==null||i.call(e,m.detail),s(),window.removeEventListener("import",l,!1)}),document.body.appendChild(o)},s=()=>{const e=document.querySelector("rowslint-element");e==null||e.remove()};t.launchRowslint=n,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowslint/importer-js",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "author": "Mouad Ennaciri",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/rowslint.js",