@esri/solution-common
Version:
Provides general helper functions for @esri/solution.js.
304 lines (303 loc) • 15.1 kB
TypeScript
/** @license
* Copyright 2018 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { IGroupCategorySchema, IRelatedItems } from "./interfaces";
import { IGetRelatedItemsResponse, IGroup, IItem, IPagingParams, IPortal, ItemRelationshipType, IUser, UserSession } from "./arcgisRestJS";
export declare function checkJsonForError(json: any): boolean;
export declare function getPortal(id: string, authentication: UserSession): Promise<IPortal>;
/**
* Get the urls available on the portal self.
*
* @param authentication Credentials for the request to AGO
* @returns List of http and https helper urls
*/
export declare function getPortalUrls(authentication: UserSession): Promise<IPortal>;
export declare function getUser(authentication: UserSession): Promise<IUser>;
export declare function getUsername(authentication: UserSession): Promise<string>;
export declare function getFoldersAndGroups(authentication: UserSession): Promise<any>;
/**
* Gets a Blob from a web site and casts it as a file using the supplied name.
*
* @param url Address of Blob
* @param filename Name to use for file
* @param authentication Credentials for the request
* @returns Promise that will resolve with a File, undefined if the Blob is null, or an AGO-style JSON failure response
*/
export declare function getBlobAsFile(url: string, filename: string, authentication: UserSession, ignoreErrors?: number[], mimeType?: string): Promise<File>;
/**
* Gets a Blob from a web site and checks for a JSON error packet in the Blob.
*
* @param url Address of Blob
* @param authentication Credentials for the request
* @param ignoreErrors List of HTTP error codes that should be ignored
* @returns Promise that will resolve with Blob or an AGO-REST JSON failure response
*/
export declare function getBlobCheckForError(url: string, authentication: UserSession, ignoreErrors?: number[]): Promise<Blob>;
/**
* Get the servers available on the Enterprise portal.
*
* @param portalRestUrl URL of the portal REST endpoint, e.g., "https://gisserver.domain.com/server/rest/services"
* @param authentication Credentials for the request to AGO
* @returns List of servers available on the portal
*/
export declare function getEnterpriseServers(portalRestUrl: string, authentication: UserSession): Promise<any[]>;
/**
* Extracts the text in a url between the last forward slash and the beginning of the url's parameters.
*
* @param url URL to work with
* @returns Text extracted; empty if url ends with a forward slash or has a "?" immediately after the last
* forward slash
*/
export declare function getFilenameFromUrl(url: string): string;
/**
* Gets the primary information of an AGO group.
*
* @param groupId Id of an group whose primary information is sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with group's JSON or error JSON or throws ArcGISRequestError in case of HTTP error
* or response error code
*/
export declare function getGroupBase(groupId: string, authentication: UserSession): Promise<IGroup>;
/**
* Gets the category schema set on a group.
*
* @param groupId Id of an group whose category schema information is sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with JSON of group's category schema
* @see https://developers.arcgis.com/rest/users-groups-and-items/group-category-schema.htm
*/
export declare function getGroupCategorySchema(groupId: string, authentication: UserSession): Promise<IGroupCategorySchema>;
/**
* Gets the ids of the dependencies (contents) of an AGO group.
*
* @param groupId Id of a group whose contents are sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with list of dependent ids or an empty list
*/
export declare function getGroupContents(groupId: string, authentication: UserSession): Promise<string[]>;
/**
* Gets the primary information of an AGO item.
*
* @param itemId Id of an item whose primary information is sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with item's JSON or error JSON or throws ArcGISRequestError in case of HTTP error
* or response error code
*/
export declare function getItemBase(itemId: string, authentication: UserSession): Promise<IItem>;
/**
* Gets the data information of an AGO item in its raw (Blob) form and casts it as a file using the supplied name.
*
* @param itemId Id of an item whose data information is sought
* @param filename Name to use for file
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with a File, undefined if the Blob is null, or an AGO-style JSON failure response
*/
export declare function getItemDataAsFile(itemId: string, filename: string, authentication: UserSession): Promise<File>;
/**
* Gets the data information of an AGO item in its JSON form.
*
* @param itemId Id of an item whose data information is sought
* @param filename Name to use for file
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with JSON, or an AGO-style JSON failure response
*/
export declare function getItemDataAsJson(itemId: string, authentication: UserSession): Promise<any>;
/**
* Gets the data information of an AGO item in its raw (Blob) form.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with the data Blob or null if the item doesn't have a data section
*/
export declare function getItemDataBlob(itemId: string, authentication: UserSession): Promise<Blob>;
/**
* Gets the URL to the data information of an AGO item in its raw (Blob) form.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns URL string
*/
export declare function getItemDataBlobUrl(itemId: string, authentication: UserSession): string;
/**
* Gets the URL to an information item in an AGO item.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns URL string
*/
export declare function getItemInfoFileUrlPrefix(itemId: string, authentication: UserSession): string;
/**
* Gets the metadata information of an AGO item.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with `undefined` or a File containing the metadata
*/
export declare function getItemMetadataAsFile(itemId: string, authentication: UserSession): Promise<File>;
/**
* Gets the metadata information of an AGO item.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with the metadata Blob or null if the item doesn't have a metadata file
*/
export declare function getItemMetadataBlob(itemId: string, authentication: UserSession): Promise<Blob>;
/**
* Gets the URL to the metadata information of an AGO item.
*
* @param itemId Id of an item whose data information is sought
* @param authentication Credentials for the request to AGO
* @returns URL string
*/
export declare function getItemMetadataBlobUrl(itemId: string, authentication: UserSession): string;
/**
* Gets the related items of an AGO item.
*
* @param itemId Id of an item whose related items are sought
* @param relationshipType Tag for relationship type, e.g., "Solution2Item"
* @param direction Relationship direction
* @param authentication Credentials for the request to AGO
* @param num Number of related items to request per batch; maximum is 100
* @returns A promise that will resolve with the list of related items
*/
export declare function getItemRelatedItems(itemId: string, relationshipType: ItemRelationshipType | ItemRelationshipType[], direction: "forward" | "reverse", authentication: UserSession, num?: number): Promise<IGetRelatedItemsResponse>;
/**
* Gets all of the related items of an AGO item in the specified direction.
*
* @param itemId Id of an item whose related items are sought
* @param direction
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with a list of IRelatedItems
*/
export declare function getItemRelatedItemsInSameDirection(itemId: string, direction: "forward" | "reverse", authentication: UserSession): Promise<IRelatedItems[]>;
export declare function getItemResources(id: string, authentication: UserSession): Promise<any>;
/**
* Gets the resources of an AGO item.
*
* @param itemId Id of an item whose resources are sought
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with a list of Files or an AGO-style JSON failure response
*/
export declare function getItemResourcesFiles(itemId: string, authentication: UserSession): Promise<File[]>;
/**
* Gets all of the items associated with a Solution via a Solution2Item relationship.
*
* @param solutionItemId Id of a deployed Solution
* @param authentication Credentials for the request
* @returns Promise resolving to a list of detailed item information
*/
export declare function getItemsRelatedToASolution(solutionItemId: string, authentication: UserSession): Promise<IItem[]>;
/**
* Gets the thumbnail of an AGO item.
*
* @param itemId Id of an item whose resources are sought
* @param thumbnailUrlPart The partial name of the item's thumbnail as reported by the `thumbnail` property
* in the item's base section
* @param isGroup Switch indicating if the item is a group
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with an image Blob or an AGO-style JSON failure response
*/
export declare function getItemThumbnail(itemId: string, thumbnailUrlPart: string | null, isGroup: boolean, authentication: UserSession): Promise<Blob>;
/**
* Gets the thumbnail of an AGO item.
*
* @param itemId Id of an item whose resources are sought
* @param thumbnailUrlPart The partial name of the item's thumbnail as reported by the `thumbnail` property
* in the item's base section
* @param isGroup Switch indicating if the item is a group
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with an image Blob or an AGO-style JSON failure response
*/
export declare function getItemThumbnailAsFile(itemId: string, thumbnailUrlPart: string | null, isGroup: boolean, authentication: UserSession): Promise<File>;
/**
* Gets the URL to the thumbnail of an AGO item.
*
* @param itemId Id of an item whose resources are sought
* @param thumbnailUrlPart The partial name of the item's thumbnail as reported by the `thumbnail` property
* in the item's base section
* @param isGroup Switch indicating if the item is a group
* @param authentication Credentials for the request to AGO
* @returns URL string
*/
export declare function getItemThumbnailUrl(itemId: string, thumbnailUrlPart: string, isGroup: boolean, authentication: UserSession): string;
/**
* Gets a JSON from a web site.
*
* @param url Address of JSON
* @param authentication Credentials for the request
* @returns Promise that will resolve with JSON
*/
export declare function getJson(url: string, authentication?: UserSession): Promise<any>;
/**
* Extracts the portal sharing url from a supplied authentication.
*
* @param authentication Credentials for the request to AGO
* @returns Portal sharing url to be used in API requests, defaulting to `https://www.arcgis.com/sharing/rest`
*/
export declare function getPortalSharingUrlFromAuth(authentication: UserSession | undefined): string;
/**
* Extracts the portal url from a supplied authentication.
*
* @param authentication Credentials for the request to AGO
* @returns Portal url to be used in API requests, defaulting to `https://www.arcgis.com`
*/
export declare function getPortalUrlFromAuth(authentication: UserSession): string;
/**
* Gets the ids of all Solution items associated with an AGO item via a Solution2Item relationship.
*
* @param itemId Id of an AGO item to query
* @param authentication Credentials for the request
* @returns Promise resolving to a list of Solution item ids
*/
export declare function getSolutionsRelatedToAnItem(itemId: string, authentication: UserSession): Promise<string[]>;
export declare function getThumbnailFile(url: string, filename: string, authentication: UserSession): Promise<File>;
/**
* Fixes the types of Blobs incorrectly typed as text/plain.
*
* @param blob Blob to check
* @returns Promise resolving to original Blob, unless it's originally typed as text/plain but is
* really JSON, ZIP, or XML
* @private
*/
export declare function _fixTextBlobType(blob: Blob): Promise<Blob>;
/**
* Gets some of the ids of the dependencies (contents) of an AGO group.
*
* @param groupId Id of a group whose contents are sought
* @param pagingParams Structure with start and num properties for the tranche to fetch
* @param authentication Credentials for the request to AGO
* @returns A promise that will resolve with list of dependent ids or an empty list
* @private
*/
export declare function _getGroupContentsTranche(groupId: string, pagingParams: IPagingParams, authentication: UserSession): Promise<string[]>;
/**
* Gets some of the resources of an AGO item.
*
* @param itemId Id of an item whose resources are sought
* @param pagingParams Structure with start and num properties for the tranche to fetch
* @param authentication Credentials for the request to AGO
* @returns Promise that will resolve with a list of File promises or an AGO-style JSON failure response
* @private
*/
export declare function _getItemResourcesTranche(itemId: string, pagingParams: IPagingParams, authentication: UserSession): Promise<Array<Promise<File>>>;
/**
* Retrieves the default basemap for the given & basemapGalleryGroupQuery, basemapTitle
*
* @param {string} basemapGalleryGroupQuery The default basemap group query
* @param {string} basemapTitle The default basemap title
* @param {UserSession} authentication The session info
* @returns {IItem}
*/
export declare function getPortalDefaultBasemap(basemapGalleryGroupQuery: string, basemapTitle: string, authentication: UserSession): Promise<IItem>;