@esri/solution-common
Version:
Provides general helper functions for @esri/solution.js.
193 lines (192 loc) • 10.6 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.
*/
/**
* Provides common functions involving the management of item and group resources.
*
* @module resourceHelpers
*
* How it works
*
* An item may have resources that are listed as a set of filenames and/or folder/filename combinations. It may have
* a thumbnail, listed in its item info as a filename or folder/filename combination. It may have metadata, which is
* not listed, but has a distinct URL. A group may have a thumbnail, but not the others.
*
* For storing these files in a common storage item, a new folder and filename combination is created for each. The
* filename is kept as-is. The folder consists of the source item's id and an optional suffix. For thumbnails, the
* suffix is "_info_thumbnail"; for metadata, the suffix is "_info_metadata"; for resources, the suffix is "_" plus
* the resource's folder's name; if the resource doesn't have a folder, there is no suffix.
*
* Note that "thumbnail" is included in an item's thumbnail property like a folder (e.g., "thumbnail/thumbnail.png"),
* and the item's thumbnail is accessed using a path such as "%lt;itemId>/info/thumbnail/thumbnail.png". Groups,
* on the other hand, have a property with a simple name (e.g., "thumbnail.png") and it is accessed using a path
* such as "%lt;groupId>/info/thumbnail.png".
*
* For copying these files from the common storage item to another item, one converts the unique names back into the
* original names (or the special cases for thumbnails and metadata).
*
* Routines are provided to
* 1. create full URLs to resources, thumbnails, and metadata.
* 2. create a folder and filename combination that uniquely identifies these files for
* storing them in a single, shared storage item
* 3. copy a set of resources, thumbnails, and metadata for an item to a storage item
* 4. copy a file by URL to an item using specified folder and filename
* 5. undo the unique folder and filename into the original folder and filename
*/
import { IDeployFileCopyPath, IFileMimeTyped, ISourceFile, ISourceFileCopyPath } from "./interfaces";
import { IItemResourceResponse, UserSession } from "./arcgisRestJS";
export declare function addThumbnailFromBlob(blob: any, itemId: string, authentication: UserSession, isGroup?: boolean): Promise<any>;
export declare function convertBlobToSupportableResource(blob: Blob, filename?: string): IFileMimeTyped;
/**
* Copies the files described by a list of full URLs and folder/filename combinations for
* the resources and metadata of an item or group to an item.
*
* @param storageAuthentication Credentials for the request to the storage
* @param filePaths List of item files' URLs and folder/filenames for storing the files
* @param sourceItemId Id of item supplying resource/metadata
* @param destinationFolderId Id of folder
* @param destinationItemId Id of item to receive copy of resource/metadata
* @param destinationAuthentication Credentials for the request to the destination
* @param template Description of item that will receive files
* @param templateDictionary Hash of facts: org URL, adlib replacements, deferreds for dependencies
* @returns A promise which resolves to a boolean indicating if the copies were successful
*/
export declare function copyFilesFromStorageItem(storageAuthentication: UserSession, filePaths: IDeployFileCopyPath[], sourceItemId: string, destinationFolderId: string, destinationItemId: string, destinationAuthentication: UserSession, template?: any, templateDictionary?: any): Promise<boolean>;
/**
* Copies the files for storing the resources, metadata, and thumbnail of an item or group to a storage item
* with a specified path.
*
* @param files List of item files and paths for storing the files
* @param storageItemId Id of item to receive copy of resource/metadata
* @param storageAuthentication Credentials for the request to the storage
* @returns A promise which resolves to a list of the filenames under which the resource/metadata are stored
*/
export declare function copyFilesToStorageItem(files: ISourceFile[], storageItemId: string, storageAuthentication: UserSession): Promise<string[]>;
/**
* Generates a folder and filename for storing a copy of an item's metadata in a storage item.
*
* @param itemId Id of item
* @returns Folder and filename for storage; folder is the itemID suffixed with "_info_metadata"
* @see convertStorageResourceToItemResource
*/
export declare function generateMetadataStorageFilename(itemId: string): {
folder: string;
filename: string;
};
/**
* Generates a list of full URLs and storage folder/filename combinations for storing the resources, metadata,
* and thumbnail of an item.
*
* @param portalSharingUrl Server/sharing
* @param itemId Id of item
* @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
* @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
* @param isGroup Boolean to indicate if the files are associated with a group or item
* @param storageVersion Version of the Solution template
* @returns List of item files' URLs and folder/filenames for storing the files
*/
export declare function generateSourceFilePaths(portalSharingUrl: string, itemId: string, thumbnailUrlPart: string, resourceFilenames: string[], isGroup?: boolean, storageVersion?: number): ISourceFileCopyPath[];
/**
* Generates the full URL and storage folder/filename for storing an item's thumbnail.
*
* @param portalSharingUrl Server/sharing
* @param itemId Id of item
* @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
* @param isGroup Boolean to indicate if the files are associated with a group or item
* @returns URL and folder/filename for storing the thumbnail
*/
export declare function generateSourceThumbnailPath(portalSharingUrl: string, itemId: string, thumbnailUrlPart: string, isGroup?: boolean): ISourceFileCopyPath;
/**
* Generates the URL for reading an item's metadata.
*
* @param sourcePortalSharingUrl Server/sharing
* @param itemId Id of item
* @param isGroup Boolean to indicate if the files are associated with a group or item
* @returns URL string
*/
export declare function generateSourceMetadataUrl(sourcePortalSharingUrl: string, itemId: string, isGroup?: boolean): string;
/**
* Generates the URL for reading an item's resource given the filename of the resource.
*
* @param sourcePortalSharingUrl Server/sharing
* @param itemId Id of item
* @param sourceResourceFilename Either filename or folder/filename to resource
* @returns URL string
*/
export declare function generateSourceResourceUrl(sourcePortalSharingUrl: string, itemId: string, sourceResourceFilename: string): string;
/**
* Generates the URL for reading an item's thumbnail.
*
* @param sourcePortalSharingUrl Server/sharing
* @param itemId Id of item
* @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON
* @param isGroup Boolean to indicate if the files are associated with a group or item
* @returns URL string
*/
export declare function generateSourceThumbnailUrl(sourcePortalSharingUrl: string, itemId: string, thumbnailUrlPart: string, isGroup?: boolean): string;
/**
* Generates a list of full URLs and folder/filename combinations used to store the resources, metadata,
* and thumbnail of an item.
*
* @param portalSharingUrl Server/sharing
* @param storageItemId Id of storage item
* @param resourceFilenames List of resource filenames for an item, e.g., ["file1", "myFolder/file2"]
* @param storageVersion Version of the Solution template
* @returns List of item files' URLs and folder/filenames for storing the files
*/
export declare function generateStorageFilePaths(portalSharingUrl: string, storageItemId: string, resourceFilenames?: string[], storageVersion?: number): IDeployFileCopyPath[];
/**
* Generates a folder and filename for storing a copy of an item's thumbnail in a storage item.
*
* @param itemId Id of item
* @param thumbnailUrlPart Partial path to the thumbnail held in an item's JSON; can also be a filename
* @returns Folder and filename for storage; folder is the itemID suffixed with "_info_thumbnail";
* file is URI-encoded thumbnailUrlPart
* @see convertStorageResourceToItemResource
*/
export declare function generateThumbnailStorageFilename(itemId: string, thumbnailurl: string): {
folder: string;
filename: string;
};
export declare function isSupportedFileType(filename: string): boolean;
/**
* Gets the thumbnail of an item or group.
*
* @param authentication Credentials for the request to the storage
* @param filePaths List of item files' URLs and folder/filenames for storing the files
* @returns A promise which resolves to a boolean indicating if the copies were successful
*/
export declare function getThumbnailFromStorageItem(authentication: UserSession, filePaths: IDeployFileCopyPath[]): Promise<File>;
/**
* Removes the item's resource that matches the filename with new content
*
* @param itemId Id of the item to remove
* @param filename Name of the resource file to remove
* @param authentication Credentials for the request to the storage
* @returns A promise which resolves with a success true/false response
*/
export declare function removeItemResourceFile(itemId: string, filename: string, authentication: UserSession): Promise<{
success: boolean;
}>;
/**
* Updates the item's resource that matches the filename with new content
*
* @param itemId Id of the item to update
* @param filename Name of the resource file to update; prefix optional (e.g., a/b/file.txt)
* @param resource The new content to update the resource with
* @param authentication Credentials for the request to the storage
* @returns A promise which resolves with a success true/false response
*/
export declare function updateItemResourceFile(itemId: string, filename: string, resource: File, authentication: UserSession): Promise<IItemResourceResponse>;