@longzai-intelligence-telemetry/core 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/README.md +13 -0
- package/dist/index.d.mts +708 -0
- package/dist/index.d.ts +709 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("zod");c=s(c);const l=/^[a-z][a-z0-9_]{1,63}$/,u=4e3,d=8e3,f={trackingEventsBatch:`/telemetry/tracking-events/batch`,clientLogsBatch:`/telemetry/client-logs/batch`},p=c.enum([`debug`,`info`,`warn`,`error`,`fatal`]),m=c.enum([`ios`,`android`,`harmony`]),h=c.string().regex(l),g=c.union([c.string(),c.number(),c.boolean(),c.null()]),_=c.object({platform:m,appVersion:c.string().min(1).max(64),sessionId:c.string().min(1).max(64),deviceId:c.string().min(1).max(64),buildChannel:c.string().min(1).max(32),userId:c.string().min(1).max(64).nullable(),batchedAt:c.number().int().nonnegative()}),v=c.object({name:h,properties:c.record(c.string(),g),occurredAt:c.number().int().nonnegative()}),y=c.object({level:p,message:c.string().min(1).max(u),stack:c.string().max(d),tag:c.string().min(1).max(64),occurredAt:c.number().int().nonnegative()}),b=c.object({context:_,events:c.array(v).min(1).max(100)}),x=c.object({context:_,logs:c.array(y).min(1).max(100)}),S={crashChannelEnabled:!0,behavioralEventsEnabled:!1};function C(e,t){return t.kind===`crash-channel`?{...e,crashChannelEnabled:t.enabled}:{...e,behavioralEventsEnabled:t.enabled}}function w(e,t){return t===`crash-reporting`?e.crashChannelEnabled:e.behavioralEventsEnabled}const T={mode:`lossless`,persistentOutbox:!0,eventBufferLimit:1e4,logBufferLimit:5e4,maxBatchesPerRun:30,failureCooldownMs:5e3,flushIntervalMs:1e4,remoteLogLevelThreshold:`info`,infoCommitDelayMs:1e3},E={mode:`balanced`,persistentOutbox:!1,eventBufferLimit:200,logBufferLimit:1e3,maxBatchesPerRun:3,failureCooldownMs:3e4,flushIntervalMs:1e4,remoteLogLevelThreshold:`info`,infoCommitDelayMs:0},D={mode:`lite`,persistentOutbox:!1,eventBufferLimit:100,logBufferLimit:300,maxBatchesPerRun:3,failureCooldownMs:6e4,flushIntervalMs:3e4,remoteLogLevelThreshold:`warn`,infoCommitDelayMs:0};function O(e){switch(e){case`balanced`:return E;case`lite`:return D;case`lossless`:return T}}function k(e){return e===`balanced`||e===`lite`||e===`lossless`?e:`lossless`}const A=`…[truncated]`,j=`invalid_event_name`;function M(e,t){return e.length<=t?e:`${e.slice(0,t-12)}${A}`}function N(e){return M(e,u)}function P(e){return e===``?``:M(e,d)}function F(e){return l.test(e)?e:j}function I(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)&&(r[t]=i);return r}const L={cooldownUntilMs:0};function R(e,t){return t>=e.cooldownUntilMs}function z(e,t,n){return{cooldownUntilMs:Math.max(e.cooldownUntilMs,t+n)}}function B(){return{cooldownUntilMs:0}}function V(e){return Math.max(1,Math.min(e,100))}function H(e,t,n){let r=V(n),i=t.slice(0,r);return{batch:{context:{...e},events:i.map(e=>({name:F(e.entry.name),properties:{...e.entry.properties},occurredAt:e.entry.occurredAt}))},recordIds:i.map(e=>e.id)}}function U(e,t,n){let r=V(n),i=t.slice(0,r);return{batch:{context:{...e},logs:i.map(e=>({level:e.entry.level===`fatal`?`error`:e.entry.level,message:N(e.entry.message),stack:P(e.entry.stack),tag:e.entry.tag,occurredAt:e.entry.occurredAt}))},recordIds:i.map(e=>e.id)}}function W(e){return e>=200&&e<300?{outcome:`success`}:e===408?{outcome:`retryable`,cause:`timeout`}:e===429?{outcome:`retryable`,cause:`rate-limited`}:e>=500?{outcome:`retryable`,cause:`server-error`}:{outcome:`rejected`,cause:`client-rejected`}}function G(){return{outcome:`retryable`,cause:`network-error`}}exports.BALANCED_DELIVERY_PROFILE=E,exports.DEFAULT_DELIVERY_MODE=`lossless`,exports.DEFAULT_TELEMETRY_CONSENT=S,exports.INITIAL_COOLDOWN_STATE=L,exports.INVALID_EVENT_NAME_SENTINEL=j,exports.LITE_DELIVERY_PROFILE=D,exports.LOSSLESS_DELIVERY_PROFILE=T,exports.TELEMETRY_BATCH_MAX_ENTRIES=100,exports.TELEMETRY_CLOCK_ANOMALY_THRESHOLD_MS=6e5,exports.TELEMETRY_ENDPOINTS=f,exports.TELEMETRY_EVENT_NAME_PATTERN=l,exports.TELEMETRY_MESSAGE_MAX_LENGTH=u,exports.TELEMETRY_STACK_MAX_LENGTH=d,exports.TELEMETRY_TRUNCATION_TAIL=A,exports.applyConsentChange=C,exports.assembleEventBatch=H,exports.assembleLogBatch=U,exports.batchContextSchema=_,exports.classifyHttpStatus=W,exports.classifyTransportFailure=G,exports.eventBatchSchema=b,exports.eventEntrySchema=v,exports.getDeliveryProfile=O,exports.isChannelUploadAllowed=w,exports.logBatchSchema=x,exports.logEntrySchema=y,exports.normalizeDeliveryMode=k,exports.registerSendFailure=z,exports.registerSendSuccess=B,exports.sanitizeEventName=F,exports.sanitizeMessage=N,exports.sanitizeProperties=I,exports.sanitizeStack=P,exports.shouldAttemptSend=R;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"zod";const t=/^[a-z][a-z0-9_]{1,63}$/,n=4e3,r=8e3,i=100,a=6e5,o={trackingEventsBatch:`/telemetry/tracking-events/batch`,clientLogsBatch:`/telemetry/client-logs/batch`},s=e.enum([`debug`,`info`,`warn`,`error`,`fatal`]),c=e.enum([`ios`,`android`,`harmony`]),l=e.string().regex(t),u=e.union([e.string(),e.number(),e.boolean(),e.null()]),d=e.object({platform:c,appVersion:e.string().min(1).max(64),sessionId:e.string().min(1).max(64),deviceId:e.string().min(1).max(64),buildChannel:e.string().min(1).max(32),userId:e.string().min(1).max(64).nullable(),batchedAt:e.number().int().nonnegative()}),f=e.object({name:l,properties:e.record(e.string(),u),occurredAt:e.number().int().nonnegative()}),p=e.object({level:s,message:e.string().min(1).max(n),stack:e.string().max(r),tag:e.string().min(1).max(64),occurredAt:e.number().int().nonnegative()}),m=e.object({context:d,events:e.array(f).min(1).max(100)}),h=e.object({context:d,logs:e.array(p).min(1).max(100)}),g={crashChannelEnabled:!0,behavioralEventsEnabled:!1};function _(e,t){return t.kind===`crash-channel`?{...e,crashChannelEnabled:t.enabled}:{...e,behavioralEventsEnabled:t.enabled}}function v(e,t){return t===`crash-reporting`?e.crashChannelEnabled:e.behavioralEventsEnabled}const y={mode:`lossless`,persistentOutbox:!0,eventBufferLimit:1e4,logBufferLimit:5e4,maxBatchesPerRun:30,failureCooldownMs:5e3,flushIntervalMs:1e4,remoteLogLevelThreshold:`info`,infoCommitDelayMs:1e3},b={mode:`balanced`,persistentOutbox:!1,eventBufferLimit:200,logBufferLimit:1e3,maxBatchesPerRun:3,failureCooldownMs:3e4,flushIntervalMs:1e4,remoteLogLevelThreshold:`info`,infoCommitDelayMs:0},x={mode:`lite`,persistentOutbox:!1,eventBufferLimit:100,logBufferLimit:300,maxBatchesPerRun:3,failureCooldownMs:6e4,flushIntervalMs:3e4,remoteLogLevelThreshold:`warn`,infoCommitDelayMs:0},S=`lossless`;function C(e){switch(e){case`balanced`:return b;case`lite`:return x;case`lossless`:return y}}function w(e){return e===`balanced`||e===`lite`||e===`lossless`?e:`lossless`}const T=`…[truncated]`,E=`invalid_event_name`;function D(e,t){return e.length<=t?e:`${e.slice(0,t-12)}${T}`}function O(e){return D(e,n)}function k(e){return e===``?``:D(e,r)}function A(e){return t.test(e)?e:E}function j(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))n.has(t)&&(r[t]=i);return r}const M={cooldownUntilMs:0};function N(e,t){return t>=e.cooldownUntilMs}function P(e,t,n){return{cooldownUntilMs:Math.max(e.cooldownUntilMs,t+n)}}function F(){return{cooldownUntilMs:0}}function I(e){return Math.max(1,Math.min(e,100))}function L(e,t,n){let r=I(n),i=t.slice(0,r);return{batch:{context:{...e},events:i.map(e=>({name:A(e.entry.name),properties:{...e.entry.properties},occurredAt:e.entry.occurredAt}))},recordIds:i.map(e=>e.id)}}function R(e,t,n){let r=I(n),i=t.slice(0,r);return{batch:{context:{...e},logs:i.map(e=>({level:e.entry.level===`fatal`?`error`:e.entry.level,message:O(e.entry.message),stack:k(e.entry.stack),tag:e.entry.tag,occurredAt:e.entry.occurredAt}))},recordIds:i.map(e=>e.id)}}function z(e){return e>=200&&e<300?{outcome:`success`}:e===408?{outcome:`retryable`,cause:`timeout`}:e===429?{outcome:`retryable`,cause:`rate-limited`}:e>=500?{outcome:`retryable`,cause:`server-error`}:{outcome:`rejected`,cause:`client-rejected`}}function B(){return{outcome:`retryable`,cause:`network-error`}}export{b as BALANCED_DELIVERY_PROFILE,S as DEFAULT_DELIVERY_MODE,g as DEFAULT_TELEMETRY_CONSENT,M as INITIAL_COOLDOWN_STATE,E as INVALID_EVENT_NAME_SENTINEL,x as LITE_DELIVERY_PROFILE,y as LOSSLESS_DELIVERY_PROFILE,i as TELEMETRY_BATCH_MAX_ENTRIES,a as TELEMETRY_CLOCK_ANOMALY_THRESHOLD_MS,o as TELEMETRY_ENDPOINTS,t as TELEMETRY_EVENT_NAME_PATTERN,n as TELEMETRY_MESSAGE_MAX_LENGTH,r as TELEMETRY_STACK_MAX_LENGTH,T as TELEMETRY_TRUNCATION_TAIL,_ as applyConsentChange,L as assembleEventBatch,R as assembleLogBatch,d as batchContextSchema,z as classifyHttpStatus,B as classifyTransportFailure,m as eventBatchSchema,f as eventEntrySchema,C as getDeliveryProfile,v as isChannelUploadAllowed,h as logBatchSchema,p as logEntrySchema,w as normalizeDeliveryMode,P as registerSendFailure,F as registerSendSuccess,A as sanitizeEventName,O as sanitizeMessage,j as sanitizeProperties,k as sanitizeStack,N as shouldAttemptSend};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-telemetry/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"core",
|
|
7
|
+
"observability",
|
|
8
|
+
"telemetry",
|
|
9
|
+
"typescript"
|
|
10
|
+
],
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "lzi-builder",
|
|
27
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
28
|
+
"prepublishOnly": "bun run build:prod",
|
|
29
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
30
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
31
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
32
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
33
|
+
"lint": "oxlint && oxfmt --check",
|
|
34
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"test:watch": "bun test --watch",
|
|
37
|
+
"test:coverage": "bun test --coverage",
|
|
38
|
+
"clean": "lzi-dev-cli clean"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"zod": "^4.4.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {}
|
|
44
|
+
}
|