@credal/sdk 0.1.11 → 0.1.13

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 (48) hide show
  1. package/dist/cjs/BaseClient.d.ts +10 -1
  2. package/dist/cjs/BaseClient.js +55 -0
  3. package/dist/cjs/Client.d.ts +18 -17
  4. package/dist/cjs/Client.js +8 -49
  5. package/dist/cjs/api/resources/copilots/client/Client.d.ts +22 -22
  6. package/dist/cjs/api/resources/copilots/client/Client.js +32 -34
  7. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +13 -13
  8. package/dist/cjs/api/resources/documentCatalog/client/Client.js +18 -25
  9. package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +19 -19
  10. package/dist/cjs/api/resources/documentCollections/client/Client.js +27 -31
  11. package/dist/cjs/api/resources/search/client/Client.d.ts +7 -7
  12. package/dist/cjs/api/resources/search/client/Client.js +9 -19
  13. package/dist/cjs/api/resources/users/client/Client.d.ts +7 -7
  14. package/dist/cjs/api/resources/users/client/Client.js +9 -19
  15. package/dist/cjs/auth/BearerAuthProvider.d.ts +14 -0
  16. package/dist/cjs/auth/BearerAuthProvider.js +72 -0
  17. package/dist/cjs/auth/index.d.ts +1 -0
  18. package/dist/cjs/auth/index.js +5 -0
  19. package/dist/cjs/core/auth/AuthProvider.d.ts +4 -1
  20. package/dist/cjs/core/auth/BearerToken.d.ts +3 -1
  21. package/dist/cjs/core/auth/BearerToken.js +7 -6
  22. package/dist/cjs/version.d.ts +1 -1
  23. package/dist/cjs/version.js +1 -1
  24. package/dist/esm/BaseClient.d.mts +10 -1
  25. package/dist/esm/BaseClient.mjs +20 -1
  26. package/dist/esm/Client.d.mts +18 -17
  27. package/dist/esm/Client.mjs +13 -21
  28. package/dist/esm/api/resources/copilots/client/Client.d.mts +22 -22
  29. package/dist/esm/api/resources/copilots/client/Client.mjs +31 -33
  30. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +13 -13
  31. package/dist/esm/api/resources/documentCatalog/client/Client.mjs +16 -23
  32. package/dist/esm/api/resources/documentCollections/client/Client.d.mts +19 -19
  33. package/dist/esm/api/resources/documentCollections/client/Client.mjs +26 -30
  34. package/dist/esm/api/resources/search/client/Client.d.mts +7 -7
  35. package/dist/esm/api/resources/search/client/Client.mjs +8 -18
  36. package/dist/esm/api/resources/users/client/Client.d.mts +7 -7
  37. package/dist/esm/api/resources/users/client/Client.mjs +8 -18
  38. package/dist/esm/auth/BearerAuthProvider.d.mts +14 -0
  39. package/dist/esm/auth/BearerAuthProvider.mjs +35 -0
  40. package/dist/esm/auth/index.d.mts +1 -0
  41. package/dist/esm/auth/index.mjs +1 -0
  42. package/dist/esm/core/auth/AuthProvider.d.mts +4 -1
  43. package/dist/esm/core/auth/BearerToken.d.mts +3 -1
  44. package/dist/esm/core/auth/BearerToken.mjs +7 -6
  45. package/dist/esm/version.d.mts +1 -1
  46. package/dist/esm/version.mjs +1 -1
  47. package/package.json +1 -1
  48. package/reference.md +21 -21
@@ -8,19 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
11
+ import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
12
+ import { mergeHeaders } from "../../../../core/headers.mjs";
12
13
  import * as core from "../../../../core/index.mjs";
13
14
  import * as environments from "../../../../environments.mjs";
14
15
  import * as errors from "../../../../errors/index.mjs";
15
- export class Users {
16
- constructor(_options = {}) {
17
- this._options = _options;
16
+ export class UsersClient {
17
+ constructor(options = {}) {
18
+ this._options = normalizeClientOptionsWithAuth(options);
18
19
  }
19
20
  /**
20
21
  * Bulk patch metadata for users
21
22
  *
22
23
  * @param {Credal.UserMetadataPatch[]} request
23
- * @param {Users.RequestOptions} requestOptions - Request-specific configuration.
24
+ * @param {UsersClient.RequestOptions} requestOptions - Request-specific configuration.
24
25
  *
25
26
  * @example
26
27
  * await client.users.metadata([{
@@ -43,7 +44,8 @@ export class Users {
43
44
  __metadata(request, requestOptions) {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
46
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
47
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
48
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
47
49
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
48
50
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/users/metadata"),
49
51
  method: "PATCH",
@@ -85,16 +87,4 @@ export class Users {
85
87
  }
86
88
  });
87
89
  }
88
- _getAuthorizationHeader() {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- var _a;
91
- const bearer = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CREDAL_API_KEY;
92
- if (bearer == null) {
93
- throw new errors.CredalError({
94
- message: "Please specify a bearer by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
95
- });
96
- }
97
- return `Bearer ${bearer}`;
98
- });
99
- }
100
90
  }
@@ -0,0 +1,14 @@
1
+ import * as core from "../core/index.mjs";
2
+ export declare namespace BearerAuthProvider {
3
+ interface Options {
4
+ apiKey?: core.Supplier<core.BearerToken | undefined>;
5
+ }
6
+ }
7
+ export declare class BearerAuthProvider implements core.AuthProvider {
8
+ private readonly token;
9
+ constructor(options: BearerAuthProvider.Options);
10
+ static canCreate(options: BearerAuthProvider.Options): boolean;
11
+ getAuthRequest(_arg?: {
12
+ endpointMetadata?: core.EndpointMetadata;
13
+ }): Promise<core.AuthRequest>;
14
+ }
@@ -0,0 +1,35 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import * as core from "../core/index.mjs";
12
+ import * as errors from "../errors/index.mjs";
13
+ export class BearerAuthProvider {
14
+ constructor(options) {
15
+ this.token = options.apiKey;
16
+ }
17
+ static canCreate(options) {
18
+ var _a;
19
+ return options.apiKey != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.CREDAL_API_KEY) != null;
20
+ }
21
+ getAuthRequest(_arg) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ const apiKey = (_a = (yield core.Supplier.get(this.token))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.CREDAL_API_KEY;
25
+ if (apiKey == null) {
26
+ throw new errors.CredalError({
27
+ message: "Please specify a apiKey by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
28
+ });
29
+ }
30
+ return {
31
+ headers: { Authorization: `Bearer ${apiKey}` },
32
+ };
33
+ });
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export { BearerAuthProvider } from "./BearerAuthProvider.mjs";
@@ -0,0 +1 @@
1
+ export { BearerAuthProvider } from "./BearerAuthProvider.mjs";
@@ -1,4 +1,7 @@
1
+ import type { EndpointMetadata } from "../fetcher/EndpointMetadata.mjs";
1
2
  import type { AuthRequest } from "./AuthRequest.mjs";
2
3
  export interface AuthProvider {
3
- getAuthRequest(): Promise<AuthRequest>;
4
+ getAuthRequest(arg?: {
5
+ endpointMetadata?: EndpointMetadata;
6
+ }): Promise<AuthRequest>;
4
7
  }
@@ -1,5 +1,7 @@
1
1
  export type BearerToken = string;
2
+ declare function toAuthorizationHeader(token: string | undefined): string | undefined;
2
3
  export declare const BearerToken: {
3
- toAuthorizationHeader: (token: BearerToken | undefined) => string | undefined;
4
+ toAuthorizationHeader: typeof toAuthorizationHeader;
4
5
  fromAuthorizationHeader: (header: string) => BearerToken;
5
6
  };
7
+ export {};
@@ -1,11 +1,12 @@
1
1
  const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
2
+ function toAuthorizationHeader(token) {
3
+ if (token == null) {
4
+ return undefined;
5
+ }
6
+ return `Bearer ${token}`;
7
+ }
2
8
  export const BearerToken = {
3
- toAuthorizationHeader: (token) => {
4
- if (token == null) {
5
- return undefined;
6
- }
7
- return `Bearer ${token}`;
8
- },
9
+ toAuthorizationHeader: toAuthorizationHeader,
9
10
  fromAuthorizationHeader: (header) => {
10
11
  return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
11
12
  },
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.11";
1
+ export declare const SDK_VERSION = "0.1.13";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.11";
1
+ export const SDK_VERSION = "0.1.13";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "private": false,
5
5
  "repository": "github:credal-ai/credal-typescript-sdk",
6
6
  "type": "commonjs",
package/reference.md CHANGED
@@ -58,7 +58,7 @@ await client.copilots.createCopilot({
58
58
  <dl>
59
59
  <dd>
60
60
 
61
- **requestOptions:** `Copilots.RequestOptions`
61
+ **requestOptions:** `CopilotsClient.RequestOptions`
62
62
 
63
63
  </dd>
64
64
  </dl>
@@ -124,7 +124,7 @@ await client.copilots.createConversation({
124
124
  <dl>
125
125
  <dd>
126
126
 
127
- **requestOptions:** `Copilots.RequestOptions`
127
+ **requestOptions:** `CopilotsClient.RequestOptions`
128
128
 
129
129
  </dd>
130
130
  </dl>
@@ -182,7 +182,7 @@ await client.copilots.provideMessageFeedback({
182
182
  <dl>
183
183
  <dd>
184
184
 
185
- **requestOptions:** `Copilots.RequestOptions`
185
+ **requestOptions:** `CopilotsClient.RequestOptions`
186
186
 
187
187
  </dd>
188
188
  </dl>
@@ -242,7 +242,7 @@ await client.copilots.sendMessage({
242
242
  <dl>
243
243
  <dd>
244
244
 
245
- **requestOptions:** `Copilots.RequestOptions`
245
+ **requestOptions:** `CopilotsClient.RequestOptions`
246
246
 
247
247
  </dd>
248
248
  </dl>
@@ -319,7 +319,7 @@ for await (const item of response) {
319
319
  <dl>
320
320
  <dd>
321
321
 
322
- **requestOptions:** `Copilots.RequestOptions`
322
+ **requestOptions:** `CopilotsClient.RequestOptions`
323
323
 
324
324
  </dd>
325
325
  </dl>
@@ -385,7 +385,7 @@ await client.copilots.addCollectionToCopilot({
385
385
  <dl>
386
386
  <dd>
387
387
 
388
- **requestOptions:** `Copilots.RequestOptions`
388
+ **requestOptions:** `CopilotsClient.RequestOptions`
389
389
 
390
390
  </dd>
391
391
  </dl>
@@ -451,7 +451,7 @@ await client.copilots.removeCollectionFromCopilot({
451
451
  <dl>
452
452
  <dd>
453
453
 
454
- **requestOptions:** `Copilots.RequestOptions`
454
+ **requestOptions:** `CopilotsClient.RequestOptions`
455
455
 
456
456
  </dd>
457
457
  </dl>
@@ -525,7 +525,7 @@ await client.copilots.updateConfiguration({
525
525
  <dl>
526
526
  <dd>
527
527
 
528
- **requestOptions:** `Copilots.RequestOptions`
528
+ **requestOptions:** `CopilotsClient.RequestOptions`
529
529
 
530
530
  </dd>
531
531
  </dl>
@@ -576,7 +576,7 @@ await client.copilots.deleteCopilot({
576
576
  <dl>
577
577
  <dd>
578
578
 
579
- **requestOptions:** `Copilots.RequestOptions`
579
+ **requestOptions:** `CopilotsClient.RequestOptions`
580
580
 
581
581
  </dd>
582
582
  </dl>
@@ -632,7 +632,7 @@ await client.documentCatalog.uploadDocumentContents({
632
632
  <dl>
633
633
  <dd>
634
634
 
635
- **requestOptions:** `DocumentCatalog.RequestOptions`
635
+ **requestOptions:** `DocumentCatalogClient.RequestOptions`
636
636
 
637
637
  </dd>
638
638
  </dl>
@@ -698,7 +698,7 @@ await client.documentCatalog.syncSourceByUrl({
698
698
  <dl>
699
699
  <dd>
700
700
 
701
- **requestOptions:** `DocumentCatalog.RequestOptions`
701
+ **requestOptions:** `DocumentCatalogClient.RequestOptions`
702
702
 
703
703
  </dd>
704
704
  </dl>
@@ -784,7 +784,7 @@ await client.documentCatalog.metadata({
784
784
  <dl>
785
785
  <dd>
786
786
 
787
- **requestOptions:** `DocumentCatalog.RequestOptions`
787
+ **requestOptions:** `DocumentCatalogClient.RequestOptions`
788
788
 
789
789
  </dd>
790
790
  </dl>
@@ -859,7 +859,7 @@ await client.documentCollections.addDocumentsToCollection({
859
859
  <dl>
860
860
  <dd>
861
861
 
862
- **requestOptions:** `DocumentCollections.RequestOptions`
862
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
863
863
 
864
864
  </dd>
865
865
  </dl>
@@ -933,7 +933,7 @@ await client.documentCollections.removeDocumentsFromCollection({
933
933
  <dl>
934
934
  <dd>
935
935
 
936
- **requestOptions:** `DocumentCollections.RequestOptions`
936
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
937
937
 
938
938
  </dd>
939
939
  </dl>
@@ -998,7 +998,7 @@ await client.documentCollections.listDocumentsInCollection({
998
998
  <dl>
999
999
  <dd>
1000
1000
 
1001
- **requestOptions:** `DocumentCollections.RequestOptions`
1001
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
1002
1002
 
1003
1003
  </dd>
1004
1004
  </dl>
@@ -1068,7 +1068,7 @@ await client.documentCollections.createCollection({
1068
1068
  <dl>
1069
1069
  <dd>
1070
1070
 
1071
- **requestOptions:** `DocumentCollections.RequestOptions`
1071
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
1072
1072
 
1073
1073
  </dd>
1074
1074
  </dl>
@@ -1133,7 +1133,7 @@ await client.documentCollections.deleteCollection({
1133
1133
  <dl>
1134
1134
  <dd>
1135
1135
 
1136
- **requestOptions:** `DocumentCollections.RequestOptions`
1136
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
1137
1137
 
1138
1138
  </dd>
1139
1139
  </dl>
@@ -1214,7 +1214,7 @@ await client.documentCollections.createMongoCollectionSync({
1214
1214
  <dl>
1215
1215
  <dd>
1216
1216
 
1217
- **requestOptions:** `DocumentCollections.RequestOptions`
1217
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
1218
1218
 
1219
1219
  </dd>
1220
1220
  </dl>
@@ -1295,7 +1295,7 @@ await client.documentCollections.updateMongoCollectionSync({
1295
1295
  <dl>
1296
1296
  <dd>
1297
1297
 
1298
- **requestOptions:** `DocumentCollections.RequestOptions`
1298
+ **requestOptions:** `DocumentCollectionsClient.RequestOptions`
1299
1299
 
1300
1300
  </dd>
1301
1301
  </dl>
@@ -1376,7 +1376,7 @@ await client.search.searchDocumentCollection({
1376
1376
  <dl>
1377
1377
  <dd>
1378
1378
 
1379
- **requestOptions:** `Search.RequestOptions`
1379
+ **requestOptions:** `SearchClient.RequestOptions`
1380
1380
 
1381
1381
  </dd>
1382
1382
  </dl>
@@ -1452,7 +1452,7 @@ await client.users.metadata([{
1452
1452
  <dl>
1453
1453
  <dd>
1454
1454
 
1455
- **requestOptions:** `Users.RequestOptions`
1455
+ **requestOptions:** `UsersClient.RequestOptions`
1456
1456
 
1457
1457
  </dd>
1458
1458
  </dl>