@orderly.network/net 1.0.112-alpha.2 → 1.0.113-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +0,0 @@
1
- import { get } from "../src";
2
-
3
- test("get function", async () => {
4
- const res = await get("https://testnet-api.orderly.org/v1/public/info");
5
- const data = await res.json();
6
-
7
- // expect(res).toEqual({
8
- // completed: false,
9
- // id: 1,
10
- // title: "delectus aut autem",
11
- // userId: 1,
12
- // });
13
- });
package/babel.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- ["@babel/preset-env", { targets: { node: "current" } }],
4
- "@babel/preset-typescript",
5
- ],
6
- };
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const __ORDERLY_API_URL_KEY__: string = "__ORDERLY_API_URL__";
@@ -1,6 +0,0 @@
1
- export class ApiError extends Error {
2
- constructor(message: string, private readonly code: number) {
3
- super(message);
4
- this.name = "ApiError";
5
- }
6
- }
@@ -1,130 +0,0 @@
1
- import { ApiError } from "@/errors/apiError";
2
-
3
- async function request(url: string, options: RequestInit) {
4
- //
5
- if (!url.startsWith("http")) {
6
- throw new Error("url must start with http(s)");
7
- }
8
- // const urlInstance = new URL(url);
9
- const response = await fetch(url, {
10
- ...options,
11
- // mode: "cors",
12
- // credentials: "include",
13
- headers: _createHeaders(options.headers, options.method),
14
- });
15
-
16
- if (response.ok) {
17
- const res = await response.json();
18
- return res;
19
- // if (res.success) {
20
- // return res;
21
- // } else {
22
- // throw new Error(res.message);
23
- // }
24
- } else {
25
- // console.log(response.status);
26
- try {
27
- const errorMsg = await response.json();
28
- if (response.status === 400) {
29
- throw new ApiError(
30
- errorMsg.message || errorMsg.code || response.statusText,
31
- errorMsg.code
32
- );
33
- }
34
- throw new Error(errorMsg.message || errorMsg.code || response.statusText);
35
- } catch (e) {
36
- throw e;
37
- }
38
- }
39
-
40
- // throw new Error(response.statusText);
41
- }
42
-
43
- function _createHeaders(
44
- headers: HeadersInit = {},
45
- method?: string
46
- ): HeadersInit {
47
- //
48
- const _headers = new Headers(headers);
49
- // _headers.append("Accept", "application/json");
50
-
51
- if (!_headers.has("Content-Type")) {
52
- if (method !== "DELETE") {
53
- _headers.append("Content-Type", "application/json;charset=utf-8");
54
- } else {
55
- _headers.append("Content-Type", "application/x-www-form-urlencoded");
56
- }
57
- }
58
-
59
- return _headers;
60
- }
61
-
62
- async function get<R>(
63
- url: string,
64
- options?: RequestInit,
65
- formatter?: (data: any) => R
66
- ): Promise<R> {
67
- const res = await request(url, {
68
- method: "GET",
69
- ...options,
70
- });
71
-
72
- if (res.success) {
73
- if (typeof formatter === "function") {
74
- return formatter(res.data);
75
- }
76
- // 根据返回的数据结构,返回需要的数据
77
- if (Array.isArray(res.data["rows"])) {
78
- return res.data["rows"] as unknown as R;
79
- }
80
- return res.data;
81
- }
82
- throw new Error(res.message);
83
- }
84
- async function post(
85
- url: string,
86
- data: any,
87
- options?: Omit<RequestInit, "method">
88
- ): Promise<any> {
89
- const res = await request(url, {
90
- method: "POST",
91
- body: JSON.stringify(data),
92
- ...options,
93
- });
94
-
95
- return res;
96
- }
97
-
98
- async function put(
99
- url: string,
100
- data: any,
101
- options?: Omit<RequestInit, "method">
102
- ): Promise<any> {
103
- const res = await request(url, {
104
- method: "PUT",
105
- body: JSON.stringify(data),
106
- ...options,
107
- });
108
-
109
- return res;
110
- }
111
-
112
- async function del(
113
- url: string,
114
- options?: Omit<RequestInit, "method">
115
- ): Promise<any> {
116
- const res = await request(url, {
117
- method: "DELETE",
118
- ...options,
119
- });
120
-
121
- return res;
122
- }
123
-
124
- async function mutate(url: string, init: RequestInit) {
125
- const res = await request(url, init);
126
-
127
- return res;
128
- }
129
-
130
- export { get, post, del, put, mutate };
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export { default as version } from "./version";
2
- export { get, post, del, put, mutate } from "./fetch";
3
-
4
- export { __ORDERLY_API_URL_KEY__ } from "./constants";
5
-
6
- export { WS, WebSocketEvent } from "./ws/ws";
package/src/sum.test.ts DELETED
@@ -1,5 +0,0 @@
1
- import { sum } from "./sum";
2
-
3
- test("adds 1 + 2 to equal 3", () => {
4
- expect(sum(1, 2)).toBe(3);
5
- });
package/src/sum.ts DELETED
@@ -1 +0,0 @@
1
- export const sum = (a: number, b: number): number => a + b;
package/src/types/ws.ts DELETED
@@ -1,13 +0,0 @@
1
- export type MessageObserveTopic = {
2
- event: "subscribe" | "unsubscribe";
3
- topic: string;
4
- };
5
-
6
- export type MessageObserveParams = string | MessageObserveTopic;
7
-
8
- export type SendFunc = (message: any) => void;
9
-
10
- export interface MessageHandler {
11
- // wsSubject: WebSocketSubject<any>;
12
- handle: (message: any, webSocket: WebSocket) => void;
13
- }
package/src/version.ts DELETED
@@ -1,14 +0,0 @@
1
-
2
- declare global {
3
- interface Window {
4
- __ORDERLY_VERSION__?: {
5
- [key: string]: string;
6
- };
7
- }
8
- }
9
- if(typeof window !== 'undefined') {
10
- window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
11
- window.__ORDERLY_VERSION__["@orderly.network/net"] = "1.0.112-alpha.2";
12
- };
13
-
14
- export default "1.0.112-alpha.2";
@@ -1,7 +0,0 @@
1
- import { MessageHandler } from "@/types/ws";
2
-
3
- export default class BaseHandler implements MessageHandler {
4
- handle(message: any, webSocket: WebSocket) {
5
- throw new Error("Method not implemented.");
6
- }
7
- }
@@ -1,17 +0,0 @@
1
- import { MessageHandler } from "@/types/ws";
2
- import PingHandler from "./ping";
3
-
4
- export type MessageType =
5
- | "ping"
6
- | "pong"
7
- | "subscribe"
8
- | "unsubscribe"
9
- | "authenticate"
10
- | "message"
11
- | "error"
12
- | "auth"
13
- | "close";
14
-
15
- export const messageHandlers = new Map<MessageType, MessageHandler>([
16
- ["ping", new PingHandler()],
17
- ]);
@@ -1,7 +0,0 @@
1
- import BaseHandler from "./baseHandler";
2
-
3
- export default class PingHandler extends BaseHandler {
4
- handle(_: any, webSocket: WebSocket) {
5
- webSocket.send(JSON.stringify({ event: "pong", ts: Date.now() }));
6
- }
7
- }