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

@superoffice/tsclient.webapi

v10.2.6-1262

Published

TypeScript client for SuperOffice WebApi.

Downloads

88

Readme

SuperOffice WebAPI TypeScript client

Provides a strongly-typed API to the SuperOffice Agents (web services).

You can either set up a WebApi connection object, and use it as a factory to get agents:

import { WebApi } from "@superoffice/tsclient.webapi";

let webapi = new WebApi("http://example.com/SuperOffice");
let agent = webapi.getWebhookAgent();
let hook = await agent.CreateDefaultWebhook();
hook.Name = "My hook";
hook.Events = ["contact.created"];
hook.TargetUrl = "https://www.requestbin.com";
let hook = await agent.SaveWebhook(hook);

or you can configure the WebApi using a static method, and let the agents re-use the global configuration:

import { WebApi, WebhookAgent } from "@superoffice/tsclient.webapi";

WebApi.configure("http://example.com/SuperOffice");
WebApi.authenticateWithPassword("username", "password");
let agent = new WebhookAgent();
let hook = await agent.CreateDefaultWebhook();

or you can configure the agents directly

import { WebhookAgent } from "@superoffice/tsclient.webapi";

let config: AxiosRequestConfig = { auth: { username: "username", password: "password" } };
let agent = new WebhookAgent("http://example.com/SuperOffice", config);
let hook = await agent.CreateDefaultWebhook();

Request parameters are also typed, so you can define objects like this:

import { WebApi, WebhookAgent } from "@superoffice/tsclient.webapi";
import { Webhook } from "@superoffice/tsclient.webapi/src/WebApi/Carriers";

let webhook: Webhook = {
  Name: "My hook",
  Events: ["contact.created"],
  Type: "webhook",
  TargetUrl: "https://www.requestbin.com"
};
WebApi.configure("http://example.com/SuperOffice");
let agent = new WebhookAgent();
let hook = await agent.SaveWebhook(webhook);

The hook object is typed, and its properties are all marked as optional, so that you don't have to fill in everything.

The agent methods return promises, so these are all thenable.

let agent = new WebhookAgent();
agent.SaveWebhook(webhook).then(webhook => console.log(webhook.WebhookId));

You connect the language parsing to the current resource manager instance using the global configuration. This request will add SO-Language and SO-Culture headers to the HTTP request, so that the WebAPI will return strings that match the requested language (by using the resource strings and multi-language string parsing.

import { WebApi, WebhookAgent } from "@superoffice/tsclient.webapi";
import { ResourceManager } from "../scil-core/src/Data/ResourceManager";

let rm = ResourceManager.GetInstance();
WebApi.configure("http://example.com/SuperOffice", rm);

let agent = new WebhookAgent();
let hook = await agent.CreateDefaultWebhook();

// HTTP request:
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
// SO-Language: en-us

You can disable string substitution for an agent instance by passing in an enum value:

WebApi.configure("http://example.com/SuperOffice", "en");

let agent = new WebhookAgent(ResourceParsing.DoNotParse);
let hook = await agent.CreateDefaultWebhook();

// HTTP request:
// POST http://example.com/SuperOffice/api/v1/Webhook/CreateDefaultWebhook
// SO-Language: -

You can cancel a request by providing an AbortController.

let agent = new WebhookAgent();
let aborter = agent.MakeAbortController();
let options: WebApiRequestOptions = { abortController: aborter };
agent
  .CreateDefaultWebhook(options)
  .then(response => console.log(response))
  .catch(err => {
    if (options.requestStatus === WebApiStatus.Cancelled) {
      console.error("Request was cancelled");
      done();
    }
  });

// Abort the request
aborter.abort();

Misc Types

  • DateTime is converted to TS date
  • TimeSpan is converted to a momentjs.duration
  • Blobs are converted to ArrayBuffers.

License

Proprietary.

Copyright (c) 2020, SuperOffice AS