New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@short.io/client-node

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@short.io/client-node - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

4

dist/index.d.ts

@@ -1,5 +0,4 @@

/// <reference types="node" />
import { ErrorResBody, StatusResBody, SuccessResBody } from "./types/common.js";
import { Domain, DomainCreateOptions } from "./types/domain.js";
import { DeleteLinkRes, GetLinkQRCodeOptions, Link, LinkBulkCreateOptions, LinkCountry, LinkCountryCreateOptions, LinkCreateOptions, LinkListOptions, LinkOpenGraphData, LinkRegion, LinkRegionCreateOptions, LinkRegionDeleteOptions, LinksAndCount, LinkUpdateOptions, LinkWithUser, UpdateLinkErrorRes } from "./types/link.js";
import { DeleteLinkRes, GetLinkQRCodeOptions, Link, LinkBulkCreateOptions, LinkCountry, LinkCountryCreateOptions, LinkCreateOptions, LinkListOptions, LinkOpenGraphData, LinkRegion, LinkRegionCreateOptions, LinkRegionDeleteOptions, LinkUpdateOptions, LinkWithUser, LinksAndCount, UpdateLinkErrorRes } from "./types/link.js";
import { Column, DomainStatistics, FilterOptions, GetLastClicksOptions, GetStatisticsOptions, IncludeExcludeOptions, LastClicksRes, LinkClicks, LinkIds, LinkStatistics, PathClicks, PathDate, StartEndDate, TopByColumnOptions, TopByIntervalOptions, TopByIntervalRes, TopColumnRes } from "./types/statistics.js";

@@ -17,2 +16,3 @@ export declare class Shortio {

createPublic: (hostname: Domain["hostname"], originalURL: Link["originalURL"], publicAPIKey: string, options?: LinkCreateOptions) => Promise<Link | (SuccessResBody & ErrorResBody)>;
createSecure: (hostname: Domain["hostname"], originalURL: Link["originalURL"], publicAPIKey: string, options?: LinkCreateOptions) => Promise<Link | ErrorResBody>;
bulkCreate: (hostname: Domain["hostname"], links: LinkBulkCreateOptions[], allowDuplicates?: boolean) => Promise<(Link & SuccessResBody)[] | (SuccessResBody & ErrorResBody & StatusResBody)>;

@@ -19,0 +19,0 @@ archive: (linkIdString: Link["idString"]) => Promise<SuccessResBody | ErrorResBody>;

@@ -79,5 +79,31 @@ export class Shortio {

});
const link = await linkRes.json();
const link = (await linkRes.json());
return link;
},
createSecure: async (hostname, originalURL, publicAPIKey, options) => {
const cryptoKey = await crypto.subtle.generateKey({
name: "AES-GCM",
length: 128,
}, true, ["encrypt", "decrypt"]);
const iv = crypto.getRandomValues(new Uint8Array(12));
const urlData = new TextEncoder().encode(originalURL);
const encryptedUrl = await crypto.subtle.encrypt({
name: "AES-GCM",
iv,
}, cryptoKey, urlData);
const encryptedUrlBase64 = Buffer.from(encryptedUrl).toString("base64");
const encryptedIvBase64 = Buffer.from(iv).toString("base64");
const encryptedData = `shortsecure://${encryptedUrlBase64}?${encryptedIvBase64}`;
const link = (await this.link.createPublic(hostname, encryptedData, publicAPIKey, options));
if ("error" in link) {
return {
error: link.error,
};
}
const exportedKey = await crypto.subtle.exportKey("raw", cryptoKey);
const keyBase64 = Buffer.from(new Uint8Array(exportedKey)).toString("base64");
link.shortURL += `#${keyBase64}`;
link.secureShortURL += `#${keyBase64}`;
return link;
},
bulkCreate: async (hostname, links, allowDuplicates = false) => {

@@ -84,0 +110,0 @@ const linkRes = await fetch(`${this.baseApiUrl}/links/bulk`, {

{
"name": "@short.io/client-node",
"version": "1.0.3",
"version": "1.1.0",
"description": "",

@@ -13,3 +13,3 @@ "main": "dist/index.js",

"prepare": "npm run compile",
"prepublishOnly": "npm run format && npm version patch"
"prepublishOnly": "npm run format"
},

@@ -16,0 +16,0 @@ "repository": {

@@ -51,1 +51,26 @@ # Short.io Node.js SDK

```
Create links:
```js
const link = await shortio.link.create({
domain: "link.example.com",
path: "example",
originalURL: "https://example.com",
});
console.log(link.shortURL); // https://link.example.com/example
const publicLink = await shortio.link.createPublic({
domain: "link.example.com",
originalURL: "https://example.com",
publicAPIKey: "PUBLIC_API_KEY",
});
console.log(publicLink.shortURL); // https://link.example.com/a83t48
const secureLink = await shortio.link.createSecure({
domain: "link.example.com",
publicAPIKey: "PUBLIC_API_KEY",
originalURL: "https://example.com",
});
console.log(secureLink.shortURL); // https://link.example.com/a83t48#ta95me8
```

@@ -16,5 +16,5 @@ import { ErrorResBody, StatusResBody, SuccessResBody } from "./types/common.js";

LinkRegionDeleteOptions,
LinksAndCount,
LinkUpdateOptions,
LinkWithUser,
LinksAndCount,
UpdateLinkErrorRes,

@@ -154,3 +154,3 @@ } from "./types/link.js";

* @param options Options for the request
* @returns Shortened link
* @returns Created link or error response
*/

@@ -175,3 +175,3 @@ createPublic: async (

});
const link = await linkRes.json();
const link = (await linkRes.json()) as Link | (SuccessResBody & ErrorResBody);
return link;

@@ -181,2 +181,58 @@ },

/**
* Encode original URL, then shorten it with public key and create a new short link.
* If parameter "path" in the options is omitted, it generates path by algorithm, chosen in domain settings.
* To decrypt and navigate the long original URL add the returned key in base64 format to the short link as a hash.
*
* **Note that secure links feature usage is available only for Team and Enterprise plans.**
*
* API reference: https://developers.short.io/reference/linkspostsecure
* @param hostname Domain hostname
* @param originalURL Original URL of the link
* @param publicAPIKey Public API key
* @param options Options for the request
* @returns Created link with the keyBase64 or error response
*/
createSecure: async (
hostname: Domain["hostname"],
originalURL: Link["originalURL"],
publicAPIKey: string,
options?: LinkCreateOptions,
): Promise<Link | ErrorResBody> => {
const cryptoKey = await crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 128,
},
true,
["encrypt", "decrypt"],
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const urlData = new TextEncoder().encode(originalURL);
const encryptedUrl = await crypto.subtle.encrypt(
{
name: "AES-GCM",
iv,
},
cryptoKey,
urlData,
);
const encryptedUrlBase64 = Buffer.from(encryptedUrl).toString("base64");
const encryptedIvBase64 = Buffer.from(iv).toString("base64");
const encryptedData = `shortsecure://${encryptedUrlBase64}?${encryptedIvBase64}`;
const link = (await this.link.createPublic(hostname, encryptedData, publicAPIKey, options)) as
| Link
| (SuccessResBody & ErrorResBody);
if ("error" in link) {
return {
error: link.error,
} as ErrorResBody;
}
const exportedKey = await crypto.subtle.exportKey("raw", cryptoKey);
const keyBase64 = Buffer.from(new Uint8Array(exportedKey)).toString("base64");
link.shortURL += `#${keyBase64}`;
link.secureShortURL += `#${keyBase64}`;
return link;
},
/**
* Shorten links in bulk. Method accepts up to 1000 links in one API call.

@@ -183,0 +239,0 @@ * API reference: https://developers.short.io/reference/linksbulkpost

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc