@neuroncloud/ido-node 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,4 @@
1
+ import { type Tokens } from "@neuroncloud/ido-client";
2
+ import type { NodeClientOptions } from "./client-options.js";
3
+ export declare function getClientCredentialsToken(options: NodeClientOptions): Promise<Tokens>;
4
+ //# sourceMappingURL=client-credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-credentials.d.ts","sourceRoot":"","sources":["../src/client-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,MAAM,EACZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB3F"}
@@ -0,0 +1,19 @@
1
+ import { RuntimeError, GrantTypes, HttpClient, exchangeToken, fetchHttpAdapter, resolveClientOptions, } from "@neuroncloud/ido-client";
2
+ import { createConfidentialAdapter } from "./confidential-client.js";
3
+ export async function getClientCredentialsToken(options) {
4
+ if (!options.clientSecret) {
5
+ throw new RuntimeError("clientSecret is required for client_credentials.", { code: "client_secret_required" });
6
+ }
7
+ const resolved = resolveClientOptions(options);
8
+ const http = new HttpClient(fetchHttpAdapter, createConfidentialAdapter(options.clientSecret));
9
+ const scopes = resolved.scopes.filter((scope) => scope !== "openid" && scope !== "offline_access").join(" ");
10
+ const result = await exchangeToken(http, resolved, {
11
+ grantType: GrantTypes.ClientCredentials,
12
+ scopes: scopes || undefined,
13
+ });
14
+ if (result.tokens) {
15
+ return result.tokens;
16
+ }
17
+ throw result.error ?? new RuntimeError("The client credentials request failed.");
18
+ }
19
+ //# sourceMappingURL=client-credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-credentials.js","sourceRoot":"","sources":["../src/client-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,oBAAoB,GAErB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,OAA0B;IACxE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,MAAM,IAAI,YAAY,CAAC,kDAAkD,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7G,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE;QACjD,SAAS,EAAE,UAAU,CAAC,iBAAiB;QACvC,MAAM,EAAE,MAAM,IAAI,SAAS;KAC5B,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,MAAM,MAAM,CAAC,KAAK,IAAI,IAAI,YAAY,CAAC,wCAAwC,CAAC,CAAC;AACnF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ClientOptions, StorageSlots } from "@neuroncloud/ido-client";
2
+ export interface NodeClientOptions extends ClientOptions {
3
+ clientSecret?: string;
4
+ storage?: Partial<StorageSlots>;
5
+ setLocation?: (url: string) => void;
6
+ getHref?: () => string;
7
+ }
8
+ //# 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,iBAAkB,SAAQ,aAAa;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;CACxB"}
@@ -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,31 @@
1
+ import { type ClientStateManager, type IdoClient as IdoClientContract, type InteractionClient, type SignInWithRedirectOptions, type SignOutOptions, type TokenApi, type TokenManager, type Tokens, type UserClaims } from "@neuroncloud/ido-client";
2
+ import type { NodeClientOptions } from "./client-options.js";
3
+ export declare class IdoClient implements IdoClientContract {
4
+ readonly interaction: InteractionClient;
5
+ readonly token: TokenApi;
6
+ readonly tokenManager: TokenManager;
7
+ readonly clientStateManager: ClientStateManager;
8
+ private readonly client;
9
+ private readonly options;
10
+ constructor(options: NodeClientOptions);
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
+ getToken(options?: {
28
+ scope?: string;
29
+ }): Promise<Tokens>;
30
+ }
31
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,SAAS,IAAI,iBAAiB,EACnC,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,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;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;gBAEhC,OAAO,EAAE,iBAAiB;IA0BtC,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;IAInB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAU9D"}
package/dist/client.js ADDED
@@ -0,0 +1,83 @@
1
+ import { createClient, createMemoryStorageSlots, } from "@neuroncloud/ido-client";
2
+ import { createConfidentialAdapter } from "./confidential-client.js";
3
+ import { getClientCredentialsToken } from "./client-credentials.js";
4
+ export class IdoClient {
5
+ interaction;
6
+ token;
7
+ tokenManager;
8
+ clientStateManager;
9
+ client;
10
+ options;
11
+ constructor(options) {
12
+ const defaults = createMemoryStorageSlots();
13
+ this.options = options;
14
+ this.client = createClient(options, {
15
+ storage: {
16
+ token: options.storage?.token ?? defaults.token,
17
+ transaction: options.storage?.transaction ?? defaults.transaction,
18
+ cache: options.storage?.cache ?? defaults.cache,
19
+ },
20
+ confidential: createConfidentialAdapter(options.clientSecret),
21
+ location: options.setLocation
22
+ ? {
23
+ getHref: options.getHref ?? (() => ""),
24
+ assign: options.setLocation,
25
+ replace: options.setLocation,
26
+ }
27
+ : undefined,
28
+ });
29
+ this.interaction = this.client.interaction;
30
+ this.token = this.client.token;
31
+ this.tokenManager = this.client.tokenManager;
32
+ this.clientStateManager = this.client.clientStateManager;
33
+ }
34
+ start() {
35
+ return this.client.start();
36
+ }
37
+ stop() {
38
+ return this.client.stop();
39
+ }
40
+ signOut(options) {
41
+ return this.client.signOut(options);
42
+ }
43
+ signInWithRedirect(options) {
44
+ return this.client.signInWithRedirect(options);
45
+ }
46
+ isLoginRedirect(url) {
47
+ return this.client.isLoginRedirect(url);
48
+ }
49
+ handleRedirect(input) {
50
+ return this.client.handleRedirect(input);
51
+ }
52
+ isAuthenticated() {
53
+ return this.client.isAuthenticated();
54
+ }
55
+ getAccessToken() {
56
+ return this.client.getAccessToken();
57
+ }
58
+ getIdToken() {
59
+ return this.client.getIdToken();
60
+ }
61
+ getUser() {
62
+ return this.client.getUser();
63
+ }
64
+ setOriginalUri(uri) {
65
+ this.client.setOriginalUri(uri);
66
+ }
67
+ getOriginalUri() {
68
+ return this.client.getOriginalUri();
69
+ }
70
+ removeOriginalUri() {
71
+ this.client.removeOriginalUri();
72
+ }
73
+ async getToken(options) {
74
+ const tokens = await getClientCredentialsToken({
75
+ ...this.options,
76
+ scopes: options?.scope ? options.scope.split(" ").filter(Boolean) : this.options.scopes,
77
+ });
78
+ this.tokenManager.setTokens(tokens);
79
+ this.clientStateManager.updateClientState();
80
+ return tokens;
81
+ }
82
+ }
83
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,wBAAwB,GAUzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAGpE,MAAM,OAAO,SAAS;IACX,WAAW,CAAoB;IAC/B,KAAK,CAAW;IAChB,YAAY,CAAe;IAC3B,kBAAkB,CAAqB;IAE/B,MAAM,CAAoB;IAC1B,OAAO,CAAoB;IAE5C,YAAY,OAA0B;QACpC,MAAM,QAAQ,GAAG,wBAAwB,EAAE,CAAC;QAE5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAA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AAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { type ConfidentialAdapter } from "@neuroncloud/ido-client";
2
+ export declare function createConfidentialAdapter(clientSecret?: string): ConfidentialAdapter;
3
+ //# sourceMappingURL=confidential-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidential-client.d.ts","sourceRoot":"","sources":["../src/confidential-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE/E,wBAAgB,yBAAyB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAapF"}
@@ -0,0 +1,15 @@
1
+ import { Parameters } from "@neuroncloud/ido-client";
2
+ export function createConfidentialAdapter(clientSecret) {
3
+ return {
4
+ applyClientAuth(body) {
5
+ if (!clientSecret) {
6
+ return body;
7
+ }
8
+ return {
9
+ ...body,
10
+ [Parameters.ClientSecret]: clientSecret,
11
+ };
12
+ },
13
+ };
14
+ }
15
+ //# sourceMappingURL=confidential-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidential-client.js","sourceRoot":"","sources":["../src/confidential-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,MAAM,yBAAyB,CAAC;AAE/E,MAAM,UAAU,yBAAyB,CAAC,YAAqB;IAC7D,OAAO;QACL,eAAe,CAAC,IAAI;YAClB,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO;gBACL,GAAG,IAAI;gBACP,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,YAAY;aACxC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "@neuroncloud/ido-client";
2
+ export { IdoClient } from "./client.js";
3
+ export type { NodeClientOptions } from "./client-options.js";
4
+ export { getClientCredentialsToken } from "./client-credentials.js";
5
+ //# 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,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "@neuroncloud/ido-client";
2
+ export { IdoClient } from "./client.js";
3
+ export { getClientCredentialsToken } from "./client-credentials.js";
4
+ //# 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,yBAAyB,EAAE,MAAM,yBAAyB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@neuroncloud/ido-node",
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
+ }