@uipath/uipath-typescript 1.4.2 → 1.5.1
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.
- package/README.md +7 -1
- package/dist/agent-memory/index.d.ts +4 -1
- package/dist/agents/index.cjs +341 -6
- package/dist/agents/index.d.ts +717 -16
- package/dist/agents/index.mjs +342 -7
- package/dist/assets/index.cjs +132 -15
- package/dist/assets/index.d.ts +12 -1
- package/dist/assets/index.mjs +132 -15
- package/dist/attachments/index.cjs +120 -12
- package/dist/attachments/index.mjs +120 -12
- package/dist/buckets/index.cjs +136 -15
- package/dist/buckets/index.d.ts +12 -1
- package/dist/buckets/index.mjs +136 -15
- package/dist/cases/index.cjs +1203 -938
- package/dist/cases/index.d.ts +325 -45
- package/dist/cases/index.mjs +1203 -938
- package/dist/conversational-agent/index.cjs +48 -10
- package/dist/conversational-agent/index.d.ts +117 -6
- package/dist/conversational-agent/index.mjs +48 -10
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.mjs +1 -1
- package/dist/entities/index.cjs +448 -9
- package/dist/entities/index.d.ts +441 -1
- package/dist/entities/index.mjs +447 -10
- package/dist/feedback/index.cjs +25 -9
- package/dist/feedback/index.mjs +25 -9
- package/dist/index.cjs +1281 -330
- package/dist/index.d.ts +1988 -143
- package/dist/index.mjs +1282 -331
- package/dist/index.umd.js +1230 -279
- package/dist/jobs/index.cjs +141 -19
- package/dist/jobs/index.d.ts +22 -6
- package/dist/jobs/index.mjs +141 -19
- package/dist/maestro-processes/index.cjs +553 -354
- package/dist/maestro-processes/index.d.ts +376 -47
- package/dist/maestro-processes/index.mjs +553 -354
- package/dist/notifications/index.cjs +2012 -0
- package/dist/notifications/index.d.ts +615 -0
- package/dist/notifications/index.mjs +2010 -0
- package/dist/processes/index.cjs +118 -18
- package/dist/processes/index.d.ts +18 -2
- package/dist/processes/index.mjs +118 -18
- package/dist/queues/index.cjs +131 -14
- package/dist/queues/index.d.ts +12 -1
- package/dist/queues/index.mjs +131 -14
- package/dist/tasks/index.cjs +125 -13
- package/dist/tasks/index.d.ts +4 -1
- package/dist/tasks/index.mjs +125 -13
- package/dist/traces/index.cjs +220 -6
- package/dist/traces/index.d.ts +360 -25
- package/dist/traces/index.mjs +221 -7
- package/package.json +14 -4
package/dist/buckets/index.cjs
CHANGED
|
@@ -965,7 +965,16 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
965
965
|
* Returns the original value if parsing fails.
|
|
966
966
|
*/
|
|
967
967
|
/**
|
|
968
|
-
* Transforms data by
|
|
968
|
+
* Transforms data by renaming each key in `data` exactly once, using the
|
|
969
|
+
* mapping (`sourceField → targetField`). Keys not present in the mapping
|
|
970
|
+
* pass through unchanged. The original (pre-rename) key is dropped — the
|
|
971
|
+
* result contains only the renamed key.
|
|
972
|
+
*
|
|
973
|
+
* Each rename is independent. If the mapping happens to contain chained
|
|
974
|
+
* entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
|
|
975
|
+
* in `data` becomes `b` (not `c`), because the renames are applied based
|
|
976
|
+
* on the original data's keys, not the running result.
|
|
977
|
+
*
|
|
969
978
|
* @param data The source data to transform
|
|
970
979
|
* @param fieldMapping Object mapping source field names to target field names
|
|
971
980
|
* @returns Transformed data with mapped field names
|
|
@@ -988,21 +997,28 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
988
997
|
* // { userId: '123', name: 'john' },
|
|
989
998
|
* // { userId: '456', name: 'jane' }
|
|
990
999
|
* // ]
|
|
1000
|
+
*
|
|
1001
|
+
* // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
|
|
1002
|
+
* transformData({ a: 1 }, { a: 'b', b: 'c' });
|
|
1003
|
+
* // result = { b: 1 }
|
|
991
1004
|
* ```
|
|
992
1005
|
*/
|
|
993
1006
|
function transformData(data, fieldMapping) {
|
|
1007
|
+
// Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
|
|
1008
|
+
// may invoke this on optional fields that an OData `select` excluded.
|
|
1009
|
+
if (data == null) {
|
|
1010
|
+
return data;
|
|
1011
|
+
}
|
|
994
1012
|
// Handle array of objects
|
|
995
1013
|
if (Array.isArray(data)) {
|
|
996
1014
|
return data.map(item => transformData(item, fieldMapping));
|
|
997
1015
|
}
|
|
998
|
-
//
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
result[targetField] = value;
|
|
1005
|
-
}
|
|
1016
|
+
// Walk the ORIGINAL data's keys, look up each in the mapping. One rename
|
|
1017
|
+
// per data key — no mutation of an in-progress result, so chains can't form.
|
|
1018
|
+
const result = {};
|
|
1019
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1020
|
+
const renamedKey = fieldMapping[key] ?? key;
|
|
1021
|
+
result[renamedKey] = value;
|
|
1006
1022
|
}
|
|
1007
1023
|
return result;
|
|
1008
1024
|
}
|
|
@@ -1112,6 +1128,97 @@ function addPrefixToKeys(obj, prefix, keys) {
|
|
|
1112
1128
|
}
|
|
1113
1129
|
return result;
|
|
1114
1130
|
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Creates a new map with the keys and values reversed
|
|
1133
|
+
* @param map The original map to reverse
|
|
1134
|
+
* @returns A new map with keys and values swapped
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* const original = { key1: 'value1', key2: 'value2' };
|
|
1139
|
+
* const reversed = reverseMap(original);
|
|
1140
|
+
* // reversed = { value1: 'key1', value2: 'key2' }
|
|
1141
|
+
* ```
|
|
1142
|
+
*/
|
|
1143
|
+
function reverseMap(map) {
|
|
1144
|
+
return Object.entries(map).reduce((acc, [key, value]) => {
|
|
1145
|
+
acc[value] = key;
|
|
1146
|
+
return acc;
|
|
1147
|
+
}, {});
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* OData query-string keys whose values may contain field identifiers that
|
|
1151
|
+
* need rewriting from SDK names → API names.
|
|
1152
|
+
*/
|
|
1153
|
+
const ODATA_FIELD_PARAM_KEYS = ['filter', 'orderby', 'select', 'expand'];
|
|
1154
|
+
/**
|
|
1155
|
+
* Matches one token at a time in an OData expression:
|
|
1156
|
+
* 1. A single-quoted string literal, allowing the `''` escape sequence —
|
|
1157
|
+
* consumed atomically so identifiers inside the literal can't match.
|
|
1158
|
+
* 2. An OData identifier (`[A-Za-z_][A-Za-z0-9_]*`).
|
|
1159
|
+
* Anything else (whitespace, operators, parens, commas) is left alone by
|
|
1160
|
+
* `String.prototype.replace`, which only substitutes matched substrings.
|
|
1161
|
+
*/
|
|
1162
|
+
const ODATA_TOKEN_RE = /'(?:[^']|'')*'|[A-Za-z_][A-Za-z0-9_]*/g;
|
|
1163
|
+
/**
|
|
1164
|
+
* Rewrites SDK field identifiers to API field identifiers inside an OData
|
|
1165
|
+
* expression string (`$filter`, `$orderby`, `$select`, `$expand`).
|
|
1166
|
+
*
|
|
1167
|
+
* Field maps (e.g. `JobMap`) rename API fields → SDK fields on responses, so
|
|
1168
|
+
* SDK consumers see the renamed names. Without this rewrite, the same name
|
|
1169
|
+
* in a `filter` string would be forwarded verbatim and the API (which still
|
|
1170
|
+
* uses the original name) would reject it.
|
|
1171
|
+
*
|
|
1172
|
+
* Quoted string literals (with the OData `''` escape) are preserved exactly:
|
|
1173
|
+
* the token regex consumes them whole, so identifiers inside literals never
|
|
1174
|
+
* match. Identifier tokens are looked up in the reversed field map.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```typescript
|
|
1178
|
+
* const requestMap = { processName: 'releaseName' };
|
|
1179
|
+
* rewriteODataIdentifiers("processName eq 'processName'", requestMap);
|
|
1180
|
+
* // "releaseName eq 'processName'" — identifier rewritten, literal preserved
|
|
1181
|
+
* ```
|
|
1182
|
+
*/
|
|
1183
|
+
function rewriteODataIdentifiers(expression, requestMap) {
|
|
1184
|
+
if (!expression)
|
|
1185
|
+
return expression;
|
|
1186
|
+
return expression.replace(ODATA_TOKEN_RE, (match) => match.startsWith("'") ? match : (requestMap[match] ?? match));
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Symmetric counterpart of {@link transformRequest} for OData query options:
|
|
1190
|
+
* rewrites SDK field identifiers inside the recognized OData string params
|
|
1191
|
+
* (`filter`, `orderby`, `select`, `expand`) to their API names using the
|
|
1192
|
+
* reversed form of a response field map. Returns a shallow copy with the
|
|
1193
|
+
* relevant values rewritten; other keys pass through unchanged.
|
|
1194
|
+
*
|
|
1195
|
+
* Use at the OData edge so SDK consumers can refer to renamed fields by
|
|
1196
|
+
* their SDK name throughout — for reading the response and for filtering /
|
|
1197
|
+
* sorting / projecting / expanding.
|
|
1198
|
+
*
|
|
1199
|
+
* @param options The OData query options as authored with SDK field names
|
|
1200
|
+
* @param responseMap The response field map (API → SDK); reversed internally
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* // JobMap renames releaseName → processName on responses.
|
|
1205
|
+
* transformOptions({ filter: "processName eq 'X'" }, JobMap);
|
|
1206
|
+
* // { filter: "releaseName eq 'X'" }
|
|
1207
|
+
* ```
|
|
1208
|
+
*/
|
|
1209
|
+
function transformOptions(options, responseMap) {
|
|
1210
|
+
const requestMap = reverseMap(responseMap);
|
|
1211
|
+
if (Object.keys(requestMap).length === 0)
|
|
1212
|
+
return options;
|
|
1213
|
+
const result = { ...options };
|
|
1214
|
+
for (const key of ODATA_FIELD_PARAM_KEYS) {
|
|
1215
|
+
const value = result[key];
|
|
1216
|
+
if (typeof value === 'string') {
|
|
1217
|
+
result[key] = rewriteODataIdentifiers(value, requestMap);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
return result;
|
|
1221
|
+
}
|
|
1115
1222
|
/**
|
|
1116
1223
|
* Transforms an array-based dictionary with separate keys and values arrays
|
|
1117
1224
|
* into a standard JavaScript object/record
|
|
@@ -1909,9 +2016,12 @@ class FolderScopedService extends BaseService {
|
|
|
1909
2016
|
* @param name - Resource name to search for
|
|
1910
2017
|
* @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`) + OData query options (`expand`, `select`)
|
|
1911
2018
|
* @param transform - Maps a raw OData item to the typed response (e.g. PascalCase → camelCase via field map)
|
|
2019
|
+
* @param responseFieldMap - Optional response field map (API → SDK), reversed internally by
|
|
2020
|
+
* `transformOptions` to rewrite SDK field names back to API names in user-supplied
|
|
2021
|
+
* `expand` / `select` (symmetric counterpart to `transform`)
|
|
1912
2022
|
* @throws ValidationError when inputs are malformed; NotFoundError when no match
|
|
1913
2023
|
*/
|
|
1914
|
-
async getByNameLookup(resourceType, endpoint, name, options, transform) {
|
|
2024
|
+
async getByNameLookup(resourceType, endpoint, name, options, transform, responseFieldMap) {
|
|
1915
2025
|
const validatedName = validateName(resourceType, name);
|
|
1916
2026
|
const { folderId, folderKey, folderPath, ...queryOptions } = options;
|
|
1917
2027
|
const headers = resolveFolderHeaders({
|
|
@@ -1921,8 +2031,11 @@ class FolderScopedService extends BaseService {
|
|
|
1921
2031
|
resourceType: `${resourceType}.getByName`,
|
|
1922
2032
|
fallbackFolderKey: this.config.folderKey,
|
|
1923
2033
|
});
|
|
2034
|
+
const apiFieldOptions = responseFieldMap
|
|
2035
|
+
? transformOptions(queryOptions, responseFieldMap)
|
|
2036
|
+
: queryOptions;
|
|
1924
2037
|
const apiOptions = {
|
|
1925
|
-
...addPrefixToKeys(
|
|
2038
|
+
...addPrefixToKeys(apiFieldOptions, ODATA_PREFIX, Object.keys(apiFieldOptions)),
|
|
1926
2039
|
'$filter': `Name eq '${validatedName.replace(SINGLE_QUOTE_RE, "''")}'`,
|
|
1927
2040
|
'$top': '1',
|
|
1928
2041
|
};
|
|
@@ -2167,6 +2280,9 @@ class BucketService extends FolderScopedService {
|
|
|
2167
2280
|
});
|
|
2168
2281
|
// Transformation function for blob items
|
|
2169
2282
|
const transformBlobItem = (item) => transformData(item, BucketMap);
|
|
2283
|
+
// Rewrite renamed SDK field names → API names inside OData strings
|
|
2284
|
+
// before delegating.
|
|
2285
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2170
2286
|
return PaginationHelpers.getAll({
|
|
2171
2287
|
serviceAccess: this.createPaginationServiceAccess(),
|
|
2172
2288
|
getEndpoint: () => BUCKET_ENDPOINTS.GET_FILE_META_DATA(bucketId),
|
|
@@ -2182,7 +2298,7 @@ class BucketService extends FolderScopedService {
|
|
|
2182
2298
|
},
|
|
2183
2299
|
excludeFromPrefix: ['prefix'], // Bucket-specific param, not OData
|
|
2184
2300
|
headers,
|
|
2185
|
-
},
|
|
2301
|
+
}, apiRestOptions);
|
|
2186
2302
|
}
|
|
2187
2303
|
async uploadFile(bucketIdOrOptions, path, content, options) {
|
|
2188
2304
|
// Normalize the two overload forms into a single internal shape.
|
|
@@ -2266,9 +2382,10 @@ class BucketService extends FolderScopedService {
|
|
|
2266
2382
|
resourceType: 'Buckets.getReadUri',
|
|
2267
2383
|
fallbackFolderKey: this.config.folderKey,
|
|
2268
2384
|
});
|
|
2385
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2269
2386
|
const queryOptions = {
|
|
2270
2387
|
expiryInMinutes,
|
|
2271
|
-
...addPrefixToKeys(
|
|
2388
|
+
...addPrefixToKeys(apiRestOptions, ODATA_PREFIX, Object.keys(apiRestOptions))
|
|
2272
2389
|
};
|
|
2273
2390
|
return this._getUri(BUCKET_ENDPOINTS.GET_READ_URI(bucketId), bucketId, resolvedPath, headers, queryOptions);
|
|
2274
2391
|
}
|
|
@@ -2388,6 +2505,9 @@ class BucketService extends FolderScopedService {
|
|
|
2388
2505
|
fallbackFolderKey: this.config.folderKey,
|
|
2389
2506
|
});
|
|
2390
2507
|
const transformBucketFile = (file) => transformData(pascalToCamelCaseKeys(file), BucketMap);
|
|
2508
|
+
// Rewrite renamed SDK field names → API names inside OData strings
|
|
2509
|
+
// before delegating.
|
|
2510
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2391
2511
|
return PaginationHelpers.getAll({
|
|
2392
2512
|
serviceAccess: this.createPaginationServiceAccess(),
|
|
2393
2513
|
getEndpoint: () => BUCKET_ENDPOINTS.GET_FILES(bucketId),
|
|
@@ -2404,7 +2524,7 @@ class BucketService extends FolderScopedService {
|
|
|
2404
2524
|
},
|
|
2405
2525
|
excludeFromPrefix: ['directory', 'recursive', 'fileNameRegex'],
|
|
2406
2526
|
headers,
|
|
2407
|
-
}, { ...
|
|
2527
|
+
}, { ...apiRestOptions, directory: '/', recursive: true });
|
|
2408
2528
|
}
|
|
2409
2529
|
/**
|
|
2410
2530
|
* Deletes a file from a bucket
|
|
@@ -2451,9 +2571,10 @@ class BucketService extends FolderScopedService {
|
|
|
2451
2571
|
*/
|
|
2452
2572
|
async _getWriteUri(options) {
|
|
2453
2573
|
const { bucketId, path, expiryInMinutes, headers, ...restOptions } = options;
|
|
2574
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2454
2575
|
const queryOptions = {
|
|
2455
2576
|
expiryInMinutes,
|
|
2456
|
-
...addPrefixToKeys(
|
|
2577
|
+
...addPrefixToKeys(apiRestOptions, ODATA_PREFIX, Object.keys(apiRestOptions))
|
|
2457
2578
|
};
|
|
2458
2579
|
return this._getUri(BUCKET_ENDPOINTS.GET_WRITE_URI(bucketId), bucketId, path, headers, queryOptions);
|
|
2459
2580
|
}
|
package/dist/buckets/index.d.ts
CHANGED
|
@@ -326,6 +326,14 @@ interface FolderScopedOptions extends BaseOptions {
|
|
|
326
326
|
folderPath?: string;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Type for field mapping configuration
|
|
331
|
+
* Maps source field names to target field names
|
|
332
|
+
*/
|
|
333
|
+
type FieldMapping = {
|
|
334
|
+
[sourceField: string]: string;
|
|
335
|
+
};
|
|
336
|
+
|
|
329
337
|
/**
|
|
330
338
|
* Base service for services that need folder-specific functionality.
|
|
331
339
|
*
|
|
@@ -367,9 +375,12 @@ declare class FolderScopedService extends BaseService {
|
|
|
367
375
|
* @param name - Resource name to search for
|
|
368
376
|
* @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`) + OData query options (`expand`, `select`)
|
|
369
377
|
* @param transform - Maps a raw OData item to the typed response (e.g. PascalCase → camelCase via field map)
|
|
378
|
+
* @param responseFieldMap - Optional response field map (API → SDK), reversed internally by
|
|
379
|
+
* `transformOptions` to rewrite SDK field names back to API names in user-supplied
|
|
380
|
+
* `expand` / `select` (symmetric counterpart to `transform`)
|
|
370
381
|
* @throws ValidationError when inputs are malformed; NotFoundError when no match
|
|
371
382
|
*/
|
|
372
|
-
protected getByNameLookup<TRaw extends object, T>(resourceType: string, endpoint: string, name: string, options: FolderScopedOptions, transform: (raw: TRaw) => T): Promise<T>;
|
|
383
|
+
protected getByNameLookup<TRaw extends object, T>(resourceType: string, endpoint: string, name: string, options: FolderScopedOptions, transform: (raw: TRaw) => T, responseFieldMap?: FieldMapping): Promise<T>;
|
|
373
384
|
}
|
|
374
385
|
|
|
375
386
|
declare enum BucketOptions {
|
package/dist/buckets/index.mjs
CHANGED
|
@@ -963,7 +963,16 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
963
963
|
* Returns the original value if parsing fails.
|
|
964
964
|
*/
|
|
965
965
|
/**
|
|
966
|
-
* Transforms data by
|
|
966
|
+
* Transforms data by renaming each key in `data` exactly once, using the
|
|
967
|
+
* mapping (`sourceField → targetField`). Keys not present in the mapping
|
|
968
|
+
* pass through unchanged. The original (pre-rename) key is dropped — the
|
|
969
|
+
* result contains only the renamed key.
|
|
970
|
+
*
|
|
971
|
+
* Each rename is independent. If the mapping happens to contain chained
|
|
972
|
+
* entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
|
|
973
|
+
* in `data` becomes `b` (not `c`), because the renames are applied based
|
|
974
|
+
* on the original data's keys, not the running result.
|
|
975
|
+
*
|
|
967
976
|
* @param data The source data to transform
|
|
968
977
|
* @param fieldMapping Object mapping source field names to target field names
|
|
969
978
|
* @returns Transformed data with mapped field names
|
|
@@ -986,21 +995,28 @@ const BUCKET_TOKEN_PARAMS = {
|
|
|
986
995
|
* // { userId: '123', name: 'john' },
|
|
987
996
|
* // { userId: '456', name: 'jane' }
|
|
988
997
|
* // ]
|
|
998
|
+
*
|
|
999
|
+
* // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
|
|
1000
|
+
* transformData({ a: 1 }, { a: 'b', b: 'c' });
|
|
1001
|
+
* // result = { b: 1 }
|
|
989
1002
|
* ```
|
|
990
1003
|
*/
|
|
991
1004
|
function transformData(data, fieldMapping) {
|
|
1005
|
+
// Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
|
|
1006
|
+
// may invoke this on optional fields that an OData `select` excluded.
|
|
1007
|
+
if (data == null) {
|
|
1008
|
+
return data;
|
|
1009
|
+
}
|
|
992
1010
|
// Handle array of objects
|
|
993
1011
|
if (Array.isArray(data)) {
|
|
994
1012
|
return data.map(item => transformData(item, fieldMapping));
|
|
995
1013
|
}
|
|
996
|
-
//
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
result[targetField] = value;
|
|
1003
|
-
}
|
|
1014
|
+
// Walk the ORIGINAL data's keys, look up each in the mapping. One rename
|
|
1015
|
+
// per data key — no mutation of an in-progress result, so chains can't form.
|
|
1016
|
+
const result = {};
|
|
1017
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1018
|
+
const renamedKey = fieldMapping[key] ?? key;
|
|
1019
|
+
result[renamedKey] = value;
|
|
1004
1020
|
}
|
|
1005
1021
|
return result;
|
|
1006
1022
|
}
|
|
@@ -1110,6 +1126,97 @@ function addPrefixToKeys(obj, prefix, keys) {
|
|
|
1110
1126
|
}
|
|
1111
1127
|
return result;
|
|
1112
1128
|
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Creates a new map with the keys and values reversed
|
|
1131
|
+
* @param map The original map to reverse
|
|
1132
|
+
* @returns A new map with keys and values swapped
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* const original = { key1: 'value1', key2: 'value2' };
|
|
1137
|
+
* const reversed = reverseMap(original);
|
|
1138
|
+
* // reversed = { value1: 'key1', value2: 'key2' }
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
function reverseMap(map) {
|
|
1142
|
+
return Object.entries(map).reduce((acc, [key, value]) => {
|
|
1143
|
+
acc[value] = key;
|
|
1144
|
+
return acc;
|
|
1145
|
+
}, {});
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* OData query-string keys whose values may contain field identifiers that
|
|
1149
|
+
* need rewriting from SDK names → API names.
|
|
1150
|
+
*/
|
|
1151
|
+
const ODATA_FIELD_PARAM_KEYS = ['filter', 'orderby', 'select', 'expand'];
|
|
1152
|
+
/**
|
|
1153
|
+
* Matches one token at a time in an OData expression:
|
|
1154
|
+
* 1. A single-quoted string literal, allowing the `''` escape sequence —
|
|
1155
|
+
* consumed atomically so identifiers inside the literal can't match.
|
|
1156
|
+
* 2. An OData identifier (`[A-Za-z_][A-Za-z0-9_]*`).
|
|
1157
|
+
* Anything else (whitespace, operators, parens, commas) is left alone by
|
|
1158
|
+
* `String.prototype.replace`, which only substitutes matched substrings.
|
|
1159
|
+
*/
|
|
1160
|
+
const ODATA_TOKEN_RE = /'(?:[^']|'')*'|[A-Za-z_][A-Za-z0-9_]*/g;
|
|
1161
|
+
/**
|
|
1162
|
+
* Rewrites SDK field identifiers to API field identifiers inside an OData
|
|
1163
|
+
* expression string (`$filter`, `$orderby`, `$select`, `$expand`).
|
|
1164
|
+
*
|
|
1165
|
+
* Field maps (e.g. `JobMap`) rename API fields → SDK fields on responses, so
|
|
1166
|
+
* SDK consumers see the renamed names. Without this rewrite, the same name
|
|
1167
|
+
* in a `filter` string would be forwarded verbatim and the API (which still
|
|
1168
|
+
* uses the original name) would reject it.
|
|
1169
|
+
*
|
|
1170
|
+
* Quoted string literals (with the OData `''` escape) are preserved exactly:
|
|
1171
|
+
* the token regex consumes them whole, so identifiers inside literals never
|
|
1172
|
+
* match. Identifier tokens are looked up in the reversed field map.
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```typescript
|
|
1176
|
+
* const requestMap = { processName: 'releaseName' };
|
|
1177
|
+
* rewriteODataIdentifiers("processName eq 'processName'", requestMap);
|
|
1178
|
+
* // "releaseName eq 'processName'" — identifier rewritten, literal preserved
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
1181
|
+
function rewriteODataIdentifiers(expression, requestMap) {
|
|
1182
|
+
if (!expression)
|
|
1183
|
+
return expression;
|
|
1184
|
+
return expression.replace(ODATA_TOKEN_RE, (match) => match.startsWith("'") ? match : (requestMap[match] ?? match));
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Symmetric counterpart of {@link transformRequest} for OData query options:
|
|
1188
|
+
* rewrites SDK field identifiers inside the recognized OData string params
|
|
1189
|
+
* (`filter`, `orderby`, `select`, `expand`) to their API names using the
|
|
1190
|
+
* reversed form of a response field map. Returns a shallow copy with the
|
|
1191
|
+
* relevant values rewritten; other keys pass through unchanged.
|
|
1192
|
+
*
|
|
1193
|
+
* Use at the OData edge so SDK consumers can refer to renamed fields by
|
|
1194
|
+
* their SDK name throughout — for reading the response and for filtering /
|
|
1195
|
+
* sorting / projecting / expanding.
|
|
1196
|
+
*
|
|
1197
|
+
* @param options The OData query options as authored with SDK field names
|
|
1198
|
+
* @param responseMap The response field map (API → SDK); reversed internally
|
|
1199
|
+
*
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```typescript
|
|
1202
|
+
* // JobMap renames releaseName → processName on responses.
|
|
1203
|
+
* transformOptions({ filter: "processName eq 'X'" }, JobMap);
|
|
1204
|
+
* // { filter: "releaseName eq 'X'" }
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
function transformOptions(options, responseMap) {
|
|
1208
|
+
const requestMap = reverseMap(responseMap);
|
|
1209
|
+
if (Object.keys(requestMap).length === 0)
|
|
1210
|
+
return options;
|
|
1211
|
+
const result = { ...options };
|
|
1212
|
+
for (const key of ODATA_FIELD_PARAM_KEYS) {
|
|
1213
|
+
const value = result[key];
|
|
1214
|
+
if (typeof value === 'string') {
|
|
1215
|
+
result[key] = rewriteODataIdentifiers(value, requestMap);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return result;
|
|
1219
|
+
}
|
|
1113
1220
|
/**
|
|
1114
1221
|
* Transforms an array-based dictionary with separate keys and values arrays
|
|
1115
1222
|
* into a standard JavaScript object/record
|
|
@@ -1907,9 +2014,12 @@ class FolderScopedService extends BaseService {
|
|
|
1907
2014
|
* @param name - Resource name to search for
|
|
1908
2015
|
* @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`) + OData query options (`expand`, `select`)
|
|
1909
2016
|
* @param transform - Maps a raw OData item to the typed response (e.g. PascalCase → camelCase via field map)
|
|
2017
|
+
* @param responseFieldMap - Optional response field map (API → SDK), reversed internally by
|
|
2018
|
+
* `transformOptions` to rewrite SDK field names back to API names in user-supplied
|
|
2019
|
+
* `expand` / `select` (symmetric counterpart to `transform`)
|
|
1910
2020
|
* @throws ValidationError when inputs are malformed; NotFoundError when no match
|
|
1911
2021
|
*/
|
|
1912
|
-
async getByNameLookup(resourceType, endpoint, name, options, transform) {
|
|
2022
|
+
async getByNameLookup(resourceType, endpoint, name, options, transform, responseFieldMap) {
|
|
1913
2023
|
const validatedName = validateName(resourceType, name);
|
|
1914
2024
|
const { folderId, folderKey, folderPath, ...queryOptions } = options;
|
|
1915
2025
|
const headers = resolveFolderHeaders({
|
|
@@ -1919,8 +2029,11 @@ class FolderScopedService extends BaseService {
|
|
|
1919
2029
|
resourceType: `${resourceType}.getByName`,
|
|
1920
2030
|
fallbackFolderKey: this.config.folderKey,
|
|
1921
2031
|
});
|
|
2032
|
+
const apiFieldOptions = responseFieldMap
|
|
2033
|
+
? transformOptions(queryOptions, responseFieldMap)
|
|
2034
|
+
: queryOptions;
|
|
1922
2035
|
const apiOptions = {
|
|
1923
|
-
...addPrefixToKeys(
|
|
2036
|
+
...addPrefixToKeys(apiFieldOptions, ODATA_PREFIX, Object.keys(apiFieldOptions)),
|
|
1924
2037
|
'$filter': `Name eq '${validatedName.replace(SINGLE_QUOTE_RE, "''")}'`,
|
|
1925
2038
|
'$top': '1',
|
|
1926
2039
|
};
|
|
@@ -2165,6 +2278,9 @@ class BucketService extends FolderScopedService {
|
|
|
2165
2278
|
});
|
|
2166
2279
|
// Transformation function for blob items
|
|
2167
2280
|
const transformBlobItem = (item) => transformData(item, BucketMap);
|
|
2281
|
+
// Rewrite renamed SDK field names → API names inside OData strings
|
|
2282
|
+
// before delegating.
|
|
2283
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2168
2284
|
return PaginationHelpers.getAll({
|
|
2169
2285
|
serviceAccess: this.createPaginationServiceAccess(),
|
|
2170
2286
|
getEndpoint: () => BUCKET_ENDPOINTS.GET_FILE_META_DATA(bucketId),
|
|
@@ -2180,7 +2296,7 @@ class BucketService extends FolderScopedService {
|
|
|
2180
2296
|
},
|
|
2181
2297
|
excludeFromPrefix: ['prefix'], // Bucket-specific param, not OData
|
|
2182
2298
|
headers,
|
|
2183
|
-
},
|
|
2299
|
+
}, apiRestOptions);
|
|
2184
2300
|
}
|
|
2185
2301
|
async uploadFile(bucketIdOrOptions, path, content, options) {
|
|
2186
2302
|
// Normalize the two overload forms into a single internal shape.
|
|
@@ -2264,9 +2380,10 @@ class BucketService extends FolderScopedService {
|
|
|
2264
2380
|
resourceType: 'Buckets.getReadUri',
|
|
2265
2381
|
fallbackFolderKey: this.config.folderKey,
|
|
2266
2382
|
});
|
|
2383
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2267
2384
|
const queryOptions = {
|
|
2268
2385
|
expiryInMinutes,
|
|
2269
|
-
...addPrefixToKeys(
|
|
2386
|
+
...addPrefixToKeys(apiRestOptions, ODATA_PREFIX, Object.keys(apiRestOptions))
|
|
2270
2387
|
};
|
|
2271
2388
|
return this._getUri(BUCKET_ENDPOINTS.GET_READ_URI(bucketId), bucketId, resolvedPath, headers, queryOptions);
|
|
2272
2389
|
}
|
|
@@ -2386,6 +2503,9 @@ class BucketService extends FolderScopedService {
|
|
|
2386
2503
|
fallbackFolderKey: this.config.folderKey,
|
|
2387
2504
|
});
|
|
2388
2505
|
const transformBucketFile = (file) => transformData(pascalToCamelCaseKeys(file), BucketMap);
|
|
2506
|
+
// Rewrite renamed SDK field names → API names inside OData strings
|
|
2507
|
+
// before delegating.
|
|
2508
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2389
2509
|
return PaginationHelpers.getAll({
|
|
2390
2510
|
serviceAccess: this.createPaginationServiceAccess(),
|
|
2391
2511
|
getEndpoint: () => BUCKET_ENDPOINTS.GET_FILES(bucketId),
|
|
@@ -2402,7 +2522,7 @@ class BucketService extends FolderScopedService {
|
|
|
2402
2522
|
},
|
|
2403
2523
|
excludeFromPrefix: ['directory', 'recursive', 'fileNameRegex'],
|
|
2404
2524
|
headers,
|
|
2405
|
-
}, { ...
|
|
2525
|
+
}, { ...apiRestOptions, directory: '/', recursive: true });
|
|
2406
2526
|
}
|
|
2407
2527
|
/**
|
|
2408
2528
|
* Deletes a file from a bucket
|
|
@@ -2449,9 +2569,10 @@ class BucketService extends FolderScopedService {
|
|
|
2449
2569
|
*/
|
|
2450
2570
|
async _getWriteUri(options) {
|
|
2451
2571
|
const { bucketId, path, expiryInMinutes, headers, ...restOptions } = options;
|
|
2572
|
+
const apiRestOptions = transformOptions(restOptions, BucketMap);
|
|
2452
2573
|
const queryOptions = {
|
|
2453
2574
|
expiryInMinutes,
|
|
2454
|
-
...addPrefixToKeys(
|
|
2575
|
+
...addPrefixToKeys(apiRestOptions, ODATA_PREFIX, Object.keys(apiRestOptions))
|
|
2455
2576
|
};
|
|
2456
2577
|
return this._getUri(BUCKET_ENDPOINTS.GET_WRITE_URI(bucketId), bucketId, path, headers, queryOptions);
|
|
2457
2578
|
}
|