rtc4js 0.0.1 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +322 -0
  2. package/package.json +6 -2
package/README.md ADDED
@@ -0,0 +1,322 @@
1
+ # RapidTableConnector for Javascript
2
+ RapidTableConnector provides an SDK that allows easy CRUD operations using the Rest API provided by [RapidTable](https://rapid-table.com/).
3
+
4
+
5
+ [![npm](https://img.shields.io/npm/v/rtc4js.svg)](https://www.npmjs.com/package/rtc4js)
6
+ [![GitHub license](https://img.shields.io/github/license/rapid-table/rapid-table-connector.svg)](https://github.com/rapid-table/rapid-table-connector)
7
+ [![npm](https://img.shields.io/bundlephobia/min/rtc4js.svg)](https://www.npmjs.com/package/rtc4js)
8
+
9
+ ---
10
+
11
+ ## Getting started
12
+ ### Installation
13
+ ```
14
+ npm install rtc4js
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Usage - Create Connector
20
+ ### Create a connection instance
21
+ ```js
22
+ import { RapidTableConnector } from 'rtc4js';
23
+
24
+ const connector = RapidTableConnector.builder()
25
+ .accessId("developer@example.com")
26
+ .accessKey("************************")
27
+ .endpoint("rapid-table.example.com")
28
+ .build();
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Usage - Drive
34
+ ### Drive - Search assets
35
+ > Search for Drive assets in any workspace.
36
+ ```js
37
+ import { DriveComponentType, DriveResponse, DriveSearchRequest } from 'rtc4js';
38
+
39
+ const request = DriveSearchRequest.builder()
40
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
41
+ .componentType(DriveComponentType.DRIVE)
42
+ .page(0)
43
+ .size(15)
44
+ .build();
45
+ const results = await connector.search(request, DriveResponse.of);
46
+ console.log('results', results);
47
+ ```
48
+
49
+ ### Drive - Count assets
50
+ > Count Drive assets in this any workspace.
51
+ ```js
52
+ import { DriveComponentType, DriveCountRequest } from 'rtc4js';
53
+
54
+ const request = DriveCountRequest.builder()
55
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
56
+ .componentType(DriveComponentType.REPORT)
57
+ .query('png')
58
+ .build();
59
+ const results = await connector.count(request);
60
+ console.log('results', results);
61
+ ```
62
+
63
+ ### Drive - Get object
64
+ > Get specific object data in this any workspace
65
+ ```js
66
+ import * as fs from 'fs';
67
+ import { DriveGetMetadataRequest, metadataRequest, DriveResponse, DriveGetObjectRequest } from 'rtc4js';
68
+
69
+ const metadataRequest = DriveGetMetadataRequest.builder()
70
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
71
+ .objectId('RTC4J_TEST_OBJECT_ID')
72
+ .build();
73
+ try {
74
+ const metadata = await connector.get(metadataRequest, DriveResponse.of);
75
+
76
+ // download
77
+ const objectRequest = DriveGetObjectRequest.builder()
78
+ .path(metadata.path)
79
+ .build();
80
+ const object = await connector.getObject(objectRequest);
81
+ fs.writeFileSync(object.fileName, object.data, 'binary');
82
+ } catch (ex) {
83
+ console.error(ex);
84
+ }
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Usage - Projects Report
90
+
91
+ ### Projects - Search reports
92
+ > Search reports for a specific project in this any workspace.
93
+ ```js
94
+ import { ReportSearchRequest, ReportResponse } from 'rtc4js';
95
+
96
+ const request = ReportSearchRequest.builder()
97
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
98
+ .projectId('RTC4J_TEST_PROJECT_ID')
99
+ .page(0)
100
+ .size(15)
101
+ .build();
102
+ const results = await connector.search(request, ReportResponse.of);
103
+ console.log('results', results);
104
+ ```
105
+
106
+ ### Projects - Count reports
107
+ > Count reports for a specific project in this any workspace.
108
+ ```js
109
+ import { ReportCountRequest } from 'rtc4js';
110
+
111
+ const request = ReportCountRequest.builder()
112
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
113
+ .projectId('RTC4J_TEST_PROJECT_ID')
114
+ .build();
115
+ const results = await connector.count(request);
116
+ console.log('results', results);
117
+ ```
118
+
119
+ ### Projects - Get report
120
+ > Get report for a specific project in this any workspace.
121
+ ```js
122
+ import { ReportGetRequest, ReportResponse } from 'rtc4js';
123
+
124
+ const request = ReportGetRequest.builder()
125
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
126
+ .projectId('RTC4J_TEST_PROJECT_ID')
127
+ .reportId('RTC4J_TEST_REPORT_ID')
128
+ .build();
129
+ const report = await connector.get(request, ReportResponse.of);
130
+ console.log('report', report);
131
+ ```
132
+
133
+ ### Projects - Get report object
134
+ > Get report object for a specific object data in this any workspace.
135
+ ```js
136
+ import * as fs from 'fs';
137
+ import { ReportGetRequest, ReportResponse, ReportGetObjectRequest } from 'rtc4js';
138
+
139
+ const request = ReportGetRequest.builder()
140
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
141
+ .projectId('RTC4J_TEST_PROJECT_ID')
142
+ .reportId('RTC4J_TEST_REPORT_ID')
143
+ .build();
144
+ try {
145
+ const report = await connector.get(request, ReportResponse.of);
146
+ console.log('report', report);
147
+ const testImageFieldId = 'BAJNu8NgYi';
148
+ const images = report.getFieldAsList(testImageFieldId);
149
+
150
+ if (images.length) {
151
+ // download
152
+ const objectRequest = ReportGetObjectRequest.builder()
153
+ .target(images[0])
154
+ .build();
155
+ const object = await connector.getObject(objectRequest);
156
+ console.log('data', object.fileName, object.contentType, object.contentLength);
157
+ fs.writeFileSync(object.fileName, object.data, 'binary');
158
+ }
159
+ } catch (ex) {
160
+ console.error(ex);
161
+ }
162
+ ```
163
+
164
+ ### Projects - Generate Report ID
165
+ > This is an endpoint that generates IDs for reports in advance.
166
+ ```js
167
+ import { ReportGenerateIdRequest } from 'rtc4js';
168
+
169
+ const requestBuilder = ReportGenerateIdRequest.builder()
170
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
171
+ .projectId('RTC4J_TEST_PROJECT_ID')
172
+ .build();
173
+ const response = await connector.generateId(requestBuilder);
174
+ console.log('Report generateId = ' + response);
175
+ ```
176
+
177
+ ### Projects - Create Reports
178
+ > Create reports for a specific project in this any workspace.
179
+ ```js
180
+ import { ReportCreateRequest, ReportResponse } from 'rtc4js';
181
+
182
+ const requestBuilder = ReportCreateRequest.builder()
183
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
184
+ .projectId('RTC4J_TEST_PROJECT_ID')
185
+ // A sample dummy field is shown in the next section.
186
+ .append(makeDummyFields())
187
+ .build();
188
+ const response = await connector.create(requestBuilder, ReportResponse.of);
189
+ // FIXME
190
+ console.log('Report create = ' + response);
191
+ ```
192
+
193
+ ### Projects - Update Reports
194
+ > Update reports for a specific project in this any workspace.
195
+ ```js
196
+ import { ReportGetRequest, ReportUpdateRequest, ReportResponse } from 'rtc4js';
197
+
198
+ // Get report
199
+ const request = ReportGetRequest.builder()
200
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
201
+ .projectId('RTC4J_TEST_PROJECT_ID')
202
+ .reportId('RTC4J_TEST_REPORT_ID')
203
+ .build();
204
+ const response = await connector.get(request, ReportResponse.of);
205
+
206
+ // Update report
207
+ const testUpdateFieldId = 'B97LjXOPr7';
208
+ response.setField(testUpdateFieldId, response.getFieldAsString(testUpdateFieldId) + '-update');
209
+
210
+ const requestBuilder = ReportUpdateRequest.builder()
211
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
212
+ .projectId('RTC4J_TEST_PROJECT_ID')
213
+ .append('RTC4J_TEST_REPORT_ID', response.fields)
214
+ .build();
215
+ const updated = await connector.update(requestBuilder, ReportResponse.of);
216
+ console.log('Report update = ' + updated);
217
+ ```
218
+
219
+ ### Projects - Delete Reports
220
+ > Delete reports for a specific project in this any workspace.
221
+ ```js
222
+ import { ReportSearchRequest, ReportDeleteRequest, ReportResponse } from 'rtc4js';
223
+
224
+ // Search reports
225
+ const request = ReportSearchRequest.builder()
226
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
227
+ .projectId('RTC4J_TEST_PROJECT_ID')
228
+ .size(100)
229
+ .gte('CssVTEBWnK', '2023-05-09T00:00:00.000Z')
230
+ .build();
231
+ const response = await connector.search(request, ReportResponse.of);
232
+ console.log('Report search = ' + response.length);
233
+
234
+ if (response.length) {
235
+ // Delete reports
236
+ const ids = response.map(({ id }) => id);
237
+ const deleteRequest = ReportDeleteRequest.builder()
238
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
239
+ .projectId('RTC4J_TEST_PROJECT_ID')
240
+ .ids(...ids)
241
+ .build();
242
+ await connector.delete(deleteRequest);
243
+ }
244
+ ```
245
+
246
+ ### Projects - Put report object
247
+ > Put report object for a specific project in this any workspace.
248
+ ```js
249
+ import * as fs from 'fs';
250
+ import { ReportPutObjectRequest } from 'rtc4js';
251
+
252
+ const buffer = await fs.readFileSync('example.jpg');
253
+ const request = ReportPutObjectRequest.builder()
254
+ .workspaceId('RTC4J_TEST_WORKSPACE_ID')
255
+ .projectId('RTC4J_TEST_PROJECT_ID')
256
+ .reportId('RTC4J_TEST_REPORT_ID')
257
+ .append(buffer, 'example.jpg')
258
+ .build();
259
+ const response = await connector.putObject(request);
260
+ console.log('Report putObject = ' + response);
261
+ ```
262
+
263
+ ### Projects - Delete Report object
264
+ > Delete specific report object data in this any workspace
265
+ ```js
266
+ import { ReportDeleteObjectRequest } from 'rtc4js';
267
+
268
+ // FIXME
269
+ const target = "reports/******/******/******/objects/******?v=9999999999";
270
+ const request = ReportDeleteObjectRequest.builder()
271
+ .target(target)
272
+ .build();
273
+ await connector.delete(request);
274
+ ```
275
+
276
+ ### Sample code for report registration
277
+ ```js
278
+ function makeDummyFields(): { [key: string]: unknown } {
279
+ const fields: { [key: string]: unknown } = {};
280
+ // Number
281
+ fields['numberFieldId'] = 4;
282
+ // Text
283
+ fields['textFieldId'] = 'キーワード 3';
284
+ // DateTime
285
+ fields['dateTimeFieldId'] = new Date(2023, 5, 10, 12, 34, 45);
286
+ // Date
287
+ fields['dateFieldId'] = new Date(2023, 6, 11, 12, 34, 45);
288
+ // Time
289
+ fields['timeFieldId'] = new Date(2023, 5, 10, 13, 54, 2);
290
+ // Check
291
+ fields['checkFieldId'] = ['Check 2', 'Check 1'];
292
+ // Select
293
+ fields['SelectFieldId'] = 'Select 1';
294
+ // Radio
295
+ fields['radioFieldId'] = 'Radio 3';
296
+ // Check (Mode ref)
297
+ fields['checkRefFieldId'] = ['36', '33', '50'];
298
+ // Select (Mode ref)
299
+ fields['selectRefFieldId'] = '41';
300
+ // Radio (Mode ref)
301
+ fields['radioRefFieldId'] = '44';
302
+ // Tags
303
+ fields['tagFieldId'] = ['tagId1', 'tagId2'];
304
+ // Phone number
305
+ fields['phoneFieldId'] = '090-1234-7890';
306
+ // E-Mail
307
+ fields['emailFieldId'] = 'mail@example.com';
308
+ // Zip code
309
+ fields['zipCodeFieldId'] = '123-4567';
310
+ // File path
311
+ fields['fileFieldId'] = ['reports/workspaceId/projectId/reportId/objects/objectId?v=1674895052825'];
312
+ // User Ids
313
+ fields['userFieldId'] = ['userId1', 'userId2'];
314
+ // Projects
315
+ fields['projectFieldId'] = ['projectId'];
316
+ // Rate
317
+ fields['rateFieldId'] = 5;
318
+ // Url
319
+ fields['urlFieldId'] = 'https://example.com';
320
+ return fields;
321
+ }
322
+ ```
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "rtc4js",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "RapidTableConnector provides an SDK that allows easy CRUD operations using the Rest API provided by RapidTable.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "publish": "npm run build && npm publish",
9
+ "publish": "npm publish",
10
10
  "test": "jest --silent=false --verbose=false"
11
11
  },
12
12
  "keywords": [
@@ -16,6 +16,10 @@
16
16
  "author": "RapidTable <eiji.hirakawa@rapid-table.com> (https://rapid-table.com)",
17
17
  "license": "The Apache License, Version 2.0",
18
18
  "homepage": "https://rapid-table.com",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/rapid-table/rapid-table-connector.git"
22
+ },
19
23
  "dependencies": {
20
24
  "axios": "^1.3.4"
21
25
  },