signet-auth 1.0.0-beta.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.

Potentially problematic release.


This version of signet-auth might be problematic. Click here for more details.

Files changed (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +393 -0
  3. package/bin/sig.js +65 -0
  4. package/dist/auth-manager.d.ts +90 -0
  5. package/dist/auth-manager.js +262 -0
  6. package/dist/browser/adapters/playwright.adapter.d.ts +14 -0
  7. package/dist/browser/adapters/playwright.adapter.js +188 -0
  8. package/dist/browser/flows/form-login.flow.d.ts +6 -0
  9. package/dist/browser/flows/form-login.flow.js +35 -0
  10. package/dist/browser/flows/header-capture.d.ts +23 -0
  11. package/dist/browser/flows/header-capture.js +104 -0
  12. package/dist/browser/flows/hybrid-flow.d.ts +37 -0
  13. package/dist/browser/flows/hybrid-flow.js +104 -0
  14. package/dist/browser/flows/oauth-consent.flow.d.ts +20 -0
  15. package/dist/browser/flows/oauth-consent.flow.js +170 -0
  16. package/dist/cli/commands/doctor.d.ts +6 -0
  17. package/dist/cli/commands/doctor.js +263 -0
  18. package/dist/cli/commands/get.d.ts +2 -0
  19. package/dist/cli/commands/get.js +83 -0
  20. package/dist/cli/commands/init.d.ts +6 -0
  21. package/dist/cli/commands/init.js +244 -0
  22. package/dist/cli/commands/login.d.ts +2 -0
  23. package/dist/cli/commands/login.js +77 -0
  24. package/dist/cli/commands/logout.d.ts +2 -0
  25. package/dist/cli/commands/logout.js +11 -0
  26. package/dist/cli/commands/providers.d.ts +2 -0
  27. package/dist/cli/commands/providers.js +30 -0
  28. package/dist/cli/commands/remote.d.ts +1 -0
  29. package/dist/cli/commands/remote.js +67 -0
  30. package/dist/cli/commands/request.d.ts +2 -0
  31. package/dist/cli/commands/request.js +82 -0
  32. package/dist/cli/commands/status.d.ts +2 -0
  33. package/dist/cli/commands/status.js +41 -0
  34. package/dist/cli/commands/sync.d.ts +2 -0
  35. package/dist/cli/commands/sync.js +62 -0
  36. package/dist/cli/formatters.d.ts +3 -0
  37. package/dist/cli/formatters.js +25 -0
  38. package/dist/cli/main.d.ts +8 -0
  39. package/dist/cli/main.js +125 -0
  40. package/dist/config/generator.d.ts +24 -0
  41. package/dist/config/generator.js +97 -0
  42. package/dist/config/loader.d.ts +21 -0
  43. package/dist/config/loader.js +54 -0
  44. package/dist/config/schema.d.ts +44 -0
  45. package/dist/config/schema.js +8 -0
  46. package/dist/config/validator.d.ts +15 -0
  47. package/dist/config/validator.js +228 -0
  48. package/dist/core/errors.d.ts +57 -0
  49. package/dist/core/errors.js +107 -0
  50. package/dist/core/interfaces/auth-strategy.d.ts +48 -0
  51. package/dist/core/interfaces/auth-strategy.js +1 -0
  52. package/dist/core/interfaces/browser-adapter.d.ts +73 -0
  53. package/dist/core/interfaces/browser-adapter.js +1 -0
  54. package/dist/core/interfaces/provider.d.ts +15 -0
  55. package/dist/core/interfaces/provider.js +1 -0
  56. package/dist/core/interfaces/storage.d.ts +21 -0
  57. package/dist/core/interfaces/storage.js +1 -0
  58. package/dist/core/result.d.ts +21 -0
  59. package/dist/core/result.js +16 -0
  60. package/dist/core/types.d.ts +128 -0
  61. package/dist/core/types.js +6 -0
  62. package/dist/deps.d.ts +20 -0
  63. package/dist/deps.js +54 -0
  64. package/dist/index.d.ts +35 -0
  65. package/dist/index.js +37 -0
  66. package/dist/providers/auto-provision.d.ts +9 -0
  67. package/dist/providers/auto-provision.js +27 -0
  68. package/dist/providers/config-loader.d.ts +7 -0
  69. package/dist/providers/config-loader.js +7 -0
  70. package/dist/providers/provider-registry.d.ts +19 -0
  71. package/dist/providers/provider-registry.js +68 -0
  72. package/dist/storage/cached-storage.d.ts +24 -0
  73. package/dist/storage/cached-storage.js +57 -0
  74. package/dist/storage/directory-storage.d.ts +25 -0
  75. package/dist/storage/directory-storage.js +184 -0
  76. package/dist/storage/memory-storage.d.ts +14 -0
  77. package/dist/storage/memory-storage.js +27 -0
  78. package/dist/strategies/api-token.strategy.d.ts +6 -0
  79. package/dist/strategies/api-token.strategy.js +63 -0
  80. package/dist/strategies/basic-auth.strategy.d.ts +6 -0
  81. package/dist/strategies/basic-auth.strategy.js +41 -0
  82. package/dist/strategies/cookie.strategy.d.ts +6 -0
  83. package/dist/strategies/cookie.strategy.js +118 -0
  84. package/dist/strategies/oauth2.strategy.d.ts +6 -0
  85. package/dist/strategies/oauth2.strategy.js +134 -0
  86. package/dist/strategies/registry.d.ts +13 -0
  87. package/dist/strategies/registry.js +25 -0
  88. package/dist/sync/remote-config.d.ts +8 -0
  89. package/dist/sync/remote-config.js +49 -0
  90. package/dist/sync/sync-engine.d.ts +10 -0
  91. package/dist/sync/sync-engine.js +96 -0
  92. package/dist/sync/transports/ssh.d.ts +18 -0
  93. package/dist/sync/transports/ssh.js +115 -0
  94. package/dist/sync/types.d.ts +17 -0
  95. package/dist/sync/types.js +1 -0
  96. package/dist/utils/duration.d.ts +9 -0
  97. package/dist/utils/duration.js +34 -0
  98. package/dist/utils/http.d.ts +4 -0
  99. package/dist/utils/http.js +10 -0
  100. package/dist/utils/jwt.d.ts +15 -0
  101. package/dist/utils/jwt.js +30 -0
  102. package/package.json +56 -0
  103. package/src/auth-manager.ts +331 -0
  104. package/src/browser/adapters/playwright.adapter.ts +247 -0
  105. package/src/browser/flows/form-login.flow.ts +35 -0
  106. package/src/browser/flows/header-capture.ts +128 -0
  107. package/src/browser/flows/hybrid-flow.ts +165 -0
  108. package/src/browser/flows/oauth-consent.flow.ts +200 -0
  109. package/src/cli/commands/doctor.ts +301 -0
  110. package/src/cli/commands/get.ts +96 -0
  111. package/src/cli/commands/init.ts +289 -0
  112. package/src/cli/commands/login.ts +94 -0
  113. package/src/cli/commands/logout.ts +17 -0
  114. package/src/cli/commands/providers.ts +39 -0
  115. package/src/cli/commands/remote.ts +71 -0
  116. package/src/cli/commands/request.ts +97 -0
  117. package/src/cli/commands/status.ts +48 -0
  118. package/src/cli/commands/sync.ts +71 -0
  119. package/src/cli/formatters.ts +31 -0
  120. package/src/cli/main.ts +144 -0
  121. package/src/config/generator.ts +122 -0
  122. package/src/config/loader.ts +70 -0
  123. package/src/config/schema.ts +75 -0
  124. package/src/config/validator.ts +281 -0
  125. package/src/core/errors.ts +182 -0
  126. package/src/core/interfaces/auth-strategy.ts +65 -0
  127. package/src/core/interfaces/browser-adapter.ts +81 -0
  128. package/src/core/interfaces/provider.ts +19 -0
  129. package/src/core/interfaces/storage.ts +26 -0
  130. package/src/core/result.ts +24 -0
  131. package/src/core/types.ts +194 -0
  132. package/src/deps.ts +80 -0
  133. package/src/index.ts +109 -0
  134. package/src/providers/auto-provision.ts +30 -0
  135. package/src/providers/config-loader.ts +8 -0
  136. package/src/providers/provider-registry.ts +79 -0
  137. package/src/storage/cached-storage.ts +72 -0
  138. package/src/storage/directory-storage.ts +204 -0
  139. package/src/storage/memory-storage.ts +35 -0
  140. package/src/strategies/api-token.strategy.ts +87 -0
  141. package/src/strategies/basic-auth.strategy.ts +64 -0
  142. package/src/strategies/cookie.strategy.ts +153 -0
  143. package/src/strategies/oauth2.strategy.ts +178 -0
  144. package/src/strategies/registry.ts +34 -0
  145. package/src/sync/remote-config.ts +60 -0
  146. package/src/sync/sync-engine.ts +113 -0
  147. package/src/sync/transports/ssh.ts +130 -0
  148. package/src/sync/types.ts +15 -0
  149. package/src/utils/duration.ts +34 -0
  150. package/src/utils/http.ts +11 -0
  151. package/src/utils/jwt.ts +39 -0
  152. package/tsconfig.json +20 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Error hierarchy for signet.
3
+ * These are used as Result.err values, NOT thrown for control flow.
4
+ * Only truly unexpected errors (programmer bugs, I/O failures) are thrown.
5
+ */
6
+ export type AuthErrorCode = 'PROVIDER_NOT_FOUND' | 'CREDENTIAL_NOT_FOUND' | 'CREDENTIAL_EXPIRED' | 'CREDENTIAL_TYPE_MISMATCH' | 'REFRESH_FAILED' | 'BROWSER_ERROR' | 'BROWSER_LAUNCH_ERROR' | 'BROWSER_TIMEOUT' | 'BROWSER_NAVIGATION_ERROR' | 'STORAGE_ERROR' | 'CONFIG_ERROR' | 'MANUAL_SETUP_REQUIRED' | 'SYNC_ERROR' | 'REMOTE_NOT_FOUND' | 'SYNC_CONFLICT';
7
+ export declare class AuthError extends Error {
8
+ readonly code: AuthErrorCode;
9
+ readonly providerId?: string | undefined;
10
+ constructor(message: string, code: AuthErrorCode, providerId?: string | undefined);
11
+ }
12
+ export declare class ProviderNotFoundError extends AuthError {
13
+ constructor(urlOrId: string);
14
+ }
15
+ export declare class CredentialNotFoundError extends AuthError {
16
+ constructor(providerId: string);
17
+ }
18
+ export declare class CredentialExpiredError extends AuthError {
19
+ constructor(providerId: string);
20
+ }
21
+ export declare class CredentialTypeError extends AuthError {
22
+ constructor(providerId: string, expected: string[], actual: string);
23
+ }
24
+ export declare class RefreshError extends AuthError {
25
+ constructor(providerId: string, reason: string);
26
+ }
27
+ export declare class BrowserError extends AuthError {
28
+ constructor(message: string, providerId?: string);
29
+ }
30
+ export declare class BrowserLaunchError extends AuthError {
31
+ constructor(reason: string);
32
+ }
33
+ export declare class BrowserTimeoutError extends AuthError {
34
+ constructor(operation: string, timeoutMs: number, providerId?: string);
35
+ }
36
+ export declare class BrowserNavigationError extends AuthError {
37
+ constructor(url: string, reason: string, providerId?: string);
38
+ }
39
+ export declare class StorageError extends AuthError {
40
+ constructor(operation: string, reason: string);
41
+ }
42
+ export declare class ConfigError extends AuthError {
43
+ constructor(message: string);
44
+ }
45
+ export declare class ManualSetupRequired extends AuthError {
46
+ readonly instructions: string;
47
+ constructor(providerId: string, instructions: string);
48
+ }
49
+ export declare class SyncError extends AuthError {
50
+ constructor(message: string, providerId?: string);
51
+ }
52
+ export declare class RemoteNotFoundError extends AuthError {
53
+ constructor(remoteName: string);
54
+ }
55
+ export declare class SyncConflictError extends AuthError {
56
+ constructor(providerId: string, localUpdated: string, remoteUpdated: string);
57
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Error hierarchy for signet.
3
+ * These are used as Result.err values, NOT thrown for control flow.
4
+ * Only truly unexpected errors (programmer bugs, I/O failures) are thrown.
5
+ */
6
+ export class AuthError extends Error {
7
+ code;
8
+ providerId;
9
+ constructor(message, code, providerId) {
10
+ super(message);
11
+ this.code = code;
12
+ this.providerId = providerId;
13
+ this.name = 'AuthError';
14
+ }
15
+ }
16
+ export class ProviderNotFoundError extends AuthError {
17
+ constructor(urlOrId) {
18
+ super(`No provider matches "${urlOrId}". Check your config.yaml or run "sig providers" to see configured ones.`, 'PROVIDER_NOT_FOUND');
19
+ this.name = 'ProviderNotFoundError';
20
+ }
21
+ }
22
+ export class CredentialNotFoundError extends AuthError {
23
+ constructor(providerId) {
24
+ super(`No stored credentials for provider "${providerId}". Run "sig login" first.`, 'CREDENTIAL_NOT_FOUND', providerId);
25
+ this.name = 'CredentialNotFoundError';
26
+ }
27
+ }
28
+ export class CredentialExpiredError extends AuthError {
29
+ constructor(providerId) {
30
+ super(`Credentials for "${providerId}" have expired and could not be refreshed.`, 'CREDENTIAL_EXPIRED', providerId);
31
+ this.name = 'CredentialExpiredError';
32
+ }
33
+ }
34
+ export class CredentialTypeError extends AuthError {
35
+ constructor(providerId, expected, actual) {
36
+ super(`Provider "${providerId}" expects credential type [${expected.join(', ')}] but got "${actual}".`, 'CREDENTIAL_TYPE_MISMATCH', providerId);
37
+ this.name = 'CredentialTypeError';
38
+ }
39
+ }
40
+ export class RefreshError extends AuthError {
41
+ constructor(providerId, reason) {
42
+ super(`Token refresh failed for "${providerId}": ${reason}`, 'REFRESH_FAILED', providerId);
43
+ this.name = 'RefreshError';
44
+ }
45
+ }
46
+ export class BrowserError extends AuthError {
47
+ constructor(message, providerId) {
48
+ super(message, 'BROWSER_ERROR', providerId);
49
+ this.name = 'BrowserError';
50
+ }
51
+ }
52
+ export class BrowserLaunchError extends AuthError {
53
+ constructor(reason) {
54
+ super(`Failed to launch browser: ${reason}`, 'BROWSER_LAUNCH_ERROR');
55
+ this.name = 'BrowserLaunchError';
56
+ }
57
+ }
58
+ export class BrowserTimeoutError extends AuthError {
59
+ constructor(operation, timeoutMs, providerId) {
60
+ super(`Browser operation "${operation}" timed out after ${timeoutMs}ms`, 'BROWSER_TIMEOUT', providerId);
61
+ this.name = 'BrowserTimeoutError';
62
+ }
63
+ }
64
+ export class BrowserNavigationError extends AuthError {
65
+ constructor(url, reason, providerId) {
66
+ super(`Failed to navigate to ${url}: ${reason}`, 'BROWSER_NAVIGATION_ERROR', providerId);
67
+ this.name = 'BrowserNavigationError';
68
+ }
69
+ }
70
+ export class StorageError extends AuthError {
71
+ constructor(operation, reason) {
72
+ super(`Storage ${operation} failed: ${reason}`, 'STORAGE_ERROR');
73
+ this.name = 'StorageError';
74
+ }
75
+ }
76
+ export class ConfigError extends AuthError {
77
+ constructor(message) {
78
+ super(message, 'CONFIG_ERROR');
79
+ this.name = 'ConfigError';
80
+ }
81
+ }
82
+ export class ManualSetupRequired extends AuthError {
83
+ instructions;
84
+ constructor(providerId, instructions) {
85
+ super(`Provider "${providerId}" requires manual setup. ${instructions}`, 'MANUAL_SETUP_REQUIRED', providerId);
86
+ this.instructions = instructions;
87
+ this.name = 'ManualSetupRequired';
88
+ }
89
+ }
90
+ export class SyncError extends AuthError {
91
+ constructor(message, providerId) {
92
+ super(message, 'SYNC_ERROR', providerId);
93
+ this.name = 'SyncError';
94
+ }
95
+ }
96
+ export class RemoteNotFoundError extends AuthError {
97
+ constructor(remoteName) {
98
+ super(`Remote "${remoteName}" not found. Run "sig remote add ${remoteName} <host>" first.`, 'REMOTE_NOT_FOUND');
99
+ this.name = 'RemoteNotFoundError';
100
+ }
101
+ }
102
+ export class SyncConflictError extends AuthError {
103
+ constructor(providerId, localUpdated, remoteUpdated) {
104
+ super(`Conflict for "${providerId}": local updated ${localUpdated}, remote updated ${remoteUpdated}. Use --force to overwrite.`, 'SYNC_CONFLICT', providerId);
105
+ this.name = 'SyncConflictError';
106
+ }
107
+ }
@@ -0,0 +1,48 @@
1
+ import type { Result } from '../result.js';
2
+ import type { AuthError } from '../errors.js';
3
+ import type { Credential, ProviderConfig, StrategyConfig } from '../types.js';
4
+ import type { IBrowserAdapter } from './browser-adapter.js';
5
+ import type { ILogger } from '../types.js';
6
+ import type { BrowserConfig } from '../../config/schema.js';
7
+ /**
8
+ * Context provided to strategies during authentication.
9
+ * Browser adapter is optional — strategies that don't need a browser (api-token, basic)
10
+ * simply ignore it.
11
+ */
12
+ export interface AuthContext {
13
+ browserAdapter: IBrowserAdapter;
14
+ browserConfig: BrowserConfig;
15
+ logger?: ILogger;
16
+ }
17
+ /**
18
+ * Core strategy interface — implements a specific authentication method.
19
+ *
20
+ * Each method returns Result<T, AuthError> instead of throwing.
21
+ * This ensures expected failures (expired tokens, manual setup needed)
22
+ * are handled through types, not catch blocks.
23
+ */
24
+ export interface IAuthStrategy {
25
+ /** Check if a credential is still valid (not expired, not revoked). */
26
+ validate(credential: Credential, config: StrategyConfig): Result<boolean, AuthError>;
27
+ /** Perform fresh authentication. May launch a browser. */
28
+ authenticate(provider: ProviderConfig, context: AuthContext): Promise<Result<Credential, AuthError>>;
29
+ /**
30
+ * Try to refresh an expired credential without full re-authentication.
31
+ * Returns ok(null) if refresh is not supported by this strategy.
32
+ * Returns ok(credential) if refresh succeeded.
33
+ * Returns err() if refresh was attempted but failed.
34
+ */
35
+ refresh(credential: Credential, config: StrategyConfig): Promise<Result<Credential | null, AuthError>>;
36
+ /** Convert a credential into HTTP headers for an outgoing request. */
37
+ applyToRequest(credential: Credential): Record<string, string>;
38
+ }
39
+ /**
40
+ * Factory for creating strategy instances from YAML config.
41
+ * Each factory is registered in the StrategyRegistry by name.
42
+ */
43
+ export interface IAuthStrategyFactory {
44
+ /** Strategy name as used in provider config (e.g. "cookie", "oauth2") */
45
+ readonly name: string;
46
+ /** Create a strategy instance with the given config */
47
+ create(config: StrategyConfig): IAuthStrategy;
48
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ import type { Cookie, BrowserLaunchOptions } from '../types.js';
2
+ /**
3
+ * Pluggable browser automation adapter.
4
+ *
5
+ * Ships with PlaywrightAdapter. Users can implement this interface
6
+ * for Puppeteer, raw CDP, or any other browser automation tool.
7
+ *
8
+ * Example:
9
+ * class PuppeteerAdapter implements IBrowserAdapter {
10
+ * readonly name = 'puppeteer';
11
+ * async launch(options) { ... }
12
+ * }
13
+ */
14
+ export interface IBrowserAdapter {
15
+ readonly name: string;
16
+ launch(options: BrowserLaunchOptions): Promise<IBrowserSession>;
17
+ }
18
+ export interface IBrowserSession {
19
+ newPage(): Promise<IBrowserPage>;
20
+ pages(): Promise<IBrowserPage[]>;
21
+ close(): Promise<void>;
22
+ isConnected(): boolean;
23
+ }
24
+ export interface IBrowserPage {
25
+ goto(url: string, options?: NavigateOptions): Promise<void>;
26
+ url(): string;
27
+ waitForUrl(pattern: string | RegExp, options?: {
28
+ timeout?: number;
29
+ }): Promise<void>;
30
+ waitForNavigation(options?: {
31
+ timeout?: number;
32
+ }): Promise<void>;
33
+ waitForLoadState(state?: 'load' | 'networkidle' | 'domcontentloaded'): Promise<void>;
34
+ fill(selector: string, value: string): Promise<void>;
35
+ click(selector: string, options?: {
36
+ timeout?: number;
37
+ }): Promise<void>;
38
+ type(selector: string, text: string, options?: {
39
+ delay?: number;
40
+ }): Promise<void>;
41
+ waitForSelector(selector: string, options?: {
42
+ timeout?: number;
43
+ state?: 'visible' | 'hidden' | 'attached';
44
+ }): Promise<void>;
45
+ cookies(urls?: string[]): Promise<Cookie[]>;
46
+ evaluate<T>(fn: (() => T) | string): Promise<T>;
47
+ evaluateWithArg<T, A>(fn: ((arg: A) => T), arg: A): Promise<T>;
48
+ screenshot(options?: {
49
+ path?: string;
50
+ fullPage?: boolean;
51
+ }): Promise<Buffer>;
52
+ content(): Promise<string>;
53
+ title(): Promise<string>;
54
+ close(): Promise<void>;
55
+ isClosed(): boolean;
56
+ onClose(handler: () => void): void;
57
+ onRequest?(handler: (request: PageRequest) => void): () => void;
58
+ onResponse?(handler: (response: PageResponse) => void): () => void;
59
+ }
60
+ export interface PageRequest {
61
+ url: string;
62
+ method: string;
63
+ headers: Record<string, string>;
64
+ }
65
+ export interface PageResponse {
66
+ url: string;
67
+ status: number;
68
+ headers: Record<string, string>;
69
+ }
70
+ export interface NavigateOptions {
71
+ waitUntil?: 'load' | 'networkidle' | 'domcontentloaded' | 'commit';
72
+ timeout?: number;
73
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { ProviderConfig } from '../types.js';
2
+ /**
3
+ * Registry for provider configurations.
4
+ * Providers are loaded from YAML config files and can be registered at runtime.
5
+ */
6
+ export interface IProviderRegistry {
7
+ /** Resolve a provider by matching a URL against registered domains. */
8
+ resolve(url: string): ProviderConfig | null;
9
+ /** Get a provider by its ID. */
10
+ get(id: string): ProviderConfig | null;
11
+ /** List all registered providers. */
12
+ list(): ProviderConfig[];
13
+ /** Register a new provider at runtime. Overwrites if ID already exists. */
14
+ register(provider: ProviderConfig): void;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { StoredCredential, StoredEntry } from '../types.js';
2
+ /**
3
+ * Credential persistence interface.
4
+ *
5
+ * Implementations:
6
+ * - DirectoryStorage: one JSON file per provider in a directory (production)
7
+ * - CachedStorage: TTL cache decorator wrapping any IStorage
8
+ * - MemoryStorage: in-memory (testing)
9
+ */
10
+ export interface IStorage {
11
+ /** Get stored credential for a provider. Returns null if not found. */
12
+ get(providerId: string): Promise<StoredCredential | null>;
13
+ /** Store (or overwrite) credential for a provider. */
14
+ set(providerId: string, credential: StoredCredential): Promise<void>;
15
+ /** Delete stored credential for a provider. No-op if not found. */
16
+ delete(providerId: string): Promise<void>;
17
+ /** List all stored entries (summary, not full credentials). */
18
+ list(): Promise<StoredEntry[]>;
19
+ /** Delete all stored credentials. */
20
+ clear(): Promise<void>;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Result type for operations that can fail without throwing exceptions.
3
+ * Used instead of try/catch for expected failure modes like "manual setup required".
4
+ */
5
+ export type Result<T, E = Error> = {
6
+ ok: true;
7
+ value: T;
8
+ } | {
9
+ ok: false;
10
+ error: E;
11
+ };
12
+ export declare function ok<T>(value: T): Result<T, never>;
13
+ export declare function err<E>(error: E): Result<never, E>;
14
+ export declare function isOk<T, E>(result: Result<T, E>): result is {
15
+ ok: true;
16
+ value: T;
17
+ };
18
+ export declare function isErr<T, E>(result: Result<T, E>): result is {
19
+ ok: false;
20
+ error: E;
21
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Result type for operations that can fail without throwing exceptions.
3
+ * Used instead of try/catch for expected failure modes like "manual setup required".
4
+ */
5
+ export function ok(value) {
6
+ return { ok: true, value };
7
+ }
8
+ export function err(error) {
9
+ return { ok: false, error };
10
+ }
11
+ export function isOk(result) {
12
+ return result.ok;
13
+ }
14
+ export function isErr(result) {
15
+ return !result.ok;
16
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Core type definitions for signet.
3
+ * These types have zero external dependencies — they are the shared vocabulary
4
+ * used across all layers (strategies, storage, providers, handlers).
5
+ */
6
+ export interface CookieStrategyConfig {
7
+ strategy: 'cookie';
8
+ ttl?: string;
9
+ requiredCookies?: string[];
10
+ }
11
+ export interface OAuth2StrategyConfig {
12
+ strategy: 'oauth2';
13
+ audiences?: string[];
14
+ tokenEndpoint?: string;
15
+ clientId?: string;
16
+ scopes?: string[];
17
+ }
18
+ export interface ApiTokenStrategyConfig {
19
+ strategy: 'api-token';
20
+ headerName?: string;
21
+ headerPrefix?: string;
22
+ setupInstructions?: string;
23
+ }
24
+ export interface BasicStrategyConfig {
25
+ strategy: 'basic';
26
+ setupInstructions?: string;
27
+ }
28
+ export type StrategyConfig = CookieStrategyConfig | OAuth2StrategyConfig | ApiTokenStrategyConfig | BasicStrategyConfig;
29
+ export type StrategyName = StrategyConfig['strategy'];
30
+ export type CredentialType = 'cookie' | 'bearer' | 'api-key' | 'basic';
31
+ export interface Cookie {
32
+ name: string;
33
+ value: string;
34
+ domain: string;
35
+ path: string;
36
+ expires: number;
37
+ httpOnly: boolean;
38
+ secure: boolean;
39
+ sameSite?: 'Strict' | 'Lax' | 'None';
40
+ }
41
+ export interface CookieCredential {
42
+ type: 'cookie';
43
+ cookies: Cookie[];
44
+ obtainedAt: string;
45
+ xHeaders?: Record<string, string>;
46
+ }
47
+ export interface BearerCredential {
48
+ type: 'bearer';
49
+ accessToken: string;
50
+ refreshToken?: string;
51
+ expiresAt?: string;
52
+ scopes?: string[];
53
+ tokenEndpoint?: string;
54
+ xHeaders?: Record<string, string>;
55
+ }
56
+ export interface ApiKeyCredential {
57
+ type: 'api-key';
58
+ key: string;
59
+ headerName: string;
60
+ headerPrefix?: string;
61
+ }
62
+ export interface BasicCredential {
63
+ type: 'basic';
64
+ username: string;
65
+ password: string;
66
+ }
67
+ export type Credential = CookieCredential | BearerCredential | ApiKeyCredential | BasicCredential;
68
+ export interface XHeaderConfig {
69
+ name: string;
70
+ source?: 'request' | 'response';
71
+ urlPattern?: string;
72
+ staticValue?: string;
73
+ }
74
+ export interface ProviderConfig {
75
+ id: string;
76
+ name: string;
77
+ domains: string[];
78
+ entryUrl?: string;
79
+ strategy: string;
80
+ strategyConfig: StrategyConfig;
81
+ acceptedCredentialTypes?: CredentialType[];
82
+ setupInstructions?: string;
83
+ credentialFile?: string;
84
+ xHeaders?: XHeaderConfig[];
85
+ autoProvisioned?: boolean;
86
+ forceVisible?: boolean;
87
+ }
88
+ export interface StoredCredential {
89
+ credential: Credential;
90
+ providerId: string;
91
+ strategy: string;
92
+ updatedAt: string;
93
+ metadata?: Record<string, unknown>;
94
+ }
95
+ export interface StoredEntry {
96
+ providerId: string;
97
+ strategy: string;
98
+ updatedAt: string;
99
+ credentialType: CredentialType;
100
+ }
101
+ export interface BrowserLaunchOptions {
102
+ headless?: boolean;
103
+ timeout?: number;
104
+ args?: string[];
105
+ }
106
+ export interface ProviderStatus {
107
+ id: string;
108
+ name: string;
109
+ configured: boolean;
110
+ valid: boolean;
111
+ credentialType?: CredentialType;
112
+ strategy: string;
113
+ expiresAt?: string;
114
+ expiresInMinutes?: number;
115
+ }
116
+ export interface ILogger {
117
+ debug(message: string, ...args: unknown[]): void;
118
+ info(message: string, ...args: unknown[]): void;
119
+ warn(message: string, ...args: unknown[]): void;
120
+ error(message: string, ...args: unknown[]): void;
121
+ }
122
+ export interface AuthDiagnostics {
123
+ authDetectedImmediately: boolean;
124
+ oauthTokensDetected: boolean;
125
+ cookiesExtracted: number;
126
+ testRequestStatus?: number;
127
+ suggestions: string[];
128
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Core type definitions for signet.
3
+ * These types have zero external dependencies — they are the shared vocabulary
4
+ * used across all layers (strategies, storage, providers, handlers).
5
+ */
6
+ export {};
package/dist/deps.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { IStorage } from './core/interfaces/storage.js';
2
+ import type { SignetConfig } from './config/schema.js';
3
+ import { AuthManager } from './auth-manager.js';
4
+ import { StrategyRegistry } from './strategies/registry.js';
5
+ import { ProviderRegistry } from './providers/provider-registry.js';
6
+ /**
7
+ * Shared dependency graph used by the CLI and programmatic API.
8
+ */
9
+ export interface AuthDeps {
10
+ authManager: AuthManager;
11
+ storage: IStorage;
12
+ providerRegistry: ProviderRegistry;
13
+ strategyRegistry: StrategyRegistry;
14
+ config: SignetConfig;
15
+ }
16
+ /**
17
+ * Create the auth dependency graph from a validated SignetConfig.
18
+ * No env vars, no cascade — config is the single source of truth.
19
+ */
20
+ export declare function createAuthDeps(config: SignetConfig): AuthDeps;
package/dist/deps.js ADDED
@@ -0,0 +1,54 @@
1
+ import os from 'node:os';
2
+ import { AuthManager } from './auth-manager.js';
3
+ import { StrategyRegistry } from './strategies/registry.js';
4
+ import { CookieStrategyFactory } from './strategies/cookie.strategy.js';
5
+ import { OAuth2StrategyFactory } from './strategies/oauth2.strategy.js';
6
+ import { ApiTokenStrategyFactory } from './strategies/api-token.strategy.js';
7
+ import { BasicAuthStrategyFactory } from './strategies/basic-auth.strategy.js';
8
+ import { ProviderRegistry } from './providers/provider-registry.js';
9
+ import { DirectoryStorage } from './storage/directory-storage.js';
10
+ import { CachedStorage } from './storage/cached-storage.js';
11
+ import { PlaywrightAdapter } from './browser/adapters/playwright.adapter.js';
12
+ import { buildStrategyConfig } from './config/validator.js';
13
+ /**
14
+ * Create the auth dependency graph from a validated SignetConfig.
15
+ * No env vars, no cascade — config is the single source of truth.
16
+ */
17
+ export function createAuthDeps(config) {
18
+ // 1. Convert config providers to ProviderConfig[]
19
+ const providerConfigs = Object.entries(config.providers).map(([id, entry]) => ({
20
+ id,
21
+ name: entry.name ?? id,
22
+ domains: entry.domains,
23
+ entryUrl: entry.entryUrl,
24
+ strategy: entry.strategy,
25
+ strategyConfig: buildStrategyConfig(entry.strategy, entry.config),
26
+ acceptedCredentialTypes: entry.acceptedCredentialTypes,
27
+ setupInstructions: entry.setupInstructions,
28
+ credentialFile: entry.credentialFile,
29
+ xHeaders: entry.xHeaders,
30
+ ...(entry.forceVisible !== undefined ? { forceVisible: entry.forceVisible } : {}),
31
+ }));
32
+ const providerRegistry = new ProviderRegistry(providerConfigs);
33
+ // 2. Build strategy registry with built-in strategies
34
+ const strategyRegistry = new StrategyRegistry();
35
+ strategyRegistry.register(new CookieStrategyFactory());
36
+ strategyRegistry.register(new OAuth2StrategyFactory());
37
+ strategyRegistry.register(new ApiTokenStrategyFactory());
38
+ strategyRegistry.register(new BasicAuthStrategyFactory());
39
+ // 3. Build storage (CachedStorage wrapping DirectoryStorage)
40
+ const credDir = config.storage.credentialsDir.replace(/^~/, os.homedir());
41
+ const storage = new CachedStorage(new DirectoryStorage(credDir), { ttlMs: 5000 });
42
+ // 4. Build browser adapter factory using config.browser
43
+ const browserConfig = config.browser;
44
+ const browserAdapterFactory = () => new PlaywrightAdapter(browserConfig);
45
+ // 5. Build AuthManager
46
+ const authManager = new AuthManager({
47
+ storage,
48
+ strategyRegistry,
49
+ providerRegistry,
50
+ browserAdapterFactory,
51
+ browserConfig,
52
+ });
53
+ return { authManager, storage, providerRegistry, strategyRegistry, config };
54
+ }
@@ -0,0 +1,35 @@
1
+ export type { SignetConfig, BrowserConfig, StorageConfig, ProviderEntry, RemoteEntry, } from './config/schema.js';
2
+ export { loadConfig, saveConfig, getConfigPath } from './config/loader.js';
3
+ export { validateConfig, buildStrategyConfig } from './config/validator.js';
4
+ export { generateConfigYaml } from './config/generator.js';
5
+ export type { InitOptions } from './config/generator.js';
6
+ export { createAuthDeps } from './deps.js';
7
+ export type { AuthDeps } from './deps.js';
8
+ export type { Credential, CookieCredential, BearerCredential, ApiKeyCredential, BasicCredential, CredentialType, Cookie, ProviderConfig, StrategyConfig, StrategyName, CookieStrategyConfig, OAuth2StrategyConfig, ApiTokenStrategyConfig, BasicStrategyConfig, StoredCredential, StoredEntry, ProviderStatus, BrowserLaunchOptions, ILogger, XHeaderConfig, AuthDiagnostics, } from './core/types.js';
9
+ export { ok, err, isOk, isErr } from './core/result.js';
10
+ export type { Result } from './core/result.js';
11
+ export { AuthError, ProviderNotFoundError, CredentialNotFoundError, CredentialExpiredError, CredentialTypeError, RefreshError, BrowserError, BrowserLaunchError, BrowserTimeoutError, BrowserNavigationError, StorageError, ConfigError, ManualSetupRequired, SyncError, RemoteNotFoundError, SyncConflictError, } from './core/errors.js';
12
+ export type { IAuthStrategy, IAuthStrategyFactory, AuthContext } from './core/interfaces/auth-strategy.js';
13
+ export type { IBrowserAdapter, IBrowserSession, IBrowserPage, NavigateOptions, PageRequest, PageResponse } from './core/interfaces/browser-adapter.js';
14
+ export type { IStorage } from './core/interfaces/storage.js';
15
+ export type { IProviderRegistry } from './core/interfaces/provider.js';
16
+ export { AuthManager } from './auth-manager.js';
17
+ export { CookieStrategyFactory } from './strategies/cookie.strategy.js';
18
+ export { OAuth2StrategyFactory } from './strategies/oauth2.strategy.js';
19
+ export { ApiTokenStrategyFactory } from './strategies/api-token.strategy.js';
20
+ export { BasicAuthStrategyFactory } from './strategies/basic-auth.strategy.js';
21
+ export { StrategyRegistry } from './strategies/registry.js';
22
+ export { DirectoryStorage } from './storage/directory-storage.js';
23
+ export { CachedStorage } from './storage/cached-storage.js';
24
+ export { MemoryStorage } from './storage/memory-storage.js';
25
+ export { ProviderRegistry } from './providers/provider-registry.js';
26
+ export { createDefaultProvider } from './providers/auto-provision.js';
27
+ export { PlaywrightAdapter } from './browser/adapters/playwright.adapter.js';
28
+ export { run as runCli, parseArgs } from './cli/main.js';
29
+ export { SyncEngine } from './sync/sync-engine.js';
30
+ export { SshTransport } from './sync/transports/ssh.js';
31
+ export { getRemotes, getRemote, addRemote, removeRemote } from './sync/remote-config.js';
32
+ export type { RemoteConfig, SyncResult } from './sync/types.js';
33
+ export { decodeJwt, isJwtExpired, getJwtExpiresAt } from './utils/jwt.js';
34
+ export { parseDuration, formatDuration } from './utils/duration.js';
35
+ export { buildUserAgent } from './utils/http.js';
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ // Public API exports for signet
2
+ export { loadConfig, saveConfig, getConfigPath } from './config/loader.js';
3
+ export { validateConfig, buildStrategyConfig } from './config/validator.js';
4
+ export { generateConfigYaml } from './config/generator.js';
5
+ // Dependency wiring
6
+ export { createAuthDeps } from './deps.js';
7
+ // Result type
8
+ export { ok, err, isOk, isErr } from './core/result.js';
9
+ // Errors
10
+ export { AuthError, ProviderNotFoundError, CredentialNotFoundError, CredentialExpiredError, CredentialTypeError, RefreshError, BrowserError, BrowserLaunchError, BrowserTimeoutError, BrowserNavigationError, StorageError, ConfigError, ManualSetupRequired, SyncError, RemoteNotFoundError, SyncConflictError, } from './core/errors.js';
11
+ // AuthManager
12
+ export { AuthManager } from './auth-manager.js';
13
+ // Strategy factories (for custom registration)
14
+ export { CookieStrategyFactory } from './strategies/cookie.strategy.js';
15
+ export { OAuth2StrategyFactory } from './strategies/oauth2.strategy.js';
16
+ export { ApiTokenStrategyFactory } from './strategies/api-token.strategy.js';
17
+ export { BasicAuthStrategyFactory } from './strategies/basic-auth.strategy.js';
18
+ export { StrategyRegistry } from './strategies/registry.js';
19
+ // Storage implementations
20
+ export { DirectoryStorage } from './storage/directory-storage.js';
21
+ export { CachedStorage } from './storage/cached-storage.js';
22
+ export { MemoryStorage } from './storage/memory-storage.js';
23
+ // Provider system
24
+ export { ProviderRegistry } from './providers/provider-registry.js';
25
+ export { createDefaultProvider } from './providers/auto-provision.js';
26
+ // Browser adapters
27
+ export { PlaywrightAdapter } from './browser/adapters/playwright.adapter.js';
28
+ // CLI
29
+ export { run as runCli, parseArgs } from './cli/main.js';
30
+ // Sync
31
+ export { SyncEngine } from './sync/sync-engine.js';
32
+ export { SshTransport } from './sync/transports/ssh.js';
33
+ export { getRemotes, getRemote, addRemote, removeRemote } from './sync/remote-config.js';
34
+ // Utilities
35
+ export { decodeJwt, isJwtExpired, getJwtExpiresAt } from './utils/jwt.js';
36
+ export { parseDuration, formatDuration } from './utils/duration.js';
37
+ export { buildUserAgent } from './utils/http.js';