@teardown/react-native 1.2.31 → 1.2.33

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teardown/react-native",
3
- "version": "1.2.31",
3
+ "version": "1.2.33",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -16,9 +16,9 @@
16
16
  "dependencies": {
17
17
  "@react-native/dev-middleware": "^0.76.1",
18
18
  "@teardown/cli": "^1.2.20",
19
- "@teardown/logger": "1.2.31",
20
- "@teardown/util": "1.2.31",
21
- "@teardown/websocket": "1.2.31",
19
+ "@teardown/logger": "1.2.33",
20
+ "@teardown/util": "1.2.33",
21
+ "@teardown/websocket": "1.2.33",
22
22
  "async-mutex": "^0.5.0",
23
23
  "chalk": "^5.3.0",
24
24
  "compression": "^1.7.5",
@@ -28,7 +28,7 @@
28
28
  "ws": "^8.18.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@teardown/config": "1.2.31",
31
+ "@teardown/config": "1.2.33",
32
32
  "@types/compression": "^1.7.5",
33
33
  "@types/connect": "^3.4.38",
34
34
  "@types/react": "^18.3.12",
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import type { FunctionComponent } from "react";
2
- import { type SvgProps } from "react-native-svg";
3
- export type TeardownLogoProps = SvgProps;
4
- export declare const TeardownLogo: FunctionComponent<TeardownLogoProps>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.TeardownLogo = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_native_svg_1 = __importStar(require("react-native-svg"));
29
- const TeardownLogo = (props) => {
30
- const {} = props;
31
- return ((0, jsx_runtime_1.jsx)(react_native_svg_1.default, { width: "350", height: "350", viewBox: "0 0 350 350", fill: "none", ...props, children: (0, jsx_runtime_1.jsx)(react_native_svg_1.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M175.09 345L300 218.574L256.859 174.909L299.821 131.426L174.91 5.00001L50 131.426L93.141 175.091L50.179 218.574L175.09 345ZM114.879 197.093L93.656 218.574L175.09 300.995L256.523 218.574L235.12 196.911L174.91 257.853L114.879 197.093ZM213.382 174.909L174.91 213.848L136.618 175.091L175.09 136.152L213.382 174.909ZM235.12 152.907L175.09 92.147L114.879 153.089L93.477 131.426L174.91 49.005L256.344 131.426L235.12 152.907Z", fill: "white" }) }));
32
- };
33
- exports.TeardownLogo = TeardownLogo;
@@ -1 +0,0 @@
1
- export * from './teardown.container';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./teardown.container"), exports);
@@ -1,8 +0,0 @@
1
- import type { FunctionComponent, PropsWithChildren } from "react";
2
- import type { PluginTuple, TeardownClient } from "../teardown.client";
3
- export type TeardownContainerOptions = {};
4
- export type TeardownContainerProps<T extends readonly PluginTuple[]> = PropsWithChildren<{
5
- client: TeardownClient<T>;
6
- options?: TeardownContainerOptions;
7
- }>;
8
- export declare const TeardownContainer: FunctionComponent<TeardownContainerProps<any>>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TeardownContainer = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const services_1 = require("../services");
6
- const react_native_safe_area_context_1 = require("react-native-safe-area-context");
7
- const react_native_gesture_handler_1 = require("react-native-gesture-handler");
8
- const TeardownContainer = (props) => {
9
- const { children, client, options } = props;
10
- const providedState = services_1.TeardownService.useProvidedState(client);
11
- return ((0, jsx_runtime_1.jsx)(react_native_safe_area_context_1.SafeAreaProvider, { children: (0, jsx_runtime_1.jsx)(react_native_gesture_handler_1.GestureHandlerRootView, { children: children }) }));
12
- };
13
- exports.TeardownContainer = TeardownContainer;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./containers";
2
- export * from "./plugins";
package/dist/index.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- // export * from './components';
18
- __exportStar(require("./containers"), exports);
19
- // export * from './services';
20
- // export * from "./teardown.client";
21
- __exportStar(require("./plugins"), exports);
@@ -1,23 +0,0 @@
1
- import type { TeardownClient } from "../teardown.client";
2
- import { type DefaultPluginOptions, Plugin } from "../teardown.client";
3
- export type HTTPPluginOptions = DefaultPluginOptions<{
4
- ignoreURLs?: RegExp[];
5
- }>;
6
- export declare class HTTPPlugin extends Plugin {
7
- private client;
8
- private requests;
9
- private ignoreURLs;
10
- constructor(options?: HTTPPluginOptions);
11
- install(client: TeardownClient<any>): void;
12
- enableXHRInterceptor(): void;
13
- disableInterception(): void;
14
- private shouldIgnoreURL;
15
- private xhrOpenCallback;
16
- private xhrRequestHeaderCallback;
17
- private xhrSendCallback;
18
- private serializeRequestBody;
19
- private xhrResponseCallback;
20
- private parseResponseHeaders;
21
- private parseResponseBody;
22
- private sendHTTPEvent;
23
- }
@@ -1,144 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HTTPPlugin = void 0;
7
- const util_1 = require("@teardown/util");
8
- // @ts-ignore
9
- const XHRInterceptor_1 = __importDefault(require("react-native/Libraries/Network/XHRInterceptor"));
10
- const teardown_client_1 = require("../teardown.client");
11
- class HTTPPlugin extends teardown_client_1.Plugin {
12
- client = null;
13
- requests = new Map();
14
- ignoreURLs;
15
- constructor(options = {}) {
16
- super({
17
- ...options,
18
- key: "HTTPPlugin",
19
- });
20
- this.ignoreURLs = options.ignoreURLs || [];
21
- }
22
- install(client) {
23
- this.client = client;
24
- this.enableXHRInterceptor();
25
- }
26
- enableXHRInterceptor() {
27
- // noinspection TypeScriptUnresolvedReference
28
- if (XHRInterceptor_1.default.isInterceptorEnabled()) {
29
- // this.logger.info(
30
- // 'XHRInterceptor is already enabled by another library. Disable it or run this plugin first when your app loads.',
31
- // );
32
- this.logger.info("XHRInterceptor is already enabled. Teardown overrides the existing interceptor - other plugins may not work as expected.");
33
- this.disableInterception();
34
- }
35
- this.logger.info("Enabling XHRInterceptor");
36
- // noinspection TypeScriptUnresolvedReference
37
- XHRInterceptor_1.default.setOpenCallback(this.xhrOpenCallback);
38
- // noinspection TypeScriptUnresolvedReference
39
- XHRInterceptor_1.default.setRequestHeaderCallback(this.xhrRequestHeaderCallback);
40
- // noinspection TypeScriptUnresolvedReference
41
- XHRInterceptor_1.default.setSendCallback(this.xhrSendCallback);
42
- // noinspection TypeScriptUnresolvedReference
43
- XHRInterceptor_1.default.setResponseCallback(this.xhrResponseCallback);
44
- // noinspection TypeScriptUnresolvedReference
45
- XHRInterceptor_1.default.enableInterception();
46
- this.logger.info("XHRInterceptor enabled");
47
- }
48
- disableInterception() {
49
- this.logger.info("Disabling XHRInterceptor");
50
- XHRInterceptor_1.default.disableInterception();
51
- this.requests.clear();
52
- this.logger.info("XHRInterceptor disabled");
53
- }
54
- shouldIgnoreURL(url) {
55
- return this.ignoreURLs.some((ignoreRegex) => ignoreRegex.test(url));
56
- }
57
- xhrOpenCallback = (method, url, xhr) => {
58
- if (this.shouldIgnoreURL(url)) {
59
- return;
60
- }
61
- const requestId = util_1.Util.generateUUID();
62
- const HTTPRequestInfo = {
63
- id: requestId,
64
- type: "XMLHttpRequest",
65
- url,
66
- method: method,
67
- requestHeaders: { "TD-Request-ID": requestId },
68
- startTime: performance.now(),
69
- updatedAt: performance.now(),
70
- };
71
- this.requests.set(xhr._id, HTTPRequestInfo);
72
- };
73
- xhrRequestHeaderCallback = (header, value, xhr) => {
74
- const request = this.requests.get(xhr._id);
75
- if (request) {
76
- request.requestHeaders[header] = value;
77
- request.updatedAt = performance.now();
78
- }
79
- };
80
- xhrSendCallback = (data, xhr) => {
81
- const request = this.requests.get(xhr._id);
82
- if (request) {
83
- xhr.setRequestHeader("TD-Request-ID", request.id);
84
- request.dataSent = this.serializeRequestBody(data);
85
- request.updatedAt = performance.now();
86
- this.sendHTTPEvent(request);
87
- }
88
- };
89
- serializeRequestBody(data) {
90
- if (typeof data === "string") {
91
- return data;
92
- }
93
- try {
94
- return JSON.stringify(data);
95
- }
96
- catch (error) {
97
- this.logger.warn("Failed to stringify request body", error);
98
- return "[Unable to serialize request body]";
99
- }
100
- }
101
- xhrResponseCallback = (status, timeout, response, responseURL, responseType, xhr) => {
102
- const request = this.requests.get(xhr._id);
103
- if (request) {
104
- request.status = status;
105
- request.responseHeaders = this.parseResponseHeaders(xhr.getAllResponseHeaders());
106
- request.response = this.parseResponseBody(response, responseType);
107
- request.responseURL = responseURL;
108
- request.responseType = responseType;
109
- request.timeout = timeout;
110
- request.endTime = performance.now();
111
- request.updatedAt = performance.now();
112
- this.sendHTTPEvent(request);
113
- this.requests.delete(xhr._id);
114
- }
115
- };
116
- parseResponseHeaders(headersString) {
117
- const headersObject = {};
118
- if (headersString) {
119
- const headerPairs = headersString.trim().split(/[\r\n]+/);
120
- headerPairs.forEach((headerPair) => {
121
- const [key, value] = headerPair.split(": ");
122
- headersObject[key] = value;
123
- });
124
- }
125
- return headersObject;
126
- }
127
- parseResponseBody(response, responseType) {
128
- if (responseType === "json") {
129
- try {
130
- return JSON.stringify(JSON.parse(response), null, 2);
131
- }
132
- catch (error) {
133
- this.logger.warn("Failed to parse JSON response", error);
134
- }
135
- }
136
- return response;
137
- }
138
- sendHTTPEvent(httpRequestInfo) {
139
- // if (this.client?.debugger) {
140
- // this.client.debugger.send("NETWORK_HTTP_REQUEST", httpRequestInfo);
141
- // }
142
- }
143
- }
144
- exports.HTTPPlugin = HTTPPlugin;
@@ -1,2 +0,0 @@
1
- export * from './http.plugin';
2
- export * from './logging.plugin';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./http.plugin"), exports);
18
- // export * from './websocket.plugin';
19
- __exportStar(require("./logging.plugin"), exports);
@@ -1,9 +0,0 @@
1
- import type { IPlugin, TeardownClient } from "../teardown.client";
2
- export declare class LoggingPlugin implements IPlugin {
3
- private client;
4
- private originalConsoleMethods;
5
- private createConsoleProxy;
6
- constructor();
7
- install(client: TeardownClient<any>): void;
8
- uninstall(): void;
9
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoggingPlugin = void 0;
4
- const methods = ["log", "warn", "error", "debug", "info"];
5
- class LoggingPlugin {
6
- client = null;
7
- originalConsoleMethods = {};
8
- createConsoleProxy(method) {
9
- const original = console[method];
10
- return new Proxy(original, {
11
- apply: (target, thisArg, args) => {
12
- target.apply(thisArg, args);
13
- // this.client?.debugger?.send("CONSOLE_LOG", {
14
- // type: method,
15
- // args,
16
- // });
17
- },
18
- });
19
- }
20
- constructor() {
21
- methods.forEach((method) => {
22
- this.originalConsoleMethods[method] = console[method];
23
- console[method] = this.createConsoleProxy(method);
24
- });
25
- }
26
- install(client) {
27
- this.client = client;
28
- }
29
- uninstall() {
30
- methods.forEach((method) => {
31
- console[method] = this.originalConsoleMethods[method];
32
- });
33
- }
34
- }
35
- exports.LoggingPlugin = LoggingPlugin;
@@ -1 +0,0 @@
1
- export {};
@@ -1,107 +0,0 @@
1
- "use strict";
2
- // @ts-ignore
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- // export class WebSocketPlugin implements IPlugin {
5
- // private logger = new Logger("WebSocketPlugin");
6
- // private client: TeardownClient<any> | null = null;
7
- // private sockets: Map<string, WebSocketInfo> = new Map();
8
- // constructor() {
9
- // this.setupWebSocketInterceptor();
10
- // }
11
- // install(client: TeardownClient<any>): void {
12
- // this.client = client;
13
- // }
14
- // private setupWebSocketInterceptor(): void {
15
- // if (WebSocketInterceptor.isInterceptorEnabled()) {
16
- // this.logger.warn(
17
- // "WebSocketInterceptor is already enabled by another library, disable it or run this first when your app loads",
18
- // );
19
- // this.disableInterception();
20
- // }
21
- // WebSocketInterceptor.setConnectCallback(this.wsConnectCallback);
22
- // WebSocketInterceptor.setSendCallback(this.wsSendCallback);
23
- // WebSocketInterceptor.setOnMessageCallback(this.wsOnMessageCallback);
24
- // WebSocketInterceptor.setOnCloseCallback(this.wsOnCloseCallback);
25
- // WebSocketInterceptor.enableInterception();
26
- // this.logger.log("WebSocketInterceptor enabled");
27
- // }
28
- // private wsConnectCallback = (
29
- // url: string,
30
- // protocols: string | string[] | undefined,
31
- // options: Object,
32
- // socketId: string,
33
- // ): void => {
34
- // const requestId = Util.generateUUID();
35
- // const socketInfo: WebSocketInfo = {
36
- // id: requestId,
37
- // url,
38
- // protocols,
39
- // timestamp: performance.now(),
40
- // };
41
- // this.sockets.set(socketId, socketInfo);
42
- // this.sendOpenEvent(socketInfo);
43
- // };
44
- // private wsSendCallback = (
45
- // data: string | ArrayBuffer | ArrayBufferView,
46
- // socketId: string,
47
- // ): void => {
48
- // const socket = this.sockets.get(socketId);
49
- // if (socket) {
50
- // const messageInfo: WebSocketMessageInfo = {
51
- // id: socket.id,
52
- // data: "", // TODO: Currently getting array buffer length errors here when sending data
53
- // timestamp: performance.now(),
54
- // direction: "sent",
55
- // };
56
- // console.log("messageInfo", messageInfo);
57
- // // this.sendMessageEvent(messageInfo);
58
- // }
59
- // };
60
- // private wsOnMessageCallback = (
61
- // socketId: string,
62
- // message: WebSocketMessageEvent,
63
- // ): void => {
64
- // const socket = this.sockets.get(socketId);
65
- // if (socket) {
66
- // const messageInfo: WebSocketMessageInfo = {
67
- // id: socket.id,
68
- // data: "", // TODO: Currently getting array buffer length errors here when sending data
69
- // timestamp: performance.now(),
70
- // direction: "received",
71
- // };
72
- // this.sendMessageEvent(messageInfo);
73
- // }
74
- // };
75
- // private wsOnCloseCallback = (socketId: string, event: any): void => {
76
- // const socket = this.sockets.get(socketId);
77
- // if (socket) {
78
- // const closeInfo: WebSocketCloseInfo = {
79
- // id: socket.id,
80
- // code: event.code,
81
- // reason: event.reason,
82
- // timestamp: performance.now(),
83
- // };
84
- // this.sendCloseEvent(closeInfo);
85
- // this.sockets.delete(socketId);
86
- // }
87
- // };
88
- // private sendOpenEvent(info: WebSocketInfo): void {
89
- // // if (this.client && this.client.debugger) {
90
- // // this.client.debugger.send("NETWORK_WEBSOCKET_OPEN", info);
91
- // // }
92
- // }
93
- // private sendMessageEvent(info: WebSocketMessageInfo): void {
94
- // // if (this.client && this.client.debugger) {
95
- // // this.client.debugger.send("NETWORK_WEBSOCKET_MESSAGE", info);
96
- // // }
97
- // }
98
- // private sendCloseEvent(info: WebSocketCloseInfo): void {
99
- // // if (this.client && this.client.debugger) {
100
- // // this.client.debugger.send("NETWORK_WEBSOCKET_CLOSE", info);
101
- // // }
102
- // }
103
- // disableInterception(): void {
104
- // WebSocketInterceptor.disableInterception();
105
- // this.sockets.clear();
106
- // }
107
- // }
@@ -1 +0,0 @@
1
- export * from './teardown.service';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./teardown.service"), exports);
@@ -1,10 +0,0 @@
1
- import type { PluginTuple, TeardownClient } from "../teardown.client";
2
- export type TeardownServiceContextType<T extends readonly PluginTuple[]> = {
3
- client: TeardownClient<T>;
4
- };
5
- export declare const TeardownService: {
6
- Context: import("react").Context<TeardownServiceContextType<any> | null>;
7
- Provider: import("react").Provider<TeardownServiceContextType<any> | null>;
8
- useState<T extends readonly PluginTuple[]>(): TeardownServiceContextType<T>;
9
- useProvidedState<T extends readonly PluginTuple[]>(client: TeardownClient<T>): TeardownServiceContextType<T>;
10
- };
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TeardownService = void 0;
4
- const react_1 = require("react");
5
- const Context = (0, react_1.createContext)(null);
6
- exports.TeardownService = {
7
- Context,
8
- Provider: Context.Provider,
9
- useState() {
10
- const state = (0, react_1.useContext)(Context);
11
- if (state == null) {
12
- throw new Error("TeardownService not found");
13
- }
14
- return state;
15
- },
16
- useProvidedState(client) {
17
- return {
18
- client
19
- };
20
- },
21
- };
@@ -1,41 +0,0 @@
1
- import { Logger } from "@teardown/logger";
2
- export interface IPlugin {
3
- install?(client: TeardownClient<any>): void;
4
- uninstall?(): void;
5
- }
6
- export type DefaultPluginOptions<T> = {
7
- debug?: boolean;
8
- } & T;
9
- export type PluginOptions<T> = DefaultPluginOptions<{
10
- key: string;
11
- }> & T;
12
- export declare abstract class Plugin<T = any> {
13
- protected logger: Logger;
14
- protected constructor(options: PluginOptions<T>);
15
- install?(client: TeardownClient<any>): void;
16
- uninstall?(): void;
17
- }
18
- export type PluginTuple = readonly [string, IPlugin];
19
- type InferPluginFromTuple<T extends PluginTuple> = {
20
- [K in T[0]]: Omit<T[1], "install" | "uninstall">;
21
- };
22
- type InferPluginsFromArray<T extends readonly PluginTuple[]> = UnionToIntersection<InferPluginFromTuple<T[number]>>;
23
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
24
- export type TeardownClientOptions<T extends readonly PluginTuple[]> = {
25
- plugins?: T;
26
- loggingEnabled?: boolean;
27
- };
28
- export declare class TeardownClient<T extends readonly PluginTuple[]> {
29
- readonly options?: TeardownClientOptions<T> | undefined;
30
- logger: Logger;
31
- private readonly plugins;
32
- api: InferPluginsFromArray<T>;
33
- constructor(options?: TeardownClientOptions<T> | undefined);
34
- private installPlugin;
35
- private uninstallPlugin;
36
- private uninstallAllPlugins;
37
- private reinstallPlugins;
38
- shutdown(): void;
39
- }
40
- export declare const createTeardownClient: <Plugins extends readonly PluginTuple[]>(plugins: Plugins) => TeardownClient<Plugins>;
41
- export {};
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTeardownClient = exports.TeardownClient = exports.Plugin = void 0;
4
- const logger_1 = require("@teardown/logger");
5
- class Plugin {
6
- logger;
7
- constructor(options) {
8
- this.logger = new logger_1.Logger(options.key, options.debug ?? false);
9
- }
10
- }
11
- exports.Plugin = Plugin;
12
- class TeardownClient {
13
- options;
14
- logger;
15
- plugins = new Map();
16
- api = {};
17
- constructor(options) {
18
- this.options = options;
19
- this.logger = new logger_1.Logger("TeardownClient", options?.loggingEnabled ?? false);
20
- // options?.plugins?.forEach(([key, plugin]) => {
21
- // this.plugins.set(key, plugin);
22
- // });
23
- this.installPlugin();
24
- }
25
- installPlugin() {
26
- this.logger.log("Installing plugins");
27
- this.plugins.forEach((plugin, key) => {
28
- plugin.install?.(this);
29
- this.api[key] = plugin;
30
- });
31
- this.logger.log("Plugins installed");
32
- }
33
- uninstallPlugin(key) {
34
- const plugin = this.plugins.get(key);
35
- if (plugin) {
36
- plugin.uninstall?.();
37
- this.plugins.delete(key);
38
- delete this.api[key];
39
- }
40
- }
41
- uninstallAllPlugins() {
42
- this.plugins.forEach((_, key) => this.uninstallPlugin(key));
43
- }
44
- reinstallPlugins() {
45
- this.uninstallAllPlugins();
46
- this.installPlugin();
47
- }
48
- shutdown() {
49
- this.uninstallAllPlugins();
50
- }
51
- }
52
- exports.TeardownClient = TeardownClient;
53
- const createTeardownClient = (plugins) => {
54
- return new TeardownClient({
55
- loggingEnabled: true,
56
- plugins,
57
- });
58
- };
59
- exports.createTeardownClient = createTeardownClient;
@@ -1,5 +0,0 @@
1
- export declare const Log: {
2
- info: (...args: any[]) => void;
3
- warn: (...args: any[]) => void;
4
- error: (...args: any[]) => void;
5
- };
package/dist/utils/log.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Log = void 0;
4
- exports.Log = {
5
- info: (...args) => console.log(...args),
6
- warn: (...args) => console.warn(...args),
7
- error: (...args) => console.error(...args),
8
- };