@esri/arcgis-rest-portal 4.4.1 → 4.5.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.
Files changed (65) hide show
  1. package/dist/bundled/portal.esm.js +74 -46
  2. package/dist/bundled/portal.esm.js.map +1 -1
  3. package/dist/bundled/portal.esm.min.js +4 -4
  4. package/dist/bundled/portal.esm.min.js.map +1 -1
  5. package/dist/bundled/portal.umd.js +74 -45
  6. package/dist/bundled/portal.umd.js.map +1 -1
  7. package/dist/bundled/portal.umd.min.js +4 -4
  8. package/dist/bundled/portal.umd.min.js.map +1 -1
  9. package/dist/cjs/index.js +1 -0
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/items/helpers.js.map +1 -1
  12. package/dist/cjs/sharing/access.js +5 -4
  13. package/dist/cjs/sharing/access.js.map +1 -1
  14. package/dist/cjs/sharing/helpers.js +8 -9
  15. package/dist/cjs/sharing/helpers.js.map +1 -1
  16. package/dist/cjs/sharing/share-item-with-group.js +6 -5
  17. package/dist/cjs/sharing/share-item-with-group.js.map +1 -1
  18. package/dist/cjs/sharing/unshare-item-with-group.js +5 -4
  19. package/dist/cjs/sharing/unshare-item-with-group.js.map +1 -1
  20. package/dist/cjs/users/get-user-tags.js +4 -3
  21. package/dist/cjs/users/get-user-tags.js.map +1 -1
  22. package/dist/cjs/users/get-user-url.js +1 -0
  23. package/dist/cjs/users/get-user-url.js.map +1 -1
  24. package/dist/cjs/users/get-user.js +4 -3
  25. package/dist/cjs/users/get-user.js.map +1 -1
  26. package/dist/cjs/users/invitation.js +9 -8
  27. package/dist/cjs/users/invitation.js.map +1 -1
  28. package/dist/cjs/users/notification.js +5 -4
  29. package/dist/cjs/users/notification.js.map +1 -1
  30. package/dist/cjs/users/update.js +3 -2
  31. package/dist/cjs/users/update.js.map +1 -1
  32. package/dist/cjs/util/determine-username.js +28 -0
  33. package/dist/cjs/util/determine-username.js.map +1 -0
  34. package/dist/esm/index.d.ts +1 -0
  35. package/dist/esm/index.js +1 -0
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/items/helpers.d.ts +3 -3
  38. package/dist/esm/items/helpers.js.map +1 -1
  39. package/dist/esm/sharing/access.js +5 -4
  40. package/dist/esm/sharing/access.js.map +1 -1
  41. package/dist/esm/sharing/helpers.d.ts +2 -2
  42. package/dist/esm/sharing/helpers.js +8 -9
  43. package/dist/esm/sharing/helpers.js.map +1 -1
  44. package/dist/esm/sharing/share-item-with-group.js +6 -5
  45. package/dist/esm/sharing/share-item-with-group.js.map +1 -1
  46. package/dist/esm/sharing/unshare-item-with-group.js +5 -4
  47. package/dist/esm/sharing/unshare-item-with-group.js.map +1 -1
  48. package/dist/esm/users/get-user-tags.js +4 -3
  49. package/dist/esm/users/get-user-tags.js.map +1 -1
  50. package/dist/esm/users/get-user-url.d.ts +1 -0
  51. package/dist/esm/users/get-user-url.js +1 -0
  52. package/dist/esm/users/get-user-url.js.map +1 -1
  53. package/dist/esm/users/get-user.d.ts +2 -2
  54. package/dist/esm/users/get-user.js +4 -3
  55. package/dist/esm/users/get-user.js.map +1 -1
  56. package/dist/esm/users/invitation.js +9 -8
  57. package/dist/esm/users/invitation.js.map +1 -1
  58. package/dist/esm/users/notification.js +5 -4
  59. package/dist/esm/users/notification.js.map +1 -1
  60. package/dist/esm/users/update.js +3 -2
  61. package/dist/esm/users/update.js.map +1 -1
  62. package/dist/esm/util/determine-username.d.ts +16 -0
  63. package/dist/esm/util/determine-username.js +24 -0
  64. package/dist/esm/util/determine-username.js.map +1 -0
  65. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/arcgis-rest-portal - v4.4.0 - Apache-2.0
3
- * Copyright (c) 2017-2024 Esri, Inc.
4
- * Sat Jun 15 2024 00:37:50 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/arcgis-rest-portal - v4.4.1 - Apache-2.0
3
+ * Copyright (c) 2017-2025 Esri, Inc.
4
+ * Thu Jan 23 2025 20:04:52 GMT+0000 (Coordinated Universal Time)
5
5
  */
6
6
  import { cleanUrl, request, appendCustomParams, warn } from '@esri/arcgis-rest-request';
7
7
 
@@ -866,15 +866,15 @@ function searchGroupUsers(id, searchOptions) {
866
866
 
867
867
  /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
868
868
  * Apache-2.0 */
869
- function getSharingUrl(requestOptions) {
870
- const username = requestOptions.authentication.username;
871
- const owner = requestOptions.owner || username;
869
+ function getSharingUrl(requestOptions, username) {
870
+ const providedUsername = username || requestOptions.authentication.username; // as any workaround for backward compatibility for discovering username from provided auth method
871
+ const owner = requestOptions.owner || providedUsername;
872
872
  return `${getPortalUrl(requestOptions)}/content/users/${encodeURIComponent(owner)}/items/${requestOptions.id}/share`;
873
873
  }
874
- function isItemOwner(requestOptions) {
875
- const username = requestOptions.authentication.username;
876
- const owner = requestOptions.owner || username;
877
- return owner === username;
874
+ function isItemOwner(requestOptions, username) {
875
+ const providedUsername = username || requestOptions.authentication.username; // as any workaround for backward compatibility for discovering username from provided auth method
876
+ const owner = requestOptions.owner || providedUsername;
877
+ return owner === providedUsername;
878
878
  }
879
879
  /**
880
880
  * Check it the user is a full org_admin
@@ -882,8 +882,7 @@ function isItemOwner(requestOptions) {
882
882
  * @returns Promise resolving in a boolean indicating if the user is an ArcGIS Organization administrator
883
883
  */
884
884
  function isOrgAdmin(requestOptions) {
885
- const session = requestOptions.authentication;
886
- return session.getUser(requestOptions).then((user) => {
885
+ return requestOptions.authentication.getUser().then((user) => {
887
886
  return user && user.role === "org_admin" && !user.roleId;
888
887
  });
889
888
  }
@@ -2075,6 +2074,30 @@ function _combineResults(responses) {
2075
2074
  return combined;
2076
2075
  }
2077
2076
 
2077
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
2078
+ * Apache-2.0 */
2079
+ /**
2080
+ * Used to determine the username to use in a request. Will use the `username` passed in the
2081
+ * `requestOptions` if present, otherwise will use the username from the `authentication` option.
2082
+ * This method is used internally to determine the username to use in a request and is async to
2083
+ * support the case where the username is not immediately available.
2084
+ *
2085
+ * @param requestOptions the requests options
2086
+ * @returns the authentecated users username encoded for use in a URL.
2087
+ */
2088
+ async function determineUsername(requestOptions) {
2089
+ var _a;
2090
+ if (requestOptions.username) {
2091
+ return encodeURIComponent(requestOptions.username);
2092
+ }
2093
+ if ((_a = requestOptions.authentication) === null || _a === void 0 ? void 0 : _a.username) {
2094
+ return encodeURIComponent(requestOptions.authentication.username);
2095
+ }
2096
+ if (requestOptions.authentication) {
2097
+ return requestOptions.authentication.getUsername().then(encodeURIComponent);
2098
+ }
2099
+ }
2100
+
2078
2101
  /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
2079
2102
  * Apache-2.0 */
2080
2103
  /**
@@ -2091,7 +2114,7 @@ function _combineResults(responses) {
2091
2114
  * @param requestOptions - options to pass through in the request
2092
2115
  * @returns A Promise that will resolve with metadata about the user
2093
2116
  */
2094
- function getUser(requestOptions) {
2117
+ async function getUser(requestOptions) {
2095
2118
  let url;
2096
2119
  let options = { httpMethod: "GET" };
2097
2120
  // if a username is passed, assume ArcGIS Online
@@ -2100,8 +2123,8 @@ function getUser(requestOptions) {
2100
2123
  }
2101
2124
  else {
2102
2125
  // if an authenticated session is passed, default to that user/portal unless another username is provided manually
2103
- const username = requestOptions.username || requestOptions.authentication.username;
2104
- url = `${getPortalUrl(requestOptions)}/community/users/${encodeURIComponent(username)}`;
2126
+ const username = await determineUsername(requestOptions);
2127
+ url = `${getPortalUrl(requestOptions)}/community/users/${username}`;
2105
2128
  options = Object.assign(Object.assign({}, requestOptions), options);
2106
2129
  }
2107
2130
  // send the request
@@ -2126,9 +2149,9 @@ function getUser(requestOptions) {
2126
2149
  * @param IGetUserOptions - options to pass through in the request
2127
2150
  * @returns A Promise that will resolve with the user tag array
2128
2151
  */
2129
- function getUserTags(requestOptions) {
2130
- const username = requestOptions.username || requestOptions.authentication.username;
2131
- const url = `${getPortalUrl(requestOptions)}/community/users/${encodeURIComponent(username)}/tags`;
2152
+ async function getUserTags(requestOptions) {
2153
+ const username = await determineUsername(requestOptions);
2154
+ const url = `${getPortalUrl(requestOptions)}/community/users/${username}/tags`;
2132
2155
  // send the request
2133
2156
  return request(url, requestOptions);
2134
2157
  }
@@ -2140,6 +2163,7 @@ function getUserTags(requestOptions) {
2140
2163
  *
2141
2164
  * @param session
2142
2165
  * @returns User url to be used in API requests.
2166
+ * @deprecated This function requires a synchronous `username` on the session object which is not guaranteed. Use `getUser` instead. This function will be removed in the next release.
2143
2167
  */
2144
2168
  function getUserUrl(session) {
2145
2169
  return `${getPortalUrl(session)}/community/users/${encodeURIComponent(session.username)}`;
@@ -2160,9 +2184,9 @@ function getUserUrl(session) {
2160
2184
  * @param requestOptions - options to pass through in the request
2161
2185
  * @returns A Promise that will resolve with the user's invitations
2162
2186
  */
2163
- function getUserInvitations(requestOptions) {
2187
+ async function getUserInvitations(requestOptions) {
2164
2188
  let options = { httpMethod: "GET" };
2165
- const username = encodeURIComponent(requestOptions.authentication.username);
2189
+ const username = await determineUsername(requestOptions);
2166
2190
  const portalUrl = getPortalUrl(requestOptions);
2167
2191
  const url = `${portalUrl}/community/users/${username}/invitations`;
2168
2192
  options = Object.assign(Object.assign({}, requestOptions), options);
@@ -2185,8 +2209,8 @@ function getUserInvitations(requestOptions) {
2185
2209
  * @param requestOptions - options to pass through in the request
2186
2210
  * @returns A Promise that will resolve with the invitation
2187
2211
  */
2188
- function getUserInvitation(requestOptions) {
2189
- const username = encodeURIComponent(requestOptions.authentication.username);
2212
+ async function getUserInvitation(requestOptions) {
2213
+ const username = await determineUsername(requestOptions);
2190
2214
  const portalUrl = getPortalUrl(requestOptions);
2191
2215
  const url = `${portalUrl}/community/users/${username}/invitations/${requestOptions.invitationId}`;
2192
2216
  let options = { httpMethod: "GET" };
@@ -2210,8 +2234,8 @@ function getUserInvitation(requestOptions) {
2210
2234
  * @param requestOptions - Options for the request
2211
2235
  * @returns A Promise that will resolve with the success/failure status of the request
2212
2236
  */
2213
- function acceptInvitation(requestOptions) {
2214
- const username = encodeURIComponent(requestOptions.authentication.username);
2237
+ async function acceptInvitation(requestOptions) {
2238
+ const username = await determineUsername(requestOptions);
2215
2239
  const portalUrl = getPortalUrl(requestOptions);
2216
2240
  const url = `${portalUrl}/community/users/${username}/invitations/${requestOptions.invitationId}/accept`;
2217
2241
  const options = Object.assign({}, requestOptions);
@@ -2233,8 +2257,8 @@ function acceptInvitation(requestOptions) {
2233
2257
  * @param requestOptions - Options for the request
2234
2258
  * @returns A Promise that will resolve with the success/failure status of the request
2235
2259
  */
2236
- function declineInvitation(requestOptions) {
2237
- const username = encodeURIComponent(requestOptions.authentication.username);
2260
+ async function declineInvitation(requestOptions) {
2261
+ const username = await determineUsername(requestOptions);
2238
2262
  const portalUrl = getPortalUrl(requestOptions);
2239
2263
  const url = `${portalUrl}/community/users/${username}/invitations/${requestOptions.invitationId}/decline`;
2240
2264
  const options = Object.assign({}, requestOptions);
@@ -2257,9 +2281,9 @@ function declineInvitation(requestOptions) {
2257
2281
  * @param requestOptions - options to pass through in the request
2258
2282
  * @returns A Promise that will resolve with the user's notifications
2259
2283
  */
2260
- function getUserNotifications(requestOptions) {
2284
+ async function getUserNotifications(requestOptions) {
2261
2285
  let options = { httpMethod: "GET" };
2262
- const username = encodeURIComponent(requestOptions.authentication.username);
2286
+ const username = await determineUsername(requestOptions);
2263
2287
  const portalUrl = getPortalUrl(requestOptions);
2264
2288
  const url = `${portalUrl}/community/users/${username}/notifications`;
2265
2289
  options = Object.assign(Object.assign({}, requestOptions), options);
@@ -2272,8 +2296,8 @@ function getUserNotifications(requestOptions) {
2272
2296
  * @param requestOptions - Options for the request
2273
2297
  * @returns A Promise that will resolve with the success/failure status of the request
2274
2298
  */
2275
- function removeNotification(requestOptions) {
2276
- const username = encodeURIComponent(requestOptions.authentication.username);
2299
+ async function removeNotification(requestOptions) {
2300
+ const username = await determineUsername(requestOptions);
2277
2301
  const portalUrl = getPortalUrl(requestOptions);
2278
2302
  const url = `${portalUrl}/community/users/${username}/notifications/${requestOptions.id}/delete`;
2279
2303
  return request(url, requestOptions);
@@ -2338,9 +2362,10 @@ function searchCommunityUsers(search) {
2338
2362
  * @param requestOptions - options to pass through in the request
2339
2363
  * @returns A Promise that will resolve with metadata about the user
2340
2364
  */
2341
- function updateUser(requestOptions) {
2365
+ async function updateUser(requestOptions) {
2342
2366
  // default to the authenticated username unless another username is provided manually
2343
- const username = requestOptions.user.username || requestOptions.authentication.username;
2367
+ const username = requestOptions.user.username ||
2368
+ (await requestOptions.authentication.getUsername());
2344
2369
  const updateUrl = `${getPortalUrl(requestOptions)}/community/users/${encodeURIComponent(username)}/update`;
2345
2370
  // mixin custom params and the user information, then drop the user info
2346
2371
  requestOptions.params = Object.assign(Object.assign({}, requestOptions.user), requestOptions.params);
@@ -2409,9 +2434,10 @@ async function setUserProperties(username, properties, requestOptions) {
2409
2434
  * @param requestOptions - Options for the request.
2410
2435
  * @returns A Promise that will resolve with the data from the response.
2411
2436
  */
2412
- function setItemAccess(requestOptions) {
2413
- const url = getSharingUrl(requestOptions);
2414
- if (isItemOwner(requestOptions)) {
2437
+ async function setItemAccess(requestOptions) {
2438
+ const username = await requestOptions.authentication.getUsername();
2439
+ const url = getSharingUrl(requestOptions, username);
2440
+ if (isItemOwner(requestOptions, username)) {
2415
2441
  // if the user owns the item, proceed
2416
2442
  return updateItemAccess(url, requestOptions);
2417
2443
  }
@@ -2423,7 +2449,7 @@ function setItemAccess(requestOptions) {
2423
2449
  }
2424
2450
  else {
2425
2451
  // if neither, updating the sharing isnt possible
2426
- throw Error(`This item can not be shared by ${requestOptions.authentication.username}. They are neither the item owner nor an organization admin.`);
2452
+ throw Error(`This item can not be shared by ${username}. They are neither the item owner nor an organization admin.`);
2427
2453
  }
2428
2454
  });
2429
2455
  }
@@ -2504,9 +2530,9 @@ function isItemSharedWithGroup(requestOptions) {
2504
2530
  * @param requestOptions - Options for the request.
2505
2531
  * @returns A Promise that will resolve with the data from the response.
2506
2532
  */
2507
- function shareItemWithGroup(requestOptions) {
2533
+ async function shareItemWithGroup(requestOptions) {
2508
2534
  return isItemSharedWithGroup(requestOptions)
2509
- .then((isShared) => {
2535
+ .then(async (isShared) => {
2510
2536
  if (isShared) {
2511
2537
  // already shared, exit early with success response
2512
2538
  return {
@@ -2515,7 +2541,8 @@ function shareItemWithGroup(requestOptions) {
2515
2541
  notSharedWith: []
2516
2542
  };
2517
2543
  }
2518
- const { authentication: { username }, owner, confirmItemControl } = requestOptions;
2544
+ const { owner, confirmItemControl } = requestOptions;
2545
+ const username = await requestOptions.authentication.getUsername();
2519
2546
  const itemOwner = owner || username;
2520
2547
  // non-item owner
2521
2548
  if (itemOwner !== username) {
@@ -2604,8 +2631,8 @@ function getMembershipAdjustments(currentUser, isSharedEditingGroup, membership,
2604
2631
  }
2605
2632
  return membershipGuarantees;
2606
2633
  }
2607
- function shareToGroup(requestOptions, isAdmin = false, isCrossOrgSharing = false) {
2608
- const username = requestOptions.authentication.username;
2634
+ async function shareToGroup(requestOptions, isAdmin = false, isCrossOrgSharing = false) {
2635
+ const username = await requestOptions.authentication.getUsername();
2609
2636
  const itemOwner = requestOptions.owner || username;
2610
2637
  // decide what url to use
2611
2638
  // default to the non-owner url...
@@ -2742,7 +2769,7 @@ function ensureMembership(currentUser, ownerUser, shouldPromote, errorMessage, r
2742
2769
  * @returns A Promise that will resolve with the data from the response.
2743
2770
  */
2744
2771
  function unshareItemWithGroup(requestOptions) {
2745
- return isItemSharedWithGroup(requestOptions).then((isShared) => {
2772
+ return isItemSharedWithGroup(requestOptions).then(async (isShared) => {
2746
2773
  // not shared
2747
2774
  if (!isShared) {
2748
2775
  // exit early with success response
@@ -2752,7 +2779,8 @@ function unshareItemWithGroup(requestOptions) {
2752
2779
  notUnsharedFrom: []
2753
2780
  });
2754
2781
  }
2755
- const { authentication: { username }, owner } = requestOptions;
2782
+ const { owner } = requestOptions;
2783
+ const username = await requestOptions.authentication.getUsername();
2756
2784
  // next check if the user is a member of the group
2757
2785
  return Promise.all([
2758
2786
  getUserMembership(requestOptions),
@@ -2785,8 +2813,8 @@ function unshareItemWithGroup(requestOptions) {
2785
2813
  });
2786
2814
  });
2787
2815
  }
2788
- function unshareFromGroup(requestOptions) {
2789
- const username = requestOptions.authentication.username;
2816
+ async function unshareFromGroup(requestOptions) {
2817
+ const username = await requestOptions.authentication.getUsername();
2790
2818
  const itemOwner = requestOptions.owner || username;
2791
2819
  // decide what url to use
2792
2820
  // default to the non-owner url...
@@ -2914,5 +2942,5 @@ function getPortalSettings(id, requestOptions) {
2914
2942
  return request(url, options);
2915
2943
  }
2916
2944
 
2917
- export { SearchQueryBuilder, acceptInvitation, addGroupUsers, addItemData, addItemPart, addItemRelationship, addItemResource, bboxToString, cancelItemUpload, commitItemUpload, createFolder, createGroup, createGroupNotification, createItem, createItemInFolder, createOrgNotification, declineInvitation, determineOwner, ensureMembership, exportItem, getGroup, getGroupCategorySchema, getGroupContent, getGroupUsers, getItem, getItemBaseUrl, getItemData, getItemGroups, getItemInfo, getItemMetadata, getItemParts, getItemResource, getItemResources, getItemStatus, getPortal, getPortalSettings, getPortalUrl, getRelatedItems, getSelf, getSharingUrl, getUniqueServiceName, getUser, getUserContent, getUserInvitation, getUserInvitations, getUserMembership, getUserNotifications, getUserProperties, getUserTags, getUserUrl, inviteGroupUsers, isBBox, isItemOwner, isItemSharedWithGroup, isOrgAdmin, isServiceNameAvailable, joinGroup, leaveGroup, moveItem, protectGroup, protectItem, reassignItem, removeFolder, removeGroup, removeGroupUsers, removeItem, removeItemRelationship, removeItemResource, removeNotification, scrubControlChars, searchCommunityUsers, searchGroupContent, searchGroupUsers, searchGroups, searchItems, searchUsers, setItemAccess, setUserProperties, shareItemWithGroup, unprotectGroup, unprotectItem, unshareItemWithGroup, updateGroup, updateItem, updateItemInfo, updateItemResource, updateUser, updateUserMemberships };
2945
+ export { SearchQueryBuilder, acceptInvitation, addGroupUsers, addItemData, addItemPart, addItemRelationship, addItemResource, bboxToString, cancelItemUpload, commitItemUpload, createFolder, createGroup, createGroupNotification, createItem, createItemInFolder, createOrgNotification, declineInvitation, determineOwner, determineUsername, ensureMembership, exportItem, getGroup, getGroupCategorySchema, getGroupContent, getGroupUsers, getItem, getItemBaseUrl, getItemData, getItemGroups, getItemInfo, getItemMetadata, getItemParts, getItemResource, getItemResources, getItemStatus, getPortal, getPortalSettings, getPortalUrl, getRelatedItems, getSelf, getSharingUrl, getUniqueServiceName, getUser, getUserContent, getUserInvitation, getUserInvitations, getUserMembership, getUserNotifications, getUserProperties, getUserTags, getUserUrl, inviteGroupUsers, isBBox, isItemOwner, isItemSharedWithGroup, isOrgAdmin, isServiceNameAvailable, joinGroup, leaveGroup, moveItem, protectGroup, protectItem, reassignItem, removeFolder, removeGroup, removeGroupUsers, removeItem, removeItemRelationship, removeItemResource, removeNotification, scrubControlChars, searchCommunityUsers, searchGroupContent, searchGroupUsers, searchGroups, searchItems, searchUsers, setItemAccess, setUserProperties, shareItemWithGroup, unprotectGroup, unprotectItem, unshareItemWithGroup, updateGroup, updateItem, updateItemInfo, updateItemResource, updateUser, updateUserMemberships };
2918
2946
  //# sourceMappingURL=portal.esm.js.map