@chaosity/location-client-react 0.3.0 → 0.3.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.
@@ -1,4 +1,5 @@
1
1
  import type { ClientConfig } from '@chaosity/location-client';
2
+ import { type AppConfigClaims } from '@chaosity/location-client';
2
3
  import type { ReactNode } from 'react';
3
4
  /**
4
5
  * Per-request transport options.
@@ -26,6 +27,24 @@ export interface LocationClient {
26
27
  serviceId: string;
27
28
  };
28
29
  send<TInput, TOutput>(command: TInput, options?: SendOptions): Promise<TOutput>;
30
+ /**
31
+ * This application's own configuration, read from the access token —
32
+ * bias precision, and the countries it is scoped to (api#65).
33
+ *
34
+ * Here so a React app can SHOW its own settings: populate a country
35
+ * selector with the markets it serves, label a settings screen. Being a
36
+ * few minutes stale is cosmetic for that.
37
+ *
38
+ * It is not an entitlement check, and the `countries` value must not be
39
+ * used to shape requests. The token is a snapshot; the API reads the scope
40
+ * fresh from the application row on every call. Injecting a stale scope
41
+ * turns a request that would have succeeded into a 400. See
42
+ * `AppConfigClaims` in @chaosity/location-client for the measurement.
43
+ *
44
+ * Returns `{}` when the token carries no application config, which is the
45
+ * case until one is set in the portal.
46
+ */
47
+ getAppConfig(): AppConfigClaims;
29
48
  }
30
49
  interface LocationClientContextValue {
31
50
  client: LocationClient | null;
@@ -170,6 +170,13 @@ export function LocationClientProvider({ children, getConfig, }) {
170
170
  await ensureValidTokenRef.current();
171
171
  return baseClient.send(command, options);
172
172
  },
173
+ // Reads whatever token the client currently holds. Deliberately not
174
+ // awaiting a refresh: this is display data, callers expect it to be
175
+ // synchronous, and a token that is minutes from expiry carries the
176
+ // same application config as its replacement will.
177
+ getAppConfig() {
178
+ return baseClient.getAppConfig();
179
+ },
173
180
  };
174
181
  setClient(refreshing);
175
182
  scheduleRefreshRef.current();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaosity/location-client-react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "React bindings for Chaosity Location Service client",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "url": "https://github.com/chaosity-io/location-service-client-react/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@chaosity/location-client": "^0.2.1",
37
+ "@chaosity/location-client": "^0.3.0",
38
38
  "debug": "^4.4.3"
39
39
  },
40
40
  "peerDependencies": {