frameio 3.2.2 → 4.1.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.
Files changed (119) hide show
  1. package/README.md +159 -4
  2. package/dist/cjs/BaseClient.d.ts +4 -0
  3. package/dist/cjs/BaseClient.js +4 -2
  4. package/dist/cjs/api/resources/accountPermissions/client/Client.js +6 -6
  5. package/dist/cjs/api/resources/accounts/client/Client.js +13 -13
  6. package/dist/cjs/api/resources/comments/client/Client.js +48 -48
  7. package/dist/cjs/api/resources/files/client/Client.js +77 -77
  8. package/dist/cjs/api/resources/folders/client/Client.js +56 -56
  9. package/dist/cjs/api/resources/metadata/client/Client.d.ts +4 -4
  10. package/dist/cjs/api/resources/metadata/client/Client.js +18 -18
  11. package/dist/cjs/api/resources/metadata/client/requests/BulkUpdateMetadataParams.d.ts +4 -4
  12. package/dist/cjs/api/resources/metadataFields/client/Client.js +28 -28
  13. package/dist/cjs/api/resources/projectPermissions/client/Client.js +20 -20
  14. package/dist/cjs/api/resources/projects/client/Client.js +34 -34
  15. package/dist/cjs/api/resources/shares/client/Client.d.ts +4 -4
  16. package/dist/cjs/api/resources/shares/client/Client.js +72 -72
  17. package/dist/cjs/api/resources/shares/client/requests/AddAssetParams.d.ts +1 -1
  18. package/dist/cjs/api/resources/shares/client/requests/CreateShareParams.d.ts +2 -2
  19. package/dist/cjs/api/resources/shares/client/requests/UpdateShareParams.d.ts +1 -1
  20. package/dist/cjs/api/resources/users/client/Client.js +7 -7
  21. package/dist/cjs/api/resources/versionStacks/client/Client.d.ts +6 -2
  22. package/dist/cjs/api/resources/versionStacks/client/Client.js +48 -44
  23. package/dist/cjs/api/resources/versionStacks/client/requests/VersionStackCreateParams.d.ts +1 -1
  24. package/dist/cjs/api/resources/webhooks/client/Client.js +34 -34
  25. package/dist/cjs/api/resources/workspacePermissions/client/Client.js +20 -20
  26. package/dist/cjs/api/resources/workspaces/client/Client.js +34 -34
  27. package/dist/cjs/api/types/Account.d.ts +0 -2
  28. package/dist/cjs/api/types/AuditLogwithIncludes.d.ts +4 -0
  29. package/dist/cjs/api/types/AuditLogwithIncludes.js +4 -0
  30. package/dist/cjs/api/types/Filters.d.ts +4 -0
  31. package/dist/cjs/api/types/Filters.js +4 -0
  32. package/dist/cjs/index.d.ts +4 -0
  33. package/dist/cjs/index.js +21 -1
  34. package/dist/cjs/oauth/BaseAuth.d.ts +66 -0
  35. package/dist/cjs/oauth/BaseAuth.js +113 -0
  36. package/dist/cjs/oauth/NativeAppAuth.d.ts +32 -0
  37. package/dist/cjs/oauth/NativeAppAuth.js +35 -0
  38. package/dist/cjs/oauth/SPAAuth.d.ts +38 -0
  39. package/dist/cjs/oauth/SPAAuth.js +96 -0
  40. package/dist/cjs/oauth/ServerToServerAuth.d.ts +17 -0
  41. package/dist/cjs/oauth/ServerToServerAuth.js +49 -0
  42. package/dist/cjs/oauth/TokenManager.d.ts +83 -0
  43. package/dist/cjs/oauth/TokenManager.js +174 -0
  44. package/dist/cjs/oauth/WebAppAuth.d.ts +29 -0
  45. package/dist/cjs/oauth/WebAppAuth.js +88 -0
  46. package/dist/cjs/oauth/errors.d.ts +41 -0
  47. package/dist/cjs/oauth/errors.js +83 -0
  48. package/dist/cjs/oauth/http.d.ts +70 -0
  49. package/dist/cjs/oauth/http.js +280 -0
  50. package/dist/cjs/oauth/index.d.ts +34 -0
  51. package/dist/cjs/oauth/index.js +47 -0
  52. package/dist/cjs/oauth/logger.d.ts +17 -0
  53. package/dist/cjs/oauth/logger.js +18 -0
  54. package/dist/cjs/oauth/pkce.d.ts +30 -0
  55. package/dist/cjs/oauth/pkce.js +102 -0
  56. package/dist/cjs/oauth/validation.d.ts +17 -0
  57. package/dist/cjs/oauth/validation.js +55 -0
  58. package/dist/cjs/version.d.ts +1 -1
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/BaseClient.d.mts +4 -0
  61. package/dist/esm/BaseClient.mjs +4 -2
  62. package/dist/esm/api/resources/accountPermissions/client/Client.mjs +7 -7
  63. package/dist/esm/api/resources/accounts/client/Client.mjs +13 -13
  64. package/dist/esm/api/resources/comments/client/Client.mjs +49 -49
  65. package/dist/esm/api/resources/files/client/Client.mjs +78 -78
  66. package/dist/esm/api/resources/folders/client/Client.mjs +57 -57
  67. package/dist/esm/api/resources/metadata/client/Client.d.mts +4 -4
  68. package/dist/esm/api/resources/metadata/client/Client.mjs +19 -19
  69. package/dist/esm/api/resources/metadata/client/requests/BulkUpdateMetadataParams.d.mts +4 -4
  70. package/dist/esm/api/resources/metadataFields/client/Client.mjs +29 -29
  71. package/dist/esm/api/resources/projectPermissions/client/Client.mjs +21 -21
  72. package/dist/esm/api/resources/projects/client/Client.mjs +35 -35
  73. package/dist/esm/api/resources/shares/client/Client.d.mts +4 -4
  74. package/dist/esm/api/resources/shares/client/Client.mjs +73 -73
  75. package/dist/esm/api/resources/shares/client/requests/AddAssetParams.d.mts +1 -1
  76. package/dist/esm/api/resources/shares/client/requests/CreateShareParams.d.mts +2 -2
  77. package/dist/esm/api/resources/shares/client/requests/UpdateShareParams.d.mts +1 -1
  78. package/dist/esm/api/resources/users/client/Client.mjs +8 -8
  79. package/dist/esm/api/resources/versionStacks/client/Client.d.mts +6 -2
  80. package/dist/esm/api/resources/versionStacks/client/Client.mjs +49 -45
  81. package/dist/esm/api/resources/versionStacks/client/requests/VersionStackCreateParams.d.mts +1 -1
  82. package/dist/esm/api/resources/webhooks/client/Client.mjs +35 -35
  83. package/dist/esm/api/resources/workspacePermissions/client/Client.mjs +21 -21
  84. package/dist/esm/api/resources/workspaces/client/Client.mjs +35 -35
  85. package/dist/esm/api/types/Account.d.mts +0 -2
  86. package/dist/esm/api/types/AuditLogwithIncludes.d.mts +4 -0
  87. package/dist/esm/api/types/AuditLogwithIncludes.mjs +4 -0
  88. package/dist/esm/api/types/Filters.d.mts +4 -0
  89. package/dist/esm/api/types/Filters.mjs +4 -0
  90. package/dist/esm/index.d.mts +4 -0
  91. package/dist/esm/index.mjs +6 -0
  92. package/dist/esm/oauth/BaseAuth.d.mts +66 -0
  93. package/dist/esm/oauth/BaseAuth.mjs +109 -0
  94. package/dist/esm/oauth/NativeAppAuth.d.mts +32 -0
  95. package/dist/esm/oauth/NativeAppAuth.mjs +31 -0
  96. package/dist/esm/oauth/SPAAuth.d.mts +38 -0
  97. package/dist/esm/oauth/SPAAuth.mjs +92 -0
  98. package/dist/esm/oauth/ServerToServerAuth.d.mts +17 -0
  99. package/dist/esm/oauth/ServerToServerAuth.mjs +45 -0
  100. package/dist/esm/oauth/TokenManager.d.mts +83 -0
  101. package/dist/esm/oauth/TokenManager.mjs +170 -0
  102. package/dist/esm/oauth/WebAppAuth.d.mts +29 -0
  103. package/dist/esm/oauth/WebAppAuth.mjs +84 -0
  104. package/dist/esm/oauth/errors.d.mts +41 -0
  105. package/dist/esm/oauth/errors.mjs +72 -0
  106. package/dist/esm/oauth/http.d.mts +70 -0
  107. package/dist/esm/oauth/http.mjs +274 -0
  108. package/dist/esm/oauth/index.d.mts +34 -0
  109. package/dist/esm/oauth/index.mjs +30 -0
  110. package/dist/esm/oauth/logger.d.mts +17 -0
  111. package/dist/esm/oauth/logger.mjs +15 -0
  112. package/dist/esm/oauth/pkce.d.mts +30 -0
  113. package/dist/esm/oauth/pkce.mjs +98 -0
  114. package/dist/esm/oauth/validation.d.mts +17 -0
  115. package/dist/esm/oauth/validation.mjs +51 -0
  116. package/dist/esm/version.d.mts +1 -1
  117. package/dist/esm/version.mjs +1 -1
  118. package/package.json +1 -1
  119. package/reference.md +14 -10
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Server-to-Server authentication (client_credentials grant).
3
+ *
4
+ * Use for backend services and scripts with no user interaction.
5
+ */
6
+ import { BaseAuth, type BaseAuthOptions } from "./BaseAuth";
7
+ import type { TokenResponse } from "./TokenManager";
8
+ export interface ServerToServerAuthOptions extends BaseAuthOptions {
9
+ clientSecret: string;
10
+ }
11
+ export declare class ServerToServerAuth extends BaseAuth {
12
+ private readonly _scopes;
13
+ constructor(options: ServerToServerAuthOptions);
14
+ /** Explicitly fetch a new access token. */
15
+ authenticate(): Promise<TokenResponse>;
16
+ protected _refresh(): Promise<TokenResponse>;
17
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Server-to-Server authentication (client_credentials grant).
3
+ *
4
+ * Use for backend services and scripts with no user interaction.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ import { BaseAuth } from "./BaseAuth";
16
+ import { ConfigurationError } from "./errors";
17
+ import { S2S_SCOPES } from "./http";
18
+ export class ServerToServerAuth extends BaseAuth {
19
+ constructor(options) {
20
+ var _a;
21
+ if (!options.clientSecret) {
22
+ throw new ConfigurationError("clientSecret is required");
23
+ }
24
+ super(options, options.clientSecret);
25
+ this._scopes = (_a = options.scopes) !== null && _a !== void 0 ? _a : S2S_SCOPES;
26
+ }
27
+ /** Explicitly fetch a new access token. */
28
+ authenticate() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const result = yield this._refresh();
31
+ this._storeTokens(result);
32
+ return result;
33
+ });
34
+ }
35
+ _refresh() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return this._tokenRequest({
38
+ grant_type: "client_credentials",
39
+ client_id: this._clientId,
40
+ client_secret: this._clientSecret,
41
+ scope: this._scopes,
42
+ });
43
+ });
44
+ }
45
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Token lifecycle manager — the core of frameio-auth-sdk.
3
+ *
4
+ * Stores access/refresh tokens, checks expiry with a configurable buffer,
5
+ * and coordinates async-safe automatic refresh.
6
+ */
7
+ import type { Logger } from "./logger";
8
+ /** Shape returned by refresh functions and token endpoints. */
9
+ export interface TokenResponse {
10
+ access_token: string;
11
+ expires_in: number;
12
+ refresh_token?: string;
13
+ token_type?: string;
14
+ scope?: string;
15
+ }
16
+ /** Serialised token state for persistence. */
17
+ export interface ExportedTokens {
18
+ access_token: string | null;
19
+ refresh_token: string | null;
20
+ expires_at: number;
21
+ }
22
+ /** A function that performs the actual token refresh / fetch. */
23
+ export type RefreshFunction = () => Promise<TokenResponse>;
24
+ /** Optional callback fired after every successful token refresh. */
25
+ export type OnTokenRefreshed = (tokens: ExportedTokens) => void;
26
+ export interface TokenManagerOptions {
27
+ refreshFunc: RefreshFunction;
28
+ /** Seconds before actual expiry to trigger proactive refresh. Default: 60. */
29
+ refreshBuffer?: number;
30
+ /** Called after every successful refresh. */
31
+ onTokenRefreshed?: OnTokenRefreshed;
32
+ /** Logger instance for diagnostic output. */
33
+ logger?: Logger;
34
+ }
35
+ /**
36
+ * Manages token storage, expiry detection, and auto-refresh.
37
+ *
38
+ * Pass `manager.getToken` (bound) to the Frame.io SDK:
39
+ * ```ts
40
+ * const client = new FrameioClient({ token: () => auth.getToken() });
41
+ * ```
42
+ */
43
+ export declare class TokenManager {
44
+ private _refreshFunc;
45
+ private _refreshBuffer;
46
+ private _onTokenRefreshed?;
47
+ private _logger;
48
+ private _accessToken;
49
+ private _refreshToken;
50
+ private _expiresAt;
51
+ /** In-flight refresh promise for deduplication. */
52
+ private _refreshPromise;
53
+ /** Set by clear() to prevent an in-flight refresh from restoring tokens. */
54
+ private _revoked;
55
+ constructor(options: TokenManagerOptions);
56
+ /**
57
+ * Return a valid access token, refreshing if necessary.
58
+ *
59
+ * Safe to call concurrently — only one refresh request will fire.
60
+ */
61
+ getToken(): Promise<string>;
62
+ get accessToken(): string | null;
63
+ get refreshTokenValue(): string | null;
64
+ get expiresAt(): number;
65
+ get isExpired(): boolean;
66
+ /**
67
+ * Manually set token data (e.g. after initial code exchange).
68
+ */
69
+ setTokens(accessToken: string, expiresIn: number, refreshToken?: string): void;
70
+ /** Export current token state for persistence. */
71
+ exportTokens(): ExportedTokens;
72
+ /** Restore token state from a previously exported object. */
73
+ importTokens(data: ExportedTokens): void;
74
+ /** Clear all stored tokens and cancel any in-flight refresh. */
75
+ clear(): void;
76
+ private _isTokenValid;
77
+ /**
78
+ * Async-safe refresh: if a refresh is already in flight, await the
79
+ * existing promise instead of firing a second request.
80
+ */
81
+ private _doRefresh;
82
+ private _executeRefresh;
83
+ }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Token lifecycle manager — the core of frameio-auth-sdk.
3
+ *
4
+ * Stores access/refresh tokens, checks expiry with a configurable buffer,
5
+ * and coordinates async-safe automatic refresh.
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ import { AuthenticationError, NetworkError, RateLimitError, sanitizeMessage, TokenExpiredError } from "./errors";
17
+ import { noopLogger } from "./logger";
18
+ import { validateTokenImport } from "./validation";
19
+ /**
20
+ * Manages token storage, expiry detection, and auto-refresh.
21
+ *
22
+ * Pass `manager.getToken` (bound) to the Frame.io SDK:
23
+ * ```ts
24
+ * const client = new FrameioClient({ token: () => auth.getToken() });
25
+ * ```
26
+ */
27
+ export class TokenManager {
28
+ constructor(options) {
29
+ var _a, _b;
30
+ this._accessToken = null;
31
+ this._refreshToken = null;
32
+ this._expiresAt = 0;
33
+ /** In-flight refresh promise for deduplication. */
34
+ this._refreshPromise = null;
35
+ /** Set by clear() to prevent an in-flight refresh from restoring tokens. */
36
+ this._revoked = false;
37
+ this._refreshFunc = options.refreshFunc;
38
+ this._refreshBuffer = (_a = options.refreshBuffer) !== null && _a !== void 0 ? _a : 60;
39
+ this._onTokenRefreshed = options.onTokenRefreshed;
40
+ this._logger = (_b = options.logger) !== null && _b !== void 0 ? _b : noopLogger;
41
+ }
42
+ // ------------------------------------------------------------------
43
+ // Public API
44
+ // ------------------------------------------------------------------
45
+ /**
46
+ * Return a valid access token, refreshing if necessary.
47
+ *
48
+ * Safe to call concurrently — only one refresh request will fire.
49
+ */
50
+ getToken() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ if (this._isTokenValid()) {
53
+ return this._accessToken;
54
+ }
55
+ return this._doRefresh();
56
+ });
57
+ }
58
+ get accessToken() {
59
+ return this._accessToken;
60
+ }
61
+ get refreshTokenValue() {
62
+ return this._refreshToken;
63
+ }
64
+ get expiresAt() {
65
+ return this._expiresAt;
66
+ }
67
+ get isExpired() {
68
+ return !this._isTokenValid();
69
+ }
70
+ /**
71
+ * Manually set token data (e.g. after initial code exchange).
72
+ */
73
+ setTokens(accessToken, expiresIn, refreshToken) {
74
+ this._revoked = false;
75
+ this._accessToken = accessToken;
76
+ this._expiresAt = Date.now() / 1000 + expiresIn;
77
+ if (refreshToken !== undefined) {
78
+ this._refreshToken = refreshToken;
79
+ }
80
+ }
81
+ /** Export current token state for persistence. */
82
+ exportTokens() {
83
+ return {
84
+ access_token: this._accessToken,
85
+ refresh_token: this._refreshToken,
86
+ expires_at: this._expiresAt,
87
+ };
88
+ }
89
+ /** Restore token state from a previously exported object. */
90
+ importTokens(data) {
91
+ var _a;
92
+ validateTokenImport(data);
93
+ this._revoked = false;
94
+ this._accessToken = data.access_token;
95
+ this._refreshToken = data.refresh_token;
96
+ this._expiresAt = (_a = data.expires_at) !== null && _a !== void 0 ? _a : 0;
97
+ }
98
+ /** Clear all stored tokens and cancel any in-flight refresh. */
99
+ clear() {
100
+ this._accessToken = null;
101
+ this._refreshToken = null;
102
+ this._expiresAt = 0;
103
+ this._refreshPromise = null;
104
+ this._revoked = true;
105
+ }
106
+ // ------------------------------------------------------------------
107
+ // Internals
108
+ // ------------------------------------------------------------------
109
+ _isTokenValid() {
110
+ return this._accessToken !== null && Date.now() / 1000 < this._expiresAt - this._refreshBuffer;
111
+ }
112
+ /**
113
+ * Async-safe refresh: if a refresh is already in flight, await the
114
+ * existing promise instead of firing a second request.
115
+ */
116
+ _doRefresh() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ if (this._refreshPromise) {
119
+ return this._refreshPromise;
120
+ }
121
+ this._refreshPromise = this._executeRefresh();
122
+ try {
123
+ return yield this._refreshPromise;
124
+ }
125
+ finally {
126
+ this._refreshPromise = null;
127
+ }
128
+ });
129
+ }
130
+ _executeRefresh() {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ var _a;
133
+ let result;
134
+ this._logger.debug("Token refresh triggered.");
135
+ try {
136
+ result = yield this._refreshFunc();
137
+ }
138
+ catch (err) {
139
+ if (err instanceof AuthenticationError ||
140
+ err instanceof TokenExpiredError ||
141
+ err instanceof NetworkError ||
142
+ err instanceof RateLimitError) {
143
+ throw err;
144
+ }
145
+ throw new AuthenticationError("refresh_failed", sanitizeMessage(`Token refresh failed: ${err instanceof Error ? err.message : String(err)}`));
146
+ }
147
+ // If clear() was called while the refresh was in flight (e.g. via
148
+ // revoke()), do not overwrite the cleared state with new tokens.
149
+ if (this._revoked) {
150
+ throw new AuthenticationError("revoked", "Tokens were revoked during refresh.");
151
+ }
152
+ const token = result.access_token;
153
+ this._accessToken = token;
154
+ this._expiresAt = Date.now() / 1000 + ((_a = result.expires_in) !== null && _a !== void 0 ? _a : 86400);
155
+ if (result.refresh_token) {
156
+ this._refreshToken = result.refresh_token;
157
+ }
158
+ this._logger.info(`Token refreshed (length=${token.length}).`);
159
+ if (this._onTokenRefreshed) {
160
+ try {
161
+ this._onTokenRefreshed(this.exportTokens());
162
+ }
163
+ catch (err) {
164
+ this._logger.warn(`onTokenRefreshed callback raised: ${err}`);
165
+ }
166
+ }
167
+ return token;
168
+ });
169
+ }
170
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Web App authentication (authorization_code grant).
3
+ *
4
+ * Use for server-side applications that can securely store a client secret.
5
+ */
6
+ import { BaseAuth, type BaseAuthOptions } from "./BaseAuth";
7
+ import type { TokenResponse } from "./TokenManager";
8
+ export interface WebAppAuthOptions extends BaseAuthOptions {
9
+ clientSecret: string;
10
+ redirectUri: string;
11
+ }
12
+ export declare class WebAppAuth extends BaseAuth {
13
+ private readonly _redirectUri;
14
+ private readonly _scopes;
15
+ constructor(options: WebAppAuthOptions);
16
+ /**
17
+ * Build the Adobe IMS authorization URL.
18
+ *
19
+ * @param options.state - An opaque CSRF/state value.
20
+ */
21
+ getAuthorizationUrl(options: {
22
+ state: string;
23
+ }): string;
24
+ /** Exchange an authorization code for access and refresh tokens. */
25
+ exchangeCode(code: string): Promise<TokenResponse>;
26
+ /** Manually trigger a token refresh. */
27
+ refresh(): Promise<TokenResponse>;
28
+ protected _refresh(): Promise<TokenResponse>;
29
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Web App authentication (authorization_code grant).
3
+ *
4
+ * Use for server-side applications that can securely store a client secret.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ import { BaseAuth } from "./BaseAuth";
16
+ import { ConfigurationError } from "./errors";
17
+ import { DEFAULT_SCOPES } from "./http";
18
+ import { validateRedirectUriScheme } from "./validation";
19
+ export class WebAppAuth extends BaseAuth {
20
+ constructor(options) {
21
+ var _a;
22
+ if (!options.clientSecret) {
23
+ throw new ConfigurationError("clientSecret is required");
24
+ }
25
+ if (!options.redirectUri) {
26
+ throw new ConfigurationError("redirectUri is required");
27
+ }
28
+ validateRedirectUriScheme(options.redirectUri);
29
+ super(options, options.clientSecret);
30
+ this._redirectUri = options.redirectUri;
31
+ this._scopes = (_a = options.scopes) !== null && _a !== void 0 ? _a : DEFAULT_SCOPES;
32
+ }
33
+ /**
34
+ * Build the Adobe IMS authorization URL.
35
+ *
36
+ * @param options.state - An opaque CSRF/state value.
37
+ */
38
+ getAuthorizationUrl(options) {
39
+ const params = new URLSearchParams({
40
+ client_id: this._clientId,
41
+ redirect_uri: this._redirectUri,
42
+ scope: this._scopes,
43
+ response_type: "code",
44
+ state: options.state,
45
+ });
46
+ return `${this._authorizeUrl}?${params.toString()}`;
47
+ }
48
+ /** Exchange an authorization code for access and refresh tokens. */
49
+ exchangeCode(code) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const result = yield this._tokenRequest({
52
+ grant_type: "authorization_code",
53
+ client_id: this._clientId,
54
+ client_secret: this._clientSecret,
55
+ code,
56
+ redirect_uri: this._redirectUri,
57
+ });
58
+ this._storeTokens(result);
59
+ return result;
60
+ });
61
+ }
62
+ /** Manually trigger a token refresh. */
63
+ refresh() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const result = yield this._refresh();
66
+ this._storeTokens(result);
67
+ return result;
68
+ });
69
+ }
70
+ _refresh() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const refreshTok = this._tokenManager.refreshTokenValue;
73
+ if (!refreshTok) {
74
+ throw new ConfigurationError("No refresh token available. Call exchangeCode() first.");
75
+ }
76
+ return this._tokenRequest({
77
+ grant_type: "refresh_token",
78
+ client_id: this._clientId,
79
+ client_secret: this._clientSecret,
80
+ refresh_token: refreshTok,
81
+ });
82
+ });
83
+ }
84
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Custom error types for frameio-auth-sdk.
3
+ */
4
+ /**
5
+ * Strip JWT-like tokens from error messages to prevent token leakage.
6
+ *
7
+ * Redacts strings matching the JWT prefix pattern (eyJ followed by 10+
8
+ * base64url characters). This covers Adobe IMS access and refresh tokens.
9
+ */
10
+ export declare function sanitizeMessage(msg: string): string;
11
+ /** Base error for all frameio-auth-sdk errors. */
12
+ export declare class FrameioAuthError extends Error {
13
+ constructor(message: string);
14
+ }
15
+ /** Raised when token exchange or refresh fails. */
16
+ export declare class AuthenticationError extends FrameioAuthError {
17
+ readonly errorCode: string;
18
+ readonly errorDescription?: string;
19
+ constructor(errorCode: string, errorDescription?: string);
20
+ }
21
+ /** Raised when the refresh token is expired and re-authentication is required. */
22
+ export declare class TokenExpiredError extends FrameioAuthError {
23
+ constructor(message?: string);
24
+ }
25
+ /** Raised when a network request fails (timeout, connection error, etc.). */
26
+ export declare class NetworkError extends FrameioAuthError {
27
+ constructor(message?: string);
28
+ }
29
+ /** Raised when the API returns 429 Too Many Requests and retries are exhausted. */
30
+ export declare class RateLimitError extends FrameioAuthError {
31
+ readonly retryAfter: number | undefined;
32
+ constructor(retryAfter?: number);
33
+ }
34
+ /** Raised when PKCE verification fails. */
35
+ export declare class PKCEError extends FrameioAuthError {
36
+ constructor(message?: string);
37
+ }
38
+ /** Raised when required configuration is missing or invalid. */
39
+ export declare class ConfigurationError extends FrameioAuthError {
40
+ constructor(message: string);
41
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Custom error types for frameio-auth-sdk.
3
+ */
4
+ /** Pattern to detect JWT-like tokens (eyJ...) in error messages. */
5
+ const JWT_PATTERN = /eyJ[A-Za-z0-9_-]{10,}/g;
6
+ /**
7
+ * Strip JWT-like tokens from error messages to prevent token leakage.
8
+ *
9
+ * Redacts strings matching the JWT prefix pattern (eyJ followed by 10+
10
+ * base64url characters). This covers Adobe IMS access and refresh tokens.
11
+ */
12
+ export function sanitizeMessage(msg) {
13
+ return msg.replace(JWT_PATTERN, "[REDACTED]");
14
+ }
15
+ /** Base error for all frameio-auth-sdk errors. */
16
+ export class FrameioAuthError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "FrameioAuthError";
20
+ }
21
+ }
22
+ /** Raised when token exchange or refresh fails. */
23
+ export class AuthenticationError extends FrameioAuthError {
24
+ constructor(errorCode, errorDescription) {
25
+ const desc = errorDescription ? sanitizeMessage(errorDescription) : undefined;
26
+ const msg = desc ? `${errorCode} — ${desc}` : errorCode;
27
+ super(msg);
28
+ this.name = "AuthenticationError";
29
+ this.errorCode = errorCode;
30
+ this.errorDescription = desc;
31
+ }
32
+ }
33
+ /** Raised when the refresh token is expired and re-authentication is required. */
34
+ export class TokenExpiredError extends FrameioAuthError {
35
+ constructor(message = "Refresh token expired. Re-authentication required.") {
36
+ super(sanitizeMessage(message));
37
+ this.name = "TokenExpiredError";
38
+ }
39
+ }
40
+ /** Raised when a network request fails (timeout, connection error, etc.). */
41
+ export class NetworkError extends FrameioAuthError {
42
+ constructor(message = "Network request failed.") {
43
+ super(message);
44
+ this.name = "NetworkError";
45
+ }
46
+ }
47
+ /** Raised when the API returns 429 Too Many Requests and retries are exhausted. */
48
+ export class RateLimitError extends FrameioAuthError {
49
+ constructor(retryAfter) {
50
+ let msg = "Rate limited by Adobe IMS.";
51
+ if (retryAfter !== undefined) {
52
+ msg += ` Retry after ${Math.round(retryAfter)}s.`;
53
+ }
54
+ super(msg);
55
+ this.name = "RateLimitError";
56
+ this.retryAfter = retryAfter;
57
+ }
58
+ }
59
+ /** Raised when PKCE verification fails. */
60
+ export class PKCEError extends FrameioAuthError {
61
+ constructor(message = "PKCE verification failed.") {
62
+ super(message);
63
+ this.name = "PKCEError";
64
+ }
65
+ }
66
+ /** Raised when required configuration is missing or invalid. */
67
+ export class ConfigurationError extends FrameioAuthError {
68
+ constructor(message) {
69
+ super(message);
70
+ this.name = "ConfigurationError";
71
+ }
72
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Internal HTTP helper for Adobe IMS token endpoint calls.
3
+ *
4
+ * Supports configurable timeouts, retries with exponential backoff,
5
+ * rate-limit handling (429), and response validation.
6
+ *
7
+ * Allows configurable IMS base URL for staging/alternative environments,
8
+ * and optional fetch injection for proxy, TLS, and custom HTTP handling.
9
+ */
10
+ import type { Logger } from "./logger";
11
+ import type { TokenResponse } from "./TokenManager";
12
+ export declare const DEFAULT_IMS_BASE_URL = "https://ims-na1.adobelogin.com";
13
+ /**
14
+ * Build authorize, token, and revoke URLs from an IMS base URL.
15
+ *
16
+ * @throws {Error} if the base URL does not use HTTPS.
17
+ */
18
+ export declare function buildImsUrls(imsBaseUrl: string): {
19
+ authorizeUrl: string;
20
+ tokenUrl: string;
21
+ revokeUrl: string;
22
+ };
23
+ export declare const AUTHORIZE_URL: string;
24
+ export declare const TOKEN_URL: string;
25
+ export declare const REVOKE_URL: string;
26
+ export declare const DEFAULT_SCOPES = "openid email profile offline_access additional_info.roles";
27
+ export declare const S2S_SCOPES = "openid AdobeID frame.s2s.all";
28
+ export declare const DEFAULT_TIMEOUT = 30000;
29
+ export declare const DEFAULT_MAX_RETRIES = 2;
30
+ /** Options for token requests. */
31
+ export interface TokenRequestOptions {
32
+ timeout?: number;
33
+ maxRetries?: number;
34
+ logger?: Logger;
35
+ /** Token endpoint URL (for alternative IMS environments). */
36
+ tokenUrl?: string;
37
+ /** Custom fetch implementation (for proxy, TLS, etc.). */
38
+ fetch?: typeof fetch;
39
+ }
40
+ /**
41
+ * Send a POST to the Adobe IMS token endpoint.
42
+ *
43
+ * Rate-limit retries (429) are tracked separately from error retries
44
+ * (5xx / network failures), so a 429 does not consume the error retry
45
+ * budget and vice versa.
46
+ *
47
+ * @param data - Form-encoded body parameters.
48
+ * @param options - Timeout, retry, and logger options.
49
+ * @returns Parsed token response.
50
+ */
51
+ export declare function tokenRequest(data: Record<string, string>, options?: TokenRequestOptions): Promise<TokenResponse>;
52
+ /** Options for revoke requests. */
53
+ export interface RevokeRequestOptions {
54
+ timeout?: number;
55
+ logger?: Logger;
56
+ /** Revoke endpoint URL (for alternative IMS environments). */
57
+ revokeUrl?: string;
58
+ /** Custom fetch implementation (for proxy, TLS, etc.). */
59
+ fetch?: typeof fetch;
60
+ }
61
+ /**
62
+ * Revoke an access or refresh token.
63
+ *
64
+ * For confidential clients (with client_secret), credentials are sent via
65
+ * HTTP Basic Auth per RFC 7009. For public clients, the client_id is sent
66
+ * as a query parameter.
67
+ *
68
+ * This is best-effort — errors are logged but not thrown.
69
+ */
70
+ export declare function revokeRequest(token: string, clientId: string, clientSecret?: string, options?: RevokeRequestOptions): Promise<void>;