From dc3fc1222fb2dc3e9f2bce73f1b4d1c8bb945b4f Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 31 Mar 2023 21:46:04 -0600 Subject: [PATCH 01/30] add method for seam components --- docs/classes/Seam.md | 30 ++++++++- .../AccessCodeCreateMultipleResponse.md | 2 +- docs/interfaces/AccessCodeCreateResponse.md | 4 +- docs/interfaces/AccessCodeGetResponse.md | 2 +- docs/interfaces/AccessCodesListResponse.md | 2 +- .../interfaces/ActionAttemptCreateResponse.md | 2 +- docs/interfaces/ActionAttemptGetResponse.md | 2 +- docs/interfaces/ClientAccessTokenInterface.md | 63 +++++++++++++++++++ .../ClientAccessTokenResponseInterface.md | 19 ++++++ .../ConnectWebviewCreateResponse.md | 2 +- docs/interfaces/ConnectWebviewGetResponse.md | 2 +- .../interfaces/ConnectWebviewsListResponse.md | 2 +- .../ConnectedAccountsGetResponse.md | 2 +- .../ConnectedAccountsListResponse.md | 2 +- docs/interfaces/DeviceGetResponse.md | 2 +- .../interfaces/DeviceProvidersListResponse.md | 2 +- docs/interfaces/DevicesListResponse.md | 2 +- docs/interfaces/EventsListResponse.md | 2 +- docs/interfaces/LockGetResponse.md | 2 +- docs/interfaces/LocksListResponse.md | 2 +- docs/interfaces/SeamClientOptions.md | 8 +-- .../UnmanagedAccessCodesListResponse.md | 2 +- .../interfaces/UnmanagedDeviceListResponse.md | 2 +- docs/interfaces/WebhookGetResponse.md | 2 +- docs/interfaces/WebhookListResponse.md | 2 +- docs/interfaces/WorkspaceGetResponse.md | 2 +- .../WorkspaceResetSandboxResponse.md | 2 +- docs/interfaces/WorkspacesListResponse.md | 2 +- docs/modules.md | 4 +- src/seam-connect/client.ts | 23 ++++++- src/types/models.ts | 8 +++ src/types/route-responses.ts | 5 ++ 32 files changed, 176 insertions(+), 34 deletions(-) create mode 100644 docs/interfaces/ClientAccessTokenInterface.md create mode 100644 docs/interfaces/ClientAccessTokenResponseInterface.md diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 665d823d..f3e2f977 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -30,6 +30,7 @@ ### Methods - [makeRequest](Seam.md#makerequest) +- [getClientAccessToken](Seam.md#getclientaccesstoken) ## Constructors @@ -49,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:52](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L52) +[src/seam-connect/client.ts:57](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L57) ## Properties @@ -106,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:50](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L50) +[src/seam-connect/client.ts:55](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L55) ___ @@ -296,4 +297,27 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:90](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L90) +[src/seam-connect/client.ts:95](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L95) + +___ + +### getClientAccessToken + +▸ `Static` **getClientAccessToken**(`pubKey`, `extHostUserId`, `endpoint`, `workspaceId?`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `pubKey` | `string` | +| `extHostUserId` | `string` | +| `endpoint` | `string` | +| `workspaceId?` | `string` | + +#### Returns + +`Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> + +#### Defined in + +[src/seam-connect/client.ts:119](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L119) diff --git a/docs/interfaces/AccessCodeCreateMultipleResponse.md b/docs/interfaces/AccessCodeCreateMultipleResponse.md index 753283b0..4f48d8a8 100644 --- a/docs/interfaces/AccessCodeCreateMultipleResponse.md +++ b/docs/interfaces/AccessCodeCreateMultipleResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:84](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L84) +[src/types/route-responses.ts:85](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L85) diff --git a/docs/interfaces/AccessCodeCreateResponse.md b/docs/interfaces/AccessCodeCreateResponse.md index cf200cfd..489875f1 100644 --- a/docs/interfaces/AccessCodeCreateResponse.md +++ b/docs/interfaces/AccessCodeCreateResponse.md @@ -29,7 +29,7 @@ #### Defined in -[src/types/route-responses.ts:77](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L77) +[src/types/route-responses.ts:78](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L78) ___ @@ -43,4 +43,4 @@ ___ #### Defined in -[src/types/route-responses.ts:118](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L118) +[src/types/route-responses.ts:119](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L119) diff --git a/docs/interfaces/AccessCodeGetResponse.md b/docs/interfaces/AccessCodeGetResponse.md index 89e075d6..f4051e32 100644 --- a/docs/interfaces/AccessCodeGetResponse.md +++ b/docs/interfaces/AccessCodeGetResponse.md @@ -22,4 +22,4 @@ #### Defined in -[src/types/route-responses.ts:77](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L77) +[src/types/route-responses.ts:78](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L78) diff --git a/docs/interfaces/AccessCodesListResponse.md b/docs/interfaces/AccessCodesListResponse.md index 49179e29..f66a09f5 100644 --- a/docs/interfaces/AccessCodesListResponse.md +++ b/docs/interfaces/AccessCodesListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:74](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L74) +[src/types/route-responses.ts:75](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L75) diff --git a/docs/interfaces/ActionAttemptCreateResponse.md b/docs/interfaces/ActionAttemptCreateResponse.md index 347de9ed..e3821aea 100644 --- a/docs/interfaces/ActionAttemptCreateResponse.md +++ b/docs/interfaces/ActionAttemptCreateResponse.md @@ -22,4 +22,4 @@ #### Defined in -[src/types/route-responses.ts:114](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L114) +[src/types/route-responses.ts:115](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L115) diff --git a/docs/interfaces/ActionAttemptGetResponse.md b/docs/interfaces/ActionAttemptGetResponse.md index 73211bb5..c63e89af 100644 --- a/docs/interfaces/ActionAttemptGetResponse.md +++ b/docs/interfaces/ActionAttemptGetResponse.md @@ -28,4 +28,4 @@ #### Defined in -[src/types/route-responses.ts:118](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L118) +[src/types/route-responses.ts:119](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L119) diff --git a/docs/interfaces/ClientAccessTokenInterface.md b/docs/interfaces/ClientAccessTokenInterface.md new file mode 100644 index 00000000..4dc9a693 --- /dev/null +++ b/docs/interfaces/ClientAccessTokenInterface.md @@ -0,0 +1,63 @@ +[seamapi](../README.md) / [Exports](../modules.md) / ClientAccessTokenInterface + +# Interface: ClientAccessTokenInterface + +## Table of contents + +### Properties + +- [client\_access\_token\_id](ClientAccessTokenInterface.md#client_access_token_id) +- [created\_at](ClientAccessTokenInterface.md#created_at) +- [short\_token](ClientAccessTokenInterface.md#short_token) +- [token](ClientAccessTokenInterface.md#token) +- [user\_id](ClientAccessTokenInterface.md#user_id) + +## Properties + +### client\_access\_token\_id + +• **client\_access\_token\_id**: `string` + +#### Defined in + +[src/types/models.ts:290](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L290) + +___ + +### created\_at + +• **created\_at**: `string` + +#### Defined in + +[src/types/models.ts:294](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L294) + +___ + +### short\_token + +• **short\_token**: `string` + +#### Defined in + +[src/types/models.ts:292](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L292) + +___ + +### token + +• **token**: `string` + +#### Defined in + +[src/types/models.ts:291](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L291) + +___ + +### user\_id + +• **user\_id**: `string` + +#### Defined in + +[src/types/models.ts:293](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L293) diff --git a/docs/interfaces/ClientAccessTokenResponseInterface.md b/docs/interfaces/ClientAccessTokenResponseInterface.md new file mode 100644 index 00000000..68a7af12 --- /dev/null +++ b/docs/interfaces/ClientAccessTokenResponseInterface.md @@ -0,0 +1,19 @@ +[seamapi](../README.md) / [Exports](../modules.md) / ClientAccessTokenResponseInterface + +# Interface: ClientAccessTokenResponseInterface + +## Table of contents + +### Properties + +- [client\_access\_token](ClientAccessTokenResponseInterface.md#client_access_token) + +## Properties + +### client\_access\_token + +• **client\_access\_token**: [`ClientAccessTokenInterface`](ClientAccessTokenInterface.md) + +#### Defined in + +[src/types/route-responses.ts:128](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L128) diff --git a/docs/interfaces/ConnectWebviewCreateResponse.md b/docs/interfaces/ConnectWebviewCreateResponse.md index 6c7aeaa0..35c30348 100644 --- a/docs/interfaces/ConnectWebviewCreateResponse.md +++ b/docs/interfaces/ConnectWebviewCreateResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:66](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L66) +[src/types/route-responses.ts:67](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L67) diff --git a/docs/interfaces/ConnectWebviewGetResponse.md b/docs/interfaces/ConnectWebviewGetResponse.md index 66b518ce..457fc9f9 100644 --- a/docs/interfaces/ConnectWebviewGetResponse.md +++ b/docs/interfaces/ConnectWebviewGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:63](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L63) +[src/types/route-responses.ts:64](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L64) diff --git a/docs/interfaces/ConnectWebviewsListResponse.md b/docs/interfaces/ConnectWebviewsListResponse.md index 5add8efc..e898fef5 100644 --- a/docs/interfaces/ConnectWebviewsListResponse.md +++ b/docs/interfaces/ConnectWebviewsListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:60](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L60) +[src/types/route-responses.ts:61](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L61) diff --git a/docs/interfaces/ConnectedAccountsGetResponse.md b/docs/interfaces/ConnectedAccountsGetResponse.md index a846b3ca..9714f03d 100644 --- a/docs/interfaces/ConnectedAccountsGetResponse.md +++ b/docs/interfaces/ConnectedAccountsGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:97](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L97) +[src/types/route-responses.ts:98](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L98) diff --git a/docs/interfaces/ConnectedAccountsListResponse.md b/docs/interfaces/ConnectedAccountsListResponse.md index ad654a84..3f095b6d 100644 --- a/docs/interfaces/ConnectedAccountsListResponse.md +++ b/docs/interfaces/ConnectedAccountsListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:94](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L94) +[src/types/route-responses.ts:95](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L95) diff --git a/docs/interfaces/DeviceGetResponse.md b/docs/interfaces/DeviceGetResponse.md index 2eac80c0..f2f6d922 100644 --- a/docs/interfaces/DeviceGetResponse.md +++ b/docs/interfaces/DeviceGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:45](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L45) +[src/types/route-responses.ts:46](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L46) diff --git a/docs/interfaces/DeviceProvidersListResponse.md b/docs/interfaces/DeviceProvidersListResponse.md index 74640480..28ec7c02 100644 --- a/docs/interfaces/DeviceProvidersListResponse.md +++ b/docs/interfaces/DeviceProvidersListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:55](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L55) +[src/types/route-responses.ts:56](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L56) diff --git a/docs/interfaces/DevicesListResponse.md b/docs/interfaces/DevicesListResponse.md index 042aab09..e944f5cb 100644 --- a/docs/interfaces/DevicesListResponse.md +++ b/docs/interfaces/DevicesListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:42](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L42) +[src/types/route-responses.ts:43](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L43) diff --git a/docs/interfaces/EventsListResponse.md b/docs/interfaces/EventsListResponse.md index 4f45293c..754c7233 100644 --- a/docs/interfaces/EventsListResponse.md +++ b/docs/interfaces/EventsListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:123](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L123) +[src/types/route-responses.ts:124](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L124) diff --git a/docs/interfaces/LockGetResponse.md b/docs/interfaces/LockGetResponse.md index 45fcdd1d..437bc20e 100644 --- a/docs/interfaces/LockGetResponse.md +++ b/docs/interfaces/LockGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:37](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L37) +[src/types/route-responses.ts:38](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L38) diff --git a/docs/interfaces/LocksListResponse.md b/docs/interfaces/LocksListResponse.md index cdde2437..30e4bdea 100644 --- a/docs/interfaces/LocksListResponse.md +++ b/docs/interfaces/LocksListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:33](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L33) +[src/types/route-responses.ts:34](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L34) diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index 0ea2097d..34bec640 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -19,7 +19,7 @@ #### Defined in -[src/seam-connect/client.ts:10](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L10) +[src/seam-connect/client.ts:15](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L15) ___ @@ -31,7 +31,7 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:23](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L23) +[src/seam-connect/client.ts:28](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L28) ___ @@ -43,7 +43,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:14](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L14) +[src/seam-connect/client.ts:19](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L19) ___ @@ -56,4 +56,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:19](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L19) +[src/seam-connect/client.ts:24](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L24) diff --git a/docs/interfaces/UnmanagedAccessCodesListResponse.md b/docs/interfaces/UnmanagedAccessCodesListResponse.md index d47094c9..4611321f 100644 --- a/docs/interfaces/UnmanagedAccessCodesListResponse.md +++ b/docs/interfaces/UnmanagedAccessCodesListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:89](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L89) +[src/types/route-responses.ts:90](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L90) diff --git a/docs/interfaces/UnmanagedDeviceListResponse.md b/docs/interfaces/UnmanagedDeviceListResponse.md index 318226d0..ae530d76 100644 --- a/docs/interfaces/UnmanagedDeviceListResponse.md +++ b/docs/interfaces/UnmanagedDeviceListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:50](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L50) +[src/types/route-responses.ts:51](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L51) diff --git a/docs/interfaces/WebhookGetResponse.md b/docs/interfaces/WebhookGetResponse.md index 888d44c9..c7451b48 100644 --- a/docs/interfaces/WebhookGetResponse.md +++ b/docs/interfaces/WebhookGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:106](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L106) +[src/types/route-responses.ts:107](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L107) diff --git a/docs/interfaces/WebhookListResponse.md b/docs/interfaces/WebhookListResponse.md index 5ff4015e..ce6f6eb0 100644 --- a/docs/interfaces/WebhookListResponse.md +++ b/docs/interfaces/WebhookListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:102](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L102) +[src/types/route-responses.ts:103](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L103) diff --git a/docs/interfaces/WorkspaceGetResponse.md b/docs/interfaces/WorkspaceGetResponse.md index fcd70264..31aa9c57 100644 --- a/docs/interfaces/WorkspaceGetResponse.md +++ b/docs/interfaces/WorkspaceGetResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:23](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L23) +[src/types/route-responses.ts:24](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L24) diff --git a/docs/interfaces/WorkspaceResetSandboxResponse.md b/docs/interfaces/WorkspaceResetSandboxResponse.md index 44541584..4ccf561a 100644 --- a/docs/interfaces/WorkspaceResetSandboxResponse.md +++ b/docs/interfaces/WorkspaceResetSandboxResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:28](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L28) +[src/types/route-responses.ts:29](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L29) diff --git a/docs/interfaces/WorkspacesListResponse.md b/docs/interfaces/WorkspacesListResponse.md index 1445f70b..8ff5a9bf 100644 --- a/docs/interfaces/WorkspacesListResponse.md +++ b/docs/interfaces/WorkspacesListResponse.md @@ -16,4 +16,4 @@ #### Defined in -[src/types/route-responses.ts:20](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L20) +[src/types/route-responses.ts:21](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L21) diff --git a/docs/modules.md b/docs/modules.md index 48a082d2..093f259e 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -39,6 +39,8 @@ - [ActionAttemptGetResponse](interfaces/ActionAttemptGetResponse.md) - [ActionAttemptResultTypeMap](interfaces/ActionAttemptResultTypeMap.md) - [ActionAttemptWithError](interfaces/ActionAttemptWithError.md) +- [ClientAccessTokenInterface](interfaces/ClientAccessTokenInterface.md) +- [ClientAccessTokenResponseInterface](interfaces/ClientAccessTokenResponseInterface.md) - [ConnectWebview](interfaces/ConnectWebview.md) - [ConnectWebviewCreateRequest](interfaces/ConnectWebviewCreateRequest.md) - [ConnectWebviewCreateResponse](interfaces/ConnectWebviewCreateResponse.md) @@ -613,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:26](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L26) +[src/seam-connect/client.ts:31](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L31) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 2537433a..5bcc915f 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -2,8 +2,13 @@ import axios, { AxiosInstance, AxiosRequestConfig } from "axios" import axiosRetry from "axios-retry" import { SeamAPIError, SeamMalformedInputError } from "../lib/api-error" import { Routes } from "./routes" -import { ErroredAPIResponse, SuccessfulAPIResponse } from "../types/globals" +import { + APIResponse, + ErroredAPIResponse, + SuccessfulAPIResponse, +} from "../types/globals" import { version } from "../../package.json" +import { ClientAccessTokenResponseInterface } from "../types" export interface SeamClientOptions { /* Seam API Key */ @@ -111,4 +116,20 @@ export class Seam extends Routes { throw error } } + static async getClientAccessToken( + pubKey: string, + extHostUserId: string, + endpoint: string, + workspaceId?: string + ): Promise> { + const response = await axios.post( + endpoint + "internal/client_access_tokens/create", + { + pub_key: pubKey, + ext_host_user_id: extHostUserId, + workspace_id: workspaceId, + } + ) + return await response.data + } } diff --git a/src/types/models.ts b/src/types/models.ts index 7428b86c..f3bb33ae 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -285,3 +285,11 @@ type Flatten = : never export type Event = Flatten + +export interface ClientAccessTokenInterface { + client_access_token_id: string + token: string + short_token: string + user_id: string + created_at: string +} diff --git a/src/types/route-responses.ts b/src/types/route-responses.ts index 129cc2bc..3f67268c 100644 --- a/src/types/route-responses.ts +++ b/src/types/route-responses.ts @@ -13,6 +13,7 @@ import { Event, UnmanagedAccessCode, UnmanagedDevice, + ClientAccessTokenInterface, } from "./models" // Workspaces @@ -122,3 +123,7 @@ export interface ActionAttemptGetResponse { export interface EventsListResponse { events: Event[] } + +export interface ClientAccessTokenResponseInterface { + client_access_token: ClientAccessTokenInterface +} From 7cd10a70b7392b5830a27fb93c413c5f92dda132 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Sat, 1 Apr 2023 08:27:16 -0600 Subject: [PATCH 02/30] Update client.ts --- docs/classes/Seam.md | 8 ++++---- docs/interfaces/SeamClientOptions.md | 17 ++++++++++++++--- docs/modules.md | 2 +- src/seam-connect/client.ts | 8 +++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index f3e2f977..aca4d784 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:57](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L57) +[src/seam-connect/client.ts:59](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L59) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:55](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L55) +[src/seam-connect/client.ts:57](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L57) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:95](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L95) +[src/seam-connect/client.ts:97](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L97) ___ @@ -320,4 +320,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:119](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L119) +[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index 34bec640..c54632b2 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -8,6 +8,7 @@ - [apiKey](SeamClientOptions.md#apikey) - [axiosOptions](SeamClientOptions.md#axiosoptions) +- [clientAccessToken](SeamClientOptions.md#clientaccesstoken) - [endpoint](SeamClientOptions.md#endpoint) - [workspaceId](SeamClientOptions.md#workspaceid) @@ -31,7 +32,17 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:28](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L28) +[src/seam-connect/client.ts:30](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L30) + +___ + +### clientAccessToken + +• `Optional` **clientAccessToken**: `string` + +#### Defined in + +[src/seam-connect/client.ts:17](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L17) ___ @@ -43,7 +54,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:19](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L19) +[src/seam-connect/client.ts:21](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L21) ___ @@ -56,4 +67,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:24](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L24) +[src/seam-connect/client.ts:26](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L26) diff --git a/docs/modules.md b/docs/modules.md index 093f259e..0897c681 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -615,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:31](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L31) +[src/seam-connect/client.ts:33](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L33) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 5bcc915f..1cffe82b 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -13,6 +13,8 @@ import { ClientAccessTokenResponseInterface } from "../types" export interface SeamClientOptions { /* Seam API Key */ apiKey?: string + /* Seam Client Access Token */ + clientAccessToken?: string /** * Seam Endpoint to use, defaults to https://connect.getseam.com **/ @@ -57,7 +59,7 @@ export class Seam extends Routes { constructor(apiKeyOrOptions?: string | SeamClientOptions) { super() - const { apiKey, endpoint, workspaceId, axiosOptions } = + const { apiKey, endpoint, workspaceId, axiosOptions, clientAccessToken } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) const isRegularAPIKey = apiKey?.startsWith("seam_") @@ -78,8 +80,8 @@ export class Seam extends Routes { baseURL: endpoint, headers: { ...axiosOptions?.headers, - Authorization: `Bearer ${apiKey}`, - ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, + Authorization: `Bearer ${apiKey || clientAccessToken}`, + // ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, // only needed for session key authentication ...(!workspaceId ? {} : { "Seam-Workspace": workspaceId }), From 84ba5e52677820fe635a74d8b67ad8261617912b Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 3 Apr 2023 13:56:06 -0600 Subject: [PATCH 03/30] Update client.ts --- docs/classes/Seam.md | 9 +++++---- src/seam-connect/client.ts | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index aca4d784..e922aee9 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -303,16 +303,17 @@ ___ ### getClientAccessToken -▸ `Static` **getClientAccessToken**(`pubKey`, `extHostUserId`, `endpoint`, `workspaceId?`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> +▸ `Static` **getClientAccessToken**(`pubKey?`, `extHostUserId?`, `endpoint?`, `workspaceId?`, `apiKey?`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> #### Parameters | Name | Type | | :------ | :------ | -| `pubKey` | `string` | -| `extHostUserId` | `string` | -| `endpoint` | `string` | +| `pubKey?` | `string` | +| `extHostUserId?` | `string` | +| `endpoint?` | `string` | | `workspaceId?` | `string` | +| `apiKey?` | `string` | #### Returns diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 1cffe82b..83409bc0 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -119,18 +119,23 @@ export class Seam extends Routes { } } static async getClientAccessToken( - pubKey: string, - extHostUserId: string, - endpoint: string, - workspaceId?: string + pubKey?: string, + extHostUserId?: string, + endpoint?: string, + workspaceId?: string, + apiKey?: string ): Promise> { + let params: any = {} + if (apiKey) { + params["api_key"] = apiKey + } else { + params["pub_key"] = pubKey + params["workspace_id"] = workspaceId + } + params["ext_host_user_id"] = extHostUserId const response = await axios.post( endpoint + "internal/client_access_tokens/create", - { - pub_key: pubKey, - ext_host_user_id: extHostUserId, - workspace_id: workspaceId, - } + params ) return await response.data } From 482765d4d27521db5cc0d58df7f27f767ed0d409 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Thu, 6 Apr 2023 21:53:44 -0600 Subject: [PATCH 04/30] Update client.ts --- docs/classes/Seam.md | 10 +++------- src/seam-connect/client.ts | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index e922aee9..7fe4c850 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -303,17 +303,13 @@ ___ ### getClientAccessToken -▸ `Static` **getClientAccessToken**(`pubKey?`, `extHostUserId?`, `endpoint?`, `workspaceId?`, `apiKey?`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> +▸ `Static` **getClientAccessToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> #### Parameters | Name | Type | | :------ | :------ | -| `pubKey?` | `string` | -| `extHostUserId?` | `string` | -| `endpoint?` | `string` | -| `workspaceId?` | `string` | -| `apiKey?` | `string` | +| `ops` | `catParams` | #### Returns @@ -321,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) +[src/seam-connect/client.ts:122](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L122) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 83409bc0..b38ef8e6 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -118,25 +118,29 @@ export class Seam extends Routes { throw error } } + static async getClientAccessToken( - pubKey?: string, - extHostUserId?: string, - endpoint?: string, - workspaceId?: string, - apiKey?: string + ops: catParams ): Promise> { let params: any = {} - if (apiKey) { - params["api_key"] = apiKey - } else { - params["pub_key"] = pubKey - params["workspace_id"] = workspaceId + if (ops.apiKey?.startsWith("seam_test")) { + params["api_key"] = ops.apiKey + } else if (ops.pubKey?.startsWith("seam_pk")) { + params["pub_key"] = ops.pubKey } - params["ext_host_user_id"] = extHostUserId + params["ext_host_user_id"] = ops.userIdentifierKey // TODO: rename this to user_identifier_key in DB later const response = await axios.post( - endpoint + "internal/client_access_tokens/create", + ops.endpoint + "internal/client_access_tokens/create", params ) return await response.data } } + +type catParams = { + pubKey?: string + userIdentifierKey: string + endpoint: string + workspaceId?: string + apiKey?: string +} From fab51abc55557385f1efd3183c849f10611f02fc Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Thu, 6 Apr 2023 21:55:57 -0600 Subject: [PATCH 05/30] Update client.ts --- src/seam-connect/client.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index b38ef8e6..e817272c 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -124,8 +124,10 @@ export class Seam extends Routes { ): Promise> { let params: any = {} if (ops.apiKey?.startsWith("seam_test")) { + // backend mode params["api_key"] = ops.apiKey } else if (ops.pubKey?.startsWith("seam_pk")) { + // frontend mode params["pub_key"] = ops.pubKey } params["ext_host_user_id"] = ops.userIdentifierKey // TODO: rename this to user_identifier_key in DB later From 5fb84d014c2189fcd8531a4f25c1256fb1c260fc Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 7 Apr 2023 08:53:15 -0600 Subject: [PATCH 06/30] rename everything https://www.notion.so/Azat-Review-c1afff0644a648a4864f85de3b11c14f --- docs/classes/Seam.md | 4 +-- .../ClientAccessTokenResponseInterface.md | 19 ---------- ...essTokenInterface.md => ClientSessionI.md} | 14 ++++---- .../ClientSessionResponseInterface.md | 19 ++++++++++ docs/modules.md | 4 +-- src/seam-connect/client.ts | 36 ++++++++++++++----- src/types/models.ts | 2 +- src/types/route-responses.ts | 6 ++-- 8 files changed, 62 insertions(+), 42 deletions(-) delete mode 100644 docs/interfaces/ClientAccessTokenResponseInterface.md rename docs/interfaces/{ClientAccessTokenInterface.md => ClientSessionI.md} (68%) create mode 100644 docs/interfaces/ClientSessionResponseInterface.md diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 7fe4c850..dc9644fa 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -303,7 +303,7 @@ ___ ### getClientAccessToken -▸ `Static` **getClientAccessToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> +▸ `Static` **getClientAccessToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> #### Parameters @@ -313,7 +313,7 @@ ___ #### Returns -`Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientAccessTokenResponseInterface`](../interfaces/ClientAccessTokenResponseInterface.md)\>\> +`Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> #### Defined in diff --git a/docs/interfaces/ClientAccessTokenResponseInterface.md b/docs/interfaces/ClientAccessTokenResponseInterface.md deleted file mode 100644 index 68a7af12..00000000 --- a/docs/interfaces/ClientAccessTokenResponseInterface.md +++ /dev/null @@ -1,19 +0,0 @@ -[seamapi](../README.md) / [Exports](../modules.md) / ClientAccessTokenResponseInterface - -# Interface: ClientAccessTokenResponseInterface - -## Table of contents - -### Properties - -- [client\_access\_token](ClientAccessTokenResponseInterface.md#client_access_token) - -## Properties - -### client\_access\_token - -• **client\_access\_token**: [`ClientAccessTokenInterface`](ClientAccessTokenInterface.md) - -#### Defined in - -[src/types/route-responses.ts:128](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L128) diff --git a/docs/interfaces/ClientAccessTokenInterface.md b/docs/interfaces/ClientSessionI.md similarity index 68% rename from docs/interfaces/ClientAccessTokenInterface.md rename to docs/interfaces/ClientSessionI.md index 4dc9a693..cf26f540 100644 --- a/docs/interfaces/ClientAccessTokenInterface.md +++ b/docs/interfaces/ClientSessionI.md @@ -1,16 +1,16 @@ -[seamapi](../README.md) / [Exports](../modules.md) / ClientAccessTokenInterface +[seamapi](../README.md) / [Exports](../modules.md) / ClientSessionI -# Interface: ClientAccessTokenInterface +# Interface: ClientSessionI ## Table of contents ### Properties -- [client\_access\_token\_id](ClientAccessTokenInterface.md#client_access_token_id) -- [created\_at](ClientAccessTokenInterface.md#created_at) -- [short\_token](ClientAccessTokenInterface.md#short_token) -- [token](ClientAccessTokenInterface.md#token) -- [user\_id](ClientAccessTokenInterface.md#user_id) +- [client\_access\_token\_id](ClientSessionI.md#client_access_token_id) +- [created\_at](ClientSessionI.md#created_at) +- [short\_token](ClientSessionI.md#short_token) +- [token](ClientSessionI.md#token) +- [user\_id](ClientSessionI.md#user_id) ## Properties diff --git a/docs/interfaces/ClientSessionResponseInterface.md b/docs/interfaces/ClientSessionResponseInterface.md new file mode 100644 index 00000000..7b10f667 --- /dev/null +++ b/docs/interfaces/ClientSessionResponseInterface.md @@ -0,0 +1,19 @@ +[seamapi](../README.md) / [Exports](../modules.md) / ClientSessionResponseInterface + +# Interface: ClientSessionResponseInterface + +## Table of contents + +### Properties + +- [client\_session](ClientSessionResponseInterface.md#client_session) + +## Properties + +### client\_session + +• **client\_session**: [`ClientSessionI`](ClientSessionI.md) + +#### Defined in + +[src/types/route-responses.ts:128](https://github.com/seamapi/javascript/blob/main/src/types/route-responses.ts#L128) diff --git a/docs/modules.md b/docs/modules.md index 0897c681..a93ab685 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -39,8 +39,8 @@ - [ActionAttemptGetResponse](interfaces/ActionAttemptGetResponse.md) - [ActionAttemptResultTypeMap](interfaces/ActionAttemptResultTypeMap.md) - [ActionAttemptWithError](interfaces/ActionAttemptWithError.md) -- [ClientAccessTokenInterface](interfaces/ClientAccessTokenInterface.md) -- [ClientAccessTokenResponseInterface](interfaces/ClientAccessTokenResponseInterface.md) +- [ClientSessionI](interfaces/ClientSessionI.md) +- [ClientSessionResponseInterface](interfaces/ClientSessionResponseInterface.md) - [ConnectWebview](interfaces/ConnectWebview.md) - [ConnectWebviewCreateRequest](interfaces/ConnectWebviewCreateRequest.md) - [ConnectWebviewCreateResponse](interfaces/ConnectWebviewCreateResponse.md) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index e817272c..abf76c4f 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -8,7 +8,7 @@ import { SuccessfulAPIResponse, } from "../types/globals" import { version } from "../../package.json" -import { ClientAccessTokenResponseInterface } from "../types" +import { ClientSessionResponseInterface } from "../types" export interface SeamClientOptions { /* Seam API Key */ @@ -121,8 +121,9 @@ export class Seam extends Routes { static async getClientAccessToken( ops: catParams - ): Promise> { + ): Promise> { let params: any = {} + if (ops.apiKey?.startsWith("seam_test")) { // backend mode params["api_key"] = ops.apiKey @@ -130,12 +131,31 @@ export class Seam extends Routes { // frontend mode params["pub_key"] = ops.pubKey } - params["ext_host_user_id"] = ops.userIdentifierKey // TODO: rename this to user_identifier_key in DB later - const response = await axios.post( - ops.endpoint + "internal/client_access_tokens/create", - params - ) - return await response.data + params["user_identifier_key"] = ops.userIdentifierKey // TODO: rename this to user_identifier_key in DB later + try { + const response = await axios.post( + ops.endpoint + "internal/client_access_tokens/create", + params + ) + if (response.data.error) { + return { + ok: false, + error: { + type: response.data.error.type, + message: response.data.error.message, + }, + } + } + return await response.data + } catch (e: any) { + return { + ok: false, + error: { + type: "unknown", + message: e.toString() ?? "Something went wrong", + }, + } + } } } diff --git a/src/types/models.ts b/src/types/models.ts index f3bb33ae..c3db0684 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -286,7 +286,7 @@ type Flatten = export type Event = Flatten -export interface ClientAccessTokenInterface { +export interface ClientSessionI { client_access_token_id: string token: string short_token: string diff --git a/src/types/route-responses.ts b/src/types/route-responses.ts index 3f67268c..6924ac54 100644 --- a/src/types/route-responses.ts +++ b/src/types/route-responses.ts @@ -13,7 +13,7 @@ import { Event, UnmanagedAccessCode, UnmanagedDevice, - ClientAccessTokenInterface, + ClientSessionI, } from "./models" // Workspaces @@ -124,6 +124,6 @@ export interface EventsListResponse { events: Event[] } -export interface ClientAccessTokenResponseInterface { - client_access_token: ClientAccessTokenInterface +export interface ClientSessionResponseInterface { + client_session: ClientSessionI } From cf9c60713eadf84bdef0a6e76c8189fed0169951 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 7 Apr 2023 11:05:30 -0600 Subject: [PATCH 07/30] Update client.ts --- src/seam-connect/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index abf76c4f..4bcc1dec 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -131,7 +131,7 @@ export class Seam extends Routes { // frontend mode params["pub_key"] = ops.pubKey } - params["user_identifier_key"] = ops.userIdentifierKey // TODO: rename this to user_identifier_key in DB later + params["user_identifier_key"] = ops.userIdentifierKey try { const response = await axios.post( ops.endpoint + "internal/client_access_tokens/create", From 2d169442d20875b9ed26a6a7b713ec43183dd75f Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 10 Apr 2023 17:31:01 -0600 Subject: [PATCH 08/30] Update client.ts --- src/seam-connect/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 4bcc1dec..210530cb 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -127,14 +127,14 @@ export class Seam extends Routes { if (ops.apiKey?.startsWith("seam_test")) { // backend mode params["api_key"] = ops.apiKey - } else if (ops.pubKey?.startsWith("seam_pk")) { + } else if (ops.publishedKey?.startsWith("seam_pk")) { // frontend mode - params["pub_key"] = ops.pubKey + params["publishable_key"] = ops.publishedKey } params["user_identifier_key"] = ops.userIdentifierKey try { const response = await axios.post( - ops.endpoint + "internal/client_access_tokens/create", + ops.endpoint + "internal/client_session_tokens/create", params ) if (response.data.error) { @@ -160,7 +160,7 @@ export class Seam extends Routes { } type catParams = { - pubKey?: string + publishedKey?: string userIdentifierKey: string endpoint: string workspaceId?: string From 944d6106dbee8e3f94e6c1dd864fdd91c89b8835 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 10 Apr 2023 17:32:13 -0600 Subject: [PATCH 09/30] Update client.ts --- docs/classes/Seam.md | 6 +++--- src/seam-connect/client.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index dc9644fa..76b21b56 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -30,7 +30,7 @@ ### Methods - [makeRequest](Seam.md#makerequest) -- [getClientAccessToken](Seam.md#getclientaccesstoken) +- [getClientSessionToken](Seam.md#getclientsessiontoken) ## Constructors @@ -301,9 +301,9 @@ Routes.makeRequest ___ -### getClientAccessToken +### getClientSessionToken -▸ `Static` **getClientAccessToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> +▸ `Static` **getClientSessionToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> #### Parameters diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 210530cb..8b2d9f0c 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -119,7 +119,7 @@ export class Seam extends Routes { } } - static async getClientAccessToken( + static async getClientSessionToken( ops: catParams ): Promise> { let params: any = {} From 57d6542623c32891b06757a3e36a1c1cce8e6bf3 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:15:34 -0600 Subject: [PATCH 10/30] Update client.ts --- docs/classes/Seam.md | 8 +++--- .../{ClientSessionI.md => ClientSession.md} | 14 +++++----- .../ClientSessionResponseInterface.md | 2 +- docs/interfaces/SeamClientOptions.md | 10 +++---- docs/modules.md | 4 +-- src/seam-connect/client.ts | 26 ++++++++++++------- 6 files changed, 35 insertions(+), 29 deletions(-) rename docs/interfaces/{ClientSessionI.md => ClientSession.md} (78%) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 76b21b56..7dda08e3 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:59](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L59) +[src/seam-connect/client.ts:63](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L63) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:57](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L57) +[src/seam-connect/client.ts:61](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L61) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:97](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L97) +[src/seam-connect/client.ts:101](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L101) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:122](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L122) +[src/seam-connect/client.ts:126](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L126) diff --git a/docs/interfaces/ClientSessionI.md b/docs/interfaces/ClientSession.md similarity index 78% rename from docs/interfaces/ClientSessionI.md rename to docs/interfaces/ClientSession.md index cf26f540..e898e3a2 100644 --- a/docs/interfaces/ClientSessionI.md +++ b/docs/interfaces/ClientSession.md @@ -1,16 +1,16 @@ -[seamapi](../README.md) / [Exports](../modules.md) / ClientSessionI +[seamapi](../README.md) / [Exports](../modules.md) / ClientSession -# Interface: ClientSessionI +# Interface: ClientSession ## Table of contents ### Properties -- [client\_access\_token\_id](ClientSessionI.md#client_access_token_id) -- [created\_at](ClientSessionI.md#created_at) -- [short\_token](ClientSessionI.md#short_token) -- [token](ClientSessionI.md#token) -- [user\_id](ClientSessionI.md#user_id) +- [client\_access\_token\_id](ClientSession.md#client_access_token_id) +- [created\_at](ClientSession.md#created_at) +- [short\_token](ClientSession.md#short_token) +- [token](ClientSession.md#token) +- [user\_id](ClientSession.md#user_id) ## Properties diff --git a/docs/interfaces/ClientSessionResponseInterface.md b/docs/interfaces/ClientSessionResponseInterface.md index 7b10f667..9e07c19b 100644 --- a/docs/interfaces/ClientSessionResponseInterface.md +++ b/docs/interfaces/ClientSessionResponseInterface.md @@ -12,7 +12,7 @@ ### client\_session -• **client\_session**: [`ClientSessionI`](ClientSessionI.md) +• **client\_session**: [`ClientSession`](ClientSession.md) #### Defined in diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index c54632b2..bebbf0c5 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -20,7 +20,7 @@ #### Defined in -[src/seam-connect/client.ts:15](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L15) +[src/seam-connect/client.ts:19](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L19) ___ @@ -32,7 +32,7 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:30](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L30) +[src/seam-connect/client.ts:34](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L34) ___ @@ -42,7 +42,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:17](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L17) +[src/seam-connect/client.ts:21](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L21) ___ @@ -54,7 +54,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:21](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L21) +[src/seam-connect/client.ts:25](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L25) ___ @@ -67,4 +67,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:26](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L26) +[src/seam-connect/client.ts:30](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L30) diff --git a/docs/modules.md b/docs/modules.md index a93ab685..476932da 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -39,7 +39,7 @@ - [ActionAttemptGetResponse](interfaces/ActionAttemptGetResponse.md) - [ActionAttemptResultTypeMap](interfaces/ActionAttemptResultTypeMap.md) - [ActionAttemptWithError](interfaces/ActionAttemptWithError.md) -- [ClientSessionI](interfaces/ClientSessionI.md) +- [ClientSession](interfaces/ClientSession.md) - [ClientSessionResponseInterface](interfaces/ClientSessionResponseInterface.md) - [ConnectWebview](interfaces/ConnectWebview.md) - [ConnectWebviewCreateRequest](interfaces/ConnectWebviewCreateRequest.md) @@ -615,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:33](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L33) +[src/seam-connect/client.ts:37](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L37) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 8b2d9f0c..66df09ec 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -1,4 +1,8 @@ -import axios, { AxiosInstance, AxiosRequestConfig } from "axios" +import axios, { + AxiosInstance, + AxiosRequestConfig, + AxiosRequestHeaders, +} from "axios" import axiosRetry from "axios-retry" import { SeamAPIError, SeamMalformedInputError } from "../lib/api-error" import { Routes } from "./routes" @@ -122,20 +126,22 @@ export class Seam extends Routes { static async getClientSessionToken( ops: catParams ): Promise> { - let params: any = {} + let headers: AxiosRequestHeaders = {} - if (ops.apiKey?.startsWith("seam_test")) { - // backend mode - params["api_key"] = ops.apiKey - } else if (ops.publishedKey?.startsWith("seam_pk")) { + if (ops.publishedKey?.startsWith("seam_pk")) { // frontend mode - params["publishable_key"] = ops.publishedKey + headers["seam-publishable-key"] = ops.publishedKey + } else if (ops.apiKey?.startsWith("seam_")) { + // backend mode + headers["seam-api-key"] = ops.apiKey } - params["user_identifier_key"] = ops.userIdentifierKey + headers["seam-user-identifier-key"] = ops.userIdentifierKey + try { const response = await axios.post( - ops.endpoint + "internal/client_session_tokens/create", - params + ops.endpoint + "internal/client_sessions/create", + {}, + { headers } ) if (response.data.error) { return { From 8cddcd72aa2ace4acc39cbcbe91b35f53b3439ec Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:15:54 -0600 Subject: [PATCH 11/30] rename https://github.com/seamapi/javascript/pull/176#discussion_r1160877713 --- src/types/models.ts | 2 +- src/types/route-responses.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/models.ts b/src/types/models.ts index c3db0684..99998187 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -286,7 +286,7 @@ type Flatten = export type Event = Flatten -export interface ClientSessionI { +export interface ClientSession { client_access_token_id: string token: string short_token: string diff --git a/src/types/route-responses.ts b/src/types/route-responses.ts index 6924ac54..915e178a 100644 --- a/src/types/route-responses.ts +++ b/src/types/route-responses.ts @@ -13,7 +13,7 @@ import { Event, UnmanagedAccessCode, UnmanagedDevice, - ClientSessionI, + ClientSession, } from "./models" // Workspaces @@ -125,5 +125,5 @@ export interface EventsListResponse { } export interface ClientSessionResponseInterface { - client_session: ClientSessionI + client_session: ClientSession } From f55f2014a08eac0cfd71651bed9051c26f64693d Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:20:10 -0600 Subject: [PATCH 12/30] Update client.ts --- docs/classes/Seam.md | 4 ++-- src/seam-connect/client.ts | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 7dda08e3..b14b9e0c 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:101](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L101) +[src/seam-connect/client.ts:104](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L104) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:126](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L126) +[src/seam-connect/client.ts:129](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L129) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 66df09ec..895153bd 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -79,17 +79,20 @@ export class Seam extends Routes { ) } + const headers: AxiosRequestHeaders = { + ...axiosOptions?.headers, + Authorization: `Bearer ${apiKey || clientAccessToken}`, + ...(!workspaceId ? {} : { "Seam-Workspace": workspaceId }), // only needed for session key authentication + } + if (typeof window === "undefined") { + headers[ + "User-Agent" + ] = `Javascript SDK v${version}, Node.js mode, (https://github.com/seamapi/javascript)` + } this.client = axios.create({ ...axiosOptions, baseURL: endpoint, - headers: { - ...axiosOptions?.headers, - Authorization: `Bearer ${apiKey || clientAccessToken}`, - // ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, - - // only needed for session key authentication - ...(!workspaceId ? {} : { "Seam-Workspace": workspaceId }), - }, + headers, }) axiosRetry(this.client, { From 8fd1faaabb022ce711c59e4e64699a83287522f0 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:22:54 -0600 Subject: [PATCH 13/30] Update client.ts --- docs/classes/Seam.md | 4 ++-- src/seam-connect/client.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index b14b9e0c..a0a7ea39 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:104](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L104) +[src/seam-connect/client.ts:105](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L105) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:129](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L129) +[src/seam-connect/client.ts:130](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L130) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 895153bd..23480ded 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -83,6 +83,7 @@ export class Seam extends Routes { ...axiosOptions?.headers, Authorization: `Bearer ${apiKey || clientAccessToken}`, ...(!workspaceId ? {} : { "Seam-Workspace": workspaceId }), // only needed for session key authentication + // 'seam-sdk-version': version // TODO: resolve error Access to XMLHttpRequest at 'http://localhost:3020/devices/list' from origin 'http://localhost:5173' has been blocked by CORS policy: Request header field seam-sdk-version is not allowed by Access-Control-Allow-Headers in preflight response. } if (typeof window === "undefined") { headers[ From df3898e655fb1a38526883a348fe909e7eab8be1 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:25:38 -0600 Subject: [PATCH 14/30] Update client.ts --- src/seam-connect/client.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 23480ded..271806bd 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -157,14 +157,12 @@ export class Seam extends Routes { } } return await response.data - } catch (e: any) { - return { - ok: false, - error: { - type: "unknown", - message: e.toString() ?? "Something went wrong", - }, - } + } catch (error: any) { + throw new SeamAPIError( + error.response.status, + error.response.headers["seam-request-id"], + (error.response.data as ErroredAPIResponse).error + ) } } } From a4124ff564e30d0cbb9c50b9319504c0b9c68cdc Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:26:54 -0600 Subject: [PATCH 15/30] Update client.ts --- docs/classes/Seam.md | 2 +- src/seam-connect/client.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index a0a7ea39..d9ae1526 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -309,7 +309,7 @@ ___ | Name | Type | | :------ | :------ | -| `ops` | `catParams` | +| `ops` | `CSTParams` | #### Returns diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 271806bd..6a87ef63 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -128,7 +128,7 @@ export class Seam extends Routes { } static async getClientSessionToken( - ops: catParams + ops: CSTParams ): Promise> { let headers: AxiosRequestHeaders = {} @@ -167,7 +167,7 @@ export class Seam extends Routes { } } -type catParams = { +type CSTParams = { publishedKey?: string userIdentifierKey: string endpoint: string From 5ab0dea4849205df634fb9990188285d0ff7be86 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Fri, 14 Apr 2023 08:32:26 -0600 Subject: [PATCH 16/30] 5.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75c4f5d3..9ea347c6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "iot", "device" ], - "version": "5.12.0", + "version": "5.12.1", "license": "MIT", "sideEffects": false, "main": "./cjs-wrapper.js", From ff9216f07184999812c620eb143c50fe87332d7a Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 07:13:08 -0600 Subject: [PATCH 17/30] renaming --- docs/classes/Seam.md | 4 ++-- ...SessionResponseInterface.md => ClientSessionResponse.md} | 6 +++--- docs/modules.md | 2 +- src/seam-connect/client.ts | 4 ++-- src/types/route-responses.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) rename docs/interfaces/{ClientSessionResponseInterface.md => ClientSessionResponse.md} (71%) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index d9ae1526..4b3eeb8a 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -303,7 +303,7 @@ ___ ### getClientSessionToken -▸ `Static` **getClientSessionToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> +▸ `Static` **getClientSessionToken**(`ops`): `Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponse`](../interfaces/ClientSessionResponse.md)\>\> #### Parameters @@ -313,7 +313,7 @@ ___ #### Returns -`Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponseInterface`](../interfaces/ClientSessionResponseInterface.md)\>\> +`Promise`<[`APIResponse`](../modules.md#apiresponse)<[`ClientSessionResponse`](../interfaces/ClientSessionResponse.md)\>\> #### Defined in diff --git a/docs/interfaces/ClientSessionResponseInterface.md b/docs/interfaces/ClientSessionResponse.md similarity index 71% rename from docs/interfaces/ClientSessionResponseInterface.md rename to docs/interfaces/ClientSessionResponse.md index 9e07c19b..5de6ba04 100644 --- a/docs/interfaces/ClientSessionResponseInterface.md +++ b/docs/interfaces/ClientSessionResponse.md @@ -1,12 +1,12 @@ -[seamapi](../README.md) / [Exports](../modules.md) / ClientSessionResponseInterface +[seamapi](../README.md) / [Exports](../modules.md) / ClientSessionResponse -# Interface: ClientSessionResponseInterface +# Interface: ClientSessionResponse ## Table of contents ### Properties -- [client\_session](ClientSessionResponseInterface.md#client_session) +- [client\_session](ClientSessionResponse.md#client_session) ## Properties diff --git a/docs/modules.md b/docs/modules.md index 476932da..1bd763b6 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -40,7 +40,7 @@ - [ActionAttemptResultTypeMap](interfaces/ActionAttemptResultTypeMap.md) - [ActionAttemptWithError](interfaces/ActionAttemptWithError.md) - [ClientSession](interfaces/ClientSession.md) -- [ClientSessionResponseInterface](interfaces/ClientSessionResponseInterface.md) +- [ClientSessionResponse](interfaces/ClientSessionResponse.md) - [ConnectWebview](interfaces/ConnectWebview.md) - [ConnectWebviewCreateRequest](interfaces/ConnectWebviewCreateRequest.md) - [ConnectWebviewCreateResponse](interfaces/ConnectWebviewCreateResponse.md) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 6a87ef63..f5ad1ad4 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -12,7 +12,7 @@ import { SuccessfulAPIResponse, } from "../types/globals" import { version } from "../../package.json" -import { ClientSessionResponseInterface } from "../types" +import { ClientSessionResponse } from "../types" export interface SeamClientOptions { /* Seam API Key */ @@ -129,7 +129,7 @@ export class Seam extends Routes { static async getClientSessionToken( ops: CSTParams - ): Promise> { + ): Promise> { let headers: AxiosRequestHeaders = {} if (ops.publishedKey?.startsWith("seam_pk")) { diff --git a/src/types/route-responses.ts b/src/types/route-responses.ts index 915e178a..7066aabb 100644 --- a/src/types/route-responses.ts +++ b/src/types/route-responses.ts @@ -124,6 +124,6 @@ export interface EventsListResponse { events: Event[] } -export interface ClientSessionResponseInterface { +export interface ClientSessionResponse { client_session: ClientSession } From d050ec6782d4994be7e9e63868380086dd201b60 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 07:14:07 -0600 Subject: [PATCH 18/30] Revert "5.12.1" This reverts commit 5ab0dea4849205df634fb9990188285d0ff7be86. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ea347c6..75c4f5d3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "iot", "device" ], - "version": "5.12.1", + "version": "5.12.0", "license": "MIT", "sideEffects": false, "main": "./cjs-wrapper.js", From cfb2be2e846df91e7d4190963819f2da853b9beb Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 07:35:53 -0600 Subject: [PATCH 19/30] be generous in acceptance (since it's detectable) but we shouldn't conflate the options be generous in acceptance (since it's detectable) but we shouldn't conflate the options --- docs/classes/Seam.md | 8 ++--- docs/interfaces/SeamClientOptions.md | 17 ++++++++-- docs/modules.md | 2 +- src/seam-connect/client.ts | 47 ++++++++++++++++++---------- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 4b3eeb8a..7a4e68e2 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:63](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L63) +[src/seam-connect/client.ts:65](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L65) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:61](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L61) +[src/seam-connect/client.ts:63](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L63) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:105](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L105) +[src/seam-connect/client.ts:120](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L120) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:130](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L130) +[src/seam-connect/client.ts:145](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L145) diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index bebbf0c5..b3266917 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -9,6 +9,7 @@ - [apiKey](SeamClientOptions.md#apikey) - [axiosOptions](SeamClientOptions.md#axiosoptions) - [clientAccessToken](SeamClientOptions.md#clientaccesstoken) +- [clientSessionToken](SeamClientOptions.md#clientsessiontoken) - [endpoint](SeamClientOptions.md#endpoint) - [workspaceId](SeamClientOptions.md#workspaceid) @@ -32,7 +33,7 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:34](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L34) +[src/seam-connect/client.ts:36](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L36) ___ @@ -46,6 +47,16 @@ ___ ___ +### clientSessionToken + +• `Optional` **clientSessionToken**: `string` + +#### Defined in + +[src/seam-connect/client.ts:23](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L23) + +___ + ### endpoint • `Optional` **endpoint**: `string` @@ -54,7 +65,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:25](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L25) +[src/seam-connect/client.ts:27](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L27) ___ @@ -67,4 +78,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:30](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L30) +[src/seam-connect/client.ts:32](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L32) diff --git a/docs/modules.md b/docs/modules.md index 1bd763b6..0a3ec048 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -615,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:37](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L37) +[src/seam-connect/client.ts:39](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L39) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index f5ad1ad4..206ff9f1 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -19,6 +19,8 @@ export interface SeamClientOptions { apiKey?: string /* Seam Client Access Token */ clientAccessToken?: string + /* Seam Client Session Token */ + clientSessionToken?: string /** * Seam Endpoint to use, defaults to https://connect.getseam.com **/ @@ -63,25 +65,38 @@ export class Seam extends Routes { constructor(apiKeyOrOptions?: string | SeamClientOptions) { super() - const { apiKey, endpoint, workspaceId, axiosOptions, clientAccessToken } = - getSeamClientOptionsWithDefaults(apiKeyOrOptions) - - const isRegularAPIKey = apiKey?.startsWith("seam_") - - if (isRegularAPIKey && workspaceId) - throw new Error( - "You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support." - ) - - if (!apiKey) { - throw new Error( - "SEAM_API_KEY not found in environment, and apiKey not provided" - ) + const { + apiKey, + endpoint, + workspaceId, + axiosOptions, + clientAccessToken, + clientSessionToken, + } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) + let bearer = `Bearer ` + if ( + (clientSessionToken && clientSessionToken?.startsWith("seam_cst")) || + (apiKey && apiKey.startsWith("seam_cst")) + ) { + bearer += clientSessionToken || apiKey + } else if (clientAccessToken && clientAccessToken?.startsWith("seam_at")) { + bearer += clientAccessToken + } else { + const isRegularAPIKey = apiKey?.startsWith("seam_") + if (isRegularAPIKey && workspaceId) + throw new Error( + "You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support." + ) + if (!apiKey) { + throw new Error( + "SEAM_API_KEY not found in environment, and apiKey not provided" + ) + } + bearer += apiKey } - const headers: AxiosRequestHeaders = { ...axiosOptions?.headers, - Authorization: `Bearer ${apiKey || clientAccessToken}`, + Authorization: bearer, ...(!workspaceId ? {} : { "Seam-Workspace": workspaceId }), // only needed for session key authentication // 'seam-sdk-version': version // TODO: resolve error Access to XMLHttpRequest at 'http://localhost:3020/devices/list' from origin 'http://localhost:5173' has been blocked by CORS policy: Request header field seam-sdk-version is not allowed by Access-Control-Allow-Headers in preflight response. } From d9a2278e4808b64091234381b206bf90f0893767 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 07:44:31 -0600 Subject: [PATCH 20/30] Update client.ts --- src/seam-connect/client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 206ff9f1..932a26f4 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -147,9 +147,9 @@ export class Seam extends Routes { ): Promise> { let headers: AxiosRequestHeaders = {} - if (ops.publishedKey?.startsWith("seam_pk")) { + if (ops.publishableKey?.startsWith("seam_pk")) { // frontend mode - headers["seam-publishable-key"] = ops.publishedKey + headers["seam-publishable-key"] = ops.publishableKey } else if (ops.apiKey?.startsWith("seam_")) { // backend mode headers["seam-api-key"] = ops.apiKey @@ -183,7 +183,7 @@ export class Seam extends Routes { } type CSTParams = { - publishedKey?: string + publishableKey?: string userIdentifierKey: string endpoint: string workspaceId?: string From a7730aa42d1a9b98807eb456a17104301d5e77b2 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 07:58:08 -0600 Subject: [PATCH 21/30] clean up --- docs/classes/Seam.md | 8 ++++---- docs/interfaces/ClientSession.md | 26 ++------------------------ docs/interfaces/SeamClientOptions.md | 12 ++++++------ docs/modules.md | 2 +- src/seam-connect/client.ts | 7 +++++-- src/types/models.ts | 2 -- 6 files changed, 18 insertions(+), 39 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 7a4e68e2..805d570f 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:65](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L65) +[src/seam-connect/client.ts:66](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L66) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:63](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L63) +[src/seam-connect/client.ts:64](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L64) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:120](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L120) +[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:145](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L145) +[src/seam-connect/client.ts:146](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L146) diff --git a/docs/interfaces/ClientSession.md b/docs/interfaces/ClientSession.md index e898e3a2..dafd4c0f 100644 --- a/docs/interfaces/ClientSession.md +++ b/docs/interfaces/ClientSession.md @@ -6,40 +6,18 @@ ### Properties -- [client\_access\_token\_id](ClientSession.md#client_access_token_id) - [created\_at](ClientSession.md#created_at) -- [short\_token](ClientSession.md#short_token) - [token](ClientSession.md#token) - [user\_id](ClientSession.md#user_id) ## Properties -### client\_access\_token\_id - -• **client\_access\_token\_id**: `string` - -#### Defined in - -[src/types/models.ts:290](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L290) - -___ - ### created\_at • **created\_at**: `string` #### Defined in -[src/types/models.ts:294](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L294) - -___ - -### short\_token - -• **short\_token**: `string` - -#### Defined in - [src/types/models.ts:292](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L292) ___ @@ -50,7 +28,7 @@ ___ #### Defined in -[src/types/models.ts:291](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L291) +[src/types/models.ts:290](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L290) ___ @@ -60,4 +38,4 @@ ___ #### Defined in -[src/types/models.ts:293](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L293) +[src/types/models.ts:291](https://github.com/seamapi/javascript/blob/main/src/types/models.ts#L291) diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index b3266917..7b8d31e9 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -21,7 +21,7 @@ #### Defined in -[src/seam-connect/client.ts:19](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L19) +[src/seam-connect/client.ts:20](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L20) ___ @@ -33,7 +33,7 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:36](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L36) +[src/seam-connect/client.ts:37](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L37) ___ @@ -43,7 +43,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:21](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L21) +[src/seam-connect/client.ts:22](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L22) ___ @@ -53,7 +53,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:23](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L23) +[src/seam-connect/client.ts:24](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L24) ___ @@ -65,7 +65,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:27](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L27) +[src/seam-connect/client.ts:28](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L28) ___ @@ -78,4 +78,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:32](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L32) +[src/seam-connect/client.ts:33](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L33) diff --git a/docs/modules.md b/docs/modules.md index 0a3ec048..4fb061c7 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -615,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:39](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L39) +[src/seam-connect/client.ts:40](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L40) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 932a26f4..83730861 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -2,6 +2,7 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, + AxiosResponse, } from "axios" import axiosRetry from "axios-retry" import { SeamAPIError, SeamMalformedInputError } from "../lib/api-error" @@ -12,7 +13,7 @@ import { SuccessfulAPIResponse, } from "../types/globals" import { version } from "../../package.json" -import { ClientSessionResponse } from "../types" +import { ClientSession, ClientSessionResponse } from "../types" export interface SeamClientOptions { /* Seam API Key */ @@ -157,7 +158,9 @@ export class Seam extends Routes { headers["seam-user-identifier-key"] = ops.userIdentifierKey try { - const response = await axios.post( + const response: AxiosResponse & { + data: { client_session: ClientSession } + } = await axios.post( ops.endpoint + "internal/client_sessions/create", {}, { headers } diff --git a/src/types/models.ts b/src/types/models.ts index 99998187..5f578d46 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -287,9 +287,7 @@ type Flatten = export type Event = Flatten export interface ClientSession { - client_access_token_id: string token: string - short_token: string user_id: string created_at: string } From e949111cf9a88b1ed090cd73d7bae1b58f460a8e Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 08:00:17 -0600 Subject: [PATCH 22/30] Update src/seam-connect/client.ts Co-authored-by: Severin Ibarluzea --- src/seam-connect/client.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 83730861..50d282a9 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -165,15 +165,6 @@ export class Seam extends Routes { {}, { headers } ) - if (response.data.error) { - return { - ok: false, - error: { - type: response.data.error.type, - message: response.data.error.message, - }, - } - } return await response.data } catch (error: any) { throw new SeamAPIError( From 0e60d229df58775543882eb99e868c3e67d46d18 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 08:15:16 -0600 Subject: [PATCH 23/30] a warning/error that they need to use a different parameter https://github.com/seamapi/javascript/pull/176#issuecomment-1509226589 --- docs/classes/Seam.md | 4 ++-- src/seam-connect/client.ts | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 805d570f..06c7fdf1 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) +[src/seam-connect/client.ts:138](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L138) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:146](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L146) +[src/seam-connect/client.ts:163](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L163) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 50d282a9..82354ee2 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -75,13 +75,30 @@ export class Seam extends Routes { clientSessionToken, } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) let bearer = `Bearer ` - if ( - (clientSessionToken && clientSessionToken?.startsWith("seam_cst")) || - (apiKey && apiKey.startsWith("seam_cst")) - ) { - bearer += clientSessionToken || apiKey - } else if (clientAccessToken && clientAccessToken?.startsWith("seam_at")) { - bearer += clientAccessToken + if (clientSessionToken) { + if (clientSessionToken?.startsWith("seam_cst")) + bearer += clientSessionToken || apiKey + else throw new Error("clientSessionToken must start with seam_cst") + if (apiKey || clientAccessToken) + throw new Error( + "You can't use clientSessionToken AND specify apiKey or clientAccessToken." + ) + } else if (apiKey && apiKey.startsWith("seam_cst")) { + if (clientAccessToken || clientSessionToken) + throw new Error( + "You can't use clientSessionToken in apiKey AND specify clientSessionToken or clientAccessToken." + ) + bearer += apiKey + console.warn( + "Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead." + ) + } else if (clientAccessToken) { + if (clientAccessToken?.startsWith("seam_at")) bearer += clientAccessToken + else throw new Error("clientAccessToken must start with seam_at") + if (apiKey || clientSessionToken) + throw new Error( + "You can't use clientAccessToken AND specify apiKey or clientSessionToken." + ) } else { const isRegularAPIKey = apiKey?.startsWith("seam_") if (isRegularAPIKey && workspaceId) From 650842af0d7cfb6c4298ca2459a321162f61536f Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 08:24:09 -0600 Subject: [PATCH 24/30] Update client.ts --- src/seam-connect/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 82354ee2..15a190a3 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -178,7 +178,8 @@ export class Seam extends Routes { const response: AxiosResponse & { data: { client_session: ClientSession } } = await axios.post( - ops.endpoint + "internal/client_sessions/create", + (ops.endpoint ?? "https://connect.getseam.com") + + "/internal/client_sessions/create", {}, { headers } ) From cc3b51615d8e546a6294af52cde003cf937835c0 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Mon, 17 Apr 2023 08:26:44 -0600 Subject: [PATCH 25/30] Update client.ts --- src/seam-connect/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 15a190a3..4c813c40 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -197,7 +197,7 @@ export class Seam extends Routes { type CSTParams = { publishableKey?: string userIdentifierKey: string - endpoint: string + endpoint?: string workspaceId?: string apiKey?: string } From 225366e5fab6fa27ea666234d4804bd9dc19a457 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Tue, 18 Apr 2023 22:18:37 -0600 Subject: [PATCH 26/30] Update client.ts --- docs/classes/Seam.md | 8 ++++---- docs/interfaces/SeamClientOptions.md | 19 ++++-------------- docs/modules.md | 2 +- src/seam-connect/client.ts | 29 ++++++---------------------- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 06c7fdf1..5d91aa84 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:66](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L66) +[src/seam-connect/client.ts:64](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L64) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:64](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L64) +[src/seam-connect/client.ts:62](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L62) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:138](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L138) +[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:163](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L163) +[src/seam-connect/client.ts:146](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L146) diff --git a/docs/interfaces/SeamClientOptions.md b/docs/interfaces/SeamClientOptions.md index 7b8d31e9..c860bf8f 100644 --- a/docs/interfaces/SeamClientOptions.md +++ b/docs/interfaces/SeamClientOptions.md @@ -8,7 +8,6 @@ - [apiKey](SeamClientOptions.md#apikey) - [axiosOptions](SeamClientOptions.md#axiosoptions) -- [clientAccessToken](SeamClientOptions.md#clientaccesstoken) - [clientSessionToken](SeamClientOptions.md#clientsessiontoken) - [endpoint](SeamClientOptions.md#endpoint) - [workspaceId](SeamClientOptions.md#workspaceid) @@ -33,17 +32,7 @@ Extended options to pass to Axios #### Defined in -[src/seam-connect/client.ts:37](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L37) - -___ - -### clientAccessToken - -• `Optional` **clientAccessToken**: `string` - -#### Defined in - -[src/seam-connect/client.ts:22](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L22) +[src/seam-connect/client.ts:35](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L35) ___ @@ -53,7 +42,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:24](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L24) +[src/seam-connect/client.ts:22](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L22) ___ @@ -65,7 +54,7 @@ Seam Endpoint to use, defaults to https://connect.getseam.com #### Defined in -[src/seam-connect/client.ts:28](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L28) +[src/seam-connect/client.ts:26](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L26) ___ @@ -78,4 +67,4 @@ or undefined #### Defined in -[src/seam-connect/client.ts:33](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L33) +[src/seam-connect/client.ts:31](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L31) diff --git a/docs/modules.md b/docs/modules.md index 4fb061c7..f5247389 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -615,7 +615,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:40](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L40) +[src/seam-connect/client.ts:38](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L38) ___ diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 4c813c40..074d95b8 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -18,8 +18,6 @@ import { ClientSession, ClientSessionResponse } from "../types" export interface SeamClientOptions { /* Seam API Key */ apiKey?: string - /* Seam Client Access Token */ - clientAccessToken?: string /* Seam Client Session Token */ clientSessionToken?: string /** @@ -66,39 +64,24 @@ export class Seam extends Routes { constructor(apiKeyOrOptions?: string | SeamClientOptions) { super() - const { - apiKey, - endpoint, - workspaceId, - axiosOptions, - clientAccessToken, - clientSessionToken, - } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) + const { apiKey, endpoint, workspaceId, axiosOptions, clientSessionToken } = + getSeamClientOptionsWithDefaults(apiKeyOrOptions) let bearer = `Bearer ` if (clientSessionToken) { if (clientSessionToken?.startsWith("seam_cst")) bearer += clientSessionToken || apiKey else throw new Error("clientSessionToken must start with seam_cst") - if (apiKey || clientAccessToken) - throw new Error( - "You can't use clientSessionToken AND specify apiKey or clientAccessToken." - ) + if (apiKey) + throw new Error("You can't use clientSessionToken AND specify apiKey.") } else if (apiKey && apiKey.startsWith("seam_cst")) { - if (clientAccessToken || clientSessionToken) + if (clientSessionToken) throw new Error( - "You can't use clientSessionToken in apiKey AND specify clientSessionToken or clientAccessToken." + "You can't use clientSessionToken in apiKey AND specify clientSessionToken." ) bearer += apiKey console.warn( "Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead." ) - } else if (clientAccessToken) { - if (clientAccessToken?.startsWith("seam_at")) bearer += clientAccessToken - else throw new Error("clientAccessToken must start with seam_at") - if (apiKey || clientSessionToken) - throw new Error( - "You can't use clientAccessToken AND specify apiKey or clientSessionToken." - ) } else { const isRegularAPIKey = apiKey?.startsWith("seam_") if (isRegularAPIKey && workspaceId) From f5d6f954b700f13cec9ba531a1137bc07cb43232 Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Tue, 18 Apr 2023 22:21:17 -0600 Subject: [PATCH 27/30] Update client.ts --- src/seam-connect/client.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 074d95b8..5e949041 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -155,8 +155,11 @@ export class Seam extends Routes { // backend mode headers["seam-api-key"] = ops.apiKey } - headers["seam-user-identifier-key"] = ops.userIdentifierKey - + if (ops.userIdentifierKey) { + headers["seam-user-identifier-key"] = ops.userIdentifierKey + } else { + throw new Error("userIdentifierKey is required") + } try { const response: AxiosResponse & { data: { client_session: ClientSession } From 9aacc9bd8273d6170e436dca116f4b04c7dabd1b Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Tue, 18 Apr 2023 22:25:56 -0600 Subject: [PATCH 28/30] Update client.ts --- src/seam-connect/client.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 5e949041..562047ea 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -146,14 +146,18 @@ export class Seam extends Routes { static async getClientSessionToken( ops: CSTParams ): Promise> { - let headers: AxiosRequestHeaders = {} + const { apiKey, endpoint, axiosOptions } = + getSeamClientOptionsWithDefaults(ops) + let headers: AxiosRequestHeaders = { + ...axiosOptions?.headers, + } if (ops.publishableKey?.startsWith("seam_pk")) { // frontend mode headers["seam-publishable-key"] = ops.publishableKey - } else if (ops.apiKey?.startsWith("seam_")) { + } else if (apiKey?.startsWith("seam_")) { // backend mode - headers["seam-api-key"] = ops.apiKey + headers["seam-api-key"] = apiKey } if (ops.userIdentifierKey) { headers["seam-user-identifier-key"] = ops.userIdentifierKey @@ -164,8 +168,7 @@ export class Seam extends Routes { const response: AxiosResponse & { data: { client_session: ClientSession } } = await axios.post( - (ops.endpoint ?? "https://connect.getseam.com") + - "/internal/client_sessions/create", + endpoint + "/internal/client_sessions/create", {}, { headers } ) From 2b0b067ec47895925e86cbdc74aaa7099cce7ecb Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Tue, 18 Apr 2023 22:47:05 -0600 Subject: [PATCH 29/30] refactor to use getBearerToken --- docs/classes/Seam.md | 8 ++--- src/seam-connect/client.ts | 67 +++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/docs/classes/Seam.md b/docs/classes/Seam.md index 5d91aa84..2273ff3f 100644 --- a/docs/classes/Seam.md +++ b/docs/classes/Seam.md @@ -50,7 +50,7 @@ Routes.constructor #### Defined in -[src/seam-connect/client.ts:64](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L64) +[src/seam-connect/client.ts:98](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L98) ## Properties @@ -107,7 +107,7 @@ ___ #### Defined in -[src/seam-connect/client.ts:62](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L62) +[src/seam-connect/client.ts:96](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L96) ___ @@ -297,7 +297,7 @@ Routes.makeRequest #### Defined in -[src/seam-connect/client.ts:121](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L121) +[src/seam-connect/client.ts:130](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L130) ___ @@ -317,4 +317,4 @@ ___ #### Defined in -[src/seam-connect/client.ts:146](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L146) +[src/seam-connect/client.ts:155](https://github.com/seamapi/javascript/blob/main/src/seam-connect/client.ts#L155) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index 562047ea..a270c258 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -58,6 +58,40 @@ export const getSeamClientOptionsWithDefaults = ( } } +const getBearerToken = ({ + clientSessionToken, + apiKey, + workspaceId, +}: { + clientSessionToken?: string + apiKey?: string + workspaceId?: string +}): string => { + if (apiKey && clientSessionToken) { + throw new Error("You can't use clientSessionToken AND specify apiKey.") + } + if (clientSessionToken) { + if (clientSessionToken.startsWith("seam_cst")) return clientSessionToken + else throw new Error("clientSessionToken must start with seam_cst") + } + if (apiKey) { + if (apiKey.startsWith("seam_cst")) { + console.warn( + "Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead." + ) + return apiKey + } + if (!apiKey.startsWith("seam_at") && workspaceId) + throw new Error( + "You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support." + ) + return apiKey + } + throw new Error( + "Must provide either clientSessionToken or apiKey (API Key or Access Token with Workspace ID)." + ) +} + export class Seam extends Routes { public client: AxiosInstance @@ -66,35 +100,10 @@ export class Seam extends Routes { const { apiKey, endpoint, workspaceId, axiosOptions, clientSessionToken } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) - let bearer = `Bearer ` - if (clientSessionToken) { - if (clientSessionToken?.startsWith("seam_cst")) - bearer += clientSessionToken || apiKey - else throw new Error("clientSessionToken must start with seam_cst") - if (apiKey) - throw new Error("You can't use clientSessionToken AND specify apiKey.") - } else if (apiKey && apiKey.startsWith("seam_cst")) { - if (clientSessionToken) - throw new Error( - "You can't use clientSessionToken in apiKey AND specify clientSessionToken." - ) - bearer += apiKey - console.warn( - "Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead." - ) - } else { - const isRegularAPIKey = apiKey?.startsWith("seam_") - if (isRegularAPIKey && workspaceId) - throw new Error( - "You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support." - ) - if (!apiKey) { - throw new Error( - "SEAM_API_KEY not found in environment, and apiKey not provided" - ) - } - bearer += apiKey - } + + const bearer = + `Bearer ` + getBearerToken({ clientSessionToken, apiKey, workspaceId }) + const headers: AxiosRequestHeaders = { ...axiosOptions?.headers, Authorization: bearer, From 6da07a12563f5f1df4c1fc493f4809284d551cdd Mon Sep 17 00:00:00 2001 From: Azat Mardan Date: Wed, 19 Apr 2023 12:21:52 -0600 Subject: [PATCH 30/30] use options --- src/seam-connect/client.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/seam-connect/client.ts b/src/seam-connect/client.ts index a270c258..c2eb87e4 100644 --- a/src/seam-connect/client.ts +++ b/src/seam-connect/client.ts @@ -173,13 +173,19 @@ export class Seam extends Routes { } else { throw new Error("userIdentifierKey is required") } + const client = axios.create({ + ...axiosOptions, + baseURL: endpoint, + headers, + }) try { const response: AxiosResponse & { data: { client_session: ClientSession } - } = await axios.post( - endpoint + "/internal/client_sessions/create", + } = await client.post( + "/internal/client_sessions/create", {}, - { headers } + // { headers: { "seam-sdk-version": version } } + {} ) return await response.data } catch (error: any) {