@tigeropenapi/tigeropen 0.5.5 → 0.5.7

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 (61) hide show
  1. package/README.md +27 -0
  2. package/dist/cjs/auth/authentication.js +74 -0
  3. package/dist/cjs/auth/index.js +24 -0
  4. package/dist/cjs/auth/oauth2/client-registration.js +44 -0
  5. package/dist/cjs/auth/oauth2/device-authorization.js +40 -0
  6. package/dist/cjs/auth/oauth2/errors.js +64 -0
  7. package/dist/cjs/auth/oauth2/http-utils.js +112 -0
  8. package/dist/cjs/auth/oauth2/index.js +42 -0
  9. package/dist/cjs/auth/oauth2/loopback-receiver.js +215 -0
  10. package/dist/cjs/auth/oauth2/metadata.js +34 -0
  11. package/dist/cjs/auth/oauth2/oauth2-authentication.js +74 -0
  12. package/dist/cjs/auth/oauth2/session-manager.js +762 -0
  13. package/dist/cjs/auth/oauth2/token-store.js +252 -0
  14. package/dist/cjs/auth/oauth2/token.js +76 -0
  15. package/dist/cjs/push/pb/Request.js +12 -1
  16. package/dist/cjs/push/proto-message.js +5 -1
  17. package/dist/cjs/push/push-client.js +29 -13
  18. package/dist/cjs/trade/trade-client.js +12 -3
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/esm/auth/authentication.js +68 -0
  21. package/dist/esm/auth/index.js +3 -0
  22. package/dist/esm/auth/oauth2/client-registration.js +40 -0
  23. package/dist/esm/auth/oauth2/device-authorization.js +36 -0
  24. package/dist/esm/auth/oauth2/errors.js +59 -0
  25. package/dist/esm/auth/oauth2/http-utils.js +105 -0
  26. package/dist/esm/auth/oauth2/index.js +11 -0
  27. package/dist/esm/auth/oauth2/loopback-receiver.js +178 -0
  28. package/dist/esm/auth/oauth2/metadata.js +30 -0
  29. package/dist/esm/auth/oauth2/oauth2-authentication.js +70 -0
  30. package/dist/esm/auth/oauth2/session-manager.js +725 -0
  31. package/dist/esm/auth/oauth2/token-store.js +214 -0
  32. package/dist/esm/auth/oauth2/token.js +71 -0
  33. package/dist/esm/package.json +3 -0
  34. package/dist/esm/push/pb/Request.js +12 -1
  35. package/dist/esm/push/proto-message.js +5 -1
  36. package/dist/esm/push/push-client.js +29 -13
  37. package/dist/esm/trade/trade-client.js +12 -3
  38. package/dist/esm/version.js +1 -1
  39. package/dist/types/auth/authentication.d.ts +98 -0
  40. package/dist/types/auth/index.d.ts +4 -0
  41. package/dist/types/auth/oauth2/client-registration.d.ts +32 -0
  42. package/dist/types/auth/oauth2/device-authorization.d.ts +40 -0
  43. package/dist/types/auth/oauth2/errors.d.ts +46 -0
  44. package/dist/types/auth/oauth2/http-utils.d.ts +21 -0
  45. package/dist/types/auth/oauth2/index.d.ts +16 -0
  46. package/dist/types/auth/oauth2/loopback-receiver.d.ts +29 -0
  47. package/dist/types/auth/oauth2/metadata.d.ts +32 -0
  48. package/dist/types/auth/oauth2/oauth2-authentication.d.ts +31 -0
  49. package/dist/types/auth/oauth2/session-manager.d.ts +241 -0
  50. package/dist/types/auth/oauth2/token-store.d.ts +49 -0
  51. package/dist/types/auth/oauth2/token.d.ts +56 -0
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/model/quote.d.ts +1 -0
  54. package/dist/types/model/trade-requests.d.ts +5 -0
  55. package/dist/types/push/index.d.ts +1 -1
  56. package/dist/types/push/pb/Request.d.ts +1 -0
  57. package/dist/types/push/proto-message.d.ts +4 -1
  58. package/dist/types/push/push-client.d.ts +33 -0
  59. package/dist/types/trade/trade-client.d.ts +12 -3
  60. package/dist/types/version.d.ts +1 -1
  61. package/package.json +6 -4
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * Authorization server metadata (RFC 8414).
4
+ *
5
+ * Endpoints always come from metadata, never hardcoded, so switching environments only
6
+ * means changing the issuer.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OAuth2Metadata = void 0;
10
+ class OAuth2Metadata {
11
+ constructor(init = {}) {
12
+ this.issuer = init.issuer;
13
+ this.authorizationEndpoint = init.authorizationEndpoint;
14
+ this.tokenEndpoint = init.tokenEndpoint;
15
+ this.registrationEndpoint = init.registrationEndpoint;
16
+ this.deviceAuthorizationEndpoint = init.deviceAuthorizationEndpoint;
17
+ this.revocationEndpoint = init.revocationEndpoint;
18
+ this.scopesSupported = init.scopesSupported ?? [];
19
+ }
20
+ static fromJSON(data) {
21
+ if (!data)
22
+ return null;
23
+ return new OAuth2Metadata({
24
+ issuer: data.issuer,
25
+ authorizationEndpoint: data.authorization_endpoint,
26
+ tokenEndpoint: data.token_endpoint,
27
+ registrationEndpoint: data.registration_endpoint,
28
+ deviceAuthorizationEndpoint: data.device_authorization_endpoint,
29
+ revocationEndpoint: data.revocation_endpoint,
30
+ scopesSupported: data.scopes_supported ?? [],
31
+ });
32
+ }
33
+ }
34
+ exports.OAuth2Metadata = OAuth2Metadata;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuth2Authentication = exports.BEARER_PREFIX = void 0;
4
+ /** Request authentication backed by an OAuth 2.0 session manager. */
5
+ const authentication_1 = require("../authentication");
6
+ const errors_1 = require("./errors");
7
+ exports.BEARER_PREFIX = 'Bearer ';
8
+ const UNAUTHORIZED_STATUS = 401;
9
+ /** Authenticate with an OAuth2 access token. */
10
+ class OAuth2Authentication {
11
+ constructor(sessionManager) {
12
+ if (!sessionManager) {
13
+ throw new Error('OAuth2SessionManager is required');
14
+ }
15
+ this.sessions = sessionManager;
16
+ }
17
+ get authType() {
18
+ return authentication_1.AuthenticationType.OAuth2;
19
+ }
20
+ get sessionManager() {
21
+ return this.sessions;
22
+ }
23
+ /**
24
+ * Attach a Bearer token to the request context.
25
+ *
26
+ * Near-expiry refreshes use the session manager's single-flight synchronization.
27
+ * Missing authorization rejects with `ReauthorizationRequired` without starting an
28
+ * implicit browser flow.
29
+ */
30
+ async apply(context) {
31
+ const accessToken = await this.sessions.getAccessToken();
32
+ context.authorizationHeader = exports.BEARER_PREFIX + accessToken;
33
+ return new authentication_1.AuthenticationAttempt(authentication_1.AuthenticationType.OAuth2, accessToken);
34
+ }
35
+ /**
36
+ * Process HTTP 401 responses.
37
+ *
38
+ * HTTP 403 indicates insufficient permission and cannot be resolved by refreshing a
39
+ * token with the same scope. Server errors and timeouts are not credential failures.
40
+ */
41
+ async onUnauthorized(attempt, statusCode) {
42
+ if (statusCode !== UNAUTHORIZED_STATUS) {
43
+ return authentication_1.RetryDecision.noRetry();
44
+ }
45
+ const credential = attempt?.credential;
46
+ try {
47
+ // Reuse a token already rotated elsewhere without another token request.
48
+ const refreshed = await this.sessions.refreshAfterUnauthorized(credential);
49
+ if (!refreshed || !refreshed.accessToken) {
50
+ return authentication_1.RetryDecision.noRetry();
51
+ }
52
+ if (credential !== undefined && refreshed.accessToken === credential) {
53
+ // Credential unchanged, so a retry would get the same 401.
54
+ return authentication_1.RetryDecision.noRetry();
55
+ }
56
+ return authentication_1.RetryDecision.retry(exports.BEARER_PREFIX + refreshed.accessToken);
57
+ }
58
+ catch (e) {
59
+ if (!(e instanceof errors_1.OAuth2Error)) {
60
+ // Not an OAuth2Error, so most likely a defect in the refresh path.
61
+ console.warn('[TigerOpen] oauth2 refresh after 401 error', e);
62
+ }
63
+ return authentication_1.RetryDecision.noRetry();
64
+ }
65
+ }
66
+ /**
67
+ * The session is owned by the application and may still be in use, so it is not
68
+ * closed here.
69
+ */
70
+ close() {
71
+ // Nothing to release.
72
+ }
73
+ }
74
+ exports.OAuth2Authentication = OAuth2Authentication;