@learncard/learn-cloud-client 1.0.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.
package/.env ADDED
@@ -0,0 +1,7 @@
1
+ # Wait 60 seconds before connecting using these details, or login to https://console.neo4j.io to validate the Aura Instance is available
2
+ NEO4J_URI=neo4j+s://ab9edde2.databases.neo4j.io
3
+ NEO4J_USERNAME=neo4j
4
+ NEO4J_PASSWORD=V58sFdxds9E42A62bD1oA39AONg8fl8tNSMXCCQomow
5
+ AURA_INSTANCENAME=Instance01
6
+
7
+ SEED=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
package/CHANGELOG.md ADDED
@@ -0,0 +1,171 @@
1
+ # @learncard/network-brain-client
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#300](https://github.com/learningeconomy/LearnCard/pull/300) [`2e80eb8`](https://github.com/learningeconomy/LearnCard/commit/2e80eb83fc5ee2b954b40cc020ad5c790b571209) Thanks [@TaylorBeeston](https://github.com/TaylorBeeston)! - LearnCloud Initial Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`2e80eb8`](https://github.com/learningeconomy/LearnCard/commit/2e80eb83fc5ee2b954b40cc020ad5c790b571209), [`2e80eb8`](https://github.com/learningeconomy/LearnCard/commit/2e80eb83fc5ee2b954b40cc020ad5c790b571209)]:
12
+ - @learncard/learn-cloud-service@1.0.0
13
+
14
+ ## 1.1.12
15
+
16
+ ### Patch Changes
17
+
18
+ - [`74e459d`](https://github.com/learningeconomy/LearnCard/commit/74e459d0089497cbf031d18305f33fa539f2a96f) Thanks [@TaylorBeeston](https://github.com/TaylorBeeston)! - Empty version bump
19
+
20
+ - Updated dependencies [[`74e459d`](https://github.com/learningeconomy/LearnCard/commit/74e459d0089497cbf031d18305f33fa539f2a96f)]:
21
+ - @learncard/network-brain-service@1.4.8
22
+
23
+ ## 1.1.11
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`4787227`](https://github.com/learningeconomy/LearnCard/commit/4787227c2e8a2b4ffa4c8b177920f80feed8a64b)]:
28
+ - @learncard/network-brain-service@1.4.7
29
+
30
+ ## 1.1.10
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`d6b7861`](https://github.com/learningeconomy/LearnCard/commit/d6b786120b803c7c940e560570438d5f688a2d0f)]:
35
+ - @learncard/network-brain-service@1.4.6
36
+
37
+ ## 1.1.9
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`4703488`](https://github.com/learningeconomy/LearnCard/commit/470348841414ecd4c91b0eed4a25b530e3fe4fa8)]:
42
+ - @learncard/network-brain-service@1.4.5
43
+
44
+ ## 1.1.8
45
+
46
+ ### Patch Changes
47
+
48
+ - No change, just forcible version bump
49
+
50
+ - Updated dependencies []:
51
+ - @learncard/network-brain-service@1.4.4
52
+
53
+ ## 1.1.7
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`abd556c`](https://github.com/learningeconomy/LearnCard/commit/abd556c63d7bf857bcc0d71e9cae769c115ade4c), [`b471409`](https://github.com/learningeconomy/LearnCard/commit/b471409ccd9a4a7c169971d3d4906b6a85355066), [`ed85667`](https://github.com/learningeconomy/LearnCard/commit/ed8566758f9218d41a97713bfc955ed14b49f5bf), [`b471409`](https://github.com/learningeconomy/LearnCard/commit/b471409ccd9a4a7c169971d3d4906b6a85355066)]:
58
+ - @learncard/network-brain-service@1.4.3
59
+
60
+ ## 1.1.6
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies [[`106977b`](https://github.com/learningeconomy/LearnCard/commit/106977b379487286b40023e467c2cb720ca195aa)]:
65
+ - @learncard/network-brain-service@1.4.2
66
+
67
+ ## 1.1.5
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies [[`cd55df3`](https://github.com/learningeconomy/LearnCard/commit/cd55df354d7786014727b3e8782e109a3fbc8b17)]:
72
+ - @learncard/network-brain-service@1.4.1
73
+
74
+ ## 1.1.4
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [[`82289ba`](https://github.com/learningeconomy/LearnCard/commit/82289bacb997880ae25eaf833afe5c9e4ad68c37)]:
79
+ - @learncard/network-brain-service@1.4.0
80
+
81
+ ## 1.1.3
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [[`8366a2c`](https://github.com/learningeconomy/LearnCard/commit/8366a2caeeda82febe373d4028f47970d94134f0), [`de46ebb`](https://github.com/learningeconomy/LearnCard/commit/de46ebb3d5f41677dacdce2bc50ea2fdd1450602), [`37133bf`](https://github.com/learningeconomy/LearnCard/commit/37133bf375a883c8086ba837c2155a609dea1912)]:
86
+ - @learncard/network-brain-service@1.3.3
87
+
88
+ ## 1.1.2
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies [[`d0d4a33`](https://github.com/learningeconomy/LearnCard/commit/d0d4a333c7a53a5fa2d14dafbb1c14c8d54c1cda)]:
93
+ - @learncard/network-brain-service@1.3.2
94
+
95
+ ## 1.1.1
96
+
97
+ ### Patch Changes
98
+
99
+ - [#252](https://github.com/learningeconomy/LearnCard/pull/252) [`f6abbd4`](https://github.com/learningeconomy/LearnCard/commit/f6abbd490e02f65d56465ec5853aa31cfd2ae40c) Thanks [@Custard7](https://github.com/Custard7)! - Update to prepare for LCA Notifications Webhook
100
+
101
+ Adds LCNNotification types for notification webhook payload
102
+ Updates learn card core getDidAuthVp() to use learnCard.id.did() instead of 'key' did method.
103
+ Removes previous notification microservice functions.
104
+ Adds SendNotification for sending notifications to external webhook service
105
+
106
+ - Updated dependencies [[`f6abbd4`](https://github.com/learningeconomy/LearnCard/commit/f6abbd490e02f65d56465ec5853aa31cfd2ae40c)]:
107
+ - @learncard/network-brain-service@1.3.1
108
+
109
+ ## 1.1.0
110
+
111
+ ### Minor Changes
112
+
113
+ - [#232](https://github.com/learningeconomy/LearnCard/pull/232) [`3606fec`](https://github.com/learningeconomy/LearnCard/commit/3606fec4c226828e51a3df6eb780e420935ebc94) Thanks [@wthomasmiii](https://github.com/wthomasmiii)! - Addition of push notification configs for hitting an http webhook
114
+
115
+ ## What is being done
116
+
117
+ On the backend learn-card-network we have done the following
118
+
119
+ 1. Added 2 new endpoints to the lambda service, one for registering, and one for unregistering
120
+ 2. Added both functions to the learncard Network plugin, hitting the tRPC client
121
+ 3. Triggerable push notifications are included with functions now, initalizing a class, then using its subfunctionality.
122
+
123
+ ## Why this was done
124
+
125
+ Was made to include hitting webhooks, that process notification sending.
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [[`3606fec`](https://github.com/learningeconomy/LearnCard/commit/3606fec4c226828e51a3df6eb780e420935ebc94)]:
130
+ - @learncard/network-brain-service@1.3.0
131
+
132
+ ## 1.0.4
133
+
134
+ ### Patch Changes
135
+
136
+ - [#249](https://github.com/learningeconomy/LearnCard/pull/249) [`6a1a143`](https://github.com/learningeconomy/LearnCard/commit/6a1a1431a3bfdec261e1c9386a774cadbca6a5a1) Thanks [@goblincore](https://github.com/goblincore)! - Republish
137
+
138
+ - Updated dependencies [[`6a1a143`](https://github.com/learningeconomy/LearnCard/commit/6a1a1431a3bfdec261e1c9386a774cadbca6a5a1)]:
139
+ - @learncard/network-brain-service@1.2.2
140
+
141
+ ## 1.0.3
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies []:
146
+ - @learncard/network-brain-service@1.2.1
147
+
148
+ ## 1.0.2
149
+
150
+ ### Patch Changes
151
+
152
+ - Updated dependencies [[`e69af5a`](https://github.com/learningeconomy/LearnCard/commit/e69af5ab09b88d111ddf207f413552aa0bac991a)]:
153
+ - @learncard/network-brain-service@1.2.0
154
+
155
+ ## 1.0.1
156
+
157
+ ### Patch Changes
158
+
159
+ - Updated dependencies [[`13d0393`](https://github.com/learningeconomy/LearnCard/commit/13d0393725d9d5e17b02de7a8088f46bda688d92), [`ed3c460`](https://github.com/learningeconomy/LearnCard/commit/ed3c460fadae88702c1244795ab3b7483d97bab7)]:
160
+ - @learncard/network-brain-service@1.1.0
161
+
162
+ ## 1.0.0
163
+
164
+ ### Major Changes
165
+
166
+ - [#213](https://github.com/learningeconomy/LearnCard/pull/213) [`2508bba`](https://github.com/learningeconomy/LearnCard/commit/2508bba1950faed5ebe4c92f6a5e3bf82114b9fe) Thanks [@TaylorBeeston](https://github.com/TaylorBeeston)! - Initial Release
167
+
168
+ ### Patch Changes
169
+
170
+ - Updated dependencies [[`2508bba`](https://github.com/learningeconomy/LearnCard/commit/2508bba1950faed5ebe4c92f6a5e3bf82114b9fe)]:
171
+ - @learncard/network-brain-service@1.0.0
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 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
+ © 2022 GitHub, Inc.
24
+ Footer navigation
25
+ Terms
@@ -0,0 +1,3 @@
1
+ import { TRPCLink } from '@trpc/client';
2
+ import type { AppRouter } from '@learncard/learn-cloud-service';
3
+ export declare const callbackLink: (callback: () => Promise<void>) => TRPCLink<AppRouter>;
@@ -0,0 +1,15 @@
1
+ import { CreateTRPCProxyClient } from '@trpc/client';
2
+ import type { inferRouterInputs } from '@trpc/server';
3
+ import type { JWE, PaginatedEncryptedCredentialRecordsType } from '@learncard/types';
4
+ import type { AppRouter } from '@learncard/learn-cloud-service';
5
+ type Inputs = inferRouterInputs<AppRouter>;
6
+ type Client = CreateTRPCProxyClient<AppRouter>;
7
+ type OverriddenClient = Omit<Client, 'index'> & {
8
+ index: Client['index'] & {
9
+ get: {
10
+ query: (args: Inputs['index']['get']) => Promise<PaginatedEncryptedCredentialRecordsType | JWE>;
11
+ };
12
+ };
13
+ };
14
+ export declare const getClient: (url: string, didAuthFunction: (challenge?: string) => Promise<string>) => Promise<OverriddenClient>;
15
+ export default getClient;
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./learn-cloud-client.cjs.production.min.js');
5
+ } else {
6
+ module.exports = require('./learn-cloud-client.cjs.development.js');
7
+ }
@@ -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
+ challenges = await getChallenges();
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 { inferRouterInputs } from '@trpc/server';\nimport type { JWE, PaginatedEncryptedCredentialRecordsType } from '@learncard/types';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Inputs = inferRouterInputs<AppRouter>;\n\ntype Client = CreateTRPCProxyClient<AppRouter>;\n\ntype OverriddenClient = Omit<Client, 'index'> & {\n index: Client['index'] & {\n get: {\n query: (\n args: Inputs['index']['get']\n ) => Promise<PaginatedEncryptedCredentialRecordsType | JWE>;\n };\n };\n};\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n) => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as OverriddenClient;\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 challenges = await getChallenges();\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 OverriddenClient;\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/learn-cloud-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,cAAM,UAAU,6BAAM;AAClB,sBAAY;AACZ,mBAAS,YAAY;AACrB,oBAAU,KAAK,EAAE,EAAE,UAAU;AAAA,YACzB,OAAO,OAAM,UAAS;AAClB,kBAAI,WAAW,KAAK,MAAM,MAAM,eAAe,KAAK;AAChD,uBAAO,SAAS,MAAM,KAAK;AAAA,cAC/B;AAEA,oBAAM,SAAS;AAEf,sBAAQ;AAAA,YACZ;AAAA,YACA,MAAM,YAAU,SAAS,KAAK,MAAM;AAAA,YACpC,UAAU,MAAM;AACZ,kBAAI;AAAQ,yBAAS,SAAS;AAAA,YAClC;AAAA,UACJ,CAAC;AAAA,QACL,GAlBgB;AAoBhB,gBAAQ;AAER,eAAO,MAAM;AACT,mBAAS;AACT,mBAAS,YAAY;AAAA,QACzB;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AACJ,GArC4B;;;ADiBrB,IAAM,YAAY,8BACrB,KACA,oBACC;AACD,MAAI,aAAuB,CAAC;AAE5B,QAAM,yBAAqB,qCAAiC;AAAA,IACxD,OAAO;AAAA,UACH,6BAAc,EAAE,KAAK,SAAS,EAAE,eAAe,UAAU,MAAM,gBAAgB,IAAI,EAAE,CAAC;AAAA,IAC1F;AAAA,EACJ,CAAC;AAED,QAAM,gBAAgB,8BAClB,SAAS,KAAK,KAAK,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,MAC9B;AACpB,WAAO,mBAAmB,UAAU,cAAc,MAAM,EAAE,OAAO,CAAC;AAAA,EACtE,GAJsB;AAMtB,eAAa,MAAM,cAAc;AAEjC,QAAM,WAAO,qCAAiC;AAAA,IAC1C,OAAO;AAAA,MACH,aAAa,YAAY;AACrB,qBAAa,MAAM,cAAc;AAAA,MACrC,CAAC;AAAA,UACD,6BAAc;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
+ }
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var a=(t,e)=>l(t,"name",{value:e,configurable:!0});var f=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},h=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of g(e))!R.call(t,r)&&r!==n&&l(t,r,{get:()=>e[r],enumerable:!(i=C(e,r))||i.enumerable});return t};var b=t=>h(l({},"__esModule",{value:!0}),t);var x={};f(x,{default:()=>P,getClient:()=>y});module.exports=b(x);var s=require("@trpc/client");var d=require("@trpc/server/observable");var m=a(t=>()=>({next:e,op:n})=>(0,d.observable)(i=>{let r=null,u=0,o=!1,c=a(()=>{u+=1,r?.unsubscribe(),r=e(n).subscribe({error:async p=>{if(u>5||p.data?.httpStatus!==401)return i.error(p);await t(),c()},next:p=>i.next(p),complete:()=>{o&&i.complete()}})},"attempt");return c(),()=>{o=!0,r?.unsubscribe()}}),"callbackLink");var y=a(async(t,e)=>{let n=[],i=(0,s.createTRPCProxyClient)({links:[(0,s.httpBatchLink)({url:t,headers:{Authorization:`Bearer ${await e()}`}})]}),r=a(async(o=95+Math.round((Math.random()-.5)*5))=>i.utilities.getChallenges.query({amount:o}),"getChallenges");return n=await r(),(0,s.createTRPCProxyClient)({links:[m(async()=>{n=await r()}),(0,s.httpBatchLink)({url:t,headers:async()=>(n.length===0&&n.push(...await r()),{Authorization:`Bearer ${await e(n.pop())}`})})]})},"getClient"),P=y;
@@ -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 { inferRouterInputs } from '@trpc/server';\nimport type { JWE, PaginatedEncryptedCredentialRecordsType } from '@learncard/types';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Inputs = inferRouterInputs<AppRouter>;\n\ntype Client = CreateTRPCProxyClient<AppRouter>;\n\ntype OverriddenClient = Omit<Client, 'index'> & {\n index: Client['index'] & {\n get: {\n query: (\n args: Inputs['index']['get']\n ) => Promise<PaginatedEncryptedCredentialRecordsType | JWE>;\n };\n };\n};\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n) => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as OverriddenClient;\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 challenges = await getChallenges();\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 OverriddenClient;\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/learn-cloud-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": "+cAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,cAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAA4E,wBCC5E,IAAAC,EAA2C,mCAGpC,IAAMC,EAAeC,EAACC,GAClB,IACI,CAAC,CAAE,KAAAC,EAAM,GAAAC,CAAG,OACR,cAAWC,GAAY,CAC1B,IAAIC,EAAiC,KACjCC,EAAW,EACXC,EAAS,GAEPC,EAAUR,EAAA,IAAM,CAClBM,GAAY,EACZD,GAAS,YAAY,EACrBA,EAAUH,EAAKC,CAAE,EAAE,UAAU,CACzB,MAAO,MAAMM,GAAS,CAClB,GAAIH,EAAW,GAAKG,EAAM,MAAM,aAAe,IAC3C,OAAOL,EAAS,MAAMK,CAAK,EAG/B,MAAMR,EAAS,EAEfO,EAAQ,CACZ,EACA,KAAME,GAAUN,EAAS,KAAKM,CAAM,EACpC,SAAU,IAAM,CACRH,GAAQH,EAAS,SAAS,CAClC,CACJ,CAAC,CACL,EAlBgB,WAoBhB,OAAAI,EAAQ,EAED,IAAM,CACTD,EAAS,GACTF,GAAS,YAAY,CACzB,CACJ,CAAC,EAlCe,gBDiBrB,IAAMM,EAAYC,EAAA,MACrBC,EACAC,IACC,CACD,IAAIC,EAAuB,CAAC,EAEtBC,KAAqB,yBAAiC,CACxD,MAAO,IACH,iBAAc,CAAE,IAAAH,EAAK,QAAS,CAAE,cAAe,UAAU,MAAMC,EAAgB,GAAI,CAAE,CAAC,CAC1F,CACJ,CAAC,EAEKG,EAAgBL,EAAA,MAClBM,EAAS,GAAK,KAAK,OAAO,KAAK,OAAO,EAAI,IAAO,CAAC,IAE3CF,EAAmB,UAAU,cAAc,MAAM,CAAE,OAAAE,CAAO,CAAC,EAHhD,iBAMtB,OAAAH,EAAa,MAAME,EAAc,KAEpB,yBAAiC,CAC1C,MAAO,CACHE,EAAa,SAAY,CACrBJ,EAAa,MAAME,EAAc,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,aAuClBK,EAAQT",
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", "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
+ challenges = await getChallenges();
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 { inferRouterInputs } from '@trpc/server';\nimport type { JWE, PaginatedEncryptedCredentialRecordsType } from '@learncard/types';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Inputs = inferRouterInputs<AppRouter>;\n\ntype Client = CreateTRPCProxyClient<AppRouter>;\n\ntype OverriddenClient = Omit<Client, 'index'> & {\n index: Client['index'] & {\n get: {\n query: (\n args: Inputs['index']['get']\n ) => Promise<PaginatedEncryptedCredentialRecordsType | JWE>;\n };\n };\n};\n\nexport const getClient = async (\n url: string,\n didAuthFunction: (challenge?: string) => Promise<string>\n) => {\n let challenges: string[] = [];\n\n const challengeRequester = createTRPCProxyClient<AppRouter>({\n links: [\n httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),\n ],\n }) as OverriddenClient;\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 challenges = await getChallenges();\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 OverriddenClient;\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/learn-cloud-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,SAAS,uBAA8C,qBAAqB;;;ACC5E,SAAS,kBAAkC;AAGpC,IAAM,eAAe,wBAAC,aAAuD;AAChF,SAAO,MAAM;AACT,WAAO,CAAC,EAAE,MAAM,GAAG,MAAM;AACrB,aAAO,WAAW,cAAY;AAC1B,YAAI,UAAiC;AACrC,YAAI,WAAW;AACf,YAAI,SAAS;AAEb,cAAM,UAAU,6BAAM;AAClB,sBAAY;AACZ,mBAAS,YAAY;AACrB,oBAAU,KAAK,EAAE,EAAE,UAAU;AAAA,YACzB,OAAO,OAAM,UAAS;AAClB,kBAAI,WAAW,KAAK,MAAM,MAAM,eAAe,KAAK;AAChD,uBAAO,SAAS,MAAM,KAAK;AAAA,cAC/B;AAEA,oBAAM,SAAS;AAEf,sBAAQ;AAAA,YACZ;AAAA,YACA,MAAM,YAAU,SAAS,KAAK,MAAM;AAAA,YACpC,UAAU,MAAM;AACZ,kBAAI;AAAQ,yBAAS,SAAS;AAAA,YAClC;AAAA,UACJ,CAAC;AAAA,QACL,GAlBgB;AAoBhB,gBAAQ;AAER,eAAO,MAAM;AACT,mBAAS;AACT,mBAAS,YAAY;AAAA,QACzB;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AACJ,GArC4B;;;ADiBrB,IAAM,YAAY,8BACrB,KACA,oBACC;AACD,MAAI,aAAuB,CAAC;AAE5B,QAAM,qBAAqB,sBAAiC;AAAA,IACxD,OAAO;AAAA,MACH,cAAc,EAAE,KAAK,SAAS,EAAE,eAAe,UAAU,MAAM,gBAAgB,IAAI,EAAE,CAAC;AAAA,IAC1F;AAAA,EACJ,CAAC;AAED,QAAM,gBAAgB,8BAClB,SAAS,KAAK,KAAK,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,MAC9B;AACpB,WAAO,mBAAmB,UAAU,cAAc,MAAM,EAAE,OAAO,CAAC;AAAA,EACtE,GAJsB;AAMtB,eAAa,MAAM,cAAc;AAEjC,QAAM,OAAO,sBAAiC;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
+ await build(finalBuildObj).then(() => {
24
+ console.log(`🎁 Done building main bundle! (${Date.now() - startTime}ms)`);
25
+ });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@learncard/learn-cloud-client",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "./dist/learn-cloud-client.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "keywords": [],
9
+ "author": "Learning Economy Foundation (www.learningeconomy.io)",
10
+ "license": "MIT",
11
+ "devDependencies": {
12
+ "dts-bundle-generator": "^6.10.0",
13
+ "esbuild": "^0.16.16",
14
+ "@learncard/types": "5.3.0"
15
+ },
16
+ "dependencies": {
17
+ "@trpc/client": "^10.17.0",
18
+ "@trpc/server": "^10.17.0",
19
+ "@learncard/learn-cloud-service": "1.0.0"
20
+ },
21
+ "scripts": {
22
+ "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.js && tsc --p tsconfig.json"
23
+ }
24
+ }
package/project.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "../../../node_modules/nx/schemas/project-schema.json",
3
+ "name": "learn-cloud-client",
4
+ "sourceRoot": "packages/learn-card-network/cloud-client/src",
5
+ "projectType": "library",
6
+ "root": "packages/learn-card-network/cloud-client",
7
+ "tags": [],
8
+ "implicitDependencies": ["types", "learn-cloud-service"],
9
+ "namedInputs": {
10
+ "source": ["{projectRoot}/src/**/*"],
11
+ "scripts": ["{projectRoot}/scripts/**/*"],
12
+ "dist": ["{projectRoot}/dist/**/*"]
13
+ },
14
+ "targets": {
15
+ "build": {
16
+ "executor": "nx:run-script",
17
+ "inputs": ["source", "scripts"],
18
+ "options": {
19
+ "script": "build"
20
+ }
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "root": false,
3
+ "env": {
4
+ "node": true
5
+ },
6
+ "rules": {
7
+ "no-console": "off",
8
+ "@typescript-eslint/no-var-requires": "off"
9
+ }
10
+ }
@@ -0,0 +1,83 @@
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/learn-cloud-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/learn-cloud-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/learn-cloud-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
+ await Promise.all(
69
+ configurations.map(async config => {
70
+ var dir = config.outdir || path.dirname(config.outfile);
71
+ await asyncRimraf(dir).catch(() => {
72
+ console.log('Unable to delete directory', dir);
73
+ });
74
+ })
75
+ );
76
+
77
+ await Promise.all(configurations.map(config => esbuild.build(config))).catch(err => {
78
+ console.error('❌ Build failed');
79
+ process.exit(1);
80
+ });
81
+
82
+ console.log('✔ Build successful');
83
+ process.exit(0);
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./learn-cloud-client.cjs.production.min.js');
5
+ } else {
6
+ module.exports = require('./learn-cloud-client.cjs.development.js');
7
+ }
@@ -0,0 +1,42 @@
1
+ import { TRPCLink } from '@trpc/client';
2
+ import { observable, Unsubscribable } from '@trpc/server/observable';
3
+ import type { AppRouter } from '@learncard/learn-cloud-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,61 @@
1
+ import { createTRPCProxyClient, CreateTRPCProxyClient, httpBatchLink } from '@trpc/client';
2
+ import type { inferRouterInputs } from '@trpc/server';
3
+ import type { JWE, PaginatedEncryptedCredentialRecordsType } from '@learncard/types';
4
+ import type { AppRouter } from '@learncard/learn-cloud-service';
5
+
6
+ import { callbackLink } from './callbackLink';
7
+
8
+ type Inputs = inferRouterInputs<AppRouter>;
9
+
10
+ type Client = CreateTRPCProxyClient<AppRouter>;
11
+
12
+ type OverriddenClient = Omit<Client, 'index'> & {
13
+ index: Client['index'] & {
14
+ get: {
15
+ query: (
16
+ args: Inputs['index']['get']
17
+ ) => Promise<PaginatedEncryptedCredentialRecordsType | JWE>;
18
+ };
19
+ };
20
+ };
21
+
22
+ export const getClient = async (
23
+ url: string,
24
+ didAuthFunction: (challenge?: string) => Promise<string>
25
+ ) => {
26
+ let challenges: string[] = [];
27
+
28
+ const challengeRequester = createTRPCProxyClient<AppRouter>({
29
+ links: [
30
+ httpBatchLink({ url, headers: { Authorization: `Bearer ${await didAuthFunction()}` } }),
31
+ ],
32
+ }) as OverriddenClient;
33
+
34
+ const getChallenges = async (
35
+ amount = 95 + Math.round((Math.random() - 0.5) * 5)
36
+ ): Promise<string[]> => {
37
+ return challengeRequester.utilities.getChallenges.query({ amount });
38
+ };
39
+
40
+ challenges = await getChallenges();
41
+
42
+ const trpc = createTRPCProxyClient<AppRouter>({
43
+ links: [
44
+ callbackLink(async () => {
45
+ challenges = await getChallenges();
46
+ }),
47
+ httpBatchLink({
48
+ url,
49
+ headers: async () => {
50
+ if (challenges.length === 0) challenges.push(...(await getChallenges()));
51
+
52
+ return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
53
+ },
54
+ }),
55
+ ],
56
+ }) as OverriddenClient;
57
+
58
+ return trpc;
59
+ };
60
+
61
+ export default getClient;
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["es2022"],
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "resolveJsonModule": true,
7
+ "removeComments": true,
8
+ "preserveConstEnums": true,
9
+ "strict": true,
10
+ "alwaysStrict": true,
11
+ "strictNullChecks": true,
12
+ "noUncheckedIndexedAccess": true,
13
+
14
+ "noImplicitAny": true,
15
+ "noImplicitReturns": true,
16
+ "noImplicitThis": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "allowUnreachableCode": false,
20
+ "noFallthroughCasesInSwitch": true,
21
+
22
+ "target": "es2022",
23
+ "outDir": "dist",
24
+ "rootDir": "src",
25
+ "declaration": true,
26
+ "emitDeclarationOnly": true,
27
+ "sourceMap": true,
28
+
29
+ "esModuleInterop": true,
30
+ "allowSyntheticDefaultImports": true,
31
+ "allowJs": false,
32
+ "skipLibCheck": true,
33
+ "forceConsistentCasingInFileNames": true
34
+ },
35
+ "exclude": ["./dist/**/*", "./node_modules/**/*"]
36
+ }