diff --git a/packages/arcgis-rest-items/src/add.ts b/packages/arcgis-rest-items/src/add.ts index 98cbc97bf1..a9e4a1a0d5 100644 --- a/packages/arcgis-rest-items/src/add.ts +++ b/packages/arcgis-rest-items/src/add.ts @@ -23,6 +23,9 @@ export interface IItemDataAddRequestOptions extends IItemIdRequestOptions { data: any; } +/** + * Deprecated. Please use `IItemResourceRequestOptions` instead. + */ export interface IItemResourceAddRequestOptions extends IItemResourceRequestOptions { /** @@ -136,7 +139,8 @@ export function addItemRelationship( /** * ```js * import { addItemResource } from '@esri/arcgis-rest-items'; - * // + * + * // Add a file resource * addItemResource({ * id: '3ef', * resource: file, @@ -144,6 +148,15 @@ export function addItemRelationship( * authentication * }) * .then(response) + * + * // Add a text resource + * addItemResource({ + * id: '4fg', + * content: "Text content", + * name: 'bigkahuna.txt', + * authentication + * }) + * .then(response) * ``` * Add a resource associated with an item. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/add-resources.htm) for more information. * @@ -151,7 +164,7 @@ export function addItemRelationship( * @returns A Promise to add item resources. */ export function addItemResource( - requestOptions: IItemResourceAddRequestOptions + requestOptions: IItemResourceRequestOptions ): Promise { const owner = determineOwner(requestOptions); const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${ diff --git a/packages/arcgis-rest-items/src/helpers.ts b/packages/arcgis-rest-items/src/helpers.ts index b67728806e..d2bbcfb56d 100644 --- a/packages/arcgis-rest-items/src/helpers.ts +++ b/packages/arcgis-rest-items/src/helpers.ts @@ -89,6 +89,9 @@ export interface IItemResourceRequestOptions extends IItemIdRequestOptions { * Controls whether access to the file resource is restricted to the owner or inherited from the sharing permissions set for the associated item. */ private?: boolean; + /** + * Object to store + */ resource?: any; } diff --git a/packages/arcgis-rest-items/test/add.test.ts b/packages/arcgis-rest-items/test/add.test.ts index 514e5ac87b..82aa780591 100644 --- a/packages/arcgis-rest-items/test/add.test.ts +++ b/packages/arcgis-rest-items/test/add.test.ts @@ -286,5 +286,35 @@ describe("search", () => { fail(e); }); }); + + it("should add a text resource", done => { + fetchMock.once("*", { + success: true + }); + + addItemResource({ + id: "3ef", + content: "Text content", + name: "thebigkahuna.txt", + ...MOCK_USER_REQOPTS + }) + .then(() => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/addResources" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain("text=Text%20content"); + expect(options.body).toContain("fileName=thebigkahuna"); + expect(options.body).toContain(encodeParam("token", "fake-token")); + + done(); + }) + .catch(e => { + fail(e); + }); + }); }); // auth requests });