@chaosity/location-client-react 0.6.0 → 0.8.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.
@@ -1,15 +1,22 @@
1
- import type { ClientConfig } from '@chaosity/location-client';
1
+ import type { ClientConfig, VerifyAddressResponse } from '@chaosity/location-client';
2
2
  import { type AppConfigClaims } from '@chaosity/location-client';
3
3
  import type { ReactNode } from 'react';
4
4
  /**
5
5
  * Per-request transport options.
6
6
  *
7
- * Declared structurally rather than imported so this package builds against the
8
- * currently published client; it matches `SendOptions` there exactly.
7
+ * Declared structurally rather than imported, like `LocationClient` below. A
8
+ * hand copy does not move when the core does — `overallTimeoutMs` reached the
9
+ * core in 0.8.0 and not this copy (#26) — so `test/core-surface.test.ts` fails
10
+ * while the core's `SendOptions` has a key this one lacks.
9
11
  */
10
12
  export interface SendOptions {
13
+ /** Caller cancellation. Aborting rejects with code `AbortedException`. */
11
14
  signal?: AbortSignal;
15
+ /** Per ATTEMPT, not for the whole call. */
12
16
  timeoutMs?: number;
17
+ /** The whole call: attempts and the waits between them. Core 0.8.0+. */
18
+ overallTimeoutMs?: number;
19
+ /** `false` disables retries entirely. */
13
20
  retry?: false | {
14
21
  maxAttempts?: number;
15
22
  };
@@ -21,6 +28,9 @@ export interface SendOptions {
21
28
  * real client to refresh tokens first, and a class with private fields is not
22
29
  * structurally assignable — which is why this used to be an `Object.create`
23
30
  * prototype hack.
31
+ *
32
+ * It must carry every public member of the core client this package builds
33
+ * with: `test/core-surface.test.ts` fails when the core gains one (#26).
24
34
  */
25
35
  export interface LocationClient {
26
36
  readonly config: {
@@ -28,27 +38,49 @@ export interface LocationClient {
28
38
  };
29
39
  send<TInput, TOutput>(command: TInput, options?: SendOptions): Promise<TOutput>;
30
40
  /**
31
- * This application's own configuration, read from the access token —
32
- * bias precision, and the countries it is scoped to (api#65).
41
+ * Verify a PlaceId through `POST /address/verify`: the full place record plus
42
+ * `verified`, the one Places result an integrator may store (#26). A
43
+ * `verified: false` resolves; it is not an error. Refreshes a stale token
44
+ * first, as `send` does.
45
+ *
46
+ * Needs @chaosity/location-client 0.10.0 or later, the peer range's floor.
47
+ * `send(new VerifyAddressCommand({ PlaceId }))` is the same request.
48
+ *
49
+ * Billed per call, whether or not the address verifies: call it once per
50
+ * chosen PlaceId, at submit.
51
+ */
52
+ verifyAddress(placeId: string, options?: SendOptions): Promise<VerifyAddressResponse>;
53
+ /**
54
+ * This application's own configuration, read from the access token
55
+ * (api#65). The fields are whatever the installed @chaosity/location-client
56
+ * reads — its `AppConfigClaims` is the list, and this passes that client's
57
+ * answer through unchanged. So a field the core adds appears here with no
58
+ * change to this package, and is absent under a core too old to read it;
59
+ * the peer range cannot say which.
33
60
  *
34
61
  * Here so a React app can SHOW its own settings: populate a country
35
62
  * selector with the markets it serves, label a settings screen. Being a
36
63
  * few minutes stale is cosmetic for that.
37
64
  *
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
65
+ * It is not an entitlement check, and none of it may be used to shape or
66
+ * refuse requests. The token is a snapshot; the API reads every setting
67
+ * fresh from the application on every call. Injecting a stale country
68
+ * scope turns a request that would have succeeded into a 400. See
42
69
  * `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
70
  */
47
71
  getAppConfig(): AppConfigClaims;
48
72
  }
49
73
  interface LocationClientContextValue {
50
74
  client: LocationClient | null;
51
75
  getToken: () => string | undefined;
76
+ /**
77
+ * The API `client` talks to, from the same `getConfig` answer as the token
78
+ * `getToken` returns (#14). Build a map's style and tile URLs from this
79
+ * rather than restating the URL, so a map and its token cannot come from two
80
+ * different configurations. `null` until a configuration has loaded, and
81
+ * again while a new `configKey` loads.
82
+ */
83
+ apiUrl: string | null;
52
84
  loading: boolean;
53
85
  error: string | null;
54
86
  }
@@ -57,7 +89,20 @@ export interface LocationClientProviderProps {
57
89
  getConfig: () => Promise<ClientConfig & {
58
90
  expiresAt?: number;
59
91
  }>;
92
+ /**
93
+ * What `getConfig` answers for: an organisation or application id.
94
+ *
95
+ * Changing it drops the old configuration's token, client and `apiUrl` in
96
+ * the same render, and asks `getConfig` again, without remounting the
97
+ * children (#14). A client or a `getToken` kept from before the change
98
+ * refuses from then on, rather than pairing one configuration's token with
99
+ * the other's URL.
100
+ *
101
+ * `getConfig`'s own identity is deliberately not such a signal: it is
102
+ * usually an inline function, new on every render.
103
+ */
104
+ configKey?: string | number;
60
105
  }
61
- export declare function LocationClientProvider({ children, getConfig, }: LocationClientProviderProps): import("react").JSX.Element;
106
+ export declare function LocationClientProvider({ children, getConfig, configKey, }: LocationClientProviderProps): import("react").JSX.Element;
62
107
  export declare function useLocationClient(): LocationClientContextValue;
63
108
  export {};