@seamapi/http 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE.txt +20 -0
  2. package/README.md +155 -0
  3. package/connect.d.ts +1 -0
  4. package/connect.js +2 -0
  5. package/connect.js.map +1 -0
  6. package/dist/connect.cjs +219 -0
  7. package/dist/connect.cjs.map +1 -0
  8. package/dist/connect.d.cts +35 -0
  9. package/dist/index.cjs +8 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +3 -0
  12. package/index.d.ts +2 -0
  13. package/index.js +2 -0
  14. package/index.js.map +1 -0
  15. package/lib/seam/connect/auth.d.ts +7 -0
  16. package/lib/seam/connect/auth.js +47 -0
  17. package/lib/seam/connect/auth.js.map +1 -0
  18. package/lib/seam/connect/axios.d.ts +3 -0
  19. package/lib/seam/connect/axios.js +17 -0
  20. package/lib/seam/connect/axios.js.map +1 -0
  21. package/lib/seam/connect/client-options.d.ts +19 -0
  22. package/lib/seam/connect/client-options.js +29 -0
  23. package/lib/seam/connect/client-options.js.map +1 -0
  24. package/lib/seam/connect/client.d.ts +11 -0
  25. package/lib/seam/connect/client.js +51 -0
  26. package/lib/seam/connect/client.js.map +1 -0
  27. package/lib/seam/connect/index.d.ts +1 -0
  28. package/lib/seam/connect/index.js +2 -0
  29. package/lib/seam/connect/index.js.map +1 -0
  30. package/lib/seam/connect/legacy/workspaces.d.ts +8 -0
  31. package/lib/seam/connect/legacy/workspaces.js +10 -0
  32. package/lib/seam/connect/legacy/workspaces.js.map +1 -0
  33. package/lib/seam/connect/parse-options.d.ts +2 -0
  34. package/lib/seam/connect/parse-options.js +20 -0
  35. package/lib/seam/connect/parse-options.js.map +1 -0
  36. package/lib/seam/connect/routes/workspaces.d.ts +11 -0
  37. package/lib/seam/connect/routes/workspaces.js +20 -0
  38. package/lib/seam/connect/routes/workspaces.js.map +1 -0
  39. package/package.json +109 -0
  40. package/src/connect.ts +1 -0
  41. package/src/index.ts +1 -0
  42. package/src/lib/seam/connect/auth.ts +86 -0
  43. package/src/lib/seam/connect/axios.ts +23 -0
  44. package/src/lib/seam/connect/client-options.ts +62 -0
  45. package/src/lib/seam/connect/client.ts +63 -0
  46. package/src/lib/seam/connect/index.ts +1 -0
  47. package/src/lib/seam/connect/legacy/workspaces.ts +26 -0
  48. package/src/lib/seam/connect/parse-options.ts +28 -0
  49. package/src/lib/seam/connect/routes/workspaces.ts +41 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-2023 Seam Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Seam HTTP client.
2
+
3
+ [![npm](https://img.shields.io/npm/v/@seamapi/http.svg)](https://www.npmjs.com/package/@seamapi/http)
4
+ [![GitHub Actions](https://github.com/seamapi/javascript-http/actions/workflows/check.yml/badge.svg)](https://github.com/seamapi/javascript-http/actions/workflows/check.yml)
5
+
6
+ JavaScript HTTP client for the Seam API written in TypeScript.
7
+
8
+ ## Description
9
+
10
+ TODO
11
+
12
+ ## Installation
13
+
14
+ Add this as a dependency to your project using [npm] with
15
+
16
+ ```
17
+ $ npm install @seamapi/http
18
+ ```
19
+
20
+ [npm]: https://www.npmjs.com/
21
+
22
+ ## Development and Testing
23
+
24
+ ### Quickstart
25
+
26
+ ```
27
+ $ git clone https://github.com/seamapi/javascript-http.git
28
+ $ cd javascript-http
29
+ $ nvm install
30
+ $ npm install
31
+ $ npm run test:watch
32
+ ```
33
+
34
+ Primary development tasks are defined under `scripts` in `package.json`
35
+ and available via `npm run`.
36
+ View them with
37
+
38
+ ```
39
+ $ npm run
40
+ ```
41
+
42
+ ### Source code
43
+
44
+ The [source code] is hosted on GitHub.
45
+ Clone the project with
46
+
47
+ ```
48
+ $ git clone git@github.com:seamapi/javascript-http.git
49
+ ```
50
+
51
+ [source code]: https://github.com/seamapi/javascript-http
52
+
53
+ ### Requirements
54
+
55
+ You will need [Node.js] with [npm] and a [Node.js debugging] client.
56
+
57
+ Be sure that all commands run under the correct Node version, e.g.,
58
+ if using [nvm], install the correct version with
59
+
60
+ ```
61
+ $ nvm install
62
+ ```
63
+
64
+ Set the active version for each shell session with
65
+
66
+ ```
67
+ $ nvm use
68
+ ```
69
+
70
+ Install the development dependencies with
71
+
72
+ ```
73
+ $ npm install
74
+ ```
75
+
76
+ [Node.js]: https://nodejs.org/
77
+ [Node.js debugging]: https://nodejs.org/en/docs/guides/debugging-getting-started/
78
+ [npm]: https://www.npmjs.com/
79
+ [nvm]: https://github.com/creationix/nvm
80
+
81
+ ### Publishing
82
+
83
+ #### Automatic
84
+
85
+ New versions are released automatically with [semantic-release]
86
+ as long as commits follow the [Angular Commit Message Conventions].
87
+
88
+ [Angular Commit Message Conventions]: https://semantic-release.gitbook.io/semantic-release/#commit-message-format
89
+ [semantic-release]: https://semantic-release.gitbook.io/
90
+
91
+ #### Manual
92
+
93
+ Publish a new version by triggering a [version workflow_dispatch on GitHub Actions].
94
+ The `version` input will be passed as the first argument to [npm-version].
95
+
96
+ This may be done on the web or using the [GitHub CLI] with
97
+
98
+ ```
99
+ $ gh workflow run version.yml --raw-field version=<version>
100
+ ```
101
+
102
+ [GitHub CLI]: https://cli.github.com/
103
+ [npm-version]: https://docs.npmjs.com/cli/version
104
+ [version workflow_dispatch on GitHub Actions]: https://github.com/seamapi/javascript-http/actions?query=workflow%3Aversion
105
+
106
+ ## GitHub Actions
107
+
108
+ _GitHub Actions should already be configured: this section is for reference only._
109
+
110
+ The following repository secrets must be set on [GitHub Actions]:
111
+
112
+ - `NPM_TOKEN`: npm token for installing and publishing packages.
113
+ - `GH_TOKEN`: A personal access token for the bot user with
114
+ `packages:write` and `contents:write` permission.
115
+ - `GIT_USER_NAME`: The GitHub bot user's real name.
116
+ - `GIT_USER_EMAIL`: The GitHub bot user's email.
117
+ - `GPG_PRIVATE_KEY`: The GitHub bot user's [GPG private key].
118
+ - `GPG_PASSPHRASE`: The GitHub bot user's GPG passphrase.
119
+
120
+ [GitHub Actions]: https://github.com/features/actions
121
+ [GPG private key]: https://github.com/marketplace/actions/import-gpg#prerequisites
122
+
123
+ ## Contributing
124
+
125
+ > If using squash merge, edit and ensure the commit message follows the [Angular Commit Message Conventions] specification.
126
+ > Otherwise, each individual commit must follow the [Angular Commit Message Conventions] specification.
127
+
128
+ 1. Create your feature branch (`git checkout -b my-new-feature`).
129
+ 2. Make changes.
130
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
131
+ 4. Push to the branch (`git push origin my-new-feature`).
132
+ 5. Create a new draft pull request.
133
+ 6. Ensure all checks pass.
134
+ 7. Mark your pull request ready for review.
135
+ 8. Wait for the required approval from the code owners.
136
+ 9. Merge when ready.
137
+
138
+ [Angular Commit Message Conventions]: https://semantic-release.gitbook.io/semantic-release/#commit-message-format
139
+
140
+ ## License
141
+
142
+ This npm package is licensed under the MIT license.
143
+
144
+ ## Warranty
145
+
146
+ This software is provided by the copyright holders and contributors "as is" and
147
+ any express or implied warranties, including, but not limited to, the implied
148
+ warranties of merchantability and fitness for a particular purpose are
149
+ disclaimed. In no event shall the copyright holder or contributors be liable for
150
+ any direct, indirect, incidental, special, exemplary, or consequential damages
151
+ (including, but not limited to, procurement of substitute goods or services;
152
+ loss of use, data, or profits; or business interruption) however caused and on
153
+ any theory of liability, whether in contract, strict liability, or tort
154
+ (including negligence or otherwise) arising in any way out of the use of this
155
+ software, even if advised of the possibility of such damage.
package/connect.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/seam/connect/index.js';
package/connect.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/seam/connect/index.js';
2
+ //# sourceMappingURL=connect.js.map
package/connect.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.js","sourceRoot":"","sources":["src/connect.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
@@ -0,0 +1,219 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
8
+
9
+ var __accessCheck = (obj, member, msg) => {
10
+ if (!member.has(obj))
11
+ throw TypeError("Cannot " + msg);
12
+ };
13
+ var __privateGet = (obj, member, getter) => {
14
+ __accessCheck(obj, member, "read from private field");
15
+ return getter ? getter.call(obj) : member.get(obj);
16
+ };
17
+ var __privateAdd = (obj, member, value) => {
18
+ if (member.has(obj))
19
+ throw TypeError("Cannot add the same private member more than once");
20
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
21
+ };
22
+ var __privateSet = (obj, member, value, setter) => {
23
+ __accessCheck(obj, member, "write to private field");
24
+ setter ? setter.call(obj, value) : member.set(obj, value);
25
+ return value;
26
+ };
27
+
28
+ // src/lib/seam/connect/client-options.ts
29
+ var isSeamHttpOptionsWithApiKey = (options) => {
30
+ if (!("apiKey" in options))
31
+ return false;
32
+ if ("clientSessionToken" in options && options.clientSessionToken != null) {
33
+ throw new InvalidSeamHttpOptionsError(
34
+ "The clientSessionToken option cannot be used with the apiKey option."
35
+ );
36
+ }
37
+ return true;
38
+ };
39
+ var isSeamHttpOptionsWithClientSessionToken = (options) => {
40
+ if (!("clientSessionToken" in options))
41
+ return false;
42
+ if ("apiKey" in options && options.apiKey != null) {
43
+ throw new InvalidSeamHttpOptionsError(
44
+ "The clientSessionToken option cannot be used with the apiKey option."
45
+ );
46
+ }
47
+ return true;
48
+ };
49
+ var InvalidSeamHttpOptionsError = class extends Error {
50
+ constructor(message) {
51
+ super(`SeamHttp received invalid options: ${message}`);
52
+ this.name = this.constructor.name;
53
+ Error.captureStackTrace(this, this.constructor);
54
+ }
55
+ };
56
+
57
+ // src/lib/seam/connect/auth.ts
58
+ var getAuthHeaders = (options) => {
59
+ if (isSeamHttpOptionsWithApiKey(options)) {
60
+ return getAuthHeadersForApiKey(options);
61
+ }
62
+ if (isSeamHttpOptionsWithClientSessionToken(options)) {
63
+ return getAuthHeadersForClientSessionToken(options);
64
+ }
65
+ throw new InvalidSeamHttpOptionsError(
66
+ "Must specify an apiKey or clientSessionToken"
67
+ );
68
+ };
69
+ var getAuthHeadersForApiKey = ({
70
+ apiKey
71
+ }) => {
72
+ if (isClientSessionToken(apiKey)) {
73
+ throw new InvalidSeamTokenError(
74
+ "A Client Session Token cannot be used as an apiKey"
75
+ );
76
+ }
77
+ if (isAccessToken(apiKey)) {
78
+ throw new InvalidSeamTokenError(
79
+ "An access token cannot be used as an apiKey"
80
+ );
81
+ }
82
+ if (isJwt(apiKey) || !isSeamToken(apiKey)) {
83
+ throw new InvalidSeamTokenError(
84
+ `Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`
85
+ );
86
+ }
87
+ return {
88
+ authorization: `Bearer ${apiKey}`
89
+ };
90
+ };
91
+ var getAuthHeadersForClientSessionToken = ({
92
+ clientSessionToken
93
+ }) => {
94
+ if (!isClientSessionToken(clientSessionToken)) {
95
+ throw new InvalidSeamTokenError(
96
+ `Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`
97
+ );
98
+ }
99
+ return {
100
+ authorization: `Bearer ${clientSessionToken}`,
101
+ "client-session-token": clientSessionToken
102
+ };
103
+ };
104
+ var InvalidSeamTokenError = class extends Error {
105
+ constructor(message) {
106
+ super(`SeamHttp received an invalid token: ${message}`);
107
+ this.name = this.constructor.name;
108
+ Error.captureStackTrace(this, this.constructor);
109
+ }
110
+ };
111
+ var tokenPrefix = "seam_";
112
+ var clientSessionTokenPrefix = "seam_cst";
113
+ var isClientSessionToken = (token) => token.startsWith(clientSessionTokenPrefix);
114
+ var isAccessToken = (token) => token.startsWith("seam_at");
115
+ var isJwt = (token) => token.startsWith("ey");
116
+ var isSeamToken = (token) => token.startsWith(tokenPrefix);
117
+
118
+ // src/lib/seam/connect/axios.ts
119
+ var createAxiosClient = (options) => {
120
+ return axios__default.default.create({
121
+ baseURL: options.endpoint,
122
+ withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
123
+ ...options.axiosOptions,
124
+ headers: {
125
+ ...getAuthHeaders(options),
126
+ ...options.axiosOptions.headers
127
+ // TODO: User-Agent
128
+ }
129
+ });
130
+ };
131
+
132
+ // src/lib/seam/connect/parse-options.ts
133
+ var parseOptions = (apiKeyOrOptions) => {
134
+ const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions;
135
+ const endpoint = options.endpoint ?? globalThis.process?.env?.["SEAM_ENDPOINT"] ?? globalThis.process?.env?.["SEAM_API_URL"] ?? "https://connect.getseam.com";
136
+ const apiKey = "apiKey" in options ? options.apiKey : globalThis.process?.env?.["SEAM_API_KEY"];
137
+ return {
138
+ ...options,
139
+ ...apiKey != null ? { apiKey } : {},
140
+ endpoint,
141
+ axiosOptions: options.axiosOptions ?? {},
142
+ enableLegacyMethodBehaivor: false
143
+ };
144
+ };
145
+
146
+ // src/lib/seam/connect/routes/workspaces.ts
147
+ var WorkspacesHttp = class {
148
+ constructor(apiKeyOrOptionsOrClient) {
149
+ if (apiKeyOrOptionsOrClient instanceof axios.Axios) {
150
+ this.client = apiKeyOrOptionsOrClient;
151
+ return;
152
+ }
153
+ const options = parseOptions(apiKeyOrOptionsOrClient);
154
+ this.client = createAxiosClient(options);
155
+ }
156
+ async get(params = {}) {
157
+ const { data } = await this.client.get(
158
+ "/workspaces/get",
159
+ {
160
+ params
161
+ }
162
+ );
163
+ return data.workspace;
164
+ }
165
+ };
166
+
167
+ // src/lib/seam/connect/legacy/workspaces.ts
168
+ var LegacyWorkspacesHttp = class extends WorkspacesHttp {
169
+ async get(params = {}) {
170
+ const { data } = await this.client.get(
171
+ "/workspaces/get",
172
+ {
173
+ params
174
+ }
175
+ );
176
+ return data.workspace;
177
+ }
178
+ };
179
+
180
+ // src/lib/seam/connect/client.ts
181
+ var _legacy;
182
+ var _SeamHttp = class _SeamHttp {
183
+ constructor(apiKeyOrOptions) {
184
+ __privateAdd(this, _legacy, void 0);
185
+ const options = parseOptions(apiKeyOrOptions);
186
+ __privateSet(this, _legacy, options.enableLegacyMethodBehaivor);
187
+ this.client = createAxiosClient(options);
188
+ }
189
+ static fromApiKey(apiKey, options = {}) {
190
+ const opts = { ...options, apiKey };
191
+ if (!isSeamHttpOptionsWithApiKey(opts)) {
192
+ throw new InvalidSeamHttpOptionsError("Missing apiKey");
193
+ }
194
+ return new _SeamHttp(opts);
195
+ }
196
+ static fromClientSessionToken(clientSessionToken, options = {}) {
197
+ const opts = { ...options, clientSessionToken };
198
+ if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
199
+ throw new InvalidSeamHttpOptionsError("Missing clientSessionToken");
200
+ }
201
+ return new _SeamHttp(opts);
202
+ }
203
+ // TODO
204
+ // static fromPublishableKey and deprecate getClientSessionToken
205
+ // TODO: Should we keep makeRequest?
206
+ // Better to implement error handling and wrapping in an error handler.
207
+ // makeRequest
208
+ get workspaces() {
209
+ if (__privateGet(this, _legacy))
210
+ return new LegacyWorkspacesHttp(this.client);
211
+ return new WorkspacesHttp(this.client);
212
+ }
213
+ };
214
+ _legacy = new WeakMap();
215
+ var SeamHttp = _SeamHttp;
216
+
217
+ exports.SeamHttp = SeamHttp;
218
+ //# sourceMappingURL=out.js.map
219
+ //# sourceMappingURL=connect.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/seam/connect/axios.ts","../src/lib/seam/connect/client-options.ts","../src/lib/seam/connect/auth.ts","../src/lib/seam/connect/routes/workspaces.ts","../src/lib/seam/connect/parse-options.ts","../src/lib/seam/connect/legacy/workspaces.ts","../src/lib/seam/connect/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAA2B;;;ACgB3B,IAAM,8BAA8B,CACzC,YACyC;AACzC,MAAI,EAAE,YAAY;AAAU,WAAO;AAEnC,MAAI,wBAAwB,WAAW,QAAQ,sBAAsB,MAAM;AACzE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAOO,IAAM,0CAA0C,CACrD,YACqD;AACrD,MAAI,EAAE,wBAAwB;AAAU,WAAO;AAE/C,MAAI,YAAY,WAAW,QAAQ,UAAU,MAAM;AACjD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,8BAAN,cAA0C,MAAM;AAAA,EACrD,YAAY,SAAiB;AAC3B,UAAM,sCAAsC,OAAO,EAAE;AACrD,SAAK,OAAO,KAAK,YAAY;AAC7B,UAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,EAChD;AACF;;;AC5CO,IAAM,iBAAiB,CAAC,YAAsC;AACnE,MAAI,4BAA4B,OAAO,GAAG;AACxC,WAAO,wBAAwB,OAAO;AAAA,EACxC;AAEA,MAAI,wCAAwC,OAAO,GAAG;AACpD,WAAO,oCAAoC,OAAO;AAAA,EACpD;AAEA,Q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pB,YAAY,iBAA2C;AAFvD;AAGE,UAAM,UAAU,aAAa,eAAe;AAC5C,uBAAK,SAAU,QAAQ;AACvB,SAAK,SAAS,kBAAkB,OAAO;AAAA,EACzC;AAAA,EAEA,OAAO,WACL,QACA,UAAqD,CAAC,GAC5C;AACV,UAAM,OAAO,EAAE,GAAG,SAAS,OAAO;AAClC,QAAI,CAAC,4BAA4B,IAAI,GAAG;AACtC,YAAM,IAAI,4BAA4B,gBAAgB;AAAA,IACxD;AACA,WAAO,IAAI,UAAS,IAAI;AAAA,EAC1B;AAAA,EAEA,OAAO,uBACL,oBACA,UAGI,CAAC,GACK;AACV,UAAM,OAAO,EAAE,GAAG,SAAS,mBAAmB;AAC9C,QAAI,CAAC,wCAAwC,IAAI,GAAG;AAClD,YAAM,IAAI,4BAA4B,4BAA4B;AAAA,IACpE;AACA,WAAO,IAAI,UAAS,IAAI;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,aAA6B;AAC/B,QAAI,mBAAK;AAAS,aAAO,IAAI,qBAAqB,KAAK,MAAM;AAC7D,WAAO,IAAI,eAAe,KAAK,MAAM;AAAA,EACvC;AACF;AA5CE;AAHK,IAAM,WAAN","sourcesContent":["import axios, { type Axios } from 'axios'\n\nimport { getAuthHeaders } from './auth.js'\nimport {\n isSeamHttpOptionsWithClientSessionToken,\n type SeamHttpOptions,\n} from './client-options.js'\n\nexport const createAxiosClient = (\n options: Required<SeamHttpOptions>,\n): Axios => {\n // TODO: axiosRetry? Allow options to configure this if so\n return axios.create({\n baseURL: options.endpoint,\n withCredentials: isSeamHttpOptionsWithClientSessionToken(options),\n ...options.axiosOptions,\n headers: {\n ...getAuthHeaders(options),\n ...options.axiosOptions.headers,\n // TODO: User-Agent\n },\n })\n}\n","import type { AxiosRequestConfig } from 'axios'\n\nexport type SeamHttpOptions =\n | SeamHttpOptionsWithApiKey\n | SeamHttpOptionsWithClientSessionToken\n\ninterface SeamHttpCommonOptions {\n endpoint?: string\n axiosOptions?: AxiosRequestConfig\n enableLegacyMethodBehaivor?: boolean\n}\n\nexport interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {\n apiKey: string\n}\n\nexport const isSeamHttpOptionsWithApiKey = (\n options: SeamHttpOptions,\n): options is SeamHttpOptionsWithApiKey => {\n if (!('apiKey' in options)) return false\n\n if ('clientSessionToken' in options && options.clientSessionToken != null) {\n throw new InvalidSeamHttpOptionsError(\n 'The clientSessionToken option cannot be used with the apiKey option.',\n )\n }\n\n return true\n}\n\nexport interface SeamHttpOptionsWithClientSessionToken\n extends SeamHttpCommonOptions {\n clientSessionToken: string\n}\n\nexport const isSeamHttpOptionsWithClientSessionToken = (\n options: SeamHttpOptions,\n): options is SeamHttpOptionsWithClientSessionToken => {\n if (!('clientSessionToken' in options)) return false\n\n if ('apiKey' in options && options.apiKey != null) {\n throw new InvalidSeamHttpOptionsError(\n 'The clientSessionToken option cannot be used with the apiKey option.',\n )\n }\n\n return true\n}\n\nexport class InvalidSeamHttpOptionsError extends Error {\n constructor(message: string) {\n super(`SeamHttp received invalid options: ${message}`)\n this.name = this.constructor.name\n Error.captureStackTrace(this, this.constructor)\n }\n}\n\n// TODO: withSessionToken { sessionToken } or withMultiWorkspaceApiKey { apiKey }?\n// export interface SeamHttpOptionsWithSessionToken extends SeamHttpCommonOptions {\n// workspaceId: string\n// apiKey: string\n// }\n","import {\n InvalidSeamHttpOptionsError,\n isSeamHttpOptionsWithApiKey,\n isSeamHttpOptionsWithClientSessionToken,\n type SeamHttpOptions,\n type SeamHttpOptionsWithApiKey,\n type SeamHttpOptionsWithClientSessionToken,\n} from './client-options.js'\n\ntype Headers = Record<string, string>\n\nexport const getAuthHeaders = (options: SeamHttpOptions): Headers => {\n if (isSeamHttpOptionsWithApiKey(options)) {\n return getAuthHeadersForApiKey(options)\n }\n\n if (isSeamHttpOptionsWithClientSessionToken(options)) {\n return getAuthHeadersForClientSessionToken(options)\n }\n\n throw new InvalidSeamHttpOptionsError(\n 'Must specify an apiKey or clientSessionToken',\n )\n}\n\nconst getAuthHeadersForApiKey = ({\n apiKey,\n}: SeamHttpOptionsWithApiKey): Headers => {\n if (isClientSessionToken(apiKey)) {\n throw new InvalidSeamTokenError(\n 'A Client Session Token cannot be used as an apiKey',\n )\n }\n\n if (isAccessToken(apiKey)) {\n throw new InvalidSeamTokenError(\n 'An access token cannot be used as an apiKey',\n )\n }\n\n if (isJwt(apiKey) || !isSeamToken(apiKey)) {\n throw new InvalidSeamTokenError(\n `Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`,\n )\n }\n\n return {\n authorization: `Bearer ${apiKey}`,\n }\n}\n\nconst getAuthHeadersForClientSessionToken = ({\n clientSessionToken,\n}: SeamHttpOptionsWithClientSessionToken): Headers => {\n if (!isClientSessionToken(clientSessionToken)) {\n throw new InvalidSeamTokenError(\n `Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`,\n )\n }\n\n return {\n authorization: `Bearer ${clientSessionToken}`,\n 'client-session-token': clientSessionToken,\n }\n}\n\nexport class InvalidSeamTokenError extends Error {\n constructor(message: string) {\n super(`SeamHttp received an invalid token: ${message}`)\n this.name = this.constructor.name\n Error.captureStackTrace(this, this.constructor)\n }\n}\n\nconst tokenPrefix = 'seam_'\n\nconst clientSessionTokenPrefix = 'seam_cst'\n\nconst isClientSessionToken = (token: string): boolean =>\n token.startsWith(clientSessionTokenPrefix)\n\nconst isAccessToken = (token: string): boolean => token.startsWith('seam_at')\n\nconst isJwt = (token: string): boolean => token.startsWith('ey')\n\nconst isSeamToken = (token: string): boolean => token.startsWith(tokenPrefix)\n","import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect'\nimport { Axios } from 'axios'\nimport type { SetNonNullable } from 'type-fest'\n\nimport { createAxiosClient } from 'lib/seam/connect/axios.js'\nimport type { SeamHttpOptions } from 'lib/seam/connect/client-options.js'\nimport { parseOptions } from 'lib/seam/connect/parse-options.js'\n\nexport class WorkspacesHttp {\n client: Axios\n\n constructor(apiKeyOrOptionsOrClient: Axios | string | SeamHttpOptions) {\n if (apiKeyOrOptionsOrClient instanceof Axios) {\n this.client = apiKeyOrOptionsOrClient\n return\n }\n\n const options = parseOptions(apiKeyOrOptionsOrClient)\n this.client = createAxiosClient(options)\n }\n\n async get(\n params: WorkspacesGetParams = {},\n ): Promise<WorkspacesGetResponse['workspace']> {\n const { data } = await this.client.get<WorkspacesGetResponse>(\n '/workspaces/get',\n {\n params,\n },\n )\n return data.workspace\n }\n}\n\nexport type WorkspacesGetParams = SetNonNullable<\n Required<RouteRequestParams<'/workspaces/get'>>\n>\n\nexport type WorkspacesGetResponse = SetNonNullable<\n Required<RouteResponse<'/workspaces/get'>>\n>\n","import type { SeamHttpOptions } from './client-options.js'\nexport const parseOptions = (\n apiKeyOrOptions: string | SeamHttpOptions,\n): Required<SeamHttpOptions> => {\n const options =\n typeof apiKeyOrOptions === 'string'\n ? { apiKey: apiKeyOrOptions }\n : apiKeyOrOptions\n\n const endpoint =\n options.endpoint ??\n globalThis.process?.env?.['SEAM_ENDPOINT'] ??\n globalThis.process?.env?.['SEAM_API_URL'] ??\n 'https://connect.getseam.com'\n\n const apiKey =\n 'apiKey' in options\n ? options.apiKey\n : globalThis.process?.env?.['SEAM_API_KEY']\n\n return {\n ...options,\n ...(apiKey != null ? { apiKey } : {}),\n endpoint,\n axiosOptions: options.axiosOptions ?? {},\n enableLegacyMethodBehaivor: false,\n }\n}\n","import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect'\nimport type { SetNonNullable } from 'type-fest'\n\nimport { WorkspacesHttp } from 'lib/seam/connect/routes/workspaces.js'\n\nexport class LegacyWorkspacesHttp extends WorkspacesHttp {\n override async get(\n params: WorkspacesGetParams = {},\n ): Promise<WorkspacesGetResponse['workspace']> {\n const { data } = await this.client.get<WorkspacesGetResponse>(\n '/workspaces/get',\n {\n params,\n },\n )\n return data.workspace\n }\n}\n\nexport type WorkspacesGetParams = SetNonNullable<\n Required<RouteRequestParams<'/workspaces/get'>>\n>\n\nexport type WorkspacesGetResponse = SetNonNullable<\n Required<RouteResponse<'/workspaces/get'>>\n>\n","import type { Axios } from 'axios'\n\nimport { createAxiosClient } from './axios.js'\nimport {\n InvalidSeamHttpOptionsError,\n isSeamHttpOptionsWithApiKey,\n isSeamHttpOptionsWithClientSessionToken,\n type SeamHttpOptions,\n type SeamHttpOptionsWithApiKey,\n type SeamHttpOptionsWithClientSessionToken,\n} from './client-options.js'\nimport { LegacyWorkspacesHttp } from './legacy/workspaces.js'\nimport { parseOptions } from './parse-options.js'\nimport { WorkspacesHttp } from './routes/workspaces.js'\n\nexport class SeamHttp {\n client: Axios\n\n #legacy: boolean\n\n constructor(apiKeyOrOptions: string | SeamHttpOptions) {\n const options = parseOptions(apiKeyOrOptions)\n this.#legacy = options.enableLegacyMethodBehaivor\n this.client = createAxiosClient(options)\n }\n\n static fromApiKey(\n apiKey: SeamHttpOptionsWithApiKey['apiKey'],\n options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},\n ): SeamHttp {\n const opts = { ...options, apiKey }\n if (!isSeamHttpOptionsWithApiKey(opts)) {\n throw new InvalidSeamHttpOptionsError('Missing apiKey')\n }\n return new SeamHttp(opts)\n }\n\n static fromClientSessionToken(\n clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],\n options: Omit<\n SeamHttpOptionsWithClientSessionToken,\n 'clientSessionToken'\n > = {},\n ): SeamHttp {\n const opts = { ...options, clientSessionToken }\n if (!isSeamHttpOptionsWithClientSessionToken(opts)) {\n throw new InvalidSeamHttpOptionsError('Missing clientSessionToken')\n }\n return new SeamHttp(opts)\n }\n\n // TODO\n // static fromPublishableKey and deprecate getClientSessionToken\n\n // TODO: Should we keep makeRequest?\n // Better to implement error handling and wrapping in an error handler.\n // makeRequest\n\n get workspaces(): WorkspacesHttp {\n if (this.#legacy) return new LegacyWorkspacesHttp(this.client)\n return new WorkspacesHttp(this.client)\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { AxiosRequestConfig, Axios } from 'axios';
2
+ import { RouteRequestParams, RouteResponse } from '@seamapi/types/connect';
3
+ import { SetNonNullable } from 'type-fest';
4
+
5
+ type SeamHttpOptions = SeamHttpOptionsWithApiKey | SeamHttpOptionsWithClientSessionToken;
6
+ interface SeamHttpCommonOptions {
7
+ endpoint?: string;
8
+ axiosOptions?: AxiosRequestConfig;
9
+ enableLegacyMethodBehaivor?: boolean;
10
+ }
11
+ interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {
12
+ apiKey: string;
13
+ }
14
+ interface SeamHttpOptionsWithClientSessionToken extends SeamHttpCommonOptions {
15
+ clientSessionToken: string;
16
+ }
17
+
18
+ declare class WorkspacesHttp {
19
+ client: Axios;
20
+ constructor(apiKeyOrOptionsOrClient: Axios | string | SeamHttpOptions);
21
+ get(params?: WorkspacesGetParams): Promise<WorkspacesGetResponse['workspace']>;
22
+ }
23
+ type WorkspacesGetParams = SetNonNullable<Required<RouteRequestParams<'/workspaces/get'>>>;
24
+ type WorkspacesGetResponse = SetNonNullable<Required<RouteResponse<'/workspaces/get'>>>;
25
+
26
+ declare class SeamHttp {
27
+ #private;
28
+ client: Axios;
29
+ constructor(apiKeyOrOptions: string | SeamHttpOptions);
30
+ static fromApiKey(apiKey: SeamHttpOptionsWithApiKey['apiKey'], options?: Omit<SeamHttpOptionsWithApiKey, 'apiKey'>): SeamHttp;
31
+ static fromClientSessionToken(clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options?: Omit<SeamHttpOptionsWithClientSessionToken, 'clientSessionToken'>): SeamHttp;
32
+ get workspaces(): WorkspacesHttp;
33
+ }
34
+
35
+ export { SeamHttp };
package/dist/index.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ var src_default = null;
5
+
6
+ module.exports = src_default;
7
+ //# sourceMappingURL=out.js.map
8
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,IAAO,cAAQ","sourcesContent":["export default null\n"]}
@@ -0,0 +1,3 @@
1
+ declare const _default: null;
2
+
3
+ export { _default as default };
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: null;
2
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export default null;
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,eAAe,IAAI,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { type SeamHttpOptions } from './client-options.js';
2
+ type Headers = Record<string, string>;
3
+ export declare const getAuthHeaders: (options: SeamHttpOptions) => Headers;
4
+ export declare class InvalidSeamTokenError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export {};
@@ -0,0 +1,47 @@
1
+ import { InvalidSeamHttpOptionsError, isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClientSessionToken, } from './client-options.js';
2
+ export const getAuthHeaders = (options) => {
3
+ if (isSeamHttpOptionsWithApiKey(options)) {
4
+ return getAuthHeadersForApiKey(options);
5
+ }
6
+ if (isSeamHttpOptionsWithClientSessionToken(options)) {
7
+ return getAuthHeadersForClientSessionToken(options);
8
+ }
9
+ throw new InvalidSeamHttpOptionsError('Must specify an apiKey or clientSessionToken');
10
+ };
11
+ const getAuthHeadersForApiKey = ({ apiKey, }) => {
12
+ if (isClientSessionToken(apiKey)) {
13
+ throw new InvalidSeamTokenError('A Client Session Token cannot be used as an apiKey');
14
+ }
15
+ if (isAccessToken(apiKey)) {
16
+ throw new InvalidSeamTokenError('An access token cannot be used as an apiKey');
17
+ }
18
+ if (isJwt(apiKey) || !isSeamToken(apiKey)) {
19
+ throw new InvalidSeamTokenError(`Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`);
20
+ }
21
+ return {
22
+ authorization: `Bearer ${apiKey}`,
23
+ };
24
+ };
25
+ const getAuthHeadersForClientSessionToken = ({ clientSessionToken, }) => {
26
+ if (!isClientSessionToken(clientSessionToken)) {
27
+ throw new InvalidSeamTokenError(`Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`);
28
+ }
29
+ return {
30
+ authorization: `Bearer ${clientSessionToken}`,
31
+ 'client-session-token': clientSessionToken,
32
+ };
33
+ };
34
+ export class InvalidSeamTokenError extends Error {
35
+ constructor(message) {
36
+ super(`SeamHttp received an invalid token: ${message}`);
37
+ this.name = this.constructor.name;
38
+ Error.captureStackTrace(this, this.constructor);
39
+ }
40
+ }
41
+ const tokenPrefix = 'seam_';
42
+ const clientSessionTokenPrefix = 'seam_cst';
43
+ const isClientSessionToken = (token) => token.startsWith(clientSessionTokenPrefix);
44
+ const isAccessToken = (token) => token.startsWith('seam_at');
45
+ const isJwt = (token) => token.startsWith('ey');
46
+ const isSeamToken = (token) => token.startsWith(tokenPrefix);
47
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,uCAAuC,GAIxC,MAAM,qBAAqB,CAAA;AAI5B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAwB,EAAW,EAAE;IAClE,IAAI,2BAA2B,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAA;KACxC;IAED,IAAI,uCAAuC,CAAC,OAAO,CAAC,EAAE;QACpD,OAAO,mCAAmC,CAAC,OAAO,CAAC,CAAA;KACpD;IAED,MAAM,IAAI,2BAA2B,CACnC,8CAA8C,CAC/C,CAAA;AACH,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAC,EAC/B,MAAM,GACoB,EAAW,EAAE;IACvC,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAChC,M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AK,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAEhE,MAAM,WAAW,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { type Axios } from 'axios';
2
+ import { type SeamHttpOptions } from './client-options.js';
3
+ export declare const createAxiosClient: (options: Required<SeamHttpOptions>) => Axios;
@@ -0,0 +1,17 @@
1
+ import axios, {} from 'axios';
2
+ import { getAuthHeaders } from './auth.js';
3
+ import { isSeamHttpOptionsWithClientSessionToken, } from './client-options.js';
4
+ export const createAxiosClient = (options) => {
5
+ // TODO: axiosRetry? Allow options to configure this if so
6
+ return axios.create({
7
+ baseURL: options.endpoint,
8
+ withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
9
+ ...options.axiosOptions,
10
+ headers: {
11
+ ...getAuthHeaders(options),
12
+ ...options.axiosOptions.headers,
13
+ // TODO: User-Agent
14
+ },
15
+ });
16
+ };
17
+ //# sourceMappingURL=axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/axios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EACL,uCAAuC,GAExC,MAAM,qBAAqB,CAAA;AAE5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAkC,EAC3B,EAAE;IACT,0DAA0D;IAC1D,OAAO,KAAK,CAAC,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC,QAAQ;QACzB,eAAe,EAAE,uCAAuC,CAAC,OAAO,CAAC;QACjE,GAAG,OAAO,CAAC,YAAY;QACvB,OAAO,EAAE;YACP,GAAG,cAAc,CAAC,OAAO,CAAC;YAC1B,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO;YAC/B,mBAAmB;SACpB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ export type SeamHttpOptions = SeamHttpOptionsWithApiKey | SeamHttpOptionsWithClientSessionToken;
3
+ interface SeamHttpCommonOptions {
4
+ endpoint?: string;
5
+ axiosOptions?: AxiosRequestConfig;
6
+ enableLegacyMethodBehaivor?: boolean;
7
+ }
8
+ export interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {
9
+ apiKey: string;
10
+ }
11
+ export declare const isSeamHttpOptionsWithApiKey: (options: SeamHttpOptions) => options is SeamHttpOptionsWithApiKey;
12
+ export interface SeamHttpOptionsWithClientSessionToken extends SeamHttpCommonOptions {
13
+ clientSessionToken: string;
14
+ }
15
+ export declare const isSeamHttpOptionsWithClientSessionToken: (options: SeamHttpOptions) => options is SeamHttpOptionsWithClientSessionToken;
16
+ export declare class InvalidSeamHttpOptionsError extends Error {
17
+ constructor(message: string);
18
+ }
19
+ export {};
@@ -0,0 +1,29 @@
1
+ export const isSeamHttpOptionsWithApiKey = (options) => {
2
+ if (!('apiKey' in options))
3
+ return false;
4
+ if ('clientSessionToken' in options && options.clientSessionToken != null) {
5
+ throw new InvalidSeamHttpOptionsError('The clientSessionToken option cannot be used with the apiKey option.');
6
+ }
7
+ return true;
8
+ };
9
+ export const isSeamHttpOptionsWithClientSessionToken = (options) => {
10
+ if (!('clientSessionToken' in options))
11
+ return false;
12
+ if ('apiKey' in options && options.apiKey != null) {
13
+ throw new InvalidSeamHttpOptionsError('The clientSessionToken option cannot be used with the apiKey option.');
14
+ }
15
+ return true;
16
+ };
17
+ export class InvalidSeamHttpOptionsError extends Error {
18
+ constructor(message) {
19
+ super(`SeamHttp received invalid options: ${message}`);
20
+ this.name = this.constructor.name;
21
+ Error.captureStackTrace(this, this.constructor);
22
+ }
23
+ }
24
+ // TODO: withSessionToken { sessionToken } or withMultiWorkspaceApiKey { apiKey }?
25
+ // export interface SeamHttpOptionsWithSessionToken extends SeamHttpCommonOptions {
26
+ // workspaceId: string
27
+ // apiKey: string
28
+ // }
29
+ //# sourceMappingURL=client-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-options.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/client-options.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,OAAwB,EACc,EAAE;IACxC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IAExC,IAAI,oBAAoB,IAAI,OAAO,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAI,EAAE;QACzE,MAAM,IAAI,2BAA2B,CACnC,sEAAsE,CACvE,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAOD,MAAM,CAAC,MAAM,uCAAuC,GAAG,CACrD,OAAwB,EAC0B,EAAE;IACpD,IAAI,CAAC,CAAC,oBAAoB,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpD,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;QACjD,MAAM,IAAI,2BAA2B,CACnC,sEAAsE,CACvE,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,sCAAsC,OAAO,EAAE,CAAC,CAAA;QACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACjD,CAAC;CACF;AAED,kFAAkF;AAClF,mFAAmF;AACnF,wBAAwB;AACxB,mBAAmB;AACnB,IAAI"}
@@ -0,0 +1,11 @@
1
+ import type { Axios } from 'axios';
2
+ import { type SeamHttpOptions, type SeamHttpOptionsWithApiKey, type SeamHttpOptionsWithClientSessionToken } from './client-options.js';
3
+ import { WorkspacesHttp } from './routes/workspaces.js';
4
+ export declare class SeamHttp {
5
+ #private;
6
+ client: Axios;
7
+ constructor(apiKeyOrOptions: string | SeamHttpOptions);
8
+ static fromApiKey(apiKey: SeamHttpOptionsWithApiKey['apiKey'], options?: Omit<SeamHttpOptionsWithApiKey, 'apiKey'>): SeamHttp;
9
+ static fromClientSessionToken(clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options?: Omit<SeamHttpOptionsWithClientSessionToken, 'clientSessionToken'>): SeamHttp;
10
+ get workspaces(): WorkspacesHttp;
11
+ }