capacitor-launchdarkly 0.0.0-stage → 0.1.1

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 (40) hide show
  1. package/CapacitorLaunchdarkly.podspec +20 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +32 -0
  4. package/README.md +747 -2
  5. package/android/build.gradle +68 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/Json.kt +67 -0
  8. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/LaunchDarklyClient.kt +250 -0
  9. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/LaunchDarklyPlugin.kt +148 -0
  10. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/LdConfigFactory.kt +34 -0
  11. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/StartOptions.kt +76 -0
  12. package/android/src/main/kotlin/io/github/maximbelov/launchdarkly/StoredContext.kt +47 -0
  13. package/android/src/main/res/.gitkeep +0 -0
  14. package/dist/docs.json +1174 -0
  15. package/dist/esm/definitions.d.ts +520 -0
  16. package/dist/esm/definitions.js +2 -0
  17. package/dist/esm/definitions.js.map +1 -0
  18. package/dist/esm/index.d.ts +4 -0
  19. package/dist/esm/index.js +7 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/web.d.ts +46 -0
  22. package/dist/esm/web.js +204 -0
  23. package/dist/esm/web.js.map +1 -0
  24. package/dist/plugin.cjs.js +221 -0
  25. package/dist/plugin.cjs.js.map +1 -0
  26. package/dist/plugin.js +224 -0
  27. package/dist/plugin.js.map +1 -0
  28. package/ios/Sources/LaunchDarklyPlugin/ConfigFactory.swift +29 -0
  29. package/ios/Sources/LaunchDarklyPlugin/JSONValues.swift +68 -0
  30. package/ios/Sources/LaunchDarklyPlugin/LaunchDarklyClient.swift +165 -0
  31. package/ios/Sources/LaunchDarklyPlugin/LaunchDarklyPlugin.swift +169 -0
  32. package/ios/Sources/LaunchDarklyPlugin/PrivacyInfo.xcprivacy +23 -0
  33. package/ios/Sources/LaunchDarklyPlugin/StartOptions.swift +79 -0
  34. package/ios/Sources/LaunchDarklyPlugin/StoredContext.swift +43 -0
  35. package/ios/Tests/LaunchDarklyPluginTests/BillingSafetyTests.swift +53 -0
  36. package/ios/Tests/LaunchDarklyPluginTests/JSONValuesTests.swift +67 -0
  37. package/ios/Tests/LaunchDarklyPluginTests/LaunchDarklyPluginTests.swift +37 -0
  38. package/ios/Tests/LaunchDarklyPluginTests/PluginConfigurationTests.swift +52 -0
  39. package/ios/Tests/LaunchDarklyPluginTests/StartContextTests.swift +36 -0
  40. package/package.json +105 -4
@@ -0,0 +1,47 @@
1
+ package io.github.maximbelov.launchdarkly
2
+
3
+ import android.content.SharedPreferences
4
+ import com.launchdarkly.sdk.LDContext
5
+
6
+ /** Where the context of the last `identify()` is kept between launches. */
7
+ interface ContextStore {
8
+ fun read(): String?
9
+ fun write(json: String)
10
+ fun clear()
11
+ }
12
+
13
+ /** [ContextStore] in the plugin's own preferences file, [PREFERENCES], private to the app. */
14
+ class SharedPreferencesContextStore(private val preferences: SharedPreferences) : ContextStore {
15
+ override fun read(): String? = preferences.getString(KEY, null)
16
+
17
+ override fun write(json: String) {
18
+ preferences.edit().putString(KEY, json).apply()
19
+ }
20
+
21
+ override fun clear() {
22
+ preferences.edit().remove(KEY).apply()
23
+ }
24
+
25
+ companion object {
26
+ const val PREFERENCES = "CapacitorLaunchDarkly"
27
+ const val KEY = "context"
28
+ }
29
+ }
30
+
31
+ /** A context and the JSON it was read from, which is what the plugin stores and answers in `getState()`. */
32
+ data class ContextChoice(val context: LDContext, val json: String)
33
+
34
+ object StartContext {
35
+ /**
36
+ * The context a native start-up begins with: the stored one when there is a valid one, so the app does not flip to the
37
+ * initial (usually anonymous) context for a moment and the SDK uses its flag cache for that context; else [initialContext];
38
+ * else the default anonymous context.
39
+ */
40
+ fun choose(stored: String?, initialContext: String): ContextChoice {
41
+ for (json in listOf(stored, initialContext, PluginConfig.DEFAULT_INITIAL_CONTEXT)) {
42
+ val context = Contexts.parseOrNull(json) ?: continue
43
+ return ContextChoice(context, json!!)
44
+ }
45
+ throw IllegalStateException("the default context is not valid")
46
+ }
47
+ }
File without changes