@arcteninc/core 0.0.66 → 0.0.68
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/server.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function h(i){const{apiKey:c,user:l,apiUrl:m="https://api.arcten.com"}=i,o=3,d=1e4;let s=null;for(let t=0;t<o;t++)try{const r=new AbortController,n=setTimeout(()=>r.abort(),d);try{const e=await fetch(`${m}/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:c,user:l}),signal:r.signal});if(clearTimeout(n),!e.ok){const a=await e.json().catch(()=>({}));throw new Error(a.error||`Failed to verify token: ${e.statusText}`)}return e.json()}catch(e){if(clearTimeout(n),(e.name==="AbortError"||e.code==="UND_ERR_SOCKET"||e.message?.includes("fetch failed")||e.message?.includes("other side closed")||e.message?.includes("ECONNRESET")||e.message?.includes("ETIMEDOUT"))&&t<o-1){const f=Math.min(1e3*Math.pow(2,t),5e3);await new Promise(T=>setTimeout(T,f)),s=e;continue}throw e}}catch(r){if(s=r,t===o-1||!r.code)break}const u=s instanceof Error?s.message:"Failed to verify token";throw new Error(`Failed to verify token after ${o} attempts: ${u}`)}exports.verifyToken=h;
|
package/dist/server.mjs
CHANGED
|
@@ -1,26 +1,49 @@
|
|
|
1
|
-
async function
|
|
1
|
+
async function E(i) {
|
|
2
2
|
const {
|
|
3
|
-
apiKey:
|
|
4
|
-
user:
|
|
5
|
-
apiUrl:
|
|
6
|
-
} =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
apiKey: c,
|
|
4
|
+
user: l,
|
|
5
|
+
apiUrl: m = "https://api.arcten.com"
|
|
6
|
+
} = i, o = 3, d = 1e4;
|
|
7
|
+
let s = null;
|
|
8
|
+
for (let t = 0; t < o; t++)
|
|
9
|
+
try {
|
|
10
|
+
const r = new AbortController(), n = setTimeout(() => r.abort(), d);
|
|
11
|
+
try {
|
|
12
|
+
const e = await fetch(`${m}/token`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
apiKey: c,
|
|
19
|
+
user: l
|
|
20
|
+
}),
|
|
21
|
+
signal: r.signal
|
|
22
|
+
});
|
|
23
|
+
if (clearTimeout(n), !e.ok) {
|
|
24
|
+
const a = await e.json().catch(() => ({}));
|
|
25
|
+
throw new Error(
|
|
26
|
+
a.error || `Failed to verify token: ${e.statusText}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return e.json();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (clearTimeout(n), (e.name === "AbortError" || e.code === "UND_ERR_SOCKET" || e.message?.includes("fetch failed") || e.message?.includes("other side closed") || e.message?.includes("ECONNRESET") || e.message?.includes("ETIMEDOUT")) && t < o - 1) {
|
|
32
|
+
const u = Math.min(1e3 * Math.pow(2, t), 5e3);
|
|
33
|
+
await new Promise((h) => setTimeout(h, u)), s = e;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
} catch (r) {
|
|
39
|
+
if (s = r, t === o - 1 || !r.code)
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
const f = s instanceof Error ? s.message : "Failed to verify token";
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Failed to verify token after ${o} attempts: ${f}`
|
|
45
|
+
);
|
|
23
46
|
}
|
|
24
47
|
export {
|
|
25
|
-
|
|
48
|
+
E as verifyToken
|
|
26
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyToken.d.ts","sourceRoot":"","sources":["../src/verifyToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"verifyToken.d.ts","sourceRoot":"","sources":["../src/verifyToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAgFxB"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* JavaScript wrapper for the CommonJS wrapper script
|
|
4
|
-
* This file exists to ensure binary resolution works correctly
|
|
5
|
-
* when package managers look for .js files
|
|
6
|
-
*
|
|
7
|
-
* Works in both Bun and Node.js environments, even when package.json has "type": "module"
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { createRequire } from 'module';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
import { dirname, join } from 'path';
|
|
13
|
-
|
|
14
|
-
// Get __dirname equivalent for ES modules
|
|
15
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
-
const __dirname = dirname(__filename);
|
|
17
|
-
|
|
18
|
-
// Create require function that works in ES module context
|
|
19
|
-
const require = createRequire(import.meta.url);
|
|
20
|
-
|
|
21
|
-
// Load and execute the CommonJS wrapper
|
|
22
|
-
// This works in both Node.js (v12+) and Bun
|
|
23
|
-
const wrapperPath = join(__dirname, 'cli-extract-types-auto-wrapper.cjs');
|
|
24
|
-
require(wrapperPath);
|
|
25
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* JavaScript wrapper for the CommonJS wrapper script
|
|
4
|
+
* This file exists to ensure binary resolution works correctly
|
|
5
|
+
* when package managers look for .js files
|
|
6
|
+
*
|
|
7
|
+
* Works in both Bun and Node.js environments, even when package.json has "type": "module"
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createRequire } from 'module';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { dirname, join } from 'path';
|
|
13
|
+
|
|
14
|
+
// Get __dirname equivalent for ES modules
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
|
|
18
|
+
// Create require function that works in ES module context
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
// Load and execute the CommonJS wrapper
|
|
22
|
+
// This works in both Node.js (v12+) and Bun
|
|
23
|
+
const wrapperPath = join(__dirname, 'cli-extract-types-auto-wrapper.cjs');
|
|
24
|
+
require(wrapperPath);
|
|
25
|
+
|
|
@@ -843,6 +843,75 @@ function serializeTypeCustom(
|
|
|
843
843
|
}
|
|
844
844
|
}
|
|
845
845
|
|
|
846
|
+
// Handle Partial<T> utility type
|
|
847
|
+
// Check if this is a type reference (like Partial<Settings>)
|
|
848
|
+
// TypeScript represents Partial<T> as a TypeReference with typeArguments
|
|
849
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
850
|
+
const typeRef = type as ts.TypeReference;
|
|
851
|
+
if (typeRef.typeArguments && typeRef.typeArguments.length > 0) {
|
|
852
|
+
const typeSymbol = type.getSymbol();
|
|
853
|
+
const aliasSymbol = (type as any).getAliasSymbol ? (type as any).getAliasSymbol(checker) : null;
|
|
854
|
+
|
|
855
|
+
// Check symbol name or alias symbol name
|
|
856
|
+
const typeName = typeSymbol?.getName() || aliasSymbol?.getName();
|
|
857
|
+
|
|
858
|
+
// Also check type string as fallback (e.g., "Partial<Settings>")
|
|
859
|
+
const typeString = checker.typeToString(type);
|
|
860
|
+
|
|
861
|
+
// Check if it's Partial utility type
|
|
862
|
+
if (typeName === 'Partial' || typeString.startsWith('Partial<')) {
|
|
863
|
+
// Extract the type argument (the T in Partial<T>)
|
|
864
|
+
const baseType = typeRef.typeArguments[0];
|
|
865
|
+
|
|
866
|
+
// Process the base type to get its properties
|
|
867
|
+
const baseResult = serializeTypeCustom(baseType, checker, defs, visited, depth + 1);
|
|
868
|
+
|
|
869
|
+
// If the base type is an object with properties, make all properties optional
|
|
870
|
+
if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
|
|
871
|
+
return {
|
|
872
|
+
isOptional: false,
|
|
873
|
+
schema: {
|
|
874
|
+
type: 'object',
|
|
875
|
+
properties: baseResult.schema.properties,
|
|
876
|
+
// Don't include 'required' - all properties are optional in Partial<T>
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// If base type uses $ref, we need to handle it differently
|
|
882
|
+
// For Partial<SomeInterface>, we need to make all properties optional
|
|
883
|
+
if (baseResult.schema.$ref) {
|
|
884
|
+
// Get the referenced type and process it
|
|
885
|
+
const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
|
|
886
|
+
if (defs && defs[refTypeName]) {
|
|
887
|
+
const refSchema = defs[refTypeName];
|
|
888
|
+
if (refSchema.type === 'object' && refSchema.properties) {
|
|
889
|
+
// Create a new schema with all properties optional
|
|
890
|
+
return {
|
|
891
|
+
isOptional: false,
|
|
892
|
+
schema: {
|
|
893
|
+
type: 'object',
|
|
894
|
+
properties: refSchema.properties,
|
|
895
|
+
// No required array - all optional
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// Fallback: return the base result but mark as all optional
|
|
903
|
+
return {
|
|
904
|
+
isOptional: false,
|
|
905
|
+
schema: {
|
|
906
|
+
...baseResult.schema,
|
|
907
|
+
// Remove required if present
|
|
908
|
+
required: undefined,
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
846
915
|
// Handle arrays
|
|
847
916
|
if (checker.isArrayType(type)) {
|
|
848
917
|
const typeArgs = (type as ts.TypeReference).typeArguments;
|
|
@@ -984,6 +1053,73 @@ async function serializeType(
|
|
|
984
1053
|
return { isOptional: false, schema: { type: 'number', const: literalType.value } };
|
|
985
1054
|
}
|
|
986
1055
|
|
|
1056
|
+
// Handle Partial<T> utility type - check early before other type processing
|
|
1057
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
1058
|
+
const typeRef = type as ts.TypeReference;
|
|
1059
|
+
if (typeRef.typeArguments && typeRef.typeArguments.length > 0) {
|
|
1060
|
+
const typeSymbol = type.getSymbol();
|
|
1061
|
+
const aliasSymbol = (type as any).getAliasSymbol ? (type as any).getAliasSymbol(checker) : null;
|
|
1062
|
+
|
|
1063
|
+
// Check symbol name or alias symbol name
|
|
1064
|
+
const typeName = typeSymbol?.getName() || aliasSymbol?.getName();
|
|
1065
|
+
|
|
1066
|
+
// Also check type string as fallback (e.g., "Partial<Settings>")
|
|
1067
|
+
const typeString = checker.typeToString(type);
|
|
1068
|
+
|
|
1069
|
+
// Check if it's Partial utility type
|
|
1070
|
+
if (typeName === 'Partial' || typeString.startsWith('Partial<')) {
|
|
1071
|
+
// Extract the type argument (the T in Partial<T>)
|
|
1072
|
+
const baseType = typeRef.typeArguments[0];
|
|
1073
|
+
|
|
1074
|
+
// Process the base type to get its properties
|
|
1075
|
+
const baseResult = await serializeType(baseType, checker, program, configPath, defs);
|
|
1076
|
+
|
|
1077
|
+
// If the base type is an object with properties, make all properties optional
|
|
1078
|
+
if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
|
|
1079
|
+
return {
|
|
1080
|
+
isOptional: false,
|
|
1081
|
+
schema: {
|
|
1082
|
+
type: 'object',
|
|
1083
|
+
properties: baseResult.schema.properties,
|
|
1084
|
+
// Don't include 'required' - all properties are optional in Partial<T>
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// If base type uses $ref, we need to handle it differently
|
|
1090
|
+
// For Partial<SomeInterface>, we need to make all properties optional
|
|
1091
|
+
if (baseResult.schema.$ref) {
|
|
1092
|
+
// Get the referenced type and process it
|
|
1093
|
+
const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
|
|
1094
|
+
if (defs && defs[refTypeName]) {
|
|
1095
|
+
const refSchema = defs[refTypeName];
|
|
1096
|
+
if (refSchema.type === 'object' && refSchema.properties) {
|
|
1097
|
+
// Create a new schema with all properties optional
|
|
1098
|
+
return {
|
|
1099
|
+
isOptional: false,
|
|
1100
|
+
schema: {
|
|
1101
|
+
type: 'object',
|
|
1102
|
+
properties: refSchema.properties,
|
|
1103
|
+
// No required array - all optional
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Fallback: return the base result but mark as all optional
|
|
1111
|
+
return {
|
|
1112
|
+
isOptional: false,
|
|
1113
|
+
schema: {
|
|
1114
|
+
...baseResult.schema,
|
|
1115
|
+
// Remove required if present
|
|
1116
|
+
required: undefined,
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
987
1123
|
// Handle arrays
|
|
988
1124
|
if (checker.isArrayType(type)) {
|
|
989
1125
|
const typeArgs = (type as ts.TypeReference).typeArguments;
|
|
@@ -1276,6 +1412,11 @@ async function extractFunctionMetadata(
|
|
|
1276
1412
|
let isOptional = false;
|
|
1277
1413
|
|
|
1278
1414
|
if (param.type) {
|
|
1415
|
+
// Check if the type node text contains "Partial<" before resolving
|
|
1416
|
+
// This helps us detect Partial<T> even if TypeScript resolves it differently
|
|
1417
|
+
const typeNodeText = param.type.getText(sourceFile);
|
|
1418
|
+
const isPartialType = typeNodeText.startsWith('Partial<') || typeNodeText.includes('Partial<');
|
|
1419
|
+
|
|
1279
1420
|
// Try to get type from type annotation
|
|
1280
1421
|
let type = checker.getTypeFromTypeNode(param.type);
|
|
1281
1422
|
|
|
@@ -1291,11 +1432,53 @@ async function extractFunctionMetadata(
|
|
|
1291
1432
|
}
|
|
1292
1433
|
}
|
|
1293
1434
|
|
|
1294
|
-
//
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1435
|
+
// If we detected Partial<T> from the type node, try to extract the base type
|
|
1436
|
+
if (isPartialType && ts.isTypeReferenceNode(param.type) && param.type.typeArguments && param.type.typeArguments.length > 0) {
|
|
1437
|
+
// Extract the base type (T from Partial<T>)
|
|
1438
|
+
const baseTypeNode = param.type.typeArguments[0];
|
|
1439
|
+
const baseType = checker.getTypeFromTypeNode(baseTypeNode);
|
|
1440
|
+
|
|
1441
|
+
// Process the base type
|
|
1442
|
+
const baseResult = await serializeType(baseType, checker, program, configPath, defs);
|
|
1443
|
+
|
|
1444
|
+
// Make all properties optional
|
|
1445
|
+
if (baseResult.schema.type === 'object' && baseResult.schema.properties) {
|
|
1446
|
+
propSchema = {
|
|
1447
|
+
type: 'object',
|
|
1448
|
+
properties: baseResult.schema.properties,
|
|
1449
|
+
// No required array - all properties optional
|
|
1450
|
+
};
|
|
1451
|
+
isOptional = false; // The parameter itself is not optional, but its properties are
|
|
1452
|
+
} else if (baseResult.schema.$ref) {
|
|
1453
|
+
// Handle $ref case
|
|
1454
|
+
const refTypeName = baseResult.schema.$ref.replace('#/$defs/', '');
|
|
1455
|
+
if (defs && defs[refTypeName]) {
|
|
1456
|
+
const refSchema = defs[refTypeName];
|
|
1457
|
+
if (refSchema.type === 'object' && refSchema.properties) {
|
|
1458
|
+
propSchema = {
|
|
1459
|
+
type: 'object',
|
|
1460
|
+
properties: refSchema.properties,
|
|
1461
|
+
};
|
|
1462
|
+
isOptional = false;
|
|
1463
|
+
} else {
|
|
1464
|
+
propSchema = baseResult.schema;
|
|
1465
|
+
isOptional = baseResult.isOptional;
|
|
1466
|
+
}
|
|
1467
|
+
} else {
|
|
1468
|
+
propSchema = baseResult.schema;
|
|
1469
|
+
isOptional = baseResult.isOptional;
|
|
1470
|
+
}
|
|
1471
|
+
} else {
|
|
1472
|
+
propSchema = baseResult.schema;
|
|
1473
|
+
isOptional = baseResult.isOptional;
|
|
1474
|
+
}
|
|
1475
|
+
} else {
|
|
1476
|
+
// Use ts-json-schema-generator for named types only
|
|
1477
|
+
// Anonymous types are not supported - agents can't use them anyway
|
|
1478
|
+
const result = await serializeType(type, checker, program, configPath, defs);
|
|
1479
|
+
propSchema = result.schema;
|
|
1480
|
+
isOptional = result.isOptional;
|
|
1481
|
+
}
|
|
1299
1482
|
} else {
|
|
1300
1483
|
propSchema = {}; // Empty schema = any value (JSON Schema draft 2020-12)
|
|
1301
1484
|
}
|