@axcode/axcloud-sdk 0.2.0-dev.1e6c3d5 → 0.2.0-dev.5dc7e06
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/README.md +67 -0
- package/dist/barnsport.d.mts +39 -0
- package/dist/barnsport.d.ts +39 -0
- package/dist/barnsport.js +73 -0
- package/dist/barnsport.js.map +1 -0
- package/dist/barnsport.mjs +4 -0
- package/dist/barnsport.mjs.map +1 -0
- package/dist/chunk-2IVJTMRB.js +519 -0
- package/dist/chunk-2IVJTMRB.js.map +1 -0
- package/dist/chunk-7IPCZJ5Q.mjs +273 -0
- package/dist/chunk-7IPCZJ5Q.mjs.map +1 -0
- package/dist/chunk-7K5N3DQ4.js +231 -0
- package/dist/chunk-7K5N3DQ4.js.map +1 -0
- package/dist/chunk-CACQMQCJ.mjs +506 -0
- package/dist/chunk-CACQMQCJ.mjs.map +1 -0
- package/dist/chunk-PMMCOWL3.mjs +223 -0
- package/dist/chunk-PMMCOWL3.mjs.map +1 -0
- package/dist/chunk-ZOQAXLCZ.js +290 -0
- package/dist/chunk-ZOQAXLCZ.js.map +1 -0
- package/dist/client-FOpKwe3e.d.mts +75 -0
- package/dist/client-FOpKwe3e.d.ts +75 -0
- package/dist/index.d.mts +41 -819
- package/dist/index.d.ts +41 -819
- package/dist/index.js +130 -889
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -839
- package/dist/index.mjs.map +1 -1
- package/dist/public.d.mts +27 -0
- package/dist/public.d.ts +27 -0
- package/dist/public.js +131 -0
- package/dist/public.js.map +1 -0
- package/dist/public.mjs +99 -0
- package/dist/public.mjs.map +1 -0
- package/dist/useBarnsport-C6uDSuHf.d.mts +583 -0
- package/dist/useBarnsport-C6uDSuHf.d.ts +583 -0
- package/dist/useContent-1WbKvPY4.d.mts +508 -0
- package/dist/useContent-Cl7dvERE.d.ts +508 -0
- package/package.json +15 -5
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { A as AxCloudAnalyticsOptions } from './useContent-1WbKvPY4.mjs';
|
|
4
|
+
export { l as AnalyticsEventData, m as AnalyticsEventValue, o as AnalyticsRuntime, p as AnalyticsRuntimeConfig, a6 as ContentBlock, t as ContentItem, a7 as ContentItemOptions, c as ContentListResponse, C as ContentQueryOptions, u as ContentSlotImage, v as ContentSlotMap, w as ContentSlotReader, x as ContentSlotValue, P as Page, I as PageContentState, Q as createContentSlotReader, T as getContentSlotMap, Z as useAnalytics, _ as useAnalyticsRuntime, $ as useAxCloudContext, a0 as useContent, a1 as useContentItem, a2 as usePageContent } from './useContent-1WbKvPY4.mjs';
|
|
5
|
+
import './client-FOpKwe3e.mjs';
|
|
6
|
+
|
|
7
|
+
interface AxCloudPublicProviderProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
orgId: string;
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
/** API stage - defaults to 'dev'. Use 'prod' for production. */
|
|
12
|
+
stage?: string;
|
|
13
|
+
/** Scope-limited browser API key for public endpoints. */
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** Optional privacy-safe analytics collection through AxCloud. */
|
|
16
|
+
analytics?: AxCloudAnalyticsOptions;
|
|
17
|
+
queryClient?: QueryClient;
|
|
18
|
+
/** Default request timeout in milliseconds (default: 30000). */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* AxCloudPublicProvider mounts the SDK client, query cache and analytics without
|
|
23
|
+
* importing or initializing Auth0. It is intended for anonymous public sites.
|
|
24
|
+
*/
|
|
25
|
+
declare function AxCloudPublicProvider({ children, orgId, apiUrl, stage, apiKey, analytics: analyticsOptions, queryClient: providedQueryClient, timeout, }: AxCloudPublicProviderProps): React.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { AxCloudAnalyticsOptions, AxCloudPublicProvider, type AxCloudPublicProviderProps };
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { A as AxCloudAnalyticsOptions } from './useContent-Cl7dvERE.js';
|
|
4
|
+
export { l as AnalyticsEventData, m as AnalyticsEventValue, o as AnalyticsRuntime, p as AnalyticsRuntimeConfig, a6 as ContentBlock, t as ContentItem, a7 as ContentItemOptions, c as ContentListResponse, C as ContentQueryOptions, u as ContentSlotImage, v as ContentSlotMap, w as ContentSlotReader, x as ContentSlotValue, P as Page, I as PageContentState, Q as createContentSlotReader, T as getContentSlotMap, Z as useAnalytics, _ as useAnalyticsRuntime, $ as useAxCloudContext, a0 as useContent, a1 as useContentItem, a2 as usePageContent } from './useContent-Cl7dvERE.js';
|
|
5
|
+
import './client-FOpKwe3e.js';
|
|
6
|
+
|
|
7
|
+
interface AxCloudPublicProviderProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
orgId: string;
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
/** API stage - defaults to 'dev'. Use 'prod' for production. */
|
|
12
|
+
stage?: string;
|
|
13
|
+
/** Scope-limited browser API key for public endpoints. */
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** Optional privacy-safe analytics collection through AxCloud. */
|
|
16
|
+
analytics?: AxCloudAnalyticsOptions;
|
|
17
|
+
queryClient?: QueryClient;
|
|
18
|
+
/** Default request timeout in milliseconds (default: 30000). */
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* AxCloudPublicProvider mounts the SDK client, query cache and analytics without
|
|
23
|
+
* importing or initializing Auth0. It is intended for anonymous public sites.
|
|
24
|
+
*/
|
|
25
|
+
declare function AxCloudPublicProvider({ children, orgId, apiUrl, stage, apiKey, analytics: analyticsOptions, queryClient: providedQueryClient, timeout, }: AxCloudPublicProviderProps): React.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { AxCloudAnalyticsOptions, AxCloudPublicProvider, type AxCloudPublicProviderProps };
|
package/dist/public.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2IVJTMRB_js = require('./chunk-2IVJTMRB.js');
|
|
4
|
+
var chunk7K5N3DQ4_js = require('./chunk-7K5N3DQ4.js');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var reactQuery = require('@tanstack/react-query');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function createDefaultQueryClient() {
|
|
10
|
+
return new reactQuery.QueryClient({
|
|
11
|
+
defaultOptions: {
|
|
12
|
+
queries: {
|
|
13
|
+
staleTime: 1e3 * 60,
|
|
14
|
+
gcTime: 1e3 * 60 * 30,
|
|
15
|
+
retry: (failureCount, error) => {
|
|
16
|
+
if (chunk7K5N3DQ4_js.isAxCloudError(error) && error.status >= 400 && error.status < 500) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return failureCount < 2;
|
|
20
|
+
},
|
|
21
|
+
refetchOnWindowFocus: true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
var publicQueryClientOwners = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function AxCloudPublicProvider({
|
|
28
|
+
children,
|
|
29
|
+
orgId,
|
|
30
|
+
apiUrl,
|
|
31
|
+
stage = "dev",
|
|
32
|
+
apiKey,
|
|
33
|
+
analytics: analyticsOptions,
|
|
34
|
+
queryClient: providedQueryClient,
|
|
35
|
+
timeout
|
|
36
|
+
}) {
|
|
37
|
+
const [ownedQueryClient] = react.useState(createDefaultQueryClient);
|
|
38
|
+
const queryClient = providedQueryClient || ownedQueryClient;
|
|
39
|
+
const [activatedOwner, setActivatedOwner] = react.useState(null);
|
|
40
|
+
const config = react.useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
orgId,
|
|
43
|
+
apiUrl,
|
|
44
|
+
stage,
|
|
45
|
+
apiKey,
|
|
46
|
+
analytics: analyticsOptions,
|
|
47
|
+
auth0: {
|
|
48
|
+
domain: "public.invalid",
|
|
49
|
+
clientId: "public",
|
|
50
|
+
redirectUri: ""
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
[orgId, apiUrl, stage, apiKey, analyticsOptions]
|
|
54
|
+
);
|
|
55
|
+
const ownerSignature = react.useMemo(
|
|
56
|
+
() => JSON.stringify(["public", orgId, stage, apiUrl, apiKey]),
|
|
57
|
+
[orgId, stage, apiUrl, apiKey]
|
|
58
|
+
);
|
|
59
|
+
const ownerNeedsActivation = publicQueryClientOwners.get(queryClient) !== ownerSignature;
|
|
60
|
+
const clearContentCache = react.useCallback(() => {
|
|
61
|
+
queryClient.removeQueries({ queryKey: ["axcloud"] });
|
|
62
|
+
}, [queryClient]);
|
|
63
|
+
react.useLayoutEffect(() => {
|
|
64
|
+
if (!ownerNeedsActivation) return;
|
|
65
|
+
clearContentCache();
|
|
66
|
+
publicQueryClientOwners.set(queryClient, ownerSignature);
|
|
67
|
+
setActivatedOwner(ownerSignature);
|
|
68
|
+
}, [clearContentCache, ownerNeedsActivation, ownerSignature, queryClient]);
|
|
69
|
+
const client = react.useMemo(
|
|
70
|
+
() => new chunk7K5N3DQ4_js.AxCloudClient({
|
|
71
|
+
baseUrl: apiUrl,
|
|
72
|
+
apiKey,
|
|
73
|
+
timeout
|
|
74
|
+
}),
|
|
75
|
+
[apiUrl, apiKey, timeout]
|
|
76
|
+
);
|
|
77
|
+
const analytics = chunk2IVJTMRB_js.useAnalyticsRuntime(config);
|
|
78
|
+
const contextValue = react.useMemo(
|
|
79
|
+
() => ({
|
|
80
|
+
config,
|
|
81
|
+
client,
|
|
82
|
+
orgId,
|
|
83
|
+
stage,
|
|
84
|
+
isPublicMode: true,
|
|
85
|
+
isAuthLoading: false,
|
|
86
|
+
isAuthenticated: false,
|
|
87
|
+
authSubject: void 0,
|
|
88
|
+
clearContentCache,
|
|
89
|
+
analytics
|
|
90
|
+
}),
|
|
91
|
+
[config, client, orgId, stage, clearContentCache, analytics]
|
|
92
|
+
);
|
|
93
|
+
const identityReady = !ownerNeedsActivation && (activatedOwner === ownerSignature || publicQueryClientOwners.get(queryClient) === ownerSignature);
|
|
94
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsxRuntime.jsx(chunk7K5N3DQ4_js.AxCloudContext.Provider, { value: contextValue, children: identityReady ? children : null }) });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
Object.defineProperty(exports, "createContentSlotReader", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () { return chunk2IVJTMRB_js.createContentSlotReader; }
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "getContentSlotMap", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () { return chunk2IVJTMRB_js.getContentSlotMap; }
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "useAnalytics", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return chunk2IVJTMRB_js.useAnalytics; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "useAnalyticsRuntime", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return chunk2IVJTMRB_js.useAnalyticsRuntime; }
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, "useContent", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () { return chunk2IVJTMRB_js.useContent; }
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "useContentItem", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function () { return chunk2IVJTMRB_js.useContentItem; }
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "usePageContent", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () { return chunk2IVJTMRB_js.usePageContent; }
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "useAxCloudContext", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function () { return chunk7K5N3DQ4_js.useAxCloudContext; }
|
|
128
|
+
});
|
|
129
|
+
exports.AxCloudPublicProvider = AxCloudPublicProvider;
|
|
130
|
+
//# sourceMappingURL=public.js.map
|
|
131
|
+
//# sourceMappingURL=public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/publicProvider.tsx"],"names":["QueryClient","isAxCloudError","useState","useMemo","useCallback","useLayoutEffect","AxCloudClient","useAnalyticsRuntime","jsx","QueryClientProvider","AxCloudContext"],"mappings":";;;;;;;;AAwBA,SAAS,wBAAA,GAAwC;AAC/C,EAAA,OAAO,IAAIA,sBAAA,CAAY;AAAA,IACrB,cAAA,EAAgB;AAAA,MACd,OAAA,EAAS;AAAA,QACP,WAAW,GAAA,GAAO,EAAA;AAAA,QAClB,MAAA,EAAQ,MAAO,EAAA,GAAK,EAAA;AAAA,QACpB,KAAA,EAAO,CAAC,YAAA,EAAc,KAAA,KAAU;AAC9B,UAAA,IAAIC,+BAAA,CAAe,KAAK,CAAA,IAAK,KAAA,CAAM,UAAU,GAAA,IAAO,KAAA,CAAM,SAAS,GAAA,EAAK;AACtE,YAAA,OAAO,KAAA;AAAA,UACT;AACA,UAAA,OAAO,YAAA,GAAe,CAAA;AAAA,QACxB,CAAA;AAAA,QACA,oBAAA,EAAsB;AAAA;AACxB;AACF,GACD,CAAA;AACH;AAEA,IAAM,uBAAA,uBAA8B,OAAA,EAA6B;AAM1D,SAAS,qBAAA,CAAsB;AAAA,EACpC,QAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA,GAAQ,KAAA;AAAA,EACR,MAAA;AAAA,EACA,SAAA,EAAW,gBAAA;AAAA,EACX,WAAA,EAAa,mBAAA;AAAA,EACb;AACF,CAAA,EAA+B;AAC7B,EAAA,MAAM,CAAC,gBAAgB,CAAA,GAAIC,cAAA,CAA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EAAgB,WAAW,CAAC,CAAA;AAEzE,EAAA,MAAM,MAAA,GAASF,aAAA;AAAA,IACb,MACE,IAAIG,8BAAA,CAAc;AAAA,MAChB,OAAA,EAAS,MAAA;AAAA,MACT,MAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,IACH,CAAC,MAAA,EAAQ,MAAA,EAAQ,OAAO;AAAA,GAC1B;AACA,EAAA,MAAM,SAAA,GAAYC,qCAAoB,MAAM,CAAA;AAC5C,EAAA,MAAM,YAAA,GAAeJ,aAAA;AAAA,IACnB,OAAO;AAAA,MACL,MAAA;AAAA,MACA,MAAA;AAAA,MACA,KAAA;AAAA,MACA,KAAA;AAAA,MACA,YAAA,EAAc,IAAA;AAAA,MACd,aAAA,EAAe,KAAA;AAAA,MACf,eAAA,EAAiB,KAAA;AAAA,MACjB,WAAA,EAAa,MAAA;AAAA,MACb,iBAAA;AAAA,MACA;AAAA,KACF,CAAA;AAAA,IACA,CAAC,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,mBAAmB,SAAS;AAAA,GAC7D;AAEA,EAAA,MAAM,aAAA,GACJ,CAAC,oBAAA,KACA,cAAA,KAAmB,kBAClB,uBAAA,CAAwB,GAAA,CAAI,WAAW,CAAA,KAAM,cAAA,CAAA;AAEjD,EAAA,uBACEK,cAAA,CAACC,8BAAA,EAAA,EAAoB,MAAA,EAAQ,WAAA,EAC3B,QAAA,kBAAAD,cAAA,CAACE,+BAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,YAAA,EAC7B,QAAA,EAAA,aAAA,GAAgB,QAAA,GAAW,MAC9B,CAAA,EACF,CAAA;AAEJ","file":"public.js","sourcesContent":["import React, { useCallback, useLayoutEffect, useMemo, useState } from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { AxCloudClient } from '../core/client';\nimport { isAxCloudError } from '../core/errors';\nimport type { AxCloudAnalyticsOptions } from '../core/analytics';\nimport type { AxCloudConfig } from '../core/types';\nimport { useAnalyticsRuntime } from './analytics';\nimport { AxCloudContext } from './context';\n\nexport interface AxCloudPublicProviderProps {\n children: React.ReactNode;\n orgId: string;\n apiUrl: string;\n /** API stage - defaults to 'dev'. Use 'prod' for production. */\n stage?: string;\n /** Scope-limited browser API key for public endpoints. */\n apiKey: string;\n /** Optional privacy-safe analytics collection through AxCloud. */\n analytics?: AxCloudAnalyticsOptions;\n queryClient?: QueryClient;\n /** Default request timeout in milliseconds (default: 30000). */\n timeout?: number;\n}\n\nfunction createDefaultQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 1000 * 60,\n gcTime: 1000 * 60 * 30,\n retry: (failureCount, error) => {\n if (isAxCloudError(error) && error.status >= 400 && error.status < 500) {\n return false;\n }\n return failureCount < 2;\n },\n refetchOnWindowFocus: true,\n },\n },\n });\n}\n\nconst publicQueryClientOwners = new WeakMap<QueryClient, string>();\n\n/**\n * AxCloudPublicProvider mounts the SDK client, query cache and analytics without\n * importing or initializing Auth0. It is intended for anonymous public sites.\n */\nexport function AxCloudPublicProvider({\n children,\n orgId,\n apiUrl,\n stage = 'dev',\n apiKey,\n analytics: analyticsOptions,\n queryClient: providedQueryClient,\n timeout,\n}: AxCloudPublicProviderProps) {\n const [ownedQueryClient] = useState(createDefaultQueryClient);\n const queryClient = providedQueryClient || ownedQueryClient;\n const [activatedOwner, setActivatedOwner] = useState<string | null>(null);\n\n // Keep AxCloudConfig and the existing authenticated context shape unchanged\n // for current consumers. The sentinel is never used to mount Auth0 and is not\n // accepted as a public-provider prop.\n const config: AxCloudConfig = useMemo(\n () => ({\n orgId,\n apiUrl,\n stage,\n apiKey,\n analytics: analyticsOptions,\n auth0: {\n domain: 'public.invalid',\n clientId: 'public',\n redirectUri: '',\n },\n }),\n [orgId, apiUrl, stage, apiKey, analyticsOptions]\n );\n const ownerSignature = useMemo(\n () => JSON.stringify(['public', orgId, stage, apiUrl, apiKey]),\n [orgId, stage, apiUrl, apiKey]\n );\n const ownerNeedsActivation = publicQueryClientOwners.get(queryClient) !== ownerSignature;\n\n const clearContentCache = useCallback(() => {\n queryClient.removeQueries({ queryKey: ['axcloud'] });\n }, [queryClient]);\n\n useLayoutEffect(() => {\n if (!ownerNeedsActivation) return;\n clearContentCache();\n publicQueryClientOwners.set(queryClient, ownerSignature);\n setActivatedOwner(ownerSignature);\n }, [clearContentCache, ownerNeedsActivation, ownerSignature, queryClient]);\n\n const client = useMemo(\n () =>\n new AxCloudClient({\n baseUrl: apiUrl,\n apiKey,\n timeout,\n }),\n [apiUrl, apiKey, timeout]\n );\n const analytics = useAnalyticsRuntime(config);\n const contextValue = useMemo(\n () => ({\n config,\n client,\n orgId,\n stage,\n isPublicMode: true,\n isAuthLoading: false,\n isAuthenticated: false,\n authSubject: undefined,\n clearContentCache,\n analytics,\n }),\n [config, client, orgId, stage, clearContentCache, analytics]\n );\n\n const identityReady =\n !ownerNeedsActivation &&\n (activatedOwner === ownerSignature ||\n publicQueryClientOwners.get(queryClient) === ownerSignature);\n\n return (\n <QueryClientProvider client={queryClient}>\n <AxCloudContext.Provider value={contextValue}>\n {identityReady ? children : null}\n </AxCloudContext.Provider>\n </QueryClientProvider>\n );\n}\n"]}
|
package/dist/public.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useAnalyticsRuntime } from './chunk-CACQMQCJ.mjs';
|
|
2
|
+
export { createContentSlotReader, getContentSlotMap, useAnalytics, useAnalyticsRuntime, useContent, useContentItem, usePageContent } from './chunk-CACQMQCJ.mjs';
|
|
3
|
+
import { AxCloudClient, AxCloudContext, isAxCloudError } from './chunk-PMMCOWL3.mjs';
|
|
4
|
+
export { useAxCloudContext } from './chunk-PMMCOWL3.mjs';
|
|
5
|
+
import { useState, useMemo, useCallback, useLayoutEffect } from 'react';
|
|
6
|
+
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
function createDefaultQueryClient() {
|
|
10
|
+
return new QueryClient({
|
|
11
|
+
defaultOptions: {
|
|
12
|
+
queries: {
|
|
13
|
+
staleTime: 1e3 * 60,
|
|
14
|
+
gcTime: 1e3 * 60 * 30,
|
|
15
|
+
retry: (failureCount, error) => {
|
|
16
|
+
if (isAxCloudError(error) && error.status >= 400 && error.status < 500) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return failureCount < 2;
|
|
20
|
+
},
|
|
21
|
+
refetchOnWindowFocus: true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
var publicQueryClientOwners = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function AxCloudPublicProvider({
|
|
28
|
+
children,
|
|
29
|
+
orgId,
|
|
30
|
+
apiUrl,
|
|
31
|
+
stage = "dev",
|
|
32
|
+
apiKey,
|
|
33
|
+
analytics: analyticsOptions,
|
|
34
|
+
queryClient: providedQueryClient,
|
|
35
|
+
timeout
|
|
36
|
+
}) {
|
|
37
|
+
const [ownedQueryClient] = useState(createDefaultQueryClient);
|
|
38
|
+
const queryClient = providedQueryClient || ownedQueryClient;
|
|
39
|
+
const [activatedOwner, setActivatedOwner] = useState(null);
|
|
40
|
+
const config = useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
orgId,
|
|
43
|
+
apiUrl,
|
|
44
|
+
stage,
|
|
45
|
+
apiKey,
|
|
46
|
+
analytics: analyticsOptions,
|
|
47
|
+
auth0: {
|
|
48
|
+
domain: "public.invalid",
|
|
49
|
+
clientId: "public",
|
|
50
|
+
redirectUri: ""
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
[orgId, apiUrl, stage, apiKey, analyticsOptions]
|
|
54
|
+
);
|
|
55
|
+
const ownerSignature = useMemo(
|
|
56
|
+
() => JSON.stringify(["public", orgId, stage, apiUrl, apiKey]),
|
|
57
|
+
[orgId, stage, apiUrl, apiKey]
|
|
58
|
+
);
|
|
59
|
+
const ownerNeedsActivation = publicQueryClientOwners.get(queryClient) !== ownerSignature;
|
|
60
|
+
const clearContentCache = useCallback(() => {
|
|
61
|
+
queryClient.removeQueries({ queryKey: ["axcloud"] });
|
|
62
|
+
}, [queryClient]);
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
if (!ownerNeedsActivation) return;
|
|
65
|
+
clearContentCache();
|
|
66
|
+
publicQueryClientOwners.set(queryClient, ownerSignature);
|
|
67
|
+
setActivatedOwner(ownerSignature);
|
|
68
|
+
}, [clearContentCache, ownerNeedsActivation, ownerSignature, queryClient]);
|
|
69
|
+
const client = useMemo(
|
|
70
|
+
() => new AxCloudClient({
|
|
71
|
+
baseUrl: apiUrl,
|
|
72
|
+
apiKey,
|
|
73
|
+
timeout
|
|
74
|
+
}),
|
|
75
|
+
[apiUrl, apiKey, timeout]
|
|
76
|
+
);
|
|
77
|
+
const analytics = useAnalyticsRuntime(config);
|
|
78
|
+
const contextValue = useMemo(
|
|
79
|
+
() => ({
|
|
80
|
+
config,
|
|
81
|
+
client,
|
|
82
|
+
orgId,
|
|
83
|
+
stage,
|
|
84
|
+
isPublicMode: true,
|
|
85
|
+
isAuthLoading: false,
|
|
86
|
+
isAuthenticated: false,
|
|
87
|
+
authSubject: void 0,
|
|
88
|
+
clearContentCache,
|
|
89
|
+
analytics
|
|
90
|
+
}),
|
|
91
|
+
[config, client, orgId, stage, clearContentCache, analytics]
|
|
92
|
+
);
|
|
93
|
+
const identityReady = !ownerNeedsActivation && (activatedOwner === ownerSignature || publicQueryClientOwners.get(queryClient) === ownerSignature);
|
|
94
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(AxCloudContext.Provider, { value: contextValue, children: identityReady ? children : null }) });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { AxCloudPublicProvider };
|
|
98
|
+
//# sourceMappingURL=public.mjs.map
|
|
99
|
+
//# sourceMappingURL=public.mjs.map
|
|
@@ -0,0 +1 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AAA;AAAA,MACA,MAAA;AAAA,MACA,KAAA;AAAA,MACA,KAAA;AAAA,MACA,YAAA,EAAc,IAAA;AAAA,MACd,aAAA,EAAe,KAAA;AAAA,MACf,eAAA,EAAiB,KAAA;AAAA,MACjB,WAAA,EAAa,MAAA;AAAA,MACb,iBAAA;AAAA,MACA;AAAA,KACF,CAAA;AAAA,IACA,CAAC,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,mBAAmB,SAAS;AAAA,GAC7D;AAEA,EAAA,MAAM,aAAA,GACJ,CAAC,oBAAA,KACA,cAAA,KAAmB,kBAClB,uBAAA,CAAwB,GAAA,CAAI,WAAW,CAAA,KAAM,cAAA,CAAA;AAEjD,EAAA,uBACE,GAAA,CAAC,mBAAA,EAAA,EAAoB,MAAA,EAAQ,WAAA,EAC3B,QAAA,kBAAA,GAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,YAAA,EAC7B,QAAA,EAAA,aAAA,GAAgB,QAAA,GAAW,MAC9B,CAAA,EACF,CAAA;AAEJ","file":"public.mjs","sourcesContent":["import React, { useCallback, useLayoutEffect, useMemo, useState } from 'react';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { AxCloudClient } from '../core/client';\nimport { isAxCloudError } from '../core/errors';\nimport type { AxCloudAnalyticsOptions } from '../core/analytics';\nimport type { AxCloudConfig } from '../core/types';\nimport { useAnalyticsRuntime } from './analytics';\nimport { AxCloudContext } from './context';\n\nexport interface AxCloudPublicProviderProps {\n children: React.ReactNode;\n orgId: string;\n apiUrl: string;\n /** API stage - defaults to 'dev'. Use 'prod' for production. */\n stage?: string;\n /** Scope-limited browser API key for public endpoints. */\n apiKey: string;\n /** Optional privacy-safe analytics collection through AxCloud. */\n analytics?: AxCloudAnalyticsOptions;\n queryClient?: QueryClient;\n /** Default request timeout in milliseconds (default: 30000). */\n timeout?: number;\n}\n\nfunction createDefaultQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 1000 * 60,\n gcTime: 1000 * 60 * 30,\n retry: (failureCount, error) => {\n if (isAxCloudError(error) && error.status >= 400 && error.status < 500) {\n return false;\n }\n return failureCount < 2;\n },\n refetchOnWindowFocus: true,\n },\n },\n });\n}\n\nconst publicQueryClientOwners = new WeakMap<QueryClient, string>();\n\n/**\n * AxCloudPublicProvider mounts the SDK client, query cache and analytics without\n * importing or initializing Auth0. It is intended for anonymous public sites.\n */\nexport function AxCloudPublicProvider({\n children,\n orgId,\n apiUrl,\n stage = 'dev',\n apiKey,\n analytics: analyticsOptions,\n queryClient: providedQueryClient,\n timeout,\n}: AxCloudPublicProviderProps) {\n const [ownedQueryClient] = useState(createDefaultQueryClient);\n const queryClient = providedQueryClient || ownedQueryClient;\n const [activatedOwner, setActivatedOwner] = useState<string | null>(null);\n\n // Keep AxCloudConfig and the existing authenticated context shape unchanged\n // for current consumers. The sentinel is never used to mount Auth0 and is not\n // accepted as a public-provider prop.\n const config: AxCloudConfig = useMemo(\n () => ({\n orgId,\n apiUrl,\n stage,\n apiKey,\n analytics: analyticsOptions,\n auth0: {\n domain: 'public.invalid',\n clientId: 'public',\n redirectUri: '',\n },\n }),\n [orgId, apiUrl, stage, apiKey, analyticsOptions]\n );\n const ownerSignature = useMemo(\n () => JSON.stringify(['public', orgId, stage, apiUrl, apiKey]),\n [orgId, stage, apiUrl, apiKey]\n );\n const ownerNeedsActivation = publicQueryClientOwners.get(queryClient) !== ownerSignature;\n\n const clearContentCache = useCallback(() => {\n queryClient.removeQueries({ queryKey: ['axcloud'] });\n }, [queryClient]);\n\n useLayoutEffect(() => {\n if (!ownerNeedsActivation) return;\n clearContentCache();\n publicQueryClientOwners.set(queryClient, ownerSignature);\n setActivatedOwner(ownerSignature);\n }, [clearContentCache, ownerNeedsActivation, ownerSignature, queryClient]);\n\n const client = useMemo(\n () =>\n new AxCloudClient({\n baseUrl: apiUrl,\n apiKey,\n timeout,\n }),\n [apiUrl, apiKey, timeout]\n );\n const analytics = useAnalyticsRuntime(config);\n const contextValue = useMemo(\n () => ({\n config,\n client,\n orgId,\n stage,\n isPublicMode: true,\n isAuthLoading: false,\n isAuthenticated: false,\n authSubject: undefined,\n clearContentCache,\n analytics,\n }),\n [config, client, orgId, stage, clearContentCache, analytics]\n );\n\n const identityReady =\n !ownerNeedsActivation &&\n (activatedOwner === ownerSignature ||\n publicQueryClientOwners.get(queryClient) === ownerSignature);\n\n return (\n <QueryClientProvider client={queryClient}>\n <AxCloudContext.Provider value={contextValue}>\n {identityReady ? children : null}\n </AxCloudContext.Provider>\n </QueryClientProvider>\n );\n}\n"]}
|