@fractary/codex 0.9.0 → 0.10.0
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.cjs +89 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +264 -12
- package/dist/index.d.ts +264 -12
- package/dist/index.js +89 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -908,8 +908,40 @@ var ArchiveProjectConfigSchema = zod.z.object({
|
|
|
908
908
|
var ArchiveConfigSchema = zod.z.object({
|
|
909
909
|
projects: zod.z.record(ArchiveProjectConfigSchema)
|
|
910
910
|
});
|
|
911
|
+
var GitHubAuthConfigSchema = zod.z.object({
|
|
912
|
+
/** Default token environment variable name (default: GITHUB_TOKEN) */
|
|
913
|
+
default_token_env: zod.z.string().optional(),
|
|
914
|
+
/** Fallback to public access if authentication fails */
|
|
915
|
+
fallback_to_public: zod.z.boolean().optional()
|
|
916
|
+
});
|
|
917
|
+
var AuthConfigSchema = zod.z.object({
|
|
918
|
+
/** GitHub authentication configuration */
|
|
919
|
+
github: GitHubAuthConfigSchema.optional()
|
|
920
|
+
});
|
|
921
|
+
var SourceConfigSchema = zod.z.object({
|
|
922
|
+
/** Source type */
|
|
923
|
+
type: zod.z.enum(["github", "s3", "http", "local"]),
|
|
924
|
+
/** Environment variable containing the authentication token */
|
|
925
|
+
token_env: zod.z.string().optional(),
|
|
926
|
+
/** Direct token value (not recommended, use token_env instead) */
|
|
927
|
+
token: zod.z.string().optional(),
|
|
928
|
+
/** Branch to fetch from (for GitHub sources) */
|
|
929
|
+
branch: zod.z.string().optional(),
|
|
930
|
+
/** Base URL (for HTTP sources) */
|
|
931
|
+
base_url: zod.z.string().optional(),
|
|
932
|
+
/** Bucket name (for S3 sources) */
|
|
933
|
+
bucket: zod.z.string().optional(),
|
|
934
|
+
/** Prefix/path within bucket (for S3 sources) */
|
|
935
|
+
prefix: zod.z.string().optional()
|
|
936
|
+
});
|
|
937
|
+
var DependencyConfigSchema = zod.z.object({
|
|
938
|
+
/** Sources within this dependency */
|
|
939
|
+
sources: zod.z.record(SourceConfigSchema)
|
|
940
|
+
});
|
|
911
941
|
var CodexConfigSchema = zod.z.object({
|
|
912
942
|
organizationSlug: zod.z.string(),
|
|
943
|
+
/** Project name (optional) */
|
|
944
|
+
project: zod.z.string().optional(),
|
|
913
945
|
directories: zod.z.object({
|
|
914
946
|
source: zod.z.string().optional(),
|
|
915
947
|
target: zod.z.string().optional(),
|
|
@@ -919,7 +951,11 @@ var CodexConfigSchema = zod.z.object({
|
|
|
919
951
|
// Directional sync configuration
|
|
920
952
|
sync: DirectionalSyncSchema.optional(),
|
|
921
953
|
// Archive configuration
|
|
922
|
-
archive: ArchiveConfigSchema.optional()
|
|
954
|
+
archive: ArchiveConfigSchema.optional(),
|
|
955
|
+
// Authentication configuration
|
|
956
|
+
auth: AuthConfigSchema.optional(),
|
|
957
|
+
// Dependencies configuration (external projects)
|
|
958
|
+
dependencies: zod.z.record(DependencyConfigSchema).optional()
|
|
923
959
|
}).strict();
|
|
924
960
|
var FileSourceSchema = zod.z.object({
|
|
925
961
|
type: zod.z.enum(["s3", "r2", "gcs", "local"]),
|
|
@@ -2294,7 +2330,9 @@ var S3ArchiveStorage = class {
|
|
|
2294
2330
|
var StorageManager = class {
|
|
2295
2331
|
providers = /* @__PURE__ */ new Map();
|
|
2296
2332
|
priority;
|
|
2333
|
+
codexConfig;
|
|
2297
2334
|
constructor(config = {}) {
|
|
2335
|
+
this.codexConfig = config.codexConfig;
|
|
2298
2336
|
this.providers.set("local", new LocalStorage(config.local));
|
|
2299
2337
|
this.providers.set("github", new GitHubStorage(config.github));
|
|
2300
2338
|
this.providers.set("http", new HttpStorage(config.http));
|
|
@@ -2306,6 +2344,48 @@ var StorageManager = class {
|
|
|
2306
2344
|
}
|
|
2307
2345
|
this.priority = config.priority || (config.filePlugin && config.s3Archive ? ["file-plugin", "local", "s3-archive", "github", "http"] : config.filePlugin ? ["file-plugin", "local", "github", "http"] : config.s3Archive ? ["local", "s3-archive", "github", "http"] : ["local", "github", "http"]);
|
|
2308
2346
|
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Resolve authentication token for a reference
|
|
2349
|
+
*
|
|
2350
|
+
* Looks up dependency-specific authentication or falls back to default
|
|
2351
|
+
*/
|
|
2352
|
+
resolveToken(reference) {
|
|
2353
|
+
if (!this.codexConfig) {
|
|
2354
|
+
return void 0;
|
|
2355
|
+
}
|
|
2356
|
+
const dependencyKey = `${reference.org}/${reference.project}`;
|
|
2357
|
+
if (this.codexConfig.dependencies?.[dependencyKey]) {
|
|
2358
|
+
const dependency = this.codexConfig.dependencies[dependencyKey];
|
|
2359
|
+
for (const [, sourceConfig] of Object.entries(dependency.sources)) {
|
|
2360
|
+
if (sourceConfig.type === "github") {
|
|
2361
|
+
if (sourceConfig.token_env) {
|
|
2362
|
+
const token = process.env[sourceConfig.token_env];
|
|
2363
|
+
if (token) {
|
|
2364
|
+
return token;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
if (sourceConfig.token) {
|
|
2368
|
+
return sourceConfig.token;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
const defaultTokenEnv = this.codexConfig.auth?.github?.default_token_env || "GITHUB_TOKEN";
|
|
2374
|
+
return process.env[defaultTokenEnv];
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Resolve fetch options with authentication
|
|
2378
|
+
*
|
|
2379
|
+
* Merges reference-specific authentication with provided options
|
|
2380
|
+
*/
|
|
2381
|
+
resolveFetchOptions(reference, options) {
|
|
2382
|
+
const token = this.resolveToken(reference);
|
|
2383
|
+
return {
|
|
2384
|
+
...options,
|
|
2385
|
+
token: options?.token || token
|
|
2386
|
+
// Explicit option overrides resolved token
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2309
2389
|
/**
|
|
2310
2390
|
* Register a custom storage provider
|
|
2311
2391
|
*/
|
|
@@ -2346,8 +2426,10 @@ var StorageManager = class {
|
|
|
2346
2426
|
* Fetch content for a reference
|
|
2347
2427
|
*
|
|
2348
2428
|
* Tries providers in priority order until one succeeds.
|
|
2429
|
+
* Automatically resolves authentication based on dependency configuration.
|
|
2349
2430
|
*/
|
|
2350
2431
|
async fetch(reference, options) {
|
|
2432
|
+
const resolvedOptions = this.resolveFetchOptions(reference, options);
|
|
2351
2433
|
const errors = [];
|
|
2352
2434
|
for (const type of this.priority) {
|
|
2353
2435
|
const provider = this.providers.get(type);
|
|
@@ -2355,7 +2437,7 @@ var StorageManager = class {
|
|
|
2355
2437
|
continue;
|
|
2356
2438
|
}
|
|
2357
2439
|
try {
|
|
2358
|
-
return await provider.fetch(reference,
|
|
2440
|
+
return await provider.fetch(reference, resolvedOptions);
|
|
2359
2441
|
} catch (error) {
|
|
2360
2442
|
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
2361
2443
|
}
|
|
@@ -2376,15 +2458,17 @@ var StorageManager = class {
|
|
|
2376
2458
|
* Check if content exists for a reference
|
|
2377
2459
|
*
|
|
2378
2460
|
* Returns true if any provider reports the content exists.
|
|
2461
|
+
* Automatically resolves authentication based on dependency configuration.
|
|
2379
2462
|
*/
|
|
2380
2463
|
async exists(reference, options) {
|
|
2464
|
+
const resolvedOptions = this.resolveFetchOptions(reference, options);
|
|
2381
2465
|
for (const type of this.priority) {
|
|
2382
2466
|
const provider = this.providers.get(type);
|
|
2383
2467
|
if (!provider || !provider.canHandle(reference)) {
|
|
2384
2468
|
continue;
|
|
2385
2469
|
}
|
|
2386
2470
|
try {
|
|
2387
|
-
if (await provider.exists(reference,
|
|
2471
|
+
if (await provider.exists(reference, resolvedOptions)) {
|
|
2388
2472
|
return true;
|
|
2389
2473
|
}
|
|
2390
2474
|
} catch {
|
|
@@ -2404,6 +2488,8 @@ var StorageManager = class {
|
|
|
2404
2488
|
}
|
|
2405
2489
|
/**
|
|
2406
2490
|
* Fetch multiple references in parallel
|
|
2491
|
+
*
|
|
2492
|
+
* Automatically resolves authentication for each reference based on dependency configuration.
|
|
2407
2493
|
*/
|
|
2408
2494
|
async fetchMany(references, options) {
|
|
2409
2495
|
const results = /* @__PURE__ */ new Map();
|