@odla-ai/chapter 0.25.1 → 0.25.3

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.
@@ -111,6 +111,17 @@ function createWorkerContext(options) {
111
111
  // src/worker-routes.ts
112
112
  import { createCrmRoutes } from "@odla-ai/crm";
113
113
 
114
+ // src/application-id.ts
115
+ var APPLICATION_ID_DOMAIN = "odla-ai/chapter/application/v1:";
116
+ async function applicationIdForSubmission(submissionId) {
117
+ const input = new TextEncoder().encode(`${APPLICATION_ID_DOMAIN}${submissionId}`);
118
+ const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", input)).slice(0, 16);
119
+ bytes[6] = bytes[6] & 15 | 128;
120
+ bytes[8] = bytes[8] & 63 | 128;
121
+ const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
122
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
123
+ }
124
+
114
125
  // src/member.ts
115
126
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
116
127
  function isValidEmail(value) {
@@ -154,7 +165,7 @@ async function submitApplication(db, chapter, fields, opts) {
154
165
  if (app.requireDisclaimerAck && !acked) {
155
166
  return { ok: false, error: "disclaimerAck is required" };
156
167
  }
157
- const id = opts.newId();
168
+ const id = opts.submissionId ? await applicationIdForSubmission(opts.submissionId) : opts.newId();
158
169
  const row = { id, status: chapter.pipeline.initial, createdAt: opts.now };
159
170
  for (const f of [...app.required, ...app.optional]) {
160
171
  if (typeof fields[f] === "string") row[f] = fields[f].trim();