@uipath/data-fabric-tool 1.0.4 → 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
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type CommandExample,
3
3
  catchError,
4
+ createHiddenDeprecatedTenantOption,
4
5
  extractErrorMessage,
5
6
  OutputFormatter,
6
7
  processContext,
@@ -9,7 +10,8 @@ import {
9
10
  import { getFileSystem } from "@uipath/filesystem";
10
11
  import type { Command } from "commander";
11
12
  import { readFileBinary } from "../utils/input";
12
- import { createDataFabricClient } from "../utils/sdk-client";
13
+ import { fail } from "../utils/output";
14
+ import { connectOrFail } from "../utils/sdk-client";
13
15
 
14
16
  interface UploadOptions {
15
17
  tenant?: string;
@@ -86,7 +88,9 @@ export const registerFilesCommand = (program: Command) => {
86
88
  .argument("<entity-id>", "Entity ID")
87
89
  .argument("<record-id>", "Record ID")
88
90
  .argument("<field-name>", "Name of the file field (case-sensitive)")
89
- .option("-t, --tenant <tenant-name>", "Tenant name")
91
+ .addOption(
92
+ createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
93
+ )
90
94
  .option("-f, --file <path>", "Path to the file to upload")
91
95
  .examples(FILES_UPLOAD_EXAMPLES)
92
96
  .trackedAction(
@@ -98,41 +102,21 @@ export const registerFilesCommand = (program: Command) => {
98
102
  options: UploadOptions,
99
103
  ) => {
100
104
  if (!options.file) {
101
- OutputFormatter.error({
102
- Result: RESULTS.Failure,
103
- Message: "A file path is required",
104
- Instructions: "Provide a file path via --file.",
105
- });
106
- processContext.exit(1);
107
- return;
105
+ return fail(
106
+ "A file path is required",
107
+ "Provide a file path via --file.",
108
+ );
108
109
  }
109
110
 
110
- const [clientError, sdk] = await catchError(
111
- createDataFabricClient(options.tenant),
112
- );
113
-
114
- if (clientError) {
115
- OutputFormatter.error({
116
- Result: RESULTS.Failure,
117
- Message: "Error connecting to Data Fabric",
118
- Instructions: await extractErrorMessage(clientError),
119
- });
120
- processContext.exit(1);
121
- return;
122
- }
111
+ const sdk = await connectOrFail(options.tenant);
112
+ if (!sdk) return;
123
113
 
124
114
  const [readError, fileContent] = await catchError(
125
115
  readFileBinary(options.file),
126
116
  );
127
117
 
128
118
  if (readError) {
129
- OutputFormatter.error({
130
- Result: RESULTS.Failure,
131
- Message: "Error reading file",
132
- Instructions: readError.message,
133
- });
134
- processContext.exit(1);
135
- return;
119
+ return fail("Error reading file", readError.message);
136
120
  }
137
121
 
138
122
  const fsInst = getFileSystem();
@@ -151,13 +135,10 @@ export const registerFilesCommand = (program: Command) => {
151
135
  );
152
136
 
153
137
  if (uploadError) {
154
- OutputFormatter.error({
155
- Result: RESULTS.Failure,
156
- Message: `Error uploading file to field '${fieldName}'`,
157
- Instructions: await extractErrorMessage(uploadError),
158
- });
159
- processContext.exit(1);
160
- return;
138
+ return fail(
139
+ `Error uploading file to field '${fieldName}'`,
140
+ await extractErrorMessage(uploadError),
141
+ );
161
142
  }
162
143
 
163
144
  OutputFormatter.success({
@@ -179,7 +160,9 @@ export const registerFilesCommand = (program: Command) => {
179
160
  .argument("<entity-id>", "Entity ID")
180
161
  .argument("<record-id>", "Record ID")
181
162
  .argument("<field-name>", "Name of the file field (case-sensitive)")
182
- .option("-t, --tenant <tenant-name>", "Tenant name")
163
+ .addOption(
164
+ createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
165
+ )
183
166
  .option(
184
167
  "--destination <path>",
185
168
  "Output file path (defaults to <record-id>_<field-name>.bin)",
@@ -193,19 +176,8 @@ export const registerFilesCommand = (program: Command) => {
193
176
  fieldName: string,
194
177
  options: DownloadOptions,
195
178
  ) => {
196
- const [clientError, sdk] = await catchError(
197
- createDataFabricClient(options.tenant),
198
- );
199
-
200
- if (clientError) {
201
- OutputFormatter.error({
202
- Result: RESULTS.Failure,
203
- Message: "Error connecting to Data Fabric",
204
- Instructions: await extractErrorMessage(clientError),
205
- });
206
- processContext.exit(1);
207
- return;
208
- }
179
+ const sdk = await connectOrFail(options.tenant);
180
+ if (!sdk) return;
209
181
 
210
182
  const [downloadError, blob] = await catchError(
211
183
  sdk.entities.downloadAttachment(
@@ -216,13 +188,10 @@ export const registerFilesCommand = (program: Command) => {
216
188
  );
217
189
 
218
190
  if (downloadError) {
219
- OutputFormatter.error({
220
- Result: RESULTS.Failure,
221
- Message: `Error downloading file from field '${fieldName}'`,
222
- Instructions: await extractErrorMessage(downloadError),
223
- });
224
- processContext.exit(1);
225
- return;
191
+ return fail(
192
+ `Error downloading file from field '${fieldName}'`,
193
+ await extractErrorMessage(downloadError),
194
+ );
226
195
  }
227
196
 
228
197
  const outputPath =
@@ -233,13 +202,10 @@ export const registerFilesCommand = (program: Command) => {
233
202
  );
234
203
 
235
204
  if (bufferError) {
236
- OutputFormatter.error({
237
- Result: RESULTS.Failure,
238
- Message: "Error reading downloaded file content",
239
- Instructions: bufferError.message,
240
- });
241
- processContext.exit(1);
242
- return;
205
+ return fail(
206
+ "Error reading downloaded file content",
207
+ bufferError.message,
208
+ );
243
209
  }
244
210
 
245
211
  const [writeError] = await catchError(
@@ -247,13 +213,10 @@ export const registerFilesCommand = (program: Command) => {
247
213
  );
248
214
 
249
215
  if (writeError) {
250
- OutputFormatter.error({
251
- Result: RESULTS.Failure,
252
- Message: "Error writing downloaded file",
253
- Instructions: writeError.message,
254
- });
255
- processContext.exit(1);
256
- return;
216
+ return fail(
217
+ "Error writing downloaded file",
218
+ writeError.message,
219
+ );
257
220
  }
258
221
 
259
222
  OutputFormatter.success({
@@ -275,7 +238,9 @@ export const registerFilesCommand = (program: Command) => {
275
238
  .argument("<entity-id>", "Entity ID")
276
239
  .argument("<record-id>", "Record ID")
277
240
  .argument("<field-name>", "Name of the file field (case-sensitive)")
278
- .option("-t, --tenant <tenant-name>", "Tenant name")
241
+ .addOption(
242
+ createHiddenDeprecatedTenantOption("-t, --tenant <tenant-name>"),
243
+ )
279
244
  .examples(FILES_DELETE_EXAMPLES)
280
245
  .trackedAction(
281
246
  processContext,
@@ -285,19 +250,8 @@ export const registerFilesCommand = (program: Command) => {
285
250
  fieldName: string,
286
251
  options: DeleteOptions,
287
252
  ) => {
288
- const [clientError, sdk] = await catchError(
289
- createDataFabricClient(options.tenant),
290
- );
291
-
292
- if (clientError) {
293
- OutputFormatter.error({
294
- Result: RESULTS.Failure,
295
- Message: "Error connecting to Data Fabric",
296
- Instructions: await extractErrorMessage(clientError),
297
- });
298
- processContext.exit(1);
299
- return;
300
- }
253
+ const sdk = await connectOrFail(options.tenant);
254
+ if (!sdk) return;
301
255
 
302
256
  const [deleteError] = await catchError(
303
257
  sdk.entities.deleteAttachment(
@@ -308,13 +262,10 @@ export const registerFilesCommand = (program: Command) => {
308
262
  );
309
263
 
310
264
  if (deleteError) {
311
- OutputFormatter.error({
312
- Result: RESULTS.Failure,
313
- Message: `Error deleting file from field '${fieldName}'`,
314
- Instructions: await extractErrorMessage(deleteError),
315
- });
316
- processContext.exit(1);
317
- return;
265
+ return fail(
266
+ `Error deleting file from field '${fieldName}'`,
267
+ await extractErrorMessage(deleteError),
268
+ );
318
269
  }
319
270
 
320
271
  OutputFormatter.success({