@junobuild/core
Version:
JavaScript core client for Juno
4 lines • 135 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/index.ts", "../../src/services/auth-timout.services.ts", "../../src/stores/store.ts", "../../src/stores/auth.store.ts", "../../src/utils/events.utils.ts", "../../src/services/auth.services.ts", "../../src/constants/auth.constants.ts", "../../src/providers/auth.providers.ts", "../../src/constants/container.constants.ts", "../../src/stores/env.store.ts", "../../src/utils/window.utils.ts", "../../../utils/src/utils/did.utils.ts", "../../../utils/src/utils/env.utils.ts", "../../src/stores/actor.store.ts", "../../src/stores/agent.store.ts", "../../src/types/errors.types.ts", "../../src/utils/auth.utils.ts", "../../src/services/user.services.ts", "../../../errors/src/utils.ts", "../../../errors/src/constants/cdn.constants.ts", "../../../errors/src/constants/collections.constants.ts", "../../../errors/src/constants/satellite.constants.ts", "../../../errors/src/constants/shared.constants.ts", "../../src/api/doc.api.ts", "../../src/utils/data.utils.ts", "../../src/utils/doc.utils.ts", "../../src/utils/list.utils.ts", "../../src/api/actor.api.ts", "../../declarations/satellite/satellite.factory.did.js", "../../src/utils/env.utils.ts", "../../src/services/identity.services.ts", "../../src/services/doc.services.ts", "../../src/utils/window.env.utils.ts", "../../src/services/factory.services.ts", "../../src/services/storage.services.ts", "../../src/api/storage.api.ts", "../../../storage/src/api/storage.api.ts", "../../src/utils/crypto.utils.ts"],
"sourcesContent": ["import {assertNonNullish} from '@dfinity/utils';\nimport type {Asset, AssetEncoding, AssetKey, ENCODING_TYPE, Storage} from '@junobuild/storage';\nimport {initAuthTimeoutWorker} from './services/auth-timout.services';\nimport {initAuth} from './services/auth.services';\nimport {AuthStore} from './stores/auth.store';\nimport {EnvStore} from './stores/env.store';\nimport type {User} from './types/auth.types';\nimport type {Environment, UserEnvironment} from './types/env.types';\nimport type {Unsubscribe} from './types/subscription.types';\nimport {envContainer, envSatelliteId} from './utils/window.env.utils';\nexport * from './providers/auth.providers';\nexport {signIn, signOut, unsafeIdentity} from './services/auth.services';\nexport * from './services/doc.services';\nexport * from './services/factory.services';\nexport * from './services/storage.services';\nexport type * from './types/auth.types';\nexport type * from './types/doc.types';\nexport type * from './types/env.types';\nexport * from './types/errors.types';\nexport {ListOrder, ListPaginate, ListParams, ListResults} from './types/list.types';\nexport type * from './types/satellite.types';\nexport type * from './types/storage.types';\nexport type * from './types/subscription.types';\nexport type * from './types/utility.types';\nexport type {Asset, AssetEncoding, AssetKey, ENCODING_TYPE, Storage};\n\nconst parseEnv = (userEnv?: UserEnvironment): Environment => {\n const satelliteId = userEnv?.satelliteId ?? envSatelliteId();\n\n assertNonNullish(satelliteId, 'Satellite ID is not configured. Juno cannot be initialized.');\n\n const container = userEnv?.container ?? envContainer();\n\n return {\n satelliteId,\n internetIdentityId: userEnv?.internetIdentityId,\n workers: userEnv?.workers,\n container\n };\n};\n\n/**\n * Initializes Juno with the provided optional environment parameters.\n * If no environment is provided, the variables injected by the Vite or NextJS plugins will be used.\n * @deprecated Use {@link initSatellite} instead.\n * @param {UserEnvironment} [userEnv] - The optional user environment configuration.\n * @returns {Promise<Unsubscribe[]>} A promise that resolves to an array of unsubscribe functions.\n */\nexport const initJuno = (userEnv?: UserEnvironment): Promise<Unsubscribe[]> =>\n initSatellite(userEnv);\n\n/**\n * Initializes a Juno satellite with the provided optional environment parameters.\n * If no environment is provided, the variables injected by the Vite or NextJS plugins will be used.\n * @param {UserEnvironment} [userEnv] - The optional user environment configuration.\n * @returns {Promise<Unsubscribe[]>} A promise that resolves to an array of unsubscribe functions.\n */\nexport const initSatellite = async (userEnv?: UserEnvironment): Promise<Unsubscribe[]> => {\n const env = parseEnv(userEnv);\n\n EnvStore.getInstance().set(env);\n\n await initAuth();\n\n const authSubscribe =\n env.workers?.auth !== undefined ? initAuthTimeoutWorker(env.workers.auth) : undefined;\n\n return [...(authSubscribe ? [authSubscribe] : [])];\n};\n\n/**\n * Subscribes to authentication state changes. i.e. each time a user signs in or signs out, the callback will be triggered.\n * @param {function(User | null): void} callback - The callback function to execute when the authentication state changes.\n * @returns {Unsubscribe} A function to unsubscribe from the authentication state changes.\n */\nexport const authSubscribe = (callback: (authUser: User | null) => void): Unsubscribe =>\n AuthStore.getInstance().subscribe(callback);\n", "import {isNullish} from '@dfinity/utils';\nimport {AuthStore} from '../stores/auth.store';\nimport type {User} from '../types/auth.types';\nimport type {EnvironmentWorker} from '../types/env.types';\nimport type {PostMessage, PostMessageDataResponseAuth} from '../types/post-message';\nimport type {Unsubscribe} from '../types/subscription.types';\nimport {emit} from '../utils/events.utils';\nimport {signOut} from './auth.services';\n\nexport const initAuthTimeoutWorker = (auth: EnvironmentWorker): Unsubscribe => {\n const workerUrl = auth === true ? './workers/auth.worker.js' : auth;\n const worker = new Worker(workerUrl);\n\n const timeoutSignOut = async () => {\n emit({message: 'junoSignOutAuthTimer'});\n await signOut();\n };\n\n worker.onmessage = async ({data}: MessageEvent<PostMessage<PostMessageDataResponseAuth>>) => {\n const {msg, data: value} = data;\n\n switch (msg) {\n case 'junoSignOutAuthTimer':\n await timeoutSignOut();\n return;\n case 'junoDelegationRemainingTime':\n emit({message: 'junoDelegationRemainingTime', detail: value?.authRemainingTime});\n return;\n }\n };\n\n return AuthStore.getInstance().subscribe((user: User | null) => {\n if (isNullish(user)) {\n worker.postMessage({msg: 'junoStopAuthTimer'});\n return;\n }\n\n worker.postMessage({msg: 'junoStartAuthTimer'});\n });\n};\n", "export abstract class Store<T> {\n private callbacks: {id: symbol; callback: (data: T | null) => void}[] = [];\n\n protected populate(data: T | null) {\n this.callbacks.forEach(({callback}: {id: symbol; callback: (data: T | null) => void}) =>\n callback(data)\n );\n }\n\n subscribe(callback: (data: T | null) => void): () => void {\n const callbackId = Symbol();\n this.callbacks.push({id: callbackId, callback});\n\n return () =>\n (this.callbacks = this.callbacks.filter(\n ({id}: {id: symbol; callback: (data: T | null) => void}) => id !== callbackId\n ));\n }\n}\n", "import type {User} from '../types/auth.types';\nimport type {Unsubscribe} from '../types/subscription.types';\nimport {Store} from './store';\n\nexport class AuthStore extends Store<User | null> {\n private static instance: AuthStore;\n\n private authUser: User | null = null;\n\n private constructor() {\n super();\n }\n\n static getInstance() {\n if (!AuthStore.instance) {\n AuthStore.instance = new AuthStore();\n }\n return AuthStore.instance;\n }\n\n set(authUser: User | null) {\n this.authUser = authUser;\n\n this.populate(authUser);\n }\n\n get(): User | null {\n return this.authUser;\n }\n\n override subscribe(callback: (data: User | null) => void): Unsubscribe {\n const unsubscribe: () => void = super.subscribe(callback);\n\n callback(this.authUser);\n\n return unsubscribe;\n }\n\n reset() {\n this.authUser = null;\n\n this.populate(this.authUser);\n }\n}\n", "export const emit = <T>({message, detail}: {message: string; detail?: T | undefined}) => {\n const $event: CustomEvent<T> = new CustomEvent<T>(message, {detail, bubbles: true});\n document.dispatchEvent($event);\n};\n", "import type {Identity} from '@dfinity/agent';\nimport {type AuthClient, ERROR_USER_INTERRUPT} from '@dfinity/auth-client';\nimport {isNullish} from '@dfinity/utils';\nimport {\n ALLOW_PIN_AUTHENTICATION,\n DELEGATION_IDENTITY_EXPIRATION\n} from '../constants/auth.constants';\nimport {InternetIdentityProvider} from '../providers/auth.providers';\nimport {ActorStore} from '../stores/actor.store';\nimport {AgentStore} from '../stores/agent.store';\nimport {AuthStore} from '../stores/auth.store';\nimport type {Provider, SignInOptions} from '../types/auth.types';\nimport {SignInError, SignInInitError, SignInUserInterruptError} from '../types/errors.types';\nimport {createAuthClient} from '../utils/auth.utils';\nimport {initUser} from './user.services';\n\nlet authClient: AuthClient | undefined | null;\n\nexport const initAuth = async (provider?: Provider) => {\n authClient = authClient ?? (await createAuthClient());\n\n const isAuthenticated: boolean = (await authClient?.isAuthenticated()) ?? false;\n\n if (!isAuthenticated) {\n return;\n }\n\n const user = await initUser(provider);\n AuthStore.getInstance().set(user);\n};\n\n/**\n * Signs in a user with the specified options.\n *\n * @param {SignInOptions} [options] - The options for signing in.\n * @returns {Promise<void>} A promise that resolves when the sign-in process is complete and the authenticated user is initialized.\n * @throws {SignInError} If the sign-in process fails or no authentication client is available.\n */\nexport const signIn = (options?: SignInOptions): Promise<void> =>\n /* eslint-disable no-async-promise-executor */\n new Promise<void>(async (resolve, reject) => {\n if (isNullish(authClient)) {\n reject(\n new SignInInitError(\n 'No client is ready to perform a sign-in. Have you initialized the Satellite?'\n )\n );\n return;\n }\n\n const provider = options?.provider ?? new InternetIdentityProvider({});\n\n await authClient.login({\n onSuccess: async () => {\n await initAuth(provider.id);\n resolve();\n },\n onError: (error?: string) => {\n if (error === ERROR_USER_INTERRUPT) {\n reject(new SignInUserInterruptError(error));\n return;\n }\n\n reject(new SignInError(error));\n },\n maxTimeToLive: options?.maxTimeToLive ?? DELEGATION_IDENTITY_EXPIRATION,\n allowPinAuthentication: options?.allowPin ?? ALLOW_PIN_AUTHENTICATION,\n ...(options?.derivationOrigin !== undefined && {derivationOrigin: options.derivationOrigin}),\n ...provider.signInOptions({\n windowed: options?.windowed\n })\n });\n });\n\n/**\n * Signs out the current user.\n * @returns {Promise<void>} A promise that resolves when the sign-out process is complete.\n */\nexport const signOut = async (): Promise<void> => {\n await authClient?.logout();\n\n // Reset local object otherwise next sign in (sign in - sign out - sign in) might not work out - i.e. agent-js might not recreate the delegation or identity if not resetted\n // Technically we do not need this since we recreate the agent below. We just keep it to make the reset explicit.\n authClient = null;\n\n AuthStore.getInstance().reset();\n\n ActorStore.getInstance().reset();\n AgentStore.getInstance().reset();\n\n // Recreate an HttpClient immediately because next sign-in, if window is not reloaded, would fail if the agent is created within the process.\n // For example, Safari blocks the Internet Identity (II) window if the agent is created during the interaction.\n // Agent-js must be created either globally or at least before performing a sign-in.\n authClient = await createAuthClient();\n};\n\nexport const getIdentity = (): Identity | undefined => authClient?.getIdentity();\n\n/**\n * Returns the identity of a signed-in user or an anonymous identity.\n * This function is useful for loading an identity in web workers.\n * Used to imperatively get the identity. Please be certain before using it.\n * @returns {Promise<Identity>} A promise that resolves to the identity of the user or an anonymous identity.\n */\nexport const unsafeIdentity = async (): Promise<Identity> =>\n (authClient ?? (await createAuthClient())).getIdentity();\n", "// How long the delegation identity should remain valid?\n// e.g. BigInt(7 * 24 * 60 * 60 * 1000 * 1000 * 1000) = 7 days in nanoseconds\n// For Juno: 4 hours\nexport const DELEGATION_IDENTITY_EXPIRATION = BigInt(4 * 60 * 60 * 1000 * 1000 * 1000);\n\n// We consider PIN authentication as \"insecure\" because users can easily lose their PIN if they do not register a passphrase, especially since Safari clears the browser cache every two weeks in cases of inactivity.\n// That's why we disable it by default.\nexport const ALLOW_PIN_AUTHENTICATION = false;\n\nexport const II_POPUP: {width: number; height: number} = {width: 576, height: 576};\nexport const NFID_POPUP: {width: number; height: number} = {width: 505, height: 705};\n\nexport const INTERNET_COMPUTER_ORG = 'internetcomputer.org';\n\n// Worker\nexport const AUTH_TIMER_INTERVAL = 1000;\n", "import {isNullish, nonNullish} from '@dfinity/utils';\nimport {II_POPUP, INTERNET_COMPUTER_ORG, NFID_POPUP} from '../constants/auth.constants';\nimport {DOCKER_CONTAINER_URL, DOCKER_INTERNET_IDENTITY_ID} from '../constants/container.constants';\nimport {EnvStore} from '../stores/env.store';\nimport type {\n InternetIdentityConfig,\n InternetIdentityDomain,\n NFIDConfig,\n Provider,\n SignInOptions\n} from '../types/auth.types';\nimport {popupCenter} from '../utils/window.utils';\n\n/**\n * Options for signing in with an authentication provider.\n * @interface AuthProviderSignInOptions\n */\nexport interface AuthProviderSignInOptions {\n /**\n * The URL of the identity provider - commonly Internet Identity.\n */\n identityProvider: string;\n /**\n * Optional features for the window opener.\n */\n windowOpenerFeatures?: string;\n}\n\n/**\n * Common traits for all authentication providers\n * @interface AuthProvider\n */\nexport interface AuthProvider {\n /**\n * The unique identifier of the provider.\n */\n readonly id: Provider;\n /**\n * Method to get the sign-in options for the provider.\n * @param options - The sign-in options.\n * @returns The sign-in options for the provider that can be use to effectively perform a sign-in.\n */\n signInOptions: (options: Pick<SignInOptions, 'windowed'>) => AuthProviderSignInOptions;\n}\n\n/**\n * Internet Identity authentication provider.\n * @class InternetIdentityProvider\n * @implements {AuthProvider}\n */\nexport class InternetIdentityProvider implements AuthProvider {\n #domain?: InternetIdentityDomain;\n\n /**\n * Creates an instance of InternetIdentityProvider.\n * @param {InternetIdentityConfig} config - The configuration for Internet Identity.\n */\n constructor({domain}: InternetIdentityConfig) {\n this.#domain = domain;\n }\n\n /**\n * Gets the identifier of the provider.\n * @returns {Provider} The identifier of the provider - `internet_identity`.\n */\n get id(): Provider {\n return 'internet_identity';\n }\n\n /**\n * Gets the sign-in options for Internet Identity.\n * @param {Pick<SignInOptions, 'windowed'>} options - The sign-in options.\n * @returns {AuthProviderSignInOptions} The sign-in options for Internet Identity.\n */\n signInOptions({windowed}: Pick<SignInOptions, 'windowed'>): AuthProviderSignInOptions {\n const identityProviderUrl = (): string => {\n const container = EnvStore.getInstance().get()?.container;\n\n // Production\n if (isNullish(container) || container === false) {\n return `https://identity.${this.#domain ?? INTERNET_COMPUTER_ORG}`;\n }\n\n const env = EnvStore.getInstance().get();\n\n const internetIdentityId =\n nonNullish(env) && nonNullish(env?.internetIdentityId)\n ? env.internetIdentityId\n : DOCKER_INTERNET_IDENTITY_ID;\n\n const {host: containerHost, protocol} = new URL(\n container === true ? DOCKER_CONTAINER_URL : container\n );\n\n return /apple/i.test(navigator?.vendor)\n ? `${protocol}//${containerHost}?canisterId=${internetIdentityId}`\n : `${protocol}//${internetIdentityId}.${containerHost.replace('127.0.0.1', 'localhost')}`;\n };\n\n return {\n ...(windowed !== false && {\n windowOpenerFeatures: popupCenter(II_POPUP)\n }),\n identityProvider: identityProviderUrl()\n };\n }\n}\n\n/**\n * NFID authentication provider.\n * @class NFIDProvider\n * @implements {AuthProvider}\n */\nexport class NFIDProvider implements AuthProvider {\n #appName: string;\n #logoUrl: string;\n\n /**\n * Creates an instance of NFIDProvider.\n * @param {NFIDConfig} config - The configuration for NFID.\n */\n constructor({appName, logoUrl}: NFIDConfig) {\n this.#appName = appName;\n this.#logoUrl = logoUrl;\n }\n\n /**\n * Gets the identifier of the provider.\n * @returns {Provider} The identifier of the provider- nfid.\n */\n get id(): Provider {\n return 'nfid';\n }\n\n /**\n * Gets the sign-in options for NFID.\n * @param {Pick<SignInOptions, 'windowed'>} options - The sign-in options.\n * @returns {AuthProviderSignInOptions} The sign-in options to effectively sign-in with NFID.\n */\n signInOptions({windowed}: Pick<SignInOptions, 'windowed'>): AuthProviderSignInOptions {\n return {\n ...(windowed !== false && {\n windowOpenerFeatures: popupCenter(NFID_POPUP)\n }),\n identityProvider: `https://nfid.one/authenticate/?applicationName=${encodeURI(\n this.#appName\n )}&applicationLogo=${encodeURI(this.#logoUrl)}`\n };\n }\n}\n", "export const DOCKER_CONTAINER_URL = 'http://127.0.0.1:5987';\nexport const DOCKER_INTERNET_IDENTITY_ID = 'rdmx6-jaaaa-aaaaa-aaadq-cai';\n", "import type {Environment} from '../types/env.types';\nimport {Store} from './store';\n\nexport class EnvStore extends Store<Environment | undefined> {\n private static instance: EnvStore;\n\n private env: Environment | undefined;\n\n private constructor() {\n super();\n }\n\n static getInstance() {\n if (!EnvStore.instance) {\n EnvStore.instance = new EnvStore();\n }\n return EnvStore.instance;\n }\n\n set(env: Environment | undefined) {\n this.env = env;\n\n this.populate(env);\n }\n\n get(): Environment | undefined {\n return this.env;\n }\n\n override subscribe(callback: (data: Environment | null | undefined) => void): () => void {\n const unsubscribe: () => void = super.subscribe(callback);\n\n callback(this.env);\n\n return unsubscribe;\n }\n}\n", "import {isNullish} from '@dfinity/utils';\nimport {isBrowser} from '@junobuild/utils';\n\nexport const popupCenter = ({\n width,\n height\n}: {\n width: number;\n height: number;\n}): string | undefined => {\n if (!isBrowser()) {\n return undefined;\n }\n\n if (isNullish(window) || isNullish(window.top)) {\n return undefined;\n }\n\n const {\n top: {innerWidth, innerHeight}\n } = window;\n\n const y = innerHeight / 2 + screenY - height / 2;\n const x = innerWidth / 2 + screenX - width / 2;\n\n return `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${width}, height=${height}, top=${y}, left=${x}`;\n};\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob: Blob = new Blob([data instanceof Uint8Array ? data : new Uint8Array(data)], {\n type: 'application/json; charset=utf-8'\n });\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n", "import {Actor, type ActorSubclass} from '@dfinity/agent';\nimport type {ActorMethod} from '@dfinity/agent/lib/esm/actor';\nimport type {IDL} from '@dfinity/candid';\nimport {isNullish} from '@dfinity/utils';\nimport type {BuildType} from '../types/build.types';\nimport type {Satellite} from '../types/satellite.types';\nimport {AgentStore} from './agent.store';\n\ntype ActorParams = {\n idlFactory: IDL.InterfaceFactory;\n} & Required<Pick<Satellite, 'satelliteId' | 'identity'>> &\n Pick<Satellite, 'container'>;\n\ntype ActorRecord = Record<string, ActorMethod>;\n\nexport class ActorStore {\n private static instance: ActorStore;\n\n #actors: Record<string, ActorSubclass<ActorRecord>> | undefined | null = undefined;\n\n private constructor() {}\n\n static getInstance() {\n if (isNullish(ActorStore.instance)) {\n ActorStore.instance = new ActorStore();\n }\n return ActorStore.instance;\n }\n\n async getActor<T = ActorRecord>({\n satelliteId,\n identity,\n buildType,\n ...rest\n }: ActorParams & {buildType: BuildType}): Promise<ActorSubclass<T>> {\n const key = `${buildType}#${identity.getPrincipal().toText()}#${satelliteId};`;\n\n if (isNullish(this.#actors) || isNullish(this.#actors[key])) {\n const actor = await this.createActor({satelliteId, identity, ...rest});\n\n this.#actors = {\n ...(this.#actors ?? {}),\n [key]: actor\n };\n\n return actor as ActorSubclass<T>;\n }\n\n return this.#actors[key] as ActorSubclass<T>;\n }\n\n reset() {\n this.#actors = null;\n }\n\n private async createActor<T = ActorRecord>({\n idlFactory,\n satelliteId: canisterId,\n ...rest\n }: ActorParams): Promise<ActorSubclass<T>> {\n const agent = await AgentStore.getInstance().getAgent(rest);\n\n return Actor.createActor(idlFactory, {\n agent,\n canisterId\n });\n }\n}\n", "import {HttpAgent, type Agent} from '@dfinity/agent';\nimport {isNullish, nonNullish} from '@dfinity/utils';\nimport {DOCKER_CONTAINER_URL} from '../constants/container.constants';\nimport type {Satellite} from '../types/satellite.types';\n\ntype AgentParams = Required<Pick<Satellite, 'identity'>> & Pick<Satellite, 'container'>;\n\nexport class AgentStore {\n private static instance: AgentStore;\n\n #agents: Record<string, HttpAgent> | undefined | null = undefined;\n\n private constructor() {}\n\n static getInstance() {\n if (isNullish(AgentStore.instance)) {\n AgentStore.instance = new AgentStore();\n }\n return AgentStore.instance;\n }\n\n async getAgent({identity, ...rest}: AgentParams): Promise<Agent> {\n const key = identity.getPrincipal().toText();\n\n if (isNullish(this.#agents) || isNullish(this.#agents[key])) {\n const agent = await this.createAgent({identity, ...rest});\n\n this.#agents = {\n ...(this.#agents ?? {}),\n [key]: agent\n };\n\n return agent;\n }\n\n return this.#agents[key];\n }\n\n reset() {\n this.#agents = null;\n }\n\n private async createAgent({identity, container}: AgentParams): Promise<HttpAgent> {\n const localActor = nonNullish(container) && container !== false;\n\n const host = localActor\n ? container === true\n ? DOCKER_CONTAINER_URL\n : container\n : 'https://icp-api.io';\n\n const shouldFetchRootKey = nonNullish(container);\n\n return await HttpAgent.create({\n identity,\n shouldFetchRootKey,\n host\n });\n }\n}\n", "export class SignInError extends Error {}\nexport class SignInInitError extends Error {}\nexport class SignInUserInterruptError extends Error {}\n\nexport class InitError extends Error {}\n\nexport class ListError extends Error {}\n", "import {AuthClient} from '@dfinity/auth-client';\n\nexport const createAuthClient = (): Promise<AuthClient> =>\n AuthClient.create({\n idleOptions: {\n disableIdle: true,\n disableDefaultIdleCallback: true\n }\n });\n", "import type {Identity} from '@dfinity/agent';\nimport {isNullish, nonNullish} from '@dfinity/utils';\nimport {isSatelliteError, JUNO_DATASTORE_ERROR_USER_CANNOT_UPDATE} from '@junobuild/errors';\nimport type {Provider, User, UserData} from '../types/auth.types';\nimport {InitError} from '../types/errors.types';\nimport {getIdentity} from './auth.services';\nimport {getDoc, setDoc} from './doc.services';\n\nexport const initUser = async (provider?: Provider): Promise<User> => {\n const identity: Identity | undefined = getIdentity();\n\n if (isNullish(identity)) {\n throw new InitError('No identity to initialize the user. Have you initialized Juno?');\n }\n\n const userId = identity.getPrincipal().toText();\n\n const loadUser = (): Promise<User | undefined> =>\n getDoc<UserData>({\n collection: `#user`,\n key: userId\n });\n\n const user = await loadUser();\n\n if (nonNullish(user)) {\n return user;\n }\n\n try {\n return await createUser({userId, provider});\n } catch (error: unknown) {\n // When a user signs in for the first time and get user returns `undefined`,\n // a new user entry is created. If the browser is reloaded and get user\n // still returns `undefined`, another try is made to create user entry, which is not\n // allowed since only the controller can update users, assuming the entry has been\n // created in the meantime. To prevent errors, we reload the user data,\n // as the issue indicates the user entity exists.\n if (isSatelliteError({error, type: JUNO_DATASTORE_ERROR_USER_CANNOT_UPDATE})) {\n const userOnCreateError = await loadUser();\n\n if (nonNullish(userOnCreateError)) {\n return userOnCreateError;\n }\n }\n\n throw error;\n }\n};\n\nconst createUser = ({\n userId,\n ...rest\n}: {\n userId: string;\n} & UserData): Promise<User> =>\n setDoc<UserData>({\n collection: `#user`,\n doc: {\n key: userId,\n data: rest\n }\n });\n", "export const isSatelliteError = ({error, type}: {error: unknown; type: string}): boolean => {\n if (typeof error === 'string') {\n return error.includes(type);\n }\n\n if (error instanceof Error) {\n return error.message.includes(type);\n }\n\n return false;\n};\n", "export const JUNO_CDN_PROPOSALS_ERROR_CANNOT_SUBMIT = 'juno.cdn.proposals.error.cannot_submit';\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_SUBMIT_INVALID_STATUS =\n 'juno.cdn.proposals.error.cannot_submit_invalid_status';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_REJECT = 'juno.cdn.proposals.error.cannot_reject';\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_REJECT_INVALID_STATUS =\n 'juno.cdn.proposals.error.cannot_reject_invalid_status';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_COMMIT = 'juno.cdn.proposals.error.cannot_commit';\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_COMMIT_INVALID_STATUS =\n 'juno.cdn.proposals.error.cannot_commit_invalid_status';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_INVALID_HASH = 'juno.cdn.proposals.error.invalid_hash';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_UNKNOWN_TYPE = 'juno.cdn.proposals.error.unknown_type';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_EMPTY_CONTENT_CHUNKS =\n 'juno.cdn.proposals.error.empty_content_chunks';\nexport const JUNO_CDN_PROPOSALS_ERROR_NOT_CONTENT_CHUNKS_AT_INDEX =\n 'juno.cdn.proposals.error.no_content_chunks_at_index';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_EMPTY_ASSETS = 'juno.cdn.proposals.error.empty_assets';\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_DELETE_ASSETS =\n 'juno.cdn.proposals.error.cannot_delete_assets';\nexport const JUNO_CDN_PROPOSALS_ERROR_CANNOT_DELETE_ASSETS_INVALID_STATUS =\n 'juno.cdn.proposals.error.cannot_delete_assets_invalid_status';\n\nexport const JUNO_CDN_PROPOSALS_ERROR_NEXT_ID_CONVERT = 'juno.cdn.proposals.error.next_id_convert';\nexport const JUNO_CDN_PROPOSALS_ERROR_NEXT_ID_OVERFLOW =\n 'juno.cdn.proposals.error.next_id_overflow';\n\nexport const JUNO_CDN_STORAGE_ERROR_CANNOT_INSERT_ASSET_UNKNOWN_REFERENCE_ID =\n 'juno.cdn.storage.error.cannot_insert_asset_unknown_reference_id';\nexport const JUNO_CDN_STORAGE_ERROR_CANNOT_GET_ASSET_UNKNOWN_REFERENCE_ID =\n 'juno.cdn.storage.error.cannot_get_asset_unknown_reference_id';\nexport const JUNO_CDN_STORAGE_ERROR_CANNOT_INSERT_ASSET_ENCODING_UNKNOWN_REFERENCE_ID =\n 'juno.cdn.storage.error.cannot_insert_asset_encoding_unknown_reference_id';\n\nexport const JUNO_CDN_STORAGE_ERROR_NO_PROPOSAL_FOUND = 'juno.cdn.storage.error.no_proposal_found';\n\nexport const JUNO_CDN_STORAGE_ERROR_INVALID_RELEASES_PATH =\n 'juno.cdn.storage.error.invalid_releases_path';\n\nexport const JUNO_CDN_STORAGE_ERROR_MISSING_RELEASES_DESCRIPTION =\n 'juno.cdn.storage.error.missing_releases_description';\n\nexport const JUNO_CDN_STORAGE_ERROR_INVALID_RELEASES_DESCRIPTION =\n 'juno.cdn.storage.error.invalid_releases_description';\n\nexport const JUNO_CDN_STORAGE_ERROR_INVALID_COLLECTION =\n 'juno.cdn.storage.error.invalid_collection';\n", "export const JUNO_COLLECTIONS_ERROR_MODIFY_RESERVED_COLLECTION =\n 'juno.collections.error.modify_reserved_collection';\nexport const JUNO_COLLECTIONS_ERROR_RESERVED_NAME = 'juno.collections.error.reserved_name';\nexport const JUNO_COLLECTIONS_ERROR_RESERVED_COLLECTION =\n 'juno.collections.error.reserved_collection';\nexport const JUNO_COLLECTIONS_ERROR_RATE_CONFIG_ENABLED =\n 'juno.collections.error.rate_config_enabled';\nexport const JUNO_COLLECTIONS_ERROR_DELETE_PREFIX_RESERVED =\n 'juno.collections.error.prefix_deletion';\nexport const JUNO_COLLECTIONS_ERROR_COLLECTION_NOT_EMPTY = 'juno.collections.error.not_empty';\nexport const JUNO_COLLECTIONS_ERROR_COLLECTION_NOT_FOUND = 'juno.collections.error.not_found';\nexport const JUNO_COLLECTIONS_ERROR_PREFIX_RESERVED = 'juno.collections.error.prefix_reserved';\n", "export const JUNO_ERROR_NO_TIMESTAMP_PROVIDED = 'juno.error.no_timestamp_provided';\nexport const JUNO_ERROR_TIMESTAMP_OUTDATED_OR_FUTURE = 'juno.error.timestamp_outdated_or_future';\nexport const JUNO_ERROR_NO_VERSION_PROVIDED = 'juno.error.no_version_provided';\nexport const JUNO_ERROR_VERSION_OUTDATED_OR_FUTURE = 'juno.error.version_outdated_or_future';\n\nexport const JUNO_DATASTORE_ERROR_CANNOT_WRITE = 'juno.datastore.error.cannot_write';\nexport const JUNO_DATASTORE_ERROR_CANNOT_READ = 'juno.datastore.error.cannot_read';\n\nexport const JUNO_STORAGE_ERROR_UPLOAD_NOT_ALLOWED = 'juno.storage.error.upload_not_allowed';\nexport const JUNO_STORAGE_ERROR_SET_NOT_ALLOWED = 'juno.storage.error.set_not_allowed';\nexport const JUNO_STORAGE_ERROR_CANNOT_COMMIT_INVALID_COLLECTION =\n 'juno.storage.error.cannot_commit_invalid_collection';\nexport const JUNO_STORAGE_ERROR_CANNOT_COMMIT_BATCH = 'juno.storage.error.cannot_commit_batch';\nexport const JUNO_STORAGE_ERROR_ASSET_NOT_FOUND = 'juno.storage.error.asset_not_found';\nexport const JUNO_STORAGE_ERROR_CANNOT_READ_ASSET = 'juno.storage.error.cannot_read_asset';\nexport const JUNO_STORAGE_ERROR_UPLOAD_PATH_COLLECTION_PREFIX =\n 'juno.storage.error.upload_path_collection_prefix';\nexport const JUNO_STORAGE_ERROR_RESERVED_ASSET = 'juno.storage.error.reserved_asset';\nexport const JUNO_STORAGE_ERROR_BATCH_NOT_FOUND = 'juno.storage.error.batch_not_found';\nexport const JUNO_STORAGE_ERROR_CHUNK_NOT_FOUND = 'juno.storage.error.chunk_not_found';\nexport const JUNO_STORAGE_ERROR_CHUNK_NOT_INCLUDED_IN_BATCH =\n 'juno.storage.error.chunk_not_included_in_batch';\nexport const JUNO_STORAGE_ERROR_CHUNK_TO_COMMIT_NOT_FOUND =\n 'juno.storage.error.chunk_to_commit_not_found';\nexport const JUNO_STORAGE_ERROR_ASSET_MAX_ALLOWED_SIZE =\n 'juno.storage.error.asset_max_allowed_size';\n\nexport const JUNO_AUTH_ERROR_NOT_ADMIN_CONTROLLER = 'juno.auth.error.not_admin_controller';\nexport const JUNO_AUTH_ERROR_INVALID_ORIGIN = 'juno.auth.error.invalid_origin';\nexport const JUNO_AUTH_ERROR_NOT_WRITE_CONTROLLER = 'juno.auth.error.not_write_controller';\nexport const JUNO_AUTH_ERROR_NOT_CONTROLLER = 'juno.auth.error.not_controller';\n\nexport const JUNO_DATASTORE_ERROR_USER_CANNOT_UPDATE = 'juno.datastore.error.user.cannot_update';\nexport const JUNO_DATASTORE_ERROR_USER_INVALID_DATA = 'juno.datastore.error.user.invalid_data';\nexport const JUNO_DATASTORE_ERROR_USER_CALLER_KEY = 'juno.datastore.error.user.caller_key';\nexport const JUNO_DATASTORE_ERROR_USER_KEY_NO_PRINCIPAL =\n 'juno.datastore.error.user.key_no_principal';\nexport const JUNO_DATASTORE_ERROR_USER_NOT_ALLOWED = 'juno.datastore.error.user.not_allowed';\nexport const JUNO_DATASTORE_ERROR_USER_USAGE_CHANGE_LIMIT_REACHED =\n 'juno.datastore.error.user.usage.change_limit_reached';\nexport const JUNO_DATASTORE_ERROR_USER_USAGE_INVALID_DATA =\n 'juno.datastore.error.user.usage.invalid_data';\n", "export const JUNO_ERROR_CONTROLLERS_MAX_NUMBER = 'juno.error.controllers.max_number';\nexport const JUNO_ERROR_CONTROLLERS_ANONYMOUS_NOT_ALLOWED =\n 'juno.error.controllers.anonymous_not_allowed';\nexport const JUNO_ERROR_CONTROLLERS_REVOKED_NOT_ALLOWED =\n 'juno.error.controllers.revoked_not_allowed';\n\nexport const JUNO_ERROR_MEMORY_STABLE_EXCEEDED = 'juno.error.memory.stable_exceeded';\nexport const JUNO_ERROR_MEMORY_HEAP_EXCEEDED = 'juno.error.memory.heap_exceeded';\n\nexport const JUNO_ERROR_CYCLES_DEPOSIT_BALANCE_LOW = 'juno.error.cycles.deposit_balance_low';\nexport const JUNO_ERROR_CYCLES_DEPOSIT_FAILED = 'juno.error.cycles.deposit_failed';\n\nexport const JUNO_ERROR_CANISTER_CREATE_FAILED = 'juno.error.canister.create_failed';\nexport const JUNO_ERROR_CANISTER_INSTALL_CODE_FAILED = 'juno.error.canister.install_code_failed';\n\nexport const JUNO_ERROR_SEGMENT_STOP_FAILED = 'juno.error.segment.stop_failed';\nexport const JUNO_ERROR_SEGMENT_DELETE_FAILED = 'juno.error.segment.delete_failed';\n\nexport const JUNO_ERROR_CMC_CALL_LEDGER_FAILED = 'juno.error.cmc.call_ledger_failed';\nexport const JUNO_ERROR_CMC_LEDGER_TRANSFER_FAILED = 'juno.error.cmc.ledger_transfer_failed';\nexport const JUNO_ERROR_CMC_TOP_UP_FAILED = 'juno.error.cmc.top_up_failed';\nexport const JUNO_ERROR_CMC_CALL_CREATE_CANISTER_FAILED =\n 'juno.error.cmc.call_create_canister_failed';\nexport const JUNO_ERROR_CMC_CREATE_CANISTER_FAILED = 'juno.error.cmc.create_canister_failed';\nexport const JUNO_ERROR_CMC_INSTALL_CODE_FAILED = 'juno.error.cmc.install_code_failed';\n\nexport const JUNO_ERROR_INVALID_REGEX = 'juno.error.invalid_regex';\n", "import {fromNullable, isNullish, nonNullish} from '@dfinity/utils';\nimport type {DelDoc, SetDoc} from '../../declarations/satellite/satellite.did';\nimport type {Doc} from '../types/doc.types';\nimport type {ListParams, ListResults} from '../types/list.types';\nimport type {Satellite} from '../types/satellite.types';\nimport type {ExcludeDate} from '../types/utility.types';\nimport {mapData} from '../utils/data.utils';\nimport {fromDoc, toDelDoc, toSetDoc} from '../utils/doc.utils';\nimport {toListParams} from '../utils/list.utils';\nimport {getSatelliteActor} from './actor.api';\n\nexport const getDoc = async <D>({\n collection,\n key,\n satellite\n}: {\n collection: string;\n satellite: Satellite;\n} & Pick<Doc<D>, 'key'>): Promise<Doc<D> | undefined> => {\n const {get_doc} = await getSatelliteActor(satellite);\n\n const doc = fromNullable(await get_doc(collection, key));\n\n if (isNullish(doc)) {\n return undefined;\n }\n\n return fromDoc({doc, key});\n};\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const getManyDocs = async ({\n docs,\n satellite\n}: {\n docs: ({collection: string} & Pick<Doc<any>, 'key'>)[];\n satellite: Satellite;\n}): Promise<(Doc<any> | undefined)[]> => {\n const {get_many_docs} = await getSatelliteActor(satellite);\n\n const payload: [string, string][] = docs.map(({collection, key}) => [collection, key]);\n\n const resultsDocs = await get_many_docs(payload);\n\n const results: (Doc<any> | undefined)[] = [];\n for (const [key, resultDoc] of resultsDocs) {\n const doc = fromNullable(resultDoc);\n results.push(nonNullish(doc) ? await fromDoc({key, doc}) : undefined);\n }\n\n return results;\n};\n/* eslint-enable */\n\nexport const setDoc = async <D>({\n collection,\n doc,\n satellite\n}: {\n collection: string;\n doc: Doc<D>;\n satellite: Satellite;\n}): Promise<Doc<D>> => {\n const {set_doc} = await getSatelliteActor(satellite);\n\n const {key} = doc;\n\n const setDoc = await toSetDoc(doc);\n\n const updatedDoc = await set_doc(collection, key, setDoc);\n\n return await fromDoc({key, doc: updatedDoc});\n};\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const setManyDocs = async ({\n docs,\n satellite\n}: {\n docs: {collection: string; doc: Doc<any>}[];\n satellite: Satellite;\n}): Promise<Doc<any>[]> => {\n const {set_many_docs} = await getSatelliteActor(satellite);\n\n const payload: [string, string, SetDoc][] = [];\n for (const {collection, doc} of docs) {\n const {key} = doc;\n payload.push([collection, key, await toSetDoc(doc)]);\n }\n\n const updatedDocs = await set_many_docs(payload);\n\n const results: Doc<any>[] = [];\n for (const [key, updatedDoc] of updatedDocs) {\n results.push(await fromDoc({key, doc: updatedDoc}));\n }\n\n return results;\n};\n/* eslint-enable */\n\nexport const deleteDoc = async <D>({\n collection,\n doc,\n satellite\n}: {\n collection: string;\n doc: Doc<D>;\n satellite: Satellite;\n}): Promise<void> => {\n const {del_doc} = await getSatelliteActor(satellite);\n\n const {key} = doc;\n\n return del_doc(collection, key, toDelDoc(doc));\n};\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const deleteManyDocs = async ({\n docs,\n satellite\n}: {\n docs: {collection: string; doc: Doc<any>}[];\n satellite: Satellite;\n}): Promise<void> => {\n const {del_many_docs} = await getSatelliteActor(satellite);\n\n const payload: [string, string, DelDoc][] = docs.map(({collection, doc}) => [\n collection,\n doc.key,\n toDelDoc(doc)\n ]);\n\n await del_many_docs(payload);\n};\n/* eslint-enable */\n\nexport const deleteFilteredDocs = async ({\n collection,\n filter,\n satellite\n}: {\n collection: string;\n filter: ListParams;\n satellite: Satellite;\n}): Promise<void> => {\n const {del_filtered_docs} = await getSatelliteActor(satellite);\n\n return del_filtered_docs(collection, toListParams(filter));\n};\n\nexport const listDocs = async <D>({\n collection,\n filter,\n satellite\n}: {\n collection: string;\n filter: ListParams;\n satellite: Satellite;\n}): Promise<ListResults<Doc<D>>> => {\n const {list_docs} = await getSatelliteActor(satellite);\n\n const {items, items_page, items_length, matches_length, matches_pages} = await list_docs(\n collection,\n toListParams(filter)\n );\n\n const docs: Doc<D>[] = [];\n\n for (const [key, item] of items) {\n const {data: dataArray, owner, description, version, ...rest} = item;\n\n docs.push({\n key,\n description: fromNullable(description),\n owner: owner.toText(),\n data: await mapData<ExcludeDate<D>>({data: dataArray}),\n version: fromNullable(version),\n ...rest\n });\n }\n\n return {\n items: docs,\n items_length,\n items_page: fromNullable(items_page),\n matches_length,\n matches_pages: fromNullable(matches_pages)\n };\n};\n\nexport const countDocs = async ({\n collection,\n filter,\n satellite\n}: {\n collection: string;\n filter: ListParams;\n satellite: Satellite;\n}): Promise<bigint> => {\n const {count_docs} = await getSatelliteActor(satellite);\n\n return count_docs(collection, toListParams(filter));\n};\n", "import {fromArray} from '@junobuild/utils';\nimport type {Doc} from '../../declarations/satellite/satellite.did';\n\nexport const mapData = async <D>({data}: Pick<Doc, 'data'>): Promise<D> => {\n try {\n return await fromArray<D>(data);\n } catch (err: unknown) {\n console.error('The data parsing has failed, mapping to undefined as a fallback.', err);\n return undefined as D;\n }\n};\n", "import {fromNullable, toNullable} from '@dfinity/utils';\nimport {fromArray, toArray} from '@junobuild/utils';\nimport type {DelDoc, Doc as DocApi, SetDoc} from '../../declarations/satellite/satellite.did';\nimport type {Doc} from '../types/doc.types';\nimport type {ExcludeDate} from '../types/utility.types';\n\nexport const toSetDoc = async <D>(doc: Doc<D>): Promise<SetDoc> => {\n const {data, version, description} = doc;\n\n return {\n description: toNullable(description),\n data: await toArray<ExcludeDate<D>>(data),\n version: toNullable(version)\n };\n};\n\nexport const toDelDoc = <D>(doc: Doc<D>): DelDoc => {\n const {version} = doc;\n\n return {\n version: toNullable(version)\n };\n};\n\nexport const fromDoc = async <D>({doc, key}: {doc: DocApi; key: string}): Promise<Doc<D>> => {\n const {owner, version, description: docDescription, data, ...rest} = doc;\n\n return {\n key,\n description: fromNullable(docDescription),\n owner: owner.toText(),\n data: await fromArray<ExcludeDate<D>>(data),\n version: fromNullable(version),\n ...rest\n };\n};\n", "import {Principal} from '@dfinity/principal';\nimport {isNullish, toNullable} from '@dfinity/utils';\nimport type {\n ListParams as ListParamsApi,\n TimestampMatcher\n} from '../../declarations/satellite/satellite.did';\nimport {ListError} from '../types/errors.types';\nimport type {ListParams, ListTimestampMatcher} from '../types/list.types';\n\nconst toListMatcherTimestamp = (matcher?: ListTimestampMatcher): [] | [TimestampMatcher] => {\n if (isNullish(matcher)) {\n return toNullable();\n }\n\n switch (matcher.matcher) {\n case 'equal':\n return toNullable({Equal: matcher.timestamp});\n case 'greaterThan':\n return toNullable({GreaterThan: matcher.timestamp});\n case 'lessThan':\n return toNullable({LessThan: matcher.timestamp});\n case 'between':\n return toNullable({Between: [matcher.timestamps.start, matcher.timestamps.end]});\n default:\n throw new ListError('Invalid list matcher for timestamp', matcher);\n }\n};\n\nexport const toListParams = ({matcher, paginate, order, owner}: ListParams): ListParamsApi => ({\n matcher: isNullish(matcher)\n ? []\n : [\n {\n key: toNullable(matcher.key),\n description: toNullable(matcher.description),\n created_at: toListMatcherTimestamp(matcher.createdAt),\n updated_at: toListMatcherTimestamp(matcher.updatedAt)\n }\n ],\n paginate: toNullable(\n isNullish(paginate)\n ? undefined\n : {\n start_after: toNullable(paginate.startAfter),\n limit: toNullable(isNullish(paginate.limit) ? undefined : BigInt(paginate.limit))\n }\n ),\n order: toNullable(\n isNullish(order)\n ? undefined\n : {\n desc: order.desc,\n field:\n order.field === 'created_at'\n ? {CreatedAt: null}\n : order.field === 'updated_at'\n ? {UpdatedAt: null}\n : {Keys: null}\n }\n ),\n owner: toNullable(\n isNullish(owner) ? undefined : typeof owner === 'string' ? Principal.fromText(owner) : owner\n )\n});\n", "import type {ActorSubclass} from '@dfinity/agent';\nimport type {ActorMethod} from '@dfinity/agent/lib/esm/actor';\nimport type {IDL} from '@dfinity/candid';\nimport {assertNonNullish} from '@dfinity/utils';\nimport type {_SERVICE as SatelliteActor} from '../../declarations/satellite/satellite.did';\n// eslint-disable-next-line import/no-relative-parent-imports\nimport {idlFactory as stockIdlFactory} from '../../declarations/satellite/satellite.factory.did.js';\nimport {ActorStore} from '../stores/actor.store';\nimport type {BuildType} from '../types/build.types';\nimport type {Satellite} from '../types/satellite.types';\nimport {customOrEnvContainer, customOrEnvSatelliteId} from '../utils/env.utils';\n\nexport const getSatelliteActor = (satellite: Satellite): Promise<SatelliteActor> =>\n getActor({\n idlFactory: stockIdlFactory,\n buildType: 'stock',\n ...satellite\n });\n\nexport const getSatelliteExtendedActor = <T = Record<string, ActorMethod>>({\n idlFactory,\n ...rest\n}: Satellite & {idlFactory: IDL.InterfaceFactory}): Promise<ActorSubclass<T>> =>\n getActor({\n idlFactory,\n buildType: 'extended',\n ...rest\n });\n\nconst getActor = async <T = Record<string, ActorMethod>>({\n satelliteId: customSatelliteId,\n container: customContainer,\n ...rest\n}: Satellite & {idlFactory: IDL.InterfaceFactory; buildType: BuildType}): Promise<\n ActorSubclass<T>\n> => {\n const {satelliteId} = customOrEnvSatelliteId({satelliteId: customSatelliteId});\n\n assertNonNullish(satelliteId, 'No satellite ID defined. Did you initialize Juno?');\n\n const {container} = customOrEnvContainer({container: customContainer});\n\n return await ActorStore.getInstance().getActor({\n satelliteId,\n container,\n ...rest\n });\n};\n", "// @ts-ignore\nexport const idlFactory = ({IDL}) => {\n const CommitBatch = IDL.Record({\n batch_id: IDL.Nat,\n headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),\n chunk_ids: IDL.Vec(IDL.Nat)\n });\n const CommitProposal = IDL.Record({\n sha256: IDL.Vec(IDL.Nat8),\n proposal_id: IDL.Nat\n });\n const ListOrderField = IDL.Variant({\n UpdatedAt: IDL.Null,\n Keys: IDL.Null,\n CreatedAt: IDL.Null\n });\n const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});\n const TimestampMatcher = IDL.Variant({\n Equal: IDL.Nat64,\n Between: IDL.Tuple(IDL.Nat64, IDL.Nat64),\n GreaterThan: IDL.Nat64,\n LessThan: IDL.Nat64\n });\n const ListMatcher = IDL.Record({\n key: IDL.Opt(IDL.Text),\n updated_at: IDL.Opt(TimestampMatcher),\n description: IDL.Opt(IDL.Text),\n created_at: IDL.Opt(TimestampMatcher)\n });\n const ListPaginate = IDL.Record({\n start_after: IDL.Opt(IDL.Text),\n limit: IDL.Opt(IDL.Nat64)\n });\n const ListParams = IDL.Record({\n order: IDL.Opt(ListOrder),\n owner: IDL.Opt(IDL.Principal),\n matcher: IDL.Opt(ListMatcher),\n paginate: IDL.Opt(ListPaginate)\n });\n const DeleteControllersArgs = IDL.Record({\n controllers: IDL.Vec(IDL.Principal)\n });\n const ControllerScope = IDL.Variant({\n Write: IDL.Null,\n Admin: IDL.Null,\n Submit: IDL.Null\n });\n const Controller = IDL.Record({\n updated_at: IDL.Nat64,\n metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),\n created_at: IDL.Nat64,\n scope: ControllerScope,\n expires_at: IDL.Opt(IDL.Nat64)\n });\n const DelDoc = IDL.Record({version: IDL.Opt(IDL.Nat64)});\n const CollectionType = IDL.Variant({Db: IDL.Null, Storage: IDL.Null});\n const DelRule = IDL.Record({version: IDL.Opt(IDL.Nat64)});\n const DeleteProposalAssets = IDL.Record({\n proposal_ids: IDL.Vec(IDL.Nat)\n });\n const DepositCyclesArgs = IDL.Record({\n cycles: IDL.Nat,\n destination_id: IDL.Principal\n });\n const AssetKey = IDL.Record({\n token: IDL.Opt(IDL.Text),\n collection: IDL.Text,\n owner: IDL.Principal,\n name: IDL.Text,\n description: IDL.Opt(IDL.Text),\n full_path: IDL.Text\n });\n const AssetEncodingNoContent = IDL.Record({\n modified: IDL.Nat64,\n sha256: IDL.Vec(IDL.Nat8),\n total_length: IDL.Nat\n });\n const AssetNoContent = IDL.Record({\n key: AssetKey,\n updated_at: IDL.Nat64,\n encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),\n headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),\n created_at: IDL.Nat64,\n version: IDL.Opt(IDL.Nat64)\n });\n const AuthenticationConfigInternetIdentity = IDL.Record({\n derivation_origin: IDL.Opt(IDL.Text),\n external_alternative_origins: IDL.Opt(IDL.Vec(IDL.Text))\n });\n const AuthenticationConfig = IDL.Record({\n internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity)\n });\n const ConfigMaxMemorySize = IDL.Record({\n stable: IDL.Opt(IDL.Nat64),\n heap: IDL.Opt(IDL.Nat64)\n });\n const DbConfig = IDL.Record({\n max_memory_size: IDL.Opt(ConfigMaxMemorySize)\n });\n const StorageConfigIFrame = IDL.Variant({\n Deny: IDL.Null,\n AllowAny: IDL.Null,\n SameOrigin: IDL.Null\n });\n const StorageConfigRawAccess = IDL.Variant({\n Deny: IDL.Null,\n Allow: IDL.Null\n });\n const StorageConfigRedirect = IDL.Record({\n status_code: IDL.Nat16,\n location: IDL.Text\n });\n const StorageConfig = IDL.Record({\n iframe: IDL.Opt(StorageConfigIFrame),\n rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),\n headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))),\n max_memory_size: IDL.Opt(ConfigMaxMemorySize),\n raw_access: IDL.Opt(StorageConfigRawAccess),\n redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect)))\n });\n const Config = IDL.Record({\n db: IDL.Opt(DbConfig),\n authentication: IDL.Opt(AuthenticationCo