PermanentOrg / node-sdk

Node.js SDK for Permanent.org
GNU Affero General Public License v3.0
4 stars 2 forks source link

Public methods to create files and folders and generate share links for files and folders #8

Closed andrewatwood closed 3 years ago

andrewatwood commented 3 years ago

Client config parameters have also changed, exposing baseUrl as an optional param to help easily test against local, and using archiveNbr instead of archiveId, which is more practically useful internally it turns out. And now the client will throw an exception if required params are missing!

This PR got a little larger change-wise than intended due to:

  1. Updating types and interfaces for API requests and responses to make use of generics when appropriate to actually return the appropriate type signature with the expected VO field, instead of a bunch of optional params that all return as, like FolderVO | undefined instead of just FolderVO. This added a lot of line changes in otherwise untouched files. But a worthy change! Just makes the diff a little larger.
  2. A check-in call with TheirStory with a realization that they'll need to share multiple items in a single batch instead of single files from the jump, which required adding the folder.create and createFolderShareLink methods in this PR instead of for another later issue.

My demo code (minus client config) that creates a folder, uploads files to the folder, and generates a share link is as follows for reference:

  await permanent.init();

  const newFolder = await permanent.folder.create('Folder To Share');

  await permanent.record.uploadFromUrl(
    {
      uploadUri: 'https://static.wikia.nocookie.net/non-aliencreatures/images/9/90/Mogwai.jpg/revision/latest/scale-to-width-down/300?cb=20110102071311',
      displayName: 'My Little Friend!',
      uploadFileName: 'gremlin.jpg'
    },
    newFolder
  );

  await permanent.record.uploadFromUrl(
    {
      uploadUri: 'https://upload.wikimedia.org/wikipedia/commons/c/ce/E.T._figure_at_Madame_Tussauds_London.jpg',
      displayName: 'My Other Little Friend!',
      uploadFileName: 'et.jpg'
    },
    newFolder
  );

  const shareLink = await permanent.share.createFolderShareLink(newFolder);

  console.log(`SHARE LINK: ${shareLink}`);
jasonaowen commented 3 years ago

For the record, @andrewatwood and @slifty are working together to split this into several smaller PRs, starting with #10. Thanks, both of you!