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

surgejs-sdk

v0.4.1

Published

JavaScript library of public Surge API endpoints

Downloads

16

Readme

npm version Gitpod Ready-to-Code install size

SurgeJS SDK

JavaScript library of public Surge API endpoints. Sharing structure and documentation in an open sourc environment.

Table of Contents

Features

  • Common JS (CJS) enabled
  • ES Modules (ESM) enabled
  • TypeScript enabled

Installation

Using npm:

npm install surgejs-sdk

Using yarn:

yarn add surgejs-sdk

Example

note: CommonJS usage

const Surge = require('surgejs-sdk');

Logging the user into surge servers

const Surge = require('surgejs-sdk');

const surge = new Surge({
  username: '[email protected]',
  password: 'password'
});

surge
  .login()
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  });

API

Every API must have Basic Authentication attached with user credentials. This is required for any call made to the servers.

When using the surgejs-sdk library, all you need to do is provide your credentials in the new Surge({username: '[email protected]', password: 'password}) arguments. No need to worry about http headers.

Methods

All provided methods are promise based so we won't add .then(...).catch(...) to all of the examples.

Authentication

Login

Authenticate the user with surge servers using their email and password provided upon initiation of the library. See Installation

surge.login();

Response

{
  "email": "[email protected]",
  "token": "abcdefg0123456789"
}
Logout

Logout is an informal event. Remove your locally stored credentials (email, token) to "logout" the user.

Account

Get the user's account information.

surge.account();

Response

{
  "email": "[email protected]",
  "id": "0000-0000-0000",
  "uuid": "00000000-0000-0000-0000-000000000000",
  "role": 0,
  "updated_at": "2020-01-01T01:01:01.000Z",
  "created_at": "2020-01-01T01:01:01.000Z",
  "email_verified_at": "2020-01-01T01:01:01.000Z",
  "payment_id": null,
  "plan": {
    "id": "abcdefg-00",
    "name": "abcdefg",
    "amount": "0000",
    "friendly": "abcdefg",
    "dummy": true,
    "current": true,
    "metadata": {
      "type": "account"
    },
    "ext": "00",
    "perks": [],
    "comped": false
  },
  "card": null
}
Reset Password

Initiate password reset steps for a user's email.

surge.resetPassword('[email protected]');

Response

Reset instructions send to email.
Stats

Get stats about your account usage.

surge.stats();

Response

{
  "calls": "7515855",
  "deployemnts": "7515855",
  "bytes": "77879308777468",
  "files": "903079863",
  "accounts": "148665",
  "projects": "1193327",
  "builds": "1169",
  "deployments": "7515855",
  "formatted": {
    "calls": "7,515,855",
    "deployments": "7,515,855",
    "bytes": "70.83 TB",
    "files": "903,079,863",
    "accounts": "148,665",
    "projects": "1,193,327",
    "builds": "1,169"
  }
}

Projects

Discover

Surge Cli uses moniker to randomly generate domain name for the user.

surge.discover();
List
surge.list();

Response

[
    {
    "domain": "domain_name.surge.sh",
    "planName": "Standard",
    "output": {},
    "rev": 0123456789,
    "config": {},
    "cmd": "surge",
    "email": "[email protected]",
    "platform": "surge.sh",
    "cliVersion": "0.21.7",
    "message": null,
    "buildTime": null,
    "ip": "00.000.000.00",
    "privateFileList": [],
    "publicFileCount": 00,
    "publicTotalSize": 000000,
    "privateFileCount": 00,
    "privateTotalSize": 0000000,
    "uploadStartTime": 0000000000000,
    "uploadEndTime": 0000000000000,
    "uploadDuration": 1.000,
    "preview": "0000000000000-domain_name.surge.sh",
    "timeAgoInWords": "4 weeks ago"
  },
  ...
]
Deploy

Not yet implemented.

PUT https://surge.surge.sh/<domain_name>
Content-Types: application/json

| Parameters | Type | Default | Description | | ---------- | -------- | ------- | ---------------------------------------------------------------------------------- | | domain | string | N/A | domain_name.surge.sh which you would like to create. Do not include ".surge.sh". | | data | gzip | N/A | Tar packed, gzip files including the index.html to serve your static site. |

Project is ran through three pipes in the cli:

// cli files:
// 1. prep.js
// 2. deploy.js
// 3. project.js

var fsReader = require('surge-fstream-ignore');

// Read Project
var project = fsReader({ path: req.project, ignoreFiles: ['.surgeignore'] });

// we always ignore .git directory
project.addIgnoreRules(ignore);

// chain all this together...
project
  .pipe(tar.Pack())
  .pipe(zlib.Gzip())
  .pipe(handshake);

Untested libraries equivalent to Node:

Teardown

Remove the domain and hosted site from surge servers. e.g. domain_name.surge.sh.

surge.teardown('domain_name');

Response

{
  "msg": "project removed",
  "nsDomain": "surge.world",
  "regions": {},
  "servers": []
}

Payments

Payments are still under development.

Card

N/A

Set Card

N/A

Payment

Multi step process.

  1. If the user does not exist in stripe, choose a plan and credit card information.
  2. If the user exists in stripe, choose a new plan to pay for.

+++ Request

GET https://surge.surge.sh/<domain_name>/plans
Content-Types: application/json

Response

N / A
Plans

N/A

Plus

Requires an undocumented Stripe call to get user's Stripe data.

Subscribe
PUT https://surge.surge.sh/<domain_name>/plan
Content-Types: application/json

Body

| Parameter | Type | Default | Description | | --------- | -------- | ------- | ------------- | | token | string | N/A | Payment Token |

Response

N / A
Subscription
GET https://surge.surge.sh/<domain_name>/subscription
Content-Types: application/json

Response

{
  "type": "",
  "stripe_pk": "",
  "plan": {},
  "card": null,
  "perks": []
}

Support

Technical support questions are best asked in the Discussions. We will do our best to assist as soon as possible.

If you find a defect or would like to submit a feature request, please create an Issue and we will investigate right away.