@skylab-tech/skylab-studio

0.0.4 • Public • Published

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

Dependencies (10)

Dev Dependencies (5)

Package Sidebar

Install

npm i @skylab-tech/skylab-studio

Weekly Downloads

15

Version

0.0.4

License

Apache-2.0

Unpacked Size

503 kB

Total Files

17

Last publish

Collaborators

  • 2lives
  • paul-skylab-tech
  • kev-le