@mediaclip/hub-js-sdk
v1.3.2
Published
JavaScript/TypeScript SDK for interacting with the Mediaclip Hub API and URL signing utilities.
Downloads
535
Keywords
Readme
Mediaclip Hub JS SDK
JavaScript/TypeScript SDK for interacting with the Mediaclip Hub API and URL signing utilities.
Installation
Install via npm:
npm install @mediaclip/hub-js-sdkClient Module
For a full list of endpoints and usage, see the Mediaclip documentation.
Usage Example
See example
URL Signer Module
Creating a Signing Key
Use the Mediaclip Hub Admin to access the Graph Explorer and run the following mutation to create a signing key for your store. Keep the encodedSigningKey in a safe and secure location:
mutation {
createStoreUrlSigningKey(
input: {
format: Pem
label: "Some Label"
passphrase: "some-passphrase"
storeId: "my-store-id"
}
) {
encodedSigningKey
}
}Signing a URL
Use the encoded signing key and the passphrase to sign a URL with a given identity:
import {
decodeMediaclipUrlSigningKey,
signMediaclipUrlForHubUser,
signMediaclipUrlForStoreUser,
} from "@mediaclip/hub-js-sdk";
const url = new URL("https://api.mediacliphub.com/some-endpoint");
const signingKey = decodeMediaclipUrlSigningKey(
process.env.ENCODED_KEY!,
"some-passphrase"
);
const expiration = new Date(Date.now() + 60 * 60 * 1000); // Max 90 days
const signedUrlForHubUser = signMediaclipUrlForHubUser(
url,
signingKey,
"hubUserId",
expiration
);
// or
const signedUrlForStoreUser = signMediaclipUrlForStoreUser(
url,
signingKey,
"storeUserId",
expiration
);