@sparkvault/sdk-js 7.0.1 → 8.0.0
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/README.md +29 -0
- package/dist/config.d.ts +6 -0
- package/dist/index.d.ts +30 -0
- package/dist/products/identity/index.d.ts +24 -0
- package/dist/products/identity/types.d.ts +6 -0
- package/dist/sparkvault.cjs.js +69 -0
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +69 -0
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.esm.js
CHANGED
|
@@ -167,6 +167,7 @@ function resolveConfig(config) {
|
|
|
167
167
|
accessToken: config.accessToken,
|
|
168
168
|
getAccessToken: config.getAccessToken,
|
|
169
169
|
apiKey: config.apiKey,
|
|
170
|
+
clientId: config.clientId,
|
|
170
171
|
preloadConfig: config.preloadConfig !== false, // Default: true
|
|
171
172
|
backdropBlur: config.backdropBlur !== false, // Default: true
|
|
172
173
|
allowedDownloadHostPatterns: config.allowedDownloadHostPatterns ?? DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS,
|
|
@@ -7845,6 +7846,74 @@ class IdentityModule {
|
|
|
7845
7846
|
}
|
|
7846
7847
|
return new URL(path, this.config.portalBaseUrl).toString();
|
|
7847
7848
|
}
|
|
7849
|
+
/**
|
|
7850
|
+
* One-click sign-in through the browser's native FedCM account chooser.
|
|
7851
|
+
*
|
|
7852
|
+
* When the person is already signed into auth.sv (carrying the SSO session),
|
|
7853
|
+
* the browser surfaces a "Continue as …" prompt with no popup, redirect, or
|
|
7854
|
+
* typing. Requires a registered `clientId` in the SDK config and a browser
|
|
7855
|
+
* with FedCM support — callers should feature-detect with
|
|
7856
|
+
* `IdentityModule.isFedcmAvailable()` and fall back to `verify()` otherwise.
|
|
7857
|
+
*
|
|
7858
|
+
* @returns the verified result, or `null` when the browser has no FedCM
|
|
7859
|
+
* support (so the caller can fall back). Throws `UserCancelledError` when the
|
|
7860
|
+
* person dismisses the chooser.
|
|
7861
|
+
*
|
|
7862
|
+
* @example
|
|
7863
|
+
* const result = (await sv.products.identity.isFedcmAvailable())
|
|
7864
|
+
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.verify())
|
|
7865
|
+
* : await sv.products.identity.verify();
|
|
7866
|
+
*/
|
|
7867
|
+
async signInWithFedcm(options = {}) {
|
|
7868
|
+
if (!IdentityModule.isFedcmAvailable()) {
|
|
7869
|
+
return null;
|
|
7870
|
+
}
|
|
7871
|
+
if (!this.config.clientId) {
|
|
7872
|
+
throw new ValidationError('clientId must be set in the SDK config to use FedCM sign-in', {
|
|
7873
|
+
field: 'clientId',
|
|
7874
|
+
});
|
|
7875
|
+
}
|
|
7876
|
+
const nonce = options.nonce ?? generateState();
|
|
7877
|
+
const configURL = `${this.config.portalBaseUrl}/${this.config.accountId}/fedcm/config.json`;
|
|
7878
|
+
const request = {
|
|
7879
|
+
identity: { providers: [{ configURL, clientId: this.config.clientId, nonce }] },
|
|
7880
|
+
...(options.mediation ? { mediation: options.mediation } : {}),
|
|
7881
|
+
};
|
|
7882
|
+
let credential;
|
|
7883
|
+
try {
|
|
7884
|
+
// FedCM's `identity` provider request isn't in every TS DOM lib version, so
|
|
7885
|
+
// adapt navigator.credentials.get through our own request/credential types
|
|
7886
|
+
// (avoids naming the type-only `CredentialRequestOptions` DOM global).
|
|
7887
|
+
const getCredential = navigator.credentials.get.bind(navigator.credentials);
|
|
7888
|
+
credential = await getCredential(request);
|
|
7889
|
+
}
|
|
7890
|
+
catch (error) {
|
|
7891
|
+
// The browser rejects with an AbortError/NotAllowedError when the person
|
|
7892
|
+
// dismisses the chooser — normalize that to the SDK's cancel signal.
|
|
7893
|
+
throw new UserCancelledError(error instanceof Error ? error.message : undefined);
|
|
7894
|
+
}
|
|
7895
|
+
const token = credential?.token;
|
|
7896
|
+
if (!token) {
|
|
7897
|
+
throw new ValidationError('FedCM did not return a token');
|
|
7898
|
+
}
|
|
7899
|
+
// Same decode + issuer/expiry/alg validation every returned token goes through.
|
|
7900
|
+
const claims = this.decodeToken(token);
|
|
7901
|
+
return {
|
|
7902
|
+
token,
|
|
7903
|
+
identity: claims.identity,
|
|
7904
|
+
identityType: claims.identity_type,
|
|
7905
|
+
svid: claims.svid,
|
|
7906
|
+
sessionId: claims.session_id,
|
|
7907
|
+
};
|
|
7908
|
+
}
|
|
7909
|
+
/** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
|
|
7910
|
+
static isFedcmAvailable() {
|
|
7911
|
+
return (typeof window !== 'undefined' &&
|
|
7912
|
+
'IdentityCredential' in window &&
|
|
7913
|
+
typeof navigator !== 'undefined' &&
|
|
7914
|
+
!!navigator.credentials &&
|
|
7915
|
+
typeof navigator.credentials.get === 'function');
|
|
7916
|
+
}
|
|
7848
7917
|
/**
|
|
7849
7918
|
* Verify user identity.
|
|
7850
7919
|
*
|