npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@skylab-tech/skylab-studio

v0.0.4

Published

studio.skylabtech.ai JavaScript client

Downloads

38

Readme

Skylab Studio JavaScript Client

studio.skylabtech.ai

Installation

npm install skylab-studio

Example usage

// CREATE PROFILE
const profilePayload = {
  "name": "profile name",
  "enable_crop": false,
  "enable_retouch": true
}

const profile = await api.createProfile(profilePayload)

// CREATE JOB
const jobPayload = {
  "name": "job name",
  "profile_id": profile.id
}

const job = await api.createJob(jobPayload)

// UPLOAD JOB PHOTO(S)
const filePath = "/path/to/photo"
await api.uploadJobPhoto(filePath, job.id)

// QUEUE JOB
payload = { "callback_url" = "YOUR_CALLBACK_ENDPOINT" }
await api.queueJob(job.id, payload)

// NOTE: Once the job is queued, it will get processed then completed
// We will send a response to the specified callback_url with the output photo download urls

// After job has been completed, either download manually or download 1 photo:
await api.downloadPhoto(photoId, 'path/to/output/directory')

// or download all photos for a job:

await api.downloadPhotos(jobId, 'path/to/output/directory')

Jobs

List all Jobs

await api.listJobs();

Create a Job

await api.createJob({
  name: "your job name",
  profile_id: 123,
});

For all payload options, consult the API documentation.

Get a Job

await api.getJob(jobId);

Get Job by Name

await api.getJobByName(name);

Update a Job

await api.updateJob(jobId, { name: "updated job name", profile_id: 456 });

For all payload options, consult the API documentation.

Queue Job

const payload = {
  callback_url: "desired_callback_url",
};

await api.queueJob(jobId, payload);

Jobs in Front

await api.getJobsInFront(jobId);

Delete a Job

await api.deleteJob(jobId);

Cancel a Job

await api.cancelJob(jobId);

Profiles

List all Profiles

await api.listProfiles();

Create a Profile

await api.createProfile({
  name: "My Profile",
});

For all payload options, consult the API documentation.

Get a Profile

await api.getProfile(profileId);

Update profile

payload = {
  name: "My updated profile name",
};

await api.updateProfile(profileId, payload);

For all payload options, consult the API documentation.

Photos

Upload Job Photo

This function handles validating a photo, creating a photo object and uploading it to your job/profile's s3 bucket. If the bucket upload process fails, it retries 3 times and if failures persist, the photo object is deleted.

await api.uploadJobPhoto(photoPath, jobId);

Returns: { photo: { photoObject }, uploadResponse: bucketUploadResponseStatus }

If upload fails, the photo object is deleted for you. If upload succeeds and you later decide you no longer want to include that image, use delete_photo to remove it.

Upload Profile Photo

This function handles validating a background photo for a profile. Note: enable_extract and replace_background (profile attributes) MUST be true in order to create background photos. Follows the same upload process as uploadJobPhoto.

await api.uploadProfilePhoto(photoPath, profileId);

Returns: { photo: { photoObject }, uploadResponse: bucketUploadResponseStatus }

If upload fails, the photo object is deleted for you. If upload succeeds and you later decide you no longer want to include that image, use delete_photo to remove it.

Download Photo

await api.downloadPhoto(photoId, outputDirectoryPath);

Downloads an individual photo to specified output directory. (preferred over manually downloading)

Returns array of ofjects, [{ status, id }]

Download Photos

await api.downloadPhotos(jobId, outputDirectoryPath);

Downloads all photos for a job to specified output directory. (preferred over manually downloading)

Returns array of ofjects, [{ status, id }]

Get a Photo

await api.getPhoto(photoId);

Delete a Photo

await api.deletePhoto(photoId);

Validate HMAC Headers

  • secretKey: Obtained from Skylab account (contact)
  • jobJson: Raw JSON response from callback
  • requestTimestamp: Timestamp header received in callback under 'X-Skylab-Timestamp'
  • signature: Signature header received in callback under 'X-Skylab-Signature'

NOTE: If using something like an express server to handle the callback, the JSON response needs to be the raw response. If your express server is running app.use(express.json) you will need to create a middleware and pass it to your callback handler to use the raw response: app.use(express.raw({ type: "application/json" }))

await api.validateHmacHeaders(secretKey, jobJson, requestTimestamp, signature);

Troubleshooting

General Troubleshooting

  • Enable debug mode
  • Make sure you're using the latest Node client
  • Capture the response data and check your logs — often this will have the exact error

Enable Debug Mode

Debug mode prints out the underlying request information as well as the data payload that gets sent to Skylab. You will most likely find this information in your logs. To enable it, simply put debug=true as a parameter when instantiating the API object.

const skylabStudio = require("skylab-studio");

const api = skylabStudio("your-api-key", (debug = true));

Response Ranges

SkylabTech's API typically sends responses back in these ranges:

  • 2xx – Successful Request
  • 4xx – Failed Request (Client error)
  • 5xx – Failed Request (Server error)

If you're receiving an error in the 400 response range follow these steps:

  • Double check the data and ID's getting passed to Skylab
  • Ensure your API key is correct
  • Log and check the body of the response