{"_id":"@edgeone/ef-cls-sdk","_rev":"15-a0ec82b065ae736f217d04a0d37b83b0","name":"@edgeone/ef-cls-sdk","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@edgeone/ef-cls-sdk","version":"1.0.0","keywords":["tencent","edgeone","edgefunctions","cls"],"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","_id":"@edgeone/ef-cls-sdk@1.0.0","maintainers":[{"name":"tomtomyang","email":"stomtomyoung@gmail.com"}],"dist":{"shasum":"5768178c0f37122a9d818fe9cd87cd7cda297440","tarball":"https://registry.npmjs.org/@edgeone/ef-cls-sdk/-/ef-cls-sdk-1.0.0.tgz","fileCount":29,"integrity":"sha512-+ljBJ5lbJkcRJLs+AETqR81ichhLGtHj06s6S0e80S6FmBwUjoXEx4agLOStC4Y44rKnxtseURKo/jOy4NPdqQ==","signatures":[{"sig":"MEYCIQC/3wRkaXL2Eu7rlRj7KUPMgh/lqcSK9CHHQK4Ov3RuKQIhAJh3O/6MEoze/Dfgm1DnDi+7nCLUhOgbN/RMYjygZeiu","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":105496},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"49873ce803d5a8028e17da951bf00d14e5819e00","private":false,"scripts":{"lint":"eslint ./src --ext js,ts","build":"rimraf dist && tsc --outDir dist","lint:fix":"eslint ./src --ext js,ts --fix","build:cjs":"rimraf dist-cjs && tsc --outDir dist-cjs --module commonjs","prepublishOnly":"npm run lint:fix && npm run build"},"_npmUser":{"name":"tomtomyang","email":"stomtomyoung@gmail.com"},"_npmVersion":"8.16.0","description":"Edgefunction CLS SDK","directories":{},"_nodeVersion":"16.16.0","dependencies":{"protobufjs":"^6.11.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ef-cls-sdk_1.0.0_1701338235967_0.9032621678545605","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@edgeone/ef-cls-sdk","version":"1.0.1","keywords":["tencent","edgeone","edgefunctions","cls"],"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","_id":"@edgeone/ef-cls-sdk@1.0.1","maintainers":[{"name":"raxu","email":"raxu@tencent.com"},{"name":"tomtomyang","email":"tomtomyang@tencent.com"}],"dist":{"shasum":"ea52967e671bb63c3e2a8bdca35d83ad094dea60","tarball":"https://registry.npmjs.org/@edgeone/ef-cls-sdk/-/ef-cls-sdk-1.0.1.tgz","fileCount":31,"integrity":"sha512-0uHOmzptIR/S4dPbRDMjklH7PgrSCrpYeuaL9TmpLM7wV1SpZlW3d+rZxMwJWAz0cZqm4IlJBpJzXNN+l8jfhQ==","signatures":[{"sig":"MEUCIQC5AXSTrIkNd6cUgxfsNEd+9RSNAOSkzYlrSzxV5ofUmAIgK87lMowVICTIDNjLpSxCEEq5SWC2qJBktZmRkhicY6k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":106958},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"a7864f5237559ec8cec3535cc29d77af515b04c0","private":false,"scripts":{"lint":"eslint ./src --ext js,ts","build":"rimraf dist && tsc --outDir dist","lint:fix":"eslint ./src --ext js,ts --fix","build:cjs":"rimraf dist-cjs && tsc --outDir dist-cjs --module commonjs","prepublishOnly":"npm run lint:fix && npm run build"},"_npmUser":{"name":"tomtomyang","email":"tomtomyang@tencent.com"},"_npmVersion":"8.16.0","description":"Edgefunctions CLS SDK","directories":{},"_nodeVersion":"16.16.0","dependencies":{"protobufjs":"^6.11.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ef-cls-sdk_1.0.1_1703559510689_0.38129161939634293","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@edgeone/ef-cls-sdk","version":"1.0.2","keywords":["tencent","edgeone","edgefunctions","cls"],"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","_id":"@edgeone/ef-cls-sdk@1.0.2","maintainers":[{"name":"raxu","email":"raxu@tencent.com"},{"name":"tomtomyang","email":"tomtomyang@tencent.com"}],"dist":{"shasum":"6b27e332152dffcef7667407c8af7af6a81f0e52","tarball":"https://registry.npmjs.org/@edgeone/ef-cls-sdk/-/ef-cls-sdk-1.0.2.tgz","fileCount":31,"integrity":"sha512-EsMb4N2UnEwBOGrEZBmU619YIBuQgqp54GmNgqrx7GEakYHmBbpUq4G89ifO0KlrNg+scQQ5UnlZz1uaQSlDRA==","signatures":[{"sig":"MEYCIQCrNYr3ULLwEPkMfKCSG3JQsphvfQ+voNDWuMkxcF5KbAIhAIpZzmgSKcwEgx65Dt0wUJ2ecr/Jk0TfB8b7n1jIFBVL","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":106958},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"a7864f5237559ec8cec3535cc29d77af515b04c0","private":false,"scripts":{"lint":"eslint ./src --ext js,ts","build":"rimraf dist && tsc --outDir dist","lint:fix":"eslint ./src --ext js,ts --fix","build:cjs":"rimraf dist-cjs && tsc --outDir dist-cjs --module commonjs","prepublishOnly":"npm run lint:fix && npm run build"},"_npmUser":{"name":"tomtomyang","email":"tomtomyang@tencent.com"},"_npmVersion":"8.16.0","description":"Edgefunctions CLS SDK","directories":{},"_nodeVersion":"16.16.0","dependencies":{"protobufjs":"^6.11.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ef-cls-sdk_1.0.2_1703559972281_0.1941297846868446","host":"s3://npm-registry-packages"}},"1.0.3":{"name":"@edgeone/ef-cls-sdk","version":"1.0.3","keywords":["tencent","edgeone","edgefunctions","cls"],"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","_id":"@edgeone/ef-cls-sdk@1.0.3","maintainers":[{"name":"raxu","email":"raxu@tencent.com"},{"name":"tomtomyang","email":"tomtomyang@tencent.com"}],"dist":{"shasum":"98611baf689fb1543071c075c74766c7fec7dbf0","tarball":"https://registry.npmjs.org/@edgeone/ef-cls-sdk/-/ef-cls-sdk-1.0.3.tgz","fileCount":29,"integrity":"sha512-4hA6wdRKAUGImHLFUdlpbyWQF+fqMpglGktQGLlQpBqq5OvYxJFJ4opL73zL4JvE8vtrBTh3iTPUcHCl98JCJQ==","signatures":[{"sig":"MEQCIG6SJEQKhFMYYFMDrRXjqvQ4hvIzB35tFmX7cULqtcCBAiB5xqYforM8VRu20mn/GIXy/gcFjmal+eFn+8XWPvDXOw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":105559},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"6211fc8963ea6f6ca6540ed93762a4fb478e97f5","private":false,"scripts":{"lint":"eslint ./src --ext js,ts","build":"rimraf dist && tsc --rootDir src --outDir dist","lint:fix":"eslint ./src --ext js,ts --fix","build:cjs":"rimraf dist-cjs && tsc --rootDir src --outDir dist-cjs --module commonjs","prepublishOnly":"npm run lint:fix && npm run build"},"_npmUser":{"name":"tomtomyang","email":"tomtomyang@tencent.com"},"_npmVersion":"8.16.0","description":"Edgefunctions CLS SDK","directories":{},"_nodeVersion":"16.16.0","dependencies":{"protobufjs":"^6.11.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ef-cls-sdk_1.0.3_1703574146517_0.5863740319977775","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"@edgeone/ef-cls-sdk","version":"1.0.4","keywords":["tencent","edgeone","edgefunctions","cls"],"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","_id":"@edgeone/ef-cls-sdk@1.0.4","maintainers":[{"name":"tomtomyang","email":"stomtomyoung@gmail.com"}],"dist":{"shasum":"f029fc46c42af9e95b7ec5be482540cc3b3ce1c5","tarball":"https://registry.npmjs.org/@edgeone/ef-cls-sdk/-/ef-cls-sdk-1.0.4.tgz","fileCount":29,"integrity":"sha512-cBCfSNa15GN8eKF1bVasxdRf6DPe3LEMbmTkgDScEXUEskj6AhGrWzVOMywcHav2E1yHPbKNOtyexlefG0ymSQ==","signatures":[{"sig":"MEUCIQDWu6VFw3iteTHdEttAbI9WtLFjemyXwstQvs4XAeG3oQIgQiWygT2rN2m3Mdy6rz2IjTlsNl6EhUoqaGIaLjlw4pI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":105835},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"3a909a6881796fe6ef7111bd3efa895633228365","private":false,"scripts":{"lint":"eslint ./src --ext js,ts","build":"rimraf dist && tsc --rootDir src --outDir dist","lint:fix":"eslint ./src --ext js,ts --fix","build:cjs":"rimraf dist-cjs && tsc --rootDir src --outDir dist-cjs --module commonjs","prepublishOnly":"npm run lint:fix && npm run build"},"_npmUser":{"name":"tomtomyang","email":"stomtomyoung@gmail.com"},"_npmVersion":"8.16.0","description":"Edgefunctions CLS SDK","directories":{},"_nodeVersion":"16.16.0","dependencies":{"protobufjs":"^6.11.2"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/ef-cls-sdk_1.0.4_1724904314980_0.3873941042209541","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-11-30T09:57:15.830Z","modified":"2026-08-25T12:42:37.500Z","1.0.0":"2023-11-30T09:57:16.177Z","1.0.1":"2023-12-26T02:58:30.859Z","1.0.2":"2023-12-26T03:06:12.486Z","1.0.3":"2023-12-26T07:02:26.680Z","1.0.4":"2024-08-29T04:05:15.240Z"},"author":{"name":"tomtomyang@tencent.com"},"license":"Apache","keywords":["tencent","edgeone","edgefunctions","cls"],"description":"Edgefunctions CLS SDK","maintainers":[{"email":"yorkyu@tencent.com","name":"tyorkyu"},{"email":"chuckcchen@gmail.com","name":"chuckcchen"},{"email":"xindeli@tencent.com","name":"xindeli"},{"email":"drogbaqb@gmail.com","name":"drogbaqu"},{"email":"simxin@tencent.com","name":"simxin"}],"readme":"# @edgeone/ef-cls-sdk\n\n基于 [tencentcloud-cls-sdk-js](https://github.com/TencentCloud/tencentcloud-cls-sdk-js.git) 进行开发，适配 EdgeFunctions Runtime API，用于在 EdgeOne 边缘函数中进行 [CLS](https://cloud.tencent.com/document/product/614) 日志上报。\n\n## 安装\n\n```bash\nnpm i @edgeone/ef-cls-sdk\n```\n\n## 使用\n\n```ts\nimport { AsyncClient, Content, LogGroup, LogItem, PutLogsRequest } from '@edgeone/ef-cls-sdk';\n\n/** CONFIG START */\n\nconst TENCENT_SECRET_ID = 'xxxxx';\nconst TENCENT_SECRET_KEY = 'xxxxx';\n\nconst CLS_END_POINT = 'ap-xxxxx.cls.tencentcs.com';\nconst CLS_TOPIC_ID = 'xxxxx';\n\n/** CONFIG END */\n\nconst clsAsyncClient = new AsyncClient({\n  endpoint: CLS_END_POINT,\n  secretId: TENCENT_SECRET_ID,\n  secretKey: TENCENT_SECRET_KEY,\n  sourceIp: 'edge',\n  retry_times: 1,\n});\n\nasync function clsUpload(data: string) {\n  const logGroup = new LogGroup();\n  const logItem = new LogItem();\n  const logTime = Math.floor(Date.now() / 1000);\n  const logContent = new Content('__CONTENT__', JSON.stringify(data));\n\n  logItem.setTime(logTime);\n  logItem.pushBack(logContent);\n  logGroup.addLogs(logItem);\n\n  const clsRequest = new PutLogsRequest(CLS_TOPIC_ID, logGroup);\n  return await clsAsyncClient.PutLogs(clsRequest);\n}\n\nasync function doClsUpload(request: Request) {\n  try {\n    const data = await request.clone().text();\n    await clsUpload(data);\n  } catch (err) {\n    console.error(`cls upload error: ${err}`);\n  }\n}\n\nasync function handleRequest(event: FetchEvent) {\n  const { request } = event;\n  const contentType = request.headers.get('content-type') || '';\n\n  if (contentType.includes('application/json') || contentType.includes('text/plain')) {\n    // 用于通知边缘函数等待 Promise 完成，可延长事件处理的生命周期，不阻塞 fetch(request) 的返回。\n    event.waitUntil(doClsUpload(request));\n  }\n\n  return;\n}\n\naddEventListener('fetch', handleRequest);\n```\n\n## 文档\n\n- [tencentcloud-cls-sdk-js](https://github.com/TencentCloud/tencentcloud-cls-sdk-js)\n- [腾讯云 EdgeOne](https://edgeone.ai/)\n- [腾讯云 EdgeOne 边缘函数](https://cloud.tencent.com/document/product/1552/81344)\n- [腾讯云 CLS 日志服务](https://cloud.tencent.com/document/product/614)\n","readmeFilename":"README.md"}