@zayne-labs/callapi-plugins 0.0.1
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/LICENSE +21 -0
- package/dist/esm/index.d.ts +93 -0
- package/dist/esm/index.js +136 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Ikedigwe Ebube
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import * as _zayne_labs_callapi from '@zayne-labs/callapi';
|
2
|
+
import { AnyFunction } from '@zayne-labs/toolkit-type-helpers';
|
3
|
+
|
4
|
+
type ConsoleLike = {
|
5
|
+
error: AnyFunction<void>;
|
6
|
+
fail?: AnyFunction<void>;
|
7
|
+
log: AnyFunction<void>;
|
8
|
+
success?: AnyFunction<void>;
|
9
|
+
warn?: AnyFunction<void>;
|
10
|
+
};
|
11
|
+
type LoggerOptions = {
|
12
|
+
/**
|
13
|
+
* Custom console object
|
14
|
+
*/
|
15
|
+
consoleObject?: ConsoleLike;
|
16
|
+
/**
|
17
|
+
* Enable or disable the logger
|
18
|
+
* @default true
|
19
|
+
*/
|
20
|
+
enabled?: boolean;
|
21
|
+
/**
|
22
|
+
* Enable or disable verbose mode
|
23
|
+
*/
|
24
|
+
verbose?: boolean;
|
25
|
+
};
|
26
|
+
declare const loggerPlugin: (options?: LoggerOptions) => {
|
27
|
+
id: string;
|
28
|
+
name: string;
|
29
|
+
version: string;
|
30
|
+
hooks: {
|
31
|
+
onRequest: (ctx: {
|
32
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
33
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
34
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
35
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
36
|
+
}) => void;
|
37
|
+
onRequestError: (ctx: {
|
38
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
39
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
40
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
41
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
42
|
+
error: _zayne_labs_callapi.PossibleJavaScriptError;
|
43
|
+
response: null;
|
44
|
+
}) => void;
|
45
|
+
onResponseError: (ctx: {
|
46
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
47
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
48
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
49
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
50
|
+
error: {
|
51
|
+
errorData: never;
|
52
|
+
message: string;
|
53
|
+
name: "HTTPError";
|
54
|
+
originalError: _zayne_labs_callapi.HTTPError;
|
55
|
+
};
|
56
|
+
response: Response;
|
57
|
+
}) => void;
|
58
|
+
onRetry: (ctx: ({
|
59
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
60
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
61
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
62
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
63
|
+
error: _zayne_labs_callapi.PossibleJavaScriptError;
|
64
|
+
response: null;
|
65
|
+
retryAttemptCount: number;
|
66
|
+
} | {
|
67
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
68
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
69
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
70
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
71
|
+
error: {
|
72
|
+
errorData: never;
|
73
|
+
message: string;
|
74
|
+
name: "HTTPError";
|
75
|
+
originalError: _zayne_labs_callapi.HTTPError;
|
76
|
+
};
|
77
|
+
response: Response;
|
78
|
+
retryAttemptCount: number;
|
79
|
+
}) & {
|
80
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
81
|
+
}) => void;
|
82
|
+
onSuccess: (ctx: {
|
83
|
+
baseConfig: _zayne_labs_callapi.BaseCallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
84
|
+
config: _zayne_labs_callapi.CallApiExtraOptions & _zayne_labs_callapi.CallApiRequestOptions;
|
85
|
+
options: _zayne_labs_callapi.CombinedCallApiExtraOptions & Partial<{}>;
|
86
|
+
request: _zayne_labs_callapi.CallApiRequestOptionsForHooks;
|
87
|
+
data: never;
|
88
|
+
response: Response;
|
89
|
+
}) => void;
|
90
|
+
};
|
91
|
+
};
|
92
|
+
|
93
|
+
export { type LoggerOptions, loggerPlugin };
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { definePlugin } from '@zayne-labs/callapi';
|
2
|
+
import { createConsola } from 'consola';
|
3
|
+
|
4
|
+
// src/logger/logger.ts
|
5
|
+
|
6
|
+
// src/logger/constants.ts
|
7
|
+
var statusTextMap = /* @__PURE__ */ new Map([
|
8
|
+
[100, "Continue"],
|
9
|
+
[101, "Switching Protocols"],
|
10
|
+
[102, "Processing"],
|
11
|
+
[200, "OK"],
|
12
|
+
[201, "Created"],
|
13
|
+
[202, "Accepted"],
|
14
|
+
[203, "Non-Authoritative Information"],
|
15
|
+
[204, "No Content"],
|
16
|
+
[205, "Reset Content"],
|
17
|
+
[206, "Partial Content"],
|
18
|
+
[207, "Multi-Status"],
|
19
|
+
[208, "Already Reported"],
|
20
|
+
[226, "IM Used"],
|
21
|
+
[300, "Multiple Choices"],
|
22
|
+
[301, "Moved Permanently"],
|
23
|
+
[302, "Found"],
|
24
|
+
[303, "See Other"],
|
25
|
+
[304, "Not Modified"],
|
26
|
+
[305, "Use Proxy"],
|
27
|
+
[307, "Temporary Redirect"],
|
28
|
+
[308, "Permanent Redirect"],
|
29
|
+
[400, "Bad Request"],
|
30
|
+
[401, "Unauthorized"],
|
31
|
+
[402, "Payment Required"],
|
32
|
+
[403, "Forbidden"],
|
33
|
+
[404, "Not Found"],
|
34
|
+
[405, "Method Not Allowed"],
|
35
|
+
[406, "Not Acceptable"],
|
36
|
+
[407, "Proxy Authentication Required"],
|
37
|
+
[408, "Request Timeout"],
|
38
|
+
[409, "Conflict"],
|
39
|
+
[410, "Gone"],
|
40
|
+
[411, "Length Required"],
|
41
|
+
[412, "Precondition Failed"],
|
42
|
+
[413, "Payload Too Large"],
|
43
|
+
[414, "URI Too Long"],
|
44
|
+
[415, "Unsupported Media Type"],
|
45
|
+
[416, "Range Not Satisfiable"],
|
46
|
+
[417, "Expectation Failed"],
|
47
|
+
[418, "I'm a teapot"],
|
48
|
+
[421, "Misdirected Request"],
|
49
|
+
[422, "Unprocessable Entity"],
|
50
|
+
[423, "Locked"],
|
51
|
+
[424, "Failed Dependency"],
|
52
|
+
[425, "Too Early"],
|
53
|
+
[426, "Upgrade Required"],
|
54
|
+
[428, "Precondition Required"],
|
55
|
+
[429, "Too Many Requests"],
|
56
|
+
[431, "Request Header Fields Too Large"],
|
57
|
+
[451, "Unavailable For Legal Reasons"],
|
58
|
+
[500, "Internal Server Error"],
|
59
|
+
[501, "Not Implemented"],
|
60
|
+
[502, "Bad Gateway"],
|
61
|
+
[503, "Service Unavailable"],
|
62
|
+
[504, "Gateway Timeout"],
|
63
|
+
[505, "HTTP Version Not Supported"],
|
64
|
+
[506, "Variant Also Negotiates"],
|
65
|
+
[507, "Insufficient Storage"],
|
66
|
+
[508, "Loop Detected"],
|
67
|
+
[510, "Not Extended"],
|
68
|
+
[511, "Network Authentication Required"]
|
69
|
+
]);
|
70
|
+
|
71
|
+
// src/logger/utils.ts
|
72
|
+
var getStatusText = (status) => statusTextMap.get(status) ?? "Unknown";
|
73
|
+
|
74
|
+
// src/logger/logger.ts
|
75
|
+
var consola = createConsola({
|
76
|
+
formatOptions: {
|
77
|
+
colors: true,
|
78
|
+
columns: 80,
|
79
|
+
compact: 10,
|
80
|
+
date: false,
|
81
|
+
fancy: true
|
82
|
+
}
|
83
|
+
});
|
84
|
+
var defaultConsole = {
|
85
|
+
error: (...args) => consola.error("", ...args),
|
86
|
+
fail: (...args) => consola.fail("", ...args),
|
87
|
+
log: (...args) => consola.info("", ...args),
|
88
|
+
success: (...args) => consola.success("", ...args),
|
89
|
+
warn: (...args) => consola.warn("", ...args)
|
90
|
+
};
|
91
|
+
var loggerPlugin = definePlugin((options) => {
|
92
|
+
const { consoleObject = defaultConsole, enabled = true, verbose } = options ?? {};
|
93
|
+
return {
|
94
|
+
/* eslint-disable perfectionist/sort-objects -- Ignore for now */
|
95
|
+
id: "logger",
|
96
|
+
name: "Logger",
|
97
|
+
version: "1.0.0",
|
98
|
+
hooks: {
|
99
|
+
/* eslint-enable perfectionist/sort-objects -- Ignore */
|
100
|
+
onRequest: (ctx) => {
|
101
|
+
if (!enabled) return;
|
102
|
+
consoleObject.log(`Request being sent to: ${ctx.options.fullURL}`);
|
103
|
+
},
|
104
|
+
onRequestError: (ctx) => {
|
105
|
+
if (!enabled) return;
|
106
|
+
const log = consoleObject.fail ?? consoleObject.error;
|
107
|
+
log(`Request to failed with error: ${ctx.error.name}`);
|
108
|
+
verbose && consoleObject.error(ctx.error.errorData);
|
109
|
+
},
|
110
|
+
onResponseError: (ctx) => {
|
111
|
+
if (!enabled) return;
|
112
|
+
const log = consoleObject.fail ?? consoleObject.error;
|
113
|
+
log(
|
114
|
+
"Request failed with status: ",
|
115
|
+
ctx.response.status,
|
116
|
+
`(${ctx.response.statusText || getStatusText(ctx.response.status)})`
|
117
|
+
);
|
118
|
+
verbose && consoleObject.error(ctx.error.errorData);
|
119
|
+
},
|
120
|
+
onRetry: (ctx) => {
|
121
|
+
if (!enabled) return;
|
122
|
+
const log = consoleObject.warn ?? consoleObject.log;
|
123
|
+
log(`Retrying request... Attempt: `, ctx.retryAttemptCount);
|
124
|
+
},
|
125
|
+
onSuccess: (ctx) => {
|
126
|
+
if (!enabled) return;
|
127
|
+
const log = consoleObject.success ?? consoleObject.log;
|
128
|
+
log("Request succeeded", ctx.data);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
};
|
132
|
+
});
|
133
|
+
|
134
|
+
export { loggerPlugin };
|
135
|
+
//# sourceMappingURL=index.js.map
|
136
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/logger/constants.ts","../../src/logger/utils.ts","../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAO,IAAM,aAAA,uBAAoB,GAAoB,CAAA;AAAA,EACpD,CAAC,KAAK,UAAU,CAAA;AAAA,EAChB,CAAC,KAAK,qBAAqB,CAAA;AAAA,EAC3B,CAAC,KAAK,YAAY,CAAA;AAAA,EAClB,CAAC,KAAK,IAAI,CAAA;AAAA,EACV,CAAC,KAAK,SAAS,CAAA;AAAA,EACf,CAAC,KAAK,UAAU,CAAA;AAAA,EAChB,CAAC,KAAK,+BAA+B,CAAA;AAAA,EACrC,CAAC,KAAK,YAAY,CAAA;AAAA,EAClB,CAAC,KAAK,eAAe,CAAA;AAAA,EACrB,CAAC,KAAK,iBAAiB,CAAA;AAAA,EACvB,CAAC,KAAK,cAAc,CAAA;AAAA,EACpB,CAAC,KAAK,kBAAkB,CAAA;AAAA,EACxB,CAAC,KAAK,SAAS,CAAA;AAAA,EACf,CAAC,KAAK,kBAAkB,CAAA;AAAA,EACxB,CAAC,KAAK,mBAAmB,CAAA;AAAA,EACzB,CAAC,KAAK,OAAO,CAAA;AAAA,EACb,CAAC,KAAK,WAAW,CAAA;AAAA,EACjB,CAAC,KAAK,cAAc,CAAA;AAAA,EACpB,CAAC,KAAK,WAAW,CAAA;AAAA,EACjB,CAAC,KAAK,oBAAoB,CAAA;AAAA,EAC1B,CAAC,KAAK,oBAAoB,CAAA;AAAA,EAC1B,CAAC,KAAK,aAAa,CAAA;AAAA,EACnB,CAAC,KAAK,cAAc,CAAA;AAAA,EACpB,CAAC,KAAK,kBAAkB,CAAA;AAAA,EACxB,CAAC,KAAK,WAAW,CAAA;AAAA,EACjB,CAAC,KAAK,WAAW,CAAA;AAAA,EACjB,CAAC,KAAK,oBAAoB,CAAA;AAAA,EAC1B,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,OAAS,EAAA;AAEd,QAAM,MAAA,GAAA,GAAM,aAAc,CAAA,OAAA,IAAW,aAAc,CAAA,GAAA;AAEnD,QAAI,GAAA,CAAA,mBAAA,EAAqB,IAAI,IAAI,CAAA;AAAA;AAClC;AACD,GACD;AACD,CAAC","file":"index.js","sourcesContent":["export const statusTextMap = new Map<number, string>([\n\t[100, \"Continue\"],\n\t[101, \"Switching Protocols\"],\n\t[102, \"Processing\"],\n\t[200, \"OK\"],\n\t[201, \"Created\"],\n\t[202, \"Accepted\"],\n\t[203, \"Non-Authoritative Information\"],\n\t[204, \"No Content\"],\n\t[205, \"Reset Content\"],\n\t[206, \"Partial Content\"],\n\t[207, \"Multi-Status\"],\n\t[208, \"Already Reported\"],\n\t[226, \"IM Used\"],\n\t[300, \"Multiple Choices\"],\n\t[301, \"Moved Permanently\"],\n\t[302, \"Found\"],\n\t[303, \"See Other\"],\n\t[304, \"Not Modified\"],\n\t[305, \"Use Proxy\"],\n\t[307, \"Temporary Redirect\"],\n\t[308, \"Permanent Redirect\"],\n\t[400, \"Bad Request\"],\n\t[401, \"Unauthorized\"],\n\t[402, \"Payment Required\"],\n\t[403, \"Forbidden\"],\n\t[404, \"Not Found\"],\n\t[405, \"Method Not Allowed\"],\n\t[406, \"Not Acceptable\"],\n\t[407, \"Proxy Authentication Required\"],\n\t[408, \"Request Timeout\"],\n\t[409, \"Conflict\"],\n\t[410, \"Gone\"],\n\t[411, \"Length Required\"],\n\t[412, \"Precondition Failed\"],\n\t[413, \"Payload Too Large\"],\n\t[414, \"URI Too Long\"],\n\t[415, \"Unsupported Media Type\"],\n\t[416, \"Range Not Satisfiable\"],\n\t[417, \"Expectation Failed\"],\n\t[418, \"I'm a teapot\"],\n\t[421, \"Misdirected Request\"],\n\t[422, \"Unprocessable Entity\"],\n\t[423, \"Locked\"],\n\t[424, \"Failed Dependency\"],\n\t[425, \"Too Early\"],\n\t[426, \"Upgrade Required\"],\n\t[428, \"Precondition Required\"],\n\t[429, \"Too Many Requests\"],\n\t[431, \"Request Header Fields Too Large\"],\n\t[451, \"Unavailable For Legal Reasons\"],\n\t[500, \"Internal Server Error\"],\n\t[501, \"Not Implemented\"],\n\t[502, \"Bad Gateway\"],\n\t[503, \"Service Unavailable\"],\n\t[504, \"Gateway Timeout\"],\n\t[505, \"HTTP Version Not Supported\"],\n\t[506, \"Variant Also Negotiates\"],\n\t[507, \"Insufficient Storage\"],\n\t[508, \"Loop Detected\"],\n\t[510, \"Not Extended\"],\n\t[511, \"Network Authentication Required\"],\n]);\n","import { statusTextMap } from \"./constants\";\n\nexport const getStatusText = (status: number) => statusTextMap.get(status) ?? \"Unknown\";\n","import { definePlugin } from \"@zayne-labs/callapi\";\nimport type { AnyFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createConsola } from \"consola\";\nimport { getStatusText } from \"./utils\";\n\ntype ConsoleLike = {\n\terror: AnyFunction<void>;\n\tfail?: AnyFunction<void>;\n\tlog: AnyFunction<void>;\n\tsuccess?: AnyFunction<void>;\n\twarn?: AnyFunction<void>;\n};\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tcolors: true,\n\t\tcolumns: 80,\n\t\tcompact: 10,\n\t\tdate: false,\n\t\tfancy: true,\n\t},\n});\n\nexport type LoggerOptions = {\n\t/**\n\t * Custom console object\n\t */\n\tconsoleObject?: ConsoleLike;\n\t/**\n\t * Enable or disable the logger\n\t * @default true\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Enable or disable verbose mode\n\t */\n\tverbose?: boolean;\n};\n\n/* eslint-disable ts-eslint/no-unsafe-argument -- Ignore for now */\nconst defaultConsole: ConsoleLike = {\n\terror: (...args) => consola.error(\"\", ...args),\n\tfail: (...args) => consola.fail(\"\", ...args),\n\tlog: (...args) => consola.info(\"\", ...args),\n\tsuccess: (...args) => consola.success(\"\", ...args),\n\twarn: (...args) => consola.warn(\"\", ...args),\n};\n/* eslint-enable ts-eslint/no-unsafe-argument -- Ignore for now */\n\nexport const loggerPlugin = definePlugin((options?: LoggerOptions) => {\n\tconst { consoleObject = defaultConsole, enabled = true, verbose } = options ?? {};\n\n\treturn {\n\t\t/* eslint-disable perfectionist/sort-objects -- Ignore for now */\n\t\tid: \"logger\",\n\t\tname: \"Logger\",\n\t\tversion: \"1.0.0\",\n\n\t\thooks: {\n\t\t\t/* eslint-enable perfectionist/sort-objects -- Ignore */\n\t\t\tonRequest: (ctx) => {\n\t\t\t\tif (!enabled) return;\n\n\t\t\t\tconsoleObject.log(`Request being sent to: ${ctx.options.fullURL}`);\n\t\t\t},\n\n\t\t\tonRequestError: (ctx) => {\n\t\t\t\tif (!enabled) return;\n\n\t\t\t\tconst log = consoleObject.fail ?? consoleObject.error;\n\n\t\t\t\tlog(`Request to failed with error: ${ctx.error.name}`);\n\n\t\t\t\tverbose && consoleObject.error(ctx.error.errorData);\n\t\t\t},\n\n\t\t\tonResponseError: (ctx) => {\n\t\t\t\tif (!enabled) return;\n\n\t\t\t\tconst log = consoleObject.fail ?? consoleObject.error;\n\n\t\t\t\tlog(\n\t\t\t\t\t\"Request failed with status: \",\n\t\t\t\t\tctx.response.status,\n\t\t\t\t\t`(${ctx.response.statusText || getStatusText(ctx.response.status)})`\n\t\t\t\t);\n\n\t\t\t\tverbose && consoleObject.error(ctx.error.errorData);\n\t\t\t},\n\n\t\t\tonRetry: (ctx) => {\n\t\t\t\tif (!enabled) return;\n\n\t\t\t\tconst log = consoleObject.warn ?? consoleObject.log;\n\n\t\t\t\tlog(`Retrying request... Attempt: `, ctx.retryAttemptCount);\n\t\t\t},\n\n\t\t\tonSuccess: (ctx) => {\n\t\t\t\tif (!enabled) return;\n\n\t\t\t\tconst log = consoleObject.success ?? consoleObject.log;\n\n\t\t\t\tlog(\"Request succeeded\", ctx.data);\n\t\t\t},\n\t\t},\n\t};\n});\n"]}
|
package/package.json
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
{
|
2
|
+
"name": "@zayne-labs/callapi-plugins",
|
3
|
+
"type": "module",
|
4
|
+
"version": "0.0.1",
|
5
|
+
"description": "A collection of plugins for callapi",
|
6
|
+
"author": "Ryan Zayne",
|
7
|
+
"license": "MIT",
|
8
|
+
"homepage": "https://github.com/zayne-labs/call-api#readme",
|
9
|
+
"sideEffects": false,
|
10
|
+
"exports": "./dist/esm/index.js",
|
11
|
+
"files": [
|
12
|
+
"dist"
|
13
|
+
],
|
14
|
+
"engines": {
|
15
|
+
"node": ">=v18.17.0"
|
16
|
+
},
|
17
|
+
"peerDependencies": {
|
18
|
+
"@zayne-labs/toolkit-type-helpers": "^0.9.33",
|
19
|
+
"consola": "^3.2.3",
|
20
|
+
"@zayne-labs/callapi": "1.7.14"
|
21
|
+
},
|
22
|
+
"devDependencies": {
|
23
|
+
"@arethetypeswrong/cli": "0.17.4",
|
24
|
+
"@size-limit/esbuild-why": "11.2.0",
|
25
|
+
"@size-limit/preset-small-lib": "11.2.0",
|
26
|
+
"@total-typescript/ts-reset": "0.6.1",
|
27
|
+
"@zayne-labs/toolkit-type-helpers": "^0.9.35",
|
28
|
+
"@zayne-labs/tsconfig": "0.8.2",
|
29
|
+
"concurrently": "^9.1.2",
|
30
|
+
"consola": "3.4.2",
|
31
|
+
"cross-env": "^7.0.3",
|
32
|
+
"publint": "^0.3.12",
|
33
|
+
"size-limit": "11.2.0",
|
34
|
+
"tsup": "8.4.0",
|
35
|
+
"typescript": "5.8.3",
|
36
|
+
"vitest": "^3.1.2",
|
37
|
+
"@zayne-labs/callapi": "1.7.14"
|
38
|
+
},
|
39
|
+
"publishConfig": {
|
40
|
+
"access": "public",
|
41
|
+
"registry": "https://registry.npmjs.org/",
|
42
|
+
"provenance": false
|
43
|
+
},
|
44
|
+
"size-limit": [
|
45
|
+
{
|
46
|
+
"path": "./src/index.ts",
|
47
|
+
"limit": "1.5 kb"
|
48
|
+
}
|
49
|
+
],
|
50
|
+
"scripts": {
|
51
|
+
"build": "tsup",
|
52
|
+
"build:dev": "cross-env NODE_ENV=development tsup",
|
53
|
+
"build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
|
54
|
+
"dev": "pnpm build:dev --watch",
|
55
|
+
"lint:attw": "attw --pack . --profile esm-only --format table-flipped --ignore-rules=cjs-resolves-to-esm --ignore-rules=named-exports",
|
56
|
+
"lint:eslint": "pnpm build && pnpm lint:eslint:dev",
|
57
|
+
"lint:eslint:dev": "eslint . --max-warnings 0",
|
58
|
+
"lint:eslint:interactive": "pnpx eslint-interactive@latest . --max-warnings 0 --fix",
|
59
|
+
"lint:format": "prettier --write .",
|
60
|
+
"lint:publint": "publint --strict .",
|
61
|
+
"lint:size": "size-limit",
|
62
|
+
"lint:type-check": "tsc --pretty -p tsconfig.json",
|
63
|
+
"release": "pnpm publish --no-git-checks",
|
64
|
+
"release:test": "pnpx pkg-pr-new publish"
|
65
|
+
}
|
66
|
+
}
|