@krutai/db-service 1.0.2 → 1.0.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/dist/index.d.mts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +7 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export { KrutAIKeyValidationError } from 'krutai';
|
|
2
|
+
|
|
4
3
|
interface DbServiceConfig {
|
|
5
4
|
apiKey: string;
|
|
6
5
|
serverUrl?: string;
|
|
@@ -15,8 +14,6 @@ interface DbConfigResponse {
|
|
|
15
14
|
}
|
|
16
15
|
declare const DEFAULT_SERVER_URL = "http://localhost:8000";
|
|
17
16
|
declare const DEFAULT_DB_MANAGE_PREFIX = "/db-manage";
|
|
18
|
-
declare function validateApiKeyFormat(apiKey?: string): void;
|
|
19
|
-
declare function validateApiKeyWithService(apiKey?: string, serverUrl?: string): Promise<boolean>;
|
|
20
17
|
declare class DbService {
|
|
21
18
|
private readonly apiKey;
|
|
22
19
|
private readonly serverUrl;
|
|
@@ -34,4 +31,4 @@ declare class DbService {
|
|
|
34
31
|
declare function dbService(config: DbServiceConfig): DbService;
|
|
35
32
|
declare const VERSION = "0.1.0";
|
|
36
33
|
|
|
37
|
-
export { DEFAULT_DB_MANAGE_PREFIX, DEFAULT_SERVER_URL, type DbConfigRequest, type DbConfigResponse, DbService, type DbServiceConfig,
|
|
34
|
+
export { DEFAULT_DB_MANAGE_PREFIX, DEFAULT_SERVER_URL, type DbConfigRequest, type DbConfigResponse, DbService, type DbServiceConfig, VERSION, dbService };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export { KrutAIKeyValidationError } from 'krutai';
|
|
2
|
+
|
|
4
3
|
interface DbServiceConfig {
|
|
5
4
|
apiKey: string;
|
|
6
5
|
serverUrl?: string;
|
|
@@ -15,8 +14,6 @@ interface DbConfigResponse {
|
|
|
15
14
|
}
|
|
16
15
|
declare const DEFAULT_SERVER_URL = "http://localhost:8000";
|
|
17
16
|
declare const DEFAULT_DB_MANAGE_PREFIX = "/db-manage";
|
|
18
|
-
declare function validateApiKeyFormat(apiKey?: string): void;
|
|
19
|
-
declare function validateApiKeyWithService(apiKey?: string, serverUrl?: string): Promise<boolean>;
|
|
20
17
|
declare class DbService {
|
|
21
18
|
private readonly apiKey;
|
|
22
19
|
private readonly serverUrl;
|
|
@@ -34,4 +31,4 @@ declare class DbService {
|
|
|
34
31
|
declare function dbService(config: DbServiceConfig): DbService;
|
|
35
32
|
declare const VERSION = "0.1.0";
|
|
36
33
|
|
|
37
|
-
export { DEFAULT_DB_MANAGE_PREFIX, DEFAULT_SERVER_URL, type DbConfigRequest, type DbConfigResponse, DbService, type DbServiceConfig,
|
|
34
|
+
export { DEFAULT_DB_MANAGE_PREFIX, DEFAULT_SERVER_URL, type DbConfigRequest, type DbConfigResponse, DbService, type DbServiceConfig, VERSION, dbService };
|
package/dist/index.js
CHANGED
|
@@ -23,69 +23,14 @@ __export(index_exports, {
|
|
|
23
23
|
DEFAULT_DB_MANAGE_PREFIX: () => DEFAULT_DB_MANAGE_PREFIX,
|
|
24
24
|
DEFAULT_SERVER_URL: () => DEFAULT_SERVER_URL,
|
|
25
25
|
DbService: () => DbService,
|
|
26
|
-
|
|
26
|
+
KrutAIKeyValidationError: () => import_krutai.KrutAIKeyValidationError,
|
|
27
27
|
VERSION: () => VERSION,
|
|
28
|
-
dbService: () => dbService
|
|
29
|
-
validateApiKeyFormat: () => validateApiKeyFormat,
|
|
30
|
-
validateApiKeyWithService: () => validateApiKeyWithService
|
|
28
|
+
dbService: () => dbService
|
|
31
29
|
});
|
|
32
30
|
module.exports = __toCommonJS(index_exports);
|
|
33
|
-
var
|
|
34
|
-
constructor(message) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.name = "DbServiceKeyValidationError";
|
|
37
|
-
}
|
|
38
|
-
};
|
|
31
|
+
var import_krutai = require("krutai");
|
|
39
32
|
var DEFAULT_SERVER_URL = "http://localhost:8000";
|
|
40
33
|
var DEFAULT_DB_MANAGE_PREFIX = "/db-manage";
|
|
41
|
-
function validateApiKeyFormat(apiKey) {
|
|
42
|
-
const key = apiKey || process.env.KRUTAI_API_KEY;
|
|
43
|
-
if (!key || typeof key !== "string") {
|
|
44
|
-
throw new DbServiceKeyValidationError("API key must be a non-empty string");
|
|
45
|
-
}
|
|
46
|
-
if (key.trim().length === 0) {
|
|
47
|
-
throw new DbServiceKeyValidationError("API key cannot be empty or whitespace");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function validateApiKeyWithService(apiKey, serverUrl = DEFAULT_SERVER_URL) {
|
|
51
|
-
const key = apiKey || process.env.KRUTAI_API_KEY;
|
|
52
|
-
if (!key) {
|
|
53
|
-
throw new DbServiceKeyValidationError("API key is required");
|
|
54
|
-
}
|
|
55
|
-
validateApiKeyFormat(key);
|
|
56
|
-
try {
|
|
57
|
-
const url = `${serverUrl.replace(/\/$/, "")}/validate`;
|
|
58
|
-
const response = await fetch(url, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: {
|
|
61
|
-
"Content-Type": "application/json",
|
|
62
|
-
"x-api-key": key
|
|
63
|
-
},
|
|
64
|
-
body: JSON.stringify({ apiKey: key })
|
|
65
|
-
});
|
|
66
|
-
let data = {};
|
|
67
|
-
try {
|
|
68
|
-
data = await response.json();
|
|
69
|
-
} catch {
|
|
70
|
-
}
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
throw new DbServiceKeyValidationError(
|
|
73
|
-
data.error || data.message || `API key validation failed: server responded with HTTP ${response.status}`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
if (data.valid === false) {
|
|
77
|
-
throw new DbServiceKeyValidationError(
|
|
78
|
-
data.error ?? data.message ?? "API key rejected by server"
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (error instanceof DbServiceKeyValidationError) throw error;
|
|
84
|
-
throw new DbServiceKeyValidationError(
|
|
85
|
-
`Failed to reach validation endpoint: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
34
|
var DbService = class {
|
|
90
35
|
apiKey;
|
|
91
36
|
serverUrl;
|
|
@@ -97,7 +42,7 @@ var DbService = class {
|
|
|
97
42
|
this.apiKey = config.apiKey || process.env.KRUTAI_API_KEY || "";
|
|
98
43
|
this.serverUrl = (config.serverUrl ?? DEFAULT_SERVER_URL).replace(/\/$/, "");
|
|
99
44
|
this.dbManagePrefix = DEFAULT_DB_MANAGE_PREFIX.replace(/\/$/, "");
|
|
100
|
-
validateApiKeyFormat(this.apiKey);
|
|
45
|
+
(0, import_krutai.validateApiKeyFormat)(this.apiKey);
|
|
101
46
|
if (config.validateOnInit === false) {
|
|
102
47
|
this.initialized = true;
|
|
103
48
|
}
|
|
@@ -105,7 +50,7 @@ var DbService = class {
|
|
|
105
50
|
async initialize() {
|
|
106
51
|
if (this.initialized) return;
|
|
107
52
|
if (this.config.validateOnInit !== false) {
|
|
108
|
-
await
|
|
53
|
+
await (0, import_krutai.validateApiKey)(this.apiKey, this.serverUrl);
|
|
109
54
|
}
|
|
110
55
|
this.initialized = true;
|
|
111
56
|
}
|
|
@@ -167,10 +112,8 @@ var VERSION = "0.1.0";
|
|
|
167
112
|
DEFAULT_DB_MANAGE_PREFIX,
|
|
168
113
|
DEFAULT_SERVER_URL,
|
|
169
114
|
DbService,
|
|
170
|
-
|
|
115
|
+
KrutAIKeyValidationError,
|
|
171
116
|
VERSION,
|
|
172
|
-
dbService
|
|
173
|
-
validateApiKeyFormat,
|
|
174
|
-
validateApiKeyWithService
|
|
117
|
+
dbService
|
|
175
118
|
});
|
|
176
119
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n validateApiKey,\n validateApiKeyFormat,\n KrutAIKeyValidationError,\n} from 'krutai';\n\nexport { KrutAIKeyValidationError };\n\nexport interface DbServiceConfig {\n apiKey: string;\n serverUrl?: string;\n validateOnInit?: boolean;\n}\n\nexport interface DbConfigRequest {\n projectId: string;\n dbName: string;\n}\n\nexport interface DbConfigResponse {\n dbUrl: string;\n}\n\nexport const DEFAULT_SERVER_URL = 'http://localhost:8000';\nexport const DEFAULT_DB_MANAGE_PREFIX = '/db-manage';\n\nexport class DbService {\n private readonly apiKey: string;\n private readonly serverUrl: string;\n private readonly dbManagePrefix: string;\n private readonly config: DbServiceConfig;\n private initialized = false;\n\n constructor(config: DbServiceConfig) {\n this.config = config;\n this.apiKey = config.apiKey || process.env.KRUTAI_API_KEY || '';\n this.serverUrl = (config.serverUrl ?? DEFAULT_SERVER_URL).replace(/\\/$/, '');\n this.dbManagePrefix = DEFAULT_DB_MANAGE_PREFIX.replace(/\\/$/, '');\n\n validateApiKeyFormat(this.apiKey);\n\n if (config.validateOnInit === false) {\n this.initialized = true;\n }\n }\n\n async initialize(): Promise<void> {\n if (this.initialized) return;\n\n if (this.config.validateOnInit !== false) {\n await validateApiKey(this.apiKey, this.serverUrl);\n }\n\n this.initialized = true;\n }\n\n isInitialized(): boolean {\n return this.initialized;\n }\n\n private assertInitialized(): void {\n if (!this.initialized) {\n throw new Error(\n 'DbService not initialized. Call initialize() first or set validateOnInit to false.'\n );\n }\n }\n\n private headers(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n 'x-api-key': this.apiKey,\n };\n }\n\n private url(path: string): string {\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return `${this.serverUrl}${this.dbManagePrefix}${cleanPath}`;\n }\n\n async getDbConfig(request: DbConfigRequest): Promise<DbConfigResponse> {\n this.assertInitialized();\n\n if (!request.projectId || request.projectId.trim().length === 0) {\n throw new Error('projectId is required');\n }\n\n if (!request.dbName || request.dbName.trim().length === 0) {\n throw new Error('dbName is required');\n }\n\n const response = await fetch(this.url('/config'), {\n method: 'POST',\n headers: this.headers(),\n body: JSON.stringify({\n projectId: request.projectId,\n dbName: request.dbName,\n }),\n });\n\n if (!response.ok) {\n let message = `DB service returned HTTP ${response.status} for /config`;\n try {\n const errorData = (await response.json()) as {\n message?: string;\n error?: string;\n };\n message = errorData.error ?? errorData.message ?? message;\n } catch {\n // ignore malformed error payloads\n }\n throw new Error(message);\n }\n\n return (await response.json()) as DbConfigResponse;\n }\n}\n\nexport function dbService(config: DbServiceConfig): DbService {\n return new DbService(config);\n}\n\nexport const VERSION = '0.1.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAmBA,IAAM,qBAAqB;AAC3B,IAAM,2BAA2B;AAEjC,IAAM,YAAN,MAAgB;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,cAAc;AAAA,EAEtB,YAAY,QAAyB;AACjC,SAAK,SAAS;AACd,SAAK,SAAS,OAAO,UAAU,QAAQ,IAAI,kBAAkB;AAC7D,SAAK,aAAa,OAAO,aAAa,oBAAoB,QAAQ,OAAO,EAAE;AAC3E,SAAK,iBAAiB,yBAAyB,QAAQ,OAAO,EAAE;AAEhE,4CAAqB,KAAK,MAAM;AAEhC,QAAI,OAAO,mBAAmB,OAAO;AACjC,WAAK,cAAc;AAAA,IACvB;AAAA,EACJ;AAAA,EAEA,MAAM,aAA4B;AAC9B,QAAI,KAAK,YAAa;AAEtB,QAAI,KAAK,OAAO,mBAAmB,OAAO;AACtC,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AACA,YAAM,IAAI,MAAM,OAAO;AAAA,IAC3B;AAEA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAChC;AACJ;AAEO,SAAS,UAAU,QAAoC;AAC1D,SAAO,IAAI,UAAU,MAAM;AAC/B;AAEO,IAAM,UAAU;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,60 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
2
|
+
import {
|
|
3
|
+
validateApiKey,
|
|
4
|
+
validateApiKeyFormat,
|
|
5
|
+
KrutAIKeyValidationError
|
|
6
|
+
} from "krutai";
|
|
8
7
|
var DEFAULT_SERVER_URL = "http://localhost:8000";
|
|
9
8
|
var DEFAULT_DB_MANAGE_PREFIX = "/db-manage";
|
|
10
|
-
function validateApiKeyFormat(apiKey) {
|
|
11
|
-
const key = apiKey || process.env.KRUTAI_API_KEY;
|
|
12
|
-
if (!key || typeof key !== "string") {
|
|
13
|
-
throw new DbServiceKeyValidationError("API key must be a non-empty string");
|
|
14
|
-
}
|
|
15
|
-
if (key.trim().length === 0) {
|
|
16
|
-
throw new DbServiceKeyValidationError("API key cannot be empty or whitespace");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async function validateApiKeyWithService(apiKey, serverUrl = DEFAULT_SERVER_URL) {
|
|
20
|
-
const key = apiKey || process.env.KRUTAI_API_KEY;
|
|
21
|
-
if (!key) {
|
|
22
|
-
throw new DbServiceKeyValidationError("API key is required");
|
|
23
|
-
}
|
|
24
|
-
validateApiKeyFormat(key);
|
|
25
|
-
try {
|
|
26
|
-
const url = `${serverUrl.replace(/\/$/, "")}/validate`;
|
|
27
|
-
const response = await fetch(url, {
|
|
28
|
-
method: "POST",
|
|
29
|
-
headers: {
|
|
30
|
-
"Content-Type": "application/json",
|
|
31
|
-
"x-api-key": key
|
|
32
|
-
},
|
|
33
|
-
body: JSON.stringify({ apiKey: key })
|
|
34
|
-
});
|
|
35
|
-
let data = {};
|
|
36
|
-
try {
|
|
37
|
-
data = await response.json();
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
throw new DbServiceKeyValidationError(
|
|
42
|
-
data.error || data.message || `API key validation failed: server responded with HTTP ${response.status}`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
if (data.valid === false) {
|
|
46
|
-
throw new DbServiceKeyValidationError(
|
|
47
|
-
data.error ?? data.message ?? "API key rejected by server"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
if (error instanceof DbServiceKeyValidationError) throw error;
|
|
53
|
-
throw new DbServiceKeyValidationError(
|
|
54
|
-
`Failed to reach validation endpoint: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
9
|
var DbService = class {
|
|
59
10
|
apiKey;
|
|
60
11
|
serverUrl;
|
|
@@ -74,7 +25,7 @@ var DbService = class {
|
|
|
74
25
|
async initialize() {
|
|
75
26
|
if (this.initialized) return;
|
|
76
27
|
if (this.config.validateOnInit !== false) {
|
|
77
|
-
await
|
|
28
|
+
await validateApiKey(this.apiKey, this.serverUrl);
|
|
78
29
|
}
|
|
79
30
|
this.initialized = true;
|
|
80
31
|
}
|
|
@@ -135,10 +86,8 @@ export {
|
|
|
135
86
|
DEFAULT_DB_MANAGE_PREFIX,
|
|
136
87
|
DEFAULT_SERVER_URL,
|
|
137
88
|
DbService,
|
|
138
|
-
|
|
89
|
+
KrutAIKeyValidationError,
|
|
139
90
|
VERSION,
|
|
140
|
-
dbService
|
|
141
|
-
validateApiKeyFormat,
|
|
142
|
-
validateApiKeyWithService
|
|
91
|
+
dbService
|
|
143
92
|
};
|
|
144
93
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n validateApiKey,\n validateApiKeyFormat,\n KrutAIKeyValidationError,\n} from 'krutai';\n\nexport { KrutAIKeyValidationError };\n\nexport interface DbServiceConfig {\n apiKey: string;\n serverUrl?: string;\n validateOnInit?: boolean;\n}\n\nexport interface DbConfigRequest {\n projectId: string;\n dbName: string;\n}\n\nexport interface DbConfigResponse {\n dbUrl: string;\n}\n\nexport const DEFAULT_SERVER_URL = 'http://localhost:8000';\nexport const DEFAULT_DB_MANAGE_PREFIX = '/db-manage';\n\nexport class DbService {\n private readonly apiKey: string;\n private readonly serverUrl: string;\n private readonly dbManagePrefix: string;\n private readonly config: DbServiceConfig;\n private initialized = false;\n\n constructor(config: DbServiceConfig) {\n this.config = config;\n this.apiKey = config.apiKey || process.env.KRUTAI_API_KEY || '';\n this.serverUrl = (config.serverUrl ?? DEFAULT_SERVER_URL).replace(/\\/$/, '');\n this.dbManagePrefix = DEFAULT_DB_MANAGE_PREFIX.replace(/\\/$/, '');\n\n validateApiKeyFormat(this.apiKey);\n\n if (config.validateOnInit === false) {\n this.initialized = true;\n }\n }\n\n async initialize(): Promise<void> {\n if (this.initialized) return;\n\n if (this.config.validateOnInit !== false) {\n await validateApiKey(this.apiKey, this.serverUrl);\n }\n\n this.initialized = true;\n }\n\n isInitialized(): boolean {\n return this.initialized;\n }\n\n private assertInitialized(): void {\n if (!this.initialized) {\n throw new Error(\n 'DbService not initialized. Call initialize() first or set validateOnInit to false.'\n );\n }\n }\n\n private headers(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n 'x-api-key': this.apiKey,\n };\n }\n\n private url(path: string): string {\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return `${this.serverUrl}${this.dbManagePrefix}${cleanPath}`;\n }\n\n async getDbConfig(request: DbConfigRequest): Promise<DbConfigResponse> {\n this.assertInitialized();\n\n if (!request.projectId || request.projectId.trim().length === 0) {\n throw new Error('projectId is required');\n }\n\n if (!request.dbName || request.dbName.trim().length === 0) {\n throw new Error('dbName is required');\n }\n\n const response = await fetch(this.url('/config'), {\n method: 'POST',\n headers: this.headers(),\n body: JSON.stringify({\n projectId: request.projectId,\n dbName: request.dbName,\n }),\n });\n\n if (!response.ok) {\n let message = `DB service returned HTTP ${response.status} for /config`;\n try {\n const errorData = (await response.json()) as {\n message?: string;\n error?: string;\n };\n message = errorData.error ?? errorData.message ?? message;\n } catch {\n // ignore malformed error payloads\n }\n throw new Error(message);\n }\n\n return (await response.json()) as DbConfigResponse;\n }\n}\n\nexport function dbService(config: DbServiceConfig): DbService {\n return new DbService(config);\n}\n\nexport const VERSION = '0.1.0';\n"],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAmBA,IAAM,qBAAqB;AAC3B,IAAM,2BAA2B;AAEjC,IAAM,YAAN,MAAgB;AAAA,EACF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,cAAc;AAAA,EAEtB,YAAY,QAAyB;AACjC,SAAK,SAAS;AACd,SAAK,SAAS,OAAO,UAAU,QAAQ,IAAI,kBAAkB;AAC7D,SAAK,aAAa,OAAO,aAAa,oBAAoB,QAAQ,OAAO,EAAE;AAC3E,SAAK,iBAAiB,yBAAyB,QAAQ,OAAO,EAAE;AAEhE,yBAAqB,KAAK,MAAM;AAEhC,QAAI,OAAO,mBAAmB,OAAO;AACjC,WAAK,cAAc;AAAA,IACvB;AAAA,EACJ;AAAA,EAEA,MAAM,aAA4B;AAC9B,QAAI,KAAK,YAAa;AAEtB,QAAI,KAAK,OAAO,mBAAmB,OAAO;AACtC,YAAM,eAAe,KAAK,QAAQ,KAAK,SAAS;AAAA,IACpD;AAEA,SAAK,cAAc;AAAA,EACvB;AAAA,EAEA,gBAAyB;AACrB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEQ,oBAA0B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B;AAEO,IAAM,UAAU;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krutai/db-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "DB service client for KrutAI",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "",
|
|
31
31
|
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"krutai": ">=0.1.5"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"krutai": ">=0.1.5"
|
|
37
|
+
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"@types/node": "^20.11.0",
|
|
34
40
|
"tsup": "^8.0.1",
|