Skip to content

Commit

Permalink
feat: include contact fields on the api
Browse files Browse the repository at this point in the history
  • Loading branch information
marian2js committed Aug 29, 2023
1 parent 265a25a commit 34940ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/api/src/chat/entities/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Contact extends BaseEntity {
@prop({ default: [], index: true })
tags: string[]

@Field(() => GraphQLJSONObject, { nullable: true })
@jsonProp()
fields?: Record<string, any>
}
Expand Down
18 changes: 17 additions & 1 deletion apps/runner/src/utils/input.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
return input
}

// Your custom handler for undefined functions
const customFunctionHandler = (name, args) => {
console.log(`Unknown function ${name} called with arguments:`, args)
// You can return whatever you like here or throw an error
return null
}

/**
* Replace references with their values and calculate expression
* Example:
Expand All @@ -60,7 +67,7 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
*/
export function calculateExpression(input: string, references: Record<string, Record<string, unknown>>): unknown {
// each "[\w[\]]" group matches the allowed characters for variables, including array access (e.g. a.b[0].c)
const operatorsRegex = /[\w\s[\]]+(\.[\w\s[\]]+|\[\d+\])*/g
const operatorsRegex = /(\w+\[\w+\]|\w+)\.[\w\[\]]+(\.[\w\[\]]+)*/g

const operators = [...input.matchAll(operatorsRegex)]

Expand Down Expand Up @@ -100,6 +107,11 @@ export function calculateExpression(input: string, references: Record<string, Re
}
return ('' + str).substring(start, end)
})
parser.set('contact', (str: string, params: string) => {
console.log(`get: ${str}`, params)
console.log(`references:`, references)
return _.get(references, `${str}[${params}]`)
})
parser.set('formatNumber', (value: number, locales?: Intl.LocalesArgument) => Number(value).toLocaleString(locales))
parser.set('lowercase', (str: string) => (str ? ('' + str).toLowerCase() : str))
parser.set('uppercase', (str: string) => (str ? ('' + str).toUpperCase() : str))
Expand Down Expand Up @@ -181,3 +193,7 @@ export function findOutputKeys(input: Record<string, any>, key: string): string[

return matches
}

export function strToInterpolationKey(str: string): string {
return str.replace(/[^a-zA-Z0-9]/g, '_')
}
2 changes: 2 additions & 0 deletions generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ export interface Contact {
createdAt: DateTime;
address: string;
tags?: Nullable<string[]>;
fields?: Nullable<JSONObject>;
}

export interface AccountCredential {
Expand Down Expand Up @@ -1372,6 +1373,7 @@ export interface ContactDeleteResponse {
createdAt?: Nullable<DateTime>;
address?: Nullable<string>;
tags?: Nullable<string[]>;
fields?: Nullable<JSONObject>;
}

export interface ContactEdge {
Expand Down
2 changes: 2 additions & 0 deletions generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ type Contact {
createdAt: DateTime!
address: String!
tags: [String!]
fields: JSONObject
}

type AccountCredential {
Expand Down Expand Up @@ -826,6 +827,7 @@ type ContactDeleteResponse {
createdAt: DateTime
address: String
tags: [String!]
fields: JSONObject
}

type ContactEdge {
Expand Down

0 comments on commit 34940ba

Please sign in to comment.