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

anymock-openapi

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anymock-openapi - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

lib/interface.d.ts

13

lib/base.d.ts
import { IAnymockConfigUpdate } from 'anymock-include';
import MockCtx from '.';
import { IAnymockResponse } from './types';
export declare type IRequestOption<T> = T;
export default class Base {
protected ctx: MockCtx;
constructor(ctx: MockCtx);
request<T extends object>(
path: string,
payload: IRequestOption<T>,
options: IAnymockConfigUpdate
): Promise<any>;
protected ctx: MockCtx;
constructor(ctx: MockCtx);
request<T extends object>(path: string, payload: IRequestOption<T>, options: IAnymockConfigUpdate): Promise<IAnymockResponse<any>>;
}
//# sourceMappingURL=base.d.ts.map
//# sourceMappingURL=base.d.ts.map

@@ -10,34 +10,36 @@ "use strict";

// 请求api
async request(path, payload, options) {
// 判断 token 是否合法
const finalConfig = Object.assign({}, this.ctx.anymockConfig, options); // 请求时可覆盖
const projectToken = finalConfig.projectToken;
let finalData = payload;
if (!anymock_client_token_1.isValidToken(finalConfig.projectToken)) {
throw new Error(`missing or invalid project token: ${projectToken}`);
return;
}
// 序列化数据,去掉 undefined
try {
finalData = JSON.parse(JSON.stringify(finalData));
}
catch (err) {
// 静默
console && console.warn && console.warn('Anymock 数据序列化失败:', err);
}
// 从 token 中拿到密钥
const { accessId, accessSecret } = anymock_client_token_1.tokenToAk(projectToken);
// 对 mock 数据加签
const signature = await anymock_client_token_1.default(accessSecret, finalData);
return this.ctx.requestPipe({
url: `${finalConfig.host}/openapi${path}`,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
_accessid: accessId,
_signature: signature,
_from: finalConfig.fromClient,
},
method: 'POST',
data: finalData,
request(path, payload, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
// 判断 token 是否合法
const finalConfig = Object.assign({}, this.ctx.anymockConfig, options); // 请求时可覆盖
const projectToken = finalConfig.projectToken;
let finalData = payload;
if (!anymock_client_token_1.isValidToken(finalConfig.projectToken)) {
throw new Error(`missing or invalid project token: ${projectToken}`);
return;
}
// 序列化数据,去掉 undefined
try {
finalData = JSON.parse(JSON.stringify(finalData));
}
catch (err) {
// 静默
console && console.warn && console.warn('Anymock 数据序列化失败:', err);
}
// 从 token 中拿到密钥
const { accessId, accessSecret } = anymock_client_token_1.tokenToAk(projectToken);
// 对 mock 数据加签
const signature = yield anymock_client_token_1.default(accessSecret, finalData);
return this.ctx.requestPipe({
url: `${finalConfig.host}/openapi${path}`,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
_accessid: accessId,
_signature: signature,
_from: finalConfig.fromClient,
},
method: 'POST',
data: finalData,
});
});

@@ -44,0 +46,0 @@ }

import { IAnymockConfigUpdate, IRequestPipe } from 'anymock-include';
import Interface from './interface';
import Mock from './mock';
import Project from './project';
import Request from './request';
export default class AnymockOpenapi {
mock: Mock;
project: Project;
anymockConfig: IAnymockConfigUpdate;
requestPipe: IRequestPipe;
constructor(anymockConfig: IAnymockConfigUpdate, requestPipe?: IRequestPipe);
mock: Mock;
project: Project;
interface: Interface;
request: Request;
anymockConfig: IAnymockConfigUpdate;
requestPipe: IRequestPipe;
constructor(anymockConfig: IAnymockConfigUpdate, requestPipe?: IRequestPipe);
setProjectToken(projectToken: string): AnymockOpenapi;
}
//# sourceMappingURL=index.d.ts.map
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -5,7 +5,9 @@ "use strict";

const anymock_include_1 = require("anymock-include");
const interface_1 = tslib_1.__importDefault(require("./interface"));
const mock_1 = tslib_1.__importDefault(require("./mock"));
const project_1 = tslib_1.__importDefault(require("./project"));
const request_1 = tslib_1.__importDefault(require("./request"));
// declare var window: Window & typeof globalThis;
let fromClient;
if (typeof window === 'object' && typeof window.location == 'object') {
if (typeof window === 'object' && typeof window.location === 'object') {
fromClient = window.location.host || anymock_include_1.EClients.unknownAnymock;

@@ -29,5 +31,12 @@ }

this.project = new project_1.default(this);
this.interface = new interface_1.default(this);
this.request = new request_1.default(this);
}
setProjectToken(projectToken) {
this.anymockConfig = Object.assign({}, this.anymockConfig, { projectToken });
return this;
}
}
exports.default = AnymockOpenapi;
//# sourceMappingURL=index.js.map
tslib_1.__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map
import { IAnymockConfigUpdate, IMockQueryPayload } from 'anymock-include';
import Base from './base';
import { IAnymockResponse, ID, IMock } from './types';
interface IMockResp {
mock: {
data: string;
};
}
export default class Mock extends Base {
query(payload: IMockQueryPayload, options?: IAnymockConfigUpdate): Promise<any>;
query(payload: IMockQueryPayload, options?: IAnymockConfigUpdate): Promise<IAnymockResponse<IMockResp>>;
/**
* 更新 Mock
* 仅允许更新 Mock 数据和入参过滤器
* 根据项目 Token 解析出 project id,从而在该项目更新一个目标接口
*/
update(requestId: ID, mockId: ID, payload: Pick<IMock, 'data'>): Promise<IAnymockResponse<any>>;
}
//# sourceMappingURL=mock.d.ts.map
export {};
//# sourceMappingURL=mock.d.ts.map

@@ -6,7 +6,19 @@ "use strict";

class Mock extends base_1.default {
async query(payload, options) {
return this.request('/mock/query', payload, options);
query(payload, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.request('/mock/query', payload, options);
});
}
/**
* 更新 Mock
* 仅允许更新 Mock 数据和入参过滤器
* 根据项目 Token 解析出 project id,从而在该项目更新一个目标接口
*/
update(requestId, mockId, payload) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.request(`/request/${requestId}/mock/${mockId}/update`, payload, {});
});
}
}
exports.default = Mock;
//# sourceMappingURL=mock.js.map

@@ -0,38 +1,43 @@

/**
* 项目 SDK
*/
import { IAnymockConfigUpdate } from 'anymock-include';
import Base from './base';
interface IGetProjectPayload {
[key: string]: any;
[key: string]: any;
}
interface IAnymockResponse<T> {
success: boolean;
data: T;
success: boolean;
data: T;
}
interface IProject {
id: number;
gmtCreate: string;
gmtModified: string;
name: string;
cname: string;
avatar?: any;
description: string;
spaceId: number;
status: number;
token: string;
members: IMember[];
id: number;
gmtCreate: string;
gmtModified: string;
name: string;
cname: string;
avatar?: any;
description: string;
spaceId: number;
status: number;
token: string;
members: IMember[];
}
interface IMember {
id: number;
anymockId: string;
userId: string;
userName: string;
nickName: string;
avatar: string;
id: number;
anymockId: string;
userId: string;
userName: string;
nickName: string;
avatar: string;
}
export default class Project extends Base {
get(
options?: IAnymockConfigUpdate,
payload?: IGetProjectPayload
): Promise<IAnymockResponse<IProject>>;
/**
* 获取项目详情
* @param options
* @param payload
*/
get(options?: IAnymockConfigUpdate, payload?: IGetProjectPayload): Promise<IAnymockResponse<IProject>>;
}
export {};
//# sourceMappingURL=project.d.ts.map
//# sourceMappingURL=project.d.ts.map

@@ -6,4 +6,11 @@ "use strict";

class Project extends base_1.default {
async get(options, payload = {}) {
return this.request('/project/get', payload, options);
/**
* 获取项目详情
* @param options
* @param payload
*/
get(options, payload = {}) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.request('/project/get', payload, options);
});
}

@@ -10,0 +17,0 @@ }

{
"name": "anymock-openapi",
"version": "0.1.8",
"version": "0.1.9",
"main": "lib/index.js",

@@ -28,3 +28,3 @@ "types": "./lib/index.d.ts",

},
"gitHead": "319489f717e2298b740ccd386b1c2f0d5263a6e9"
"gitHead": "d0d5e545cde73961097d20ec7e90c84d47d88e27"
}

@@ -122,1 +122,11 @@ # anymock-openapi

```
## Develop
### UT
单测项目:http://anymock.local.alipay.net:7002/project/2000008/workspace
```sh
yarn test packages/openapi/__tests__/basic.spec.ts
```

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

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

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