nana800-remote-config 1.0.1 → 1.2.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Andreas Linnert
3
+ Copyright (c) 2025 Bekender
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Nana800 Remote Config from NANA800.io 🍺
2
2
 
3
+ Lightweight client (no dependencies, about 2 KB minified) for the Remote Config (remote variables) feature of the NANA800.io platform.
4
+ Works in browsers, React Native, Node.js 18+ and any runtime with `fetch`.
5
+
3
6
  ### Detail Documentation
4
7
 
5
8
  [NANA800 Documentation 📊](https://nana800.gitbook.io/doc/features/remote-config-peremennye)
@@ -35,7 +38,10 @@ window.addEventListener('load', async () => {
35
38
  version: 1
36
39
  })
37
40
  console.log({isFetched})
38
-
41
+ if (!isFetched) {
42
+ console.log(nana800RemoteConfig.getLastError())
43
+ }
44
+
39
45
  const landingUrl = nana800RemoteConfig.getString('landing_url');
40
46
  console.log({landingUrl})
41
47
  })
@@ -44,7 +50,7 @@ window.addEventListener('load', async () => {
44
50
  #### For HTML/JS projects:
45
51
 
46
52
  ```html
47
- <script src="https://s3.timeweb.cloud/c14a1252-bekender-files/cdn_libraries/nana800-remote-config.cjs.js"></script>
53
+ <script src="https://cdn.jsdelivr.net/npm/nana800-remote-config@1/dist/nana800-remote-config.min.js"></script>
48
54
 
49
55
  <script>
50
56
  window.addEventListener('load', async () => {
@@ -64,11 +70,14 @@ window.addEventListener('load', async () => {
64
70
  </script>
65
71
  ```
66
72
 
73
+ The script defines the global `nana800RemoteConfig` object and the `RemoteConfigPlatform` enum.
74
+
67
75
  #### For other platforms (cURL):
68
76
 
69
77
  ```bash
70
78
  curl --location 'https://api.nana800.io/remote_config_records/fetch_user_remote_config_records' \
71
79
  --header 'Content-Type: application/json' \
80
+ --header 'x-nana-api-key: your-api-key' \
72
81
  --data '{
73
82
  "api_key": "your-api-key",
74
83
  "remote_config_project_id": "your-project-id",
@@ -78,6 +87,34 @@ curl --location 'https://api.nana800.io/remote_config_records/fetch_user_remote_
78
87
  }'
79
88
  ```
80
89
 
90
+ ## API
91
+
92
+ ### `initFetch(input, options?)`
93
+ Loads the variables for the given user and returns `true` on success.
94
+ `options.timeout_ms` sets the request timeout (10000 by default).
95
+
96
+ ### `getString(name)`, `getNumber(name)`, `getBoolean(name)`
97
+ Return the variable converted to the requested type, or `undefined` when the variable is missing, cannot be converted, or `initFetch` has not succeeded yet.
98
+ `getNumber` accepts numeric strings, `getBoolean` accepts `"true"` and `"false"`, `getString` returns objects and arrays as JSON text.
99
+
100
+ ### `getJSON<T>(name)`
101
+ Returns the value of a JSON variable. JSON variables arrive already parsed: an object, an array, a string, a number, a boolean or `null`.
102
+
103
+ ```ts
104
+ type Banner = { title: string; url: string }
105
+ const banner = nana800RemoteConfig.getJSON<Banner>('main_banner')
106
+ ```
107
+
108
+ ### `getReceivedVariablesObject()`
109
+ Returns a copy of all received variables.
110
+
111
+ ### `getLastError()`
112
+ Returns the error text of the last unsuccessful `initFetch` call.
113
+ The fetch endpoint allows 100 requests per 3 seconds and 300 requests per 10 seconds from one IP, above that it answers `HTTP 429`.
114
+
115
+ ### `isFetched`
116
+ `true` after the first successful `initFetch` call.
117
+
81
118
  ## FAQ
82
119
 
83
120
  ### Where is the API key ("api_key"):