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

getui-rest-sdk

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getui-rest-sdk - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

9

dist/src/getui.d.ts
import { Alias } from './other';
import { Target, SingleMessage, AppMessage, ListMessage, TagMessage, TargetList, BatchTask, Condition } from './message';
export declare const GetuiError: any;
/**

@@ -15,12 +16,16 @@ * 个推配置

*/
export default class Getui {
export declare class Getui {
options: GetuiOption;
private rp;
private authToken;
private authTokenAcquireTime;
private waitQueue;
private connecting;
constructor(options: GetuiOption);
private request(params);
private startAuthSign();
/**
* 用户身份验证通过获得 auth_token 权限令牌,后面的请求都会自动带上 auth_token
*/
authSign(): Promise<void>;
authSign(): Promise<any>;
/**

@@ -27,0 +32,0 @@ * 将 auth_token 设为无效,以防止 auth_token 被其他人恶意使用

@@ -38,3 +38,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var timers_1 = require("timers");
var _ = require("lodash");

@@ -46,3 +45,3 @@ var rp = require("request-promise");

var log = debug('getui');
var GetuiError = createError('GetuiError', {
exports.GetuiError = createError('GetuiError', {
code: 'GETUI_ERROR',

@@ -59,2 +58,4 @@ });

function Getui(options) {
this.waitQueue = [];
this.connecting = false;
this.options = options;

@@ -72,3 +73,3 @@ this.rp = rp.defaults({

return __awaiter(this, void 0, void 0, function () {
var ret;
var ingoreUrls, ret;
return __generator(this, function (_a) {

@@ -80,2 +81,12 @@ switch (_a.label) {

}
ingoreUrls = [
'/auth_sign',
'/auth_close',
];
if (!!_.includes(ingoreUrls, params.url)) return [3 /*break*/, 2];
return [4 /*yield*/, this.authSign()];
case 1:
_a.sent();
_a.label = 2;
case 2:
if (this.authToken) {

@@ -89,6 +100,6 @@ params.headers = {

return [4 /*yield*/, this.rp(params)];
case 1:
case 3:
ret = _a.sent();
if (ret.result !== 'ok')
throw new GetuiError(ret.result, { detail: ret });
throw new exports.GetuiError(ret.result, { detail: ret });
return [2 /*return*/, ret];

@@ -99,6 +110,3 @@ }

};
/**
* 用户身份验证通过获得 auth_token 权限令牌,后面的请求都会自动带上 auth_token
*/
Getui.prototype.authSign = function () {
Getui.prototype.startAuthSign = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -122,4 +130,4 @@ var timestamp, sign, authToken;

this.authToken = authToken;
// Token 有效期24小时,提前十分钟,即每过 23 小时 50 分钟刷新
timers_1.setTimeout(this.authSign.bind(this), 86340000);
this.authTokenAcquireTime = _.now();
log("authToken: " + this.authToken + ", authTokenAcquireTime: " + this.authTokenAcquireTime);
return [2 /*return*/];

@@ -131,2 +139,45 @@ }

/**
* 用户身份验证通过获得 auth_token 权限令牌,后面的请求都会自动带上 auth_token
*/
Getui.prototype.authSign = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var elaspe, e_1, resolve;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
elaspe = _.now() - this.authTokenAcquireTime;
// 检验 token 是否超过了有效时间,官方说明为一天,考虑到网络延时,提前 10 分钟
if (this.authToken && elaspe < 8580000)
return [2 /*return*/];
if (this.connecting) {
return [2 /*return*/, new Promise(function (resolve) {
_this.waitQueue.push(resolve);
})];
}
this.connecting = true;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.startAuthSign()];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
this.connecting = false;
throw e_1;
case 4:
this.connecting = false;
log("wait queue lenght: " + this.waitQueue.length);
while (this.waitQueue.length) {
resolve = this.waitQueue.pop();
resolve();
}
return [2 /*return*/];
}
});
});
};
/**
* 将 auth_token 设为无效,以防止 auth_token 被其他人恶意使用

@@ -764,3 +815,3 @@ */

}());
exports.default = Getui;
exports.Getui = Getui;
//# sourceMappingURL=getui.js.map

@@ -7,3 +7,3 @@ export * from './message';

export * from './other';
import Getui from './getui';
import { Getui } from './getui';
export default Getui;

@@ -13,3 +13,3 @@ "use strict";

var getui_1 = require("./getui");
exports.default = getui_1.default;
exports.default = getui_1.Getui;
//# sourceMappingURL=index.js.map
{
"name": "getui-rest-sdk",
"version": "0.2.3",
"version": "0.3.0",
"description": "Getui rest api for node.js, in TypeScript",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -37,3 +37,2 @@ # Getui Rest SDK

const gt = new Getui(option);
await gt.authSign();
```

@@ -40,0 +39,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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