@skillbuilder/minitool-cli-auth 0.0.0-beta-20261027053041051

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.
@@ -0,0 +1,63 @@
1
+ export type AuthMethod = "secret" | "device";
2
+ export type CredentialSource = "local_file" | "os_keychain";
3
+ export interface CreatorIdentity {
4
+ creatorId: string;
5
+ displayName: string;
6
+ avatarUrl?: string;
7
+ description?: string;
8
+ }
9
+ export interface AuthenticatedAuthState {
10
+ status: "authenticated";
11
+ method: AuthMethod;
12
+ source: CredentialSource;
13
+ identitySnapshot: CreatorIdentity | null;
14
+ expiresAt: string;
15
+ }
16
+ export interface AnonymousAuthState {
17
+ status: "anonymous";
18
+ reason: "not_logged_in" | "expired";
19
+ }
20
+ export interface UnavailableAuthState {
21
+ status: "unavailable";
22
+ reason: "credential_store_error";
23
+ }
24
+ export type AuthState = AuthenticatedAuthState | AnonymousAuthState | UnavailableAuthState;
25
+ export interface LoginResult {
26
+ secretId?: string;
27
+ expiresAt: string;
28
+ creator?: CreatorIdentity;
29
+ }
30
+ export interface AuthStateProvider {
31
+ getAuthState(): Promise<AuthState>;
32
+ }
33
+ export interface AccessTokenProvider {
34
+ getAccessToken(): Promise<string>;
35
+ }
36
+ export interface DeviceAuthPrompt {
37
+ authorizeCommonUrl: string;
38
+ authorizeH5Url: string;
39
+ userCode: string;
40
+ expiresAt: string;
41
+ }
42
+ export interface QrLoginOptions {
43
+ onPrompt(prompt: DeviceAuthPrompt): void | Promise<void>;
44
+ signal?: AbortSignal;
45
+ }
46
+ export interface AuthService extends AuthStateProvider, AccessTokenProvider {
47
+ loginWithSecret(secretId: string, secretKey: string): Promise<LoginResult>;
48
+ whoAmI(): Promise<CreatorIdentity>;
49
+ logout(): Promise<void>;
50
+ }
51
+ export declare class CredentialStoreUnavailableError extends Error {
52
+ readonly code = "CREDENTIAL_STORE_UNAVAILABLE";
53
+ constructor(message?: string);
54
+ }
55
+ export declare class AuthenticationRequiredError extends Error {
56
+ readonly code = "AUTHENTICATION_REQUIRED";
57
+ constructor(message?: string);
58
+ }
59
+ export declare class CreatorIdentityUnavailableError extends Error {
60
+ readonly code = "CREATOR_IDENTITY_UNAVAILABLE";
61
+ constructor(message?: string);
62
+ }
63
+ export declare function requireAuthenticatedAuthState(state: AuthState): AuthenticatedAuthState;
@@ -0,0 +1,32 @@
1
+ import type { AuthFileConfig, GlobalConfig } from "@skillbuilder/minitool-cli-config";
2
+ import { ConfigFiles } from "@skillbuilder/minitool-cli-config";
3
+ export type CredentialStorageMode = GlobalConfig["credentialStore"];
4
+ export interface CredentialStore {
5
+ get(): AuthFileConfig | null;
6
+ update(config: AuthFileConfig): void;
7
+ delete(): void;
8
+ }
9
+ export interface CredentialStorageStatus {
10
+ configuredMode: CredentialStorageMode;
11
+ provider: string;
12
+ protection: "restricted_plaintext_file" | "os_protected_store";
13
+ keyringAvailable?: boolean;
14
+ keyringIssue?: "package_unavailable" | "access_error";
15
+ }
16
+ export interface CredentialStorageSwitchResult {
17
+ changed: boolean;
18
+ migrated: boolean;
19
+ sourceRetained: boolean;
20
+ }
21
+ export interface CredentialStorageController {
22
+ getMode(): CredentialStorageMode;
23
+ use(mode: CredentialStorageMode): CredentialStorageSwitchResult;
24
+ inspect(probeKeyring?: boolean): CredentialStorageStatus;
25
+ }
26
+ export declare class FileCredentialStore implements CredentialStore {
27
+ private readonly files;
28
+ constructor(files: ConfigFiles);
29
+ get(): AuthFileConfig | null;
30
+ update(config: AuthFileConfig): void;
31
+ delete(): void;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import type { DeviceAuthPrompt } from "./auth-state";
2
+ export declare const DEVICE_AUTH_PATHS: Readonly<{
3
+ create: "/api/sns/v1/creator/red_skill/create_cli_oauth_device_code";
4
+ poll: "/api/sns/v1/creator/red_skill/poll_cli_oauth_device_token";
5
+ exchange: "/api/sns/v1/creator/red_skill/exchange_cli_oauth_token";
6
+ refresh: "/api/sns/v1/creator/red_skill/refresh_cli_oauth_token";
7
+ }>;
8
+ export declare const DEVICE_AUTH_SCOPES: readonly ["base_info", "skill_publish"];
9
+ export interface DeviceCode extends Omit<DeviceAuthPrompt, "expiresAt"> {
10
+ deviceCode: string;
11
+ expiresInSeconds: number;
12
+ pollIntervalSeconds: number;
13
+ }
14
+ export interface PollResult {
15
+ status: "pending" | "approved" | "denied" | "expired" | "cancelled";
16
+ authorizationCode?: string;
17
+ }
18
+ export interface DeviceAuthApi {
19
+ readonly apiBaseUrl: string;
20
+ create(codeChallenge: string, signal?: AbortSignal): Promise<DeviceCode>;
21
+ poll(deviceCode: string, signal?: AbortSignal): Promise<PollResult>;
22
+ exchange(code: string, verifier: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
23
+ refresh(token: string): Promise<Record<string, unknown>>;
24
+ }
25
+ export declare class DeviceAuthError extends Error {
26
+ readonly code: string;
27
+ constructor(code: string, message: string);
28
+ }
29
+ export declare function authRecord(value: unknown): value is Record<string, unknown>;
30
+ export declare function authText(value: unknown): string;
31
+ export declare class HttpDeviceAuthApi implements DeviceAuthApi {
32
+ private readonly request;
33
+ readonly apiBaseUrl: string;
34
+ constructor(baseUrl: string, request?: typeof fetch);
35
+ private call;
36
+ create(codeChallenge: string, signal?: AbortSignal): Promise<DeviceCode>;
37
+ poll(deviceCode: string, signal?: AbortSignal): Promise<PollResult>;
38
+ exchange(code: string, verifier: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
39
+ refresh(token: string): Promise<Record<string, unknown>>;
40
+ }
@@ -0,0 +1,34 @@
1
+ import { type ConfigFiles } from "@skillbuilder/minitool-cli-config";
2
+ import { type AuthService, type AuthState, type CreatorIdentity, type LoginResult, type QrLoginOptions } from "./auth-state";
3
+ import type { CredentialStorageController, CredentialStore } from "./credential-store";
4
+ import { type DeviceAuthApi } from "./device-auth-api";
5
+ type PendingStore = Pick<ConfigFiles, "readPendingAuth" | "writePendingAuth" | "clearPendingAuth">;
6
+ export interface DeviceAuthClock {
7
+ now(): number;
8
+ sleep(milliseconds: number, signal?: AbortSignal): Promise<void>;
9
+ }
10
+ /** 扫码 PKCE 与续期生命周期;UI 回调只接收公开授权链接,不接收设备码和 verifier。 */
11
+ export declare class DeviceAuthService implements AuthService {
12
+ private readonly store;
13
+ private readonly api;
14
+ private readonly storage;
15
+ private readonly pending;
16
+ private readonly secretAuth?;
17
+ private readonly clock;
18
+ private refreshPromise?;
19
+ constructor(store: CredentialStore, api: DeviceAuthApi, storage: Pick<CredentialStorageController, "getMode">, pending: PendingStore, secretAuth?: AuthService | undefined, clock?: DeviceAuthClock);
20
+ loginWithSecret(id: string, key: string): Promise<LoginResult>;
21
+ private read;
22
+ private owns;
23
+ private canRefresh;
24
+ private identity;
25
+ getAuthState(): Promise<AuthState>;
26
+ getAccessToken(): Promise<string>;
27
+ private tokenCredential;
28
+ private refresh;
29
+ loginWithQr(options: QrLoginOptions): Promise<LoginResult>;
30
+ cancelLogin(): Promise<void>;
31
+ whoAmI(): Promise<CreatorIdentity>;
32
+ logout(): Promise<void>;
33
+ }
34
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export { AuthenticationRequiredError, CredentialStoreUnavailableError, CreatorIdentityUnavailableError, requireAuthenticatedAuthState, } from "./auth-state";
2
+ export type { AccessTokenProvider, AuthMethod, AuthService, AuthState, AuthStateProvider, AuthenticatedAuthState, AnonymousAuthState, CreatorIdentity, CredentialSource, LoginResult, UnavailableAuthState, } from "./auth-state";
3
+ export { HttpSecretAuthApi, SecretAuthService } from "./secret-auth";
4
+ export type { CheckStatusResponse, SecretAuthApi, } from "./secret-auth";
5
+ export type { CredentialStorageController, CredentialStorageMode, CredentialStorageStatus, CredentialStorageSwitchResult, CredentialStore, } from "./credential-store";
6
+ export { ManagedCredentialStore } from "./managed-credential-store";
7
+ export { DeviceAuthService } from "./device-auth";
8
+ export type { DeviceAuthClock } from "./device-auth";
9
+ export { HttpDeviceAuthApi, DeviceAuthError, DEVICE_AUTH_PATHS } from "./device-auth-api";
10
+ export type { DeviceAuthApi, DeviceCode, PollResult } from "./device-auth-api";
11
+ export type { DeviceAuthPrompt, QrLoginOptions } from "./auth-state";
@@ -0,0 +1,30 @@
1
+ import type { AuthFileConfig } from "@skillbuilder/minitool-cli-config";
2
+ import type { CredentialStore } from "./credential-store";
3
+ export interface KeyringCredentialStorePort extends CredentialStore {
4
+ probe(): void;
5
+ }
6
+ export interface KeyringEntry {
7
+ getPassword(): string | null;
8
+ setPassword(password: string): void;
9
+ deleteCredential(): boolean;
10
+ }
11
+ export type KeyringEntryFactory = (service: string, account: string) => KeyringEntry;
12
+ export declare class KeyringUnavailableError extends Error {
13
+ readonly code = "KEYRING_UNAVAILABLE";
14
+ constructor();
15
+ }
16
+ export declare class KeyringAccessError extends Error {
17
+ readonly code = "KEYRING_ACCESS_FAILED";
18
+ constructor(operation: "读取" | "写入" | "删除");
19
+ }
20
+ export declare function getSystemCredentialStoreName(platform?: NodeJS.Platform): string;
21
+ /** 每个配置目录使用独立系统凭据条目。 */
22
+ export declare class KeyringCredentialStore implements KeyringCredentialStorePort {
23
+ private readonly entryFactory;
24
+ private readonly account;
25
+ constructor(authPath: string, entryFactory?: KeyringEntryFactory);
26
+ probe(): void;
27
+ get(): AuthFileConfig | null;
28
+ update(config: AuthFileConfig): void;
29
+ delete(): void;
30
+ }
@@ -0,0 +1,21 @@
1
+ import type { AuthFileConfig } from "@skillbuilder/minitool-cli-config";
2
+ import { ConfigFiles } from "@skillbuilder/minitool-cli-config";
3
+ import { type CredentialStorageController, type CredentialStorageMode, type CredentialStorageStatus, type CredentialStorageSwitchResult, type CredentialStore } from "./credential-store";
4
+ import { type KeyringCredentialStorePort } from "./keyring-credential-store";
5
+ /** 文件与系统凭据库之间的显式存储策略。 */
6
+ export declare class ManagedCredentialStore implements CredentialStore, CredentialStorageController {
7
+ private readonly files;
8
+ private readonly file;
9
+ private readonly keyring;
10
+ constructor(files: ConfigFiles, file?: CredentialStore, keyring?: KeyringCredentialStorePort);
11
+ getMode(): CredentialStorageMode;
12
+ inspect(probeKeyring?: boolean): CredentialStorageStatus;
13
+ get(): AuthFileConfig | null;
14
+ update(config: AuthFileConfig): void;
15
+ delete(): void;
16
+ use(mode: CredentialStorageMode): CredentialStorageSwitchResult;
17
+ private store;
18
+ private setMode;
19
+ private inspectKeyring;
20
+ private writeVerified;
21
+ }
@@ -0,0 +1,52 @@
1
+ import { type AuthService, type AuthState, type CreatorIdentity, type LoginResult } from "./auth-state";
2
+ import type { CredentialStorageController, CredentialStore } from "./credential-store";
3
+ export interface CreatorUserInfo {
4
+ nick?: string;
5
+ nickname?: string;
6
+ user_id?: string;
7
+ avatar?: string;
8
+ desc?: string;
9
+ [key: string]: unknown;
10
+ }
11
+ /** 平台 cli_auth 的真实响应不回传 secret_id;持久化时使用已验证的请求值补齐。 */
12
+ export interface SecretAuthResponseData {
13
+ secret_id?: string;
14
+ cli_token: string;
15
+ create_at: number;
16
+ expire_in_sec: number;
17
+ userInfo?: CreatorUserInfo | null;
18
+ }
19
+ export interface CheckStatusRequest {
20
+ secret_id: string;
21
+ nonce: string;
22
+ cli_token: string;
23
+ }
24
+ export interface CheckStatusResponse {
25
+ code: number;
26
+ msg: string;
27
+ data: SecretAuthResponseData | null;
28
+ }
29
+ export interface SecretAuthApi {
30
+ check(request: CheckStatusRequest): Promise<CheckStatusResponse>;
31
+ }
32
+ export declare class HttpSecretAuthApi implements SecretAuthApi {
33
+ private readonly endpointUrl;
34
+ private readonly request;
35
+ constructor(endpointUrl: string | undefined, request?: typeof fetch);
36
+ check(payload: CheckStatusRequest): Promise<CheckStatusResponse>;
37
+ }
38
+ /** Secret Key 仅用于一次签名,永不进入 CredentialStore。 */
39
+ export declare class SecretAuthService implements AuthService {
40
+ private readonly store;
41
+ private readonly api;
42
+ private readonly storage;
43
+ private readonly now;
44
+ constructor(store: CredentialStore, api: SecretAuthApi, storage: Pick<CredentialStorageController, "getMode">, now?: () => number);
45
+ private createProof;
46
+ loginWithSecret(secretId: string, secretKey: string): Promise<LoginResult>;
47
+ private readStoredCredential;
48
+ getAuthState(): Promise<AuthState>;
49
+ getAccessToken(): Promise<string>;
50
+ whoAmI(): Promise<CreatorIdentity>;
51
+ logout(): Promise<void>;
52
+ }
@@ -0,0 +1 @@
1
+ export {};