@collective-intelligence/external-apps-server-sdk 0.1.10 → 0.1.11

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
@@ -25,6 +25,7 @@ export type ExternalApplicationsGetContextErrors = {
25
25
  error: {
26
26
  code: "invalid_request";
27
27
  message: string;
28
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
28
29
  retryable: false;
29
30
  };
30
31
  };
@@ -36,6 +37,7 @@ export type ExternalApplicationsGetContextErrors = {
36
37
  error: {
37
38
  code: "authentication_required";
38
39
  message: string;
40
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
39
41
  retryable: false;
40
42
  };
41
43
  };
@@ -47,6 +49,7 @@ export type ExternalApplicationsGetContextErrors = {
47
49
  error: {
48
50
  code: "authorization_denied";
49
51
  message: string;
52
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
50
53
  retryable: false;
51
54
  };
52
55
  };
@@ -58,6 +61,7 @@ export type ExternalApplicationsGetContextErrors = {
58
61
  error: {
59
62
  code: "operation_not_allowed";
60
63
  message: string;
64
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
61
65
  retryable: false;
62
66
  };
63
67
  } | {
@@ -65,6 +69,7 @@ export type ExternalApplicationsGetContextErrors = {
65
69
  error: {
66
70
  code: "not_found";
67
71
  message: string;
72
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
68
73
  retryable: false;
69
74
  };
70
75
  };
@@ -76,6 +81,7 @@ export type ExternalApplicationsGetContextErrors = {
76
81
  error: {
77
82
  code: "conflict";
78
83
  message: string;
84
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
79
85
  retryable: false;
80
86
  };
81
87
  };
@@ -87,6 +93,7 @@ export type ExternalApplicationsGetContextErrors = {
87
93
  error: {
88
94
  code: "internal_error";
89
95
  message: string;
96
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
90
97
  retryable: false;
91
98
  };
92
99
  };
@@ -98,11 +105,93 @@ export type ExternalApplicationsGetContextErrors = {
98
105
  error: {
99
106
  code: "temporarily_unavailable";
100
107
  message: string;
108
+ reason?: "users_create_forbidden" | "role_not_assignable" | "user_unavailable" | "target_inactive" | "user_not_found" | "user_not_created_by_app" | "application_unavailable" | "actor_not_allowed";
101
109
  retryable: true;
102
110
  };
103
111
  };
104
112
  };
105
113
  export type ExternalApplicationsGetContextError = ExternalApplicationsGetContextErrors[keyof ExternalApplicationsGetContextErrors];
114
+ export type ExternalApplicationsListAppUsersResponses = {
115
+ /**
116
+ * Success
117
+ */
118
+ 200: {
119
+ correlationId: string;
120
+ result: {
121
+ items: Array<{
122
+ email: string | null;
123
+ name: string | null;
124
+ userId: string;
125
+ }>;
126
+ };
127
+ };
128
+ };
129
+ export type ExternalApplicationsListAppUsersResponse = ExternalApplicationsListAppUsersResponses[keyof ExternalApplicationsListAppUsersResponses];
130
+ export type ExternalApplicationsCreateOrGetAppUserData = {
131
+ body: {
132
+ email: string;
133
+ name: string;
134
+ roles: Array<string>;
135
+ };
136
+ headers: {
137
+ authorization?: string;
138
+ "x-organization-id": string;
139
+ "x-correlation-id"?: string;
140
+ "x-external-audit-issuer"?: string;
141
+ "x-external-audit-subject"?: string;
142
+ "x-external-caller-kind"?: "anonymous_visitor";
143
+ "x-external-ci-user-id"?: string;
144
+ "x-external-server-role"?: string;
145
+ };
146
+ path?: never;
147
+ query?: never;
148
+ url: "/application/v1/users";
149
+ };
150
+ export type ExternalApplicationsCreateOrGetAppUserResponses = {
151
+ /**
152
+ * Success
153
+ */
154
+ 200: {
155
+ correlationId: string;
156
+ result: {
157
+ email: string | null;
158
+ name: string | null;
159
+ userId: string;
160
+ created: boolean;
161
+ kind: "member" | "external_app_user";
162
+ };
163
+ };
164
+ };
165
+ export type ExternalApplicationsCreateOrGetAppUserResponse = ExternalApplicationsCreateOrGetAppUserResponses[keyof ExternalApplicationsCreateOrGetAppUserResponses];
166
+ export type ExternalApplicationsGetAppUserResponses = {
167
+ /**
168
+ * Success
169
+ */
170
+ 200: {
171
+ correlationId: string;
172
+ result: {
173
+ email: string | null;
174
+ name: string | null;
175
+ userId: string;
176
+ };
177
+ };
178
+ };
179
+ export type ExternalApplicationsGetAppUserResponse = ExternalApplicationsGetAppUserResponses[keyof ExternalApplicationsGetAppUserResponses];
180
+ export type ExternalApplicationsListAppRolesResponses = {
181
+ /**
182
+ * Success
183
+ */
184
+ 200: {
185
+ correlationId: string;
186
+ result: {
187
+ items: Array<{
188
+ id: string;
189
+ key: string;
190
+ }>;
191
+ };
192
+ };
193
+ };
194
+ export type ExternalApplicationsListAppRolesResponse = ExternalApplicationsListAppRolesResponses[keyof ExternalApplicationsListAppRolesResponses];
106
195
  export type JsonValue = boolean | null | number | readonly JsonValue[] | Readonly<{
107
196
  readonly [key: string]: JsonValue;
108
197
  }> | string;
@@ -187,6 +276,40 @@ export type KnowledgeQuery = {
187
276
  op: "autocomplete";
188
277
  });
189
278
  export type ExternalApplicationOperationRequest = {
279
+ input: {
280
+ userId: string;
281
+ };
282
+ operationId: "users_get";
283
+ } | {
284
+ input: {
285
+ page?: number;
286
+ pageSize?: number;
287
+ };
288
+ operationId: "users_list";
289
+ } | {
290
+ input: {
291
+ userId: string;
292
+ };
293
+ operationId: "users_deactivate";
294
+ } | {
295
+ input: Record<string, never>;
296
+ operationId: "roles_list";
297
+ } | {
298
+ input: {
299
+ userId: string;
300
+ roles: string[];
301
+ };
302
+ operationId: "roles_assign";
303
+ } | {
304
+ input: {
305
+ userId: string;
306
+ roles: string[];
307
+ };
308
+ operationId: "roles_revoke";
309
+ } | {
310
+ input: ExternalApplicationsCreateOrGetAppUserData["body"];
311
+ operationId: "users_create_or_get";
312
+ } | {
190
313
  input: JsonObject | unknown[];
191
314
  operationId: "context_get";
192
315
  } | {
@@ -388,7 +511,15 @@ export interface EnvelopeSuccess<Id extends string, Result> {
388
511
  operationId: Id;
389
512
  result: Result;
390
513
  }
391
- export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get", JsonObject> | EnvelopeSuccess<"knowledge_query", JsonObject> | EnvelopeSuccess<"knowledge_get_entity_schema_snapshot", JsonObject> | EnvelopeSuccess<"knowledge_search_entities", JsonObject> | EnvelopeSuccess<"knowledge_facets", JsonObject> | EnvelopeSuccess<"knowledge_get_schema_query_context", JsonObject> | EnvelopeSuccess<"knowledge_autocomplete", JsonObject> | EnvelopeSuccess<"knowledge_get_entity", JsonObject> | EnvelopeSuccess<"knowledge_create_entity", JsonObject> | EnvelopeSuccess<"knowledge_update_entity", JsonObject> | EnvelopeSuccess<"knowledge_upsert_entity", JsonObject> | EnvelopeSuccess<"knowledge_delete_entity", JsonObject> | EnvelopeSuccess<"knowledge_traverse", JsonObject> | EnvelopeSuccess<"knowledge_create_relation", JsonObject> | EnvelopeSuccess<"knowledge_update_relation", JsonObject> | EnvelopeSuccess<"knowledge_delete_relation", JsonObject> | EnvelopeSuccess<"agents_list", JsonObject> | EnvelopeSuccess<"agents_invoke", {
514
+ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"users_get", ApplicationUser> | EnvelopeSuccess<"users_list", ApplicationUserPage> | EnvelopeSuccess<"users_deactivate", {
515
+ userId: string;
516
+ }> | EnvelopeSuccess<"roles_list", {
517
+ items: ApplicationRole[];
518
+ }> | EnvelopeSuccess<"roles_assign", {
519
+ userId: string;
520
+ }> | EnvelopeSuccess<"roles_revoke", {
521
+ userId: string;
522
+ }> | EnvelopeSuccess<"users_create_or_get", ApplicationUserResolution> | EnvelopeSuccess<"context_get", JsonObject> | EnvelopeSuccess<"knowledge_query", JsonObject> | EnvelopeSuccess<"knowledge_get_entity_schema_snapshot", JsonObject> | EnvelopeSuccess<"knowledge_search_entities", JsonObject> | EnvelopeSuccess<"knowledge_facets", JsonObject> | EnvelopeSuccess<"knowledge_get_schema_query_context", JsonObject> | EnvelopeSuccess<"knowledge_autocomplete", JsonObject> | EnvelopeSuccess<"knowledge_get_entity", JsonObject> | EnvelopeSuccess<"knowledge_create_entity", JsonObject> | EnvelopeSuccess<"knowledge_update_entity", JsonObject> | EnvelopeSuccess<"knowledge_upsert_entity", JsonObject> | EnvelopeSuccess<"knowledge_delete_entity", JsonObject> | EnvelopeSuccess<"knowledge_traverse", JsonObject> | EnvelopeSuccess<"knowledge_create_relation", JsonObject> | EnvelopeSuccess<"knowledge_update_relation", JsonObject> | EnvelopeSuccess<"knowledge_delete_relation", JsonObject> | EnvelopeSuccess<"agents_list", JsonObject> | EnvelopeSuccess<"agents_invoke", {
392
523
  runId: string;
393
524
  }> | EnvelopeSuccess<"skills_list", JsonObject> | EnvelopeSuccess<"skills_invoke", {
394
525
  runId: string;
@@ -406,28 +537,11 @@ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get",
406
537
  conversationId: string;
407
538
  runId: string;
408
539
  }> | EnvelopeSuccess<"conversations_history", ConversationHistory>;
409
- /**
410
- * Operations only the confidential application itself may invoke. They stay
411
- * out of `externalApplicationOperationIds`, so browser clients and the user
412
- * proxy never offer them.
413
- */
414
- /** A person whose only role in the application's Organization is `member`. */
415
- interface MemberUser {
416
- email: string | null;
417
- name: string | null;
418
- userId: string;
419
- }
420
- /**
421
- * How create-or-get resolved the email: a new user, an existing CI user who
422
- * joined the Organization as a member, or a user who already was one.
423
- */
424
- type MemberUserResolution = "created" | "existing" | "linked";
425
- interface MemberUserPage {
426
- items: MemberUser[];
427
- page: number;
428
- pageSize: number;
429
- totalItems: number;
430
- }
540
+ /** User details returned by the application's user-management gateway. */
541
+ type ApplicationUser = ExternalApplicationsGetAppUserResponse["result"];
542
+ type ApplicationUserResolution = ExternalApplicationsCreateOrGetAppUserResponse["result"];
543
+ type ApplicationUserPage = ExternalApplicationsListAppUsersResponse["result"];
544
+ type ApplicationRole = ExternalApplicationsListAppRolesResponse["result"]["items"][number];
431
545
  declare const storageFileIdBrand: unique symbol;
432
546
  /** A durable private file of the application's Organization. */
433
547
  type StorageFileId = string & Readonly<{
@@ -446,34 +560,6 @@ interface DurableFileUpload {
446
560
  export type ExternalApplicationServiceOperationRequest = {
447
561
  input: DurableFileUpload;
448
562
  operationId: "files_upload";
449
- } | {
450
- input: {
451
- email: string;
452
- name: string;
453
- };
454
- operationId: "members_create_or_get";
455
- } | {
456
- input: {
457
- userId: string;
458
- };
459
- operationId: "members_get";
460
- } | {
461
- input: {
462
- page?: number;
463
- pageSize?: number;
464
- };
465
- operationId: "members_list";
466
- } | {
467
- input: {
468
- name: string;
469
- userId: string;
470
- };
471
- operationId: "members_update";
472
- } | {
473
- input: {
474
- userId: string;
475
- };
476
- operationId: "members_remove";
477
563
  } | {
478
564
  input: {
479
565
  origin: string;
@@ -497,10 +583,6 @@ export interface UserCompanyLinks {
497
583
  }
498
584
  export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"files_upload", {
499
585
  storageFileId: StorageFileId;
500
- }> | EnvelopeSuccess<"members_create_or_get", MemberUser & {
501
- outcome: MemberUserResolution;
502
- }> | EnvelopeSuccess<"members_get", MemberUser> | EnvelopeSuccess<"members_list", MemberUserPage> | EnvelopeSuccess<"members_update", MemberUser> | EnvelopeSuccess<"members_remove", {
503
- userId: string;
504
586
  }> | EnvelopeSuccess<"origins_set_runtime", {
505
587
  origin: string;
506
588
  }> | EnvelopeSuccess<"users_list_company_links", UserCompanyLinks> | EnvelopeSuccess<"users_link_companies", UserCompanyLinks>;
@@ -672,6 +754,8 @@ export interface ServerInvocationContext {
672
754
  readonly callerKind?: "anonymous_visitor";
673
755
  readonly correlationId?: string;
674
756
  readonly organizationId: string;
757
+ /** Selects a Server Role for this call; omission uses the credential default. */
758
+ readonly serverRole?: string;
675
759
  readonly signal?: AbortSignal;
676
760
  readonly traceparent?: string;
677
761
  }
@@ -682,7 +766,7 @@ export type ManagedInput<Input> = Input extends {
682
766
  readonly idempotencyKey?: string;
683
767
  } : Input;
684
768
  export type ManagedOperationInput<Id extends ExternalApplicationServerOperationId> = ManagedInput<OperationInput<Id>>;
685
- export type ServerOperationRequest<Id extends ExternalApplicationServerOperationId> = ManagedOperationInput<Id> & ServerInvocationContext;
769
+ export type ServerOperationRequest<Id extends ExternalApplicationServerOperationId> = OperationInput<Id> extends Readonly<Record<string, never>> ? ServerInvocationContext : ManagedOperationInput<Id> & ServerInvocationContext;
686
770
  export type ServerOperationMethod<Id extends ExternalApplicationServerOperationId> = (request: ServerOperationRequest<Id>) => Promise<ExternalApplicationOperationResult<Id>>;
687
771
  /** One message to send; `idempotencyKey` is generated when omitted. */
688
772
  export type ServerMessageSendRequest = Omit<MessageSendInput, "idempotencyKey"> & Readonly<{
@@ -838,21 +922,6 @@ export interface ServerClient {
838
922
  updateRelation: ServerOperationMethod<"knowledge_update_relation">;
839
923
  upsertEntity: ServerOperationMethod<"knowledge_upsert_entity">;
840
924
  }>;
841
- /**
842
- * Member users of the application's Organization: people whose only role
843
- * there is `member`. Needs `members:read` (get, list) or `members:write`
844
- * (createOrGet, update, remove) and confidential credentials; a user with
845
- * any other role is refused. `createOrGet` resolves an email to the same
846
- * user on every call and never sends CI's activation invitation. `remove`
847
- * ends the membership and keeps the CI user.
848
- */
849
- readonly members: Readonly<{
850
- createOrGet: ServerOperationMethod<"members_create_or_get">;
851
- get: ServerOperationMethod<"members_get">;
852
- list: ServerOperationMethod<"members_list">;
853
- remove: ServerOperationMethod<"members_remove">;
854
- update: ServerOperationMethod<"members_update">;
855
- }>;
856
925
  /**
857
926
  * Sends one message through a messaging connection that an administrator
858
927
  * granted to the application. Needs the `messaging:send` scope. A repeat
@@ -882,6 +951,11 @@ export interface ServerClient {
882
951
  readonly resources: Readonly<{
883
952
  createUpload: ServerResourceUploadMethod;
884
953
  }>;
954
+ readonly roles: Readonly<{
955
+ assign: ServerOperationMethod<"roles_assign">;
956
+ list: ServerOperationMethod<"roles_list">;
957
+ revoke: ServerOperationMethod<"roles_revoke">;
958
+ }>;
885
959
  readonly runs: Readonly<{
886
960
  cancel: ServerRunOperationMethod<"runs_cancel", ServerRun>;
887
961
  get: ServerRunOperationMethod<"runs_get", ServerRun>;
@@ -892,12 +966,17 @@ export interface ServerClient {
892
966
  list: ServerOperationMethod<"skills_list">;
893
967
  }>;
894
968
  /**
895
- * Organization members' links to the company entities they act for.
896
- * Confidential service credentials only; the Organization is the caller's.
969
+ * Application users and their role-bounded lifecycle. User tokens and service
970
+ * credentials are authorized by CI on each call. Company-link operations
971
+ * remain limited to service credentials and Organization members.
897
972
  */
898
973
  readonly users: Readonly<{
974
+ createOrGet: ServerOperationMethod<"users_create_or_get">;
975
+ deactivate: ServerOperationMethod<"users_deactivate">;
976
+ get: ServerOperationMethod<"users_get">;
899
977
  /** Links `userId` to `entityIds`, keeping existing links; returns all of them. */
900
978
  linkCompanies: ServerOperationMethod<"users_link_companies">;
979
+ list: ServerOperationMethod<"users_list">;
901
980
  listCompanyLinks: ServerOperationMethod<"users_list_company_links">;
902
981
  }>;
903
982
  readonly workflows: Readonly<{
@@ -964,11 +1043,12 @@ export declare const exchangeMemberSession: (request: MemberSessionExchangeReque
964
1043
  export declare const uuidV7: () => string;
965
1044
 
966
1045
  export {
1046
+ ApplicationRole as ServerApplicationRole,
1047
+ ApplicationUser as ServerApplicationUser,
1048
+ ApplicationUserPage as ServerApplicationUserPage,
1049
+ ApplicationUserResolution as ServerApplicationUserResolution,
967
1050
  DurableFileUpload as ServerDurableFileUpload,
968
1051
  MemberSessionExchangeError$1 as MemberSessionExchangeError,
969
- MemberUser as ServerMemberUser,
970
- MemberUserPage as ServerMemberUserPage,
971
- MemberUserResolution as ServerMemberUserResolution,
972
1052
  MessageContent as ServerMessageContent,
973
1053
  MessageReceipt as ServerMessageReceipt,
974
1054
  MessageSendErrorCode as ServerMessageSendErrorCode,