@levo-so/core 0.1.71 → 0.1.78

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,52 @@
1
+ import y from "wretch";
2
+ const w = (f = {}) => {
3
+ const { logApiUrl: l = "https://public-api.levo.so" } = f, d = l, n = /* @__PURE__ */ new Map();
4
+ let o = Promise.resolve(), r = setTimeout(() => {
5
+ }, 0), a = /* @__PURE__ */ new Date();
6
+ const u = (e) => {
7
+ const t = JSON.stringify(e?.content ?? "{}"), s = e?.message ?? "";
8
+ n.set(`${s}${t}`, e);
9
+ }, h = async (e) => {
10
+ const t = `${d}/v1/apm/logs/json`, s = () => y().url(t).post(e).res().catch((i) => console.error(i));
11
+ try {
12
+ if (typeof fetch > "u")
13
+ throw new Error("fetch is not defined");
14
+ if (typeof window < "u" && navigator.sendBeacon)
15
+ try {
16
+ if (!navigator.sendBeacon.bind(navigator)(t, JSON.stringify(e)))
17
+ return s();
18
+ } catch {
19
+ return s();
20
+ }
21
+ else
22
+ return s();
23
+ } catch (i) {
24
+ console.warn(`Failed to send logs to server: ${i}`), e.forEach((g) => u(g));
25
+ }
26
+ }, c = async () => {
27
+ const e = Array.from(n.values());
28
+ if (n.clear(), clearTimeout(r), await o, e.length === 0) {
29
+ a = /* @__PURE__ */ new Date();
30
+ return;
31
+ }
32
+ try {
33
+ await h(e);
34
+ } catch (t) {
35
+ console.error("error sending logs", t);
36
+ } finally {
37
+ a = /* @__PURE__ */ new Date();
38
+ }
39
+ };
40
+ return {
41
+ ingest: (e) => {
42
+ if (!l) return;
43
+ (Array.isArray(e) ? e : [e]).forEach((s) => u(s)), n.size >= 50 || a.getTime() < Date.now() - 1500 ? (clearTimeout(r), o = c()) : (clearTimeout(r), r = setTimeout(() => {
44
+ o = c();
45
+ }, 1500));
46
+ },
47
+ flush: c
48
+ };
49
+ };
50
+ export {
51
+ w as createLogBatch
52
+ };
@@ -0,0 +1,77 @@
1
+ import { createLogBatch as h } from "./batch.js";
2
+ const l = typeof window < "u", y = (r) => {
3
+ switch (r) {
4
+ case 0:
5
+ return "log";
6
+ case 1:
7
+ return "info";
8
+ case 2:
9
+ return "warn";
10
+ case 3:
11
+ return "error";
12
+ default:
13
+ return "log";
14
+ }
15
+ }, A = (r, m = {}) => {
16
+ const {
17
+ enableRemote: f = r.NODE_ENV !== "development",
18
+ level: p = r.NODE_ENV !== "development" ? 2 : 0,
19
+ context: w = {},
20
+ logApiUrl: d
21
+ } = m, g = h({ logApiUrl: d }), u = (t) => {
22
+ let n = "";
23
+ const o = t.map((e) => {
24
+ let s = "";
25
+ const a = !n;
26
+ return typeof e == "string" ? (s = e, a && (n = e)) : e instanceof Error ? (s = {
27
+ message: e.message,
28
+ name: e.name,
29
+ stack: e.stack
30
+ }, a && (n = e.message)) : typeof e == "object" ? s = e : (s = String(e), a && (n = String(e))), s;
31
+ }).filter(Boolean);
32
+ return !n && o.length > 0 && (n = "Default message (Check content for details)"), o?.length === 1 && o[0] === n ? { message: n, content: {} } : {
33
+ message: n,
34
+ content: o
35
+ };
36
+ }, c = (t, n) => {
37
+ const o = Array.isArray(n) ? n : [n];
38
+ if (t < p)
39
+ return;
40
+ if (f && t === 3) {
41
+ const { content: s = {}, message: a } = u(o);
42
+ if (a) {
43
+ const i = {
44
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
45
+ level: "error",
46
+ workspace: r.workspace,
47
+ appName: r?.appName,
48
+ isBrowser: l,
49
+ ...w,
50
+ message: a,
51
+ content: s
52
+ };
53
+ l && (i.hostname = window.location.hostname, i.pathname = window.location.pathname, i.url = window.location.href, i.page_title = window.document.title, i.userAgent = window.navigator.userAgent), g.ingest(i);
54
+ }
55
+ }
56
+ const e = y(t);
57
+ console[e](...o);
58
+ };
59
+ return {
60
+ debug: (...t) => {
61
+ c(0, t);
62
+ },
63
+ info: (...t) => {
64
+ c(1, t);
65
+ },
66
+ warn: (...t) => {
67
+ c(2, t);
68
+ },
69
+ error: (...t) => {
70
+ c(3, t);
71
+ }
72
+ };
73
+ };
74
+ export {
75
+ A as createLevoLogger,
76
+ l as isBrowser
77
+ };
@@ -0,0 +1,20 @@
1
+ import { getLevoError as a } from "../utils/getLevoError.js";
2
+ const p = (c, s) => ({
3
+ getAllBlogs: async (r, t = {}, o) => s.instance.url(`/v1/blog/${r}/post/query`).query({ ...o?.params || {} }).options({
4
+ headers: {
5
+ "Levo-Workspace": o?.workspace_id || void 0
6
+ }
7
+ }).post(t).json().then((e) => e).catch((e) => {
8
+ throw a(e);
9
+ }),
10
+ getSingleBlog: async (r, t, o) => s.instance.url(`/v1/blog/${r}/post/${t}`).query({ ...o?.params || {} }).options({
11
+ headers: {
12
+ "Levo-Workspace": o?.workspace_id || void 0
13
+ }
14
+ }).get().json().then((e) => e).catch((e) => {
15
+ throw a(e);
16
+ })
17
+ });
18
+ export {
19
+ p as createLevoBlogModule
20
+ };
@@ -0,0 +1,51 @@
1
+ import { getLevoError as c } from "../utils/getLevoError.js";
2
+ const w = (l, o) => ({
3
+ getAllCollections: async (e = {}, n = {}) => o.instance.url("/v1/bevy/collection/query").options(n).post(e).json().then((t) => t).catch((t) => {
4
+ throw c(t);
5
+ }),
6
+ getCollectionByIDExpanded: async (e, n = {}) => o.instance.url(`/v1/bevy/collection/${e}`).options(n).get().json().then((t) => t).catch((t) => {
7
+ throw c(t);
8
+ }),
9
+ createCollection: async (e) => o.instance.url("/v1/bevy/collection").post(e).json().then((n) => n).catch((n) => {
10
+ throw c(n);
11
+ }),
12
+ saveCollectionData: async ({
13
+ collection_id: e,
14
+ data: n,
15
+ options: t = {}
16
+ }) => o.instance.url(`/v1/bevy/content/${e}`).options(t).post(n).json().then((r) => r).catch((r) => {
17
+ throw c(r);
18
+ }),
19
+ getCollectionContentList: async ({
20
+ collection_key: e,
21
+ page: n,
22
+ search: t,
23
+ limit: r = 10,
24
+ where: a
25
+ }) => o.instance.url(`/v1/bevy/content/${e}/query`).post({
26
+ page: n,
27
+ limit: r,
28
+ search: t,
29
+ where: a
30
+ }).json().then((s) => s).catch((s) => {
31
+ throw c(s);
32
+ }),
33
+ saveDraftEntry: async (e, n) => o.instance.url(`/v1/bevy/content/${e}/save-entry`).post(n).json().then((t) => t).catch((t) => {
34
+ throw c(t);
35
+ }),
36
+ editDraftEntry: async (e, n, t) => o.instance.url(`/v1/bevy/content/${e}/${n}/edit-entry`).put(t).json().then((r) => r).catch((r) => {
37
+ throw c(r);
38
+ }),
39
+ getDraftEntry: async (e) => o.instance.url(`/v1/bevy/content/${e}/list-entry`).get().json().then((n) => n).catch((n) => {
40
+ throw c(n);
41
+ }),
42
+ submitDraftEntry: async (e, n) => o.instance.url(`/v1/bevy/content/${e}/submit-entry`).post(n).json().then((t) => t).catch((t) => {
43
+ throw c(t);
44
+ }),
45
+ getFilters: async (e, n = {}) => o.instance.url(`/v1/bevy/collection/${e}/get-filters`).options(n).get().json().then((t) => t).catch((t) => {
46
+ throw c(t);
47
+ })
48
+ });
49
+ export {
50
+ w as createLevoCollectionModule
51
+ };
@@ -0,0 +1,12 @@
1
+ import { getLevoError as a } from "../utils/getLevoError.js";
2
+ const d = (s, r) => ({
3
+ mediaBulkUpload: async (t, e = {}) => r.instance.url("/v1/assets/media/bulk").options(e).post(t).json().then((o) => o).catch((o) => {
4
+ throw a(o);
5
+ }),
6
+ getAllMedia: async (t = {}) => r.instance.url("/v1/assets/media/query").post(t).json().then((e) => e).catch((e) => {
7
+ throw a(e);
8
+ })
9
+ });
10
+ export {
11
+ d as createLevoMediaModule
12
+ };
@@ -0,0 +1,50 @@
1
+ import { LevoOAuthProviderList as g } from "../constants/oauthProvider.js";
2
+ import { getLevoError as o } from "../utils/getLevoError.js";
3
+ const k = (a, r) => {
4
+ const p = async (e = {}) => r.instance.url("/v1/membership/auth/oauth/get-redirect-url").options(e).get().json().then((n) => {
5
+ const t = n?.content?.data, w = Object.keys(t);
6
+ if (typeof window < "u")
7
+ for (const i of w) {
8
+ const u = t[i];
9
+ if (u) {
10
+ const h = new URL(u), s = h.searchParams;
11
+ s.set("redirect_uri", window.location.href), a.workspace && s.set("workspace_id", a.workspace), r.pageContext && s.set("page_context", JSON.stringify(r.pageContext)), t[i] = h.toString();
12
+ }
13
+ }
14
+ return t;
15
+ }).catch(() => g.reduce((n, t) => (n[t] = null, n), {})), d = async (e = {}) => r.instance.url("/v1/membership/auth/sign-out").options(e).post("").json().then((n) => n?.content?.data).catch((n) => {
16
+ throw o(n);
17
+ }), c = async (e = {}) => r.instance.url("/v1/membership/auth/get-me").options(e).get().json().then((n) => n?.content?.data).catch((n) => {
18
+ throw o(n);
19
+ });
20
+ return {
21
+ getOAuthURL: p,
22
+ signOut: d,
23
+ getMe: c,
24
+ updateMe: async (e, n = {}) => r.instance.url("/v1/membership/auth/update-me").options(n).put(e).json().then((t) => t?.content?.data).catch((t) => {
25
+ throw o(t);
26
+ }),
27
+ createPassword: async (e, n = {}) => r.instance.url("/v1/membership/auth/change-password").options(n).put(e).json().then((t) => t?.content?.data).catch((t) => {
28
+ throw o(t);
29
+ }),
30
+ isLoggedIn: async (e = {}) => c(e).then((n) => n).catch(() => null),
31
+ requestMagicLink: async (e, n = {}) => (typeof window < "u" && !e.redirect_uri && (e.redirect_uri = window.location.href), r.instance.url("/v1/membership/auth/request-magic-link").options(n).post(e).json().then((t) => t?.content?.data).catch((t) => {
32
+ throw o(t);
33
+ })),
34
+ requestOtp: async (e, n = {}) => r.instance.url("/v1/membership/auth/request-otp").options(n).post(e).json().then((t) => t?.content?.data).catch((t) => {
35
+ throw o(t);
36
+ }),
37
+ signInWithOtp: async (e, n = {}) => r.instance.url("/v1/membership/auth/signin-with-otp").options(n).post(e).json().then((t) => t?.content?.data).catch((t) => {
38
+ throw o(t);
39
+ }),
40
+ signInWithPassword: async (e, n = {}) => r.instance.url("/v1/membership/auth/signin-with-password").options(n).post(e).json().then((t) => t?.content?.data).catch((t) => {
41
+ throw o(t);
42
+ }),
43
+ signUpWithPassword: async (e, n = {}) => r.instance.url("/v1/membership/auth/signup-with-password").options(n).post(e).json().then((t) => t?.content?.data).catch((t) => {
44
+ throw o(t);
45
+ })
46
+ };
47
+ };
48
+ export {
49
+ k as createLevoMembershipModule
50
+ };
@@ -0,0 +1,40 @@
1
+ import { listToRecord as e } from "../utils/listToX.js";
2
+ const i = [
3
+ // Bevy Events
4
+ "bevy.collection.filled",
5
+ "bevy.collection.submitted",
6
+ "bevy.collection.view",
7
+ // Block Events
8
+ "block.view",
9
+ // Blog Events
10
+ "blog.post.view",
11
+ // Event Events
12
+ "event.booking.confirmed",
13
+ "event.booking.initiated",
14
+ "event.booking.pending",
15
+ "event.coupon.applied",
16
+ "event.event.view",
17
+ // Form Events
18
+ "form.change",
19
+ "form.submit",
20
+ // Membership Events
21
+ "membership.account.signin",
22
+ "membership.account.signout",
23
+ "membership.account.signup",
24
+ // UI Events
25
+ "button.click",
26
+ "page.bounce",
27
+ "page.click",
28
+ "page.copy",
29
+ "page.impression",
30
+ "page.scroll",
31
+ "page.view",
32
+ "page.selection",
33
+ // User Activity Events
34
+ "user.active",
35
+ "user.idle"
36
+ ], n = e(i);
37
+ export {
38
+ n as AnalyticsEvents,
39
+ i as AnalyticsEventsList
40
+ };
@@ -0,0 +1,10 @@
1
+ const e = {
2
+ published: "published",
3
+ unpublished: "unpublished",
4
+ archived: "archived",
5
+ flagged: "flagged",
6
+ pending_moderation: "pending_moderation"
7
+ };
8
+ export {
9
+ e as COMMENT_STATUS
10
+ };
@@ -0,0 +1,18 @@
1
+ const e = {
2
+ post: "post",
3
+ poll: "poll",
4
+ gallery: "gallery",
5
+ link: "link"
6
+ }, d = Object.keys(e), l = {
7
+ draft: "draft",
8
+ published: "published",
9
+ unpublished: "unpublished",
10
+ archived: "archived",
11
+ flagged: "flagged",
12
+ pending_moderation: "pending_moderation"
13
+ };
14
+ export {
15
+ e as FORUM_POST_KIND,
16
+ l as FORUM_POST_STATUS,
17
+ d as ForumPostKindExpandedList
18
+ };
@@ -0,0 +1,25 @@
1
+ class s extends Error {
2
+ code;
3
+ title;
4
+ status;
5
+ type;
6
+ errors;
7
+ constructor(r) {
8
+ super(r.description), this.name = "Levo Request Error", this.status = r.status, this.code = r.code, this.title = r.title, this.type = r.type, this.errors = r.errors;
9
+ }
10
+ /**
11
+ * Get validation errors for form fields
12
+ */
13
+ get fieldErrors() {
14
+ return this.errors || [];
15
+ }
16
+ /**
17
+ * Check if this is a validation error with field-specific errors
18
+ */
19
+ get hasFieldErrors() {
20
+ return !!this.errors?.length;
21
+ }
22
+ }
23
+ export {
24
+ s as LevoError
25
+ };
@@ -0,0 +1,12 @@
1
+ const o = (e) => {
2
+ const n = e.split("/"), t = n[n.length - 1];
3
+ if (t) {
4
+ const a = encodeURIComponent(t);
5
+ return e.replace(t, a);
6
+ }
7
+ return "";
8
+ };
9
+ export {
10
+ o as default,
11
+ o as formatImagePath
12
+ };
@@ -0,0 +1,66 @@
1
+ import { WretchError as i } from "wretch/resolver";
2
+ import { LevoError as e } from "./LevoError.js";
3
+ const c = (t) => t instanceof i || t instanceof Error && "response" in t && "status" in t && "url" in t, u = (t) => {
4
+ if (t instanceof e)
5
+ return t;
6
+ if (c(t)) {
7
+ let n = t?.json;
8
+ if (!n && (t?.text || t?.message))
9
+ try {
10
+ n = JSON.parse(t.text || t.message);
11
+ } catch {
12
+ }
13
+ if (n) {
14
+ const s = n;
15
+ return new e({
16
+ status: s?.content?.status || t?.status || 500,
17
+ code: s?.content?.code || "Unknown",
18
+ title: s?.content?.title || `HTTP ${t?.status || 500} Error`,
19
+ description: s?.content?.description || s?.content?.errors?.[0]?.message || `Request failed with status ${t?.status || 500}`,
20
+ type: s?.content?.type,
21
+ errors: s?.content?.errors
22
+ });
23
+ }
24
+ return new e({
25
+ status: t?.status || 500,
26
+ code: "HTTP_ERROR",
27
+ title: `HTTP ${t?.status || 500} Error`,
28
+ description: `Request failed with status ${t?.status || 500}`
29
+ });
30
+ }
31
+ if (t instanceof TypeError) {
32
+ if (t?.message.includes("Failed to fetch") || t?.message.includes("Network request failed") || t?.message.includes("fetch"))
33
+ return new e({
34
+ status: 0,
35
+ code: "NETWORK_ERROR",
36
+ title: "Network Error",
37
+ description: "Unable to connect to the server. Please check your internet connection."
38
+ });
39
+ if (t?.message.includes("CORS") || t?.message.includes("cross-origin"))
40
+ return new e({
41
+ status: 0,
42
+ code: "CORS_ERROR",
43
+ title: "CORS Error",
44
+ description: "Cross-origin request blocked. Please contact support."
45
+ });
46
+ }
47
+ return t?.name === "AbortError" || t instanceof DOMException ? new e({
48
+ status: 408,
49
+ code: "REQUEST_TIMEOUT",
50
+ title: "Request Timeout",
51
+ description: "The request was cancelled or timed out. Please try again."
52
+ }) : t?.request ? new e({
53
+ status: t?.response?.status || 500,
54
+ code: t?.code || "REQUEST_ERROR",
55
+ title: "Request Error",
56
+ description: t?.message || "An error occurred while making the request"
57
+ }) : new e({
58
+ status: 500,
59
+ code: "UNKNOWN_ERROR",
60
+ title: "Unexpected Error",
61
+ description: t?.message || "Something unexpected happened"
62
+ });
63
+ };
64
+ export {
65
+ u as getLevoError
66
+ };
@@ -0,0 +1,5 @@
1
+ const r = (e) => e.reduce((o, t) => (o[t] = t, o), {}), n = (e) => e.reduce((o, t) => (o[t] = t, o), {});
2
+ export {
3
+ r as listToColumn,
4
+ n as listToRecord
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/core",
3
- "version": "0.1.71",
3
+ "version": "0.1.78",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Levo common utilities",
6
6
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  "typescript": "5.9.3",
23
23
  "vite": "7.2.4",
24
24
  "vite-plugin-dts": "4.1.0",
25
+ "vite-plugin-externalize-deps": "0.10.0",
25
26
  "@levo/ts-config": "0.0.0"
26
27
  },
27
28
  "main": "./dist/index.js",