Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@substrate/playground-client

Package Overview
Dependencies
Maintainers
19
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@substrate/playground-client - npm Package Compare versions

Comparing version 1.7.2 to 1.8.0

dist/browser/auth.d.ts

10

dist/browser/index.d.ts

@@ -16,2 +16,4 @@ import { Playground, Pool, Workspace, WorkspaceConfiguration, WorkspaceUpdateConfiguration, User, UserConfiguration, UserUpdateConfiguration, Repository, RepositoryConfiguration, RepositoryUpdateConfiguration, RepositoryVersion, RepositoryVersionConfiguration, SessionConfiguration, Session, SessionUpdateConfiguration, Template } from './types';

constructor(base: string, timeout?: number, defaultInit?: RequestInit);
login(bearer: string, init?: RequestInit): Promise<void>;
logout(init?: RequestInit): Promise<void>;
path(...resources: string[]): string;

@@ -40,3 +42,3 @@ loginPath(queryParams?: string): string;

getSession(id: string, init?: RequestInit): Promise<Session | null>;
listSessions(init?: RequestInit): Promise<Record<string, Session>>;
listSessions(init?: RequestInit): Promise<Session[]>;
createSession(id: string, conf: SessionConfiguration, init?: RequestInit): Promise<void>;

@@ -54,9 +56,7 @@ updateSession(id: string, conf: SessionUpdateConfiguration, init?: RequestInit): Promise<void>;

deleteRepositoryVersion(id: Repository['id'], version: string, init?: RequestInit): Promise<void>;
listTemplates(init?: RequestInit): Promise<Record<string, Template>>;
listTemplates(init?: RequestInit): Promise<Template[]>;
getPool(id: Pool['id'], init?: RequestInit): Promise<Pool | null>;
listPools(init?: RequestInit): Promise<Pool[]>;
login(bearer: string, init?: RequestInit): Promise<Response>;
logout(init?: RequestInit): Promise<Response>;
}
export * from "./login";
export * from "./auth";
export * from "./rpc";

@@ -63,0 +63,0 @@ export * from "./workspace";

@@ -11,2 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { fetchWithTimeout, rpc } from './rpc';
function extractCookies(response) {
const raw = response.headers.raw()['set-cookie'];
return raw.map((entry) => {
const parts = entry.split(';');
const cookiePart = parts[0];
return cookiePart;
}).join(';');
}
export class Client {

@@ -18,2 +26,23 @@ constructor(base, timeout = 10000, defaultInit) {

}
// Login
login(bearer, init = this.defaultInit) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield fetchWithTimeout(`${this.path('login')}?bearer=${bearer}`, init, this.timeout);
const headers = this.defaultInit.headers;
if (!(headers instanceof Headers)) {
throw Error('Unsupported headers type');
}
headers.set('set-cookie', response.headers.get('set-cookie'));
});
}
logout(init = this.defaultInit) {
return __awaiter(this, void 0, void 0, function* () {
yield fetchWithTimeout(this.path('logout'), init, this.timeout);
const headers = this.defaultInit.headers;
if (!(headers instanceof Headers)) {
throw Error('Unsupported headers type');
}
headers.delete('set-cookie');
});
}
path(...resources) {

@@ -219,13 +248,2 @@ return [this.base, ...resources].join("/");

}
// Login
login(bearer, init = this.defaultInit) {
return __awaiter(this, void 0, void 0, function* () {
return fetchWithTimeout(`${this.path('login')}?bearer=${bearer}`, Object.assign({}, init), this.timeout);
});
}
logout(init = this.defaultInit) {
return __awaiter(this, void 0, void 0, function* () {
return fetchWithTimeout(this.path('logout'), init, this.timeout);
});
}
}

@@ -241,3 +259,3 @@ Client.userResource = 'user';

Client.poolsResource = 'pools';
export * from "./login";
export * from "./auth";
export * from "./rpc";

@@ -244,0 +262,0 @@ export * from "./workspace";

@@ -11,3 +11,3 @@ export declare enum RpcErrorCode {

}
export declare function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeout: any): Promise<Response>;
export declare function rpc<T>(input: string, init: RequestInit, timeout: number): Promise<T>;
export declare function fetchWithTimeout(input: RequestInfo, { signal, ...options }: RequestInit, timeout: number): Promise<Response>;
export declare function rpc<T>(input: string, { headers, ...options }: RequestInit, timeout: number): Promise<T>;

@@ -10,2 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
export var RpcErrorCode;

@@ -22,9 +33,12 @@ (function (RpcErrorCode) {

})(RpcErrorCode || (RpcErrorCode = {}));
export function fetchWithTimeout(input, init, timeout) {
// `fetch` but with a `timeout` in milliseconds. Relies on `AbortController`.
export function fetchWithTimeout(input, _a = {}, timeout) {
var { signal } = _a, options = __rest(_a, ["signal"]);
return __awaiter(this, void 0, void 0, function* () {
const controller = new AbortController();
if (signal)
signal.addEventListener("abort", () => controller.abort());
const id = setTimeout(() => controller.abort(), timeout);
const response = yield fetch(input, Object.assign(Object.assign({}, init), { signal: controller.signal }));
clearTimeout(id);
return response;
const response = fetch(input, Object.assign(Object.assign({}, options), { signal: controller.signal }));
return response.finally(() => clearTimeout(id));
});

@@ -35,8 +49,4 @@ }

try {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const response = yield fetch(input, Object.assign(Object.assign({}, init), { signal: controller.signal }));
clearTimeout(id);
const response = yield fetchWithTimeout(input, init, timeout);
if (response.ok) {
// TODO check content-type
try {

@@ -68,6 +78,7 @@ const { result, error } = yield response.json();

}
export function rpc(input, init, timeout) {
export function rpc(input, _a = {}, timeout) {
var { headers } = _a, options = __rest(_a, ["headers"]);
return __awaiter(this, void 0, void 0, function* () {
return yield call(input, Object.assign({ method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }, init), timeout);
return yield call(input, Object.assign({ method: 'GET', headers: Object.assign({ 'Accept': 'application/json', 'Content-Type': 'application/json' }, headers) }, options), timeout);
});
}

@@ -14,3 +14,2 @@ export interface IdentifiedResource {

export interface Environment {
secured: boolean;
host: string;

@@ -17,0 +16,0 @@ namespace: string;

@@ -16,2 +16,4 @@ import { Playground, Pool, Workspace, WorkspaceConfiguration, WorkspaceUpdateConfiguration, User, UserConfiguration, UserUpdateConfiguration, Repository, RepositoryConfiguration, RepositoryUpdateConfiguration, RepositoryVersion, RepositoryVersionConfiguration, SessionConfiguration, Session, SessionUpdateConfiguration, Template } from './types';

constructor(base: string, timeout?: number, defaultInit?: RequestInit);
login(bearer: string, init?: RequestInit): Promise<void>;
logout(init?: RequestInit): Promise<void>;
path(...resources: string[]): string;

@@ -40,3 +42,3 @@ loginPath(queryParams?: string): string;

getSession(id: string, init?: RequestInit): Promise<Session | null>;
listSessions(init?: RequestInit): Promise<Record<string, Session>>;
listSessions(init?: RequestInit): Promise<Session[]>;
createSession(id: string, conf: SessionConfiguration, init?: RequestInit): Promise<void>;

@@ -54,9 +56,7 @@ updateSession(id: string, conf: SessionUpdateConfiguration, init?: RequestInit): Promise<void>;

deleteRepositoryVersion(id: Repository['id'], version: string, init?: RequestInit): Promise<void>;
listTemplates(init?: RequestInit): Promise<Record<string, Template>>;
listTemplates(init?: RequestInit): Promise<Template[]>;
getPool(id: Pool['id'], init?: RequestInit): Promise<Pool | null>;
listPools(init?: RequestInit): Promise<Pool[]>;
login(bearer: string, init?: RequestInit): Promise<Response>;
logout(init?: RequestInit): Promise<Response>;
}
export * from "./login";
export * from "./auth";
export * from "./rpc";

@@ -63,0 +63,0 @@ export * from "./workspace";

@@ -71,2 +71,10 @@ "use strict";

var rpc_1 = require("./rpc");
function extractCookies(response) {
var raw = response.headers.raw()['set-cookie'];
return raw.map(function (entry) {
var parts = entry.split(';');
var cookiePart = parts[0];
return cookiePart;
}).join(';');
}
var Client = /** @class */ (function () {

@@ -79,2 +87,41 @@ function Client(base, timeout, defaultInit) {

}
// Login
Client.prototype.login = function (bearer, init) {
if (init === void 0) { init = this.defaultInit; }
return __awaiter(this, void 0, void 0, function () {
var response, headers;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, rpc_1.fetchWithTimeout)("".concat(this.path('login'), "?bearer=").concat(bearer), init, this.timeout)];
case 1:
response = _a.sent();
headers = this.defaultInit.headers;
if (!(headers instanceof Headers)) {
throw Error('Unsupported headers type');
}
headers.set('set-cookie', response.headers.get('set-cookie'));
return [2 /*return*/];
}
});
});
};
Client.prototype.logout = function (init) {
if (init === void 0) { init = this.defaultInit; }
return __awaiter(this, void 0, void 0, function () {
var headers;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, rpc_1.fetchWithTimeout)(this.path('logout'), init, this.timeout)];
case 1:
_a.sent();
headers = this.defaultInit.headers;
if (!(headers instanceof Headers)) {
throw Error('Unsupported headers type');
}
headers.delete('set-cookie');
return [2 /*return*/];
}
});
});
};
Client.prototype.path = function () {

@@ -396,19 +443,2 @@ var resources = [];

};
// Login
Client.prototype.login = function (bearer, init) {
if (init === void 0) { init = this.defaultInit; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, rpc_1.fetchWithTimeout)("".concat(this.path('login'), "?bearer=").concat(bearer), __assign({}, init), this.timeout)];
});
});
};
Client.prototype.logout = function (init) {
if (init === void 0) { init = this.defaultInit; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, rpc_1.fetchWithTimeout)(this.path('logout'), init, this.timeout)];
});
});
};
Client.userResource = 'user';

@@ -426,3 +456,3 @@ Client.usersResource = 'users';

exports.Client = Client;
__exportStar(require("./login"), exports);
__exportStar(require("./auth"), exports);
__exportStar(require("./rpc"), exports);

@@ -429,0 +459,0 @@ __exportStar(require("./workspace"), exports);

@@ -11,3 +11,3 @@ export declare enum RpcErrorCode {

}
export declare function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeout: any): Promise<Response>;
export declare function rpc<T>(input: string, init: RequestInit, timeout: number): Promise<T>;
export declare function fetchWithTimeout(input: RequestInfo, { signal, ...options }: RequestInit, timeout: number): Promise<Response>;
export declare function rpc<T>(input: string, { headers, ...options }: RequestInit, timeout: number): Promise<T>;

@@ -49,2 +49,13 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -63,16 +74,15 @@ exports.rpc = exports.fetchWithTimeout = exports.RpcErrorCode = void 0;

})(RpcErrorCode = exports.RpcErrorCode || (exports.RpcErrorCode = {}));
function fetchWithTimeout(input, init, timeout) {
// `fetch` but with a `timeout` in milliseconds. Relies on `AbortController`.
function fetchWithTimeout(input, _a, timeout) {
if (_a === void 0) { _a = {}; }
var signal = _a.signal, options = __rest(_a, ["signal"]);
return __awaiter(this, void 0, void 0, function () {
var controller, id, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
controller = new AbortController();
id = setTimeout(function () { return controller.abort(); }, timeout);
return [4 /*yield*/, fetch(input, __assign(__assign({}, init), { signal: controller.signal }))];
case 1:
response = _a.sent();
clearTimeout(id);
return [2 /*return*/, response];
}
return __generator(this, function (_b) {
controller = new AbortController();
if (signal)
signal.addEventListener("abort", function () { return controller.abort(); });
id = setTimeout(function () { return controller.abort(); }, timeout);
response = fetch(input, __assign(__assign({}, options), { signal: controller.signal }));
return [2 /*return*/, response.finally(function () { return clearTimeout(id); })];
});

@@ -84,3 +94,3 @@ });

return __awaiter(this, void 0, void 0, function () {
var controller_1, id, response, _a, result, error, e_1, e_2;
var response, _a, result, error, e_1, e_2;
return __generator(this, function (_b) {

@@ -90,8 +100,5 @@ switch (_b.label) {

_b.trys.push([0, 8, , 9]);
controller_1 = new AbortController();
id = setTimeout(function () { return controller_1.abort(); }, timeout);
return [4 /*yield*/, fetch(input, __assign(__assign({}, init), { signal: controller_1.signal }))];
return [4 /*yield*/, fetchWithTimeout(input, init, timeout)];
case 1:
response = _b.sent();
clearTimeout(id);
if (!response.ok) return [3 /*break*/, 6];

@@ -130,8 +137,10 @@ _b.label = 2;

}
function rpc(input, init, timeout) {
function rpc(input, _a, timeout) {
if (_a === void 0) { _a = {}; }
var headers = _a.headers, options = __rest(_a, ["headers"]);
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, call(input, __assign({ method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }, init), timeout)];
case 1: return [2 /*return*/, _a.sent()];
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, call(input, __assign({ method: 'GET', headers: __assign({ 'Accept': 'application/json', 'Content-Type': 'application/json' }, headers) }, options), timeout)];
case 1: return [2 /*return*/, _b.sent()];
}

@@ -138,0 +147,0 @@ });

@@ -14,3 +14,2 @@ export interface IdentifiedResource {

export interface Environment {
secured: boolean;
host: string;

@@ -17,0 +16,0 @@ namespace: string;

{
"name": "@substrate/playground-client",
"version": "1.7.2",
"version": "1.8.0",
"description": "An isomorphic client for Substrate Playground",

@@ -37,4 +37,4 @@ "main": "dist/main/index.js",

"devDependencies": {
"typescript": "4.5.4"
"typescript": "4.5.5"
}
}
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