{"version":3,"sources":["../src/internal/actions/setRawState.ts","../src/internal/types/suggestedActions.ts","../src/internal/types/suggestedActionsOriginActivity.ts","../../core-debug-api/src/private/DebugAPI.ts","../../core-debug-api/src/RestrictedDebugAPI.ts","../src/types/StoreDebugAPI.ts","../src/internal/StoreDebugAPIRegistry.ts"],"sourcesContent":["import { literal, object, pipe, readonly, union, type InferOutput } from 'valibot';\n\nimport { suggestedActionsStateSchema } from '../types/suggestedActions';\nimport { suggestedActionsOriginActivityStateSchema } from '../types/suggestedActionsOriginActivity';\n\nconst SET_RAW_STATE = 'WEB_CHAT_INTERNAL/SET_RAW_STATE' as const;\n\nconst setRawStateActionSchema = pipe(\n  object({\n    payload: union([\n      pipe(\n        object({\n          name: literal('suggestedActions'),\n          state: suggestedActionsStateSchema\n        }),\n        readonly()\n      ),\n      pipe(\n        object({\n          name: literal('suggestedActionsOriginActivity'),\n          state: suggestedActionsOriginActivityStateSchema\n        }),\n        readonly()\n      )\n    ]),\n    type: literal(SET_RAW_STATE)\n  }),\n  readonly()\n);\n\ntype SetRawStateAction = InferOutput<typeof setRawStateActionSchema>;\n\n// Due to limitation of TypeScript, we need to specify overloading functions.\nexport default function setRawState(\n  name: 'suggestedActions',\n  state: (SetRawStateAction['payload'] & { name: typeof name })['state']\n): SetRawStateAction;\n\nexport default function setRawState(\n  name: 'suggestedActionsOriginActivity',\n  state: (SetRawStateAction['payload'] & { name: typeof name })['state']\n): SetRawStateAction;\n\nexport default function setRawState(name: SetRawStateAction['payload']['name'], state: any): SetRawStateAction {\n  return { payload: { name, state }, type: SET_RAW_STATE };\n}\n\nexport { SET_RAW_STATE, setRawStateActionSchema, type SetRawStateAction };\n","import { array, custom, pipe, readonly, type InferOutput } from 'valibot';\n\n// TODO: Resolve possibly cyclic dependency by moving `types` into a separate package.\n// import { type DirectLineCardAction } from '../../types/external/DirectLineCardAction';\n\n// const suggestedActionsStateSchema = pipe(array(custom<DirectLineCardAction>(() => true)), readonly());\nconst suggestedActionsStateSchema = pipe(array(custom<any>(() => true)), readonly());\n\ntype SuggestedActionsState = InferOutput<typeof suggestedActionsStateSchema>;\n\nexport { suggestedActionsStateSchema, type SuggestedActionsState };\n","import { custom, object, pipe, readonly, undefinedable, type InferOutput } from 'valibot';\n\n// TODO: Resolve possibly cyclic dependency by moving `types` into a separate package.\n// import { type WebChatActivity } from '../../types/WebChatActivity';\n\nconst suggestedActionsOriginActivityStateSchema = pipe(\n  object({\n    // activity: undefinedable(custom<WebChatActivity>(() => true))\n    activity: undefinedable(custom<any>(() => true))\n  }),\n  readonly()\n);\n\ntype SuggestedActionsOriginActivityState = InferOutput<typeof suggestedActionsOriginActivityStateSchema>;\n\nexport { suggestedActionsOriginActivityStateSchema, type SuggestedActionsOriginActivityState };\n","import type { BreakpointObject, DebugAPIType } from '../types';\n\nclass DebugAPI<TBreakpointName extends string, TContext extends object> implements DebugAPIType<\n  TBreakpointName,\n  TContext\n> {\n  constructor(breakpoint: BreakpointObject<TBreakpointName, TContext>, context: TContext) {\n    this.#breakpoint = breakpoint;\n    this.#context = context;\n\n    Object.freeze(this);\n  }\n\n  #breakpoint: BreakpointObject<TBreakpointName, TContext>;\n  #context: TContext;\n\n  get breakpoint() {\n    return this.#breakpoint;\n  }\n\n  get debugger() {\n    // @ts-expect-error Unused variable for debugging.\n    const __DEBUG_CONTEXT__ = this.#context;\n\n    // eslint-disable-next-line no-debugger\n    debugger;\n\n    return undefined;\n  }\n}\n\nexport default DebugAPI;\n","import { SHOULD_LOCKDOWN } from './private/constants';\nimport DebugAPI from './private/DebugAPI';\nimport type { BaseContext, BreakpointObject, RestrictedDebugAPIType } from './types';\n\n// 🔒 This function must be left empty.\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nconst BREAKPOINT_FUNCTION = <T>(__DEBUG_CONTEXT__: T) => {};\n\ntype AsGetters<T> = {\n  readonly [K in keyof T]: () => T[K];\n};\n\nabstract class RestrictedDebugAPI<\n  TBreakpointName extends string,\n  TContext extends BaseContext\n> implements RestrictedDebugAPIType<TBreakpointName, TContext> {\n  constructor(breakpointNames: readonly TBreakpointName[], contextGetters: AsGetters<TContext>) {\n    this.#context = Object.create(null) satisfies Partial<TContext> as TContext;\n\n    for (const [name, getter] of Object.entries(contextGetters)) {\n      Object.defineProperty(this.#context, name, {\n        configurable: false,\n        enumerable: true,\n        get() {\n          return getter();\n        }\n      });\n    }\n\n    const breakpoint = Object.create(null) as Record<\n      TBreakpointName,\n      (__DEBUG_CONTEXT__: TContext, ...args: any[]) => void\n    >;\n    const UNSAFE_callBreakpoint = Object.create(null) as Record<TBreakpointName, (...args: any[]) => void>;\n\n    // Design of lockdown:\n    // - Modifying `this.breakpoint` object will not trick our `this.UNSAFE_callBreakpoint()` to trigger the new code path\n    // - No JS code should know if a function is being called or not, except the engine/debugger\n    // - Thus, breakpoint functions cannot be spied from another JS code\n\n    // 🔒 We must make sure JS code cannot intercept the call to any breakpoint functions.\n\n    // TODO: [P1] Lockdown cannot be tested automatically. Any code changed below must be tested manually.\n    //       How to test manually: set `SHOULD_LOCKDOWN = true`, run the same test, it should fail with:\n    //       \"Cannot assign to read only property 'incomingActivity' of object '#<Object>'\"\n    for (const name of breakpointNames) {\n      // breakpoint is created by Object.create(null).\n      // eslint-disable-next-line security/detect-object-injection\n      breakpoint[name] = BREAKPOINT_FUNCTION.bind(this);\n\n      // UNSAFE_callBreakpoint is created by Object.create(null).\n      // eslint-disable-next-line security/detect-object-injection\n      UNSAFE_callBreakpoint[name] = SHOULD_LOCKDOWN\n        ? // breakpoint is created by Object.create(null).\n          // eslint-disable-next-line security/detect-object-injection\n          breakpoint[name].bind(this, { ...this.#context })\n        : (...args: any[]) =>\n            // breakpoint is created by Object.create(null).\n            // eslint-disable-next-line security/detect-object-injection\n            breakpoint[name]({ ...this.#context }, ...args);\n    }\n\n    this.#breakpoint = breakpoint;\n    this.UNSAFE_callBreakpoint = Object.freeze(UNSAFE_callBreakpoint);\n\n    if (SHOULD_LOCKDOWN) {\n      Object.freeze(breakpoint);\n      Object.freeze(this);\n    }\n  }\n\n  #breakpoint: BreakpointObject<TBreakpointName, TContext>;\n  #context: TContext;\n\n  toPublic() {\n    return new DebugAPI(this.#breakpoint, this.#context);\n  }\n\n  UNSAFE_callBreakpoint: Readonly<Record<TBreakpointName, (...args: any[]) => void>>;\n\n  // eslint-disable-next-line class-methods-use-this\n  get '~types'() {\n    return Object.freeze({ public: undefined as any });\n  }\n}\n\nexport default RestrictedDebugAPI;\n","import { RestrictedDebugAPI, type InferPublic } from '@msinternal/botframework-webchat-core-debug-api';\nimport type { ArrayElement } from 'type-fest';\n\nconst BREAKPOINT_NAMES = ['incomingActivity'] as const;\n\ntype StoreBreakpointName = ArrayElement<typeof BREAKPOINT_NAMES>;\n\ntype StoreDebugContext = {\n  readonly activities: readonly any[];\n};\n\nclass RestrictedStoreDebugAPI extends RestrictedDebugAPI<StoreBreakpointName, StoreDebugContext> {\n  constructor(getActivities: () => StoreDebugContext['activities']) {\n    super(\n      BREAKPOINT_NAMES,\n      Object.freeze({\n        activities: getActivities\n      })\n    );\n  }\n}\n\ntype StoreDebugAPI = InferPublic<RestrictedStoreDebugAPI>;\n\nexport { RestrictedStoreDebugAPI, type StoreDebugAPI };\n","import type createStore from '../createStore';\nimport type { StoreDebugAPI } from '../types/StoreDebugAPI';\n\nexport default new WeakMap<ReturnType<typeof createStore>, StoreDebugAPI>();\n"],"mappings":"AAAA,OAAS,WAAAA,EAAS,UAAAC,EAAQ,QAAAC,EAAM,YAAAC,EAAU,SAAAC,MAA+B,UCAzE,OAAS,SAAAC,EAAO,UAAAC,EAAQ,QAAAC,EAAM,YAAAC,MAAkC,UAMhE,IAAMC,EAA8BF,EAAKF,EAAMC,EAAY,IAAM,EAAI,CAAC,EAAGE,EAAS,CAAC,ECNnF,OAAS,UAAAE,EAAQ,UAAAC,EAAQ,QAAAC,EAAM,YAAAC,EAAU,iBAAAC,MAAuC,UAKhF,IAAMC,EAA4CH,EAChDD,EAAO,CAEL,SAAUG,EAAcJ,E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GAAG,KAAKP,EAAS,CAAC,EAOtD,KAAKD,GAAcF,EACnB,KAAK,sBAAwB,OAAO,OAAOY,CAAqB,EAG9D,OAAO,OAAOZ,CAAU,EACxB,OAAO,OAAO,IAAI,CAEtB,CAEAE,GACAC,GAEA,UAAW,CACT,OAAO,IAAIE,EAAS,KAAKH,GAAa,KAAKC,EAAQ,CACrD,CAEA,sBAGA,GAAI,UAAW,CACb,OAAO,OAAO,OAAO,CAAE,OAAQ,MAAiB,CAAC,CACnD,CACF,EAEOU,EAAQN,ECnFf,IAAMO,EAAmB,CAAC,kBAAkB,EAQtCC,EAAN,cAAsCC,CAA2D,CAC/F,YAAYC,EAAsD,CAChE,MACEH,EACA,OAAO,OAAO,CACZ,WAAYG,CACd,CAAC,CACH,CACF,CACF,ECjBA,IAAOC,EAAQ,IAAI","names":["literal","object","pipe","readonly","union","array","custom","pipe","readonly","suggestedActionsStateSchema","custom","object","pipe","readonly","undefinedable","suggestedActionsOriginActivityStateSchema","SET_RAW_STATE","setRawStateActionSchema","pipe","object","union","literal","suggestedActionsStateSchema","readonly","suggestedActionsOriginActivityStateSchema","setRawState","name","state","DebugAPI","breakpoint","context","#breakpoint","#context","__DEBUG_CONTEXT__","DebugAPI_default","BREAKPOINT_FUNCTION","RestrictedDebugAPI","breakpointNames","contextGetters","name","getter","UNSAFE_callBreakpoint","RestrictedDebugAPI_default","BREAKPOINT_NAMES","RestrictedStoreDebugAPI","d","getActivities","StoreDebugAPIRegistry_default"]}