@fetchx/fetcher-interceptor-sls-core 0.1.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.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/intercept-sls-core.js +48 -0
- package/dist/cjs/types/index.js +5 -0
- package/dist/cjs/util/get-duration.js +9 -0
- package/dist/cjs/util/index.js +13 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/intercept-sls-core.js +42 -0
- package/dist/esm/intercept-sls-core.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/util/get-duration.js +4 -0
- package/dist/esm/util/get-duration.js.map +1 -0
- package/dist/esm/util/index.js +2 -0
- package/dist/esm/util/index.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/intercept-sls-core.d.ts +4 -0
- package/dist/types/types/index.d.ts +5 -0
- package/dist/types/util/get-duration.d.ts +2 -0
- package/dist/types/util/index.d.ts +1 -0
- package/package.json +51 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Alibaba Cloud
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @fetchx/fetcher-interceptor-sls-core
|
|
2
|
+
|
|
3
|
+
SLS logger interceptor for `@fetchx/fetcher`, which can log success and error, plus duration.
|
|
4
|
+
|
|
5
|
+
Platform independent. For web use `@fetchx/fetcher-interceptor-sls`。
|
|
6
|
+
|
|
7
|
+
## How to Use
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import interceptSlsCore from '@fetchx/fetcher-interceptor-sls-core';
|
|
11
|
+
|
|
12
|
+
interceptSlsCore(fetcher, transport, { // suppose you have the fetcher by createFetcher
|
|
13
|
+
project: 'my-sls-project',
|
|
14
|
+
endpoint: '<region>.log.aliyuncs.com',
|
|
15
|
+
logstore: 'my-logstore',
|
|
16
|
+
defaultParams: getDefaultParams
|
|
17
|
+
});
|
|
18
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _interceptSlsCore.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _interceptSlsCore = _interopRequireDefault(require("./intercept-sls-core"));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = interceptSlsCore;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _slsLoggerBase = _interopRequireDefault(require("@fetchx/sls-logger-base"));
|
|
10
|
+
var _util = require("./util");
|
|
11
|
+
var _excluded = ["topicSuccess", "topicError"];
|
|
12
|
+
var FLATTEN_DIRECT = ['request.headers', 'request.body', 'response.headers', 'response.data'];
|
|
13
|
+
function interceptSlsCore(fetcher, transport, options) {
|
|
14
|
+
var priority = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 50;
|
|
15
|
+
var _options$topicSuccess = options.topicSuccess,
|
|
16
|
+
topicSuccess = _options$topicSuccess === void 0 ? 'fetcher_success' : _options$topicSuccess,
|
|
17
|
+
_options$topicError = options.topicError,
|
|
18
|
+
topicError = _options$topicError === void 0 ? 'fetcher_error' : _options$topicError,
|
|
19
|
+
createLoggerOptions = (0, _objectWithoutProperties2.default)(options, _excluded);
|
|
20
|
+
var sls = (0, _slsLoggerBase.default)(transport, createLoggerOptions);
|
|
21
|
+
function onFulfilled(data, config, response) {
|
|
22
|
+
sls({
|
|
23
|
+
flatten: {
|
|
24
|
+
direct: FLATTEN_DIRECT
|
|
25
|
+
}
|
|
26
|
+
}, topicSuccess, {
|
|
27
|
+
request: config,
|
|
28
|
+
response: response,
|
|
29
|
+
duration: (0, _util.getDuration)(config)
|
|
30
|
+
});
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
function onRejected(error, config, response) {
|
|
34
|
+
sls.error({
|
|
35
|
+
flatten: {
|
|
36
|
+
omit: 'error.config',
|
|
37
|
+
direct: FLATTEN_DIRECT
|
|
38
|
+
}
|
|
39
|
+
}, topicError, {
|
|
40
|
+
error: error,
|
|
41
|
+
request: config,
|
|
42
|
+
response: response,
|
|
43
|
+
duration: (0, _util.getDuration)(config)
|
|
44
|
+
});
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
return fetcher.interceptResponse(onFulfilled, onRejected, priority);
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "getDuration", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _getDuration.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _getDuration = _interopRequireDefault(require("./get-duration"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../src/index.ts"],"sourcesContent":["export { default } from './intercept-sls-core';\n\nexport type {\n IFetcherInterceptorSlsOptions as FetcherInterceptorSlsOptions\n} from './types';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,sBAAsB","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
var _excluded = ["topicSuccess", "topicError"];
|
|
3
|
+
import createLogger from '@fetchx/sls-logger-base';
|
|
4
|
+
import { getDuration } from './util';
|
|
5
|
+
var FLATTEN_DIRECT = ['request.headers', 'request.body', 'response.headers', 'response.data'];
|
|
6
|
+
export default function interceptSlsCore(fetcher, transport, options) {
|
|
7
|
+
var priority = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 50;
|
|
8
|
+
var _options$topicSuccess = options.topicSuccess,
|
|
9
|
+
topicSuccess = _options$topicSuccess === void 0 ? 'fetcher_success' : _options$topicSuccess,
|
|
10
|
+
_options$topicError = options.topicError,
|
|
11
|
+
topicError = _options$topicError === void 0 ? 'fetcher_error' : _options$topicError,
|
|
12
|
+
createLoggerOptions = _objectWithoutProperties(options, _excluded);
|
|
13
|
+
var sls = createLogger(transport, createLoggerOptions);
|
|
14
|
+
function onFulfilled(data, config, response) {
|
|
15
|
+
sls({
|
|
16
|
+
flatten: {
|
|
17
|
+
direct: FLATTEN_DIRECT
|
|
18
|
+
}
|
|
19
|
+
}, topicSuccess, {
|
|
20
|
+
request: config,
|
|
21
|
+
response: response,
|
|
22
|
+
duration: getDuration(config)
|
|
23
|
+
});
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
function onRejected(error, config, response) {
|
|
27
|
+
sls.error({
|
|
28
|
+
flatten: {
|
|
29
|
+
omit: 'error.config',
|
|
30
|
+
direct: FLATTEN_DIRECT
|
|
31
|
+
}
|
|
32
|
+
}, topicError, {
|
|
33
|
+
error: error,
|
|
34
|
+
request: config,
|
|
35
|
+
response: response,
|
|
36
|
+
duration: getDuration(config)
|
|
37
|
+
});
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
return fetcher.interceptResponse(onFulfilled, onRejected, priority);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=intercept-sls-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercept-sls-core.js","names":["createLogger","getDuration","FLATTEN_DIRECT","interceptSlsCore","fetcher","transport","options","priority","arguments","length","undefined","_options$topicSuccess","topicSuccess","_options$topicError","topicError","createLoggerOptions","_objectWithoutProperties","_excluded","sls","onFulfilled","data","config","response","flatten","direct","request","duration","onRejected","error","omit","interceptResponse"],"sources":["../../src/intercept-sls-core.ts"],"sourcesContent":["import {\n Fetcher,\n FetcherError,\n FetcherConfig,\n FetcherResponse\n} from '@fetchx/fetcher-core';\nimport createLogger, {\n SlsLoggerTransport\n} from '@fetchx/sls-logger-base';\n\nimport {\n IFetcherInterceptorSlsOptions\n} from './types';\nimport {\n getDuration\n} from './util';\n\nconst FLATTEN_DIRECT = ['request.headers', 'request.body', 'response.headers', 'response.data'];\n\nexport default function interceptSlsCore(fetcher: Fetcher, transport: SlsLoggerTransport, options: IFetcherInterceptorSlsOptions, priority = 50): () => void {\n const {\n topicSuccess = 'fetcher_success',\n topicError = 'fetcher_error',\n ...createLoggerOptions\n } = options;\n const sls = createLogger(transport, createLoggerOptions);\n \n function onFulfilled(data: unknown, config: FetcherConfig, response: FetcherResponse<unknown> | undefined): unknown {\n sls({\n flatten: {\n direct: FLATTEN_DIRECT\n }\n }, topicSuccess, {\n request: config,\n response,\n duration: getDuration(config)\n });\n \n return data;\n }\n \n function onRejected(error: FetcherError, config: FetcherConfig, response?: FetcherResponse<unknown>): never {\n sls.error({\n flatten: {\n omit: 'error.config',\n direct: FLATTEN_DIRECT\n }\n }, topicError, {\n error,\n request: config,\n response,\n duration: getDuration(config)\n });\n \n throw error;\n }\n \n return fetcher.interceptResponse(onFulfilled, onRejected, priority);\n}\n"],"mappings":";;AAMA,OAAOA,YAAY,MAEZ,yBAAyB;AAKhC,SACEC,WAAW,QACN,QAAQ;AAEf,IAAMC,cAAc,GAAG,CAAC,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,CAAC;AAE/F,eAAe,SAASC,gBAAgBA,CAACC,OAAgB,EAAEC,SAA6B,EAAEC,OAAsC,EAA6B;EAAA,IAA3BC,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC7I,IAAAG,qBAAA,GAIIL,OAAO,CAHTM,YAAY;IAAZA,YAAY,GAAAD,qBAAA,cAAG,iBAAiB,GAAAA,qBAAA;IAAAE,mBAAA,GAG9BP,OAAO,CAFTQ,UAAU;IAAVA,UAAU,GAAAD,mBAAA,cAAG,eAAe,GAAAA,mBAAA;IACzBE,mBAAmB,GAAAC,wBAAA,CACpBV,OAAO,EAAAW,SAAA;EACX,IAAMC,GAAG,GAAGlB,YAAY,CAACK,SAAS,EAAEU,mBAAmB,CAAC;EAExD,SAASI,WAAWA,CAACC,IAAa,EAAEC,MAAqB,EAAEC,QAA8C,EAAW;IAClHJ,GAAG,CAAC;MACFK,OAAO,EAAE;QACPC,MAAM,EAAEtB;MACV;IACF,CAAC,EAAEU,YAAY,EAAE;MACfa,OAAO,EAAEJ,MAAM;MACfC,QAAQ,EAARA,QAAQ;MACRI,QAAQ,EAAEzB,WAAW,CAACoB,MAAM;IAC9B,CAAC,CAAC;IAEF,OAAOD,IAAI;EACb;EAEA,SAASO,UAAUA,CAACC,KAAmB,EAAEP,MAAqB,EAAEC,QAAmC,EAAS;IAC1GJ,GAAG,CAACU,KAAK,CAAC;MACRL,OAAO,EAAE;QACPM,IAAI,EAAE,cAAc;QACpBL,MAAM,EAAEtB;MACV;IACF,CAAC,EAAEY,UAAU,EAAE;MACbc,KAAK,EAALA,KAAK;MACLH,OAAO,EAAEJ,MAAM;MACfC,QAAQ,EAARA,QAAQ;MACRI,QAAQ,EAAEzB,WAAW,CAACoB,MAAM;IAC9B,CAAC,CAAC;IAEF,MAAMO,KAAK;EACb;EAEA,OAAOxB,OAAO,CAAC0B,iBAAiB,CAACX,WAAW,EAAEQ,UAAU,EAAEpB,QAAQ,CAAC;AACrE","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/types/index.ts"],"sourcesContent":["import {\n CreateLoggerOptions\n} from '@fetchx/sls-logger-base';\n\nexport interface IFetcherInterceptorSlsOptions extends CreateLoggerOptions {\n topicSuccess?: string;\n topicError?: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-duration.js","names":["getDuration","config","_timeStarted","Date","now"],"sources":["../../../src/util/get-duration.ts"],"sourcesContent":["import {\n FetcherConfig\n} from '@fetchx/fetcher-core';\n\nexport default function getDuration(config: FetcherConfig): number {\n return config._timeStarted ? Date.now() - config._timeStarted : -1;\n}\n"],"mappings":"AAIA,eAAe,SAASA,WAAWA,CAACC,MAAqB,EAAU;EACjE,OAAOA,MAAM,CAACC,YAAY,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGH,MAAM,CAACC,YAAY,GAAG,CAAC,CAAC;AACpE","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","getDuration"],"sources":["../../../src/util/index.ts"],"sourcesContent":["export { default as getDuration } from './get-duration';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Fetcher } from '@fetchx/fetcher-core';
|
|
2
|
+
import { SlsLoggerTransport } from '@fetchx/sls-logger-base';
|
|
3
|
+
import { IFetcherInterceptorSlsOptions } from './types';
|
|
4
|
+
export default function interceptSlsCore(fetcher: Fetcher, transport: SlsLoggerTransport, options: IFetcherInterceptorSlsOptions, priority?: number): () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as getDuration } from './get-duration';
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fetchx/fetcher-interceptor-sls-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fetcher interceptor to do sls log when request success or fail.",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "dist/cjs/index.js",
|
|
9
|
+
"module": "dist/esm/index.js",
|
|
10
|
+
"types": "dist/types/index.d.ts",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/justnewbee/fetcher.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/justnewbee/fetcher/tree/main/packages-fetcher/fetcher-interceptor-sls-core",
|
|
16
|
+
"bugs": "https://github.com/justnewbee/fetcher/issues",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Jianchun Wang",
|
|
19
|
+
"email": "justnewbee@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.29.7",
|
|
26
|
+
"@babel/core": "^7.29.7",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.29.7",
|
|
28
|
+
"@babel/preset-env": "^7.29.7",
|
|
29
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
30
|
+
"@kcuf/ts-config": "^0.2.0",
|
|
31
|
+
"rimraf": "^6.1.3",
|
|
32
|
+
"typescript": "^6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@babel/runtime": ">=7.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@fetchx/fetcher-core": "^0.1.0",
|
|
39
|
+
"@fetchx/sls-logger-base": "^0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build:clean": "rimraf dist",
|
|
43
|
+
"build:esm": "ESM=1 babel src -d dist/esm --extensions .ts,.tsx --source-maps",
|
|
44
|
+
"build:cjs": "ESM=0 babel src -d dist/cjs --extensions .ts,.tsx",
|
|
45
|
+
"build:types": "tsc -rootDir src --outDir dist/types --declaration --noEmit false --emitDeclarationOnly --isolatedModules false",
|
|
46
|
+
"build": "pnpm build:esm && pnpm build:cjs && pnpm build:types",
|
|
47
|
+
"watch": "pnpm build:esm -w",
|
|
48
|
+
"prepublishOnly": "pnpm build:clean && pnpm build"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "bf2c0669d37eb75df199b4762e5295eef57600aa"
|
|
51
|
+
}
|