Skip to content

Commit 34940ba

Browse files
committed
feat: include contact fields on the api
1 parent 265a25a commit 34940ba

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

apps/api/src/chat/entities/contact.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class Contact extends BaseEntity {
3131
@prop({ default: [], index: true })
3232
tags: string[]
3333

34+
@Field(() => GraphQLJSONObject, { nullable: true })
3435
@jsonProp()
3536
fields?: Record<string, any>
3637
}

apps/runner/src/utils/input.utils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
5151
return input
5252
}
5353

54+
// Your custom handler for undefined functions
55+
const customFunctionHandler = (name, args) => {
56+
console.log(`Unknown function ${name} called with arguments:`, args)
57+
// You can return whatever you like here or throw an error
58+
return null
59+
}
60+
5461
/**
5562
* Replace references with their values and calculate expression
5663
* Example:
@@ -60,7 +67,7 @@ export function parseInput(input: unknown, outputs: Record<string, Record<string
6067
*/
6168
export function calculateExpression(input: string, references: Record<string, Record<string, unknown>>): unknown {
6269
// each "[\w[\]]" group matches the allowed characters for variables, including array access (e.g. a.b[0].c)
63-
const operatorsRegex = /[\w\s[\]]+(\.[\w\s[\]]+|\[\d+\])*/g
70+
const operatorsRegex = /(\w+\[\w+\]|\w+)\.[\w\[\]]+(\.[\w\[\]]+)*/g
6471

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

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

182194
return matches
183195
}
196+
197+
export function strToInterpolationKey(str: string): string {
198+
return str.replace(/[^a-zA-Z0-9]/g, '_')
199+
}

generated/graphql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ export interface Contact {
10601060
createdAt: DateTime;
10611061
address: string;
10621062
tags?: Nullable<string[]>;
1063+
fields?: Nullable<JSONObject>;
10631064
}
10641065

10651066
export interface AccountCredential {
@@ -1372,6 +1373,7 @@ export interface ContactDeleteResponse {
13721373
createdAt?: Nullable<DateTime>;
13731374
address?: Nullable<string>;
13741375
tags?: Nullable<string[]>;
1376+
fields?: Nullable<JSONObject>;
13751377
}
13761378

13771379
export interface ContactEdge {

generated/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ type Contact {
413413
createdAt: DateTime!
414414
address: String!
415415
tags: [String!]
416+
fields: JSONObject
416417
}
417418

418419
type AccountCredential {
@@ -826,6 +827,7 @@ type ContactDeleteResponse {
826827
createdAt: DateTime
827828
address: String
828829
tags: [String!]
830+
fields: JSONObject
829831
}
830832

831833
type ContactEdge {

0 commit comments

Comments
 (0)