@collective-intelligence/external-apps-server-sdk 0.1.0 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -393,15 +393,88 @@ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get",
393
393
  conversationId: string;
394
394
  runId: string;
395
395
  }> | EnvelopeSuccess<"conversations_history", ConversationHistory>;
396
+ /**
397
+ * Operations only the confidential application itself may invoke. They stay
398
+ * out of `externalApplicationOperationIds`, so browser clients and the user
399
+ * proxy never offer them.
400
+ */
401
+ /** A person whose only role in the application's Organization is `member`. */
402
+ interface MemberUser {
403
+ email: string | null;
404
+ name: string | null;
405
+ userId: string;
406
+ }
407
+ /**
408
+ * How create-or-get resolved the email: a new user, an existing CI user who
409
+ * joined the Organization as a member, or a user who already was one.
410
+ */
411
+ type MemberUserResolution = "created" | "existing" | "linked";
412
+ interface MemberUserPage {
413
+ items: MemberUser[];
414
+ page: number;
415
+ pageSize: number;
416
+ totalItems: number;
417
+ }
418
+ export type ExternalApplicationServiceOperationRequest = {
419
+ input: {
420
+ email: string;
421
+ name: string;
422
+ };
423
+ operationId: "members_create_or_get";
424
+ } | {
425
+ input: {
426
+ userId: string;
427
+ };
428
+ operationId: "members_get";
429
+ } | {
430
+ input: {
431
+ page?: number;
432
+ pageSize?: number;
433
+ };
434
+ operationId: "members_list";
435
+ } | {
436
+ input: {
437
+ name: string;
438
+ userId: string;
439
+ };
440
+ operationId: "members_update";
441
+ } | {
442
+ input: {
443
+ userId: string;
444
+ };
445
+ operationId: "members_remove";
446
+ } | {
447
+ input: {
448
+ userId: string;
449
+ };
450
+ operationId: "users_list_company_links";
451
+ } | {
452
+ input: {
453
+ entityIds: string[];
454
+ userId: string;
455
+ };
456
+ operationId: "users_link_companies";
457
+ };
458
+ /** A user's linked company entities, in entity id order. */
459
+ export interface UserCompanyLinks {
460
+ entityIds: string[];
461
+ }
462
+ export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"members_create_or_get", MemberUser & {
463
+ outcome: MemberUserResolution;
464
+ }> | EnvelopeSuccess<"members_get", MemberUser> | EnvelopeSuccess<"members_list", MemberUserPage> | EnvelopeSuccess<"members_update", MemberUser> | EnvelopeSuccess<"members_remove", {
465
+ userId: string;
466
+ }> | EnvelopeSuccess<"users_list_company_links", UserCompanyLinks> | EnvelopeSuccess<"users_link_companies", UserCompanyLinks>;
467
+ /** Every operation a confidential server client may invoke. */
468
+ export type ExternalApplicationServerOperationRequest = ExternalApplicationOperationRequest | ExternalApplicationServiceOperationRequest;
396
469
  export type ExternalApplicationOperationFailure = ExternalApplicationsGetContextError;
397
- export type ExternalApplicationOperationId = ExternalApplicationOperationRequest["operationId"];
398
- export type ExternalApplicationOperationRequestFor<Id extends ExternalApplicationOperationId> = Extract<ExternalApplicationOperationRequest, {
470
+ export type ExternalApplicationServerOperationId = ExternalApplicationServerOperationRequest["operationId"];
471
+ export type ExternalApplicationOperationRequestFor<Id extends ExternalApplicationServerOperationId> = Extract<ExternalApplicationServerOperationRequest, {
399
472
  operationId: Id;
400
473
  }>;
401
- export type ExternalApplicationOperationSuccessFor<Id extends ExternalApplicationOperationId> = Extract<ExternalApplicationOperationSuccess, {
474
+ export type ExternalApplicationOperationSuccessFor<Id extends ExternalApplicationServerOperationId> = Extract<ExternalApplicationOperationSuccess | ExternalApplicationServiceOperationSuccess, {
402
475
  operationId: Id;
403
476
  }>;
404
- export type ExternalApplicationOperationResult<Id extends ExternalApplicationOperationId> = Readonly<{
477
+ export type ExternalApplicationOperationResult<Id extends ExternalApplicationServerOperationId> = Readonly<{
405
478
  error: ExternalApplicationOperationFailure;
406
479
  ok: false;
407
480
  }> | Readonly<{
@@ -458,15 +531,15 @@ export interface ServerInvocationContext {
458
531
  readonly signal?: AbortSignal;
459
532
  readonly traceparent?: string;
460
533
  }
461
- export type OperationInput<Id extends ExternalApplicationOperationId> = ExternalApplicationOperationRequestFor<Id>["input"];
534
+ export type OperationInput<Id extends ExternalApplicationServerOperationId> = ExternalApplicationOperationRequestFor<Id>["input"];
462
535
  export type ManagedInput<Input> = Input extends {
463
536
  idempotencyKey: string;
464
537
  } ? Omit<Input, "idempotencyKey"> & {
465
538
  readonly idempotencyKey?: string;
466
539
  } : Input;
467
- export type ManagedOperationInput<Id extends ExternalApplicationOperationId> = ManagedInput<OperationInput<Id>>;
468
- export type ServerOperationRequest<Id extends ExternalApplicationOperationId> = ManagedOperationInput<Id> & ServerInvocationContext;
469
- export type ServerOperationMethod<Id extends ExternalApplicationOperationId> = (request: ServerOperationRequest<Id>) => Promise<ExternalApplicationOperationResult<Id>>;
540
+ export type ManagedOperationInput<Id extends ExternalApplicationServerOperationId> = ManagedInput<OperationInput<Id>>;
541
+ export type ServerOperationRequest<Id extends ExternalApplicationServerOperationId> = ManagedOperationInput<Id> & ServerInvocationContext;
542
+ export type ServerOperationMethod<Id extends ExternalApplicationServerOperationId> = (request: ServerOperationRequest<Id>) => Promise<ExternalApplicationOperationResult<Id>>;
470
543
  export type RunOperationId = "runs_cancel" | "runs_get" | "runs_stream";
471
544
  export type ServerRunStatus = "accepted" | "cancelled" | "failed" | "running" | "succeeded";
472
545
  /**
@@ -566,6 +639,21 @@ export interface ServerClient {
566
639
  updateRelation: ServerOperationMethod<"knowledge_update_relation">;
567
640
  upsertEntity: ServerOperationMethod<"knowledge_upsert_entity">;
568
641
  }>;
642
+ /**
643
+ * Member users of the application's Organization: people whose only role
644
+ * there is `member`. Needs `members:read` (get, list) or `members:write`
645
+ * (createOrGet, update, remove) and confidential credentials; a user with
646
+ * any other role is refused. `createOrGet` resolves an email to the same
647
+ * user on every call and never sends CI's activation invitation. `remove`
648
+ * ends the membership and keeps the CI user.
649
+ */
650
+ readonly members: Readonly<{
651
+ createOrGet: ServerOperationMethod<"members_create_or_get">;
652
+ get: ServerOperationMethod<"members_get">;
653
+ list: ServerOperationMethod<"members_list">;
654
+ remove: ServerOperationMethod<"members_remove">;
655
+ update: ServerOperationMethod<"members_update">;
656
+ }>;
569
657
  readonly runs: Readonly<{
570
658
  cancel: ServerRunOperationMethod<"runs_cancel", ServerRun>;
571
659
  get: ServerRunOperationMethod<"runs_get", ServerRun>;
@@ -575,11 +663,63 @@ export interface ServerClient {
575
663
  invoke: ServerOperationMethod<"skills_invoke">;
576
664
  list: ServerOperationMethod<"skills_list">;
577
665
  }>;
666
+ /**
667
+ * Organization members' links to the company entities they act for.
668
+ * Confidential service credentials only; the Organization is the caller's.
669
+ */
670
+ readonly users: Readonly<{
671
+ /** Links `userId` to `entityIds`, keeping existing links; returns all of them. */
672
+ linkCompanies: ServerOperationMethod<"users_link_companies">;
673
+ listCompanyLinks: ServerOperationMethod<"users_list_company_links">;
674
+ }>;
578
675
  readonly workflows: Readonly<{
579
676
  invoke: ServerOperationMethod<"workflows_invoke">;
580
677
  list: ServerOperationMethod<"workflows_list">;
581
678
  }>;
582
679
  }
680
+ declare const oauthErrorCodes: readonly [
681
+ "invalid_client",
682
+ "invalid_grant",
683
+ "invalid_request",
684
+ "invalid_scope",
685
+ "invalid_target",
686
+ "temporarily_unavailable",
687
+ "unauthorized_client",
688
+ "unsupported_grant_type"
689
+ ];
690
+ /**
691
+ * `invalid_grant` means the member's CI session ended or the member cannot act
692
+ * in the Organization: sign the member in again. `invalid_response` means CI
693
+ * answered with neither a token nor an OAuth error. Other codes are CI's OAuth
694
+ * errors and point at the application's configuration or CI availability.
695
+ */
696
+ export type MemberSessionExchangeErrorCode = (typeof oauthErrorCodes)[number] | "invalid_response";
697
+ export interface MemberSessionExchangeRequest {
698
+ readonly credentials: ConfidentialCredentialProvider;
699
+ readonly fetch?: typeof globalThis.fetch;
700
+ /** The Organization the member acts in; the application must be allowed in it. */
701
+ readonly organizationId: string;
702
+ /** A subset of the application's scopes. */
703
+ readonly scopes: readonly string[];
704
+ /** The member's CI session token, for example from `POST /auth/otp/verify`. */
705
+ readonly sessionToken: string;
706
+ /** Cancels the exchange; a cancelled exchange rejects with the signal's reason. */
707
+ readonly signal?: AbortSignal;
708
+ readonly tenantUrl: string;
709
+ /** Bound on the request and its response body. Defaults to 10 seconds. */
710
+ readonly timeoutMs?: number;
711
+ }
712
+ export interface MemberAccessToken {
713
+ readonly accessToken: string;
714
+ /** When to exchange again: before CI's expiry, which is counted from signing. */
715
+ readonly expiresAt: Date;
716
+ }
717
+ declare class MemberSessionExchangeError extends Error {
718
+ readonly code: MemberSessionExchangeErrorCode;
719
+ /** The HTTP status CI answered with; absent when CI was unreachable. */
720
+ readonly status: number | undefined;
721
+ constructor(code: MemberSessionExchangeErrorCode, status: number | undefined, options?: ErrorOptions);
722
+ }
583
723
  export type RunAsApplicationConfig = Readonly<{
584
724
  auditSubject: ExternalApplicationExternalAuditSubject;
585
725
  credentials: ConfidentialCredentials;
@@ -592,6 +732,14 @@ export type RunAsApplicationConfig = Readonly<{
592
732
  }>;
593
733
  export declare const createServerClient: (config: ServerClientConfig) => ServerClient, serverSdkRuntime: "node";
594
734
  export declare const runAsApplication: (config: RunAsApplicationConfig) => ServerClient;
735
+ export declare const exchangeMemberSession: (request: MemberSessionExchangeRequest) => Promise<MemberAccessToken>, MemberSessionExchangeError$1: typeof MemberSessionExchangeError;
595
736
  export declare const uuidV7: () => string;
596
737
 
738
+ export {
739
+ MemberSessionExchangeError$1 as MemberSessionExchangeError,
740
+ MemberUser as ServerMemberUser,
741
+ MemberUserPage as ServerMemberUserPage,
742
+ MemberUserResolution as ServerMemberUserResolution,
743
+ };
744
+
597
745
  export {};