@junobuild/core-peer 0.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/declarations/deprecated/mission_control-0-0-4.did.d.ts +80 -0
  4. package/declarations/deprecated/mission_control-0-0-4.factory.did.js +99 -0
  5. package/declarations/deprecated/satellite-0-0-8.did.d.ts +183 -0
  6. package/declarations/deprecated/satellite-0-0-8.factory.did.js +194 -0
  7. package/declarations/deprecated/satellite-0-0-9.did.d.ts +199 -0
  8. package/declarations/deprecated/satellite-0-0-9.factory.did.js +213 -0
  9. package/declarations/satellite/index.d.ts +45 -0
  10. package/declarations/satellite/index.js +37 -0
  11. package/declarations/satellite/satellite.did.d.ts +207 -0
  12. package/declarations/satellite/satellite.factory.did.js +221 -0
  13. package/declarations/satellite/satellite.factory.did.mjs +221 -0
  14. package/dist/browser/index.js +2 -0
  15. package/dist/browser/index.js.map +7 -0
  16. package/dist/declarations/deprecated/mission_control-0-0-4.did.d.ts +80 -0
  17. package/dist/declarations/deprecated/mission_control-0-0-4.factory.did.js +99 -0
  18. package/dist/declarations/deprecated/satellite-0-0-8.did.d.ts +183 -0
  19. package/dist/declarations/deprecated/satellite-0-0-8.factory.did.js +194 -0
  20. package/dist/declarations/deprecated/satellite-0-0-9.did.d.ts +199 -0
  21. package/dist/declarations/deprecated/satellite-0-0-9.factory.did.js +213 -0
  22. package/dist/declarations/satellite/index.d.ts +45 -0
  23. package/dist/declarations/satellite/index.js +37 -0
  24. package/dist/declarations/satellite/satellite.did.d.ts +207 -0
  25. package/dist/declarations/satellite/satellite.factory.did.js +221 -0
  26. package/dist/declarations/satellite/satellite.factory.did.mjs +221 -0
  27. package/dist/index.js +1 -0
  28. package/dist/node/index.mjs +4 -0
  29. package/dist/node/index.mjs.map +7 -0
  30. package/dist/types/api/actor.api.d.ts +3 -0
  31. package/dist/types/api/doc.api.d.ts +22 -0
  32. package/dist/types/api/storage.api.d.ts +20 -0
  33. package/dist/types/constants/auth.constants.d.ts +11 -0
  34. package/dist/types/index.d.ts +16 -0
  35. package/dist/types/providers/auth.providers.d.ts +31 -0
  36. package/dist/types/services/auth-timout.services.d.ts +3 -0
  37. package/dist/types/services/auth.services.d.ts +11 -0
  38. package/dist/types/services/doc.services.d.ts +22 -0
  39. package/dist/types/services/identity.services.d.ts +2 -0
  40. package/dist/types/services/storage.services.d.ts +24 -0
  41. package/dist/types/services/user.services.d.ts +2 -0
  42. package/dist/types/stores/auth.store.d.ts +13 -0
  43. package/dist/types/stores/env.store.d.ts +12 -0
  44. package/dist/types/stores/store.d.ts +5 -0
  45. package/dist/types/types/auth.types.d.ts +13 -0
  46. package/dist/types/types/doc.types.d.ts +8 -0
  47. package/dist/types/types/env.types.d.ts +10 -0
  48. package/dist/types/types/list.types.d.ts +28 -0
  49. package/dist/types/types/post-message.d.ts +5 -0
  50. package/dist/types/types/satellite.types.d.ts +8 -0
  51. package/dist/types/types/storage.types.d.ts +35 -0
  52. package/dist/types/types/subscription.types.d.ts +1 -0
  53. package/dist/types/utils/actor.utils.d.ts +6 -0
  54. package/dist/types/utils/auth.utils.d.ts +2 -0
  55. package/dist/types/utils/crypto.utils.d.ts +1 -0
  56. package/dist/types/utils/data.utils.d.ts +2 -0
  57. package/dist/types/utils/env.utils.d.ts +1 -0
  58. package/dist/types/utils/events.utils.d.ts +4 -0
  59. package/dist/types/utils/list.utils.d.ts +3 -0
  60. package/dist/types/utils/storage.utils.d.ts +1 -0
  61. package/dist/types/utils/window.utils.d.ts +4 -0
  62. package/dist/types/workers/auth.worker.d.ts +6 -0
  63. package/dist/workers/auth.worker.js +25 -0
  64. package/dist/workers/auth.worker.js.gz +0 -0
  65. package/dist/workers/auth.worker.js.map +7 -0
  66. package/package.json +66 -0
@@ -0,0 +1,22 @@
1
+ import type { Doc } from '../types/doc.types';
2
+ import type { ListParams, ListResults } from '../types/list.types';
3
+ import type { Satellite } from '../types/satellite.types';
4
+ export declare const getDoc: <D>({ collection, key, satellite }: {
5
+ collection: string;
6
+ satellite: Satellite;
7
+ } & Pick<Doc<D>, "key">) => Promise<Doc<D> | undefined>;
8
+ export declare const setDoc: <D>({ collection, doc, satellite }: {
9
+ collection: string;
10
+ doc: Doc<D>;
11
+ satellite: Satellite;
12
+ }) => Promise<Doc<D>>;
13
+ export declare const deleteDoc: <D>({ collection, doc, satellite }: {
14
+ collection: string;
15
+ doc: Doc<D>;
16
+ satellite: Satellite;
17
+ }) => Promise<void>;
18
+ export declare const listDocs: <D>({ collection, filter, satellite }: {
19
+ collection: string;
20
+ filter: ListParams;
21
+ satellite: Satellite;
22
+ }) => Promise<ListResults<Doc<D>>>;
@@ -0,0 +1,20 @@
1
+ import type { AssetNoContent } from '../../declarations/satellite/satellite.did';
2
+ import type { ListParams, ListResults } from '../types/list.types';
3
+ import type { Satellite } from '../types/satellite.types';
4
+ import type { AssetKey, Storage } from '../types/storage.types';
5
+ export declare const uploadAsset: ({ data, filename, collection, headers, token, fullPath, encoding, description, satellite }: Required<Omit<Storage, "description" | "token" | "encoding">> & Pick<Storage, "description" | "token" | "encoding"> & {
6
+ satellite: Satellite;
7
+ }) => Promise<void>;
8
+ export declare const listAssets: ({ collection, satellite, filter }: {
9
+ collection: string;
10
+ satellite: Satellite;
11
+ filter: ListParams;
12
+ }) => Promise<ListResults<AssetNoContent>>;
13
+ export declare const deleteAsset: ({ collection, fullPath, satellite }: {
14
+ collection: string;
15
+ satellite: Satellite;
16
+ } & Pick<AssetKey, "fullPath">) => Promise<void>;
17
+ export declare const deleteAssets: ({ collection, satellite }: {
18
+ collection: string;
19
+ satellite: Satellite;
20
+ }) => Promise<void>;
@@ -0,0 +1,11 @@
1
+ export declare const DELEGATION_IDENTITY_EXPIRATION: bigint;
2
+ export declare const II_POPUP: {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export declare const NFID_POPUP: {
7
+ width: number;
8
+ height: number;
9
+ };
10
+ export declare const INTERNET_COMPUTER_ORG = "internetcomputer.org";
11
+ export declare const AUTH_TIMER_INTERVAL = 1000;
@@ -0,0 +1,16 @@
1
+ import type { User } from './types/auth.types';
2
+ import type { Environment } from './types/env.types';
3
+ import type { Unsubscribe } from './types/subscription.types';
4
+ export * from './providers/auth.providers';
5
+ export { signIn, signOut, unsafeIdentity } from './services/auth.services';
6
+ export * from './services/doc.services';
7
+ export * from './services/storage.services';
8
+ export * from './types/auth.types';
9
+ export * from './types/doc.types';
10
+ export * from './types/env.types';
11
+ export { ListOrder, ListPaginate, ListParams, ListResults } from './types/list.types';
12
+ export * from './types/satellite.types';
13
+ export * from './types/storage.types';
14
+ export * from './types/subscription.types';
15
+ export declare const initJuno: (env: Environment) => Promise<Unsubscribe[]>;
16
+ export declare const authSubscribe: (callback: (authUser: User | null) => void) => Unsubscribe;
@@ -0,0 +1,31 @@
1
+ import type { Provider, SignInOptions } from '../types/auth.types';
2
+ export interface AuthProvider {
3
+ readonly id: Provider;
4
+ signInOptions: (options: Pick<SignInOptions, 'windowed'>) => {
5
+ identityProvider: string;
6
+ windowOpenerFeatures?: string;
7
+ };
8
+ }
9
+ export declare class InternetIdentityProvider implements AuthProvider {
10
+ #private;
11
+ constructor({ domain }: {
12
+ domain?: 'internetcomputer.org' | 'ic0.app';
13
+ });
14
+ get id(): Provider;
15
+ signInOptions({ windowed }: Pick<SignInOptions, 'windowed'>): {
16
+ identityProvider: string;
17
+ windowOpenerFeatures?: string;
18
+ };
19
+ }
20
+ export declare class NFIDProvider implements AuthProvider {
21
+ #private;
22
+ constructor({ appName, logoUrl }: {
23
+ appName: string;
24
+ logoUrl: string;
25
+ });
26
+ get id(): Provider;
27
+ signInOptions({ windowed }: Pick<SignInOptions, 'windowed'>): {
28
+ identityProvider: string;
29
+ windowOpenerFeatures?: string;
30
+ };
31
+ }
@@ -0,0 +1,3 @@
1
+ import type { EnvironmentWorker } from '../types/env.types';
2
+ import type { Unsubscribe } from '../types/subscription.types';
3
+ export declare const initAuthTimeoutWorker: (auth: EnvironmentWorker) => Unsubscribe;
@@ -0,0 +1,11 @@
1
+ import type { Identity } from '@dfinity/agent';
2
+ import type { Provider, SignInOptions } from '../types/auth.types';
3
+ export declare const initAuth: (provider?: Provider) => Promise<void>;
4
+ export declare const signIn: (options?: SignInOptions) => Promise<void>;
5
+ export declare const signOut: () => Promise<void>;
6
+ export declare const getIdentity: () => Identity | undefined;
7
+ /**
8
+ * Return what can be the identity of a sign-in user or an anonymous identity.
9
+ * Useful to load an identity in web workers.
10
+ */
11
+ export declare const unsafeIdentity: () => Promise<Identity>;
@@ -0,0 +1,22 @@
1
+ import type { Doc } from '../types/doc.types';
2
+ import type { ListParams, ListResults } from '../types/list.types';
3
+ import type { SatelliteOptions } from '../types/satellite.types';
4
+ export declare const getDoc: <D>({ satellite, ...rest }: {
5
+ collection: string;
6
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
7
+ } & Pick<Doc<D>, "key">) => Promise<Doc<D> | undefined>;
8
+ export declare const setDoc: <D>({ satellite, ...rest }: {
9
+ collection: string;
10
+ doc: Doc<D>;
11
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
12
+ }) => Promise<Doc<D>>;
13
+ export declare const deleteDoc: <D>({ satellite, ...rest }: {
14
+ collection: string;
15
+ doc: Doc<D>;
16
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
17
+ }) => Promise<void>;
18
+ export declare const listDocs: <D>({ satellite, filter, ...rest }: {
19
+ collection: string;
20
+ filter?: ListParams | undefined;
21
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
22
+ }) => Promise<ListResults<Doc<D>>>;
@@ -0,0 +1,2 @@
1
+ import type { Identity } from '@dfinity/agent';
2
+ export declare const getIdentity: (identity?: Identity) => Identity;
@@ -0,0 +1,24 @@
1
+ import type { ListParams } from '../types/list.types';
2
+ import type { SatelliteOptions } from '../types/satellite.types';
3
+ import type { AssetKey, Assets, Storage } from '../types/storage.types';
4
+ export declare const uploadBlob: (params: Storage & {
5
+ satellite?: SatelliteOptions;
6
+ }) => Promise<AssetKey>;
7
+ export declare const uploadFile: (params: Partial<Pick<Storage, 'filename'>> & Omit<Storage, 'filename' | 'data'> & {
8
+ data: File;
9
+ } & {
10
+ satellite?: SatelliteOptions;
11
+ }) => Promise<AssetKey>;
12
+ export declare const listAssets: ({ collection, satellite, filter }: {
13
+ collection: string;
14
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
15
+ filter?: ListParams | undefined;
16
+ }) => Promise<Assets>;
17
+ export declare const deleteAsset: ({ collection, fullPath, satellite }: {
18
+ collection: string;
19
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
20
+ } & Pick<AssetKey, "fullPath">) => Promise<void>;
21
+ export declare const deleteAssets: ({ collection, satellite }: {
22
+ collection: string;
23
+ satellite?: Partial<import("../types/satellite.types").Satellite> | undefined;
24
+ }) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { Provider, User } from '../types/auth.types';
2
+ export declare const initUser: (provider?: Provider) => Promise<User>;
@@ -0,0 +1,13 @@
1
+ import type { User } from '../types/auth.types';
2
+ import type { Unsubscribe } from '../types/subscription.types';
3
+ import { Store } from './store';
4
+ export declare class AuthStore extends Store<User | null> {
5
+ private static instance;
6
+ private authUser;
7
+ private constructor();
8
+ static getInstance(): AuthStore;
9
+ set(authUser: User | null): void;
10
+ get(): User | null;
11
+ subscribe(callback: (data: User | null) => void): Unsubscribe;
12
+ reset(): void;
13
+ }
@@ -0,0 +1,12 @@
1
+ import type { Environment } from '../types/env.types';
2
+ import { Store } from './store';
3
+ export declare class EnvStore extends Store<Environment | undefined> {
4
+ private static instance;
5
+ private env;
6
+ private constructor();
7
+ static getInstance(): EnvStore;
8
+ set(env: Environment | undefined): void;
9
+ get(): Environment | undefined;
10
+ localIdentity(): boolean;
11
+ subscribe(callback: (data: Environment | null | undefined) => void): () => void;
12
+ }
@@ -0,0 +1,5 @@
1
+ export declare abstract class Store<T> {
2
+ private callbacks;
3
+ protected populate(data: T | null): void;
4
+ subscribe(callback: (data: T | null) => void): () => void;
5
+ }
@@ -0,0 +1,13 @@
1
+ import type { InternetIdentityProvider, NFIDProvider } from '../providers/auth.providers';
2
+ import type { Doc } from './doc.types';
3
+ export type Provider = 'internet_identity' | 'nfid';
4
+ export interface UserData {
5
+ provider?: Provider;
6
+ }
7
+ export type User = Doc<UserData>;
8
+ export interface SignInOptions {
9
+ maxTimeToLive?: bigint;
10
+ derivationOrigin?: string | URL;
11
+ windowed?: boolean;
12
+ provider?: InternetIdentityProvider | NFIDProvider;
13
+ }
@@ -0,0 +1,8 @@
1
+ export interface Doc<D> {
2
+ key: string;
3
+ description?: string;
4
+ data: D;
5
+ owner?: string;
6
+ created_at?: bigint;
7
+ updated_at?: bigint;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { Satellite } from './satellite.types';
2
+ export type EnvironmentWorkerPath = string;
3
+ export type EnvironmentWorker = true | EnvironmentWorkerPath;
4
+ export interface EnvironmentWorkers {
5
+ auth?: EnvironmentWorker;
6
+ }
7
+ export type Environment = {
8
+ localIdentityCanisterId?: string;
9
+ workers?: EnvironmentWorkers;
10
+ } & Required<Pick<Satellite, 'satelliteId'>>;
@@ -0,0 +1,28 @@
1
+ import type { Principal } from '@dfinity/principal';
2
+ export interface ListResults<T> {
3
+ items: T[];
4
+ items_length: bigint;
5
+ items_page?: bigint;
6
+ matches_length: bigint;
7
+ matches_pages?: bigint;
8
+ }
9
+ export interface ListPaginate {
10
+ startAfter?: string;
11
+ limit?: number;
12
+ }
13
+ export type ListOrderField = 'keys' | 'updated_at' | 'created_at';
14
+ export interface ListOrder {
15
+ desc: boolean;
16
+ field: ListOrderField;
17
+ }
18
+ export type ListOwner = string | Principal;
19
+ export interface ListMatcher {
20
+ key?: string;
21
+ description?: string;
22
+ }
23
+ export interface ListParams {
24
+ matcher?: ListMatcher;
25
+ paginate?: ListPaginate;
26
+ order?: ListOrder;
27
+ owner?: ListOwner;
28
+ }
@@ -0,0 +1,5 @@
1
+ export type PostMessageRequest = 'junoStartAuthTimer' | 'junoStopAuthTimer';
2
+ export type PostMessageResponse = 'junoSignOutAuthTimer';
3
+ export interface PostMessage {
4
+ msg: PostMessageRequest | PostMessageResponse;
5
+ }
@@ -0,0 +1,8 @@
1
+ import type { Identity } from '@dfinity/agent';
2
+ export interface Satellite {
3
+ identity: Identity;
4
+ satelliteId?: string;
5
+ fetch?: typeof fetch;
6
+ env?: 'dev' | 'prod';
7
+ }
8
+ export type SatelliteOptions = Partial<Satellite>;
@@ -0,0 +1,35 @@
1
+ import type { AssetNoContent } from '../../declarations/satellite/satellite.did';
2
+ import type { ListResults } from './list.types';
3
+ export interface AssetEncoding {
4
+ modified: bigint;
5
+ sha256: string;
6
+ total_length: bigint;
7
+ }
8
+ export interface AssetKey {
9
+ fullPath: string;
10
+ name: string;
11
+ downloadUrl: string;
12
+ }
13
+ export type ENCODING_TYPE = 'identity' | 'gzip' | 'compress' | 'deflate' | 'br';
14
+ export interface Asset extends AssetKey {
15
+ description?: string;
16
+ token?: string;
17
+ headers: [string, string][];
18
+ encodings: Record<ENCODING_TYPE, AssetEncoding>;
19
+ owner?: string;
20
+ created_at?: bigint;
21
+ updated_at?: bigint;
22
+ }
23
+ export interface Assets extends Pick<ListResults<AssetNoContent>, 'items_length' | 'items_page' | 'matches_length' | 'matches_pages'> {
24
+ assets: Asset[];
25
+ }
26
+ export interface Storage {
27
+ filename: string;
28
+ data: Blob;
29
+ collection: string;
30
+ fullPath?: string;
31
+ headers?: [string, string][];
32
+ token?: string;
33
+ encoding?: ENCODING_TYPE;
34
+ description?: string;
35
+ }
@@ -0,0 +1 @@
1
+ export type Unsubscribe = () => void;
@@ -0,0 +1,6 @@
1
+ import type { ActorMethod, ActorSubclass } from '@dfinity/agent';
2
+ import type { IDL } from '@dfinity/candid';
3
+ import type { Satellite } from '../types/satellite.types';
4
+ export declare const createActor: <T = Record<string, ActorMethod<unknown[], unknown>>>({ satelliteId: canisterId, idlFactory, identity, fetch, env }: {
5
+ idlFactory: IDL.InterfaceFactory;
6
+ } & Required<Pick<Satellite, "satelliteId" | "identity">> & Pick<Satellite, "fetch" | "env">) => Promise<ActorSubclass<T>>;
@@ -0,0 +1,2 @@
1
+ import { AuthClient } from '@dfinity/auth-client';
2
+ export declare const createAuthClient: () => Promise<AuthClient>;
@@ -0,0 +1 @@
1
+ export declare const sha256ToBase64String: (sha256: Iterable<number>) => string;
@@ -0,0 +1,2 @@
1
+ import type { Doc } from '../../declarations/satellite/satellite.did';
2
+ export declare const mapData: <D>({ data }: Pick<Doc, 'data'>) => Promise<D>;
@@ -0,0 +1 @@
1
+ export declare const satelliteUrl: () => string;
@@ -0,0 +1,4 @@
1
+ export declare const emit: <T>({ message, detail }: {
2
+ message: string;
3
+ detail?: T | undefined;
4
+ }) => void;
@@ -0,0 +1,3 @@
1
+ import type { ListParams as ListParamsApi } from '../../declarations/satellite/satellite.did';
2
+ import type { ListParams } from '../types/list.types';
3
+ export declare const toListParams: ({ matcher, paginate, order, owner }: ListParams) => ListParamsApi;
@@ -0,0 +1 @@
1
+ export declare const encodeFilename: (filename: string) => string;
@@ -0,0 +1,4 @@
1
+ export declare const popupCenter: ({ width, height }: {
2
+ width: number;
3
+ height: number;
4
+ }) => string | undefined;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * The timer is executed only if user has signed in
4
+ */
5
+ export declare const startTimer: () => NodeJS.Timer;
6
+ export declare const stopTimer: () => void;