@miaixz/sdk 0.5.0
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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +412 -0
- package/dist/api/client.d.ts +223 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +1069 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/endpoint.d.ts +10 -0
- package/dist/api/endpoint.d.ts.map +1 -0
- package/dist/api/endpoint.js +51 -0
- package/dist/api/endpoint.js.map +1 -0
- package/dist/api/errors.d.ts +180 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +173 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +5 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/request.d.ts +135 -0
- package/dist/api/request.d.ts.map +1 -0
- package/dist/api/request.js +2 -0
- package/dist/api/request.js.map +1 -0
- package/dist/api/response.d.ts +69 -0
- package/dist/api/response.d.ts.map +1 -0
- package/dist/api/response.js +43 -0
- package/dist/api/response.js.map +1 -0
- package/dist/api/telemetry.d.ts +139 -0
- package/dist/api/telemetry.d.ts.map +1 -0
- package/dist/api/telemetry.js +2 -0
- package/dist/api/telemetry.js.map +1 -0
- package/dist/appearance/appearance.d.ts +161 -0
- package/dist/appearance/appearance.d.ts.map +1 -0
- package/dist/appearance/appearance.js +614 -0
- package/dist/appearance/appearance.js.map +1 -0
- package/dist/appearance/index.d.ts +3 -0
- package/dist/appearance/index.d.ts.map +1 -0
- package/dist/appearance/index.js +3 -0
- package/dist/appearance/index.js.map +1 -0
- package/dist/auth/auth.d.ts +197 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +314 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/config/config.d.ts +117 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +241 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/consts/index.d.ts +35 -0
- package/dist/consts/index.d.ts.map +1 -0
- package/dist/consts/index.js +35 -0
- package/dist/consts/index.js.map +1 -0
- package/dist/context/context.d.ts +123 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +252 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/index.js.map +1 -0
- package/dist/contracts/host-context.d.ts +132 -0
- package/dist/contracts/host-context.d.ts.map +1 -0
- package/dist/contracts/host-context.js +2 -0
- package/dist/contracts/host-context.js.map +1 -0
- package/dist/contracts/index.d.ts +8 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/lifecycle.d.ts +49 -0
- package/dist/contracts/lifecycle.d.ts.map +1 -0
- package/dist/contracts/lifecycle.js +2 -0
- package/dist/contracts/lifecycle.js.map +1 -0
- package/dist/contracts/module-manifest.d.ts +110 -0
- package/dist/contracts/module-manifest.d.ts.map +1 -0
- package/dist/contracts/module-manifest.js +317 -0
- package/dist/contracts/module-manifest.js.map +1 -0
- package/dist/contracts/navigation.d.ts +36 -0
- package/dist/contracts/navigation.d.ts.map +1 -0
- package/dist/contracts/navigation.js +11 -0
- package/dist/contracts/navigation.js.map +1 -0
- package/dist/contracts/permission.d.ts +8 -0
- package/dist/contracts/permission.d.ts.map +1 -0
- package/dist/contracts/permission.js +14 -0
- package/dist/contracts/permission.js.map +1 -0
- package/dist/contracts/post-message.d.ts +124 -0
- package/dist/contracts/post-message.d.ts.map +1 -0
- package/dist/contracts/post-message.js +2 -0
- package/dist/contracts/post-message.js.map +1 -0
- package/dist/contracts/route.d.ts +45 -0
- package/dist/contracts/route.d.ts.map +1 -0
- package/dist/contracts/route.js +35 -0
- package/dist/contracts/route.js.map +1 -0
- package/dist/events/events.d.ts +191 -0
- package/dist/events/events.d.ts.map +1 -0
- package/dist/events/events.js +486 -0
- package/dist/events/events.js.map +1 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/files/files.d.ts +138 -0
- package/dist/files/files.d.ts.map +1 -0
- package/dist/files/files.js +144 -0
- package/dist/files/files.js.map +1 -0
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.d.ts.map +1 -0
- package/dist/files/index.js +2 -0
- package/dist/files/index.js.map +1 -0
- package/dist/formatters/index.d.ts +44 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +50 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/i18n/default-translator.d.ts +17 -0
- package/dist/i18n/default-translator.d.ts.map +1 -0
- package/dist/i18n/default-translator.js +19 -0
- package/dist/i18n/default-translator.js.map +1 -0
- package/dist/i18n/i18n.d.ts +248 -0
- package/dist/i18n/i18n.d.ts.map +1 -0
- package/dist/i18n/i18n.js +617 -0
- package/dist/i18n/i18n.js.map +1 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -0
- package/dist/permissions/index.d.ts +2 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +2 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/permissions.d.ts +67 -0
- package/dist/permissions/permissions.d.ts.map +1 -0
- package/dist/permissions/permissions.js +123 -0
- package/dist/permissions/permissions.js.map +1 -0
- package/dist/runtime/direct-host-bridge.d.ts +11 -0
- package/dist/runtime/direct-host-bridge.d.ts.map +1 -0
- package/dist/runtime/direct-host-bridge.js +299 -0
- package/dist/runtime/direct-host-bridge.js.map +1 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/post-message-bridge.d.ts +20 -0
- package/dist/runtime/post-message-bridge.d.ts.map +1 -0
- package/dist/runtime/post-message-bridge.js +1115 -0
- package/dist/runtime/post-message-bridge.js.map +1 -0
- package/dist/sdk.d.ts +177 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +214 -0
- package/dist/sdk.js.map +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.d.ts +246 -0
- package/dist/storage/storage.d.ts.map +1 -0
- package/dist/storage/storage.js +358 -0
- package/dist/storage/storage.js.map +1 -0
- package/dist/types/api.d.ts +82 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/appearance.d.ts +85 -0
- package/dist/types/appearance.d.ts.map +1 -0
- package/dist/types/appearance.js +48 -0
- package/dist/types/appearance.js.map +1 -0
- package/dist/types/config.d.ts +49 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/context.d.ts +41 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/file.d.ts +48 -0
- package/dist/types/file.d.ts.map +1 -0
- package/dist/types/file.js +2 -0
- package/dist/types/file.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/organization.d.ts +56 -0
- package/dist/types/organization.d.ts.map +1 -0
- package/dist/types/organization.js +2 -0
- package/dist/types/organization.js.map +1 -0
- package/dist/types/pagination.d.ts +55 -0
- package/dist/types/pagination.d.ts.map +1 -0
- package/dist/types/pagination.js +13 -0
- package/dist/types/pagination.js.map +1 -0
- package/dist/types/permissions.d.ts +26 -0
- package/dist/types/permissions.d.ts.map +1 -0
- package/dist/types/permissions.js +2 -0
- package/dist/types/permissions.js.map +1 -0
- package/dist/types/space.d.ts +43 -0
- package/dist/types/space.d.ts.map +1 -0
- package/dist/types/space.js +2 -0
- package/dist/types/space.js.map +1 -0
- package/dist/types/tenant.d.ts +31 -0
- package/dist/types/tenant.d.ts.map +1 -0
- package/dist/types/tenant.js +2 -0
- package/dist/types/tenant.js.map +1 -0
- package/dist/types/user.d.ts +48 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +2 -0
- package/dist/types/user.js.map +1 -0
- package/dist/utils/date.d.ts +9 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +11 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/number.d.ts +11 -0
- package/dist/utils/number.d.ts.map +1 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/number.js.map +1 -0
- package/dist/utils/object.d.ts +9 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +11 -0
- package/dist/utils/object.js.map +1 -0
- package/dist/utils/string.d.ts +9 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +11 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/validators/index.d.ts +8 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +8 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +156 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appearance.js","sourceRoot":"","sources":["../../src/appearance/appearance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAE9E,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAI1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,sBAAsB,GAOvB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAwB;IACjE,UAAU;IACV,QAAQ;IACR,eAAe;IACf,WAAW;CACZ,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAS,sBAAsB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,yBAAyB,GAAG;IAChC,CAAC,cAAc,EAAE,YAAY,CAAC;IAC9B,CAAC,gBAAgB,EAAE,YAAY,CAAC;IAChC,CAAC,YAAY,EAAE,YAAY,CAAC;IAC5B,CAAC,UAAU,EAAE,OAAO,CAAC;IACrB,CAAC,SAAS,EAAE,cAAc,CAAC;IAC3B,CAAC,SAAS,EAAE,cAAc,CAAC;IAC3B,CAAC,QAAQ,EAAE,aAAa,CAAC;IACzB,CAAC,MAAM,EAAE,WAAW,CAAC;CACkE,CAAC;AAE1F;;GAEG;AACH,MAAM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"../events/index.js\";\nimport { translateMiaixzDefaultMessage } from \"../i18n/default-translator.js\";\nimport type { MiaixzTranslator } from \"../i18n/index.js\";\nimport {\n getMiaixzBrowserStorage,\n readMiaixzVersionedValue,\n writeMiaixzVersionedValue,\n type MiaixzKeyValueStorage,\n type MiaixzStorageMigration,\n type MiaixzStorageScope,\n} from \"../storage/index.js\";\nimport {\n miaixzColorModes,\n miaixzDensities,\n miaixzThemeColorTokens,\n type MiaixzAppearancePayload,\n type MiaixzAppearanceSettings,\n type MiaixzColorMode,\n type MiaixzDensity,\n type MiaixzThemeColors,\n type MiaixzThemeColorToken,\n} from \"../types/index.js\";\n\n/**\n * Identifies the current appearance persistence and event schema.\n */\nconst miaixzAppearanceSchemaVersion = 1;\n\n/**\n * Lists color tokens that may include an alpha channel.\n */\nconst miaixzAlphaThemeColorTokens = new Set<MiaixzThemeColorToken>([\n \"backdrop\",\n \"shadow\",\n \"shadow-strong\",\n \"selection\",\n]);\n\n/**\n * Lists the exact top-level keys accepted by appearance settings.\n */\nconst miaixzAppearanceKeys = new Set([\"colorMode\", \"density\", \"colors\"]);\n\n/**\n * Lists all configurable color tokens for runtime membership checks.\n */\nconst miaixzThemeColorTokenSet = new Set<string>(miaixzThemeColorTokens);\n\n/**\n * Lists foreground and background pairs that require normal-text contrast.\n */\nconst miaixzNormalContrastPairs = [\n [\"text-primary\", \"background\"],\n [\"text-secondary\", \"background\"],\n [\"text-muted\", \"background\"],\n [\"on-brand\", \"brand\"],\n [\"success\", \"success-soft\"],\n [\"warning\", \"warning-soft\"],\n [\"danger\", \"danger-soft\"],\n [\"info\", \"info-soft\"],\n] as const satisfies readonly (readonly [MiaixzThemeColorToken, MiaixzThemeColorToken])[];\n\n/**\n * Lists graphical-object pairs that require non-text contrast.\n */\nconst miaixzGraphicalContrastPairs = [\n [\"focus\", \"background\"],\n [\"focus\", \"surface\"],\n [\"border-strong\", \"background\"],\n [\"border-strong\", \"surface\"],\n] as const satisfies readonly (readonly [MiaixzThemeColorToken, MiaixzThemeColorToken])[];\n\n/**\n * Defines the complete built-in light theme used for validation and CSS mirroring.\n *\n * @public\n */\nexport const miaixzLightThemeColors: Readonly<Record<MiaixzThemeColorToken, string>> =\n Object.freeze({\n brand: \"#58B832\",\n \"on-brand\": \"#10160D\",\n background: \"#F8FAF7\",\n surface: \"#FFFFFF\",\n \"surface-secondary\": \"#F3F6F1\",\n \"surface-hover\": \"#EEF3EB\",\n \"surface-active\": \"#E6EDE2\",\n \"surface-selected\": \"#EBF8E7\",\n \"text-primary\": \"#1D211B\",\n \"text-secondary\": \"#667061\",\n \"text-muted\": \"#6B7567\",\n \"text-disabled\": \"#9DA69A\",\n \"text-inverse\": \"#F8FAF7\",\n border: \"#DCE4D8\",\n \"border-strong\": \"#74806F\",\n focus: \"#3F8F22\",\n success: \"#267A39\",\n \"success-soft\": \"#EEF8F0\",\n warning: \"#8A5500\",\n \"warning-soft\": \"#FFF6E5\",\n danger: \"#B03030\",\n \"danger-soft\": \"#FCEEEE\",\n info: \"#2568B5\",\n \"info-soft\": \"#EDF5FD\",\n backdrop: \"#11180F7A\",\n shadow: \"#1D211B1A\",\n \"shadow-strong\": \"#1D211B2E\",\n selection: \"#E1F2DA\",\n });\n\n/**\n * Defines the complete built-in dark theme used for validation and CSS mirroring.\n *\n * @public\n */\nexport const miaixzDarkThemeColors: Readonly<Record<MiaixzThemeColorToken, string>> = Object.freeze(\n {\n brand: \"#6BC548\",\n \"on-brand\": \"#10160D\",\n background: \"#121510\",\n surface: \"#191D17\",\n \"surface-secondary\": \"#20251E\",\n \"surface-hover\": \"#272D24\",\n \"surface-active\": \"#30372C\",\n \"surface-selected\": \"#233A1C\",\n \"text-primary\": \"#EDF1EB\",\n \"text-secondary\": \"#B6C0B2\",\n \"text-muted\": \"#929D8E\",\n \"text-disabled\": \"#6F796C\",\n \"text-inverse\": \"#161A14\",\n border: \"#343C31\",\n \"border-strong\": \"#697A64\",\n focus: \"#8ADB69\",\n success: \"#7AD18C\",\n \"success-soft\": \"#18321F\",\n warning: \"#E5B45F\",\n \"warning-soft\": \"#382A16\",\n danger: \"#F08A8A\",\n \"danger-soft\": \"#3A1F1F\",\n info: \"#8ABCF2\",\n \"info-soft\": \"#192C40\",\n backdrop: \"#000000A3\",\n shadow: \"#00000047\",\n \"shadow-strong\": \"#00000070\",\n selection: \"#294A20\",\n },\n);\n\n/**\n * Defines the default Miaixz appearance settings.\n *\n * @public\n */\nexport const miaixzDefaultAppearance: Readonly<MiaixzAppearanceSettings> = Object.freeze({\n colorMode: \"system\",\n density: \"standard\",\n});\n\n/**\n * Configures a Miaixz appearance manager.\n *\n * @public\n */\nexport interface MiaixzAppearanceManagerOptions {\n /**\n * Identifies the consuming frontend application.\n */\n readonly appId: string;\n\n /**\n * Identifies the optional initial tenant persistence boundary.\n */\n readonly tenantId?: string;\n\n /**\n * Supplies complete settings merged over persisted settings at construction.\n */\n readonly initialAppearance?: MiaixzAppearanceSettings;\n\n /**\n * Supplies an optional versioned persistence adapter.\n */\n readonly storage?: MiaixzKeyValueStorage;\n\n /**\n * Supplies an optional continuous appearance migration chain.\n */\n readonly migrations?: readonly MiaixzStorageMigration[];\n\n /**\n * Supplies an optional event bus for local or cross-service synchronization.\n */\n readonly events?: MiaixzEventBus<MiaixzSdkEventMap>;\n\n /**\n * Supplies the translator used for appearance validation errors.\n */\n readonly translate?: MiaixzTranslator;\n}\n\n/**\n * Determines whether a value is a supported Miaixz color mode.\n *\n * @param value - Value to inspect.\n * @returns Whether the value is a supported color mode.\n * @public\n */\nexport function isMiaixzColorMode(value: unknown): value is MiaixzColorMode {\n return typeof value === \"string\" && miaixzColorModes.includes(value as MiaixzColorMode);\n}\n\n/**\n * Determines whether a value is a supported Miaixz density.\n *\n * @param value - Value to inspect.\n * @returns Whether the value is a supported density.\n * @public\n */\nexport function isMiaixzDensity(value: unknown): value is MiaixzDensity {\n return typeof value === \"string\" && miaixzDensities.includes(value as MiaixzDensity);\n}\n\n/**\n * Parses, normalizes, validates, and freezes appearance settings.\n *\n * @param value - Untrusted appearance settings to parse.\n * @returns A deeply frozen settings snapshot with uppercase custom colors.\n * @throws MiaixzSdkError When object shape, values, colors, or contrast are invalid.\n * @public\n */\nexport function parseMiaixzAppearanceSettings(value: unknown): MiaixzAppearanceSettings {\n return parseAppearanceSettings(value, translateMiaixzDefaultMessage);\n}\n\n/**\n * Determines whether a value satisfies the complete appearance contract.\n *\n * @param value - Untrusted appearance settings to inspect.\n * @returns Whether parsing and contrast validation both succeed.\n * @public\n */\nexport function isMiaixzAppearanceSettings(value: unknown): value is MiaixzAppearanceSettings {\n try {\n parseMiaixzAppearanceSettings(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validates all frozen WCAG contrast pairs for an appearance.\n *\n * @param appearance - Appearance settings whose merged themes are validated.\n * @throws MiaixzSdkError When a custom color is invalid or a pair misses its threshold.\n * @public\n */\nexport function validateMiaixzThemeContrast(appearance: Readonly<MiaixzAppearanceSettings>): void {\n const normalized = normalizeAppearanceSettings(appearance, translateMiaixzDefaultMessage);\n validateNormalizedThemeContrast(normalized, translateMiaixzDefaultMessage);\n}\n\n/**\n * Manages versioned, tenant-scoped appearance state without accessing the DOM.\n *\n * @public\n */\nexport class MiaixzAppearanceManager {\n readonly #appId: string;\n readonly #storage: MiaixzKeyValueStorage | undefined;\n readonly #migrations: readonly MiaixzStorageMigration[] | undefined;\n readonly #events: MiaixzEventBus<MiaixzSdkEventMap> | undefined;\n readonly #translate: MiaixzTranslator;\n readonly #listeners = new Set<(appearance: Readonly<MiaixzAppearanceSettings>) => void>();\n #tenantId: string | undefined;\n #appearance: MiaixzAppearanceSettings;\n #stopEventListener: (() => void) | undefined;\n #destroyed = false;\n #publishingEvent = false;\n\n /**\n * Creates a validated appearance manager for one application and tenant scope.\n *\n * @param options - Required application identity and optional runtime adapters.\n * @throws MiaixzSdkError When scope, migrations, initial settings, or contrast are invalid.\n */\n constructor(options: Readonly<MiaixzAppearanceManagerOptions>) {\n this.#appId = options.appId;\n this.#tenantId = options.tenantId;\n this.#storage = options.storage ?? getMiaixzBrowserStorage();\n this.#migrations = options.migrations;\n this.#events = options.events;\n this.#translate = options.translate ?? translateMiaixzDefaultMessage;\n\n const scope = this.#createScope(this.#tenantId);\n this.#validateStorageConfiguration(scope);\n const initial =\n options.initialAppearance === undefined\n ? undefined\n : parseAppearanceSettings(options.initialAppearance, this.#translate);\n const persisted = this.#read(scope);\n this.#appearance = parseAppearanceSettings(\n {\n ...miaixzDefaultAppearance,\n ...persisted,\n ...initial,\n },\n this.#translate,\n );\n this.#stopEventListener = this.#events?.on(\"appearance:changed\", (payload) => {\n if (this.#publishingEvent) return;\n const appearance = parseAppearancePayload(payload, this.#translate);\n if (appearance !== undefined) this.#commit(appearance, false);\n });\n }\n\n /**\n * Returns the current deeply frozen appearance snapshot.\n *\n * @returns Current normalized appearance settings.\n */\n getSnapshot(): Readonly<MiaixzAppearanceSettings> {\n return this.#appearance;\n }\n\n /**\n * Replaces the complete appearance after atomic validation.\n *\n * @param appearance - Complete appearance settings to commit.\n * @throws MiaixzSdkError When settings, colors, or contrast are invalid.\n */\n set(appearance: MiaixzAppearanceSettings): void {\n this.#commit(parseAppearanceSettings(appearance, this.#translate), true);\n }\n\n /**\n * Shallowly merges and commits a partial appearance update.\n *\n * @param appearance - Top-level settings fields to replace.\n * @throws MiaixzSdkError When merged settings, colors, or contrast are invalid.\n */\n patch(appearance: Partial<MiaixzAppearanceSettings>): void {\n this.set({ ...this.#appearance, ...appearance });\n }\n\n /**\n * Reloads appearance state from a new validated tenant scope.\n *\n * @param tenantId - Optional tenant identifier, or undefined for global scope.\n * @throws MiaixzSdkError When the new scope or migration configuration is invalid.\n */\n setScope(tenantId?: string): void {\n const scope = this.#createScope(tenantId);\n this.#validateStorageConfiguration(scope);\n const appearance = this.#read(scope) ?? miaixzDefaultAppearance;\n this.#tenantId = tenantId;\n this.#appearance = appearance;\n this.#notify();\n }\n\n /**\n * Registers a listener for committed appearance snapshots.\n *\n * @param listener - Callback invoked synchronously after each committed change.\n * @returns An idempotent function that removes the listener.\n */\n subscribe(listener: (appearance: Readonly<MiaixzAppearanceSettings>) => void): () => void {\n this.#listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n this.#listeners.delete(listener);\n };\n }\n\n /**\n * Releases the event subscription and all local appearance listeners.\n */\n destroy(): void {\n if (this.#destroyed) return;\n this.#destroyed = true;\n this.#stopEventListener?.();\n this.#stopEventListener = undefined;\n this.#listeners.clear();\n }\n\n /**\n * Creates the current versioned-storage scope.\n *\n * @param tenantId - Optional tenant identifier.\n * @returns Application and tenant storage scope.\n */\n #createScope(tenantId: string | undefined): MiaixzStorageScope {\n return tenantId === undefined ? { appId: this.#appId } : { appId: this.#appId, tenantId };\n }\n\n /**\n * Validates scope, schema, and migrations before reading physical storage.\n *\n * @param scope - Candidate appearance persistence scope.\n * @throws MiaixzSdkError When scope or migrations are invalid.\n */\n #validateStorageConfiguration(scope: Readonly<MiaixzStorageScope>): void {\n readMiaixzVersionedValue({\n scope,\n kind: \"appearance\",\n schemaVersion: miaixzAppearanceSchemaVersion,\n ...(this.#migrations === undefined ? {} : { migrations: this.#migrations }),\n parse: (value) => parseAppearanceSettings(value, this.#translate),\n });\n }\n\n /**\n * Reads and normalizes one tenant-scoped appearance value.\n *\n * @param scope - Validated appearance persistence scope.\n * @returns Persisted normalized appearance, or undefined when absent or unusable.\n */\n #read(scope: Readonly<MiaixzStorageScope>): MiaixzAppearanceSettings | undefined {\n return readMiaixzVersionedValue({\n ...(this.#storage === undefined ? {} : { storage: this.#storage }),\n scope,\n kind: \"appearance\",\n schemaVersion: miaixzAppearanceSchemaVersion,\n ...(this.#migrations === undefined ? {} : { migrations: this.#migrations }),\n parse: (value) => parseAppearanceSettings(value, this.#translate),\n });\n }\n\n /**\n * Commits one already-normalized appearance and optionally broadcasts it.\n *\n * @param appearance - Deeply frozen settings to commit.\n * @param broadcast - Whether to emit the versioned appearance event.\n */\n #commit(appearance: MiaixzAppearanceSettings, broadcast: boolean): void {\n this.#appearance = appearance;\n const scope = this.#createScope(this.#tenantId);\n writeMiaixzVersionedValue(\n {\n ...(this.#storage === undefined ? {} : { storage: this.#storage }),\n scope,\n kind: \"appearance\",\n schemaVersion: miaixzAppearanceSchemaVersion,\n },\n appearance,\n );\n this.#notify();\n if (broadcast) {\n const payload: MiaixzAppearancePayload = Object.freeze({\n schemaVersion: miaixzAppearanceSchemaVersion,\n value: appearance,\n });\n this.#publishingEvent = true;\n try {\n this.#events?.emit(\"appearance:changed\", payload);\n } finally {\n this.#publishingEvent = false;\n }\n }\n }\n\n /**\n * Delivers the current immutable snapshot to all local listeners.\n */\n #notify(): void {\n for (const listener of this.#listeners) listener(this.#appearance);\n }\n}\n\n/**\n * Creates a tenant-aware appearance manager without DOM side effects.\n *\n * @param options - Required application identity and optional runtime adapters.\n * @returns Configured appearance manager.\n * @throws MiaixzSdkError When scope, migrations, initial settings, or contrast are invalid.\n * @public\n */\nexport function createMiaixzAppearanceManager(\n options: Readonly<MiaixzAppearanceManagerOptions>,\n): MiaixzAppearanceManager {\n return new MiaixzAppearanceManager(options);\n}\n\n/**\n * Parses appearance settings using the supplied translator.\n *\n * @param value - Untrusted appearance settings.\n * @param translate - Translator used for validation errors.\n * @returns Deeply frozen normalized settings.\n * @throws MiaixzSdkError When syntax, colors, or contrast are invalid.\n */\nfunction parseAppearanceSettings(\n value: unknown,\n translate: MiaixzTranslator,\n): MiaixzAppearanceSettings {\n const normalized = normalizeAppearanceSettings(value, translate);\n validateNormalizedThemeContrast(normalized, translate);\n return normalized;\n}\n\n/**\n * Parses a versioned event payload without surfacing untrusted event failures.\n *\n * @param value - Untrusted event payload.\n * @param translate - Translator used internally by the parser.\n * @returns Normalized settings, or undefined when the payload is invalid.\n */\nfunction parseAppearancePayload(\n value: unknown,\n translate: MiaixzTranslator,\n): MiaixzAppearanceSettings | undefined {\n const record = readPlainDataObject(value);\n if (!record || !hasExactKeys(record, [\"schemaVersion\", \"value\"])) return undefined;\n if (record.schemaVersion !== miaixzAppearanceSchemaVersion) return undefined;\n try {\n return parseAppearanceSettings(record.value, translate);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Normalizes appearance structure and custom color syntax.\n *\n * @param value - Untrusted appearance settings.\n * @param translate - Translator used for syntax errors.\n * @returns Deeply frozen normalized settings without contrast evaluation.\n * @throws MiaixzSdkError When object shape, values, tokens, or color syntax are invalid.\n */\nfunction normalizeAppearanceSettings(\n value: unknown,\n translate: MiaixzTranslator,\n): MiaixzAppearanceSettings {\n const record = readPlainDataObject(value);\n if (\n !record ||\n !Object.keys(record).every((key) => miaixzAppearanceKeys.has(key)) ||\n !Object.hasOwn(record, \"colorMode\") ||\n !Object.hasOwn(record, \"density\") ||\n !isMiaixzColorMode(record.colorMode) ||\n !isMiaixzDensity(record.density)\n ) {\n throw createAppearanceColorError(translate);\n }\n\n let colors: MiaixzThemeColors | undefined;\n if (Object.hasOwn(record, \"colors\")) {\n const colorRecord = readPlainDataObject(record.colors);\n if (!colorRecord) throw createAppearanceColorError(translate);\n const normalizedColors: Partial<Record<MiaixzThemeColorToken, string>> = {};\n for (const [token, color] of Object.entries(colorRecord)) {\n if (\n !miaixzThemeColorTokenSet.has(token) ||\n typeof color !== \"string\" ||\n !isValidThemeHex(token as MiaixzThemeColorToken, color)\n ) {\n throw createAppearanceColorError(translate, { token });\n }\n normalizedColors[token as MiaixzThemeColorToken] = color.toUpperCase();\n }\n colors = Object.freeze(normalizedColors);\n }\n\n return Object.freeze({\n colorMode: record.colorMode,\n density: record.density,\n ...(colors === undefined ? {} : { colors }),\n });\n}\n\n/**\n * Validates contrast against every applicable built-in theme.\n *\n * @param appearance - Normalized settings to validate.\n * @param translate - Translator used for contrast errors.\n * @throws MiaixzSdkError When any frozen contrast pair misses its threshold.\n */\nfunction validateNormalizedThemeContrast(\n appearance: Readonly<MiaixzAppearanceSettings>,\n translate: MiaixzTranslator,\n): void {\n const themes =\n appearance.colorMode === \"light\"\n ? [[\"light\", miaixzLightThemeColors] as const]\n : appearance.colorMode === \"dark\"\n ? [[\"dark\", miaixzDarkThemeColors] as const]\n : ([\n [\"light\", miaixzLightThemeColors],\n [\"dark\", miaixzDarkThemeColors],\n ] as const);\n\n for (const [mode, defaults] of themes) {\n const colors = { ...defaults, ...appearance.colors };\n assertContrastPairs(colors, miaixzNormalContrastPairs, 4.5, mode, translate);\n assertContrastPairs(colors, miaixzGraphicalContrastPairs, 3, mode, translate);\n }\n}\n\n/**\n * Validates a collection of contrast pairs against one threshold.\n *\n * @param colors - Complete merged theme color map.\n * @param pairs - Foreground and background token pairs.\n * @param minimum - Minimum accepted WCAG contrast ratio.\n * @param mode - Theme mode used for safe diagnostic details.\n * @param translate - Translator used for contrast errors.\n * @throws MiaixzSdkError When a pair misses the minimum ratio.\n */\nfunction assertContrastPairs(\n colors: Readonly<Record<MiaixzThemeColorToken, string>>,\n pairs: readonly (readonly [MiaixzThemeColorToken, MiaixzThemeColorToken])[],\n minimum: number,\n mode: \"light\" | \"dark\",\n translate: MiaixzTranslator,\n): void {\n for (const [foreground, background] of pairs) {\n const ratio = calculateContrastRatio(colors[foreground], colors[background]);\n if (ratio < minimum) {\n throw createAppearanceContrastError(translate, {\n mode,\n foreground,\n background,\n minimum,\n ratio: Number(ratio.toFixed(2)),\n });\n }\n }\n}\n\n/**\n * Calculates the WCAG contrast ratio between two opaque hexadecimal colors.\n *\n * @param foreground - Foreground color in hexadecimal notation.\n * @param background - Background color in hexadecimal notation.\n * @returns Contrast ratio from one through twenty-one.\n */\nfunction calculateContrastRatio(foreground: string, background: string): number {\n const foregroundLuminance = calculateRelativeLuminance(foreground);\n const backgroundLuminance = calculateRelativeLuminance(background);\n const lighter = Math.max(foregroundLuminance, backgroundLuminance);\n const darker = Math.min(foregroundLuminance, backgroundLuminance);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Calculates WCAG relative luminance for an opaque hexadecimal color.\n *\n * @param color - Six-digit hexadecimal color.\n * @returns Relative luminance from zero through one.\n */\nfunction calculateRelativeLuminance(color: string): number {\n const channels = [color.slice(1, 3), color.slice(3, 5), color.slice(5, 7)].map((channel) => {\n const value = Number.parseInt(channel, 16) / 255;\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * (channels[0] ?? 0) + 0.7152 * (channels[1] ?? 0) + 0.0722 * (channels[2] ?? 0);\n}\n\n/**\n * Determines whether a custom token uses its permitted hexadecimal syntax.\n *\n * @param token - Theme token receiving the value.\n * @param value - Color value to inspect.\n * @returns Whether the color has the exact permitted length and character set.\n */\nfunction isValidThemeHex(token: MiaixzThemeColorToken, value: string): boolean {\n if (/^#[0-9A-Fa-f]{6}$/.test(value)) return true;\n return miaixzAlphaThemeColorTokens.has(token) && /^#[0-9A-Fa-f]{8}$/.test(value);\n}\n\n/**\n * Reads an object without invoking accessors or accepting exotic prototypes.\n *\n * @param value - Runtime value to inspect.\n * @returns A plain data record, or undefined when the value is unsafe.\n */\nfunction readPlainDataObject(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n try {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) return undefined;\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const record: Record<string, unknown> = {};\n for (const key of Object.keys(descriptors)) {\n const descriptor = descriptors[key];\n if (!descriptor?.enumerable) continue;\n if (!(\"value\" in descriptor)) return undefined;\n record[key] = descriptor.value;\n }\n return record;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Determines whether a record has exactly the supplied enumerable keys.\n *\n * @param record - Plain data record to inspect.\n * @param expected - Exact key set required by the contract.\n * @returns Whether every and only expected key is present.\n */\nfunction hasExactKeys(\n record: Readonly<Record<string, unknown>>,\n expected: readonly string[],\n): boolean {\n const keys = Object.keys(record);\n return keys.length === expected.length && expected.every((key) => Object.hasOwn(record, key));\n}\n\n/**\n * Creates a localized appearance syntax or color error.\n *\n * @param translate - Translator used to resolve the public message.\n * @param details - Optional safe token diagnostics.\n * @returns Stable SDK color-validation error.\n */\nfunction createAppearanceColorError(\n translate: MiaixzTranslator,\n details?: Readonly<{\n /**\n * Identifies the rejected theme token.\n */\n token: string;\n }>,\n): MiaixzSdkError {\n return new MiaixzSdkError(translate(\"sdk.error.appearance.colorInvalid\"), {\n code: \"APPEARANCE_COLOR_INVALID\",\n ...(details === undefined ? {} : { details }),\n });\n}\n\n/**\n * Creates a localized appearance contrast error.\n *\n * @param translate - Translator used to resolve the public message.\n * @param details - Safe theme and ratio diagnostics.\n * @returns Stable SDK contrast-validation error.\n */\nfunction createAppearanceContrastError(\n translate: MiaixzTranslator,\n details: Readonly<{\n /**\n * Identifies the theme mode that failed validation.\n */\n mode: \"light\" | \"dark\";\n /**\n * Identifies the foreground token in the failed pair.\n */\n foreground: MiaixzThemeColorToken;\n /**\n * Identifies the background token in the failed pair.\n */\n background: MiaixzThemeColorToken;\n /**\n * Identifies the minimum required contrast ratio.\n */\n minimum: number;\n /**\n * Contains the measured contrast ratio.\n */\n ratio: number;\n }>,\n): MiaixzSdkError {\n return new MiaixzSdkError(translate(\"sdk.error.appearance.contrastInvalid\"), {\n code: \"APPEARANCE_CONTRAST_INVALID\",\n details: Object.freeze({ ...details }),\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/appearance/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/appearance/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from \"./appearance.js\";\nexport * from \"../types/appearance.js\";\n"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { MiaixzEventBus, MiaixzSdkEventMap } from "../events/index.js";
|
|
2
|
+
import { type MiaixzTranslator } from "../i18n/index.js";
|
|
3
|
+
import { type MiaixzKeyValueStorage } from "../storage/index.js";
|
|
4
|
+
import type { MiaixzUserSummary } from "../types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Describes authentication state managed by the Miaixz SDK.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface MiaixzAuthSession {
|
|
11
|
+
/**
|
|
12
|
+
* Access token presented to protected services.
|
|
13
|
+
*/
|
|
14
|
+
readonly accessToken: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional token used to renew the session.
|
|
17
|
+
*/
|
|
18
|
+
readonly refreshToken?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional authorization scheme associated with the access token.
|
|
21
|
+
*/
|
|
22
|
+
readonly tokenType?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional token expiry as Unix time in milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
readonly expiresAt?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Optional summary of the authenticated user.
|
|
29
|
+
*/
|
|
30
|
+
readonly user?: MiaixzUserSummary;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Identifies the only cross-window authentication states exposed by the SDK.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type MiaixzAuthStatus = "authenticated" | "anonymous";
|
|
38
|
+
/**
|
|
39
|
+
* Refreshes an expiring authentication session.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export type MiaixzSessionRefresher = (session: Readonly<MiaixzAuthSession>) => MiaixzAuthSession | undefined | Promise<MiaixzAuthSession | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Marks a storage adapter whose use for Bearer credentials was explicitly acknowledged.
|
|
46
|
+
*
|
|
47
|
+
* Persisting access or refresh tokens in Web Storage increases exposure to script injection.
|
|
48
|
+
* Prefer the default in-memory mode or an HttpOnly Cookie/BFF integration whenever possible.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface MiaixzPersistentAuthStorage extends MiaixzKeyValueStorage {
|
|
53
|
+
/**
|
|
54
|
+
* Discriminator proving that the adapter was created by the explicit-risk factory.
|
|
55
|
+
*/
|
|
56
|
+
readonly kind: "miaixz-persistent-auth-storage";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates the only storage adapter accepted for persistent Bearer sessions.
|
|
60
|
+
*
|
|
61
|
+
* Access and refresh tokens stored in localStorage or sessionStorage can be read by scripts
|
|
62
|
+
* running in the same origin. Callers must explicitly acknowledge that security trade-off.
|
|
63
|
+
*
|
|
64
|
+
* @param storage - Underlying storage adapter, such as localStorage or sessionStorage.
|
|
65
|
+
* @param options - Mandatory risk acknowledgement and optional physical storage key.
|
|
66
|
+
* @returns An authentication-specific persistent storage adapter.
|
|
67
|
+
* @throws MiaixzSdkError When the Web Storage risk is not explicitly acknowledged.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare function createMiaixzPersistentAuthStorage(storage: MiaixzKeyValueStorage, options: Readonly<{
|
|
71
|
+
/**
|
|
72
|
+
* Confirms that the caller accepts the security risk of persistent browser token storage.
|
|
73
|
+
*/
|
|
74
|
+
acknowledgeWebStorageRisk: true;
|
|
75
|
+
/**
|
|
76
|
+
* Optional physical storage key; defaults to `miaixz-auth`.
|
|
77
|
+
*/
|
|
78
|
+
storageKey?: string;
|
|
79
|
+
}>): MiaixzPersistentAuthStorage;
|
|
80
|
+
/**
|
|
81
|
+
* Configures a Miaixz authentication manager.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export interface MiaixzAuthManagerOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Explicitly acknowledged storage used to persist Bearer credentials.
|
|
88
|
+
*/
|
|
89
|
+
readonly persistence?: MiaixzPersistentAuthStorage;
|
|
90
|
+
/**
|
|
91
|
+
* Optional callback used to refresh an expiring session.
|
|
92
|
+
*/
|
|
93
|
+
readonly refresh?: MiaixzSessionRefresher;
|
|
94
|
+
/**
|
|
95
|
+
* Optional safety window in seconds before token expiry.
|
|
96
|
+
*/
|
|
97
|
+
readonly expirationLeewaySeconds?: number;
|
|
98
|
+
/**
|
|
99
|
+
* Optional clock returning Unix time in milliseconds.
|
|
100
|
+
*/
|
|
101
|
+
readonly now?: () => number;
|
|
102
|
+
/**
|
|
103
|
+
* Optional translator used for authentication errors.
|
|
104
|
+
*/
|
|
105
|
+
readonly translate?: MiaixzTranslator;
|
|
106
|
+
/**
|
|
107
|
+
* Optional event bus used to synchronize service instances.
|
|
108
|
+
*/
|
|
109
|
+
readonly events?: MiaixzEventBus<MiaixzSdkEventMap>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Determines whether a value is a usable authentication session.
|
|
113
|
+
*
|
|
114
|
+
* @param value - Value to inspect.
|
|
115
|
+
* @returns Whether `value` is a usable authentication session.
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
export declare function isMiaixzAuthSession(value: unknown): value is MiaixzAuthSession;
|
|
119
|
+
/**
|
|
120
|
+
* Checks token expiry with a configurable refresh safety window.
|
|
121
|
+
* @param session - Session to inspect.
|
|
122
|
+
* @param now - Current Unix time in milliseconds.
|
|
123
|
+
* @param leewaySeconds - Seconds before expiry that count as expired.
|
|
124
|
+
* @returns Whether the session has expired within the safety window.
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export declare function isMiaixzSessionExpired(session: Readonly<MiaixzAuthSession>, now?: number, leewaySeconds?: number): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Persists authentication state, refreshes tokens, and synchronizes service instances.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare class MiaixzAuthManager {
|
|
134
|
+
#private;
|
|
135
|
+
/**
|
|
136
|
+
* Creates an authentication manager.
|
|
137
|
+
*
|
|
138
|
+
* @param options - Storage, refresh, clock, event, and translation adapters.
|
|
139
|
+
*/
|
|
140
|
+
constructor(options?: MiaixzAuthManagerOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Returns the active authentication session.
|
|
143
|
+
*
|
|
144
|
+
* @returns An immutable copy of the active session, when signed in.
|
|
145
|
+
*/
|
|
146
|
+
getSession(): Readonly<MiaixzAuthSession> | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Validates, persists, broadcasts, and publishes a new session.
|
|
149
|
+
*
|
|
150
|
+
* @param session - Authentication session to activate.
|
|
151
|
+
*/
|
|
152
|
+
setSession(session: MiaixzAuthSession): void;
|
|
153
|
+
/**
|
|
154
|
+
* Removes the active session from memory and persistent storage.
|
|
155
|
+
*/
|
|
156
|
+
clearSession(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Registers a session listener and returns its unsubscribe function.
|
|
159
|
+
*
|
|
160
|
+
* @param listener - Callback invoked with each authentication snapshot.
|
|
161
|
+
* @returns Function that unregisters the listener.
|
|
162
|
+
*/
|
|
163
|
+
subscribe(listener: (session: Readonly<MiaixzAuthSession> | undefined) => void): () => void;
|
|
164
|
+
/**
|
|
165
|
+
* Returns a valid access token, refreshing an expired session once when possible.
|
|
166
|
+
* Concurrent callers share the same refresh operation.
|
|
167
|
+
*
|
|
168
|
+
* @returns Active access token when a valid session is available.
|
|
169
|
+
*/
|
|
170
|
+
getAccessToken(): Promise<string | undefined>;
|
|
171
|
+
/**
|
|
172
|
+
* Fetch-compatible token provider bound to this manager.
|
|
173
|
+
*
|
|
174
|
+
* @returns Active access token when a valid session is available.
|
|
175
|
+
*/
|
|
176
|
+
readonly tokenProvider: () => Promise<string | undefined>;
|
|
177
|
+
/**
|
|
178
|
+
* Returns a complete Authorization header value using the session token type.
|
|
179
|
+
* Bearer remains the default when the session does not declare a token type.
|
|
180
|
+
*
|
|
181
|
+
* @returns Complete Authorization header value when signed in.
|
|
182
|
+
*/
|
|
183
|
+
readonly authorizationProvider: () => Promise<string | undefined>;
|
|
184
|
+
/**
|
|
185
|
+
* Releases event subscriptions and local listeners owned by this manager.
|
|
186
|
+
*/
|
|
187
|
+
destroy(): void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates a Bearer authentication manager with in-memory-only defaults.
|
|
191
|
+
*
|
|
192
|
+
* @param options - Optional persistence, refresh, clock, event, and translation adapters.
|
|
193
|
+
* @returns Configured authentication manager.
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
export declare function createMiaixzAuthManager(options?: MiaixzAuthManagerOptions): MiaixzAuthManager;
|
|
197
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyB,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAmC,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,WAAW,CAAC;AAE7D;;;;GA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BAAa,iBAAiB;;IAa5B;;;;OAIG;IACH,YAAY,OAAO,GAAE,wBAA6B,EAmBjD;IAED;;;;OAIG;IACH,UAAU,IAAI,QAAQ,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAOpD;IAED;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAE3C;IAwBD;;OAEG;IACH,YAAY,IAAI,IAAI,CAEnB;IAeD;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAAG,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAG1F;IAED;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA0BlD;IAED;;;;OAIG;IACH,QAAQ,CAAC,aAAa,QAAO,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAA0B;IAElF;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAKpE;IAEF;;OAEG;IACH,OAAO,IAAI,IAAI,CAGd;CAwBF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,iBAAiB,CAE7F"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { miaixzStorageKeys } from "../consts/index.js";
|
|
2
|
+
import { MiaixzSdkError } from "../api/errors.js";
|
|
3
|
+
import { miaixzDefaultI18n } from "../i18n/index.js";
|
|
4
|
+
import { readMiaixzJson, writeMiaixzJson } from "../storage/index.js";
|
|
5
|
+
import { isRecord } from "../utils/object.js";
|
|
6
|
+
/**
|
|
7
|
+
* Tracks adapters created by the explicit-risk factory without exposing a forgeable public flag.
|
|
8
|
+
*/
|
|
9
|
+
const persistentAuthStorages = new WeakSet();
|
|
10
|
+
/**
|
|
11
|
+
* Creates the only storage adapter accepted for persistent Bearer sessions.
|
|
12
|
+
*
|
|
13
|
+
* Access and refresh tokens stored in localStorage or sessionStorage can be read by scripts
|
|
14
|
+
* running in the same origin. Callers must explicitly acknowledge that security trade-off.
|
|
15
|
+
*
|
|
16
|
+
* @param storage - Underlying storage adapter, such as localStorage or sessionStorage.
|
|
17
|
+
* @param options - Mandatory risk acknowledgement and optional physical storage key.
|
|
18
|
+
* @returns An authentication-specific persistent storage adapter.
|
|
19
|
+
* @throws MiaixzSdkError When the Web Storage risk is not explicitly acknowledged.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export function createMiaixzPersistentAuthStorage(storage, options) {
|
|
23
|
+
if (options?.acknowledgeWebStorageRisk !== true) {
|
|
24
|
+
throw new MiaixzSdkError(miaixzDefaultI18n.t("sdk.error.auth.persistenceAcknowledgementRequired"), { code: "AUTH_PERSISTENCE_ACKNOWLEDGEMENT_REQUIRED" });
|
|
25
|
+
}
|
|
26
|
+
const physicalKey = options.storageKey ?? miaixzStorageKeys.auth;
|
|
27
|
+
const persistence = Object.freeze({
|
|
28
|
+
kind: "miaixz-persistent-auth-storage",
|
|
29
|
+
getItem: (_key) => storage.getItem(physicalKey),
|
|
30
|
+
setItem: (_key, value) => storage.setItem(physicalKey, value),
|
|
31
|
+
removeItem: (_key) => storage.removeItem(physicalKey),
|
|
32
|
+
});
|
|
33
|
+
persistentAuthStorages.add(persistence);
|
|
34
|
+
return persistence;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Determines whether a value is a valid user summary for a session.
|
|
38
|
+
*
|
|
39
|
+
* @param value - Value to inspect.
|
|
40
|
+
* @returns Whether `value` is a valid immutable user summary for a session.
|
|
41
|
+
*/
|
|
42
|
+
function isMiaixzUserSummary(value) {
|
|
43
|
+
if (!isRecord(value) || typeof value.id !== "string" || !value.id.trim())
|
|
44
|
+
return false;
|
|
45
|
+
if (typeof value.displayName !== "string" || !value.displayName.trim())
|
|
46
|
+
return false;
|
|
47
|
+
if (value.username !== undefined && typeof value.username !== "string")
|
|
48
|
+
return false;
|
|
49
|
+
if (value.avatarUrl !== undefined && typeof value.avatarUrl !== "string")
|
|
50
|
+
return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether a value is a usable authentication session.
|
|
55
|
+
*
|
|
56
|
+
* @param value - Value to inspect.
|
|
57
|
+
* @returns Whether `value` is a usable authentication session.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export function isMiaixzAuthSession(value) {
|
|
61
|
+
if (!isRecord(value) || typeof value.accessToken !== "string" || !value.accessToken.trim())
|
|
62
|
+
return false;
|
|
63
|
+
if (value.refreshToken !== undefined && typeof value.refreshToken !== "string")
|
|
64
|
+
return false;
|
|
65
|
+
if (value.tokenType !== undefined && typeof value.tokenType !== "string")
|
|
66
|
+
return false;
|
|
67
|
+
if (value.expiresAt !== undefined &&
|
|
68
|
+
(typeof value.expiresAt !== "number" || !Number.isFinite(value.expiresAt)))
|
|
69
|
+
return false;
|
|
70
|
+
if (value.user !== undefined && !isMiaixzUserSummary(value.user))
|
|
71
|
+
return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks token expiry with a configurable refresh safety window.
|
|
76
|
+
* @param session - Session to inspect.
|
|
77
|
+
* @param now - Current Unix time in milliseconds.
|
|
78
|
+
* @param leewaySeconds - Seconds before expiry that count as expired.
|
|
79
|
+
* @returns Whether the session has expired within the safety window.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export function isMiaixzSessionExpired(session, now = Date.now(), leewaySeconds = 30) {
|
|
83
|
+
return session.expiresAt !== undefined && session.expiresAt <= now + leewaySeconds * 1000;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Compares persisted authentication values to suppress duplicate event delivery.
|
|
87
|
+
*
|
|
88
|
+
* @param first - First session to compare.
|
|
89
|
+
* @param second - Second session to compare.
|
|
90
|
+
* @returns Whether both session values contain equivalent data.
|
|
91
|
+
*/
|
|
92
|
+
function sessionsEqual(first, second) {
|
|
93
|
+
return JSON.stringify(first) === JSON.stringify(second);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Determines whether an untrusted event is a supported authentication status signal.
|
|
97
|
+
*
|
|
98
|
+
* @param value - Event payload to inspect.
|
|
99
|
+
* @returns Whether the payload contains only a recognized authentication status.
|
|
100
|
+
*/
|
|
101
|
+
function isMiaixzAuthStatusEvent(value) {
|
|
102
|
+
return (isRecord(value) &&
|
|
103
|
+
(value.status === "authenticated" || value.status === "anonymous") &&
|
|
104
|
+
Object.keys(value).length === 1);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Persists authentication state, refreshes tokens, and synchronizes service instances.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export class MiaixzAuthManager {
|
|
112
|
+
#persistence;
|
|
113
|
+
#refresh;
|
|
114
|
+
#expirationLeewaySeconds;
|
|
115
|
+
#now;
|
|
116
|
+
#translate;
|
|
117
|
+
#events;
|
|
118
|
+
#listeners = new Set();
|
|
119
|
+
#session;
|
|
120
|
+
#refreshPromise;
|
|
121
|
+
#stopEventListener;
|
|
122
|
+
#publishingStatus = false;
|
|
123
|
+
/**
|
|
124
|
+
* Creates an authentication manager.
|
|
125
|
+
*
|
|
126
|
+
* @param options - Storage, refresh, clock, event, and translation adapters.
|
|
127
|
+
*/
|
|
128
|
+
constructor(options = {}) {
|
|
129
|
+
if (options.persistence && !persistentAuthStorages.has(options.persistence)) {
|
|
130
|
+
throw new MiaixzSdkError((options.translate ?? miaixzDefaultI18n.t)("sdk.error.auth.persistenceAcknowledgementRequired"), { code: "AUTH_PERSISTENCE_ACKNOWLEDGEMENT_REQUIRED" });
|
|
131
|
+
}
|
|
132
|
+
this.#persistence = options.persistence;
|
|
133
|
+
this.#refresh = options.refresh;
|
|
134
|
+
this.#expirationLeewaySeconds = options.expirationLeewaySeconds ?? 30;
|
|
135
|
+
this.#now = options.now ?? Date.now;
|
|
136
|
+
this.#translate = options.translate ?? miaixzDefaultI18n.t;
|
|
137
|
+
this.#events = options.events;
|
|
138
|
+
this.#session = readMiaixzJson(this.#persistence, miaixzStorageKeys.auth, isMiaixzAuthSession);
|
|
139
|
+
this.#stopEventListener = this.#events?.on("auth:changed", (event) => {
|
|
140
|
+
if (!this.#publishingStatus && isMiaixzAuthStatusEvent(event))
|
|
141
|
+
this.#clearSession(false);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the active authentication session.
|
|
146
|
+
*
|
|
147
|
+
* @returns An immutable copy of the active session, when signed in.
|
|
148
|
+
*/
|
|
149
|
+
getSession() {
|
|
150
|
+
return this.#session === undefined
|
|
151
|
+
? undefined
|
|
152
|
+
: Object.freeze({
|
|
153
|
+
...this.#session,
|
|
154
|
+
...(this.#session.user ? { user: Object.freeze({ ...this.#session.user }) } : {}),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Validates, persists, broadcasts, and publishes a new session.
|
|
159
|
+
*
|
|
160
|
+
* @param session - Authentication session to activate.
|
|
161
|
+
*/
|
|
162
|
+
setSession(session) {
|
|
163
|
+
this.#setSession(session, true);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Commits a session and optionally broadcasts it to other service instances.
|
|
167
|
+
*
|
|
168
|
+
* @param session - Authentication session to commit.
|
|
169
|
+
* @param broadcast - Whether to publish the change through the event bus.
|
|
170
|
+
*/
|
|
171
|
+
#setSession(session, broadcast) {
|
|
172
|
+
if (!isMiaixzAuthSession(session)) {
|
|
173
|
+
throw new MiaixzSdkError(this.#translate("sdk.error.auth.sessionInvalid"), {
|
|
174
|
+
code: "AUTH_SESSION_INVALID",
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (sessionsEqual(this.#session, session))
|
|
178
|
+
return;
|
|
179
|
+
this.#session = {
|
|
180
|
+
...session,
|
|
181
|
+
...(session.user ? { user: { ...session.user } } : {}),
|
|
182
|
+
};
|
|
183
|
+
writeMiaixzJson(this.#persistence, miaixzStorageKeys.auth, this.#session);
|
|
184
|
+
this.#notify();
|
|
185
|
+
if (broadcast)
|
|
186
|
+
this.#publishStatus("authenticated");
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Removes the active session from memory and persistent storage.
|
|
190
|
+
*/
|
|
191
|
+
clearSession() {
|
|
192
|
+
this.#clearSession(true);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Clears session state and optionally broadcasts the change.
|
|
196
|
+
*
|
|
197
|
+
* @param broadcast - Whether to publish the change through the event bus.
|
|
198
|
+
*/
|
|
199
|
+
#clearSession(broadcast) {
|
|
200
|
+
if (this.#session === undefined)
|
|
201
|
+
return;
|
|
202
|
+
this.#session = undefined;
|
|
203
|
+
writeMiaixzJson(this.#persistence, miaixzStorageKeys.auth, undefined);
|
|
204
|
+
this.#notify();
|
|
205
|
+
if (broadcast)
|
|
206
|
+
this.#publishStatus("anonymous");
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Registers a session listener and returns its unsubscribe function.
|
|
210
|
+
*
|
|
211
|
+
* @param listener - Callback invoked with each authentication snapshot.
|
|
212
|
+
* @returns Function that unregisters the listener.
|
|
213
|
+
*/
|
|
214
|
+
subscribe(listener) {
|
|
215
|
+
this.#listeners.add(listener);
|
|
216
|
+
return () => this.#listeners.delete(listener);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns a valid access token, refreshing an expired session once when possible.
|
|
220
|
+
* Concurrent callers share the same refresh operation.
|
|
221
|
+
*
|
|
222
|
+
* @returns Active access token when a valid session is available.
|
|
223
|
+
*/
|
|
224
|
+
async getAccessToken() {
|
|
225
|
+
const session = this.#session;
|
|
226
|
+
if (!session)
|
|
227
|
+
return undefined;
|
|
228
|
+
if (!isMiaixzSessionExpired(session, this.#now(), this.#expirationLeewaySeconds)) {
|
|
229
|
+
return session.accessToken;
|
|
230
|
+
}
|
|
231
|
+
if (!this.#refresh)
|
|
232
|
+
return undefined;
|
|
233
|
+
this.#refreshPromise ??= Promise.resolve()
|
|
234
|
+
.then(() => this.#refresh?.(Object.freeze({ ...session })))
|
|
235
|
+
.then((refreshed) => {
|
|
236
|
+
if (refreshed)
|
|
237
|
+
this.setSession(refreshed);
|
|
238
|
+
else
|
|
239
|
+
this.clearSession();
|
|
240
|
+
return refreshed;
|
|
241
|
+
})
|
|
242
|
+
.catch(() => {
|
|
243
|
+
this.clearSession();
|
|
244
|
+
throw new MiaixzSdkError(this.#translate("sdk.error.auth.refreshFailed"), {
|
|
245
|
+
code: "AUTH_REFRESH_FAILED",
|
|
246
|
+
});
|
|
247
|
+
})
|
|
248
|
+
.finally(() => {
|
|
249
|
+
this.#refreshPromise = undefined;
|
|
250
|
+
});
|
|
251
|
+
return (await this.#refreshPromise)?.accessToken;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Fetch-compatible token provider bound to this manager.
|
|
255
|
+
*
|
|
256
|
+
* @returns Active access token when a valid session is available.
|
|
257
|
+
*/
|
|
258
|
+
tokenProvider = () => this.getAccessToken();
|
|
259
|
+
/**
|
|
260
|
+
* Returns a complete Authorization header value using the session token type.
|
|
261
|
+
* Bearer remains the default when the session does not declare a token type.
|
|
262
|
+
*
|
|
263
|
+
* @returns Complete Authorization header value when signed in.
|
|
264
|
+
*/
|
|
265
|
+
authorizationProvider = async () => {
|
|
266
|
+
const accessToken = await this.getAccessToken();
|
|
267
|
+
if (!accessToken)
|
|
268
|
+
return undefined;
|
|
269
|
+
const tokenType = this.#session?.tokenType?.trim() || "Bearer";
|
|
270
|
+
return `${tokenType} ${accessToken}`;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Releases event subscriptions and local listeners owned by this manager.
|
|
274
|
+
*/
|
|
275
|
+
destroy() {
|
|
276
|
+
this.#stopEventListener?.();
|
|
277
|
+
this.#listeners.clear();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Publishes an immutable session snapshot to local subscribers.
|
|
281
|
+
*/
|
|
282
|
+
#notify() {
|
|
283
|
+
const snapshot = this.getSession();
|
|
284
|
+
for (const listener of this.#listeners)
|
|
285
|
+
listener(snapshot);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Publishes a non-sensitive authentication status without consuming its local echo.
|
|
289
|
+
*
|
|
290
|
+
* @param status - Authentication status to deliver locally and across configured windows.
|
|
291
|
+
*/
|
|
292
|
+
#publishStatus(status) {
|
|
293
|
+
if (!this.#events)
|
|
294
|
+
return;
|
|
295
|
+
this.#publishingStatus = true;
|
|
296
|
+
try {
|
|
297
|
+
this.#events.emit("auth:changed", Object.freeze({ status }));
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
this.#publishingStatus = false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Creates a Bearer authentication manager with in-memory-only defaults.
|
|
306
|
+
*
|
|
307
|
+
* @param options - Optional persistence, refresh, clock, event, and translation adapters.
|
|
308
|
+
* @returns Configured authentication manager.
|
|
309
|
+
* @public
|
|
310
|
+
*/
|
|
311
|
+
export function createMiaixzAuthManager(options) {
|
|
312
|
+
return new MiaixzAuthManager(options);
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=auth.js.map
|