@valbuild/shared 0.75.5 → 0.76.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.
@@ -1719,6 +1719,200 @@ export declare const Api: {
1719
1719
  }>]>;
1720
1720
  };
1721
1721
  };
1722
+ "/upload/patches": {
1723
+ POST: {
1724
+ req: {
1725
+ path: z.ZodOptional<z.ZodString>;
1726
+ body: z.ZodObject<{
1727
+ parentRef: z.ZodUnion<[z.ZodObject<{
1728
+ type: z.ZodLiteral<"head">;
1729
+ headBaseSha: z.ZodString;
1730
+ }, "strip", z.ZodTypeAny, {
1731
+ type: "head";
1732
+ headBaseSha: string;
1733
+ }, {
1734
+ type: "head";
1735
+ headBaseSha: string;
1736
+ }>, z.ZodObject<{
1737
+ type: z.ZodLiteral<"patch">;
1738
+ patchId: z.ZodEffects<z.ZodString, PatchIdT, string>;
1739
+ }, "strip", z.ZodTypeAny, {
1740
+ type: "patch";
1741
+ patchId?: any;
1742
+ }, {
1743
+ type: "patch";
1744
+ patchId: string;
1745
+ }>]>;
1746
+ filePath: z.ZodString;
1747
+ data: z.ZodAny;
1748
+ type: z.ZodUnion<[z.ZodLiteral<"file">, z.ZodLiteral<"image">]>;
1749
+ metadata: z.ZodAny;
1750
+ remote: z.ZodBoolean;
1751
+ }, "strip", z.ZodTypeAny, {
1752
+ type: "file" | "image";
1753
+ parentRef: {
1754
+ type: "head";
1755
+ headBaseSha: string;
1756
+ } | {
1757
+ type: "patch";
1758
+ patchId?: any;
1759
+ };
1760
+ filePath: string;
1761
+ remote: boolean;
1762
+ data?: any;
1763
+ metadata?: any;
1764
+ }, {
1765
+ type: "file" | "image";
1766
+ parentRef: {
1767
+ type: "head";
1768
+ headBaseSha: string;
1769
+ } | {
1770
+ type: "patch";
1771
+ patchId: string;
1772
+ };
1773
+ filePath: string;
1774
+ remote: boolean;
1775
+ data?: any;
1776
+ metadata?: any;
1777
+ }>;
1778
+ };
1779
+ res: z.ZodUnion<[z.ZodObject<{
1780
+ status: z.ZodLiteral<400>;
1781
+ json: z.ZodObject<{
1782
+ message: z.ZodString;
1783
+ }, "strip", z.ZodTypeAny, {
1784
+ message: string;
1785
+ }, {
1786
+ message: string;
1787
+ }>;
1788
+ }, "strip", z.ZodTypeAny, {
1789
+ status: 400;
1790
+ json: {
1791
+ message: string;
1792
+ };
1793
+ }, {
1794
+ status: 400;
1795
+ json: {
1796
+ message: string;
1797
+ };
1798
+ }>, z.ZodObject<{
1799
+ status: z.ZodLiteral<200>;
1800
+ json: z.ZodObject<{
1801
+ filePath: z.ZodString;
1802
+ patchId: z.ZodEffects<z.ZodString, PatchIdT, string>;
1803
+ }, "strip", z.ZodTypeAny, {
1804
+ filePath: string;
1805
+ patchId?: any;
1806
+ }, {
1807
+ patchId: string;
1808
+ filePath: string;
1809
+ }>;
1810
+ }, "strip", z.ZodTypeAny, {
1811
+ status: 200;
1812
+ json: {
1813
+ filePath: string;
1814
+ patchId?: any;
1815
+ };
1816
+ }, {
1817
+ status: 200;
1818
+ json: {
1819
+ patchId: string;
1820
+ filePath: string;
1821
+ };
1822
+ }>]>;
1823
+ };
1824
+ };
1825
+ "/direct-file-upload-settings": {
1826
+ POST: {
1827
+ req: {
1828
+ cookies: {
1829
+ val_session: z.ZodOptional<z.ZodString>;
1830
+ };
1831
+ };
1832
+ res: z.ZodUnion<[z.ZodObject<{
1833
+ status: z.ZodLiteral<400>;
1834
+ json: z.ZodObject<{
1835
+ message: z.ZodString;
1836
+ }, "strip", z.ZodTypeAny, {
1837
+ message: string;
1838
+ }, {
1839
+ message: string;
1840
+ }>;
1841
+ }, "strip", z.ZodTypeAny, {
1842
+ status: 400;
1843
+ json: {
1844
+ message: string;
1845
+ };
1846
+ }, {
1847
+ status: 400;
1848
+ json: {
1849
+ message: string;
1850
+ };
1851
+ }>, z.ZodObject<{
1852
+ status: z.ZodLiteral<401>;
1853
+ json: z.ZodObject<{
1854
+ message: z.ZodString;
1855
+ }, "strip", z.ZodTypeAny, {
1856
+ message: string;
1857
+ }, {
1858
+ message: string;
1859
+ }>;
1860
+ }, "strip", z.ZodTypeAny, {
1861
+ status: 401;
1862
+ json: {
1863
+ message: string;
1864
+ };
1865
+ }, {
1866
+ status: 401;
1867
+ json: {
1868
+ message: string;
1869
+ };
1870
+ }>, z.ZodObject<{
1871
+ status: z.ZodLiteral<500>;
1872
+ json: z.ZodObject<{
1873
+ message: z.ZodString;
1874
+ }, "strip", z.ZodTypeAny, {
1875
+ message: string;
1876
+ }, {
1877
+ message: string;
1878
+ }>;
1879
+ }, "strip", z.ZodTypeAny, {
1880
+ status: 500;
1881
+ json: {
1882
+ message: string;
1883
+ };
1884
+ }, {
1885
+ status: 500;
1886
+ json: {
1887
+ message: string;
1888
+ };
1889
+ }>, z.ZodObject<{
1890
+ status: z.ZodLiteral<200>;
1891
+ json: z.ZodObject<{
1892
+ nonce: z.ZodNullable<z.ZodString>;
1893
+ baseUrl: z.ZodString;
1894
+ }, "strip", z.ZodTypeAny, {
1895
+ nonce: string | null;
1896
+ baseUrl: string;
1897
+ }, {
1898
+ nonce: string | null;
1899
+ baseUrl: string;
1900
+ }>;
1901
+ }, "strip", z.ZodTypeAny, {
1902
+ status: 200;
1903
+ json: {
1904
+ nonce: string | null;
1905
+ baseUrl: string;
1906
+ };
1907
+ }, {
1908
+ status: 200;
1909
+ json: {
1910
+ nonce: string | null;
1911
+ baseUrl: string;
1912
+ };
1913
+ }>]>;
1914
+ };
1915
+ };
1722
1916
  "/patches": {
1723
1917
  DELETE: {
1724
1918
  req: {
@@ -1853,8 +2047,8 @@ export declare const Api: {
1853
2047
  patch: z.ZodType<PatchT, z.ZodTypeDef, PatchT>;
1854
2048
  }, "strip", z.ZodTypeAny, {
1855
2049
  path?: any;
1856
- patchId?: any;
1857
2050
  patch?: any;
2051
+ patchId?: any;
1858
2052
  }, {
1859
2053
  path: string;
1860
2054
  patchId: string;
@@ -1863,8 +2057,8 @@ export declare const Api: {
1863
2057
  }, "strip", z.ZodTypeAny, {
1864
2058
  patches: {
1865
2059
  path?: any;
1866
- patchId?: any;
1867
2060
  patch?: any;
2061
+ patchId?: any;
1868
2062
  }[];
1869
2063
  parentRef: {
1870
2064
  type: "head";
@@ -2219,8 +2413,8 @@ export declare const Api: {
2219
2413
  commitSha: string;
2220
2414
  } | null;
2221
2415
  path?: any;
2222
- patchId?: any;
2223
2416
  patch?: any;
2417
+ patchId?: any;
2224
2418
  }, {
2225
2419
  path: string;
2226
2420
  createdAt: string;
@@ -2255,8 +2449,8 @@ export declare const Api: {
2255
2449
  commitSha: string;
2256
2450
  } | null;
2257
2451
  path?: any;
2258
- patchId?: any;
2259
2452
  patch?: any;
2453
+ patchId?: any;
2260
2454
  }[];
2261
2455
  errors?: Record<PatchIdT, {
2262
2456
  message: string;
@@ -2294,8 +2488,8 @@ export declare const Api: {
2294
2488
  commitSha: string;
2295
2489
  } | null;
2296
2490
  path?: any;
2297
- patchId?: any;
2298
2491
  patch?: any;
2492
+ patchId?: any;
2299
2493
  }[];
2300
2494
  errors?: Record<PatchIdT, {
2301
2495
  message: string;
@@ -3054,7 +3248,7 @@ export declare const Api: {
3054
3248
  status: z.ZodLiteral<400>;
3055
3249
  json: z.ZodUnion<[z.ZodObject<{
3056
3250
  message: z.ZodString;
3057
- details: z.ZodUnion<[z.ZodObject<{
3251
+ details: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
3058
3252
  sourceFilePatchErrors: z.ZodRecord<z.ZodEffects<z.ZodString, ModuleFilePath, string>, z.ZodArray<z.ZodObject<{
3059
3253
  message: z.ZodString;
3060
3254
  }, "strip", z.ZodTypeAny, {
@@ -3089,10 +3283,10 @@ export declare const Api: {
3089
3283
  message: string;
3090
3284
  }, {
3091
3285
  message: string;
3092
- }>, "many">]>;
3286
+ }>, "many">]>>;
3093
3287
  }, "strip", z.ZodTypeAny, {
3094
3288
  message: string;
3095
- details: {
3289
+ details?: {
3096
3290
  message: string;
3097
3291
  }[] | {
3098
3292
  sourceFilePatchErrors: Record<ModuleFilePath, {
@@ -3101,10 +3295,10 @@ export declare const Api: {
3101
3295
  binaryFilePatchErrors: Record<string, {
3102
3296
  message: string;
3103
3297
  }>;
3104
- };
3298
+ } | undefined;
3105
3299
  }, {
3106
3300
  message: string;
3107
- details: {
3301
+ details?: {
3108
3302
  message: string;
3109
3303
  }[] | {
3110
3304
  sourceFilePatchErrors: Record<string, {
@@ -3113,7 +3307,7 @@ export declare const Api: {
3113
3307
  binaryFilePatchErrors: Record<string, {
3114
3308
  message: string;
3115
3309
  }>;
3116
- };
3310
+ } | undefined;
3117
3311
  }>, z.ZodObject<{
3118
3312
  message: z.ZodString;
3119
3313
  errorCode: z.ZodUnion<[z.ZodLiteral<"project-not-configured">, z.ZodLiteral<"pat-error">]>;
@@ -3128,7 +3322,7 @@ export declare const Api: {
3128
3322
  status: 400;
3129
3323
  json: {
3130
3324
  message: string;
3131
- details: {
3325
+ details?: {
3132
3326
  message: string;
3133
3327
  }[] | {
3134
3328
  sourceFilePatchErrors: Record<ModuleFilePath, {
@@ -3137,7 +3331,7 @@ export declare const Api: {
3137
3331
  binaryFilePatchErrors: Record<string, {
3138
3332
  message: string;
3139
3333
  }>;
3140
- };
3334
+ } | undefined;
3141
3335
  } | {
3142
3336
  message: string;
3143
3337
  errorCode: "project-not-configured" | "pat-error";
@@ -3146,7 +3340,7 @@ export declare const Api: {
3146
3340
  status: 400;
3147
3341
  json: {
3148
3342
  message: string;
3149
- details: {
3343
+ details?: {
3150
3344
  message: string;
3151
3345
  }[] | {
3152
3346
  sourceFilePatchErrors: Record<string, {
@@ -3155,7 +3349,7 @@ export declare const Api: {
3155
3349
  binaryFilePatchErrors: Record<string, {
3156
3350
  message: string;
3157
3351
  }>;
3158
- };
3352
+ } | undefined;
3159
3353
  } | {
3160
3354
  message: string;
3161
3355
  errorCode: "project-not-configured" | "pat-error";
@@ -7,10 +7,19 @@ export type RemoteRichTextOptions = {
7
7
  schema: SerializedImageSchema;
8
8
  remoteHost: string;
9
9
  };
10
+ type RTFiles = Record<string, {
11
+ value: string;
12
+ filePathOrRef: string;
13
+ patchPaths: string[][];
14
+ metadata: {
15
+ mimeType: string;
16
+ height: number;
17
+ width: number;
18
+ alt?: string;
19
+ };
20
+ }>;
10
21
  export declare function remirrorToRichTextSource(node: RemirrorJSON, configDirectory: ConfigDirectory, remoteOptions: RemoteRichTextOptions | null): {
11
22
  blocks: RichTextSource<AllRichTextOptions>;
12
- files: Record<string, {
13
- value: string;
14
- patchPaths: string[][];
15
- }>;
23
+ files: RTFiles;
16
24
  };
25
+ export {};
@@ -294,6 +294,16 @@ function convertOrderedList(path, node, files, configDirectory, remoteOptions) {
294
294
  })) || []
295
295
  };
296
296
  }
297
+ var convertToNumber = function convertToNumber(value) {
298
+ if (value === null || value === undefined) {
299
+ return 0;
300
+ }
301
+ if (typeof value === "number") {
302
+ return value;
303
+ }
304
+ var parsedValue = parseInt(value, 10);
305
+ return isNaN(parsedValue) ? 0 : parsedValue;
306
+ };
297
307
  var textEncoder = new TextEncoder();
298
308
  function convertImageNode(path, node, files, configDirectory, remoteOptions) {
299
309
  if (node.attrs && node.attrs.src.startsWith("data:")) {
@@ -314,14 +324,6 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
314
324
  var thisPath = path
315
325
  // file is added as src (see below):
316
326
  .concat("src");
317
- if (existingFilesEntry) {
318
- existingFilesEntry.patchPaths.push(thisPath);
319
- } else {
320
- files[filePath] = {
321
- value: node.attrs.src,
322
- patchPaths: [thisPath]
323
- };
324
- }
325
327
  var remoteFileHash = core.Internal.remote.hashToRemoteFileHash(fullFileHash);
326
328
  var ref = remoteOptions ? core.Internal.remote.createRemoteRef(remoteOptions.remoteHost, _objectSpread2(_objectSpread2({}, remoteOptions), {}, {
327
329
  fileHash: remoteFileHash,
@@ -331,6 +333,21 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
331
333
  }, remoteFileHash, textEncoder),
332
334
  filePath: filePath.slice(1)
333
335
  })) : filePath;
336
+ if (existingFilesEntry) {
337
+ existingFilesEntry.patchPaths.push(thisPath);
338
+ } else {
339
+ // TODO: use ref instead on filePath?
340
+ files[filePath] = {
341
+ value: node.attrs.src,
342
+ filePathOrRef: ref,
343
+ metadata: {
344
+ height: convertToNumber(node.attrs.height),
345
+ width: convertToNumber(node.attrs.width),
346
+ mimeType: mimeType
347
+ },
348
+ patchPaths: [thisPath]
349
+ };
350
+ }
334
351
  return {
335
352
  tag: "img",
336
353
  src: _objectSpread2(_objectSpread2(_defineProperty({}, core.FILE_REF_PROP, ref), remoteOptions ? _defineProperty({}, core.VAL_EXTENSION, "remote") : _defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_SUBTYPE_TAG, "image")), {}, {
@@ -348,7 +365,14 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
348
365
  var remote = false;
349
366
  if (patchId) {
350
367
  remote = getParam("remote", url) === "true";
351
- if (noParamsUrl.startsWith("/api/val/files/public")) {
368
+ if (remote) {
369
+ var remoteRef = getParam("ref", url);
370
+ if (remoteRef) {
371
+ noParamsUrl = decodeURIComponent(remoteRef);
372
+ } else {
373
+ console.error("Remote image URL does not contain ref: " + url);
374
+ }
375
+ } else if (noParamsUrl.startsWith("/api/val/files/public")) {
352
376
  noParamsUrl = noParamsUrl.slice("/api/val/files".length);
353
377
  } else {
354
378
  console.error("Patched image URL does not start with /api/val/files: " + url);
@@ -642,7 +666,7 @@ function convertLinkNodeToRemirror(linkNode) {
642
666
  });
643
667
  }
644
668
  function convertImageNodeToRemirror(imageNode) {
645
- var _fileSource$metadata, _fileSource$metadata2;
669
+ var _fileSource$metadata, _fileSource$metadata2, _fileSource$metadata3;
646
670
  var fileSource = imageNode.src;
647
671
  if (!(core.VAL_EXTENSION in fileSource) || fileSource[core.VAL_EXTENSION] !== "file" && fileSource[core.VAL_EXTENSION] !== "remote") {
648
672
  throw Error("Expected file source in image node");
@@ -658,6 +682,7 @@ function convertImageNodeToRemirror(imageNode) {
658
682
  attrs: {
659
683
  height: (_fileSource$metadata = fileSource.metadata) === null || _fileSource$metadata === void 0 ? void 0 : _fileSource$metadata.height,
660
684
  width: (_fileSource$metadata2 = fileSource.metadata) === null || _fileSource$metadata2 === void 0 ? void 0 : _fileSource$metadata2.width,
685
+ alt: (_fileSource$metadata3 = fileSource.metadata) === null || _fileSource$metadata3 === void 0 ? void 0 : _fileSource$metadata3.alt,
661
686
  src: fileVal.url
662
687
  }
663
688
  };
@@ -1075,6 +1100,17 @@ function _asyncToGenerator(n) {
1075
1100
  var JSONValueT = zod.z.lazy(function () {
1076
1101
  return zod.z.union([zod.z.string(), zod.z.number(), zod.z["boolean"](), zod.z["null"](), zod.z.array(JSONValueT), zod.z.record(JSONValueT)]);
1077
1102
  });
1103
+ var FileOperation = function FileOperation(path) {
1104
+ return zod.z.object({
1105
+ op: zod.z.literal("file"),
1106
+ path: path,
1107
+ filePath: zod.z.string(),
1108
+ value: zod.z.string(),
1109
+ remote: zod.z["boolean"](),
1110
+ nestedFilePath: zod.z.array(zod.z.string()).optional(),
1111
+ metadata: JSONValueT.optional() // TODO: remove optional
1112
+ });
1113
+ };
1078
1114
 
1079
1115
  /**
1080
1116
  * Raw JSON patch operation.
@@ -1108,13 +1144,7 @@ var OperationJSONT = zod.z.discriminatedUnion("op", [zod.z.object({
1108
1144
  op: zod.z.literal("test"),
1109
1145
  path: zod.z.string(),
1110
1146
  value: JSONValueT
1111
- }).strict(), zod.z.object({
1112
- op: zod.z.literal("file"),
1113
- path: zod.z.string(),
1114
- filePath: zod.z.string(),
1115
- value: zod.z.string(),
1116
- remote: zod.z["boolean"]()
1117
- }).strict()]);
1147
+ }).strict(), FileOperation(zod.z.string()).strict()]);
1118
1148
  var PatchJSON = zod.z.array(OperationJSONT);
1119
1149
  /**
1120
1150
  * Raw JSON patch operation.
@@ -1142,14 +1172,7 @@ var OperationT = zod.z.discriminatedUnion("op", [zod.z.object({
1142
1172
  op: zod.z.literal("test"),
1143
1173
  path: zod.z.array(zod.z.string()),
1144
1174
  value: JSONValueT
1145
- }).strict(), zod.z.object({
1146
- op: zod.z.literal("file"),
1147
- path: zod.z.array(zod.z.string()),
1148
- filePath: zod.z.string(),
1149
- nestedFilePath: zod.z.array(zod.z.string()).optional(),
1150
- value: zod.z.string(),
1151
- remote: zod.z["boolean"]()
1152
- }).strict()]);
1175
+ }).strict(), FileOperation(zod.z.array(zod.z.string())).strict()]);
1153
1176
  var Patch = zod.z.array(OperationT);
1154
1177
  var PatchId = zod.z.string().refine(function (_id) {
1155
1178
  return true;
@@ -1721,6 +1744,59 @@ var Api = {
1721
1744
  })])
1722
1745
  }
1723
1746
  },
1747
+ // This has a path which is like this: /upload/patches/:patchId/files. Example: /upload/patches/76b9237a-7712-4d60-88b4-d273e6d6fe18/files
1748
+ "/upload/patches": {
1749
+ POST: {
1750
+ req: {
1751
+ path: zod.z.string().optional(),
1752
+ body: zod.z.object({
1753
+ parentRef: ParentRef,
1754
+ filePath: zod.z.string(),
1755
+ data: zod.z.any(),
1756
+ // TODO: Json zod type
1757
+ type: zod.z.union([zod.z.literal("file"), zod.z.literal("image")]),
1758
+ metadata: zod.z.any(),
1759
+ // TODO: Json zod type
1760
+ remote: zod.z["boolean"]()
1761
+ })
1762
+ },
1763
+ res: zod.z.union([zod.z.object({
1764
+ status: zod.z.literal(400),
1765
+ json: GenericError
1766
+ }), zod.z.object({
1767
+ status: zod.z.literal(200),
1768
+ json: zod.z.object({
1769
+ filePath: zod.z.string(),
1770
+ patchId: PatchId
1771
+ })
1772
+ })])
1773
+ }
1774
+ },
1775
+ "/direct-file-upload-settings": {
1776
+ POST: {
1777
+ req: {
1778
+ cookies: {
1779
+ val_session: zod.z.string().optional()
1780
+ }
1781
+ },
1782
+ res: zod.z.union([zod.z.object({
1783
+ status: zod.z.literal(400),
1784
+ json: GenericError
1785
+ }), zod.z.object({
1786
+ status: zod.z.literal(401),
1787
+ json: GenericError
1788
+ }), zod.z.object({
1789
+ status: zod.z.literal(500),
1790
+ json: GenericError
1791
+ }), zod.z.object({
1792
+ status: zod.z.literal(200),
1793
+ json: zod.z.object({
1794
+ nonce: zod.z.string().nullable(),
1795
+ baseUrl: zod.z.string()
1796
+ })
1797
+ })])
1798
+ }
1799
+ },
1724
1800
  "/patches": {
1725
1801
  DELETE: {
1726
1802
  req: {
@@ -1975,7 +2051,7 @@ var Api = {
1975
2051
  details: zod.z.union([zod.z.object({
1976
2052
  sourceFilePatchErrors: zod.z.record(ModuleFilePath, zod.z.array(GenericError)),
1977
2053
  binaryFilePatchErrors: zod.z.record(GenericError)
1978
- }), zod.z.array(GenericError)])
2054
+ }), zod.z.array(GenericError)]).optional()
1979
2055
  }), zod.z.object({
1980
2056
  message: zod.z.string(),
1981
2057
  errorCode: zod.z.union([zod.z.literal("project-not-configured"), zod.z.literal("pat-error")])
@@ -2174,7 +2250,7 @@ var createValClient = function createValClient(host, config // We want to use th
2174
2250
  _context.next = 12;
2175
2251
  break;
2176
2252
  }
2177
- console.log("Server responded with an error", json);
2253
+ console.error("Server responded with an error", json);
2178
2254
  return _context.abrupt("return", {
2179
2255
  status: 500,
2180
2256
  json: _objectSpread2({
@@ -294,6 +294,16 @@ function convertOrderedList(path, node, files, configDirectory, remoteOptions) {
294
294
  })) || []
295
295
  };
296
296
  }
297
+ var convertToNumber = function convertToNumber(value) {
298
+ if (value === null || value === undefined) {
299
+ return 0;
300
+ }
301
+ if (typeof value === "number") {
302
+ return value;
303
+ }
304
+ var parsedValue = parseInt(value, 10);
305
+ return isNaN(parsedValue) ? 0 : parsedValue;
306
+ };
297
307
  var textEncoder = new TextEncoder();
298
308
  function convertImageNode(path, node, files, configDirectory, remoteOptions) {
299
309
  if (node.attrs && node.attrs.src.startsWith("data:")) {
@@ -314,14 +324,6 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
314
324
  var thisPath = path
315
325
  // file is added as src (see below):
316
326
  .concat("src");
317
- if (existingFilesEntry) {
318
- existingFilesEntry.patchPaths.push(thisPath);
319
- } else {
320
- files[filePath] = {
321
- value: node.attrs.src,
322
- patchPaths: [thisPath]
323
- };
324
- }
325
327
  var remoteFileHash = core.Internal.remote.hashToRemoteFileHash(fullFileHash);
326
328
  var ref = remoteOptions ? core.Internal.remote.createRemoteRef(remoteOptions.remoteHost, _objectSpread2(_objectSpread2({}, remoteOptions), {}, {
327
329
  fileHash: remoteFileHash,
@@ -331,6 +333,21 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
331
333
  }, remoteFileHash, textEncoder),
332
334
  filePath: filePath.slice(1)
333
335
  })) : filePath;
336
+ if (existingFilesEntry) {
337
+ existingFilesEntry.patchPaths.push(thisPath);
338
+ } else {
339
+ // TODO: use ref instead on filePath?
340
+ files[filePath] = {
341
+ value: node.attrs.src,
342
+ filePathOrRef: ref,
343
+ metadata: {
344
+ height: convertToNumber(node.attrs.height),
345
+ width: convertToNumber(node.attrs.width),
346
+ mimeType: mimeType
347
+ },
348
+ patchPaths: [thisPath]
349
+ };
350
+ }
334
351
  return {
335
352
  tag: "img",
336
353
  src: _objectSpread2(_objectSpread2(_defineProperty({}, core.FILE_REF_PROP, ref), remoteOptions ? _defineProperty({}, core.VAL_EXTENSION, "remote") : _defineProperty(_defineProperty({}, core.VAL_EXTENSION, "file"), core.FILE_REF_SUBTYPE_TAG, "image")), {}, {
@@ -348,7 +365,14 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
348
365
  var remote = false;
349
366
  if (patchId) {
350
367
  remote = getParam("remote", url) === "true";
351
- if (noParamsUrl.startsWith("/api/val/files/public")) {
368
+ if (remote) {
369
+ var remoteRef = getParam("ref", url);
370
+ if (remoteRef) {
371
+ noParamsUrl = decodeURIComponent(remoteRef);
372
+ } else {
373
+ console.error("Remote image URL does not contain ref: " + url);
374
+ }
375
+ } else if (noParamsUrl.startsWith("/api/val/files/public")) {
352
376
  noParamsUrl = noParamsUrl.slice("/api/val/files".length);
353
377
  } else {
354
378
  console.error("Patched image URL does not start with /api/val/files: " + url);
@@ -642,7 +666,7 @@ function convertLinkNodeToRemirror(linkNode) {
642
666
  });
643
667
  }
644
668
  function convertImageNodeToRemirror(imageNode) {
645
- var _fileSource$metadata, _fileSource$metadata2;
669
+ var _fileSource$metadata, _fileSource$metadata2, _fileSource$metadata3;
646
670
  var fileSource = imageNode.src;
647
671
  if (!(core.VAL_EXTENSION in fileSource) || fileSource[core.VAL_EXTENSION] !== "file" && fileSource[core.VAL_EXTENSION] !== "remote") {
648
672
  throw Error("Expected file source in image node");
@@ -658,6 +682,7 @@ function convertImageNodeToRemirror(imageNode) {
658
682
  attrs: {
659
683
  height: (_fileSource$metadata = fileSource.metadata) === null || _fileSource$metadata === void 0 ? void 0 : _fileSource$metadata.height,
660
684
  width: (_fileSource$metadata2 = fileSource.metadata) === null || _fileSource$metadata2 === void 0 ? void 0 : _fileSource$metadata2.width,
685
+ alt: (_fileSource$metadata3 = fileSource.metadata) === null || _fileSource$metadata3 === void 0 ? void 0 : _fileSource$metadata3.alt,
661
686
  src: fileVal.url
662
687
  }
663
688
  };
@@ -1075,6 +1100,17 @@ function _asyncToGenerator(n) {
1075
1100
  var JSONValueT = zod.z.lazy(function () {
1076
1101
  return zod.z.union([zod.z.string(), zod.z.number(), zod.z["boolean"](), zod.z["null"](), zod.z.array(JSONValueT), zod.z.record(JSONValueT)]);
1077
1102
  });
1103
+ var FileOperation = function FileOperation(path) {
1104
+ return zod.z.object({
1105
+ op: zod.z.literal("file"),
1106
+ path: path,
1107
+ filePath: zod.z.string(),
1108
+ value: zod.z.string(),
1109
+ remote: zod.z["boolean"](),
1110
+ nestedFilePath: zod.z.array(zod.z.string()).optional(),
1111
+ metadata: JSONValueT.optional() // TODO: remove optional
1112
+ });
1113
+ };
1078
1114
 
1079
1115
  /**
1080
1116
  * Raw JSON patch operation.
@@ -1108,13 +1144,7 @@ var OperationJSONT = zod.z.discriminatedUnion("op", [zod.z.object({
1108
1144
  op: zod.z.literal("test"),
1109
1145
  path: zod.z.string(),
1110
1146
  value: JSONValueT
1111
- }).strict(), zod.z.object({
1112
- op: zod.z.literal("file"),
1113
- path: zod.z.string(),
1114
- filePath: zod.z.string(),
1115
- value: zod.z.string(),
1116
- remote: zod.z["boolean"]()
1117
- }).strict()]);
1147
+ }).strict(), FileOperation(zod.z.string()).strict()]);
1118
1148
  var PatchJSON = zod.z.array(OperationJSONT);
1119
1149
  /**
1120
1150
  * Raw JSON patch operation.
@@ -1142,14 +1172,7 @@ var OperationT = zod.z.discriminatedUnion("op", [zod.z.object({
1142
1172
  op: zod.z.literal("test"),
1143
1173
  path: zod.z.array(zod.z.string()),
1144
1174
  value: JSONValueT
1145
- }).strict(), zod.z.object({
1146
- op: zod.z.literal("file"),
1147
- path: zod.z.array(zod.z.string()),
1148
- filePath: zod.z.string(),
1149
- nestedFilePath: zod.z.array(zod.z.string()).optional(),
1150
- value: zod.z.string(),
1151
- remote: zod.z["boolean"]()
1152
- }).strict()]);
1175
+ }).strict(), FileOperation(zod.z.array(zod.z.string())).strict()]);
1153
1176
  var Patch = zod.z.array(OperationT);
1154
1177
  var PatchId = zod.z.string().refine(function (_id) {
1155
1178
  return true;
@@ -1721,6 +1744,59 @@ var Api = {
1721
1744
  })])
1722
1745
  }
1723
1746
  },
1747
+ // This has a path which is like this: /upload/patches/:patchId/files. Example: /upload/patches/76b9237a-7712-4d60-88b4-d273e6d6fe18/files
1748
+ "/upload/patches": {
1749
+ POST: {
1750
+ req: {
1751
+ path: zod.z.string().optional(),
1752
+ body: zod.z.object({
1753
+ parentRef: ParentRef,
1754
+ filePath: zod.z.string(),
1755
+ data: zod.z.any(),
1756
+ // TODO: Json zod type
1757
+ type: zod.z.union([zod.z.literal("file"), zod.z.literal("image")]),
1758
+ metadata: zod.z.any(),
1759
+ // TODO: Json zod type
1760
+ remote: zod.z["boolean"]()
1761
+ })
1762
+ },
1763
+ res: zod.z.union([zod.z.object({
1764
+ status: zod.z.literal(400),
1765
+ json: GenericError
1766
+ }), zod.z.object({
1767
+ status: zod.z.literal(200),
1768
+ json: zod.z.object({
1769
+ filePath: zod.z.string(),
1770
+ patchId: PatchId
1771
+ })
1772
+ })])
1773
+ }
1774
+ },
1775
+ "/direct-file-upload-settings": {
1776
+ POST: {
1777
+ req: {
1778
+ cookies: {
1779
+ val_session: zod.z.string().optional()
1780
+ }
1781
+ },
1782
+ res: zod.z.union([zod.z.object({
1783
+ status: zod.z.literal(400),
1784
+ json: GenericError
1785
+ }), zod.z.object({
1786
+ status: zod.z.literal(401),
1787
+ json: GenericError
1788
+ }), zod.z.object({
1789
+ status: zod.z.literal(500),
1790
+ json: GenericError
1791
+ }), zod.z.object({
1792
+ status: zod.z.literal(200),
1793
+ json: zod.z.object({
1794
+ nonce: zod.z.string().nullable(),
1795
+ baseUrl: zod.z.string()
1796
+ })
1797
+ })])
1798
+ }
1799
+ },
1724
1800
  "/patches": {
1725
1801
  DELETE: {
1726
1802
  req: {
@@ -1975,7 +2051,7 @@ var Api = {
1975
2051
  details: zod.z.union([zod.z.object({
1976
2052
  sourceFilePatchErrors: zod.z.record(ModuleFilePath, zod.z.array(GenericError)),
1977
2053
  binaryFilePatchErrors: zod.z.record(GenericError)
1978
- }), zod.z.array(GenericError)])
2054
+ }), zod.z.array(GenericError)]).optional()
1979
2055
  }), zod.z.object({
1980
2056
  message: zod.z.string(),
1981
2057
  errorCode: zod.z.union([zod.z.literal("project-not-configured"), zod.z.literal("pat-error")])
@@ -2174,7 +2250,7 @@ var createValClient = function createValClient(host, config // We want to use th
2174
2250
  _context.next = 12;
2175
2251
  break;
2176
2252
  }
2177
- console.log("Server responded with an error", json);
2253
+ console.error("Server responded with an error", json);
2178
2254
  return _context.abrupt("return", {
2179
2255
  status: 500,
2180
2256
  json: _objectSpread2({
@@ -290,6 +290,16 @@ function convertOrderedList(path, node, files, configDirectory, remoteOptions) {
290
290
  })) || []
291
291
  };
292
292
  }
293
+ var convertToNumber = function convertToNumber(value) {
294
+ if (value === null || value === undefined) {
295
+ return 0;
296
+ }
297
+ if (typeof value === "number") {
298
+ return value;
299
+ }
300
+ var parsedValue = parseInt(value, 10);
301
+ return isNaN(parsedValue) ? 0 : parsedValue;
302
+ };
293
303
  var textEncoder = new TextEncoder();
294
304
  function convertImageNode(path, node, files, configDirectory, remoteOptions) {
295
305
  if (node.attrs && node.attrs.src.startsWith("data:")) {
@@ -310,14 +320,6 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
310
320
  var thisPath = path
311
321
  // file is added as src (see below):
312
322
  .concat("src");
313
- if (existingFilesEntry) {
314
- existingFilesEntry.patchPaths.push(thisPath);
315
- } else {
316
- files[filePath] = {
317
- value: node.attrs.src,
318
- patchPaths: [thisPath]
319
- };
320
- }
321
323
  var remoteFileHash = Internal.remote.hashToRemoteFileHash(fullFileHash);
322
324
  var ref = remoteOptions ? Internal.remote.createRemoteRef(remoteOptions.remoteHost, _objectSpread2(_objectSpread2({}, remoteOptions), {}, {
323
325
  fileHash: remoteFileHash,
@@ -327,6 +329,21 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
327
329
  }, remoteFileHash, textEncoder),
328
330
  filePath: filePath.slice(1)
329
331
  })) : filePath;
332
+ if (existingFilesEntry) {
333
+ existingFilesEntry.patchPaths.push(thisPath);
334
+ } else {
335
+ // TODO: use ref instead on filePath?
336
+ files[filePath] = {
337
+ value: node.attrs.src,
338
+ filePathOrRef: ref,
339
+ metadata: {
340
+ height: convertToNumber(node.attrs.height),
341
+ width: convertToNumber(node.attrs.width),
342
+ mimeType: mimeType
343
+ },
344
+ patchPaths: [thisPath]
345
+ };
346
+ }
330
347
  return {
331
348
  tag: "img",
332
349
  src: _objectSpread2(_objectSpread2(_defineProperty({}, FILE_REF_PROP, ref), remoteOptions ? _defineProperty({}, VAL_EXTENSION, "remote") : _defineProperty(_defineProperty({}, VAL_EXTENSION, "file"), FILE_REF_SUBTYPE_TAG, "image")), {}, {
@@ -344,7 +361,14 @@ function convertImageNode(path, node, files, configDirectory, remoteOptions) {
344
361
  var remote = false;
345
362
  if (patchId) {
346
363
  remote = getParam("remote", url) === "true";
347
- if (noParamsUrl.startsWith("/api/val/files/public")) {
364
+ if (remote) {
365
+ var remoteRef = getParam("ref", url);
366
+ if (remoteRef) {
367
+ noParamsUrl = decodeURIComponent(remoteRef);
368
+ } else {
369
+ console.error("Remote image URL does not contain ref: " + url);
370
+ }
371
+ } else if (noParamsUrl.startsWith("/api/val/files/public")) {
348
372
  noParamsUrl = noParamsUrl.slice("/api/val/files".length);
349
373
  } else {
350
374
  console.error("Patched image URL does not start with /api/val/files: " + url);
@@ -638,7 +662,7 @@ function convertLinkNodeToRemirror(linkNode) {
638
662
  });
639
663
  }
640
664
  function convertImageNodeToRemirror(imageNode) {
641
- var _fileSource$metadata, _fileSource$metadata2;
665
+ var _fileSource$metadata, _fileSource$metadata2, _fileSource$metadata3;
642
666
  var fileSource = imageNode.src;
643
667
  if (!(VAL_EXTENSION in fileSource) || fileSource[VAL_EXTENSION] !== "file" && fileSource[VAL_EXTENSION] !== "remote") {
644
668
  throw Error("Expected file source in image node");
@@ -654,6 +678,7 @@ function convertImageNodeToRemirror(imageNode) {
654
678
  attrs: {
655
679
  height: (_fileSource$metadata = fileSource.metadata) === null || _fileSource$metadata === void 0 ? void 0 : _fileSource$metadata.height,
656
680
  width: (_fileSource$metadata2 = fileSource.metadata) === null || _fileSource$metadata2 === void 0 ? void 0 : _fileSource$metadata2.width,
681
+ alt: (_fileSource$metadata3 = fileSource.metadata) === null || _fileSource$metadata3 === void 0 ? void 0 : _fileSource$metadata3.alt,
657
682
  src: fileVal.url
658
683
  }
659
684
  };
@@ -1071,6 +1096,17 @@ function _asyncToGenerator(n) {
1071
1096
  var JSONValueT = z.lazy(function () {
1072
1097
  return z.union([z.string(), z.number(), z["boolean"](), z["null"](), z.array(JSONValueT), z.record(JSONValueT)]);
1073
1098
  });
1099
+ var FileOperation = function FileOperation(path) {
1100
+ return z.object({
1101
+ op: z.literal("file"),
1102
+ path: path,
1103
+ filePath: z.string(),
1104
+ value: z.string(),
1105
+ remote: z["boolean"](),
1106
+ nestedFilePath: z.array(z.string()).optional(),
1107
+ metadata: JSONValueT.optional() // TODO: remove optional
1108
+ });
1109
+ };
1074
1110
 
1075
1111
  /**
1076
1112
  * Raw JSON patch operation.
@@ -1104,13 +1140,7 @@ var OperationJSONT = z.discriminatedUnion("op", [z.object({
1104
1140
  op: z.literal("test"),
1105
1141
  path: z.string(),
1106
1142
  value: JSONValueT
1107
- }).strict(), z.object({
1108
- op: z.literal("file"),
1109
- path: z.string(),
1110
- filePath: z.string(),
1111
- value: z.string(),
1112
- remote: z["boolean"]()
1113
- }).strict()]);
1143
+ }).strict(), FileOperation(z.string()).strict()]);
1114
1144
  var PatchJSON = z.array(OperationJSONT);
1115
1145
  /**
1116
1146
  * Raw JSON patch operation.
@@ -1138,14 +1168,7 @@ var OperationT = z.discriminatedUnion("op", [z.object({
1138
1168
  op: z.literal("test"),
1139
1169
  path: z.array(z.string()),
1140
1170
  value: JSONValueT
1141
- }).strict(), z.object({
1142
- op: z.literal("file"),
1143
- path: z.array(z.string()),
1144
- filePath: z.string(),
1145
- nestedFilePath: z.array(z.string()).optional(),
1146
- value: z.string(),
1147
- remote: z["boolean"]()
1148
- }).strict()]);
1171
+ }).strict(), FileOperation(z.array(z.string())).strict()]);
1149
1172
  var Patch = z.array(OperationT);
1150
1173
  var PatchId = z.string().refine(function (_id) {
1151
1174
  return true;
@@ -1717,6 +1740,59 @@ var Api = {
1717
1740
  })])
1718
1741
  }
1719
1742
  },
1743
+ // This has a path which is like this: /upload/patches/:patchId/files. Example: /upload/patches/76b9237a-7712-4d60-88b4-d273e6d6fe18/files
1744
+ "/upload/patches": {
1745
+ POST: {
1746
+ req: {
1747
+ path: z.string().optional(),
1748
+ body: z.object({
1749
+ parentRef: ParentRef,
1750
+ filePath: z.string(),
1751
+ data: z.any(),
1752
+ // TODO: Json zod type
1753
+ type: z.union([z.literal("file"), z.literal("image")]),
1754
+ metadata: z.any(),
1755
+ // TODO: Json zod type
1756
+ remote: z["boolean"]()
1757
+ })
1758
+ },
1759
+ res: z.union([z.object({
1760
+ status: z.literal(400),
1761
+ json: GenericError
1762
+ }), z.object({
1763
+ status: z.literal(200),
1764
+ json: z.object({
1765
+ filePath: z.string(),
1766
+ patchId: PatchId
1767
+ })
1768
+ })])
1769
+ }
1770
+ },
1771
+ "/direct-file-upload-settings": {
1772
+ POST: {
1773
+ req: {
1774
+ cookies: {
1775
+ val_session: z.string().optional()
1776
+ }
1777
+ },
1778
+ res: z.union([z.object({
1779
+ status: z.literal(400),
1780
+ json: GenericError
1781
+ }), z.object({
1782
+ status: z.literal(401),
1783
+ json: GenericError
1784
+ }), z.object({
1785
+ status: z.literal(500),
1786
+ json: GenericError
1787
+ }), z.object({
1788
+ status: z.literal(200),
1789
+ json: z.object({
1790
+ nonce: z.string().nullable(),
1791
+ baseUrl: z.string()
1792
+ })
1793
+ })])
1794
+ }
1795
+ },
1720
1796
  "/patches": {
1721
1797
  DELETE: {
1722
1798
  req: {
@@ -1971,7 +2047,7 @@ var Api = {
1971
2047
  details: z.union([z.object({
1972
2048
  sourceFilePatchErrors: z.record(ModuleFilePath, z.array(GenericError)),
1973
2049
  binaryFilePatchErrors: z.record(GenericError)
1974
- }), z.array(GenericError)])
2050
+ }), z.array(GenericError)]).optional()
1975
2051
  }), z.object({
1976
2052
  message: z.string(),
1977
2053
  errorCode: z.union([z.literal("project-not-configured"), z.literal("pat-error")])
@@ -2170,7 +2246,7 @@ var createValClient = function createValClient(host, config // We want to use th
2170
2246
  _context.next = 12;
2171
2247
  break;
2172
2248
  }
2173
- console.log("Server responded with an error", json);
2249
+ console.error("Server responded with an error", json);
2174
2250
  return _context.abrupt("return", {
2175
2251
  status: 500,
2176
2252
  json: _objectSpread2({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.75.5",
3
+ "version": "0.76.0",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "exports": true
30
30
  },
31
31
  "dependencies": {
32
- "@valbuild/core": "~0.75.5",
32
+ "@valbuild/core": "~0.76.0",
33
33
  "zod": "^3.22.4",
34
34
  "zod-validation-error": "^3.3.0"
35
35
  },