mindsim 0.1.2 → 0.1.4
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 +8 -1
- package/dist/auth.d.ts +0 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +184 -93
- package/dist/auth.js.map +1 -1
- package/dist/cli.js +1 -28
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +12 -12
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +47 -40
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth.ts +261 -105
- package/src/cli.ts +2 -29
- package/src/config.ts +11 -11
- package/src/index.ts +0 -6
- package/src/types.ts +50 -46
- package/tests/config.test.ts +20 -15
- package/tests/version.test.ts +1 -1
- package/dist/resources/usage.d.ts +0 -14
- package/dist/resources/usage.d.ts.map +0 -1
- package/dist/resources/usage.js +0 -20
- package/dist/resources/usage.js.map +0 -1
- package/dist/resources/users.d.ts +0 -14
- package/dist/resources/users.d.ts.map +0 -1
- package/dist/resources/users.js +0 -20
- package/dist/resources/users.js.map +0 -1
- package/src/resources/usage.ts +0 -16
- package/src/resources/users.ts +0 -16
- package/tests/resources/usage.test.ts +0 -34
- package/tests/resources/users.test.ts +0 -54
package/src/types.ts
CHANGED
|
@@ -1,13 +1,56 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export interface DeviceAuthConfig {
|
|
2
|
+
deviceAuthUrl: string;
|
|
3
|
+
tokenUrl: string;
|
|
4
|
+
clientId: string;
|
|
5
|
+
sdkKeysApiUrl: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
8
|
+
export interface DeviceAuthResponse {
|
|
9
|
+
device_code: string;
|
|
10
|
+
user_code: string;
|
|
11
|
+
verification_uri: string;
|
|
12
|
+
verification_uri_complete: string;
|
|
13
|
+
expires_in: number;
|
|
14
|
+
interval: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TokenResponse {
|
|
18
|
+
access_token: string;
|
|
19
|
+
refresh_token?: string;
|
|
20
|
+
user?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SdkKeysResponse {
|
|
24
|
+
success: boolean;
|
|
25
|
+
user: {
|
|
10
26
|
id: string;
|
|
27
|
+
workosUserId: string;
|
|
28
|
+
email: string;
|
|
29
|
+
firstName: string | null;
|
|
30
|
+
lastName: string | null;
|
|
31
|
+
};
|
|
32
|
+
keys: SdkKeyInfo[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SdkKeyInfo {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
description: string | null;
|
|
39
|
+
tier: "development" | "production";
|
|
40
|
+
lastUsedAt: string | null;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
app: {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
description: string | null;
|
|
46
|
+
mindsimOrgId: string;
|
|
47
|
+
mindsimOrgName: string | null;
|
|
48
|
+
} | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SdkKeyDetailResponse {
|
|
52
|
+
success: boolean;
|
|
53
|
+
key: SdkKeyInfo & {
|
|
11
54
|
key: string;
|
|
12
55
|
};
|
|
13
56
|
}
|
|
@@ -205,42 +248,3 @@ export interface GetMindTopicsResponse {
|
|
|
205
248
|
topicsSentimentSummary?: Record<string, any> | null;
|
|
206
249
|
mindReasonerStopError?: any | null;
|
|
207
250
|
}
|
|
208
|
-
|
|
209
|
-
// -- Users --
|
|
210
|
-
|
|
211
|
-
export interface User {
|
|
212
|
-
id: string;
|
|
213
|
-
name: string;
|
|
214
|
-
email: string;
|
|
215
|
-
imageUrl?: string | null;
|
|
216
|
-
createdAt?: string;
|
|
217
|
-
updatedAt?: string;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export interface ListUsersResponse {
|
|
221
|
-
users: User[];
|
|
222
|
-
count: number;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// -- Usage --
|
|
226
|
-
|
|
227
|
-
export interface ApiKeyUsage {
|
|
228
|
-
successCount: number;
|
|
229
|
-
errorCount: number;
|
|
230
|
-
totalCount: number;
|
|
231
|
-
averageLatency: number;
|
|
232
|
-
maxLatency: number;
|
|
233
|
-
minLatency: number;
|
|
234
|
-
medianLatency: number;
|
|
235
|
-
p90Latency: number;
|
|
236
|
-
p95Latency: number;
|
|
237
|
-
p99Latency: number;
|
|
238
|
-
p999Latency: number;
|
|
239
|
-
numberOfSimulations: number;
|
|
240
|
-
numberOfSimulatedTwins: number;
|
|
241
|
-
numberOfSnapshotsCreated: number;
|
|
242
|
-
numberOfSnapshotsTotal: number;
|
|
243
|
-
numberOfCoresReprocessed: number;
|
|
244
|
-
numberOfPsychometricsRequests: number;
|
|
245
|
-
numberOfMindTopicsRequests: number;
|
|
246
|
-
}
|
package/tests/config.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, type Mocked, vi } from "vitest";
|
|
5
|
-
import { getApiBaseUrl,
|
|
5
|
+
import { getApiBaseUrl, getDeviceAuthConfig, loadApiKey, saveApiKey } from "../src/config";
|
|
6
6
|
|
|
7
7
|
// Mock Node built-ins
|
|
8
8
|
vi.mock("node:fs");
|
|
@@ -96,29 +96,34 @@ describe("Config Module", () => {
|
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
describe("
|
|
99
|
+
describe("getDeviceAuthConfig", () => {
|
|
100
100
|
it("should return default values when env vars are not set", () => {
|
|
101
|
-
const config =
|
|
102
|
-
expect(config.
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
const config = getDeviceAuthConfig();
|
|
102
|
+
expect(config.deviceAuthUrl).toBe(
|
|
103
|
+
"https://auth.reasoner.com/user_management/authorize/device",
|
|
104
|
+
);
|
|
105
|
+
expect(config.tokenUrl).toBe("https://auth.reasoner.com/user_management/authenticate");
|
|
106
|
+
expect(config.clientId).toBe("client_01GPECHM1J9DMY7WQNKTJ195P6");
|
|
107
|
+
expect(config.sdkKeysApiUrl).toBe("https://api.reasoner.com/api/sdk/keys");
|
|
105
108
|
});
|
|
106
109
|
|
|
107
110
|
it("should return env overrides when set", () => {
|
|
108
|
-
vi.stubEnv("
|
|
109
|
-
vi.stubEnv("
|
|
110
|
-
vi.stubEnv("
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
expect(config.
|
|
115
|
-
expect(config.
|
|
111
|
+
vi.stubEnv("MINDSIM_WORKOS_DEVICE_AUTH_URL", "https://custom-auth.example.com/device");
|
|
112
|
+
vi.stubEnv("MINDSIM_WORKOS_TOKEN_URL", "https://custom-auth.example.com/token");
|
|
113
|
+
vi.stubEnv("MINDSIM_WORKOS_CLIENT_ID", "custom_client_id");
|
|
114
|
+
vi.stubEnv("MINDSIM_SDK_KEYS_API_URL", "https://custom-api.example.com/keys");
|
|
115
|
+
|
|
116
|
+
const config = getDeviceAuthConfig();
|
|
117
|
+
expect(config.deviceAuthUrl).toBe("https://custom-auth.example.com/device");
|
|
118
|
+
expect(config.tokenUrl).toBe("https://custom-auth.example.com/token");
|
|
119
|
+
expect(config.clientId).toBe("custom_client_id");
|
|
120
|
+
expect(config.sdkKeysApiUrl).toBe("https://custom-api.example.com/keys");
|
|
116
121
|
});
|
|
117
122
|
});
|
|
118
123
|
|
|
119
124
|
describe("getApiBaseUrl", () => {
|
|
120
125
|
it("should return default URL", () => {
|
|
121
|
-
expect(getApiBaseUrl()).toBe("https://
|
|
126
|
+
expect(getApiBaseUrl()).toBe("https://api.reasoner.com/api/mindsim");
|
|
122
127
|
});
|
|
123
128
|
|
|
124
129
|
it("should return override from environment", () => {
|
package/tests/version.test.ts
CHANGED
|
@@ -91,7 +91,7 @@ describe("Version Module", () => {
|
|
|
91
91
|
mockedFs.existsSync.mockReturnValue(true);
|
|
92
92
|
mockedFs.readFileSync.mockReturnValue("INVALID_JSON");
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
95
95
|
|
|
96
96
|
const version = getPackageVersion();
|
|
97
97
|
expect(version).toBe("0.0.0");
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
|
-
import type { ApiKeyUsage } from "../types";
|
|
3
|
-
export declare class UsageResource {
|
|
4
|
-
private client;
|
|
5
|
-
constructor(client: AxiosInstance);
|
|
6
|
-
/**
|
|
7
|
-
* Get API Key Usage stats
|
|
8
|
-
*/
|
|
9
|
-
get(params?: {
|
|
10
|
-
from?: string;
|
|
11
|
-
to?: string;
|
|
12
|
-
}): Promise<ApiKeyUsage>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEzC;;OAEG;IACG,GAAG,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;CAMzE"}
|
package/dist/resources/usage.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UsageResource = void 0;
|
|
4
|
-
class UsageResource {
|
|
5
|
-
client;
|
|
6
|
-
constructor(client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Get API Key Usage stats
|
|
11
|
-
*/
|
|
12
|
-
async get(params) {
|
|
13
|
-
const response = await this.client.get("/usage", {
|
|
14
|
-
params,
|
|
15
|
-
});
|
|
16
|
-
return response.data;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.UsageResource = UsageResource;
|
|
20
|
-
//# sourceMappingURL=usage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":";;;AAGA,MAAa,aAAa;IACJ;IAApB,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,MAAuC;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAc,QAAQ,EAAE;YAC5D,MAAM;SACP,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AAZD,sCAYC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
|
-
import type { ListUsersResponse } from "../types";
|
|
3
|
-
export declare class UsersResource {
|
|
4
|
-
private client;
|
|
5
|
-
constructor(client: AxiosInstance);
|
|
6
|
-
/**
|
|
7
|
-
* List users in the organization
|
|
8
|
-
*/
|
|
9
|
-
list(params?: {
|
|
10
|
-
limit?: number;
|
|
11
|
-
offset?: number;
|
|
12
|
-
}): Promise<ListUsersResponse>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=users.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/resources/users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEzC;;OAEG;IACG,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAMrF"}
|
package/dist/resources/users.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UsersResource = void 0;
|
|
4
|
-
class UsersResource {
|
|
5
|
-
client;
|
|
6
|
-
constructor(client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* List users in the organization
|
|
11
|
-
*/
|
|
12
|
-
async list(params) {
|
|
13
|
-
const response = await this.client.get("/organizations/users", {
|
|
14
|
-
params,
|
|
15
|
-
});
|
|
16
|
-
return response.data;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.UsersResource = UsersResource;
|
|
20
|
-
//# sourceMappingURL=users.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/resources/users.ts"],"names":[],"mappings":";;;AAGA,MAAa,aAAa;IACJ;IAApB,YAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE7C;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,MAA4C;QACrD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAoB,sBAAsB,EAAE;YAChF,MAAM;SACP,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AAZD,sCAYC"}
|
package/src/resources/usage.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
|
-
import type { ApiKeyUsage } from "../types";
|
|
3
|
-
|
|
4
|
-
export class UsageResource {
|
|
5
|
-
constructor(private client: AxiosInstance) {}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get API Key Usage stats
|
|
9
|
-
*/
|
|
10
|
-
async get(params?: { from?: string; to?: string }): Promise<ApiKeyUsage> {
|
|
11
|
-
const response = await this.client.get<ApiKeyUsage>("/usage", {
|
|
12
|
-
params,
|
|
13
|
-
});
|
|
14
|
-
return response.data;
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/resources/users.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { AxiosInstance } from "axios";
|
|
2
|
-
import type { ListUsersResponse } from "../types";
|
|
3
|
-
|
|
4
|
-
export class UsersResource {
|
|
5
|
-
constructor(private client: AxiosInstance) {}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* List users in the organization
|
|
9
|
-
*/
|
|
10
|
-
async list(params?: { limit?: number; offset?: number }): Promise<ListUsersResponse> {
|
|
11
|
-
const response = await this.client.get<ListUsersResponse>("/organizations/users", {
|
|
12
|
-
params,
|
|
13
|
-
});
|
|
14
|
-
return response.data;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { beforeEach, describe, expect, it, type Mocked, vi } from "vitest";
|
|
3
|
-
import { MindSim } from "../../src/index";
|
|
4
|
-
|
|
5
|
-
vi.mock("axios");
|
|
6
|
-
const mockedAxios = axios as Mocked<typeof axios>;
|
|
7
|
-
|
|
8
|
-
describe("MindSim Usage Resource", () => {
|
|
9
|
-
let mindsim: MindSim;
|
|
10
|
-
|
|
11
|
-
const mockClient = {
|
|
12
|
-
get: vi.fn(),
|
|
13
|
-
defaults: { headers: { common: {} } },
|
|
14
|
-
interceptors: { request: { use: vi.fn() }, response: { use: vi.fn() } },
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
mockedAxios.create.mockReturnValue(mockClient as any);
|
|
19
|
-
mindsim = new MindSim("test-key");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("get() should call /usage with date params", async () => {
|
|
23
|
-
mockClient.get.mockResolvedValue({
|
|
24
|
-
data: { totalCount: 100, successCount: 99 },
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const result = await mindsim.usage.get({ from: "2023-01-01", to: "2023-01-31" });
|
|
28
|
-
|
|
29
|
-
expect(mockClient.get).toHaveBeenCalledWith("/usage", {
|
|
30
|
-
params: { from: "2023-01-01", to: "2023-01-31" },
|
|
31
|
-
});
|
|
32
|
-
expect(result.totalCount).toBe(100);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { beforeEach, describe, expect, it, type Mocked, vi } from "vitest";
|
|
3
|
-
import { MindSim } from "../../src/index";
|
|
4
|
-
import type { ListUsersResponse } from "../../src/types";
|
|
5
|
-
|
|
6
|
-
vi.mock("axios");
|
|
7
|
-
const mockedAxios = axios as Mocked<typeof axios>;
|
|
8
|
-
|
|
9
|
-
describe("MindSim Users Resource", () => {
|
|
10
|
-
let mindsim: MindSim;
|
|
11
|
-
|
|
12
|
-
const mockClient = {
|
|
13
|
-
get: vi.fn(),
|
|
14
|
-
defaults: { headers: { common: {} } },
|
|
15
|
-
interceptors: { request: { use: vi.fn() }, response: { use: vi.fn() } },
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
mockedAxios.create.mockReturnValue(mockClient as any);
|
|
20
|
-
mindsim = new MindSim("test-api-key");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("list() should call /organizations/users endpoint", async () => {
|
|
24
|
-
const mockResponse: ListUsersResponse = {
|
|
25
|
-
users: [
|
|
26
|
-
{ id: "u1", name: "Alice", email: "alice@test.com" },
|
|
27
|
-
{ id: "u2", name: "Bob", email: "bob@test.com" },
|
|
28
|
-
],
|
|
29
|
-
count: 2,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
mockClient.get.mockResolvedValue({ data: mockResponse });
|
|
33
|
-
|
|
34
|
-
const result = await mindsim.users.list();
|
|
35
|
-
|
|
36
|
-
expect(mockClient.get).toHaveBeenCalledWith("/organizations/users", {
|
|
37
|
-
params: undefined,
|
|
38
|
-
});
|
|
39
|
-
expect(result.count).toBe(2);
|
|
40
|
-
expect(result.users[0].name).toBe("Alice");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("list() should pass pagination parameters", async () => {
|
|
44
|
-
const mockResponse: ListUsersResponse = { users: [], count: 0 };
|
|
45
|
-
mockClient.get.mockResolvedValue({ data: mockResponse });
|
|
46
|
-
|
|
47
|
-
const params = { limit: 10, offset: 5 };
|
|
48
|
-
await mindsim.users.list(params);
|
|
49
|
-
|
|
50
|
-
expect(mockClient.get).toHaveBeenCalledWith("/organizations/users", {
|
|
51
|
-
params: params,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|