@apifuse/provider-sdk 2.2.0-beta.61 → 2.2.0-beta.63
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/AUTHORING.md +268 -9
- package/CHANGELOG.md +8 -0
- package/README.md +1 -0
- package/bin/apifuse-check.ts +84 -2
- package/bin/apifuse-dev.ts +11 -31
- package/bin/apifuse-migrate-deployment.ts +200 -0
- package/bin/apifuse-pack-check.ts +11 -4
- package/bin/apifuse-pack-types.ts +191 -4
- package/bin/apifuse-record.ts +44 -32
- package/bin/apifuse-test.ts +3 -1
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/deployment-intent.d.ts +178 -0
- package/dist/cli/deployment-intent.js +277 -0
- package/dist/cli/migrate-deployment-intent.d.ts +132 -0
- package/dist/cli/migrate-deployment-intent.js +1552 -0
- package/dist/cli/migrate-provider-shape.d.ts +5 -1
- package/dist/cli/migrate-provider-shape.js +4 -2
- package/dist/cli/resolver-runtime.d.ts +21 -0
- package/dist/cli/resolver-runtime.js +31 -0
- package/dist/define.d.ts +3 -0
- package/dist/define.js +5 -0
- package/dist/dev.d.ts +3 -1
- package/dist/dev.js +6 -1
- package/dist/engine.d.ts +35 -1
- package/dist/engine.js +21 -2
- package/dist/error-resolution.d.ts +1 -0
- package/dist/error-resolution.js +54 -0
- package/dist/errors.d.ts +39 -1
- package/dist/errors.js +50 -0
- package/dist/handle-meta.d.ts +18 -2
- package/dist/handle-meta.js +30 -2
- package/dist/handle.d.ts +33 -12
- package/dist/handle.js +69 -24
- package/dist/i18n/error-messages.d.ts +86 -0
- package/dist/i18n/error-messages.js +192 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/keys.d.ts +12 -0
- package/dist/i18n/keys.js +76 -5
- package/dist/index.d.ts +10 -2
- package/dist/index.js +9 -1
- package/dist/lint.d.ts +10 -0
- package/dist/lint.js +440 -57
- package/dist/provider.d.ts +7 -5
- package/dist/provider.js +4 -2
- package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
- package/dist/runtime/browser-telemetry-binding.js +83 -0
- package/dist/runtime/browser-telemetry.d.ts +76 -0
- package/dist/runtime/browser-telemetry.js +165 -0
- package/dist/runtime/browser.d.ts +3 -0
- package/dist/runtime/browser.js +208 -47
- package/dist/runtime/cache-telemetry.d.ts +71 -0
- package/dist/runtime/cache-telemetry.js +177 -0
- package/dist/runtime/cache.js +67 -7
- package/dist/runtime/capability-response.d.ts +3 -0
- package/dist/runtime/capability-response.js +56 -0
- package/dist/runtime/capability-telemetry.d.ts +46 -0
- package/dist/runtime/capability-telemetry.js +68 -0
- package/dist/runtime/diagnostic-env.d.ts +3 -0
- package/dist/runtime/diagnostic-env.js +10 -1
- package/dist/runtime/engine-mode.d.ts +74 -0
- package/dist/runtime/engine-mode.js +152 -0
- package/dist/runtime/handle.js +15 -10
- package/dist/runtime/http-telemetry-binding.d.ts +10 -0
- package/dist/runtime/http-telemetry-binding.js +152 -0
- package/dist/runtime/http-telemetry-guard.d.ts +16 -0
- package/dist/runtime/http-telemetry-guard.js +202 -0
- package/dist/runtime/http-telemetry.d.ts +104 -0
- package/dist/runtime/http-telemetry.js +190 -0
- package/dist/runtime/http.d.ts +31 -0
- package/dist/runtime/http.js +356 -174
- package/dist/runtime/instrumentation.js +92 -13
- package/dist/runtime/ocr-telemetry.d.ts +82 -0
- package/dist/runtime/ocr-telemetry.js +192 -0
- package/dist/runtime/ocr.js +30 -8
- package/dist/runtime/request-telemetry.d.ts +2 -0
- package/dist/runtime/request-telemetry.js +2 -1
- package/dist/runtime/resolver-runtime-options.d.ts +14 -0
- package/dist/runtime/resolver-runtime-options.js +33 -0
- package/dist/runtime/resolver-shared.d.ts +3 -2
- package/dist/runtime/resolver-shared.js +4 -4
- package/dist/runtime/resolver-telemetry.d.ts +1 -0
- package/dist/runtime/resolver-telemetry.js +1 -1
- package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
- package/dist/runtime/resolver-vendors/browser.js +46 -0
- package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
- package/dist/runtime/resolver-vendors/hosts.js +35 -0
- package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
- package/dist/runtime/resolver-vendors/types.d.ts +5 -4
- package/dist/runtime/resolver.d.ts +4 -1
- package/dist/runtime/resolver.js +46 -13
- package/dist/runtime/state-telemetry.d.ts +79 -0
- package/dist/runtime/state-telemetry.js +194 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +26 -7
- package/dist/runtime/stealth-cookies.d.ts +5 -1
- package/dist/runtime/stealth-cookies.js +21 -1
- package/dist/runtime/stealth-owned-headers.d.ts +26 -0
- package/dist/runtime/stealth-owned-headers.js +37 -0
- package/dist/runtime/stealth-telemetry.d.ts +92 -0
- package/dist/runtime/stealth-telemetry.js +179 -0
- package/dist/runtime/stealth.d.ts +4 -1
- package/dist/runtime/stealth.js +228 -85
- package/dist/runtime/stt-telemetry.d.ts +77 -0
- package/dist/runtime/stt-telemetry.js +176 -0
- package/dist/runtime/stt.js +15 -6
- package/dist/server/error-stack-frames.d.ts +35 -0
- package/dist/server/error-stack-frames.js +219 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +5 -0
- package/dist/server/sdk-version.d.ts +3 -0
- package/dist/server/sdk-version.js +19 -0
- package/dist/server/self-test.js +1 -18
- package/dist/server/sensitive-values.d.ts +1 -1
- package/dist/server/sensitive-values.js +9 -0
- package/dist/server/serve-implementation.d.ts +53 -2
- package/dist/server/serve-implementation.js +369 -123
- package/dist/server/types.d.ts +1 -0
- package/dist/server/types.js +7 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
- package/dist/stateful/stateful-provider-runtime-context.js +1 -0
- package/dist/types.d.ts +94 -1
- package/package.json +6 -1
- package/src/cli/commands.ts +14 -0
- package/src/cli/deployment-intent.ts +364 -0
- package/src/cli/migrate-deployment-intent.ts +1908 -0
- package/src/cli/migrate-provider-shape.ts +10 -4
- package/src/cli/resolver-runtime.ts +72 -0
- package/src/define.ts +13 -0
- package/src/dev.ts +9 -2
- package/src/engine.ts +38 -2
- package/src/error-resolution.ts +58 -0
- package/src/errors.ts +77 -1
- package/src/handle-meta.ts +39 -4
- package/src/handle.ts +121 -38
- package/src/i18n/error-messages.ts +255 -0
- package/src/i18n/index.ts +1 -0
- package/src/i18n/keys.ts +80 -6
- package/src/index.ts +91 -0
- package/src/lint.ts +552 -57
- package/src/provider.ts +20 -0
- package/src/runtime/browser-telemetry-binding.ts +92 -0
- package/src/runtime/browser-telemetry.ts +289 -0
- package/src/runtime/browser.ts +249 -65
- package/src/runtime/cache-telemetry.ts +247 -0
- package/src/runtime/cache.ts +68 -17
- package/src/runtime/capability-response.ts +53 -0
- package/src/runtime/capability-telemetry.ts +101 -0
- package/src/runtime/diagnostic-env.ts +11 -1
- package/src/runtime/engine-mode.ts +233 -0
- package/src/runtime/handle.ts +20 -10
- package/src/runtime/http-telemetry-binding.ts +162 -0
- package/src/runtime/http-telemetry-guard.ts +208 -0
- package/src/runtime/http-telemetry.ts +292 -0
- package/src/runtime/http.ts +457 -204
- package/src/runtime/instrumentation.ts +105 -16
- package/src/runtime/ocr-telemetry.ts +308 -0
- package/src/runtime/ocr.ts +109 -74
- package/src/runtime/request-telemetry.ts +2 -1
- package/src/runtime/resolver-runtime-options.ts +50 -0
- package/src/runtime/resolver-shared.ts +9 -4
- package/src/runtime/resolver-telemetry.ts +1 -1
- package/src/runtime/resolver-vendors/browser.ts +65 -7
- package/src/runtime/resolver-vendors/hosts.ts +43 -0
- package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
- package/src/runtime/resolver-vendors/types.ts +5 -4
- package/src/runtime/resolver.ts +64 -21
- package/src/runtime/state-telemetry.ts +298 -0
- package/src/runtime/state.ts +46 -45
- package/src/runtime/stealth-cookies.ts +24 -1
- package/src/runtime/stealth-owned-headers.ts +41 -0
- package/src/runtime/stealth-telemetry.ts +304 -0
- package/src/runtime/stealth.ts +355 -150
- package/src/runtime/stt-telemetry.ts +282 -0
- package/src/runtime/stt.ts +93 -71
- package/src/server/error-stack-frames.ts +214 -0
- package/src/server/index.ts +66 -0
- package/src/server/sdk-version.ts +22 -0
- package/src/server/self-test.ts +1 -21
- package/src/server/sensitive-values.ts +14 -0
- package/src/server/serve-implementation.ts +601 -157
- package/src/server/types.ts +7 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
- package/src/stateful/stateful-provider-runtime-context.ts +4 -0
- package/src/types.ts +99 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
- package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +0 -12
package/dist/provider.d.ts
CHANGED
|
@@ -6,14 +6,16 @@ export type { OperationDefinitionFor, ProviderBuilder, ProviderContextOf, Provid
|
|
|
6
6
|
export type { JsonPrimitive, JsonValue } from "./contract-json.js";
|
|
7
7
|
export { AssertionExpressionSchema, AssertionPredicateSchema, AssertStepSchema, BoundedJsonPathSchema, CandidateBlockSchema, CandidatePolicySchema, CredentialRefDeclarationSchema, defineHealthScenario, HealthScenarioSchema, HealthStepSchema, ExtractStepSchema, FindFirstSchema, GuardStepSchema, JournalPolicySchema, JsonTemplateSchema, ManualTriggerPolicySchema, OperandSchema, OperationStepSchema, QuantifierSchema, ReferenceSchema, RetryPolicySchema, SafeRegexSchema, ScopedAssertionExpressionSchema, ScopedAssertionPredicateSchema, ScopedItemReferenceSchema, ScopedOperandSchema, StepReferenceSchema, RelativeDateNodeSchema, ValueTypeSchema, } from "./health-scenario.js";
|
|
8
8
|
export type { AssertionExpression, AssertionPredicate, AttemptReference, AssertResult, AssertStep, BoundedJsonPath, CandidateBlock, CandidatePolicy, CandidateReference, CredentialReference, CredentialRefDeclaration, EstablishedConnectionReference, ExtractStep, FindFirst, GuardAttribution, GuardReasonCode, GuardResult, GuardStep, HealthScenario, HealthStep, JsonTemplate, JournalPolicy, ManualTriggerPolicy, NonEmpty, OperationResult, OperationStep, Operand, Quantifier, ReferenceNode, Reference, RelativeDateNode, RetryPolicy, SafeRegex, ScopedAssertionExpression, ScopedAssertionPredicate, ScopedItemReference, ScopedOperand, StepBase, StepReference, ExtractResult, ValueType, } from "./health-scenario.js";
|
|
9
|
-
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, type ProviderErrorObservability, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
10
|
-
export { createProviderEnvironment, createInProcessProviderEngine, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
11
|
-
export type { ProviderCapabilityKey, ProviderEngine, ProviderEngineAttachmentInput, ProviderEngineBindingCandidates, ProviderEngineCapabilitySurface, ProviderEngineRequest, ProviderEngineResidentSurface, ProviderEngineSession, ProviderEngineTransport, } from "./engine.js";
|
|
12
|
-
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
9
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderEgressDeniedError, ProviderEngineAuthenticationError, ProviderEngineProtocolVersionError, ProviderEngineUnavailableError, ProviderError, type ProviderErrorObservability, SDKError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
10
|
+
export { createProviderEnvironment, createInProcessProviderEngine, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_MODE_ENV, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
11
|
+
export type { ProviderCapabilityKey, ProviderEngine, ProviderEngineAttachmentInput, ProviderEngineBindingCandidates, ProviderEngineCapabilitySurface, ProviderEngineMode, ProviderEngineRequest, ProviderEngineResidentSurface, ProviderEngineSession, ProviderEngineTransport, } from "./engine.js";
|
|
12
|
+
export { getProviderLocalePath, type ProviderErrorMessageParams, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
13
13
|
export * from "./handle.js";
|
|
14
|
+
export { APIFUSE_HANDLE_META_KEY, HANDLE_KIND_NAME_PATTERN, handleFieldDescription, isHandleFieldMeta, } from "./handle-meta.js";
|
|
14
15
|
export { type CreateHandleContextOptions, type CreateTestHandleContextOptions, createHandleContext, createTestHandleContext, type HandleNormalizationClass, type NormalizedHandle, normalizeHandle, } from "./runtime/handle.js";
|
|
16
|
+
export { createMemoryProviderRuntimeState, createUnsupportedProviderRuntimeState, } from "./runtime/state.js";
|
|
15
17
|
export { APIFUSE_CONTENT_PROVENANCE_META_KEY, APIFUSE_CONTENT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, publicField, redactPayload, type SensitiveFieldKind, type SensitiveFieldOptions, type SensitivePath, sensitive, untrustedContent, z, } from "./schema.js";
|
|
16
|
-
export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpRedirectFailureReason, HttpRedirectPolicy, HttpRedirectPolicyMode, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, NativeContext, NativeNetworkClient, NativeNetworkCloseReason, NativeNetworkConnection, NativeNetworkConnectInput, NativeNetworkConnectOptions, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyDrainHandler, NativeProxyEgressInfo, NativeProxyExpiringEvent, NativeProxyExpiringReason, NativeTcpDynamicEgressRule, NativeTcpEgressGrant, NativeTcpEgressRule, NativeTcpPortRange, NativeTcpTlsMode, NativeTlsConnectOptions, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationExample, OperationErrorCode, ProviderErrorStatus, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationTransport, ProviderAccessVisibility, ProviderContext, ProviderContextFor, ProviderDefinition, ProviderDeploymentOverrides, ProviderFileRef, ProviderFilesContext, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProxiedOAuthConfig, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderResolvedFile, ProviderRuntimeTarget, ProviderRuntimeState, ProviderStealthConfig, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, RedirectRunReason, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateNamespaceScope, StateValue, StateWriteOptions, StealthChallengeClassification, } from "./types.js";
|
|
18
|
+
export type { AuthAbortData, AuthAbortRetry, AuthFlowTerminalContext, AuthMode, AuthSafeData, AuthSafeJson, FlowContext, HealthCheckAssertionContext, HealthCheckCase, HealthCheckSuite, HealthCheckUnsupported, HealthJourneyDefinition, HealthJourneyEventContext, HealthJourneyManualTriggerPolicy, HealthJourneyRunContext, HealthJourneyRunResult, HealthScheduleRandomization, HttpAttemptContext, HttpHeadersFactory, HttpRedirectFailureReason, HttpRedirectPolicy, HttpRedirectPolicyMode, HttpRetryOptions, HttpRetrySummary, InferSchemaOutput, NativeContext, NativeNetworkClient, NativeNetworkCloseReason, NativeNetworkConnection, NativeNetworkConnectInput, NativeNetworkConnectOptions, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyDrainHandler, NativeProxyEgressInfo, NativeProxyExpiringEvent, NativeProxyExpiringReason, NativeTcpDynamicEgressRule, NativeTcpEgressGrant, NativeTcpEgressRule, NativeTcpPortRange, NativeTcpTlsMode, NativeTlsConnectOptions, OperationApprovalPolicy, OperationContractMetadata, OperationDefinition, OperationExample, OperationErrorCode, ProviderErrorStatus, OperationLifecycle, OperationObservabilityConfig, OperationObservabilitySensitiveConfig, OperationRelationships, OperationRiskClass, OperationSensitivePath, OperationTransport, ProviderAccessVisibility, ProviderContext, ProviderContextFor, ProviderDefinition, ProviderDeploymentOverrides, ProviderFileRef, ProviderFilesContext, ProviderLocale, ProviderLocaleKey, ProviderLocaleKeyInput, ProviderLogoProfile, ProviderProxyPolicy, ProxiedOAuthConfig, ProviderPublicConnectionMode, ProviderPublicProfile, ProviderResolvedFile, ProviderRuntimeTarget, ProviderRuntimeState, ProviderStealthConfig, ProviderStateDurationString, ProviderStateNamespace, ProviderSupportLevel, RedirectRunReason, SchemaLike, SmsOtpMatcherDefinition, StandardSchemaV1, StateCasResult, StateNamespaceOptions, StateNamespaceScope, StateValue, StateWriteOptions, StealthChallengeClassification, } from "./types.js";
|
|
17
19
|
export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.js";
|
|
18
20
|
export type { NativeGatewayProxy, NativeGatewayProxyResolutionInput, NativeGatewayProxySkipReason, NativeGatewayProxySynthesizer, NativeGatewayProxySynthesisResult, NativeGatewayProxySynthesisInput, NativeNetworkClientOptions, NativeNetworkErrorCode, VendorCredentialLookup, VendorCredentialResolver, } from "./runtime/native-network.js";
|
|
19
21
|
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
package/dist/provider.js
CHANGED
|
@@ -2,11 +2,13 @@ export { AuthAbortError, credentialsAuthChallenge, createAuthFlowHelpers, define
|
|
|
2
2
|
export { createFormCeremony } from "./ceremonies/index.js";
|
|
3
3
|
export { centered, delayed, defineHealthJourney, defineOperation, defineProvider, defineSmsOtpMatcher, every, } from "./define.js";
|
|
4
4
|
export { AssertionExpressionSchema, AssertionPredicateSchema, AssertStepSchema, BoundedJsonPathSchema, CandidateBlockSchema, CandidatePolicySchema, CredentialRefDeclarationSchema, defineHealthScenario, HealthScenarioSchema, HealthStepSchema, ExtractStepSchema, FindFirstSchema, GuardStepSchema, JournalPolicySchema, JsonTemplateSchema, ManualTriggerPolicySchema, OperandSchema, OperationStepSchema, QuantifierSchema, ReferenceSchema, RetryPolicySchema, SafeRegexSchema, ScopedAssertionExpressionSchema, ScopedAssertionPredicateSchema, ScopedItemReferenceSchema, ScopedOperandSchema, StepReferenceSchema, RelativeDateNodeSchema, ValueTypeSchema, } from "./health-scenario.js";
|
|
5
|
-
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
6
|
-
export { createProviderEnvironment, createInProcessProviderEngine, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
5
|
+
export { AuthError, HttpRedirectError, isProviderError, isSessionExpiredError, isTransportError, ProviderEgressDeniedError, ProviderEngineAuthenticationError, ProviderEngineProtocolVersionError, ProviderEngineUnavailableError, ProviderError, SDKError, SessionExpiredError, TransportError, ValidationError, } from "./errors.js";
|
|
6
|
+
export { createProviderEnvironment, createInProcessProviderEngine, ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES, ENGINE_OWNED_RUNTIME_ENV_NAMES, ENGINE_OWNED_TELEMETRY_ENV_NAMES, isEngineOwnedEnvName, isEngineOwnedProxyCredentialName, isEngineOwnedResolverCredentialName, isEngineOwnedRuntimeEnvName, isEngineOwnedTelemetryEnvName, PROVIDER_CAPABILITY_KEYS, PROVIDER_ENGINE_MODE_ENV, PROVIDER_ENGINE_PROTOCOL_VERSION, readEngineProxyCredentials, } from "./engine.js";
|
|
7
7
|
export { getProviderLocalePath, providerLocaleKey, qualifyProviderLocaleKey, } from "./i18n/index.js";
|
|
8
8
|
export * from "./handle.js";
|
|
9
|
+
export { APIFUSE_HANDLE_META_KEY, HANDLE_KIND_NAME_PATTERN, handleFieldDescription, isHandleFieldMeta, } from "./handle-meta.js";
|
|
9
10
|
export { createHandleContext, createTestHandleContext, normalizeHandle, } from "./runtime/handle.js";
|
|
11
|
+
export { createMemoryProviderRuntimeState, createUnsupportedProviderRuntimeState, } from "./runtime/state.js";
|
|
10
12
|
export { APIFUSE_CONTENT_PROVENANCE_META_KEY, APIFUSE_CONTENT_TRUST_META_KEY, APIFUSE_DESCRIPTION_KEY_META_KEY, APIFUSE_REDACTION_MARKER, APIFUSE_SENSITIVE_KIND_META_KEY, APIFUSE_SENSITIVE_META_KEY, collectSensitivePaths, describeKey, field, fields, isSensitiveSchema, publicField, redactPayload, sensitive, untrustedContent, z, } from "./schema.js";
|
|
11
13
|
export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./runtime/native-network-errors.js";
|
|
12
14
|
export { HttpRetryAfterPolicy, HttpRetryDelayStrategy, HttpRetryJitter, HttpRetryPreset, HttpRetryUnsafeMethodPolicy, } from "./types.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserClient } from "../types.js";
|
|
2
|
+
import type { BrowserTelemetrySink } from "./browser-telemetry.js";
|
|
3
|
+
export declare function isSupportedBrowserBinding(value: unknown): value is BrowserClient;
|
|
4
|
+
export declare function warnUnsupportedBrowserBinding(): void;
|
|
5
|
+
export declare function bindBrowserTelemetry(client: BrowserClient, sink: BrowserTelemetrySink): BrowserClient;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { observeTelemetryCallback } from "./http-telemetry-guard.js";
|
|
2
|
+
const methods = new Set(["newPage", "rawPage", "withIsolatedContext", "solveChallenge"]);
|
|
3
|
+
const adapters = new WeakMap();
|
|
4
|
+
let warned = false;
|
|
5
|
+
export function isSupportedBrowserBinding(value) {
|
|
6
|
+
if ((typeof value !== "object" && typeof value !== "function") || value === null)
|
|
7
|
+
return false;
|
|
8
|
+
return [...methods].some((method) => {
|
|
9
|
+
try {
|
|
10
|
+
return typeof Reflect.get(value, method) === "function";
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function warnUnsupportedBrowserBinding() {
|
|
18
|
+
if (warned)
|
|
19
|
+
return;
|
|
20
|
+
warned = true;
|
|
21
|
+
try {
|
|
22
|
+
console.warn("[apifuse] browser telemetry not attached; reason=unsupported_binding_shape");
|
|
23
|
+
}
|
|
24
|
+
catch { }
|
|
25
|
+
}
|
|
26
|
+
export function bindBrowserTelemetry(client, sink) {
|
|
27
|
+
const existing = adapters.get(client);
|
|
28
|
+
if (existing) {
|
|
29
|
+
existing.sink = sink;
|
|
30
|
+
return existing.adapter;
|
|
31
|
+
}
|
|
32
|
+
const wrappers = new Map();
|
|
33
|
+
const adapter = new Proxy(Object.create(client), {
|
|
34
|
+
get(_target, property) {
|
|
35
|
+
const original = Reflect.get(client, property, client);
|
|
36
|
+
if (typeof property !== "string" || !methods.has(property) || typeof original !== "function")
|
|
37
|
+
return original;
|
|
38
|
+
const cached = wrappers.get(property);
|
|
39
|
+
if (cached && cached.original === original)
|
|
40
|
+
return cached.wrapped;
|
|
41
|
+
const wrapped = function (...args) {
|
|
42
|
+
const receiver = this === adapter ? client : this;
|
|
43
|
+
observeTelemetryCallback(state.sink, () => {
|
|
44
|
+
const declared = client.engine;
|
|
45
|
+
const engine = declared === "playwright-stealth" ||
|
|
46
|
+
declared === "nodriver" ||
|
|
47
|
+
declared === "selenium-uc"
|
|
48
|
+
? declared
|
|
49
|
+
: "host";
|
|
50
|
+
return state.sink.recordEngine(engine);
|
|
51
|
+
});
|
|
52
|
+
if (property === "newPage" || property === "rawPage" || property === "withIsolatedContext")
|
|
53
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordPoolAcquire("not_configured"));
|
|
54
|
+
let result;
|
|
55
|
+
try {
|
|
56
|
+
result = Reflect.apply(original, receiver, args);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordError("other"));
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (result instanceof Promise)
|
|
64
|
+
void Promise.prototype.then.call(result, undefined, () => {
|
|
65
|
+
observeTelemetryCallback(state.sink, () => state.sink.recordError("other"));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
observeTelemetryCallback(state.sink, () => {
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
wrappers.set(property, { original, wrapped });
|
|
76
|
+
return wrapped;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const state = { sink, adapter };
|
|
80
|
+
adapters.set(client, state);
|
|
81
|
+
adapters.set(adapter, state);
|
|
82
|
+
return adapter;
|
|
83
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { BrowserEngine } from "../types.js";
|
|
2
|
+
export type BrowserTelemetryEngine = BrowserEngine | "host";
|
|
3
|
+
import { type ClosedEnum, type SpanIndex, type TelemetryContributor } from "./request-telemetry.js";
|
|
4
|
+
export type BrowserTelemetryPoolAcquireOutcome = "ok" | "not_configured" | "queue_full" | "timed_out" | "shutting_down" | "unknown_lease" | "unknown_method" | "missing_allowed_hosts" | "transport_failure" | "other";
|
|
5
|
+
export type BrowserTelemetryErrorCode = "BROWSER_CDP_POOL_REQUIRED" | "BROWSER_PROXY_INVALID" | "BROWSER_RUNTIME_UNSUPPORTED" | "BROWSER_CDP_POOL_ERROR" | "other";
|
|
6
|
+
export type BrowserTelemetrySampleName = "browser.newPage" | "browser.page.goto" | "browser.page.fill" | "browser.page.click" | "browser.page.type" | "browser.page.waitForSelector" | "browser.evaluate" | "browser.content" | "browser.screenshot" | "other";
|
|
7
|
+
export type BrowserTelemetryLogPayload = {
|
|
8
|
+
allocateMs: number;
|
|
9
|
+
pages: number;
|
|
10
|
+
navigations: number;
|
|
11
|
+
actions: number;
|
|
12
|
+
evaluate: number;
|
|
13
|
+
content: number;
|
|
14
|
+
screenshot: number;
|
|
15
|
+
poolAcquireOutcome?: BrowserTelemetryPoolAcquireOutcome;
|
|
16
|
+
poolAcquireAttempts: number;
|
|
17
|
+
poolAcquireFailures: number;
|
|
18
|
+
poolAcquireUnknownCode?: number;
|
|
19
|
+
proxyAuthChallenges: number;
|
|
20
|
+
engine?: BrowserTelemetryEngine;
|
|
21
|
+
lastErrorCode?: BrowserTelemetryErrorCode;
|
|
22
|
+
samples: {
|
|
23
|
+
name: BrowserTelemetrySampleName;
|
|
24
|
+
ms: number;
|
|
25
|
+
status: "ok" | "error";
|
|
26
|
+
diagnostics?: string;
|
|
27
|
+
}[];
|
|
28
|
+
dropped: number;
|
|
29
|
+
telemetryFailed?: true;
|
|
30
|
+
};
|
|
31
|
+
export type BrowserTelemetryHeaderPayload = {
|
|
32
|
+
allocateMs: number;
|
|
33
|
+
pages: number;
|
|
34
|
+
navigations: number;
|
|
35
|
+
actions: number;
|
|
36
|
+
evaluate: number;
|
|
37
|
+
content: number;
|
|
38
|
+
screenshot: number;
|
|
39
|
+
poolAcquireOutcome?: ClosedEnum<BrowserTelemetryPoolAcquireOutcome>;
|
|
40
|
+
poolAcquireAttempts: number;
|
|
41
|
+
poolAcquireFailures: number;
|
|
42
|
+
proxyAuthChallenges: number;
|
|
43
|
+
engine?: ClosedEnum<BrowserTelemetryEngine>;
|
|
44
|
+
lastErrorCode?: ClosedEnum<BrowserTelemetryErrorCode>;
|
|
45
|
+
samples: {
|
|
46
|
+
name: ClosedEnum<BrowserTelemetrySampleName>;
|
|
47
|
+
ms: number;
|
|
48
|
+
status: ClosedEnum<"ok" | "error">;
|
|
49
|
+
}[];
|
|
50
|
+
dropped: number;
|
|
51
|
+
};
|
|
52
|
+
export interface BrowserTelemetrySink {
|
|
53
|
+
recordPoolAcquire(outcome: BrowserTelemetryPoolAcquireOutcome): void;
|
|
54
|
+
recordPoolAcquireUnknownCode?(code: number): void;
|
|
55
|
+
recordProxyAuthChallenge(): void;
|
|
56
|
+
recordEngine(engine: BrowserTelemetryEngine): void;
|
|
57
|
+
recordError(code: BrowserTelemetryErrorCode): void;
|
|
58
|
+
markTelemetryFailed?(): void;
|
|
59
|
+
}
|
|
60
|
+
export declare class BrowserTelemetryCollector implements TelemetryContributor<BrowserTelemetryLogPayload, BrowserTelemetryHeaderPayload>, BrowserTelemetrySink {
|
|
61
|
+
#private;
|
|
62
|
+
readonly key: "browser";
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
redact?: (value: string) => string;
|
|
65
|
+
});
|
|
66
|
+
recordPoolAcquire(outcome: BrowserTelemetryPoolAcquireOutcome): void;
|
|
67
|
+
recordPoolAcquireUnknownCode(code: number): void;
|
|
68
|
+
recordProxyAuthChallenge(): void;
|
|
69
|
+
recordEngine(engine: BrowserTelemetryEngine): void;
|
|
70
|
+
recordError(code: BrowserTelemetryErrorCode): void;
|
|
71
|
+
markTelemetryFailed(): void;
|
|
72
|
+
toLogPayload(spans: SpanIndex): BrowserTelemetryLogPayload | undefined;
|
|
73
|
+
toHeaderPayload(log: BrowserTelemetryLogPayload): BrowserTelemetryHeaderPayload;
|
|
74
|
+
}
|
|
75
|
+
/** Defence in depth for diagnostics that accidentally contain protocol headers. */
|
|
76
|
+
export declare function stripBrowserHeaderMaterial(value: string): string;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { closedEnum, } from "./request-telemetry.js";
|
|
3
|
+
const MAX_SAMPLES = 24;
|
|
4
|
+
const SAMPLE_NAMES = new Set([
|
|
5
|
+
"browser.newPage",
|
|
6
|
+
"browser.page.goto",
|
|
7
|
+
"browser.page.fill",
|
|
8
|
+
"browser.page.click",
|
|
9
|
+
"browser.page.type",
|
|
10
|
+
"browser.page.waitForSelector",
|
|
11
|
+
"browser.evaluate",
|
|
12
|
+
"browser.content",
|
|
13
|
+
"browser.screenshot",
|
|
14
|
+
]);
|
|
15
|
+
function sampleName(name) {
|
|
16
|
+
if (name === "browser.page.evaluate")
|
|
17
|
+
return "browser.evaluate";
|
|
18
|
+
if (name === "browser.page.content")
|
|
19
|
+
return "browser.content";
|
|
20
|
+
if (name === "browser.page.screenshot")
|
|
21
|
+
return "browser.screenshot";
|
|
22
|
+
return name === "[REDACTION_FAILED]" || !SAMPLE_NAMES.has(name)
|
|
23
|
+
? "other"
|
|
24
|
+
: name;
|
|
25
|
+
}
|
|
26
|
+
function boundedDiagnostics(text, redact) {
|
|
27
|
+
let result;
|
|
28
|
+
try {
|
|
29
|
+
result = stripBrowserHeaderMaterial(redact?.(text) ?? text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return "[REDACTION_FAILED]";
|
|
33
|
+
}
|
|
34
|
+
const length = Math.min(result.length, 300);
|
|
35
|
+
const units = Buffer.alloc(length * 2);
|
|
36
|
+
for (let i = 0; i < length; i += 1)
|
|
37
|
+
units.writeUInt16LE(result.charCodeAt(i), i * 2);
|
|
38
|
+
return units.toString("utf16le");
|
|
39
|
+
}
|
|
40
|
+
function integer(value) {
|
|
41
|
+
return Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, Math.floor(Number.isFinite(value) ? value : 0)));
|
|
42
|
+
}
|
|
43
|
+
function add(a, b) {
|
|
44
|
+
return Math.min(Number.MAX_SAFE_INTEGER, integer(a) + integer(b));
|
|
45
|
+
}
|
|
46
|
+
export class BrowserTelemetryCollector {
|
|
47
|
+
key = "browser";
|
|
48
|
+
#poolAcquireOutcome;
|
|
49
|
+
#poolAcquireAttempts = 0;
|
|
50
|
+
#poolAcquireFailures = 0;
|
|
51
|
+
#poolAcquireUnknownCode;
|
|
52
|
+
#telemetryFailed = false;
|
|
53
|
+
#proxyAuthChallenges = 0;
|
|
54
|
+
#engine;
|
|
55
|
+
#lastErrorCode;
|
|
56
|
+
#redact;
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
this.#redact = options.redact;
|
|
59
|
+
}
|
|
60
|
+
recordPoolAcquire(outcome) {
|
|
61
|
+
this.#poolAcquireOutcome = outcome;
|
|
62
|
+
this.#poolAcquireAttempts = add(this.#poolAcquireAttempts, 1);
|
|
63
|
+
if (outcome !== "ok")
|
|
64
|
+
this.#poolAcquireFailures = add(this.#poolAcquireFailures, 1);
|
|
65
|
+
}
|
|
66
|
+
recordPoolAcquireUnknownCode(code) {
|
|
67
|
+
this.#poolAcquireUnknownCode = code;
|
|
68
|
+
}
|
|
69
|
+
recordProxyAuthChallenge() {
|
|
70
|
+
this.#proxyAuthChallenges = add(this.#proxyAuthChallenges, 1);
|
|
71
|
+
}
|
|
72
|
+
recordEngine(engine) {
|
|
73
|
+
this.#engine = engine;
|
|
74
|
+
}
|
|
75
|
+
recordError(code) {
|
|
76
|
+
this.#lastErrorCode = code;
|
|
77
|
+
}
|
|
78
|
+
markTelemetryFailed() {
|
|
79
|
+
this.#telemetryFailed = true;
|
|
80
|
+
}
|
|
81
|
+
toLogPayload(spans) {
|
|
82
|
+
const browserSpans = spans.spans.filter((span) => span.name === "browser.newPage" ||
|
|
83
|
+
span.name === "browser.rawPage" ||
|
|
84
|
+
span.name === "browser.withIsolatedContext" ||
|
|
85
|
+
span.name.startsWith("browser.page.") ||
|
|
86
|
+
/^browser\.(evaluate|content|screenshot)$/.test(span.name));
|
|
87
|
+
const failedSpan = spans.spans.some((span) => span.name === "[REDACTION_FAILED]");
|
|
88
|
+
if (browserSpans.length === 0 &&
|
|
89
|
+
!failedSpan &&
|
|
90
|
+
!this.#poolAcquireOutcome &&
|
|
91
|
+
this.#proxyAuthChallenges === 0 &&
|
|
92
|
+
!this.#engine &&
|
|
93
|
+
!this.#lastErrorCode &&
|
|
94
|
+
!this.#telemetryFailed)
|
|
95
|
+
return undefined;
|
|
96
|
+
const count = (name) => spans.count(name);
|
|
97
|
+
const sampleSpans = failedSpan
|
|
98
|
+
? [...browserSpans, ...spans.spans.filter((span) => span.name === "[REDACTION_FAILED]")]
|
|
99
|
+
: browserSpans;
|
|
100
|
+
const samples = sampleSpans
|
|
101
|
+
.slice(0, MAX_SAMPLES)
|
|
102
|
+
.map((span) => ({
|
|
103
|
+
name: sampleName(span.name),
|
|
104
|
+
ms: integer(span.duration_ms),
|
|
105
|
+
status: (span.status === "error" ? "error" : "ok"),
|
|
106
|
+
...(span.name === "[REDACTION_FAILED]"
|
|
107
|
+
? { diagnostics: "[REDACTION_FAILED]" }
|
|
108
|
+
: span.error
|
|
109
|
+
? { diagnostics: boundedDiagnostics(span.error, this.#redact) }
|
|
110
|
+
: {}),
|
|
111
|
+
}));
|
|
112
|
+
return {
|
|
113
|
+
allocateMs: integer(browserSpans
|
|
114
|
+
.filter((span) => span.name === "browser.newPage")
|
|
115
|
+
.reduce((sum, span) => sum + Number(span.attributes.allocate_ms ?? span.duration_ms), 0)),
|
|
116
|
+
pages: add(add(count("browser.newPage"), count("browser.rawPage")), count("browser.withIsolatedContext")),
|
|
117
|
+
navigations: integer(count("browser.page.goto")),
|
|
118
|
+
actions: ["fill", "click", "type", "waitForSelector"].reduce((sum, method) => add(sum, count(`browser.page.${method}`)), 0),
|
|
119
|
+
evaluate: add(count("browser.evaluate"), count("browser.page.evaluate")),
|
|
120
|
+
content: add(count("browser.page.content"), count("browser.content")),
|
|
121
|
+
screenshot: add(count("browser.page.screenshot"), count("browser.screenshot")),
|
|
122
|
+
...(this.#poolAcquireOutcome ? { poolAcquireOutcome: this.#poolAcquireOutcome } : {}),
|
|
123
|
+
poolAcquireAttempts: this.#poolAcquireAttempts,
|
|
124
|
+
poolAcquireFailures: this.#poolAcquireFailures,
|
|
125
|
+
...(this.#poolAcquireUnknownCode === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { poolAcquireUnknownCode: this.#poolAcquireUnknownCode }),
|
|
128
|
+
proxyAuthChallenges: this.#proxyAuthChallenges,
|
|
129
|
+
...(this.#engine ? { engine: this.#engine } : {}),
|
|
130
|
+
...(this.#lastErrorCode ? { lastErrorCode: this.#lastErrorCode } : {}),
|
|
131
|
+
samples,
|
|
132
|
+
dropped: Math.max(0, sampleSpans.length - samples.length),
|
|
133
|
+
...(this.#telemetryFailed ? { telemetryFailed: true } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
toHeaderPayload(log) {
|
|
137
|
+
return {
|
|
138
|
+
allocateMs: log.allocateMs,
|
|
139
|
+
pages: log.pages,
|
|
140
|
+
navigations: log.navigations,
|
|
141
|
+
actions: log.actions,
|
|
142
|
+
evaluate: log.evaluate,
|
|
143
|
+
content: log.content,
|
|
144
|
+
screenshot: log.screenshot,
|
|
145
|
+
...(log.poolAcquireOutcome ? { poolAcquireOutcome: closedEnum(log.poolAcquireOutcome) } : {}),
|
|
146
|
+
poolAcquireAttempts: log.poolAcquireAttempts,
|
|
147
|
+
poolAcquireFailures: log.poolAcquireFailures,
|
|
148
|
+
proxyAuthChallenges: log.proxyAuthChallenges,
|
|
149
|
+
...(log.engine ? { engine: closedEnum(log.engine) } : {}),
|
|
150
|
+
...(log.lastErrorCode ? { lastErrorCode: closedEnum(log.lastErrorCode) } : {}),
|
|
151
|
+
samples: log.samples.map((sample) => ({
|
|
152
|
+
name: closedEnum(sample.name),
|
|
153
|
+
ms: sample.ms,
|
|
154
|
+
status: closedEnum(sample.status),
|
|
155
|
+
})),
|
|
156
|
+
dropped: log.dropped,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Defence in depth for diagnostics that accidentally contain protocol headers. */
|
|
161
|
+
export function stripBrowserHeaderMaterial(value) {
|
|
162
|
+
return value
|
|
163
|
+
.replace(/(^|[^\p{L}\p{N}_-])[\t ]*(?:cookie|set-cookie|authorization)[\t ]*(?::|=)[^\r\n]*/giu, "$1[REDACTED]")
|
|
164
|
+
.replace(/"(?:cookie|set-cookie|authorization)"[\t ]*:[\t ]*"(?:\\.|[^"\\])*"/giu, "[REDACTED]");
|
|
165
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BrowserTelemetrySink } from "./browser-telemetry.js";
|
|
1
2
|
import type { BrowserChallengeRequest, BrowserChallengeResult, BrowserClient as BrowserClientContract, BrowserEngine, BrowserOptions, BrowserPage } from "../types.js";
|
|
2
3
|
type BrowserPageContract = BrowserPage;
|
|
3
4
|
export type BrowserClientOptions = BrowserOptions & {
|
|
@@ -6,6 +7,7 @@ export type BrowserClientOptions = BrowserOptions & {
|
|
|
6
7
|
executablePath?: string;
|
|
7
8
|
extraArgs?: string[];
|
|
8
9
|
serviceWorkers?: "allow" | "block";
|
|
10
|
+
telemetry?: BrowserTelemetrySink;
|
|
9
11
|
};
|
|
10
12
|
export declare class BrowserClient implements BrowserClientContract {
|
|
11
13
|
private readonly client;
|
|
@@ -13,6 +15,7 @@ export declare class BrowserClient implements BrowserClientContract {
|
|
|
13
15
|
private activePage?;
|
|
14
16
|
private readonly activePages;
|
|
15
17
|
private readonly _engine;
|
|
18
|
+
private readonly telemetry?;
|
|
16
19
|
constructor(options?: BrowserClientOptions);
|
|
17
20
|
get engine(): BrowserEngine;
|
|
18
21
|
newPage(): Promise<BrowserPageContract>;
|