@launchdarkly/js-sdk-common 0.1.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 (227) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +25 -0
  3. package/dist/AttributeReference.d.ts +35 -0
  4. package/dist/AttributeReference.d.ts.map +1 -0
  5. package/dist/AttributeReference.js +126 -0
  6. package/dist/AttributeReference.js.map +1 -0
  7. package/dist/Context.d.ts +90 -0
  8. package/dist/Context.d.ts.map +1 -0
  9. package/dist/Context.js +385 -0
  10. package/dist/Context.js.map +1 -0
  11. package/dist/ContextFilter.d.ts +11 -0
  12. package/dist/ContextFilter.d.ts.map +1 -0
  13. package/dist/ContextFilter.js +122 -0
  14. package/dist/ContextFilter.js.map +1 -0
  15. package/dist/api/context/LDContext.d.ts +8 -0
  16. package/dist/api/context/LDContext.d.ts.map +1 -0
  17. package/dist/api/context/LDContext.js +3 -0
  18. package/dist/api/context/LDContext.js.map +1 -0
  19. package/dist/api/context/LDContextCommon.d.ts +29 -0
  20. package/dist/api/context/LDContextCommon.d.ts.map +1 -0
  21. package/dist/api/context/LDContextCommon.js +3 -0
  22. package/dist/api/context/LDContextCommon.js.map +1 -0
  23. package/dist/api/context/LDContextMeta.d.ts +52 -0
  24. package/dist/api/context/LDContextMeta.d.ts.map +1 -0
  25. package/dist/api/context/LDContextMeta.js +3 -0
  26. package/dist/api/context/LDContextMeta.js.map +1 -0
  27. package/dist/api/context/LDMultiKindContext.d.ts +46 -0
  28. package/dist/api/context/LDMultiKindContext.d.ts.map +1 -0
  29. package/dist/api/context/LDMultiKindContext.js +3 -0
  30. package/dist/api/context/LDMultiKindContext.js.map +1 -0
  31. package/dist/api/context/LDSingleKindContext.d.ts +24 -0
  32. package/dist/api/context/LDSingleKindContext.d.ts.map +1 -0
  33. package/dist/api/context/LDSingleKindContext.js +3 -0
  34. package/dist/api/context/LDSingleKindContext.js.map +1 -0
  35. package/dist/api/context/LDUser.d.ts +66 -0
  36. package/dist/api/context/LDUser.d.ts.map +1 -0
  37. package/dist/api/context/LDUser.js +3 -0
  38. package/dist/api/context/LDUser.js.map +1 -0
  39. package/dist/api/context/index.d.ts +7 -0
  40. package/dist/api/context/index.d.ts.map +1 -0
  41. package/dist/api/context/index.js +23 -0
  42. package/dist/api/context/index.js.map +1 -0
  43. package/dist/api/data/LDEvaluationDetail.d.ts +27 -0
  44. package/dist/api/data/LDEvaluationDetail.d.ts.map +1 -0
  45. package/dist/api/data/LDEvaluationDetail.js +3 -0
  46. package/dist/api/data/LDEvaluationDetail.js.map +1 -0
  47. package/dist/api/data/LDEvaluationReason.d.ts +57 -0
  48. package/dist/api/data/LDEvaluationReason.d.ts.map +1 -0
  49. package/dist/api/data/LDEvaluationReason.js +3 -0
  50. package/dist/api/data/LDEvaluationReason.js.map +1 -0
  51. package/dist/api/data/LDFlagSet.d.ts +8 -0
  52. package/dist/api/data/LDFlagSet.d.ts.map +1 -0
  53. package/dist/api/data/LDFlagSet.js +3 -0
  54. package/dist/api/data/LDFlagSet.js.map +1 -0
  55. package/dist/api/data/LDFlagValue.d.ts +7 -0
  56. package/dist/api/data/LDFlagValue.d.ts.map +1 -0
  57. package/dist/api/data/LDFlagValue.js +3 -0
  58. package/dist/api/data/LDFlagValue.js.map +1 -0
  59. package/dist/api/data/index.d.ts +5 -0
  60. package/dist/api/data/index.d.ts.map +1 -0
  61. package/dist/api/data/index.js +21 -0
  62. package/dist/api/data/index.js.map +1 -0
  63. package/dist/api/index.d.ts +7 -0
  64. package/dist/api/index.d.ts.map +1 -0
  65. package/dist/api/index.js +24 -0
  66. package/dist/api/index.js.map +1 -0
  67. package/dist/api/logging/BasicLoggerOptions.d.ts +43 -0
  68. package/dist/api/logging/BasicLoggerOptions.d.ts.map +1 -0
  69. package/dist/api/logging/BasicLoggerOptions.js +3 -0
  70. package/dist/api/logging/BasicLoggerOptions.js.map +1 -0
  71. package/dist/api/logging/LDLogLevel.d.ts +10 -0
  72. package/dist/api/logging/LDLogLevel.d.ts.map +1 -0
  73. package/dist/api/logging/LDLogLevel.js +3 -0
  74. package/dist/api/logging/LDLogLevel.js.map +1 -0
  75. package/dist/api/logging/LDLogger.d.ts +47 -0
  76. package/dist/api/logging/LDLogger.d.ts.map +1 -0
  77. package/dist/api/logging/LDLogger.js +3 -0
  78. package/dist/api/logging/LDLogger.js.map +1 -0
  79. package/dist/api/logging/index.d.ts +4 -0
  80. package/dist/api/logging/index.d.ts.map +1 -0
  81. package/dist/api/logging/index.js +20 -0
  82. package/dist/api/logging/index.js.map +1 -0
  83. package/dist/api/options/LDClientContext.d.ts +43 -0
  84. package/dist/api/options/LDClientContext.d.ts.map +1 -0
  85. package/dist/api/options/LDClientContext.js +3 -0
  86. package/dist/api/options/LDClientContext.js.map +1 -0
  87. package/dist/api/options/index.d.ts +3 -0
  88. package/dist/api/options/index.d.ts.map +1 -0
  89. package/dist/api/options/index.js +3 -0
  90. package/dist/api/options/index.js.map +1 -0
  91. package/dist/api/platform/Crypto.d.ts +31 -0
  92. package/dist/api/platform/Crypto.d.ts.map +1 -0
  93. package/dist/api/platform/Crypto.js +3 -0
  94. package/dist/api/platform/Crypto.js.map +1 -0
  95. package/dist/api/platform/EventSource.d.ts +25 -0
  96. package/dist/api/platform/EventSource.d.ts.map +1 -0
  97. package/dist/api/platform/EventSource.js +3 -0
  98. package/dist/api/platform/EventSource.js.map +1 -0
  99. package/dist/api/platform/Filesystem.d.ts +40 -0
  100. package/dist/api/platform/Filesystem.d.ts.map +1 -0
  101. package/dist/api/platform/Filesystem.js +3 -0
  102. package/dist/api/platform/Filesystem.js.map +1 -0
  103. package/dist/api/platform/Info.d.ts +64 -0
  104. package/dist/api/platform/Info.d.ts.map +1 -0
  105. package/dist/api/platform/Info.js +3 -0
  106. package/dist/api/platform/Info.js.map +1 -0
  107. package/dist/api/platform/Platform.d.ts +25 -0
  108. package/dist/api/platform/Platform.d.ts.map +1 -0
  109. package/dist/api/platform/Platform.js +3 -0
  110. package/dist/api/platform/Platform.js.map +1 -0
  111. package/dist/api/platform/Requests.d.ts +75 -0
  112. package/dist/api/platform/Requests.d.ts.map +1 -0
  113. package/dist/api/platform/Requests.js +6 -0
  114. package/dist/api/platform/Requests.js.map +1 -0
  115. package/dist/api/platform/index.d.ts +7 -0
  116. package/dist/api/platform/index.d.ts.map +1 -0
  117. package/dist/api/platform/index.js +23 -0
  118. package/dist/api/platform/index.js.map +1 -0
  119. package/dist/api/subsystem/LDContextDeduplicator.d.ts +24 -0
  120. package/dist/api/subsystem/LDContextDeduplicator.d.ts.map +1 -0
  121. package/dist/api/subsystem/LDContextDeduplicator.js +3 -0
  122. package/dist/api/subsystem/LDContextDeduplicator.js.map +1 -0
  123. package/dist/api/subsystem/LDEventProcessor.d.ts +7 -0
  124. package/dist/api/subsystem/LDEventProcessor.d.ts.map +1 -0
  125. package/dist/api/subsystem/LDEventProcessor.js +3 -0
  126. package/dist/api/subsystem/LDEventProcessor.js.map +1 -0
  127. package/dist/api/subsystem/LDEventSender.d.ts +18 -0
  128. package/dist/api/subsystem/LDEventSender.d.ts.map +1 -0
  129. package/dist/api/subsystem/LDEventSender.js +15 -0
  130. package/dist/api/subsystem/LDEventSender.js.map +1 -0
  131. package/dist/api/subsystem/index.d.ts +5 -0
  132. package/dist/api/subsystem/index.d.ts.map +1 -0
  133. package/dist/api/subsystem/index.js +7 -0
  134. package/dist/api/subsystem/index.js.map +1 -0
  135. package/dist/index.d.ts +10 -0
  136. package/dist/index.d.ts.map +1 -0
  137. package/dist/index.js +29 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/internal/events/EventProcessor.d.ts +51 -0
  140. package/dist/internal/events/EventProcessor.d.ts.map +1 -0
  141. package/dist/internal/events/EventProcessor.js +214 -0
  142. package/dist/internal/events/EventProcessor.js.map +1 -0
  143. package/dist/internal/events/EventSummarizer.d.ts +2 -0
  144. package/dist/internal/events/EventSummarizer.d.ts.map +1 -0
  145. package/dist/internal/events/EventSummarizer.js +84 -0
  146. package/dist/internal/events/EventSummarizer.js.map +1 -0
  147. package/dist/internal/events/InputCustomEvent.d.ts +11 -0
  148. package/dist/internal/events/InputCustomEvent.d.ts.map +1 -0
  149. package/dist/internal/events/InputCustomEvent.js +14 -0
  150. package/dist/internal/events/InputCustomEvent.js.map +1 -0
  151. package/dist/internal/events/InputEvalEvent.d.ts +19 -0
  152. package/dist/internal/events/InputEvalEvent.d.ts.map +1 -0
  153. package/dist/internal/events/InputEvalEvent.js +35 -0
  154. package/dist/internal/events/InputEvalEvent.js.map +1 -0
  155. package/dist/internal/events/InputEvent.d.ts +6 -0
  156. package/dist/internal/events/InputEvent.d.ts.map +1 -0
  157. package/dist/internal/events/InputEvent.js +3 -0
  158. package/dist/internal/events/InputEvent.js.map +1 -0
  159. package/dist/internal/events/InputEventBase.d.ts +8 -0
  160. package/dist/internal/events/InputEventBase.d.ts.map +1 -0
  161. package/dist/internal/events/InputEventBase.js +11 -0
  162. package/dist/internal/events/InputEventBase.js.map +1 -0
  163. package/dist/internal/events/InputIdentifyEvent.d.ts +8 -0
  164. package/dist/internal/events/InputIdentifyEvent.d.ts.map +1 -0
  165. package/dist/internal/events/InputIdentifyEvent.js +11 -0
  166. package/dist/internal/events/InputIdentifyEvent.js.map +1 -0
  167. package/dist/internal/events/LDInvalidSDKKeyError.d.ts +4 -0
  168. package/dist/internal/events/LDInvalidSDKKeyError.d.ts.map +1 -0
  169. package/dist/internal/events/LDInvalidSDKKeyError.js +10 -0
  170. package/dist/internal/events/LDInvalidSDKKeyError.js.map +1 -0
  171. package/dist/internal/events/SummaryCounter.d.ts +2 -0
  172. package/dist/internal/events/SummaryCounter.d.ts.map +1 -0
  173. package/dist/internal/events/SummaryCounter.js +20 -0
  174. package/dist/internal/events/SummaryCounter.js.map +1 -0
  175. package/dist/internal/events/guards.d.ts +7 -0
  176. package/dist/internal/events/guards.d.ts.map +1 -0
  177. package/dist/internal/events/guards.js +16 -0
  178. package/dist/internal/events/guards.js.map +1 -0
  179. package/dist/internal/events/index.d.ts +7 -0
  180. package/dist/internal/events/index.d.ts.map +1 -0
  181. package/dist/internal/events/index.js +12 -0
  182. package/dist/internal/events/index.js.map +1 -0
  183. package/dist/internal/index.d.ts +2 -0
  184. package/dist/internal/index.d.ts.map +1 -0
  185. package/dist/internal/index.js +18 -0
  186. package/dist/internal/index.js.map +1 -0
  187. package/dist/logging/BasicLogger.d.ts +27 -0
  188. package/dist/logging/BasicLogger.d.ts.map +1 -0
  189. package/dist/logging/BasicLogger.js +89 -0
  190. package/dist/logging/BasicLogger.js.map +1 -0
  191. package/dist/logging/SafeLogger.d.ts +28 -0
  192. package/dist/logging/SafeLogger.d.ts.map +1 -0
  193. package/dist/logging/SafeLogger.js +63 -0
  194. package/dist/logging/SafeLogger.js.map +1 -0
  195. package/dist/logging/format.d.ts +2 -0
  196. package/dist/logging/format.d.ts.map +1 -0
  197. package/dist/logging/format.js +156 -0
  198. package/dist/logging/format.js.map +1 -0
  199. package/dist/logging/index.d.ts +4 -0
  200. package/dist/logging/index.d.ts.map +1 -0
  201. package/dist/logging/index.js +8 -0
  202. package/dist/logging/index.js.map +1 -0
  203. package/dist/options/ApplicationTags.d.ts +15 -0
  204. package/dist/options/ApplicationTags.d.ts.map +1 -0
  205. package/dist/options/ApplicationTags.js +57 -0
  206. package/dist/options/ApplicationTags.js.map +1 -0
  207. package/dist/options/ClientContext.d.ts +36 -0
  208. package/dist/options/ClientContext.d.ts.map +1 -0
  209. package/dist/options/ClientContext.js +19 -0
  210. package/dist/options/ClientContext.js.map +1 -0
  211. package/dist/options/OptionMessages.d.ts +14 -0
  212. package/dist/options/OptionMessages.d.ts.map +1 -0
  213. package/dist/options/OptionMessages.js +33 -0
  214. package/dist/options/OptionMessages.js.map +1 -0
  215. package/dist/options/ServiceEndpoints.d.ts +10 -0
  216. package/dist/options/ServiceEndpoints.d.ts.map +1 -0
  217. package/dist/options/ServiceEndpoints.js +17 -0
  218. package/dist/options/ServiceEndpoints.js.map +1 -0
  219. package/dist/options/index.d.ts +6 -0
  220. package/dist/options/index.d.ts.map +1 -0
  221. package/dist/options/index.js +12 -0
  222. package/dist/options/index.js.map +1 -0
  223. package/dist/validators.d.ts +84 -0
  224. package/dist/validators.d.ts.map +1 -0
  225. package/dist/validators.js +149 -0
  226. package/dist/validators.js.map +1 -0
  227. package/package.json +40 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@launchdarkly/js-sdk-common` will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
+
5
+ ## 0.1.0 (2023-03-15)
6
+
7
+ Initial prerelease version.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # LaunchDarkly SDK JavaScript Common Code
2
+
3
+ [![NPM](TODO)
4
+ ![Actions Status](TODO)
5
+ [![Documentation](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](TODO)
6
+
7
+ This project contains Typescript classes and interfaces that are applicable to client-side and server-side JavaScript SDKs.
8
+
9
+ ## Contributing
10
+
11
+ See [Contributing](../CONTRIBUTING.md).
12
+
13
+ ## About LaunchDarkly
14
+
15
+ - LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
16
+ - Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
17
+ - Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
18
+ - Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
19
+ - Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
20
+ - LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
21
+ - Explore LaunchDarkly
22
+ - [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
23
+ - [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
24
+ - [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
25
+ - [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
@@ -0,0 +1,35 @@
1
+ import { LDContextCommon } from './api/context/LDContextCommon';
2
+ export default class AttributeReference {
3
+ readonly isValid: boolean;
4
+ /**
5
+ * When redacting attributes this name can be directly added to the list of
6
+ * redactions.
7
+ */
8
+ readonly redactionName: string;
9
+ /**
10
+ * For use as invalid references when deserializing Flag/Segment data.
11
+ */
12
+ static readonly invalidReference: AttributeReference;
13
+ private readonly components;
14
+ /**
15
+ * Take an attribute reference string, or literal string, and produce
16
+ * an attribute reference.
17
+ *
18
+ * Legacy user objects would have been created with names not
19
+ * references. So, in that case, we need to use them as a component
20
+ * without escaping them.
21
+ *
22
+ * e.g. A user could contain a custom attribute of `/a` which would
23
+ * become the literal `a` if treated as a reference. Which would cause
24
+ * it to no longer be redacted.
25
+ * @param refOrLiteral The attribute reference string or literal string.
26
+ * @param literal it true the value should be treated as a literal.
27
+ */
28
+ constructor(refOrLiteral: string, literal?: boolean);
29
+ get(target: LDContextCommon): LDContextCommon | undefined;
30
+ getComponent(depth: number): string;
31
+ get depth(): number;
32
+ get isKind(): boolean;
33
+ compare(other: AttributeReference): boolean;
34
+ }
35
+ //# sourceMappingURL=AttributeReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeReference.d.ts","sourceRoot":"","sources":["../src/AttributeReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAiChE,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC,SAAgB,OAAO,UAAC;IAExB;;;OAGG;IACH,SAAgB,aAAa,SAAC;IAE9B;;OAEG;IACH,gBAAuB,gBAAgB,qBAA8B;IAErE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IAEtC;;;;;;;;;;;;;OAaG;gBACgB,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe;IAkC1D,GAAG,CAAC,MAAM,EAAE,eAAe;IA+B3B,YAAY,CAAC,KAAK,EAAE,MAAM;IAIjC,IAAW,KAAK,WAEf;IAED,IAAW,MAAM,IAAI,OAAO,CAE3B;IAEM,OAAO,CAAC,KAAK,EAAE,kBAAkB;CAMzC"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Converts a literal to a ref string.
5
+ * @param value
6
+ * @returns An escaped literal which can be used as a ref.
7
+ */
8
+ function toRefString(value) {
9
+ return `/${value.replace(/~/g, '~0').replace(/\//g, '~1')}`;
10
+ }
11
+ /**
12
+ * Produce a literal from a ref component.
13
+ * @param ref
14
+ * @returns A literal version of the ref.
15
+ */
16
+ function unescape(ref) {
17
+ return ref.indexOf('~') ? ref.replace(/~1/g, '/').replace(/~0/g, '~') : ref;
18
+ }
19
+ function getComponents(reference) {
20
+ const referenceWithoutPrefix = reference.startsWith('/') ? reference.substring(1) : reference;
21
+ return referenceWithoutPrefix.split('/').map((component) => unescape(component));
22
+ }
23
+ function isLiteral(reference) {
24
+ return !reference.startsWith('/');
25
+ }
26
+ function validate(reference) {
27
+ return !reference.match(/\/\/|(^\/.*~[^0|^1])|~$/);
28
+ }
29
+ class AttributeReference {
30
+ /**
31
+ * Take an attribute reference string, or literal string, and produce
32
+ * an attribute reference.
33
+ *
34
+ * Legacy user objects would have been created with names not
35
+ * references. So, in that case, we need to use them as a component
36
+ * without escaping them.
37
+ *
38
+ * e.g. A user could contain a custom attribute of `/a` which would
39
+ * become the literal `a` if treated as a reference. Which would cause
40
+ * it to no longer be redacted.
41
+ * @param refOrLiteral The attribute reference string or literal string.
42
+ * @param literal it true the value should be treated as a literal.
43
+ */
44
+ constructor(refOrLiteral, literal = false) {
45
+ if (!literal) {
46
+ this.redactionName = refOrLiteral;
47
+ if (refOrLiteral === '' || refOrLiteral === '/' || !validate(refOrLiteral)) {
48
+ this.isValid = false;
49
+ this.components = [];
50
+ return;
51
+ }
52
+ if (isLiteral(refOrLiteral)) {
53
+ this.components = [refOrLiteral];
54
+ }
55
+ else if (refOrLiteral.indexOf('/', 1) < 0) {
56
+ this.components = [unescape(refOrLiteral.slice(1))];
57
+ }
58
+ else {
59
+ this.components = getComponents(refOrLiteral);
60
+ }
61
+ // The items inside of '_meta' are not intended to be addressable.
62
+ // Excluding it as a valid reference means that we can make it non-addressable
63
+ // without having to copy all the attributes out of the context object
64
+ // provided by the user.
65
+ if (this.components[0] === '_meta') {
66
+ this.isValid = false;
67
+ }
68
+ else {
69
+ this.isValid = true;
70
+ }
71
+ }
72
+ else {
73
+ const literalVal = refOrLiteral;
74
+ this.components = [literalVal];
75
+ this.isValid = literalVal !== '';
76
+ // Literals which start with '/' need escaped to prevent ambiguity.
77
+ this.redactionName = literalVal.startsWith('/') ? toRefString(literalVal) : literalVal;
78
+ }
79
+ }
80
+ get(target) {
81
+ const { components, isValid } = this;
82
+ if (!isValid) {
83
+ return undefined;
84
+ }
85
+ let current = target;
86
+ // This doesn't use a range based for loops, because those use generators.
87
+ // See `no-restricted-syntax`.
88
+ // It also doesn't use a collection method because this logic is more
89
+ // straightforward with a loop.
90
+ for (let index = 0; index < components.length; index += 1) {
91
+ const component = components[index];
92
+ if (current !== null &&
93
+ current !== undefined &&
94
+ // See https://eslint.org/docs/rules/no-prototype-builtins
95
+ Object.prototype.hasOwnProperty.call(current, component) &&
96
+ typeof current === 'object' &&
97
+ // We do not want to allow indexing into an array.
98
+ !Array.isArray(current)) {
99
+ current = current[component];
100
+ }
101
+ else {
102
+ return undefined;
103
+ }
104
+ }
105
+ return current;
106
+ }
107
+ getComponent(depth) {
108
+ return this.components[depth];
109
+ }
110
+ get depth() {
111
+ return this.components.length;
112
+ }
113
+ get isKind() {
114
+ return this.components.length === 1 && this.components[0] === 'kind';
115
+ }
116
+ compare(other) {
117
+ return (this.depth === other.depth &&
118
+ this.components.every((value, index) => value === other.getComponent(index)));
119
+ }
120
+ }
121
+ exports.default = AttributeReference;
122
+ /**
123
+ * For use as invalid references when deserializing Flag/Segment data.
124
+ */
125
+ AttributeReference.invalidReference = new AttributeReference('');
126
+ //# sourceMappingURL=AttributeReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeReference.js","sourceRoot":"","sources":["../src/AttributeReference.ts"],"names":[],"mappings":";;AAEA;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAa;IAChC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9E,CAAC;AAED,SAAS,aAAa,CAAC,SAAiB;IACtC,MAAM,sBAAsB,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9F,OAAO,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB;IAClC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC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,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;IACvE,CAAC;IAEM,OAAO,CAAC,KAAyB;QACtC,OAAO,CACL,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;YAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAC7E,CAAC;IACJ,CAAC;;AAhHH,qCAiHC;AAxGC;;GAEG;AACoB,mCAAgB,GAAG,IAAI,kBAAkB,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,90 @@
1
+ import { LDContextCommon } from './api/context';
2
+ import { LDContext } from './api/context/LDContext';
3
+ import AttributeReference from './AttributeReference';
4
+ /**
5
+ * Container for a context/contexts. Because contexts come from external code
6
+ * they must be thoroughly validated and then formed to comply with
7
+ * the type system.
8
+ */
9
+ export default class Context {
10
+ private context?;
11
+ private isMulti;
12
+ private isUser;
13
+ private wasLegacy;
14
+ private contexts;
15
+ private privateAttributeReferences?;
16
+ readonly kind: string;
17
+ /**
18
+ * Is this a valid context. If a valid context cannot be created, then this flag will be true.
19
+ * The validity of a context should be tested before it is used.
20
+ */
21
+ readonly valid: boolean;
22
+ readonly message?: string;
23
+ static readonly userKind: string;
24
+ /**
25
+ * Contexts should be created using the static factory method {@link Context.fromLDContext}.
26
+ * @param kind The kind of the context.
27
+ *
28
+ * The factory methods are static functions within the class because they access private
29
+ * implementation details, so they cannot be free functions.
30
+ */
31
+ private constructor();
32
+ private static contextForError;
33
+ private static getValueFromContext;
34
+ private contextForKind;
35
+ private static fromMultiKindContext;
36
+ private static fromSingleKindContext;
37
+ private static fromLegacyUser;
38
+ /**
39
+ * Attempt to create a {@link Context} from an {@link LDContext}.
40
+ * @param context The input context to create a Context from.
41
+ * @returns a {@link Context}, if the context was not valid, then the returned contexts `valid`
42
+ * property will be false.
43
+ */
44
+ static fromLDContext(context: LDContext): Context;
45
+ /**
46
+ * Attempt to get a value for the given context kind using the given reference.
47
+ * @param reference The reference to the value to get.
48
+ * @param kind The kind of the context to get the value for.
49
+ * @returns a value or `undefined` if one is not found.
50
+ */
51
+ valueForKind(reference: AttributeReference, kind?: string): any | undefined;
52
+ /**
53
+ * Attempt to get a key for the specified kind.
54
+ * @param kind The kind to get a key for.
55
+ * @returns The key for the specified kind, or undefined.
56
+ */
57
+ key(kind?: string): string | undefined;
58
+ /**
59
+ * True if this is a multi-kind context.
60
+ */
61
+ get isMultiKind(): boolean;
62
+ /**
63
+ * Get the canonical key for this context.
64
+ */
65
+ get canonicalKey(): string;
66
+ /**
67
+ * Get the kinds of this context.
68
+ */
69
+ get kinds(): string[];
70
+ /**
71
+ * Get the kinds, and their keys, for this context.
72
+ */
73
+ get kindsAndKeys(): Record<string, string>;
74
+ /**
75
+ * Get the attribute references.
76
+ *
77
+ * @param kind
78
+ */
79
+ privateAttributes(kind: string): AttributeReference[];
80
+ /**
81
+ * Get the underlying context objects from this context.
82
+ *
83
+ * This method is intended to be used in event generation.
84
+ *
85
+ * The returned objects should not be modified.
86
+ */
87
+ getContexts(): [string, LDContextCommon][];
88
+ get legacy(): boolean;
89
+ }
90
+ //# sourceMappingURL=Context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../src/Context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmD,eAAe,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AA+KtD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAkB;IAElC,OAAO,CAAC,OAAO,CAAkB;IAEjC,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO,CAAC,SAAS,CAAkB;IAEnC,OAAO,CAAC,QAAQ,CAAuC;IA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