@datadog/apps-frontend 0.0.9 → 0.0.10
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/dist/src/_chunks/chunk-64RLSXHA.js +184 -0
- package/dist/src/_chunks/chunk-64RLSXHA.js.map +7 -0
- package/dist/src/_chunks/chunk-BWBMAWDD.js +235 -0
- package/dist/src/_chunks/{chunk-OEPH347K.js.map → chunk-BWBMAWDD.js.map} +3 -3
- package/dist/src/_chunks/chunk-E6L6DSL7.js +230 -0
- package/dist/src/_chunks/{chunk-LEEYMNMO.js.map → chunk-E6L6DSL7.js.map} +1 -1
- package/dist/src/_chunks/chunk-OF23NNWB.js +34 -0
- package/dist/src/_chunks/{chunk-XSHCFEOH.js.map → chunk-OF23NNWB.js.map} +1 -1
- package/dist/src/_chunks/chunk-ONCDAC2F.js +802 -0
- package/dist/src/_chunks/{chunk-EYBITW7J.js.map → chunk-ONCDAC2F.js.map} +2 -2
- package/dist/src/_chunks/chunk-SSORLL57.js +219 -0
- package/dist/src/_chunks/{chunk-D43RPVCF.js.map → chunk-SSORLL57.js.map} +1 -1
- package/dist/src/_chunks/chunk-VSZMABRM.js +54 -0
- package/dist/src/_chunks/{chunk-2V2HASKF.js.map → chunk-VSZMABRM.js.map} +1 -1
- package/dist/src/deep-links/react/index.js +8 -1
- package/dist/src/druids/react/index.js +25 -1
- package/dist/src/druids/react/index.js.map +1 -1
- package/dist/src/embedding/react/index.js +2908 -1
- package/dist/src/embedding/react/index.js.map +1 -1
- package/dist/src/inputs/published-definition.d.ts +13 -0
- package/dist/src/inputs/react/index.js +9 -1
- package/dist/src/inputs/schemas/index.js +15 -1
- package/package.json +2 -1
- package/dist/src/_chunks/chunk-2V2HASKF.js +0 -7
- package/dist/src/_chunks/chunk-D43RPVCF.js +0 -7
- package/dist/src/_chunks/chunk-DETZPDFA.js +0 -7
- package/dist/src/_chunks/chunk-DETZPDFA.js.map +0 -7
- package/dist/src/_chunks/chunk-EYBITW7J.js +0 -7
- package/dist/src/_chunks/chunk-LEEYMNMO.js +0 -7
- package/dist/src/_chunks/chunk-OEPH347K.js +0 -7
- package/dist/src/_chunks/chunk-XSHCFEOH.js +0 -7
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/embedding/config.ts", "../../../src/embedding/diagnostics.ts", "../../../src/embedding/shared.ts", "../../../src/embedding/contract.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Every tunable the embedding protocol uses -- timeouts and the limits that\n * bound peer-influenced state -- together in one place with an obvious name\n * each, instead of scattered as same-looking magic numbers across unrelated\n * files.\n */\n\nexport const PROTOCOL_VERSION = 1;\n\n// --- Timeouts -----------------------------------------------------------\n//\n// Each one is a local decision made independently by whichever side enforces\n// it -- none of these are negotiated with, or need to match, the peer's own\n// value for the same phase.\n\n/** Phase 1: transferring the private control port across the window boundary. */\nexport const BOOTSTRAP_TIMEOUT_MS = 10_000;\n\n/** Phases 2 and 3: protocol compatibility negotiation and bringing up the\n * operational protocol on the transferred port. Each phase receives this\n * full deadline independently. */\nexport const CONNECT_TIMEOUT_MS = 10_000;\n\n/** How long the app waits for the host to answer its claim of a module. */\nexport const CLAIM_TIMEOUT_MS = 5_000;\n\n/** How long a function call is allowed to run (host side) or be waited on\n * (app side). Each side enforces this purely locally -- it is never sent\n * over the wire, and one side never needs to know the other's value: the\n * watchdog that fires first just wins through the normal error path, the\n * same way any other host/app-independent failure already does. */\nexport const FUNCTION_CALL_TIMEOUT_MS = 600_000;\n\n/**\n * Ceiling for a `FunctionField.timeoutMs` override: the largest delay\n * `setTimeout` accepts. Anything above it silently overflows the 32-bit\n * signed timer and fires almost immediately, inverting the longest deadline\n * an author can ask for into the shortest one they could get.\n */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/** Reject a public timeout override that `setTimeout` cannot represent. */\nexport function assertValidTimerDelay(name: string, timeoutMs: number): void {\n if (\n !Number.isFinite(timeoutMs) ||\n timeoutMs < 0 ||\n timeoutMs > MAX_TIMER_DELAY_MS\n ) {\n throw new RangeError(\n `${name} must be a finite number between 0 and ${MAX_TIMER_DELAY_MS}.`,\n );\n }\n}\n\n/** How often a heartbeat ping is sent, and how long a reply is awaited\n * before it counts as a miss. */\nexport const HEARTBEAT_INTERVAL_MS = 10_000;\nexport const HEARTBEAT_DEADLINE_MS = 5_000;\n\n/** Grace period between posting a close envelope and actually tearing down\n * the transport, so the envelope isn't truncated in flight. */\nexport const CLOSE_DELIVERY_TIMEOUT_MS = 250;\n\n/** Reconnection backoff: starting delay, cap, and how long to keep retrying\n * before giving up on the whole recovery attempt. */\nexport const RECONNECT_RETRY_MS = 1_000;\nexport const RECONNECT_MAX_RETRY_MS = 10_000;\nexport const RECONNECT_GIVE_UP_AFTER_MS = 45_000;\n\n// --- Limits ---------------------------------------------------------------\n//\n// These bound state retained at the request of iframe code, so an\n// adversarial or malformed peer can't grow it without limit. Both peers\n// validate against them independently.\n\nexport const MAX_LIVE_HOST_CLAIMS = 128;\nexport const MAX_CLAIM_ID_LENGTH = 256;\nexport const MAX_CALL_ID_LENGTH = 256;\nexport const MAX_LIVE_HOST_FUNCTION_CALLS = 128;\nexport const MAX_PENDING_ENDPOINT_OPERATIONS = 32;\nexport const MAX_CLAIM_FIELDS = 128;\nexport const MAX_CLAIM_FIELD_NAME_LENGTH = 256;\n", "/**\n * Console diagnostics for every embedding outcome that is not\n * starting -> connecting -> connected.\n *\n * Debugging an embedding failure means reasoning about two documents that each\n * see half of the connection: the Datadog page owns the host listener, the app\n * iframe owns the connection handle, and neither observes why the other gave\n * up. Every failure, rejection, timeout, and lost connection therefore reports\n * itself locally, naming the side that produced it and carrying the detail the\n * wire deliberately does not: raw causes, validation issues, claim and call\n * identifiers, attempt counts, and the deadline that expired.\n *\n * This module never throws. It runs on paths that are already failing, in\n * browsers we do not control, so a missing or hostile `console` must not\n * replace the failure being reported.\n */\n\nimport type { AnyError } from './types';\n\nconst PREFIX = '[Datadog Apps embedding]';\n\n/** How deep an `Error.cause` chain is described before it is truncated. */\nconst MAX_CAUSE_DEPTH = 3;\n\n/** Which peer produced a log line; both peers run this code. */\nexport type DiagnosticSide = 'app' | 'host';\n\nexport type DiagnosticDetail = Readonly<Record<string, unknown>>;\n\n/**\n * Renders an arbitrary thrown value as inspectable data. Errors lose their\n * `name`, `message`, `stack`, and `cause` when a console is handed a bare\n * `Error` inside an object in some environments, so those are spread out\n * explicitly; anything else is passed through for the console to format.\n */\nexport function describeCause(cause: unknown, depth = 0): unknown {\n if (!(cause instanceof Error)) {\n return cause;\n }\n // A peer-influenced Error may have hostile name/message/stack/cause\n // accessors; this module's \"never throws\" guarantee must hold even then.\n try {\n const described: Record<string, unknown> = {\n name: cause.name,\n message: cause.message,\n };\n if (typeof cause.stack === 'string') {\n described.stack = cause.stack;\n }\n if (cause.cause !== undefined) {\n described.cause =\n depth < MAX_CAUSE_DEPTH\n ? describeCause(cause.cause, depth + 1)\n : '(cause chain truncated)';\n }\n return described;\n } catch {\n return '(cause could not be described)';\n }\n}\n\n/**\n * Renders a wire error for logging. Every code carries structured-clone-safe\n * data already, except the local-only `cause` of `TRANSPORT_FAILED`, which is\n * where the actual explanation usually lives.\n */\nexport function describeError(error: AnyError): DiagnosticDetail {\n return 'cause' in error\n ? { ...error, cause: describeCause(error.cause) }\n : error;\n}\n\nfunction log(\n level: 'warn' | 'error',\n event: string,\n detail: DiagnosticDetail,\n): void {\n try {\n globalThis.console?.[level](`${PREFIX} ${event}`, detail);\n } catch {\n // A console that cannot be used is not a reason to lose the outcome\n // this call was reporting.\n }\n}\n\n/** A failure the connection expects to recover from, or a degraded outcome. */\nexport function logWarning(event: string, detail: DiagnosticDetail = {}): void {\n log('warn', event, detail);\n}\n\n/** A failure a consumer observes: terminal, unrecoverable, or data-losing. */\nexport function logFailure(event: string, detail: DiagnosticDetail = {}): void {\n log('error', event, detail);\n}\n", "import { describeCause, logFailure } from './diagnostics';\nimport type { Result } from './types';\n\nlet nextId = 0;\n\n/**\n * The counter prevents local reuse if randomness repeats; the random segment\n * makes heartbeat nonces difficult for the peer to predict.\n */\nexport function createId(prefix: string): string {\n nextId += 1;\n return `${prefix}:${randomSegment()}:${nextId.toString(36)}`;\n}\n\nfunction randomSegment(): string {\n const bytes = new Uint8Array(8);\n globalThis.crypto.getRandomValues(bytes);\n let segment = '';\n for (const byte of bytes) {\n segment += byte.toString(16).padStart(2, '0');\n }\n return segment;\n}\n\nexport function success<TValue>(value: TValue): Result<TValue, never> {\n return { ok: true, value };\n}\n\nexport function err<TError>(value: TError): Result<never, TError> {\n return { ok: false, error: value };\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * True when `value` is a well-formed identifier: a non-empty string. Bounds\n * its length to at most `limit` characters only when a limit is supplied.\n */\nexport function isValidIdentifier(\n value: unknown,\n limit?: number,\n): value is string {\n return (\n typeof value === 'string' &&\n value.length > 0 &&\n (limit === undefined || value.length <= limit)\n );\n}\n\n/**\n * Runs a cleanup action that must not throw into its caller. Teardown runs on\n * paths that are already failing, so a secondary failure is reported and\n * swallowed instead of replacing the outcome the caller is about to return.\n */\nexport function teardown(description: string, action: () => void): void {\n try {\n action();\n } catch (error) {\n logFailure('a teardown step failed', {\n description,\n cause: describeCause(error),\n });\n }\n}\n\n/**\n * Calls every listener, isolating exceptions so one listener throwing doesn't\n * stop the rest from being notified or propagate into the caller that\n * triggered the notification.\n */\nexport function notifyListeners<TArgs extends readonly unknown[] = []>(\n listeners: Iterable<(...args: TArgs) => void>,\n ...args: TArgs\n): void {\n for (const listener of [...listeners]) {\n try {\n listener(...args);\n } catch (error) {\n // Rethrown out of band, where the stack no longer shows that\n // embedding was notifying a listener.\n logFailure('an embedding listener threw', {\n cause: describeCause(error),\n });\n globalThis.queueMicrotask(() => {\n throw error;\n });\n }\n }\n}\n", "import {\n MAX_CLAIM_FIELDS,\n MAX_CLAIM_FIELD_NAME_LENGTH,\n MAX_TIMER_DELAY_MS,\n} from './config';\nimport { isRecord, isValidIdentifier } from './shared';\nimport type {\n AnyContract,\n AnyField,\n AnyFunctionField,\n AnySchema,\n Contract,\n ContractVersion,\n FunctionField,\n HostFunction,\n HostModule,\n LiveValue,\n ValidationOnlySchema,\n ValueField,\n} from './types';\n\n/**\n * A field name must be a valid own-property identifier the wire protocol\n * will actually carry: excludes \"__proto__\" and other names that a plain\n * object assignment would resolve against the prototype chain instead of\n * creating an own property. Exported so every place a contract-shaped field\n * name is declared (e.g. an older version's `extraInputs`) enforces the same\n * shape, not just `defineContract` itself.\n */\nexport const VALID_FIELD_NAME: RegExp = /^[A-Za-z][A-Za-z0-9_]*$/;\n\n/**\n * Every module this package has minted. Backs the runtime half of\n * `HostModule`'s brand, so a structurally-identical object built elsewhere is\n * rejected at `listen()` even where types were bypassed.\n */\nconst mintedHostModules = new WeakSet<object>();\n\n/**\n * The only way a `HostModule` comes into existence. Kept here, beside the\n * validation it has to satisfy, and deliberately not re-exported from\n * `@datadog/apps-frontend/embedding/internal` -- a host reaches modules only\n * as the output of providing an inputs definition, never by naming a version\n * and building one itself.\n */\nexport function createHostModule(\n contract: AnyContract,\n implementation: Readonly<Record<string, LiveValue<unknown> | HostFunction>>,\n signal?: AbortSignal,\n): HostModule {\n // A null-prototype snapshot means a wire-supplied field name (e.g.\n // \"__proto__\" or \"constructor\") can never resolve to an inherited\n // Object.prototype member when this dict is later indexed by that name.\n const snapshot: Record<string, LiveValue<unknown> | HostFunction> =\n Object.create(null);\n for (const [name, provider] of Object.entries(implementation)) {\n snapshot[name] = provider;\n }\n Object.freeze(snapshot);\n const module = Object.freeze(\n signal === undefined\n ? { contract, implementation: snapshot }\n : { contract, implementation: snapshot, signal },\n ) as unknown as HostModule;\n mintedHostModules.add(module);\n return module;\n}\n\nfunction isSchemaShape(value: unknown): value is AnySchema {\n if (\n !(\n (typeof value === 'object' && value !== null) ||\n typeof value === 'function'\n )\n ) {\n return false;\n }\n const standard = (value as AnySchema)['~standard'];\n return (\n isRecord(standard) &&\n standard.version === 1 &&\n typeof standard.validate === 'function'\n );\n}\n\n/**\n * True when `field` has the generic shape of a read-only value field.\n * Ignores identifier-name rules and implementation matching, which are\n * caller-specific (e.g. host modules also validate against a provider).\n */\nexport function isValueFieldShape(\n field: unknown,\n): field is ValueField<AnySchema> {\n return (\n isRecord(field) && field.kind === 'value' && isSchemaShape(field.schema)\n );\n}\n\n/**\n * True when `field` has the generic shape of a callable function field.\n * Ignores identifier-name rules and implementation matching, which are\n * caller-specific (e.g. host modules also validate against a provider).\n */\nexport function isFunctionFieldShape(\n field: unknown,\n): field is AnyFunctionField {\n return (\n isRecord(field) &&\n field.kind === 'function' &&\n isRecord(field.inputs) &&\n Object.entries(field.inputs).every(\n ([name, schema]) => name.length > 0 && isSchemaShape(schema),\n ) &&\n isSchemaShape(field.result)\n );\n}\n\n/** True when `field` has the generic shape of any well-formed contract field. */\nexport function isAnyFieldShape(field: unknown): field is AnyField {\n return isValueFieldShape(field) || isFunctionFieldShape(field);\n}\n\n/**\n * True when a function field's optional `timeoutMs` is a deadline a call could\n * actually meet -- see `FunctionField.timeoutMs` for why each end is not.\n *\n * Deliberately separate from `isFunctionFieldShape`: this is about a value being\n * sensible, not about the field being a function, so folding it in would make an\n * out-of-range deadline report as a malformed shape or a mismatched provider.\n */\nexport function hasUsableFunctionTimeout(field: AnyField): boolean {\n return (\n field.kind !== 'function' ||\n field.timeoutMs === undefined ||\n (typeof field.timeoutMs === 'number' &&\n Number.isFinite(field.timeoutMs) &&\n field.timeoutMs > 0 &&\n field.timeoutMs <= MAX_TIMER_DELAY_MS)\n );\n}\n\ninterface ReadOnlyValueBuilder {\n readOnly<TSchema extends AnySchema>(\n schema: ValidationOnlySchema<TSchema>,\n ): ValueField<TSchema>;\n}\n\ninterface ReadOnlyFunctionBuilder {\n readOnly<\n const TInputs extends Readonly<Record<string, AnySchema>>,\n TResult extends AnySchema,\n >(\n definition: Readonly<{\n inputs: {\n readonly [TName in keyof TInputs]: ValidationOnlySchema<\n TInputs[TName]\n >;\n };\n result: ValidationOnlySchema<TResult>;\n /**\n * Optional per-function override of `FUNCTION_CALL_TIMEOUT_MS`.\n * See `FunctionField.timeoutMs`.\n */\n timeoutMs?: number;\n }>,\n ): FunctionField<TInputs, TResult>;\n}\n\n/**\n * Builds a value field for any embedding contract. `readOnly` is the only\n * builder today because no transport exists for an app to write a value\n * back to the host; the name leaves room for a future writable builder\n * without implying one exists yet.\n */\nexport const value: ReadOnlyValueBuilder = /* @__PURE__ */ Object.freeze({\n readOnly<TSchema extends AnySchema>(\n schema: ValidationOnlySchema<TSchema>,\n ): ValueField<TSchema> {\n return Object.freeze({ kind: 'value', schema });\n },\n});\n\n/** Builds a callable function field for any embedding contract. */\nexport const fn: ReadOnlyFunctionBuilder = /* @__PURE__ */ Object.freeze({\n readOnly<\n const TInputs extends Readonly<Record<string, AnySchema>>,\n TResult extends AnySchema,\n >({\n inputs,\n result,\n timeoutMs,\n }: Readonly<{\n inputs: {\n readonly [TName in keyof TInputs]: ValidationOnlySchema<\n TInputs[TName]\n >;\n };\n result: ValidationOnlySchema<TResult>;\n timeoutMs?: number;\n }>): FunctionField<TInputs, TResult> {\n // Omitted entirely rather than stored as an explicit `undefined`, so\n // `'timeoutMs' in field` answers whether an override was declared.\n return Object.freeze(\n timeoutMs === undefined\n ? { kind: 'function', inputs, result }\n : { kind: 'function', inputs, result, timeoutMs },\n );\n },\n});\n\ntype ValidationOnlyField<TField extends AnyField> =\n TField extends Readonly<{\n kind: 'value';\n schema: infer TSchema extends AnySchema;\n }>\n ? TField & Readonly<{ schema: ValidationOnlySchema<TSchema> }>\n : TField extends Readonly<{\n kind: 'function';\n inputs: infer TInputs extends Readonly<\n Record<string, AnySchema>\n >;\n result: infer TResult extends AnySchema;\n }>\n ? TField &\n Readonly<{\n inputs: {\n readonly [TName in keyof TInputs]: ValidationOnlySchema<\n TInputs[TName]\n >;\n };\n result: ValidationOnlySchema<TResult>;\n }>\n : never;\n\ntype ValidationOnlyFields<TFields extends Record<string, AnyField>> = {\n readonly [TName in keyof TFields]: ValidationOnlyField<TFields[TName]>;\n};\n\n/**\n * Assembles and validates a well-formed `Contract`: the one place any\n * claim-defining module builds an identifier, version, and fields into the\n * shape the embedding protocol requires. Field-shape correctness reuses\n * `isAnyFieldShape` so there is a single source of truth for what a\n * contract field looks like, shared with the host-registration gate above.\n */\nexport function defineContract<\n const TIdentifier extends string,\n const TVersion extends ContractVersion,\n const TFields extends Record<string, AnyField>,\n>(\n definition: Contract<TFields> &\n Readonly<{\n identifier: TIdentifier;\n version: TVersion;\n fields: ValidationOnlyFields<TFields>;\n }>,\n): Contract<TFields> &\n Readonly<{ identifier: TIdentifier; version: TVersion }> {\n if (!isValidIdentifier(definition.identifier)) {\n throw new Error(\n `Invalid embedding contract identifier \"${String(definition.identifier)}\".`,\n );\n }\n if (!Number.isSafeInteger(definition.version) || definition.version < 1) {\n throw new Error(\n `Embedding contract \"${definition.identifier}\" must have a positive integer version.`,\n );\n }\n\n const entries = Object.entries(definition.fields);\n if (entries.length === 0 || entries.length > MAX_CLAIM_FIELDS) {\n throw new Error(\n `Embedding contract \"${definition.identifier}\" must define between 1 and ${MAX_CLAIM_FIELDS} fields.`,\n );\n }\n for (const [name, field] of entries) {\n if (\n !VALID_FIELD_NAME.test(name) ||\n name.length > MAX_CLAIM_FIELD_NAME_LENGTH ||\n !isAnyFieldShape(field)\n ) {\n throw new Error(\n `Embedding contract field \"${definition.identifier}.${name}\" must be a named read-only value or function whose schemas implement Standard Schema V1.`,\n );\n }\n if (!hasUsableFunctionTimeout(field)) {\n throw new Error(\n `Embedding contract field \"${definition.identifier}.${name}\" declares a timeoutMs no call could meet. It must be greater than 0 and at most ${MAX_TIMER_DELAY_MS}.`,\n );\n }\n }\n\n return Object.freeze({\n identifier: definition.identifier,\n version: definition.version,\n fields: Object.freeze(\n Object.fromEntries(\n entries.map(([name, field]) => [\n name,\n field.kind === 'value'\n ? Object.freeze({ ...field, schema: field.schema })\n : Object.freeze({\n ...field,\n inputs: Object.freeze({ ...field.inputs }),\n result: field.result,\n }),\n ]),\n ),\n ) as unknown as TFields,\n });\n}\n\n/**\n * The host-side registration gate. Runs when a host registers its modules, so\n * a contract that does not match its implementation fails loudly at `listen()`\n * instead of as a confusing claim failure later.\n */\nexport function assertHostModule(module: HostModule): void {\n if (!isRecord(module) || !mintedHostModules.has(module)) {\n throw new Error(\n 'A host module must come from its module provider -- the host-side helper that serves every contract version its definition still converts to.',\n );\n }\n if (\n !isRecord(module.contract) ||\n !isValidIdentifier(module.contract.identifier) ||\n typeof module.contract.version !== 'number' ||\n !Number.isSafeInteger(module.contract.version) ||\n module.contract.version < 1 ||\n !isRecord(module.contract.fields) ||\n Object.keys(module.contract.fields).length === 0 ||\n !isRecord(module.implementation) ||\n (module.signal !== undefined &&\n (typeof module.signal.aborted !== 'boolean' ||\n typeof module.signal.addEventListener !== 'function' ||\n typeof module.signal.removeEventListener !== 'function'))\n ) {\n throw new Error('The host module has an invalid contract.');\n }\n\n for (const [name, field] of Object.entries(module.contract.fields)) {\n const provider = Object.hasOwn(module.implementation, name)\n ? module.implementation[name]\n : undefined;\n if (\n !VALID_FIELD_NAME.test(name) ||\n name.length > MAX_CLAIM_FIELD_NAME_LENGTH\n ) {\n throw new Error(\n `A host module field name \"${name}\" is not a valid claim field name.`,\n );\n }\n const isValue =\n isValueFieldShape(field) &&\n isRecord(provider) &&\n typeof provider.get === 'function' &&\n typeof provider.subscribe === 'function';\n const isFunction =\n isFunctionFieldShape(field) &&\n isRecord(provider) &&\n typeof provider.invoke === 'function';\n if (!isValue && !isFunction) {\n throw new Error(\n `The implementation of \"${module.contract.identifier}.${name}\" does not match its field contract.`,\n );\n }\n }\n}\n\n/**\n * Validates a whole registration: every module well-formed and no duplicate\n * `(identifier, version)`. Returns the failure rather than throwing so a\n * caller can report it over the connection.\n */\nexport function invalidHostModule(\n modules: readonly HostModule[],\n): Error | undefined {\n try {\n const versions = new Set<string>();\n for (const module of modules) {\n assertHostModule(module);\n const key = JSON.stringify([\n module.contract.identifier,\n module.contract.version,\n ]);\n if (versions.has(key)) {\n throw new Error(\n `The host registered \"${module.contract.identifier}\" v${module.contract.version} more than once.`,\n );\n }\n versions.add(key);\n }\n return undefined;\n } catch (error) {\n return error instanceof Error\n ? error\n : new Error('The host module is invalid.', { cause: error });\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;AA0CO,SAASA,EAAsBC,GAAcC,GAAyB;AACzE,MACI,CAAC,OAAO,SAASA,CAAS,KAC1BA,IAAY,KACZA,IAAY;AAEZ,UAAM,IAAI;AAAA,MACN,GAAGD,CAAI;AAAA,IACX;AAER;AAIO,IAAME,IAAwB,KACxBC,IAAwB,KAIxBC,IAA4B,KAI5BC,IAAqB,KACrBC,IAAyB,KACzBC,IAA6B,MAQ7BC,IAAuB,KACvBC,IAAsB,KACtBC,IAAqB,KACrBC,IAA+B,KAC/BC,IAAkC,IAClCC,IAAmB,KACnBC,IAA8B;;;AC9D3C,IAAMC,IAAS;AAgBR,SAASC,EAAcC,GAAgBC,IAAQ,GAAY;AAC9D,MAAI,EAAED,aAAiB;AACnB,WAAOA;AAIX,MAAI;AACA,QAAME,IAAqC;AAAA,MACvC,MAAMF,EAAM;AAAA,MACZ,SAASA,EAAM;AAAA,IACnB;AACA,WAAI,OAAOA,EAAM,SAAU,aACvBE,EAAU,QAAQF,EAAM,QAExBA,EAAM,UAAU,WAChBE,EAAU,QACND,IAAQ,IACFF,EAAcC,EAAM,OAAOC,IAAQ,CAAC,IACpC,4BAEPC;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAOO,SAASC,EAAcC,GAAmC;AAC7D,SAAO,WAAWA,IACZ,EAAE,GAAGA,GAAO,OAAOL,EAAcK,EAAM,KAAK,EAAE,IAC9CA;AACV;AAEA,SAASC,EACLC,GACAC,GACAC,GACI;AACJ,MAAI;AACA,eAAW,UAAU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,GAAS;AACjC,QACI,CAAC3B,EAAiB,KAAKO,CAAI,KAC3BA,EAAK,SAASsB,KACd,CAACX,EAAgBH,CAAK;AAEtB,YAAM,IAAI;AAAA,QACN,6BAA6BU,EAAW,UAAU,IAAIlB,CAAI;AAAA,MAC9D;AAEJ,QAAI,CAACY,EAAyBJ,CAAK;AAC/B,YAAM,IAAI;AAAA,QACN,6BAA6BU,EAAW,UAAU,IAAIlB,CAAI,oFAAoF,UAAkB;AAAA,MACpK;AAAA,EAER;AAEA,SAAO,OAAO,OAAO;AAAA,IACjB,YAAYkB,EAAW;AAAA,IACvB,SAASA,EAAW;AAAA,IACpB,QAAQ,OAAO;AAAA,MACX,OAAO;AAAA,QACHE,EAAQ,IAAI,CAAC,CAACpB,GAAMQ,CAAK,MAAM;AAAA,UAC3BR;AAAA,UACAQ,EAAM,SAAS,UACT,OAAO,OAAO,EAAE,GAAGA,GAAO,QAAQA,EAAM,OAAO,CAAC,IAChD,OAAO,OAAO;AAAA,YACV,GAAGA;AAAA,YACH,QAAQ,OAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,CAAC;AAAA,YACzC,QAAQA,EAAM;AAAA,UAClB,CAAC;AAAA,QACX,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,EACJ,CAAC;AACL;",
|
|
6
6
|
"names": ["assertValidTimerDelay", "name", "timeoutMs", "HEARTBEAT_INTERVAL_MS", "HEARTBEAT_DEADLINE_MS", "CLOSE_DELIVERY_TIMEOUT_MS", "RECONNECT_RETRY_MS", "RECONNECT_MAX_RETRY_MS", "RECONNECT_GIVE_UP_AFTER_MS", "MAX_LIVE_HOST_CLAIMS", "MAX_CLAIM_ID_LENGTH", "MAX_CALL_ID_LENGTH", "MAX_LIVE_HOST_FUNCTION_CALLS", "MAX_PENDING_ENDPOINT_OPERATIONS", "MAX_CLAIM_FIELDS", "MAX_CLAIM_FIELD_NAME_LENGTH", "PREFIX", "describeCause", "cause", "depth", "described", "describeError", "error", "log", "level", "event", "detail", "PREFIX", "logWarning", "logFailure", "nextId", "createId", "prefix", "randomSegment", "bytes", "segment", "byte", "success", "value", "err", "isRecord", "isValidIdentifier", "limit", "teardown", "description", "action", "error", "logFailure", "describeCause", "notifyListeners", "listeners", "args", "listener", "VALID_FIELD_NAME", "mintedHostModules", "createHostModule", "contract", "implementation", "signal", "snapshot", "name", "provider", "module", "isSchemaShape", "value", "standard", "isRecord", "isValueFieldShape", "field", "isFunctionFieldShape", "schema", "isAnyFieldShape", "hasUsableFunctionTimeout", "fn", "inputs", "result", "timeoutMs", "defineContract", "definition", "isValidIdentifier", "entries", "MAX_CLAIM_FIELDS", "MAX_CLAIM_FIELD_NAME_LENGTH"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0.
|
|
2
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
3
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
d as i
|
|
8
|
+
} from "./chunk-VSZMABRM.js";
|
|
9
|
+
import {
|
|
10
|
+
g as n
|
|
11
|
+
} from "./chunk-BWBMAWDD.js";
|
|
12
|
+
|
|
13
|
+
// src/inputs/react/use-package-datadog-app-input.ts
|
|
14
|
+
import { useSyncExternalStore as a } from "react";
|
|
15
|
+
function o(t) {
|
|
16
|
+
let p = i();
|
|
17
|
+
n(t);
|
|
18
|
+
let e = p.getClaim(t.latest);
|
|
19
|
+
return a(
|
|
20
|
+
e.subscribe,
|
|
21
|
+
e.getSnapshot,
|
|
22
|
+
e.getSnapshot
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/inputs/react/use-datadog-app-input.ts
|
|
27
|
+
function d(t) {
|
|
28
|
+
return o(t);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
d as a
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-OF23NNWB.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/inputs/react/use-package-datadog-app-input.ts", "../../../src/inputs/react/use-datadog-app-input.ts"],
|
|
4
4
|
"sourcesContent": ["import { useSyncExternalStore } from 'react';\n\nimport { useAppEmbedding } from '../../embedding/react/context';\nimport type { ClaimState } from '../../embedding/types';\nimport type { AnyPublishedDatadogAppInput } from '../published-definition';\nimport { assertPublishedDatadogAppInputsDefinition } from '../published-definition';\n\n/** Claims a package-owned definition that is absent from the public schema barrel. */\nexport function usePackageDatadogAppInput<\n TDefinition extends AnyPublishedDatadogAppInput,\n>(definition: TDefinition): ClaimState<TDefinition['latest']> {\n const embedding = useAppEmbedding();\n assertPublishedDatadogAppInputsDefinition(definition);\n const store = embedding.getClaim<TDefinition['latest']>(definition.latest);\n return useSyncExternalStore(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot,\n );\n}\n", "import type { ClaimState } from '../../embedding/types';\nimport type { DatadogAppInputDefinition } from '../schemas/index';\n\nimport { usePackageDatadogAppInput } from './use-package-datadog-app-input';\n\n/**\n * What {@link useDatadogAppInput} gives back for one input: `pending` while the\n * connection or claim is in flight, `ready` with validated `fields`, `unavailable`\n * when this host does not provide the input, or `failed` with an actionable\n * `error`. `fields` exists only on `ready`, so stale values can never be read as\n * live.\n *\n * Named in terms of the input rather than the contract behind it -- which\n * version is being served is not a caller's concern.\n */\nexport type DatadogAppInputState<\n TDefinition extends DatadogAppInputDefinition,\n> = ClaimState<TDefinition['latest']>;\n\n/**\n * A type that refuses to match while saying why.\n *\n * A compiler error is the one piece of documentation a caller cannot skip, so\n * rejections here resolve to a sentence rather than to a bare `never` -- the\n * message becomes the error text, at the call site, in the editor.\n */\ntype Rejected<TMessage extends string> = Readonly<{\n __datadogAppInputsError: TMessage;\n}>;\n\ntype PublishedDefinitionFor<TDefinition extends DatadogAppInputDefinition> =\n Extract<\n DatadogAppInputDefinition,\n Readonly<{ identifier: TDefinition['identifier'] }>\n >;\n\ntype NoExtraFields<TDefinition extends DatadogAppInputDefinition> =\n Exclude<\n keyof TDefinition['latest']['fields'],\n keyof PublishedDefinitionFor<TDefinition>['latest']['fields']\n > extends never\n ? unknown\n : Rejected<'This definition has fields the published one does not. Pass a definition exported from @datadog/apps-frontend/inputs/schema, unmodified.'>;\n\n/**\n * Claims one Datadog App input and tracks its state across renders. Call it\n * below {@link DatadogAppProvider}.\n *\n * Pass a definition exported from `@datadog/apps-frontend/inputs/schema` --\n * {@link datadogTheme} is one. Hovering a definition shows the surfaces it is\n * offered on; the returned {@link ClaimState} says whether its values are usable\n * yet, and carries `fields` only while they are.\n *\n * Versions are not a caller's concern: this claims whichever version the\n * installed copy of the package treats as latest. An older copy asks for an\n * older version and keeps working for as long as the host still converts to it.\n * Past that the claim fails with `APP_MAJOR_TOO_OLD` -- update this package and\n * re-upload the app -- rather than silently degrading.\n *\n * @param definition An input definition from `@datadog/apps-frontend/inputs/schema`.\n * @returns The claim's current state: `pending`, `ready` (with `fields`),\n * `unavailable` when this host does not provide the input, or `failed` with an\n * actionable `error`.\n */\nexport function useDatadogAppInput<\n const TDefinition extends DatadogAppInputDefinition,\n>(\n definition: TDefinition & NoExtraFields<TDefinition>,\n): DatadogAppInputState<TDefinition> {\n return usePackageDatadogAppInput<TDefinition>(definition);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;AAAA,SAAS,wBAAAA,SAA4B;AAQ9B,SAASC,EAEdC,GAA4D;AAC1D,MAAMC,IAAYC,EAAgB;AAClC,EAAAC,EAA0CH,CAAU;AACpD,MAAMI,IAAQH,EAAU,SAAgCD,EAAW,MAAM;AACzE,SAAOK;AAAA,IACHD,EAAM;AAAA,IACNA,EAAM;AAAA,IACNA,EAAM;AAAA,EACV;AACJ;;;AC6CO,SAASE,EAGZC,GACiC;AACjC,SAAOC,EAAuCD,CAAU;AAC5D;",
|
|
6
6
|
"names": ["useSyncExternalStore", "usePackageDatadogAppInput", "definition", "embedding", "useAppEmbedding", "assertPublishedDatadogAppInputsDefinition", "store", "useSyncExternalStore", "useDatadogAppInput", "definition", "usePackageDatadogAppInput"]
|
|
7
7
|
}
|