@odla-ai/chapter 0.7.0 → 0.9.0

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
@@ -33,8 +33,10 @@ __export(index_exports, {
33
33
  canceledPatch: () => canceledPatch,
34
34
  chapterDb: () => chapterDb,
35
35
  clerkInviteRequest: () => clerkInviteRequest,
36
+ clerkUserRequest: () => clerkUserRequest,
36
37
  createChapterIntegration: () => createChapterIntegration,
37
38
  createClerkInvitation: () => createClerkInvitation,
39
+ createClerkUser: () => createClerkUser,
38
40
  defaultCrm: () => defaultCrm,
39
41
  defineChapter: () => defineChapter,
40
42
  emailGroupFrom: () => emailGroupFrom,
@@ -308,7 +310,7 @@ Warmly,
308
310
  ${name}`;
309
311
  return {
310
312
  adminNotification: {
311
- subject: `New application \u2014 {{firstName}} {{lastName}}`,
313
+ subject: `New application: {{firstName}} {{lastName}}`,
312
314
  text: `A new application came in for ${name}.
313
315
 
314
316
  Name: {{firstName}} {{lastName}}
@@ -327,7 +329,7 @@ Your membership payment is confirmed. We'll be in touch to schedule your intro c
327
329
  Looking forward to our call at {{meetingTime}}. {{meetingLink}}${sign}`
328
330
  },
329
331
  onboardingInvite: {
330
- subject: `You're in \u2014 ${name}`,
332
+ subject: `You're in, ${name}`,
331
333
  text: `Hi {{firstName}},
332
334
 
333
335
  Welcome to ${name}. Your member area is here: {{membersUrl}}${sign}`
@@ -552,6 +554,10 @@ function defineChapter(config) {
552
554
  const application = resolveApplication(config.application);
553
555
  const { schema, rules } = chapterDb(mode, auth);
554
556
  const services = config.services ?? ["db", "calendar", "o11y"];
557
+ const account = config.account ?? "invite";
558
+ if (account !== "invite" && account !== "create" && account !== "none") {
559
+ throw new Error(`defineChapter.account: must be "invite", "create", or "none" \u2014 got "${String(account)}"`);
560
+ }
555
561
  const chapter = {
556
562
  config,
557
563
  id: id2,
@@ -564,6 +570,7 @@ function defineChapter(config) {
564
570
  schema,
565
571
  rules,
566
572
  services,
573
+ account,
567
574
  groupSeed: () => mode === "chapter" ? buildGroupSeed(config) : null
568
575
  };
569
576
  if (config.url !== void 0) chapter.url = config.url;
@@ -590,7 +597,7 @@ function createChapterIntegration(chapter, options = {}) {
590
597
  }
591
598
  return {
592
599
  id: "chapter",
593
- title: `Chapter \u2014 ${chapter.name}`,
600
+ title: `Chapter: ${chapter.name}`,
594
601
  npm: "@odla-ai/chapter",
595
602
  schema: {
596
603
  entities: { ...crmDesc.schema.entities, ...chapter.schema.entities },
@@ -841,13 +848,15 @@ async function projectApplicant(deps, applicant) {
841
848
  }
842
849
 
843
850
  // src/clerk.ts
851
+ var heal = (status) => status === 422 ? { ok: true, status, existed: true } : { ok: false, status };
844
852
  function clerkInviteRequest(input) {
845
853
  return {
846
854
  path: "/v1/invitations",
847
855
  body: {
848
856
  email_address: input.email,
849
857
  notify: true,
850
- ...input.redirectUrl ? { redirect_url: input.redirectUrl } : {}
858
+ ...input.redirectUrl ? { redirect_url: input.redirectUrl } : {},
859
+ ...input.publicMetadata ? { public_metadata: input.publicMetadata } : {}
851
860
  }
852
861
  };
853
862
  }
@@ -858,7 +867,28 @@ async function createClerkInvitation(secretKey, input, fetchImpl = fetch) {
858
867
  headers: { authorization: `Bearer ${secretKey}`, "content-type": "application/json" },
859
868
  body: JSON.stringify(body)
860
869
  });
861
- return { ok: res.ok, status: res.status };
870
+ return res.ok ? { ok: true, status: res.status } : heal(res.status);
871
+ }
872
+ function clerkUserRequest(input) {
873
+ return {
874
+ path: "/v1/users",
875
+ body: {
876
+ email_address: [input.email],
877
+ skip_password_requirement: true,
878
+ ...input.firstName ? { first_name: input.firstName } : {},
879
+ ...input.lastName ? { last_name: input.lastName } : {},
880
+ ...input.publicMetadata ? { public_metadata: input.publicMetadata } : {}
881
+ }
882
+ };
883
+ }
884
+ async function createClerkUser(secretKey, input, fetchImpl = fetch) {
885
+ const { path, body } = clerkUserRequest(input);
886
+ const res = await fetchImpl(`https://api.clerk.com${path}`, {
887
+ method: "POST",
888
+ headers: { authorization: `Bearer ${secretKey}`, "content-type": "application/json" },
889
+ body: JSON.stringify(body)
890
+ });
891
+ return res.ok ? { ok: true, status: res.status } : heal(res.status);
862
892
  }
863
893
 
864
894
  // src/session.ts