@access-dlsu/leapify 0.260507.4 → 0.260507.5

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
@@ -3,7 +3,7 @@
3
3
  var chunkOK6RVPEH_cjs = require('./chunk-OK6RVPEH.cjs');
4
4
  var chunkRFP2X2FA_cjs = require('./chunk-RFP2X2FA.cjs');
5
5
  require('./chunk-JPVIXCF5.cjs');
6
- var chunkBFMJDSDI_cjs = require('./chunk-BFMJDSDI.cjs');
6
+ var chunkLVKPYSXI_cjs = require('./chunk-LVKPYSXI.cjs');
7
7
  var chunk5JKLV7IE_cjs = require('./chunk-5JKLV7IE.cjs');
8
8
  require('./chunk-NKIQRCOM.cjs');
9
9
  var chunk4DPT2KQR_cjs = require('./chunk-4DPT2KQR.cjs');
@@ -64,11 +64,14 @@ function shouldPullFromContentful(mode) {
64
64
 
65
65
  // node_modules/hono/dist/middleware/cors/index.js
66
66
  var cors = (options) => {
67
- const opts = {
67
+ const defaults = {
68
68
  origin: "*",
69
69
  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
70
70
  allowHeaders: [],
71
- exposeHeaders: [],
71
+ exposeHeaders: []
72
+ };
73
+ const opts = {
74
+ ...defaults,
72
75
  ...options
73
76
  };
74
77
  const findAllowOrigin = ((optsOrigin) => {
@@ -159,9 +162,22 @@ function createCorsMiddleware(allowedOrigins) {
159
162
  });
160
163
  return async (c, next) => {
161
164
  const origin = c.req.header("origin");
165
+ if (c.req.path.startsWith("/api/uploads/images")) {
166
+ c.header("Access-Control-Allow-Origin", "*");
167
+ c.header("Access-Control-Allow-Methods", "GET, OPTIONS");
168
+ if (c.req.method === "OPTIONS") {
169
+ return c.body(null, 204);
170
+ }
171
+ return next();
172
+ }
162
173
  if (!c.req.path.startsWith("/health") && !c.req.path.startsWith("/api/auth") && !c.req.path.startsWith("/internal") && origin && !allowedOrigins.includes("*") && !allowedOrigins.includes(origin)) {
163
174
  return c.json(
164
- { error: { code: "DOMAIN_RESTRICTED", message: `Origin ${origin} is not allowed` } },
175
+ {
176
+ error: {
177
+ code: "DOMAIN_RESTRICTED",
178
+ message: `Origin ${origin} is not allowed`
179
+ }
180
+ },
165
181
  403
166
182
  );
167
183
  }
@@ -173,7 +189,7 @@ function createCorsMiddleware(allowedOrigins) {
173
189
  function createRefererGuard(allowedOrigins) {
174
190
  const MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PATCH", "PUT", "DELETE"]);
175
191
  const SKIP_PREFIXES = ["/health", "/internal", "/api/auth", "/.well-known"];
176
- return chunkBFMJDSDI_cjs.createMiddleware(async (c, next) => {
192
+ return chunkLVKPYSXI_cjs.createMiddleware(async (c, next) => {
177
193
  if (!MUTATION_METHODS.has(c.req.method)) return next();
178
194
  if (SKIP_PREFIXES.some((p) => c.req.path.startsWith(p))) return next();
179
195
  if (allowedOrigins.includes("*")) return next();
@@ -36666,11 +36682,21 @@ function createAuth(env2) {
36666
36682
  };
36667
36683
  if (isFirstUser) {
36668
36684
  await db.insert(users).values(base).onConflictDoUpdate({
36669
- target: users.betterAuthId,
36670
- set: { role: "super_admin" }
36685
+ target: users.email,
36686
+ set: {
36687
+ betterAuthId: user.id,
36688
+ role: "super_admin",
36689
+ name: user.name ?? user.email.split("@")[0]
36690
+ }
36671
36691
  });
36672
36692
  } else {
36673
- await db.insert(users).values(base).onConflictDoNothing({ target: users.betterAuthId });
36693
+ await db.insert(users).values(base).onConflictDoUpdate({
36694
+ target: users.email,
36695
+ set: {
36696
+ betterAuthId: user.id,
36697
+ name: user.name ?? user.email.split("@")[0]
36698
+ }
36699
+ });
36674
36700
  }
36675
36701
  }
36676
36702
  }
@@ -36699,7 +36725,13 @@ async function resolveUser(env2, betterAuthUserId, betterAuthUserEmail, betterAu
36699
36725
  betterAuthId: betterAuthUserId,
36700
36726
  email: betterAuthUserEmail,
36701
36727
  name: betterAuthUserName ?? betterAuthUserEmail.split("@")[0]
36702
- }).onConflictDoNothing({ target: users.betterAuthId }).returning();
36728
+ }).onConflictDoUpdate({
36729
+ target: users.email,
36730
+ set: {
36731
+ betterAuthId: betterAuthUserId,
36732
+ name: betterAuthUserName ?? betterAuthUserEmail.split("@")[0]
36733
+ }
36734
+ }).returning();
36703
36735
  dbUser = created;
36704
36736
  }
36705
36737
  if (!dbUser) throw unauthorized("Failed to resolve user record");
@@ -36712,7 +36744,7 @@ async function resolveUser(env2, betterAuthUserId, betterAuthUserEmail, betterAu
36712
36744
  emailVerified: betterAuthEmailVerified
36713
36745
  };
36714
36746
  }
36715
- var authMiddleware = chunkBFMJDSDI_cjs.createMiddleware(
36747
+ var authMiddleware = chunkLVKPYSXI_cjs.createMiddleware(
36716
36748
  async (c, next) => {
36717
36749
  const rawToken = extractRawToken(c);
36718
36750
  if (rawToken) {
@@ -36754,7 +36786,7 @@ var authMiddleware = chunkBFMJDSDI_cjs.createMiddleware(
36754
36786
  return next();
36755
36787
  }
36756
36788
  );
36757
- var optionalAuthMiddleware = chunkBFMJDSDI_cjs.createMiddleware(async (c, next) => {
36789
+ var optionalAuthMiddleware = chunkLVKPYSXI_cjs.createMiddleware(async (c, next) => {
36758
36790
  const rawToken = extractRawToken(c);
36759
36791
  if (!rawToken) {
36760
36792
  c.set("user", null);
@@ -36762,7 +36794,7 @@ var optionalAuthMiddleware = chunkBFMJDSDI_cjs.createMiddleware(async (c, next)
36762
36794
  }
36763
36795
  return authMiddleware(c, next);
36764
36796
  });
36765
- var adminMiddleware = chunkBFMJDSDI_cjs.createMiddleware(
36797
+ var adminMiddleware = chunkLVKPYSXI_cjs.createMiddleware(
36766
36798
  async (c, next) => {
36767
36799
  const user = c.get("user");
36768
36800
  if (!user || !["admin", "super_admin"].includes(user.role)) {
@@ -36771,7 +36803,7 @@ var adminMiddleware = chunkBFMJDSDI_cjs.createMiddleware(
36771
36803
  return next();
36772
36804
  }
36773
36805
  );
36774
- var internalMiddleware = chunkBFMJDSDI_cjs.createMiddleware(async (c, next) => {
36806
+ var internalMiddleware = chunkLVKPYSXI_cjs.createMiddleware(async (c, next) => {
36775
36807
  const secret = c.req.header("X-Internal-Secret");
36776
36808
  if (!secret || secret !== c.env.INTERNAL_API_SECRET) {
36777
36809
  throw forbidden("Invalid internal secret");
@@ -36780,7 +36812,7 @@ var internalMiddleware = chunkBFMJDSDI_cjs.createMiddleware(async (c, next) => {
36780
36812
  });
36781
36813
 
36782
36814
  // src/routes/health.ts
36783
- var healthRoute = new chunkBFMJDSDI_cjs.Hono();
36815
+ var healthRoute = new chunkLVKPYSXI_cjs.Hono();
36784
36816
  async function probeResend(apiKey) {
36785
36817
  const start = Date.now();
36786
36818
  try {
@@ -37009,7 +37041,7 @@ var parse4 = (cookie, name) => {
37009
37041
  cookieValue = cookieValue.slice(1, -1);
37010
37042
  }
37011
37043
  if (validCookieValueRegEx.test(cookieValue)) {
37012
- parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? chunkBFMJDSDI_cjs.tryDecode(cookieValue, chunkBFMJDSDI_cjs.decodeURIComponent_) : cookieValue;
37044
+ parsedCookie[cookieName] = cookieValue.indexOf("%") !== -1 ? chunkLVKPYSXI_cjs.tryDecode(cookieValue, chunkLVKPYSXI_cjs.decodeURIComponent_) : cookieValue;
37013
37045
  }
37014
37046
  }
37015
37047
  return parsedCookie;
@@ -37052,7 +37084,7 @@ var validator = (target, validationFunc) => {
37052
37084
  value = await c.req.json();
37053
37085
  } catch {
37054
37086
  const message2 = "Malformed JSON in request body";
37055
- throw new chunkBFMJDSDI_cjs.HTTPException(400, { message: message2 });
37087
+ throw new chunkLVKPYSXI_cjs.HTTPException(400, { message: message2 });
37056
37088
  }
37057
37089
  break;
37058
37090
  case "form": {
@@ -37070,7 +37102,7 @@ var validator = (target, validationFunc) => {
37070
37102
  } catch (e) {
37071
37103
  let message2 = "Malformed FormData request.";
37072
37104
  message2 += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
37073
- throw new chunkBFMJDSDI_cjs.HTTPException(400, { message: message2 });
37105
+ throw new chunkLVKPYSXI_cjs.HTTPException(400, { message: message2 });
37074
37106
  }
37075
37107
  }
37076
37108
  const form = /* @__PURE__ */ Object.create(null);
@@ -37619,7 +37651,7 @@ var ContentfulManagement = class {
37619
37651
  // src/lib/middleware/rate-limit.ts
37620
37652
  function createRateLimitMiddleware(config3) {
37621
37653
  const { endpoint, limit, windowSec, identifier } = config3;
37622
- return chunkBFMJDSDI_cjs.createMiddleware(async (c, next) => {
37654
+ return chunkLVKPYSXI_cjs.createMiddleware(async (c, next) => {
37623
37655
  if (c.req.path === "/.well-known/leapify/pow/verify") return next();
37624
37656
  const id = identifier === "uid" ? c.get("user")?.uid ?? c.req.header("CF-Connecting-IP") ?? "unknown" : c.req.header("CF-Connecting-IP") ?? "unknown";
37625
37657
  const key = `rl:${endpoint}:${id}`;
@@ -37754,7 +37786,7 @@ var createEventSchema = external_exports.object({
37754
37786
  contentfulEntryId: external_exports.string().optional(),
37755
37787
  status: external_exports.enum(["draft", "queued", "published"]).default("draft")
37756
37788
  });
37757
- var classesRoute = new chunkBFMJDSDI_cjs.Hono();
37789
+ var classesRoute = new chunkLVKPYSXI_cjs.Hono();
37758
37790
  function generateSlug(title) {
37759
37791
  return title.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
37760
37792
  }
@@ -37944,7 +37976,7 @@ classesRoute.delete("/:slug", authMiddleware, adminMiddleware, async (c) => {
37944
37976
 
37945
37977
  // src/routes/users.ts
37946
37978
  var VALID_ROLES = ["student", "admin", "super_admin"];
37947
- var usersRoute = new chunkBFMJDSDI_cjs.Hono();
37979
+ var usersRoute = new chunkLVKPYSXI_cjs.Hono();
37948
37980
  usersRoute.get("/", authMiddleware, adminMiddleware, async (c) => {
37949
37981
  const db = createDb(c.env.DB);
37950
37982
  const data = await db.select().from(users);
@@ -38647,7 +38679,7 @@ async function pushToContentful(db, mgmt, config3 = {}, kv, forceFull = false) {
38647
38679
  }
38648
38680
 
38649
38681
  // src/routes/site-config.ts
38650
- var siteConfigRoute = new chunkBFMJDSDI_cjs.Hono();
38682
+ var siteConfigRoute = new chunkLVKPYSXI_cjs.Hono();
38651
38683
  siteConfigRoute.get("/", async (c) => {
38652
38684
  const db = createDb(c.env.DB);
38653
38685
  const rows = await db.query.siteConfig.findMany();
@@ -38722,7 +38754,7 @@ var faqSchema = external_exports.object({
38722
38754
  category: external_exports.string().optional(),
38723
38755
  sortOrder: external_exports.number().int().default(0)
38724
38756
  });
38725
- var faqsRoute = new chunkBFMJDSDI_cjs.Hono();
38757
+ var faqsRoute = new chunkLVKPYSXI_cjs.Hono();
38726
38758
  async function pushFaqToContentful(env2, faq) {
38727
38759
  console.log("[Contentful] pushFaqToContentful called for FAQ:", faq.id);
38728
38760
  if (!ContentfulManagement.isConfigured(env2.CONTENTFUL_SPACE_ID, env2.CONTENTFUL_MANAGEMENT_TOKEN)) {
@@ -38806,7 +38838,7 @@ faqsRoute.delete("/:id", authMiddleware, adminMiddleware, async (c) => {
38806
38838
  });
38807
38839
 
38808
38840
  // src/routes/internal/gforms-webhook.ts
38809
- var gformsWebhookRoute = new chunkBFMJDSDI_cjs.Hono();
38841
+ var gformsWebhookRoute = new chunkLVKPYSXI_cjs.Hono();
38810
38842
  gformsWebhookRoute.post("/", internalMiddleware, async (c) => {
38811
38843
  const rawBody = await c.req.text();
38812
38844
  const signature = c.req.header("X-Goog-Signature");
@@ -38878,7 +38910,7 @@ var ALLOWED_MIME_TYPES = /* @__PURE__ */ new Set([
38878
38910
  "image/svg+xml"
38879
38911
  ]);
38880
38912
  var MAX_FILE_SIZE = 10 * 1024 * 1024;
38881
- var uploadsRoute = new chunkBFMJDSDI_cjs.Hono();
38913
+ var uploadsRoute = new chunkLVKPYSXI_cjs.Hono();
38882
38914
  uploadsRoute.get("/images/*", async (c) => {
38883
38915
  const bucket = c.env.FILES;
38884
38916
  if (!bucket) {
@@ -39052,7 +39084,7 @@ var createThemeSchema = external_exports.object({
39052
39084
  name: external_exports.string().min(1),
39053
39085
  path: external_exports.string().min(1)
39054
39086
  });
39055
- var themesRoute = new chunkBFMJDSDI_cjs.Hono();
39087
+ var themesRoute = new chunkLVKPYSXI_cjs.Hono();
39056
39088
  themesRoute.get("/", async (c) => {
39057
39089
  const db = createDb(c.env.DB);
39058
39090
  const data = await db.select().from(themes);
@@ -39121,7 +39153,7 @@ var createOrganizationSchema = external_exports.object({
39121
39153
  logoUrl: external_exports.string().url().nullable().optional(),
39122
39154
  link: external_exports.string().url().nullable().optional()
39123
39155
  });
39124
- var organizationsRoute = new chunkBFMJDSDI_cjs.Hono();
39156
+ var organizationsRoute = new chunkLVKPYSXI_cjs.Hono();
39125
39157
  organizationsRoute.get("/", async (c) => {
39126
39158
  const db = createDb(c.env.DB);
39127
39159
  const data = await db.select().from(organizations);
@@ -39175,7 +39207,7 @@ organizationsRoute.delete("/:id", authMiddleware, adminMiddleware, async (c) =>
39175
39207
  });
39176
39208
 
39177
39209
  // src/routes/contentful-sync.ts
39178
- var contentfulSyncRoute = new chunkBFMJDSDI_cjs.Hono();
39210
+ var contentfulSyncRoute = new chunkLVKPYSXI_cjs.Hono();
39179
39211
  contentfulSyncRoute.post(
39180
39212
  "/trigger",
39181
39213
  authMiddleware,
@@ -39253,7 +39285,7 @@ contentfulSyncRoute.get(
39253
39285
 
39254
39286
  // src/app.ts
39255
39287
  function createApp(options = {}) {
39256
- const app = new chunkBFMJDSDI_cjs.Hono();
39288
+ const app = new chunkLVKPYSXI_cjs.Hono();
39257
39289
  if (options.gformsWebhookUrl) {
39258
39290
  const webhookUrl = `${options.gformsWebhookUrl.replace(/\/$/, "")}/internal/gforms-webhook`;
39259
39291
  app.use("*", async (c, next) => {
@@ -39262,7 +39294,7 @@ function createApp(options = {}) {
39262
39294
  });
39263
39295
  }
39264
39296
  app.use("*", createCorsMiddleware(options.allowedOrigins ?? ["*"]));
39265
- app.use("*", chunkBFMJDSDI_cjs.createPowChallengeMiddleware());
39297
+ app.use("*", chunkLVKPYSXI_cjs.createPowChallengeMiddleware());
39266
39298
  app.use("*", createRefererGuard(options.allowedOrigins ?? ["*"]));
39267
39299
  app.use("*", async (c, next) => {
39268
39300
  const overrideRaw = await c.env.KV.get("config:cms_mode").catch(() => null);
@@ -39299,7 +39331,7 @@ function createApp(options = {}) {
39299
39331
  }
39300
39332
  return next();
39301
39333
  });
39302
- app.post(chunkBFMJDSDI_cjs.POW_VERIFY_PATH, chunkBFMJDSDI_cjs.handlePowVerify);
39334
+ app.post(chunkLVKPYSXI_cjs.POW_VERIFY_PATH, chunkLVKPYSXI_cjs.handlePowVerify);
39303
39335
  app.route("/health", healthRoute);
39304
39336
  app.route("/api/config", siteConfigRoute);
39305
39337
  app.route("/api/classes", classesRoute);
@@ -40108,7 +40140,7 @@ async function ensureDatabase(d1) {
40108
40140
  try {
40109
40141
  await d1.prepare(sql3).run();
40110
40142
  } catch (err) {
40111
- if (err?.message?.includes("duplicate column") || err?.message?.includes("no such column: is_major")) {
40143
+ if (err?.message?.includes("duplicate column") || err?.message?.includes("no such column") && err?.message?.includes("is_major")) {
40112
40144
  continue;
40113
40145
  }
40114
40146
  throw err;