mindsim 0.1.2 → 0.1.3

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/src/types.ts CHANGED
@@ -1,13 +1,56 @@
1
- export interface AuthConfig {
2
- authServerUrl: string;
3
- authServerLandingPath: string;
4
- authRedirectPath: string;
5
- listenPort: string;
1
+ export interface DeviceAuthConfig {
2
+ deviceAuthUrl: string;
3
+ tokenUrl: string;
4
+ clientId: string;
5
+ sdkKeysApiUrl: string;
6
6
  }
7
7
 
8
- export interface AuthResponse {
9
- apiKey?: {
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
  }
@@ -221,26 +264,3 @@ export interface ListUsersResponse {
221
264
  users: User[];
222
265
  count: number;
223
266
  }
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
- }
@@ -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, getAuthConfig, loadApiKey, saveApiKey } from "../src/config";
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("getAuthConfig", () => {
99
+ describe("getDeviceAuthConfig", () => {
100
100
  it("should return default values when env vars are not set", () => {
101
- const config = getAuthConfig();
102
- expect(config.authServerUrl).toBe("https://app.mindsim.com/sdk/authorize");
103
- expect(config.authRedirectPath).toBe("http://localhost:4242/callback");
104
- expect(config.listenPort).toBe("4242");
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("MINDSIM_AUTH_SERVER_URL", "https://dev.mindsim.com/auth");
109
- vi.stubEnv("MINDSIM_AUTH_REDIRECT_URI", "http://custom-callback");
110
- vi.stubEnv("MINDSIM_AUTH_PORT", "8080");
111
-
112
- const config = getAuthConfig();
113
- expect(config.authServerUrl).toBe("https://dev.mindsim.com/auth");
114
- expect(config.authRedirectPath).toBe("http://custom-callback");
115
- expect(config.listenPort).toBe("8080");
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://app.mindsim.com/api/public/v1");
126
+ expect(getApiBaseUrl()).toBe("https://api.reasoner.com/api/mindsim");
122
127
  });
123
128
 
124
129
  it("should return override from environment", () => {
@@ -91,7 +91,7 @@ describe("Version Module", () => {
91
91
  mockedFs.existsSync.mockReturnValue(true);
92
92
  mockedFs.readFileSync.mockReturnValue("INVALID_JSON");
93
93
 
94
- const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
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"}
@@ -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,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
- }
@@ -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
- });