tigeropen 0.5.7 → 0.5.9

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.
Files changed (77) hide show
  1. package/README.md +159 -0
  2. package/dist/cjs/client/api-response.js +6 -5
  3. package/dist/cjs/index.js +4 -2
  4. package/dist/cjs/model/news-requests.js +9 -0
  5. package/dist/cjs/model/news.js +8 -0
  6. package/dist/cjs/news/index.js +8 -0
  7. package/dist/cjs/news/news-client.js +84 -0
  8. package/dist/cjs/push/pb/QuoteBasicData.js +37 -1
  9. package/dist/cjs/push/pb/QuoteData.js +37 -1
  10. package/dist/cjs/quote/quote-client.js +4 -1
  11. package/dist/cjs/trade/trade-client.js +26 -4
  12. package/dist/cjs/version.js +1 -1
  13. package/dist/esm/client/api-response.js +6 -5
  14. package/dist/esm/index.js +2 -1
  15. package/dist/esm/model/news-requests.js +8 -0
  16. package/dist/esm/model/news.js +7 -0
  17. package/dist/esm/news/index.js +4 -0
  18. package/dist/esm/news/news-client.js +80 -0
  19. package/dist/esm/push/pb/QuoteBasicData.js +37 -1
  20. package/dist/esm/push/pb/QuoteData.js +37 -1
  21. package/dist/esm/quote/quote-client.js +4 -1
  22. package/dist/esm/trade/trade-client.js +26 -4
  23. package/dist/esm/version.js +1 -1
  24. package/dist/types/index.d.ts +8 -4
  25. package/dist/types/model/contract.d.ts +8 -0
  26. package/dist/types/model/news-requests.d.ts +39 -0
  27. package/dist/types/model/news.d.ts +38 -0
  28. package/dist/types/model/order.d.ts +2 -0
  29. package/dist/types/model/quote.d.ts +16 -0
  30. package/dist/types/model/trade-requests.d.ts +20 -1
  31. package/dist/types/news/index.d.ts +5 -0
  32. package/dist/types/news/news-client.d.ts +60 -0
  33. package/dist/types/push/pb/QuoteBasicData.d.ts +14 -5
  34. package/dist/types/push/pb/QuoteData.d.ts +14 -5
  35. package/dist/types/quote/quote-client.d.ts +2 -1
  36. package/dist/types/trade/trade-client.d.ts +10 -2
  37. package/dist/types/version.d.ts +1 -1
  38. package/package.json +2 -3
  39. package/dist/cjs/auth/authentication.js +0 -74
  40. package/dist/cjs/auth/index.js +0 -24
  41. package/dist/cjs/auth/oauth2/client-registration.js +0 -44
  42. package/dist/cjs/auth/oauth2/device-authorization.js +0 -40
  43. package/dist/cjs/auth/oauth2/errors.js +0 -64
  44. package/dist/cjs/auth/oauth2/http-utils.js +0 -112
  45. package/dist/cjs/auth/oauth2/index.js +0 -42
  46. package/dist/cjs/auth/oauth2/loopback-receiver.js +0 -215
  47. package/dist/cjs/auth/oauth2/metadata.js +0 -34
  48. package/dist/cjs/auth/oauth2/oauth2-authentication.js +0 -74
  49. package/dist/cjs/auth/oauth2/session-manager.js +0 -762
  50. package/dist/cjs/auth/oauth2/token-store.js +0 -252
  51. package/dist/cjs/auth/oauth2/token.js +0 -76
  52. package/dist/esm/auth/authentication.js +0 -68
  53. package/dist/esm/auth/index.js +0 -3
  54. package/dist/esm/auth/oauth2/client-registration.js +0 -40
  55. package/dist/esm/auth/oauth2/device-authorization.js +0 -36
  56. package/dist/esm/auth/oauth2/errors.js +0 -59
  57. package/dist/esm/auth/oauth2/http-utils.js +0 -105
  58. package/dist/esm/auth/oauth2/index.js +0 -11
  59. package/dist/esm/auth/oauth2/loopback-receiver.js +0 -178
  60. package/dist/esm/auth/oauth2/metadata.js +0 -30
  61. package/dist/esm/auth/oauth2/oauth2-authentication.js +0 -70
  62. package/dist/esm/auth/oauth2/session-manager.js +0 -725
  63. package/dist/esm/auth/oauth2/token-store.js +0 -214
  64. package/dist/esm/auth/oauth2/token.js +0 -71
  65. package/dist/types/auth/authentication.d.ts +0 -98
  66. package/dist/types/auth/index.d.ts +0 -4
  67. package/dist/types/auth/oauth2/client-registration.d.ts +0 -32
  68. package/dist/types/auth/oauth2/device-authorization.d.ts +0 -40
  69. package/dist/types/auth/oauth2/errors.d.ts +0 -46
  70. package/dist/types/auth/oauth2/http-utils.d.ts +0 -21
  71. package/dist/types/auth/oauth2/index.d.ts +0 -16
  72. package/dist/types/auth/oauth2/loopback-receiver.d.ts +0 -29
  73. package/dist/types/auth/oauth2/metadata.d.ts +0 -32
  74. package/dist/types/auth/oauth2/oauth2-authentication.d.ts +0 -31
  75. package/dist/types/auth/oauth2/session-manager.d.ts +0 -241
  76. package/dist/types/auth/oauth2/token-store.d.ts +0 -49
  77. package/dist/types/auth/oauth2/token.d.ts +0 -56
@@ -1,241 +0,0 @@
1
- import { OAuth2DeviceAuthorization } from './device-authorization';
2
- import { OAuth2Token } from './token';
3
- import { type TokenStore } from './token-store';
4
- export declare const ENV_ISSUER = "TIGEROPEN_OAUTH2_ISSUER";
5
- /**
6
- * Production authorization server. The environment variable or constructor argument
7
- * overrides this value.
8
- */
9
- export declare const BUILTIN_ISSUER = "https://openapi-oauth2.tigerfintech.com";
10
- /** How early to refresh an access token. */
11
- export declare const DEFAULT_REFRESH_AHEAD_MILLIS: number;
12
- /** Remaining lifetime below which a token is no longer handed out. */
13
- export declare const MIN_USABLE_REMAINING_MILLIS: number;
14
- /** How long to wait for the browser callback. */
15
- export declare const DEFAULT_AUTHORIZE_TIMEOUT_SECONDS: number;
16
- /**
17
- * Fixed callback port for a manually configured clientId. Chosen to stay clear of the
18
- * default Linux ephemeral range (from 32768) and of common dev ports.
19
- */
20
- export declare const DEFAULT_MANUAL_CALLBACK_PORT = 18888;
21
- /**
22
- * Application name registered by the SDK itself. Shown on the user's authorization
23
- * page, so an entry point that registers its own client passes its own name.
24
- */
25
- export declare const CLIENT_NAME = "Tiger TypeScript SDK";
26
- /** Receives the authorization URL. The SDK does not open a browser itself. */
27
- export type AuthorizationUrlHandler = (url: string) => void | Promise<void>;
28
- /** Receives the device authorization so the caller can display it. */
29
- export type DeviceAuthorizationHandler = (device: OAuth2DeviceAuthorization) => void | Promise<void>;
30
- export interface OAuth2SessionManagerOptions {
31
- /** Authorization server; defaults to `TIGEROPEN_OAUTH2_ISSUER` or the built-in issuer */
32
- issuer?: string;
33
- /** Manually issued client ID; omit for dynamic registration */
34
- clientId?: string;
35
- /**
36
- * Loopback port; 0 selects a system-assigned port for dynamic registration. Do not
37
- * pass one in dynamic registration mode: it pins the registered redirect_uri to that
38
- * port, and later dropping the argument leaves the registration behind.
39
- */
40
- callbackPort?: number;
41
- /**
42
- * Storage root; defaults to `TIGEROPEN_HOME` or `~/.tiger/openapi`. Ignored when
43
- * `store` is provided
44
- */
45
- home?: string;
46
- /**
47
- * Persistence provider; when given, it owns its own surface and `surface` is ignored
48
- */
49
- store?: TokenStore;
50
- /**
51
- * Entry point owning the dynamic registration, e.g. `sdk-typescript`, `cli`, `mcp`.
52
- * Each surface registers its own client, so it appears separately on the user's
53
- * authorization page and can be revoked on its own. Tools built on this SDK must pass
54
- * their own value
55
- */
56
- surface?: string;
57
- /**
58
- * Application name sent with dynamic registration and shown on the user's
59
- * authorization page. A tool passing its own `surface` passes its own name too, or
60
- * the user sees the SDK's name where the tool's belongs
61
- */
62
- clientName?: string;
63
- /** Loopback callback timeout in seconds */
64
- authorizeTimeoutSeconds?: number;
65
- }
66
- /** OAuth 2.0 authorization session manager. */
67
- export declare class OAuth2SessionManager {
68
- private readonly _issuer;
69
- private readonly _callbackPort;
70
- /** Fixed for the session because it determines storage keys and registration mode. */
71
- private readonly explicitClientId;
72
- private readonly authorizeTimeoutSeconds;
73
- private readonly clientName;
74
- private readonly store;
75
- private registeredClientId;
76
- private metadata;
77
- private token;
78
- private resolvedScopes;
79
- /** In-flight refresh, so concurrent callers share one token request (single-flight). */
80
- private refreshInFlight;
81
- /** In-flight metadata discovery, so concurrent callers share one round trip. */
82
- private metadataInFlight;
83
- constructor(options?: OAuth2SessionManagerOptions);
84
- static defaultIssuer(): string;
85
- get issuer(): string;
86
- /** Currently known clientId; undefined before registration in dynamic mode. */
87
- get clientId(): string | undefined;
88
- get hasExplicitClientId(): boolean;
89
- get callbackPort(): number;
90
- /** Scopes requested by this session, space-separated. Fetches metadata. */
91
- scopes(): Promise<string>;
92
- /**
93
- * Create a default session and perform browser authorization when required.
94
- *
95
- * The callback receives the authorization URL; the SDK does not open a browser.
96
- */
97
- static loginWithDefaults(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2SessionManager>;
98
- /** Create a default session and perform device authorization when required. */
99
- static loginWithDeviceCodeDefaults(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2SessionManager>;
100
- /**
101
- * Perform browser authorization with a loopback redirect and PKCE.
102
- *
103
- * @param onAuthorizationUrl callback receiving the authorization URL
104
- */
105
- login(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2Token>;
106
- /**
107
- * Use the existing local authorization if usable, otherwise run a full loopback +
108
- * PKCE authorization.
109
- */
110
- loginIfNeeded(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2Token>;
111
- /**
112
- * Reuse local authorization or perform device authorization (RFC 8628).
113
- *
114
- * Device authorization supports environments without a local browser. Unlike loopback
115
- * authorization with PKCE, it has no redirect binding or proof that the initiating and
116
- * redeeming clients are the same party, increasing phishing risk. Loopback
117
- * authorization is preferred when a local browser is available.
118
- */
119
- loginWithDeviceCodeIfNeeded(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2Token>;
120
- /**
121
- * Perform device authorization as defined by RFC 8628.
122
- *
123
- * This flow is intended for environments without a local browser and has the security
124
- * limitations documented by {@link loginWithDeviceCodeIfNeeded}.
125
- */
126
- loginWithDeviceCode(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2Token>;
127
- /**
128
- * Revoke authorization under RFC 7009 and delete the local token.
129
- *
130
- * Dynamic client registration is retained across logout. The local token is deleted
131
- * even if server-side revocation fails.
132
- *
133
- * @returns true when server-side revocation succeeds; false when only local state is
134
- * cleared and the server credential may remain valid
135
- */
136
- logout(): Promise<boolean>;
137
- /**
138
- * Return a usable access token, refreshing near expiry.
139
- *
140
- * Throws `ReauthorizationRequired` when no authorization is available. Browser
141
- * authorization is never started implicitly.
142
- *
143
- * A refresh being due does not make the caller wait for one. While the current token
144
- * still has {@link MIN_USABLE_REMAINING_MILLIS} of life, a refresh already running
145
- * elsewhere is left to finish and the current token is returned.
146
- */
147
- getAccessToken(): Promise<string>;
148
- /** The current token, or undefined. Sends no requests and triggers no authorization. */
149
- status(): OAuth2Token | undefined;
150
- /**
151
- * Whether asking for a token now would trigger a refresh. Reads memory only.
152
- *
153
- * Exists so no other component needs a refresh-ahead window of its own.
154
- */
155
- shouldRefreshSoon(): boolean;
156
- isAuthorized(): boolean;
157
- /** Refresh because the token is close to expiry. */
158
- refresh(failedAccessToken?: string): Promise<OAuth2Token>;
159
- /**
160
- * Refresh after a 401 even when the token is not near expiry.
161
- *
162
- * @param failedAccessToken token used by the failed request; comparison with the
163
- * current token detects rotation completed elsewhere and preserves single-flight
164
- * refresh behavior
165
- */
166
- refreshAfterUnauthorized(failedAccessToken: string | undefined): Promise<OAuth2Token>;
167
- /**
168
- * Single-flight refresh: the first caller performs rotation while others await the
169
- * same promise.
170
- */
171
- private doRefresh;
172
- private refreshOnce;
173
- /**
174
- * Handle a refresh the authorization server rejected.
175
- *
176
- * Refresh tokens rotate, so the rejected value may already have been replaced by
177
- * another process sharing this store. The store is re-read before any local state is
178
- * removed, and the authorization is treated as ended only once the newest stored
179
- * credential is rejected too.
180
- */
181
- private recoverOrGiveUp;
182
- /** Exchange the given token's refresh token for a new access token and persist it. */
183
- private exchangeRefreshToken;
184
- /**
185
- * Read the stored token from disk, bypassing the in-memory copy.
186
- *
187
- * @returns the stored token, or null when there is none or it cannot be read
188
- */
189
- private reloadFromStore;
190
- /**
191
- * Remove the local token, and the dynamic registration when that was refused.
192
- *
193
- * Only the credential that was refused is removed, and only while it is still the one
194
- * on disk. Another process sharing the store may have replaced it in the meantime, and
195
- * that replacement was never refused.
196
- */
197
- private forgetRejectedAuthorization;
198
- /**
199
- * Remove a refused dynamic client registration so the next authorization registers a
200
- * new one. Explicit clientIds are left alone.
201
- */
202
- private forgetRejectedRegistration;
203
- /**
204
- * Return a reusable local token, refreshing it when required.
205
- *
206
- * @returns undefined when interactive authorization is required
207
- */
208
- private reusableToken;
209
- private currentToken;
210
- /**
211
- * The known clientId, without triggering registration. Manual mode never reads
212
- * `clients/`.
213
- */
214
- private knownClientId;
215
- private persist;
216
- private effectiveCallbackPort;
217
- private resolveScopes;
218
- private metadataOf;
219
- /** Manual clientId > saved registration whose scopes still cover > register. */
220
- private resolveClientId;
221
- /**
222
- * Register a public client under RFC 7591.
223
- *
224
- * Registration omits scope. The granted scope set is stored separately so a wider
225
- * requirement triggers re-registration instead of `invalid_scope`.
226
- */
227
- private register;
228
- private requestDeviceAuthorization;
229
- /** Poll the token endpoint according to RFC 8628 response semantics. */
230
- private pollForDeviceToken;
231
- private exchange;
232
- private toToken;
233
- /**
234
- * Attempt server-side revocation without throwing.
235
- *
236
- * The refresh token is preferred because RFC 7009 §2.1 permits revocation of its
237
- * associated access tokens. RFC 7009 §2.2 also returns success for unknown or
238
- * previously revoked tokens.
239
- */
240
- private revoke;
241
- }
@@ -1,49 +0,0 @@
1
- import { OAuth2ClientRegistration } from './client-registration';
2
- import { OAuth2Token } from './token';
3
- export declare const ENV_HOME = "TIGEROPEN_HOME";
4
- /**
5
- * Entry point owning a registration. Tools built on this SDK must pass their own value,
6
- * otherwise they would be filed as the TypeScript SDK and share its client. Keep in
7
- * step with the Java SDK's `sdk-java` and the Python SDK's `sdk-python`.
8
- */
9
- export declare const DEFAULT_SURFACE = "sdk-typescript";
10
- /** Persistence provider contract, so a caller can store tokens somewhere else. */
11
- export interface TokenStore {
12
- loadToken(clientId: string, expectedIssuer?: string): OAuth2Token | null;
13
- saveToken(token: OAuth2Token): void;
14
- deleteToken(clientId: string): string | null;
15
- loadClientId(issuer: string): string | null;
16
- loadClientRegistration(issuer: string): OAuth2ClientRegistration | null;
17
- saveClientRegistration(registration: OAuth2ClientRegistration): void;
18
- deleteClientRegistration(issuer: string): void;
19
- }
20
- export declare class OAuth2TokenStore implements TokenStore {
21
- readonly home: string;
22
- readonly surface: string;
23
- /**
24
- * @param home storage root; defaults to `TIGEROPEN_HOME` then `~/.tiger/openapi`
25
- * @param surface entry point owning the registration, e.g. `sdk-typescript`, `cli`.
26
- * Lowercase alphanumerics and hyphens only
27
- */
28
- constructor(home?: string, surface?: string);
29
- /** Load a token, treating a missing file or issuer mismatch as a cache miss. */
30
- loadToken(clientId: string, expectedIssuer?: string): OAuth2Token | null;
31
- saveToken(token: OAuth2Token): void;
32
- /**
33
- * Delete authorization state while retaining client registration.
34
- *
35
- * @returns the path removed, or null when there was nothing to remove. A clientId is
36
- * not its own file name, so a caller reporting what it deleted has to be told rather
37
- * than build the path itself
38
- */
39
- deleteToken(clientId: string): string | null;
40
- loadClientId(issuer: string): string | null;
41
- loadClientRegistration(issuer: string): OAuth2ClientRegistration | null;
42
- saveClientRegistration(registration: OAuth2ClientRegistration): void;
43
- /** Delete registration state after an `invalid_client` response. */
44
- deleteClientRegistration(issuer: string): void;
45
- private tokenFile;
46
- private clientFile;
47
- }
48
- /** Return the Java-compatible 32-character SHA-256 issuer file key. */
49
- export declare function hashIssuer(issuer: string): string;
@@ -1,56 +0,0 @@
1
- /**
2
- * Persisted OAuth 2.0 authorization state.
3
- *
4
- * The `issuer` and `clientId` bind credentials to an authorization server and client,
5
- * preventing credential reuse across environments. The on-disk field names are
6
- * snake_case and shared with the Java and Python SDKs.
7
- */
8
- /** On-disk format version. An unrecognised version is an error, not a guess. */
9
- export declare const TOKEN_SCHEMA_VERSION = 1;
10
- export declare function currentMillis(): number;
11
- /** Raw on-disk shape. */
12
- export interface OAuth2TokenJson {
13
- schema_version?: number;
14
- issuer?: string;
15
- client_id?: string;
16
- access_token?: string;
17
- refresh_token?: string;
18
- token_type?: string;
19
- scope?: string;
20
- expires_at?: number;
21
- }
22
- /** An access token and its metadata. */
23
- export declare class OAuth2Token {
24
- schemaVersion: number;
25
- issuer?: string;
26
- clientId?: string;
27
- accessToken?: string;
28
- refreshToken?: string;
29
- tokenType: string;
30
- scope?: string;
31
- /** Absolute expiry as epoch millis, not expires_in */
32
- expiresAt: number;
33
- constructor(init?: {
34
- issuer?: string;
35
- clientId?: string;
36
- accessToken?: string;
37
- refreshToken?: string;
38
- tokenType?: string;
39
- scope?: string;
40
- expiresAt?: number;
41
- schemaVersion?: number;
42
- });
43
- /** Time until expiry; negative once already expired. */
44
- remainingMillis(): number;
45
- /**
46
- * @param aheadMillis how early to refresh. The window exists because time passes
47
- * between sending a request and the server validating it, so using a token right up
48
- * to its expiry produces intermittent 401s
49
- */
50
- needsRefresh(aheadMillis: number): boolean;
51
- hasRefreshToken(): boolean;
52
- toJSON(): OAuth2TokenJson;
53
- static fromJSON(data: OAuth2TokenJson | null | undefined): OAuth2Token | null;
54
- /** Prints no token values. */
55
- toString(): string;
56
- }