Skip to content

Commit

Permalink
remove old v0 errors from js sdk. provide error details to the user (#…
Browse files Browse the repository at this point in the history
…385)

* remove old v0 errors from js sdk.  provide error details to the user

* building now seems to consistently work

* refactored error handling to make it cleaner

* Remove unused function

* okay also added requestId in a few places

* ran the linter

* fix: replace nx executor

* feat: add gitignore

---------

Co-authored-by: Ansonhkg <ansonox@gmail.com>
  • Loading branch information
glitch003 and Ansonhkg authored Feb 26, 2024
1 parent 1628810 commit 5464279
Show file tree
Hide file tree
Showing 41 changed files with 128 additions and 155 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ apps/html/index.html
apps/nodejs/main.ts
apps/react/src/app/app.tsx

storage.test.db
storage.test.db

.nx
60 changes: 29 additions & 31 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/html/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- (DO NOT EDIT!) (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Thu, 22 Feb 2024 05:05:54 GMT -->
<!-- (DO NOT EDIT!) (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Sat, 24 Feb 2024 04:18:12 GMT -->
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -62,7 +62,7 @@
</style>
</head>
<body>
(HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Thu, 22 Feb 2024 05:05:54 GMT
(HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Sat, 24 Feb 2024 04:18:12 GMT

<!-- ==================== ALL EXPORTED VANILLA LIBRARIES ==================== -->

Expand Down
2 changes: 1 addition & 1 deletion apps/react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ pre {
`,
}}
/>
(REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Thu, 22 Feb 2024 05:05:54 GMT
(REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Sat, 24 Feb 2024 04:18:12 GMT
<div id="root"></div>
<pre><code id="result"></code></pre>
</>
Expand Down
4 changes: 2 additions & 2 deletions packages/access-control-conditions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
3 changes: 2 additions & 1 deletion packages/access-control-conditions/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
"types": [],
"explainFiles": true
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/auth-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
},
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/bls-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
},
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/constants/src/lib/constants/autogen_internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Last Modified: 2024-02-26 06:49:39
// This file is auto-generated by tools/scripts/gen-internal-dev.mjs
// Last Modified: 2024-02-24 04:15:54
// This file is auto-generated by tools/scripts/gen-internal-dev.mjs
export const INTERNAL_DEV = [
"https://167.114.17.205:443",
"https://64.131.85.108:443",
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
21 changes: 12 additions & 9 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,29 +929,32 @@ export class LitCore {
* @returns { void }
*
*/
_throwNodeError = (res: RejectedNodePromises): void => {
if (res.error && res.error.errorCode) {
_throwNodeError = (res: RejectedNodePromises, requestId: string): void => {
if (res.error) {
if (
(res.error.errorCode === LIT_ERROR_CODE.NODE_NOT_AUTHORIZED ||
((res.error.errorCode &&
res.error.errorCode === LIT_ERROR_CODE.NODE_NOT_AUTHORIZED) ||
res.error.errorCode === 'not_authorized') &&
this.config.alertWhenUnauthorized
) {
log(
'[Alert originally] You are not authorized to access to this content'
);
log('You are not authorized to access this content');
}

throwError({
...res.error,
message:
res.error.message ||
'You are not authorized to access to this content',
errorCode: res.error.errorCode!,
'There was an error getting the signing shares from the nodes',
errorCode: res.error.errorCode || LIT_ERROR.UNKNOWN_ERROR.code,
requestId,
} as NodeClientErrorV0 | NodeClientErrorV1);
} else {
throwError({
message: `There was an error getting the signing shares from the nodes`,
message: `There was an error getting the signing shares from the nodes. Response from the nodes: ${JSON.stringify(
res
)}`,
error: LIT_ERROR.UNKNOWN_ERROR,
requestId,
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/ecdsa-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
},
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/lit-auth-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
"nanoid": "3.3.4"
},
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/lit-node-client-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
23 changes: 11 additions & 12 deletions packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ export class LitNodeClientNodeJs
getSignatures = (signedData: Array<any>, requestId: string = ''): any => {
const initialKeys = [...new Set(signedData.flatMap((i) => Object.keys(i)))];

// processing signature shares for failed or invalid contents.
// processing signature shares for failed or invalid contents. mutates the signedData object.
for (const signatureResponse of signedData) {
for (const sigName of Object.keys(signatureResponse)) {
const requiredFields = ['signatureShare'];
Expand Down Expand Up @@ -1436,10 +1436,10 @@ export class LitNodeClientNodeJs
);

throwError({
message:
'total number of valid signatures shares does not match threshold',
message: `The total number of valid signatures shares ${shares.length} does not meet the threshold of ${this.config.minNodeCount}`,
errorKind: LIT_ERROR.NO_VALID_SHARES.kind,
errorCode: LIT_ERROR.NO_VALID_SHARES.code,
requestId,
});
}

Expand Down Expand Up @@ -1598,7 +1598,7 @@ export class LitNodeClientNodeJs
params = LitNodeClientNodeJs.normalizeParams(params);

let res;
let requestId = this.getRequestId();
let requestId = '';
// -- only run on a single node
if (targetNodeRange) {
res = await this.runOnTargetedNodes(params);
Expand Down Expand Up @@ -1649,7 +1649,7 @@ export class LitNodeClientNodeJs
}
// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

// -- case: promises success (TODO: check the keys of "values")
Expand Down Expand Up @@ -1862,7 +1862,7 @@ export class LitNodeClientNodeJs

// -- case: promises rejected
if (!res.success) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

// -- case: promises success (TODO: check the keys of "values")
Expand Down Expand Up @@ -1991,7 +1991,6 @@ export class LitNodeClientNodeJs
}

// ========== Get Node Promises ==========
let requestId;
const wrapper = async (
id: string
): Promise<SuccessNodePromises<any> | RejectedNodePromises> => {
Expand Down Expand Up @@ -2036,10 +2035,11 @@ export class LitNodeClientNodeJs
},
this.config.retryTolerance
);
const requestId = res.requestId;

// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

const signatureShares: Array<NodeBlsSigningShare> = (
Expand Down Expand Up @@ -2233,7 +2233,6 @@ export class LitNodeClientNodeJs

log('identityParam', identityParam);

let requestId;
// ========== Get Network Signature ==========
const wrapper = async (
id: string
Expand Down Expand Up @@ -2277,11 +2276,11 @@ export class LitNodeClientNodeJs
this.config.retryTolerance
);

requestId = res.requestId;
const requestId = res.requestId;

// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

const signatureShares: Array<NodeBlsSigningShare> = (
Expand Down Expand Up @@ -2618,7 +2617,7 @@ export class LitNodeClientNodeJs

// -- case: promises rejected
if (!this.#isSuccessNodePromises(res)) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
return {} as SignSessionKeyResponse;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lit-node-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
},
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"directory": "../../dist/packages/logger"
},
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/misc-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/misc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
],
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/index.d.ts"
}
"typings": "./dist/src/index.d.ts"
}
Loading

0 comments on commit 5464279

Please sign in to comment.