@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.
Files changed (64) hide show
  1. package/LICENSE-APACHE +177 -0
  2. package/LICENSE-MIT +25 -0
  3. package/NOTICE +13 -0
  4. package/README.md +470 -0
  5. package/dist/examples/ethers.d.ts +1 -0
  6. package/dist/examples/ethers.js +142 -0
  7. package/dist/spec/env/beta.json +9 -0
  8. package/dist/spec/env/gamma.json +9 -0
  9. package/dist/spec/env/prod.json +9 -0
  10. package/dist/src/client.d.ts +10 -0
  11. package/dist/src/client.js +21 -0
  12. package/dist/src/env.d.ts +15 -0
  13. package/dist/src/env.js +35 -0
  14. package/dist/src/ethers/index.d.ts +50 -0
  15. package/dist/src/ethers/index.js +122 -0
  16. package/dist/src/index.d.ts +114 -0
  17. package/dist/src/index.js +205 -0
  18. package/dist/src/key.d.ts +114 -0
  19. package/dist/src/key.js +201 -0
  20. package/dist/src/mfa.d.ts +23 -0
  21. package/dist/src/mfa.js +63 -0
  22. package/dist/src/org.d.ts +161 -0
  23. package/dist/src/org.js +264 -0
  24. package/dist/src/role.d.ts +224 -0
  25. package/dist/src/role.js +256 -0
  26. package/dist/src/schema.d.ts +3049 -0
  27. package/dist/src/schema.js +7 -0
  28. package/dist/src/session/generic.d.ts +47 -0
  29. package/dist/src/session/generic.js +3 -0
  30. package/dist/src/session/management_session_manager.d.ts +59 -0
  31. package/dist/src/session/management_session_manager.js +111 -0
  32. package/dist/src/session/oidc_session_manager.d.ts +78 -0
  33. package/dist/src/session/oidc_session_manager.js +142 -0
  34. package/dist/src/session/session_manager.d.ts +74 -0
  35. package/dist/src/session/session_manager.js +79 -0
  36. package/dist/src/session/session_storage.d.ts +47 -0
  37. package/dist/src/session/session_storage.js +76 -0
  38. package/dist/src/session/signer_session_manager.d.ts +88 -0
  39. package/dist/src/session/signer_session_manager.js +159 -0
  40. package/dist/src/sign.d.ts +114 -0
  41. package/dist/src/sign.js +248 -0
  42. package/dist/src/signer_session.d.ts +180 -0
  43. package/dist/src/signer_session.js +369 -0
  44. package/dist/src/util.d.ts +35 -0
  45. package/dist/src/util.js +75 -0
  46. package/dist/test/sessions.d.ts +35 -0
  47. package/dist/test/sessions.js +56 -0
  48. package/package.json +61 -0
  49. package/src/client.ts +12 -0
  50. package/src/env.ts +25 -0
  51. package/src/ethers/index.ts +131 -0
  52. package/src/index.ts +220 -0
  53. package/src/key.ts +249 -0
  54. package/src/org.ts +333 -0
  55. package/src/role.ts +385 -0
  56. package/src/schema.ts +3054 -0
  57. package/src/session/management_session_manager.ts +136 -0
  58. package/src/session/oidc_session_manager.ts +193 -0
  59. package/src/session/session_manager.ts +114 -0
  60. package/src/session/session_storage.ts +73 -0
  61. package/src/session/signer_session_manager.ts +211 -0
  62. package/src/signer_session.ts +464 -0
  63. package/src/util.ts +58 -0
  64. 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
+ }