@seamapi/http 0.1.0 → 0.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.
Files changed (122) hide show
  1. package/dist/connect.cjs +752 -366
  2. package/dist/connect.cjs.map +1 -1
  3. package/dist/connect.d.cts +186 -142
  4. package/lib/params-serializer.d.ts +5 -0
  5. package/lib/params-serializer.js +42 -0
  6. package/lib/params-serializer.js.map +1 -0
  7. package/lib/seam/connect/auth.d.ts +3 -2
  8. package/lib/seam/connect/auth.js +55 -4
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.d.ts +10 -22
  11. package/lib/seam/connect/client.js +17 -77
  12. package/lib/seam/connect/client.js.map +1 -1
  13. package/lib/seam/connect/index.d.ts +2 -1
  14. package/lib/seam/connect/index.js +2 -1
  15. package/lib/seam/connect/index.js.map +1 -1
  16. package/lib/seam/connect/{client-options.d.ts → options.d.ts} +7 -7
  17. package/lib/seam/connect/{client-options.js → options.js} +5 -10
  18. package/lib/seam/connect/options.js.map +1 -0
  19. package/lib/seam/connect/parse-options.d.ts +6 -2
  20. package/lib/seam/connect/parse-options.js +34 -16
  21. package/lib/seam/connect/parse-options.js.map +1 -1
  22. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
  23. package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
  24. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  25. package/lib/seam/connect/routes/access-codes.d.ts +15 -14
  26. package/lib/seam/connect/routes/access-codes.js +29 -17
  27. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  28. package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
  29. package/lib/seam/connect/routes/acs-access-groups.js +26 -14
  30. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  31. package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
  32. package/lib/seam/connect/routes/acs-credentials.js +26 -14
  33. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  34. package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
  35. package/lib/seam/connect/routes/acs-systems.js +29 -17
  36. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  37. package/lib/seam/connect/routes/acs-users.d.ts +18 -11
  38. package/lib/seam/connect/routes/acs-users.js +40 -14
  39. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  40. package/lib/seam/connect/routes/acs.d.ts +5 -4
  41. package/lib/seam/connect/routes/acs.js +26 -14
  42. package/lib/seam/connect/routes/acs.js.map +1 -1
  43. package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
  44. package/lib/seam/connect/routes/action-attempts.js +26 -14
  45. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  46. package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
  47. package/lib/seam/connect/routes/client-sessions.js +33 -14
  48. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  49. package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
  50. package/lib/seam/connect/routes/connect-webviews.js +29 -17
  51. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  52. package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
  53. package/lib/seam/connect/routes/connected-accounts.js +26 -14
  54. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  55. package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
  56. package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
  57. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  58. package/lib/seam/connect/routes/devices.d.ts +10 -9
  59. package/lib/seam/connect/routes/devices.js +26 -14
  60. package/lib/seam/connect/routes/devices.js.map +1 -1
  61. package/lib/seam/connect/routes/events.d.ts +7 -6
  62. package/lib/seam/connect/routes/events.js +26 -14
  63. package/lib/seam/connect/routes/events.js.map +1 -1
  64. package/lib/seam/connect/routes/locks.d.ts +9 -8
  65. package/lib/seam/connect/routes/locks.js +26 -14
  66. package/lib/seam/connect/routes/locks.js.map +1 -1
  67. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
  68. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
  69. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  70. package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
  71. package/lib/seam/connect/routes/noise-sensors.js +26 -14
  72. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  73. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
  74. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
  75. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  76. package/lib/seam/connect/routes/thermostats.d.ts +13 -12
  77. package/lib/seam/connect/routes/thermostats.js +26 -14
  78. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  79. package/lib/seam/connect/routes/webhooks.d.ts +9 -8
  80. package/lib/seam/connect/routes/webhooks.js +26 -14
  81. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  82. package/lib/seam/connect/routes/workspaces.d.ts +8 -7
  83. package/lib/seam/connect/routes/workspaces.js +26 -14
  84. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  85. package/lib/seam/connect/seam-http.d.ts +24 -0
  86. package/lib/seam/connect/seam-http.js +82 -0
  87. package/lib/seam/connect/seam-http.js.map +1 -0
  88. package/package.json +7 -4
  89. package/src/lib/params-serializer.ts +55 -0
  90. package/src/lib/seam/connect/auth.ts +94 -6
  91. package/src/lib/seam/connect/client.ts +22 -127
  92. package/src/lib/seam/connect/env.d.ts +11 -0
  93. package/src/lib/seam/connect/index.ts +2 -1
  94. package/src/lib/seam/connect/{client-options.ts → options.ts} +13 -19
  95. package/src/lib/seam/connect/parse-options.ts +50 -23
  96. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
  97. package/src/lib/seam/connect/routes/access-codes.ts +48 -48
  98. package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
  99. package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
  100. package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
  101. package/src/lib/seam/connect/routes/acs-users.ts +70 -36
  102. package/src/lib/seam/connect/routes/acs.ts +33 -17
  103. package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
  104. package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
  105. package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
  106. package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
  107. package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
  108. package/src/lib/seam/connect/routes/devices.ts +39 -31
  109. package/src/lib/seam/connect/routes/events.ts +36 -22
  110. package/src/lib/seam/connect/routes/locks.ts +38 -28
  111. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
  112. package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
  113. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
  114. package/src/lib/seam/connect/routes/thermostats.ts +42 -40
  115. package/src/lib/seam/connect/routes/webhooks.ts +38 -28
  116. package/src/lib/seam/connect/routes/workspaces.ts +38 -25
  117. package/src/lib/seam/connect/seam-http.ts +141 -0
  118. package/lib/seam/connect/axios.d.ts +0 -3
  119. package/lib/seam/connect/axios.js +0 -19
  120. package/lib/seam/connect/axios.js.map +0 -1
  121. package/lib/seam/connect/client-options.js.map +0 -1
  122. package/src/lib/seam/connect/axios.ts +0 -25
@@ -2,34 +2,46 @@
2
2
  * Automatically generated by generate-routes.ts.
3
3
  * Do not edit this file or add other files to this directory.
4
4
  */
5
- import { createAxiosClient } from '../../../../lib/seam/connect/axios.js';
6
- import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from '../../../../lib/seam/connect/client-options.js';
5
+ import { warnOnInsecureuserIdentifierKey } from '../../../../lib/seam/connect/auth.js';
6
+ import { createClient } from '../../../../lib/seam/connect/client.js';
7
+ import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from '../../../../lib/seam/connect/options.js';
7
8
  import { parseOptions } from '../../../../lib/seam/connect/parse-options.js';
9
+ import { SeamHttpClientSessions } from './client-sessions.js';
8
10
  export class SeamHttpWorkspaces {
9
- constructor(apiKeyOrOptions) {
10
- const options = parseOptions(apiKeyOrOptions);
11
- this.client = createAxiosClient(options);
11
+ constructor(apiKeyOrOptions = {}) {
12
+ const clientOptions = parseOptions(apiKeyOrOptions);
13
+ this.client = createClient(clientOptions);
12
14
  }
13
15
  static fromClient(client, options = {}) {
14
- const opts = { ...options, client };
15
- if (!isSeamHttpOptionsWithClient(opts)) {
16
+ const constructorOptions = { ...options, client };
17
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
16
18
  throw new SeamHttpInvalidOptionsError('Missing client');
17
19
  }
18
- return new SeamHttpWorkspaces(opts);
20
+ return new SeamHttpWorkspaces(constructorOptions);
19
21
  }
20
22
  static fromApiKey(apiKey, options = {}) {
21
- const opts = { ...options, apiKey };
22
- if (!isSeamHttpOptionsWithApiKey(opts)) {
23
+ const constructorOptions = { ...options, apiKey };
24
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
23
25
  throw new SeamHttpInvalidOptionsError('Missing apiKey');
24
26
  }
25
- return new SeamHttpWorkspaces(opts);
27
+ return new SeamHttpWorkspaces(constructorOptions);
26
28
  }
27
29
  static fromClientSessionToken(clientSessionToken, options = {}) {
28
- const opts = { ...options, clientSessionToken };
29
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
30
+ const constructorOptions = { ...options, clientSessionToken };
31
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
30
32
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken');
31
33
  }
32
- return new SeamHttpWorkspaces(opts);
34
+ return new SeamHttpWorkspaces(constructorOptions);
35
+ }
36
+ static async fromPublishableKey(publishableKey, userIdentifierKey, options = {}) {
37
+ warnOnInsecureuserIdentifierKey(userIdentifierKey);
38
+ const clientOptions = parseOptions({ ...options, publishableKey });
39
+ const client = createClient(clientOptions);
40
+ const clientSessions = SeamHttpClientSessions.fromClient(client);
41
+ const { token } = await clientSessions.getOrCreate({
42
+ user_identifier_key: userIdentifierKey,
43
+ });
44
+ return SeamHttpWorkspaces.fromClientSessionToken(token, options);
33
45
  }
34
46
  async get(params) {
35
47
  const { data } = await this.client.request({
@@ -1 +1 @@
1
- {"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../../../src/lib/seam/connect/routes/workspaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,uCAAuC,EACvC,2BAA2B,GAK5B,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAEhE,MAAM,OAAO,kBAAkB;IAG7B,YAAY,eAAyC;QACnD,MAAM,OAAO,GAAG,YAAY,CAAC,eAAe,CAAC,CAAA;QAC7C,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,CAAC,UAAU,CACf,MAA2C,EAC3C,UAAqD,EAAE;QAEvD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QACnC,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE;YACtC,MAAM,IAAI,2BAA2B,CAAC,gBAAgB,CAAC,CAAA;SACxD;QACD,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CAAC,UAAU,CACf,MAA2C,EAC3C,UAAqD,EAAE;QAEvD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QACnC,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE;YACtC,MAAM,IAAI,2BAA2B,CAAC,gBAAgB,CAAC,CAAA;SACxD;QACD,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CAAC,sBAAsB,CAC3B,kBAA+E,EAC/E,UAGI,EAAE;QAEN,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,kBAAkB,EAAE,CAAA;QAC/C,IAAI,CAAC,uCAAuC,CAAC,IAAI,CAAC,EAAE;YAClD,MAAM,IAAI,2BAA2B,CAAC,4BAA4B,CAAC,CAAA;SACpE;QACD,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,MAA4B;QAE5B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAwB;YAChE,GAAG,EAAE,iBAAiB;YACtB,MAAM,EAAE,KAAK;YACb,MAAM;SACP,CAAC,CAAA;QACF,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,MAA6B;QAE7B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAyB;YACjE,GAAG,EAAE,kBAAkB;YACvB,MAAM,EAAE,KAAK;YACb,MAAM;SACP,CAAC,CAAA;QACF,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAgC;QACjD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAiC;YACxD,GAAG,EAAE,2BAA2B;YAChC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../../../src/lib/seam/connect/routes/workspaces.ts"],"names":[],"mappings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;QACjD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAiC;YACxD,GAAG,EAAE,2BAA2B;YAChC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import { type Client } from './client.js';
2
+ import { type SeamHttpFromPublishableKeyOptions, type SeamHttpOptions, type SeamHttpOptionsWithApiKey, type SeamHttpOptionsWithClient, type SeamHttpOptionsWithClientSessionToken } from './options.js';
3
+ import { SeamHttpAccessCodes, SeamHttpAcs, SeamHttpActionAttempts, SeamHttpClientSessions, SeamHttpConnectedAccounts, SeamHttpConnectWebviews, SeamHttpDevices, SeamHttpEvents, SeamHttpLocks, SeamHttpNoiseSensors, SeamHttpThermostats, SeamHttpWebhooks, SeamHttpWorkspaces } from './routes/index.js';
4
+ export declare class SeamHttp {
5
+ client: Client;
6
+ constructor(apiKeyOrOptions?: string | SeamHttpOptions);
7
+ static fromClient(client: SeamHttpOptionsWithClient['client'], options?: Omit<SeamHttpOptionsWithClient, 'client'>): SeamHttp;
8
+ static fromApiKey(apiKey: SeamHttpOptionsWithApiKey['apiKey'], options?: Omit<SeamHttpOptionsWithApiKey, 'apiKey'>): SeamHttp;
9
+ static fromClientSessionToken(clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options?: Omit<SeamHttpOptionsWithClientSessionToken, 'clientSessionToken'>): SeamHttp;
10
+ static fromPublishableKey(publishableKey: string, userIdentifierKey: string, options?: SeamHttpFromPublishableKeyOptions): Promise<SeamHttp>;
11
+ get accessCodes(): SeamHttpAccessCodes;
12
+ get acs(): SeamHttpAcs;
13
+ get actionAttempts(): SeamHttpActionAttempts;
14
+ get clientSessions(): SeamHttpClientSessions;
15
+ get connectedAccounts(): SeamHttpConnectedAccounts;
16
+ get connectWebviews(): SeamHttpConnectWebviews;
17
+ get devices(): SeamHttpDevices;
18
+ get events(): SeamHttpEvents;
19
+ get locks(): SeamHttpLocks;
20
+ get noiseSensors(): SeamHttpNoiseSensors;
21
+ get thermostats(): SeamHttpThermostats;
22
+ get webhooks(): SeamHttpWebhooks;
23
+ get workspaces(): SeamHttpWorkspaces;
24
+ }
@@ -0,0 +1,82 @@
1
+ import { warnOnInsecureuserIdentifierKey } from './auth.js';
2
+ import { createClient } from './client.js';
3
+ import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from './options.js';
4
+ import { parseOptions } from './parse-options.js';
5
+ import { SeamHttpAccessCodes, SeamHttpAcs, SeamHttpActionAttempts, SeamHttpClientSessions, SeamHttpConnectedAccounts, SeamHttpConnectWebviews, SeamHttpDevices, SeamHttpEvents, SeamHttpLocks, SeamHttpNoiseSensors, SeamHttpThermostats, SeamHttpWebhooks, SeamHttpWorkspaces, } from './routes/index.js';
6
+ export class SeamHttp {
7
+ constructor(apiKeyOrOptions = {}) {
8
+ const clientOptions = parseOptions(apiKeyOrOptions);
9
+ this.client = createClient(clientOptions);
10
+ }
11
+ static fromClient(client, options = {}) {
12
+ const constructorOptions = { ...options, client };
13
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
14
+ throw new SeamHttpInvalidOptionsError('Missing client');
15
+ }
16
+ return new SeamHttp(constructorOptions);
17
+ }
18
+ static fromApiKey(apiKey, options = {}) {
19
+ const constructorOptions = { ...options, apiKey };
20
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
21
+ throw new SeamHttpInvalidOptionsError('Missing apiKey');
22
+ }
23
+ return new SeamHttp(constructorOptions);
24
+ }
25
+ static fromClientSessionToken(clientSessionToken, options = {}) {
26
+ const constructorOptions = { ...options, clientSessionToken };
27
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
28
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken');
29
+ }
30
+ return new SeamHttp(constructorOptions);
31
+ }
32
+ static async fromPublishableKey(publishableKey, userIdentifierKey, options = {}) {
33
+ warnOnInsecureuserIdentifierKey(userIdentifierKey);
34
+ const clientOptions = parseOptions({ ...options, publishableKey });
35
+ const client = createClient(clientOptions);
36
+ const clientSessions = SeamHttpClientSessions.fromClient(client);
37
+ const { token } = await clientSessions.getOrCreate({
38
+ user_identifier_key: userIdentifierKey,
39
+ });
40
+ return SeamHttp.fromClientSessionToken(token, options);
41
+ }
42
+ get accessCodes() {
43
+ return SeamHttpAccessCodes.fromClient(this.client);
44
+ }
45
+ get acs() {
46
+ return SeamHttpAcs.fromClient(this.client);
47
+ }
48
+ get actionAttempts() {
49
+ return SeamHttpActionAttempts.fromClient(this.client);
50
+ }
51
+ get clientSessions() {
52
+ return SeamHttpClientSessions.fromClient(this.client);
53
+ }
54
+ get connectedAccounts() {
55
+ return SeamHttpConnectedAccounts.fromClient(this.client);
56
+ }
57
+ get connectWebviews() {
58
+ return SeamHttpConnectWebviews.fromClient(this.client);
59
+ }
60
+ get devices() {
61
+ return SeamHttpDevices.fromClient(this.client);
62
+ }
63
+ get events() {
64
+ return SeamHttpEvents.fromClient(this.client);
65
+ }
66
+ get locks() {
67
+ return SeamHttpLocks.fromClient(this.client);
68
+ }
69
+ get noiseSensors() {
70
+ return SeamHttpNoiseSensors.fromClient(this.client);
71
+ }
72
+ get thermostats() {
73
+ return SeamHttpThermostats.fromClient(this.client);
74
+ }
75
+ get webhooks() {
76
+ return SeamHttpWebhooks.fromClient(this.client);
77
+ }
78
+ get workspaces() {
79
+ return SeamHttpWorkspaces.fromClient(this.client);
80
+ }
81
+ }
82
+ //# sourceMappingURL=seam-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seam-http.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/seam-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,uCAA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,IAAI,CAAC,MAAM,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,YAAY;QACd,OAAO,oBAAoB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,mBAAmB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACnD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamapi/http",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "JavaScript HTTP client for the Seam API written in TypeScript.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -84,15 +84,17 @@
84
84
  }
85
85
  },
86
86
  "dependencies": {
87
- "axios": "^1.5.0"
87
+ "axios": "^1.5.0",
88
+ "axios-retry": "^3.8.0"
88
89
  },
89
90
  "devDependencies": {
90
- "@seamapi/types": "^1.14.0",
91
+ "@seamapi/fake-seam-connect": "^1.21.0",
92
+ "@seamapi/types": "^1.24.0",
91
93
  "@types/eslint": "^8.44.2",
92
94
  "@types/node": "^18.11.18",
93
95
  "ava": "^5.0.1",
94
96
  "c8": "^8.0.0",
95
- "change-case": "^4.1.2",
97
+ "change-case": "^5.0.2",
96
98
  "concurrently": "^8.2.1",
97
99
  "del-cli": "^5.0.0",
98
100
  "eslint": "^8.9.0",
@@ -102,6 +104,7 @@
102
104
  "eslint-plugin-simple-import-sort": "^10.0.0",
103
105
  "eslint-plugin-unused-imports": "^3.0.0",
104
106
  "landlubber": "^1.0.0",
107
+ "node-fetch": "^3.3.2",
105
108
  "prettier": "^3.0.0",
106
109
  "tsc-alias": "^1.8.2",
107
110
  "tsup": "^7.2.0",
@@ -0,0 +1,55 @@
1
+ import type { CustomParamsSerializer } from 'axios'
2
+
3
+ export const paramsSerializer: CustomParamsSerializer = (params) => {
4
+ const searchParams = new URLSearchParams()
5
+
6
+ for (const [name, value] of Object.entries(params)) {
7
+ if (value == null) continue
8
+
9
+ if (Array.isArray(value)) {
10
+ if (value.length === 0) searchParams.set(name, '')
11
+ if (value.length === 1 && value[0] === '') {
12
+ throw new UnserializableParamError(
13
+ name,
14
+ `is a single element array containing the empty string which is unsupported because it serializes to the empty array`,
15
+ )
16
+ }
17
+ for (const v of value) {
18
+ throwIfUnserializable(name, v)
19
+ searchParams.append(name, v)
20
+ }
21
+ continue
22
+ }
23
+
24
+ throwIfUnserializable(name, value)
25
+ searchParams.set(name, value)
26
+ }
27
+
28
+ searchParams.sort()
29
+ return searchParams.toString()
30
+ }
31
+
32
+ const throwIfUnserializable = (k: string, v: unknown): void => {
33
+ if (v == null) {
34
+ throw new UnserializableParamError(k, `is ${v} or contains ${v}`)
35
+ }
36
+
37
+ if (typeof v === 'function') {
38
+ throw new UnserializableParamError(
39
+ k,
40
+ 'is a function or contains a function',
41
+ )
42
+ }
43
+
44
+ if (typeof v === 'object') {
45
+ throw new UnserializableParamError(k, 'is an object or contains an object')
46
+ }
47
+ }
48
+
49
+ export class UnserializableParamError extends Error {
50
+ constructor(name: string, message: string) {
51
+ super(`Could not serialize parameter: '${name}' ${message}`)
52
+ this.name = this.constructor.name
53
+ Error.captureStackTrace(this, this.constructor)
54
+ }
55
+ }
@@ -2,14 +2,18 @@ import {
2
2
  isSeamHttpOptionsWithApiKey,
3
3
  isSeamHttpOptionsWithClientSessionToken,
4
4
  SeamHttpInvalidOptionsError,
5
- type SeamHttpOptions,
6
5
  type SeamHttpOptionsWithApiKey,
7
6
  type SeamHttpOptionsWithClientSessionToken,
8
- } from './client-options.js'
7
+ } from './options.js'
8
+ import type { Options } from './parse-options.js'
9
9
 
10
10
  type Headers = Record<string, string>
11
11
 
12
- export const getAuthHeaders = (options: SeamHttpOptions): Headers => {
12
+ export const getAuthHeaders = (options: Options): Headers => {
13
+ if ('publishableKey' in options) {
14
+ return getAuthHeadersForPublishableKey(options.publishableKey)
15
+ }
16
+
13
17
  if (isSeamHttpOptionsWithApiKey(options)) {
14
18
  return getAuthHeadersForApiKey(options)
15
19
  }
@@ -19,7 +23,7 @@ export const getAuthHeaders = (options: SeamHttpOptions): Headers => {
19
23
  }
20
24
 
21
25
  throw new SeamHttpInvalidOptionsError(
22
- 'Must specify an apiKey or clientSessionToken',
26
+ 'Must specify an apiKey, clientSessionToken, or publishableKey',
23
27
  )
24
28
  }
25
29
 
@@ -32,13 +36,23 @@ const getAuthHeadersForApiKey = ({
32
36
  )
33
37
  }
34
38
 
39
+ if (isJwt(apiKey)) {
40
+ throw new SeamHttpInvalidTokenError('A JWT cannot be used as an apiKey')
41
+ }
42
+
35
43
  if (isAccessToken(apiKey)) {
36
44
  throw new SeamHttpInvalidTokenError(
37
- 'An access token cannot be used as an apiKey',
45
+ 'An Access Token cannot be used as an apiKey',
46
+ )
47
+ }
48
+
49
+ if (isPublishableKey(apiKey)) {
50
+ throw new SeamHttpInvalidTokenError(
51
+ 'A Publishable Key cannot be used as an apiKey',
38
52
  )
39
53
  }
40
54
 
41
- if (isJwt(apiKey) || !isSeamToken(apiKey)) {
55
+ if (!isSeamToken(apiKey)) {
42
56
  throw new SeamHttpInvalidTokenError(
43
57
  `Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`,
44
58
  )
@@ -52,6 +66,24 @@ const getAuthHeadersForApiKey = ({
52
66
  const getAuthHeadersForClientSessionToken = ({
53
67
  clientSessionToken,
54
68
  }: SeamHttpOptionsWithClientSessionToken): Headers => {
69
+ if (isJwt(clientSessionToken)) {
70
+ throw new SeamHttpInvalidTokenError(
71
+ 'A JWT cannot be used as a clientSessionToken',
72
+ )
73
+ }
74
+
75
+ if (isAccessToken(clientSessionToken)) {
76
+ throw new SeamHttpInvalidTokenError(
77
+ 'An Access Token cannot be used as a clientSessionToken',
78
+ )
79
+ }
80
+
81
+ if (isPublishableKey(clientSessionToken)) {
82
+ throw new SeamHttpInvalidTokenError(
83
+ 'A Publishable Key cannot be used as a clientSessionToken',
84
+ )
85
+ }
86
+
55
87
  if (!isClientSessionToken(clientSessionToken)) {
56
88
  throw new SeamHttpInvalidTokenError(
57
89
  `Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`,
@@ -64,6 +96,36 @@ const getAuthHeadersForClientSessionToken = ({
64
96
  }
65
97
  }
66
98
 
99
+ const getAuthHeadersForPublishableKey = (publishableKey: string): Headers => {
100
+ if (isJwt(publishableKey)) {
101
+ throw new SeamHttpInvalidTokenError(
102
+ 'A JWT cannot be used as a publishableKey',
103
+ )
104
+ }
105
+
106
+ if (isAccessToken(publishableKey)) {
107
+ throw new SeamHttpInvalidTokenError(
108
+ 'An Access Token cannot be used as a publishableKey',
109
+ )
110
+ }
111
+
112
+ if (isClientSessionToken(publishableKey)) {
113
+ throw new SeamHttpInvalidTokenError(
114
+ 'A Client Session Token Key cannot be used as a publishableKey',
115
+ )
116
+ }
117
+
118
+ if (!isPublishableKey(publishableKey)) {
119
+ throw new SeamHttpInvalidTokenError(
120
+ `Unknown or invalid publishableKey format, expected token to start with ${publishableKeyTokenPrefix}`,
121
+ )
122
+ }
123
+
124
+ return {
125
+ 'seam-publishable-key': publishableKey,
126
+ }
127
+ }
128
+
67
129
  export class SeamHttpInvalidTokenError extends Error {
68
130
  constructor(message: string) {
69
131
  super(`SeamHttp received an invalid token: ${message}`)
@@ -72,10 +134,29 @@ export class SeamHttpInvalidTokenError extends Error {
72
134
  }
73
135
  }
74
136
 
137
+ export const warnOnInsecureuserIdentifierKey = (
138
+ userIdentifierKey: string,
139
+ ): void => {
140
+ if (isEmail(userIdentifierKey)) {
141
+ // eslint-disable-next-line no-console
142
+ console.warn(
143
+ ...[
144
+ 'Using an email for the userIdentifierKey is insecure and may return an error in the future!',
145
+ 'This is insecure because an email is common knowledge or easily guessed.',
146
+ 'Use something with sufficient entropy known only to the owner of the client session.',
147
+ 'For help choosing a user identifier key see',
148
+ 'https://docs.seam.co/latest/seam-components/overview/get-started-with-client-side-components#3-select-a-user-identifier-key',
149
+ ],
150
+ )
151
+ }
152
+ }
153
+
75
154
  const tokenPrefix = 'seam_'
76
155
 
77
156
  const clientSessionTokenPrefix = 'seam_cst'
78
157
 
158
+ const publishableKeyTokenPrefix = 'seam_pk'
159
+
79
160
  const isClientSessionToken = (token: string): boolean =>
80
161
  token.startsWith(clientSessionTokenPrefix)
81
162
 
@@ -84,3 +165,10 @@ const isAccessToken = (token: string): boolean => token.startsWith('seam_at')
84
165
  const isJwt = (token: string): boolean => token.startsWith('ey')
85
166
 
86
167
  const isSeamToken = (token: string): boolean => token.startsWith(tokenPrefix)
168
+
169
+ const isPublishableKey = (token: string): boolean =>
170
+ token.startsWith(publishableKeyTokenPrefix)
171
+
172
+ // SOURCE: https://stackoverflow.com/a/46181
173
+ const isEmail = (value: string): boolean =>
174
+ /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
@@ -1,136 +1,31 @@
1
- import type { Axios } from 'axios'
1
+ import axios, { type Axios, type AxiosRequestConfig } from 'axios'
2
+ import axiosRetry, { type AxiosRetry, exponentialDelay } from 'axios-retry'
2
3
 
3
- import { createAxiosClient } from './axios.js'
4
- import {
5
- isSeamHttpOptionsWithApiKey,
6
- isSeamHttpOptionsWithClient,
7
- isSeamHttpOptionsWithClientSessionToken,
8
- SeamHttpInvalidOptionsError,
9
- type SeamHttpOptions,
10
- type SeamHttpOptionsWithApiKey,
11
- type SeamHttpOptionsWithClient,
12
- type SeamHttpOptionsWithClientSessionToken,
13
- } from './client-options.js'
14
- import { parseOptions } from './parse-options.js'
15
- import {
16
- SeamHttpAccessCodes,
17
- SeamHttpAcs,
18
- SeamHttpActionAttempts,
19
- SeamHttpClientSessions,
20
- SeamHttpConnectedAccounts,
21
- SeamHttpConnectWebviews,
22
- SeamHttpDevices,
23
- SeamHttpEvents,
24
- SeamHttpLocks,
25
- SeamHttpNoiseSensors,
26
- SeamHttpThermostats,
27
- SeamHttpWebhooks,
28
- SeamHttpWorkspaces,
29
- } from './routes/index.js'
4
+ import { paramsSerializer } from 'lib/params-serializer.js'
30
5
 
31
- export class SeamHttp {
32
- client: Axios
6
+ export type Client = Axios
33
7
 
34
- // #legacy: boolean
35
-
36
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
37
- const options = parseOptions(apiKeyOrOptions)
38
- // this.#legacy = options.enableLegacyMethodBehaivor
39
- this.client = createAxiosClient(options)
40
- }
41
-
42
- static fromClient(
43
- client: SeamHttpOptionsWithClient['client'],
44
- options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
45
- ): SeamHttp {
46
- const opts = { ...options, client }
47
- if (!isSeamHttpOptionsWithClient(opts)) {
48
- throw new SeamHttpInvalidOptionsError('Missing client')
49
- }
50
- return new SeamHttp(opts)
51
- }
52
-
53
- static fromApiKey(
54
- apiKey: SeamHttpOptionsWithApiKey['apiKey'],
55
- options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
56
- ): SeamHttp {
57
- const opts = { ...options, apiKey }
58
- if (!isSeamHttpOptionsWithApiKey(opts)) {
59
- throw new SeamHttpInvalidOptionsError('Missing apiKey')
60
- }
61
- return new SeamHttp(opts)
62
- }
63
-
64
- static fromClientSessionToken(
65
- clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
66
- options: Omit<
67
- SeamHttpOptionsWithClientSessionToken,
68
- 'clientSessionToken'
69
- > = {},
70
- ): SeamHttp {
71
- const opts = { ...options, clientSessionToken }
72
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
73
- throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
74
- }
75
- return new SeamHttp(opts)
76
- }
77
-
78
- get accessCodes(): SeamHttpAccessCodes {
79
- return SeamHttpAccessCodes.fromClient(this.client)
80
- }
81
-
82
- get acs(): SeamHttpAcs {
83
- return SeamHttpAcs.fromClient(this.client)
84
- }
85
-
86
- get actionAttempts(): SeamHttpActionAttempts {
87
- return SeamHttpActionAttempts.fromClient(this.client)
88
- }
89
-
90
- get clientSessions(): SeamHttpClientSessions {
91
- return SeamHttpClientSessions.fromClient(this.client)
92
- }
93
-
94
- get connectedAccounts(): SeamHttpConnectedAccounts {
95
- return SeamHttpConnectedAccounts.fromClient(this.client)
96
- }
97
-
98
- get connectWebviews(): SeamHttpConnectWebviews {
99
- return SeamHttpConnectWebviews.fromClient(this.client)
100
- }
101
-
102
- get devices(): SeamHttpDevices {
103
- return SeamHttpDevices.fromClient(this.client)
104
- }
105
-
106
- get events(): SeamHttpEvents {
107
- return SeamHttpEvents.fromClient(this.client)
108
- }
8
+ export interface ClientOptions {
9
+ axiosOptions?: AxiosRequestConfig
10
+ axiosRetryOptions?: AxiosRetryConfig
11
+ client?: Client
12
+ }
109
13
 
110
- get locks(): SeamHttpLocks {
111
- return SeamHttpLocks.fromClient(this.client)
112
- }
14
+ type AxiosRetryConfig = Parameters<AxiosRetry>[1]
113
15
 
114
- get noiseSensors(): SeamHttpNoiseSensors {
115
- return SeamHttpNoiseSensors.fromClient(this.client)
116
- }
16
+ export const createClient = (options: ClientOptions): Axios => {
17
+ if (options.client != null) return options.client
117
18
 
118
- get thermostats(): SeamHttpThermostats {
119
- return SeamHttpThermostats.fromClient(this.client)
120
- }
19
+ const client = axios.create({
20
+ paramsSerializer,
21
+ ...options.axiosOptions,
22
+ })
121
23
 
122
- get webhooks(): SeamHttpWebhooks {
123
- return SeamHttpWebhooks.fromClient(this.client)
124
- }
24
+ axiosRetry(client, {
25
+ retries: 2,
26
+ retryDelay: exponentialDelay,
27
+ ...options.axiosRetryOptions,
28
+ })
125
29
 
126
- get workspaces(): SeamHttpWorkspaces {
127
- return SeamHttpWorkspaces.fromClient(this.client)
128
- }
30
+ return client
129
31
  }
130
-
131
- // TODO
132
- // static fromPublishableKey and deprecate getClientSessionToken
133
-
134
- // TODO: Should we keep makeRequest?
135
- // Better to implement error handling and wrapping in an error handler.
136
- // makeRequest
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ namespace NodeJS {
3
+ interface ProcessEnv {
4
+ SEAM_API_KEY?: string
5
+ SEAM_API_URL?: string
6
+ SEAM_ENDPOINT?: string
7
+ }
8
+ }
9
+ }
10
+
11
+ export {}
@@ -1 +1,2 @@
1
- export * from './client.js'
1
+ export * from './options.js'
2
+ export * from './seam-http.js'