@cubist-labs/cubesigner-sdk 0.4.237 → 0.4.241

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.
@@ -9,6 +9,7 @@ import type { SessionData, SessionManager, SessionMetadata } from "./session";
9
9
  import { MemorySessionManager, metadata, parseBase64SessionData } from "./session";
10
10
  import type { NewSessionResponse, ErrorResponse } from "../schema_types";
11
11
  import type { EnvInterface } from "../env";
12
+ import { mergeHeaders } from "openapi-fetch";
12
13
 
13
14
  /** CubeSigner SDK package name */
14
15
  export const NAME: string = pkg.name;
@@ -163,14 +164,16 @@ export class BaseClient extends EventEmitter<ClientEvents> {
163
164
  // If we have an activeSession, let it dictate the baseUrl. Otherwise fall back to the one set at construction
164
165
  baseUrl,
165
166
  ...opts,
166
- headers: {
167
- "User-Agent": browserUserAgent ?? `${NAME}@${VERSION}`,
168
- "X-Cubist-Ts-Sdk": `${NAME}@${VERSION}`,
169
- Origin: this.config.origin,
170
- Authorization: token,
171
- ...(this.config.headers ?? {}),
172
- ...opts.headers,
173
- },
167
+ headers: mergeHeaders(
168
+ {
169
+ "User-Agent": browserUserAgent ?? `${NAME}@${VERSION}`,
170
+ "X-Cubist-Ts-Sdk": `${NAME}@${VERSION}`,
171
+ Origin: this.config.origin,
172
+ },
173
+ authHeader(token),
174
+ this.config.headers,
175
+ opts.headers,
176
+ ),
174
177
  params: {
175
178
  ...opts.params,
176
179
  path: {
@@ -308,3 +311,13 @@ export type OmitAutoParams<O> = DeepOmit<
308
311
  params: { path: { org_id: string } };
309
312
  }
310
313
  > & { params?: { path?: Record<string, unknown> } };
314
+
315
+ /**
316
+ * Creates {@link HeadersInit} containing a single "Authorization" header with a given value.
317
+ *
318
+ * @param token The "Authorization" header value
319
+ * @returns A {@link HeadersInit} object containing a single "Authorization" header with a given value.
320
+ */
321
+ export function authHeader(token: string): HeadersInit {
322
+ return { Authorization: token };
323
+ }
package/src/client.ts CHANGED
@@ -1,19 +1,11 @@
1
1
  import { ApiClient } from "./client/api_client";
2
- import type { IdentityProof, RatchetConfig, EmailOtpResponse } from "./schema_types";
2
+ import type { EmailOtpResponse, IdentityProof, RatchetConfig } from "./schema_types";
3
3
 
4
4
  // used in doc comments
5
5
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
6
  import { AddFidoChallenge, TotpChallenge } from "./mfa";
7
7
  import { Org } from "./org";
8
- import type {
9
- CubeSignerResponse,
10
- EnvInterface,
11
- MfaReceipts,
12
- Scope,
13
- SessionData,
14
- SessionInfo,
15
- SessionManager,
16
- } from ".";
8
+ import type { MfaReceipts, SessionData, SessionInfo, SessionManager } from ".";
17
9
  import { Key } from ".";
18
10
 
19
11
  /** Options for logging in with OIDC token */
@@ -122,71 +114,45 @@ export class CubeSignerClient {
122
114
  }
123
115
 
124
116
  /**
125
- * Exchange an OIDC token for a CubeSigner session token.
126
- *
127
- * @param env The environment to log into
128
- * @param orgId The org to log into.
129
- * @param token The OIDC token to exchange
130
- * @param scopes The scopes for the new session
131
- * @param lifetimes Lifetimes of the new session.
132
- * @param mfaReceipt Optional MFA receipt(s)
133
- * @param purpose Optional session description.
134
- * @returns The session data.
117
+ * Create a new OIDC-backed session.
118
+ *
119
+ * Same as {@link ApiClient.oidcSessionCreate}, see its documentation for more details.
120
+ *
121
+ * @param args Request arguments
122
+ * @returns The new session data
135
123
  */
136
124
  static async createOidcSession(
137
- env: EnvInterface,
138
- orgId: string,
139
- token: string,
140
- scopes: Array<Scope>,
141
- lifetimes?: RatchetConfig,
142
- mfaReceipt?: MfaReceipts,
143
- purpose?: string,
144
- ): Promise<CubeSignerResponse<SessionData>> {
145
- return await ApiClient.oidcSessionCreate(
146
- env,
147
- orgId,
148
- token,
149
- scopes,
150
- lifetimes,
151
- mfaReceipt,
152
- purpose,
153
- );
125
+ ...args: Parameters<typeof ApiClient.oidcSessionCreate>
126
+ ): Promise<Awaited<ReturnType<typeof ApiClient.oidcSessionCreate>>> {
127
+ return await ApiClient.oidcSessionCreate(...args);
154
128
  }
155
129
 
156
130
  /**
157
- * Exchange an OIDC token for a proof of authentication.
131
+ * Prove an OIDC identity.
132
+ *
133
+ * Same as {@link ApiClient.identityProveOidc}, see its documentation for more details.
158
134
  *
159
- * @param env The environment to log into
160
- * @param orgId The org id in which to generate proof
161
- * @param token The oidc token
135
+ * @param args Request arguments
162
136
  * @returns Proof of authentication
163
137
  */
164
138
  static async proveOidcIdentity(
165
- env: EnvInterface,
166
- orgId: string,
167
- token: string,
139
+ ...args: Parameters<typeof ApiClient.identityProveOidc>
168
140
  ): Promise<IdentityProof> {
169
- return await ApiClient.identityProveOidc(env, orgId, token);
141
+ return await ApiClient.identityProveOidc(...args);
170
142
  }
171
143
 
172
144
  /**
173
- * Initiates login via Email OTP.
174
- * Returns an unsigned OIDC token and sends an email to the user containing the signature of that token.
175
- * The OIDC token can be reconstructed by appending the signature to the partial token like so:
145
+ * Initialize email OTP authentication.
176
146
  *
177
- * token = partial_token + signature
147
+ * Same as {@link ApiClient.initEmailOtpAuth}, see its documentation for more details.
178
148
  *
179
- * @param env The environment to use
180
- * @param orgId The org to login to
181
- * @param email The email to send the signature to
182
- * @returns The partial OIDC token that must be combined with the signature in the email
149
+ * @param args Request arguments
150
+ * @returns The partial OIDC token that must be combined with the signature in the email
183
151
  */
184
152
  static async initEmailOtpAuth(
185
- env: EnvInterface,
186
- orgId: string,
187
- email: string,
153
+ ...args: Parameters<typeof ApiClient.initEmailOtpAuth>
188
154
  ): Promise<EmailOtpResponse> {
189
- return await ApiClient.initEmailOtpAuth(env, orgId, email);
155
+ return await ApiClient.initEmailOtpAuth(...args);
190
156
  }
191
157
 
192
158
  /**
@@ -221,7 +221,7 @@ export type QueryMetricsRequest = schemas["QueryMetricsRequest"];
221
221
  export type QueryMetricsResponse = schemas["QueryMetricsResponse"];
222
222
  export type AuditLogRequest = schemas["AuditLogRequest"];
223
223
  export type AuditLogResponse = schemas["PaginatedAuditLogResponse"];
224
- export type AuditLogEntry = schemas["AuditLogEntry"];
224
+ export type { AuditLogEntry } from "./audit_log";
225
225
 
226
226
  export type DiffieHellmanRequest = schemas["DiffieHellmanRequest"];
227
227
  export type DiffieHellmanResponse = schemas["DiffieHellmanResponse"];