Skip to content

Commit 114b97f

Browse files
SDK regeneration (#40)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 6119139 commit 114b97f

File tree

203 files changed

+1418
-1027
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+1418
-1027
lines changed

Diff for: jest.config.js renamed to jest.config.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @type {import('jest').Config} */
2-
module.exports = {
2+
export default {
33
preset: "ts-jest",
44
testEnvironment: "node",
5+
moduleNameMapper: {
6+
"(.+)\.js$": "$1",
7+
},
58
};

Diff for: package.json

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@credal/sdk",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"private": false,
55
"repository": "https://github.com/credal-ai/credal-typescript-sdk",
66
"main": "./index.js",
@@ -15,26 +15,25 @@
1515
"url-join": "4.0.1",
1616
"form-data": "^4.0.0",
1717
"formdata-node": "^6.0.3",
18-
"node-fetch": "2.7.0",
19-
"qs": "6.11.2",
18+
"node-fetch": "^2.7.0",
19+
"qs": "^6.13.1",
2020
"readable-stream": "^4.5.2",
21-
"js-base64": "3.7.2"
21+
"js-base64": "3.7.7"
2222
},
2323
"devDependencies": {
2424
"@types/url-join": "4.0.1",
25-
"@types/qs": "6.9.8",
26-
"@types/node-fetch": "2.6.9",
27-
"@types/readable-stream": "^4.0.15",
28-
"fetch-mock-jest": "^1.5.1",
29-
"webpack": "^5.94.0",
30-
"ts-loader": "^9.3.1",
31-
"jest": "29.7.0",
32-
"@types/jest": "29.5.5",
33-
"ts-jest": "29.1.1",
34-
"jest-environment-jsdom": "29.7.0",
35-
"@types/node": "17.0.33",
36-
"prettier": "2.7.1",
37-
"typescript": "4.6.4"
25+
"@types/qs": "^6.9.17",
26+
"@types/node-fetch": "^2.6.12",
27+
"@types/readable-stream": "^4.0.18",
28+
"webpack": "^5.97.1",
29+
"ts-loader": "^9.5.1",
30+
"jest": "^29.7.0",
31+
"@types/jest": "^29.5.14",
32+
"ts-jest": "^29.1.1",
33+
"jest-environment-jsdom": "^29.7.0",
34+
"@types/node": "^18.19.70",
35+
"prettier": "^3.4.2",
36+
"typescript": "~5.7.2"
3837
},
3938
"browser": {
4039
"fs": false,

Diff for: scripts/rename-to-esm-files.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require("fs").promises;
4+
const path = require("path");
5+
6+
const extensionMap = {
7+
".js": ".mjs",
8+
".d.ts": ".d.mts",
9+
};
10+
const oldExtensions = Object.keys(extensionMap);
11+
12+
async function findFiles(rootPath) {
13+
const files = [];
14+
15+
async function scan(directory) {
16+
const entries = await fs.readdir(directory, { withFileTypes: true });
17+
18+
for (const entry of entries) {
19+
const fullPath = path.join(directory, entry.name);
20+
21+
if (entry.isDirectory()) {
22+
if (entry.name !== "node_modules" && !entry.name.startsWith(".")) {
23+
await scan(fullPath);
24+
}
25+
} else if (entry.isFile()) {
26+
if (oldExtensions.some((ext) => entry.name.endsWith(ext))) {
27+
files.push(fullPath);
28+
}
29+
}
30+
}
31+
}
32+
33+
await scan(rootPath);
34+
return files;
35+
}
36+
37+
async function updateFiles(files) {
38+
const updatedFiles = [];
39+
for (const file of files) {
40+
const updated = await updateFileContents(file);
41+
updatedFiles.push(updated);
42+
}
43+
44+
console.log(`Updated imports in ${updatedFiles.length} files.`);
45+
}
46+
47+
async function updateFileContents(file) {
48+
const content = await fs.readFile(file, "utf8");
49+
50+
let newContent = content;
51+
// Update each extension type defined in the map
52+
for (const [oldExt, newExt] of Object.entries(extensionMap)) {
53+
const regex = new RegExp(`(import|export)(.+from\\s+['"])(\\.\\.?\\/[^'"]+)(\\${oldExt})(['"])`, "g");
54+
newContent = newContent.replace(regex, `$1$2$3${newExt}$5`);
55+
}
56+
57+
if (content !== newContent) {
58+
await fs.writeFile(file, newContent, "utf8");
59+
return true;
60+
}
61+
return false;
62+
}
63+
64+
async function renameFiles(files) {
65+
let counter = 0;
66+
for (const file of files) {
67+
const ext = oldExtensions.find((ext) => file.endsWith(ext));
68+
const newExt = extensionMap[ext];
69+
70+
if (newExt) {
71+
const newPath = file.slice(0, -ext.length) + newExt;
72+
await fs.rename(file, newPath);
73+
counter++;
74+
}
75+
}
76+
77+
console.log(`Renamed ${counter} files.`);
78+
}
79+
80+
async function main() {
81+
try {
82+
const targetDir = process.argv[2];
83+
if (!targetDir) {
84+
console.error("Please provide a target directory");
85+
process.exit(1);
86+
}
87+
88+
const targetPath = path.resolve(targetDir);
89+
const targetStats = await fs.stat(targetPath);
90+
91+
if (!targetStats.isDirectory()) {
92+
console.error("The provided path is not a directory");
93+
process.exit(1);
94+
}
95+
96+
console.log(`Scanning directory: ${targetDir}`);
97+
98+
const files = await findFiles(targetDir);
99+
100+
if (files.length === 0) {
101+
console.log("No matching files found.");
102+
process.exit(0);
103+
}
104+
105+
console.log(`Found ${files.length} files.`);
106+
await updateFiles(files);
107+
await renameFiles(files);
108+
console.log("\nDone!");
109+
} catch (error) {
110+
console.error("An error occurred:", error.message);
111+
process.exit(1);
112+
}
113+
}
114+
115+
main();

Diff for: src/Client.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,56 @@ import { Search } from "./api/resources/search/client/Client";
1212
import { Users } from "./api/resources/users/client/Client";
1313

1414
export declare namespace CredalClient {
15-
interface Options {
15+
export interface Options {
1616
environment?: core.Supplier<environments.CredalEnvironment | string>;
17+
/** Specify a custom URL to connect the client to. */
18+
baseUrl?: core.Supplier<string>;
1719
apiKey?: core.Supplier<core.BearerToken | undefined>;
1820
fetcher?: core.FetchFunction;
1921
}
2022

21-
interface RequestOptions {
23+
export interface RequestOptions {
2224
/** The maximum time to wait for a response in seconds. */
2325
timeoutInSeconds?: number;
2426
/** The number of times to retry the request. Defaults to 2. */
2527
maxRetries?: number;
2628
/** A hook to abort the request. */
2729
abortSignal?: AbortSignal;
30+
/** Additional headers to include in the request. */
31+
headers?: Record<string, string>;
2832
}
2933
}
3034

3135
export class CredalClient {
32-
constructor(protected readonly _options: CredalClient.Options = {}) {}
33-
3436
protected _copilots: Copilots | undefined;
37+
protected _documentCatalog: DocumentCatalog | undefined;
38+
protected _documentCollections: DocumentCollections | undefined;
39+
protected _permissionsService: PermissionsService | undefined;
40+
protected _search: Search | undefined;
41+
protected _users: Users | undefined;
42+
43+
constructor(protected readonly _options: CredalClient.Options = {}) {}
3544

3645
public get copilots(): Copilots {
3746
return (this._copilots ??= new Copilots(this._options));
3847
}
3948

40-
protected _documentCatalog: DocumentCatalog | undefined;
41-
4249
public get documentCatalog(): DocumentCatalog {
4350
return (this._documentCatalog ??= new DocumentCatalog(this._options));
4451
}
4552

46-
protected _documentCollections: DocumentCollections | undefined;
47-
4853
public get documentCollections(): DocumentCollections {
4954
return (this._documentCollections ??= new DocumentCollections(this._options));
5055
}
5156

52-
protected _permissionsService: PermissionsService | undefined;
53-
5457
public get permissionsService(): PermissionsService {
5558
return (this._permissionsService ??= new PermissionsService(this._options));
5659
}
5760

58-
protected _search: Search | undefined;
59-
6061
public get search(): Search {
6162
return (this._search ??= new Search(this._options));
6263
}
6364

64-
protected _users: Users | undefined;
65-
6665
public get users(): Users {
6766
return (this._users ??= new Users(this._options));
6867
}

Diff for: src/api/resources/common/types/Operator.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
export type Operator = "<" | ">" | "<=" | ">=" | "!=" | "==" | "contains";
6-
76
export const Operator = {
87
LessThan: "<",
98
GreaterThan: ">",

Diff for: src/api/resources/common/types/ResourceIdentifier.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import * as Credal from "../../../index";
66

77
export type ResourceIdentifier = Credal.ResourceIdentifier.ExternalResourceId | Credal.ResourceIdentifier.Url;
88

9-
export declare namespace ResourceIdentifier {
10-
interface ExternalResourceId extends Credal.ExternalResourceId {
9+
export namespace ResourceIdentifier {
10+
export interface ExternalResourceId extends Credal.ExternalResourceId {
1111
type: "external-resource-id";
1212
}
1313

14-
interface Url extends Credal.Url {
14+
export interface Url extends Credal.Url {
1515
type: "url";
1616
}
1717
}

Diff for: src/api/resources/common/types/ResourceType.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export type ResourceType =
2222
| "SLACK_CHANNEL"
2323
| "MONGO_COLLECTION_SYNC"
2424
| "UNKNOWN";
25-
2625
export const ResourceType = {
2726
GoogleDriveItem: "GOOGLE_DRIVE_ITEM",
2827
MicrosoftDriveItem: "MICROSOFT_DRIVE_ITEM",

Diff for: src/api/resources/common/types/Role.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
export type Role = "viewer" | "editor";
6-
76
export const Role = {
87
Viewer: "viewer",
98
Editor: "editor",

0 commit comments

Comments
 (0)