@txstate-mws/sveltekit-utils 1.3.0 → 1.3.2

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/api.d.ts CHANGED
@@ -152,6 +152,10 @@ export declare class APIBase {
152
152
  * and it will be returned as the `data` property.
153
153
  */
154
154
  mutationForDialog(resp: MutationResponseFromAPI): SubmitResponse<undefined>;
155
+ mutationForDialog<T extends MutationResponseFromAPI, K extends keyof T>(resp: T, { prefix, dataName }: {
156
+ prefix?: string;
157
+ dataName: K;
158
+ }): SubmitResponse<T[K]>;
155
159
  mutationForDialog(resp: MutationResponseFromAPI, { prefix }: {
156
160
  prefix?: string;
157
161
  }): SubmitResponse<undefined>;
@@ -1 +1 @@
1
- {"root":["../src/api.ts","../src/index.ts","../src/unifiedauth.ts"],"version":"5.8.3"}
1
+ {"root":["../src/api.ts","../src/index.ts","../src/unifiedauth.ts"],"version":"5.9.3"}
@@ -1,16 +1,14 @@
1
1
  import { redirect } from '@sveltejs/kit';
2
2
  import { isBlank, Cache } from 'txstate-utils';
3
3
  import { decodeJwt } from 'jose';
4
- const mayImpersonateAnyCache = new Cache(async (api) => {
5
- if (isBlank(api.token))
6
- return false;
4
+ const mayImpersonateAnyCache = new Cache(async (token, api) => {
7
5
  const authUrl = new URL(api.authRedirect);
8
6
  const mayImpersonateUrl = new URL('/mayImpersonate', authUrl.origin);
9
7
  try {
10
8
  const resp = await fetch(mayImpersonateUrl, {
11
9
  method: 'POST',
12
10
  headers: {
13
- 'Authorization': `Bearer ${api.token}`,
11
+ 'Authorization': `Bearer ${token}`,
14
12
  'Content-Type': 'application/json'
15
13
  },
16
14
  body: JSON.stringify({})
@@ -24,16 +22,14 @@ const mayImpersonateAnyCache = new Cache(async (api) => {
24
22
  return false;
25
23
  }
26
24
  });
27
- const mayImpersonateNetidCache = new Cache(async (api, netid) => {
28
- if (isBlank(api.token))
29
- return false;
25
+ const mayImpersonateNetidCache = new Cache(async ({ token, netid }, api) => {
30
26
  const authUrl = new URL(api.authRedirect);
31
27
  const mayImpersonateUrl = new URL('/mayImpersonate', authUrl.origin);
32
28
  try {
33
29
  const resp = await fetch(mayImpersonateUrl, {
34
30
  method: 'POST',
35
31
  headers: {
36
- 'Authorization': `Bearer ${api.token}`,
32
+ 'Authorization': `Bearer ${token}`,
37
33
  'Content-Type': 'application/json'
38
34
  },
39
35
  body: JSON.stringify({ netid })
@@ -170,7 +166,9 @@ export const unifiedAuth = {
170
166
  * @returns A promise that resolves to true if authorized to impersonate, false otherwise
171
167
  */
172
168
  async mayImpersonateAny(api) {
173
- return await mayImpersonateAnyCache.get(api);
169
+ if (isBlank(api.token))
170
+ return false;
171
+ return await mayImpersonateAnyCache.get(api.token, api);
174
172
  },
175
173
  /**
176
174
  * Check if the current user is authorized to impersonate a specific user.
@@ -181,6 +179,8 @@ export const unifiedAuth = {
181
179
  * @returns A promise that resolves to true if authorized, false otherwise
182
180
  */
183
181
  async mayImpersonate(api, netid) {
184
- return await mayImpersonateNetidCache.get(api, netid);
182
+ if (isBlank(api.token))
183
+ return false;
184
+ return await mayImpersonateNetidCache.get({ token: api.token, netid }, api);
185
185
  }
186
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/sveltekit-utils",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Shared library for code that is specifically tied to sveltekit in addition to svelte.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  "@sveltejs/kit": "^2.5.4",
16
16
  "@txstate-mws/fastify-shared": "^1.0.4",
17
17
  "@txstate-mws/svelte-components": "^1.6.1",
18
- "@txstate-mws/svelte-forms": "^1.5.8",
18
+ "@txstate-mws/svelte-forms": "^2.0.0",
19
19
  "jose": "^5.0.0",
20
20
  "txstate-utils": "^1.8.15"
21
21
  },