@pie-players/pie-players-shared 0.3.60 → 0.3.62
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/config/profile.js +0 -1
- package/dist/i18n/index.js +0 -1
- package/dist/i18n/loader.js +0 -1
- package/dist/i18n/simple-i18n.js +0 -1
- package/dist/i18n/types.js +0 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/instrumentation/debug-panel-stream.js +0 -1
- package/dist/instrumentation/index.js +0 -1
- package/dist/instrumentation/provider-guards.js +0 -1
- package/dist/instrumentation/providers/BaseInstrumentationProvider.js +0 -1
- package/dist/instrumentation/providers/CompositeInstrumentationProvider.js +0 -1
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.js +0 -1
- package/dist/instrumentation/providers/DebugPanelInstrumentationProvider.js +0 -1
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.js +0 -1
- package/dist/instrumentation/providers/index.js +0 -1
- package/dist/instrumentation/types.js +0 -1
- package/dist/loader-config.js +0 -1
- package/dist/loaders/ElementLoader.js +0 -1
- package/dist/loaders/element-loader-types.js +0 -1
- package/dist/loaders/element-loader.js +0 -1
- package/dist/loaders/element-package-policy.js +0 -1
- package/dist/loaders/esm-adapter.js +0 -1
- package/dist/loaders/iife-adapter.js +0 -1
- package/dist/loaders/index.js +0 -1
- package/dist/object/index.js +0 -1
- package/dist/pie/asset-handler.js +0 -1
- package/dist/pie/authoring-tag.js +0 -1
- package/dist/pie/authoring.js +0 -1
- package/dist/pie/component-context.js +0 -1
- package/dist/pie/config.js +0 -1
- package/dist/pie/configure-initialization.js +0 -1
- package/dist/pie/correct-response-env.js +0 -1
- package/dist/pie/custom-element-define.js +0 -1
- package/dist/pie/index.js +0 -1
- package/dist/pie/initialization.js +0 -1
- package/dist/pie/instrumentation-event-bridge.js +0 -1
- package/dist/pie/instrumentation-event-map.js +0 -1
- package/dist/pie/instrumentation-provider-resolution.js +0 -1
- package/dist/pie/item-controller-storage.js +0 -1
- package/dist/pie/item-controller.js +0 -1
- package/dist/pie/item-session-contract.js +0 -1
- package/dist/pie/logger.js +0 -1
- package/dist/pie/math-rendering.js +0 -1
- package/dist/pie/overrides.js +0 -1
- package/dist/pie/player-initializer.js +0 -1
- package/dist/pie/registry.js +0 -1
- package/dist/pie/resource-monitor.js +0 -1
- package/dist/pie/scoring.js +0 -1
- package/dist/pie/stage-tracker.js +0 -1
- package/dist/pie/stages.js +0 -1
- package/dist/pie/tag-names.js +0 -1
- package/dist/pie/types.js +0 -1
- package/dist/pie/updates.js +0 -1
- package/dist/pie/utils.js +0 -1
- package/dist/pie/versioned-tag.js +0 -1
- package/dist/player-strategy.js +0 -1
- package/dist/security/index.js +0 -1
- package/dist/security/sanitize-item-markup.d.ts +11 -0
- package/dist/security/sanitize-item-markup.js +5 -3
- package/dist/security/sanitize-svg-icon.js +0 -1
- package/dist/security/validate-style-url.js +0 -1
- package/dist/security/wrap-model-rich-content.js +0 -1
- package/dist/security/wrap-overwide-images.js +0 -1
- package/dist/security/wrap-overwide-tables.js +0 -1
- package/dist/server/npm-registry.js +0 -1
- package/dist/types/index.js +0 -1
- package/dist/ui/content-styles.d.ts +73 -0
- package/dist/ui/content-styles.js +204 -0
- package/dist/ui/debug-panel-persistence.js +0 -1
- package/dist/ui/first-focusable.js +0 -1
- package/dist/ui/focus-trap.js +0 -1
- package/dist/ui/safe-storage.js +0 -1
- package/dist/ui/scope-css.d.ts +56 -0
- package/dist/ui/scope-css.js +310 -0
- package/dist/ui/zoom-compensation.js +0 -1
- package/package.json +9 -5
- package/dist/config/profile.js.map +0 -1
- package/dist/i18n/index.js.map +0 -1
- package/dist/i18n/loader.js.map +0 -1
- package/dist/i18n/simple-i18n.js.map +0 -1
- package/dist/i18n/types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation/debug-panel-stream.js.map +0 -1
- package/dist/instrumentation/index.js.map +0 -1
- package/dist/instrumentation/provider-guards.js.map +0 -1
- package/dist/instrumentation/providers/BaseInstrumentationProvider.js.map +0 -1
- package/dist/instrumentation/providers/CompositeInstrumentationProvider.js.map +0 -1
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.js.map +0 -1
- package/dist/instrumentation/providers/DebugPanelInstrumentationProvider.js.map +0 -1
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.js.map +0 -1
- package/dist/instrumentation/providers/index.js.map +0 -1
- package/dist/instrumentation/types.js.map +0 -1
- package/dist/loader-config.js.map +0 -1
- package/dist/loaders/ElementLoader.js.map +0 -1
- package/dist/loaders/element-loader-types.js.map +0 -1
- package/dist/loaders/element-loader.js.map +0 -1
- package/dist/loaders/element-package-policy.js.map +0 -1
- package/dist/loaders/esm-adapter.js.map +0 -1
- package/dist/loaders/iife-adapter.js.map +0 -1
- package/dist/loaders/index.js.map +0 -1
- package/dist/object/index.js.map +0 -1
- package/dist/pie/asset-handler.js.map +0 -1
- package/dist/pie/authoring-tag.js.map +0 -1
- package/dist/pie/authoring.js.map +0 -1
- package/dist/pie/component-context.js.map +0 -1
- package/dist/pie/config.js.map +0 -1
- package/dist/pie/configure-initialization.js.map +0 -1
- package/dist/pie/correct-response-env.js.map +0 -1
- package/dist/pie/custom-element-define.js.map +0 -1
- package/dist/pie/index.js.map +0 -1
- package/dist/pie/initialization.js.map +0 -1
- package/dist/pie/instrumentation-event-bridge.js.map +0 -1
- package/dist/pie/instrumentation-event-map.js.map +0 -1
- package/dist/pie/instrumentation-provider-resolution.js.map +0 -1
- package/dist/pie/item-controller-storage.js.map +0 -1
- package/dist/pie/item-controller.js.map +0 -1
- package/dist/pie/item-session-contract.js.map +0 -1
- package/dist/pie/logger.js.map +0 -1
- package/dist/pie/math-rendering.js.map +0 -1
- package/dist/pie/overrides.js.map +0 -1
- package/dist/pie/player-initializer.js.map +0 -1
- package/dist/pie/registry.js.map +0 -1
- package/dist/pie/resource-monitor.js.map +0 -1
- package/dist/pie/scoring.js.map +0 -1
- package/dist/pie/stage-tracker.js.map +0 -1
- package/dist/pie/stages.js.map +0 -1
- package/dist/pie/tag-names.js.map +0 -1
- package/dist/pie/types.js.map +0 -1
- package/dist/pie/updates.js.map +0 -1
- package/dist/pie/utils.js.map +0 -1
- package/dist/pie/versioned-tag.js.map +0 -1
- package/dist/player-strategy.js.map +0 -1
- package/dist/security/index.js.map +0 -1
- package/dist/security/sanitize-item-markup.js.map +0 -1
- package/dist/security/sanitize-svg-icon.js.map +0 -1
- package/dist/security/validate-style-url.js.map +0 -1
- package/dist/security/wrap-model-rich-content.js.map +0 -1
- package/dist/security/wrap-overwide-images.js.map +0 -1
- package/dist/security/wrap-overwide-tables.js.map +0 -1
- package/dist/server/npm-registry.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/ui/debug-panel-persistence.js.map +0 -1
- package/dist/ui/first-focusable.js.map +0 -1
- package/dist/ui/focus-trap.js.map +0 -1
- package/dist/ui/safe-storage.js.map +0 -1
- package/dist/ui/zoom-compensation.js.map +0 -1
package/dist/i18n/loader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/i18n/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wCAAwC;AACxC,OAAO,QAAQ,MAAM,+BAA+B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC3E,OAAO,SAAS,MAAM,gCAAgC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC7E,OAAO,OAAO,MAAM,8BAA8B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAGzE,cAAc;AACd,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsC;IACtE,EAAE,EAAE;QACH,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,KAAK;QAChB,YAAY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CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IAClC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACzC,OAAO,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/**\n * Translation Loader\n *\n * Implements hybrid loading strategy:\n * - English bundled with application\n * - Other languages loaded on demand\n *\n * Part of PIE Players i18n system.\n */\n\n// Import English translations (bundled)\nimport enCommon from \"./translations/en/common.json\" with { type: \"json\" };\nimport enToolkit from \"./translations/en/toolkit.json\" with { type: \"json\" };\nimport enTools from \"./translations/en/tools.json\" with { type: \"json\" };\nimport type { TranslationBundle } from \"./types.js\";\n\n// RTL locales\nconst RTL_LOCALES = [\"ar\", \"he\", \"fa\", \"ur\"];\n\n/**\n * Bundled English translations\n * Available immediately without network request\n */\nexport const BUNDLED_TRANSLATIONS: Record<string, TranslationBundle> = {\n\ten: {\n\t\tlocale: \"en\",\n\t\tdirection: \"ltr\",\n\t\ttranslations: {\n\t\t\t...flattenTranslations(enCommon),\n\t\t\t...flattenTranslations(enToolkit),\n\t\t\t...flattenTranslations(enTools),\n\t\t},\n\t},\n};\n\nconst LOCALE_IMPORTS: Record<string, () => Promise<[any, any, any]>> = {\n\tes: () =>\n\t\tPromise.all([\n\t\t\timport(\"./translations/es/common.json\"),\n\t\t\timport(\"./translations/es/toolkit.json\"),\n\t\t\timport(\"./translations/es/tools.json\"),\n\t\t]),\n\tzh: () =>\n\t\tPromise.all([\n\t\t\timport(\"./translations/zh/common.json\"),\n\t\t\timport(\"./translations/zh/toolkit.json\"),\n\t\t\timport(\"./translations/zh/tools.json\"),\n\t\t]),\n\tar: () =>\n\t\tPromise.all([\n\t\t\timport(\"./translations/ar/common.json\"),\n\t\t\timport(\"./translations/ar/toolkit.json\"),\n\t\t\timport(\"./translations/ar/tools.json\"),\n\t\t]),\n};\n\n/**\n * Load translations for a locale\n *\n * @param locale Locale code (e.g., 'en', 'es', 'zh', 'ar')\n * @returns Translation bundle with flattened keys\n */\nexport async function loadTranslations(\n\tlocale: string,\n): Promise<TranslationBundle> {\n\t// Return bundled English immediately\n\tif (locale === \"en\") {\n\t\treturn BUNDLED_TRANSLATIONS.en;\n\t}\n\n\tconst importer = LOCALE_IMPORTS[locale];\n\tif (!importer) {\n\t\tthrow new Error(\n\t\t\t`Translation files not found for locale: ${locale}. Ensure translation files exist in packages/players-shared/src/i18n/translations/${locale}/`,\n\t\t);\n\t}\n\n\t// Lazy load other locales\n\ttry {\n\t\tconst [common, toolkit, tools] = await importer();\n\n\t\treturn {\n\t\t\tlocale,\n\t\t\tdirection: RTL_LOCALES.includes(locale) ? \"rtl\" : \"ltr\",\n\t\t\ttranslations: {\n\t\t\t\t...flattenTranslations(common.default || common),\n\t\t\t\t...flattenTranslations(toolkit.default || toolkit),\n\t\t\t\t...flattenTranslations(tools.default || tools),\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(`Failed to load translations for locale: ${locale}`, error);\n\t\tthrow new Error(\n\t\t\t`Translation files not found for locale: ${locale}. Ensure translation files exist in packages/players-shared/src/i18n/translations/${locale}/`,\n\t\t);\n\t}\n}\n\n/**\n * Flatten nested JSON to dot notation\n *\n * Converts:\n * { \"common\": { \"save\": \"Save\" } }\n *\n * To:\n * { \"common.save\": \"Save\" }\n *\n * @param obj Nested translation object\n * @param prefix Current key prefix\n * @param result Accumulated result\n * @returns Flattened translation object\n */\nfunction flattenTranslations(\n\tobj: any,\n\tprefix = \"\",\n\tresult: Record<string, any> = {},\n): Record<string, any> {\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tconst newKey = prefix ? `${prefix}.${key}` : key;\n\n\t\tif (value && typeof value === \"object\" && !Array.isArray(value)) {\n\t\t\t// Check if it's a plural form (has 'one' or 'other' keys)\n\t\t\tif (\"one\" in value || \"other\" in value) {\n\t\t\t\t// This is a plural translation, keep it as an object\n\t\t\t\tresult[newKey] = value;\n\t\t\t} else {\n\t\t\t\t// This is a nested object, flatten recursively\n\t\t\t\tflattenTranslations(value, newKey, result);\n\t\t\t}\n\t\t} else {\n\t\t\t// This is a leaf value\n\t\t\tresult[newKey] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Get available locales\n *\n * @returns Array of locale codes\n */\nexport function getAvailableLocales(): string[] {\n\treturn [\"en\", \"es\", \"zh\", \"ar\"];\n}\n\n/**\n * Check if locale is RTL\n *\n * @param locale Locale code\n * @returns True if locale is right-to-left\n */\nexport function isRTLLocale(locale: string): boolean {\n\treturn RTL_LOCALES.includes(locale);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple-i18n.js","sourceRoot":"","sources":["../../src/i18n/simple-i18n.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;GAEG;AACH,MAAM,OAAO,UAAU;IACd,MAAM,GAAW,IAAI,CAAC;IACtB,cAAc,GAAW,IAAI,CAAC;IAC9B,SAAS,GAAkB,KAAK,CAAC;IACjC,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;IACpD,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAClC,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,MAAM,CAAa;IAE3B,YAAY,SAAqB,EAAE;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAEpD,4BAA4B;QAC5B,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAChC,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAC5C,MAAM,CAAC,mBAAmB,CAC1B,EAA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,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACrC,OAAO,QAAmC,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACR,+BAA+B;YAChC,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QAC/B,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC9B,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,mBAAmB;QAC1B,IAAI,OAAO,SAAS,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAElD,MAAM,WAAW,GAChB,SAAS,CAAC,QAAQ;YAClB,CAAC,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC;QAEN,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * Simple I18n Implementation\n *\n * Lightweight i18n without external dependencies.\n * Used for standalone components that don't need the full service architecture.\n */\n\nimport type {\n\tI18nConfig,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"./types.js\";\n\n/**\n * Simple I18n class for standalone use\n */\nexport class SimpleI18n {\n\tprivate locale: string = \"en\";\n\tprivate fallbackLocale: string = \"en\";\n\tprivate direction: \"ltr\" | \"rtl\" = \"ltr\";\n\tprivate translations = new Map<string, TranslationBundle>();\n\tprivate listeners = new Set<() => void>();\n\tprivate loadingPromises = new Map<string, Promise<void>>();\n\tprivate config: I18nConfig;\n\n\tconstructor(config: I18nConfig = {}) {\n\t\tthis.config = config;\n\t\tthis.fallbackLocale = config.fallbackLocale || \"en\";\n\n\t\t// Load bundled translations\n\t\tif (config.bundledTranslations) {\n\t\t\tfor (const [locale, bundle] of Object.entries(\n\t\t\t\tconfig.bundledTranslations,\n\t\t\t)) {\n\t\t\t\tthis.translations.set(locale, bundle);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Initialize with locale\n\t */\n\tasync initialize(config: I18nConfig): Promise<void> {\n\t\tObject.assign(this.config, config);\n\n\t\tconst locale = config.locale || this.detectBrowserLocale();\n\t\tawait this.setLocale(locale);\n\t}\n\n\t/**\n\t * Translate a key\n\t */\n\tt(key: string, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\t\treturn this.interpolate(translation as string, params);\n\t}\n\n\t/**\n\t * Translate with pluralization\n\t */\n\ttn(key: string, count: number, params?: Record<string, any>): string {\n\t\tconst translation = this.getTranslation(key);\n\n\t\tif (typeof translation === \"object\") {\n\t\t\tconst pluralForm = this.selectPluralForm(count, this.locale);\n\t\t\tconst text = translation[pluralForm] || translation.other;\n\t\t\treturn this.interpolate(text, { ...params, count });\n\t\t}\n\n\t\treturn this.interpolate(translation as string, { ...params, count });\n\t}\n\n\t/**\n\t * Get current locale\n\t */\n\tgetLocale(): string {\n\t\treturn this.locale;\n\t}\n\n\t/**\n\t * Change locale\n\t */\n\tasync setLocale(locale: string): Promise<void> {\n\t\t// Check if already loading\n\t\tif (this.loadingPromises.has(locale)) {\n\t\t\tawait this.loadingPromises.get(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if already loaded\n\t\tif (this.translations.has(locale)) {\n\t\t\tthis.applyLocale(locale);\n\t\t\treturn;\n\t\t}\n\n\t\t// Load translations\n\t\tconst loadingPromise = this.loadTranslationsForLocale(locale);\n\t\tthis.loadingPromises.set(locale, loadingPromise);\n\n\t\ttry {\n\t\t\tawait loadingPromise;\n\t\t\tthis.applyLocale(locale);\n\t\t} finally {\n\t\t\tthis.loadingPromises.delete(locale);\n\t\t}\n\t}\n\n\t/**\n\t * Get current direction\n\t */\n\tgetDirection(): \"ltr\" | \"rtl\" {\n\t\treturn this.direction;\n\t}\n\n\t/**\n\t * Get available locales\n\t */\n\tgetAvailableLocales(): string[] {\n\t\treturn Array.from(this.translations.keys());\n\t}\n\n\t/**\n\t * Check if locale is loaded\n\t */\n\tisLocaleLoaded(locale: string): boolean {\n\t\treturn this.translations.has(locale);\n\t}\n\n\t/**\n\t * Subscribe to changes\n\t */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/**\n\t * Check if key exists\n\t */\n\thasKey(key: string): boolean {\n\t\tconst bundle = this.translations.get(this.locale);\n\t\treturn !!bundle?.translations[key];\n\t}\n\n\tprivate notifyListeners(): void {\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener();\n\t\t}\n\t}\n\n\tprivate applyLocale(locale: string): void {\n\t\tconst bundle = this.translations.get(locale);\n\t\tif (!bundle) return;\n\n\t\tthis.locale = locale;\n\t\tthis.direction = bundle.direction;\n\n\t\tthis.applyDOMDirection();\n\t\tthis.notifyListeners();\n\t}\n\n\tprivate applyDOMDirection(): void {\n\t\tif (typeof document === \"undefined\") return;\n\n\t\tdocument.documentElement.setAttribute(\"dir\", this.direction);\n\t\tdocument.documentElement.setAttribute(\"lang\", this.locale);\n\t}\n\n\tprivate async loadTranslationsForLocale(locale: string): Promise<void> {\n\t\tif (!this.config.loadTranslations) {\n\t\t\tthrow new Error(`No translation loader configured for locale: ${locale}`);\n\t\t}\n\n\t\tconst bundle = await this.config.loadTranslations(locale);\n\t\tthis.translations.set(locale, bundle);\n\t}\n\n\tprivate getTranslation(key: string): string | PluralTranslation {\n\t\t// Try current locale\n\t\tconst currentBundle = this.translations.get(this.locale);\n\t\tif (currentBundle?.translations[key]) {\n\t\t\treturn currentBundle.translations[key];\n\t\t}\n\n\t\t// Try fallback locale\n\t\tconst fallbackBundle = this.translations.get(this.fallbackLocale);\n\t\tif (fallbackBundle?.translations[key]) {\n\t\t\treturn fallbackBundle.translations[key];\n\t\t}\n\n\t\t// Missing key\n\t\tif (this.config.onMissingKey) {\n\t\t\tthis.config.onMissingKey(key, this.locale);\n\t\t}\n\n\t\treturn key;\n\t}\n\n\tprivate interpolate(text: string, params?: Record<string, any>): string {\n\t\tif (!params) return text;\n\n\t\treturn text.replace(/\\{(\\w+)\\}/g, (match, key) => {\n\t\t\treturn params[key]?.toString() || match;\n\t\t});\n\t}\n\n\tprivate selectPluralForm(\n\t\tcount: number,\n\t\tlocale: string,\n\t): keyof PluralTranslation {\n\t\t// Use Intl.PluralRules if available\n\t\tif (typeof Intl !== \"undefined\" && Intl.PluralRules) {\n\t\t\ttry {\n\t\t\t\tconst rules = new Intl.PluralRules(locale);\n\t\t\t\tconst category = rules.select(count);\n\t\t\t\treturn category as keyof PluralTranslation;\n\t\t\t} catch {\n\t\t\t\t// Fall through to simple rules\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to simple rules\n\t\tif (count === 0) return \"zero\";\n\t\tif (count === 1) return \"one\";\n\t\treturn \"other\";\n\t}\n\n\tprivate detectBrowserLocale(): string {\n\t\tif (typeof navigator === \"undefined\") return \"en\";\n\n\t\tconst browserLang =\n\t\t\tnavigator.language ||\n\t\t\t(navigator.languages && navigator.languages[0]) ||\n\t\t\t\"en\";\n\n\t\treturn browserLang.split(\"-\")[0];\n\t}\n}\n"]}
|
package/dist/i18n/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/i18n/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * I18n Type Definitions\n *\n * Shared types for internationalization system.\n * Defined in players-shared to avoid circular dependencies.\n */\n\n/**\n * Plural translation forms\n * Follows ICU MessageFormat plural rules\n */\nexport interface PluralTranslation {\n\tzero?: string;\n\tone: string;\n\tfew?: string;\n\tmany?: string;\n\tother: string;\n}\n\n/**\n * Translation bundle structure\n */\nexport interface TranslationBundle {\n\tlocale: string;\n\ttranslations: Record<string, string | PluralTranslation>;\n\tdirection: \"ltr\" | \"rtl\";\n}\n\n/**\n * I18n configuration\n */\nexport interface I18nConfig {\n\t/** Initial locale (default: browser language) */\n\tlocale?: string;\n\n\t/** Fallback locale (default: 'en') */\n\tfallbackLocale?: string;\n\n\t/** Translation loader function */\n\tloadTranslations?: (locale: string) => Promise<TranslationBundle>;\n\n\t/** Bundled translations (for hybrid loading) */\n\tbundledTranslations?: Record<string, TranslationBundle>;\n\n\t/** Missing key handler */\n\tonMissingKey?: (key: string, locale: string) => void;\n\n\t/** Debug mode */\n\tdebug?: boolean;\n}\n\n/**\n * I18nService API contract\n */\nexport interface I18nServiceApi {\n\tinitialize(config: I18nConfig): Promise<void>;\n\tt(key: string, params?: Record<string, any>): string;\n\ttn(key: string, count: number, params?: Record<string, any>): string;\n\tgetLocale(): string;\n\tsetLocale(locale: string): Promise<void>;\n\tgetDirection(): \"ltr\" | \"rtl\";\n\tgetAvailableLocales(): string[];\n\tisLocaleLoaded(locale: string): boolean;\n\tsubscribe(listener: () => void): () => void;\n\thasKey(key: string): boolean;\n}\n"]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,0CAA0C;AAC1C,cAAc,gBAAgB,CAAC;AAuB/B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC","sourcesContent":["export * from \"./config/profile.js\";\nexport * from \"./instrumentation/index.js\";\nexport * from \"./loader-config.js\";\nexport * from \"./player-strategy.js\";\nexport * from \"./security/index.js\";\nexport * from \"./loaders/index.js\";\nexport * from \"./object/index.js\";\n// Barrel export for PIE runtime utilities\nexport * from \"./pie/index.js\";\nexport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n\tAssessmentSection,\n\tAdvancedItemConfig,\n\tConfigEntity,\n\tConfigResource,\n\tEnv,\n\tItemConfig,\n\tItemEntity,\n\tItemSession,\n\tOutcomeResponse,\n\tPassageEntity,\n\tPieController,\n\tPieContent,\n\tPieDefaultModel,\n\tPieItemElement,\n\tPieModel,\n\tQuestionEntity,\n\tRubricBlock,\n\tTestPart,\n} from \"./types/index.js\";\nexport { editorPostFix } from \"./types/index.js\";\nexport * from \"./ui/focus-trap.js\";\nexport * from \"./ui/first-focusable.js\";\nexport * from \"./ui/debug-panel-persistence.js\";\nexport * from \"./ui/safe-storage.js\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-panel-stream.js","sourceRoot":"","sources":["../../src/instrumentation/debug-panel-stream.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,gCAAgC,GAC5C,kCAAkC,CAAC;AACpC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAoC9B,SAAS,cAAc;IACtB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC/C,OAAO,MAAwB,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CAAC,WAA2B;IACjD,IAAI,CAAC,WAAW,CAAC,8BAA8B,EAAE,CAAC;QACjD,WAAW,CAAC,8BAA8B,GAAG;YAC5C,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,EAAE;SACX,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC,8BAA8B,CAAC;AACnD,CAAC;AAED,SAAS,WAAW,CACnB,MAAkC;IAElC,OAAO;QACN,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS;KACpE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,8BA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AE,EAAE,GAAI,IAAI,CAAC,UAAsC,EAAE;QAC/D,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,eAAe;QACpD,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK;KAC7B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAMvC;IACA,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,IAAI,EAAE,IAAI,CAAC,UAAU;QACrB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC1B,CAAC,CAAC,EAAE,GAAI,IAAI,CAAC,UAAsC,EAAE;YACrD,CAAC,CAAC,SAAS;KACZ,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tErrorAttributes,\n\tEventAttributes,\n\tMetricAttributes,\n} from \"./types.js\";\n\nexport const INSTRUMENTATION_DEBUG_EVENT_NAME =\n\t\"pie-instrumentation-debug-record\";\nconst MAX_DEBUG_RECORDS = 500;\n\ntype DebugRecordKind =\n\t| \"event\"\n\t| \"error\"\n\t| \"metric\"\n\t| \"user-context\"\n\t| \"global-attributes\";\n\nexport type InstrumentationDebugRecord = {\n\tid: number;\n\tkind: DebugRecordKind;\n\tproviderId: string;\n\tproviderName: string;\n\ttimestamp: string;\n\tname: string;\n\tattributes?: Record<string, unknown>;\n\terrorMessage?: string;\n\terrorStack?: string;\n\tvalue?: number;\n};\n\nexport type InstrumentationDebugRecordInput = Omit<\n\tInstrumentationDebugRecord,\n\t\"id\"\n>;\n\ntype DebugWindowState = {\n\tnextId: number;\n\trecords: InstrumentationDebugRecord[];\n};\n\ntype PieDebugWindow = Window & {\n\t__pieInstrumentationDebugState?: DebugWindowState;\n};\n\nfunction getDebugWindow(): PieDebugWindow | null {\n\tif (typeof window === \"undefined\") return null;\n\treturn window as PieDebugWindow;\n}\n\nfunction getDebugState(debugWindow: PieDebugWindow): DebugWindowState {\n\tif (!debugWindow.__pieInstrumentationDebugState) {\n\t\tdebugWindow.__pieInstrumentationDebugState = {\n\t\t\tnextId: 1,\n\t\t\trecords: [],\n\t\t};\n\t}\n\treturn debugWindow.__pieInstrumentationDebugState;\n}\n\nfunction cloneRecord(\n\trecord: InstrumentationDebugRecord,\n): InstrumentationDebugRecord {\n\treturn {\n\t\t...record,\n\t\tattributes: record.attributes ? { ...record.attributes } : undefined,\n\t};\n}\n\nexport function emitInstrumentationDebugRecord(\n\trecord: InstrumentationDebugRecordInput,\n): void {\n\tconst debugWindow = getDebugWindow();\n\tif (!debugWindow) return;\n\tconst state = getDebugState(debugWindow);\n\tconst nextRecord: InstrumentationDebugRecord = {\n\t\t...record,\n\t\tid: state.nextId++,\n\t};\n\tstate.records.push(nextRecord);\n\tif (state.records.length > MAX_DEBUG_RECORDS) {\n\t\tstate.records.splice(0, state.records.length - MAX_DEBUG_RECORDS);\n\t}\n\tdebugWindow.dispatchEvent(\n\t\tnew CustomEvent<InstrumentationDebugRecord>(\n\t\t\tINSTRUMENTATION_DEBUG_EVENT_NAME,\n\t\t\t{\n\t\t\t\tdetail: cloneRecord(nextRecord),\n\t\t\t},\n\t\t),\n\t);\n}\n\nexport function getBufferedInstrumentationDebugRecords(): InstrumentationDebugRecord[] {\n\tconst debugWindow = getDebugWindow();\n\tif (!debugWindow) return [];\n\tconst state = getDebugState(debugWindow);\n\treturn state.records.map(cloneRecord);\n}\n\nexport function clearBufferedInstrumentationDebugRecords(): void {\n\tconst debugWindow = getDebugWindow();\n\tif (!debugWindow) return;\n\tconst state = getDebugState(debugWindow);\n\tstate.records = [];\n}\n\nexport function subscribeInstrumentationDebugRecords(args: {\n\tlistener: (record: InstrumentationDebugRecord) => void;\n\treplayBuffered?: boolean;\n}): () => void {\n\tconst debugWindow = getDebugWindow();\n\tif (!debugWindow) return () => {};\n\n\tif (args.replayBuffered !== false) {\n\t\tconst records = getBufferedInstrumentationDebugRecords();\n\t\tfor (const record of records) {\n\t\t\targs.listener(record);\n\t\t}\n\t}\n\n\tconst onDebugRecord = (event: Event) => {\n\t\tconst customEvent = event as CustomEvent<InstrumentationDebugRecord>;\n\t\tif (!customEvent.detail) return;\n\t\targs.listener(cloneRecord(customEvent.detail));\n\t};\n\tdebugWindow.addEventListener(INSTRUMENTATION_DEBUG_EVENT_NAME, onDebugRecord);\n\treturn () => {\n\t\tdebugWindow.removeEventListener(\n\t\t\tINSTRUMENTATION_DEBUG_EVENT_NAME,\n\t\t\tonDebugRecord,\n\t\t);\n\t};\n}\n\nexport function createEventDebugRecord(args: {\n\tproviderId: string;\n\tproviderName: string;\n\teventName: string;\n\tattributes: EventAttributes;\n}): InstrumentationDebugRecordInput {\n\treturn {\n\t\tkind: \"event\",\n\t\tproviderId: args.providerId,\n\t\tproviderName: args.providerName,\n\t\tname: args.eventName,\n\t\ttimestamp: new Date().toISOString(),\n\t\tattributes: { ...(args.attributes as Record<string, unknown>) },\n\t};\n}\n\nexport function createErrorDebugRecord(args: {\n\tproviderId: string;\n\tproviderName: string;\n\terror: Error;\n\tattributes: ErrorAttributes;\n}): InstrumentationDebugRecordInput {\n\treturn {\n\t\tkind: \"error\",\n\t\tproviderId: args.providerId,\n\t\tproviderName: args.providerName,\n\t\tname: args.attributes.errorType || \"unknown-error\",\n\t\ttimestamp: new Date().toISOString(),\n\t\tattributes: { ...(args.attributes as Record<string, unknown>) },\n\t\terrorMessage: args.error?.message || \"Unknown error\",\n\t\terrorStack: args.error?.stack,\n\t};\n}\n\nexport function createMetricDebugRecord(args: {\n\tproviderId: string;\n\tproviderName: string;\n\tmetricName: string;\n\tvalue: number;\n\tattributes?: MetricAttributes;\n}): InstrumentationDebugRecordInput {\n\treturn {\n\t\tkind: \"metric\",\n\t\tproviderId: args.providerId,\n\t\tproviderName: args.providerName,\n\t\tname: args.metricName,\n\t\ttimestamp: new Date().toISOString(),\n\t\tvalue: args.value,\n\t\tattributes: args.attributes\n\t\t\t? { ...(args.attributes as Record<string, unknown>) }\n\t\t\t: undefined,\n\t};\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,YAAY;AACZ,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EACN,wCAAwC,EACxC,sCAAsC,EACtC,gCAAgC,EAChC,oCAAoC,GACpC,MAAM,yBAAyB,CAAC","sourcesContent":["/**\n * Instrumentation Module\n *\n * Provides pluggable instrumentation for PIE players.\n * Supports multiple providers (New Relic, console logging, custom, etc.)\n *\n * @example Using New Relic (default)\n * ```typescript\n * import { NewRelicInstrumentationProvider } from '@pie-players/pie-players-shared';\n *\n * const provider = new NewRelicInstrumentationProvider();\n * await provider.initialize();\n *\n * const monitor = new ResourceMonitor({\n * trackPageActions: true,\n * instrumentationProvider: provider\n * });\n * ```\n * @example Using console logger for development\n * ```typescript\n * import { ConsoleInstrumentationProvider } from '@pie-players/pie-players-shared';\n *\n * const provider = new ConsoleInstrumentationProvider();\n * await provider.initialize({ debug: true });\n *\n * const monitor = new ResourceMonitor({\n * trackPageActions: true,\n * instrumentationProvider: provider\n * });\n * ```\n */\n\n// Providers\nexport * from \"./providers/index.js\";\nexport { isInstrumentationProvider } from \"./provider-guards.js\";\nexport {\n\tclearBufferedInstrumentationDebugRecords,\n\tgetBufferedInstrumentationDebugRecords,\n\tINSTRUMENTATION_DEBUG_EVENT_NAME,\n\tsubscribeInstrumentationDebugRecords,\n} from \"./debug-panel-stream.js\";\nexport type { InstrumentationDebugRecord } from \"./debug-panel-stream.js\";\n// Core types\nexport type {\n\tErrorAttributes,\n\tEventAttributes,\n\tInstrumentationConfig,\n\tInstrumentationProvider,\n\tMetricAttributes,\n} from \"./types.js\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider-guards.js","sourceRoot":"","sources":["../../src/instrumentation/provider-guards.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,yBAAyB,CACxC,KAAc;IAEd,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,SAAS,GAAG,KAAgC,CAAC;IACnD,OAAO,CACN,OAAO,SAAS,CAAC,UAAU,KAAK,QAAQ;QACxC,OAAO,SAAS,CAAC,YAAY,KAAK,QAAQ;QAC1C,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU;QAC1C,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU;QAC1C,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU;QAC1C,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU;QACvC,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU,CACvC,CAAC;AACH,CAAC","sourcesContent":["import type { InstrumentationProvider } from \"./types.js\";\n\nexport function isInstrumentationProvider(\n\tvalue: unknown,\n): value is InstrumentationProvider {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst candidate = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof candidate.providerId === \"string\" &&\n\t\ttypeof candidate.providerName === \"string\" &&\n\t\ttypeof candidate.initialize === \"function\" &&\n\t\ttypeof candidate.trackError === \"function\" &&\n\t\ttypeof candidate.trackEvent === \"function\" &&\n\t\ttypeof candidate.destroy === \"function\" &&\n\t\ttypeof candidate.isReady === \"function\"\n\t);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseInstrumentationProvider.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/BaseInstrumentationProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH;;;;;;;;;GASG;AACH,MAAM,OAAgB,2BAA2B;IA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B,EAAE,SAAS,CAAC,CAAC;gBACrE,CAAC;gBACD,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACO,mBAAmB,CAC5B,UAA+B;QAE/B,IAAI,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,UAAiC,CAAC;IAC1C,CAAC;CACD","sourcesContent":["/**\n * Base Instrumentation Provider\n *\n * Abstract base class that implements common instrumentation logic for all providers.\n * Provides a template method pattern for tracking errors and events with consistent\n * filtering, transformation, and sampling behavior.\n *\n * Concrete providers only need to implement the actual tracking methods specific\n * to their instrumentation backend (New Relic, DataDog, etc.)\n */\n\nimport type {\n\tErrorAttributes,\n\tEventAttributes,\n\tInstrumentationConfig,\n\tInstrumentationProvider,\n\tMetricAttributes,\n} from \"../types.js\";\n\n/**\n * Abstract base class for instrumentation providers\n *\n * Implements the template method pattern:\n * 1. Checks if provider is ready\n * 2. Applies filters (errorFilter, eventFilter)\n * 3. Applies sampling (sampleRate)\n * 4. Transforms attributes (attributeTransformer)\n * 5. Delegates to concrete provider implementation (doTrackError, doTrackEvent, etc.)\n */\nexport abstract class BaseInstrumentationProvider\n\timplements InstrumentationProvider\n{\n\tabstract readonly providerId: string;\n\tabstract readonly providerName: string;\n\n\tprotected initialized = false;\n\tprotected config?: InstrumentationConfig;\n\n\t/**\n\t * Initialize the provider with configuration\n\t *\n\t * Concrete providers should override this method to perform provider-specific\n\t * initialization (e.g., loading SDK, checking global objects, etc.)\n\t *\n\t * @param config Optional configuration\n\t */\n\tabstract initialize(config?: InstrumentationConfig): Promise<void>;\n\n\t/**\n\t * Check if provider is ready to track events\n\t *\n\t * Concrete providers should override this method to check provider-specific\n\t * readiness (e.g., SDK loaded, global object available, etc.)\n\t *\n\t * @returns true if provider is ready\n\t */\n\tabstract isReady(): boolean;\n\n\t/**\n\t * Cleanup provider resources\n\t *\n\t * Concrete providers should override this method to perform provider-specific\n\t * cleanup (e.g., disconnect SDK, clear listeners, etc.)\n\t */\n\tabstract destroy(): void;\n\n\t// ============================================================================\n\t// Abstract methods that concrete providers MUST implement\n\t// ============================================================================\n\n\t/**\n\t * Track an error with the instrumentation backend\n\t *\n\t * Called by trackError() after all filters and transforms have been applied.\n\t * Concrete providers should implement the actual error tracking here.\n\t *\n\t * @param error The error to track\n\t * @param attributes Transformed and filtered attributes\n\t */\n\tprotected abstract doTrackError(\n\t\terror: Error,\n\t\tattributes: Record<string, any>,\n\t): void;\n\n\t/**\n\t * Track an event with the instrumentation backend\n\t *\n\t * Called by trackEvent() after all filters and transforms have been applied.\n\t * Concrete providers should implement the actual event tracking here.\n\t *\n\t * @param eventName Name of the event\n\t * @param attributes Transformed and filtered attributes\n\t */\n\tprotected abstract doTrackEvent(\n\t\teventName: string,\n\t\tattributes: Record<string, any>,\n\t): void;\n\n\t/**\n\t * Set user context in the instrumentation backend\n\t *\n\t * Called by setUserContext() after readiness check.\n\t * Concrete providers should implement the actual user context setting here.\n\t *\n\t * @param userId User identifier\n\t * @param attributes Optional user attributes\n\t */\n\tprotected abstract doSetUserContext(\n\t\tuserId: string,\n\t\tattributes?: Record<string, any>,\n\t): void;\n\n\t/**\n\t * Set global attributes in the instrumentation backend\n\t *\n\t * Called by setGlobalAttributes() after readiness check.\n\t * Concrete providers should implement the actual global attribute setting here.\n\t *\n\t * @param attributes Attributes to set globally\n\t */\n\tprotected abstract doSetGlobalAttributes(\n\t\tattributes: Record<string, any>,\n\t): void;\n\n\t// ============================================================================\n\t// Public API methods (template methods)\n\t// ============================================================================\n\n\t/**\n\t * Track an error with the instrumentation provider\n\t *\n\t * Template method that:\n\t * 1. Checks if provider is ready\n\t * 2. Applies error filter if configured\n\t * 3. Transforms attributes if configured\n\t * 4. Delegates to concrete provider implementation (doTrackError)\n\t *\n\t * @param error The error to track\n\t * @param attributes Contextual attributes\n\t */\n\ttrackError(error: Error, attributes: ErrorAttributes): void {\n\t\t// Guard: check if provider is ready\n\t\tif (!this.guardedOperation(\"trackError\", error, attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Apply error filter\n\t\tif (!this.applyErrorFilter(error, attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Transform attributes\n\t\tconst finalAttributes = this.transformAttributes(attributes);\n\n\t\t// Delegate to concrete provider\n\t\ttry {\n\t\t\tthis.doTrackError(error, finalAttributes);\n\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Tracked error:`,\n\t\t\t\t\terror,\n\t\t\t\t\tfinalAttributes,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(`[${this.providerName}] Error tracking error:`, err);\n\t\t}\n\t}\n\n\t/**\n\t * Track a custom event with the instrumentation provider\n\t *\n\t * Template method that:\n\t * 1. Checks if provider is ready\n\t * 2. Applies event filter if configured\n\t * 3. Applies sampling if configured\n\t * 4. Transforms attributes if configured\n\t * 5. Adds timestamp if not present\n\t * 6. Delegates to concrete provider implementation (doTrackEvent)\n\t *\n\t * @param eventName Name of the event\n\t * @param attributes Event attributes\n\t */\n\ttrackEvent(eventName: string, attributes: EventAttributes): void {\n\t\t// Guard: check if provider is ready\n\t\tif (!this.guardedOperation(\"trackEvent\", eventName, attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Apply event filter\n\t\tif (!this.applyEventFilter(eventName, attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Apply sampling\n\t\tif (!this.applySampling(eventName)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Transform attributes\n\t\tlet finalAttributes = this.transformAttributes(attributes);\n\n\t\t// Add timestamp if not present\n\t\tif (!finalAttributes.timestamp) {\n\t\t\tfinalAttributes = {\n\t\t\t\t...finalAttributes,\n\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t};\n\t\t}\n\n\t\t// Delegate to concrete provider\n\t\ttry {\n\t\t\tthis.doTrackEvent(eventName, finalAttributes);\n\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Tracked event:`,\n\t\t\t\t\teventName,\n\t\t\t\t\tfinalAttributes,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(`[${this.providerName}] Error tracking event:`, err);\n\t\t}\n\t}\n\n\t/**\n\t * Track a performance metric\n\t *\n\t * Default implementation tracks metrics as events with a `metric:` prefix.\n\t * Concrete providers can override this method if their backend has a\n\t * dedicated metric API.\n\t *\n\t * @param metricName Name of the metric\n\t * @param value Numeric value\n\t * @param attributes Optional metric attributes\n\t */\n\ttrackMetric(\n\t\tmetricName: string,\n\t\tvalue: number,\n\t\tattributes?: MetricAttributes,\n\t): void {\n\t\t// Default implementation: track as event\n\t\tthis.trackEvent(`metric:${metricName}`, {\n\t\t\t...attributes,\n\t\t\tmetricValue: value,\n\t\t\tmetricName,\n\t\t});\n\t}\n\n\t/**\n\t * Set user context for session tracking\n\t *\n\t * Template method that checks if provider is ready then delegates\n\t * to concrete provider implementation.\n\t *\n\t * @param userId User identifier\n\t * @param attributes Optional user attributes\n\t */\n\tsetUserContext(userId: string, attributes?: Record<string, any>): void {\n\t\t// Guard: check if provider is ready\n\t\tif (!this.guardedOperation(\"setUserContext\", userId, attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Delegate to concrete provider\n\t\ttry {\n\t\t\tthis.doSetUserContext(userId, attributes);\n\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Set user context:`,\n\t\t\t\t\tuserId,\n\t\t\t\t\tattributes,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(`[${this.providerName}] Error setting user context:`, err);\n\t\t}\n\t}\n\n\t/**\n\t * Set global custom attributes\n\t *\n\t * Template method that checks if provider is ready then delegates\n\t * to concrete provider implementation.\n\t *\n\t * @param attributes Attributes to set globally\n\t */\n\tsetGlobalAttributes(attributes: Record<string, any>): void {\n\t\t// Guard: check if provider is ready\n\t\tif (!this.guardedOperation(\"setGlobalAttributes\", attributes)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Delegate to concrete provider\n\t\ttry {\n\t\t\tthis.doSetGlobalAttributes(attributes);\n\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Set global attributes:`,\n\t\t\t\t\tattributes,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tconsole.error(\n\t\t\t\t`[${this.providerName}] Error setting global attributes:`,\n\t\t\t\terr,\n\t\t\t);\n\t\t}\n\t}\n\n\t// ============================================================================\n\t// Protected utility methods (shared logic)\n\t// ============================================================================\n\n\t/**\n\t * Guard operation - check if provider is ready\n\t *\n\t * Returns false if provider is not ready, logging a warning in debug mode.\n\t *\n\t * @param operation Name of the operation for logging\n\t * @param args Arguments for logging\n\t * @returns true if provider is ready, false otherwise\n\t */\n\tprotected guardedOperation(operation: string, ...args: any[]): boolean {\n\t\tif (!this.isReady()) {\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[${this.providerName}] Attempted to ${operation} but provider not ready:`,\n\t\t\t\t\t...args,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Apply error filter if configured\n\t *\n\t * Returns false if error should be filtered out, logging in debug mode.\n\t *\n\t * @param error The error\n\t * @param attributes Error attributes\n\t * @returns true if error should be tracked, false if filtered out\n\t */\n\tprotected applyErrorFilter(\n\t\terror: Error,\n\t\tattributes: ErrorAttributes,\n\t): boolean {\n\t\tif (\n\t\t\tthis.config?.errorFilter &&\n\t\t\t!this.config.errorFilter(error, attributes)\n\t\t) {\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Error filtered out:`,\n\t\t\t\t\terror,\n\t\t\t\t\tattributes,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Apply event filter if configured\n\t *\n\t * Returns false if event should be filtered out, logging in debug mode.\n\t *\n\t * @param eventName Event name\n\t * @param attributes Event attributes\n\t * @returns true if event should be tracked, false if filtered out\n\t */\n\tprotected applyEventFilter(\n\t\teventName: string,\n\t\tattributes: EventAttributes,\n\t): boolean {\n\t\tif (\n\t\t\tthis.config?.eventFilter &&\n\t\t\t!this.config.eventFilter(eventName, attributes)\n\t\t) {\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[${this.providerName}] Event filtered out:`,\n\t\t\t\t\teventName,\n\t\t\t\t\tattributes,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Apply sampling if configured\n\t *\n\t * Returns false if event should be sampled out, logging in debug mode.\n\t *\n\t * @param eventName Event name for logging\n\t * @returns true if event should be tracked, false if sampled out\n\t */\n\tprotected applySampling(eventName: string): boolean {\n\t\tif (this.config?.sampleRate !== undefined && this.config.sampleRate < 1.0) {\n\t\t\tif (Math.random() > this.config.sampleRate) {\n\t\t\t\tif (this.config?.debug) {\n\t\t\t\t\tconsole.log(`[${this.providerName}] Event sampled out:`, eventName);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Transform attributes if transformer is configured\n\t *\n\t * @param attributes Original attributes\n\t * @returns Transformed attributes or original if no transformer\n\t */\n\tprotected transformAttributes(\n\t\tattributes: Record<string, any>,\n\t): Record<string, any> {\n\t\tif (this.config?.attributeTransformer) {\n\t\t\treturn this.config.attributeTransformer(attributes);\n\t\t}\n\t\treturn attributes as Record<string, any>;\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CompositeInstrumentationProvider.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/CompositeInstrumentationProvider.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,gCAAgC;IAGnC,UAAU,GAAG,WAAW,CAAC;IACzB,YAAY,GAAG,oBAAoB,CAAC;IAErC,WAAW,GAAG,KAAK,CAAC;IACX,SAAS,CAA4B;IAEtD,YAAY,SAAoC;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAA8B;QAC9C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAC7D,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,MAAM,EAAE,KAAK,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;gBACjD,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;oBAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBACvC,OAAO,CAAC,IAAI,CACX,4CAA4C,QAAQ,EAAE,YAAY,IAAI,SAAS,KAAK,QAAQ,EAAE,UAAU,IAAI,SAAS,GAAG,EACxH,MAAM,CAAC,MAAM,CACb,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO;QACN,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACv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C,CAAC,QAAQ,EAAE,EAAE,CACjC,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAC7C,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,UAA+B;QAClD,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,EAAE,CACjC,QAAQ,CAAC,mBAAmB,EAAE,CAAC,UAAU,CAAC,CAC1C,CAAC;IACH,CAAC;IAEO,eAAe,CACtB,QAAqD;QAErD,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO;QAC9B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACvC,IAAI,CAAC;gBACJ,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import type {\n\tErrorAttributes,\n\tEventAttributes,\n\tInstrumentationConfig,\n\tInstrumentationProvider,\n\tMetricAttributes,\n} from \"../types.js\";\n\nexport class CompositeInstrumentationProvider\n\timplements InstrumentationProvider\n{\n\treadonly providerId = \"composite\";\n\treadonly providerName = \"Composite Provider\";\n\n\tprivate initialized = false;\n\tprivate readonly providers: InstrumentationProvider[];\n\n\tconstructor(providers: InstrumentationProvider[]) {\n\t\tthis.providers = providers.filter(Boolean);\n\t}\n\n\tasync initialize(config?: InstrumentationConfig): Promise<void> {\n\t\tconst results = await Promise.allSettled(\n\t\t\tthis.providers.map((provider) => provider.initialize(config)),\n\t\t);\n\t\tthis.initialized = true;\n\t\tif (config?.debug) {\n\t\t\tfor (const [index, result] of results.entries()) {\n\t\t\t\tif (result.status === \"rejected\") {\n\t\t\t\t\tconst provider = this.providers[index];\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[CompositeProvider] Failed to initialize ${provider?.providerName || \"unknown\"} (${provider?.providerId || \"unknown\"})`,\n\t\t\t\t\t\tresult.reason,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tisReady(): boolean {\n\t\tif (!this.initialized) return false;\n\t\treturn this.providers.some((provider) => {\n\t\t\ttry {\n\t\t\t\treturn provider.isReady();\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t}\n\n\tdestroy(): void {\n\t\tthis.initialized = false;\n\t\tfor (const provider of this.providers) {\n\t\t\ttry {\n\t\t\t\tprovider.destroy();\n\t\t\t} catch {\n\t\t\t\t// Best effort: a broken child provider should not block others.\n\t\t\t}\n\t\t}\n\t}\n\n\ttrackError(error: Error, attributes: ErrorAttributes): void {\n\t\tthis.forEachProvider((provider) => provider.trackError(error, attributes));\n\t}\n\n\ttrackEvent(eventName: string, attributes: EventAttributes): void {\n\t\tthis.forEachProvider((provider) =>\n\t\t\tprovider.trackEvent(eventName, attributes),\n\t\t);\n\t}\n\n\ttrackMetric(\n\t\tmetricName: string,\n\t\tvalue: number,\n\t\tattributes?: MetricAttributes,\n\t): void {\n\t\tthis.forEachProvider((provider) => {\n\t\t\tif (provider.trackMetric) {\n\t\t\t\tprovider.trackMetric(metricName, value, attributes);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprovider.trackEvent(`metric:${metricName}`, {\n\t\t\t\t...(attributes as Record<string, unknown>),\n\t\t\t\tmetricName,\n\t\t\t\tmetricValue: value,\n\t\t\t});\n\t\t});\n\t}\n\n\tsetUserContext(userId: string, attributes?: Record<string, any>): void {\n\t\tthis.forEachProvider((provider) =>\n\t\t\tprovider.setUserContext?.(userId, attributes),\n\t\t);\n\t}\n\n\tsetGlobalAttributes(attributes: Record<string, any>): void {\n\t\tthis.forEachProvider((provider) =>\n\t\t\tprovider.setGlobalAttributes?.(attributes),\n\t\t);\n\t}\n\n\tprivate forEachProvider(\n\t\tcallback: (provider: InstrumentationProvider) => void,\n\t): void {\n\t\tif (!this.initialized) return;\n\t\tfor (const provider of this.providers) {\n\t\t\ttry {\n\t\t\t\tcallback(provider);\n\t\t\t} catch {\n\t\t\t\t// Best effort fan-out.\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleInstrumentationProvider.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/ConsoleInstrumentationProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAyB/E,MAAM,OAAO,8BAA+B,SAAQ,2BAA2B;IACrE,UAAU,GAAG,SAAS,CAAC;IACvB,YAAY,GAAG,gBAAgB,CAAC;IAEjC,cAAc,CAAwB;IAE9C,YAAY,iBAAwC,EAAE;QACrD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG;YACrB,SAAS,EAAE,cAAc,CAAC,SAAS,KAAK,KAAK;YAC7C,iBAAiB,EAAE,cAAc,CAAC,iBAAiB,KAAK,KAAK;YAC7D,SAAS,EAAE,cAAc,CAAC,SAAS,KAAK,IAAI;SAC5C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,MAA8B;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,6CAA6C;QAC7C,IAAI,MAAM,EAAE,gBAAgB,EAAE,CAAC;YAC9B,IAAI,CAAC,cAAc,GAAG;gBACrB,GAAG,IAAI,CAAC,cAAc;gBACtB,GAAG,MAAM,CAAC,gBAAgB;aAC1B,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CACV,iCAAiC,EACjC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,EAAE,CACtE,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,OAAO;QACN,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED;;OAEG;I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QAC7C,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACO,qBAAqB,CAAC,UAA+B;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS;YAC1C,CAAC,CAAC,kCAAkC;YACpC,CAAC,CAAC,EAAE,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IACxC,CAAC;CACD","sourcesContent":["/**\n * Console Instrumentation Provider\n *\n * Development provider that logs instrumentation events to the console.\n * Useful for debugging and testing without requiring external instrumentation services.\n *\n * @example\n * ```typescript\n * const provider = new ConsoleInstrumentationProvider();\n * await provider.initialize({ debug: true });\n *\n * provider.trackError(new Error('Test error'), {\n * component: 'test-component',\n * errorType: 'TestError'\n * });\n * // Outputs: [Instrumentation Error] test-component: TestError\n * // Error: Test error\n * // { component: 'test-component', errorType: 'TestError' }\n * ```\n */\n\nimport type { InstrumentationConfig, MetricAttributes } from \"../types.js\";\nimport { BaseInstrumentationProvider } from \"./BaseInstrumentationProvider.js\";\n\nexport interface ConsoleProviderConfig {\n\t/**\n\t * Use colored output in console\n\t *\n\t * @default true\n\t */\n\tuseColors?: boolean;\n\n\t/**\n\t * Include stack traces with errors\n\t *\n\t * @default true\n\t */\n\tincludeStackTrace?: boolean;\n\n\t/**\n\t * Group related logs together\n\t *\n\t * @default false\n\t */\n\tuseGroups?: boolean;\n}\n\nexport class ConsoleInstrumentationProvider extends BaseInstrumentationProvider {\n\treadonly providerId = \"console\";\n\treadonly providerName = \"Console Logger\";\n\n\tprivate providerConfig: ConsoleProviderConfig;\n\n\tconstructor(providerConfig: ConsoleProviderConfig = {}) {\n\t\tsuper();\n\t\tthis.providerConfig = {\n\t\t\tuseColors: providerConfig.useColors !== false,\n\t\t\tincludeStackTrace: providerConfig.includeStackTrace !== false,\n\t\t\tuseGroups: providerConfig.useGroups === true,\n\t\t};\n\t}\n\n\t/**\n\t * Initialize the console provider\n\t *\n\t * @param config Optional configuration\n\t */\n\tasync initialize(config?: InstrumentationConfig): Promise<void> {\n\t\tthis.config = config;\n\t\tthis.initialized = true;\n\n\t\t// Merge provider-specific config if provided\n\t\tif (config?.providerSettings) {\n\t\t\tthis.providerConfig = {\n\t\t\t\t...this.providerConfig,\n\t\t\t\t...config.providerSettings,\n\t\t\t};\n\t\t}\n\n\t\tconsole.log(\n\t\t\t\"%c[ConsoleProvider] Initialized\",\n\t\t\tthis.providerConfig.useColors ? \"color: green; font-weight: bold\" : \"\",\n\t\t);\n\t}\n\n\t/**\n\t * Check if provider is ready\n\t *\n\t * @returns true if initialized\n\t */\n\tisReady(): boolean {\n\t\treturn this.initialized;\n\t}\n\n\t/**\n\t * Cleanup provider resources\n\t */\n\tdestroy(): void {\n\t\tthis.initialized = false;\n\t\tconsole.log(\n\t\t\t\"%c[ConsoleProvider] Destroyed\",\n\t\t\tthis.providerConfig.useColors ? \"color: gray\" : \"\",\n\t\t);\n\t}\n\n\t/**\n\t * Track an error to console\n\t *\n\t * @param error The error to track\n\t * @param attributes Transformed attributes (already filtered and transformed by base class)\n\t */\n\tprotected doTrackError(error: Error, attributes: Record<string, any>): void {\n\t\tconst style = this.providerConfig.useColors\n\t\t\t? \"color: red; font-weight: bold\"\n\t\t\t: \"\";\n\t\tconst timestamp = new Date().toISOString();\n\n\t\tif (this.providerConfig.useGroups) {\n\t\t\tconsole.groupCollapsed(\n\t\t\t\t`%c[Instrumentation Error] ${attributes.component}: ${attributes.errorType}`,\n\t\t\t\tstyle,\n\t\t\t);\n\t\t\tconsole.error(\"Error:\", error.message);\n\t\t\tif (this.providerConfig.includeStackTrace && error.stack) {\n\t\t\t\tconsole.error(\"Stack:\", error.stack);\n\t\t\t}\n\t\t\tconsole.log(\"Attributes:\", attributes);\n\t\t\tconsole.log(\"Timestamp:\", timestamp);\n\t\t\tconsole.groupEnd();\n\t\t} else {\n\t\t\tconsole.error(\n\t\t\t\t`%c[Instrumentation Error] ${attributes.component}: ${attributes.errorType}`,\n\t\t\t\tstyle,\n\t\t\t);\n\t\t\tconsole.error(\"Error:\", error.message);\n\t\t\tif (this.providerConfig.includeStackTrace && error.stack) {\n\t\t\t\tconsole.error(\"Stack:\", error.stack);\n\t\t\t}\n\t\t\tconsole.error(\"Attributes:\", attributes);\n\t\t\tconsole.error(\"Timestamp:\", timestamp);\n\t\t}\n\t}\n\n\t/**\n\t * Track an event to console\n\t *\n\t * @param eventName Name of the event\n\t * @param attributes Transformed attributes (already filtered and transformed by base class)\n\t */\n\tprotected doTrackEvent(\n\t\teventName: string,\n\t\tattributes: Record<string, any>,\n\t): void {\n\t\tconst style = this.providerConfig.useColors ? \"color: blue\" : \"\";\n\t\tconst timestamp = new Date().toISOString();\n\n\t\tif (this.providerConfig.useGroups) {\n\t\t\tconsole.groupCollapsed(`%c[Instrumentation Event] ${eventName}`, style);\n\t\t\tconsole.log(\"Attributes:\", attributes);\n\t\t\tconsole.log(\"Timestamp:\", timestamp);\n\t\t\tconsole.groupEnd();\n\t\t} else {\n\t\t\tconsole.log(`%c[Instrumentation Event] ${eventName}`, style);\n\t\t\tconsole.log(\"Attributes:\", attributes);\n\t\t\tconsole.log(\"Timestamp:\", timestamp);\n\t\t}\n\t}\n\n\t/**\n\t * Track a metric to console\n\t *\n\t * Overrides base class to provide custom formatting.\n\t *\n\t * @param metricName Name of the metric\n\t * @param value Numeric value\n\t * @param attributes Optional metric attributes\n\t */\n\ttrackMetric(\n\t\tmetricName: string,\n\t\tvalue: number,\n\t\tattributes?: MetricAttributes,\n\t): void {\n\t\tif (!this.isReady()) return;\n\n\t\tconst style = this.providerConfig.useColors ? \"color: green\" : \"\";\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst unit = attributes?.unit || \"\";\n\t\tconst displayValue = unit ? `${value} ${unit}` : value;\n\n\t\tif (this.providerConfig.useGroups) {\n\t\t\tconsole.groupCollapsed(\n\t\t\t\t`%c[Instrumentation Metric] ${metricName}: ${displayValue}`,\n\t\t\t\tstyle,\n\t\t\t);\n\t\t\tif (attributes) {\n\t\t\t\tconsole.log(\"Attributes:\", attributes);\n\t\t\t}\n\t\t\tconsole.log(\"Timestamp:\", timestamp);\n\t\t\tconsole.groupEnd();\n\t\t} else {\n\t\t\tconsole.log(\n\t\t\t\t`%c[Instrumentation Metric] ${metricName}:`,\n\t\t\t\tstyle,\n\t\t\t\tdisplayValue,\n\t\t\t);\n\t\t\tif (attributes) {\n\t\t\t\tconsole.log(\"Attributes:\", attributes);\n\t\t\t}\n\t\t\tconsole.log(\"Timestamp:\", timestamp);\n\t\t}\n\t}\n\n\t/**\n\t * Set user context\n\t *\n\t * Logs user context to console.\n\t *\n\t * @param userId User identifier\n\t * @param attributes Optional user attributes\n\t */\n\tprotected doSetUserContext(\n\t\tuserId: string,\n\t\tattributes?: Record<string, any>,\n\t): void {\n\t\tconst style = this.providerConfig.useColors\n\t\t\t? \"color: purple; font-weight: bold\"\n\t\t\t: \"\";\n\t\tconsole.log(`%c[Instrumentation] Set User Context: ${userId}`, style);\n\t\tif (attributes) {\n\t\t\tconsole.log(\"User Attributes:\", attributes);\n\t\t}\n\t}\n\n\t/**\n\t * Set global attributes\n\t *\n\t * Logs global attributes to console.\n\t *\n\t * @param attributes Attributes to set globally\n\t */\n\tprotected doSetGlobalAttributes(attributes: Record<string, any>): void {\n\t\tconst style = this.providerConfig.useColors\n\t\t\t? \"color: orange; font-weight: bold\"\n\t\t\t: \"\";\n\t\tconsole.log(\"%c[Instrumentation] Set Global Attributes\", style);\n\t\tconsole.log(\"Attributes:\", attributes);\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DebugPanelInstrumentationProvider.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/DebugPanelInstrumentationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,8BAA8B,GAC9B,MAAM,0B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SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACtC,8BAA8B,CAC7B,uBAAuB,CAAC;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,UAAU;YACV,KAAK,EAAE,cAAc;YACrB,UAAU;SACV,CAAC,CACF,CAAC;IACH,CAAC;IAES,gBAAgB,CACzB,MAAc,EACd,UAAgC;QAEhC,8BAA8B,CAAC;YAC9B,IAAI,EAAE,cAAc;YACpB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,MAAM;YACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,UAAU,EAAE,UAAU;gBACrB,CAAC,CAAC,EAAE,GAAI,UAAsC,EAAE;gBAChD,CAAC,CAAC,SAAS;SACZ,CAAC,CAAC;IACJ,CAAC;IAES,qBAAqB,CAAC,UAA+B;QAC9D,8BAA8B,CAAC;YAC9B,IAAI,EAAE,mBAAmB;YACzB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,uBAAuB;YAC7B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,UAAU,EAAE,EAAE,GAAI,UAAsC,EAAE;SAC1D,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import {\n\tcreateErrorDebugRecord,\n\tcreateEventDebugRecord,\n\tcreateMetricDebugRecord,\n\temitInstrumentationDebugRecord,\n} from \"../debug-panel-stream.js\";\nimport type { ErrorAttributes, InstrumentationConfig } from \"../types.js\";\nimport { BaseInstrumentationProvider } from \"./BaseInstrumentationProvider.js\";\n\nexport class DebugPanelInstrumentationProvider extends BaseInstrumentationProvider {\n\treadonly providerId = \"debug-panel\";\n\treadonly providerName = \"Debug Panel\";\n\n\tasync initialize(config?: InstrumentationConfig): Promise<void> {\n\t\tthis.config = config;\n\t\tthis.initialized = true;\n\t}\n\n\tisReady(): boolean {\n\t\treturn this.initialized;\n\t}\n\n\tdestroy(): void {\n\t\tthis.initialized = false;\n\t}\n\n\tprotected doTrackError(error: Error, attributes: Record<string, any>): void {\n\t\temitInstrumentationDebugRecord(\n\t\t\tcreateErrorDebugRecord({\n\t\t\t\tproviderId: this.providerId,\n\t\t\t\tproviderName: this.providerName,\n\t\t\t\terror,\n\t\t\t\tattributes: attributes as ErrorAttributes,\n\t\t\t}),\n\t\t);\n\t}\n\n\tprotected doTrackEvent(\n\t\teventName: string,\n\t\tattributes: Record<string, any>,\n\t): void {\n\t\temitInstrumentationDebugRecord(\n\t\t\tcreateEventDebugRecord({\n\t\t\t\tproviderId: this.providerId,\n\t\t\t\tproviderName: this.providerName,\n\t\t\t\teventName,\n\t\t\t\tattributes,\n\t\t\t}),\n\t\t);\n\t\tif (!eventName.startsWith(\"metric:\")) {\n\t\t\treturn;\n\t\t}\n\t\tconst rawMetricValue = attributes.metricValue;\n\t\tif (\n\t\t\ttypeof rawMetricValue !== \"number\" ||\n\t\t\t!Number.isFinite(rawMetricValue)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst metricName =\n\t\t\ttypeof attributes.metricName === \"string\" && attributes.metricName\n\t\t\t\t? attributes.metricName\n\t\t\t\t: eventName.replace(/^metric:/, \"\");\n\t\temitInstrumentationDebugRecord(\n\t\t\tcreateMetricDebugRecord({\n\t\t\t\tproviderId: this.providerId,\n\t\t\t\tproviderName: this.providerName,\n\t\t\t\tmetricName,\n\t\t\t\tvalue: rawMetricValue,\n\t\t\t\tattributes,\n\t\t\t}),\n\t\t);\n\t}\n\n\tprotected doSetUserContext(\n\t\tuserId: string,\n\t\tattributes?: Record<string, any>,\n\t): void {\n\t\temitInstrumentationDebugRecord({\n\t\t\tkind: \"user-context\",\n\t\t\tproviderId: this.providerId,\n\t\t\tproviderName: this.providerName,\n\t\t\tname: userId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tattributes: attributes\n\t\t\t\t? { ...(attributes as Record<string, unknown>) }\n\t\t\t\t: undefined,\n\t\t});\n\t}\n\n\tprotected doSetGlobalAttributes(attributes: Record<string, any>): void {\n\t\temitInstrumentationDebugRecord({\n\t\t\tkind: \"global-attributes\",\n\t\t\tproviderId: this.providerId,\n\t\t\tproviderName: this.providerName,\n\t\t\tname: \"set-global-attributes\",\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tattributes: { ...(attributes as Record<string, unknown>) },\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NewRelicInstrumentationProvider.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/NewRelicInstrumentationProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,OAAO,+BAAgC,SAAQ,2BAA2B;IACtE,UAAU,GAAG,UAAU,CAAC;IACxB,YAAY,GAAG,WAAW,CAAC;IAEpC;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,MAA8B;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,kCAAkC;QAClC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAK,MAAc,CAAC,QAAQ,EAAE,CAAC;YAC/D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;YAC5D,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;gBACxB,OAAO,CAAC,IAAI,CACX,wEAAwE,CACxE,CAAC;YACH,CAAC;YACD,2CAA2C;YAC3C,IAAI,CAAC,WAAW,GAAG,KA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AC;IACF,CAAC;IAED;;;;;;OAMG;IACO,qBAAqB,CAAC,UAA+B;QAC9D,MAAM,QAAQ,GAAI,MAAc,CAAC,QAAQ,CAAC;QAE1C,IAAI,QAAQ,CAAC,kBAAkB,EAAE,CAAC;YACjC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBACvD,QAAQ,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\n * New Relic Instrumentation Provider\n *\n * Default provider for existing New Relic Browser Agent instrumentation.\n *\n * This provider wraps the global `window.newrelic` object provided by\n * the New Relic Browser Agent.\n *\n * @example\n * ```typescript\n * const provider = new NewRelicInstrumentationProvider();\n * await provider.initialize();\n *\n * if (provider.isReady()) {\n * provider.trackError(new Error('Something went wrong'), {\n * component: 'my-component',\n * errorType: 'ValidationError'\n * });\n * }\n * ```\n */\n\nimport type { InstrumentationConfig } from \"../types.js\";\nimport { BaseInstrumentationProvider } from \"./BaseInstrumentationProvider.js\";\n\nexport class NewRelicInstrumentationProvider extends BaseInstrumentationProvider {\n\treadonly providerId = \"newrelic\";\n\treadonly providerName = \"New Relic\";\n\n\t/**\n\t * Initialize the New Relic provider\n\t *\n\t * Checks if the New Relic Browser Agent is available via `window.newrelic`.\n\t * If not available, initialization succeeds but `isReady()` will return false.\n\t *\n\t * @param config Optional configuration\n\t */\n\tasync initialize(config?: InstrumentationConfig): Promise<void> {\n\t\tthis.config = config;\n\n\t\t// Check if New Relic is available\n\t\tif (typeof window !== \"undefined\" && (window as any).newrelic) {\n\t\t\tthis.initialized = true;\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.log(\"[NewRelicProvider] Initialized successfully\");\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.config?.debug) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[NewRelicProvider] New Relic not available (window.newrelic not found)\",\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Don't throw - allow graceful degradation\n\t\t\tthis.initialized = false;\n\t\t}\n\t}\n\n\t/**\n\t * Check if provider is ready\n\t *\n\t * @returns true if New Relic is available and initialized\n\t */\n\tisReady(): boolean {\n\t\treturn (\n\t\t\tthis.initialized &&\n\t\t\ttypeof window !== \"undefined\" &&\n\t\t\t!!(window as any).newrelic\n\t\t);\n\t}\n\n\t/**\n\t * Cleanup provider resources\n\t *\n\t * Marks provider as uninitialized. The global `window.newrelic` object\n\t * is not modified.\n\t */\n\tdestroy(): void {\n\t\tthis.initialized = false;\n\t\tif (this.config?.debug) {\n\t\t\tconsole.log(\"[NewRelicProvider] Destroyed\");\n\t\t}\n\t}\n\n\t/**\n\t * Track an error with New Relic\n\t *\n\t * Calls `newrelic.noticeError(error, attributes)`\n\t *\n\t * @param error The error to track\n\t * @param attributes Transformed attributes (already filtered and transformed by base class)\n\t */\n\tprotected doTrackError(error: Error, attributes: Record<string, any>): void {\n\t\tconst newrelic = (window as any).newrelic;\n\t\tnewrelic.noticeError(error, attributes);\n\t}\n\n\t/**\n\t * Track a custom event/page action with New Relic\n\t *\n\t * Calls `newrelic.addPageAction(eventName, attributes)`\n\t *\n\t * @param eventName Name of the event\n\t * @param attributes Transformed attributes (already filtered and transformed by base class)\n\t */\n\tprotected doTrackEvent(\n\t\teventName: string,\n\t\tattributes: Record<string, any>,\n\t): void {\n\t\tconst newrelic = (window as any).newrelic;\n\t\tnewrelic.addPageAction(eventName, attributes);\n\t}\n\n\t/**\n\t * Set user context for session tracking\n\t *\n\t * Calls `newrelic.setUserId()` and `newrelic.setCustomAttribute()` for user attributes.\n\t *\n\t * @param userId User identifier\n\t * @param attributes Optional user attributes\n\t */\n\tprotected doSetUserContext(\n\t\tuserId: string,\n\t\tattributes?: Record<string, any>,\n\t): void {\n\t\tconst newrelic = (window as any).newrelic;\n\n\t\t// Set user ID if method exists\n\t\tif (newrelic.setUserId) {\n\t\t\tnewrelic.setUserId(userId);\n\t\t}\n\n\t\t// Set custom attributes for user\n\t\tif (attributes && newrelic.setCustomAttribute) {\n\t\t\tfor (const [key, value] of Object.entries(attributes)) {\n\t\t\t\tnewrelic.setCustomAttribute(key, value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Set global custom attributes\n\t *\n\t * Calls `newrelic.setCustomAttribute()` for each attribute.\n\t *\n\t * @param attributes Attributes to set globally\n\t */\n\tprotected doSetGlobalAttributes(attributes: Record<string, any>): void {\n\t\tconst newrelic = (window as any).newrelic;\n\n\t\tif (newrelic.setCustomAttribute) {\n\t\t\tfor (const [key, value] of Object.entries(attributes)) {\n\t\t\t\tnewrelic.setCustomAttribute(key, value);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/instrumentation/providers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,qBAAqB;AACrB,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC","sourcesContent":["/**\n * Instrumentation Providers\n *\n * This module exports all available instrumentation providers.\n */\n\n// Base class for creating custom providers\nexport { BaseInstrumentationProvider } from \"./BaseInstrumentationProvider.js\";\nexport type { ConsoleProviderConfig } from \"./ConsoleInstrumentationProvider.js\";\n// Built-in providers\nexport { CompositeInstrumentationProvider } from \"./CompositeInstrumentationProvider.js\";\nexport { ConsoleInstrumentationProvider } from \"./ConsoleInstrumentationProvider.js\";\nexport { DebugPanelInstrumentationProvider } from \"./DebugPanelInstrumentationProvider.js\";\nexport { NewRelicInstrumentationProvider } from \"./NewRelicInstrumentationProvider.js\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/instrumentation/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * Instrumentation Types\n *\n * Core interfaces and types for pluggable instrumentation system.\n * Abstracts vendor-specific APIs (New Relic and custom providers)\n * to enable clients to use any instrumentation provider.\n */\n\n/**\n * Pluggable instrumentation provider interface\n *\n * All instrumentation providers must implement this interface.\n * Provides methods for tracking errors, events, and metrics.\n *\n * @example\n * ```typescript\n * class CustomProvider implements InstrumentationProvider {\n * readonly providerId = 'custom';\n * readonly providerName = 'Custom Analytics';\n *\n * async initialize(config?: InstrumentationConfig): Promise<void> {\n * // Initialize your analytics SDK\n * }\n *\n * trackError(error: Error, attributes: ErrorAttributes): void {\n * // Send error to your analytics backend\n * }\n *\n * trackEvent(eventName: string, attributes: EventAttributes): void {\n * // Send event to your analytics backend\n * }\n *\n * isReady(): boolean {\n * return true;\n * }\n *\n * destroy(): void {\n * // Cleanup\n * }\n * }\n * ```\n */\nexport interface InstrumentationProvider {\n\t/**\n\t * Unique identifier for the provider (e.g., 'newrelic', 'console')\n\t */\n\treadonly providerId: string;\n\n\t/**\n\t * Human-readable provider name (e.g., 'New Relic')\n\t */\n\treadonly providerName: string;\n\n\t/**\n\t * Initialize the provider (load SDKs, configure clients, etc.)\n\t *\n\t * @param config Optional configuration for the provider\n\t */\n\tinitialize(config?: InstrumentationConfig): Promise<void>;\n\n\t/**\n\t * Track an error with contextual attributes\n\t *\n\t * @param error The error to track\n\t * @param attributes Contextual attributes about the error\n\t */\n\ttrackError(error: Error, attributes: ErrorAttributes): void;\n\n\t/**\n\t * Track a custom event/page action\n\t *\n\t * @param eventName Name of the event (e.g., 'pie-resource-load', 'pie-resource-retry')\n\t * @param attributes Contextual attributes about the event\n\t */\n\ttrackEvent(eventName: string, attributes: EventAttributes): void;\n\n\t/**\n\t * Track a performance metric\n\t *\n\t * Optional - not all providers support direct metrics.\n\t * For providers without metric support, consider tracking as custom events instead.\n\t *\n\t * @param metricName Name of the metric\n\t * @param value Numeric value of the metric\n\t * @param attributes Optional attributes about the metric\n\t */\n\ttrackMetric?(\n\t\tmetricName: string,\n\t\tvalue: number,\n\t\tattributes?: MetricAttributes,\n\t): void;\n\n\t/**\n\t * Set user context for session tracking\n\t *\n\t * Optional - associates user information with subsequent events/errors.\n\t *\n\t * @param userId User identifier\n\t * @param attributes Optional user attributes\n\t */\n\tsetUserContext?(userId: string, attributes?: Record<string, any>): void;\n\n\t/**\n\t * Set custom attributes that apply to all subsequent events\n\t *\n\t * Optional - useful for setting context like environment, version, etc.\n\t *\n\t * @param attributes Attributes to set globally\n\t */\n\tsetGlobalAttributes?(attributes: Record<string, any>): void;\n\n\t/**\n\t * Cleanup provider resources\n\t *\n\t * Called when the provider is being destroyed or replaced.\n\t */\n\tdestroy(): void;\n\n\t/**\n\t * Check if provider is ready to track events\n\t *\n\t * @returns true if provider is initialized and ready, false otherwise\n\t */\n\tisReady(): boolean;\n}\n\n/**\n * Configuration for instrumentation providers\n */\nexport interface InstrumentationConfig {\n\t/**\n\t * Enable/disable instrumentation\n\t *\n\t * @default true\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Enable debug logging\n\t *\n\t * @default false\n\t */\n\tdebug?: boolean;\n\n\t/**\n\t * Sample rate for events (0.0 to 1.0)\n\t *\n\t * 1.0 = 100% of events tracked\n\t * 0.5 = 50% of events tracked\n\t * 0.1 = 10% of events tracked\n\t *\n\t * @default 1.0\n\t */\n\tsampleRate?: number;\n\n\t/**\n\t * Provider-specific settings\n\t *\n\t * Each provider can define its own configuration structure.\n\t *\n\t * @example New Relic\n\t * ```typescript\n\t * providerSettings: {\n\t * // New Relic doesn't need additional config (uses global newrelic object)\n\t * }\n\t * ```\n\t *\n\t * @example Console provider\n\t * ```typescript\n\t * providerSettings: {\n\t * useColors: true\n\t * }\n\t * ```\n\t */\n\tproviderSettings?: Record<string, any>;\n\n\t/**\n\t * Filter function for errors\n\t *\n\t * Return false to skip tracking the error.\n\t *\n\t * @param error The error being tracked\n\t * @param attributes The error attributes\n\t * @returns true to track, false to skip\n\t */\n\terrorFilter?: (error: Error, attributes: ErrorAttributes) => boolean;\n\n\t/**\n\t * Filter function for events\n\t *\n\t * Return false to skip tracking the event.\n\t *\n\t * @param eventName The event name\n\t * @param attributes The event attributes\n\t * @returns true to track, false to skip\n\t */\n\teventFilter?: (eventName: string, attributes: EventAttributes) => boolean;\n\n\t/**\n\t * Transform function for attributes\n\t *\n\t * Allows modifying or enriching attributes before they're sent to the provider.\n\t *\n\t * @param attributes The original attributes\n\t * @returns The transformed attributes\n\t */\n\tattributeTransformer?: (\n\t\tattributes: Record<string, any>,\n\t) => Record<string, any>;\n}\n\n/**\n * Common error attributes\n *\n * These attributes are sent with error tracking calls.\n * All providers should support these base attributes.\n */\nexport interface ErrorAttributes {\n\t/**\n\t * Component that generated the error\n\t *\n\t * Examples: 'pie-item-player', 'pie-resource-monitor'\n\t */\n\tcomponent: string;\n\n\t/**\n\t * Type/category of error\n\t *\n\t * Examples: 'InvalidConfig', 'ConfigParseError', 'EsmLoadingError',\n\t * 'IifeLoadingError', 'ResourceLoadError'\n\t */\n\terrorType: string;\n\n\t// Contextual data (all optional, depends on error type)\n\n\t/**\n\t * Single item ID (if error relates to a specific item)\n\t */\n\titemId?: string;\n\n\t/**\n\t * Multiple item IDs (if error relates to multiple items)\n\t */\n\titemIds?: string[];\n\n\t/**\n\t * PIE element type (if error relates to a specific element)\n\t *\n\t * Examples: '@pie-element/inline-choice', '@pie-element/match'\n\t */\n\telementType?: string;\n\n\t/**\n\t * CDN base URL (for ESM loading errors)\n\t */\n\tcdnBaseUrl?: string;\n\n\t/**\n\t * Bundle host URL (for IIFE loading errors)\n\t */\n\tbundleHost?: string;\n\n\t/**\n\t * Resource URL (for resource loading errors)\n\t */\n\tresourceUrl?: string;\n\n\t/**\n\t * Resource type (for resource loading errors)\n\t *\n\t * Examples: 'img', 'audio', 'video', 'link', 'source'\n\t */\n\tresourceType?: string;\n\n\t/**\n\t * Duration in milliseconds (for timing-related errors)\n\t */\n\tduration?: number;\n\n\t/**\n\t * Retry count (for retry-related errors)\n\t */\n\tretryCount?: number;\n\n\t/**\n\t * Whether retry was attempted (for resource errors)\n\t */\n\twasRetried?: boolean;\n\n\t/**\n\t * Extensible for additional context-specific attributes\n\t */\n\t[key: string]: any;\n}\n\n/**\n * Common event attributes\n *\n * These attributes are sent with event tracking calls.\n */\nexport interface EventAttributes {\n\t/**\n\t * Component that generated the event\n\t *\n\t * Optional - some events may be component-agnostic\n\t */\n\tcomponent?: string;\n\n\t/**\n\t * Timestamp of the event\n\t *\n\t * ISO 8601 format string\n\t */\n\ttimestamp?: string;\n\n\t// Resource loading events\n\n\t/**\n\t * Resource URL\n\t */\n\turl?: string;\n\n\t/**\n\t * Load duration in milliseconds\n\t */\n\tduration?: number;\n\n\t/**\n\t * Transfer size in bytes\n\t */\n\tsize?: number;\n\n\t/**\n\t * Resource type\n\t *\n\t * Examples: 'img', 'audio', 'video', 'link', 'script', 'stylesheet'\n\t */\n\ttype?: string;\n\n\t/**\n\t * Whether the resource load failed\n\t */\n\tfailed?: boolean;\n\n\t/**\n\t * Whether retry was attempted\n\t */\n\twasRetried?: boolean;\n\n\t/**\n\t * Retry count\n\t */\n\tretryCount?: number;\n\n\t/**\n\t * Retry attempt number\n\t */\n\tattempt?: number;\n\n\t/**\n\t * Delay before retry in milliseconds\n\t */\n\tdelay?: number;\n\n\t/**\n\t * Extensible for additional event-specific attributes\n\t */\n\t[key: string]: any;\n}\n\n/**\n * Metric attributes\n *\n * These attributes are sent with metric tracking calls.\n */\nexport interface MetricAttributes {\n\t/**\n\t * Unit of measurement\n\t *\n\t * Examples: 'ms', 'bytes', 'count', 'percent'\n\t */\n\tunit?: string;\n\n\t/**\n\t * Category of metric\n\t *\n\t * Examples: 'performance', 'resource', 'error', 'user-action'\n\t */\n\tcategory?: string;\n\n\t/**\n\t * Extensible for additional metric-specific attributes\n\t */\n\t[key: string]: any;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader-config.js","sourceRoot":"","sources":["../src/loader-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwEH,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,MAAM;CACR,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,gBAAgB,EAAE,KAAK;IACvB,uBAAuB,EAAE,SAAS;IAClC,kBAAkB,EAAE,CAAC;IACrB,kBAAkB,EAAE,GAAG;IACvB,eAAe,EAAE,gCAAgC;CACxC,CAAC","sourcesContent":["/**\n * Shared loader configuration for PIE custom elements.\n *\n * Mirrors the `LoaderConfig` used by PIEOneer's custom element tags.\n */\n\nimport type { InstrumentationProvider } from \"./instrumentation/types.js\";\n\nexport type IifeBundleRetryConfig = {\n\t/**\n\t * Delay in ms between IIFE bundle retry attempts.\n\t */\n\tretryDelayMs?: number;\n\n\t/**\n\t * Total timeout in ms before IIFE bundle load retries fail permanently.\n\t */\n\ttimeoutMs?: number;\n};\n\nexport type LoaderConfig = {\n\t/**\n\t * Enable tracking page actions/events.\n\t *\n\t * When true, instrumentation events will be sent to the instrumentation provider.\n\t */\n\ttrackPageActions?: boolean;\n\n\t/**\n\t * Instrumentation provider for tracking events and errors.\n\t *\n\t * Optional. If not provided, defaults to NewRelicInstrumentationProvider.\n\t * The provider handles instrumentation gracefully - if New Relic (or the configured\n\t * backend) is not available, it will simply not track events (no errors thrown).\n\t *\n\t * @example Using New Relic (default - no configuration needed)\n\t * ```typescript\n\t * // Just enable tracking - will use New Relic if window.newrelic is available\n\t * const loaderConfig = {\n\t * trackPageActions: true\n\t * };\n\t * ```\n\t * @example Using Console provider (for development/debugging)\n\t * ```typescript\n\t * import { ConsoleInstrumentationProvider } from '@pie-players/pie-players-shared';\n\t *\n\t * const provider = new ConsoleInstrumentationProvider({ useColors: true });\n\t * await provider.initialize({ debug: true });\n\t *\n\t * const loaderConfig = {\n\t * trackPageActions: true,\n\t * instrumentationProvider: provider\n\t * };\n\t * ```\n\t */\n\tinstrumentationProvider?: InstrumentationProvider;\n\n\t/**\n\t * Maximum number of retry attempts for failed resources (images/audio/video).\n\t */\n\tmaxResourceRetries?: number;\n\n\t/**\n\t * Initial delay in ms before first resource retry attempt (exponential backoff).\n\t */\n\tresourceRetryDelay?: number;\n\n\t/**\n\t * Retry policy for IIFE bundle loads.\n\t *\n\t * Kept separate from resource retry settings so bundle-build polling can be tuned\n\t * independently from media/resource retries.\n\t */\n\tiifeBundleRetry?: IifeBundleRetryConfig;\n};\n\nexport const DEFAULT_IIFE_BUNDLE_RETRY_CONFIG = {\n\tretryDelayMs: 3000,\n\ttimeoutMs: 120000,\n} as const;\n\nexport const DEFAULT_LOADER_CONFIG = {\n\ttrackPageActions: false,\n\tinstrumentationProvider: undefined,\n\tmaxResourceRetries: 3,\n\tresourceRetryDelay: 500,\n\tiifeBundleRetry: DEFAULT_IIFE_BUNDLE_RETRY_CONFIG,\n} as const;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ElementLoader.js","sourceRoot":"","sources":["../../src/loaders/ElementLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAShE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAmB;IACpD,MAAM,UAAU,GAA2B,EAAE,CAAC;IAE9C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;QAEjD,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;YACnD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,MAAM,aAAa,GAAG,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE;gBAC7D,sBAAsB,EAAE,IAAI;aAC5B,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBAChC,UAAU,CAAC,aAAa,CAAC,GAAG,WAAW,CAAC;YACzC,CAAC;iBAAM,IAAI,UAAU,CAAC,aAAa,CAAC,KAAK,WAAW,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CACd,6BAA6B,aAAa,kBAAkB,UAAU,CAAC,aAAa,CAAC,QAAQ,WAAW,IAAI;oBAC3G,+DAA+D,CAChE,CAAC;YACH,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Element Loader — element aggregation utilities.\n *\n * The deep `ElementLoader` primitive lives in `./element-loader.ts`. This\n * module owns the shared `ElementMap` type and the `aggregateElements`\n * helper that reduces many items' element declarations into a single\n * deduplicated, version-aware map (used by the section-player to\n * pre-warm in one shot).\n */\n\nimport { toPackageVersionedTag } from \"../pie/versioned-tag.js\";\nimport type { ItemEntity } from \"../types/index.js\";\n\n/**\n * Map of element tag names to their package versions\n * Example: { \"pie-multiple-choice\": \"@pie-element/multiple-choice@11.0.1\" }\n */\nexport type ElementMap = { [tagName: string]: string };\n\n/**\n * Aggregate unique elements from multiple items\n *\n * Extracts elements from all item configs, versions their full tag names, and\n * deduplicates identical tag/package pairs. Multiple package versions of the\n * same original tag remain distinct through their versioned tag names.\n *\n * @param items - Array of items to aggregate elements from\n * @returns Map of unique element tag names to package versions\n * @throws Error if two package specs resolve to the same versioned tag\n *\n * @example\n * ```typescript\n * const items = [\n * { config: { elements: { \"pie-mc\": \"@pie-element/mc@11.0.1\" } } },\n * { config: { elements: { \"pie-mc\": \"@pie-element/mc@11.0.1\" } } },\n * { config: { elements: { \"pie-hotspot\": \"@pie-element/hotspot@9.0.0\" } } }\n * ];\n *\n * const elements = aggregateElements(items);\n * // Result: {\n * // \"pie-mc--version-11-0-1\": \"@pie-element/mc@11.0.1\",\n * // \"pie-hotspot--version-9-0-0\": \"@pie-element/hotspot@9.0.0\"\n * // }\n * ```\n */\nexport function aggregateElements(items: ItemEntity[]): ElementMap {\n\tconst elementMap: Record<string, string> = {};\n\n\titems.forEach((item) => {\n\t\tconst itemElements = item.config?.elements || {};\n\n\t\tObject.entries(itemElements).forEach(([tag, pkg]) => {\n\t\t\tconst packageSpec = String(pkg);\n\t\t\tconst normalizedTag = toPackageVersionedTag(tag, packageSpec, {\n\t\t\t\tpreserveUnversionedTag: true,\n\t\t\t});\n\t\t\tif (!elementMap[normalizedTag]) {\n\t\t\t\telementMap[normalizedTag] = packageSpec;\n\t\t\t} else if (elementMap[normalizedTag] !== packageSpec) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Element version conflict: ${normalizedTag} requires both ${elementMap[normalizedTag]} and ${packageSpec}. ` +\n\t\t\t\t\t\t`Each full versioned tag must map to exactly one package spec.`,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t});\n\n\treturn elementMap;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"element-loader-types.js","sourceRoot":"","sources":["../../src/loaders/element-loader-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuCH;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACtB,IAAI,GAAG,gBAAgB,CAAC;IACjC,OAAO,CAA6C;IAE7D,YAAY,OAAmD;QAC9D,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACjC,KAAK,CACJ,+BAA+B,OAAO,CAAC,IAAI,YAAY,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACxE,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD","sourcesContent":["/**\n * Shared types for the ElementLoader primitive and its backend adapters.\n *\n * Keeping types in their own module breaks the import cycle that would\n * otherwise form between the primitive (which dispatches to adapters) and\n * the adapters (which implement the backend interface).\n */\n\nimport type { ElementMap } from \"./ElementLoader.js\";\n\nexport type ElementTag = string;\n\nexport type { ElementMap };\n\n/**\n * Structured reason for why a specific tag failed to register.\n *\n * The primitive prefers adapter-supplied reasons (rich, diagnostic) over the\n * generic `timeout` reason it synthesizes from its own verification pass.\n */\nexport type RegistrationFailureReason =\n\t| { kind: \"timeout\"; tag: ElementTag; timeoutMs: number }\n\t| { kind: \"not-a-constructor\"; tag: ElementTag; packageName?: string }\n\t| {\n\t\t\tkind: \"package-not-in-bundle\";\n\t\t\ttag: ElementTag;\n\t\t\tpackageName: string;\n\t\t\tavailablePackages: string[];\n\t }\n\t| {\n\t\t\tkind: \"module-load-failed\";\n\t\t\ttag: ElementTag;\n\t\t\tspecifier: string;\n\t\t\tcause: string;\n\t }\n\t| {\n\t\t\tkind: \"bundle-load-failed\";\n\t\t\ttag: ElementTag;\n\t\t\turl: string;\n\t\t\tcause: string;\n\t }\n\t| { kind: \"define-failed\"; tag: ElementTag; cause: string }\n\t| { kind: \"backend-rejected\"; tag: ElementTag; cause: string }\n\t| { kind: \"no-element-class\"; tag: ElementTag; packageName: string };\n\n/**\n * Thrown by an adapter when it has structured, per-tag knowledge of which\n * registrations failed and why. The primitive unpacks the `reasons` map\n * and merges it into its own `ElementLoaderError.reasons`.\n *\n * Generic `Error` thrown from an adapter is treated as catastrophic: the\n * primitive assigns a blanket `backend-rejected` reason to every requested\n * tag that is still missing after verification.\n */\nexport class AdapterFailure extends Error {\n\toverride readonly name = \"AdapterFailure\";\n\treadonly reasons: Map<ElementTag, RegistrationFailureReason>;\n\n\tconstructor(reasons: Map<ElementTag, RegistrationFailureReason>) {\n\t\tconst tags = [...reasons.keys()];\n\t\tsuper(\n\t\t\t`Backend adapter failure for ${reasons.size} tag(s): ${tags.join(\", \")}`,\n\t\t);\n\t\tthis.reasons = reasons;\n\t}\n}\n\n/**\n * Context the primitive hands to the adapter for each load.\n *\n * The adapter is free to use `whenDefinedTimeoutMs` for its own internal\n * waits, but the primitive always enforces an independent\n * `customElements.whenDefined` verification after the adapter returns — so\n * an adapter cannot silently under-register tags even if it ignores this\n * context.\n */\nexport type BackendContext = {\n\tdoc: Document;\n\twhenDefinedTimeoutMs: number;\n};\n\n/**\n * Backend adapter contract.\n *\n * Resolve only if every requested tag was attempted and the adapter\n * believes every tag is registered. On partial failure, throw\n * `AdapterFailure` with a `reasons` map. On catastrophic failure, throw a\n * generic Error.\n */\nexport type ElementLoaderBackend = {\n\tload(elements: ElementMap, context: BackendContext): Promise<void>;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"element-loader.js","sourceRoot":"","sources":["../../src/loaders/element-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EACN,cAAc,GAKd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAA0B,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EACN,4BAA4B,GAE5B,MAAM,6BAA6B,CAAC;AASrC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI3D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC1B,IAAI,GAAG,oBAAoB,CAAC;IACrC,gBAAgB,CAAkB;IAClC,OAAO,CAA6C;IAE7D,YACC,OAAe,EACf,gBAAiC,EACjC,OAAmD;QAEnD,KAAK,CAAC,OAAO,CAAC,CAAC;Q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":["/**\n * ElementLoader primitive — the one place where \"these tags are registered\n * with customElements\" is decided.\n *\n * Owns the truthful promise contract end-to-end:\n *\n * ensureRegistered(elements, options) resolves iff every requested tag\n * is in `customElements` at the moment of resolution. On partial\n * success it rejects with an `ElementLoaderError` carrying the set of\n * unregistered tags and a per-tag `RegistrationFailureReason` map.\n *\n * The primitive delegates the actual fetch/register work to a backend\n * adapter (IIFE or ESM) but always verifies the outcome via\n * `customElements.whenDefined`. An adapter cannot silently under-register\n * — the primitive will catch it and surface a timeout reason.\n *\n * See packages/players-shared/tests/element-loader-contract.test.ts for\n * the executable specification of every failure mode this primitive is\n * required to catch.\n */\n\nimport { DEFAULT_IIFE_BUNDLE_RETRY_CONFIG } from \"../loader-config.js\";\nimport type { ElementMap } from \"./ElementLoader.js\";\nimport {\n\tAdapterFailure,\n\ttype BackendContext,\n\ttype ElementLoaderBackend,\n\ttype ElementTag,\n\ttype RegistrationFailureReason,\n} from \"./element-loader-types.js\";\nimport { createEsmBackend, type EsmBackendConfig } from \"./esm-adapter.js\";\nimport { createIifeBackend, type IifeBackendConfig } from \"./iife-adapter.js\";\nimport {\n\tassertElementPackagesAllowed,\n\ttype ElementPackagePolicy,\n} from \"./element-package-policy.js\";\n\nexport type {\n\tBackendContext,\n\tElementLoaderBackend,\n\tElementMap,\n\tElementTag,\n\tRegistrationFailureReason,\n} from \"./element-loader-types.js\";\nexport { AdapterFailure } from \"./element-loader-types.js\";\nexport type { IifeBackendConfig } from \"./iife-adapter.js\";\nexport type { EsmBackendConfig } from \"./esm-adapter.js\";\n\n/**\n * Aggregate error thrown by `ensureRegistered` when one or more requested\n * tags were not registered by the time verification timed out.\n */\nexport class ElementLoaderError extends Error {\n\toverride readonly name = \"ElementLoaderError\";\n\treadonly unregisteredTags: Set<ElementTag>;\n\treadonly reasons: Map<ElementTag, RegistrationFailureReason>;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tunregisteredTags: Set<ElementTag>,\n\t\treasons: Map<ElementTag, RegistrationFailureReason>,\n\t) {\n\t\tsuper(message);\n\t\tthis.unregisteredTags = unregisteredTags;\n\t\tthis.reasons = reasons;\n\t}\n}\n\n/**\n * Thrown by `assertRegistered` when any requested tag is missing from\n * `customElements`. Carries enough detail for the host to diagnose what\n * pre-registration step was skipped.\n */\nexport class ElementAssertionError extends Error {\n\toverride readonly name = \"ElementAssertionError\";\n\treadonly expectedTags: readonly ElementTag[];\n\treadonly missingTags: readonly ElementTag[];\n\treadonly currentlyRegisteredTags: readonly ElementTag[];\n\n\tconstructor(\n\t\texpected: ElementTag[],\n\t\tmissing: ElementTag[],\n\t\tcurrentlyRegistered: ElementTag[],\n\t) {\n\t\tsuper(buildAssertionMessage(expected, missing, currentlyRegistered));\n\t\tthis.expectedTags = expected;\n\t\tthis.missingTags = missing;\n\t\tthis.currentlyRegisteredTags = currentlyRegistered;\n\t}\n}\n\nfunction buildAssertionMessage(\n\texpected: ElementTag[],\n\tmissing: ElementTag[],\n\tregistered: ElementTag[],\n): string {\n\tconst expectedStr = expected.join(\", \");\n\tconst missingStr = missing.join(\", \");\n\tconst registeredStr = registered.length\n\t\t? registered.join(\", \")\n\t\t: \"(none enumerable)\";\n\treturn (\n\t\t`ElementLoader.assertRegistered: expected [${expectedStr}], ` +\n\t\t`missing [${missingStr}]. customElements contains: [${registeredStr}].`\n\t);\n}\n\nexport type BackendOption =\n\t| IifeBackendConfig\n\t| EsmBackendConfig\n\t| ElementLoaderBackend;\n\nexport type EnsureRegisteredOptions = {\n\tbackend: BackendOption;\n\t/**\n\t * Optional host-controlled allow-list for executable `config.elements`\n\t * packages. Omit to preserve the trusted-application behavior.\n\t */\n\telementPackagePolicy?: ElementPackagePolicy;\n\tdoc?: Document;\n\twhenDefinedTimeoutMs?: number;\n\t/**\n\t * Outer cumulative deadline for the backend's `load()` call.\n\t *\n\t * Closes the \"promise never settles\" seam for adapters whose underlying\n\t * fetch can stall indefinitely (e.g. ESM `import()` against a frozen\n\t * CDN). When the deadline elapses, the primitive synthesizes an\n\t * `AdapterFailure` with `kind: \"timeout\"` reasons for every requested\n\t * tag — surfacing as a normal `ElementLoaderError` to the caller.\n\t *\n\t * Defaults to `DEFAULT_IIFE_BUNDLE_RETRY_CONFIG.timeoutMs` so\n\t * adapter-internal retry windows (IIFE bundle-build polling) fit\n\t * inside the same overall budget.\n\t */\n\tloadTimeoutMs?: number;\n};\n\nconst DEFAULT_WHEN_DEFINED_TIMEOUT_MS = 5000;\nconst DEFAULT_LOAD_TIMEOUT_MS = DEFAULT_IIFE_BUNDLE_RETRY_CONFIG.timeoutMs;\n\n// Module-scoped in-flight cache. Key: backend signature + sorted elements.\n// Keeps concurrent identical requests collapsed to one backend call.\nconst inFlightRequests = new Map<string, Promise<void>>();\nconst resolvedEsmBackends = new Map<string, ElementLoaderBackend>();\nconst resolvedBackendOverrides = new Map<string, ElementLoaderBackend>();\n\n/**\n * Resolve iff every tag in `elements` is registered with `customElements`.\n * Reject with `ElementLoaderError` otherwise.\n *\n * The primitive is the sole authority on registration state:\n * - Empty element map resolves immediately (no backend call).\n * - Already-registered tags resolve immediately (no backend call).\n * - Concurrent identical requests share one backend call.\n * - After the adapter's `load` settles, a post-load verification pass\n * (bounded `customElements.whenDefined`) checks every tag. Any missing\n * tag becomes a rejection.\n */\nexport async function ensureRegistered(\n\telements: ElementMap,\n\toptions: EnsureRegisteredOptions,\n): Promise<void> {\n\tif (!elements || Object.keys(elements).length === 0) return;\n\t// Enforce policy before the already-registered fast path: a matching tag in\n\t// the registry must not turn a disallowed authored package into valid input.\n\tassertElementPackagesAllowed(elements, options.elementPackagePolicy);\n\n\tconst tags = Object.keys(elements);\n\tconst timeoutMs =\n\t\toptions.whenDefinedTimeoutMs ?? DEFAULT_WHEN_DEFINED_TIMEOUT_MS;\n\tconst loadTimeoutMs = options.loadTimeoutMs ?? DEFAULT_LOAD_TIMEOUT_MS;\n\n\t// Fast path: everything already registered. Skip backend and dedup\n\t// bookkeeping entirely.\n\tif (allAlreadyRegistered(tags)) return;\n\n\tconst dedupKey = buildDedupKey(options.backend, elements);\n\tconst existing = inFlightRequests.get(dedupKey);\n\tif (existing) return existing;\n\n\tconst backend = resolveBackend(options.backend);\n\tconst doc = resolveDoc(options.doc);\n\n\tconst promise = runEnsureRegistered(\n\t\telements,\n\t\ttags,\n\t\tbackend,\n\t\t{ doc, whenDefinedTimeoutMs: timeoutMs },\n\t\ttimeoutMs,\n\t\tloadTimeoutMs,\n\t);\n\n\tinFlightRequests.set(dedupKey, promise);\n\ttry {\n\t\tawait promise;\n\t} finally {\n\t\tif (inFlightRequests.get(dedupKey) === promise) {\n\t\t\tinFlightRequests.delete(dedupKey);\n\t\t}\n\t}\n}\n\nasync function runEnsureRegistered(\n\telements: ElementMap,\n\ttags: ElementTag[],\n\tbackend: ElementLoaderBackend,\n\tcontext: BackendContext,\n\ttimeoutMs: number,\n\tloadTimeoutMs: number,\n): Promise<void> {\n\tlet adapterError: Error | undefined;\n\ttry {\n\t\tawait raceWithLoadTimeout(\n\t\t\tbackend.load(elements, context),\n\t\t\ttags,\n\t\t\tloadTimeoutMs,\n\t\t);\n\t} catch (err) {\n\t\tadapterError = err instanceof Error ? err : new Error(String(err));\n\t}\n\n\tconst verification = await Promise.all(\n\t\ttags.map(async (tag) => {\n\t\t\tif (isRegistered(tag)) return { tag, ok: true as const };\n\t\t\ttry {\n\t\t\t\tawait whenDefinedWithTimeout(tag, timeoutMs);\n\t\t\t\treturn { tag, ok: true as const };\n\t\t\t} catch {\n\t\t\t\treturn { tag, ok: false as const };\n\t\t\t}\n\t\t}),\n\t);\n\n\tconst unregistered = new Set<ElementTag>();\n\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\tfor (const v of verification) {\n\t\tif (v.ok) continue;\n\t\tunregistered.add(v.tag);\n\t\tconst adapterReason = extractAdapterReason(adapterError, v.tag);\n\t\treasons.set(\n\t\t\tv.tag,\n\t\t\tadapterReason ?? { kind: \"timeout\", tag: v.tag, timeoutMs },\n\t\t);\n\t}\n\n\tif (unregistered.size > 0) {\n\t\tthrow new ElementLoaderError(\n\t\t\t`Element registration failed; missing tags: ${[...unregistered].join(\", \")}`,\n\t\t\tunregistered,\n\t\t\treasons,\n\t\t);\n\t}\n}\n\n/**\n * Race the backend's `load()` against a cumulative deadline.\n *\n * On timeout, synthesize an `AdapterFailure` whose `reasons` map carries\n * a `kind: \"timeout\"` entry per requested tag. The verification pass in\n * `runEnsureRegistered` will then produce a normal `ElementLoaderError`\n * with structured per-tag reasons — same surface shape as any other\n * adapter rejection.\n */\nasync function raceWithLoadTimeout(\n\tloadPromise: Promise<void>,\n\ttags: ElementTag[],\n\tloadTimeoutMs: number,\n): Promise<void> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\ttry {\n\t\tawait Promise.race([\n\t\t\tloadPromise,\n\t\t\tnew Promise<void>((_, reject) => {\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\t\t\t\tfor (const tag of tags) {\n\t\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\t\tkind: \"timeout\",\n\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\ttimeoutMs: loadTimeoutMs,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treject(new AdapterFailure(reasons));\n\t\t\t\t}, loadTimeoutMs);\n\t\t\t}),\n\t\t]);\n\t} finally {\n\t\tif (timer) clearTimeout(timer);\n\t}\n}\n\n/**\n * Synchronously assert that every tag is already in `customElements`.\n * Throws `ElementAssertionError` with diagnostic detail otherwise.\n *\n * Used by hosts that opt into the \"preloaded\" strategy — they pre-register\n * elements out-of-band and want a loud failure if anything is missing.\n */\nexport function assertRegistered(tags: ElementTag[]): void {\n\tif (!tags || tags.length === 0) return;\n\tconst missing = tags.filter((tag) => !isRegistered(tag));\n\tif (missing.length === 0) return;\n\tthrow new ElementAssertionError(tags, missing, snapshotRegisteredTags());\n}\n\n// ─── Internals ───────────────────────────────────────────────────────────────\n\nfunction resolveBackend(backend: BackendOption): ElementLoaderBackend {\n\tif (isDirectBackend(backend)) return backend;\n\tif (\"kind\" in backend) {\n\t\tif (backend.kind === \"iife\") return createIifeBackend(backend);\n\t\tif (backend.kind === \"esm\") {\n\t\t\tconst backendKey = backendKeyOf(backend);\n\t\t\tconst override = resolvedBackendOverrides.get(backendKey);\n\t\t\tif (override) return override;\n\t\t\tconst existing = resolvedEsmBackends.get(backendKey);\n\t\t\tif (existing) return existing;\n\t\t\tconst created = createEsmBackend(backend);\n\t\t\tresolvedEsmBackends.set(backendKey, created);\n\t\t\treturn created;\n\t\t}\n\t}\n\tthrow new Error(\"ElementLoader: invalid backend option\");\n}\n\nfunction isDirectBackend(\n\tbackend: BackendOption,\n): backend is ElementLoaderBackend {\n\treturn (\n\t\ttypeof (backend as { load?: unknown }).load === \"function\" &&\n\t\t!(\"kind\" in backend)\n\t);\n}\n\nfunction resolveDoc(doc: Document | undefined): Document {\n\tif (doc) return doc;\n\tif (typeof document !== \"undefined\") return document;\n\tthrow new Error(\n\t\t\"ElementLoader: no Document available; pass options.doc explicitly\",\n\t);\n}\n\nfunction buildDedupKey(backend: BackendOption, elements: ElementMap): string {\n\tconst backendKey = backendKeyOf(backend);\n\tconst entries = Object.entries(elements).sort(([a], [b]) =>\n\t\ta.localeCompare(b),\n\t);\n\treturn `${backendKey}|${JSON.stringify(entries)}`;\n}\n\nconst backendIds = new WeakMap<ElementLoaderBackend, string>();\nlet nextBackendId = 0;\nconst functionIds = new WeakMap<Function, string>();\nlet nextFunctionId = 0;\nconst opaqueObjectIds = new WeakMap<object, string>();\nlet nextOpaqueObjectId = 0;\n\nfunction backendKeyOf(backend: BackendOption): string {\n\tif (isDirectBackend(backend)) {\n\t\tlet id = backendIds.get(backend);\n\t\tif (!id) {\n\t\t\tid = `b${++nextBackendId}`;\n\t\t\tbackendIds.set(backend, id);\n\t\t}\n\t\treturn `backend#${id}`;\n\t}\n\tif (\"kind\" in backend) {\n\t\tif (backend.kind === \"iife\") {\n\t\t\treturn `iife#${fingerprintValue({\n\t\t\t\tkind: \"iife\",\n\t\t\t\tbundleHost: backend.bundleHost,\n\t\t\t\tbundleType: backend.bundleType ?? \"\",\n\t\t\t\tneedsControllers: backend.needsControllers ?? true,\n\t\t\t\tbundleInfo: backend.bundleInfo ?? null,\n\t\t\t\tdebugEnabled: backend.debugEnabled ?? null,\n\t\t\t\tbundleRetry: backend.bundleRetry ?? null,\n\t\t\t\tonBundleRetryStatus: backend.onBundleRetryStatus ?? null,\n\t\t\t\ttrackPageActions: backend.trackPageActions ?? false,\n\t\t\t\tinstrumentationProvider: backend.instrumentationProvider ?? null,\n\t\t\t})}`;\n\t\t}\n\t\tif (backend.kind === \"esm\") {\n\t\t\treturn `esm#${fingerprintValue({\n\t\t\t\tkind: \"esm\",\n\t\t\t\tcdnBaseUrl: backend.cdnBaseUrl,\n\t\t\t\tcdnProvider: backend.cdnProvider ?? null,\n\t\t\t\tmoduleResolution: backend.moduleResolution ?? \"url\",\n\t\t\t\tview: backend.view ?? \"delivery\",\n\t\t\t\tviewConfig: backend.viewConfig ?? null,\n\t\t\t\tloadControllers: backend.loadControllers ?? true,\n\t\t\t\tdebugEnabled: backend.debugEnabled ?? null,\n\t\t\t\ttrackPageActions: backend.trackPageActions ?? false,\n\t\t\t\tinstrumentationProvider: backend.instrumentationProvider ?? null,\n\t\t\t})}`;\n\t\t}\n\t}\n\treturn \"unknown\";\n}\n\nfunction fingerprintValue(value: unknown): string {\n\treturn JSON.stringify(normalizeForFingerprint(value, new Map()));\n}\n\nfunction normalizeForFingerprint(\n\tvalue: unknown,\n\tseen: Map<object, string>,\n): unknown {\n\tif (value === null || value === undefined) return value;\n\tconst primitiveType = typeof value;\n\tif (\n\t\tprimitiveType === \"string\" ||\n\t\tprimitiveType === \"number\" ||\n\t\tprimitiveType === \"boolean\"\n\t) {\n\t\treturn value;\n\t}\n\tif (primitiveType === \"function\") {\n\t\treturn { __functionRef: getFunctionRefId(value as Function) };\n\t}\n\tif (primitiveType !== \"object\") {\n\t\treturn String(value);\n\t}\n\n\tconst objectValue = value as object;\n\tconst existing = seen.get(objectValue);\n\tif (existing) return { __cycleRef: existing };\n\tconst cycleRefId = `cycle#${seen.size + 1}`;\n\tseen.set(objectValue, cycleRefId);\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => normalizeForFingerprint(entry, seen));\n\t}\n\n\tif (!isPlainObject(value)) {\n\t\treturn { __objectRef: getOpaqueObjectRefId(objectValue) };\n\t}\n\n\tconst normalized: Record<string, unknown> = {};\n\tfor (const key of Object.keys(value).sort()) {\n\t\tnormalized[key] = normalizeForFingerprint(\n\t\t\t(value as Record<string, unknown>)[key],\n\t\t\tseen,\n\t\t);\n\t}\n\treturn normalized;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction getFunctionRefId(fn: Function): string {\n\tlet id = functionIds.get(fn);\n\tif (!id) {\n\t\tid = `fn#${++nextFunctionId}`;\n\t\tfunctionIds.set(fn, id);\n\t}\n\treturn id;\n}\n\nfunction getOpaqueObjectRefId(value: object): string {\n\tlet id = opaqueObjectIds.get(value);\n\tif (!id) {\n\t\tid = `obj#${++nextOpaqueObjectId}`;\n\t\topaqueObjectIds.set(value, id);\n\t}\n\treturn id;\n}\n\nfunction allAlreadyRegistered(tags: ElementTag[]): boolean {\n\treturn tags.every((tag) => isRegistered(tag));\n}\n\nfunction isRegistered(tag: ElementTag): boolean {\n\tif (typeof customElements === \"undefined\") return false;\n\treturn customElements.get(tag) !== undefined;\n}\n\nasync function whenDefinedWithTimeout(\n\ttag: ElementTag,\n\ttimeoutMs: number,\n): Promise<void> {\n\tif (typeof customElements === \"undefined\") {\n\t\tthrow new Error(`no customElements to await ${tag}`);\n\t}\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\ttry {\n\t\treturn await Promise.race([\n\t\t\tcustomElements.whenDefined(tag).then(() => undefined),\n\t\t\tnew Promise<void>((_, reject) => {\n\t\t\t\ttimer = setTimeout(\n\t\t\t\t\t() => reject(new Error(`Timeout waiting for ${tag}`)),\n\t\t\t\t\ttimeoutMs,\n\t\t\t\t);\n\t\t\t}),\n\t\t]);\n\t} finally {\n\t\tif (timer) clearTimeout(timer);\n\t}\n}\n\nfunction snapshotRegisteredTags(): ElementTag[] {\n\tif (typeof customElements === \"undefined\") return [];\n\t// Standard `CustomElementRegistry` does not expose iteration. Tests install\n\t// a scripted registry with a `__pieSnapshot` extension to make diagnostic\n\t// messages assertable. Production falls through to an empty list —\n\t// still strictly better than today's \"missing tags: X\" error which leaks\n\t// no registry state at all.\n\tconst reg = customElements as unknown as {\n\t\t__pieSnapshot?: () => ElementTag[];\n\t};\n\tif (typeof reg.__pieSnapshot === \"function\") {\n\t\ttry {\n\t\t\treturn reg.__pieSnapshot();\n\t\t} catch {\n\t\t\treturn [];\n\t\t}\n\t}\n\treturn [];\n}\n\nfunction extractAdapterReason(\n\terr: Error | undefined,\n\ttag: ElementTag,\n): RegistrationFailureReason | undefined {\n\tif (!err) return undefined;\n\tif (err instanceof AdapterFailure) return err.reasons.get(tag);\n\treturn { kind: \"backend-rejected\", tag, cause: err.message };\n}\n\n// ─── Test-only helpers ───────────────────────────────────────────────────────\n\n/**\n * Internal helpers for test harnesses. Not part of the public runtime API;\n * production code should never reach for these.\n *\n * @internal\n */\nexport const __testing = {\n\tresetDedupState(): void {\n\t\tinFlightRequests.clear();\n\t\tresolvedEsmBackends.clear();\n\t\tresolvedBackendOverrides.clear();\n\t},\n\tinFlightCount(): number {\n\t\treturn inFlightRequests.size;\n\t},\n\tdedupKeyFor(elements: ElementMap, backend: BackendOption): string {\n\t\treturn buildDedupKey(backend, elements);\n\t},\n\treplaceResolvedBackendForTesting(\n\t\tbackend: BackendOption,\n\t\tresolvedBackend: ElementLoaderBackend,\n\t): void {\n\t\tresolvedBackendOverrides.set(backendKeyOf(backend), resolvedBackend);\n\t},\n\trestoreResolvedBackendsForTesting(): void {\n\t\tresolvedEsmBackends.clear();\n\t\tresolvedBackendOverrides.clear();\n\t},\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"element-package-policy.js","sourceRoot":"","sources":["../../src/loaders/element-package-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAWnD,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAIzC;IACA;IAJQ,IAAI,GAAG,2BAA2B,CAAC;IAErD,YACU,OAAe,EACf,WAAmB,EAC5B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAQ;IAI7B,CAAC;CACD;AAED,SAAS,aAAa,CAAC,OAAe;IACrC,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC;AACzC,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IAK3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO;QACN,WAAW,EAAE,MAAM,CAAC,IAAI;QACxB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI;QACxE,OAAO,EAAE,MAAM,CAAC,OAAO;KACvB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAC3C,QAAoB,EACpB,MAA6B;IAE7B,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,OAAO,GAAG,MAAM,CAAC,eAAe;SACpC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,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,WAAW,CAC9C,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACR,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,MAAM,IAAI,yBAAyB,CAClC,OAAO,EACP,WAAW,EACX,0CAA0C,WAAW,SAAS,OAAO,GAAG,CACxE,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { valid as validSemver } from \"semver\";\n\nimport { parsePackageName } from \"../pie/utils.js\";\nimport type { ElementMap } from \"./ElementLoader.js\";\n\n/** Optional host policy for executable packages named by `config.elements`. */\nexport type ElementPackagePolicy = {\n\t/** Exact package names, or exact `name@version` specs, that may execute. */\n\tallowedPackages: readonly string[];\n\t/** Require exact semver without build metadata. Defaults to true. */\n\trequireExactVersions?: boolean;\n};\n\nexport class ElementPackagePolicyError extends Error {\n\toverride readonly name = \"ElementPackagePolicyError\";\n\n\tconstructor(\n\t\treadonly tagName: string,\n\t\treadonly packageSpec: string,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t}\n}\n\nfunction isExactSemver(version: string): boolean {\n\treturn validSemver(version) === version;\n}\n\nfunction parsePolicyPackageSpec(spec: string): {\n\tpackageName: string;\n\tpackagePath: string;\n\tversion: string;\n} {\n\tconst parsed = parsePackageName(spec);\n\treturn {\n\t\tpackageName: parsed.name,\n\t\tpackagePath: parsed.path ? `${parsed.name}/${parsed.path}` : parsed.name,\n\t\tversion: parsed.version,\n\t};\n}\n\n/**\n * Validate an element map only when a host explicitly supplies a policy.\n * Omitting the policy preserves the existing trusted-application behavior.\n */\nexport function assertElementPackagesAllowed(\n\telements: ElementMap,\n\tpolicy?: ElementPackagePolicy,\n): void {\n\tif (!policy) return;\n\tconst allowed = policy.allowedPackages\n\t\t.filter((entry): entry is string => typeof entry === \"string\")\n\t\t.map((entry) => entry.trim())\n\t\t.filter(Boolean);\n\n\tfor (const [tagName, rawSpec] of Object.entries(elements)) {\n\t\tconst packageSpec = String(rawSpec).trim();\n\t\tlet parsed: ReturnType<typeof parsePolicyPackageSpec>;\n\t\ttry {\n\t\t\tparsed = parsePolicyPackageSpec(packageSpec);\n\t\t} catch {\n\t\t\tthrow new ElementPackagePolicyError(\n\t\t\t\ttagName,\n\t\t\t\tpackageSpec,\n\t\t\t\t`Element package policy rejected invalid package spec \"${packageSpec}\" for ${tagName}.`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t(policy.requireExactVersions ?? true) &&\n\t\t\t!isExactSemver(parsed.version)\n\t\t) {\n\t\t\tconst restriction = parsed.version.includes(\"+\")\n\t\t\t\t? \"does not allow semver build metadata because legacy IIFE bundle routes use + as a package separator\"\n\t\t\t\t: \"requires an exact version\";\n\t\t\tthrow new ElementPackagePolicyError(\n\t\t\t\ttagName,\n\t\t\t\tpackageSpec,\n\t\t\t\t`Element package policy ${restriction} for ${tagName}; received \"${packageSpec}\".`,\n\t\t\t);\n\t\t}\n\n\t\tconst permitted = allowed.some((entry) => {\n\t\t\tif (entry === packageSpec) return true;\n\t\t\ttry {\n\t\t\t\tconst allowedSpec = parsePolicyPackageSpec(entry);\n\t\t\t\treturn (\n\t\t\t\t\tallowedSpec.version.length === 0 &&\n\t\t\t\t\tallowedSpec.packagePath === parsed.packagePath\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\n\t\tif (!permitted) {\n\t\t\tthrow new ElementPackagePolicyError(\n\t\t\t\ttagName,\n\t\t\t\tpackageSpec,\n\t\t\t\t`Element package policy does not allow \"${packageSpec}\" for ${tagName}.`,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esm-adapter.js","sourceRoot":"","sources":["../../src/loaders/esm-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;A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,0BAA0B,CACzB,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,+BAA+B,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,CAAC,EAC9D,WAAW,EACX,GAAG,EACH,UAAU,CACV,CAAC;QACH,CAAC;IACF,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,CAAC;IACnE,CAAC;IACD,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,wBAAwB,EAAE,gBAAgB;KAC1C,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,IAAY,EAAE,GAAa;IACnD,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAsB,CAAC;IAChE,MAAM,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,wBAAwB;IAChC,MAAM,iBAAiB,GAAG,CACzB,OAAO,iBAAiB,KAAK,WAAW,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAK7D,CAAC;IACb,MAAM,QAAQ,GACb,OAAO,iBAAiB,EAAE,QAAQ,KAAK,UAAU;QACjD,iBAAiB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACd,6GAA6G,CAC7G,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["/**\n * ESM backend adapter for the ElementLoader primitive.\n *\n * Loads PIE elements via dynamic `import()` from static browser ESM files on a\n * CDN, optionally resolving bare specifiers through an import map injected into\n * the host document. On any per-tag failure (module load, non-constructor\n * element class, define failure), throws `AdapterFailure` with a structured\n * `reasons` map.\n *\n * Like the IIFE adapter, this module does not gate its own promise on\n * `customElements.whenDefined`; the primitive performs that verification\n * uniformly. Here the adapter's job is narrowly to fetch, extract, and\n * call `customElements.define`.\n */\n\nimport { defineCustomElementSafely } from \"../pie/custom-element-define.js\";\nimport type { InstrumentationProvider } from \"../instrumentation/types.js\";\nimport { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport { pieRegistry } from \"../pie/registry.js\";\nimport { validateCustomElementTag } from \"../pie/tag-names.js\";\nimport { isCustomElementConstructor, Status } from \"../pie/types.js\";\nimport type { ElementMap } from \"./ElementLoader.js\";\nimport {\n\tAdapterFailure,\n\ttype BackendContext,\n\ttype ElementLoaderBackend,\n\ttype ElementTag,\n\ttype RegistrationFailureReason,\n} from \"./element-loader-types.js\";\n\n/** View configuration: how a PIE package's subpath maps to a tag suffix. */\nexport type ViewConfig = {\n\tsubpath: string;\n\ttagSuffix: string;\n\tfallback?: string;\n};\n\nexport const BUILT_IN_VIEWS: Record<string, ViewConfig> = {\n\tdelivery: { subpath: \"\", tagSuffix: \"\" },\n\tauthor: { subpath: \"/author\", tagSuffix: \"-config\", fallback: \"delivery\" },\n\tprint: { subpath: \"/print\", tagSuffix: \"-print\", fallback: \"delivery\" },\n};\n\nexport type BuiltInEsmCdnProviderName = \"jsdelivr\" | \"esm.sh\";\nexport type EsmCdnProviderName = BuiltInEsmCdnProviderName | (string & {});\n\nexport type EsmCdnProvider = {\n\tname: EsmCdnProviderName;\n\tpackageJsonUrl(packageVersion: string): string;\n\tbrowserViewUrl(packageVersion: string, view: string): string;\n\tbrowserControllerUrl(packageVersion: string): string;\n\tsharedDependencyUrl(\n\t\tdependencyName: string,\n\t\tversion: string,\n\t\tsubpath?: string,\n\t): string;\n};\n\nexport type EsmCdnProviderOption = EsmCdnProviderName | EsmCdnProvider;\n\nexport type EsmBackendConfig = {\n\tkind: \"esm\";\n\t/** Base URL for the ESM CDN (e.g., \"https://esm.sh\"). */\n\tcdnBaseUrl: string;\n\t/** CDN URL strategy. Defaults to jsDelivr, or is inferred from cdnBaseUrl when possible. */\n\tcdnProvider?: EsmCdnProviderOption;\n\t/** `\"url\"` loads via fully-qualified URLs; `\"import-map\"` uses bare specifiers. */\n\tmoduleResolution?: \"url\" | \"import-map\";\n\t/** View to load (`delivery`, `author`, `print`, or a custom name). */\n\tview?: string;\n\t/** Custom view configuration (overrides built-ins). */\n\tviewConfig?: ViewConfig;\n\t/** Whether to also load controller modules. */\n\tloadControllers?: boolean;\n\t/** Debug flag hook. */\n\tdebugEnabled?: () => boolean;\n\t/** Whether ESM dependency conflict/failure events should be instrumented. */\n\ttrackPageActions?: boolean;\n\t/** Instrumentation provider for ESM dependency conflict/failure events. */\n\tinstrumentationProvider?: InstrumentationProvider;\n};\n\ntype PackageMetadata = {\n\texports?: Record<string, unknown>;\n\tdependencies?: Record<string, string>;\n\toptionalDependencies?: Record<string, string>;\n\tpeerDependencies?: Record<string, string>;\n\tpie?: {\n\t\tbrowserSharedDependencies?: Record<string, string>;\n\t};\n};\n\n/** @internal */\nexport type EsmModuleImporter = (specifier: string) => Promise<unknown>;\n/** @internal */\nexport type EsmImportMapObserver = (json: string, doc: Document) => void;\n/** @internal */\nexport type EsmPackageMetadataLoader = (\n\tpackageVersion: string,\n\tpackageJsonUrl: string,\n) => Promise<PackageMetadata | null>;\n\n/**\n * Test-only seam exposed via `EsmBackend.__seams`. Lets contract tests\n * inject scripted import behaviour and observe import-map injection\n * without going through the network or the document. Not part of the\n * runtime API; production code must not touch this field.\n *\n * @internal\n */\nexport type EsmBackendTestSeams = {\n\treplaceImporter(fn: EsmModuleImporter): void;\n\tobserveImportMapInjection(cb: EsmImportMapObserver): void;\n\treplacePackageMetadataLoader(fn: EsmPackageMetadataLoader): void;\n\trestore(): void;\n};\n\nexport type EsmBackend = ElementLoaderBackend & {\n\t/** @internal Test-only seam — see {@link EsmBackendTestSeams}. */\n\treadonly __seams: EsmBackendTestSeams;\n};\n\nexport function createEsmBackend(config: EsmBackendConfig): EsmBackend {\n\tconst cdnBaseUrl = config.cdnBaseUrl.replace(/\\/+$/, \"\");\n\tconst cdnProvider = resolveCdnProvider(config.cdnProvider, cdnBaseUrl);\n\tconst moduleResolution = config.moduleResolution ?? \"url\";\n\tconst view = config.view ?? \"delivery\";\n\tconst loadControllers = config.loadControllers ?? true;\n\tconst viewConfig = resolveEsmViewConfig(view, config.viewConfig);\n\n\tconst injectedPackageVersions = new Set<string>();\n\tconst importMappedPackageVersions = new Map<string, string>();\n\tlet sharedDependencyVersions: Record<string, string> = {};\n\tlet importer: EsmModuleImporter = defaultImporter;\n\tlet packageMetadataLoader: EsmPackageMetadataLoader =\n\t\tdefaultPackageMetadataLoader;\n\tlet importMapObserver: EsmImportMapObserver | undefined;\n\n\tconst __seams: EsmBackendTestSeams = {\n\t\treplaceImporter(fn) {\n\t\t\timporter = fn;\n\t\t},\n\t\tobserveImportMapInjection(cb) {\n\t\t\timportMapObserver = cb;\n\t\t},\n\t\treplacePackageMetadataLoader(fn) {\n\t\t\tpackageMetadataLoader = fn;\n\t\t},\n\t\trestore() {\n\t\t\timporter = defaultImporter;\n\t\t\tpackageMetadataLoader = defaultPackageMetadataLoader;\n\t\t\timportMapObserver = undefined;\n\t\t\tinjectedPackageVersions.clear();\n\t\t\timportMappedPackageVersions.clear();\n\t\t\tsharedDependencyVersions = {};\n\t\t},\n\t};\n\n\tasync function load(\n\t\telements: ElementMap,\n\t\tcontext: BackendContext,\n\t): Promise<void> {\n\t\tif (!elements || Object.keys(elements).length === 0) return;\n\t\tif (moduleResolution === \"import-map\") {\n\t\t\tassertImportMapSupported();\n\t\t}\n\n\t\tconst newEntries: ElementMap = {};\n\t\tfor (const [tag, pkg] of Object.entries(elements)) {\n\t\t\tconst packageName = extractPackageName(pkg);\n\t\t\tif (moduleResolution === \"import-map\") {\n\t\t\t\tconst existingVersion = importMappedPackageVersions.get(packageName);\n\t\t\t\tif (existingVersion && existingVersion !== pkg) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Conflicting browser ESM package version for ${packageName}: ${existingVersion} is already mapped, but ${pkg} was requested`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!injectedPackageVersions.has(pkg)) {\n\t\t\t\tnewEntries[tag] = pkg;\n\t\t\t}\n\t\t}\n\t\tif (Object.keys(newEntries).length > 0) {\n\t\t\tlet importMapResult: BrowserImportMapBuildResult;\n\t\t\ttry {\n\t\t\t\timportMapResult = await buildImportMapJson(\n\t\t\t\t\tnewEntries,\n\t\t\t\t\tviewConfig,\n\t\t\t\t\tcdnProvider,\n\t\t\t\t\tloadControllers,\n\t\t\t\t\tmoduleResolution === \"import-map\",\n\t\t\t\t\tpackageMetadataLoader,\n\t\t\t\t\tsharedDependencyVersions,\n\t\t\t\t\treportSharedDependencyConflict,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treportSharedDependencyError(err);\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tconst json = importMapResult.json;\n\t\t\tif (json) {\n\t\t\t\tassertImportMapSupported();\n\t\t\t\tinjectImportMap(json, context.doc);\n\t\t\t\timportMapObserver?.(json, context.doc);\n\t\t\t}\n\t\t\tsharedDependencyVersions = importMapResult.sharedDependencyVersions;\n\t\t\tfor (const pkg of Object.values(newEntries)) {\n\t\t\t\tinjectedPackageVersions.add(pkg);\n\t\t\t\tif (moduleResolution === \"import-map\") {\n\t\t\t\t\timportMappedPackageVersions.set(extractPackageName(pkg), pkg);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\tconst registry = pieRegistry();\n\n\t\tawait Promise.all(\n\t\t\tObject.entries(elements).map(async ([tag, packageVersion]) => {\n\t\t\t\tconst packageName = extractPackageName(packageVersion);\n\t\t\t\tlet actualTag: string;\n\t\t\t\ttry {\n\t\t\t\t\tactualTag = validateCustomElementTag(\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\t`element tag for ${packageName}`,\n\t\t\t\t\t);\n\t\t\t\t} catch (err) {\n\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\tkind: \"define-failed\",\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst specifier = resolveElementSpecifier(\n\t\t\t\t\tpackageName,\n\t\t\t\t\tpackageVersion,\n\t\t\t\t\tviewConfig,\n\t\t\t\t\tmoduleResolution,\n\t\t\t\t\tcdnProvider,\n\t\t\t\t\tview,\n\t\t\t\t);\n\n\t\t\t\tlet module: any;\n\t\t\t\ttry {\n\t\t\t\t\tmodule = await importer(specifier);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (viewConfig.fallback) {\n\t\t\t\t\t\tconst fallbackConfig =\n\t\t\t\t\t\t\tBUILT_IN_VIEWS[viewConfig.fallback] ?? BUILT_IN_VIEWS.delivery;\n\t\t\t\t\t\tconst fallbackSpecifier = resolveElementSpecifier(\n\t\t\t\t\t\t\tpackageName,\n\t\t\t\t\t\t\tpackageVersion,\n\t\t\t\t\t\t\tfallbackConfig,\n\t\t\t\t\t\t\tmoduleResolution,\n\t\t\t\t\t\t\tcdnProvider,\n\t\t\t\t\t\t\tviewConfig.fallback,\n\t\t\t\t\t\t);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tmodule = await importer(fallbackSpecifier);\n\t\t\t\t\t\t} catch (fallbackErr) {\n\t\t\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\t\t\tkind: \"module-load-failed\",\n\t\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\t\tspecifier: fallbackSpecifier,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\tfallbackErr instanceof Error\n\t\t\t\t\t\t\t\t\t\t? fallbackErr.message\n\t\t\t\t\t\t\t\t\t\t: String(fallbackErr),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\t\tkind: \"module-load-failed\",\n\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\tspecifier,\n\t\t\t\t\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst ElementClass = pickElementClass(module, view);\n\t\t\t\tif (!ElementClass) {\n\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\tkind: \"no-element-class\",\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tpackageName,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (!isCustomElementConstructor(ElementClass)) {\n\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\tkind: \"not-a-constructor\",\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tpackageName,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\t\tactualTag,\n\t\t\t\t\t\tclass extends ElementClass {},\n\t\t\t\t\t\t`element tag for ${packageName}`,\n\t\t\t\t\t);\n\t\t\t\t} catch (err) {\n\t\t\t\t\treasons.set(tag, {\n\t\t\t\t\t\tkind: \"define-failed\",\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet controller: any = null;\n\t\t\t\tif (loadControllers) {\n\t\t\t\t\tconst controllerSpecifier = resolveControllerSpecifier(\n\t\t\t\t\t\tpackageName,\n\t\t\t\t\t\tpackageVersion,\n\t\t\t\t\t\tmoduleResolution,\n\t\t\t\t\t\tcdnProvider,\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst controllerModule: any = await importer(controllerSpecifier);\n\t\t\t\t\t\tcontroller = controllerModule?.default ?? controllerModule;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Controllers are best-effort; element registration is what the\n\t\t\t\t\t\t// primitive verifies.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tregistry[actualTag] = {\n\t\t\t\t\tpackage: packageVersion,\n\t\t\t\t\tstatus: Status.loaded,\n\t\t\t\t\ttagName: actualTag,\n\t\t\t\t\telement: ElementClass,\n\t\t\t\t\tcontroller,\n\t\t\t\t\tconfig: null,\n\t\t\t\t\tbundleType: \"esm\" as unknown as import(\"../pie/types.js\").BundleType,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\tif (reasons.size > 0) {\n\t\t\tthrow new AdapterFailure(reasons);\n\t\t}\n\t}\n\n\tfunction getInstrumentationProvider(): InstrumentationProvider | undefined {\n\t\tif (!config.trackPageActions) return undefined;\n\t\tconst provider = config.instrumentationProvider;\n\t\tif (!isInstrumentationProvider(provider)) return undefined;\n\t\tif (!provider.isReady()) return undefined;\n\t\treturn provider;\n\t}\n\n\tfunction reportSharedDependencyConflict(\n\t\tattributes: Record<string, unknown>,\n\t): void {\n\t\tif (typeof console !== \"undefined\" && console.warn) {\n\t\t\tconsole.warn(\n\t\t\t\t`[pie-esm] Shared dependency version conflict resolved for ${String(attributes.dependencyName)}`,\n\t\t\t\tattributes,\n\t\t\t);\n\t\t}\n\t\tconst provider = getInstrumentationProvider();\n\t\tif (!provider) return;\n\t\ttry {\n\t\t\tprovider.trackEvent(\"pie-esm-shared-dependency-conflict\", attributes);\n\t\t} catch {\n\t\t\t// Swallow: instrumentation must never break loading.\n\t\t}\n\t}\n\n\tfunction reportSharedDependencyError(error: unknown): void {\n\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\tif (typeof console !== \"undefined\" && console.error) {\n\t\t\tconsole.error(\"[pie-esm] Shared dependency resolution failed\", err);\n\t\t}\n\t\tconst provider = getInstrumentationProvider();\n\t\tif (!provider) return;\n\t\ttry {\n\t\t\tprovider.trackError(err, {\n\t\t\t\tcomponent: \"esm-adapter\",\n\t\t\t\terrorType: \"EsmSharedDependencyError\",\n\t\t\t});\n\t\t} catch {\n\t\t\t// Swallow: instrumentation must never break loading.\n\t\t}\n\t}\n\n\treturn {\n\t\tload,\n\t\tget __seams() {\n\t\t\treturn __seams;\n\t\t},\n\t};\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\nexport function mapEsmViewElements(\n\telements: ElementMap,\n\tview = \"delivery\",\n\tviewConfig?: ViewConfig,\n): ElementMap {\n\tconst resolvedViewConfig = resolveEsmViewConfig(view, viewConfig);\n\treturn Object.fromEntries(\n\t\tObject.entries(elements).map(([tag, packageVersion]) => [\n\t\t\t`${tag}${resolvedViewConfig.tagSuffix}`,\n\t\t\tpackageVersion,\n\t\t]),\n\t);\n}\n\nfunction defaultImporter(specifier: string): Promise<unknown> {\n\t// @vite-ignore — dynamic import resolved at runtime.\n\treturn import(/* @vite-ignore */ specifier);\n}\n\nasync function defaultPackageMetadataLoader(\n\tpackageVersion: string,\n\tpackageJsonUrl: string,\n): Promise<PackageMetadata | null> {\n\tconst browserFetch =\n\t\ttypeof window !== \"undefined\" &&\n\t\ttypeof (window as Window & { fetch?: typeof fetch }).fetch === \"function\"\n\t\t\t? (window as Window & { fetch: typeof fetch }).fetch.bind(window)\n\t\t\t: undefined;\n\tif (!browserFetch) {\n\t\treturn null;\n\t}\n\n\tconst response = await browserFetch(packageJsonUrl);\n\tif (!response.ok) {\n\t\treturn null;\n\t}\n\treturn (await response.json()) as PackageMetadata;\n}\n\nfunction resolveCdnProvider(\n\tprovider: EsmCdnProviderOption | undefined,\n\tcdnBaseUrl: string,\n): EsmCdnProvider {\n\tif (isEsmCdnProvider(provider)) return provider;\n\tconst resolvedProviderName =\n\t\tprovider ?? (cdnBaseUrl.includes(\"esm.sh\") ? \"esm.sh\" : \"jsdelivr\");\n\tif (resolvedProviderName === \"esm.sh\") {\n\t\treturn createEsmShProvider(cdnBaseUrl);\n\t}\n\treturn createJsDelivrProvider(cdnBaseUrl, resolvedProviderName);\n}\n\nfunction isEsmCdnProvider(value: unknown): value is EsmCdnProvider {\n\tif (!value || typeof value !== \"object\") return false;\n\tconst candidate = value as Partial<Record<keyof EsmCdnProvider, unknown>>;\n\treturn (\n\t\ttypeof candidate.name === \"string\" &&\n\t\ttypeof candidate.packageJsonUrl === \"function\" &&\n\t\ttypeof candidate.browserViewUrl === \"function\" &&\n\t\ttypeof candidate.browserControllerUrl === \"function\" &&\n\t\ttypeof candidate.sharedDependencyUrl === \"function\"\n\t);\n}\n\nfunction createJsDelivrProvider(\n\tcdnBaseUrl: string,\n\tname: EsmCdnProviderName = \"jsdelivr\",\n): EsmCdnProvider {\n\treturn {\n\t\tname,\n\t\tpackageJsonUrl: (packageVersion) =>\n\t\t\t`${cdnBaseUrl}/${packageVersion}/package.json`,\n\t\tbrowserViewUrl: (packageVersion, view) =>\n\t\t\t`${cdnBaseUrl}/${packageVersion}/dist/browser/${view}/index.js`,\n\t\tbrowserControllerUrl: (packageVersion) =>\n\t\t\t`${cdnBaseUrl}/${packageVersion}/dist/browser/controller/index.js`,\n\t\tsharedDependencyUrl: (dependencyName, version, subpath) => {\n\t\t\tconst suffix = subpath ? `/${subpath}/+esm` : \"/+esm\";\n\t\t\treturn `${cdnBaseUrl}/${dependencyName}@${version}${suffix}`;\n\t\t},\n\t};\n}\n\nfunction createEsmShProvider(cdnBaseUrl: string): EsmCdnProvider {\n\tconst esmBaseUrl = cdnBaseUrl.replace(/\\/+$/, \"\");\n\tconst rawBaseUrl = toRawEsmShBaseUrl(esmBaseUrl);\n\treturn {\n\t\tname: \"esm.sh\",\n\t\tpackageJsonUrl: (packageVersion) =>\n\t\t\t`${rawBaseUrl}/${packageVersion}/package.json`,\n\t\tbrowserViewUrl: (packageVersion, view) =>\n\t\t\t`${rawBaseUrl}/${packageVersion}/dist/browser/${view}/index.js`,\n\t\tbrowserControllerUrl: (packageVersion) =>\n\t\t\t`${rawBaseUrl}/${packageVersion}/dist/browser/controller/index.js`,\n\t\tsharedDependencyUrl: (dependencyName, version, subpath) => {\n\t\t\tconst suffix = subpath ? `/${subpath}` : \"\";\n\t\t\treturn `${esmBaseUrl}/${dependencyName}@${version}${suffix}`;\n\t\t},\n\t};\n}\n\nfunction toRawEsmShBaseUrl(cdnBaseUrl: string): string {\n\ttry {\n\t\tconst url = new URL(cdnBaseUrl);\n\t\tif (url.hostname === \"raw.esm.sh\")\n\t\t\treturn url.toString().replace(/\\/+$/, \"\");\n\t\tif (url.hostname === \"esm.sh\") {\n\t\t\turl.hostname = \"raw.esm.sh\";\n\t\t\treturn url.toString().replace(/\\/+$/, \"\");\n\t\t}\n\t} catch {\n\t\t// Fall through to the public raw endpoint for non-URL test fixtures.\n\t}\n\treturn \"https://raw.esm.sh\";\n}\n\nfunction resolveEsmViewConfig(view: string, viewConfig?: ViewConfig): ViewConfig {\n\treturn viewConfig ?? BUILT_IN_VIEWS[view] ?? BUILT_IN_VIEWS.delivery;\n}\n\nfunction assertBrowserEsmExports(\n\tmetadata: PackageMetadata | null,\n\tpackageVersion: string,\n\tviewConfig: ViewConfig,\n\tloadControllers: boolean,\n\tviewName: string,\n): void {\n\tif (!metadata?.exports) return;\n\n\tconst requiredExports = new Set<string>([\n\t\t`./browser/${browserViewName(viewConfig, viewName)}`,\n\t]);\n\tif (viewConfig.fallback) {\n\t\tconst fallbackConfig = BUILT_IN_VIEWS[viewConfig.fallback];\n\t\tif (fallbackConfig) {\n\t\t\trequiredExports.add(\n\t\t\t\t`./browser/${browserViewName(fallbackConfig, viewConfig.fallback)}`,\n\t\t\t);\n\t\t}\n\t}\n\tif (loadControllers) {\n\t\trequiredExports.add(\"./browser/controller\");\n\t}\n\n\tfor (const exportKey of requiredExports) {\n\t\tif (!(exportKey in metadata.exports)) {\n\t\t\tthrow new Error(\n\t\t\t\t`${packageVersion} does not publish browser ESM export ${exportKey}; use IIFE/preloaded mode or publish browser ESM artifacts first`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction extractPackageName(packageVersion: string): string {\n\tconst parts = packageVersion.split(\"@\");\n\treturn parts.length >= 3 ? `@${parts[1]}` : parts[0];\n}\n\nfunction cleanViewSubpath(subpath: string): string | null {\n\tconst cleanSubpath = subpath.replace(/^\\/+|\\/+$/g, \"\");\n\treturn cleanSubpath.length > 0 ? cleanSubpath : null;\n}\n\nfunction browserViewName(\n\tviewConfig: ViewConfig,\n\tviewName = \"delivery\",\n): string {\n\tconst subpathView = cleanViewSubpath(viewConfig.subpath);\n\treturn subpathView ?? viewName;\n}\n\nfunction resolveBrowserViewUrl(\n\tpackageVersion: string,\n\tviewConfig: ViewConfig,\n\tcdnProvider: EsmCdnProvider,\n\tviewName = \"delivery\",\n): string {\n\tconst view = browserViewName(viewConfig, viewName);\n\treturn cdnProvider.browserViewUrl(packageVersion, view);\n}\n\nfunction resolveBrowserControllerUrl(\n\tpackageVersion: string,\n\tcdnProvider: EsmCdnProvider,\n): string {\n\treturn cdnProvider.browserControllerUrl(packageVersion);\n}\n\nfunction resolveElementSpecifier(\n\tpackageName: string,\n\tpackageVersion: string,\n\tviewConfig: ViewConfig,\n\tmoduleResolution: \"url\" | \"import-map\",\n\tcdnProvider: EsmCdnProvider,\n\tviewName: string,\n): string {\n\tif (moduleResolution === \"import-map\") {\n\t\treturn viewConfig.subpath\n\t\t\t? `${packageName}${viewConfig.subpath}`\n\t\t\t: packageName;\n\t}\n\treturn resolveBrowserViewUrl(\n\t\tpackageVersion,\n\t\tviewConfig,\n\t\tcdnProvider,\n\t\tviewName,\n\t);\n}\n\nfunction resolveControllerSpecifier(\n\tpackageName: string,\n\tpackageVersion: string,\n\tmoduleResolution: \"url\" | \"import-map\",\n\tcdnProvider: EsmCdnProvider,\n): string {\n\tif (moduleResolution === \"import-map\") {\n\t\treturn `${packageName}/controller`;\n\t}\n\treturn resolveBrowserControllerUrl(packageVersion, cdnProvider);\n}\n\nfunction pickElementClass(module: any, view: string): unknown {\n\tif (!module || typeof module !== \"object\") return undefined;\n\tif (view === \"author\") {\n\t\treturn module.default ?? module.Configure ?? module.Element;\n\t}\n\tif (view === \"print\") {\n\t\treturn module.default ?? module.Print ?? module.Element;\n\t}\n\treturn module.default ?? module.Element;\n}\n\nconst SHARED_BROWSER_DEPENDENCIES = [\"react\", \"react-dom\"] as const;\n\nfunction declaredSharedDependencyVersion(\n\tmetadata: PackageMetadata | null,\n\tdependencyName: (typeof SHARED_BROWSER_DEPENDENCIES)[number],\n\tpackageVersion: string,\n): string | undefined {\n\tconst version = metadata?.pie?.browserSharedDependencies?.[dependencyName];\n\tif (!version) {\n\t\tthrow new Error(\n\t\t\t`${packageVersion} is missing required pie.browserSharedDependencies.${dependencyName}`,\n\t\t);\n\t}\n\tif (!isExactVersion(version)) {\n\t\tthrow new Error(\n\t\t\t`${packageVersion} pie.browserSharedDependencies.${dependencyName} must be an exact version; received \"${version}\"`,\n\t\t);\n\t}\n\treturn version;\n}\n\nfunction packageUsesSharedDependency(\n\tmetadata: PackageMetadata | null,\n\tdependencyName: (typeof SHARED_BROWSER_DEPENDENCIES)[number],\n): boolean {\n\treturn Boolean(\n\t\tmetadata?.pie?.browserSharedDependencies?.[dependencyName] ||\n\t\t\tmetadata?.peerDependencies?.[dependencyName] ||\n\t\t\tmetadata?.dependencies?.[dependencyName] ||\n\t\t\tmetadata?.optionalDependencies?.[dependencyName],\n\t);\n}\n\nfunction addSharedDependencyImports(\n\timports: Record<string, string>,\n\tselectedVersions: Record<string, string>,\n\tlockedVersions: Set<string>,\n\tdependencyName: (typeof SHARED_BROWSER_DEPENDENCIES)[number],\n\tversion: string | undefined,\n\tcdnProvider: EsmCdnProvider,\n\tpackageVersion: string,\n\tonConflict: (attributes: Record<string, unknown>) => void,\n): void {\n\tif (!version) {\n\t\treturn;\n\t}\n\n\tconst currentVersion = selectedVersions[dependencyName];\n\tlet resolvedVersion = version;\n\tif (currentVersion && currentVersion !== version) {\n\t\tresolvedVersion = resolveSharedDependencyVersion(\n\t\t\tdependencyName,\n\t\t\tcurrentVersion,\n\t\t\tversion,\n\t\t\tpackageVersion,\n\t\t\tlockedVersions.has(dependencyName),\n\t\t);\n\t\tonConflict({\n\t\t\tdependencyName,\n\t\t\texistingVersion: currentVersion,\n\t\t\trequestedVersion: version,\n\t\t\tresolvedVersion,\n\t\t\tpackageVersion,\n\t\t});\n\t}\n\tselectedVersions[dependencyName] = resolvedVersion;\n\n\timports[dependencyName] = cdnProvider.sharedDependencyUrl(\n\t\tdependencyName,\n\t\tresolvedVersion,\n\t);\n\tif (dependencyName === \"react\") {\n\t\timports[\"react/jsx-runtime\"] = cdnProvider.sharedDependencyUrl(\n\t\t\t\"react\",\n\t\t\tresolvedVersion,\n\t\t\t\"jsx-runtime\",\n\t\t);\n\t\timports[\"react/jsx-dev-runtime\"] = cdnProvider.sharedDependencyUrl(\n\t\t\t\"react\",\n\t\t\tresolvedVersion,\n\t\t\t\"jsx-dev-runtime\",\n\t\t);\n\t}\n\tif (dependencyName === \"react-dom\") {\n\t\timports[\"react-dom/client\"] = cdnProvider.sharedDependencyUrl(\n\t\t\t\"react-dom\",\n\t\t\tresolvedVersion,\n\t\t\t\"client\",\n\t\t);\n\t}\n}\n\nfunction isExactVersion(version: string): boolean {\n\treturn /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/.test(version);\n}\n\nfunction parseVersion(version: string): {\n\tmajor: number;\n\tminor: number;\n\tpatch: number;\n} {\n\tconst match = version.match(/^(\\d+)\\.(\\d+)\\.(\\d+)/);\n\tif (!match) {\n\t\tthrow new Error(`Invalid shared browser dependency version \"${version}\"`);\n\t}\n\treturn {\n\t\tmajor: Number(match[1]),\n\t\tminor: Number(match[2]),\n\t\tpatch: Number(match[3]),\n\t};\n}\n\nfunction compareVersions(a: string, b: string): number {\n\tconst parsedA = parseVersion(a);\n\tconst parsedB = parseVersion(b);\n\tif (parsedA.major !== parsedB.major) return parsedA.major - parsedB.major;\n\tif (parsedA.minor !== parsedB.minor) return parsedA.minor - parsedB.minor;\n\treturn parsedA.patch - parsedB.patch;\n}\n\nfunction resolveSharedDependencyVersion(\n\tdependencyName: string,\n\tcurrentVersion: string,\n\trequestedVersion: string,\n\tpackageVersion: string,\n\tisLocked: boolean,\n): string {\n\tconst current = parseVersion(currentVersion);\n\tconst requested = parseVersion(requestedVersion);\n\tif (current.major !== requested.major) {\n\t\tthrow new Error(\n\t\t\t`Conflicting shared browser dependency ${dependencyName}: ${currentVersion} vs ${requestedVersion} from ${packageVersion}; different major versions cannot share one browser singleton`,\n\t\t);\n\t}\n\tif (isLocked && compareVersions(requestedVersion, currentVersion) > 0) {\n\t\tthrow new Error(\n\t\t\t`Conflicting shared browser dependency ${dependencyName}: ${currentVersion} is already selected, but ${packageVersion} requires higher version ${requestedVersion}; the browser singleton cannot be upgraded after import-map injection`,\n\t\t);\n\t}\n\treturn compareVersions(currentVersion, requestedVersion) >= 0\n\t\t? currentVersion\n\t\t: requestedVersion;\n}\n\ntype BrowserImportMapBuildResult = {\n\tjson: string | null;\n\tsharedDependencyVersions: Record<string, string>;\n};\n\nasync function buildImportMapJson(\n\telements: ElementMap,\n\tviewConfig: ViewConfig,\n\tcdnProvider: EsmCdnProvider,\n\tloadControllers: boolean,\n\tincludeElementImports: boolean,\n\tpackageMetadataLoader: EsmPackageMetadataLoader,\n\tcurrentSharedDependencyVersions: Record<string, string>,\n\tonConflict: (attributes: Record<string, unknown>) => void,\n): Promise<BrowserImportMapBuildResult> {\n\tconst imports: Record<string, string> = {};\n\tconst selectedVersions: Record<string, string> = {\n\t\t...currentSharedDependencyVersions,\n\t};\n\tconst lockedVersions = new Set(Object.keys(currentSharedDependencyVersions));\n\tfor (const [, pkg] of Object.entries(elements)) {\n\t\tconst packageName = extractPackageName(pkg);\n\t\tif (includeElementImports) {\n\t\t\timports[packageName] = resolveBrowserViewUrl(\n\t\t\t\tpkg,\n\t\t\t\tBUILT_IN_VIEWS.delivery,\n\t\t\t\tcdnProvider,\n\t\t\t\t\"delivery\",\n\t\t\t);\n\t\t\tif (viewConfig.subpath) {\n\t\t\t\timports[`${packageName}${viewConfig.subpath}`] = resolveBrowserViewUrl(\n\t\t\t\t\tpkg,\n\t\t\t\t\tviewConfig,\n\t\t\t\t\tcdnProvider,\n\t\t\t\t\tcleanViewSubpath(viewConfig.subpath) ?? \"delivery\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (loadControllers) {\n\t\t\t\timports[`${packageName}/controller`] = resolveBrowserControllerUrl(\n\t\t\t\t\tpkg,\n\t\t\t\t\tcdnProvider,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (viewConfig.fallback) {\n\t\t\t\tconst fallbackConfig = BUILT_IN_VIEWS[viewConfig.fallback];\n\t\t\t\tif (fallbackConfig) {\n\t\t\t\t\tconst fallbackSpecifier = fallbackConfig.subpath\n\t\t\t\t\t\t? `${packageName}${fallbackConfig.subpath}`\n\t\t\t\t\t\t: packageName;\n\t\t\t\t\timports[fallbackSpecifier] = resolveBrowserViewUrl(\n\t\t\t\t\t\tpkg,\n\t\t\t\t\t\tfallbackConfig,\n\t\t\t\t\t\tcdnProvider,\n\t\t\t\t\t\tviewConfig.fallback,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst metadata = await packageMetadataLoader(\n\t\t\tpkg,\n\t\t\tcdnProvider.packageJsonUrl(pkg),\n\t\t);\n\t\tassertBrowserEsmExports(\n\t\t\tmetadata,\n\t\t\tpkg,\n\t\t\tviewConfig,\n\t\t\tloadControllers,\n\t\t\tcleanViewSubpath(viewConfig.subpath) ?? \"delivery\",\n\t\t);\n\t\tfor (const dependencyName of SHARED_BROWSER_DEPENDENCIES) {\n\t\t\tif (!packageUsesSharedDependency(metadata, dependencyName)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taddSharedDependencyImports(\n\t\t\t\timports,\n\t\t\t\tselectedVersions,\n\t\t\t\tlockedVersions,\n\t\t\t\tdependencyName,\n\t\t\t\tdeclaredSharedDependencyVersion(metadata, dependencyName, pkg),\n\t\t\t\tcdnProvider,\n\t\t\t\tpkg,\n\t\t\t\tonConflict,\n\t\t\t);\n\t\t}\n\t}\n\tif (Object.keys(imports).length === 0) {\n\t\treturn { json: null, sharedDependencyVersions: selectedVersions };\n\t}\n\treturn {\n\t\tjson: JSON.stringify({ imports }, null, 2),\n\t\tsharedDependencyVersions: selectedVersions,\n\t};\n}\n\nfunction injectImportMap(json: string, doc: Document): void {\n\tconst script = doc.createElement(\"script\") as HTMLScriptElement;\n\tscript.type = \"importmap\";\n\tscript.textContent = json;\n\tdoc.head.appendChild(script);\n}\n\nfunction assertImportMapSupported(): void {\n\tconst htmlScriptElement = (\n\t\ttypeof HTMLScriptElement !== \"undefined\" ? HTMLScriptElement : undefined\n\t) as\n\t\t| (typeof HTMLScriptElement & {\n\t\t\t\tsupports?: (type: string) => boolean;\n\t\t })\n\t\t| undefined;\n\tconst supports =\n\t\ttypeof htmlScriptElement?.supports === \"function\" &&\n\t\thtmlScriptElement.supports(\"importmap\");\n\tif (!supports) {\n\t\tthrow new Error(\n\t\t\t'This browser does not support import maps. Use moduleResolution=\"url\" or switch to iife/preloaded strategy.',\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iife-adapter.js","sourceRoot":"","sources":["../../src/loaders/iife-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EACN,gCAAgC,GAEhC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,o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AC,CAAU;YAC3B,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACzB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * IIFE backend adapter for the ElementLoader primitive.\n *\n * Loads PIE elements from IIFE bundles served by the PIE build service,\n * then registers them with `customElements`. On any per-tag failure\n * (missing package, non-constructor element class, define failure),\n * throws `AdapterFailure` with a structured `reasons` map that the\n * primitive unpacks into `ElementLoaderError.reasons`.\n *\n * This adapter deliberately does *not* gate its own promise on\n * `customElements.whenDefined` — the primitive performs that verification\n * uniformly for every backend, so the adapter's job is narrowly:\n *\n * 1. Fetch the bundle.\n * 2. Extract per-tag element classes from `window.pie.default`.\n * 3. Validate each class is a custom-element constructor.\n * 4. Call `customElements.define` via `defineCustomElementSafely`.\n * 5. Collect structured per-tag reasons for anything that failed.\n * 6. Resolve (everything OK) or throw `AdapterFailure` (anything failed).\n */\n\nimport type { InstrumentationProvider } from \"../instrumentation/types.js\";\nimport { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport {\n\tDEFAULT_IIFE_BUNDLE_RETRY_CONFIG,\n\ttype IifeBundleRetryConfig,\n} from \"../loader-config.js\";\nimport { defineCustomElementSafely } from \"../pie/custom-element-define.js\";\nimport { pieRegistry } from \"../pie/registry.js\";\nimport { validateCustomElementTag } from \"../pie/tag-names.js\";\nimport {\n\tBundleType,\n\tisCustomElementConstructor,\n\tStatus,\n} from \"../pie/types.js\";\nimport { getPackageWithoutVersion, parsePackageName } from \"../pie/utils.js\";\nimport type { ElementMap } from \"./ElementLoader.js\";\nimport {\n\tAdapterFailure,\n\ttype BackendContext,\n\ttype ElementLoaderBackend,\n\ttype ElementTag,\n\ttype RegistrationFailureReason,\n} from \"./element-loader-types.js\";\n\n/**\n * Default PIE bundle service base URL. Exported so widgets can use it as\n * the fallback when the host does not supply `loaderOptions.bundleHost`.\n */\nexport const DEFAULT_BUNDLE_HOST = \"https://proxy.pie-api.com/bundles/\";\n\n/**\n * Bundle-build retry status emitted while a bundle is being built or after\n * it completes. Hosts that display a \"bundle is building…\" UI subscribe via\n * `onBundleRetryStatus` and read each transition.\n */\nexport type IifeBundleRetryStatus = {\n\tstate: \"retrying\" | \"completed\" | \"timeout\" | \"cancelled\";\n\turl: string;\n\tattempt: number;\n\telapsedMs: number;\n\ttimeoutMs: number;\n\tretryDelayMs?: number;\n\treason?: string;\n};\n\nexport type IifeBackendConfig = {\n\tkind: \"iife\";\n\t/** Base URL for the PIE bundle service. */\n\tbundleHost: string;\n\t/** Bundle variant to request (player / client-player / editor). */\n\tbundleType?: BundleType;\n\t/** Whether the registered entries should carry their controller exports. */\n\tneedsControllers?: boolean;\n\t/** Explicit bundle override (hash + optional URL) supplied by the host. */\n\tbundleInfo?: { hash?: string; url?: string };\n\t/** Debug flag hook. */\n\tdebugEnabled?: () => boolean;\n\t/**\n\t * Retry policy for transient bundle load failures.\n\t *\n\t * When the bundle service is building a bundle on demand, the first\n\t * few `<script src>` requests can fail. This policy polls until the\n\t * bundle is available or `timeoutMs` elapses. Default matches\n\t * `DEFAULT_IIFE_BUNDLE_RETRY_CONFIG`.\n\t */\n\tbundleRetry?: IifeBundleRetryConfig;\n\t/**\n\t * Callback invoked with retry status transitions. Lets hosts render\n\t * \"bundle still building, retrying in Ns\" messaging without touching\n\t * internal adapter state.\n\t */\n\tonBundleRetryStatus?: (status: IifeBundleRetryStatus) => void;\n\t/**\n\t * If true and `instrumentationProvider` is set and ready, retry\n\t * lifecycle events (`pie-iife-bundle-retry*`) are emitted.\n\t */\n\ttrackPageActions?: boolean;\n\t/**\n\t * Instrumentation provider used to emit retry lifecycle telemetry.\n\t */\n\tinstrumentationProvider?: InstrumentationProvider;\n};\n\n/**\n * Bundle-script loader seam. Default implementation injects a `<script>` tag\n * into the document head. Tests replace it with a scripted stub via\n * `IifeBackendTestSeams.replaceLoadBundleScript`.\n *\n * @internal\n */\nexport type IifeBundleScriptLoader = (\n\turl: string,\n\tdoc: Document,\n) => Promise<void>;\n\n/**\n * Test-only seam exposed via `IifeBackend.__seams`. Lets contract tests\n * inject scripted bundle-load behaviour without going through the network\n * or the document. Not part of the runtime API; production code must not\n * touch this field.\n *\n * @internal\n */\nexport type IifeBackendTestSeams = {\n\treplaceLoadBundleScript(fn: IifeBundleScriptLoader): void;\n\trestore(): void;\n};\n\nexport type IifeBackend = ElementLoaderBackend & {\n\t/** @internal Test-only seam — see {@link IifeBackendTestSeams}. */\n\treadonly __seams: IifeBackendTestSeams;\n};\n\n/**\n * The legacy IIFE bundle global is keyed by unversioned package name. Two\n * distinct specs for one package therefore cannot coexist in a single bundle:\n * one constructor would silently be reused for both requested versioned tags.\n */\nfunction findIifeElementMapConflict(elements: ElementMap): string | undefined {\n\tconst specsByPackageName = new Map<string, Set<string>>();\n\n\tfor (const packageSpecValue of Object.values(elements)) {\n\t\tconst packageSpec = String(packageSpecValue);\n\t\tconst packageName = parsePackageName(packageSpec).name;\n\t\tconst specs = specsByPackageName.get(packageName) ?? new Set<string>();\n\t\tspecs.add(packageSpec);\n\t\tspecsByPackageName.set(packageName, specs);\n\t}\n\n\tconst conflictingPackages = [...specsByPackageName.entries()]\n\t\t.filter(([, specs]) => specs.size > 1)\n\t\t.map(([packageName]) => packageName)\n\t\t.sort();\n\n\treturn conflictingPackages.length > 0\n\t\t? `IIFE bundles cannot load multiple package specs for: ${conflictingPackages.join(\", \")}`\n\t\t: undefined;\n}\n\nexport function createIifeBackend(config: IifeBackendConfig): IifeBackend {\n\tconst bundleType = config.bundleType ?? BundleType.clientPlayer;\n\tconst needsControllers = config.needsControllers ?? true;\n\n\tlet loadBundleScript: IifeBundleScriptLoader = defaultLoadBundleScript;\n\tconst inFlightBundleLoads = new Map<string, Promise<void>>();\n\n\tconst __seams: IifeBackendTestSeams = {\n\t\treplaceLoadBundleScript(fn) {\n\t\t\tloadBundleScript = fn;\n\t\t\tinFlightBundleLoads.clear();\n\t\t},\n\t\trestore() {\n\t\t\tloadBundleScript = defaultLoadBundleScript;\n\t\t\tinFlightBundleLoads.clear();\n\t\t},\n\t};\n\n\tasync function ensureBundleLoaded(url: string, doc: Document): Promise<void> {\n\t\tconst existing = inFlightBundleLoads.get(url);\n\t\tif (existing) return existing;\n\t\tconst promise = loadBundleScriptWithRetry(url, doc).finally(() => {\n\t\t\tinFlightBundleLoads.delete(url);\n\t\t});\n\t\tinFlightBundleLoads.set(url, promise);\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Wrap the single-shot script loader with poll-until-ready retry.\n\t *\n\t * The PIE bundle service may return a transient failure while it\n\t * builds a bundle on demand. Retry with fixed-interval polling until\n\t * the bundle is ready or the cumulative deadline elapses. Emits\n\t * retry lifecycle events to the host via `onBundleRetryStatus` and to\n\t * the instrumentation provider (if configured and ready).\n\t */\n\tasync function loadBundleScriptWithRetry(\n\t\turl: string,\n\t\tdoc: Document,\n\t): Promise<void> {\n\t\tconst { retryDelayMs, timeoutMs } = resolveBundleRetryConfig(\n\t\t\tconfig.bundleRetry,\n\t\t);\n\t\tconst startedAt = Date.now();\n\t\tlet attempt = 0;\n\t\twhile (true) {\n\t\t\tattempt += 1;\n\t\t\ttry {\n\t\t\t\tawait loadBundleScript(url, doc);\n\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\tif (attempt > 1) {\n\t\t\t\t\tconfig.onBundleRetryStatus?.({\n\t\t\t\t\t\tstate: \"completed\",\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\telapsedMs,\n\t\t\t\t\t\ttimeoutMs,\n\t\t\t\t\t});\n\t\t\t\t\ttrackRetryEvent(\"pie-iife-bundle-retry-success\", {\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\telapsedMs,\n\t\t\t\t\t\ttimeoutMs,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\tconst remainingMs = timeoutMs - elapsedMs;\n\t\t\t\tconst reason = error instanceof Error ? error.message : String(error);\n\t\t\t\tif (remainingMs <= 0) {\n\t\t\t\t\tconst timeoutError = new Error(\n\t\t\t\t\t\t`IIFE bundle load timed out after ${timeoutMs}ms: ${url}`,\n\t\t\t\t\t);\n\t\t\t\t\tconfig.onBundleRetryStatus?.({\n\t\t\t\t\t\tstate: \"timeout\",\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\telapsedMs,\n\t\t\t\t\t\ttimeoutMs,\n\t\t\t\t\t\treason,\n\t\t\t\t\t});\n\t\t\t\t\ttrackRetryEvent(\"pie-iife-bundle-retry-timeout\", {\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\telapsedMs,\n\t\t\t\t\t\ttimeoutMs,\n\t\t\t\t\t\tlastError: reason,\n\t\t\t\t\t});\n\t\t\t\t\ttrackRetryError(timeoutError, {\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\telapsedMs,\n\t\t\t\t\t\ttimeoutMs,\n\t\t\t\t\t\tlastError: reason,\n\t\t\t\t\t});\n\t\t\t\t\tthrow timeoutError;\n\t\t\t\t}\n\t\t\t\tconst nextDelay = Math.min(retryDelayMs, remainingMs);\n\t\t\t\tconfig.onBundleRetryStatus?.({\n\t\t\t\t\tstate: \"retrying\",\n\t\t\t\t\turl,\n\t\t\t\t\tattempt,\n\t\t\t\t\telapsedMs,\n\t\t\t\t\ttimeoutMs,\n\t\t\t\t\tretryDelayMs: nextDelay,\n\t\t\t\t\treason,\n\t\t\t\t});\n\t\t\t\ttrackRetryEvent(\"pie-iife-bundle-retry\", {\n\t\t\t\t\turl,\n\t\t\t\t\tattempt,\n\t\t\t\t\telapsedMs,\n\t\t\t\t\tretryDelayMs: nextDelay,\n\t\t\t\t\ttimeoutMs,\n\t\t\t\t\tlastError: reason,\n\t\t\t\t});\n\t\t\t\tawait waitMs(nextDelay);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction getInstrumentationProvider(): InstrumentationProvider | undefined {\n\t\tif (!config.trackPageActions) return undefined;\n\t\tconst provider = config.instrumentationProvider;\n\t\tif (!isInstrumentationProvider(provider)) return undefined;\n\t\tif (!provider.isReady()) return undefined;\n\t\treturn provider;\n\t}\n\n\tfunction trackRetryEvent(\n\t\teventName: string,\n\t\tattributes: Record<string, unknown>,\n\t): void {\n\t\tconst provider = getInstrumentationProvider();\n\t\tif (!provider) return;\n\t\ttry {\n\t\t\tprovider.trackEvent(eventName, attributes);\n\t\t} catch {\n\t\t\t// Swallow: instrumentation must never break loading.\n\t\t}\n\t}\n\n\tfunction trackRetryError(\n\t\terror: Error,\n\t\tattributes: Record<string, unknown>,\n\t): void {\n\t\tconst provider = getInstrumentationProvider();\n\t\tif (!provider) return;\n\t\ttry {\n\t\t\tprovider.trackError(error, {\n\t\t\t\t...attributes,\n\t\t\t\tcomponent: \"iife-adapter\",\n\t\t\t\terrorType: \"IifeBundleRetryError\",\n\t\t\t});\n\t\t} catch {\n\t\t\t// Swallow: instrumentation must never break loading.\n\t\t}\n\t}\n\n\tasync function load(\n\t\telements: ElementMap,\n\t\tcontext: BackendContext,\n\t): Promise<void> {\n\t\tif (!elements || Object.keys(elements).length === 0) return;\n\n\t\tconst conflict = findIifeElementMapConflict(elements);\n\t\tif (conflict) {\n\t\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\t\tfor (const tag of Object.keys(elements)) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"backend-rejected\",\n\t\t\t\t\ttag,\n\t\t\t\t\tcause: conflict,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthrow new AdapterFailure(reasons);\n\t\t}\n\n\t\tconst bundleUrl = buildBundleUrl(elements, bundleType, config);\n\t\ttry {\n\t\t\tawait ensureBundleLoaded(bundleUrl, context.doc);\n\t\t} catch (err) {\n\t\t\tconst cause = err instanceof Error ? err.message : String(err);\n\t\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\t\tfor (const tag of Object.keys(elements)) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"bundle-load-failed\",\n\t\t\t\t\ttag,\n\t\t\t\t\turl: bundleUrl,\n\t\t\t\t\tcause,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthrow new AdapterFailure(reasons);\n\t\t}\n\n\t\tconst pieModule = readPieModule();\n\t\tif (!pieModule) {\n\t\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\t\tfor (const tag of Object.keys(elements)) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"bundle-load-failed\",\n\t\t\t\t\ttag,\n\t\t\t\t\turl: bundleUrl,\n\t\t\t\t\tcause: \"window.pie.default missing after bundle load\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tthrow new AdapterFailure(reasons);\n\t\t}\n\n\t\tconst reasons = new Map<ElementTag, RegistrationFailureReason>();\n\t\tconst isEditorBundle = bundleType === BundleType.editor;\n\t\tconst registry = pieRegistry();\n\n\t\tfor (const [tag, packageVersion] of Object.entries(elements)) {\n\t\t\tconst packageName = getPackageWithoutVersion(packageVersion);\n\t\t\tconst elementData = pieModule[packageName];\n\t\t\tif (!elementData) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"package-not-in-bundle\",\n\t\t\t\t\ttag,\n\t\t\t\t\tpackageName,\n\t\t\t\t\tavailablePackages: Object.keys(pieModule),\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst ElementClass = isEditorBundle\n\t\t\t\t? (elementData.Configure ?? createEmptyConfigure())\n\t\t\t\t: elementData.Element;\n\n\t\t\tif (!ElementClass) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"no-element-class\",\n\t\t\t\t\ttag,\n\t\t\t\t\tpackageName,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isCustomElementConstructor(ElementClass)) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"not-a-constructor\",\n\t\t\t\t\ttag,\n\t\t\t\t\tpackageName,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet actualTag: string;\n\t\t\ttry {\n\t\t\t\tactualTag = validateCustomElementTag(\n\t\t\t\t\ttag,\n\t\t\t\t\t`element tag for ${packageName}`,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"define-failed\",\n\t\t\t\t\ttag,\n\t\t\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\tactualTag,\n\t\t\t\t\tclass extends ElementClass {},\n\t\t\t\t\t`element tag for ${packageName}`,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treasons.set(tag, {\n\t\t\t\t\tkind: \"define-failed\",\n\t\t\t\t\ttag,\n\t\t\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tregistry[actualTag] = {\n\t\t\t\tpackage: packageVersion,\n\t\t\t\tstatus: Status.loaded,\n\t\t\t\ttagName: actualTag,\n\t\t\t\telement: ElementClass,\n\t\t\t\tcontroller: needsControllers ? (elementData.controller ?? null) : null,\n\t\t\t\tconfig: elementData.config ?? null,\n\t\t\t\tbundleType,\n\t\t\t};\n\t\t}\n\n\t\tif (reasons.size > 0) {\n\t\t\tthrow new AdapterFailure(reasons);\n\t\t}\n\t}\n\n\treturn {\n\t\tload,\n\t\tget __seams() {\n\t\t\treturn __seams;\n\t\t},\n\t};\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\nfunction defaultLoadBundleScript(url: string, doc: Document): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst script = doc.createElement(\"script\") as HTMLScriptElement;\n\t\tscript.src = url;\n\t\tscript.defer = true;\n\t\tscript.setAttribute(\"data-pie-bundle\", \"true\");\n\t\tscript.onload = () => resolve();\n\t\tscript.onerror = () =>\n\t\t\treject(new Error(`Failed to load IIFE bundle from: ${url}`));\n\t\tdoc.head.appendChild(script);\n\t});\n}\n\nfunction readPieModule(): Record<string, any> | undefined {\n\tconst maybeWindow = (\n\t\tglobalThis as { window?: { pie?: { default?: unknown } } }\n\t).window;\n\tconst pieDefault = maybeWindow?.pie?.default;\n\tif (!pieDefault || typeof pieDefault !== \"object\") return undefined;\n\treturn pieDefault as Record<string, any>;\n}\n\nfunction buildBundleUrl(\n\telements: ElementMap,\n\tbundleType: BundleType,\n\tconfig: IifeBackendConfig,\n): string {\n\tconst elementTags = Object.keys(elements).sort().join(\",\");\n\n\tif (config.bundleInfo?.url) {\n\t\tconst separator = config.bundleInfo.url.includes(\"?\") ? \"&\" : \"?\";\n\t\treturn elementTags\n\t\t\t? `${config.bundleInfo.url}${separator}elements=${encodeURIComponent(elementTags)}`\n\t\t\t: config.bundleInfo.url;\n\t}\n\n\tconst packageVersions = Object.values(elements).join(\"+\");\n\tconst host = normalizeBundleHost(config.bundleHost);\n\tconst base = `${host}${encodeURI(packageVersions)}/${bundleType}`;\n\treturn elementTags\n\t\t? `${base}?elements=${encodeURIComponent(elementTags)}`\n\t\t: base;\n}\n\nfunction normalizeBundleHost(host: string): string {\n\treturn `${host.trim().replace(/\\/+$/, \"\")}/`;\n}\n\nfunction resolveBundleRetryConfig(\n\tconfigured: IifeBundleRetryConfig | undefined,\n): Required<IifeBundleRetryConfig> {\n\tconst retryDelayMs =\n\t\ttypeof configured?.retryDelayMs === \"number\" && configured.retryDelayMs > 0\n\t\t\t? configured.retryDelayMs\n\t\t\t: DEFAULT_IIFE_BUNDLE_RETRY_CONFIG.retryDelayMs;\n\tconst timeoutMs =\n\t\ttypeof configured?.timeoutMs === \"number\" && configured.timeoutMs > 0\n\t\t\t? configured.timeoutMs\n\t\t\t: DEFAULT_IIFE_BUNDLE_RETRY_CONFIG.timeoutMs;\n\treturn { retryDelayMs, timeoutMs };\n}\n\nfunction waitMs(ms: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction createEmptyConfigure(): CustomElementConstructor {\n\t// Minimal configure fallback used for editor bundles that omit a Configure\n\t// export. Intentionally silent; the host will see a blank configuration UI\n\t// rather than a hard failure.\n\treturn class EmptyConfigureElement extends HTMLElement {\n\t\tprivate _model: unknown;\n\t\tprivate _configuration: unknown;\n\t\tget model() {\n\t\t\treturn this._model;\n\t\t}\n\t\tset model(v: unknown) {\n\t\t\tthis._model = v;\n\t\t}\n\t\tget configuration() {\n\t\t\treturn this._configuration;\n\t\t}\n\t\tset configuration(v: unknown) {\n\t\t\tthis._configuration = v;\n\t\t}\n\t};\n}\n"]}
|