@esri/hub-common 9.29.0 → 9.31.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.
- package/dist/es2017/content/_internal.js +2 -0
- package/dist/es2017/content/_internal.js.map +1 -1
- package/dist/es2017/content/compose.js +1 -1
- package/dist/es2017/content/compose.js.map +1 -1
- package/dist/es2017/content/get-family.js +1 -1
- package/dist/es2017/content/get-family.js.map +1 -1
- package/dist/es2017/content/index.js +3 -2
- package/dist/es2017/content/index.js.map +1 -1
- package/dist/es2017/items/_enrichments.js +2 -2
- package/dist/es2017/items/_enrichments.js.map +1 -1
- package/dist/es2017/items/_internal/_prepare-upload-requests.js +28 -0
- package/dist/es2017/items/_internal/_prepare-upload-requests.js.map +1 -0
- package/dist/es2017/items/_internal/_wait-for-item-ready.js +23 -0
- package/dist/es2017/items/_internal/_wait-for-item-ready.js.map +1 -0
- package/dist/es2017/items/create-item-from-file.js +52 -0
- package/dist/es2017/items/create-item-from-file.js.map +1 -0
- package/dist/es2017/items/create-item-from-url-or-file.js +46 -0
- package/dist/es2017/items/create-item-from-url-or-file.js.map +1 -0
- package/dist/es2017/items/create-item-from-url.js +16 -0
- package/dist/es2017/items/create-item-from-url.js.map +1 -0
- package/dist/es2017/items/index.js +3 -0
- package/dist/es2017/items/index.js.map +1 -1
- package/dist/esm/content/_internal.js +2 -0
- package/dist/esm/content/_internal.js.map +1 -1
- package/dist/esm/content/compose.js +1 -1
- package/dist/esm/content/compose.js.map +1 -1
- package/dist/esm/content/get-family.js +1 -1
- package/dist/esm/content/get-family.js.map +1 -1
- package/dist/esm/content/index.js +3 -2
- package/dist/esm/content/index.js.map +1 -1
- package/dist/esm/items/_enrichments.js +2 -2
- package/dist/esm/items/_enrichments.js.map +1 -1
- package/dist/esm/items/_internal/_prepare-upload-requests.js +29 -0
- package/dist/esm/items/_internal/_prepare-upload-requests.js.map +1 -0
- package/dist/esm/items/_internal/_wait-for-item-ready.js +37 -0
- package/dist/esm/items/_internal/_wait-for-item-ready.js.map +1 -0
- package/dist/esm/items/create-item-from-file.js +76 -0
- package/dist/esm/items/create-item-from-file.js.map +1 -0
- package/dist/esm/items/create-item-from-url-or-file.js +59 -0
- package/dist/esm/items/create-item-from-url-or-file.js.map +1 -0
- package/dist/esm/items/create-item-from-url.js +25 -0
- package/dist/esm/items/create-item-from-url.js.map +1 -0
- package/dist/esm/items/index.js +3 -0
- package/dist/esm/items/index.js.map +1 -1
- package/dist/node/content/_internal.js +2 -0
- package/dist/node/content/_internal.js.map +1 -1
- package/dist/node/content/compose.js +1 -1
- package/dist/node/content/compose.js.map +1 -1
- package/dist/node/content/get-family.js +1 -1
- package/dist/node/content/get-family.js.map +1 -1
- package/dist/node/content/index.js +3 -2
- package/dist/node/content/index.js.map +1 -1
- package/dist/node/items/_enrichments.js +1 -1
- package/dist/node/items/_enrichments.js.map +1 -1
- package/dist/node/items/_internal/_prepare-upload-requests.js +32 -0
- package/dist/node/items/_internal/_prepare-upload-requests.js.map +1 -0
- package/dist/node/items/_internal/_wait-for-item-ready.js +27 -0
- package/dist/node/items/_internal/_wait-for-item-ready.js.map +1 -0
- package/dist/node/items/create-item-from-file.js +56 -0
- package/dist/node/items/create-item-from-file.js.map +1 -0
- package/dist/node/items/create-item-from-url-or-file.js +50 -0
- package/dist/node/items/create-item-from-url-or-file.js.map +1 -0
- package/dist/node/items/create-item-from-url.js +20 -0
- package/dist/node/items/create-item-from-url.js.map +1 -0
- package/dist/node/items/index.js +3 -0
- package/dist/node/items/index.js.map +1 -1
- package/dist/types/content/index.d.ts +2 -2
- package/dist/types/items/_internal/_prepare-upload-requests.d.ts +16 -0
- package/dist/types/items/_internal/_wait-for-item-ready.d.ts +10 -0
- package/dist/types/items/create-item-from-file.d.ts +13 -0
- package/dist/types/items/create-item-from-url-or-file.d.ts +18 -0
- package/dist/types/items/create-item-from-url.d.ts +12 -0
- package/dist/types/items/index.d.ts +3 -0
- package/dist/umd/common.umd.js +406 -6
- package/dist/umd/common.umd.js.map +1 -1
- package/package.json +1 -2
- package/dist/umd/common.umd.min.js +0 -2
- package/dist/umd/common.umd.min.js.map +0 -1
package/dist/umd/common.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/hub-common - v9.
|
|
2
|
+
* @esri/hub-common - v9.30.1 - Thu May 12 2022 14:13:55 GMT+0000 (Coordinated Universal Time)
|
|
3
3
|
* Copyright (c) 2022 Environmental Systems Research Institute, Inc.
|
|
4
4
|
* Apache-2.0
|
|
5
5
|
*/
|
|
@@ -3509,6 +3509,29 @@
|
|
|
3509
3509
|
var url = getItemBaseUrl(id, requestOptions) + "/groups";
|
|
3510
3510
|
return request(url, requestOptions);
|
|
3511
3511
|
}
|
|
3512
|
+
/**
|
|
3513
|
+
* ```js
|
|
3514
|
+
* import { getItemStatus } from "@esri/arcgis-rest-portal";
|
|
3515
|
+
* //
|
|
3516
|
+
* getItemStatus({
|
|
3517
|
+
* id: "30e5fe3149c34df1ba922e6f5bbf808f",
|
|
3518
|
+
* authentication
|
|
3519
|
+
* })
|
|
3520
|
+
* .then(response)
|
|
3521
|
+
* ```
|
|
3522
|
+
* Inquire about status when publishing an item, adding an item in async mode, or adding with a multipart upload. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/status.htm) for more information.
|
|
3523
|
+
*
|
|
3524
|
+
* @param id - The Id of the item to get status for.
|
|
3525
|
+
* @param requestOptions - Options for the request
|
|
3526
|
+
* @returns A Promise to get the item status.
|
|
3527
|
+
*/
|
|
3528
|
+
function getItemStatus(requestOptions) {
|
|
3529
|
+
return determineOwner(requestOptions).then(function (owner) {
|
|
3530
|
+
var url = getPortalUrl$1(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/status";
|
|
3531
|
+
var options = appendCustomParams(requestOptions, ["jobId", "jobType"], { params: __assign({}, requestOptions.params) });
|
|
3532
|
+
return request(url, options);
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3512
3535
|
/**
|
|
3513
3536
|
* ```
|
|
3514
3537
|
* import { getItemInfo } from "@esri/arcgis-rest-portal";
|
|
@@ -3611,6 +3634,27 @@
|
|
|
3611
3634
|
|
|
3612
3635
|
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
3613
3636
|
* Apache-2.0 */
|
|
3637
|
+
function getSharingUrl(requestOptions) {
|
|
3638
|
+
var username = requestOptions.authentication.username;
|
|
3639
|
+
var owner = requestOptions.owner || username;
|
|
3640
|
+
return getPortalUrl$1(requestOptions) + "/content/users/" + encodeURIComponent(owner) + "/items/" + requestOptions.id + "/share";
|
|
3641
|
+
}
|
|
3642
|
+
function isItemOwner(requestOptions) {
|
|
3643
|
+
var username = requestOptions.authentication.username;
|
|
3644
|
+
var owner = requestOptions.owner || username;
|
|
3645
|
+
return owner === username;
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* Check it the user is a full org_admin
|
|
3649
|
+
* @param requestOptions
|
|
3650
|
+
* @returns Promise resolving in a boolean indicating if the user is an ArcGIS Organization administrator
|
|
3651
|
+
*/
|
|
3652
|
+
function isOrgAdmin(requestOptions) {
|
|
3653
|
+
var session = requestOptions.authentication;
|
|
3654
|
+
return session.getUser(requestOptions).then(function (user) {
|
|
3655
|
+
return user && user.role === "org_admin" && !user.roleId;
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3614
3658
|
/**
|
|
3615
3659
|
* Get the User Membership for a particular group. Use this if all you have is the groupId.
|
|
3616
3660
|
* If you have the group object, check the `userMembership.memberType` property instead of calling this method.
|
|
@@ -4105,6 +4149,83 @@
|
|
|
4105
4149
|
return genericSearch(search, "item");
|
|
4106
4150
|
}
|
|
4107
4151
|
|
|
4152
|
+
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
|
|
4153
|
+
* Apache-2.0 */
|
|
4154
|
+
/**
|
|
4155
|
+
* ```js
|
|
4156
|
+
* import { addItemPart } from "@esri/arcgis-rest-portal";
|
|
4157
|
+
* //
|
|
4158
|
+
* addItemPart({
|
|
4159
|
+
* id: "30e5fe3149c34df1ba922e6f5bbf808f",
|
|
4160
|
+
* file: data,
|
|
4161
|
+
* partNum: 1,
|
|
4162
|
+
* authentication
|
|
4163
|
+
* })
|
|
4164
|
+
* .then(response)
|
|
4165
|
+
* ```
|
|
4166
|
+
* Add Item Part allows the caller to upload a file part when doing an add or update item operation in multipart mode. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/add-item-part.htm) for more information.
|
|
4167
|
+
*
|
|
4168
|
+
* @param requestOptions - Options for the request
|
|
4169
|
+
* @returns A Promise to add the item part status.
|
|
4170
|
+
*/
|
|
4171
|
+
function addItemPart(requestOptions) {
|
|
4172
|
+
var partNum = requestOptions.partNum;
|
|
4173
|
+
if (!Number.isInteger(partNum) || partNum < 1 || partNum > 10000) {
|
|
4174
|
+
return Promise.reject(new Error('The part number must be an integer between 1 to 10000, inclusive.'));
|
|
4175
|
+
}
|
|
4176
|
+
return determineOwner(requestOptions).then(function (owner) {
|
|
4177
|
+
// AGO adds the "partNum" parameter in the query string, not in the body
|
|
4178
|
+
var url = getPortalUrl$1(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/addPart?partNum=" + partNum;
|
|
4179
|
+
var options = appendCustomParams(requestOptions, ["file"], { params: __assign({}, requestOptions.params) });
|
|
4180
|
+
return request(url, options);
|
|
4181
|
+
});
|
|
4182
|
+
}
|
|
4183
|
+
/**
|
|
4184
|
+
* ```js
|
|
4185
|
+
* import { commitItemUpload } from "@esri/arcgis-rest-portal";
|
|
4186
|
+
* //
|
|
4187
|
+
* commitItemUpload({
|
|
4188
|
+
* id: "30e5fe3149c34df1ba922e6f5bbf808f",
|
|
4189
|
+
* authentication
|
|
4190
|
+
* })
|
|
4191
|
+
* .then(response)
|
|
4192
|
+
* ```
|
|
4193
|
+
* Commit is called once all parts are uploaded during a multipart Add Item or Update Item operation. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/commit.htm) for more information.
|
|
4194
|
+
*
|
|
4195
|
+
* @param requestOptions - Options for the request
|
|
4196
|
+
* @returns A Promise to get the commit result.
|
|
4197
|
+
*/
|
|
4198
|
+
function commitItemUpload(requestOptions) {
|
|
4199
|
+
return determineOwner(requestOptions).then(function (owner) {
|
|
4200
|
+
var url = getPortalUrl$1(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/commit";
|
|
4201
|
+
var options = appendCustomParams(requestOptions, [], {
|
|
4202
|
+
params: __assign(__assign({}, requestOptions.params), serializeItem(requestOptions.item))
|
|
4203
|
+
});
|
|
4204
|
+
return request(url, options);
|
|
4205
|
+
});
|
|
4206
|
+
}
|
|
4207
|
+
/**
|
|
4208
|
+
* ```js
|
|
4209
|
+
* import { cancelItemUpload } from "@esri/arcgis-rest-portal";
|
|
4210
|
+
* //
|
|
4211
|
+
* cancelItemUpload({
|
|
4212
|
+
* id: "30e5fe3149c34df1ba922e6f5bbf808f",
|
|
4213
|
+
* authentication
|
|
4214
|
+
* })
|
|
4215
|
+
* .then(response)
|
|
4216
|
+
* ```
|
|
4217
|
+
* Cancels a multipart upload on an item. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/cancel.htm) for more information.
|
|
4218
|
+
*
|
|
4219
|
+
* @param requestOptions - Options for the request
|
|
4220
|
+
* @returns A Promise to get the commit result.
|
|
4221
|
+
*/
|
|
4222
|
+
function cancelItemUpload(requestOptions) {
|
|
4223
|
+
return determineOwner(requestOptions).then(function (owner) {
|
|
4224
|
+
var url = getPortalUrl$1(requestOptions) + "/content/users/" + owner + "/items/" + requestOptions.id + "/cancel";
|
|
4225
|
+
return request(url, requestOptions);
|
|
4226
|
+
});
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4108
4229
|
/* Copyright (c) 2019 Environmental Systems Research Institute, Inc.
|
|
4109
4230
|
* Apache-2.0 */
|
|
4110
4231
|
function chunk(array, size) {
|
|
@@ -4520,6 +4641,61 @@
|
|
|
4520
4641
|
return genericSearch(search, "user");
|
|
4521
4642
|
}
|
|
4522
4643
|
|
|
4644
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
4645
|
+
* Apache-2.0 */
|
|
4646
|
+
/**
|
|
4647
|
+
* ```js
|
|
4648
|
+
* import { setItemAccess } from "@esri/arcgis-rest-portal";
|
|
4649
|
+
* //
|
|
4650
|
+
* setItemAccess({
|
|
4651
|
+
* id: "abc123",
|
|
4652
|
+
* access: "public", // 'org' || 'private'
|
|
4653
|
+
* authentication: session
|
|
4654
|
+
* })
|
|
4655
|
+
* ```
|
|
4656
|
+
* Change who is able to access an item.
|
|
4657
|
+
*
|
|
4658
|
+
* @param requestOptions - Options for the request.
|
|
4659
|
+
* @returns A Promise that will resolve with the data from the response.
|
|
4660
|
+
*/
|
|
4661
|
+
function setItemAccess(requestOptions) {
|
|
4662
|
+
var url = getSharingUrl(requestOptions);
|
|
4663
|
+
if (isItemOwner(requestOptions)) {
|
|
4664
|
+
// if the user owns the item, proceed
|
|
4665
|
+
return updateItemAccess(url, requestOptions);
|
|
4666
|
+
}
|
|
4667
|
+
else {
|
|
4668
|
+
// otherwise we need to check to see if they are an organization admin
|
|
4669
|
+
return isOrgAdmin(requestOptions).then(function (admin) {
|
|
4670
|
+
if (admin) {
|
|
4671
|
+
return updateItemAccess(url, requestOptions);
|
|
4672
|
+
}
|
|
4673
|
+
else {
|
|
4674
|
+
// if neither, updating the sharing isnt possible
|
|
4675
|
+
throw Error("This item can not be shared by " + requestOptions.authentication.username + ". They are neither the item owner nor an organization admin.");
|
|
4676
|
+
}
|
|
4677
|
+
});
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
function updateItemAccess(url, requestOptions) {
|
|
4681
|
+
requestOptions.params = __assign({ org: false, everyone: false }, requestOptions.params);
|
|
4682
|
+
// if the user wants to make the item private, it needs to be unshared from any/all groups as well
|
|
4683
|
+
if (requestOptions.access === "private") {
|
|
4684
|
+
requestOptions.params.groups = " ";
|
|
4685
|
+
}
|
|
4686
|
+
if (requestOptions.access === "org") {
|
|
4687
|
+
requestOptions.params.org = true;
|
|
4688
|
+
}
|
|
4689
|
+
// if sharing with everyone, share with the entire organization as well.
|
|
4690
|
+
if (requestOptions.access === "public") {
|
|
4691
|
+
// this is how the ArcGIS Online Home app sets public access
|
|
4692
|
+
// setting org = true instead of account = true will cancel out all sharing
|
|
4693
|
+
requestOptions.params.account = true;
|
|
4694
|
+
requestOptions.params.everyone = true;
|
|
4695
|
+
}
|
|
4696
|
+
return request(url, requestOptions);
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4523
4699
|
/**
|
|
4524
4700
|
* ```js
|
|
4525
4701
|
* import { isItemSharedWithGroup } from "@esri/arcgis-rest-portal";
|
|
@@ -6371,7 +6547,7 @@
|
|
|
6371
6547
|
var family;
|
|
6372
6548
|
// override default behavior for the rows that are highlighted in yellow here:
|
|
6373
6549
|
// https://esriis.sharepoint.com/:x:/r/sites/ArcGISHub/_layouts/15/Doc.aspx?sourcedoc=%7BADA1C9DC-4F6C-4DE4-92C6-693EF9571CFA%7D&file=Hub%20Routes.xlsx&nav=MTBfe0VENEREQzI4LUZFMDctNEI0Ri04NjcyLThCQUE2MTA0MEZGRn1fezIwMTIwMEJFLTA4MEQtNEExRC05QzA4LTE5MTAzOUQwMEE1RH0&action=default&mobileredirect=true&cid=df1c874b-c367-4cea-bc13-7bebfad3f2ac
|
|
6374
|
-
switch (
|
|
6550
|
+
switch (type.toLowerCase()) {
|
|
6375
6551
|
case "image service":
|
|
6376
6552
|
family = "dataset";
|
|
6377
6553
|
break;
|
|
@@ -6522,6 +6698,8 @@
|
|
|
6522
6698
|
// deployed solutions go to the generic content route
|
|
6523
6699
|
hubUrl = "/content/" + identifier;
|
|
6524
6700
|
}
|
|
6701
|
+
// TODO: I think this is a bug. The line below should be w/in else
|
|
6702
|
+
// in order to avoid overwriting the above for deployed solutions, right?
|
|
6525
6703
|
// others go to the solution about route
|
|
6526
6704
|
hubUrl = "/templates/" + identifier + "/about";
|
|
6527
6705
|
}
|
|
@@ -7200,7 +7378,7 @@
|
|
|
7200
7378
|
*/
|
|
7201
7379
|
var getContentTypeIcon = function (contentType) {
|
|
7202
7380
|
var _a;
|
|
7203
|
-
var type = camelize(contentType
|
|
7381
|
+
var type = camelize(contentType);
|
|
7204
7382
|
var iconMap = {
|
|
7205
7383
|
appbuilderExtension: "file",
|
|
7206
7384
|
appbuilderWidgetPackage: "widgets-source",
|
|
@@ -8794,7 +8972,7 @@
|
|
|
8794
8972
|
var enrichServer = function (input) {
|
|
8795
8973
|
var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
|
|
8796
8974
|
var opId = stack.start("enrichServer");
|
|
8797
|
-
var url = data.item.url;
|
|
8975
|
+
var url = parseServiceUrl(data.item.url);
|
|
8798
8976
|
var options = __assign(__assign({}, requestOptions), { url: url });
|
|
8799
8977
|
return getService(options)
|
|
8800
8978
|
.then(function (server) {
|
|
@@ -9603,11 +9781,12 @@
|
|
|
9603
9781
|
return isProxied ? "CSV" : camelize(contentType || "");
|
|
9604
9782
|
};
|
|
9605
9783
|
/**
|
|
9606
|
-
* returns a new content that has the specified hubId and updated identifier
|
|
9784
|
+
* DEPRECATED returns a new content that has the specified hubId and updated identifier
|
|
9607
9785
|
* @param content orignal content
|
|
9608
9786
|
* @param hubId new hubId
|
|
9609
9787
|
* @returns new content
|
|
9610
9788
|
*/
|
|
9789
|
+
/* istanbul ignore next DEPRECATED and no longer in use */
|
|
9611
9790
|
var setContentHubId = function (content, hubId) {
|
|
9612
9791
|
var id = content.id, slug = content.slug;
|
|
9613
9792
|
// get the identifier which is based on hubId
|
|
@@ -9620,7 +9799,7 @@
|
|
|
9620
9799
|
});
|
|
9621
9800
|
};
|
|
9622
9801
|
/**
|
|
9623
|
-
* Calculates the relative and absolute urls for a given content on a specific site
|
|
9802
|
+
* DEPRECATED: Calculates the relative and absolute urls for a given content on a specific site
|
|
9624
9803
|
*
|
|
9625
9804
|
* @param content
|
|
9626
9805
|
* @param siteModel
|
|
@@ -9665,6 +9844,10 @@
|
|
|
9665
9844
|
* instead of throwing INVALID_CHARACTER_ERR we return null.
|
|
9666
9845
|
*/
|
|
9667
9846
|
function atob(data) {
|
|
9847
|
+
if (arguments.length === 0) {
|
|
9848
|
+
throw new TypeError("1 argument required, but only 0 present.");
|
|
9849
|
+
}
|
|
9850
|
+
|
|
9668
9851
|
// Web IDL requires DOMStrings to just be converted using ECMAScript
|
|
9669
9852
|
// ToString, which in our case amounts to using a template literal.
|
|
9670
9853
|
data = `${data}`;
|
|
@@ -9761,6 +9944,10 @@
|
|
|
9761
9944
|
* RFC 4648.
|
|
9762
9945
|
*/
|
|
9763
9946
|
function btoa(s) {
|
|
9947
|
+
if (arguments.length === 0) {
|
|
9948
|
+
throw new TypeError("1 argument required, but only 0 present.");
|
|
9949
|
+
}
|
|
9950
|
+
|
|
9764
9951
|
let i;
|
|
9765
9952
|
// String conversion as required by Web IDL.
|
|
9766
9953
|
s = `${s}`;
|
|
@@ -11592,6 +11779,216 @@
|
|
|
11592
11779
|
return request(url, options);
|
|
11593
11780
|
}
|
|
11594
11781
|
|
|
11782
|
+
/**
|
|
11783
|
+
* Takes a file, file owner, and file AGO item id along with a size limit
|
|
11784
|
+
* Then chunks the file up based on that file limit.
|
|
11785
|
+
* The chunks are added to addItemPart calls and added to a queue array.
|
|
11786
|
+
*
|
|
11787
|
+
* @export
|
|
11788
|
+
* @param {*} file File to be uploaded
|
|
11789
|
+
* @param {string} owner file owner
|
|
11790
|
+
* @param {string} id file ID from AGO
|
|
11791
|
+
* @param {number} sizeLimit How large should the chunks be?
|
|
11792
|
+
* @param {IUserRequestOptions} requestOptions
|
|
11793
|
+
* @return {*} {IBatch}
|
|
11794
|
+
*/
|
|
11795
|
+
function _prepareUploadRequests(file, owner, id, sizeLimit, requestOptions) {
|
|
11796
|
+
var queue = [];
|
|
11797
|
+
// part number starts from 1
|
|
11798
|
+
var partIndex = 1;
|
|
11799
|
+
var sizeIndex = 0;
|
|
11800
|
+
// Slice the file data and create an upload request for each part
|
|
11801
|
+
while (sizeIndex < file.size) {
|
|
11802
|
+
queue.push(__assign({ file: file.slice(sizeIndex, sizeIndex + sizeLimit, file.type), owner: owner,
|
|
11803
|
+
id: id, partNum: partIndex }, requestOptions));
|
|
11804
|
+
partIndex += 1;
|
|
11805
|
+
sizeIndex += sizeLimit;
|
|
11806
|
+
}
|
|
11807
|
+
return queue.reverse();
|
|
11808
|
+
}
|
|
11809
|
+
|
|
11810
|
+
/**
|
|
11811
|
+
* Creates an item in online from a local file/item.
|
|
11812
|
+
* Upload is multithreaded as the item is chunked up.
|
|
11813
|
+
*
|
|
11814
|
+
* @export
|
|
11815
|
+
* @param {IItemAdd} item Item to be uploaded into online.
|
|
11816
|
+
* @param {IUserRequestOptions} requestOptions
|
|
11817
|
+
* @return {*} {Promise<string>} Newly created item id
|
|
11818
|
+
*/
|
|
11819
|
+
function createItemFromFile(item, requestOptions) {
|
|
11820
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11821
|
+
var file, createResult, itemId, sizeLimit, uploadQueue, e_1;
|
|
11822
|
+
var _this = this;
|
|
11823
|
+
return __generator(this, function (_a) {
|
|
11824
|
+
switch (_a.label) {
|
|
11825
|
+
case 0:
|
|
11826
|
+
file = cloneObject$1(item.file);
|
|
11827
|
+
// and remove the file object so
|
|
11828
|
+
// that it won't trigger the direct upload at the createContent request
|
|
11829
|
+
delete item.file;
|
|
11830
|
+
return [4 /*yield*/, createItem(__assign({ item: item, filename: file.name, async: true, multipart: true, overwrite: true }, requestOptions))];
|
|
11831
|
+
case 1:
|
|
11832
|
+
createResult = _a.sent();
|
|
11833
|
+
itemId = createResult.id;
|
|
11834
|
+
_a.label = 2;
|
|
11835
|
+
case 2:
|
|
11836
|
+
_a.trys.push([2, 5, , 7]);
|
|
11837
|
+
sizeLimit = 6 * 1000 * 1000;
|
|
11838
|
+
uploadQueue = _prepareUploadRequests(file, item.owner, itemId, sizeLimit, requestOptions);
|
|
11839
|
+
// execute up to 5 concurrent requests
|
|
11840
|
+
return [4 /*yield*/, batch(uploadQueue,
|
|
11841
|
+
// We are doing this to catch individual response failures
|
|
11842
|
+
// and throwing them to stop further xhr's
|
|
11843
|
+
function (opts) { return __awaiter(_this, void 0, void 0, function () {
|
|
11844
|
+
var resp;
|
|
11845
|
+
return __generator(this, function (_a) {
|
|
11846
|
+
switch (_a.label) {
|
|
11847
|
+
case 0: return [4 /*yield*/, addItemPart(opts)];
|
|
11848
|
+
case 1:
|
|
11849
|
+
resp = _a.sent();
|
|
11850
|
+
// If the response did not return with success then throw an error
|
|
11851
|
+
if (!resp.success) {
|
|
11852
|
+
throw new Error("addItemPart failed");
|
|
11853
|
+
}
|
|
11854
|
+
return [2 /*return*/];
|
|
11855
|
+
}
|
|
11856
|
+
});
|
|
11857
|
+
}); }, 5)];
|
|
11858
|
+
case 3:
|
|
11859
|
+
// execute up to 5 concurrent requests
|
|
11860
|
+
_a.sent();
|
|
11861
|
+
// Commit is called once all parts are uploaded during a multipart add item or update item operation.
|
|
11862
|
+
return [4 /*yield*/, commitItemUpload(__assign({ id: itemId, item: item, owner: item.owner }, requestOptions))];
|
|
11863
|
+
case 4:
|
|
11864
|
+
// Commit is called once all parts are uploaded during a multipart add item or update item operation.
|
|
11865
|
+
_a.sent();
|
|
11866
|
+
return [3 /*break*/, 7];
|
|
11867
|
+
case 5:
|
|
11868
|
+
e_1 = _a.sent();
|
|
11869
|
+
// If an error is thrown then cancel item upload
|
|
11870
|
+
return [4 /*yield*/, cancelItemUpload(__assign({ id: itemId, owner: item.owner }, requestOptions))];
|
|
11871
|
+
case 6:
|
|
11872
|
+
// If an error is thrown then cancel item upload
|
|
11873
|
+
_a.sent();
|
|
11874
|
+
throw e_1;
|
|
11875
|
+
case 7: return [2 /*return*/, createResult];
|
|
11876
|
+
}
|
|
11877
|
+
});
|
|
11878
|
+
});
|
|
11879
|
+
}
|
|
11880
|
+
|
|
11881
|
+
/**
|
|
11882
|
+
* Create AGO item from a URL
|
|
11883
|
+
*
|
|
11884
|
+
* @export
|
|
11885
|
+
* @param {IItemAdd} item Item to be uploaded into online.
|
|
11886
|
+
* @param {IUserRequestOptions} requestOptions
|
|
11887
|
+
* @return {*} {Promise<string>} Newly created item ID
|
|
11888
|
+
*/
|
|
11889
|
+
function createItemFromUrl(item, requestOptions) {
|
|
11890
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11891
|
+
var createResult;
|
|
11892
|
+
return __generator(this, function (_a) {
|
|
11893
|
+
switch (_a.label) {
|
|
11894
|
+
case 0: return [4 /*yield*/, createItem(__assign({ item: item, owner: item.owner, file: item.file, dataUrl: item.dataUrl, text: item.text, multipart: item.multipart, async: item.async }, requestOptions))];
|
|
11895
|
+
case 1:
|
|
11896
|
+
createResult = _a.sent();
|
|
11897
|
+
// return the newly created item id
|
|
11898
|
+
return [2 /*return*/, createResult];
|
|
11899
|
+
}
|
|
11900
|
+
});
|
|
11901
|
+
});
|
|
11902
|
+
}
|
|
11903
|
+
|
|
11904
|
+
function delay(milliseconds) {
|
|
11905
|
+
return new Promise(function (resolve) { return setTimeout(resolve, milliseconds); });
|
|
11906
|
+
}
|
|
11907
|
+
/**
|
|
11908
|
+
* Helper function which takes an itemId and checks the status
|
|
11909
|
+
* of the item every 2 seconds until it is either complete or failed.
|
|
11910
|
+
*
|
|
11911
|
+
* @export
|
|
11912
|
+
* @param {string} itemId AGO item id
|
|
11913
|
+
* @param {IUserRequestOptions} requestOptions
|
|
11914
|
+
*/
|
|
11915
|
+
function _waitForItemReady(itemId, requestOptions) {
|
|
11916
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11917
|
+
var statusResult;
|
|
11918
|
+
return __generator(this, function (_a) {
|
|
11919
|
+
switch (_a.label) {
|
|
11920
|
+
case 0: return [4 /*yield*/, delay(2000)];
|
|
11921
|
+
case 1:
|
|
11922
|
+
_a.sent();
|
|
11923
|
+
return [4 /*yield*/, getItemStatus(__assign({ id: itemId }, requestOptions))];
|
|
11924
|
+
case 2:
|
|
11925
|
+
statusResult = _a.sent();
|
|
11926
|
+
if (statusResult.status === "failed") {
|
|
11927
|
+
throw new Error(statusResult.statusMessage);
|
|
11928
|
+
}
|
|
11929
|
+
_a.label = 3;
|
|
11930
|
+
case 3:
|
|
11931
|
+
if (statusResult.status !== "completed") return [3 /*break*/, 0];
|
|
11932
|
+
_a.label = 4;
|
|
11933
|
+
case 4: return [2 /*return*/];
|
|
11934
|
+
}
|
|
11935
|
+
});
|
|
11936
|
+
});
|
|
11937
|
+
}
|
|
11938
|
+
|
|
11939
|
+
/**
|
|
11940
|
+
* Creates an item in online from either url or file.
|
|
11941
|
+
* Once created we wait for the item to be ready (or throw an error if creation failed)
|
|
11942
|
+
* If access is not private then we make a call to update that.
|
|
11943
|
+
*
|
|
11944
|
+
* @export
|
|
11945
|
+
* @param {ICreateItemFromUrlOrFileOptions} createItemFromUrlOrFileOptions Input params (item, groups?, requestoptions)
|
|
11946
|
+
* @return {*} {Promise<string>} AGO item id
|
|
11947
|
+
*/
|
|
11948
|
+
function createItemFromUrlOrFile(createItemFromUrlOrFileOptions) {
|
|
11949
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11950
|
+
var item, groups, userRequestOptions, shouldWaitForItemReady, createdItem, failSafeShare_1;
|
|
11951
|
+
return __generator(this, function (_a) {
|
|
11952
|
+
switch (_a.label) {
|
|
11953
|
+
case 0:
|
|
11954
|
+
item = createItemFromUrlOrFileOptions.item, groups = createItemFromUrlOrFileOptions.groups, userRequestOptions = __rest(createItemFromUrlOrFileOptions, ["item", "groups"]);
|
|
11955
|
+
shouldWaitForItemReady = item.dataUrl || item.file;
|
|
11956
|
+
if (!item.file) return [3 /*break*/, 2];
|
|
11957
|
+
return [4 /*yield*/, createItemFromFile(item, userRequestOptions)];
|
|
11958
|
+
case 1:
|
|
11959
|
+
createdItem = _a.sent();
|
|
11960
|
+
return [3 /*break*/, 4];
|
|
11961
|
+
case 2: return [4 /*yield*/, createItemFromUrl(item, userRequestOptions)];
|
|
11962
|
+
case 3:
|
|
11963
|
+
createdItem = _a.sent();
|
|
11964
|
+
_a.label = 4;
|
|
11965
|
+
case 4:
|
|
11966
|
+
if (!shouldWaitForItemReady) return [3 /*break*/, 6];
|
|
11967
|
+
return [4 /*yield*/, _waitForItemReady(createdItem.id, userRequestOptions)];
|
|
11968
|
+
case 5:
|
|
11969
|
+
_a.sent();
|
|
11970
|
+
_a.label = 6;
|
|
11971
|
+
case 6:
|
|
11972
|
+
if (!(item.access !== "private")) return [3 /*break*/, 8];
|
|
11973
|
+
return [4 /*yield*/, setItemAccess(__assign({ id: createdItem.id, owner: item.owner, access: item.access }, userRequestOptions))];
|
|
11974
|
+
case 7:
|
|
11975
|
+
_a.sent();
|
|
11976
|
+
_a.label = 8;
|
|
11977
|
+
case 8:
|
|
11978
|
+
if (!(groups === null || groups === void 0 ? void 0 : groups.length)) return [3 /*break*/, 10];
|
|
11979
|
+
failSafeShare_1 = failSafe(shareItemWithGroup);
|
|
11980
|
+
return [4 /*yield*/, Promise.all(groups.map(function (group) {
|
|
11981
|
+
return failSafeShare_1(__assign({ id: createdItem.id, owner: item.owner, groupId: group.id, confirmItemControl: isUpdateGroup(group) }, userRequestOptions));
|
|
11982
|
+
}))];
|
|
11983
|
+
case 9:
|
|
11984
|
+
_a.sent();
|
|
11985
|
+
_a.label = 10;
|
|
11986
|
+
case 10: return [2 /*return*/, createdItem];
|
|
11987
|
+
}
|
|
11988
|
+
});
|
|
11989
|
+
});
|
|
11990
|
+
}
|
|
11991
|
+
|
|
11595
11992
|
/* Copyright (c) 2018-2021 Environmental Systems Research Institute, Inc.
|
|
11596
11993
|
* Apache-2.0 */
|
|
11597
11994
|
/**
|
|
@@ -17134,6 +17531,9 @@
|
|
|
17134
17531
|
exports.convertUrlsToAnchorTags = convertUrlsToAnchorTags;
|
|
17135
17532
|
exports.createExtent = createExtent;
|
|
17136
17533
|
exports.createId = createId;
|
|
17534
|
+
exports.createItemFromFile = createItemFromFile;
|
|
17535
|
+
exports.createItemFromUrl = createItemFromUrl;
|
|
17536
|
+
exports.createItemFromUrlOrFile = createItemFromUrlOrFile;
|
|
17137
17537
|
exports.createModel = createModel;
|
|
17138
17538
|
exports.createOperationPipeline = createOperationPipeline;
|
|
17139
17539
|
exports.createProject = createProject;
|