@seamapi/react 4.8.2 → 4.9.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 (75) hide show
  1. package/README.md +17 -2
  2. package/dist/elements.js +22079 -18028
  3. package/dist/elements.js.map +1 -1
  4. package/lib/index.d.ts +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/seam/SeamProvider.d.ts +7 -16
  8. package/lib/seam/SeamProvider.js +12 -101
  9. package/lib/seam/SeamProvider.js.map +1 -1
  10. package/lib/seam/SeamQueryProvider.d.ts +34 -0
  11. package/lib/seam/SeamQueryProvider.js +136 -0
  12. package/lib/seam/SeamQueryProvider.js.map +1 -0
  13. package/lib/seam/access-codes/use-access-code.d.ts +2 -2
  14. package/lib/seam/access-codes/use-access-codes.d.ts +2 -2
  15. package/lib/seam/access-codes/use-create-access-code.d.ts +2 -7
  16. package/lib/seam/access-codes/use-create-access-code.js +3 -9
  17. package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
  18. package/lib/seam/access-codes/use-generate-access-code-code.d.ts +2 -2
  19. package/lib/seam/client-sessions/use-client-session.d.ts +2 -2
  20. package/lib/seam/components/SupportedDeviceTable/use-device-model.d.ts +2 -2
  21. package/lib/seam/components/SupportedDeviceTable/use-device-models.d.ts +2 -2
  22. package/lib/seam/components/SupportedDeviceTable/use-manufacturer.d.ts +2 -2
  23. package/lib/seam/components/SupportedDeviceTable/use-manufacturers.d.ts +2 -2
  24. package/lib/seam/connected-accounts/use-connected-account.d.ts +2 -2
  25. package/lib/seam/devices/use-device-providers.d.ts +2 -2
  26. package/lib/seam/devices/use-device.d.ts +2 -2
  27. package/lib/seam/devices/use-devices.d.ts +2 -2
  28. package/lib/seam/events/use-events.d.ts +2 -2
  29. package/lib/seam/index.d.ts +2 -0
  30. package/lib/seam/index.js +2 -0
  31. package/lib/seam/index.js.map +1 -1
  32. package/lib/seam/noise-sensors/use-noise-thresholds.d.ts +2 -2
  33. package/lib/seam/thermostats/use-delete-thermostat-climate-preset.d.ts +2 -2
  34. package/lib/seam/use-seam-client.d.ts +3 -1
  35. package/lib/seam/use-seam-client.js +42 -9
  36. package/lib/seam/use-seam-client.js.map +1 -1
  37. package/lib/seam/use-seam-mutation.d.ts +8 -0
  38. package/lib/seam/use-seam-mutation.js +17 -0
  39. package/lib/seam/use-seam-mutation.js.map +1 -0
  40. package/lib/seam/use-seam-query-result.d.ts +1 -1
  41. package/lib/seam/use-seam-query.d.ts +8 -0
  42. package/lib/seam/use-seam-query.js +23 -0
  43. package/lib/seam/use-seam-query.js.map +1 -0
  44. package/lib/telemetry/hooks.js +2 -2
  45. package/lib/telemetry/hooks.js.map +1 -1
  46. package/lib/ui/DateTimePicker/DateTimePicker.d.ts +1 -1
  47. package/lib/version.d.ts +1 -1
  48. package/lib/version.js +1 -1
  49. package/package.json +3 -2
  50. package/src/lib/index.ts +1 -0
  51. package/src/lib/seam/SeamProvider.tsx +31 -182
  52. package/src/lib/seam/SeamQueryProvider.tsx +270 -0
  53. package/src/lib/seam/access-codes/use-access-code.ts +2 -2
  54. package/src/lib/seam/access-codes/use-access-codes.ts +2 -2
  55. package/src/lib/seam/access-codes/use-create-access-code.ts +7 -32
  56. package/src/lib/seam/access-codes/use-generate-access-code-code.ts +2 -2
  57. package/src/lib/seam/client-sessions/use-client-session.ts +2 -2
  58. package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +2 -2
  59. package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +2 -2
  60. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +2 -2
  61. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +2 -2
  62. package/src/lib/seam/connected-accounts/use-connected-account.ts +2 -2
  63. package/src/lib/seam/devices/use-device-providers.ts +2 -2
  64. package/src/lib/seam/devices/use-device.ts +2 -2
  65. package/src/lib/seam/devices/use-devices.ts +2 -2
  66. package/src/lib/seam/events/use-events.ts +2 -2
  67. package/src/lib/seam/index.ts +2 -0
  68. package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +2 -2
  69. package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +2 -2
  70. package/src/lib/seam/use-seam-client.ts +64 -10
  71. package/src/lib/seam/use-seam-mutation.ts +50 -0
  72. package/src/lib/seam/use-seam-query-result.ts +6 -4
  73. package/src/lib/seam/use-seam-query.ts +49 -0
  74. package/src/lib/telemetry/hooks.ts +2 -2
  75. package/src/lib/version.ts +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { NoiseSensorsNoiseThresholdsListParams } from '@seamapi/http/connect';
2
2
  import type { NoiseThreshold } from '@seamapi/types/connect';
3
- import type { UseSeamQueryResult } from '../../../lib/seam/use-seam-query-result.js';
3
+ import type { UseSeamQueryResultLegacy } from '../../../lib/seam/use-seam-query-result.js';
4
4
  export type UseNoiseThresholdsParams = NoiseSensorsNoiseThresholdsListParams;
5
5
  export type UseNoiseThresholdsData = NoiseThreshold[];
6
- export declare function useNoiseThresholds(params: UseNoiseThresholdsParams): UseSeamQueryResult<'noiseThresholds', UseNoiseThresholdsData>;
6
+ export declare function useNoiseThresholds(params: UseNoiseThresholdsParams): UseSeamQueryResultLegacy<'noiseThresholds', UseNoiseThresholdsData>;
@@ -1,6 +1,6 @@
1
- import type { SeamHttpApiError, ThermostatsDeleteClimatePresetBody } from '@seamapi/http/connect';
1
+ import type { SeamHttpApiError, ThermostatsDeleteClimatePresetParams } from '@seamapi/http/connect';
2
2
  import { type UseMutationResult } from '@tanstack/react-query';
3
3
  export type UseDeleteThermostatClimatePresetParams = never;
4
4
  export type UseDeleteThermostatClimatePresetData = undefined;
5
- export type UseDeleteThermostatClimatePresetVariables = ThermostatsDeleteClimatePresetBody;
5
+ export type UseDeleteThermostatClimatePresetVariables = ThermostatsDeleteClimatePresetParams;
6
6
  export declare function useDeleteThermostatClimatePreset(): UseMutationResult<UseDeleteThermostatClimatePresetData, SeamHttpApiError, UseDeleteThermostatClimatePresetVariables>;
@@ -1,6 +1,8 @@
1
- import { SeamHttp } from '@seamapi/http/connect';
1
+ import { SeamHttp, SeamHttpEndpoints } from '@seamapi/http/connect';
2
2
  export declare function useSeamClient(): {
3
3
  client: SeamHttp | null;
4
+ endpointClient: SeamHttpEndpoints | null;
5
+ queryKeyPrefixes: string[];
4
6
  isPending: boolean;
5
7
  isError: boolean;
6
8
  error: unknown;
@@ -1,13 +1,14 @@
1
- import { SeamHttp } from '@seamapi/http/connect';
1
+ import { SeamHttp, SeamHttpEndpoints } from '@seamapi/http/connect';
2
2
  import { useQuery } from '@tanstack/react-query';
3
3
  import { useEffect } from 'react';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
- import { useSeamContext } from '../../lib/seam/SeamProvider.js';
5
+ import { useSeamQueryContext } from './SeamQueryProvider.js';
6
6
  export function useSeamClient() {
7
- const { client, clientOptions, publishableKey, clientSessionToken, ...context } = useSeamContext();
7
+ const { client, clientOptions, publishableKey, clientSessionToken, queryKeyPrefix, ...context } = useSeamQueryContext();
8
8
  const userIdentifierKey = useUserIdentifierKeyOrFingerprint(clientSessionToken != null ? '' : context.userIdentifierKey);
9
9
  const { isPending, isError, error, data } = useQuery({
10
10
  queryKey: [
11
+ ...getQueryKeyPrefixes({ queryKeyPrefix }),
11
12
  'client',
12
13
  {
13
14
  client,
@@ -19,23 +20,43 @@ export function useSeamClient() {
19
20
  ],
20
21
  queryFn: async () => {
21
22
  if (client != null)
22
- return client;
23
+ return [client, SeamHttpEndpoints.fromClient(client.client)];
23
24
  if (clientSessionToken != null) {
24
- return SeamHttp.fromClientSessionToken(clientSessionToken, clientOptions);
25
+ const clientSessionTokenClient = SeamHttp.fromClientSessionToken(clientSessionToken, clientOptions);
26
+ return [
27
+ clientSessionTokenClient,
28
+ SeamHttpEndpoints.fromClient(clientSessionTokenClient.client),
29
+ ];
25
30
  }
26
31
  if (publishableKey == null) {
27
32
  throw new Error('Missing either a client, publishableKey, or clientSessionToken');
28
33
  }
29
- return await SeamHttp.fromPublishableKey(publishableKey, userIdentifierKey, clientOptions);
34
+ const publishableKeyClient = await SeamHttp.fromPublishableKey(publishableKey, userIdentifierKey, clientOptions);
35
+ return [
36
+ publishableKeyClient,
37
+ SeamHttpEndpoints.fromClient(publishableKeyClient.client),
38
+ ];
30
39
  },
31
40
  });
32
- return { client: data ?? null, isPending, isError, error };
41
+ return {
42
+ client: data?.[0] ?? null,
43
+ endpointClient: data?.[1] ?? null,
44
+ queryKeyPrefixes: getQueryKeyPrefixes({
45
+ queryKeyPrefix,
46
+ userIdentifierKey,
47
+ publishableKey,
48
+ clientSessionToken,
49
+ }),
50
+ isPending,
51
+ isError,
52
+ error,
53
+ };
33
54
  }
34
55
  export class NullSeamClientError extends Error {
35
56
  constructor() {
36
57
  super([
37
58
  'Attempted to use a null Seam client.',
38
- 'Either a hook using useSeamClient was called outside of a SeamProvider,',
59
+ 'Either a hook using useSeamClient was called outside of a SeamProvider or SeamQueryProvider,',
39
60
  'or there was an error when creating the Seam client in useSeamClient,',
40
61
  'or useSeamClient is still loading the client.',
41
62
  ].join(' '));
@@ -48,7 +69,7 @@ function useUserIdentifierKeyOrFingerprint(userIdentifierKey) {
48
69
  if (userIdentifierKey != null)
49
70
  return;
50
71
  // eslint-disable-next-line no-console
51
- console.warn(`Using an automatically generated fingerprint for the SeamProvider userIdentifierKey!
72
+ console.warn(`Using an automatically generated fingerprint for the Seam userIdentifierKey!
52
73
  The user interface will show warnings when using a fingerprint.
53
74
  This is not recommended because the client session is now bound to this machine and is effectively ephemeral.`);
54
75
  }, [userIdentifierKey]);
@@ -60,4 +81,16 @@ This is not recommended because the client session is now bound to this machine
60
81
  globalThis.localStorage?.setItem('seam_user_fingerprint', fingerprint);
61
82
  return fingerprint;
62
83
  }
84
+ const getQueryKeyPrefixes = ({ queryKeyPrefix, userIdentifierKey, publishableKey, clientSessionToken, }) => {
85
+ const seamPrefix = 'seam';
86
+ if (queryKeyPrefix != null)
87
+ return [seamPrefix, queryKeyPrefix];
88
+ if (clientSessionToken != null) {
89
+ return [seamPrefix, clientSessionToken];
90
+ }
91
+ if (publishableKey != null && userIdentifierKey != null) {
92
+ return [seamPrefix, publishableKey, userIdentifierKey];
93
+ }
94
+ return [seamPrefix];
95
+ };
63
96
  //# sourceMappingURL=use-seam-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-seam-client.js","sourceRoot":"","sources":["../../src/lib/seam/use-seam-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD,MAAM,UAAU,aAAa;IAM3B,MAAM,EACJ,MAAM,EACN,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,GAAG,OAAO,EACX,GAAG,cAAc,EAAE,CAAA;IACpB,MAAM,iBAAiB,GAAG,iCAAiC,CACzD,kBAAkB,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAC5D,CAAA;IAED,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAW;QAC7D,QAAQ,EAAE;YACR,QAAQ;YACR;gBACE,MAAM;gBACN,aAAa;gBACb,cAAc;gBACd,iBAAiB;gBACjB,kBAAkB;aACnB;SACF;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,MAAM,IAAI,IAAI;gBAAE,OAAO,MAAM,CAAA;YAEjC,IAAI,kBAAkB,IAAI,IAAI,EAAE,CAAC;gBAC/B,OAAO,QAAQ,CAAC,sBAAsB,CACpC,kBAAkB,EAClB,aAAa,CACd,CAAA;YAC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CAAC;QAC9B,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IAED,MAAM,WAAW,GACf,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,uBAAuB,CAAC;QACzD,eAAe,MAAM,EAAE,EAAE,CAAA;IAE3B,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAA;IAEtE,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,MAAM,mBAAmB,GAAG,CAAC,EAC3B,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GAMnB,EAAY,EAAE;IACb,MAAM,UAAU,GAAG,MAAM,CAAA;IAEzB,IAAI,cAAc,IAAI,IAAI;QAAE,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;IAE/D,IAAI,kBAAkB,IAAI,IAAI,EAAE,CAAC;QAC/B,OAAO,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAA;IACzC,CAAC;IAED,IAAI,cAAc,IAAI,IAAI,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;QACxD,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAA;IACxD,CAAC;IAED,OAAO,CAAC,UAAU,CAAC,CAAA;AACrB,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { SeamHttpApiError, SeamHttpEndpointMutationPaths, SeamHttpEndpoints } from '@seamapi/http/connect';
2
+ import { type UseMutationOptions, type UseMutationResult } from '@tanstack/react-query';
3
+ export type UseSeamMutationVariables<T extends SeamHttpEndpointMutationPaths> = Parameters<SeamHttpEndpoints[T]>[0];
4
+ export type UseSeamMutationResult<T extends SeamHttpEndpointMutationPaths> = UseMutationResult<MutationData<T>, SeamHttpApiError, UseSeamMutationVariables<T>>;
5
+ export declare function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(endpointPath: T, options?: Parameters<SeamHttpEndpoints[T]>[1] & MutationOptions<MutationData<T>, SeamHttpApiError, UseSeamMutationVariables<T>>): UseSeamMutationResult<T>;
6
+ type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<ReturnType<SeamHttpEndpoints[T]>>;
7
+ type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>;
8
+ export {};
@@ -0,0 +1,17 @@
1
+ import { useMutation, } from '@tanstack/react-query';
2
+ import { NullSeamClientError, useSeamClient } from '../../lib/seam/use-seam-client.js';
3
+ export function useSeamMutation(endpointPath, options = {}) {
4
+ const { endpointClient: client } = useSeamClient();
5
+ return useMutation({
6
+ ...options,
7
+ mutationFn: async (variables) => {
8
+ if (client === null)
9
+ throw new NullSeamClientError();
10
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
11
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
12
+ const endpoint = client[endpointPath];
13
+ return await endpoint(variables, options);
14
+ },
15
+ });
16
+ }
17
+ //# sourceMappingURL=use-seam-mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-seam-mutation.js","sourceRoot":"","sources":["../../src/lib/seam/use-seam-mutation.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAYhF,MAAM,UAAU,eAAe,CAC7B,YAAe,EACf,UAKM,EAAE;IAER,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAA;IAClD,OAAO,WAAW,CAAC;QACjB,GAAG,OAAO;QACV,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC9B,IAAI,MAAM,KAAK,IAAI;gBAAE,MAAM,IAAI,mBAAmB,EAAE,CAAA;YACpD,iHAAiH;YACjH,2FAA2F;YAC3F,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAmC,CAAA;YACvE,OAAO,MAAM,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAC3C,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { SeamHttpApiError } from '@seamapi/http/connect';
2
2
  import type { UseQueryResult } from '@tanstack/react-query';
3
- export type UseSeamQueryResult<Field extends string, ResponsePayload> = Omit<UseQueryResult<ResponsePayload, SeamHttpApiError>, 'data'> & {
3
+ export type UseSeamQueryResultLegacy<Field extends string, ResponsePayload> = Omit<UseQueryResult<ResponsePayload, SeamHttpApiError>, 'data'> & {
4
4
  [key in Field]?: ResponsePayload;
5
5
  };
@@ -0,0 +1,8 @@
1
+ import type { SeamHttpApiError, SeamHttpEndpointQueryPaths, SeamHttpEndpoints } from '@seamapi/http/connect';
2
+ import { type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
3
+ export type UseSeamQueryParameters<T extends SeamHttpEndpointQueryPaths> = Parameters<SeamHttpEndpoints[T]>[0];
4
+ export type UseSeamQueryResult<T extends SeamHttpEndpointQueryPaths> = UseQueryResult<QueryData<T>, SeamHttpApiError>;
5
+ export declare function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(endpointPath: T, parameters?: UseSeamQueryParameters<T>, options?: Parameters<SeamHttpEndpoints[T]>[1] & QueryOptions<QueryData<T>, SeamHttpApiError>): UseSeamQueryResult<T>;
6
+ type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<ReturnType<SeamHttpEndpoints[T]>>;
7
+ type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>;
8
+ export {};
@@ -0,0 +1,23 @@
1
+ import { useQuery, } from '@tanstack/react-query';
2
+ import { useSeamClient } from '../../lib/seam/use-seam-client.js';
3
+ export function useSeamQuery(endpointPath, parameters, options = {}) {
4
+ const { endpointClient: client, queryKeyPrefixes } = useSeamClient();
5
+ return useQuery({
6
+ enabled: client != null,
7
+ ...options,
8
+ queryKey: [
9
+ ...queryKeyPrefixes,
10
+ ...endpointPath.split('/').filter((v) => v !== ''),
11
+ parameters,
12
+ ],
13
+ queryFn: async () => {
14
+ if (client == null)
15
+ return null;
16
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
17
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
18
+ const endpoint = client[endpointPath];
19
+ return await endpoint(parameters, options);
20
+ },
21
+ });
22
+ }
23
+ //# sourceMappingURL=use-seam-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-seam-query.js","sourceRoot":"","sources":["../../src/lib/seam/use-seam-query.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,QAAQ,GAGT,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAQ3D,MAAM,UAAU,YAAY,CAC1B,YAAe,EACf,UAAsC,EACtC,UACiD,EAAE;IAEnD,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,aAAa,EAAE,CAAA;IACpE,OAAO,QAAQ,CAAC;QACd,OAAO,EAAE,MAAM,IAAI,IAAI;QACvB,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,GAAG,gBAAgB;YACnB,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YAClD,UAAU;SACX;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,MAAM,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAA;YAC/B,iHAAiH;YACjH,2FAA2F;YAC3F,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAmC,CAAA;YACvE,OAAO,MAAM,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAC5C,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useLayoutEffect } from 'react';
2
2
  import { useClientSession } from '../../lib/seam/client-sessions/use-client-session.js';
3
- import { useSeamContext } from '../../lib/seam/SeamProvider.js';
3
+ import { useSeamQueryContext } from '../../lib/seam/SeamQueryProvider.js';
4
4
  import { useTelemetryContext } from './TelemetryProvider.js';
5
5
  export function useTelemetryClient() {
6
6
  const { client } = useTelemetryContext();
@@ -18,7 +18,7 @@ export function useComponentTelemetry(name) {
18
18
  }
19
19
  export function useUserTelemetry() {
20
20
  const telemetry = useTelemetryClient();
21
- const { publishableKey } = useSeamContext();
21
+ const { publishableKey } = useSeamQueryContext();
22
22
  const { clientSession } = useClientSession();
23
23
  // Ensure identify runs earlier than other effects to avoid anonymous telemetry data.
24
24
  useLayoutEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/lib/telemetry/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,MAAM,UAAU,kBAAkB;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAAA;IACxC,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAC5C,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAA;IACtC,SAAS,CAAC,GAAG,EAAE;QACb,sEAAsE;QACtE,IAAI,aAAa,IAAI,IAAI;YAAE,OAAM;QACjC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,SA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AM,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAC5C,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAA;IACtC,SAAS,CAAC,GAAG,EAAE;QACb,sEAAsE;QACtE,IAAI,aAAa,IAAI,IAAI;YAAE,OAAM;QACjC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAA;IACtC,MAAM,EAAE,cAAc,EAAE,GAAG,mBAAmB,EAAE,CAAA;IAChD,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAE5C,qFAAqF;IACrF,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,aAAa,IAAI,IAAI;YAAE,OAAM;QAEjC,MAAM,eAAe,GAAG;YACtB,aAAa,CAAC,YAAY;YAC1B,aAAa,CAAC,mBAAmB,IAAI,SAAS;SAC/C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEX,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;QAEhC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE;YAClC,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,mBAAmB,EAAE,aAAa,CAAC,mBAAmB;YACtD,eAAe,EAAE,cAAc;SAChC,CAAC,CAAA;QAEF,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY,EAAE;YAC1C,YAAY,EAAE,aAAa,CAAC,YAAY;SACzC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC,CAAA;AAChD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { type TextFieldProps } from '../../../lib/ui/TextField/TextField.js';
3
- export declare const DateTimePicker: import("react").ForwardRefExoticComponent<Pick<TextFieldProps, "value" | "className" | "size"> & {
3
+ export declare const DateTimePicker: import("react").ForwardRefExoticComponent<Pick<TextFieldProps, "value" | "size" | "className"> & {
4
4
  onChange: (value: string) => void;
5
5
  } & import("react").RefAttributes<HTMLInputElement | undefined>>;
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const seamapiReactVersion = "4.8.2";
1
+ declare const seamapiReactVersion = "4.9.1";
2
2
  export default seamapiReactVersion;
package/lib/version.js CHANGED
@@ -1,3 +1,3 @@
1
- const seamapiReactVersion = '4.8.2';
1
+ const seamapiReactVersion = '4.9.1';
2
2
  export default seamapiReactVersion;
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamapi/react",
3
- "version": "4.8.2",
3
+ "version": "4.9.1",
4
4
  "description": "Seam Components.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -109,6 +109,7 @@
109
109
  "npm": ">= 9.0.0"
110
110
  },
111
111
  "peerDependencies": {
112
+ "@seamapi/http": "^1.37.0",
112
113
  "@seamapi/types": "^1.395.3",
113
114
  "@types/react": "^18.0.0",
114
115
  "@types/react-dom": "^18.0.0",
@@ -128,7 +129,6 @@
128
129
  },
129
130
  "dependencies": {
130
131
  "@floating-ui/react": "^0.27.5",
131
- "@seamapi/http": "^1.30.2",
132
132
  "@tanstack/react-query": "^5.27.5",
133
133
  "classnames": "^2.3.2",
134
134
  "luxon": "^3.3.0",
@@ -145,6 +145,7 @@
145
145
  "@rxfork/r2wc-react-to-web-component": "^2.4.0",
146
146
  "@seamapi/fake-devicedb": "^1.6.1",
147
147
  "@seamapi/fake-seam-connect": "^1.76.0",
148
+ "@seamapi/http": "^1.38.3",
148
149
  "@seamapi/types": "^1.395.3",
149
150
  "@storybook/addon-designs": "^7.0.1",
150
151
  "@storybook/addon-essentials": "^7.0.2",
package/src/lib/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './seam/components/index.js'
2
2
  export * from './seam/index.js'
3
3
  export * from './seam/SeamProvider.js'
4
+ export * from './seam/SeamQueryProvider.js'
@@ -1,16 +1,13 @@
1
- import type {
2
- SeamHttp,
3
- SeamHttpOptionsWithClientSessionToken,
4
- } from '@seamapi/http/connect'
5
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6
- import {
7
- createContext,
8
- type PropsWithChildren,
9
- useContext,
10
- useEffect,
11
- useMemo,
12
- } from 'react'
1
+ import type { SeamHttp } from '@seamapi/http/connect'
2
+ import type { QueryClient } from '@tanstack/react-query'
3
+ import { createContext, type PropsWithChildren, useMemo } from 'react'
13
4
 
5
+ import {
6
+ SeamQueryProvider,
7
+ type SeamQueryProviderPropsWithClient,
8
+ type SeamQueryProviderPropsWithClientSessionToken,
9
+ type SeamQueryProviderPropsWithPublishableKey,
10
+ } from 'lib/seam/SeamQueryProvider.js'
14
11
  import { useSeamFont } from 'lib/seam/use-seam-font.js'
15
12
  import { useSeamStyles } from 'lib/seam/use-seam-styles.js'
16
13
  import {
@@ -19,8 +16,6 @@ import {
19
16
  useUserTelemetry,
20
17
  } from 'lib/telemetry/index.js'
21
18
 
22
- import { useSeamClient } from './use-seam-client.js'
23
-
24
19
  declare global {
25
20
  // eslint-disable-next-line no-var
26
21
  var seam: SeamProviderProps | undefined
@@ -30,33 +25,28 @@ declare global {
30
25
  var seamTelemetryClient: TelemetryClient | undefined
31
26
  }
32
27
 
33
- export interface SeamContext {
34
- client: SeamHttp | null
35
- clientOptions?: SeamProviderClientOptions | undefined
36
- publishableKey?: string | undefined
37
- userIdentifierKey?: string | undefined
38
- clientSessionToken?: string | undefined
39
- }
28
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
29
+ export interface SeamContext {}
40
30
 
41
31
  export type SeamProviderProps =
42
32
  | SeamProviderPropsWithClient
43
33
  | SeamProviderPropsWithPublishableKey
44
34
  | SeamProviderPropsWithClientSessionToken
45
35
 
46
- export interface SeamProviderPropsWithClient extends SeamProviderBaseProps {
47
- client: SeamHttp
48
- }
36
+ export interface SeamProviderPropsWithClient
37
+ extends SeamQueryProviderPropsWithClient,
38
+ SeamProviderBaseProps {}
49
39
 
50
40
  export interface SeamProviderPropsWithPublishableKey
51
41
  extends SeamProviderBaseProps,
52
- SeamProviderClientOptions {
42
+ SeamQueryProviderPropsWithPublishableKey {
53
43
  publishableKey: string
54
44
  userIdentifierKey?: string
55
45
  }
56
46
 
57
47
  export interface SeamProviderPropsWithClientSessionToken
58
48
  extends SeamProviderBaseProps,
59
- SeamProviderClientOptions {
49
+ SeamQueryProviderPropsWithClientSessionToken {
60
50
  clientSessionToken: string
61
51
  }
62
52
 
@@ -70,12 +60,6 @@ interface SeamProviderBaseProps extends PropsWithChildren {
70
60
  onSessionUpdate?: (client: SeamHttp) => void
71
61
  }
72
62
 
73
- type SeamClientOptions = SeamHttpOptionsWithClientSessionToken
74
-
75
- export type SeamProviderClientOptions = Pick<SeamClientOptions, 'endpoint'>
76
-
77
- const defaultQueryClient = new QueryClient()
78
-
79
63
  export const seamComponentsClassName = 'seam-components'
80
64
 
81
65
  export function SeamProvider({
@@ -84,40 +68,21 @@ export function SeamProvider({
84
68
  disableCssInjection = false,
85
69
  disableFontInjection = false,
86
70
  unminifiyCss = false,
87
- onSessionUpdate = () => {},
88
- queryClient,
89
71
  telemetryClient,
72
+ queryClient,
90
73
  ...props
91
74
  }: SeamProviderProps): JSX.Element {
92
75
  useSeamStyles({ disabled: disableCssInjection, unminified: unminifiyCss })
93
76
  useSeamFont({ disabled: disableFontInjection })
94
77
 
78
+ const { Provider } = seamContext
79
+
80
+ const endpoint = 'endpoint' in props ? props.endpoint : undefined
95
81
  const value = useMemo(() => {
96
82
  const context = createSeamContextValue(props)
97
- if (
98
- context.client == null &&
99
- context.publishableKey == null &&
100
- context.clientSessionToken == null
101
- ) {
102
- return defaultSeamContextValue
103
- }
104
83
  return context
105
84
  }, [props])
106
85
 
107
- if (
108
- value.client == null &&
109
- value.publishableKey == null &&
110
- value.clientSessionToken == null
111
- ) {
112
- throw new Error(
113
- `Must provide either a Seam client, clientSessionToken, or a publishableKey.`
114
- )
115
- }
116
-
117
- const { Provider } = seamContext
118
-
119
- const endpoint = 'endpoint' in props ? props.endpoint : undefined
120
-
121
86
  return (
122
87
  <div className={seamComponentsClassName}>
123
88
  <TelemetryProvider
@@ -125,157 +90,41 @@ export function SeamProvider({
125
90
  disabled={disableTelemetry}
126
91
  endpoint={endpoint}
127
92
  >
128
- <QueryClientProvider
129
- client={
130
- queryClient ?? globalThis.seamQueryClient ?? defaultQueryClient
131
- }
93
+ <SeamQueryProvider
94
+ queryClient={queryClient ?? globalThis.seamQueryClient}
95
+ {...props}
132
96
  >
133
97
  <Provider value={value}>
134
- <Wrapper onSessionUpdate={onSessionUpdate}>{children}</Wrapper>
98
+ <Telemetry>{children}</Telemetry>
135
99
  </Provider>
136
- </QueryClientProvider>
100
+ </SeamQueryProvider>
137
101
  </TelemetryProvider>
138
102
  </div>
139
103
  )
140
104
  }
141
105
 
142
- function Wrapper({
143
- onSessionUpdate,
144
- children,
145
- }: Required<Pick<SeamProviderProps, 'onSessionUpdate'>> &
146
- PropsWithChildren): JSX.Element | null {
106
+ function Telemetry({ children }: PropsWithChildren): JSX.Element | null {
147
107
  useUserTelemetry()
148
-
149
- const { client } = useSeamClient()
150
- useEffect(() => {
151
- if (client != null) onSessionUpdate(client)
152
- }, [onSessionUpdate, client])
153
-
154
108
  return <>{children}</>
155
109
  }
156
110
 
157
111
  const createDefaultSeamContextValue = (): SeamContext => {
158
112
  try {
159
113
  if (globalThis.seam == null) {
160
- return { client: null }
114
+ return {}
161
115
  }
162
116
  return createSeamContextValue(globalThis.seam)
163
117
  } catch (err) {
164
118
  // eslint-disable-next-line no-console
165
119
  console.warn(err)
166
- return { client: null }
120
+ return {}
167
121
  }
168
122
  }
169
123
 
170
- const createSeamContextValue = (options: SeamProviderProps): SeamContext => {
171
- if (isSeamProviderPropsWithClient(options)) {
172
- return options
173
- }
174
-
175
- if (isSeamProviderPropsWithClientSessionToken(options)) {
176
- const { clientSessionToken, ...clientOptions } = options
177
- return {
178
- clientSessionToken,
179
- clientOptions,
180
- client: null,
181
- }
182
- }
183
-
184
- if (isSeamProviderPropsWithPublishableKey(options)) {
185
- const { publishableKey, userIdentifierKey, ...clientOptions } = options
186
- return {
187
- publishableKey,
188
- userIdentifierKey,
189
- clientOptions,
190
- client: null,
191
- }
192
- }
193
-
194
- return { client: null }
124
+ const createSeamContextValue = (_options: SeamProviderProps): SeamContext => {
125
+ return {}
195
126
  }
196
127
 
197
128
  const defaultSeamContextValue = createDefaultSeamContextValue()
198
129
 
199
- export const seamContext = createContext<SeamContext>(defaultSeamContextValue)
200
-
201
- export function useSeamContext(): SeamContext {
202
- return useContext(seamContext)
203
- }
204
-
205
- const isSeamProviderPropsWithClient = (
206
- props: SeamProviderProps
207
- ): props is SeamProviderPropsWithClient => {
208
- if (!('client' in props)) return false
209
-
210
- const { client, ...otherProps } = props
211
- if (client == null) return false
212
-
213
- const otherNonNullProps = Object.values(otherProps).filter((v) => v != null)
214
- if (otherNonNullProps.length > 0) {
215
- throw new InvalidSeamProviderProps(
216
- `The client prop cannot be used with ${otherNonNullProps.join(' or ')}.`
217
- )
218
- }
219
-
220
- return true
221
- }
222
-
223
- const isSeamProviderPropsWithPublishableKey = (
224
- props: SeamProviderProps
225
- ): props is SeamProviderPropsWithPublishableKey & SeamProviderClientOptions => {
226
- if (!('publishableKey' in props)) return false
227
-
228
- const { publishableKey } = props
229
- if (publishableKey == null) return false
230
-
231
- if ('client' in props && props.client != null) {
232
- throw new InvalidSeamProviderProps(
233
- 'The client prop cannot be used with the publishableKey prop.'
234
- )
235
- }
236
-
237
- if ('clientSessionToken' in props && props.clientSessionToken != null) {
238
- throw new InvalidSeamProviderProps(
239
- 'The clientSessionToken prop cannot be used with the publishableKey prop.'
240
- )
241
- }
242
-
243
- return true
244
- }
245
-
246
- const isSeamProviderPropsWithClientSessionToken = (
247
- props: SeamProviderProps
248
- ): props is SeamProviderPropsWithClientSessionToken &
249
- SeamProviderClientOptions => {
250
- if (!('clientSessionToken' in props)) return false
251
-
252
- const { clientSessionToken } = props
253
- if (clientSessionToken == null) return false
254
-
255
- if ('client' in props && props.client != null) {
256
- throw new InvalidSeamProviderProps(
257
- 'The client prop cannot be used with the clientSessionToken prop.'
258
- )
259
- }
260
-
261
- if ('publishableKey' in props && props.publishableKey != null) {
262
- throw new InvalidSeamProviderProps(
263
- 'The publishableKey prop cannot be used with the clientSessionToken prop.'
264
- )
265
- }
266
-
267
- if ('userIdentifierKey' in props && props.userIdentifierKey != null) {
268
- throw new InvalidSeamProviderProps(
269
- 'The userIdentifierKey prop cannot be used with the clientSessionToken prop.'
270
- )
271
- }
272
-
273
- return true
274
- }
275
-
276
- class InvalidSeamProviderProps extends Error {
277
- constructor(message: string) {
278
- super(`SeamProvider received invalid props: ${message}`)
279
- this.name = this.constructor.name
280
- }
281
- }
130
+ const seamContext = createContext<SeamContext>(defaultSeamContextValue)