-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix type issues in Tolt importer #2782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughIntroduces a fallback-based external customer identity in the import flow by computing Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Importer as Batch Import
participant Zod as Schemas
participant Resolver as Link Resolver
participant DB as Prisma
participant Logger as Logger
participant Events as Click Emitter
rect rgb(245,250,255)
note over Importer,Zod: Parse and normalize inputs
Importer->>Zod: validate customer + link
Zod-->>Importer: { customer_id|null, email, id, link.value (slugified) }
Importer->>Importer: customerExternalId = customer_id ?? email ?? id
end
alt Link resolved
Importer->>Resolver: resolve link (slug / partner.email)
Resolver-->>Importer: link
Importer->>DB: upsert Customer { externalId: customerExternalId, ... }
DB-->>Importer: upsert result
Importer->>Events: emit click { externalId: customerExternalId, ... }
Events-->>Importer: ack
Importer->>Logger: log success (entity_id=customerExternalId)
else Link not found
Importer->>Logger: log LINK_NOT_FOUND (entity_id=customerExternalId)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/web/lib/tolt/schemas.ts (2)
44-44: Trim before slugifying to avoid leading/trailing dash artifacts.Apply:
- value: z.string().transform((val) => slugify(val)), // need to slugify this cause Tolt can sometimes return "john doe" + value: z.string().transform((val) => slugify(val.trim())), // need to slugify this cause Tolt can sometimes return "john doe"
50-54: Normalize empty strings to null for customer_id.
Empty string is not nullish; downstream??would pick it and produce an empty externalId.Consider:
-export const ToltCustomerSchema = z.object({ +export const ToltCustomerSchema = z.object({ id: z.string(), - customer_id: z - .string() - .describe("Internal customer identifier in client's app.") - .nullable(), + customer_id: z.preprocess( + (v) => (typeof v === "string" && v.trim() === "" ? null : v), + z.string().describe("Internal customer identifier in client's app.").nullable(), + ), email: z.string().nullable(), name: z.string().nullable(),apps/web/lib/tolt/import-customers.ts (1)
160-161: Nit: include quotes around id for clearer logs.- `A customer already exists with customerExternalId ${customerExternalId}`, + `A customer already exists with customerExternalId "${customerExternalId}"`,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/lib/tolt/import-customers.ts(3 hunks)apps/web/lib/tolt/schemas.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/lib/tolt/import-customers.ts (1)
apps/web/lib/tinybird/log-import-error.ts (1)
logImportError(4-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (5)
apps/web/lib/tolt/schemas.ts (1)
1-1: LGTM on adding slugify import.apps/web/lib/tolt/import-customers.ts (4)
10-10: Type-only import looks right.
Matches the schema changes (nullable customer_id).
139-140: LGTM on improved log context.
153-154: LGTM: unique lookup now aligned with normalized externalId.
214-215: LGTM: create payload uses normalized externalId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
apps/web/lib/tolt/import-customers.ts (2)
127-133: Avoid empty-string entity_id; coalesce to first non-empty normalized valueUsing ?? will accept "", causing bad keys and uniqueness collisions. Normalize email to lowercase and pick the first non-empty candidate.
- const commonImportLogInputs = { + const normalisedEmail = customer.email?.trim().toLowerCase() ?? null; + const entityId = + [customer.customer_id, normalisedEmail, customer.id].find( + (v): v is string => !!v && v.trim().length > 0, + ) ?? customer.id; + const commonImportLogInputs = { workspace_id: workspace.id, import_id: importId, source: "tolt", entity: "customer", - entity_id: customer.customer_id ?? customer.email ?? customer.id, + entity_id: entityId, } as const;
145-148: Unify customerExternalId with normalized entityIdReuse the computed entityId to keep logs, lookups, and persistence consistent and non-empty.
- // if customer_id is null, use customer email or Tolt customer ID as the external ID - const customerExternalId = - customer.customer_id ?? customer.email ?? customer.id; + // external ID: first non-empty of customer_id, normalized email, or Tolt ID + const customerExternalId = entityId;
🧹 Nitpick comments (2)
apps/web/lib/tolt/schemas.ts (1)
44-46: Trim before slugifying to avoid stray dashes and inconsistent keysSlugify after a trim to normalize inputs like " john doe ". Also consider being explicit about lowercase for determinism.
- value: z.string().transform((val) => slugify(val)), // need to slugify this cause Tolt can sometimes return "john doe" + value: z.string().transform((val) => slugify(val.trim())), // trim before slugifyapps/web/lib/tolt/import-customers.ts (1)
160-160: Use structured, low-PII loggingPrefer a concise, structured message and avoid dumping full objects where possible.
- console.log( - `A customer already exists with customerExternalId ${customerExternalId}`, - ); + console.info(`Customer exists; skipping import. externalId=${customerExternalId}`);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/lib/tolt/import-customers.ts(3 hunks)apps/web/lib/tolt/schemas.ts(2 hunks)
🔇 Additional comments (5)
apps/web/lib/tolt/schemas.ts (1)
1-1: LGTM: import added where usedImport aligns with the new transform usage.
apps/web/lib/tolt/import-customers.ts (4)
10-10: LGTM: types importKeeps call sites strongly typed.
139-140: Message OK; ensure it reflects normalized entityIdOnce the entityId change above lands, this log will automatically reference the normalized ID. No further change needed.
153-154: LGTM: unique lookup by (projectId, externalId)Correct uniqueness criterion assuming the composite unique exists in Prisma.
If unsure, verify the composite unique in schema: search for
@@unique([projectId, externalId]).
214-214: LGTM: persist normalized externalIdThis will prevent duplicates and empty keys once normalized upstream.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor