@cubist-labs/cubesigner-sdk 0.1.23
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.
- package/LICENSE-APACHE +177 -0
- package/LICENSE-MIT +25 -0
- package/NOTICE +13 -0
- package/README.md +470 -0
- package/dist/examples/ethers.d.ts +1 -0
- package/dist/examples/ethers.js +142 -0
- package/dist/spec/env/beta.json +9 -0
- package/dist/spec/env/gamma.json +9 -0
- package/dist/spec/env/prod.json +9 -0
- package/dist/src/client.d.ts +10 -0
- package/dist/src/client.js +21 -0
- package/dist/src/env.d.ts +15 -0
- package/dist/src/env.js +35 -0
- package/dist/src/ethers/index.d.ts +50 -0
- package/dist/src/ethers/index.js +122 -0
- package/dist/src/index.d.ts +114 -0
- package/dist/src/index.js +205 -0
- package/dist/src/key.d.ts +114 -0
- package/dist/src/key.js +201 -0
- package/dist/src/mfa.d.ts +23 -0
- package/dist/src/mfa.js +63 -0
- package/dist/src/org.d.ts +161 -0
- package/dist/src/org.js +264 -0
- package/dist/src/role.d.ts +224 -0
- package/dist/src/role.js +256 -0
- package/dist/src/schema.d.ts +3049 -0
- package/dist/src/schema.js +7 -0
- package/dist/src/session/generic.d.ts +47 -0
- package/dist/src/session/generic.js +3 -0
- package/dist/src/session/management_session_manager.d.ts +59 -0
- package/dist/src/session/management_session_manager.js +111 -0
- package/dist/src/session/oidc_session_manager.d.ts +78 -0
- package/dist/src/session/oidc_session_manager.js +142 -0
- package/dist/src/session/session_manager.d.ts +74 -0
- package/dist/src/session/session_manager.js +79 -0
- package/dist/src/session/session_storage.d.ts +47 -0
- package/dist/src/session/session_storage.js +76 -0
- package/dist/src/session/signer_session_manager.d.ts +88 -0
- package/dist/src/session/signer_session_manager.js +159 -0
- package/dist/src/sign.d.ts +114 -0
- package/dist/src/sign.js +248 -0
- package/dist/src/signer_session.d.ts +180 -0
- package/dist/src/signer_session.js +369 -0
- package/dist/src/util.d.ts +35 -0
- package/dist/src/util.js +75 -0
- package/dist/test/sessions.d.ts +35 -0
- package/dist/test/sessions.js +56 -0
- package/package.json +61 -0
- package/src/client.ts +12 -0
- package/src/env.ts +25 -0
- package/src/ethers/index.ts +131 -0
- package/src/index.ts +220 -0
- package/src/key.ts +249 -0
- package/src/org.ts +333 -0
- package/src/role.ts +385 -0
- package/src/schema.ts +3054 -0
- package/src/session/management_session_manager.ts +136 -0
- package/src/session/oidc_session_manager.ts +193 -0
- package/src/session/session_manager.ts +114 -0
- package/src/session/session_storage.ts +73 -0
- package/src/session/signer_session_manager.ts +211 -0
- package/src/signer_session.ts +464 -0
- package/src/util.ts +58 -0
- package/tsconfig.json +32 -0
package/src/util.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Directory where CubeSigner stores config files.
|
|
5
|
+
* @return {string} Config dir
|
|
6
|
+
*/
|
|
7
|
+
export function configDir(): string {
|
|
8
|
+
const configDir =
|
|
9
|
+
process.platform === "darwin"
|
|
10
|
+
? `${process.env.HOME}/Library/Application Support`
|
|
11
|
+
: `${process.env.HOME}/.config`;
|
|
12
|
+
return path.join(configDir, "cubesigner");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ResponseType<D, T> = { data?: D; error?: T; response?: Response };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Error response type, thrown on non-successful responses.
|
|
19
|
+
*/
|
|
20
|
+
export class ErrResponse extends Error {
|
|
21
|
+
/** Description */
|
|
22
|
+
readonly description?: string;
|
|
23
|
+
/** HTTP status code text (derived from `this.status`) */
|
|
24
|
+
readonly statusText?: string;
|
|
25
|
+
/** HTTP status code */
|
|
26
|
+
readonly status?: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Constructor
|
|
30
|
+
* @param {Partial<ErrResponse>} init Initializer
|
|
31
|
+
*/
|
|
32
|
+
constructor(init: Partial<ErrResponse>) {
|
|
33
|
+
super(init.message);
|
|
34
|
+
Object.assign(this, init);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Throw if on error response. Otherwise, return the response data.
|
|
40
|
+
* @param {ResponseType} resp The response to check
|
|
41
|
+
* @param {string} description Description to include in the thrown error
|
|
42
|
+
* @return {D} The response data.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export function assertOk<D, T>(resp: ResponseType<D, T>, description?: string): D {
|
|
46
|
+
if (resp.error) {
|
|
47
|
+
throw new ErrResponse({
|
|
48
|
+
description,
|
|
49
|
+
message: (resp.error as any).message, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
50
|
+
statusText: resp.response?.statusText,
|
|
51
|
+
status: resp.response?.status,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (resp.data === undefined) {
|
|
55
|
+
throw new Error("Response data is undefined");
|
|
56
|
+
}
|
|
57
|
+
return resp.data;
|
|
58
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2021",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noImplicitAny": true,
|
|
8
|
+
"noImplicitThis": true,
|
|
9
|
+
"alwaysStrict": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": false,
|
|
14
|
+
"inlineSourceMap": true,
|
|
15
|
+
"inlineSources": true,
|
|
16
|
+
"experimentalDecorators": true,
|
|
17
|
+
"strictPropertyInitialization": true,
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"outDir": "./dist"
|
|
22
|
+
},
|
|
23
|
+
"typedocOptions": {
|
|
24
|
+
"out": "./docs",
|
|
25
|
+
"excludeInternal": true,
|
|
26
|
+
"excludePrivate": true,
|
|
27
|
+
"excludeProtected": true,
|
|
28
|
+
"entryPoints": ["src/index.ts", "src/env.ts", "src/schema.ts"]
|
|
29
|
+
},
|
|
30
|
+
"exclude": ["spec", "node_modules", "dist"],
|
|
31
|
+
"include": ["src/**/*.ts"]
|
|
32
|
+
}
|