@zoho_apptics/apptics-js-sdk 2.0.0-beta → 2.0.0-beta.2

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 (236) hide show
  1. package/CHANGELOG.md +191 -21
  2. package/README.md +519 -333
  3. package/dist/apptics.esm.min.js +2 -2
  4. package/dist/apptics.esm.min.js.map +1 -1
  5. package/dist/apptics.min.js +2 -2
  6. package/dist/apptics.min.js.map +1 -1
  7. package/dist/chunks/lifecycle-C6m1W7jo.min.js +3 -0
  8. package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +1 -0
  9. package/dist/chunks/send-CgUO82ne.min.js +3 -0
  10. package/dist/chunks/send-CgUO82ne.min.js.map +1 -0
  11. package/dist/cjs/core/attempts.js +1 -1
  12. package/dist/cjs/core/batch.js +2 -2
  13. package/dist/cjs/core/consent.d.ts +18 -4
  14. package/dist/cjs/core/consent.js +31 -15
  15. package/dist/cjs/core/constants.d.ts +57 -27
  16. package/dist/cjs/core/constants.js +52 -33
  17. package/dist/cjs/core/db.d.ts +12 -4
  18. package/dist/cjs/core/db.js +167 -34
  19. package/dist/cjs/core/debug.js +1 -1
  20. package/dist/cjs/core/env.d.ts +0 -3
  21. package/dist/cjs/core/env.js +1 -9
  22. package/dist/cjs/core/framework-id.d.ts +1 -1
  23. package/dist/cjs/core/framework-id.js +3 -3
  24. package/dist/cjs/core/guard.d.ts +9 -0
  25. package/dist/cjs/core/guard.js +27 -13
  26. package/dist/cjs/core/hooks.d.ts +7 -4
  27. package/dist/cjs/core/hooks.js +3 -3
  28. package/dist/cjs/core/locks.d.ts +9 -0
  29. package/dist/cjs/core/locks.js +22 -0
  30. package/dist/cjs/core/logger.d.ts +3 -4
  31. package/dist/cjs/core/logger.js +4 -40
  32. package/dist/cjs/core/state.d.ts +9 -6
  33. package/dist/cjs/core/state.js +3 -5
  34. package/dist/cjs/core/storage.d.ts +20 -5
  35. package/dist/cjs/core/storage.js +115 -20
  36. package/dist/cjs/core/stylesheet.d.ts +8 -0
  37. package/dist/cjs/core/stylesheet.js +29 -0
  38. package/dist/cjs/core/transport.d.ts +2 -0
  39. package/dist/cjs/core/transport.js +30 -18
  40. package/dist/cjs/core/utils.js +1 -1
  41. package/dist/cjs/core/validate.js +2 -2
  42. package/dist/cjs/device/appversion.d.ts +10 -6
  43. package/dist/cjs/device/appversion.js +38 -3
  44. package/dist/cjs/device/index.d.ts +28 -2
  45. package/dist/cjs/device/index.js +312 -44
  46. package/dist/cjs/engagement/api-rules.d.ts +32 -67
  47. package/dist/cjs/engagement/api-rules.js +144 -157
  48. package/dist/cjs/engagement/auto-api.js +2 -2
  49. package/dist/cjs/engagement/auto-screen.d.ts +2 -0
  50. package/dist/cjs/engagement/auto-screen.js +67 -3
  51. package/dist/cjs/engagement/defined-events.js +1 -1
  52. package/dist/cjs/engagement/send.js +12 -3
  53. package/dist/cjs/engagement/session.d.ts +29 -3
  54. package/dist/cjs/engagement/session.js +253 -26
  55. package/dist/cjs/engagement/track.d.ts +4 -4
  56. package/dist/cjs/engagement/track.js +58 -30
  57. package/dist/cjs/errors/send.js +2 -2
  58. package/dist/cjs/errors/track.d.ts +2 -1
  59. package/dist/cjs/errors/track.js +49 -7
  60. package/dist/cjs/feedback/controls.d.ts +12 -0
  61. package/dist/cjs/feedback/controls.js +104 -25
  62. package/dist/cjs/feedback/index.d.ts +8 -7
  63. package/dist/cjs/feedback/index.js +32 -13
  64. package/dist/cjs/feedback/logs.d.ts +13 -11
  65. package/dist/cjs/feedback/logs.js +57 -28
  66. package/dist/cjs/feedback/quartz.d.ts +18 -0
  67. package/dist/cjs/feedback/quartz.js +105 -0
  68. package/dist/cjs/feedback/send.d.ts +5 -2
  69. package/dist/cjs/feedback/send.js +30 -28
  70. package/dist/cjs/feedback/styles.d.ts +10 -0
  71. package/dist/cjs/feedback/styles.js +8 -0
  72. package/dist/cjs/feedback/template.d.ts +1 -1
  73. package/dist/cjs/feedback/template.js +20 -12
  74. package/dist/cjs/feedback/ui.d.ts +21 -6
  75. package/dist/cjs/feedback/ui.js +283 -70
  76. package/dist/cjs/heatmap/send.d.ts +2 -0
  77. package/dist/cjs/heatmap/send.js +3 -5
  78. package/dist/cjs/heatmap/track.d.ts +1 -1
  79. package/dist/cjs/heatmap/track.js +87 -16
  80. package/dist/cjs/index.d.ts +16 -63
  81. package/dist/cjs/index.js +144 -95
  82. package/dist/cjs/lifecycle.d.ts +21 -3
  83. package/dist/cjs/lifecycle.js +353 -89
  84. package/dist/cjs/remoteconfig/country.d.ts +4 -0
  85. package/dist/cjs/remoteconfig/country.js +73 -0
  86. package/dist/cjs/remoteconfig/custom.d.ts +7 -7
  87. package/dist/cjs/remoteconfig/custom.js +31 -51
  88. package/dist/cjs/remoteconfig/evaluate.d.ts +3 -3
  89. package/dist/cjs/remoteconfig/evaluate.js +56 -43
  90. package/dist/cjs/remoteconfig/fetch.d.ts +16 -9
  91. package/dist/cjs/remoteconfig/fetch.js +120 -39
  92. package/dist/cjs/remoteconfig/index.d.ts +19 -8
  93. package/dist/cjs/remoteconfig/index.js +81 -39
  94. package/dist/cjs/remoteconfig/store.d.ts +15 -7
  95. package/dist/cjs/remoteconfig/store.js +68 -35
  96. package/dist/cjs/remoteconfig/tz-countries.d.ts +8 -0
  97. package/dist/cjs/remoteconfig/tz-countries.js +13 -0
  98. package/dist/{esm/core → cjs/remotelog}/callsite.d.ts +11 -4
  99. package/dist/cjs/{core → remotelog}/callsite.js +30 -7
  100. package/dist/cjs/remotelog/gate.d.ts +2 -11
  101. package/dist/cjs/remotelog/gate.js +9 -35
  102. package/dist/cjs/remotelog/index.d.ts +4 -21
  103. package/dist/cjs/remotelog/logger.d.ts +11 -17
  104. package/dist/cjs/remotelog/logger.js +31 -59
  105. package/dist/cjs/remotelog/send.js +11 -11
  106. package/dist/cjs/remotelogger/index.d.ts +12 -0
  107. package/dist/cjs/remotelogger/index.js +18 -0
  108. package/dist/cjs/scheduler.d.ts +3 -1
  109. package/dist/cjs/scheduler.js +25 -22
  110. package/dist/cjs/types.d.ts +208 -90
  111. package/dist/cjs/user/index.js +16 -7
  112. package/dist/esm/core/attempts.js +1 -1
  113. package/dist/esm/core/batch.js +2 -2
  114. package/dist/esm/core/consent.d.ts +18 -4
  115. package/dist/esm/core/consent.js +32 -17
  116. package/dist/esm/core/constants.d.ts +57 -27
  117. package/dist/esm/core/constants.js +51 -33
  118. package/dist/esm/core/db.d.ts +12 -4
  119. package/dist/esm/core/db.js +164 -35
  120. package/dist/esm/core/debug.js +1 -1
  121. package/dist/esm/core/env.d.ts +0 -3
  122. package/dist/esm/core/env.js +2 -9
  123. package/dist/esm/core/framework-id.d.ts +1 -1
  124. package/dist/esm/core/framework-id.js +3 -3
  125. package/dist/esm/core/guard.d.ts +9 -0
  126. package/dist/esm/core/guard.js +27 -14
  127. package/dist/esm/core/hooks.d.ts +7 -4
  128. package/dist/esm/core/hooks.js +3 -3
  129. package/dist/esm/core/locks.d.ts +9 -0
  130. package/dist/esm/core/locks.js +20 -0
  131. package/dist/esm/core/logger.d.ts +3 -4
  132. package/dist/esm/core/logger.js +4 -40
  133. package/dist/esm/core/state.d.ts +9 -6
  134. package/dist/esm/core/state.js +3 -5
  135. package/dist/esm/core/storage.d.ts +20 -5
  136. package/dist/esm/core/storage.js +113 -21
  137. package/dist/esm/core/stylesheet.d.ts +8 -0
  138. package/dist/esm/core/stylesheet.js +27 -0
  139. package/dist/esm/core/transport.d.ts +2 -0
  140. package/dist/esm/core/transport.js +30 -19
  141. package/dist/esm/core/utils.js +1 -1
  142. package/dist/esm/core/validate.js +2 -2
  143. package/dist/esm/device/appversion.d.ts +10 -6
  144. package/dist/esm/device/appversion.js +37 -4
  145. package/dist/esm/device/index.d.ts +28 -2
  146. package/dist/esm/device/index.js +313 -49
  147. package/dist/esm/engagement/api-rules.d.ts +32 -67
  148. package/dist/esm/engagement/api-rules.js +143 -155
  149. package/dist/esm/engagement/auto-api.js +3 -3
  150. package/dist/esm/engagement/auto-screen.d.ts +2 -0
  151. package/dist/esm/engagement/auto-screen.js +67 -4
  152. package/dist/esm/engagement/defined-events.js +1 -1
  153. package/dist/esm/engagement/send.js +12 -3
  154. package/dist/esm/engagement/session.d.ts +29 -3
  155. package/dist/esm/engagement/session.js +251 -30
  156. package/dist/esm/engagement/track.d.ts +4 -4
  157. package/dist/esm/engagement/track.js +65 -37
  158. package/dist/esm/errors/send.js +2 -2
  159. package/dist/esm/errors/track.d.ts +2 -1
  160. package/dist/esm/errors/track.js +49 -7
  161. package/dist/esm/feedback/controls.d.ts +12 -0
  162. package/dist/esm/feedback/controls.js +103 -26
  163. package/dist/esm/feedback/index.d.ts +8 -7
  164. package/dist/esm/feedback/index.js +34 -13
  165. package/dist/esm/feedback/logs.d.ts +13 -11
  166. package/dist/esm/feedback/logs.js +59 -30
  167. package/dist/esm/feedback/quartz.d.ts +18 -0
  168. package/dist/esm/feedback/quartz.js +99 -0
  169. package/dist/esm/feedback/send.d.ts +5 -2
  170. package/dist/esm/feedback/send.js +31 -31
  171. package/dist/esm/feedback/styles.d.ts +10 -0
  172. package/dist/esm/feedback/styles.js +4 -0
  173. package/dist/esm/feedback/template.d.ts +1 -1
  174. package/dist/esm/feedback/template.js +20 -12
  175. package/dist/esm/feedback/ui.d.ts +21 -6
  176. package/dist/esm/feedback/ui.js +283 -71
  177. package/dist/esm/heatmap/send.d.ts +2 -0
  178. package/dist/esm/heatmap/send.js +3 -5
  179. package/dist/esm/heatmap/track.d.ts +1 -1
  180. package/dist/esm/heatmap/track.js +87 -16
  181. package/dist/esm/index.d.ts +16 -63
  182. package/dist/esm/index.js +148 -83
  183. package/dist/esm/lifecycle.d.ts +21 -3
  184. package/dist/esm/lifecycle.js +359 -98
  185. package/dist/esm/remoteconfig/country.d.ts +4 -0
  186. package/dist/esm/remoteconfig/country.js +70 -0
  187. package/dist/esm/remoteconfig/custom.d.ts +7 -7
  188. package/dist/esm/remoteconfig/custom.js +32 -52
  189. package/dist/esm/remoteconfig/evaluate.d.ts +3 -3
  190. package/dist/esm/remoteconfig/evaluate.js +57 -44
  191. package/dist/esm/remoteconfig/fetch.d.ts +16 -9
  192. package/dist/esm/remoteconfig/fetch.js +120 -39
  193. package/dist/esm/remoteconfig/index.d.ts +19 -8
  194. package/dist/esm/remoteconfig/index.js +82 -40
  195. package/dist/esm/remoteconfig/store.d.ts +15 -7
  196. package/dist/esm/remoteconfig/store.js +68 -36
  197. package/dist/esm/remoteconfig/tz-countries.d.ts +8 -0
  198. package/dist/esm/remoteconfig/tz-countries.js +11 -0
  199. package/dist/{cjs/core → esm/remotelog}/callsite.d.ts +11 -4
  200. package/dist/esm/{core → remotelog}/callsite.js +30 -8
  201. package/dist/esm/remotelog/gate.d.ts +2 -11
  202. package/dist/esm/remotelog/gate.js +10 -32
  203. package/dist/esm/remotelog/index.d.ts +4 -21
  204. package/dist/esm/remotelog/logger.d.ts +11 -17
  205. package/dist/esm/remotelog/logger.js +33 -61
  206. package/dist/esm/remotelog/send.js +13 -13
  207. package/dist/esm/remotelogger/index.d.ts +12 -0
  208. package/dist/esm/remotelogger/index.js +13 -0
  209. package/dist/esm/scheduler.d.ts +3 -1
  210. package/dist/esm/scheduler.js +26 -24
  211. package/dist/esm/types.d.ts +208 -90
  212. package/dist/esm/user/index.js +18 -8
  213. package/dist/feedback.esm.min.js +2 -2
  214. package/dist/feedback.esm.min.js.map +1 -1
  215. package/dist/remoteconfig.esm.min.js +3 -0
  216. package/dist/remoteconfig.esm.min.js.map +1 -0
  217. package/dist/remotelogger.esm.min.js +3 -0
  218. package/dist/remotelogger.esm.min.js.map +1 -0
  219. package/package.json +16 -17
  220. package/dist/chunks/batch-BU_mTpm1.min.js +0 -3
  221. package/dist/chunks/batch-BU_mTpm1.min.js.map +0 -1
  222. package/dist/chunks/logs-Bea5zUW_.min.js +0 -3
  223. package/dist/chunks/logs-Bea5zUW_.min.js.map +0 -1
  224. package/dist/cjs/auto-init.d.ts +0 -8
  225. package/dist/cjs/auto-init.js +0 -32
  226. package/dist/cjs/heatmap/index.d.ts +0 -16
  227. package/dist/cjs/heatmap/index.js +0 -22
  228. package/dist/cjs/remotelog/index.js +0 -55
  229. package/dist/esm/auto-init.d.ts +0 -8
  230. package/dist/esm/auto-init.js +0 -29
  231. package/dist/esm/heatmap/index.d.ts +0 -16
  232. package/dist/esm/heatmap/index.js +0 -17
  233. package/dist/esm/remotelog/index.js +0 -51
  234. package/dist/heatmap.esm.min.js +0 -3
  235. package/dist/heatmap.esm.min.js.map +0 -1
  236. package/dist/style.css +0 -1
@@ -0,0 +1,4 @@
1
+ /** The ISO code of a time zone's country, '' for one with none (UTC) or unknown. */
2
+ export declare function timeZoneCountryCode(timeZone: string): string;
3
+ /** The country: the user's, else the time zone's. '' when neither says. */
4
+ export declare function deviceCountry(): string;
@@ -0,0 +1,70 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ import { _ZAP } from '../core/state.js';
3
+ import { getTimeZone } from '../core/env.js';
4
+ import { TZ_COUNTRIES } from './tz-countries.js';
5
+
6
+ /**
7
+ * The country of this device, for remote config's `country` criteria, by its English name as the
8
+ * console lists it ("India").
9
+ *
10
+ * The one AppticsUser.setUser registered comes first. Otherwise it is the country of the
11
+ * browser's time zone, which is the device clock's: Asia/Kolkata (or Chrome's Asia/Calcutta) is
12
+ * India, whatever language the browser is in. A browser has no other source short of asking for
13
+ * the user's location, which is a permission prompt. A zone shared by several countries is the
14
+ * one tzdata names for it.
15
+ */
16
+ /** Zone -> ISO code, unpacked on first use. */
17
+ var byZone = null;
18
+ function zones() {
19
+ if (byZone !== null) {
20
+ return byZone;
21
+ }
22
+ var out = {};
23
+ TZ_COUNTRIES.split(';').forEach(function (entry) {
24
+ var colon = entry.indexOf(':'); // no i18n
25
+ var code = entry.slice(0, colon);
26
+ entry.slice(colon + 1).split('|').forEach(function (group) {
27
+ // "Area/City,City", or bare names with no area ("Cuba,Egypt")
28
+ var slash = group.indexOf('/'); // no i18n
29
+ var area = slash === -1 ? '' : group.slice(0, slash + 1); // no i18n
30
+ group.slice(area.length).split(',').forEach(function (city) {
31
+ out[area + city] = code;
32
+ });
33
+ });
34
+ });
35
+ byZone = out;
36
+ return out;
37
+ }
38
+ /** The ISO code of a time zone's country, '' for one with none (UTC) or unknown. */
39
+ function timeZoneCountryCode(timeZone) {
40
+ var all = zones();
41
+ return Object.prototype.hasOwnProperty.call(all, timeZone) ? all[timeZone] : ''; // no i18n
42
+ }
43
+ /** IN -> India, in English; the code itself where the browser has no region names. */
44
+ function regionName(code) {
45
+ try {
46
+ var names = new Intl.DisplayNames(['en'], { type: 'region' }); // no i18n
47
+ return names.of(code) || code;
48
+ }
49
+ catch (err) {
50
+ return code;
51
+ }
52
+ }
53
+ /** The country: the user's, else the time zone's. '' when neither says. */
54
+ function deviceCountry() {
55
+ var named = String(_ZAP._user_info.country || '').trim(); // no i18n
56
+ if (named !== '') {
57
+ return named;
58
+ }
59
+ var timeZone = ''; // no i18n
60
+ try {
61
+ timeZone = String(getTimeZone() || ''); // no i18n
62
+ }
63
+ catch (err) {
64
+ timeZone = ''; // no i18n
65
+ }
66
+ var code = timeZoneCountryCode(timeZone);
67
+ return code === '' ? '' : regionName(code); // no i18n
68
+ }
69
+
70
+ export { deviceCountry, timeZoneCountryCode };
@@ -1,10 +1,10 @@
1
- /** The value set for a custom criteria key, or undefined when none is. */
2
- export declare function customConditionValue(key: string): string | undefined;
1
+ /** The values set for a condition, by its name; empty when none are. */
2
+ export declare function customConditionValues(conditionname: string): string[];
3
3
  /**
4
- * Sets what this device is for a custom criteria, or removes it with an empty value. Re-applies
5
- * the stored rules as soon as storage is ready, so the next read sees the new result without a
6
- * fetch.
4
+ * Sets what this device is for a custom condition, by its name, as comma separated values; an
5
+ * empty value removes it. Re-applies the stored rules once storage is ready, so the next read sees
6
+ * the new result without a fetch.
7
7
  */
8
- export declare function setCustomConditionValue(key: string, value: string | number | boolean | null | undefined): void;
9
- /** reset(): forgets the values set on this page; the stored ones go with the rest of storage. */
8
+ export declare function setCustomConditionValue(conditionname: string, value: string | number | boolean | null | undefined): void;
9
+ /** reset(): forgets the values set on this page. */
10
10
  export declare function clearCustomConditionValues(): void;
@@ -1,74 +1,54 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
2
- import { user_defaults, storageReady } from '../core/storage.js';
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ import { storageReady } from '../core/storage.js';
3
3
  import { Console } from '../core/logger.js';
4
4
  import { reresolve } from './store.js';
5
5
 
6
6
  /**
7
- * Custom condition values, as Android's AppticsRemoteConfig.setCustomConditionValue: the app says
8
- * what this device is for a custom criteria the console defines (a condition key with a list of
9
- * values), and a condition on that key matches when the value set here is one of the listed ones.
7
+ * Custom condition values: a console condition on the custom criteria (`custom_sdk_value`) is
8
+ * answered by what the app says this device is for that condition, by the condition's name:
10
9
  *
11
- * AppticsRemoteConfig.setCustomConditionValue('plan_tier', 'gold');
10
+ * AppticsRemoteConfig.setCustomConditionValue('is_custom', 'custom_color');
11
+ * AppticsRemoteConfig.setCustomConditionValue('is_custom', 'gold,platinum'); // several
12
12
  *
13
- * The rules are evaluated on the device, so the values have to be here on the next visit too:
14
- * they are stored, and a value set on this page wins over a stored one. Setting one before
15
- * storage has loaded — before init(), say — is kept in memory and saved once it has.
16
- *
17
- * Assumed wire format, until the server confirms it: a custom criteria arrives with the custom
18
- * key as its `key` and operator 1 ("is one of"), the same shape as the built-in criteria. A
19
- * different shape fails closed — the condition does not match and the default is used.
13
+ * The condition matches when one of the comma separated values is one of the values it lists.
14
+ * Values are for this page: an app sets them as it starts, as it would any other app state.
20
15
  */
21
- const STORE_KEY = 'remoteconfig_custom'; // no i18n
22
- /** This page's values; null marks a key removed here, so a stored value no longer counts. */
23
16
  var mine = {};
24
- function stored() {
25
- var saved = user_defaults.item(STORE_KEY);
26
- return saved && typeof saved === 'object' ? saved : {}; // no i18n
27
- }
28
- /** The value set for a custom criteria key, or undefined when none is. */
29
- function customConditionValue(key) {
30
- if (Object.prototype.hasOwnProperty.call(mine, key)) {
31
- var here = mine[key];
32
- return here === null ? undefined : here;
33
- }
34
- var saved = stored();
35
- return Object.prototype.hasOwnProperty.call(saved, key) ? saved[key] : undefined;
17
+ /** The values set for a condition, by its name; empty when none are. */
18
+ function customConditionValues(conditionname) {
19
+ var name = String(conditionname || '').trim(); // no i18n
20
+ return Object.prototype.hasOwnProperty.call(mine, name) ? mine[name] : [];
36
21
  }
37
22
  /**
38
- * Sets what this device is for a custom criteria, or removes it with an empty value. Re-applies
39
- * the stored rules as soon as storage is ready, so the next read sees the new result without a
40
- * fetch.
23
+ * Sets what this device is for a custom condition, by its name, as comma separated values; an
24
+ * empty value removes it. Re-applies the stored rules once storage is ready, so the next read sees
25
+ * the new result without a fetch.
41
26
  */
42
- function setCustomConditionValue(key, value) {
43
- var name = typeof key === 'string' ? key.trim() : ''; // no i18n
27
+ function setCustomConditionValue(conditionname, value) {
28
+ var name = typeof conditionname === 'string' ? conditionname.trim() : ''; // no i18n
44
29
  if (name === '') { // no i18n
45
- Console.warn('AppticsRemoteConfig.setCustomConditionValue: a condition key is required'); // no i18n
30
+ Console.warn('AppticsRemoteConfig.setCustomConditionValue: a condition name is required'); // no i18n
46
31
  return;
47
32
  }
48
- var text = value === null || value === undefined ? '' : String(value).trim(); // no i18n
49
- mine[name] = text === '' ? null : text; // no i18n
33
+ var values = (value === null || value === undefined ? '' : String(value)).split(',') // no i18n
34
+ .map(function (one) { return one.trim(); })
35
+ .filter(function (one, i, all) { return one !== '' && all.indexOf(one) === i; }); // no i18n
36
+ if (values.length === 0) {
37
+ delete mine[name];
38
+ }
39
+ else {
40
+ mine[name] = values;
41
+ }
50
42
  storageReady().then(function (backend) {
51
- if (!backend) {
52
- return;
53
- }
54
- var saved = stored();
55
- Object.keys(mine).forEach(function (one) {
56
- var here = mine[one];
57
- if (here === null || here === undefined) {
58
- delete saved[one];
59
- }
60
- else {
61
- saved[one] = here;
62
- }
63
- });
64
- user_defaults.add(STORE_KEY, saved);
65
43
  // only once storage has loaded: re-resolving before it would read an empty rule set and keep it
66
- reresolve();
44
+ if (backend) {
45
+ reresolve();
46
+ }
67
47
  });
68
48
  }
69
- /** reset(): forgets the values set on this page; the stored ones go with the rest of storage. */
49
+ /** reset(): forgets the values set on this page. */
70
50
  function clearCustomConditionValues() {
71
51
  mine = {};
72
52
  }
73
53
 
74
- export { clearCustomConditionValues, customConditionValue, setCustomConditionValue };
54
+ export { clearCustomConditionValues, customConditionValues, setCustomConditionValue };
@@ -10,10 +10,10 @@ export declare function conditionMatches(condition: Dict): boolean;
10
10
  /**
11
11
  * The value of one parameter on this device, as the string the server stores it as.
12
12
  *
13
- * `byId` is every condition the answer carried, keyed by its id — the mapping on the parameter
14
- * names a condition but does not repeat its criteria.
13
+ * `conditions` is `all_condition` as the server sent it: its order is the order they are tried
14
+ * in. The parameter's own `conditions` say which of them apply to it, and with what value.
15
15
  */
16
- export declare function resolve(parameter: Dict, byId: Record<string, Dict>): string;
16
+ export declare function resolve(parameter: Dict, conditions: Dict[]): string;
17
17
  /**
18
18
  * Every parameter resolved against this device, as a flat name -> value map.
19
19
  *
@@ -1,8 +1,9 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  import { Console } from '../core/logger.js';
3
3
  import { _ZAP } from '../core/state.js';
4
4
  import { isEmpty } from '../core/utils.js';
5
- import { customConditionValue } from './custom.js';
5
+ import { customConditionValues } from './custom.js';
6
+ import { deviceCountry } from './country.js';
6
7
 
7
8
  /**
8
9
  * Working out what a parameter is worth on this device.
@@ -11,11 +12,17 @@ import { customConditionValue } from './custom.js';
11
12
  * condition with its criteria, and the mapping between them. Resolving it here rather than on
12
13
  * the server is what lets a value be read with no network at all on the next visit.
13
14
  *
14
- * A parameter resolves by walking its conditions in `conditionorder` and taking the value of the
15
- * first one that matches this device. Nothing matches, or nothing is mapped: the default.
15
+ * A parameter resolves by walking the conditions in the order of `all_condition`, the console's
16
+ * own order, and taking the value the parameter maps to the first one that both applies to it and
17
+ * matches this device. A condition matches when every one of its criteria does. Nothing matches,
18
+ * or nothing is mapped: the parameter's default value.
19
+ *
20
+ * Criteria are answered from what the browser knows about itself (app version, device type,
21
+ * country...), except a custom one (`custom_sdk_value`): that is answered by what the app set with
22
+ * setCustomConditionValue(conditionname, 'a,b'), and matches when one of those values is listed.
16
23
  *
17
24
  * Everything fails closed. An operator we do not recognise, a criteria key we cannot answer, a
18
- * condition the parameter names but the server did not send — each one means "does not match",
25
+ * condition the parameter names but the server did not send: each one means "does not match",
19
26
  * never "matches". A config system that guesses hands an app a value its author never chose, on
20
27
  * a device they cannot see, and that is far worse than falling back to the default.
21
28
  */
@@ -39,9 +46,12 @@ const FACTS = Object.freeze({
39
46
  osversion: function () { return String(_ZAP._device_info.osversion || ''); }, // no i18n
40
47
  devicetype: function () { return String(_ZAP._device_info.devicetype || ''); }, // no i18n
41
48
  language: function () { return String(navigator.language || ''); }, // no i18n
49
+ country: deviceCountry,
42
50
  customergroupid: function () { return String(_ZAP._user_info.groupid || ''); }, // no i18n
43
51
  userid: function () { return String(_ZAP._user_info.userid || ''); }, // no i18n
44
52
  });
53
+ /** The criteria key of a custom condition, answered by setCustomConditionValue. */
54
+ const CUSTOM_KEY = 'custom_sdk_value'; // no i18n
45
55
  /** Codes and keys already complained about, so one unknown rule is not a log per read. */
46
56
  var reported = {};
47
57
  function sayOnce(key, message) {
@@ -63,8 +73,8 @@ function valuesOf(criteria) {
63
73
  }
64
74
  return raw.map(function (one) { return String(one); });
65
75
  }
66
- /** Whether one criteria holds on this device. */
67
- function criteriaMatches(criteria) {
76
+ /** Whether one criteria holds on this device; `conditionname` answers a custom criteria. */
77
+ function criteriaMatches(criteria, conditionname) {
68
78
  var key = String(criteria.key || ''); // no i18n
69
79
  var operator = OPERATORS[String(criteria.status)];
70
80
  if (operator === undefined) {
@@ -72,21 +82,31 @@ function criteriaMatches(criteria) {
72
82
  + '", so conditions using it will not match'); // no i18n
73
83
  return false;
74
84
  }
85
+ var listed = valuesOf(criteria);
86
+ if (key === CUSTOM_KEY) {
87
+ var mine = customConditionValues(conditionname);
88
+ if (mine.length === 0) {
89
+ sayOnce('custom:' + conditionname, 'AppticsRemoteConfig: no value for the custom condition "' + conditionname // no i18n
90
+ + '"; set one with setCustomConditionValue, or it will not match'); // no i18n
91
+ return false;
92
+ }
93
+ // 'in': one of the values the app set is one of the listed ones
94
+ return mine.some(function (one) { return listed.indexOf(one) !== -1; });
95
+ }
75
96
  var fact = FACTS[key];
76
- // not something a browser knows about itself: a custom criteria, answered by what the app set
77
- // with setCustomConditionValue
78
- var actual = fact !== undefined ? fact() : customConditionValue(key);
79
- if (actual === undefined) {
80
- sayOnce('key:' + key, 'AppticsRemoteConfig: no value for criteria "' + key // no i18n
81
- + '"; set one with setCustomConditionValue, or conditions using it will not match'); // no i18n
97
+ if (fact === undefined) {
98
+ // not something a browser knows about itself
99
+ sayOnce('key:' + key, 'AppticsRemoteConfig: unknown criteria "' + key // no i18n
100
+ + '", so conditions using it will not match'); // no i18n
82
101
  return false;
83
102
  }
103
+ var actual = fact();
84
104
  if (actual === '') {
85
105
  return false;
86
106
  }
87
107
  // 'in': the device's value is one of the listed ones. Compared as strings because that is
88
108
  // what both sides are - '1.1' is a version, not the number 1.1
89
- return valuesOf(criteria).indexOf(actual) !== -1;
109
+ return listed.indexOf(actual) !== -1;
90
110
  }
91
111
  /**
92
112
  * Whether a condition holds: every one of its criteria must. The template requires at least one
@@ -99,43 +119,40 @@ function conditionMatches(condition) {
99
119
  return false;
100
120
  }
101
121
  for (var i = 0; i < criterias.length; i++) {
102
- if (!criteriaMatches(criterias[i])) {
122
+ if (!criteriaMatches(criterias[i], String(condition.conditionname || ''))) { // no i18n
103
123
  return false;
104
124
  }
105
125
  }
106
126
  return true;
107
127
  }
108
- /** The conditions a parameter names, in the order the console put them in. */
109
- function orderedConditions(parameter) {
110
- var mapped = parameter.conditions;
111
- if (!Array.isArray(mapped)) {
112
- return [];
113
- }
114
- return mapped.slice().sort(function (a, b) {
115
- return Number(a.conditionorder || 0) - Number(b.conditionorder || 0); // no i18n
116
- });
117
- }
118
128
  /**
119
129
  * The value of one parameter on this device, as the string the server stores it as.
120
130
  *
121
- * `byId` is every condition the answer carried, keyed by its id — the mapping on the parameter
122
- * names a condition but does not repeat its criteria.
131
+ * `conditions` is `all_condition` as the server sent it: its order is the order they are tried
132
+ * in. The parameter's own `conditions` say which of them apply to it, and with what value.
123
133
  */
124
- function resolve(parameter, byId) {
125
- var mapped = orderedConditions(parameter);
126
- for (var i = 0; i < mapped.length; i++) {
127
- var link = mapped[i];
128
- var condition = byId[String(link.conditionid)];
129
- if (condition === undefined) {
130
- // the parameter points at a condition the answer did not include
131
- sayOnce('missing:' + link.conditionid, 'AppticsRemoteConfig: parameter "' + parameter.paramname // no i18n
132
- + '" uses condition ' + link.conditionid + ', which the server did not send'); // no i18n
133
- continue;
134
- }
135
- if (conditionMatches(condition)) {
134
+ function resolve(parameter, conditions) {
135
+ var links = {};
136
+ (Array.isArray(parameter.conditions) ? parameter.conditions : []).forEach(function (link) {
137
+ links[String(link.conditionid)] = link;
138
+ });
139
+ var sent = {};
140
+ for (var i = 0; i < conditions.length; i++) {
141
+ var condition = conditions[i];
142
+ var id = String(condition.conditionid);
143
+ sent[id] = true;
144
+ var link = links[id];
145
+ if (link !== undefined && conditionMatches(condition)) {
136
146
  return String(link.value === undefined || link.value === null ? '' : link.value);
137
147
  }
138
148
  }
149
+ Object.keys(links).forEach(function (id) {
150
+ if (!sent[id]) {
151
+ // the parameter points at a condition the answer did not include
152
+ sayOnce('missing:' + id, 'AppticsRemoteConfig: parameter "' + parameter.paramname // no i18n
153
+ + '" uses condition ' + id + ', which the server did not send'); // no i18n
154
+ }
155
+ });
139
156
  return String(parameter.defaultvalue === undefined || parameter.defaultvalue === null ? '' : parameter.defaultvalue);
140
157
  }
141
158
  /**
@@ -149,16 +166,12 @@ function resolveAll(remoteconfig) {
149
166
  var out = {};
150
167
  var parameters = Array.isArray(remoteconfig.all_parameter) ? remoteconfig.all_parameter : [];
151
168
  var conditions = Array.isArray(remoteconfig.all_condition) ? remoteconfig.all_condition : [];
152
- var byId = {};
153
- conditions.forEach(function (condition) {
154
- byId[String(condition.conditionid)] = condition;
155
- });
156
169
  parameters.forEach(function (parameter) {
157
170
  var name = String(parameter.paramname || ''); // no i18n
158
171
  if (name === '') {
159
172
  return;
160
173
  }
161
- out[name] = resolve(parameter, byId);
174
+ out[name] = resolve(parameter, conditions);
162
175
  });
163
176
  return out;
164
177
  }
@@ -1,22 +1,29 @@
1
1
  /**
2
- * Asks for the rule set, if anything has changed since the last one.
2
+ * Asks for the rule set: the whole of it with flagtime 0 on the first fetch of a page load, then
3
+ * only what changed since the last answered request, which is merged into what is stored.
3
4
  *
4
- * Resolves with the parameters as they stand afterwards, whether or not the answer carried a new
5
- * rule set — an answer with no `remoteconfig` block means nothing has changed, which is the
6
- * normal case and not a failure.
5
+ * Resolves with the answer, whether or not it carried a rule set — a later answer with no
6
+ * `remoteconfig` block means nothing has changed, which is the normal case and not a failure.
7
7
  *
8
- * A second caller joins the first rather than making another request.
8
+ * With `whole`, a cold fetch: flagtime 0 whatever this page has fetched already, and the answer
9
+ * replaces the stored set as the first fetch of a page load does.
10
+ *
11
+ * A second caller joins the first rather than making another request. A cold fetch joins one
12
+ * only when it asked with flagtime 0 too, and otherwise asks once it has answered.
9
13
  */
10
- export declare function fetchRemoteConfig(): Promise<Record<string, unknown>>;
14
+ export declare function fetchRemoteConfig(whole?: boolean): Promise<Record<string, unknown>>;
11
15
  /**
12
16
  * reset(): forgets the rule set, its values and what the server last reported, and disowns a
13
17
  * request still in flight, whose answer would otherwise put the old rule set back.
14
18
  */
15
19
  export declare function resetRemoteConfig(): void;
16
20
  /**
17
- * Makes sure the values are this page's own: from a fetch that just succeeded, or one within
18
- * CACHE_MS. Resolves true when they are, false when the fetch failed, could not be made, or was
19
- * past the coldFetch limit — the caller then decides whether stored values will do. Never rejects.
21
+ * Makes sure the values are this page's own: from a fetch on this page that succeeded, kept up to
22
+ * date by the polling after it. With `coldFetch`, a fetch with flagtime 0 now, whatever this page
23
+ * already has, whose answer replaces what is stored: at most COLD_LIMIT a minute, and one past
24
+ * that answers from what this page has. Resolves true when they are, false when the
25
+ * fetch failed or could not be made — the caller then decides whether stored values will do.
26
+ * Never rejects.
20
27
  *
21
28
  * Waits for start-up and for the device to be registered, which a first visit is still doing
22
29
  * when ready() resolves: getupdates is refused without the device ids.