@learncard/simple-signing-client 1.0.3
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/CHANGELOG.md +22 -0
- package/LICENSE +25 -0
- package/README.md +43 -0
- package/dist/callbackLink.d.ts +4 -0
- package/dist/callbackLink.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/simple-signing-client.cjs.development.js +95 -0
- package/dist/simple-signing-client.cjs.development.js.map +7 -0
- package/dist/simple-signing-client.cjs.production.min.js +1 -0
- package/dist/simple-signing-client.cjs.production.min.js.map +7 -0
- package/dist/simple-signing-client.esm.js +77 -0
- package/dist/simple-signing-client.esm.js.map +7 -0
- package/esbuild.mjs +25 -0
- package/package.json +27 -0
- package/project.json +34 -0
- package/scripts/.eslintrc +10 -0
- package/scripts/build.mjs +89 -0
- package/scripts/mixedEntypoint.js +7 -0
- package/src/callbackLink.ts +42 -0
- package/src/index.ts +47 -0
- package/tsconfig.json +40 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @welibraryos/lca-api-client
|
|
2
|
+
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @learncard/simple-signing-service@1.0.3
|
|
9
|
+
|
|
10
|
+
## 1.0.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies []:
|
|
15
|
+
- @learncard/simple-signing-service@1.0.2
|
|
16
|
+
|
|
17
|
+
## 1.0.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies []:
|
|
22
|
+
- @learncard/simple-signing-service@1.0.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Learning Economy Foundation <sdk@learningeconomy.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
Footer
|
|
23
|
+
© 2024 GitHub, Inc.
|
|
24
|
+
Footer navigation
|
|
25
|
+
Terms
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[<img src="https://user-images.githubusercontent.com/2185016/190510561-294db809-09fd-4771-9749-6c0e0f4144fd.png" width="215"/>](https://learncard.com)
|
|
2
|
+
|
|
3
|
+
# Simple Signing Client
|
|
4
|
+
|
|
5
|
+
A client library for interacting with the Simple Signing Service in the LearnCard Network ecosystem.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This client provides a convenient way to communicate with a Simple Signing Service instance. It abstracts away the details of the network requests and provides a simple interface for signing operations.
|
|
10
|
+
|
|
11
|
+
Key features:
|
|
12
|
+
- TypeScript-based API client for Simple Signing Service
|
|
13
|
+
- Streamlined authentication flow
|
|
14
|
+
- Integration with LearnCard Network operations
|
|
15
|
+
- Support for Signing Authorities
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { getClient } from '@learncard/simple-signing-client';
|
|
21
|
+
|
|
22
|
+
// Initialize the client with your service endpoint
|
|
23
|
+
const client = getClient('https://yourendpoint.com/trpc', () => {} // DID-Auth function);
|
|
24
|
+
|
|
25
|
+
// Authenticate and perform operations
|
|
26
|
+
const response = await client.verifySignature({
|
|
27
|
+
// Signature data
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Related Packages
|
|
32
|
+
|
|
33
|
+
This client is designed to work with:
|
|
34
|
+
- `@learncard/simple-signing-service`: The service implementation
|
|
35
|
+
- `@learncard/simple-signing-plugin`: The LearnCard plugin that uses this client
|
|
36
|
+
|
|
37
|
+
## E2E Testing
|
|
38
|
+
|
|
39
|
+
This client is particularly useful for end-to-end testing of LearnCard Network operations that require Signing Authorities, without needing to implement a full production signing authority.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT © [Learning Economy Foundation](https://github.com/Learning-Economy-Foundation)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callbackLink.d.ts","sourceRoot":"","sources":["../src/callbackLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE,eAAO,MAAM,YAAY,aAAc,MAAM,OAAO,CAAC,IAAI,CAAC,KAAG,QAAQ,CAAC,SAAS,CAqC9E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CreateTRPCProxyClient } from '@trpc/client';
|
|
2
|
+
import type { AppRouter } from '@learncard/simple-signing-service';
|
|
3
|
+
export type Client = CreateTRPCProxyClient<AppRouter>;
|
|
4
|
+
export declare const getClient: (url: string, didAuthFunction: (challenge?: string) => Promise<string>) => Promise<Client>;
|
|
5
|
+
export default getClient;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,qBAAqB,EAAiB,MAAM,cAAc,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAInE,MAAM,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAEtD,eAAO,MAAM,SAAS,QACb,MAAM,mBACM,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,KACzD,OAAO,CAAC,MAAM,CAkChB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
default: () => src_default,
|
|
24
|
+
getClient: () => getClient
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
var import_client = require("@trpc/client");
|
|
28
|
+
|
|
29
|
+
// src/callbackLink.ts
|
|
30
|
+
var import_observable = require("@trpc/server/observable");
|
|
31
|
+
var callbackLink = /* @__PURE__ */ __name((callback) => {
|
|
32
|
+
return () => {
|
|
33
|
+
return ({ next, op }) => {
|
|
34
|
+
return (0, import_observable.observable)((observer) => {
|
|
35
|
+
let request = null;
|
|
36
|
+
let attempts = 0;
|
|
37
|
+
let isDone = false;
|
|
38
|
+
const attempt = /* @__PURE__ */ __name(() => {
|
|
39
|
+
attempts += 1;
|
|
40
|
+
request?.unsubscribe();
|
|
41
|
+
request = next(op).subscribe({
|
|
42
|
+
error: async (error) => {
|
|
43
|
+
if (attempts > 5 || error.data?.httpStatus !== 401) {
|
|
44
|
+
return observer.error(error);
|
|
45
|
+
}
|
|
46
|
+
await callback();
|
|
47
|
+
attempt();
|
|
48
|
+
},
|
|
49
|
+
next: (result) => observer.next(result),
|
|
50
|
+
complete: () => {
|
|
51
|
+
if (isDone)
|
|
52
|
+
observer.complete();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, "attempt");
|
|
56
|
+
attempt();
|
|
57
|
+
return () => {
|
|
58
|
+
isDone = true;
|
|
59
|
+
request?.unsubscribe();
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}, "callbackLink");
|
|
65
|
+
|
|
66
|
+
// src/index.ts
|
|
67
|
+
var getClient = /* @__PURE__ */ __name(async (url, didAuthFunction) => {
|
|
68
|
+
let challenges = [];
|
|
69
|
+
const challengeRequester = (0, import_client.createTRPCProxyClient)({
|
|
70
|
+
links: [
|
|
71
|
+
(0, import_client.httpBatchLink)({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } })
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
const getChallenges = /* @__PURE__ */ __name(async (amount = 95 + Math.round((Math.random() - 0.5) * 5)) => {
|
|
75
|
+
return challengeRequester.utilities.getChallenges.query({ amount });
|
|
76
|
+
}, "getChallenges");
|
|
77
|
+
getChallenges().then((result) => challenges = result);
|
|
78
|
+
const trpc = (0, import_client.createTRPCProxyClient)({
|
|
79
|
+
links: [
|
|
80
|
+
callbackLink(async () => {
|
|
81
|
+
challenges = await getChallenges();
|
|
82
|
+
}),
|
|
83
|
+
(0, import_client.httpBatchLink)({
|
|
84
|
+
url,
|
|
85
|
+
headers: async () => {
|
|
86
|
+
if (challenges.length === 0)
|
|
87
|
+
challenges.push(...await getChallenges());
|
|
88
|
+
return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
return trpc;
|
|
94
|
+
}, "getClient");
|
|
95
|
+
var src_default = getClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
|
+
"sourcesContent": ["import { createTRPCProxyClient, CreateTRPCProxyClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nimport { callbackLink } from './callbackLink';\n\nexport type Client = CreateTRPCProxyClient<AppRouter>;\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n): Promise<Client> => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as Client;\n\n const getChallenges = async (\n amount = 95 + Math.round((Math.random() - 0.5) * 5)\n ): Promise<string[]> => {\n return challengeRequester.utilities.getChallenges.query({ amount });\n };\n\n getChallenges().then(result => (challenges = result));\n\n const trpc = createTRPCProxyClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n url,\n headers: async () => {\n if (challenges.length === 0) challenges.push(...(await getChallenges()));\n\n return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };\n },\n }),\n ],\n }) as Client;\n\n return trpc;\n};\n\nexport default getClient;\n", "import { TRPCLink } from '@trpc/client';\nimport { observable, Unsubscribable } from '@trpc/server/observable';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nexport const callbackLink = (callback: () => Promise<void>): TRPCLink<AppRouter> => {\n return () => {\n return ({ next, op }) => {\n return observable(observer => {\n let request: Unsubscribable | null = null;\n let attempts = 0;\n let isDone = false;\n\n const attempt = () => {\n attempts += 1;\n request?.unsubscribe();\n request = next(op).subscribe({\n error: async error => {\n if (attempts > 5 || error.data?.httpStatus !== 401) {\n return observer.error(error);\n }\n\n await callback();\n\n attempt();\n },\n next: result => observer.next(result),\n complete: () => {\n if (isDone) observer.complete();\n },\n });\n };\n\n attempt();\n\n return () => {\n isDone = true;\n request?.unsubscribe();\n };\n });\n };\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4E;;;ACC5E,wBAA2C;AAGpC,IAAM,eAAe,wBAAC,aAAuD;AAChF,SAAO,MAAM;AACT,WAAO,CAAC,EAAE,MAAM,GAAG,MAAM;AACrB,iBAAO,8BAAW,cAAY;AAC1B,YAAI,UAAiC;AACrC,YAAI,WAAW;AACf,YAAI,SAAS;AAEb,cAA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UAAU,MAAM,gBAAgB,WAAW,IAAI,CAAC,IAAI;AAAA,QAChF;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX,GArCyB;AAuCzB,IAAO,cAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var s=(t,e)=>p(t,"name",{value:e,configurable:!0});var P=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},R=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of b(e))!y.call(t,r)&&r!==n&&p(t,r,{get:()=>e[r],enumerable:!(i=h(e,r))||i.enumerable});return t};var f=t=>R(p({},"__esModule",{value:!0}),t);var x={};P(x,{default:()=>k,getClient:()=>C});module.exports=f(x);var o=require("@trpc/client");var m=require("@trpc/server/observable");var g=s(t=>()=>({next:e,op:n})=>(0,m.observable)(i=>{let r=null,c=0,a=!1,u=s(()=>{c+=1,r?.unsubscribe(),r=e(n).subscribe({error:async l=>{if(c>5||l.data?.httpStatus!==401)return i.error(l);await t(),u()},next:l=>i.next(l),complete:()=>{a&&i.complete()}})},"attempt");return u(),()=>{a=!0,r?.unsubscribe()}}),"callbackLink");var C=s(async(t,e)=>{let n=[],i=(0,o.createTRPCProxyClient)({links:[(0,o.httpBatchLink)({url:t,headers:{Authorization:`Bearer ${await e()}`}})]}),r=s(async(a=95+Math.round((Math.random()-.5)*5))=>i.utilities.getChallenges.query({amount:a}),"getChallenges");return r().then(a=>n=a),(0,o.createTRPCProxyClient)({links:[g(async()=>{n=await r()}),(0,o.httpBatchLink)({url:t,headers:async()=>(n.length===0&&n.push(...await r()),{Authorization:`Bearer ${await e(n.pop())}`})})]})},"getClient"),k=C;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
|
+
"sourcesContent": ["import { createTRPCProxyClient, CreateTRPCProxyClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nimport { callbackLink } from './callbackLink';\n\nexport type Client = CreateTRPCProxyClient<AppRouter>;\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n): Promise<Client> => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as Client;\n\n const getChallenges = async (\n amount = 95 + Math.round((Math.random() - 0.5) * 5)\n ): Promise<string[]> => {\n return challengeRequester.utilities.getChallenges.query({ amount });\n };\n\n getChallenges().then(result => (challenges = result));\n\n const trpc = createTRPCProxyClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n url,\n headers: async () => {\n if (challenges.length === 0) challenges.push(...(await getChallenges()));\n\n return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };\n },\n }),\n ],\n }) as Client;\n\n return trpc;\n};\n\nexport default getClient;\n", "import { TRPCLink } from '@trpc/client';\nimport { observable, Unsubscribable } from '@trpc/server/observable';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nexport const callbackLink = (callback: () => Promise<void>): TRPCLink<AppRouter> => {\n return () => {\n return ({ next, op }) => {\n return observable(observer => {\n let request: Unsubscribable | null = null;\n let attempts = 0;\n let isDone = false;\n\n const attempt = () => {\n attempts += 1;\n request?.unsubscribe();\n request = next(op).subscribe({\n error: async error => {\n if (attempts > 5 || error.data?.httpStatus !== 401) {\n return observer.error(error);\n }\n\n await callback();\n\n attempt();\n },\n next: result => observer.next(result),\n complete: () => {\n if (isDone) observer.complete();\n },\n });\n };\n\n attempt();\n\n return () => {\n isDone = true;\n request?.unsubscribe();\n };\n });\n };\n };\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Ac,CACrC,CAAC,KACD,iBAAc,CACV,IAAAJ,EACA,QAAS,UACDE,EAAW,SAAW,GAAGA,EAAW,KAAK,GAAI,MAAME,EAAc,CAAE,EAEhE,CAAE,cAAe,UAAU,MAAMH,EAAgBC,EAAW,IAAI,CAAC,GAAI,EAEpF,CAAC,CACL,CACJ,CAAC,CAGL,EArCyB,aAuClBM,EAAQV",
|
|
6
|
+
"names": ["src_exports", "__export", "src_default", "getClient", "__toCommonJS", "import_client", "import_observable", "callbackLink", "__name", "callback", "next", "op", "observer", "request", "attempts", "isDone", "attempt", "error", "result", "getClient", "__name", "url", "didAuthFunction", "challenges", "challengeRequester", "getChallenges", "amount", "result", "callbackLink", "src_default"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
|
|
6
|
+
|
|
7
|
+
// src/callbackLink.ts
|
|
8
|
+
import { observable } from "@trpc/server/observable";
|
|
9
|
+
var callbackLink = /* @__PURE__ */ __name((callback) => {
|
|
10
|
+
return () => {
|
|
11
|
+
return ({ next, op }) => {
|
|
12
|
+
return observable((observer) => {
|
|
13
|
+
let request = null;
|
|
14
|
+
let attempts = 0;
|
|
15
|
+
let isDone = false;
|
|
16
|
+
const attempt = /* @__PURE__ */ __name(() => {
|
|
17
|
+
attempts += 1;
|
|
18
|
+
request?.unsubscribe();
|
|
19
|
+
request = next(op).subscribe({
|
|
20
|
+
error: async (error) => {
|
|
21
|
+
if (attempts > 5 || error.data?.httpStatus !== 401) {
|
|
22
|
+
return observer.error(error);
|
|
23
|
+
}
|
|
24
|
+
await callback();
|
|
25
|
+
attempt();
|
|
26
|
+
},
|
|
27
|
+
next: (result) => observer.next(result),
|
|
28
|
+
complete: () => {
|
|
29
|
+
if (isDone)
|
|
30
|
+
observer.complete();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}, "attempt");
|
|
34
|
+
attempt();
|
|
35
|
+
return () => {
|
|
36
|
+
isDone = true;
|
|
37
|
+
request?.unsubscribe();
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}, "callbackLink");
|
|
43
|
+
|
|
44
|
+
// src/index.ts
|
|
45
|
+
var getClient = /* @__PURE__ */ __name(async (url, didAuthFunction) => {
|
|
46
|
+
let challenges = [];
|
|
47
|
+
const challengeRequester = createTRPCProxyClient({
|
|
48
|
+
links: [
|
|
49
|
+
httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } })
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const getChallenges = /* @__PURE__ */ __name(async (amount = 95 + Math.round((Math.random() - 0.5) * 5)) => {
|
|
53
|
+
return challengeRequester.utilities.getChallenges.query({ amount });
|
|
54
|
+
}, "getChallenges");
|
|
55
|
+
getChallenges().then((result) => challenges = result);
|
|
56
|
+
const trpc = createTRPCProxyClient({
|
|
57
|
+
links: [
|
|
58
|
+
callbackLink(async () => {
|
|
59
|
+
challenges = await getChallenges();
|
|
60
|
+
}),
|
|
61
|
+
httpBatchLink({
|
|
62
|
+
url,
|
|
63
|
+
headers: async () => {
|
|
64
|
+
if (challenges.length === 0)
|
|
65
|
+
challenges.push(...await getChallenges());
|
|
66
|
+
return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
return trpc;
|
|
72
|
+
}, "getClient");
|
|
73
|
+
var src_default = getClient;
|
|
74
|
+
export {
|
|
75
|
+
src_default as default,
|
|
76
|
+
getClient
|
|
77
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
|
+
"sourcesContent": ["import { createTRPCProxyClient, CreateTRPCProxyClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nimport { callbackLink } from './callbackLink';\n\nexport type Client = CreateTRPCProxyClient<AppRouter>;\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n): Promise<Client> => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as Client;\n\n const getChallenges = async (\n amount = 95 + Math.round((Math.random() - 0.5) * 5)\n ): Promise<string[]> => {\n return challengeRequester.utilities.getChallenges.query({ amount });\n };\n\n getChallenges().then(result => (challenges = result));\n\n const trpc = createTRPCProxyClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n url,\n headers: async () => {\n if (challenges.length === 0) challenges.push(...(await getChallenges()));\n\n return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };\n },\n }),\n ],\n }) as Client;\n\n return trpc;\n};\n\nexport default getClient;\n", "import { TRPCLink } from '@trpc/client';\nimport { observable, Unsubscribable } from '@trpc/server/observable';\nimport type { AppRouter } from '@learncard/simple-signing-service';\n\nexport const callbackLink = (callback: () => Promise<void>): TRPCLink<AppRouter> => {\n return () => {\n return ({ next, op }) => {\n return observable(observer => {\n let request: Unsubscribable | null = null;\n let attempts = 0;\n let isDone = false;\n\n const attempt = () => {\n attempts += 1;\n request?.unsubscribe();\n request = next(op).subscribe({\n error: async error => {\n if (attempts > 5 || error.data?.httpStatus !== 401) {\n return observer.error(error);\n }\n\n await callback();\n\n attempt();\n },\n next: result => observer.next(result),\n complete: () => {\n if (isDone) observer.complete();\n },\n });\n };\n\n attempt();\n\n return () => {\n isDone = true;\n request?.unsubscribe();\n };\n });\n };\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;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C;AAAA,IAC1C,OAAO;AAAA,MACH,aAAa,YAAY;AACrB,qBAAa,MAAM,cAAc;AAAA,MACrC,CAAC;AAAA,MACD,cAAc;AAAA,QACV;AAAA,QACA,SAAS,YAAY;AACjB,cAAI,WAAW,WAAW;AAAG,uBAAW,KAAK,GAAI,MAAM,cAAc,CAAE;AAEvE,iBAAO,EAAE,eAAe,UAAU,MAAM,gBAAgB,WAAW,IAAI,CAAC,IAAI;AAAA,QAChF;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX,GArCyB;AAuCzB,IAAO,cAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esbuild.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
|
|
3
|
+
const startTime = Date.now();
|
|
4
|
+
|
|
5
|
+
console.log('🎁 Building main bundle...');
|
|
6
|
+
|
|
7
|
+
const finalBuildObj = {
|
|
8
|
+
entryPoints: ['src/index.ts'],
|
|
9
|
+
platform: 'node',
|
|
10
|
+
bundle: true,
|
|
11
|
+
format: 'cjs',
|
|
12
|
+
outdir: 'dist',
|
|
13
|
+
target: 'node18',
|
|
14
|
+
external: [],
|
|
15
|
+
minify: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
finalBuildObj.sourcemap = 'inline';
|
|
20
|
+
finalBuildObj.minify = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
build(finalBuildObj).then(() => {
|
|
24
|
+
console.log(`🎁 Done building main bundle! (${Date.now() - startTime}ms)`);
|
|
25
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@learncard/simple-signing-client",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "./dist/simple-signing-client.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"author": "WeLibrary, LLC (www.welibrary.io)",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@esbuild-plugins/node-resolve": "^0.1.4",
|
|
13
|
+
"dts-bundle-generator": "^6.10.0",
|
|
14
|
+
"esbuild": "^0.16.16",
|
|
15
|
+
"rimraf": "^3.0.2",
|
|
16
|
+
"shx": "^0.3.4",
|
|
17
|
+
"@learncard/types": "5.6.7"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@trpc/client": "^10.17.0",
|
|
21
|
+
"@trpc/server": "^10.17.0",
|
|
22
|
+
"@learncard/simple-signing-service": "1.0.3"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.js && tsc --p tsconfig.json"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
3
|
+
"name": "simple-signing-client",
|
|
4
|
+
"sourceRoot": "packages/learn-card-network/simple-signing-client/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"root": "packages/learn-card-network/simple-signing-client",
|
|
7
|
+
"tags": [],
|
|
8
|
+
"implicitDependencies": [
|
|
9
|
+
"simple-signing-service"
|
|
10
|
+
],
|
|
11
|
+
"namedInputs": {
|
|
12
|
+
"source": [
|
|
13
|
+
"{projectRoot}/src/**/*"
|
|
14
|
+
],
|
|
15
|
+
"scripts": [
|
|
16
|
+
"{projectRoot}/scripts/**/*"
|
|
17
|
+
],
|
|
18
|
+
"dist": [
|
|
19
|
+
"{projectRoot}/dist/**/*"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"targets": {
|
|
23
|
+
"build": {
|
|
24
|
+
"executor": "nx:run-script",
|
|
25
|
+
"inputs": [
|
|
26
|
+
"source",
|
|
27
|
+
"scripts"
|
|
28
|
+
],
|
|
29
|
+
"options": {
|
|
30
|
+
"script": "build"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import esbuild from 'esbuild';
|
|
4
|
+
import { NodeResolvePlugin } from '@esbuild-plugins/node-resolve';
|
|
5
|
+
import rimraf from 'rimraf';
|
|
6
|
+
|
|
7
|
+
const nodeResolveExternal = NodeResolvePlugin({
|
|
8
|
+
extensions: ['.ts', '.js', '.tsx', '.jsx', '.cjs', '.mjs'],
|
|
9
|
+
onResolved: resolved => {
|
|
10
|
+
if (resolved.includes('node_modules')) {
|
|
11
|
+
return {
|
|
12
|
+
external: true,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return resolved;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const configurations = [
|
|
20
|
+
{
|
|
21
|
+
keepNames: true,
|
|
22
|
+
bundle: true,
|
|
23
|
+
sourcemap: 'external',
|
|
24
|
+
incremental: true,
|
|
25
|
+
tsconfig: 'tsconfig.json',
|
|
26
|
+
plugins: [nodeResolveExternal],
|
|
27
|
+
entryPoints: ['src/index.ts'],
|
|
28
|
+
format: 'cjs',
|
|
29
|
+
outfile: 'dist/simple-signing-client.cjs.development.js',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
keepNames: true,
|
|
33
|
+
bundle: true,
|
|
34
|
+
sourcemap: 'external',
|
|
35
|
+
incremental: true,
|
|
36
|
+
tsconfig: 'tsconfig.json',
|
|
37
|
+
plugins: [nodeResolveExternal],
|
|
38
|
+
entryPoints: ['src/index.ts'],
|
|
39
|
+
minify: true,
|
|
40
|
+
format: 'cjs',
|
|
41
|
+
outfile: 'dist/simple-signing-client.cjs.production.min.js',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
keepNames: true,
|
|
45
|
+
bundle: true,
|
|
46
|
+
sourcemap: 'external',
|
|
47
|
+
incremental: true,
|
|
48
|
+
tsconfig: 'tsconfig.json',
|
|
49
|
+
plugins: [nodeResolveExternal],
|
|
50
|
+
entryPoints: ['src/index.ts'],
|
|
51
|
+
format: 'esm',
|
|
52
|
+
outfile: 'dist/simple-signing-client.esm.js',
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
function asyncRimraf(path) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
rimraf(path, err => {
|
|
59
|
+
if (err) {
|
|
60
|
+
reject(err);
|
|
61
|
+
} else {
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function main() {
|
|
69
|
+
Promise.all(
|
|
70
|
+
configurations.map(config => {
|
|
71
|
+
var dir = config.outdir || path.dirname(config.outfile);
|
|
72
|
+
asyncRimraf(dir).catch(() => {
|
|
73
|
+
console.log('Unable to delete directory', dir);
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
).then(() => {
|
|
77
|
+
Promise.all(configurations.map(config => esbuild.build(config)))
|
|
78
|
+
.then(() => {
|
|
79
|
+
console.log('✔ Build successful');
|
|
80
|
+
process.exit(0);
|
|
81
|
+
})
|
|
82
|
+
.catch(err => {
|
|
83
|
+
console.error('❌ Build failed');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TRPCLink } from '@trpc/client';
|
|
2
|
+
import { observable, Unsubscribable } from '@trpc/server/observable';
|
|
3
|
+
import type { AppRouter } from '@learncard/simple-signing-service';
|
|
4
|
+
|
|
5
|
+
export const callbackLink = (callback: () => Promise<void>): TRPCLink<AppRouter> => {
|
|
6
|
+
return () => {
|
|
7
|
+
return ({ next, op }) => {
|
|
8
|
+
return observable(observer => {
|
|
9
|
+
let request: Unsubscribable | null = null;
|
|
10
|
+
let attempts = 0;
|
|
11
|
+
let isDone = false;
|
|
12
|
+
|
|
13
|
+
const attempt = () => {
|
|
14
|
+
attempts += 1;
|
|
15
|
+
request?.unsubscribe();
|
|
16
|
+
request = next(op).subscribe({
|
|
17
|
+
error: async error => {
|
|
18
|
+
if (attempts > 5 || error.data?.httpStatus !== 401) {
|
|
19
|
+
return observer.error(error);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
await callback();
|
|
23
|
+
|
|
24
|
+
attempt();
|
|
25
|
+
},
|
|
26
|
+
next: result => observer.next(result),
|
|
27
|
+
complete: () => {
|
|
28
|
+
if (isDone) observer.complete();
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
attempt();
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
isDone = true;
|
|
37
|
+
request?.unsubscribe();
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createTRPCProxyClient, CreateTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|
2
|
+
import type { AppRouter } from '@learncard/simple-signing-service';
|
|
3
|
+
|
|
4
|
+
import { callbackLink } from './callbackLink';
|
|
5
|
+
|
|
6
|
+
export type Client = CreateTRPCProxyClient<AppRouter>;
|
|
7
|
+
|
|
8
|
+
export const getClient = async (
|
|
9
|
+
url: string,
|
|
10
|
+
didAuthFunction: (challenge?: string) => Promise<string>
|
|
11
|
+
): Promise<Client> => {
|
|
12
|
+
let challenges: string[] = [];
|
|
13
|
+
|
|
14
|
+
const challengeRequester = createTRPCProxyClient<AppRouter>({
|
|
15
|
+
links: [
|
|
16
|
+
httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),
|
|
17
|
+
],
|
|
18
|
+
}) as Client;
|
|
19
|
+
|
|
20
|
+
const getChallenges = async (
|
|
21
|
+
amount = 95 + Math.round((Math.random() - 0.5) * 5)
|
|
22
|
+
): Promise<string[]> => {
|
|
23
|
+
return challengeRequester.utilities.getChallenges.query({ amount });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
getChallenges().then(result => (challenges = result));
|
|
27
|
+
|
|
28
|
+
const trpc = createTRPCProxyClient<AppRouter>({
|
|
29
|
+
links: [
|
|
30
|
+
callbackLink(async () => {
|
|
31
|
+
challenges = await getChallenges();
|
|
32
|
+
}),
|
|
33
|
+
httpBatchLink({
|
|
34
|
+
url,
|
|
35
|
+
headers: async () => {
|
|
36
|
+
if (challenges.length === 0) challenges.push(...(await getChallenges()));
|
|
37
|
+
|
|
38
|
+
return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
}) as Client;
|
|
43
|
+
|
|
44
|
+
return trpc;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default getClient;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"es2022",
|
|
5
|
+
"DOM"
|
|
6
|
+
],
|
|
7
|
+
"module": "esnext",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"removeComments": true,
|
|
11
|
+
"preserveConstEnums": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"alwaysStrict": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"noUncheckedIndexedAccess": true,
|
|
16
|
+
"noImplicitAny": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"noImplicitThis": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"allowUnreachableCode": false,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"target": "es2022",
|
|
24
|
+
"outDir": "dist",
|
|
25
|
+
"rootDir": "src",
|
|
26
|
+
"declaration": true,
|
|
27
|
+
"declarationMap": true,
|
|
28
|
+
"emitDeclarationOnly": true,
|
|
29
|
+
"sourceMap": true,
|
|
30
|
+
"esModuleInterop": true,
|
|
31
|
+
"allowSyntheticDefaultImports": true,
|
|
32
|
+
"allowJs": false,
|
|
33
|
+
"skipLibCheck": true,
|
|
34
|
+
"forceConsistentCasingInFileNames": true
|
|
35
|
+
},
|
|
36
|
+
"exclude": [
|
|
37
|
+
"./dist/**/*",
|
|
38
|
+
"./node_modules/**/*"
|
|
39
|
+
]
|
|
40
|
+
}
|