@uipath/data-fabric-tool 1.1.0 → 1.195.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.
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
3
3
 
4
4
  vi.mock("../utils/sdk-client", () => ({
5
5
  createDataFabricClient: vi.fn(),
6
+ connectOrFail: vi.fn(),
6
7
  }));
7
8
 
8
9
  vi.mock("@uipath/common", async (importOriginal) => {
@@ -27,7 +28,7 @@ vi.mock("@uipath/filesystem", () => ({
27
28
  }));
28
29
 
29
30
  import { OutputFormatter } from "@uipath/common";
30
- import { createDataFabricClient } from "../utils/sdk-client";
31
+ import { connectOrFail } from "../utils/sdk-client";
31
32
  import { registerFilesCommand } from "./files";
32
33
 
33
34
  function mockSdk(overrides: Record<string, unknown> = {}) {
@@ -39,7 +40,7 @@ function mockSdk(overrides: Record<string, unknown> = {}) {
39
40
  ...overrides,
40
41
  },
41
42
  };
42
- vi.mocked(createDataFabricClient).mockResolvedValue(sdk as never);
43
+ vi.mocked(connectOrFail).mockResolvedValue(sdk as never);
43
44
  return sdk;
44
45
  }
45
46
 
@@ -134,22 +135,17 @@ describe("files upload", () => {
134
135
  );
135
136
  });
136
137
 
137
- it("should error when SDK connection fails on upload", async () => {
138
- vi.mocked(createDataFabricClient).mockRejectedValue(
139
- new Error("Not logged in"),
140
- );
138
+ it("should bail when SDK connection fails on upload", async () => {
139
+ const sdk = mockSdk();
140
+ vi.mocked(connectOrFail).mockResolvedValue(undefined);
141
141
  mockFs.readFile.mockResolvedValue(new Uint8Array([1, 2, 3]));
142
142
  const program = buildProgram();
143
143
  await runCommand(
144
144
  program,
145
145
  "files upload entity-1 record-1 attachment --file /tmp/report.pdf",
146
146
  );
147
- expect(OutputFormatter.error).toHaveBeenCalledWith(
148
- expect.objectContaining({
149
- Result: "Failure",
150
- Message: "Error connecting to Data Fabric",
151
- }),
152
- );
147
+ expect(sdk.entities.uploadAttachment).not.toHaveBeenCalled();
148
+ expect(OutputFormatter.success).not.toHaveBeenCalled();
153
149
  });
154
150
 
155
151
  it("should error when upload API fails", async () => {
@@ -218,21 +214,16 @@ describe("files download", () => {
218
214
  );
219
215
  });
220
216
 
221
- it("should error when SDK connection fails", async () => {
222
- vi.mocked(createDataFabricClient).mockRejectedValue(
223
- new Error("Not logged in"),
224
- );
217
+ it("should bail when SDK connection fails", async () => {
218
+ const sdk = mockSdk();
219
+ vi.mocked(connectOrFail).mockResolvedValue(undefined);
225
220
  const program = buildProgram();
226
221
  await runCommand(
227
222
  program,
228
223
  "files download entity-1 record-1 attachment",
229
224
  );
230
- expect(OutputFormatter.error).toHaveBeenCalledWith(
231
- expect.objectContaining({
232
- Result: "Failure",
233
- Message: "Error connecting to Data Fabric",
234
- }),
235
- );
225
+ expect(sdk.entities.downloadAttachment).not.toHaveBeenCalled();
226
+ expect(OutputFormatter.success).not.toHaveBeenCalled();
236
227
  });
237
228
  });
238
229
 
@@ -270,18 +261,13 @@ describe("files delete", () => {
270
261
  );
271
262
  });
272
263
 
273
- it("should error when SDK connection fails on delete", async () => {
274
- vi.mocked(createDataFabricClient).mockRejectedValue(
275
- new Error("Not logged in"),
276
- );
264
+ it("should bail when SDK connection fails on delete", async () => {
265
+ const sdk = mockSdk();
266
+ vi.mocked(connectOrFail).mockResolvedValue(undefined);
277
267
  const program = buildProgram();
278
268
  await runCommand(program, "files delete entity-1 record-1 attachment");
279
- expect(OutputFormatter.error).toHaveBeenCalledWith(
280
- expect.objectContaining({
281
- Result: "Failure",
282
- Message: "Error connecting to Data Fabric",
283
- }),
284
- );
269
+ expect(sdk.entities.deleteAttachment).not.toHaveBeenCalled();
270
+ expect(OutputFormatter.success).not.toHaveBeenCalled();
285
271
  });
286
272
  });
287
273
 
@@ -10,7 +10,8 @@ import {
10
10
  import { getFileSystem } from "@uipath/filesystem";
11
11
  import type { Command } from "commander";
12
12
  import { readFileBinary } from "../utils/input";
13
- import { createDataFabricClient } from "../utils/sdk-client";
13
+ import { fail } from "../utils/output";
14
+ import { connectOrFail } from "../utils/sdk-client";
14
15
 
15
16
  interface UploadOptions {
16
17
  tenant?: string;
@@ -101,41 +102,21 @@ export const registerFilesCommand = (program: Command) => {
101
102
  options: UploadOptions,
102
103
  ) => {
103
104
  if (!options.file) {
104
- OutputFormatter.error({
105
- Result: RESULTS.Failure,
106
- Message: "A file path is required",
107
- Instructions: "Provide a file path via --file.",
108
- });
109
- processContext.exit(1);
110
- return;
105
+ return fail(
106
+ "A file path is required",
107
+ "Provide a file path via --file.",
108
+ );
111
109
  }
112
110
 
113
- const [clientError, sdk] = await catchError(
114
- createDataFabricClient(options.tenant),
115
- );
116
-
117
- if (clientError) {
118
- OutputFormatter.error({
119
- Result: RESULTS.Failure,
120
- Message: "Error connecting to Data Fabric",
121
- Instructions: await extractErrorMessage(clientError),
122
- });
123
- processContext.exit(1);
124
- return;
125
- }
111
+ const sdk = await connectOrFail(options.tenant);
112
+ if (!sdk) return;
126
113
 
127
114
  const [readError, fileContent] = await catchError(
128
115
  readFileBinary(options.file),
129
116
  );
130
117
 
131
118
  if (readError) {
132
- OutputFormatter.error({
133
- Result: RESULTS.Failure,
134
- Message: "Error reading file",
135
- Instructions: readError.message,
136
- });
137
- processContext.exit(1);
138
- return;
119
+ return fail("Error reading file", readError.message);
139
120
  }
140
121
 
141
122
  const fsInst = getFileSystem();
@@ -154,13 +135,10 @@ export const registerFilesCommand = (program: Command) => {
154
135
  );
155
136
 
156
137
  if (uploadError) {
157
- OutputFormatter.error({
158
- Result: RESULTS.Failure,
159
- Message: `Error uploading file to field '${fieldName}'`,
160
- Instructions: await extractErrorMessage(uploadError),
161
- });
162
- processContext.exit(1);
163
- return;
138
+ return fail(
139
+ `Error uploading file to field '${fieldName}'`,
140
+ await extractErrorMessage(uploadError),
141
+ );
164
142
  }
165
143
 
166
144
  OutputFormatter.success({
@@ -198,19 +176,8 @@ export const registerFilesCommand = (program: Command) => {
198
176
  fieldName: string,
199
177
  options: DownloadOptions,
200
178
  ) => {
201
- const [clientError, sdk] = await catchError(
202
- createDataFabricClient(options.tenant),
203
- );
204
-
205
- if (clientError) {
206
- OutputFormatter.error({
207
- Result: RESULTS.Failure,
208
- Message: "Error connecting to Data Fabric",
209
- Instructions: await extractErrorMessage(clientError),
210
- });
211
- processContext.exit(1);
212
- return;
213
- }
179
+ const sdk = await connectOrFail(options.tenant);
180
+ if (!sdk) return;
214
181
 
215
182
  const [downloadError, blob] = await catchError(
216
183
  sdk.entities.downloadAttachment(
@@ -221,13 +188,10 @@ export const registerFilesCommand = (program: Command) => {
221
188
  );
222
189
 
223
190
  if (downloadError) {
224
- OutputFormatter.error({
225
- Result: RESULTS.Failure,
226
- Message: `Error downloading file from field '${fieldName}'`,
227
- Instructions: await extractErrorMessage(downloadError),
228
- });
229
- processContext.exit(1);
230
- return;
191
+ return fail(
192
+ `Error downloading file from field '${fieldName}'`,
193
+ await extractErrorMessage(downloadError),
194
+ );
231
195
  }
232
196
 
233
197
  const outputPath =
@@ -238,13 +202,10 @@ export const registerFilesCommand = (program: Command) => {
238
202
  );
239
203
 
240
204
  if (bufferError) {
241
- OutputFormatter.error({
242
- Result: RESULTS.Failure,
243
- Message: "Error reading downloaded file content",
244
- Instructions: bufferError.message,
245
- });
246
- processContext.exit(1);
247
- return;
205
+ return fail(
206
+ "Error reading downloaded file content",
207
+ bufferError.message,
208
+ );
248
209
  }
249
210
 
250
211
  const [writeError] = await catchError(
@@ -252,13 +213,10 @@ export const registerFilesCommand = (program: Command) => {
252
213
  );
253
214
 
254
215
  if (writeError) {
255
- OutputFormatter.error({
256
- Result: RESULTS.Failure,
257
- Message: "Error writing downloaded file",
258
- Instructions: writeError.message,
259
- });
260
- processContext.exit(1);
261
- return;
216
+ return fail(
217
+ "Error writing downloaded file",
218
+ writeError.message,
219
+ );
262
220
  }
263
221
 
264
222
  OutputFormatter.success({
@@ -292,19 +250,8 @@ export const registerFilesCommand = (program: Command) => {
292
250
  fieldName: string,
293
251
  options: DeleteOptions,
294
252
  ) => {
295
- const [clientError, sdk] = await catchError(
296
- createDataFabricClient(options.tenant),
297
- );
298
-
299
- if (clientError) {
300
- OutputFormatter.error({
301
- Result: RESULTS.Failure,
302
- Message: "Error connecting to Data Fabric",
303
- Instructions: await extractErrorMessage(clientError),
304
- });
305
- processContext.exit(1);
306
- return;
307
- }
253
+ const sdk = await connectOrFail(options.tenant);
254
+ if (!sdk) return;
308
255
 
309
256
  const [deleteError] = await catchError(
310
257
  sdk.entities.deleteAttachment(
@@ -315,13 +262,10 @@ export const registerFilesCommand = (program: Command) => {
315
262
  );
316
263
 
317
264
  if (deleteError) {
318
- OutputFormatter.error({
319
- Result: RESULTS.Failure,
320
- Message: `Error deleting file from field '${fieldName}'`,
321
- Instructions: await extractErrorMessage(deleteError),
322
- });
323
- processContext.exit(1);
324
- return;
265
+ return fail(
266
+ `Error deleting file from field '${fieldName}'`,
267
+ await extractErrorMessage(deleteError),
268
+ );
325
269
  }
326
270
 
327
271
  OutputFormatter.success({