@neuroncloud/ido-browser 0.1.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.
@@ -0,0 +1,7 @@
1
+ import type { ClientOptions, StorageSlots } from "@neuroncloud/ido-client";
2
+ export interface BrowserClientOptions extends ClientOptions {
3
+ storage?: Partial<StorageSlots>;
4
+ redirectUri?: string;
5
+ postLogoutRedirectUri?: string;
6
+ }
7
+ //# sourceMappingURL=client-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-options.d.ts","sourceRoot":"","sources":["../src/client-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE3E,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=client-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-options.js","sourceRoot":"","sources":["../src/client-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import { type ClientStateManager, type IdoClient as IdoClientContract, type InteractionClient, type SignOutOptions, type TokenApi, type TokenManager, type Tokens, type UserClaims } from "@neuroncloud/ido-client";
2
+ import type { SignInWithRedirectOptions } from "@neuroncloud/ido-client";
3
+ import type { BrowserClientOptions } from "./client-options.js";
4
+ export declare class IdoClient implements IdoClientContract {
5
+ readonly interaction: InteractionClient;
6
+ readonly token: TokenApi;
7
+ readonly tokenManager: TokenManager;
8
+ readonly clientStateManager: ClientStateManager;
9
+ private readonly client;
10
+ constructor(options: BrowserClientOptions);
11
+ start(): Promise<void>;
12
+ stop(): Promise<void>;
13
+ signOut(options?: SignOutOptions): Promise<void>;
14
+ signInWithRedirect(options?: SignInWithRedirectOptions): Promise<void>;
15
+ isLoginRedirect(url?: string): boolean;
16
+ handleRedirect(input?: string | {
17
+ url?: string;
18
+ originalUri?: string;
19
+ }): Promise<Tokens>;
20
+ isAuthenticated(): Promise<boolean>;
21
+ getAccessToken(): string | undefined;
22
+ getIdToken(): string | undefined;
23
+ getUser(): Promise<UserClaims>;
24
+ setOriginalUri(uri: string): void;
25
+ getOriginalUri(): string | undefined;
26
+ removeOriginalUri(): void;
27
+ }
28
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,SAAS,IAAI,iBAAiB,EACnC,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAIzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,qBAAa,SAAU,YAAW,iBAAiB;IACjD,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAEhD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;gBAE/B,OAAO,EAAE,oBAAoB;IAyBzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItE,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO;IAItC,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxF,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC,cAAc,IAAI,MAAM,GAAG,SAAS;IAIpC,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAI9B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIjC,cAAc,IAAI,MAAM,GAAG,SAAS;IAIpC,iBAAiB,IAAI,IAAI;CAG1B"}
package/dist/client.js ADDED
@@ -0,0 +1,70 @@
1
+ import { createClient, } from "@neuroncloud/ido-client";
2
+ import { createBrowserStorageSlots } from "./storage.js";
3
+ import { browserLocationAdapter } from "./location.js";
4
+ import { browserWebAuthnAdapter } from "./webauthn.js";
5
+ export class IdoClient {
6
+ interaction;
7
+ token;
8
+ tokenManager;
9
+ clientStateManager;
10
+ client;
11
+ constructor(options) {
12
+ const defaults = createBrowserStorageSlots();
13
+ this.client = createClient({
14
+ ...options,
15
+ redirectUri: options.redirectUri ?? (typeof window === "undefined" ? undefined : window.location.origin),
16
+ }, {
17
+ storage: {
18
+ token: options.storage?.token ?? defaults.token,
19
+ transaction: options.storage?.transaction ?? defaults.transaction,
20
+ cache: options.storage?.cache ?? defaults.cache,
21
+ },
22
+ webauthn: browserWebAuthnAdapter,
23
+ location: browserLocationAdapter,
24
+ });
25
+ this.interaction = this.client.interaction;
26
+ this.token = this.client.token;
27
+ this.tokenManager = this.client.tokenManager;
28
+ this.clientStateManager = this.client.clientStateManager;
29
+ }
30
+ start() {
31
+ return this.client.start();
32
+ }
33
+ stop() {
34
+ return this.client.stop();
35
+ }
36
+ signOut(options) {
37
+ return this.client.signOut(options);
38
+ }
39
+ signInWithRedirect(options) {
40
+ return this.client.signInWithRedirect(options);
41
+ }
42
+ isLoginRedirect(url) {
43
+ return this.client.isLoginRedirect(url);
44
+ }
45
+ handleRedirect(input) {
46
+ return this.client.handleRedirect(input);
47
+ }
48
+ isAuthenticated() {
49
+ return this.client.isAuthenticated();
50
+ }
51
+ getAccessToken() {
52
+ return this.client.getAccessToken();
53
+ }
54
+ getIdToken() {
55
+ return this.client.getIdToken();
56
+ }
57
+ getUser() {
58
+ return this.client.getUser();
59
+ }
60
+ setOriginalUri(uri) {
61
+ this.client.setOriginalUri(uri);
62
+ }
63
+ getOriginalUri() {
64
+ return this.client.getOriginalUri();
65
+ }
66
+ removeOriginalUri() {
67
+ this.client.removeOriginalUri();
68
+ }
69
+ }
70
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GASb,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,OAAO,SAAS;IACX,WAAW,CAAoB;IAC/B,KAAK,CAAW;IAChB,YAAY,CAAe;IAC3B,kBAAkB,CAAqB;IAE/B,MAAM,CAAoB;IAE3C,YAAY,OAA6B;QACvC,MAAM,QAAQ,GAAG,yBAAyB,EAAE,CAAC;QAE7C,IAAI,CAAC,MAAM,GAAG,YAAY,CACxB;YACE,GAAG,OAAO;YACV,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;SACzG,EACD;YACE,OA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IACvC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,cAAc,CAAC,GAAW;QACxB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { isWebAuthnSupported } from "./webauthn.js";
2
+ export declare const features: {
3
+ isWebAuthnSupported: typeof isWebAuthnSupported;
4
+ };
5
+ //# sourceMappingURL=features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,eAAO,MAAM,QAAQ;;CAEpB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { isWebAuthnSupported } from "./webauthn.js";
2
+ export const features = {
3
+ isWebAuthnSupported,
4
+ };
5
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.js","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,mBAAmB;CACpB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "@neuroncloud/ido-client";
2
+ export { IdoClient } from "./client.js";
3
+ export type { BrowserClientOptions } from "./client-options.js";
4
+ export { features } from "./features.js";
5
+ export { isWebAuthnSupported } from "./webauthn.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "@neuroncloud/ido-client";
2
+ export { IdoClient } from "./client.js";
3
+ export { features } from "./features.js";
4
+ export { isWebAuthnSupported } from "./webauthn.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { LocationAdapter } from "@neuroncloud/ido-client";
2
+ export declare const browserLocationAdapter: LocationAdapter;
3
+ //# sourceMappingURL=location.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,EAAE,eAUpC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export const browserLocationAdapter = {
2
+ getHref() {
3
+ return window.location.href;
4
+ },
5
+ assign(url) {
6
+ window.location.assign(url);
7
+ },
8
+ replace(url) {
9
+ window.location.replace(url);
10
+ },
11
+ };
12
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.js","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,OAAO;QACL,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,GAAG;QACR,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,CAAC,GAAG;QACT,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type StorageSlots } from "@neuroncloud/ido-client";
2
+ export declare function createBrowserStorageSlots(): StorageSlots;
3
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmE,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE7H,wBAAgB,yBAAyB,IAAI,YAAY,CAMxD"}
@@ -0,0 +1,48 @@
1
+ import { MemoryStorage } from "@neuroncloud/ido-client";
2
+ export function createBrowserStorageSlots() {
3
+ return {
4
+ token: tryWebStorage("localStorage") ?? tryWebStorage("sessionStorage") ?? new MemoryStorage(),
5
+ transaction: tryWebStorage("sessionStorage") ?? new MemoryStorage(),
6
+ cache: tryWebStorage("sessionStorage") ?? new MemoryStorage(),
7
+ };
8
+ }
9
+ function tryWebStorage(type) {
10
+ try {
11
+ if (typeof globalThis === "undefined") {
12
+ return undefined;
13
+ }
14
+ const store = globalThis[type];
15
+ const probe = "__identityone.storage";
16
+ store.setItem(probe, "1");
17
+ store.removeItem(probe);
18
+ return {
19
+ getItem: (key) => store.getItem(key),
20
+ setItem: (key, value) => {
21
+ store.setItem(key, value);
22
+ },
23
+ removeItem: (key) => {
24
+ store.removeItem(key);
25
+ },
26
+ subscribe: (listener) => subscribeWebStorage(store, listener),
27
+ };
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ }
33
+ function subscribeWebStorage(store, listener) {
34
+ if (typeof window === "undefined") {
35
+ return () => undefined;
36
+ }
37
+ const handler = (event) => {
38
+ if (event.storageArea !== store) {
39
+ return;
40
+ }
41
+ listener({ key: event.key, value: event.newValue });
42
+ };
43
+ window.addEventListener("storage", handler);
44
+ return () => {
45
+ window.removeEventListener("storage", handler);
46
+ };
47
+ }
48
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuE,MAAM,yBAAyB,CAAC;AAE7H,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,IAAI,aAAa,CAAC,gBAAgB,CAAC,IAAI,IAAI,aAAa,EAAE;QAC9F,WAAW,EAAE,aAAa,CAAC,gBAAgB,CAAC,IAAI,IAAI,aAAa,EAAE;QACnE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,IAAI,IAAI,aAAa,EAAE;KAC9D,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,IAAuC;IAC5D,IAAI,CAAC;QACH,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,GAAI,UAAgC,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,uBAAuB,CAAC;QACtC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC1B,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAExB,OAAO;YACL,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YACpC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBACtB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5B,CAAC;YACD,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;gBAClB,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;YACD,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC;SAC9D,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc,EAAE,QAA+B;IAC1E,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;IACzB,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,KAAmB,EAAE,EAAE;QACtC,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type WebAuthnAdapter } from "@neuroncloud/ido-client";
2
+ export declare function isWebAuthnSupported(): boolean;
3
+ export declare const browserWebAuthnAdapter: WebAuthnAdapter;
4
+ //# sourceMappingURL=webauthn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webauthn.d.ts","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE7E,wBAAgB,mBAAmB,IAAI,OAAO,CAO7C;AAED,eAAO,MAAM,sBAAsB,EAAE,eAiBpC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { RuntimeError } from "@neuroncloud/ido-client";
2
+ export function isWebAuthnSupported() {
3
+ return (typeof window !== "undefined" &&
4
+ window.isSecureContext &&
5
+ "PublicKeyCredential" in window &&
6
+ typeof PublicKeyCredential.parseRequestOptionsFromJSON === "function");
7
+ }
8
+ export const browserWebAuthnAdapter = {
9
+ async get(publicKey) {
10
+ if (!isWebAuthnSupported()) {
11
+ throw new RuntimeError("Passkeys are not supported by this browser.", { code: "webauthn_unsupported" });
12
+ }
13
+ const options = toRequestOptions(publicKey);
14
+ const credential = await navigator.credentials.get({
15
+ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(options),
16
+ });
17
+ if (!(credential instanceof PublicKeyCredential)) {
18
+ throw new RuntimeError("The browser did not return a valid passkey credential.", { code: "webauthn_invalid" });
19
+ }
20
+ return JSON.stringify(credential.toJSON());
21
+ },
22
+ };
23
+ function toRequestOptions(publicKey) {
24
+ if (typeof publicKey === "string") {
25
+ return JSON.parse(publicKey);
26
+ }
27
+ if (typeof publicKey === "object" && publicKey !== null) {
28
+ const record = publicKey;
29
+ if (record.publicKey && typeof record.publicKey === "object") {
30
+ return record.publicKey;
31
+ }
32
+ return publicKey;
33
+ }
34
+ throw new RuntimeError("The passkey publicKey is invalid.", { code: "passkey_public_key_required" });
35
+ }
36
+ //# sourceMappingURL=webauthn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwB,MAAM,yBAAyB,CAAC;AAE7E,MAAM,UAAU,mBAAmB;IACjC,OAAO,CACL,OAAO,MAA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kD,CAAC;IAC5D,CAAC;IAED,MAAM,IAAI,YAAY,CAAC,mCAAmC,EAAE,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC,CAAC;AACvG,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@neuroncloud/ido-browser",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "typecheck": "tsc --noEmit -p tsconfig.json"
20
+ },
21
+ "dependencies": {
22
+ "@neuroncloud/ido-client": "0.1.0"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ }
27
+ }