@learncard/network-brain-client 2.5.21 → 2.5.24

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/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { TRPCClient } from '@trpc/client';
2
2
  import type { AppRouter } from '@learncard/network-brain-service';
3
3
  export type LCNClient = TRPCClient<AppRouter>;
4
- export declare const getClient: (url: string, didAuthFunction: (challenge?: string) => Promise<string>) => Promise<LCNClient>;
5
- export declare const getApiTokenClient: (url: string, apiToken: string) => Promise<LCNClient>;
4
+ export type GuardianApprovalGetter = () => string | undefined | Promise<string | undefined>;
5
+ export declare const getClient: (url: string, didAuthFunction: (challenge?: string) => Promise<string>, guardianApprovalGetter?: GuardianApprovalGetter) => Promise<LCNClient>;
6
+ export declare const getApiTokenClient: (url: string, apiToken: string, guardianApprovalGetter?: GuardianApprovalGetter) => Promise<LCNClient>;
6
7
  export default getClient;
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAIlE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;AAE9C,eAAO,MAAM,SAAS,QACb,MAAM,mBACM,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,KACzD,OAAO,CAAC,SAAS,CAiDnB,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAe,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,SAAS,CAiBxF,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAIlE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;AAE9C,MAAM,MAAM,sBAAsB,GAAG,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAE5F,eAAO,MAAM,SAAS,QACb,MAAM,mBACM,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,2BAC/B,sBAAsB,KAChD,OAAO,CAAC,SAAS,CAwDnB,CAAC;AAGF,eAAO,MAAM,iBAAiB,QACrB,MAAM,YACD,MAAM,2BACS,sBAAsB,KAChD,OAAO,CAAC,SAAS,CA0BnB,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learncard/network-brain-client",
3
- "version": "2.5.21",
3
+ "version": "2.5.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/brain-client.esm.js",
@@ -11,12 +11,12 @@
11
11
  "devDependencies": {
12
12
  "dts-bundle-generator": "^6.10.0",
13
13
  "esbuild": "^0.27.1",
14
- "@learncard/types": "5.12.3",
15
- "@learncard/helpers": "1.2.9"
14
+ "@learncard/types": "5.13.2",
15
+ "@learncard/helpers": "1.2.12"
16
16
  },
17
17
  "dependencies": {
18
18
  "@trpc/client": "11.3.0",
19
- "@learncard/network-brain-service": "3.12.5"
19
+ "@learncard/network-brain-service": "3.13.2"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
package/src/index.ts CHANGED
@@ -6,9 +6,12 @@ import { callbackLink } from './callbackLink';
6
6
 
7
7
  export type LCNClient = TRPCClient<AppRouter>;
8
8
 
9
+ export type GuardianApprovalGetter = () => string | undefined | Promise<string | undefined>;
10
+
9
11
  export const getClient = async (
10
12
  url: string,
11
- didAuthFunction: (challenge?: string) => Promise<string>
13
+ didAuthFunction: (challenge?: string) => Promise<string>,
14
+ guardianApprovalGetter?: GuardianApprovalGetter
12
15
  ): Promise<LCNClient> => {
13
16
  let challenges: string[] = [];
14
17
 
@@ -47,7 +50,14 @@ export const getClient = async (
47
50
  headers: async () => {
48
51
  if (challenges.length === 0) challenges.push(...(await getChallenges()));
49
52
 
50
- return { Authorization: `Bearer ${await didAuthFunction(challenges.pop())}` };
53
+ const guardianApproval = guardianApprovalGetter
54
+ ? await guardianApprovalGetter()
55
+ : undefined;
56
+
57
+ return {
58
+ Authorization: `Bearer ${await didAuthFunction(challenges.pop())}`,
59
+ ...(guardianApproval ? { 'x-guardian-approval': guardianApproval } : {}),
60
+ };
51
61
  },
52
62
  transformer: {
53
63
  input: RegExpTransformer,
@@ -61,14 +71,27 @@ export const getClient = async (
61
71
  };
62
72
 
63
73
  // Create a client that always uses a provided API token and never fetches challenges
64
- export const getApiTokenClient = async (url: string, apiToken: string): Promise<LCNClient> => {
74
+ export const getApiTokenClient = async (
75
+ url: string,
76
+ apiToken: string,
77
+ guardianApprovalGetter?: GuardianApprovalGetter
78
+ ): Promise<LCNClient> => {
65
79
  const trpc = createTRPCClient<AppRouter>({
66
80
  links: [
67
81
  httpBatchLink({
68
82
  methodOverride: 'POST',
69
83
  url,
70
84
  maxURLLength: 3072,
71
- headers: { Authorization: `Bearer ${apiToken}` },
85
+ headers: async () => {
86
+ const guardianApproval = guardianApprovalGetter
87
+ ? await guardianApprovalGetter()
88
+ : undefined;
89
+
90
+ return {
91
+ Authorization: `Bearer ${apiToken}`,
92
+ ...(guardianApproval ? { 'x-guardian-approval': guardianApproval } : {}),
93
+ };
94
+ },
72
95
  transformer: {
73
96
  input: RegExpTransformer,
74
97
  output: { serialize: o => o, deserialize: o => o },