Package Exports
- @vercel/remote
- @vercel/remote/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@vercel/remote) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Vercel Remote Caching SDK
The Vercel Remote Caching SDK is a thin layer over our existing REST API.
Usage
Install the latest version of the SDK using:
npm install @vercel/remoteThen in your build system you can cache artifacts to Vercel's remote cache as shown in the following examples.
Using buffers
import fs from 'fs-extra'
import { createClient } from '@vercel/remote'
const remote = createClient('<token>', {
teamId: '<teamId>',
// e.g. turbo, nx, rush, etc.
product: 'your-build-system'
});
async function getArtifact(hash) {
const exists = await remote.exists(hash).send();
if (!exists) {
return false
}
// Process the incoming buffer to your local cache
const buf = await remote.get(hash).buffer()
await fs.writeFile(hash, buf)
return true
}
async function putArtifact(hash, buf) {
await remote.put(hash).buffer(buf)
}Using streams
import fs from 'fs-extra'
import stream from 'stream'
import { promisify } from 'util';
import { createClient } from '@vercel/remote'
const pipeline = promisify(stream.pipeline);
const remote = createClient('<token>', {
teamId: '<teamId>',
// e.g. turbo, nx, rush, etc.
product: 'your-build-system'
});
async function getArtifact(hash) {
const exists = await remote.exists(hash).send();
if (!exists) {
return false
}
const readStream = await remote.get(hash).stream()
// Process the incoming stream to your local cache
const writeStream = fs.createWriteStream(hash);
await pipeline(readStream, writeStream)
return true
}
async function putArtifact(hash) {
// Create the artifact stream from your local cache
const readStream = fs.createReadStream(hash);
// Push to Vercel remote cache
await remote.put(hash).stream(readStream)
}Authentication
Use a Vercel Access Token with access to the requested teamId in the RemoteClient to use this SDK.
API Reference
RemoteClient(token: string, opt?: RemoteClientOptions)
interface RemoteClientOptions {
// When a teamId is not specified, the personal account associated with
// the provided `token` will be used. Specify a `teamId` to share
// artifacts with the team.
teamId?: string;
product?: string;
}
const remote = createClient('<token>', {
teamId: '<teamId>',
product: 'your-build-system'
});RemoteClientOptions
teamId- Vercel team IDproduct- The build system you are using. For example turbo, nx, rush, etc.
Methods
remote.exists(hash: string): ArtifactExistsRequest
Return true if an artifact exists in the remote cache. Otherwise return false.
const exists = await remote.exists('6079a2819459d70b').send();remote.get(hash: string): ArtifactGetRequest
Returns an artifact from the remote cache as a buffer
const buf = await remote.get('6079a2819459d70b').buffer();Returns an artifact from the remote cache as a readable stream
const readStream = await remote.get('6079a2819459d70b').stream();remote.put(hash: string): ArtifactPutRequest
Uploads an artifact to the remote cache from a buffer
await remote.put('6079a2819459d70b', {
duration: 8030,
}).buffer(buf);Uploads an artifact to the remote cache from a readable stream
await remote.put('6079a2819459d70b', {
duration: 8030,
}).stream(readStream);Errors
Throws errors in the format and for the reasons defined on the Vercel Rest API