Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .changeset/dull-meals-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@openfn/lexicon': minor
'@openfn/project': minor
'@openfn/deploy': minor
'@openfn/cli': minor
---

Add support for channels
5 changes: 5 additions & 0 deletions .changeset/frank-canyons-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/deploy': minor
---

Add support for webhook_response_config
5 changes: 5 additions & 0 deletions .changeset/salty-areas-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/lexicon': minor
---

Support `cron_cursor_job_id`, `webhook_reply` and `webhook_response_config` in Provisioner types
5 changes: 5 additions & 0 deletions .changeset/shy-needles-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/cli': minor
---

Support webhook responses in sync & deploy
5 changes: 5 additions & 0 deletions .changeset/wide-seals-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/project': patch
---

Support more trigger keys
88 changes: 86 additions & 2 deletions packages/deploy/src/stateTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ function mergeTriggers(
if (specTrigger.type === 'webhook' && specTrigger.webhook_reply) {
trigger.webhook_reply = specTrigger.webhook_reply;
}
if (
specTrigger.type === 'webhook' &&
specTrigger.webhook_response_config
) {
trigger.webhook_response_config =
specTrigger.webhook_response_config;
}

if (specTrigger.type === 'cron') {
trigger.cron_expression = specTrigger.cron_expression;
Expand Down Expand Up @@ -202,6 +209,13 @@ function mergeTriggers(
if (specTrigger!.type === 'webhook' && specTrigger!.webhook_reply) {
trigger.webhook_reply = specTrigger!.webhook_reply;
}
if (
specTrigger!.type === 'webhook' &&
specTrigger!.webhook_response_config
) {
trigger.webhook_response_config =
specTrigger!.webhook_response_config;
}

if (specTrigger!.type === 'cron') {
trigger.cron_expression = specTrigger!.cron_expression;
Expand Down Expand Up @@ -360,6 +374,58 @@ export function mergeSpecIntoState(
}
)
);
const nextChannels = Object.fromEntries(
splitZip(oldState.channels || {}, spec.channels || {}).map(
([channelKey, stateChannel, specChannel]) => {
if (specChannel && !stateChannel) {
return [
channelKey,
{
id: crypto.randomUUID(),
name: specChannel.name,
destination_url: specChannel.destination_url,
enabled: specChannel.enabled,
destination_credential_id:
specChannel.destination_credential &&
getStateJobCredential(
specChannel.destination_credential,
nextCredentials
),
},
];
}

if (specChannel && stateChannel) {
return [
channelKey,
{
id: stateChannel.id,
name: specChannel.name,
destination_url: specChannel.destination_url,
enabled: specChannel.enabled,
destination_credential_id:
specChannel.destination_credential &&
getStateJobCredential(
specChannel.destination_credential,
nextCredentials
),
},
];
}

if (!specChannel && stateChannel) {
return [channelKey, { id: stateChannel.id, delete: true }];
}

throw new DeployError(
`Invalid channel spec or corrupted state for channel: ${
stateChannel?.name || specChannel?.name
}`,
'VALIDATION_ERROR'
);
}
)
);

const nextWorkflows = Object.fromEntries(
splitZip(oldState.workflows, spec.workflows).map(
Expand Down Expand Up @@ -428,6 +494,7 @@ export function mergeSpecIntoState(
workflows: nextWorkflows,
project_credentials: nextCredentials,
collections: nextCollections,
channels: nextChannels,
};

if (spec.description) projectState.description = spec.description;
Expand Down Expand Up @@ -476,9 +543,12 @@ export function getStateFromProjectPayload(

const collections = reduceByKey('name', project.collections || []);

const channels = reduceByKey('name', project.channels || []);

return {
...project,
collections,
channels,
project_credentials,
workflows,
};
Expand Down Expand Up @@ -547,9 +617,18 @@ export function mergeProjectPayloadIntoState(
)
);

const nextChannels = Object.fromEntries(
idKeyPairs(project.channels || [], state.channels || {}).map(
([key, nextChannel, _state]) => {
return [key, nextChannel];
}
)
);

return {
...project,
collections: nextCollections,
channels: nextChannels,
project_credentials: nextCredentials,
workflows: nextWorkflows,
};
Expand Down Expand Up @@ -595,12 +674,17 @@ export function toProjectPayload(state: ProjectState): ProjectPayload {
state.collections
);

const { collections: _, ...stateWithoutCollections } = state;
const channels: ProjectPayload['channels'] = Object.values(
state.channels || {}
);

const { collections: _, channels: __, ...stateWithoutOptionals } = state;

return {
...stateWithoutCollections,
...stateWithoutOptionals,
project_credentials,
workflows,
...(collections.length > 0 && { collections }),
...(channels.length > 0 && { channels }),
};
}
26 changes: 26 additions & 0 deletions packages/deploy/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ export type SpecKafkaConfiguration = {
connect_timeout: number;
};

export type WebhookResponseConfig = {
error_code: number | null;
success_code: number | null;
};

export type WebhookReply = 'before_start' | 'after_completion';

export type SpecTrigger = {
type: string;
cron_expression?: string;
cron_cursor_job?: string;
webhook_reply?: WebhookReply;
webhook_response_config?: WebhookResponseConfig | null;
enabled?: boolean;
kafka_configuration?: SpecKafkaConfiguration;
};
Expand All @@ -55,6 +61,7 @@ export type StateTrigger = {
cron_expression?: string;
cron_cursor_job_id?: string | null;
webhook_reply?: WebhookReply;
webhook_response_config?: WebhookResponseConfig | null;
delete?: boolean;
enabled?: boolean;
kafka_configuration?: StateKafkaConfiguration;
Expand Down Expand Up @@ -110,12 +117,29 @@ export type CollectionState = {
delete?: boolean;
};

export type ChannelSpec = {
name: string;
destination_url: string;
enabled: boolean;
destination_credential: string | null;
};

export type ChannelState = {
id: string;
name: string;
destination_url: string;
enabled: boolean;
destination_credential_id: string | null;
delete?: boolean;
};

export interface ProjectSpec {
name: string;
description: string;
workflows: Record<string | symbol, WorkflowSpec>;
credentials: Record<string | symbol, CredentialSpec>;
collections: Record<string | symbol, CollectionSpec>;
channels: Record<string | symbol, ChannelSpec>;
}

export interface WorkflowState {
Expand All @@ -139,13 +163,15 @@ export interface ProjectState {
workflows: Record<string | symbol, WorkflowState>;
project_credentials: Record<string | symbol, CredentialState>;
collections: Record<string | symbol, CollectionState>;
channels: Record<string | symbol, ChannelState>;
}

export interface ProjectPayload {
id: string;
name: string;
description: string;
collections?: Concrete<CollectionState>[];
channels?: Concrete<ChannelState>[];
project_credentials: Concrete<CredentialState>[];
workflows: {
id: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/deploy/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export async function parseAndValidate(
}
}

if (pair.key && pair.key.value === 'channels') {
if (pair.value.value === null) {
return doc.createPair('channels', {});
}
}

if (pair.key && pair.key.value === 'jobs') {
if (pair.value.value === null) {
errors.push({
Expand Down
3 changes: 3 additions & 0 deletions packages/deploy/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export function fullExampleSpec() {
name: 'my project',
description: 'some helpful description',
collections: {},
channels: {},
credentials: {},
workflows: {
'workflow-one': {
Expand Down Expand Up @@ -58,6 +59,7 @@ export function fullExampleState() {
name: 'my project',
description: 'some helpful description',
collections: {},
channels: {},
project_credentials: {},
workflows: {
'workflow-one': {
Expand Down Expand Up @@ -254,6 +256,7 @@ export const lightningProjectState = {
name: 'collection-one',
},
},
channels: {},
project_credentials: {
'email@test.com-Basic-Auth': {
id: '25f48989-d349-4eb8-99c3-923ebba5b116',
Expand Down
Loading