@junobuild/core-standalone 2.2.1 → 3.0.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 (39) hide show
  1. package/dist/browser/index.js +28 -28
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/node/index.mjs +31 -108
  4. package/dist/node/index.mjs.map +4 -4
  5. package/dist/types/auth/providers/_auth-client.providers.d.ts +3 -12
  6. package/dist/types/auth/providers/_auth.providers.d.ts +11 -0
  7. package/dist/types/auth/providers/google.providers.d.ts +25 -0
  8. package/dist/types/auth/providers/webauthn.providers.d.ts +1 -1
  9. package/dist/types/auth/services/_auth-client.services.d.ts +17 -0
  10. package/dist/types/auth/services/identity.services.d.ts +22 -0
  11. package/dist/types/auth/services/load.services.d.ts +13 -0
  12. package/dist/types/auth/services/redirect.services.d.ts +1 -0
  13. package/dist/types/auth/services/sign-in.services.d.ts +19 -0
  14. package/dist/types/auth/services/sign-out.services.d.ts +10 -0
  15. package/dist/types/auth/services/sign-up.services.d.ts +8 -0
  16. package/dist/types/auth/services/user-webauthn.services.d.ts +1 -1
  17. package/dist/types/auth/stores/auth-client.store.d.ts +15 -0
  18. package/dist/types/auth/types/auth.d.ts +11 -12
  19. package/dist/types/auth/types/errors.d.ts +2 -0
  20. package/dist/types/auth/types/google.d.ts +50 -0
  21. package/dist/types/auth/types/provider.d.ts +42 -12
  22. package/dist/types/core/api/actor.api.d.ts +2 -2
  23. package/dist/types/core/services/{identity.services.d.ts → any-identity.services.d.ts} +1 -1
  24. package/dist/types/core/stores/_agent.factory.d.ts +1 -1
  25. package/dist/types/core/stores/actor.store.d.ts +2 -2
  26. package/dist/types/core/stores/agent.store.d.ts +1 -1
  27. package/dist/types/core/types/list.d.ts +1 -1
  28. package/dist/types/core/types/satellite.d.ts +1 -1
  29. package/dist/types/core/types/utility.d.ts +5 -3
  30. package/dist/types/core/utils/window.env.utils.d.ts +1 -0
  31. package/dist/types/functions/services/functions.services.d.ts +2 -2
  32. package/dist/types/index.d.ts +5 -3
  33. package/dist/workers/auth.worker.js +6 -6
  34. package/dist/workers/auth.worker.js.map +4 -4
  35. package/package.json +15 -16
  36. package/dist/types/auth/providers/nfid.providers.d.ts +0 -28
  37. package/dist/types/auth/services/auth.services.d.ts +0 -60
  38. package/dist/types/auth/types/nfid.d.ts +0 -22
  39. package/dist/types/auth/utils/auth.utils.d.ts +0 -3
@@ -1,16 +1,7 @@
1
- import { type AuthClient } from '@dfinity/auth-client';
1
+ import { type AuthClient } from '@icp-sdk/auth/client';
2
2
  import { type AuthClientSignInOptions } from '../types/auth-client';
3
3
  import type { Provider } from '../types/provider';
4
- /**
5
- * Common traits for all authentication providers
6
- * @interface AuthProvider
7
- */
8
- export interface AuthProvider {
9
- /**
10
- * The unique identifier of the provider.
11
- */
12
- readonly id: Provider;
13
- }
4
+ import type { AuthProvider } from './_auth.providers';
14
5
  /**
15
6
  * Options for signing in with an authentication provider.
16
7
  * @interface AuthProviderSignInOptions
@@ -26,7 +17,7 @@ export interface AuthProviderSignInOptions {
26
17
  windowOpenerFeatures?: string;
27
18
  }
28
19
  /**
29
- * Abstract base class for all authentication providers that integrate with the `@dfinity/auth-client`.
20
+ * Abstract base class for all authentication providers that integrate with the `@icp-sdk/auth/client`.
30
21
  *
31
22
  * @abstract
32
23
  * @class AuthClientProvider
@@ -0,0 +1,11 @@
1
+ import type { Provider } from '../types/provider';
2
+ /**
3
+ * Common traits for all authentication providers
4
+ * @interface AuthProvider
5
+ */
6
+ export interface AuthProvider {
7
+ /**
8
+ * The unique identifier of the provider.
9
+ */
10
+ readonly id: Provider;
11
+ }
@@ -0,0 +1,25 @@
1
+ import type { GoogleSignInRedirectOptions } from '../types/google';
2
+ import type { Provider } from '../types/provider';
3
+ import type { AuthProvider } from './_auth.providers';
4
+ export declare class GoogleProvider implements AuthProvider {
5
+ /**
6
+ * Gets the identifier of the provider.
7
+ * @returns {Provider} The identifier of the provider is google.
8
+ */
9
+ get id(): Provider;
10
+ /**
11
+ * Initiates a Google sign-in flow.
12
+ *
13
+ * Depending on the environment or configuration, this may redirect the user
14
+ * to Google's authentication screen or trigger a browser-native sign-in flow
15
+ * (such as FedCM in the future).
16
+ *
17
+ * @param {Object} params - Parameters for the sign-in request.
18
+ * @param {GoogleSignInRedirectOptions} [params.options] - Optional configuration for the sign-in request.
19
+ *
20
+ * @returns {Promise<void>} Resolves once the sign-in flow has been initiated.
21
+ */
22
+ signIn({ options }: {
23
+ options?: GoogleSignInRedirectOptions;
24
+ }): Promise<void>;
25
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Provider } from '../types/provider';
2
2
  import type { User } from '../types/user';
3
3
  import { type WebAuthnSignInOptions, type WebAuthnSignUpOptions } from '../types/webauthn';
4
- import type { AuthProvider } from './_auth-client.providers';
4
+ import type { AuthProvider } from './_auth.providers';
5
5
  export declare class WebAuthnProvider implements AuthProvider {
6
6
  #private;
7
7
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Initializes a new `AuthClient`, checks authentication state,
3
+ * and executes the provided function if already authenticated.
4
+ *
5
+ * - Always creates a fresh `AuthClient` using {@link createAuthClient}.
6
+ * - If the client is **not authenticated**, it resets the client via {@link safeCreateAuthClient}
7
+ * to ensure a clean session.
8
+ * - If authenticated, it runs the given async function `fn`.
9
+ *
10
+ * @param {Object} params
11
+ * @param {() => Promise<void>} params.fn - The asynchronous function to execute when authenticated.
12
+ *
13
+ * @returns {Promise<void>} Resolves when authentication is handled and the provided function is executed (if applicable).
14
+ */
15
+ export declare const authenticateWithAuthClient: ({ fn }: {
16
+ fn: () => Promise<void>;
17
+ }) => Promise<void>;
@@ -0,0 +1,22 @@
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
+ export declare const getIdentity: () => Identity | undefined;
3
+ /**
4
+ * Returns the identity of a signed-in user or an anonymous identity.
5
+ * This function is useful for loading an identity in web workers.
6
+ * Used to imperatively get the identity. Please be certain before using it.
7
+ * @returns {Promise<Identity>} A promise that resolves to the identity of the user or an anonymous identity.
8
+ */
9
+ export declare const unsafeIdentity: () => Promise<Identity>;
10
+ /**
11
+ * Returns the current identity if the user is authenticated.
12
+ *
13
+ * ⚠️ Use this function imperatively only. Do **not** persist the identity in global state.
14
+ * It is intended for short-lived or one-time operations.
15
+ *
16
+ * Typical use case is to enable developers to implement custom features for the Internet Computer:
17
+ * - Passing the identity to temporarily create an actor or agent to call a canister
18
+ * - Signing a message or making a one-time authenticated call
19
+ *
20
+ * @returns The authenticated identity, or null if unavailable.
21
+ */
22
+ export declare const getIdentityOnce: () => Promise<Identity | null>;
@@ -0,0 +1,13 @@
1
+ import type { User } from '../types/user';
2
+ /**
3
+ * Initialize the authClient and load the existing user.
4
+ * Executed when the library is initialized through initSatellite.
5
+ */
6
+ export declare const loadAuth: () => Promise<void>;
7
+ /**
8
+ * Initialize the authClient, load the user passed as parameter.
9
+ * Executed on sign-up.
10
+ */
11
+ export declare const loadAuthWithUser: ({ user }: {
12
+ user: User;
13
+ }) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const handleRedirectCallback: () => Promise<void>;
@@ -0,0 +1,19 @@
1
+ import type { SignInOptions } from '../types/auth';
2
+ import type { Provider } from '../types/provider';
3
+ /**
4
+ * Initialize the authClient, load or create a new user.
5
+ * Executed on sign-in.
6
+ *
7
+ * ℹ️ Exposed for testing purpose only.
8
+ */
9
+ export declare const createAuth: ({ provider }: {
10
+ provider: Provider;
11
+ }) => Promise<void>;
12
+ /**
13
+ * Signs in a user with the specified options.
14
+ *
15
+ * @default Signs in by default with Internet Identity
16
+ * @param {SignInOptions} [options] - The options for signing in including the provider to use for the process.
17
+ * @returns {Promise<void>} A promise that resolves when the sign-in process is complete and the authenticated user is initialized.
18
+ */
19
+ export declare const signIn: (options: SignInOptions) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { SignOutOptions } from '../types/auth';
2
+ /**
3
+ * Signs out the current user.
4
+ * @returns {Promise<void>} A promise that resolves when the sign-out process is complete.
5
+ */
6
+ export declare const signOut: (options?: SignOutOptions) => Promise<void>;
7
+ /**
8
+ * ℹ️ Exposed for testing purpose only. Should not be leaked to consumer or used by the library.
9
+ */
10
+ export declare const resetAuth: () => Promise<void>;
@@ -0,0 +1,8 @@
1
+ import type { SignUpOptions } from '../types/auth';
2
+ /**
3
+ * Signs up to create a new user with the specified options.
4
+ *
5
+ * @param {SignUpOptions} [options] - The options for signing up including the provider to use for the process.
6
+ * @returns {Promise<void>} A promise that resolves when the sign-up process is complete and the user is authenticated.
7
+ */
8
+ export declare const signUp: (options: SignUpOptions) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { Identity } from '@dfinity/agent';
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
2
  import type { WebAuthnIdentity, WebAuthnNewCredential } from '@junobuild/ic-client/webauthn';
3
3
  import type { Environment } from '../../core/types/env';
4
4
  import type { User } from '../types/user';
@@ -0,0 +1,15 @@
1
+ import { AuthClient } from '@icp-sdk/auth/client';
2
+ import type { DelegationChain, ECDSAKeyIdentity } from '@icp-sdk/core/identity';
3
+ export declare class AuthClientStore {
4
+ #private;
5
+ private constructor();
6
+ static getInstance(): AuthClientStore;
7
+ createAuthClient: () => Promise<AuthClient>;
8
+ safeCreateAuthClient: () => Promise<AuthClient>;
9
+ getAuthClient: () => AuthClient | undefined | null;
10
+ logout: () => Promise<void>;
11
+ setAuthClientStorage: ({ delegationChain, sessionKey }: {
12
+ delegationChain: DelegationChain;
13
+ sessionKey: ECDSAKeyIdentity;
14
+ }) => Promise<void>;
15
+ }
@@ -1,5 +1,5 @@
1
+ import type { GoogleSignInRedirectOptions } from './google';
1
2
  import type { InternetIdentitySignInOptions } from './internet-identity';
2
- import type { NFIDSignInOptions } from './nfid';
3
3
  import type { WebAuthnSignInOptions, WebAuthnSignUpOptions } from './webauthn';
4
4
  /**
5
5
  * Options for the context of the sign-in flow.
@@ -16,20 +16,19 @@ export interface SignInContext {
16
16
  windowGuard?: boolean;
17
17
  }
18
18
  /**
19
- * The options for sign-in.
19
+ * Defines which provider to use for signing in and its associated options.
20
20
  *
21
- * - `internetIdentity`: Internet Identity options
22
- * - `nfid`: NFID options
23
- * - `webauthn`: WebAuthn/Passkey options
21
+ * - `google` Google sign-in
22
+ * - `internet_identity` Internet Identity
23
+ * - `webauthn` WebAuthn/Passkeys
24
24
  */
25
25
  export type SignInOptions = {
26
- internet_identity: {
27
- options?: InternetIdentitySignInOptions;
28
- context?: SignInContext;
26
+ google: {
27
+ options?: GoogleSignInRedirectOptions;
29
28
  };
30
29
  } | {
31
- nfid: {
32
- options: NFIDSignInOptions;
30
+ internet_identity: {
31
+ options?: InternetIdentitySignInOptions;
33
32
  context?: SignInContext;
34
33
  };
35
34
  } | {
@@ -39,9 +38,9 @@ export type SignInOptions = {
39
38
  };
40
39
  };
41
40
  /**
42
- * The options for sign-up.
41
+ * Defines which provider to use for signing up and its associated options.
43
42
  *
44
- * - `webauthn`: WebAuthn/Passkey options
43
+ * - `webauthn`: WebAuthn/Passkeys
45
44
  */
46
45
  export interface SignUpOptions {
47
46
  webauthn: {
@@ -6,6 +6,8 @@ export declare class SignInUserInterruptError extends Error {
6
6
  }
7
7
  export declare class SignInProviderNotSupportedError extends Error {
8
8
  }
9
+ export declare class SignInMissingClientIdError extends Error {
10
+ }
9
11
  export declare class WebAuthnSignInRetrievePublicKeyError extends Error {
10
12
  }
11
13
  export declare class SignUpProviderNotSupportedError extends Error {
@@ -0,0 +1,50 @@
1
+ export type AuthScope = 'openid' | 'profile' | 'email';
2
+ /**
3
+ * Combination of OAuth scopes supported by Google.
4
+ *
5
+ * According to Google’s OpenID Connect documentation:
6
+ * The `scope` parameter must begin with `'openid'` and include `'profile'`, `'email'`, or both.
7
+ *
8
+ * - `'openid'` is always required.
9
+ * - `'profile'` and `'email'` are optional individually, but at least one must be included.
10
+ *
11
+ * @see https://developers.google.com/identity/openid-connect/openid-connect?utm_source=chatgpt.com#authenticationuriparameters
12
+ */
13
+ export type GoogleAuthScopes = ['openid', 'profile'] | ['openid', 'email'] | ['openid', 'profile', 'email'];
14
+ /**
15
+ * Sign-in options for the Google provider using a redirect flow.
16
+ * @interface GoogleSignInRedirectOptions
17
+ */
18
+ export interface GoogleSignInRedirectOptions {
19
+ /**
20
+ * Redirect configuration.
21
+ */
22
+ redirect?: GoogleRedirectOptions;
23
+ }
24
+ /**
25
+ * Redirect options for Google sign-in.
26
+ */
27
+ export interface GoogleRedirectOptions {
28
+ /**
29
+ * Google OAuth client ID.
30
+ * If omitted, the library attempts to read it from `juno.config`.
31
+ */
32
+ clientId?: string;
33
+ /**
34
+ * OAuth scopes to request.
35
+ * Must begin with `'openid'` and include `'profile'`, `'email'`, or both.
36
+ * @default ['openid', 'profile', 'email']
37
+ */
38
+ authScopes?: GoogleAuthScopes;
39
+ /**
40
+ * Redirect URL after authentication.
41
+ * @default window.location.origin
42
+ */
43
+ redirectUrl?: string;
44
+ /**
45
+ * Optional hint about which user is trying to sign in — usually an email address
46
+ * or a Google account ID. When provided, Google can potentially skip the account-picker
47
+ * screen or prefill the login form for a smoother sign-in experience.
48
+ */
49
+ loginHint?: string;
50
+ }
@@ -1,8 +1,12 @@
1
1
  /**
2
- * Type representing the available authentication providers.
3
- * @typedef {('internet_identity' | 'nfid' | 'webauthn')} Provider
2
+ * @deprecated The support for `nfid` provider is deprecated.
4
3
  */
5
- export type Provider = 'internet_identity' | 'nfid' | 'webauthn';
4
+ export type DeprecatedNfid = 'nfid';
5
+ /**
6
+ * Type representing the authentication providers.
7
+ * @typedef {('internet_identity' | 'nfid' | 'webauthn' | 'google')} Provider
8
+ */
9
+ export type Provider = 'internet_identity' | DeprecatedNfid | 'webauthn' | 'google';
6
10
  /**
7
11
  * Metadata for WebAuthn authentication.
8
12
  * @interface ProviderDataWebAuthn
@@ -17,16 +21,42 @@ export interface ProviderDataWebAuthn {
17
21
  aaguid: Uint8Array | number[];
18
22
  }
19
23
  /**
20
- * Container for provider-specific metadata.
21
- *
22
- * Currently only `webauthn` is supported, but this type
23
- * can be extended in the future.
24
- *
25
- * @interface ProviderData
24
+ * Metadata for OpenID (e.g. Google) authentication.
25
+ * @interface ProviderDataOpenId
26
26
  */
27
- export interface ProviderData {
27
+ export interface ProviderDataOpenId {
28
28
  /**
29
- * Metadata specific to WebAuthn (passkey) authentication.
29
+ * Email address of the authenticated user.
30
30
  */
31
- webauthn: ProviderDataWebAuthn;
31
+ email?: string;
32
+ /**
33
+ * Full name of the authenticated user.
34
+ */
35
+ name?: string;
36
+ /**
37
+ * Given name of the authenticated user.
38
+ */
39
+ givenName?: string;
40
+ /**
41
+ * Family name of the authenticated user.
42
+ */
43
+ familyName?: string;
44
+ /**
45
+ * Profile picture URL of the authenticated user.
46
+ */
47
+ picture?: string;
48
+ /**
49
+ * Locale of the authenticated user.
50
+ */
51
+ locale?: string;
32
52
  }
53
+ /**
54
+ * Container for provider-specific metadata.
55
+ *
56
+ * @typedef {({ webauthn: ProviderDataWebAuthn } | { openid: ProviderDataOpenId })} ProviderData
57
+ */
58
+ export type ProviderData = {
59
+ webauthn: ProviderDataWebAuthn;
60
+ } | {
61
+ openid: ProviderDataOpenId;
62
+ };
@@ -1,5 +1,5 @@
1
- import type { ActorMethod, ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import type { ActorMethod, ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import { type SatelliteActor } from '@junobuild/ic-client/actor';
4
4
  import type { CallOptions } from '../types/call-options';
5
5
  import type { SatelliteContext } from '../types/satellite';
@@ -1,2 +1,2 @@
1
- import { type Identity } from '@dfinity/agent';
1
+ import { type Identity } from '@icp-sdk/core/agent';
2
2
  export declare const getAnyIdentity: (identity?: Identity) => Identity;
@@ -1,4 +1,4 @@
1
- import { HttpAgent } from '@dfinity/agent';
1
+ import { HttpAgent } from '@icp-sdk/core/agent';
2
2
  import type { SatelliteContext } from '../types/satellite';
3
3
  export type CreateAgentParams = Required<Pick<SatelliteContext, 'identity'>> & Pick<SatelliteContext, 'container'>;
4
4
  export declare const createAgent: ({ identity, container }: CreateAgentParams) => Promise<HttpAgent>;
@@ -1,5 +1,5 @@
1
- import { type ActorMethod, type ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import { type ActorMethod, type ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import type { ActorKey } from '../types/actor';
4
4
  import type { SatelliteContext } from '../types/satellite';
5
5
  type ActorParams = {
@@ -1,4 +1,4 @@
1
- import type { Agent } from '@dfinity/agent';
1
+ import type { Agent } from '@icp-sdk/core/agent';
2
2
  import { type CreateAgentParams } from './_agent.factory';
3
3
  export declare class AgentStore {
4
4
  #private;
@@ -1,4 +1,4 @@
1
- import type { Principal } from '@dfinity/principal';
1
+ import type { Principal } from '@icp-sdk/core/principal';
2
2
  /**
3
3
  * Represents the results of a list call.
4
4
  * @template T - The type of items in the list.
@@ -1,4 +1,4 @@
1
- import type { Identity } from '@dfinity/agent';
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
2
  /**
3
3
  * Configuration options for connecting to a satellite.
4
4
  * @interface
@@ -1,3 +1,5 @@
1
- export type ExcludeDate<T> = {
2
- [K in keyof T]: T[K] extends Date ? never : T[K] extends object ? ExcludeDate<T[K]> : T[K];
3
- };
1
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
2
+ export type ExcludeDate<T> = T extends Date ? never : T extends (...args: any) => any ? T : T extends Primitive ? T : T extends Array<infer U> ? ExcludeDate<U>[] : T extends object ? {
3
+ [K in keyof T]: ExcludeDate<T[K]>;
4
+ } : T;
5
+ export {};
@@ -1,2 +1,3 @@
1
1
  export declare const envSatelliteId: () => string | undefined;
2
2
  export declare const envContainer: () => string | undefined;
3
+ export declare const envGoogleClientId: () => string | undefined;
@@ -1,5 +1,5 @@
1
- import type { ActorMethod, ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import type { ActorMethod, ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import type { SatelliteOptions } from '../../core/types/satellite';
4
4
  /**
5
5
  * Returns an extended satellite actor instance using the provided IDL factory and satellite options.
@@ -4,8 +4,11 @@ import type { User } from './auth/types/user';
4
4
  import type { UserEnvironment } from './core/types/env';
5
5
  import type { Unsubscribe } from './core/types/subscription';
6
6
  export * from './auth/providers/internet-identity.providers';
7
- export * from './auth/providers/nfid.providers';
8
- export { getIdentityOnce, signIn, signOut, signUp, unsafeIdentity } from './auth/services/auth.services';
7
+ export { getIdentityOnce, unsafeIdentity } from './auth/services/identity.services';
8
+ export { handleRedirectCallback } from './auth/services/redirect.services';
9
+ export { signIn } from './auth/services/sign-in.services';
10
+ export { signOut } from './auth/services/sign-out.services';
11
+ export { signUp } from './auth/services/sign-up.services';
9
12
  export type * from './auth/types/auth';
10
13
  export * from './auth/types/auth-client';
11
14
  export * from './auth/types/errors';
@@ -47,4 +50,3 @@ export declare const onAuthStateChange: (callback: (authUser: User | null) => vo
47
50
  */
48
51
  export declare const authSubscribe: (callback: (authUser: User | null) => void) => Unsubscribe;
49
52
  export { InternetIdentityConfig, InternetIdentityDomain } from './auth/types/internet-identity';
50
- export { NFIDConfig } from './auth/types/nfid';