@zayne-labs/callapi-plugins 3.0.0 → 3.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/dist/esm/index.js +4 -8
- package/dist/esm/index.js.map +1 -1
- package/package.json +6 -6
package/dist/esm/index.js
CHANGED
@@ -99,25 +99,21 @@ const loggerPlugin = definePlugin((options) => {
|
|
99
99
|
},
|
100
100
|
onRequestError: (ctx) => {
|
101
101
|
if (!enabled) return;
|
102
|
-
|
103
|
-
log(`Request to failed with error: ${ctx.error.name}`);
|
102
|
+
(consoleObject.fail ?? consoleObject.error)(`Request to failed with error: ${ctx.error.name}`);
|
104
103
|
verbose && consoleObject.error(ctx.error.errorData);
|
105
104
|
},
|
106
105
|
onResponseError: (ctx) => {
|
107
106
|
if (!enabled) return;
|
108
|
-
|
109
|
-
log("Request failed with status: ", ctx.response.status, `(${ctx.response.statusText || getStatusText(ctx.response.status)})`);
|
107
|
+
(consoleObject.fail ?? consoleObject.error)("Request failed with status: ", ctx.response.status, `(${ctx.response.statusText || getStatusText(ctx.response.status)})`);
|
110
108
|
verbose && consoleObject.error(ctx.error.errorData);
|
111
109
|
},
|
112
110
|
onRetry: (ctx) => {
|
113
111
|
if (!enabled) return;
|
114
|
-
|
115
|
-
log(`Retrying request... Attempt: `, ctx.retryAttemptCount);
|
112
|
+
(consoleObject.warn ?? consoleObject.log)(`Retrying request... Attempt: `, ctx.retryAttemptCount);
|
116
113
|
},
|
117
114
|
onSuccess: (ctx) => {
|
118
115
|
if (!enabled) return;
|
119
|
-
|
120
|
-
log("Request succeeded", ctx.data);
|
116
|
+
(consoleObject.success ?? consoleObject.log)("Request succeeded", ctx.data);
|
121
117
|
}
|
122
118
|
}
|
123
119
|
};
|
package/dist/esm/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["defaultConsoleObject: ConsoleLikeObject"],"sources":["../../src/logger/constants.ts","../../src/logger/utils.ts","../../src/logger/logger.ts"],"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 ConsoleLikeObject = {\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?: ConsoleLikeObject;\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 */\nexport const defaultConsoleObject: ConsoleLikeObject = {\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 = defaultConsoleObject, 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"],"mappings":";;;;AAAA,MAAa,gBAAgB,IAAI,IAAoB;CACpD,CAAC,KAAK;
|
1
|
+
{"version":3,"file":"index.js","names":["defaultConsoleObject: ConsoleLikeObject"],"sources":["../../src/logger/constants.ts","../../src/logger/utils.ts","../../src/logger/logger.ts"],"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 ConsoleLikeObject = {\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?: ConsoleLikeObject;\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 */\nexport const defaultConsoleObject: ConsoleLikeObject = {\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 = defaultConsoleObject, 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"],"mappings":";;;;AAAA,MAAa,gBAAgB,IAAI,IAAoB;CACpD,CAAC,KAAK,WAAW;CACjB,CAAC,KAAK,sBAAsB;CAC5B,CAAC,KAAK,aAAa;CACnB,CAAC,KAAK,KAAK;CACX,CAAC,KAAK,UAAU;CAChB,CAAC,KAAK,WAAW;CACjB,CAAC,KAAK,gCAAgC;CACtC,CAAC,KAAK,aAAa;CACnB,CAAC,KAAK,gBAAgB;CACtB,CAAC,KAAK,kBAAkB;CACxB,CAAC,KAAK,eAAe;CACrB,CAAC,KAAK,mBAAmB;CACzB,CAAC,KAAK,UAAU;CAChB,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AAY,QAAQ;AACnB,QAAI,CAAC,QAAS;AAId,KAFY,cAAc,WAAW,cAAc,KAE/C,qBAAqB,IAAI,KAAK;;GAEnC;EACD;EACA"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zayne-labs/callapi-plugins",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.0.
|
4
|
+
"version": "3.0.1",
|
5
5
|
"description": "A collection of plugins for callapi",
|
6
6
|
"author": "Ryan Zayne",
|
7
7
|
"license": "MIT",
|
@@ -21,24 +21,24 @@
|
|
21
21
|
"peerDependencies": {
|
22
22
|
"@zayne-labs/toolkit-type-helpers": ">=0.9.35",
|
23
23
|
"consola": "^3.4.2",
|
24
|
-
"@zayne-labs/callapi": "1.10.
|
24
|
+
"@zayne-labs/callapi": "1.10.1"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"@arethetypeswrong/cli": "0.18.2",
|
28
28
|
"@size-limit/esbuild-why": "11.2.0",
|
29
29
|
"@size-limit/preset-small-lib": "11.2.0",
|
30
30
|
"@total-typescript/ts-reset": "0.6.1",
|
31
|
-
"@zayne-labs/toolkit-type-helpers": "^0.
|
32
|
-
"@zayne-labs/tsconfig": "0.9.
|
31
|
+
"@zayne-labs/toolkit-type-helpers": "^0.11.7",
|
32
|
+
"@zayne-labs/tsconfig": "0.9.15",
|
33
33
|
"concurrently": "^9.2.1",
|
34
34
|
"consola": "3.4.2",
|
35
35
|
"cross-env": "^10.0.0",
|
36
36
|
"publint": "^0.3.12",
|
37
37
|
"size-limit": "11.2.0",
|
38
|
-
"tsdown": "^0.
|
38
|
+
"tsdown": "^0.15.2",
|
39
39
|
"typescript": "5.9.2",
|
40
40
|
"vitest": "^3.2.4",
|
41
|
-
"@zayne-labs/callapi": "1.10.
|
41
|
+
"@zayne-labs/callapi": "1.10.1"
|
42
42
|
},
|
43
43
|
"publishConfig": {
|
44
44
|
"access": "public",
|