posthog-node 5.51.8 → 5.52.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/LICENSE +64 -0
- package/dist/client.d.ts +111 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +57 -2
- package/dist/client.mjs +58 -3
- package/dist/entrypoints/index.node.d.ts +3 -0
- package/dist/entrypoints/index.node.d.ts.map +1 -1
- package/dist/entrypoints/index.node.js +16 -2
- package/dist/entrypoints/index.node.mjs +8 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.d.ts.map +1 -1
- package/dist/extensions/context/span-context.node.d.ts +15 -0
- package/dist/extensions/context/span-context.node.d.ts.map +1 -0
- package/dist/extensions/context/span-context.node.js +51 -0
- package/dist/extensions/context/span-context.node.mjs +13 -0
- package/dist/host-os.node.d.ts +10 -0
- package/dist/host-os.node.d.ts.map +1 -0
- package/dist/host-os.node.js +50 -0
- package/dist/host-os.node.mjs +12 -0
- package/dist/types.d.ts +41 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +4 -3
- package/src/client.ts +206 -3
- package/src/entrypoints/index.node.ts +11 -0
- package/src/exports.ts +15 -0
- package/src/extensions/context/span-context.node.ts +22 -0
- package/src/host-os.node.ts +22 -0
- package/src/types.ts +46 -0
- package/src/version.ts +1 -1
package/LICENSE
CHANGED
|
@@ -217,6 +217,70 @@ limitations under the License.
|
|
|
217
217
|
limitations under the License.
|
|
218
218
|
|
|
219
219
|
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
The @posthog/core package in packages/core is licensed under the MIT License below.
|
|
223
|
+
Third-party code remains subject to its respective notices in this file.
|
|
224
|
+
This owning notice is preserved from posthog-js-lite, from which @posthog/core was migrated:
|
|
225
|
+
https://github.com/PostHog/posthog-js-lite/blob/5fb7bee96f739b243dfea5589e2027f16629e8cd/LICENSE
|
|
226
|
+
|
|
227
|
+
MIT License
|
|
228
|
+
|
|
229
|
+
Copyright (c) 2022 PostHog (part of Hiberly Inc)
|
|
230
|
+
|
|
231
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
232
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
233
|
+
in the Software without restriction, including without limitation the rights
|
|
234
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
235
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
236
|
+
furnished to do so, subject to the following conditions:
|
|
237
|
+
|
|
238
|
+
The above copyright notice and this permission notice shall be included in all
|
|
239
|
+
copies or substantial portions of the Software.
|
|
240
|
+
|
|
241
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
242
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
243
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
244
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
245
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
246
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
247
|
+
SOFTWARE.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
packages/core/src/error-tracking/parsers/index.ts and its compiled distributions contain code
|
|
252
|
+
derived from TraceKit. This license only applies to the relevant code.
|
|
253
|
+
|
|
254
|
+
MIT License
|
|
255
|
+
|
|
256
|
+
Copyright (c) 2013 Onur Can Cakmak onur.cakmak@gmail.com and all TraceKit contributors.
|
|
257
|
+
|
|
258
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
259
|
+
software and associated documentation files(the 'Software'), to deal in the Software
|
|
260
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
261
|
+
merge, publish, distribute, sublicense, and / or sell copies of the Software, and to
|
|
262
|
+
permit persons to whom the Software is furnished to do so, subject to the following
|
|
263
|
+
conditions:
|
|
264
|
+
|
|
265
|
+
The above copyright notice and this permission notice shall be included in all copies
|
|
266
|
+
or substantial portions of the Software.
|
|
267
|
+
|
|
268
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
269
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
270
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
271
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
272
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
273
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
packages/core/src/vendor/uuidv7.ts and its compiled distributions contain code from uuidv7:
|
|
278
|
+
https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
|
|
279
|
+
|
|
280
|
+
Copyright 2021-2023 LiosK
|
|
281
|
+
|
|
282
|
+
This code is licensed under the Apache License, Version 2.0, reproduced above.
|
|
283
|
+
|
|
220
284
|
---
|
|
221
285
|
|
|
222
286
|
Some files in this codebase contain code from getsentry/sentry-javascript.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FeatureFlagValue, JsonType, PostHogCaptureOptions, PostHogCoreStateless, PostHogEventProperties, PostHogFetchOptions, PostHogFetchResponse, PostHogFlagsAndPayloadsResponse, PostHogPersistedProperty, Properties, RetriableOptions } from '@posthog/core';
|
|
2
|
-
import type { Metrics } from '@posthog/core';
|
|
2
|
+
import type { Metrics, Span, SpanContextManager, StartSpanOptions } from '@posthog/core';
|
|
3
3
|
import { AllFlagsOptions, EventMessage, FeatureFlagResult, FlagEvaluationOptions, GroupIdentifyMessage, IdentifyMessage, IPostHog, OverrideFeatureFlagsOptions, PostHogOptions, SetPersonPropertiesMessage, UnsetPersonPropertiesMessage } from './types';
|
|
4
4
|
import { FeatureFlagEvaluations, FlagCalledEventParams } from './feature-flag-evaluations';
|
|
5
5
|
import ErrorTracking from './extensions/error-tracking';
|
|
@@ -16,6 +16,8 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
|
|
|
16
16
|
readonly options: PostHogOptions;
|
|
17
17
|
protected readonly context?: IPostHogContext;
|
|
18
18
|
private _metrics?;
|
|
19
|
+
private _traces?;
|
|
20
|
+
private _spanContext?;
|
|
19
21
|
private readonly captureMode;
|
|
20
22
|
private _v1Sender?;
|
|
21
23
|
/** Whether this client captures full AI content: see `enableFullAiCapture` in `PostHogOptions`. */
|
|
@@ -57,7 +59,15 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
|
|
|
57
59
|
*/
|
|
58
60
|
constructor(apiKey: string, options?: PostHogOptions);
|
|
59
61
|
protected enqueue(type: string, message: any, options?: PostHogCaptureOptions, explicitRoute?: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Concurrent so a serverless handler waits for one round trip, not two. A
|
|
64
|
+
* failed span export leaves the spans queued rather than rejecting, since
|
|
65
|
+
* callers already treat `flush()` as safe to leave unwrapped.
|
|
66
|
+
*/
|
|
67
|
+
private _flushEventsAndSpans;
|
|
68
|
+
protected flushAutomatic(): Promise<void>;
|
|
60
69
|
flush(): Promise<void>;
|
|
70
|
+
private _flushKeepingRuntimeAlive;
|
|
61
71
|
private scheduleDebouncedFlush;
|
|
62
72
|
private _consumeWaitUntilCycle;
|
|
63
73
|
private resolveWaitUntilFlush;
|
|
@@ -178,6 +188,106 @@ export declare abstract class PostHogBackendClient extends PostHogCoreStateless
|
|
|
178
188
|
* {@label Metrics}
|
|
179
189
|
*/
|
|
180
190
|
get metrics(): Metrics;
|
|
191
|
+
/**
|
|
192
|
+
* Active-span tracking. Overridden by the Node entrypoint with an
|
|
193
|
+
* `AsyncLocalStorage`-backed manager; the edge build keeps this synchronous
|
|
194
|
+
* fallback, matching how `initializeContext` already differs between them.
|
|
195
|
+
*/
|
|
196
|
+
protected initializeSpanContextManager(): SpanContextManager;
|
|
197
|
+
/**
|
|
198
|
+
* Runtime-detected OTLP resource attributes for every span. Overridden by the
|
|
199
|
+
* Node entrypoint with the host OS; the edge build contributes none, keeping
|
|
200
|
+
* `node:os` out of an edge bundle, which cannot resolve it.
|
|
201
|
+
*/
|
|
202
|
+
protected hostResourceAttributes(): Record<string, string>;
|
|
203
|
+
/**
|
|
204
|
+
* Active-span tracking, built on first use. Lives on the client rather than
|
|
205
|
+
* on the traces pipeline because a client with tracing off still activates a
|
|
206
|
+
* pass-through span, so it needs the same store the pipeline would use.
|
|
207
|
+
*/
|
|
208
|
+
private get _spanContextManager();
|
|
209
|
+
/**
|
|
210
|
+
* The traces pipeline, built on first use. Returns `undefined` when the
|
|
211
|
+
* `traces` client option is absent — tracing is off until configured.
|
|
212
|
+
*/
|
|
213
|
+
private get _tracesPipeline();
|
|
214
|
+
/**
|
|
215
|
+
* PostHog context attached to every span, so traces join back to persons and
|
|
216
|
+
* sessions. A server process has no ambient identity, so these come from the
|
|
217
|
+
* current request context — the Express/NestJS middleware or `withContext`.
|
|
218
|
+
*/
|
|
219
|
+
private _tracingContext;
|
|
220
|
+
/**
|
|
221
|
+
* Starts a span without making it active — for work that can't wrap a
|
|
222
|
+
* callback. Prefer `withSpan`, which ends the span for you.
|
|
223
|
+
*
|
|
224
|
+
* Always returns a handle, so calling code never has to branch: when the
|
|
225
|
+
* `traces` option is absent, the SDK is disabled, or the user has opted out,
|
|
226
|
+
* the handle is inert and nothing is exported. An inert handle given a
|
|
227
|
+
* `parent` header still returns it from `traceparent()`, so a service with
|
|
228
|
+
* tracing off passes a distributed trace through instead of severing it.
|
|
229
|
+
*
|
|
230
|
+
* {@label Traces}
|
|
231
|
+
*
|
|
232
|
+
* @experimental Subject to change in a minor release.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const span = posthog.startSpan('checkout', { attributes: { plan: 'pro' } })
|
|
237
|
+
* span.setAttribute('cart.items', 3)
|
|
238
|
+
* span.end()
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
startSpan(name: string, options?: StartSpanOptions): Span;
|
|
242
|
+
/**
|
|
243
|
+
* Runs a callback with a span active for its duration and ends the span for
|
|
244
|
+
* you — at return for a sync callback, at settle for an async one. Takes an
|
|
245
|
+
* optional `StartSpanOptions` between the name and the callback:
|
|
246
|
+
* `withSpan(name, fn)` or `withSpan(name, options, fn)`.
|
|
247
|
+
*
|
|
248
|
+
* Spans started inside the callback nest under it automatically. If the
|
|
249
|
+
* callback throws or rejects, the span records the exception and the original
|
|
250
|
+
* error is rethrown unchanged. A callback that ends the span itself gets the
|
|
251
|
+
* rethrow but not the recording, since the span is already exported by then.
|
|
252
|
+
*
|
|
253
|
+
* Spans nest across `await` only on the Node runtime, which tracks the active
|
|
254
|
+
* span with `AsyncLocalStorage`. The edge build restores the active span when
|
|
255
|
+
* the callback returns its promise, so spans started after an `await` there
|
|
256
|
+
* begin a new trace.
|
|
257
|
+
*
|
|
258
|
+
* {@label Traces}
|
|
259
|
+
*
|
|
260
|
+
* @experimental Subject to change in a minor release.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* await posthog.withSpan('POST /checkout', { parent: req.get('traceparent') }, async (span) => {
|
|
265
|
+
* span.setAttribute('plan', user.plan)
|
|
266
|
+
* return processOrder()
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
withSpan<T>(name: string, fn: (span: Span) => T): T;
|
|
271
|
+
withSpan<T>(name: string, options: StartSpanOptions, fn: (span: Span) => T): T;
|
|
272
|
+
/**
|
|
273
|
+
* The span currently active on this async execution path, or `null` outside
|
|
274
|
+
* any `withSpan` callback.
|
|
275
|
+
*
|
|
276
|
+
* On the edge build this returns `null` after an `await`, because the active
|
|
277
|
+
* span is tracked synchronously there.
|
|
278
|
+
*
|
|
279
|
+
* {@label Traces}
|
|
280
|
+
*
|
|
281
|
+
* @experimental Subject to change in a minor release.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* // Propagate the trace to another service
|
|
286
|
+
* const traceparent = posthog.getActiveSpan()?.traceparent()
|
|
287
|
+
* await fetch(url, { headers: traceparent ? { traceparent } : {} })
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
getActiveSpan(): Span | null;
|
|
181
291
|
/**
|
|
182
292
|
* Get the custom user agent string for this client.
|
|
183
293
|
*
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,gBAAgB,EAKhB,QAAQ,EAER,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,+BAA+B,EAG/B,wBAAwB,EAGxB,UAAU,EAIV,gBAAgB,EAKjB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,gBAAgB,EAAmB,MAAM,eAAe,CAAA;AACzG,OAAO,EACL,eAAe,EACf,YAAY,EAIZ,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,QAAQ,EACR,2BAA2B,EAC3B,cAAc,EAEd,0B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C,EAAE,MAAM,EACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EACnD,KAAK,CAAC,EAAE,sBAAsB,GAC7B,OAAO,CAAC,IAAI,CAAC;IAeH,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC;QAC7D,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;QACb,UAAU,EAAE,sBAAsB,CAAA;QAClC,OAAO,EAAE,qBAAqB,CAAA;KAC/B,CAAC;YAIY,oBAAoB;IAsJlC,OAAO,CAAC,cAAc;CA4BvB"}
|
package/dist/client.js
CHANGED
|
@@ -144,8 +144,24 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
144
144
|
super.enqueue(type, message, options, explicitRoute);
|
|
145
145
|
this.scheduleDebouncedFlush();
|
|
146
146
|
}
|
|
147
|
+
_flushEventsAndSpans(skipThrottledSpans = false) {
|
|
148
|
+
const events = this.flushWithPendingPromises();
|
|
149
|
+
if (!this._traces || skipThrottledSpans && this._traces.throttled) return events;
|
|
150
|
+
return (0, core_namespaceObject.allSettled)([
|
|
151
|
+
events,
|
|
152
|
+
this._traces.flush().catch(()=>{})
|
|
153
|
+
]).then(([eventsResult])=>{
|
|
154
|
+
if ('rejected' === eventsResult.status) throw eventsResult.reason;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
flushAutomatic() {
|
|
158
|
+
return this._flushKeepingRuntimeAlive(true);
|
|
159
|
+
}
|
|
147
160
|
async flush() {
|
|
148
|
-
|
|
161
|
+
return this._flushKeepingRuntimeAlive(false);
|
|
162
|
+
}
|
|
163
|
+
_flushKeepingRuntimeAlive(skipThrottledSpans) {
|
|
164
|
+
const flushPromise = this._flushEventsAndSpans(skipThrottledSpans);
|
|
149
165
|
const waitUntil = this.options.waitUntil;
|
|
150
166
|
if (waitUntil && !this._waitUntilCycle) try {
|
|
151
167
|
waitUntil(flushPromise.catch(()=>{}));
|
|
@@ -193,7 +209,7 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
193
209
|
async resolveWaitUntilFlush() {
|
|
194
210
|
const resolve = this._consumeWaitUntilCycle();
|
|
195
211
|
try {
|
|
196
|
-
await this.
|
|
212
|
+
await this._flushEventsAndSpans();
|
|
197
213
|
} catch {} finally{
|
|
198
214
|
resolve?.();
|
|
199
215
|
}
|
|
@@ -287,6 +303,41 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
287
303
|
if (!this._metrics) this._metrics = new core_namespaceObject.PostHogMetrics(this, (0, core_namespaceObject.resolveMetricsConfig)(this.options.metrics), this._logger);
|
|
288
304
|
return this._metrics;
|
|
289
305
|
}
|
|
306
|
+
initializeSpanContextManager() {
|
|
307
|
+
return new core_namespaceObject.SyncSpanContextManager();
|
|
308
|
+
}
|
|
309
|
+
hostResourceAttributes() {
|
|
310
|
+
return {};
|
|
311
|
+
}
|
|
312
|
+
get _spanContextManager() {
|
|
313
|
+
if (!this._spanContext) this._spanContext = this.initializeSpanContextManager();
|
|
314
|
+
return this._spanContext;
|
|
315
|
+
}
|
|
316
|
+
get _tracesPipeline() {
|
|
317
|
+
if (!this.options.traces) return;
|
|
318
|
+
if (!this._traces) this._traces = new core_namespaceObject.PostHogTraces(this, (0, core_namespaceObject.resolveTracesConfig)(this.options.traces, this.hostResourceAttributes(), this._logger), this._logger, ()=>this._tracingContext(), this._spanContextManager, ()=>this.scheduleDebouncedFlush());
|
|
319
|
+
return this._traces;
|
|
320
|
+
}
|
|
321
|
+
_tracingContext() {
|
|
322
|
+
const context = this.context?.get();
|
|
323
|
+
return {
|
|
324
|
+
distinctId: context?.distinctId,
|
|
325
|
+
sessionId: context?.sessionId
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
startSpan(name, options) {
|
|
329
|
+
return this._tracesPipeline?.startSpan(name, options) ?? (0, core_namespaceObject.inertSpan)(options, this._spanContextManager.active());
|
|
330
|
+
}
|
|
331
|
+
withSpan(name, optionsOrFn, maybeFn) {
|
|
332
|
+
const options = 'function' == typeof optionsOrFn ? void 0 : optionsOrFn;
|
|
333
|
+
const fn = 'function' == typeof optionsOrFn ? optionsOrFn : maybeFn;
|
|
334
|
+
const pipeline = this._tracesPipeline;
|
|
335
|
+
if (!pipeline) return (0, core_namespaceObject.runWithActiveSpan)(this._spanContextManager, (0, core_namespaceObject.inertSpan)(options, this._spanContextManager.active()), fn);
|
|
336
|
+
return options ? pipeline.withSpan(name, options, fn) : pipeline.withSpan(name, fn);
|
|
337
|
+
}
|
|
338
|
+
getActiveSpan() {
|
|
339
|
+
return this._spanContextManager.active() ?? null;
|
|
340
|
+
}
|
|
290
341
|
getCustomUserAgent() {
|
|
291
342
|
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
292
343
|
}
|
|
@@ -971,6 +1022,10 @@ class PostHogBackendClient extends core_namespaceObject.PostHogCoreStateless {
|
|
|
971
1022
|
await (0, core_namespaceObject.raceWithTimeout)(this._metrics.flush().catch(()=>{}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
972
1023
|
this._metrics.reset();
|
|
973
1024
|
}
|
|
1025
|
+
if (this._traces) {
|
|
1026
|
+
await (0, core_namespaceObject.raceWithTimeout)(this._traces.flush().catch(()=>{}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
1027
|
+
this._traces.reset();
|
|
1028
|
+
}
|
|
974
1029
|
try {
|
|
975
1030
|
return await super._shutdown(Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
976
1031
|
} finally{
|
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { version } from "./version.mjs";
|
|
2
|
-
import { PostHogCoreStateless, PostHogMetrics, PostHogPersistedProperty, getEventUuid, isBlockedUA, isPlainObject, isPostHogFetchContentTooLargeError, minimizeFlagCalledEventProperties, raceWithTimeout, resolveMetricsConfig, safeSetTimeout, uuidv7 } from "@posthog/core";
|
|
2
|
+
import { PostHogCoreStateless, PostHogMetrics, PostHogPersistedProperty, PostHogTraces, SyncSpanContextManager, allSettled, getEventUuid, inertSpan, isBlockedUA, isPlainObject, isPostHogFetchContentTooLargeError, minimizeFlagCalledEventProperties, raceWithTimeout, resolveMetricsConfig, resolveTracesConfig, runWithActiveSpan, safeSetTimeout, uuidv7 } from "@posthog/core";
|
|
3
3
|
import { FeatureFlagError } from "./types.mjs";
|
|
4
4
|
import { FeatureFlagEvaluations } from "./feature-flag-evaluations.mjs";
|
|
5
5
|
import { FeatureFlagsPoller, InconclusiveMatchError, RequiresServerEvaluation } from "./extensions/feature-flags/feature-flags.mjs";
|
|
@@ -101,8 +101,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
101
101
|
super.enqueue(type, message, options, explicitRoute);
|
|
102
102
|
this.scheduleDebouncedFlush();
|
|
103
103
|
}
|
|
104
|
+
_flushEventsAndSpans(skipThrottledSpans = false) {
|
|
105
|
+
const events = this.flushWithPendingPromises();
|
|
106
|
+
if (!this._traces || skipThrottledSpans && this._traces.throttled) return events;
|
|
107
|
+
return allSettled([
|
|
108
|
+
events,
|
|
109
|
+
this._traces.flush().catch(()=>{})
|
|
110
|
+
]).then(([eventsResult])=>{
|
|
111
|
+
if ('rejected' === eventsResult.status) throw eventsResult.reason;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
flushAutomatic() {
|
|
115
|
+
return this._flushKeepingRuntimeAlive(true);
|
|
116
|
+
}
|
|
104
117
|
async flush() {
|
|
105
|
-
|
|
118
|
+
return this._flushKeepingRuntimeAlive(false);
|
|
119
|
+
}
|
|
120
|
+
_flushKeepingRuntimeAlive(skipThrottledSpans) {
|
|
121
|
+
const flushPromise = this._flushEventsAndSpans(skipThrottledSpans);
|
|
106
122
|
const waitUntil = this.options.waitUntil;
|
|
107
123
|
if (waitUntil && !this._waitUntilCycle) try {
|
|
108
124
|
waitUntil(flushPromise.catch(()=>{}));
|
|
@@ -150,7 +166,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
150
166
|
async resolveWaitUntilFlush() {
|
|
151
167
|
const resolve = this._consumeWaitUntilCycle();
|
|
152
168
|
try {
|
|
153
|
-
await this.
|
|
169
|
+
await this._flushEventsAndSpans();
|
|
154
170
|
} catch {} finally{
|
|
155
171
|
resolve?.();
|
|
156
172
|
}
|
|
@@ -244,6 +260,41 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
244
260
|
if (!this._metrics) this._metrics = new PostHogMetrics(this, resolveMetricsConfig(this.options.metrics), this._logger);
|
|
245
261
|
return this._metrics;
|
|
246
262
|
}
|
|
263
|
+
initializeSpanContextManager() {
|
|
264
|
+
return new SyncSpanContextManager();
|
|
265
|
+
}
|
|
266
|
+
hostResourceAttributes() {
|
|
267
|
+
return {};
|
|
268
|
+
}
|
|
269
|
+
get _spanContextManager() {
|
|
270
|
+
if (!this._spanContext) this._spanContext = this.initializeSpanContextManager();
|
|
271
|
+
return this._spanContext;
|
|
272
|
+
}
|
|
273
|
+
get _tracesPipeline() {
|
|
274
|
+
if (!this.options.traces) return;
|
|
275
|
+
if (!this._traces) this._traces = new PostHogTraces(this, resolveTracesConfig(this.options.traces, this.hostResourceAttributes(), this._logger), this._logger, ()=>this._tracingContext(), this._spanContextManager, ()=>this.scheduleDebouncedFlush());
|
|
276
|
+
return this._traces;
|
|
277
|
+
}
|
|
278
|
+
_tracingContext() {
|
|
279
|
+
const context = this.context?.get();
|
|
280
|
+
return {
|
|
281
|
+
distinctId: context?.distinctId,
|
|
282
|
+
sessionId: context?.sessionId
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
startSpan(name, options) {
|
|
286
|
+
return this._tracesPipeline?.startSpan(name, options) ?? inertSpan(options, this._spanContextManager.active());
|
|
287
|
+
}
|
|
288
|
+
withSpan(name, optionsOrFn, maybeFn) {
|
|
289
|
+
const options = 'function' == typeof optionsOrFn ? void 0 : optionsOrFn;
|
|
290
|
+
const fn = 'function' == typeof optionsOrFn ? optionsOrFn : maybeFn;
|
|
291
|
+
const pipeline = this._tracesPipeline;
|
|
292
|
+
if (!pipeline) return runWithActiveSpan(this._spanContextManager, inertSpan(options, this._spanContextManager.active()), fn);
|
|
293
|
+
return options ? pipeline.withSpan(name, options, fn) : pipeline.withSpan(name, fn);
|
|
294
|
+
}
|
|
295
|
+
getActiveSpan() {
|
|
296
|
+
return this._spanContextManager.active() ?? null;
|
|
297
|
+
}
|
|
247
298
|
getCustomUserAgent() {
|
|
248
299
|
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
249
300
|
}
|
|
@@ -928,6 +979,10 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
928
979
|
await raceWithTimeout(this._metrics.flush().catch(()=>{}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
929
980
|
this._metrics.reset();
|
|
930
981
|
}
|
|
982
|
+
if (this._traces) {
|
|
983
|
+
await raceWithTimeout(this._traces.flush().catch(()=>{}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
984
|
+
this._traces.reset();
|
|
985
|
+
}
|
|
931
986
|
try {
|
|
932
987
|
return await super._shutdown(Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
933
988
|
} finally{
|
|
@@ -2,11 +2,14 @@ export * from '../exports';
|
|
|
2
2
|
import type { PostHogFetchBodyBytes } from '@posthog/core';
|
|
3
3
|
import { PostHogBackendClient } from '../client';
|
|
4
4
|
import { ErrorTracking as CoreErrorTracking } from '@posthog/core';
|
|
5
|
+
import type { SpanContextManager } from '@posthog/core';
|
|
5
6
|
import { PostHogContext } from '../extensions/context/context';
|
|
6
7
|
export declare class PostHog extends PostHogBackendClient {
|
|
7
8
|
getLibraryId(): string;
|
|
8
9
|
protected compressPayload(payload: string): Promise<PostHogFetchBodyBytes | null>;
|
|
9
10
|
protected initializeContext(): PostHogContext;
|
|
11
|
+
protected initializeSpanContextManager(): SpanContextManager;
|
|
12
|
+
protected hostResourceAttributes(): Record<string, string>;
|
|
10
13
|
protected createErrorPropertiesBuilder(): CoreErrorTracking.ErrorPropertiesBuilder;
|
|
11
14
|
}
|
|
12
15
|
//# sourceMappingURL=index.node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/entrypoints/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAM1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/entrypoints/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAM1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAK9D,qBAAa,OAAQ,SAAQ,oBAAoB;IAC/C,YAAY,IAAI,MAAM;cAIH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAI1F,SAAS,CAAC,iBAAiB,IAAI,cAAc;cAI1B,4BAA4B,IAAI,kBAAkB;cAIlD,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;cAIhD,4BAA4B,IAAI,iBAAiB,CAAC,sBAAsB;CAiB5F"}
|
|
@@ -9,6 +9,9 @@ var __webpack_modules__ = {
|
|
|
9
9
|
"../extensions/context/context" (module) {
|
|
10
10
|
module.exports = require("../extensions/context/context.js");
|
|
11
11
|
},
|
|
12
|
+
"../extensions/context/span-context.node" (module) {
|
|
13
|
+
module.exports = require("../extensions/context/span-context.node.js");
|
|
14
|
+
},
|
|
12
15
|
"../extensions/error-tracking/modifiers/context-lines.node" (module) {
|
|
13
16
|
module.exports = require("../extensions/error-tracking/modifiers/context-lines.node.js");
|
|
14
17
|
},
|
|
@@ -21,6 +24,9 @@ var __webpack_modules__ = {
|
|
|
21
24
|
"../gzip.node" (module) {
|
|
22
25
|
module.exports = require("../gzip.node.js");
|
|
23
26
|
},
|
|
27
|
+
"../host-os.node" (module) {
|
|
28
|
+
module.exports = require("../host-os.node.js");
|
|
29
|
+
},
|
|
24
30
|
"@posthog/core" (module) {
|
|
25
31
|
module.exports = require("@posthog/core");
|
|
26
32
|
}
|
|
@@ -85,17 +91,25 @@ var __webpack_exports__ = {};
|
|
|
85
91
|
var _client__rspack_import_4 = __webpack_require__("../client");
|
|
86
92
|
var _posthog_core__rspack_import_5 = __webpack_require__("@posthog/core");
|
|
87
93
|
var _extensions_context_context__rspack_import_6 = __webpack_require__("../extensions/context/context");
|
|
88
|
-
var
|
|
94
|
+
var _extensions_context_span_context_node__rspack_import_7 = __webpack_require__("../extensions/context/span-context.node");
|
|
95
|
+
var _gzip_node__rspack_import_8 = __webpack_require__("../gzip.node");
|
|
96
|
+
var _host_os_node__rspack_import_9 = __webpack_require__("../host-os.node");
|
|
89
97
|
class PostHog extends _client__rspack_import_4.PostHogBackendClient {
|
|
90
98
|
getLibraryId() {
|
|
91
99
|
return 'posthog-node';
|
|
92
100
|
}
|
|
93
101
|
compressPayload(payload) {
|
|
94
|
-
return (0,
|
|
102
|
+
return (0, _gzip_node__rspack_import_8.gzipCompress)(payload, this.isDebug);
|
|
95
103
|
}
|
|
96
104
|
initializeContext() {
|
|
97
105
|
return new _extensions_context_context__rspack_import_6.PostHogContext();
|
|
98
106
|
}
|
|
107
|
+
initializeSpanContextManager() {
|
|
108
|
+
return new _extensions_context_span_context_node__rspack_import_7.AsyncLocalStorageSpanContextManager();
|
|
109
|
+
}
|
|
110
|
+
hostResourceAttributes() {
|
|
111
|
+
return (0, _host_os_node__rspack_import_9.hostOsResourceAttributes)();
|
|
112
|
+
}
|
|
99
113
|
createErrorPropertiesBuilder() {
|
|
100
114
|
return new _posthog_core__rspack_import_5.ErrorTracking.ErrorPropertiesBuilder([
|
|
101
115
|
new _posthog_core__rspack_import_5.ErrorTracking.EventCoercer(),
|
|
@@ -4,7 +4,9 @@ import { createRelativePathModifier } from "../extensions/error-tracking/modifie
|
|
|
4
4
|
import { PostHogBackendClient } from "../client.mjs";
|
|
5
5
|
import { ErrorTracking } from "@posthog/core";
|
|
6
6
|
import { PostHogContext } from "../extensions/context/context.mjs";
|
|
7
|
+
import { AsyncLocalStorageSpanContextManager } from "../extensions/context/span-context.node.mjs";
|
|
7
8
|
import { gzipCompress } from "../gzip.node.mjs";
|
|
9
|
+
import { hostOsResourceAttributes } from "../host-os.node.mjs";
|
|
8
10
|
export * from "../exports.mjs";
|
|
9
11
|
class PostHog extends PostHogBackendClient {
|
|
10
12
|
getLibraryId() {
|
|
@@ -16,6 +18,12 @@ class PostHog extends PostHogBackendClient {
|
|
|
16
18
|
initializeContext() {
|
|
17
19
|
return new PostHogContext();
|
|
18
20
|
}
|
|
21
|
+
initializeSpanContextManager() {
|
|
22
|
+
return new AsyncLocalStorageSpanContextManager();
|
|
23
|
+
}
|
|
24
|
+
hostResourceAttributes() {
|
|
25
|
+
return hostOsResourceAttributes();
|
|
26
|
+
}
|
|
19
27
|
createErrorPropertiesBuilder() {
|
|
20
28
|
return new ErrorTracking.ErrorPropertiesBuilder([
|
|
21
29
|
new ErrorTracking.EventCoercer(),
|
package/dist/exports.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { FlagDefinitionCacheData, FlagDefinitionCacheProvider } from './ext
|
|
|
6
6
|
export { FeatureFlagError } from '@posthog/core';
|
|
7
7
|
export type { FeatureFlagErrorType } from '@posthog/core';
|
|
8
8
|
export type { CaptureMetricOptions, Metrics, MetricsConfig } from '@posthog/core';
|
|
9
|
+
export type { Span, SpanAttributes, SpanAttributeValue, SpanKind, SpanStatusCode, SpanTimeInput, StartSpanOptions, SpanRecord, BeforeSpanSendFn, TracesConfig, } from '@posthog/core';
|
|
9
10
|
export { cookieStateToProperties, cookieStoreFromHeader, getPostHogCookieName, parsePostHogCookie, readPostHogCookie, serializePostHogCookie, uuidv7, } from '@posthog/core';
|
|
10
11
|
export type { CookieStore, PostHogCookieState } from '@posthog/core';
|
|
11
12
|
//# sourceMappingURL=exports.d.ts.map
|
package/dist/exports.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,YAAY,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAI5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAIzD,YAAY,EAAE,oBAAoB,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,YAAY,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAI5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAIzD,YAAY,EAAE,oBAAoB,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAIjF,YAAY,EACV,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,YAAY,GACb,MAAM,eAAe,CAAA;AAKtB,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Span, SpanContextManager } from '@posthog/core';
|
|
2
|
+
/**
|
|
3
|
+
* Active-span tracking backed by `AsyncLocalStorage`, so a span stays active
|
|
4
|
+
* across `await` boundaries and through any async work its callback starts.
|
|
5
|
+
*
|
|
6
|
+
* Lives here rather than in core because core ships to browsers, edge runtimes
|
|
7
|
+
* and React Native and must not import `node:async_hooks`; the edge entrypoint
|
|
8
|
+
* falls back to core's synchronous manager.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AsyncLocalStorageSpanContextManager implements SpanContextManager {
|
|
11
|
+
private readonly _storage;
|
|
12
|
+
active(): Span | undefined;
|
|
13
|
+
with<T>(span: Span, fn: () => T): T;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=span-context.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-context.node.d.ts","sourceRoot":"","sources":["../../../src/extensions/context/span-context.node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAE7D;;;;;;;GAOG;AACH,qBAAa,mCAAoC,YAAW,kBAAkB;IAC5E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IAEzD,MAAM,IAAI,IAAI,GAAG,SAAS;IAI1B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;CAGpC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
AsyncLocalStorageSpanContextManager: ()=>AsyncLocalStorageSpanContextManager
|
|
32
|
+
});
|
|
33
|
+
const external_node_async_hooks_namespaceObject = require("node:async_hooks");
|
|
34
|
+
class AsyncLocalStorageSpanContextManager {
|
|
35
|
+
active() {
|
|
36
|
+
return this._storage.getStore();
|
|
37
|
+
}
|
|
38
|
+
with(span, fn) {
|
|
39
|
+
return this._storage.run(span, fn);
|
|
40
|
+
}
|
|
41
|
+
constructor(){
|
|
42
|
+
this._storage = new external_node_async_hooks_namespaceObject.AsyncLocalStorage();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.AsyncLocalStorageSpanContextManager = __webpack_exports__.AsyncLocalStorageSpanContextManager;
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
+
"AsyncLocalStorageSpanContextManager"
|
|
48
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
49
|
+
Object.defineProperty(exports, '__esModule', {
|
|
50
|
+
value: true
|
|
51
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
class AsyncLocalStorageSpanContextManager {
|
|
3
|
+
active() {
|
|
4
|
+
return this._storage.getStore();
|
|
5
|
+
}
|
|
6
|
+
with(span, fn) {
|
|
7
|
+
return this._storage.run(span, fn);
|
|
8
|
+
}
|
|
9
|
+
constructor(){
|
|
10
|
+
this._storage = new AsyncLocalStorage();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export { AsyncLocalStorageSpanContextManager };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTLP `os.name` / `os.version` for the machine running the SDK, so spans can
|
|
3
|
+
* be filtered by platform (e.g. "only the Linux workers") in PostHog.
|
|
4
|
+
*
|
|
5
|
+
* Node-only, like the other `.node` modules: importing `node:os` from a shared
|
|
6
|
+
* module would put it in the edge bundle. A failed read omits the key rather
|
|
7
|
+
* than throwing out of client construction.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hostOsResourceAttributes(): Record<string, string>;
|
|
10
|
+
//# sourceMappingURL=host-os.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-os.node.d.ts","sourceRoot":"","sources":["../src/host-os.node.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUjE"}
|