@nexushub/client 0.9.0 → 1.1.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.
@@ -0,0 +1,116 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/config.ts
2
+ var DEFAULT_API_URL = "https://api.gnapex.com";
3
+ var DEFAULT_ANALYTICS_URL = "https://sentry.gnapex.com";
4
+ var SDK_VERSION = "1.1.0";
5
+ var LOCAL_NEST_URL = "https://api.gnapex.com";
6
+ var LOCAL_RUST_URL = "https://sentry.gnapex.com";
7
+ var getEnvConfig = () => {
8
+ const NEXT_PUBLIC_ID = typeof process !== "undefined" ? _nullishCoalesce(process.env.NEXT_PUBLIC_GNAPEX_ID, () => ( process.env.NEXT_PUBLIC_NEXUS_ID)) : void 0;
9
+ const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? _nullishCoalesce(process.env.NEXT_PUBLIC_GNAPEX_KEY, () => ( process.env.NEXT_PUBLIC_NEXUS_KEY)) : void 0;
10
+ const NEXT_PUBLIC_URL = typeof process !== "undefined" ? _nullishCoalesce(process.env.NEXT_PUBLIC_GNAPEX_API_URL, () => ( process.env.NEXT_PUBLIC_NEXUS_API_URL)) : void 0;
11
+ const NEXT_PUBLIC_ANALYTICS_URL = typeof process !== "undefined" ? _nullishCoalesce(process.env.NEXT_PUBLIC_GNAPEX_ANALYTICS_URL, () => ( process.env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL)) : void 0;
12
+ const NODE_ID = typeof process !== "undefined" ? _nullishCoalesce(process.env.GNAPEX_PROJECT_ID, () => ( process.env.NEXUS_PROJECT_ID)) : void 0;
13
+ const NODE_KEY = typeof process !== "undefined" ? _nullishCoalesce(process.env.GNAPEX_API_KEY, () => ( process.env.NEXUS_API_KEY)) : void 0;
14
+ const NODE_URL = typeof process !== "undefined" ? _nullishCoalesce(process.env.GNAPEX_API_URL, () => ( process.env.NEXUS_API_URL)) : void 0;
15
+ const NODE_ANALYTICS_URL = typeof process !== "undefined" ? _nullishCoalesce(process.env.GNAPEX_ANALYTICS_URL, () => ( process.env.NEXUS_ANALYTICS_URL)) : void 0;
16
+ const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
17
+ const isDev = NODE_ENV === "development" || typeof window !== "undefined" && window.location.hostname === "localhost";
18
+ const runtime = typeof window !== "undefined" ? _nullishCoalesce(window.__GNAPEX__, () => ( window.__NEXUS__)) : void 0;
19
+ const meta = typeof document !== "undefined" ? (name) => _nullishCoalesce(_optionalChain([document, 'access', _ => _.querySelector, 'call', _2 => _2(`meta[name="${name}"]`), 'optionalAccess', _3 => _3.getAttribute, 'call', _4 => _4("content")]), () => ( void 0)) : (_name) => void 0;
20
+ const projectId = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _5 => _5.projectId]), () => ( meta("gnapex-project"))), () => ( meta("nexus-project"))), () => ( NEXT_PUBLIC_ID)), () => ( NODE_ID));
21
+ const apiKey = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _6 => _6.apiKey]), () => ( meta("gnapex-key"))), () => ( meta("nexus-key"))), () => ( NEXT_PUBLIC_KEY)), () => ( NODE_KEY));
22
+ const apiUrl = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _7 => _7.apiUrl]), () => ( meta("gnapex-api"))), () => ( meta("nexus-api"))), () => ( NEXT_PUBLIC_URL)), () => ( NODE_URL)), () => ( (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL)));
23
+ const analyticsUrl = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _8 => _8.analyticsUrl]), () => ( meta("gnapex-analytics"))), () => ( meta("nexus-analytics"))), () => ( NEXT_PUBLIC_ANALYTICS_URL)), () => ( NODE_ANALYTICS_URL)), () => ( (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL)));
24
+ return {
25
+ projectId,
26
+ apiKey,
27
+ apiUrl,
28
+ analyticsUrl
29
+ };
30
+ };
31
+ var mergeConfigs = (base, override) => {
32
+ const mergedApiUrl = override.apiUrl || base.apiUrl || DEFAULT_API_URL;
33
+ const mergedAnalyticsUrl = override.analyticsUrl || base.analyticsUrl || (mergedApiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
34
+ return {
35
+ ...base,
36
+ ...override,
37
+ apiUrl: mergedApiUrl,
38
+ analyticsUrl: mergedAnalyticsUrl,
39
+ projectId: override.projectId || base.projectId,
40
+ apiKey: override.apiKey || base.apiKey
41
+ };
42
+ };
43
+ var getFullConfig = (partialConfig) => {
44
+ const envConfig = getEnvConfig();
45
+ return mergeConfigs(envConfig, partialConfig || {});
46
+ };
47
+ var validateConfig = (config) => {
48
+ const errors = [];
49
+ if (!config.projectId) errors.push("Missing projectId");
50
+ if (!config.apiUrl) errors.push("Missing apiUrl");
51
+ else if (!/^https?:\/\//.test(config.apiUrl)) {
52
+ errors.push("apiUrl must be a valid URL starting with http:// or https://");
53
+ }
54
+ return errors;
55
+ };
56
+
57
+ // src/content/utils.ts
58
+ function validateSlug(slug) {
59
+ if (!slug || typeof slug !== "string") {
60
+ throw new Error("Slug must be a non-empty string");
61
+ }
62
+ if (!/^[a-z0-9-_]+$/.test(slug)) {
63
+ throw new Error("Slug can only contain lowercase letters, numbers, hyphens, and underscores");
64
+ }
65
+ }
66
+ function normalizeQuery(query) {
67
+ const normalized = { ...query };
68
+ normalized.page = Math.max(1, normalized.page || 1);
69
+ normalized.limit = Math.min(100, Math.max(1, normalized.limit || 10));
70
+ normalized.order = normalized.order || "desc";
71
+ if (normalized.page < 1) {
72
+ throw new Error("Page must be greater than 0");
73
+ }
74
+ if (normalized.limit < 1 || normalized.limit > 100) {
75
+ throw new Error("Limit must be between 1 and 100");
76
+ }
77
+ return normalized;
78
+ }
79
+ function buildQueryString(query) {
80
+ const params = new URLSearchParams();
81
+ if (query.page) params.append("page", query.page.toString());
82
+ if (query.limit) params.append("limit", query.limit.toString());
83
+ if (query.sort) params.append("sort", query.sort);
84
+ if (query.order) params.append("order", query.order);
85
+ if (query.search) params.append("search", query.search);
86
+ if (_optionalChain([query, 'access', _9 => _9.include, 'optionalAccess', _10 => _10.length])) {
87
+ params.append("include", query.include.join(","));
88
+ }
89
+ if (_optionalChain([query, 'access', _11 => _11.fields, 'optionalAccess', _12 => _12.length])) {
90
+ params.append("fields", query.fields.join(","));
91
+ }
92
+ if (query.filter) {
93
+ params.append("filter", JSON.stringify(query.filter));
94
+ }
95
+ return params.toString();
96
+ }
97
+ function measurePerformance(name, fn) {
98
+ const start = performance.now();
99
+ const result = fn();
100
+ const end = performance.now();
101
+ if (process.env.NODE_ENV === "development") {
102
+ console.log(`\u23F1\uFE0F ${name}: ${(end - start).toFixed(2)}ms`);
103
+ }
104
+ return { result, duration: end - start };
105
+ }
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+ exports.SDK_VERSION = SDK_VERSION; exports.getEnvConfig = getEnvConfig; exports.getFullConfig = getFullConfig; exports.validateConfig = validateConfig; exports.validateSlug = validateSlug; exports.normalizeQuery = normalizeQuery; exports.buildQueryString = buildQueryString; exports.measurePerformance = measurePerformance;
@@ -0,0 +1,116 @@
1
+ // src/config.ts
2
+ var DEFAULT_API_URL = "https://api.gnapex.com";
3
+ var DEFAULT_ANALYTICS_URL = "https://sentry.gnapex.com";
4
+ var SDK_VERSION = "1.1.0";
5
+ var LOCAL_NEST_URL = "https://api.gnapex.com";
6
+ var LOCAL_RUST_URL = "https://sentry.gnapex.com";
7
+ var getEnvConfig = () => {
8
+ const NEXT_PUBLIC_ID = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GNAPEX_ID ?? process.env.NEXT_PUBLIC_NEXUS_ID : void 0;
9
+ const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GNAPEX_KEY ?? process.env.NEXT_PUBLIC_NEXUS_KEY : void 0;
10
+ const NEXT_PUBLIC_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GNAPEX_API_URL ?? process.env.NEXT_PUBLIC_NEXUS_API_URL : void 0;
11
+ const NEXT_PUBLIC_ANALYTICS_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GNAPEX_ANALYTICS_URL ?? process.env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL : void 0;
12
+ const NODE_ID = typeof process !== "undefined" ? process.env.GNAPEX_PROJECT_ID ?? process.env.NEXUS_PROJECT_ID : void 0;
13
+ const NODE_KEY = typeof process !== "undefined" ? process.env.GNAPEX_API_KEY ?? process.env.NEXUS_API_KEY : void 0;
14
+ const NODE_URL = typeof process !== "undefined" ? process.env.GNAPEX_API_URL ?? process.env.NEXUS_API_URL : void 0;
15
+ const NODE_ANALYTICS_URL = typeof process !== "undefined" ? process.env.GNAPEX_ANALYTICS_URL ?? process.env.NEXUS_ANALYTICS_URL : void 0;
16
+ const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
17
+ const isDev = NODE_ENV === "development" || typeof window !== "undefined" && window.location.hostname === "localhost";
18
+ const runtime = typeof window !== "undefined" ? window.__GNAPEX__ ?? window.__NEXUS__ : void 0;
19
+ const meta = typeof document !== "undefined" ? (name) => document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") ?? void 0 : (_name) => void 0;
20
+ const projectId = runtime?.projectId ?? meta("gnapex-project") ?? meta("nexus-project") ?? NEXT_PUBLIC_ID ?? NODE_ID;
21
+ const apiKey = runtime?.apiKey ?? meta("gnapex-key") ?? meta("nexus-key") ?? NEXT_PUBLIC_KEY ?? NODE_KEY;
22
+ const apiUrl = runtime?.apiUrl ?? meta("gnapex-api") ?? meta("nexus-api") ?? NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
23
+ const analyticsUrl = runtime?.analyticsUrl ?? meta("gnapex-analytics") ?? meta("nexus-analytics") ?? NEXT_PUBLIC_ANALYTICS_URL ?? NODE_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
24
+ return {
25
+ projectId,
26
+ apiKey,
27
+ apiUrl,
28
+ analyticsUrl
29
+ };
30
+ };
31
+ var mergeConfigs = (base, override) => {
32
+ const mergedApiUrl = override.apiUrl || base.apiUrl || DEFAULT_API_URL;
33
+ const mergedAnalyticsUrl = override.analyticsUrl || base.analyticsUrl || (mergedApiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
34
+ return {
35
+ ...base,
36
+ ...override,
37
+ apiUrl: mergedApiUrl,
38
+ analyticsUrl: mergedAnalyticsUrl,
39
+ projectId: override.projectId || base.projectId,
40
+ apiKey: override.apiKey || base.apiKey
41
+ };
42
+ };
43
+ var getFullConfig = (partialConfig) => {
44
+ const envConfig = getEnvConfig();
45
+ return mergeConfigs(envConfig, partialConfig || {});
46
+ };
47
+ var validateConfig = (config) => {
48
+ const errors = [];
49
+ if (!config.projectId) errors.push("Missing projectId");
50
+ if (!config.apiUrl) errors.push("Missing apiUrl");
51
+ else if (!/^https?:\/\//.test(config.apiUrl)) {
52
+ errors.push("apiUrl must be a valid URL starting with http:// or https://");
53
+ }
54
+ return errors;
55
+ };
56
+
57
+ // src/content/utils.ts
58
+ function validateSlug(slug) {
59
+ if (!slug || typeof slug !== "string") {
60
+ throw new Error("Slug must be a non-empty string");
61
+ }
62
+ if (!/^[a-z0-9-_]+$/.test(slug)) {
63
+ throw new Error("Slug can only contain lowercase letters, numbers, hyphens, and underscores");
64
+ }
65
+ }
66
+ function normalizeQuery(query) {
67
+ const normalized = { ...query };
68
+ normalized.page = Math.max(1, normalized.page || 1);
69
+ normalized.limit = Math.min(100, Math.max(1, normalized.limit || 10));
70
+ normalized.order = normalized.order || "desc";
71
+ if (normalized.page < 1) {
72
+ throw new Error("Page must be greater than 0");
73
+ }
74
+ if (normalized.limit < 1 || normalized.limit > 100) {
75
+ throw new Error("Limit must be between 1 and 100");
76
+ }
77
+ return normalized;
78
+ }
79
+ function buildQueryString(query) {
80
+ const params = new URLSearchParams();
81
+ if (query.page) params.append("page", query.page.toString());
82
+ if (query.limit) params.append("limit", query.limit.toString());
83
+ if (query.sort) params.append("sort", query.sort);
84
+ if (query.order) params.append("order", query.order);
85
+ if (query.search) params.append("search", query.search);
86
+ if (query.include?.length) {
87
+ params.append("include", query.include.join(","));
88
+ }
89
+ if (query.fields?.length) {
90
+ params.append("fields", query.fields.join(","));
91
+ }
92
+ if (query.filter) {
93
+ params.append("filter", JSON.stringify(query.filter));
94
+ }
95
+ return params.toString();
96
+ }
97
+ function measurePerformance(name, fn) {
98
+ const start = performance.now();
99
+ const result = fn();
100
+ const end = performance.now();
101
+ if (process.env.NODE_ENV === "development") {
102
+ console.log(`\u23F1\uFE0F ${name}: ${(end - start).toFixed(2)}ms`);
103
+ }
104
+ return { result, duration: end - start };
105
+ }
106
+
107
+ export {
108
+ SDK_VERSION,
109
+ getEnvConfig,
110
+ getFullConfig,
111
+ validateConfig,
112
+ validateSlug,
113
+ normalizeQuery,
114
+ buildQueryString,
115
+ measurePerformance
116
+ };