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

chore: hackathon #3337

Draft
wants to merge 7 commits into
base: master
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
4 changes: 4 additions & 0 deletions hackathon/nango-integrations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './unauthenticated/actions/action.ts';
export * from './unauthenticated/syncs/sync.ts';
export * from './unauthenticated/on-events/post-connection-creation.ts';
export * from './unauthenticated/on-events/pre-connection-deletion.ts';
24 changes: 24 additions & 0 deletions hackathon/nango-integrations/tmp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { z } from 'zod';
import type { CreateActionProps, CreateActionResponse, CreateOnEventProps, CreateOnEventResponse, CreateSyncProps, CreateSyncResponse } from '@nangohq/types';

export function createSync<TModels extends Record<string, Zod.ZodObject<any>>, TMetadata extends Zod.ZodObject<any> | undefined = undefined>(
params: CreateSyncProps<TModels, TMetadata>
): CreateSyncResponse<TModels, TMetadata> {
return { type: 'sync', params };
}

export function createAction<
TInput extends Zod.ZodTypeAny,
TOutput extends Zod.ZodTypeAny,
TMetadata extends Zod.ZodObject<any> | undefined = undefined,
TOutputInferred = z.infer<TOutput>,
TInputInferred = z.infer<TInput>
>(params: CreateActionProps<TInput, TOutput, TMetadata, TOutputInferred, TInputInferred>): CreateActionResponse<TInput, TOutput, TMetadata> {
return { type: 'action', params };
}

export function createOnEvent<TMetadata extends Zod.ZodObject<any> | undefined = undefined>(
params: CreateOnEventProps<TMetadata>
): CreateOnEventResponse<TMetadata> {
return { type: 'on-event', params };
}
25 changes: 25 additions & 0 deletions hackathon/nango-integrations/unauthenticated/actions/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { z } from 'zod';

Check failure on line 1 in hackathon/nango-integrations/unauthenticated/actions/action.ts

View workflow job for this annotation

GitHub Actions / lint-code

'zod' should be listed in the project's dependencies. Run 'npm i -S zod' to add it
import { createAction } from '../../tmp.js';

// Action
export default createAction({
description: 'This is an action',
endpoint: { method: 'POST', path: '/my-action', group: 'My Group' },
integrationId: 'unauthenticated',
input: z.object({ foo: z.string() }),
output: z.number(),
version: '0.0.1',
exec: async (nango, input) => {
await nango.log('coucou');
console.log(input.foo);
console.log(input.bar);

return 1;
}
});

function name(top: string) {
console.log(top);
}

name(1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createOnEvent } from '../../tmp.js';

export default createOnEvent({
description: 'yes',
event: 'post-connection-creation',
integrationId: 'unauthenticated',
exec: async (nango) => {
await nango.log('top');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createOnEvent } from '../../tmp.js';

// Events
export default createOnEvent({
description: 'yes',
event: 'pre-connection-deletion',
integrationId: 'unauthenticated',
exec: async (nango) => {
await nango.log('top');
}
});
77 changes: 77 additions & 0 deletions hackathon/nango-integrations/unauthenticated/syncs/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { z } from 'zod';

Check failure on line 1 in hackathon/nango-integrations/unauthenticated/syncs/sync.ts

View workflow job for this annotation

GitHub Actions / lint-code

'zod' should be listed in the project's dependencies. Run 'npm i -S zod' to add it
import { createSync } from '../../tmp.js';

const ticketSchema = z.object({ id: z.string(), name: z.string() });

// Sync
export default createSync({
description: 'Hi this is a description',
endpoints: [{ method: 'GET', path: '/my-script', group: 'My Group' }],
integrationId: 'unauthenticated',
runs: 'every hour',
autoStart: true,
syncType: 'incremental',
trackDeletes: true,
models: {
Ticket: ticketSchema
},
metadata: z.object({
foo: z.literal('bar'),
num: z.number(),
bool: z.boolean(),
null: z.null(),
enum: z.enum(['tip', 'top']),
arr: z.array(z.string()),
obj: z.object({ bar: z.string() }),
union: z.union([z.string(), z.boolean()]),
any: z.any(),
reco: z.record(z.string(), z.date())
}),
exec: async (nango) => {
await nango.batchSave([{ id: 'foobar', name: '' }], 'Ticket');

const meta = await nango.getMetadata();
console.log(meta.foo);
console.log(meta.bar);
}
});

// No metadata
createSync({
description: 'Hi this is a description',
endpoints: [{ method: 'GET', path: '/my-script', group: 'My Group' }],
integrationId: 'unauthenticated',
runs: 'every 1hour',
autoStart: true,
syncType: 'incremental',
trackDeletes: true,

models: {
Ticket: ticketSchema
},

exec: async (nango) => {
await nango.batchSave([{ id: '', name: '' }], 'Ticket');

const meta = await nango.getMetadata();
console.log(meta.foo);
console.log(meta.bar);
console.log(meta['foo']);
}
});

// Webhook
createSync({
description: 'Hi this is a description',
endpoints: [{ method: 'GET', path: '/my-script', group: 'My Group' }],
integrationId: 'unauthenticated',
runs: 'every 1hour',
syncType: 'incremental',
models: { Ticket: ticketSchema },
exec: async () => {
//
},
onWebhook: async (nango, payload) => {
await nango.log('top', payload);
}
});
32 changes: 29 additions & 3 deletions packages/cli/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { getNangoRootPath, upgradeAction, NANGO_INTEGRATIONS_LOCATION, printDebu
import type { DeployOptions } from './types.js';
import { parse } from './services/config.service.js';
import { nangoConfigFile } from '@nangohq/nango-yaml';
import { compileScripts } from './services/zeroYaml/compile.js';
import { deploy as zeroYamlDeploy } from './services/zeroYaml/deploy.js';

class NangoCommand extends Command {
override createCommand(name: string) {
Expand Down Expand Up @@ -132,8 +134,12 @@ program
.action(async function (this: Command, sync: string, connectionId: string) {
const { autoConfirm, debug, e: environment, integrationId, validation, saveResponses } = this.opts();
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug });
const dryRun = new DryRunService({ fullPath, validation });
const preCheck = await verificationService.preCheck({ fullPath });
if (!preCheck.isZeroYaml) {
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug });
}

const dryRun = new DryRunService({ fullPath, validation, isZeroYaml: preCheck.isZeroYaml });
await dryRun.run(
{
...this.opts(),
Expand Down Expand Up @@ -176,7 +182,13 @@ program
const options: DeployOptions = this.opts();
const { debug } = options;
const fullPath = process.cwd();
await deployService.prep({ fullPath, options: { ...options, env: 'cloud' }, environment, debug });

const preCheck = await verificationService.preCheck({ fullPath });
if (preCheck.isZeroYaml) {
await zeroYamlDeploy({ fullPath, environmentName: environment, debug, options });
} else {
await deployService.prep({ fullPath, options: { ...options, env: 'cloud' }, environment, debug });
}
});

program
Expand Down Expand Up @@ -230,6 +242,20 @@ program
.action(async function (this: Command) {
const { autoConfirm, debug } = this.opts();
const fullPath = process.cwd();

const preCheck = await verificationService.preCheck({ fullPath });
if (preCheck.isZeroYaml) {
// New structure
console.log('Compiling new structure');

const success = await compileScripts({ fullPath, debug });
if (!success) {
console.log(chalk.red('Compilation was not fully successful. Please make sure all files compile before deploying'));
process.exitCode = 1;
}
return;
}

await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug, checkDist: false });

const match = verificationService.filesMatchConfig({ fullPath });
Expand Down
Loading
Loading