@burdenoff/microfe-notification 2026.531.1 → 2026.601.1
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.
|
@@ -1,56 +1,86 @@
|
|
|
1
1
|
import { getMainDefinition as e } from "../node_modules/@apollo/client/utilities/internal/getMainDefinition.js";
|
|
2
2
|
import { GraphQLWsLink as t } from "../node_modules/@apollo/client/link/subscriptions/index.js";
|
|
3
3
|
import { createClient as n } from "../node_modules/graphql-ws/dist/client.js";
|
|
4
|
-
import { ApolloClient as r,
|
|
5
|
-
import { setContext as
|
|
6
|
-
import { onError as
|
|
7
|
-
import { isAuthNetworkError as
|
|
4
|
+
import { ApolloClient as r, ApolloLink as i, HttpLink as a, InMemoryCache as o, Observable as s, from as c, split as l } from "@apollo/client";
|
|
5
|
+
import { setContext as u } from "@apollo/client/link/context";
|
|
6
|
+
import { onError as d } from "@apollo/client/link/error";
|
|
7
|
+
import { isAuthNetworkError as f, redirectToLogin as p } from "@burdenoff/fe-libs/shared/utils";
|
|
8
8
|
//#region src/graphql/global-client.ts
|
|
9
|
-
function
|
|
9
|
+
function m(e = []) {
|
|
10
10
|
return e.some((e) => {
|
|
11
11
|
let t = typeof e.extensions?.code == "string" ? e.extensions.code : "", n = typeof e.extensions?.errorCode == "string" ? e.extensions.errorCode : "", r = (e.message ?? "").toLowerCase();
|
|
12
12
|
return t === "UNAUTHENTICATED" || n === "TOKEN_EXPIRED" || r.includes("token_expired") || r.includes("token expired") || r.includes("session expired") || r.includes("unauthorized") || r.includes("unauthenticated") || r.includes("authentication required") || r.includes("workspace context missing");
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
function h(t) {
|
|
16
|
+
let n = e(t);
|
|
17
|
+
return n.kind === "OperationDefinition" && n.operation === "mutation";
|
|
18
|
+
}
|
|
16
19
|
function g(e) {
|
|
20
|
+
let t = e.errors;
|
|
21
|
+
return Array.isArray(t) && t.length > 0;
|
|
22
|
+
}
|
|
23
|
+
function _(e) {
|
|
24
|
+
return new i((t, n) => {
|
|
25
|
+
let r = h(t.query) && t.getContext().autoRefreshAfterMutation !== !1 && t.getContext().skipMutationAutoRefresh !== !0;
|
|
26
|
+
return new s((i) => {
|
|
27
|
+
let a = n(t).subscribe({
|
|
28
|
+
next: (t) => {
|
|
29
|
+
i.next(t), !(!r || g(t)) && e()?.refetchQueries({ include: "active" });
|
|
30
|
+
},
|
|
31
|
+
error: (e) => {
|
|
32
|
+
i.error(e);
|
|
33
|
+
},
|
|
34
|
+
complete: () => {
|
|
35
|
+
i.complete();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
a.unsubscribe();
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var v = null, y = null, b = null;
|
|
45
|
+
function x(e) {
|
|
17
46
|
let t = e.replace(/\/$/, "");
|
|
18
47
|
return t.endsWith("/graphql") ? t : t.endsWith("/global") ? `${t}/graphql` : `${t}/global/graphql`;
|
|
19
48
|
}
|
|
20
|
-
function
|
|
49
|
+
function S(e) {
|
|
21
50
|
return e.startsWith("https://") ? e.replace("https://", "wss://") : e.startsWith("http://") ? e.replace("http://", "ws://") : e;
|
|
22
51
|
}
|
|
23
|
-
function
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
url:
|
|
29
|
-
connectionParams: () => ({ authorization:
|
|
52
|
+
function C(i, s) {
|
|
53
|
+
let h = x(i || "https://gw-global.local.burdenoff.com/global/graphql"), g = s ?? null;
|
|
54
|
+
if (v && y === h && b === g) return v;
|
|
55
|
+
y = h, b = g;
|
|
56
|
+
let C = new a({ uri: h }), w = typeof window < "u" ? new t(n({
|
|
57
|
+
url: S(h),
|
|
58
|
+
connectionParams: () => ({ authorization: s ? `Bearer ${s}` : "" }),
|
|
30
59
|
lazy: !0,
|
|
31
60
|
retryAttempts: 3
|
|
32
|
-
})) : null,
|
|
61
|
+
})) : null, T = u((e, t) => ({ headers: {
|
|
33
62
|
...t.headers,
|
|
34
|
-
authorization:
|
|
35
|
-
} }))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
authorization: s ? `Bearer ${s}` : ""
|
|
64
|
+
} })), E = d(({ error: e }) => {
|
|
65
|
+
if (e) {
|
|
66
|
+
if (m("errors" in e && Array.isArray(e.errors) ? e.errors : [])) {
|
|
67
|
+
p();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
e instanceof Error && f(e) && p();
|
|
71
|
+
}
|
|
72
|
+
}), D = w ? l(({ query: t }) => {
|
|
73
|
+
let n = e(t);
|
|
74
|
+
return n.kind === "OperationDefinition" && n.operation === "subscription";
|
|
75
|
+
}, w, C) : C;
|
|
76
|
+
return v = new r({
|
|
77
|
+
link: c([
|
|
78
|
+
E,
|
|
79
|
+
_(() => v),
|
|
80
|
+
T,
|
|
81
|
+
D
|
|
52
82
|
]),
|
|
53
|
-
cache: new
|
|
83
|
+
cache: new o({ typePolicies: {
|
|
54
84
|
Query: { fields: {
|
|
55
85
|
notifications: { merge(e, t) {
|
|
56
86
|
return t;
|
|
@@ -67,9 +97,9 @@ function v(v, y) {
|
|
|
67
97
|
query: { fetchPolicy: "cache-first" },
|
|
68
98
|
mutate: { fetchPolicy: "network-only" }
|
|
69
99
|
}
|
|
70
|
-
}),
|
|
100
|
+
}), v;
|
|
71
101
|
}
|
|
72
102
|
//#endregion
|
|
73
|
-
export {
|
|
103
|
+
export { C as getGlobalNotificationClient };
|
|
74
104
|
|
|
75
105
|
//# sourceMappingURL=global-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-client.js","names":[],"sources":["../../src/graphql/global-client.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"global-client.js","names":[],"sources":["../../src/graphql/global-client.ts"],"sourcesContent":["import {\n ApolloClient,\n ApolloLink,\n type FetchResult,\n InMemoryCache,\n HttpLink,\n Observable,\n from,\n split,\n} from '@apollo/client';\nimport { setContext } from '@apollo/client/link/context';\nimport { onError } from '@apollo/client/link/error';\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions';\nimport { getMainDefinition } from '@apollo/client/utilities';\nimport { isAuthNetworkError, redirectToLogin } from '@burdenoff/fe-libs/shared/utils';\nimport { createClient } from 'graphql-ws';\n\nfunction hasSessionAuthErrors(\n errors: ReadonlyArray<{ message?: string; extensions?: Record<string, unknown> }> = []\n): boolean {\n return errors.some((error) => {\n const code = typeof error.extensions?.code === 'string' ? error.extensions.code : '';\n const errorCode =\n typeof error.extensions?.errorCode === 'string' ? error.extensions.errorCode : '';\n const message = (error.message ?? '').toLowerCase();\n\n return (\n code === 'UNAUTHENTICATED' ||\n errorCode === 'TOKEN_EXPIRED' ||\n message.includes('token_expired') ||\n message.includes('token expired') ||\n message.includes('session expired') ||\n message.includes('unauthorized') ||\n message.includes('unauthenticated') ||\n message.includes('authentication required') ||\n message.includes('workspace context missing')\n );\n });\n}\n\nfunction isMutationOperation(query: Parameters<typeof getMainDefinition>[0]): boolean {\n const definition = getMainDefinition(query);\n return definition.kind === 'OperationDefinition' && definition.operation === 'mutation';\n}\n\nfunction hasGraphQLResultErrors(result: FetchResult<Record<string, unknown>>): boolean {\n const errors = result.errors;\n return Array.isArray(errors) && errors.length > 0;\n}\n\nfunction createMutationAutoRefreshLink(\n getClient: () => InstanceType<typeof ApolloClient> | null\n): ApolloLink {\n return new ApolloLink((operation, forward) => {\n const shouldRefreshAfterMutation =\n isMutationOperation(operation.query) &&\n operation.getContext().autoRefreshAfterMutation !== false &&\n operation.getContext().skipMutationAutoRefresh !== true;\n\n return new Observable<FetchResult<Record<string, unknown>>>((observer) => {\n const subscription = forward(operation).subscribe({\n next: (result) => {\n observer.next(result as FetchResult<Record<string, unknown>>);\n if (!shouldRefreshAfterMutation || hasGraphQLResultErrors(result)) return;\n\n void getClient()?.refetchQueries({ include: 'active' });\n },\n error: (error: unknown) => {\n observer.error(error);\n },\n complete: () => {\n observer.complete();\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n });\n });\n}\n\nlet globalClientInstance: InstanceType<typeof ApolloClient> | null = null;\nlet currentGlobalUrl: string | null = null;\nlet currentAuthToken: string | null = null;\n\n/**\n * Default Global Gateway URL\n * Notifications are a GLOBAL service and must use the global gateway\n */\nexport const DEFAULT_GLOBAL_GATEWAY_URL = 'https://gw-global.local.burdenoff.com/global/graphql';\n\nfunction toGraphqlUrl(url: string): string {\n const normalized = url.replace(/\\/$/, '');\n if (normalized.endsWith('/graphql')) return normalized;\n if (normalized.endsWith('/global')) return `${normalized}/graphql`;\n return `${normalized}/global/graphql`;\n}\n\nfunction toSubscriptionUrl(url: string): string {\n if (url.startsWith('https://')) return url.replace('https://', 'wss://');\n if (url.startsWith('http://')) return url.replace('http://', 'ws://');\n return url;\n}\n\n/**\n * Get or create the singleton Apollo client for global notification operations\n *\n * @param globalGatewayUrl - Global Gateway GraphQL URL (default: https://gw-global.local.burdenoff.com/global/graphql)\n * @param authToken - Optional JWT auth token\n */\nexport function getGlobalNotificationClient(\n globalGatewayUrl?: string,\n authToken?: string\n): InstanceType<typeof ApolloClient> {\n const url = toGraphqlUrl(globalGatewayUrl || DEFAULT_GLOBAL_GATEWAY_URL);\n const nextAuthToken = authToken ?? null;\n\n // Return existing instance if config hasn't changed\n if (globalClientInstance && currentGlobalUrl === url && currentAuthToken === nextAuthToken) {\n return globalClientInstance;\n }\n\n // Update current config\n currentGlobalUrl = url;\n currentAuthToken = nextAuthToken;\n\n const httpLink = new HttpLink({\n uri: url,\n });\n\n const wsLink =\n typeof window !== 'undefined'\n ? new GraphQLWsLink(\n createClient({\n url: toSubscriptionUrl(url),\n connectionParams: () => ({\n authorization: authToken ? `Bearer ${authToken}` : '',\n }),\n lazy: true,\n retryAttempts: 3,\n })\n )\n : null;\n\n const authLink = setContext((_, prevContext) => {\n return {\n headers: {\n ...(prevContext.headers as Record<string, string>),\n authorization: authToken ? `Bearer ${authToken}` : '',\n },\n };\n });\n\n const errorLink = onError(({ error }) => {\n if (!error) return;\n\n const graphQLErrors = 'errors' in error && Array.isArray(error.errors) ? error.errors : [];\n\n if (hasSessionAuthErrors(graphQLErrors)) {\n redirectToLogin();\n return;\n }\n\n if (error instanceof Error && isAuthNetworkError(error)) {\n redirectToLogin();\n }\n });\n\n const transportLink = wsLink\n ? split(\n ({ query }) => {\n const definition = getMainDefinition(query);\n return (\n definition.kind === 'OperationDefinition' && definition.operation === 'subscription'\n );\n },\n wsLink,\n httpLink\n )\n : httpLink;\n\n const mutationAutoRefreshLink = createMutationAutoRefreshLink(() => globalClientInstance);\n\n globalClientInstance = new ApolloClient({\n link: from([errorLink, mutationAutoRefreshLink, authLink, transportLink]),\n cache: new InMemoryCache({\n typePolicies: {\n Query: {\n fields: {\n notifications: {\n merge(_existing: unknown, incoming: unknown) {\n return incoming;\n },\n },\n notificationTemplates: {\n merge(_existing: unknown, incoming: unknown) {\n return incoming;\n },\n },\n },\n },\n Notification: {\n keyFields: ['id'],\n },\n NotificationTemplate: {\n keyFields: ['id'],\n },\n },\n }),\n defaultOptions: {\n watchQuery: {\n fetchPolicy: 'cache-and-network',\n },\n query: {\n fetchPolicy: 'cache-first',\n },\n mutate: {\n fetchPolicy: 'network-only',\n },\n },\n });\n\n return globalClientInstance;\n}\n\n/**\n * Reset the singleton client (useful for testing or re-initialization)\n */\nexport function resetGlobalNotificationClient(): void {\n if (globalClientInstance) {\n globalClientInstance.clearStore();\n globalClientInstance = null;\n currentGlobalUrl = null;\n currentAuthToken = null;\n }\n}\n"],"mappings":";;;;;;;;AAiBA,SAAS,EACP,IAAoF,EAAE,EAC7E;AACT,QAAO,EAAO,MAAM,MA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