@deepseek-ai/dsh-deepseek-account-platform 0.1.7-alpha.1
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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +96 -0
- package/README.zh.md +96 -0
- package/lib/index.js +891 -0
- package/lib/types/details.d.ts +17 -0
- package/lib/types/details.js +55 -0
- package/lib/types/index.d.ts +132 -0
- package/lib/types/index.js +488 -0
- package/lib/types/logout.d.ts +17 -0
- package/lib/types/logout.js +34 -0
- package/lib/types/protocol.d.ts +78 -0
- package/lib/types/protocol.js +210 -0
- package/lib/types/types.d.ts +3 -0
- package/lib/types/types.js +2 -0
- package/package.json +52 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AccountDetails, AccountProfile } from '@deepseek-ai/dsh-deepseek-account/types';
|
|
2
|
+
/** Project Platform user data without retaining credentials or unneeded fields.
|
|
3
|
+
* @param value - current or exchange user response.
|
|
4
|
+
* @returns UI account profile.
|
|
5
|
+
*/
|
|
6
|
+
export declare function profile(value: unknown): AccountProfile;
|
|
7
|
+
/**
|
|
8
|
+
* Read one Platform account field without waiting for the other query.
|
|
9
|
+
* @param field - profile or recharge and bonus wallet balances.
|
|
10
|
+
* @param origin - configured origin matching the stored grant issuer.
|
|
11
|
+
* @param token - stored authorization token; response tokens are discarded.
|
|
12
|
+
* @param signal - request and credential lifetime.
|
|
13
|
+
* @param headers - validated deployment headers for the configured origin.
|
|
14
|
+
* @returns sanitized query outcome; failure never becomes a zero balance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readAccountDetail<K extends keyof AccountDetails>(field: K, origin: string, token: string, signal: AbortSignal, headers: Record<string, string>): Promise<AccountDetails[K]>;
|
|
17
|
+
//# sourceMappingURL=details.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Platform Web profile and wallet queries projected for account UI consumers. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { PlatformAuthError, requestAccount } from "./protocol.js";
|
|
4
|
+
const user = z.object({
|
|
5
|
+
id: z.string().nullish(),
|
|
6
|
+
email: z.string(), mobile: z.string().optional(), mobile_number: z.string().optional(),
|
|
7
|
+
id_profile: z.object({ name: z.string().nullable(), picture: z.string().nullish() }).nullish(),
|
|
8
|
+
});
|
|
9
|
+
const wallet = z.object({
|
|
10
|
+
currency: z.enum(['CNY', 'USD']), balance: z.string().regex(/^-?\d+(?:\.\d+)?$/),
|
|
11
|
+
});
|
|
12
|
+
const summary = z.object({ normal_wallets: z.array(wallet), bonus_wallets: z.array(wallet) });
|
|
13
|
+
/** Project Platform user data without retaining credentials or unneeded fields.
|
|
14
|
+
* @param value - current or exchange user response.
|
|
15
|
+
* @returns UI account profile.
|
|
16
|
+
*/
|
|
17
|
+
export function profile(value) {
|
|
18
|
+
const parsed = user.safeParse(value);
|
|
19
|
+
if (!parsed.success)
|
|
20
|
+
throw new PlatformAuthError('protocol');
|
|
21
|
+
const { email, mobile, mobile_number: mobileNumber, id_profile: identity } = parsed.data;
|
|
22
|
+
return {
|
|
23
|
+
id: parsed.data.id == null ? null : parsed.data.id,
|
|
24
|
+
avatarUrl: identity?.picture || null,
|
|
25
|
+
name: identity?.name || null, contact: mobile || mobileNumber || email || null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const queries = {
|
|
29
|
+
profile: { path: '/auth-api/v0/users/current', parse: value => ({ status: 'ready', value: profile(value) }) },
|
|
30
|
+
balance: { path: '/api/v0/users/get_user_summary', parse: (value) => {
|
|
31
|
+
const parsed = summary.safeParse(value);
|
|
32
|
+
if (!parsed.success)
|
|
33
|
+
throw new PlatformAuthError('protocol');
|
|
34
|
+
return { status: 'ready', value: parsed.data.normal_wallets, bonusWallets: parsed.data.bonus_wallets };
|
|
35
|
+
} },
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Read one Platform account field without waiting for the other query.
|
|
39
|
+
* @param field - profile or recharge and bonus wallet balances.
|
|
40
|
+
* @param origin - configured origin matching the stored grant issuer.
|
|
41
|
+
* @param token - stored authorization token; response tokens are discarded.
|
|
42
|
+
* @param signal - request and credential lifetime.
|
|
43
|
+
* @param headers - validated deployment headers for the configured origin.
|
|
44
|
+
* @returns sanitized query outcome; failure never becomes a zero balance.
|
|
45
|
+
*/
|
|
46
|
+
export async function readAccountDetail(field, origin, token, signal, headers) {
|
|
47
|
+
const query = queries[field];
|
|
48
|
+
try {
|
|
49
|
+
return query.parse(await requestAccount(origin, query.path, token, signal, headers));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { status: 'failed' };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=details.js.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
2
|
+
import Schema from '@deepseek-ai/schemastery';
|
|
3
|
+
import { DeepSeekAccount, type PlatformSession, type AccountDetails, type AccountView, type SignInAttemptId } from '@deepseek-ai/dsh-deepseek-account';
|
|
4
|
+
/** Deployment-specific platform and request deadlines. */
|
|
5
|
+
export interface Config {
|
|
6
|
+
/** Platform origin serving auth-api and browser pages. */
|
|
7
|
+
platformOrigin?: string;
|
|
8
|
+
/** Native desktop identity for Host API and embedded Platform requests; null omits the client platform header. */
|
|
9
|
+
desktopPlatform?: 'darwin' | 'win32' | null;
|
|
10
|
+
/** Optional frontend deployment selector for embedded Usage and Top-up pages. */
|
|
11
|
+
embeddedPageDist?: string;
|
|
12
|
+
/** Exact HTTP(S) origin allowed to receive account tokens for inference and files. */
|
|
13
|
+
inferenceOrigin?: string;
|
|
14
|
+
/** Allow HTTP only on loopback for the development Mock. */
|
|
15
|
+
allowLoopbackHttp?: boolean;
|
|
16
|
+
/** Map authorization and completion pages to platformOrigin for private development proxies. */
|
|
17
|
+
rewriteBrowserOrigin?: boolean;
|
|
18
|
+
/** Host-only headers sent exclusively to platformOrigin; account authorization cannot be overridden. */
|
|
19
|
+
requestHeaders?: Record<string, string>;
|
|
20
|
+
/** Overrides for profile, balance and embedded Platform requests; Cookie pairs merge by name. Logout retains requestHeaders. */
|
|
21
|
+
accountRequestHeaders?: Record<string, string>;
|
|
22
|
+
/** Deadline for each platform HTTP request. */
|
|
23
|
+
requestTimeoutMs?: number;
|
|
24
|
+
/** Additional logout attempts after the first request fails, at most five. */
|
|
25
|
+
logoutMaxRetries?: number;
|
|
26
|
+
/** Delay before the first logout retry; each later delay doubles. */
|
|
27
|
+
logoutRetryDelayMs?: number;
|
|
28
|
+
/** Upper bound for the entire local attempt, even if the server advertises a longer TTL. */
|
|
29
|
+
attemptTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Validated deployment choices. */
|
|
32
|
+
export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
33
|
+
platformOrigin: Schema<string, string, "defined">;
|
|
34
|
+
desktopPlatform: Schema<"darwin" | "win32" | null, "darwin" | "win32" | null, "defined">;
|
|
35
|
+
embeddedPageDist: Schema<string, string, "defined">;
|
|
36
|
+
inferenceOrigin: Schema<string, string, "defined">;
|
|
37
|
+
allowLoopbackHttp: Schema<boolean, boolean, "defined">;
|
|
38
|
+
rewriteBrowserOrigin: Schema<boolean, boolean, "defined">;
|
|
39
|
+
requestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
40
|
+
accountRequestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
41
|
+
requestTimeoutMs: Schema<number, number, "defined">;
|
|
42
|
+
logoutMaxRetries: Schema<number, number, "defined">;
|
|
43
|
+
logoutRetryDelayMs: Schema<number, number, "defined">;
|
|
44
|
+
attemptTimeoutMs: Schema<number, number, "defined">;
|
|
45
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
46
|
+
platformOrigin: Schema<string, string, "defined">;
|
|
47
|
+
desktopPlatform: Schema<"darwin" | "win32" | null, "darwin" | "win32" | null, "defined">;
|
|
48
|
+
embeddedPageDist: Schema<string, string, "defined">;
|
|
49
|
+
inferenceOrigin: Schema<string, string, "defined">;
|
|
50
|
+
allowLoopbackHttp: Schema<boolean, boolean, "defined">;
|
|
51
|
+
rewriteBrowserOrigin: Schema<boolean, boolean, "defined">;
|
|
52
|
+
requestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
53
|
+
accountRequestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
54
|
+
requestTimeoutMs: Schema<number, number, "defined">;
|
|
55
|
+
logoutMaxRetries: Schema<number, number, "defined">;
|
|
56
|
+
logoutRetryDelayMs: Schema<number, number, "defined">;
|
|
57
|
+
attemptTimeoutMs: Schema<number, number, "defined">;
|
|
58
|
+
}>>, "plain">;
|
|
59
|
+
/** The platform implementation owns login state and its opaque stored grant. */
|
|
60
|
+
export declare class PlatformAccount extends DeepSeekAccount {
|
|
61
|
+
static inject: string[];
|
|
62
|
+
static Config: Schema<Schemastery.ObjectS<NoInfer<{
|
|
63
|
+
platformOrigin: Schema<string, string, "defined">;
|
|
64
|
+
desktopPlatform: Schema<"darwin" | "win32" | null, "darwin" | "win32" | null, "defined">;
|
|
65
|
+
embeddedPageDist: Schema<string, string, "defined">;
|
|
66
|
+
inferenceOrigin: Schema<string, string, "defined">;
|
|
67
|
+
allowLoopbackHttp: Schema<boolean, boolean, "defined">;
|
|
68
|
+
rewriteBrowserOrigin: Schema<boolean, boolean, "defined">;
|
|
69
|
+
requestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
70
|
+
accountRequestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
71
|
+
requestTimeoutMs: Schema<number, number, "defined">;
|
|
72
|
+
logoutMaxRetries: Schema<number, number, "defined">;
|
|
73
|
+
logoutRetryDelayMs: Schema<number, number, "defined">;
|
|
74
|
+
attemptTimeoutMs: Schema<number, number, "defined">;
|
|
75
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
76
|
+
platformOrigin: Schema<string, string, "defined">;
|
|
77
|
+
desktopPlatform: Schema<"darwin" | "win32" | null, "darwin" | "win32" | null, "defined">;
|
|
78
|
+
embeddedPageDist: Schema<string, string, "defined">;
|
|
79
|
+
inferenceOrigin: Schema<string, string, "defined">;
|
|
80
|
+
allowLoopbackHttp: Schema<boolean, boolean, "defined">;
|
|
81
|
+
rewriteBrowserOrigin: Schema<boolean, boolean, "defined">;
|
|
82
|
+
requestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
83
|
+
accountRequestHeaders: Schema<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
84
|
+
requestTimeoutMs: Schema<number, number, "defined">;
|
|
85
|
+
logoutMaxRetries: Schema<number, number, "defined">;
|
|
86
|
+
logoutRetryDelayMs: Schema<number, number, "defined">;
|
|
87
|
+
attemptTimeoutMs: Schema<number, number, "defined">;
|
|
88
|
+
}>>, "plain">;
|
|
89
|
+
private readonly origin;
|
|
90
|
+
private readonly embeddedPageDist;
|
|
91
|
+
private readonly inferenceOrigin;
|
|
92
|
+
private readonly rewriteBrowserOrigin;
|
|
93
|
+
private readonly clientHeaders;
|
|
94
|
+
private readonly requestHeaders;
|
|
95
|
+
private readonly accountRequestHeaders;
|
|
96
|
+
private readonly requestTimeout;
|
|
97
|
+
private readonly attemptTimeout;
|
|
98
|
+
private readonly logoutPolicy;
|
|
99
|
+
private readonly logoutLifetime;
|
|
100
|
+
private readonly revocations;
|
|
101
|
+
private attempt;
|
|
102
|
+
private readonly listeners;
|
|
103
|
+
private lastProfile;
|
|
104
|
+
private detailsLifetime;
|
|
105
|
+
private closed;
|
|
106
|
+
private removing;
|
|
107
|
+
/** @param ctx - Host with authorization and credentials services. @param config - deployment options. */
|
|
108
|
+
constructor(ctx: Context, config?: Config);
|
|
109
|
+
[Service.init](): Promise<void>;
|
|
110
|
+
getState(): Promise<AccountView>;
|
|
111
|
+
getProfile(): Promise<AccountDetails['profile'] | null>;
|
|
112
|
+
getBalance(): Promise<AccountDetails['balance'] | null>;
|
|
113
|
+
private getDetail;
|
|
114
|
+
getPlatformSession(): Promise<PlatformSession | null>;
|
|
115
|
+
private readCurrentGrant;
|
|
116
|
+
resolveToken(url: string): Promise<string | undefined>;
|
|
117
|
+
startSignIn(locale: string, callbackOrigin: string, loginSource: 'web' | 'desktop'): Promise<AccountView>;
|
|
118
|
+
cancelSignIn(id: SignInAttemptId): Promise<AccountView>;
|
|
119
|
+
signOut(): Promise<AccountView>;
|
|
120
|
+
watch(signal: AbortSignal): AsyncIterable<AccountView>;
|
|
121
|
+
private revoke;
|
|
122
|
+
private invalidateDetails;
|
|
123
|
+
private changed;
|
|
124
|
+
private update;
|
|
125
|
+
private run;
|
|
126
|
+
private rejectPayload;
|
|
127
|
+
private cancelRequest;
|
|
128
|
+
private request;
|
|
129
|
+
private finishFailedCallback;
|
|
130
|
+
}
|
|
131
|
+
export default PlatformAccount;
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|