@learncard/learn-cloud-client 1.5.10 → 1.6.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 +39 -0
- package/dist/learn-cloud-client.cjs.development.js +15 -16
- package/dist/learn-cloud-client.cjs.development.js.map +1 -1
- package/dist/learn-cloud-client.cjs.production.min.js +1 -1
- package/dist/learn-cloud-client.cjs.production.min.js.map +2 -2
- package/dist/learn-cloud-client.esm.js +11 -13
- package/dist/learn-cloud-client.esm.js.map +1 -1
- package/package.json +13 -5
- package/scripts/build.mjs +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @learncard/network-brain-client
|
|
2
2
|
|
|
3
|
+
## 1.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`605f098e7c3ded38e236981dd3b3927860cb5869`](https://github.com/learningeconomy/LearnCard/commit/605f098e7c3ded38e236981dd3b3927860cb5869)]:
|
|
8
|
+
- @learncard/learn-cloud-service@2.4.3
|
|
9
|
+
|
|
10
|
+
## 1.6.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies []:
|
|
15
|
+
- @learncard/learn-cloud-service@2.4.2
|
|
16
|
+
|
|
17
|
+
## 1.6.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`4b1d40356ffd974915396fbee05d656f6c16f9c0`](https://github.com/learningeconomy/LearnCard/commit/4b1d40356ffd974915396fbee05d656f6c16f9c0)]:
|
|
22
|
+
- @learncard/learn-cloud-service@2.4.1
|
|
23
|
+
|
|
24
|
+
## 1.6.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- [#858](https://github.com/learningeconomy/LearnCard/pull/858) [`279e0491c5f284f9343ef0c39f3c38cd76e608f9`](https://github.com/learningeconomy/LearnCard/commit/279e0491c5f284f9343ef0c39f3c38cd76e608f9) Thanks [@Custard7](https://github.com/Custard7)! - Upgrade build tooling (esbuild `0.27.1`) and migrate to Zod v4 + TypeScript `5.9.3` across the monorepo.
|
|
29
|
+
|
|
30
|
+
This includes follow-up fixes for Zod v4 behavior and typing changes:
|
|
31
|
+
|
|
32
|
+
- Update query validators to preserve runtime deep-partial semantics while keeping TypeScript inference compatible with `{}` defaults.
|
|
33
|
+
- Prevent `.partial()` + `.default()` from materializing omitted fields in permission updates (`canManageChildrenProfiles`).
|
|
34
|
+
- Allow `Infinity` for generational query inputs in brain-service routes.
|
|
35
|
+
- Document running Vitest in non-watch mode (`pnpm test -- run`).
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [[`279e0491c5f284f9343ef0c39f3c38cd76e608f9`](https://github.com/learningeconomy/LearnCard/commit/279e0491c5f284f9343ef0c39f3c38cd76e608f9), [`bc81280ae6423a19c39f3596f3d88142b8fe0732`](https://github.com/learningeconomy/LearnCard/commit/bc81280ae6423a19c39f3596f3d88142b8fe0732)]:
|
|
40
|
+
- @learncard/learn-cloud-service@2.4.0
|
|
41
|
+
|
|
3
42
|
## 1.5.10
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -18,13 +19,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
|
|
20
21
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
default: () =>
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
default: () => index_default,
|
|
24
25
|
getApiTokenClient: () => getApiTokenClient,
|
|
25
26
|
getClient: () => getClient
|
|
26
27
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
29
|
var import_client = require("@trpc/client");
|
|
29
30
|
|
|
30
31
|
// src/callbackLink.ts
|
|
@@ -40,18 +41,17 @@ var callbackLink = /* @__PURE__ */ __name((callback) => {
|
|
|
40
41
|
attempts += 1;
|
|
41
42
|
request?.unsubscribe();
|
|
42
43
|
request = next(op).subscribe({
|
|
43
|
-
error: async (error) => {
|
|
44
|
+
error: /* @__PURE__ */ __name(async (error) => {
|
|
44
45
|
if (attempts > 5 || error.data?.httpStatus !== 401) {
|
|
45
46
|
return observer.error(error);
|
|
46
47
|
}
|
|
47
48
|
await callback();
|
|
48
49
|
attempt();
|
|
49
|
-
},
|
|
50
|
-
next: (result) => observer.next(result),
|
|
51
|
-
complete: () => {
|
|
52
|
-
if (isDone)
|
|
53
|
-
|
|
54
|
-
}
|
|
50
|
+
}, "error"),
|
|
51
|
+
next: /* @__PURE__ */ __name((result) => observer.next(result), "next"),
|
|
52
|
+
complete: /* @__PURE__ */ __name(() => {
|
|
53
|
+
if (isDone) observer.complete();
|
|
54
|
+
}, "complete")
|
|
55
55
|
});
|
|
56
56
|
}, "attempt");
|
|
57
57
|
attempt();
|
|
@@ -92,11 +92,10 @@ var getClient = /* @__PURE__ */ __name(async (url, didAuthFunction) => {
|
|
|
92
92
|
url,
|
|
93
93
|
maxItems: 50,
|
|
94
94
|
maxURLLength: 3072,
|
|
95
|
-
headers: async () => {
|
|
96
|
-
if (challenges.length === 0)
|
|
97
|
-
challenges.push(...await getChallenges());
|
|
95
|
+
headers: /* @__PURE__ */ __name(async () => {
|
|
96
|
+
if (challenges.length === 0) challenges.push(...await getChallenges());
|
|
98
97
|
return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
|
|
99
|
-
}
|
|
98
|
+
}, "headers")
|
|
100
99
|
})
|
|
101
100
|
]
|
|
102
101
|
});
|
|
@@ -115,4 +114,4 @@ var getApiTokenClient = /* @__PURE__ */ __name(async (url, apiToken) => {
|
|
|
115
114
|
});
|
|
116
115
|
return trpc;
|
|
117
116
|
}, "getApiTokenClient");
|
|
118
|
-
var
|
|
117
|
+
var index_default = getClient;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
4
|
"sourcesContent": ["import { createTRPCClient, TRPCClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Client = TRPCClient<AppRouter>;\n\nexport type LearnCloudClient = Client;\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 = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n maxItems: 50,\n headers: { Authorization: `Bearer ${await didAuthFunction()}` },\n }),\n ],\n });\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 = createTRPCClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxItems: 50,\n maxURLLength: 3072,\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 });\n\n return trpc;\n};\n\n// Create a client that always uses a provided API token and never fetches challenges\nexport const getApiTokenClient = async (url: string, apiToken: string): Promise<Client> => {\n const trpc = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n headers: { Authorization: `Bearer ${apiToken}` },\n }),\n ],\n });\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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4D;;;ACC5D,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,8BAAM,UAAS;AAClB,kBAAI,WAAW,KAAK,MAAM,MAAM,eAAe,KAAK;AAChD,uBAAO,SAAS,MAAM,KAAK;AAAA,cAC/B;AAEA,oBAAM,SAAS;AAEf,sBAAQ;AAAA,YACZ,GARO;AAAA,YASP,MAAM,mCAAU,SAAS,KAAK,MAAM,GAA9B;AAAA,YACN,UAAU,6BAAM;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QAAM,WAAO,gCAA4B;AAAA,IACrC,OAAO;AAAA,UACH,6BAAc;AAAA,QACV,gBAAgB;AAAA,QAChB;AAAA,QACA,cAAc;AAAA,QACd,SAAS,EAAE,eAAe,UAAU,QAAQ,GAAG;AAAA,MACnD,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX,GAbiC;AAejC,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var i=(t,e)=>p(t,"name",{value:e,configurable:!0});var b=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},P=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!R.call(t,n)&&n!==r&&p(t,n,{get:()=>e[n],enumerable:!(a=C(e,n))||a.enumerable});return t};var x=t=>P(p({},"__esModule",{value:!0}),t);var k={};b(k,{default:()=>f,getApiTokenClient:()=>L,getClient:()=>g});module.exports=x(k);var o=require("@trpc/client");var m=require("@trpc/server/observable");var h=i(t=>()=>({next:e,op:r})=>(0,m.observable)(a=>{let n=null,c=0,s=!1,u=i(()=>{c+=1,n?.unsubscribe(),n=e(r).subscribe({error:i(async l=>{if(c>5||l.data?.httpStatus!==401)return a.error(l);await t(),u()},"error"),next:i(l=>a.next(l),"next"),complete:i(()=>{s&&a.complete()},"complete")})},"attempt");return u(),()=>{s=!0,n?.unsubscribe()}}),"callbackLink");var g=i(async(t,e)=>{let r=[],a=(0,o.createTRPCClient)({links:[(0,o.httpBatchLink)({methodOverride:"POST",url:t,maxURLLength:3072,maxItems:50,headers:{Authorization:`Bearer ${await e()}`}})]}),n=i(async(s=95+Math.round((Math.random()-.5)*5))=>a.utilities.getChallenges.query({amount:s}),"getChallenges");return n().then(s=>r=s),(0,o.createTRPCClient)({links:[h(async()=>{r=await n()}),(0,o.httpBatchLink)({methodOverride:"POST",url:t,maxItems:50,maxURLLength:3072,headers:i(async()=>(r.length===0&&r.push(...await n()),{Authorization:`Bearer ${await e(r.pop())}`}),"headers")})]})},"getClient"),L=i(async(t,e)=>(0,o.createTRPCClient)({links:[(0,o.httpBatchLink)({methodOverride:"POST",url:t,maxURLLength:3072,headers:{Authorization:`Bearer ${e}`}})]}),"getApiTokenClient"),f=g;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
4
|
"sourcesContent": ["import { createTRPCClient, TRPCClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Client = TRPCClient<AppRouter>;\n\nexport type LearnCloudClient = Client;\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 = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n maxItems: 50,\n headers: { Authorization: `Bearer ${await didAuthFunction()}` },\n }),\n ],\n });\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 = createTRPCClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxItems: 50,\n maxURLLength: 3072,\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 });\n\n return trpc;\n};\n\n// Create a client that always uses a provided API token and never fetches challenges\nexport const getApiTokenClient = async (url: string, apiToken: string): Promise<Client> => {\n const trpc = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n headers: { Authorization: `Bearer ${apiToken}` },\n }),\n ],\n });\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": "
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,sBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAA4D,wBCC5D,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,MAAOH,EAAA,MAAMS,GAAS,CAClB,GAAIH,EAAW,GAAKG,EAAM,MAAM,aAAe,IAC3C,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cAAe,UAAUS,CAAQ,EAAG,CACnD,CAAC,CACL,CACJ,CAAC,EAV4B,qBAe1BC,EAAQZ",
|
|
6
|
+
"names": ["index_exports", "__export", "index_default", "getApiTokenClient", "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", "getApiTokenClient", "apiToken", "index_default"]
|
|
7
7
|
}
|
|
@@ -17,18 +17,17 @@ var callbackLink = /* @__PURE__ */ __name((callback) => {
|
|
|
17
17
|
attempts += 1;
|
|
18
18
|
request?.unsubscribe();
|
|
19
19
|
request = next(op).subscribe({
|
|
20
|
-
error: async (error) => {
|
|
20
|
+
error: /* @__PURE__ */ __name(async (error) => {
|
|
21
21
|
if (attempts > 5 || error.data?.httpStatus !== 401) {
|
|
22
22
|
return observer.error(error);
|
|
23
23
|
}
|
|
24
24
|
await callback();
|
|
25
25
|
attempt();
|
|
26
|
-
},
|
|
27
|
-
next: (result) => observer.next(result),
|
|
28
|
-
complete: () => {
|
|
29
|
-
if (isDone)
|
|
30
|
-
|
|
31
|
-
}
|
|
26
|
+
}, "error"),
|
|
27
|
+
next: /* @__PURE__ */ __name((result) => observer.next(result), "next"),
|
|
28
|
+
complete: /* @__PURE__ */ __name(() => {
|
|
29
|
+
if (isDone) observer.complete();
|
|
30
|
+
}, "complete")
|
|
32
31
|
});
|
|
33
32
|
}, "attempt");
|
|
34
33
|
attempt();
|
|
@@ -69,11 +68,10 @@ var getClient = /* @__PURE__ */ __name(async (url, didAuthFunction) => {
|
|
|
69
68
|
url,
|
|
70
69
|
maxItems: 50,
|
|
71
70
|
maxURLLength: 3072,
|
|
72
|
-
headers: async () => {
|
|
73
|
-
if (challenges.length === 0)
|
|
74
|
-
challenges.push(...await getChallenges());
|
|
71
|
+
headers: /* @__PURE__ */ __name(async () => {
|
|
72
|
+
if (challenges.length === 0) challenges.push(...await getChallenges());
|
|
75
73
|
return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
|
|
76
|
-
}
|
|
74
|
+
}, "headers")
|
|
77
75
|
})
|
|
78
76
|
]
|
|
79
77
|
});
|
|
@@ -92,9 +90,9 @@ var getApiTokenClient = /* @__PURE__ */ __name(async (url, apiToken) => {
|
|
|
92
90
|
});
|
|
93
91
|
return trpc;
|
|
94
92
|
}, "getApiTokenClient");
|
|
95
|
-
var
|
|
93
|
+
var index_default = getClient;
|
|
96
94
|
export {
|
|
97
|
-
|
|
95
|
+
index_default as default,
|
|
98
96
|
getApiTokenClient,
|
|
99
97
|
getClient
|
|
100
98
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/callbackLink.ts"],
|
|
4
4
|
"sourcesContent": ["import { createTRPCClient, TRPCClient, httpBatchLink } from '@trpc/client';\nimport type { AppRouter } from '@learncard/learn-cloud-service';\n\nimport { callbackLink } from './callbackLink';\n\ntype Client = TRPCClient<AppRouter>;\n\nexport type LearnCloudClient = Client;\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 = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n maxItems: 50,\n headers: { Authorization: `Bearer ${await didAuthFunction()}` },\n }),\n ],\n });\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 = createTRPCClient<AppRouter>({\n links: [\n callbackLink(async () => {\n challenges = await getChallenges();\n }),\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxItems: 50,\n maxURLLength: 3072,\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 });\n\n return trpc;\n};\n\n// Create a client that always uses a provided API token and never fetches challenges\nexport const getApiTokenClient = async (url: string, apiToken: string): Promise<Client> => {\n const trpc = createTRPCClient<AppRouter>({\n links: [\n httpBatchLink({\n methodOverride: 'POST',\n url,\n maxURLLength: 3072,\n headers: { Authorization: `Bearer ${apiToken}` },\n }),\n ],\n });\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,kBAA8B,qBAAqB;;;ACC5D,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,
|
|
5
|
+
"mappings": ";;;;AAAA,SAAS,kBAA8B,qBAAqB;;;ACC5D,SAAS,kBAAkC;AAGpC,IAAM,eAA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EpD,QAAM,OAAO,iBAA4B;AAAA,IACrC,OAAO;AAAA,MACH,aAAa,YAAY;AACrB,qBAAa,MAAM,cAAc;AAAA,MACrC,CAAC;AAAA,MACD,cAAc;AAAA,QACV,gBAAgB;AAAA,QAChB;AAAA,QACA,UAAU;AAAA,QACV,cAAc;AAAA,QACd,SAAS,mCAAY;AACjB,cAAI,WAAW,WAAW,EAAG,YAAW,KAAK,GAAI,MAAM,cAAc,CAAE;AAEvE,iBAAO,EAAE,eAAe,UAAU,MAAM,gBAAgB,WAAW,IAAI,CAAC,CAAC,GAAG;AAAA,QAChF,GAJS;AAAA,MAKb,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX,GA9CyB;AAiDlB,IAAM,oBAAoB,8BAAO,KAAa,aAAsC;AACvF,QAAM,OAAO,iBAA4B;AAAA,IACrC,OAAO;AAAA,MACH,cAAc;AAAA,QACV,gBAAgB;AAAA,QAChB;AAAA,QACA,cAAc;AAAA,QACd,SAAS,EAAE,eAAe,UAAU,QAAQ,GAAG;AAAA,MACnD,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX,GAbiC;AAejC,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@learncard/learn-cloud-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/learn-cloud-client.esm.js",
|
|
@@ -10,12 +10,20 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"dts-bundle-generator": "^6.10.0",
|
|
13
|
-
"esbuild": "^0.
|
|
14
|
-
"@learncard/types": "5.
|
|
13
|
+
"esbuild": "^0.27.1",
|
|
14
|
+
"@learncard/types": "5.11.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@trpc/client": "^11.
|
|
18
|
-
"@learncard/learn-cloud-service": "2.3
|
|
17
|
+
"@trpc/client": "^11.7.1",
|
|
18
|
+
"@learncard/learn-cloud-service": "2.4.3"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/learningeconomy/LearnCard"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/learningeconomy/LearnCard/tree/main/packages/learn-card-network/cloud-client/README.md",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/learningeconomy/LearnCard/issues"
|
|
19
27
|
},
|
|
20
28
|
"scripts": {
|
|
21
29
|
"build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.js && tsc --p tsconfig.json"
|
package/scripts/build.mjs
CHANGED
|
@@ -21,7 +21,6 @@ const configurations = [
|
|
|
21
21
|
keepNames: true,
|
|
22
22
|
bundle: true,
|
|
23
23
|
sourcemap: 'external',
|
|
24
|
-
incremental: true,
|
|
25
24
|
tsconfig: 'tsconfig.json',
|
|
26
25
|
plugins: [nodeResolveExternal],
|
|
27
26
|
entryPoints: ['src/index.ts'],
|
|
@@ -32,7 +31,6 @@ const configurations = [
|
|
|
32
31
|
keepNames: true,
|
|
33
32
|
bundle: true,
|
|
34
33
|
sourcemap: 'external',
|
|
35
|
-
incremental: true,
|
|
36
34
|
tsconfig: 'tsconfig.json',
|
|
37
35
|
plugins: [nodeResolveExternal],
|
|
38
36
|
entryPoints: ['src/index.ts'],
|
|
@@ -44,7 +42,6 @@ const configurations = [
|
|
|
44
42
|
keepNames: true,
|
|
45
43
|
bundle: true,
|
|
46
44
|
sourcemap: 'external',
|
|
47
|
-
incremental: true,
|
|
48
45
|
tsconfig: 'tsconfig.json',
|
|
49
46
|
plugins: [nodeResolveExternal],
|
|
50
47
|
entryPoints: ['src/index.ts'],
|