Skip to content

Commit ac9e2c5

Browse files
committed
refactor: simplify and clean up the sweep changes
1 parent e6a70d9 commit ac9e2c5

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎apps/sim/blocks/blocks/microsoft_dynamics_365.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ function optionalBoundedString(
8989
return normalized
9090
}
9191

92-
/** `primary` unless it is unset (`undefined`, `null`, or `''`), else `fallback`. */
92+
function isUnset(value: unknown): boolean {
93+
return value === undefined || value === null || value === ''
94+
}
95+
9396
function firstSet(primary: unknown, fallback: unknown): unknown {
94-
return primary === undefined || primary === null || primary === '' ? fallback : primary
97+
return isUnset(primary) ? fallback : primary
9598
}
9699

97100
function getListPaginationParams(
@@ -933,7 +936,7 @@ export const MicrosoftDynamics365Block: BlockConfig = {
933936

934937
case 'qualify_lead': {
935938
const qualifySwitch = (value: unknown, label: string, defaultValue: boolean) =>
936-
isToolCall(context) && (value === undefined || value === null || value === '')
939+
isToolCall(context) && isUnset(value)
937940
? undefined
938941
: parseBooleanWithDefault(value, label, defaultValue)
939942
const createAccount = qualifySwitch(params.createAccount, 'Create account', true)
@@ -956,9 +959,6 @@ export const MicrosoftDynamics365Block: BlockConfig = {
956959
params.qualifyOpportunityCurrencyId,
957960
params.opportunityCurrencyId
958961
)
959-
const dedicatedCustomerId = createOpportunity
960-
? optionalString(params.qualifyOpportunityCustomerId)
961-
: undefined
962962
const opportunityCustomerId = opportunityField(
963963
params.qualifyOpportunityCustomerId,
964964
params.opportunityCustomerId
@@ -982,7 +982,7 @@ export const MicrosoftDynamics365Block: BlockConfig = {
982982
}
983983
const opportunityCustomerType = opportunityCustomerId
984984
? requiredString(
985-
dedicatedCustomerId
985+
optionalString(params.qualifyOpportunityCustomerId)
986986
? params.qualifyOpportunityCustomerType
987987
: firstSet(
988988
toolCallArg(context, params.opportunityCustomerType),

‎apps/sim/tools/snowflake/sql.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535

3636
const context = { oauthCredential: 'cred-1' }
3737
const table = { ...context, database: 'ANALYTICS', schema: 'PUBLIC', table: 'EVENTS' }
38+
const untyped = (flags: Record<string, unknown>) => flags as Record<string, never>
3839
const queryId = '01b71944-0301-b428-0000-69f706bf0001'
3940

4041
/** ISO instants inside the history retention windows, so assertions never age out. */
@@ -483,7 +484,6 @@ describe('Snowflake SQL builders', () => {
483484
})
484485

485486
it('never turns an absent or string-false flag from a tool call into a clause', () => {
486-
const untyped = (flags: Record<string, unknown>) => flags as Record<string, never>
487487
expect(
488488
buildAlterWarehouse({
489489
...context,
@@ -507,7 +507,6 @@ describe('Snowflake SQL builders', () => {
507507
})
508508

509509
it('reads string flags from a tool call case-insensitively', () => {
510-
const untyped = (flags: Record<string, unknown>) => flags as Record<string, never>
511510
expect(
512511
buildAlterWarehouse({
513512
...context,

0 commit comments

Comments
 (0)