@access-dlsu/leapify 0.260601.2 → 0.260602.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.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkX4OB4DZ3_cjs = require('./chunk-X4OB4DZ3.cjs');
3
+ var chunkZV4TIJXI_cjs = require('./chunk-ZV4TIJXI.cjs');
4
4
  var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
5
5
  var hono = require('hono');
6
6
  var cors = require('hono/cors');
@@ -22,8 +22,6 @@ var LeapifyError = class extends Error {
22
22
  this.code = code;
23
23
  this.name = "LeapifyError";
24
24
  }
25
- statusCode;
26
- code;
27
25
  };
28
26
  var unauthorized = (message = "Unauthorized") => new LeapifyError(401, "UNAUTHORIZED", message);
29
27
  var domainRestricted = () => new LeapifyError(
@@ -89,6 +87,10 @@ var themes = sqliteCore.sqliteTable("themes", {
89
87
  name: sqliteCore.text("name").notNull().unique(),
90
88
  path: sqliteCore.text("path").notNull().unique(),
91
89
  // e.g. "/pirates-cove"
90
+ imageUrl: sqliteCore.text("image_url"),
91
+ descriptionEn: sqliteCore.text("description_en"),
92
+ descriptionFil: sqliteCore.text("description_fil"),
93
+ sortOrder: sqliteCore.integer("sort_order").notNull().default(0),
92
94
  createdAt: sqliteCore.integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3)),
93
95
  updatedAt: sqliteCore.integer("updated_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
94
96
  });
@@ -750,7 +752,6 @@ var CacheService = class {
750
752
  constructor(kv) {
751
753
  this.kv = kv;
752
754
  }
753
- kv;
754
755
  async get(key) {
755
756
  return this.kv.get(key, "json");
756
757
  }
@@ -796,8 +797,6 @@ var SlotsService = class {
796
797
  this.db = db;
797
798
  this.cache = cache;
798
799
  }
799
- db;
800
- cache;
801
800
  kvKey(slug) {
802
801
  return `${SLOT_KV_PREFIX}${slug}`;
803
802
  }
@@ -1455,7 +1454,7 @@ faqsRoute.get("/", async (c) => {
1455
1454
  const data = await cache.getOrSet(
1456
1455
  FAQS_KV_KEY,
1457
1456
  () => db.query.faqs.findMany({
1458
- orderBy: (t, { asc }) => [asc(t.sortOrder), asc(t.createdAt)]
1457
+ orderBy: (t, { asc: asc2 }) => [asc2(t.sortOrder), asc2(t.createdAt)]
1459
1458
  }),
1460
1459
  FAQS_TTL
1461
1460
  );
@@ -1846,14 +1845,27 @@ function extensionFromMime(mime) {
1846
1845
  };
1847
1846
  return map[mime] ?? "bin";
1848
1847
  }
1848
+ function generatePath(name) {
1849
+ return name.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
1850
+ }
1849
1851
  var createThemeSchema = zod.z.object({
1850
1852
  name: zod.z.string().min(1),
1851
- path: zod.z.string().min(1)
1853
+ imageUrl: zod.z.string().url().nullable().optional(),
1854
+ descriptionEn: zod.z.string().nullable().optional(),
1855
+ descriptionFil: zod.z.string().nullable().optional(),
1856
+ sortOrder: zod.z.number().int().default(0)
1857
+ });
1858
+ zod.z.object({
1859
+ name: zod.z.string().min(1).optional(),
1860
+ imageUrl: zod.z.string().url().nullable().optional(),
1861
+ descriptionEn: zod.z.string().nullable().optional(),
1862
+ descriptionFil: zod.z.string().nullable().optional(),
1863
+ sortOrder: zod.z.number().int().optional()
1852
1864
  });
1853
1865
  var themesRoute = new hono.Hono();
1854
1866
  themesRoute.get("/", async (c) => {
1855
1867
  const db = createDb(c.env.DB);
1856
- const data = await db.select().from(themes);
1868
+ const data = await db.select().from(themes).orderBy(drizzleOrm.asc(themes.sortOrder), drizzleOrm.asc(themes.createdAt));
1857
1869
  return c.json({ data });
1858
1870
  });
1859
1871
  themesRoute.post(
@@ -1864,8 +1876,9 @@ themesRoute.post(
1864
1876
  async (c) => {
1865
1877
  const body = c.req.valid("json");
1866
1878
  const db = createDb(c.env.DB);
1879
+ const path = generatePath(body.name);
1867
1880
  try {
1868
- const [created] = await db.insert(themes).values(body).returning();
1881
+ const [created] = await db.insert(themes).values({ ...body, path }).returning();
1869
1882
  return c.json({ data: created }, 201);
1870
1883
  } catch (err) {
1871
1884
  if (err.message && err.message.includes("UNIQUE constraint failed")) {
@@ -1883,8 +1896,12 @@ themesRoute.patch(
1883
1896
  const { id } = c.req.param();
1884
1897
  const body = await c.req.json();
1885
1898
  const db = createDb(c.env.DB);
1899
+ const update = { ...body };
1900
+ if (body.name) {
1901
+ update.path = generatePath(body.name);
1902
+ }
1886
1903
  try {
1887
- const [updated] = await db.update(themes).set(body).where(drizzleOrm.eq(themes.id, id)).returning();
1904
+ const [updated] = await db.update(themes).set(update).where(drizzleOrm.eq(themes.id, id)).returning();
1888
1905
  if (!updated) throw notFound("Theme");
1889
1906
  return c.json({ data: updated });
1890
1907
  } catch (err) {
@@ -1972,7 +1989,7 @@ function createApp(options = {}) {
1972
1989
  });
1973
1990
  }
1974
1991
  app.use("*", createCorsMiddleware(options.allowedOrigins ?? ["*"]));
1975
- app.use("*", chunkX4OB4DZ3_cjs.createTurnstileMiddleware());
1992
+ app.use("*", chunkZV4TIJXI_cjs.createTurnstileMiddleware());
1976
1993
  app.use("*", createRefererGuard(options.allowedOrigins ?? ["*"]));
1977
1994
  app.on(["POST", "GET"], "/api/auth/*", (c) => {
1978
1995
  const auth = createAuth(c.env);
@@ -2003,7 +2020,7 @@ function createApp(options = {}) {
2003
2020
  }
2004
2021
  return next();
2005
2022
  });
2006
- app.post(chunkX4OB4DZ3_cjs.TURNSTILE_VERIFY_PATH, chunkX4OB4DZ3_cjs.handleTurnstileVerify);
2023
+ app.post(chunkZV4TIJXI_cjs.TURNSTILE_VERIFY_PATH, chunkZV4TIJXI_cjs.handleTurnstileVerify);
2007
2024
  app.route("/health", healthRoute);
2008
2025
  app.route("/api/config", siteConfigRoute);
2009
2026
  app.route("/api/classes", classesRoute);
@@ -2122,7 +2139,6 @@ var SesError = class extends Error {
2122
2139
  this.status = status;
2123
2140
  this.name = "SesError";
2124
2141
  }
2125
- status;
2126
2142
  /**
2127
2143
  * True for errors that are permanent (not worth retrying via SES again).
2128
2144
  * 400 BadRequest, 403 Forbidden, 404 NotFound → non-retryable.