@esri/hub-common 9.30.1 → 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/items/index.js +3 -0
- package/dist/es2017/items/index.js.map +1 -1
- package/dist/esm/items/index.js +3 -0
- package/dist/esm/items/index.js.map +1 -1
- package/dist/node/items/index.js +3 -0
- package/dist/node/items/index.js.map +1 -1
- package/dist/types/items/index.d.ts +3 -0
- package/dist/umd/common.umd.js +390 -1
- package/dist/umd/common.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,4 +17,7 @@ export * from "./slugs";
|
|
|
17
17
|
export * from "./normalize-solution-template-item";
|
|
18
18
|
export * from "./setItemThumbnail";
|
|
19
19
|
export * from "./registerBrowserApp";
|
|
20
|
+
export * from "./create-item-from-file";
|
|
21
|
+
export * from "./create-item-from-url";
|
|
22
|
+
export * from "./create-item-from-url-or-file";
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC"}
|
package/dist/esm/items/index.js
CHANGED
|
@@ -17,4 +17,7 @@ export * from "./slugs";
|
|
|
17
17
|
export * from "./normalize-solution-template-item";
|
|
18
18
|
export * from "./setItemThumbnail";
|
|
19
19
|
export * from "./registerBrowserApp";
|
|
20
|
+
export * from "./create-item-from-file";
|
|
21
|
+
export * from "./create-item-from-url";
|
|
22
|
+
export * from "./create-item-from-url-or-file";
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC"}
|
package/dist/node/items/index.js
CHANGED
|
@@ -20,4 +20,7 @@ tslib_1.__exportStar(require("./slugs"), exports);
|
|
|
20
20
|
tslib_1.__exportStar(require("./normalize-solution-template-item"), exports);
|
|
21
21
|
tslib_1.__exportStar(require("./setItemThumbnail"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./registerBrowserApp"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./create-item-from-file"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./create-item-from-url"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./create-item-from-url-or-file"), exports);
|
|
23
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,sEAA4C;AAC5C,wDAA8B;AAC9B,6DAAmC;AACnC,mEAAyC;AACzC,wDAA8B;AAC9B,gEAAsC;AACtC,4DAAkC;AAClC,iEAAuC;AACvC,4DAAkC;AAClC,qEAA2C;AAC3C,uEAA6C;AAC7C,kEAAwC;AACxC,4DAAkC;AAClC,mEAAyC;AACzC,kDAAwB;AACxB,6EAAmD;AACnD,6DAAmC;AACnC,+DAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/items/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,sEAA4C;AAC5C,wDAA8B;AAC9B,6DAAmC;AACnC,mEAAyC;AACzC,wDAA8B;AAC9B,gEAAsC;AACtC,4DAAkC;AAClC,iEAAuC;AACvC,4DAAkC;AAClC,qEAA2C;AAC3C,uEAA6C;AAC7C,kEAAwC;AACxC,4DAAkC;AAClC,mEAAyC;AACzC,kDAAwB;AACxB,6EAAmD;AACnD,6DAAmC;AACnC,+DAAqC;AACrC,kEAAwC;AACxC,iEAAuC;AACvC,yEAA+C"}
|
|
@@ -17,3 +17,6 @@ export * from "./slugs";
|
|
|
17
17
|
export * from "./normalize-solution-template-item";
|
|
18
18
|
export * from "./setItemThumbnail";
|
|
19
19
|
export * from "./registerBrowserApp";
|
|
20
|
+
export * from "./create-item-from-file";
|
|
21
|
+
export * from "./create-item-from-url";
|
|
22
|
+
export * from "./create-item-from-url-or-file";
|
package/dist/umd/common.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/hub-common - v9.30.
|
|
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";
|
|
@@ -11603,6 +11779,216 @@
|
|
|
11603
11779
|
return request(url, options);
|
|
11604
11780
|
}
|
|
11605
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
|
+
|
|
11606
11992
|
/* Copyright (c) 2018-2021 Environmental Systems Research Institute, Inc.
|
|
11607
11993
|
* Apache-2.0 */
|
|
11608
11994
|
/**
|
|
@@ -17145,6 +17531,9 @@
|
|
|
17145
17531
|
exports.convertUrlsToAnchorTags = convertUrlsToAnchorTags;
|
|
17146
17532
|
exports.createExtent = createExtent;
|
|
17147
17533
|
exports.createId = createId;
|
|
17534
|
+
exports.createItemFromFile = createItemFromFile;
|
|
17535
|
+
exports.createItemFromUrl = createItemFromUrl;
|
|
17536
|
+
exports.createItemFromUrlOrFile = createItemFromUrlOrFile;
|
|
17148
17537
|
exports.createModel = createModel;
|
|
17149
17538
|
exports.createOperationPipeline = createOperationPipeline;
|
|
17150
17539
|
exports.createProject = createProject;
|