UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

102 lines (101 loc) 4.81 kB
import type { PickByPrefix } from '../common/ts/pick-by-prefix.js'; import type { AnyJson } from '../../private/common/json.js'; import type { MonorailEventPublic } from './monorail.js'; type ProvideMetadata<T> = () => Partial<T> | Promise<Partial<T>>; type MetadataErrorHandling = 'auto' | 'mute-and-report' | 'bubble'; /** * Any key in T that has a numeric value. */ type NumericKeyOf<T> = { [K in keyof T]: T[K] extends number ? (K extends string ? K : never) : never; }[keyof T]; export interface RuntimeMetadataManager<TPublic extends AnyJson, TSensitive extends AnyJson> { /** Add some public metadata -- this should not contain any PII. */ addPublicMetadata: (getData: ProvideMetadata<TPublic>, onError?: MetadataErrorHandling) => Promise<void>; /** * Add some potentially sensitive metadata -- this may include PII, but unnecessary data should never be tracked * (this is a good fit for command args for instance). */ addSensitiveMetadata: (getData: ProvideMetadata<TSensitive>, onError?: MetadataErrorHandling) => Promise<void>; /** Get a snapshot of the tracked public data. */ getAllPublicMetadata: () => Partial<TPublic>; /** Get a snapshot of the tracked sensitive data. */ getAllSensitiveMetadata: () => Partial<TSensitive>; /** Run a function, monitoring how long it takes, and adding the elapsed time to a running total. */ runWithTimer: (field: NumericKeyOf<TPublic>) => <T>(fn: () => Promise<T>) => Promise<T>; } export type PublicSchema<T> = T extends RuntimeMetadataManager<infer TPublic, infer _TSensitive> ? TPublic : never; export type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer _TPublic, infer TSensitive> ? TSensitive : never; /** * Creates a container for metadata collected at runtime. * The container provides async-safe functions for extracting the gathered metadata, and for setting it. * * @param defaultPublicMetadata - Optional, default data for the container. * @returns A container for the metadata. */ export declare function createRuntimeMetadataContainer<TPublic extends AnyJson, TSensitive extends AnyJson = { [key: string]: never; }>(defaultPublicMetadata?: Partial<TPublic>): RuntimeMetadataManager<TPublic, TSensitive>; type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_theme_'> & PickByPrefix<MonorailEventPublic, 'store_'>; declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, { commandStartOptions: { startTime: number; startCommand: string; startTopic?: string; startArgs: string[]; }; } & { environmentFlags: string; } & PickByPrefix<{ args: string; error_message?: string | null; app_name?: string | null; metadata?: string | null; store_fqdn?: string | null; cmd_all_environment_flags?: string | null; cmd_dev_tunnel_custom?: string | null; env_plugin_installed_all?: string | null; env_shopify_variables?: string | null; }, "store_", never>>; export declare const getAllPublicMetadata: () => Partial<CmdFieldsFromMonorail>, getAllSensitiveMetadata: () => Partial<{ commandStartOptions: { startTime: number; startCommand: string; startTopic?: string; startArgs: string[]; }; } & { environmentFlags: string; } & PickByPrefix<{ args: string; error_message?: string | null; app_name?: string | null; metadata?: string | null; store_fqdn?: string | null; cmd_all_environment_flags?: string | null; cmd_dev_tunnel_custom?: string | null; env_plugin_installed_all?: string | null; env_shopify_variables?: string | null; }, "store_", never>>, addPublicMetadata: (getData: ProvideMetadata<CmdFieldsFromMonorail>, onError?: MetadataErrorHandling) => Promise<void>, addSensitiveMetadata: (getData: ProvideMetadata<{ commandStartOptions: { startTime: number; startCommand: string; startTopic?: string; startArgs: string[]; }; } & { environmentFlags: string; } & PickByPrefix<{ args: string; error_message?: string | null; app_name?: string | null; metadata?: string | null; store_fqdn?: string | null; cmd_all_environment_flags?: string | null; cmd_dev_tunnel_custom?: string | null; env_plugin_installed_all?: string | null; env_shopify_variables?: string | null; }, "store_", never>>, onError?: MetadataErrorHandling) => Promise<void>, runWithTimer: (field: NumericKeyOf<CmdFieldsFromMonorail>) => <T>(fn: () => Promise<T>) => Promise<T>; export type Public = PublicSchema<typeof coreData>; export type Sensitive = SensitiveSchema<typeof coreData>; export {};