@uniformdev/cli 20.75.1-alpha.0 → 20.75.1-alpha.11

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/dist/index.mjs +164 -66
  2. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -2741,9 +2741,32 @@ var writeResponseBodyToFile = async (response, filePath) => {
2741
2741
  throw error;
2742
2742
  }
2743
2743
  };
2744
+ var getFileMetadata = async ({
2745
+ fileClient,
2746
+ fileId,
2747
+ fileUrl
2748
+ }) => {
2749
+ if (fileId) {
2750
+ const fileById = await fileClient.get({ id: fileId }).catch(() => null);
2751
+ if (fileById) {
2752
+ return fileById;
2753
+ }
2754
+ }
2755
+ return fileClient.get({ url: fileUrl }).catch(() => null);
2756
+ };
2757
+ var logDownloadFailure = ({
2758
+ fileUrl,
2759
+ filePath,
2760
+ status
2761
+ }) => {
2762
+ console.warn(
2763
+ `Failed to download file ${fileUrl} (HTTP status: ${status}; expected local path: ${filePath})`
2764
+ );
2765
+ };
2744
2766
  var downloadFile = async ({
2745
2767
  fileClient,
2746
2768
  fileUrl,
2769
+ fileId,
2747
2770
  directory
2748
2771
  }) => {
2749
2772
  const writeDirectory = getFilesDirectory(directory);
@@ -2752,14 +2775,10 @@ var downloadFile = async ({
2752
2775
  const filePath = join10(filesDirectory, fileName);
2753
2776
  const fileAlreadyExists = await fsj2.existsAsync(filePath);
2754
2777
  if (fileAlreadyExists) {
2755
- return { url: fileUrl };
2756
- }
2757
- const file = await fileClient.get({ url: fileUrl }).catch(() => null);
2758
- if (!file) {
2759
- console.warn(`Skipping file ${fileUrl} as it does not exist in the project anymore`);
2760
- return null;
2778
+ return { id: fileId, url: fileUrl };
2761
2779
  }
2762
- if (file.sourceId) {
2780
+ const file = await getFileMetadata({ fileClient, fileId, fileUrl });
2781
+ if (file?.sourceId) {
2763
2782
  const sourceId = file.sourceId;
2764
2783
  try {
2765
2784
  const downloadedFilePaths = await getDownloadedFilePathCache(filesDirectory);
@@ -2770,17 +2789,36 @@ var downloadFile = async ({
2770
2789
  }
2771
2790
  }
2772
2791
  const fetchUrl = `${fileUrl}?format=original`;
2773
- const response = await fetch(fetchUrl);
2792
+ const preserveWarningOnlyFailure = !file;
2793
+ let response;
2794
+ try {
2795
+ response = await fetch(fetchUrl);
2796
+ } catch (error) {
2797
+ logDownloadFailure({ fileUrl, filePath, status: "unavailable" });
2798
+ if (preserveWarningOnlyFailure) {
2799
+ return null;
2800
+ }
2801
+ throw error;
2802
+ }
2774
2803
  if (!response.ok) {
2804
+ logDownloadFailure({ fileUrl, filePath, status: response.status });
2775
2805
  return null;
2776
2806
  }
2777
- await writeResponseBodyToFile(response, filePath);
2807
+ try {
2808
+ await writeResponseBodyToFile(response, filePath);
2809
+ } catch (error) {
2810
+ logDownloadFailure({ fileUrl, filePath, status: response.status });
2811
+ if (preserveWarningOnlyFailure) {
2812
+ return null;
2813
+ }
2814
+ throw error;
2815
+ }
2778
2816
  const downloadedFilePathCache = downloadedFilePathCacheByDirectory.get(filesDirectory);
2779
2817
  if (downloadedFilePathCache) {
2780
2818
  const downloadedFilePaths = await downloadedFilePathCache;
2781
2819
  downloadedFilePaths.add(fileName);
2782
2820
  }
2783
- return { id: file.id, url: fileUrl };
2821
+ return { id: file?.id ?? fileId, url: fileUrl };
2784
2822
  };
2785
2823
 
2786
2824
  // src/files/uploadFile.ts
@@ -2799,7 +2837,8 @@ var uploadFile = async ({
2799
2837
  fileClient,
2800
2838
  fileUrl,
2801
2839
  directory,
2802
- fileId
2840
+ fileId,
2841
+ warnIfLocalCopyMissing = true
2803
2842
  }) => {
2804
2843
  const key = `${fileId}-${fileUrl}`;
2805
2844
  if (uploadQueueByKey.has(key)) {
@@ -2822,9 +2861,11 @@ var uploadFile = async ({
2822
2861
  const expectedFilePath = join11(writeDirectory, FILES_DIRECTORY_NAME, localFileName);
2823
2862
  const fileInspect = await fsj3.inspectAsync(expectedFilePath);
2824
2863
  if (fileInspect?.type !== "file") {
2825
- console.warn(
2826
- `Skipping file ${fileUrl} as we couldn't find a local copy (looked at ${expectedFilePath})`
2827
- );
2864
+ if (warnIfLocalCopyMissing) {
2865
+ console.warn(
2866
+ `Skipping file ${fileUrl} as we couldn't find a local copy (looked at ${expectedFilePath})`
2867
+ );
2868
+ }
2828
2869
  return null;
2829
2870
  }
2830
2871
  const fileName = getFileNameFromUrl(fileUrl);
@@ -2985,27 +3026,37 @@ var downloadFileForAsset = async ({
2985
3026
  directory,
2986
3027
  fileClient
2987
3028
  }) => {
2988
- if (asset.asset.fields?.file?.value === void 0 || asset.asset.fields.url?.value === void 0) {
3029
+ const fields = asset.asset.fields;
3030
+ if (!fields) {
2989
3031
  return null;
2990
3032
  }
2991
- const fileId = asset.asset.fields?.file?.value;
2992
- const fileUrl = asset.asset.fields.url?.value;
2993
- if (fileId === "" || fileUrl === "") {
3033
+ const fileId = fields.file?.value;
3034
+ if (!fileId) {
2994
3035
  return null;
2995
3036
  }
2996
- return downloadFile({ fileUrl, directory, fileClient });
3037
+ const fileUrl = fields.url?.value;
3038
+ if (!fileUrl) {
3039
+ return null;
3040
+ }
3041
+ return downloadFile({ fileUrl, fileId, directory, fileClient });
2997
3042
  };
2998
3043
  var uploadFileForAsset = async ({
2999
3044
  asset,
3000
3045
  directory,
3001
3046
  fileClient
3002
3047
  }) => {
3003
- if (asset.asset.fields?.file?.value === void 0 || asset.asset.fields.url?.value === void 0) {
3048
+ const fileId = asset.asset.fields?.file?.value;
3049
+ const fileUrl = asset.asset.fields?.url?.value;
3050
+ if (fileId === void 0 || !fileUrl) {
3004
3051
  return null;
3005
3052
  }
3006
- const fileUrl = asset.asset.fields.url.value;
3007
- const fileId = asset.asset.fields.file.value;
3008
- return uploadFile({ fileUrl, directory, fileClient, fileId });
3053
+ return uploadFile({
3054
+ fileUrl,
3055
+ directory,
3056
+ fileClient,
3057
+ fileId,
3058
+ warnIfLocalCopyMissing: false
3059
+ });
3009
3060
  };
3010
3061
  var removeUrlsFromAssetParameters = (entity) => {
3011
3062
  const treeWalker = ({ node }) => {
@@ -3307,6 +3358,25 @@ function writeCanvasPackage(filename, packageContents) {
3307
3358
 
3308
3359
  // src/commands/canvas/commands/asset/pull.ts
3309
3360
  var ASSET_PULL_ACTION_CONCURRENCY = 10;
3361
+ var prepareAssetForPull = async ({
3362
+ sourceObject,
3363
+ directory,
3364
+ fileClient
3365
+ }) => {
3366
+ delete sourceObject.object.asset._author;
3367
+ if (!sourceObject.object.asset.fields?.file) {
3368
+ return sourceObject;
3369
+ }
3370
+ const downloadedFile = await downloadFileForAsset({
3371
+ asset: sourceObject.object,
3372
+ directory,
3373
+ fileClient
3374
+ });
3375
+ if (downloadedFile?.id) {
3376
+ sourceObject.object.asset.fields.file.value = downloadedFile.id;
3377
+ }
3378
+ return sourceObject;
3379
+ };
3310
3380
  var AssetPullModule = {
3311
3381
  command: "pull <directory>",
3312
3382
  describe: "Pulls all assets to local files in a directory",
@@ -3413,27 +3483,70 @@ var AssetPullModule = {
3413
3483
  return sourceObject;
3414
3484
  },
3415
3485
  compareContents: compareAssetsWithoutUrls,
3416
- onBeforeWriteObject: async (sourceObject) => {
3417
- delete sourceObject.object.asset._author;
3418
- if (!sourceObject.object.asset.fields?.file) {
3419
- return sourceObject;
3420
- }
3421
- const downloadedFile = await downloadFileForAsset({
3422
- asset: sourceObject.object,
3423
- directory,
3424
- fileClient
3425
- });
3426
- if (downloadedFile?.id) {
3427
- sourceObject.object.asset.fields.file.value = downloadedFile.id;
3428
- }
3429
- return sourceObject;
3430
- }
3486
+ onBeforeWriteObject: (sourceObject) => prepareAssetForPull({
3487
+ sourceObject,
3488
+ directory,
3489
+ fileClient
3490
+ })
3431
3491
  });
3432
3492
  }
3433
3493
  };
3434
3494
 
3435
3495
  // src/commands/canvas/commands/asset/push.ts
3496
+ import { join as join13 } from "path";
3436
3497
  var ASSET_PUSH_ACTION_CONCURRENCY = 10;
3498
+ var getExpectedFilePath = (directory, fileUrl) => {
3499
+ if (!fileUrl) {
3500
+ return "Unavailable because the asset has no file URL";
3501
+ }
3502
+ try {
3503
+ return join13(getFilesDirectory(directory), FILES_DIRECTORY_NAME, urlToFileName(fileUrl));
3504
+ } catch {
3505
+ return "Unavailable because the asset file URL is invalid";
3506
+ }
3507
+ };
3508
+ var prepareAssetForPush = async ({
3509
+ sourceObject,
3510
+ directory,
3511
+ fileClient,
3512
+ targetProjectId
3513
+ }) => {
3514
+ const fields = sourceObject.object.asset.fields;
3515
+ const fileId = fields?.file?.value;
3516
+ if (!fields || !fileId) {
3517
+ return sourceObject;
3518
+ }
3519
+ const uploadedFile = await uploadFileForAsset({
3520
+ asset: sourceObject.object,
3521
+ directory,
3522
+ fileClient
3523
+ });
3524
+ if (!uploadedFile) {
3525
+ const assetId = sourceObject.object.asset._id;
3526
+ const fileUrl = fields.url?.value;
3527
+ const expectedFilePath = getExpectedFilePath(directory, fileUrl);
3528
+ throw new Error(
3529
+ [
3530
+ `Unable to push asset "${sourceObject.displayName ?? assetId}" (${assetId}) because its file could not be uploaded.`,
3531
+ `Source project ID: ${sourceObject.object.projectId ?? "Unavailable"}`,
3532
+ `Target project ID: ${targetProjectId}`,
3533
+ `File ID: ${fileId}`,
3534
+ `File URL: ${fileUrl || "Missing"}`,
3535
+ `Expected local path: ${expectedFilePath}`,
3536
+ `Remove the asset with the ID ${assetId} before pushing again.`
3537
+ ].join("\n")
3538
+ );
3539
+ }
3540
+ fields.file = {
3541
+ type: "file",
3542
+ value: uploadedFile.id
3543
+ };
3544
+ fields.url = {
3545
+ type: "text",
3546
+ value: uploadedFile.url
3547
+ };
3548
+ return sourceObject;
3549
+ };
3437
3550
  var AssetPushModule = {
3438
3551
  command: "push <directory>",
3439
3552
  describe: "Pushes all assets from files in a directory to Uniform",
@@ -3519,27 +3632,12 @@ var AssetPushModule = {
3519
3632
  return sourceObject;
3520
3633
  },
3521
3634
  compareContents: compareAssetsWithoutUrls,
3522
- onBeforeWriteObject: async (sourceObject) => {
3523
- const uploadedFile = await uploadFileForAsset({
3524
- asset: sourceObject.object,
3525
- directory,
3526
- fileClient
3527
- });
3528
- if (uploadedFile !== null) {
3529
- if (sourceObject.object.asset.fields === void 0) {
3530
- sourceObject.object.asset.fields = {};
3531
- }
3532
- sourceObject.object.asset.fields.file = {
3533
- type: "file",
3534
- value: uploadedFile.id
3535
- };
3536
- sourceObject.object.asset.fields.url = {
3537
- type: "text",
3538
- value: uploadedFile.url
3539
- };
3540
- }
3541
- return sourceObject;
3542
- }
3635
+ onBeforeWriteObject: (sourceObject) => prepareAssetForPush({
3636
+ sourceObject,
3637
+ directory,
3638
+ fileClient,
3639
+ targetProjectId: projectId
3640
+ })
3543
3641
  });
3544
3642
  }
3545
3643
  };
@@ -12069,7 +12167,7 @@ var PolicyDocumentsPullModule = {
12069
12167
  // src/commands/policy-documents/commands/push.ts
12070
12168
  import { existsSync as existsSync8, mkdirSync as mkdirSync4 } from "fs";
12071
12169
  import { readdir as readdir2 } from "fs/promises";
12072
- import { extname as extname3, join as join13 } from "path";
12170
+ import { extname as extname3, join as join14 } from "path";
12073
12171
  async function readLocalPolicyDocuments(directory, format, verbose) {
12074
12172
  const files = await readdir2(directory);
12075
12173
  const policyDocuments = {};
@@ -12079,7 +12177,7 @@ async function readLocalPolicyDocuments(directory, format, verbose) {
12079
12177
  if (ext !== `.${format}` && ext !== ".yaml" && ext !== ".yml" && ext !== ".json") {
12080
12178
  continue;
12081
12179
  }
12082
- const filePath = join13(directory, filename);
12180
+ const filePath = join14(directory, filename);
12083
12181
  try {
12084
12182
  let roleId = filename.replace(ext, "");
12085
12183
  const fileContent = readFileToObject(filePath);
@@ -14087,14 +14185,14 @@ import { existsSync as existsSync9, promises as fs8 } from "fs";
14087
14185
  import { get as getHttp } from "http";
14088
14186
  import { get as getHttps } from "https";
14089
14187
  import { tmpdir as tmpdir2 } from "os";
14090
- import { join as join14 } from "path";
14188
+ import { join as join15 } from "path";
14091
14189
  import registryUrl from "registry-url";
14092
14190
  import { URL as URL2 } from "url";
14093
14191
  var compareVersions = (a, b) => a.localeCompare(b, "en-US", { numeric: true });
14094
14192
  var encode = (value) => encodeURIComponent(value).replace(/^%40/, "@");
14095
14193
  var getFile = async (details, distTag) => {
14096
14194
  const rootDir = tmpdir2();
14097
- const subDir = join14(rootDir, "update-check");
14195
+ const subDir = join15(rootDir, "update-check");
14098
14196
  if (!existsSync9(subDir)) {
14099
14197
  await fs8.mkdir(subDir);
14100
14198
  }
@@ -14102,7 +14200,7 @@ var getFile = async (details, distTag) => {
14102
14200
  if (details.scope) {
14103
14201
  name = `${details.scope}-${name}`;
14104
14202
  }
14105
- return join14(subDir, name);
14203
+ return join15(subDir, name);
14106
14204
  };
14107
14205
  var evaluateCache = async (file, time, interval) => {
14108
14206
  if (existsSync9(file)) {
@@ -14257,7 +14355,7 @@ var checkForUpdateMiddleware = async ({ verbose }) => {
14257
14355
 
14258
14356
  // src/middleware/checkLocalDepsVersionsMiddleware.ts
14259
14357
  import { magenta, red as red8 } from "colorette";
14260
- import { join as join15 } from "path";
14358
+ import { join as join16 } from "path";
14261
14359
  var uniformStrictVersions = [
14262
14360
  "@uniformdev/canvas",
14263
14361
  "@uniformdev/canvas-next",
@@ -14279,7 +14377,7 @@ var checkLocalDepsVersions = async (args) => {
14279
14377
  try {
14280
14378
  let isOutside = false;
14281
14379
  let warning = `${magenta("Warning:")} Installed Uniform packages should be the same version`;
14282
- const localPackages = await tryReadJSON(join15(process.cwd(), "package.json"));
14380
+ const localPackages = await tryReadJSON(join16(process.cwd(), "package.json"));
14283
14381
  if (!localPackages) return;
14284
14382
  let firstVersion;
14285
14383
  const allDependencies = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "20.75.1-alpha.0+effbce0886",
3
+ "version": "20.75.1-alpha.11+745b427b33",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -27,14 +27,14 @@
27
27
  "dependencies": {
28
28
  "@inquirer/prompts": "^8.5.2",
29
29
  "@thi.ng/mime": "^2.2.23",
30
- "@uniformdev/assets": "20.75.1-alpha.0+effbce0886",
31
- "@uniformdev/automations-sdk": "20.75.1-alpha.0+effbce0886",
32
- "@uniformdev/canvas": "20.75.1-alpha.0+effbce0886",
33
- "@uniformdev/context": "20.75.1-alpha.0+effbce0886",
34
- "@uniformdev/files": "20.75.1-alpha.0+effbce0886",
35
- "@uniformdev/project-map": "20.75.1-alpha.0+effbce0886",
36
- "@uniformdev/redirect": "20.75.1-alpha.0+effbce0886",
37
- "@uniformdev/richtext": "20.75.1-alpha.0+effbce0886",
30
+ "@uniformdev/assets": "20.75.1-alpha.11+745b427b33",
31
+ "@uniformdev/automations-sdk": "20.75.1-alpha.11+745b427b33",
32
+ "@uniformdev/canvas": "20.75.1-alpha.11+745b427b33",
33
+ "@uniformdev/context": "20.75.1-alpha.11+745b427b33",
34
+ "@uniformdev/files": "20.75.1-alpha.11+745b427b33",
35
+ "@uniformdev/project-map": "20.75.1-alpha.11+745b427b33",
36
+ "@uniformdev/redirect": "20.75.1-alpha.11+745b427b33",
37
+ "@uniformdev/richtext": "20.75.1-alpha.11+745b427b33",
38
38
  "call-bind": "^1.0.2",
39
39
  "colorette": "2.0.20",
40
40
  "cosmiconfig": "9.0.2",
@@ -78,5 +78,5 @@
78
78
  "publishConfig": {
79
79
  "access": "public"
80
80
  },
81
- "gitHead": "effbce0886d68a0e9a4f9b492b5f263eafa73813"
81
+ "gitHead": "745b427b339b7cae41df5381eeb6d49c733f4ce1"
82
82
  }