brix-runtime-sdk-api-web 1.0.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.
Files changed (135) hide show
  1. package/dist/index.js +190 -0
  2. package/dist/types/api-exports.test.d.ts +33 -0
  3. package/dist/types/api-exports.test.d.ts.map +1 -0
  4. package/dist/types/context/RuntimeContext.d.ts +69 -0
  5. package/dist/types/context/RuntimeContext.d.ts.map +1 -0
  6. package/dist/types/context/index.d.ts +23 -0
  7. package/dist/types/context/index.d.ts.map +1 -0
  8. package/dist/types/index.d.ts +52 -0
  9. package/dist/types/index.d.ts.map +1 -0
  10. package/dist/types/types/auth.d.ts +405 -0
  11. package/dist/types/types/auth.d.ts.map +1 -0
  12. package/dist/types/types/capability.d.ts +218 -0
  13. package/dist/types/types/capability.d.ts.map +1 -0
  14. package/dist/types/types/common.d.ts +99 -0
  15. package/dist/types/types/common.d.ts.map +1 -0
  16. package/dist/types/types/config.d.ts +85 -0
  17. package/dist/types/types/config.d.ts.map +1 -0
  18. package/dist/types/types/event.d.ts +658 -0
  19. package/dist/types/types/event.d.ts.map +1 -0
  20. package/dist/types/types/http.d.ts +132 -0
  21. package/dist/types/types/http.d.ts.map +1 -0
  22. package/dist/types/types/i18n.d.ts +327 -0
  23. package/dist/types/types/i18n.d.ts.map +1 -0
  24. package/dist/types/types/index.d.ts +61 -0
  25. package/dist/types/types/index.d.ts.map +1 -0
  26. package/dist/types/types/layout.d.ts +301 -0
  27. package/dist/types/types/layout.d.ts.map +1 -0
  28. package/dist/types/types/module.d.ts +78 -0
  29. package/dist/types/types/module.d.ts.map +1 -0
  30. package/dist/types/types/navigation.d.ts +295 -0
  31. package/dist/types/types/navigation.d.ts.map +1 -0
  32. package/dist/types/types/plugin-loader-capability.d.ts +142 -0
  33. package/dist/types/types/plugin-loader-capability.d.ts.map +1 -0
  34. package/dist/types/types/plugin.d.ts +250 -0
  35. package/dist/types/types/plugin.d.ts.map +1 -0
  36. package/dist/types/types/state.d.ts +306 -0
  37. package/dist/types/types/state.d.ts.map +1 -0
  38. package/dist/types/types/theme.d.ts +279 -0
  39. package/dist/types/types/theme.d.ts.map +1 -0
  40. package/dist/types/types/ui/adapter.d.ts +181 -0
  41. package/dist/types/types/ui/adapter.d.ts.map +1 -0
  42. package/dist/types/types/ui/avatar.d.ts +102 -0
  43. package/dist/types/types/ui/avatar.d.ts.map +1 -0
  44. package/dist/types/types/ui/badge.d.ts +101 -0
  45. package/dist/types/types/ui/badge.d.ts.map +1 -0
  46. package/dist/types/types/ui/button.d.ts +135 -0
  47. package/dist/types/types/ui/button.d.ts.map +1 -0
  48. package/dist/types/types/ui/card.d.ts +105 -0
  49. package/dist/types/types/ui/card.d.ts.map +1 -0
  50. package/dist/types/types/ui/common.d.ts +29 -0
  51. package/dist/types/types/ui/common.d.ts.map +1 -0
  52. package/dist/types/types/ui/icon.d.ts +78 -0
  53. package/dist/types/types/ui/icon.d.ts.map +1 -0
  54. package/dist/types/types/ui/index.d.ts +59 -0
  55. package/dist/types/types/ui/index.d.ts.map +1 -0
  56. package/dist/types/types/ui/input.d.ts +200 -0
  57. package/dist/types/types/ui/input.d.ts.map +1 -0
  58. package/dist/types/types/ui/menu.d.ts +211 -0
  59. package/dist/types/types/ui/menu.d.ts.map +1 -0
  60. package/dist/types/types/ui/message.d.ts +121 -0
  61. package/dist/types/types/ui/message.d.ts.map +1 -0
  62. package/dist/types/types/ui/modal.d.ts +167 -0
  63. package/dist/types/types/ui/modal.d.ts.map +1 -0
  64. package/dist/types/types/ui/select.d.ts +213 -0
  65. package/dist/types/types/ui/select.d.ts.map +1 -0
  66. package/dist/types/types/ui/theme-tokens.d.ts +226 -0
  67. package/dist/types/types/ui/theme-tokens.d.ts.map +1 -0
  68. package/dist/types/types/ui/tooltip.d.ts +98 -0
  69. package/dist/types/types/ui/tooltip.d.ts.map +1 -0
  70. package/dist/types/types/ui.d.ts +49 -0
  71. package/dist/types/types/ui.d.ts.map +1 -0
  72. package/package.json +34 -0
  73. package/src/api-exports.test.ts +199 -0
  74. package/src/context/RuntimeContext.d.ts +69 -0
  75. package/src/context/RuntimeContext.d.ts.map +1 -0
  76. package/src/context/RuntimeContext.ts +75 -0
  77. package/src/context/index.d.ts +23 -0
  78. package/src/context/index.d.ts.map +1 -0
  79. package/src/context/index.ts +23 -0
  80. package/src/index.d.ts +52 -0
  81. package/src/index.d.ts.map +1 -0
  82. package/src/index.ts +59 -0
  83. package/src/types/auth.d.ts +146 -0
  84. package/src/types/auth.d.ts.map +1 -0
  85. package/src/types/auth.ts +479 -0
  86. package/src/types/capability.d.ts +218 -0
  87. package/src/types/capability.d.ts.map +1 -0
  88. package/src/types/capability.ts +302 -0
  89. package/src/types/common.d.ts +99 -0
  90. package/src/types/common.d.ts.map +1 -0
  91. package/src/types/common.ts +115 -0
  92. package/src/types/config.d.ts +64 -0
  93. package/src/types/config.d.ts.map +1 -0
  94. package/src/types/config.ts +96 -0
  95. package/src/types/event.d.ts +206 -0
  96. package/src/types/event.d.ts.map +1 -0
  97. package/src/types/event.ts +776 -0
  98. package/src/types/http.d.ts +132 -0
  99. package/src/types/http.d.ts.map +1 -0
  100. package/src/types/http.ts +156 -0
  101. package/src/types/i18n.ts +420 -0
  102. package/src/types/index.d.ts +50 -0
  103. package/src/types/index.d.ts.map +1 -0
  104. package/src/types/index.ts +120 -0
  105. package/src/types/layout.ts +394 -0
  106. package/src/types/module.d.ts +78 -0
  107. package/src/types/module.d.ts.map +1 -0
  108. package/src/types/module.ts +92 -0
  109. package/src/types/navigation.d.ts +101 -0
  110. package/src/types/navigation.d.ts.map +1 -0
  111. package/src/types/navigation.ts +361 -0
  112. package/src/types/plugin-loader-capability.ts +159 -0
  113. package/src/types/plugin.d.ts +250 -0
  114. package/src/types/plugin.d.ts.map +1 -0
  115. package/src/types/plugin.ts +344 -0
  116. package/src/types/state.d.ts +119 -0
  117. package/src/types/state.d.ts.map +1 -0
  118. package/src/types/state.ts +366 -0
  119. package/src/types/theme.ts +378 -0
  120. package/src/types/ui/adapter.ts +222 -0
  121. package/src/types/ui/avatar.ts +113 -0
  122. package/src/types/ui/badge.ts +112 -0
  123. package/src/types/ui/button.ts +148 -0
  124. package/src/types/ui/card.ts +116 -0
  125. package/src/types/ui/common.ts +29 -0
  126. package/src/types/ui/icon.ts +85 -0
  127. package/src/types/ui/index.ts +78 -0
  128. package/src/types/ui/input.ts +225 -0
  129. package/src/types/ui/menu.ts +237 -0
  130. package/src/types/ui/message.ts +135 -0
  131. package/src/types/ui/modal.ts +188 -0
  132. package/src/types/ui/select.ts +239 -0
  133. package/src/types/ui/theme-tokens.ts +357 -0
  134. package/src/types/ui/tooltip.ts +120 -0
  135. package/src/types/ui.ts +49 -0
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Copyright 2026 Brix Platform Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * @file HTTP Client Capability Type Definitions
18
+ * @description Defines HTTP client capability contract, replacing direct use of fetch/axios
19
+ * @module @brix/runtime-sdk-api-web/types/http
20
+ * @version 3.2.0
21
+ *
22
+ * [v3.2 Changes]
23
+ * Extracted from index.ts into a standalone type file.
24
+ *
25
+ * [Architectural Constraint - R3]
26
+ * Plugin layer is prohibited from using HTTP client libraries like axios/fetch directly,
27
+ * requests must be made through the HttpCapability.
28
+ */
29
+ /**
30
+ * HTTP Client Capability Type Identifier
31
+ */
32
+ export declare const HttpCapabilityType: unique symbol;
33
+ /**
34
+ * HTTP Request Configuration Options
35
+ */
36
+ export interface HttpRequestConfig {
37
+ /** Request URL (relative to baseURL or absolute path) */
38
+ readonly url: string;
39
+ /** HTTP Method */
40
+ readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
41
+ /** Request Headers */
42
+ readonly headers?: Record<string, string>;
43
+ /** URL Query Parameters */
44
+ readonly params?: Record<string, unknown>;
45
+ /** Request Body */
46
+ readonly data?: unknown;
47
+ /** Timeout (milliseconds) */
48
+ readonly timeout?: number;
49
+ /** Base URL */
50
+ readonly baseURL?: string;
51
+ }
52
+ /**
53
+ * HTTP Response Structure
54
+ */
55
+ export interface HttpResponse<T = unknown> {
56
+ /** Response Data */
57
+ readonly data: T;
58
+ /** HTTP Status Code */
59
+ readonly status: number;
60
+ /** Status Text */
61
+ readonly statusText: string;
62
+ /** Response Headers */
63
+ readonly headers: Record<string, string>;
64
+ }
65
+ /**
66
+ * HTTP Client Capability Contract
67
+ *
68
+ * <p>Provides a unified HTTP request abstraction for the plugin layer, replacing direct axios/fetch calls.</p>
69
+ *
70
+ * <h3>Usage Example</h3>
71
+ * ```typescript
72
+ * const http = runtimeContext.getCapability<HttpCapability>(HttpCapabilityType);
73
+ * const products = await http.get<Product[]>('/api/v1/products');
74
+ * const created = await http.post<Product>('/api/v1/products', newProduct);
75
+ * ```
76
+ *
77
+ * <h3>Architecture Notes</h3>
78
+ * <ul>
79
+ * <li>Shell layer provides the implementation (can be based on fetch/axios, transparent to plugins)</li>
80
+ * <li>Automatically injects auth tokens, tenant IDs, and other context headers</li>
81
+ * <li>Unified error handling and retry strategies</li>
82
+ * </ul>
83
+ */
84
+ export interface HttpCapability {
85
+ /**
86
+ * Send Generic Request
87
+ *
88
+ * @param config Request configuration
89
+ * @returns Response result
90
+ */
91
+ request<T = unknown>(config: HttpRequestConfig): Promise<HttpResponse<T>>;
92
+ /**
93
+ * GET Request
94
+ *
95
+ * @param url Request URL
96
+ * @param params Query parameters
97
+ * @returns Response data
98
+ */
99
+ get<T = unknown>(url: string, params?: Record<string, unknown>): Promise<T>;
100
+ /**
101
+ * POST Request
102
+ *
103
+ * @param url Request URL
104
+ * @param data Request body
105
+ * @returns Response data
106
+ */
107
+ post<T = unknown>(url: string, data?: unknown): Promise<T>;
108
+ /**
109
+ * PUT Request
110
+ *
111
+ * @param url Request URL
112
+ * @param data Request body
113
+ * @returns Response data
114
+ */
115
+ put<T = unknown>(url: string, data?: unknown): Promise<T>;
116
+ /**
117
+ * DELETE Request
118
+ *
119
+ * @param url Request URL
120
+ * @returns Response data
121
+ */
122
+ delete<T = unknown>(url: string): Promise<T>;
123
+ /**
124
+ * PATCH Request
125
+ *
126
+ * @param url Request URL
127
+ * @param data Request body
128
+ * @returns Response data
129
+ */
130
+ patch<T = unknown>(url: string, data?: unknown): Promise<T>;
131
+ }
132
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAM/D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gCAAgC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IACnF,UAAU;IACV,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,eAAe;IACf,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,UAAU;IACV,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe;IACf,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa;IACb,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAMD;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,WAAW;IACX,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,eAAe;IACf,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,WAAW;IACX,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,UAAU;IACV,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1E;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE5E;;;;;;OAMG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE3D;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE1D;;;;;OAKG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7C;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Copyright 2026 Brix Platform Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * @file HTTP Client Capability Type Definitions
18
+ * @description Defines HTTP client capability contract, replacing direct use of fetch/axios
19
+ * @module @brix/runtime-sdk-api-web/types/http
20
+ * @version 3.2.0
21
+ *
22
+ * [v3.2 Changes]
23
+ * Extracted from index.ts into a standalone type file.
24
+ *
25
+ * [Architectural Constraint - R3]
26
+ * Plugin layer is prohibited from using HTTP client libraries like axios/fetch directly,
27
+ * requests must be made through the HttpCapability.
28
+ */
29
+
30
+ // =========================================
31
+ // HTTP Capability Type Identifier
32
+ // =========================================
33
+
34
+ /**
35
+ * HTTP Client Capability Type Identifier
36
+ */
37
+ export const HttpCapabilityType = Symbol.for('HttpCapability');
38
+
39
+ // =========================================
40
+ // HTTP Request Configuration
41
+ // =========================================
42
+
43
+ /**
44
+ * HTTP Request Configuration Options
45
+ */
46
+ export interface HttpRequestConfig {
47
+ /** Request URL (relative to baseURL or absolute path) */
48
+ readonly url: string;
49
+ /** HTTP Method */
50
+ readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
51
+ /** Request Headers */
52
+ readonly headers?: Record<string, string>;
53
+ /** URL Query Parameters */
54
+ readonly params?: Record<string, unknown>;
55
+ /** Request Body */
56
+ readonly data?: unknown;
57
+ /** Timeout (milliseconds) */
58
+ readonly timeout?: number;
59
+ /** Base URL */
60
+ readonly baseURL?: string;
61
+ }
62
+
63
+ // =========================================
64
+ // HTTP Response Structure
65
+ // =========================================
66
+
67
+ /**
68
+ * HTTP Response Structure
69
+ */
70
+ export interface HttpResponse<T = unknown> {
71
+ /** Response Data */
72
+ readonly data: T;
73
+ /** HTTP Status Code */
74
+ readonly status: number;
75
+ /** Status Text */
76
+ readonly statusText: string;
77
+ /** Response Headers */
78
+ readonly headers: Record<string, string>;
79
+ }
80
+
81
+ // =========================================
82
+ // HTTP Capability Contract
83
+ // =========================================
84
+
85
+ /**
86
+ * HTTP Client Capability Contract
87
+ *
88
+ * <p>Provides a unified HTTP request abstraction for the plugin layer, replacing direct axios/fetch calls.</p>
89
+ *
90
+ * <h3>Usage Example</h3>
91
+ * ```typescript
92
+ * const http = runtimeContext.getCapability<HttpCapability>(HttpCapabilityType);
93
+ * const products = await http.get<Product[]>('/api/v1/products');
94
+ * const created = await http.post<Product>('/api/v1/products', newProduct);
95
+ * ```
96
+ *
97
+ * <h3>Architecture Notes</h3>
98
+ * <ul>
99
+ * <li>Shell layer provides the implementation (can be based on fetch/axios, transparent to plugins)</li>
100
+ * <li>Automatically injects auth tokens, tenant IDs, and other context headers</li>
101
+ * <li>Unified error handling and retry strategies</li>
102
+ * </ul>
103
+ */
104
+ export interface HttpCapability {
105
+ /**
106
+ * Send Generic Request
107
+ *
108
+ * @param config Request configuration
109
+ * @returns Response result
110
+ */
111
+ request<T = unknown>(config: HttpRequestConfig): Promise<HttpResponse<T>>;
112
+
113
+ /**
114
+ * GET Request
115
+ *
116
+ * @param url Request URL
117
+ * @param params Query parameters
118
+ * @returns Response data
119
+ */
120
+ get<T = unknown>(url: string, params?: Record<string, unknown>): Promise<T>;
121
+
122
+ /**
123
+ * POST Request
124
+ *
125
+ * @param url Request URL
126
+ * @param data Request body
127
+ * @returns Response data
128
+ */
129
+ post<T = unknown>(url: string, data?: unknown): Promise<T>;
130
+
131
+ /**
132
+ * PUT Request
133
+ *
134
+ * @param url Request URL
135
+ * @param data Request body
136
+ * @returns Response data
137
+ */
138
+ put<T = unknown>(url: string, data?: unknown): Promise<T>;
139
+
140
+ /**
141
+ * DELETE Request
142
+ *
143
+ * @param url Request URL
144
+ * @returns Response data
145
+ */
146
+ delete<T = unknown>(url: string): Promise<T>;
147
+
148
+ /**
149
+ * PATCH Request
150
+ *
151
+ * @param url Request URL
152
+ * @param data Request body
153
+ * @returns Response data
154
+ */
155
+ patch<T = unknown>(url: string, data?: unknown): Promise<T>;
156
+ }
@@ -0,0 +1,420 @@
1
+ /**
2
+ * Copyright 2026 Brix Platform Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * @file Internationalization Capability Type Definitions
18
+ * @description Defines core types for the internationalization system, including language switching, translation, date/number formatting, etc.
19
+ * @module @brix/runtime-sdk-api-web/types/i18n
20
+ * @version 3.2.0
21
+ *
22
+ * [v3.2.0 Added]
23
+ * Phase 1 contract layer fix: Promoted the I18nCapability interface to runtime-sdk-api-web.
24
+ *
25
+ * [Design Principles]
26
+ * - Plugins obtain translations through I18nCapability, hardcoded text is prohibited
27
+ * - Translation keys use namespace format: {moduleName}:{translationKey}
28
+ * - Language switching notifies all modules via events
29
+ * - Supports localized formatting for dates, numbers, relative time, etc.
30
+ *
31
+ * [Architectural Constraints]
32
+ * ❌ Hardcoding text in components is prohibited
33
+ * ❌ Direct use of libraries like i18next is prohibited
34
+ * ✅ Obtain translations through I18nCapability or useI18n hook
35
+ */
36
+
37
+ import type { Unsubscribe } from './event';
38
+
39
+ // =========================================
40
+ // Locale Code
41
+ // =========================================
42
+
43
+ /**
44
+ * Locale Code
45
+ *
46
+ * <p>Language tag conforming to BCP 47 specification.</p>
47
+ *
48
+ * @example
49
+ * - 'zh-CN': Simplified Chinese
50
+ * - 'zh-TW': Traditional Chinese
51
+ * - 'en-US': American English
52
+ * - 'ja-JP': Japanese
53
+ */
54
+ export type LocaleCode = string;
55
+
56
+ // =========================================
57
+ // Language Information
58
+ // =========================================
59
+
60
+ /**
61
+ * Language Information
62
+ *
63
+ * <p>Describes a supported language.</p>
64
+ */
65
+ export interface LanguageInfo {
66
+ /** Locale Code */
67
+ readonly code: LocaleCode;
68
+
69
+ /** Language Name (localized display name) */
70
+ readonly name: string;
71
+
72
+ /** English Name of the Language */
73
+ readonly englishName: string;
74
+
75
+ /** Whether it's an RTL (Right-to-Left) Language */
76
+ readonly rtl?: boolean;
77
+
78
+ /** Whether it's the Default Language */
79
+ readonly isDefault?: boolean;
80
+ }
81
+
82
+ // =========================================
83
+ // Translation Options
84
+ // =========================================
85
+
86
+ /**
87
+ * Translation Options
88
+ *
89
+ * <p>Configuration parameters controlling translation behavior.</p>
90
+ */
91
+ export interface TranslateOptions {
92
+ /**
93
+ * Interpolation Variables
94
+ *
95
+ * <p>Used to replace placeholders in translation text.</p>
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Translation template: "Welcome, {{name}}!"
100
+ * t('common:welcome', { name: 'John' }) // => "Welcome, John!"
101
+ * ```
102
+ */
103
+ readonly [key: string]: unknown;
104
+
105
+ /**
106
+ * Default Value
107
+ *
108
+ * <p>Returned when the translation key does not exist.</p>
109
+ */
110
+ readonly defaultValue?: string;
111
+
112
+ /**
113
+ * Specified Locale
114
+ *
115
+ * <p>Use specified language for translation instead of current language.</p>
116
+ */
117
+ readonly lng?: LocaleCode;
118
+
119
+ /**
120
+ * Specified Namespace
121
+ *
122
+ * <p>Overrides the namespace in the key.</p>
123
+ */
124
+ readonly ns?: string;
125
+
126
+ /**
127
+ * Plural Count
128
+ *
129
+ * <p>Used for plural rule selection.</p>
130
+ */
131
+ readonly count?: number;
132
+ }
133
+
134
+ // =========================================
135
+ // Language Bundle
136
+ // =========================================
137
+
138
+ /**
139
+ * Language Bundle
140
+ *
141
+ * <p>Translation resources under a namespace.</p>
142
+ */
143
+ export interface LanguageBundle {
144
+ /** Locale Code */
145
+ readonly locale: LocaleCode;
146
+
147
+ /** Namespace */
148
+ readonly namespace: string;
149
+
150
+ /** Translation Resources (key-value pairs) */
151
+ readonly resources: Record<string, string>;
152
+ }
153
+
154
+ // =========================================
155
+ // Date Formatting Options
156
+ // =========================================
157
+
158
+ /**
159
+ * Date Formatting Options
160
+ *
161
+ * <p>Subset based on Intl.DateTimeFormatOptions.</p>
162
+ */
163
+ export interface DateFormatOptions {
164
+ /** Date Style */
165
+ readonly dateStyle?: 'full' | 'long' | 'medium' | 'short';
166
+
167
+ /** Time Style */
168
+ readonly timeStyle?: 'full' | 'long' | 'medium' | 'short';
169
+
170
+ /** Time Zone */
171
+ readonly timeZone?: string;
172
+
173
+ /** Whether to Use 12-Hour Clock */
174
+ readonly hour12?: boolean;
175
+ }
176
+
177
+ // =========================================
178
+ // Number Formatting Options
179
+ // =========================================
180
+
181
+ /**
182
+ * Number Formatting Options
183
+ *
184
+ * <p>Subset based on Intl.NumberFormatOptions.</p>
185
+ */
186
+ export interface NumberFormatOptions {
187
+ /** Formatting Style */
188
+ readonly style?: 'decimal' | 'currency' | 'percent' | 'unit';
189
+
190
+ /** Currency Code (required when style='currency') */
191
+ readonly currency?: string;
192
+
193
+ /** Currency Display Mode */
194
+ readonly currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
195
+
196
+ /** Minimum Fraction Digits */
197
+ readonly minimumFractionDigits?: number;
198
+
199
+ /** Maximum Fraction Digits */
200
+ readonly maximumFractionDigits?: number;
201
+
202
+ /** Whether to Use Grouping (thousands separator) */
203
+ readonly useGrouping?: boolean;
204
+ }
205
+
206
+ // =========================================
207
+ // Relative Time Formatting Options
208
+ // =========================================
209
+
210
+ /**
211
+ * Relative Time Formatting Options
212
+ */
213
+ export interface RelativeTimeFormatOptions {
214
+ /** Relative Time Unit */
215
+ readonly unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
216
+
217
+ /** Display Style */
218
+ readonly style?: 'long' | 'short' | 'narrow';
219
+
220
+ /** Numeric Display Mode */
221
+ readonly numeric?: 'always' | 'auto';
222
+ }
223
+
224
+ // =========================================
225
+ // Locale Change Event
226
+ // =========================================
227
+
228
+ /**
229
+ * Locale Change Event
230
+ *
231
+ * <p>Event triggered when language is switched.</p>
232
+ */
233
+ export interface LocaleChangeEvent {
234
+ /** New Locale Code */
235
+ readonly locale: LocaleCode;
236
+
237
+ /** Previous Locale Code */
238
+ readonly previousLocale: LocaleCode;
239
+
240
+ /** Switch Timestamp */
241
+ readonly timestamp: number;
242
+ }
243
+
244
+ /**
245
+ * Locale Change Listener
246
+ */
247
+ export type LocaleChangeListener = (event: LocaleChangeEvent) => void;
248
+
249
+ // =========================================
250
+ // Internationalization Capability
251
+ // =========================================
252
+
253
+ /**
254
+ * Internationalization Capability Type Identifier
255
+ */
256
+ export const I18nCapabilityType = Symbol.for('I18nCapability');
257
+
258
+ /**
259
+ * Internationalization Capability Contract
260
+ *
261
+ * <p>Provides multi-language support for plugins, including translation, date/number formatting, etc.</p>
262
+ *
263
+ * <h3>Design Principles</h3>
264
+ * <ul>
265
+ * <li>Translation keys use namespace format: {moduleName}:{translationKey}</li>
266
+ * <li>Language bundles are registered when modules load</li>
267
+ * <li>Language switching notifies all modules via events</li>
268
+ * </ul>
269
+ *
270
+ * <h3>Usage Example</h3>
271
+ * ```typescript
272
+ * const i18n = context.getCapability<I18nCapability>(I18nCapabilityType);
273
+ *
274
+ * // Get translation
275
+ * const greeting = i18n.t('booking:greeting', { name: 'John' });
276
+ *
277
+ * // Format date
278
+ * const dateStr = i18n.formatDate(new Date(), { dateStyle: 'long' });
279
+ *
280
+ * // Switch language
281
+ * await i18n.setLocale('en-US');
282
+ *
283
+ * // Listen for language changes
284
+ * const unsubscribe = i18n.onLocaleChange((event) => {
285
+ * console.log(`Language changed from ${event.previousLocale} to ${event.locale}`);
286
+ * });
287
+ * ```
288
+ *
289
+ * @since 3.2.0
290
+ */
291
+ export interface I18nCapability {
292
+ // =========================================
293
+ // Translation Methods
294
+ // =========================================
295
+
296
+ /**
297
+ * Get Translation Text
298
+ *
299
+ * @param key Translation key (format: {namespace}:{key})
300
+ * @param options Translation options (interpolation variables, etc.)
301
+ * @returns Translated text
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * // Simple translation
306
+ * i18n.t('booking:pageTitle') // => "Booking Management"
307
+ *
308
+ * // With interpolation
309
+ * i18n.t('booking:welcome', { name: 'John' }) // => "Welcome, John!"
310
+ *
311
+ * // With pluralization
312
+ * i18n.t('booking:itemCount', { count: 5 }) // => "5 items"
313
+ * ```
314
+ */
315
+ t(key: string, options?: TranslateOptions): string;
316
+
317
+ /**
318
+ * Check if Translation Key Exists
319
+ *
320
+ * @param key Translation key
321
+ * @param options Options
322
+ * @returns Whether exists
323
+ */
324
+ exists(key: string, options?: { lng?: LocaleCode; ns?: string }): boolean;
325
+
326
+ // =========================================
327
+ // Language Management
328
+ // =========================================
329
+
330
+ /**
331
+ * Get Current Locale
332
+ *
333
+ * @returns Current locale code
334
+ */
335
+ getLocale(): LocaleCode;
336
+
337
+ /**
338
+ * Set Current Locale
339
+ *
340
+ * <p>Triggers LocaleChangeEvent after switching.</p>
341
+ *
342
+ * @param locale Target locale code
343
+ * @returns Whether switch succeeded
344
+ */
345
+ setLocale(locale: LocaleCode): Promise<boolean>;
346
+
347
+ /**
348
+ * Get Supported Locales List
349
+ *
350
+ * @returns Array of language information
351
+ */
352
+ getSupportedLocales(): LanguageInfo[];
353
+
354
+ /**
355
+ * Register Language Bundle
356
+ *
357
+ * @param bundle Language bundle definition
358
+ */
359
+ addResourceBundle(bundle: LanguageBundle): void;
360
+
361
+ /**
362
+ * Register Multiple Language Bundles
363
+ *
364
+ * @param bundles Array of language bundles
365
+ */
366
+ addResourceBundles?(bundles: LanguageBundle[]): void;
367
+
368
+ // =========================================
369
+ // Formatting Methods
370
+ // =========================================
371
+
372
+ /**
373
+ * Format Date
374
+ *
375
+ * @param date Date object or timestamp
376
+ * @param options Formatting options
377
+ * @returns Formatted date string
378
+ */
379
+ formatDate?(date: Date | number, options?: DateFormatOptions): string;
380
+
381
+ /**
382
+ * Format Number
383
+ *
384
+ * @param value Numeric value
385
+ * @param options Formatting options
386
+ * @returns Formatted number string
387
+ */
388
+ formatNumber?(value: number, options?: NumberFormatOptions): string;
389
+
390
+ /**
391
+ * Format Currency
392
+ *
393
+ * @param value Amount
394
+ * @param currency Currency code (e.g., 'CNY', 'USD')
395
+ * @param options Formatting options
396
+ * @returns Formatted currency string
397
+ */
398
+ formatCurrency?(value: number, currency: string, options?: Omit<NumberFormatOptions, 'style' | 'currency'>): string;
399
+
400
+ /**
401
+ * Format Relative Time
402
+ *
403
+ * @param date Date object or timestamp
404
+ * @param options Formatting options
405
+ * @returns Relative time string (e.g., "3 days ago")
406
+ */
407
+ formatRelativeTime?(date: Date | number, options?: RelativeTimeFormatOptions): string;
408
+
409
+ // =========================================
410
+ // Event Subscription
411
+ // =========================================
412
+
413
+ /**
414
+ * Subscribe to Locale Change Event
415
+ *
416
+ * @param listener Event listener
417
+ * @returns Unsubscribe function
418
+ */
419
+ onLocaleChange?(listener: LocaleChangeListener): Unsubscribe;
420
+ }