@walkeros/server-destination-posthog 4.8.1 → 4.8.3-next-1793115089237
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 +64 -3
- package/README.md +2 -3
- package/dist/dev.d.mts +31 -6
- package/dist/dev.d.ts +31 -6
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/examples/index.d.mts +24 -4
- package/dist/examples/index.d.ts +24 -4
- package/dist/examples/index.js +53 -15
- package/dist/examples/index.mjs +53 -16
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +145 -29
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PostHog}from"posthog-node";import{getMappingValue,isObject,isString}from"@walkeros/core";
|
|
1
|
+
import{createRequire}from"module";createRequire(import.meta.url);import{StepError}from"@walkeros/core";import{retryBudget}from"@walkeros/server-core";import{PostHog}from"posthog-node";import{createHash}from"crypto";import{getMappingValue,isObject,isString,StepError as StepError2}from"@walkeros/core";import{batchOutcome}from"@walkeros/server-core";async function call(client,message,send2){let failure;const off=client.on?.("error",error=>{failure=failure??error});try{await send2()}catch(error){failure=failure??error}finally{off?.()}if(void 0!==failure)throw new StepError2(message,{code:timedOut(failure)?"timeout":"transport",cause:failure})}function timedOut(error){if("object"!=typeof error||null===error)return!1;const name=Reflect.get(error,"name");return"AbortError"===name||"TimeoutError"===name||timedOut(Reflect.get(error,"error")??Reflect.get(error,"cause"))}function skipped(logger,event,call2,key){logger.debug(`PostHog skipped ${call2}: ${key} resolved to nothing`,{event:event.name})}async function queue(message,send2){try{await send2()}catch(error){throw new StepError2(message,{code:"transport",cause:error})}}function exclusive(settings,task){const running=(settings._sending??Promise.resolve()).then(task);return settings._sending=running.catch(()=>{}),running}function clientOf(settings){const client=settings?.client;if(!settings||!client)throw new StepError2("PostHog client not initialized",{code:"not-ready"});return{settings:settings,client:client}}async function send(event,rule,data,settings,client,collector,logger){const mappingSettings=rule?.settings||{},identifyMapping=mappingSettings.identify??settings.identify;let distinctId,identifyResolved;if(void 0!==identifyMapping){const resolved=await getMappingValue(event,identifyMapping,{collector:collector});isObject(resolved)?(identifyResolved=resolved,isString(identifyResolved.distinctId)&&(distinctId=identifyResolved.distinctId)):skipped(logger,event,"identify","identify")}if(distinctId||(distinctId=(isString(event.user?.id)?event.user.id:void 0)||(isString(event.user?.hash)?event.user.hash:void 0)||(isString(event.user?.session)?event.user.session:void 0)||"anonymous"),identifyResolved){const $set=isObject(identifyResolved.$set)?identifyResolved.$set:void 0,$setOnce=isObject(identifyResolved.$set_once)?identifyResolved.$set_once:void 0;if($set||$setOnce){const properties={};$set&&(properties.$set=$set),$setOnce&&(properties.$set_once=$setOnce),await queue("PostHog identify failed",()=>client.identify({distinctId:distinctId,properties:properties}))}}const groupMapping=mappingSettings.group??settings.group;let groups;if(void 0!==groupMapping){const resolved=await getMappingValue(event,groupMapping,{collector:collector});if(isObject(resolved)){const groupResolved=resolved,type=groupResolved.type,key=groupResolved.key,properties=isObject(groupResolved.properties)?groupResolved.properties:void 0;isString(type)&&(isString(key)||"number"==typeof key)?(properties&&await queue("PostHog group identify failed",()=>client.groupIdentify({groupType:type,groupKey:String(key),properties:properties})),groups={[type]:key}):skipped(logger,event,"group","group")}else skipped(logger,event,"group","group")}if(!0!==rule?.silent){const eventName=isString(rule?.name)?rule.name:event.name,properties=isObject(data)?data:{},captureArgs={distinctId:distinctId,event:eventName,properties:properties};groups&&(captureArgs.groups=groups),event.id&&(captureArgs.uuid=function(id){const hex=createHash("sha256").update(id).digest("hex"),variant=(3&parseInt(hex[16],16)|8).toString(16);return[hex.slice(0,8),hex.slice(8,12),`8${hex.slice(13,16)}`,`${variant}${hex.slice(17,20)}`,hex.slice(20,32)].join("-")}(event.id)),await queue("PostHog capture failed",()=>client.capture(captureArgs))}}var types_exports={},destinationPostHog={type:"posthog",config:{batch:{size:20,wait:1e4}},init:async({config:partialConfig,env:env})=>function(partialConfig={},env){const settings=partialConfig.settings||{},{apiKey:apiKey}=settings;if(!apiKey)throw new StepError("Config settings apiKey missing",{code:"config"});const budget=retryBudget(partialConfig.timeout),options={requestTimeout:budget.attempt,fetchRetryCount:budget.retries,fetchRetryDelay:budget.wait};settings.host&&(options.host=settings.host),void 0!==settings.flushAt&&(options.flushAt=settings.flushAt),void 0!==settings.flushInterval&&(options.flushInterval=settings.flushInterval),settings.personalApiKey&&(options.personalApiKey=settings.personalApiKey),void 0!==settings.featureFlagsPollingInterval&&(options.featureFlagsPollingInterval=settings.featureFlagsPollingInterval),void 0!==settings.disableGeoip&&(options.disableGeoip=settings.disableGeoip),void 0!==settings.disableCompression&&(options.disableCompression=settings.disableCompression),void 0!==settings.requestTimeout&&(options.requestTimeout=settings.requestTimeout),void 0!==settings.fetchRetryCount&&(options.fetchRetryCount=settings.fetchRetryCount),void 0!==settings.fetchRetryDelay&&(options.fetchRetryDelay=settings.fetchRetryDelay),void 0!==settings.debug&&(options.debug=settings.debug),void 0!==settings.disabled&&(options.disabled=settings.disabled);const client=new(env?.PostHog||PostHog)(apiKey,options),settingsConfig={...settings,apiKey:apiKey,client:client};return{...partialConfig,settings:settingsConfig}}(partialConfig,env),push:async function(event,{config:config,rule:rule,data:data,collector:collector,logger:logger}){const{settings:settings,client:client}=clientOf(config.settings);await exclusive(settings,async()=>{await send(event,rule,data,settings,client,collector,logger),await call(client,"PostHog send failed",()=>client.flush())})},pushBatch:async function(batch,{config:config,collector:collector,logger:logger}){const{settings:settings,client:client}=clientOf(config.settings),failed=[];let sendError;return await exclusive(settings,async()=>{const queued=[];for(const[index,entry]of batch.entries.entries())await send(entry.event,entry.rule,entry.data,settings,client,collector,logger).then(()=>queued.push(index),error=>failed.push({index:index,error:error}));queued.length&&await call(client,"PostHog send failed",()=>client.flush()).catch(error=>{sendError=error;for(const index of queued)failed.push({index:index,error:error})})}),batchOutcome(batch.entries.length,failed,sendError)},async destroy({config:config}){const client=config?.settings?.client;client&&await client.shutdown()},on(type,context){if("consent"!==type||!context?.data)return;const client=(context.config?.settings||{}).client;if(!client)return;const consent=context.data,required=context.config?.consent;if(!required||0===Object.keys(required).length)return;Object.keys(required).every(key=>!0===consent[key])?client.enable():client.disable()}},index_default=destinationPostHog;export{types_exports as DestinationPostHog,index_default as default,destinationPostHog};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/push.ts","../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Config, Env, PartialConfig, Settings } from './types';\nimport type { Logger } from '@walkeros/core';\nimport { PostHog } from 'posthog-node';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env: Env | undefined,\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { apiKey } = settings;\n\n if (!apiKey) logger.throw('Config settings apiKey missing');\n\n // Extract PostHog SDK options from settings\n const options: Record<string, unknown> = {};\n if (settings.host) options.host = settings.host;\n if (settings.flushAt !== undefined) options.flushAt = settings.flushAt;\n if (settings.flushInterval !== undefined)\n options.flushInterval = settings.flushInterval;\n if (settings.personalApiKey) options.personalApiKey = settings.personalApiKey;\n if (settings.featureFlagsPollingInterval !== undefined)\n options.featureFlagsPollingInterval = settings.featureFlagsPollingInterval;\n if (settings.disableGeoip !== undefined)\n options.disableGeoip = settings.disableGeoip;\n if (settings.disableCompression !== undefined)\n options.disableCompression = settings.disableCompression;\n if (settings.requestTimeout !== undefined)\n options.requestTimeout = settings.requestTimeout;\n if (settings.fetchRetryCount !== undefined)\n options.fetchRetryCount = settings.fetchRetryCount;\n if (settings.fetchRetryDelay !== undefined)\n options.fetchRetryDelay = settings.fetchRetryDelay;\n if (settings.debug !== undefined) options.debug = settings.debug;\n if (settings.disabled !== undefined) options.disabled = settings.disabled;\n\n // Use PostHog from env if available, otherwise use real PostHog\n const PostHogClass = env?.PostHog || PostHog;\n const client = new PostHogClass(apiKey, options);\n\n const settingsConfig: Settings = {\n ...settings,\n apiKey,\n client,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { PushFn } from './types';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\n\nexport const push: PushFn = async function (\n event,\n { config, rule, data, collector },\n) {\n const settings = config.settings!;\n const client = settings.client;\n if (!client) return;\n\n const mappingSettings = (rule?.settings || {}) as Record<string, unknown>;\n\n // Resolve distinctId: rule-level identify wins over destination-level\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n let distinctId: string | undefined;\n let identifyResolved: Record<string, unknown> | undefined;\n\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n identifyResolved = resolved as Record<string, unknown>;\n if (isString(identifyResolved.distinctId)) {\n distinctId = identifyResolved.distinctId as string;\n }\n }\n }\n\n // Fallback distinctId from event.user\n if (!distinctId) {\n distinctId =\n (isString(event.user?.id) ? event.user.id : undefined) ||\n (isString(event.user?.hash) ? event.user.hash : undefined) ||\n (isString(event.user?.session) ? event.user.session : undefined) ||\n 'anonymous';\n }\n\n // 1. Identity - if $set or $set_once present, call client.identify()\n if (identifyResolved) {\n const $set = isObject(identifyResolved.$set)\n ? (identifyResolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(identifyResolved.$set_once)\n ? (identifyResolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if ($set || $setOnce) {\n const properties: Record<string, unknown> = {};\n if ($set) properties.$set = $set;\n if ($setOnce) properties.$set_once = $setOnce;\n client.identify({ distinctId, properties });\n }\n }\n\n // 2. Group - resolve group mapping (rule-level wins)\n const groupMapping = mappingSettings.group ?? settings.group;\n let groups: Record<string, string | number> | undefined;\n\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n const groupResolved = resolved as Record<string, unknown>;\n const type = groupResolved.type;\n const key = groupResolved.key;\n const properties = isObject(groupResolved.properties)\n ? (groupResolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && (isString(key) || typeof key === 'number')) {\n // If properties present, call groupIdentify\n if (properties) {\n client.groupIdentify({\n groupType: type,\n groupKey: String(key),\n properties,\n });\n }\n // Build groups object for capture\n groups = { [type]: key as string | number };\n }\n }\n }\n\n // 3. Capture - unless rule opts out via silent\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data) ? (data as Record<string, unknown>) : {};\n\n const captureArgs: Record<string, unknown> = {\n distinctId,\n event: eventName,\n properties,\n };\n if (groups) captureArgs.groups = groups;\n\n client.capture(captureArgs as Parameters<typeof client.capture>[0]);\n }\n};\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer } from '@walkeros/server-core';\nimport type { PostHog } from 'posthog-node';\n\nexport interface Settings {\n /** PostHog project API key (phc_...) */\n apiKey: string;\n /** PostHog client instance, populated by init */\n client?: PostHogClient;\n /** Destination-level identity mapping */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group mapping */\n group?: WalkerOSMapping.Value;\n /** Event sections to flatten into capture properties */\n include?: string[];\n // PostHog SDK passthrough options\n host?: string;\n flushAt?: number;\n flushInterval?: number;\n personalApiKey?: string;\n featureFlagsPollingInterval?: number;\n disableGeoip?: boolean;\n disableCompression?: boolean;\n requestTimeout?: number;\n fetchRetryCount?: number;\n fetchRetryDelay?: number;\n debug?: boolean;\n disabled?: boolean;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n}\n\n/**\n * The part of a PostHog client this destination calls. `PostHog` from\n * `posthog-node` satisfies it, and so does an injected mock (tests, simulate)\n * without a cast.\n */\nexport interface PostHogClient {\n capture(props: Parameters<PostHog['capture']>[0]): void;\n identify(props: Parameters<PostHog['identify']>[0]): void;\n groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;\n shutdown(): Promise<void> | void;\n enable(): Promise<void> | void;\n disable(): Promise<void> | void;\n}\n\nexport interface Env extends DestinationServer.Env {\n PostHog?: new (\n apiKey: string,\n options?: ConstructorParameters<typeof PostHog>[1],\n ) => PostHogClient;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n","import type { WalkerOS } from '@walkeros/core';\nimport type { Destination, Env, Settings } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationPostHog from './types';\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config: partialConfig, env, logger }) {\n const config = getConfig(partialConfig, env as Env | undefined, logger);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n\n async destroy({ config }) {\n const client = (config?.settings as Settings | undefined)?.client;\n if (client) {\n await client.shutdown();\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n\n const settings = (context.config?.settings || {}) as Settings;\n const client = settings.client;\n if (!client) return;\n\n const consent = context.data as WalkerOS.Consent;\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\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,QAAQ,QACtB;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,aAAO,OAAO;AAAA,IAChB,OAAO;AACL,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/push.ts","../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Config, Env, PartialConfig, Settings } from './types';\nimport { StepError } from '@walkeros/core';\nimport { retryBudget } from '@walkeros/server-core';\nimport { PostHog } from 'posthog-node';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env: Env | undefined,\n): Config {\n const settings: Partial<Settings> = partialConfig.settings || {};\n const { apiKey } = settings;\n\n if (!apiKey)\n throw new StepError('Config settings apiKey missing', { code: 'config' });\n\n // The SDK's own retry ends within config.timeout: a quarter of it per\n // request, two retries a tenth of it apart. A value set in the settings\n // wins.\n const budget = retryBudget(partialConfig.timeout);\n const options: Record<string, unknown> = {\n requestTimeout: budget.attempt,\n fetchRetryCount: budget.retries,\n fetchRetryDelay: budget.wait,\n };\n\n // Extract PostHog SDK options from settings\n if (settings.host) options.host = settings.host;\n if (settings.flushAt !== undefined) options.flushAt = settings.flushAt;\n if (settings.flushInterval !== undefined)\n options.flushInterval = settings.flushInterval;\n if (settings.personalApiKey) options.personalApiKey = settings.personalApiKey;\n if (settings.featureFlagsPollingInterval !== undefined)\n options.featureFlagsPollingInterval = settings.featureFlagsPollingInterval;\n if (settings.disableGeoip !== undefined)\n options.disableGeoip = settings.disableGeoip;\n if (settings.disableCompression !== undefined)\n options.disableCompression = settings.disableCompression;\n if (settings.requestTimeout !== undefined)\n options.requestTimeout = settings.requestTimeout;\n if (settings.fetchRetryCount !== undefined)\n options.fetchRetryCount = settings.fetchRetryCount;\n if (settings.fetchRetryDelay !== undefined)\n options.fetchRetryDelay = settings.fetchRetryDelay;\n if (settings.debug !== undefined) options.debug = settings.debug;\n if (settings.disabled !== undefined) options.disabled = settings.disabled;\n\n // Use PostHog from env if available, otherwise use real PostHog\n const PostHogClass = env?.PostHog || PostHog;\n const client = new PostHogClass(apiKey, options);\n\n const settingsConfig: Settings = {\n ...settings,\n apiKey,\n client,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { Collector, Destination, Logger, WalkerOS } from '@walkeros/core';\nimport type {\n PostHogClient,\n PushBatchFn,\n PushFn,\n Rule,\n Settings,\n} from './types';\nimport { createHash } from 'crypto';\nimport { getMappingValue, isObject, isString, StepError } from '@walkeros/core';\nimport { batchOutcome } from '@walkeros/server-core';\n\n/**\n * Run one flush to its end. The SDK reports a failed send as an `error`\n * event and a rejected flush; the call listens for the event while it runs.\n * Sends never overlap (`exclusive`), so the event belongs to this flush.\n */\nasync function call(\n client: PostHogClient,\n message: string,\n send: () => unknown,\n): Promise<void> {\n let failure: unknown;\n const off = client.on?.('error', (error) => {\n failure = failure ?? error;\n });\n try {\n await send();\n } catch (error) {\n failure = failure ?? error;\n } finally {\n off?.();\n }\n if (failure !== undefined)\n throw new StepError(message, {\n code: timedOut(failure) ? 'timeout' : 'transport',\n cause: failure,\n });\n}\n\n/**\n * Whether the SDK's last request timed out: it aborts a request after\n * `requestTimeout` and reports a network error carrying the abort.\n */\nfunction timedOut(error: unknown): boolean {\n if (typeof error !== 'object' || error === null) return false;\n const name: unknown = Reflect.get(error, 'name');\n if (name === 'AbortError' || name === 'TimeoutError') return true;\n return timedOut(Reflect.get(error, 'error') ?? Reflect.get(error, 'cause'));\n}\n\n/**\n * The uuid PostHog deduplicates a captured event by, derived from the event\n * id: the same event resent gets the same uuid. PostHog takes only a UUID,\n * so the id is hashed into one (RFC 9562 version 8, name based).\n */\nfunction uuidOf(id: string): string {\n const hex = createHash('sha256').update(id).digest('hex');\n const variant = ((parseInt(hex[16], 16) & 0x3) | 0x8).toString(16);\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n `8${hex.slice(13, 16)}`,\n `${variant}${hex.slice(17, 20)}`,\n hex.slice(20, 32),\n ].join('-');\n}\n\n/**\n * A configured mapping that resolved to nothing skips its call: a declared\n * skip, said once at DEBUG with the event and the mapping key, never the\n * value, so a wrong mapping path does not look like an event without data.\n */\nfunction skipped(\n logger: Logger.Instance,\n event: WalkerOS.Event,\n call: string,\n key: string,\n): void {\n logger.debug(`PostHog skipped ${call}: ${key} resolved to nothing`, {\n event: event.name,\n });\n}\n\n/** Run one queueing call; an injected client may answer with a promise. */\nasync function queue(message: string, send: () => unknown): Promise<void> {\n try {\n await send();\n } catch (error) {\n throw new StepError(message, { code: 'transport', cause: error });\n }\n}\n\n/**\n * One send at a time per client: its calls queued, then one flush. A flush\n * sends the whole queue, so a send that overlapped another could be carried,\n * and failed, by the other's request without hearing of it.\n */\nfunction exclusive(\n settings: Partial<Settings>,\n task: () => Promise<void>,\n): Promise<void> {\n const running = (settings._sending ?? Promise.resolve()).then(task);\n settings._sending = running.catch(() => undefined);\n return running;\n}\n\n/** The settings and client init resolved, or a StepError. */\nfunction clientOf(settings: Partial<Settings> | undefined): {\n settings: Partial<Settings>;\n client: PostHogClient;\n} {\n const client = settings?.client;\n if (!settings || !client)\n throw new StepError('PostHog client not initialized', {\n code: 'not-ready',\n });\n return { settings, client };\n}\n\n/** One event: its calls queued and sent by one flush. */\nexport const push: PushFn = async function (\n event,\n { config, rule, data, collector, logger },\n) {\n const { settings, client } = clientOf(config.settings);\n await exclusive(settings, async () => {\n await send(event, rule, data, settings, client, collector, logger);\n await call(client, 'PostHog send failed', () => client.flush());\n });\n};\n\n/**\n * A flushed `config.batch` batch: every entry's calls queued, then one flush\n * sends them. An entry whose calls could not be queued fails alone; a failed\n * flush fails the batch, since PostHog answers a request as a whole.\n */\nexport const pushBatch: PushBatchFn = async function (\n batch,\n { config, collector, logger },\n) {\n const { settings, client } = clientOf(config.settings);\n const failed: Destination.BatchFailure[] = [];\n let sendError: unknown;\n\n await exclusive(settings, async () => {\n const queued: number[] = [];\n for (const [index, entry] of batch.entries.entries())\n await send(\n entry.event,\n entry.rule,\n entry.data,\n settings,\n client,\n collector,\n logger,\n ).then(\n () => queued.push(index),\n (error: unknown) => failed.push({ index, error }),\n );\n\n // One request carries every queued entry: a failed flush fails them all.\n if (queued.length)\n await call(client, 'PostHog send failed', () => client.flush()).catch(\n (error: unknown) => {\n sendError = error;\n for (const index of queued) failed.push({ index, error });\n },\n );\n });\n\n return batchOutcome(batch.entries.length, failed, sendError);\n};\n\n/** The calls of one event (identify, group identify, capture). */\nasync function send(\n event: WalkerOS.Event,\n rule: Rule | undefined,\n data: Destination.Data,\n settings: Partial<Settings>,\n client: PostHogClient,\n collector: Collector.Instance,\n logger: Logger.Instance,\n): Promise<void> {\n const mappingSettings = (rule?.settings || {}) as Record<string, unknown>;\n\n // Resolve distinctId: rule-level identify wins over destination-level\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n let distinctId: string | undefined;\n let identifyResolved: Record<string, unknown> | undefined;\n\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n identifyResolved = resolved as Record<string, unknown>;\n if (isString(identifyResolved.distinctId)) {\n distinctId = identifyResolved.distinctId as string;\n }\n } else skipped(logger, event, 'identify', 'identify');\n }\n\n // Fallback distinctId from event.user\n if (!distinctId) {\n distinctId =\n (isString(event.user?.id) ? event.user.id : undefined) ||\n (isString(event.user?.hash) ? event.user.hash : undefined) ||\n (isString(event.user?.session) ? event.user.session : undefined) ||\n 'anonymous';\n }\n\n // 1. Identity - if $set or $set_once present, call client.identify()\n if (identifyResolved) {\n const $set = isObject(identifyResolved.$set)\n ? (identifyResolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(identifyResolved.$set_once)\n ? (identifyResolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if ($set || $setOnce) {\n const properties: Record<string, unknown> = {};\n if ($set) properties.$set = $set;\n if ($setOnce) properties.$set_once = $setOnce;\n await queue('PostHog identify failed', () =>\n client.identify({ distinctId, properties }),\n );\n }\n }\n\n // 2. Group - resolve group mapping (rule-level wins)\n const groupMapping = mappingSettings.group ?? settings.group;\n let groups: Record<string, string | number> | undefined;\n\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n const groupResolved = resolved as Record<string, unknown>;\n const type = groupResolved.type;\n const key = groupResolved.key;\n const properties = isObject(groupResolved.properties)\n ? (groupResolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && (isString(key) || typeof key === 'number')) {\n // If properties present, call groupIdentify\n // No immediate variant: queued, then flushed in this push.\n if (properties)\n await queue('PostHog group identify failed', () =>\n client.groupIdentify({\n groupType: type,\n groupKey: String(key),\n properties,\n }),\n );\n // Build groups object for capture\n groups = { [type]: key as string | number };\n } else skipped(logger, event, 'group', 'group');\n } else skipped(logger, event, 'group', 'group');\n }\n\n // 3. Capture - unless rule opts out via silent\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data) ? (data as Record<string, unknown>) : {};\n\n const captureArgs: Parameters<PostHogClient['capture']>[0] = {\n distinctId,\n event: eventName,\n properties,\n };\n if (groups) captureArgs.groups = groups;\n if (event.id) captureArgs.uuid = uuidOf(event.id);\n\n await queue('PostHog capture failed', () => client.capture(captureArgs));\n }\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer } from '@walkeros/server-core';\nimport type { PostHog } from 'posthog-node';\n\nexport interface Settings {\n /** PostHog project API key (phc_...) */\n apiKey: string;\n /** PostHog client instance, populated by init */\n client?: PostHogClient;\n /** Destination-level identity mapping */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group mapping */\n group?: WalkerOSMapping.Value;\n // PostHog SDK passthrough options\n host?: string;\n flushAt?: number;\n flushInterval?: number;\n personalApiKey?: string;\n featureFlagsPollingInterval?: number;\n disableGeoip?: boolean;\n disableCompression?: boolean;\n requestTimeout?: number;\n fetchRetryCount?: number;\n fetchRetryDelay?: number;\n debug?: boolean;\n disabled?: boolean;\n /** The running send; the next one waits for it. Runtime only. */\n _sending?: Promise<void>;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n}\n\n/**\n * The part of a PostHog client this destination calls. `PostHog` from\n * `posthog-node` satisfies it, and so does an injected mock (tests, simulate)\n * without a cast.\n */\nexport interface PostHogClient {\n capture(props: Parameters<PostHog['capture']>[0]): void;\n identify(props: Parameters<PostHog['identify']>[0]): void;\n groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;\n /** Sends the queued calls; rejects when the request failed. */\n flush(): Promise<void>;\n /** The SDK reports a failed send as an `error` event; returns its remover. */\n on?(event: 'error', listener: (error: unknown) => void): () => void;\n shutdown(): Promise<void> | void;\n enable(): Promise<void> | void;\n disable(): Promise<void> | void;\n}\n\nexport interface Env extends DestinationServer.Env {\n PostHog?: new (\n apiKey: string,\n options?: ConstructorParameters<typeof PostHog>[1],\n ) => PostHogClient;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\nexport type PushBatchFn = CoreDestination.PushBatchFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n","import type { WalkerOS } from '@walkeros/core';\nimport type { Destination, Env, Settings } from './types';\nimport { getConfig } from './config';\nimport { push, pushBatch } from './push';\n\n// Types\nexport * as DestinationPostHog from './types';\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n // Batched by default, at the SDK's own former defaults (20 events, 10 s).\n config: { batch: { size: 20, wait: 10_000 } },\n\n async init({ config: partialConfig, env }) {\n return getConfig(partialConfig, env);\n },\n\n push,\n\n pushBatch,\n\n async destroy({ config }) {\n const client = config?.settings?.client;\n if (client) {\n await client.shutdown();\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n\n const settings = (context.config?.settings || {}) as Settings;\n const client = settings.client;\n if (!client) return;\n\n const consent = context.data as WalkerOS.Consent;\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n client.enable();\n } else {\n client.disable();\n }\n },\n};\n\nexport default destinationPostHog;\n"],"mappings":";;;AACA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AAEjB,SAAS,UACd,gBAA+B,CAAC,GAChC,KACQ;AACR,QAAM,WAA8B,cAAc,YAAY,CAAC;AAC/D,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI,CAAC;AACH,UAAM,IAAI,UAAU,kCAAkC,EAAE,MAAM,SAAS,CAAC;AAK1E,QAAM,SAAS,YAAY,cAAc,OAAO;AAChD,QAAM,UAAmC;AAAA,IACvC,gBAAgB,OAAO;AAAA,IACvB,iBAAiB,OAAO;AAAA,IACxB,iBAAiB,OAAO;AAAA,EAC1B;AAGA,MAAI,SAAS,KAAM,SAAQ,OAAO,SAAS;AAC3C,MAAI,SAAS,YAAY,OAAW,SAAQ,UAAU,SAAS;AAC/D,MAAI,SAAS,kBAAkB;AAC7B,YAAQ,gBAAgB,SAAS;AACnC,MAAI,SAAS,eAAgB,SAAQ,iBAAiB,SA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Q;AACxB,UAAM,WAAY,QAAQ,QACtB;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,aAAO,OAAO;AAAA,IAChB,OAAO;AACL,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["StepError","send","call"]}
|
package/dist/walkerOS.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$meta": {
|
|
3
3
|
"package": "@walkeros/server-destination-posthog",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.3-next-1793115089237",
|
|
5
5
|
"type": "destination",
|
|
6
6
|
"platform": [
|
|
7
7
|
"server"
|
|
@@ -39,40 +39,53 @@
|
|
|
39
39
|
},
|
|
40
40
|
"flushAt": {
|
|
41
41
|
"type": "number",
|
|
42
|
-
"description": "
|
|
42
|
+
"description": "Calls the SDK queues before it starts a send on its own. Each push and each config.batch batch flushes the SDK and waits for the answer either way. Default: 20."
|
|
43
43
|
},
|
|
44
44
|
"flushInterval": {
|
|
45
45
|
"type": "number",
|
|
46
|
-
"description": "Milliseconds
|
|
46
|
+
"description": "Milliseconds after which the SDK sends calls still queued on its own. Each push and each config.batch batch flushes the SDK either way. Default: 10000."
|
|
47
47
|
},
|
|
48
48
|
"personalApiKey": {
|
|
49
49
|
"type": "string",
|
|
50
|
-
"description": "Personal API key (phx_...)
|
|
50
|
+
"description": "Personal API key (phx_...). With it the SDK polls feature flag definitions; this destination evaluates no flags and attaches none to its events."
|
|
51
51
|
},
|
|
52
52
|
"featureFlagsPollingInterval": {
|
|
53
53
|
"type": "number",
|
|
54
|
-
"description": "Milliseconds between feature flag definition polls. Default: 30000."
|
|
54
|
+
"description": "Milliseconds between feature flag definition polls, with personalApiKey set. This destination evaluates no flags. Default: 30000."
|
|
55
55
|
},
|
|
56
56
|
"disableGeoip": {
|
|
57
57
|
"type": "boolean",
|
|
58
|
-
"description": "Disable GeoIP lookups
|
|
58
|
+
"description": "Disable GeoIP lookups for every event. Default: true, the SDK default."
|
|
59
|
+
},
|
|
60
|
+
"disableCompression": {
|
|
61
|
+
"type": "boolean",
|
|
62
|
+
"description": "Send requests uncompressed (no gzip). Default: false."
|
|
63
|
+
},
|
|
64
|
+
"requestTimeout": {
|
|
65
|
+
"type": "number",
|
|
66
|
+
"description": "Milliseconds before a request to PostHog times out. Default: a quarter of config.timeout (2500 at the 10 s default). A value set here wins."
|
|
67
|
+
},
|
|
68
|
+
"fetchRetryCount": {
|
|
69
|
+
"type": "number",
|
|
70
|
+
"description": "Retries of a failed request to PostHog. Default: 2, which with the default timeout and delay ends within config.timeout. A value set here wins."
|
|
71
|
+
},
|
|
72
|
+
"fetchRetryDelay": {
|
|
73
|
+
"type": "number",
|
|
74
|
+
"description": "Milliseconds between retries of a failed request. Default: a tenth of config.timeout (1000 at the 10 s default). A value set here wins."
|
|
59
75
|
},
|
|
60
76
|
"debug": {
|
|
61
77
|
"type": "boolean",
|
|
62
78
|
"description": "Enable PostHog SDK debug logging. Default: false."
|
|
63
79
|
},
|
|
80
|
+
"disabled": {
|
|
81
|
+
"type": "boolean",
|
|
82
|
+
"description": "Disable the PostHog client: nothing is sent. Default: false."
|
|
83
|
+
},
|
|
64
84
|
"identify": {
|
|
65
85
|
"description": "walkerOS mapping value resolving to an identity object. Keys: distinctId, $set, $set_once. Resolved on every push (server is stateless)."
|
|
66
86
|
},
|
|
67
87
|
"group": {
|
|
68
88
|
"description": "walkerOS mapping value resolving to a group object. Keys: type, key, properties. Resolved on every push."
|
|
69
|
-
},
|
|
70
|
-
"include": {
|
|
71
|
-
"type": "array",
|
|
72
|
-
"items": {
|
|
73
|
-
"type": "string"
|
|
74
|
-
},
|
|
75
|
-
"description": "Event sections to flatten into capture() properties (e.g. [\"data\", \"globals\"])."
|
|
76
89
|
}
|
|
77
90
|
},
|
|
78
91
|
"required": [
|
|
@@ -95,10 +108,18 @@
|
|
|
95
108
|
"call:PostHog.shutdown"
|
|
96
109
|
]
|
|
97
110
|
},
|
|
111
|
+
"minimal": {
|
|
112
|
+
"settings": {
|
|
113
|
+
"apiKey": "phc_test"
|
|
114
|
+
},
|
|
115
|
+
"secrets": {
|
|
116
|
+
"apiKey": "POSTHOG_API_KEY"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
98
119
|
"step": {
|
|
99
120
|
"captureWithGroupContext": {
|
|
100
121
|
"title": "Capture with group",
|
|
101
|
-
"description": "
|
|
122
|
+
"description": "With settings.group mapping type to 'company' and key to 'globals.company_id', every PostHog capture call carries the resolved group.",
|
|
102
123
|
"in": {
|
|
103
124
|
"name": "page view",
|
|
104
125
|
"data": {
|
|
@@ -138,7 +159,7 @@
|
|
|
138
159
|
"consent": {
|
|
139
160
|
"functional": true
|
|
140
161
|
},
|
|
141
|
-
"id": "
|
|
162
|
+
"id": "ev1700000104",
|
|
142
163
|
"trigger": "load",
|
|
143
164
|
"entity": "page",
|
|
144
165
|
"action": "view",
|
|
@@ -165,6 +186,7 @@
|
|
|
165
186
|
[
|
|
166
187
|
"client.capture",
|
|
167
188
|
{
|
|
189
|
+
"uuid": "c6a47305-44fc-8835-b15f-3f494c1f9e20",
|
|
168
190
|
"distinctId": "us3r",
|
|
169
191
|
"event": "page view",
|
|
170
192
|
"properties": {},
|
|
@@ -177,15 +199,16 @@
|
|
|
177
199
|
},
|
|
178
200
|
"captureWithInclude": {
|
|
179
201
|
"title": "Capture with include",
|
|
180
|
-
"description": "
|
|
202
|
+
"description": "With include: ['data', 'globals'] in the destination config, the data and globals sections are flattened into prefixed PostHog event properties.",
|
|
181
203
|
"in": {
|
|
182
204
|
"name": "order complete",
|
|
183
205
|
"data": {
|
|
184
206
|
"id": "0rd3r1d",
|
|
185
207
|
"currency": "EUR",
|
|
208
|
+
"value": 462,
|
|
209
|
+
"tax": 73.76,
|
|
186
210
|
"shipping": 5.22,
|
|
187
|
-
"
|
|
188
|
-
"total": 555
|
|
211
|
+
"total": 467.22
|
|
189
212
|
},
|
|
190
213
|
"context": {
|
|
191
214
|
"shopping": [
|
|
@@ -255,7 +278,7 @@
|
|
|
255
278
|
"consent": {
|
|
256
279
|
"functional": true
|
|
257
280
|
},
|
|
258
|
-
"id": "
|
|
281
|
+
"id": "ev1700000101",
|
|
259
282
|
"trigger": "load",
|
|
260
283
|
"entity": "order",
|
|
261
284
|
"action": "complete",
|
|
@@ -276,14 +299,16 @@
|
|
|
276
299
|
[
|
|
277
300
|
"client.capture",
|
|
278
301
|
{
|
|
302
|
+
"uuid": "a5a5ede9-4f3b-85f4-b30f-3da8773fabfa",
|
|
279
303
|
"distinctId": "us3r",
|
|
280
304
|
"event": "order complete",
|
|
281
305
|
"properties": {
|
|
282
306
|
"data_id": "0rd3r1d",
|
|
283
307
|
"data_currency": "EUR",
|
|
308
|
+
"data_value": 462,
|
|
309
|
+
"data_tax": 73.76,
|
|
284
310
|
"data_shipping": 5.22,
|
|
285
|
-
"
|
|
286
|
-
"data_total": 555,
|
|
311
|
+
"data_total": 467.22,
|
|
287
312
|
"globals_pagegroup": "shop"
|
|
288
313
|
}
|
|
289
314
|
}
|
|
@@ -292,7 +317,7 @@
|
|
|
292
317
|
},
|
|
293
318
|
"consentGrant": {
|
|
294
319
|
"title": "Consent granted",
|
|
295
|
-
"description": "
|
|
320
|
+
"description": "With consent: { analytics: true } in the destination config, a walker consent command that grants analytics calls client.enable on the PostHog client.",
|
|
296
321
|
"command": "consent",
|
|
297
322
|
"in": {
|
|
298
323
|
"analytics": true
|
|
@@ -306,7 +331,7 @@
|
|
|
306
331
|
},
|
|
307
332
|
"consentRevoke": {
|
|
308
333
|
"title": "Consent revoked",
|
|
309
|
-
"description": "
|
|
334
|
+
"description": "With consent: { analytics: true } in the destination config, revoking analytics consent after a grant calls client.disable on the PostHog client.",
|
|
310
335
|
"command": "consent",
|
|
311
336
|
"before": {
|
|
312
337
|
"analytics": true
|
|
@@ -334,7 +359,8 @@
|
|
|
334
359
|
"name": "Everyday Ruck Snack",
|
|
335
360
|
"color": "black",
|
|
336
361
|
"size": "l",
|
|
337
|
-
"price": 420
|
|
362
|
+
"price": 420,
|
|
363
|
+
"currency": "EUR"
|
|
338
364
|
},
|
|
339
365
|
"context": {
|
|
340
366
|
"shopping": [
|
|
@@ -357,7 +383,7 @@
|
|
|
357
383
|
"consent": {
|
|
358
384
|
"functional": true
|
|
359
385
|
},
|
|
360
|
-
"id": "
|
|
386
|
+
"id": "ev1700000100",
|
|
361
387
|
"trigger": "load",
|
|
362
388
|
"entity": "product",
|
|
363
389
|
"action": "view",
|
|
@@ -374,6 +400,7 @@
|
|
|
374
400
|
[
|
|
375
401
|
"client.capture",
|
|
376
402
|
{
|
|
403
|
+
"uuid": "b8a7f21f-1a9f-8aa7-8480-8d16fb64c44c",
|
|
377
404
|
"distinctId": "us3r",
|
|
378
405
|
"event": "product view",
|
|
379
406
|
"properties": {}
|
|
@@ -419,7 +446,7 @@
|
|
|
419
446
|
"consent": {
|
|
420
447
|
"functional": true
|
|
421
448
|
},
|
|
422
|
-
"id": "
|
|
449
|
+
"id": "5c84e91c1240ebcc",
|
|
423
450
|
"trigger": "test",
|
|
424
451
|
"entity": "company",
|
|
425
452
|
"action": "update",
|
|
@@ -465,6 +492,36 @@
|
|
|
465
492
|
]
|
|
466
493
|
]
|
|
467
494
|
},
|
|
495
|
+
"groupIdentifyWithoutData": {
|
|
496
|
+
"public": false,
|
|
497
|
+
"description": "A silent group rule whose key finds no data sends nothing: an unmet mapping, not a failure, so the push returns normally.",
|
|
498
|
+
"in": {
|
|
499
|
+
"name": "company update",
|
|
500
|
+
"entity": "company",
|
|
501
|
+
"action": "update",
|
|
502
|
+
"timestamp": 1700000106
|
|
503
|
+
},
|
|
504
|
+
"mapping": {
|
|
505
|
+
"silent": true,
|
|
506
|
+
"settings": {
|
|
507
|
+
"group": {
|
|
508
|
+
"map": {
|
|
509
|
+
"type": {
|
|
510
|
+
"value": "company"
|
|
511
|
+
},
|
|
512
|
+
"key": "data.company_id",
|
|
513
|
+
"properties": {
|
|
514
|
+
"map": {
|
|
515
|
+
"name": "data.company_name",
|
|
516
|
+
"plan": "data.plan"
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
"out": []
|
|
524
|
+
},
|
|
468
525
|
"identifyWithSetAndSetOnce": {
|
|
469
526
|
"title": "Identify with $set",
|
|
470
527
|
"description": "A user login fires PostHog identify with $set and $set_once person properties and skips the capture.",
|
|
@@ -503,11 +560,11 @@
|
|
|
503
560
|
"consent": {
|
|
504
561
|
"functional": true
|
|
505
562
|
},
|
|
506
|
-
"id": "
|
|
563
|
+
"id": "bd6d22ce162a32e8",
|
|
507
564
|
"trigger": "test",
|
|
508
565
|
"entity": "user",
|
|
509
566
|
"action": "login",
|
|
510
|
-
"timestamp":
|
|
567
|
+
"timestamp": 1700000102000,
|
|
511
568
|
"timing": 3.14,
|
|
512
569
|
"source": {
|
|
513
570
|
"count": 1,
|
|
@@ -548,12 +605,71 @@
|
|
|
548
605
|
"plan": "premium"
|
|
549
606
|
},
|
|
550
607
|
"$set_once": {
|
|
551
|
-
"first_login":
|
|
608
|
+
"first_login": 1700000102000
|
|
552
609
|
}
|
|
553
610
|
}
|
|
554
611
|
}
|
|
555
612
|
]
|
|
556
613
|
]
|
|
614
|
+
},
|
|
615
|
+
"silentRule": {
|
|
616
|
+
"public": false,
|
|
617
|
+
"description": "A rule with silent: true and no identify or group mapping sends nothing to PostHog.",
|
|
618
|
+
"in": {
|
|
619
|
+
"name": "page view",
|
|
620
|
+
"data": {
|
|
621
|
+
"domain": "www.example.com",
|
|
622
|
+
"title": "walkerOS documentation",
|
|
623
|
+
"referrer": "https://www.walkeros.io/",
|
|
624
|
+
"search": "?foo=bar",
|
|
625
|
+
"hash": "#hash",
|
|
626
|
+
"id": "/docs/"
|
|
627
|
+
},
|
|
628
|
+
"context": {
|
|
629
|
+
"dev": [
|
|
630
|
+
"test",
|
|
631
|
+
1
|
|
632
|
+
]
|
|
633
|
+
},
|
|
634
|
+
"globals": {
|
|
635
|
+
"pagegroup": "docs"
|
|
636
|
+
},
|
|
637
|
+
"custom": {
|
|
638
|
+
"completely": "random"
|
|
639
|
+
},
|
|
640
|
+
"user": {
|
|
641
|
+
"id": "us3r",
|
|
642
|
+
"device": "c00k13",
|
|
643
|
+
"session": "s3ss10n"
|
|
644
|
+
},
|
|
645
|
+
"nested": [
|
|
646
|
+
{
|
|
647
|
+
"entity": "child",
|
|
648
|
+
"data": {
|
|
649
|
+
"is": "subordinated"
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
],
|
|
653
|
+
"consent": {
|
|
654
|
+
"functional": true
|
|
655
|
+
},
|
|
656
|
+
"id": "f0cc5f6fec3d8eeb",
|
|
657
|
+
"trigger": "load",
|
|
658
|
+
"entity": "page",
|
|
659
|
+
"action": "view",
|
|
660
|
+
"timestamp": 1700000105,
|
|
661
|
+
"timing": 3.14,
|
|
662
|
+
"source": {
|
|
663
|
+
"count": 1,
|
|
664
|
+
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
|
|
665
|
+
"type": "collector",
|
|
666
|
+
"schema": "4"
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
"mapping": {
|
|
670
|
+
"silent": true
|
|
671
|
+
},
|
|
672
|
+
"out": []
|
|
557
673
|
}
|
|
558
674
|
}
|
|
559
675
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-destination-posthog",
|
|
3
3
|
"description": "PostHog server destination for walkerOS",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.3-next-1793115089237",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"update": "npx npm-check-updates -u && npm update"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@walkeros/core": "4.8.
|
|
39
|
-
"@walkeros/server-core": "4.8.
|
|
38
|
+
"@walkeros/core": "4.8.3-next-1793115089237",
|
|
39
|
+
"@walkeros/server-core": "4.8.3-next-1793115089237",
|
|
40
40
|
"posthog-node": "^5.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@walkeros/collector": "4.8.
|
|
43
|
+
"@walkeros/collector": "4.8.3-next-1793115089237"
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"url": "git+https://github.com/elbwalker/walkerOS.git",
|