Skip to content
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

[wip dont review] SFMC Create a data extension #2711

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions packages/cli/src/commands/generate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ export default class GenerateTypes extends Command {

if (action.hooks) {
const hooks: ActionHookDefinition<any, any, any, any, any> = action.hooks
let hookBundle = ''
const hookFields: Record<string, any> = {}

for (const [hookName, hook] of Object.entries(hooks)) {
if (!hookTypeStrings.includes(hookName as ActionHookType)) {
throw new Error(`Hook name ${hookName} is not a valid ActionHookType`)
Expand All @@ -155,30 +154,16 @@ export default class GenerateTypes extends Command {
continue
}

const hookSchema = {
type: 'object',
required: true,
properties: {
inputs: {
label: `${hookName} hook inputs`,
type: 'object',
properties: inputs
},
outputs: {
label: `${hookName} hook outputs`,
type: 'object',
properties: outputs
}
}
if (inputs) {
const inputTypes = await generateTypes(inputs, `${hookName}Inputs`)
types += inputTypes
}

if (outputs) {
const outputTypes = await generateTypes(outputs, `${hookName}Outputs`)
types += outputTypes
}
hookFields[hookName] = hookSchema
}
hookBundle = await generateTypes(
hookFields,
'HookBundle',
`// Generated bundle for hooks. DO NOT MODIFY IT BY HAND.`
)
types += hookBundle
}

if (fs.pathExistsSync(path.join(parentDir, `${slug}`))) {
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function setupRoutes(def: DestinationDefinition | null): void {
'/refreshAccessToken',
asyncHandler(async (req: express.Request, res: express.Response) => {
try {
const settings = {}
const settings = req.body.settings || {}
const data = await destination.refreshAccessToken(settings, req.body)
res.status(200).json({ ok: true, data })
} catch (e) {
Expand Down Expand Up @@ -334,8 +334,10 @@ function setupRoutes(def: DestinationDefinition | null): void {
payload: req.body.payload || {},
page: req.body.page || 1,
auth: req.body.auth || {},
audienceSettings: req.body.audienceSettings || {}
audienceSettings: req.body.audienceSettings || {},
dynamicFieldContext: req.body.dynamicFieldContext || {}
}

const action = destination.actions[actionSlug]
const result = await action.executeDynamicField(field, data)

Expand Down Expand Up @@ -404,8 +406,10 @@ function setupRoutes(def: DestinationDefinition | null): void {
page: req.body.page || 1,
auth: req.body.auth || {},
audienceSettings: req.body.audienceSettings || {},
hookInputs: req.body.hookInputs || {}
hookInputs: req.body.hookInputs || {},
dynamicFieldContext: req.body.dynamicFieldContext || {}
}

const action = destination.actions[actionSlug]
const dynamicFn = dynamicInputs[fieldKey] as RequestFn<any, any, any, any>
const result = await action.executeDynamicField(fieldKey, data, dynamicFn)
Expand Down
19 changes: 7 additions & 12 deletions packages/core/src/destination-kit/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ export interface BaseActionDefinition {
type HookValueTypes = string | boolean | number | Array<string | boolean | number>
type GenericActionHookValues = Record<string, HookValueTypes>

type GenericActionHookBundle = {
[K in ActionHookType]?: {
inputs?: GenericActionHookValues
outputs?: GenericActionHookValues
}
}

// Utility type to check if T is an array
type IsArray<T> = T extends (infer U)[] ? U : never

Expand All @@ -94,7 +87,9 @@ export interface ActionDefinition<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AudienceSettings = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
GeneratedActionHookBundle extends GenericActionHookBundle = any
GeneratedActionHookInputs = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
GeneratedActionHookOutputs = any
> extends BaseActionDefinition {
/**
* A way to "register" dynamic fields.
Expand Down Expand Up @@ -139,8 +134,8 @@ export interface ActionDefinition<
Settings,
Payload,
AudienceSettings,
NonNullable<GeneratedActionHookBundle[K]>['outputs'],
NonNullable<GeneratedActionHookBundle[K]>['inputs']
NonNullable<GeneratedActionHookInputs>,
NonNullable<GeneratedActionHookOutputs>
>
}

Expand Down Expand Up @@ -170,8 +165,8 @@ export interface ActionHookDefinition<
Settings,
Payload,
AudienceSettings,
GeneratedActionHookOutputs,
GeneratedActionHookTypesInputs
GeneratedActionHookTypesInputs,
GeneratedActionHookOutputs
> {
/** The display title for this hook. */
label: string
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/destination-kit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface DynamicFieldContext {
selectedArrayIndex?: number
/** The key within a dynamic object for which we are requesting values */
selectedKey?: string
/** The RichInput dropdown search query the user has entered */
query?: string
}

export interface ExecuteInput<
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import nock from 'nock'
import createRequestClient from '../../../../../core/src/create-request-client'
import { LinkedInConversions } from '../api'
import { BASE_URL } from '../constants'
import { HookBundle } from '../streamConversion/generated-types'
import { OnMappingSaveInputs, OnMappingSaveOutputs } from '../streamConversion/generated-types'

const requestClient = createRequestClient()

describe('LinkedIn Conversions', () => {
describe('conversionRule methods', () => {
const linkedIn: LinkedInConversions = new LinkedInConversions(requestClient)
const adAccountId = 'urn:li:sponsoredAccount:123456'
const hookInputs: HookBundle['onMappingSave']['inputs'] = {
const hookInputs: OnMappingSaveInputs = {
adAccountId,
name: 'A different name that should trigger an update',
conversionType: 'PURCHASE',
Expand All @@ -19,7 +19,7 @@ describe('LinkedIn Conversions', () => {
view_through_attribution_window_size: 7
}

const hookOutputs: HookBundle['onMappingSave']['outputs'] = {
const hookOutputs: OnMappingSaveOutputs = {
id: '56789',
name: 'The original name',
conversionType: 'LEAD',
Expand Down
Loading
Loading