@zohodesk/i18n 1.0.0-beta.34 → 1.0.0-beta.35-murphy

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 (51) hide show
  1. package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
  2. package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
  3. package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
  4. package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
  5. package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
  6. package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
  7. package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
  8. package/es/components/DateTimeDiffFormat.js +5 -19
  9. package/es/components/FormatText.js +2 -2
  10. package/es/components/HOCI18N.js +32 -43
  11. package/es/components/I18N.js +2 -13
  12. package/es/components/I18NProvider.js +0 -9
  13. package/es/components/PluralFormat.js +3 -5
  14. package/es/components/UserTimeDiffFormat.js +5 -9
  15. package/es/components/__tests__/DateTimeDiffFormat.spec.js +157 -221
  16. package/es/components/__tests__/FormatText.spec.js +2 -2
  17. package/es/components/__tests__/HOCI18N.spec.js +2 -4
  18. package/es/components/__tests__/I18N.spec.js +6 -4
  19. package/es/components/__tests__/I18NProvider.spec.js +4 -4
  20. package/es/components/__tests__/PluralFormat.spec.js +2 -2
  21. package/es/components/__tests__/UserTimeDiffFormat.spec.js +249 -348
  22. package/es/index.js +1 -0
  23. package/es/utils/__tests__/jsxTranslations.spec.js +3 -7
  24. package/es/utils/errorReporter.js +31 -0
  25. package/es/utils/index.js +42 -92
  26. package/es/utils/jsxTranslations.js +34 -52
  27. package/lib/I18NContext.js +2 -7
  28. package/lib/components/DateTimeDiffFormat.js +46 -87
  29. package/lib/components/FormatText.js +18 -41
  30. package/lib/components/HOCI18N.js +24 -59
  31. package/lib/components/I18N.js +27 -64
  32. package/lib/components/I18NProvider.js +27 -63
  33. package/lib/components/PluralFormat.js +24 -50
  34. package/lib/components/UserTimeDiffFormat.js +43 -72
  35. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +95 -165
  36. package/lib/components/__tests__/FormatText.spec.js +3 -10
  37. package/lib/components/__tests__/HOCI18N.spec.js +3 -14
  38. package/lib/components/__tests__/I18N.spec.js +4 -12
  39. package/lib/components/__tests__/I18NProvider.spec.js +8 -23
  40. package/lib/components/__tests__/PluralFormat.spec.js +3 -11
  41. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +157 -225
  42. package/lib/index.js +25 -23
  43. package/lib/utils/__tests__/jsxTranslations.spec.js +1 -12
  44. package/lib/utils/errorReporter.js +39 -0
  45. package/lib/utils/index.js +49 -125
  46. package/lib/utils/jsxTranslations.js +61 -100
  47. package/package.json +1 -1
  48. package/src/index.js +5 -0
  49. package/src/utils/errorReporter.js +36 -0
  50. package/src/utils/index.js +8 -1
  51. package/src/utils/jsxTranslations.js +8 -1
@@ -0,0 +1,337 @@
1
+ # Murphy Backend Configuration
2
+
3
+ ## Overview
4
+
5
+ Murphy configuration originates from the Java backend and flows to the JavaScript client through server-rendered HTML. This ensures each datacenter uses the correct Murphy instance automatically.
6
+
7
+ ---
8
+
9
+ ## Configuration Flow Diagram
10
+
11
+ ```
12
+ +-------------------------------------------------------------------+
13
+ | BACKEND CONFIGURATION FLOW |
14
+ +-------------------------------------------------------------------+
15
+ | |
16
+ | Step 1: Properties File (Region-specific credentials) |
17
+ | +--------------------------------------------------------------+ |
18
+ | | /product_package/conf/ZohoSupport/dcurl.properties | |
19
+ | | | |
20
+ | | # US Datacenter | |
21
+ | | dcurl.desk.murphy.appkey_US = 755747375 | |
22
+ | | dcurl.desk.murphy.appdomain_US = murphy.zoho.com | |
23
+ | | dcurl.desk.murphy.authKey_US = BPEEOUVxexAB... | |
24
+ | | | |
25
+ | | # JP Datacenter | |
26
+ | | dcurl.desk.murphy.appkey_JP = 90001069766 | |
27
+ | | dcurl.desk.murphy.appdomain_JP = murphy.zoho.jp | |
28
+ | | dcurl.desk.murphy.authKey_JP = TNYW... | |
29
+ | | | |
30
+ | | # IN Datacenter | |
31
+ | | dcurl.desk.murphy.appkey_IN = 60013588960 | |
32
+ | | dcurl.desk.murphy.appdomain_IN = murphy.zoho.in | |
33
+ | | dcurl.desk.murphy.authKey_IN = ... | |
34
+ | | | |
35
+ | +--------------------------------------------------------------+ |
36
+ | | |
37
+ | v |
38
+ | Step 2: Constants Class (Load into Java constants) |
39
+ | +--------------------------------------------------------------+ |
40
+ | | MurphyConstants.java | |
41
+ | | /com/adventnet/support/common/util/MurphyConstants.java | |
42
+ | | | |
43
+ | | public class MurphyConstants { | |
44
+ | | public static final String APP_KEY = | |
45
+ | | Configuration.getString("dcurl.desk.murphy.appkey"); | |
46
+ | | public static final String AUTH_KEY = | |
47
+ | | Configuration.getString("dcurl.desk.murphy.authKey"); | |
48
+ | | public static final String APP_DOMAIN = | |
49
+ | | Configuration.getString("dcurl.desk.murphy.appdomain"); | |
50
+ | | } | |
51
+ | +--------------------------------------------------------------+ |
52
+ | | |
53
+ | v |
54
+ | Step 3: Client Injection (Embed in HTML response) |
55
+ | +--------------------------------------------------------------+ |
56
+ | | ClientInitUtil.java | |
57
+ | | /com/zoho/desk/client/util/ClientInitUtil.java | |
58
+ | | | |
59
+ | | public static JSONObject getDeskUrls(HttpServletRequest) { | |
60
+ | | JSONObject deskUrls = new JSONObject(); | |
61
+ | | deskUrls.put("murphyAppKey", MurphyConstants.APP_KEY); | |
62
+ | | deskUrls.put("murphyAppDomain", MurphyConstants.APP_DOMAIN);|
63
+ | | deskUrls.put("murphyAuthKey", MurphyConstants.AUTH_KEY); | |
64
+ | | return deskUrls; | |
65
+ | | } | |
66
+ | +--------------------------------------------------------------+ |
67
+ | | |
68
+ | v |
69
+ | Step 4: HTML Output (Server-rendered script tag) |
70
+ | +--------------------------------------------------------------+ |
71
+ | | index.html (generated) | |
72
+ | | | |
73
+ | | <script nonce="abc123"> | |
74
+ | | var desk_urls = { | |
75
+ | | murphyAppKey: "755747375", | |
76
+ | | murphyAppDomain: "murphy.zoho.com", | |
77
+ | | murphyAuthKey: "BPEEOUVxexAB..." | |
78
+ | | }; | |
79
+ | | </script> | |
80
+ | +--------------------------------------------------------------+ |
81
+ | |
82
+ +--------------------------------------------------------------------+
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 1. dcurl.properties
88
+
89
+ The `dcurl.properties` file stores Murphy credentials for each datacenter:
90
+
91
+ ### File Location
92
+ ```
93
+ /product_package/conf/ZohoSupport/dcurl.properties
94
+ ```
95
+
96
+ ### Configuration Format
97
+ ```properties
98
+ # Murphy Configuration Pattern:
99
+ # dcurl.desk.murphy.<property>_<DATACENTER> = <value>
100
+
101
+ # US Datacenter
102
+ dcurl.desk.murphy.appkey_US = 755747375
103
+ dcurl.desk.murphy.appdomain_US = murphy.zoho.com
104
+ dcurl.desk.murphy.authKey_US = BPEEOUVxexABKEY...
105
+
106
+ # Japan Datacenter
107
+ dcurl.desk.murphy.appkey_JP = 90001069766
108
+ dcurl.desk.murphy.appdomain_JP = murphy.zoho.jp
109
+ dcurl.desk.murphy.authKey_JP = TNYWExampleKey...
110
+
111
+ # India Datacenter
112
+ dcurl.desk.murphy.appkey_IN = 60013588960
113
+ dcurl.desk.murphy.appdomain_IN = murphy.zoho.in
114
+ dcurl.desk.murphy.authKey_IN = INExampleKey...
115
+
116
+ # Europe Datacenter
117
+ dcurl.desk.murphy.appkey_EU = ...
118
+ dcurl.desk.murphy.appdomain_EU = murphy.zoho.eu
119
+ dcurl.desk.murphy.authKey_EU = ...
120
+
121
+ # Australia Datacenter
122
+ dcurl.desk.murphy.appkey_AU = ...
123
+ dcurl.desk.murphy.appdomain_AU = murphy.zoho.com.au
124
+ dcurl.desk.murphy.authKey_AU = ...
125
+
126
+ # Canada Datacenter
127
+ dcurl.desk.murphy.appkey_CA = ...
128
+ dcurl.desk.murphy.appdomain_CA = murphy.zoho.ca
129
+ dcurl.desk.murphy.authKey_CA = ...
130
+
131
+ # China Datacenter
132
+ dcurl.desk.murphy.appkey_CN = ...
133
+ dcurl.desk.murphy.appdomain_CN = murphy.zoho.com.cn
134
+ dcurl.desk.murphy.authKey_CN = ...
135
+
136
+ # Saudi Arabia Datacenter
137
+ dcurl.desk.murphy.appkey_SA = ...
138
+ dcurl.desk.murphy.appdomain_SA = murphy.zoho.sa
139
+ dcurl.desk.murphy.authKey_SA = ...
140
+ ```
141
+
142
+ ### Key Properties
143
+
144
+ | Property | Description |
145
+ |----------|-------------|
146
+ | `appkey` | Unique application identifier in Murphy |
147
+ | `appdomain` | Murphy server domain for the region |
148
+ | `authKey` | Base64 encoded authentication token |
149
+
150
+ ---
151
+
152
+ ## 2. MurphyConstants.java
153
+
154
+ This class reads the properties file and exposes them as Java constants:
155
+
156
+ ### File Location
157
+ ```
158
+ /com/adventnet/support/common/util/MurphyConstants.java
159
+ ```
160
+
161
+ ### Code Structure
162
+ ```java
163
+ package com.adventnet.support.common.util;
164
+
165
+ import com.zoho.conf.Configuration;
166
+
167
+ public class MurphyConstants {
168
+
169
+ /**
170
+ * Murphy application key for this datacenter.
171
+ * Automatically selects the correct key based on deployment region.
172
+ */
173
+ public static final String APP_KEY =
174
+ Configuration.getString("dcurl.desk.murphy.appkey");
175
+
176
+ /**
177
+ * Murphy authentication key (Base64 encoded).
178
+ */
179
+ public static final String AUTH_KEY =
180
+ Configuration.getString("dcurl.desk.murphy.authKey");
181
+
182
+ /**
183
+ * Murphy server domain for this datacenter.
184
+ */
185
+ public static final String APP_DOMAIN =
186
+ Configuration.getString("dcurl.desk.murphy.appdomain");
187
+ }
188
+ ```
189
+
190
+ ### How Region Selection Works
191
+
192
+ ```
193
+ +----------------------------------------------------------------+
194
+ | AUTOMATIC REGION SELECTION |
195
+ +----------------------------------------------------------------+
196
+ | |
197
+ | Configuration.getString("dcurl.desk.murphy.appkey") |
198
+ | | |
199
+ | v |
200
+ | +----------------------------------------------------------+ |
201
+ | | Zoho Configuration API: | |
202
+ | | | |
203
+ | | 1. Detects current datacenter from environment | |
204
+ | | 2. Appends datacenter suffix (_US, _JP, _IN, etc.) | |
205
+ | | 3. Reads dcurl.desk.murphy.appkey_<DC> from properties | |
206
+ | +----------------------------------------------------------+ |
207
+ | | |
208
+ | v |
209
+ | US Server: Returns "755747375" |
210
+ | JP Server: Returns "90001069766" |
211
+ | IN Server: Returns "60013588960" |
212
+ | |
213
+ +----------------------------------------------------------------+
214
+ ```
215
+
216
+ The developer writes ONE line of code, but it returns DIFFERENT values based on where the server is deployed.
217
+
218
+ ---
219
+
220
+ ## 3. ClientInitUtil.java
221
+
222
+ This utility class injects Murphy configuration into the HTML response:
223
+
224
+ ### File Location
225
+ ```
226
+ /com/zoho/desk/client/util/ClientInitUtil.java
227
+ ```
228
+
229
+ ### Code Structure
230
+ ```java
231
+ package com.zoho.desk.client.util;
232
+
233
+ import com.adventnet.support.common.util.MurphyConstants;
234
+ import org.json.JSONObject;
235
+
236
+ public class ClientInitUtil {
237
+
238
+ /**
239
+ * Creates the desk_urls object that gets embedded in HTML.
240
+ * This object is accessible to JavaScript as window.desk_urls
241
+ */
242
+ public static JSONObject getDeskUrls(HttpServletRequest request) {
243
+ JSONObject deskUrls = new JSONObject();
244
+
245
+ // ... other configuration ...
246
+
247
+ // Murphy configuration injection
248
+ deskUrls.put("murphyAppKey", MurphyConstants.APP_KEY);
249
+ deskUrls.put("murphyAppDomain", MurphyConstants.APP_DOMAIN);
250
+ deskUrls.put("murphyAuthKey", MurphyConstants.AUTH_KEY);
251
+
252
+ // ... other configuration ...
253
+
254
+ return deskUrls;
255
+ }
256
+ }
257
+ ```
258
+
259
+ ### HTML Generation (JSP/Servlet)
260
+ ```jsp
261
+ <%@ page import="com.zoho.desk.client.util.ClientInitUtil" %>
262
+ <%
263
+ JSONObject deskUrls = ClientInitUtil.getDeskUrls(request);
264
+ String encodedUrls = IAMEncoder.encodeForJavaScript(deskUrls.toString());
265
+ %>
266
+ <script nonce="<%= cspNonce %>">
267
+ var desk_urls = <%= encodedUrls %>;
268
+ </script>
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Security Considerations
274
+
275
+ ### XSS Protection
276
+ ```java
277
+ // Values are encoded to prevent XSS attacks
278
+ String encodedUrls = IAMEncoder.encodeForJavaScript(deskUrls.toString());
279
+ ```
280
+
281
+ ### Content Security Policy
282
+ ```html
283
+ <!-- Script tag uses nonce for CSP compliance -->
284
+ <script nonce="abc123">
285
+ var desk_urls = {...};
286
+ </script>
287
+ ```
288
+
289
+ ### Auth Key Encoding
290
+ ```
291
+ +------------------------------------------------+
292
+ | AUTH KEY HANDLING |
293
+ +------------------------------------------------+
294
+ | |
295
+ | Storage: Base64 encoded in properties file |
296
+ | Transport: Embedded in HTML (HTTPS only) |
297
+ | Usage: SDK handles authentication |
298
+ | |
299
+ +------------------------------------------------+
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Summary
305
+
306
+ ```
307
+ +-------------------------------------------------------------------+
308
+ | BACKEND CONFIG SUMMARY |
309
+ +-------------------------------------------------------------------+
310
+ | |
311
+ | dcurl.properties |
312
+ | +-- Stores credentials per datacenter |
313
+ | +-- Region suffix pattern: _US, _JP, _IN, _EU, etc. |
314
+ | |
315
+ | MurphyConstants.java |
316
+ | +-- Reads properties via Configuration API |
317
+ | +-- Auto-detects datacenter from environment |
318
+ | +-- Exposes as static final constants |
319
+ | |
320
+ | ClientInitUtil.java |
321
+ | +-- Creates desk_urls JSON object |
322
+ | +-- Injects Murphy config into HTML response |
323
+ | +-- Handles XSS encoding |
324
+ | |
325
+ | Result: Client JavaScript gets correct Murphy config |
326
+ | without knowing which datacenter it's in! |
327
+ | |
328
+ +-------------------------------------------------------------------+
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Related Documents
334
+
335
+ - [01-MURPHY_OVERVIEW.md](./01-MURPHY_OVERVIEW.md) - What is Murphy
336
+ - [02-MURPHY_ARCHITECTURE.md](./02-MURPHY_ARCHITECTURE.md) - Full architecture
337
+ - [04-MURPHY_FRONTEND_INIT.md](./04-MURPHY_FRONTEND_INIT.md) - Client initialization