@jsb188/mday-web 1.1.8 → 1.1.11

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/package.json CHANGED
@@ -1,20 +1,36 @@
1
1
  {
2
- "name": "@jsb188/mday-web",
3
- "version": "1.1.8",
4
- "description": "Web components and utilities for Marketday app.",
5
- "license": "ISC",
6
- "author": "jsb188",
7
- "type": "module",
8
- "exports": {
9
- "./utils/route": "./src/utils/route-helpers.ts"
10
- },
11
- "dependencies": {},
12
- "peerDependencies": {
13
- "@jsb188/app": "1.1.8",
14
- "@jsb188/mday": "1.1.8",
15
- "@jsb188/react-web": "1.1.8"
16
- },
17
- "scripts": {
18
- "test": "echo \"Error: no test specified\" && exit 1"
19
- }
2
+ "name": "@jsb188/mday-web",
3
+ "version": "1.1.11",
4
+ "description": "Web components and utilities for Marketday app.",
5
+ "license": "ISC",
6
+ "author": "jsb188",
7
+ "type": "module",
8
+ "exports": {
9
+ "./libs/public-form-beacon": "./src/libs/public-form-beacon.ts",
10
+ "./libs/route-metadata.server": "./src/libs/route-metadata.server.ts",
11
+ "./utils/account-web": "./src/utils/account-web.ts",
12
+ "./utils/route": "./src/utils/route-helpers.ts",
13
+ "./utils/log-web": "./src/utils/log-web.ts",
14
+ "./utils/list-web": "./src/utils/list-web.ts",
15
+ "./utils/org-web": "./src/utils/org-web.ts",
16
+ "./utils/public-form": "./src/utils/public-form.ts",
17
+ "./utils/workflow-web": "./src/utils/workflow-web.ts",
18
+ "./modules/AgentDocs": "./src/modules/AgentDocs.tsx",
19
+ "./modules/DocAccessSettings": "./src/modules/DocAccessSettings.tsx",
20
+ "./modules/FieldDocEmail": "./src/modules/FieldDocEmail.tsx",
21
+ "./modules/Grids": "./src/modules/Grids.tsx",
22
+ "./ui/FieldDocEmailUI": "./src/ui/FieldDocEmailUI.tsx",
23
+ "./modules/RouteShell": "./src/modules/RouteShell.tsx"
24
+ },
25
+ "dependencies": {},
26
+ "peerDependencies": {
27
+ "@jsb188/app": "1.1.11",
28
+ "@jsb188/graphql": "1.1.11",
29
+ "@jsb188/mday": "1.1.11",
30
+ "@jsb188/react": "1.1.11",
31
+ "@jsb188/react-web": "1.1.11"
32
+ },
33
+ "scripts": {
34
+ "test": "vitest run --config ./vitest.config.ts --passWithNoTests"
35
+ }
20
36
  }
@@ -0,0 +1,67 @@
1
+ import { graphqlServerRequest } from '@jsb188/graphql/client';
2
+ import { AuthSession } from '@jsb188/react-web/utils/remix';
3
+
4
+ /*
5
+ * Fetch one GraphQL metadata field with the supplied viewer token.
6
+ */
7
+ async function fetchRouteMetadataWithToken<T>(
8
+ query: any,
9
+ variables: Record<string, unknown>,
10
+ resultKey: string,
11
+ authToken: string | null,
12
+ ): Promise<T | null> {
13
+ try {
14
+ const result = await graphqlServerRequest(query, variables, {
15
+ authToken,
16
+ cacheAccountId: '*',
17
+ });
18
+
19
+ return (result?.[resultKey] as T | null | undefined) || null;
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ /*
26
+ * Fetch one metadata field with optional authentication for a public route.
27
+ */
28
+ export async function fetchRouteMetadata<T>(
29
+ request: Request,
30
+ query: any,
31
+ variables: Record<string, unknown>,
32
+ resultKey: string,
33
+ ): Promise<T | null> {
34
+ const session = await AuthSession.getSession(request.headers.get('Cookie'));
35
+ const authToken = session.get('auth_token') || null;
36
+
37
+ return await fetchRouteMetadataWithToken<T>(
38
+ query,
39
+ variables,
40
+ resultKey,
41
+ authToken,
42
+ );
43
+ }
44
+
45
+ /*
46
+ * Fetch one authenticated metadata field without letting metadata failures
47
+ * replace the route's primary page response.
48
+ */
49
+ export async function fetchAuthenticatedRouteMetadata<T>(
50
+ request: Request,
51
+ query: any,
52
+ variables: Record<string, unknown>,
53
+ resultKey: string,
54
+ ): Promise<T | null> {
55
+ const session = await AuthSession.getSession(request.headers.get('Cookie'));
56
+ const authToken = session.get('auth_token') || null;
57
+ if (!authToken) {
58
+ return null;
59
+ }
60
+
61
+ return await fetchRouteMetadataWithToken<T>(
62
+ query,
63
+ variables,
64
+ resultKey,
65
+ authToken,
66
+ );
67
+ }