@seamapi/http 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -261,10 +261,58 @@ try {
261
261
 
262
262
  [action attempt]: https://docs.seam.co/latest/core-concepts/action-attempts
263
263
 
264
+ ### Interacting with Multiple Workspaces
265
+
266
+ Some Seam API endpoints interact with multiple workspaces.
267
+ The `SeamHttpMultiWorkspace` client is not bound to a specific workspace
268
+ and may use those endpoints with an appropriate authentication method.
269
+
270
+ #### Personal Access Token
271
+
272
+ A Personal Access Token is scoped to a Seam Console user.
273
+ Obtain one from the Seam Console.
274
+
275
+ ```ts
276
+ // Pass as an option the constructor
277
+ const seam = new SeamHttpMultiWorkspace({
278
+ personalAccessToken: 'your-personal-access-token',
279
+ })
280
+
281
+ // Use the factory method
282
+ const seam = SeamHttpMultiWorkspace.fromPersonalAccessToken(
283
+ 'some-console-session-token',
284
+ )
285
+
286
+ // List workspaces authorized for this Personal Access Token
287
+ const workspaces = await seam.workspaces.list()
288
+ ```
289
+
290
+ #### Console Session Token
291
+
292
+ A Console Session Token is used by the Seam Console.
293
+ This authentication method is only used by internal Seam applications.
294
+
295
+ ```ts
296
+ // Pass as an option the constructor
297
+ const seam = new SeamHttpMultiWorkspace({
298
+ consoleSessionToken: 'some-console-session-token',
299
+ })
300
+
301
+ // Use the factory method
302
+ const seam = SeamHttpMultiWorkspace.fromConsoleSessionToken(
303
+ 'some-console-session-token',
304
+ )
305
+
306
+ // List workspaces authorized for this Seam Console user
307
+ const workspaces = await seam.workspaces.list()
308
+ ```
309
+
264
310
  ### Advanced Usage
265
311
 
312
+ #### Additional Options
313
+
266
314
  In addition the various authentication options,
267
- the constructor takes some additional options that affect behavior.
315
+ the constructor takes some advanced options that affect behavior.
268
316
 
269
317
  ```ts
270
318
  const seam = new SeamHttp({
package/dist/connect.cjs CHANGED
@@ -515,6 +515,78 @@ var getRequestId = (err) => {
515
515
  return requestId;
516
516
  };
517
517
 
518
+ // src/lib/params-serializer.ts
519
+ var paramsSerializer = (params) => {
520
+ const searchParams = new URLSearchParams();
521
+ for (const [name, value] of Object.entries(params)) {
522
+ if (value == null)
523
+ continue;
524
+ if (Array.isArray(value)) {
525
+ if (value.length === 0)
526
+ searchParams.set(name, "");
527
+ if (value.length === 1 && value[0] === "") {
528
+ throw new UnserializableParamError(
529
+ name,
530
+ `is a single element array containing the empty string which is unsupported because it serializes to the empty array`
531
+ );
532
+ }
533
+ for (const v of value) {
534
+ searchParams.append(name, serialize(name, v));
535
+ }
536
+ continue;
537
+ }
538
+ searchParams.set(name, serialize(name, value));
539
+ }
540
+ searchParams.sort();
541
+ return searchParams.toString();
542
+ };
543
+ var serialize = (k, v) => {
544
+ if (typeof v === "string")
545
+ return v.toString();
546
+ if (typeof v === "number")
547
+ return v.toString();
548
+ if (typeof v === "bigint")
549
+ return v.toString();
550
+ if (typeof v === "boolean")
551
+ return v.toString();
552
+ throw new UnserializableParamError(k, `is a ${typeof v}`);
553
+ };
554
+ var UnserializableParamError = class extends Error {
555
+ constructor(name, message) {
556
+ super(`Could not serialize parameter: '${name}' ${message}`);
557
+ this.name = this.constructor.name;
558
+ Error.captureStackTrace(this, this.constructor);
559
+ }
560
+ };
561
+
562
+ // src/lib/seam/connect/client.ts
563
+ var createClient = (options) => {
564
+ const client = axios__default.default.create({
565
+ paramsSerializer,
566
+ ...options.axiosOptions
567
+ });
568
+ axiosBetterStacktrace__default.default(axios__default.default);
569
+ axiosRetry__default.default(client, {
570
+ retries: 2,
571
+ retryDelay: axiosRetry.exponentialDelay,
572
+ ...options.axiosRetryOptions
573
+ });
574
+ client.interceptors.response.use(void 0, errorInterceptor);
575
+ return client;
576
+ };
577
+
578
+ // src/lib/seam/connect/openapi.ts
579
+ var getOpenapiSchema = async (endpoint = defaultEndpoint) => {
580
+ const client = createClient({
581
+ axiosOptions: {
582
+ baseURL: endpoint,
583
+ headers: sdkHeaders
584
+ }
585
+ });
586
+ const { data } = await client.get("/openapi.json");
587
+ return data;
588
+ };
589
+
518
590
  // src/lib/seam/connect/resolve-action-attempt.ts
519
591
  var resolveActionAttempt = async (actionAttempt, actionAttempts, { timeout = 5e3, pollingInterval = 500 }) => {
520
592
  let timeoutRef;
@@ -590,66 +662,6 @@ var SeamActionAttemptTimeoutError = class extends SeamActionAttemptError {
590
662
  var isSuccessfulActionAttempt = (actionAttempt) => actionAttempt.status === "success";
591
663
  var isFailedActionAttempt = (actionAttempt) => actionAttempt.status === "error";
592
664
 
593
- // src/lib/params-serializer.ts
594
- var paramsSerializer = (params) => {
595
- const searchParams = new URLSearchParams();
596
- for (const [name, value] of Object.entries(params)) {
597
- if (value == null)
598
- continue;
599
- if (Array.isArray(value)) {
600
- if (value.length === 0)
601
- searchParams.set(name, "");
602
- if (value.length === 1 && value[0] === "") {
603
- throw new UnserializableParamError(
604
- name,
605
- `is a single element array containing the empty string which is unsupported because it serializes to the empty array`
606
- );
607
- }
608
- for (const v of value) {
609
- searchParams.append(name, serialize(name, v));
610
- }
611
- continue;
612
- }
613
- searchParams.set(name, serialize(name, value));
614
- }
615
- searchParams.sort();
616
- return searchParams.toString();
617
- };
618
- var serialize = (k, v) => {
619
- if (typeof v === "string")
620
- return v.toString();
621
- if (typeof v === "number")
622
- return v.toString();
623
- if (typeof v === "bigint")
624
- return v.toString();
625
- if (typeof v === "boolean")
626
- return v.toString();
627
- throw new UnserializableParamError(k, `is a ${typeof v}`);
628
- };
629
- var UnserializableParamError = class extends Error {
630
- constructor(name, message) {
631
- super(`Could not serialize parameter: '${name}' ${message}`);
632
- this.name = this.constructor.name;
633
- Error.captureStackTrace(this, this.constructor);
634
- }
635
- };
636
-
637
- // src/lib/seam/connect/client.ts
638
- var createClient = (options) => {
639
- const client = axios__default.default.create({
640
- paramsSerializer,
641
- ...options.axiosOptions
642
- });
643
- axiosBetterStacktrace__default.default(axios__default.default);
644
- axiosRetry__default.default(client, {
645
- retries: 2,
646
- retryDelay: axiosRetry.exponentialDelay,
647
- ...options.axiosRetryOptions
648
- });
649
- client.interceptors.response.use(void 0, errorInterceptor);
650
- return client;
651
- };
652
-
653
665
  // src/lib/seam/connect/routes/client-sessions.ts
654
666
  var SeamHttpClientSessions = class _SeamHttpClientSessions {
655
667
  constructor(apiKeyOrOptions = {}) {
@@ -3333,6 +3345,7 @@ exports.SeamHttpWebhooks = SeamHttpWebhooks;
3333
3345
  exports.SeamHttpWorkspaces = SeamHttpWorkspaces;
3334
3346
  exports.UnserializableParamError = UnserializableParamError;
3335
3347
  exports.errorInterceptor = errorInterceptor;
3348
+ exports.getOpenapiSchema = getOpenapiSchema;
3336
3349
  exports.isSeamActionAttemptError = isSeamActionAttemptError;
3337
3350
  exports.isSeamActionAttemptFailedError = isSeamActionAttemptFailedError;
3338
3351
  exports.isSeamActionAttemptTimeoutError = isSeamActionAttemptTimeoutError;