kineticio / runnable

Build internal workflows with ease
https://getrunnable.com/
51 stars 4 forks source link

Unable to use in Node16 Nest.js #39

Closed darr1s closed 10 months ago

darr1s commented 11 months ago

It seems like the package is pure CJS, is there a plan to support import?

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/client.ts:1:62 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

1 import type { NamespaceId, WorkflowId, WorkflowTypeId } from './ids';
                                                               ~~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/index.ts:3:15 - error TS2307: Cannot find module './ws' or its corresponding type declarations.

3 export * from './ws';
                ~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/index.ts:4:15 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

4 export * from './ids';
                ~~~~~~~
...
  const RunnableWs = await import('@runnablejs/sdk').then((m) => m.RunnableWs);

  // Get Runnable actions
  const actions = app.get('RUNNABLE_ACTIONS');
  // Start Runnable server
  new RunnableWs(actions, {
    namespace: 'user-server',
    runnableHost: 'ws://localhost:3000',
    logger: logger,
    token: 'another-secret',
  }).start();

  await app.listen(8000);
import { FactoryProvider } from '@nestjs/common';

import { RunnableWorkflows } from '@runnablejs/sdk';

import { FinanceService } from 'src/core/finance/finance.service.js';

export const FinanceRunnableProvider: FactoryProvider<RunnableWorkflows> = {
  provide: 'FINANCE_RUNNABLE_ACTIONS',
  inject: [FinanceService],
  useFactory: (financeService: FinanceService) => {
    return {
      create_user: {
        title: 'Create User',
        description: 'Create a new user',
        icon: 'fa6-solid:user-plus',
        category: 'User',
        execute: async (io) => {
          const { name, email } = await io.form({
            name: io.input.text({
              label: 'Name',
              helperText: 'Enter the name of the user',
              type: 'text',
              validation: (value) => {
                if (value.length < 3) {
                  return 'Name must be at least 3 characters';
                }
                return true;
              },
            }),
            email: io.input.text({
              label: 'Email',
              helperText: 'Enter the email of the user',
              type: 'email',
              validation: (value) => {
                if (value.length < 3) {
                  return 'Email must be at least 3 characters';
                }
                return true;
              },
            }),```

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/client.ts:1:62 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

1 import type { NamespaceId, WorkflowId, WorkflowTypeId } from './ids';
                                                               ~~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/index.ts:3:15 - error TS2307: Cannot find module './ws' or its corresponding type declarations.

3 export * from './ws';
                ~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.12/node_modules/@runnablejs/api/index.ts:4:15 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

4 export * from './ids';
                ~~~~~~~
...
  const RunnableWs = await import('@runnablejs/sdk').then((m) => m.RunnableWs);

  // Get Runnable actions
  const actions = app.get('RUNNABLE_ACTIONS');
  // Start Runnable server
  new RunnableWs(actions, {
    namespace: 'user-server',
    runnableHost: 'ws://localhost:3000',
    logger: logger,
    token: 'another-secret',
  }).start();

  await app.listen(8000);

import { FactoryProvider } from '@nestjs/common';

import { RunnableWorkflows } from '@runnablejs/sdk';

import { FinanceService } from 'src/core/finance/finance.service.js';

export const FinanceRunnableProvider: FactoryProvider<RunnableWorkflows> = {
  provide: 'FINANCE_RUNNABLE_ACTIONS',
  inject: [FinanceService],
  useFactory: (financeService: FinanceService) => {
    return {
      create_user: {
        title: 'Create User',
        description: 'Create a new user',
        icon: 'fa6-solid:user-plus',
        category: 'User',
        execute: async (io) => {
          const { name, email } = await io.form({
            name: io.input.text({
              label: 'Name',
              helperText: 'Enter the name of the user',
              type: 'text',
              validation: (value) => {
                if (value.length < 3) {
                  return 'Name must be at least 3 characters';
                }
                return true;
              },
            }),
            email: io.input.text({
              label: 'Email',
              helperText: 'Enter the email of the user',
              type: 'email',
              validation: (value) => {
                if (value.length < 3) {
                  return 'Email must be at least 3 characters';
                }
                return true;
              },
            }),
          });

          // await financeService;
        },
      },
    };
  },
};

          });

          // await financeService;
        },
      },
    };
  },
};
mscolnick commented 11 months ago

hey @darr1s,

can you try a top-level import? if you cannot do that, why not?

import { RunnableWs } from '@runnablejs/sdk';

otherwise, you might be able to use require:

const RunnableWs = require('@runnablejs/sdk').RunnableWs;
darr1s commented 11 months ago

Hey there! On a second note, I think its not related to my own tsconfig.

As I gotten @runnable/api installed, I noticed node_modules/@runnable/api/index.ts is indeed not exporting ids from the package. Could it be the npm release are not up to date?

image

mscolnick commented 11 months ago

You might be right, I can investigate and fix the published typed. In the meantime, I think you can add "skipLibCheck": true in your tsconfig.json

mscolnick commented 11 months ago

@darr1s, i just released 0.4.14. can you try that out?

darr1s commented 11 months ago

I'm on 0.4.14, still facing the same issues.


1 import type { NamespaceId, WorkflowId, WorkflowTypeId } from './ids';
                                                               ~~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.14/node_modules/@runnablejs/api/index.ts:4:15 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

4 export * from './ids';
                ~~~~~~~

node_modules/.pnpm/@runnablejs+api@0.4.14/node_modules/@runnablejs/api/ws.ts:2:62 - error TS2307: Cannot find module './ids' or its corresponding type declarations.

2 import type { WorkflowId, NamespaceId, WorkflowTypeId } from './ids';
                                                               ~~~~~~~

src/main.ts:74:39 - error TS2339: Property '_events' does not exist on type 'Server<typeof IncomingMessage, typeof ServerResponse>'.
74   installRunnable(app.getHttpServer()._events.request, actions, context);
                                         ~~~~~~~
mscolnick commented 10 months ago

@darr1s, apologies for the consistent typing issues (but that is all they are and the JS should still run fine if you want to ignore the type errors)

you can use 0.4.15 which should fix both of those. i've updated the nestjs docs too, so all you need to do instead is:

installRunnable(app, actions, context);
darr1s commented 10 months ago

Hey @mscolnick, again, thanks for the prompt response!

I managed to see the interface at the URL. However, the form is rendering empty.

What I have tried:

This is my env:

RUNNABLE_AUTH_PROVIDER_FORM=false
RUNNABLE_BASE_URL="playground"
RUNNABLE_SECRET="super-duper-s3cret"
RUNNABLE_AUTH_SECRET="another-secret"

This is my context provider:

export const RunnableAppContextProvider: Provider<RunnableAppContext> = {
  provide: 'RUNNABLE_CONTEXT',
  inject: [AuthService],
  useFactory: (authService: AuthService) => ({
    auth: {
      form: {
        verifyLogin: async ({ email, password }) => {
          const auth = await authService.challengeAdmin({ loginType: AuthenticationMethodField.EMAIL_PASSWORD, email, password });
          if (!auth) throw new Error('Invalid credentials');
          return {
            id: '1',
            email: email,
            name: 'Admin'
          }
        },
      }
    },
  }),
};

This is my console output: (I believe the line __session comes from @runnable/app remix, but I not sure if its the cause)

[12:33:42 PM] Found 0 errors. Watching for file changes.

**The "__session" cookie is not signed, but session cookies should be signed to prevent tampering on the client before they are sent back to the server. See https://remix.run/utils/cookies#signing-cookies for more information.**
NewRelicInterceptor instantiated
**Installing Runnable at /playground**
INFO [2023-10-28T04:33:45.133Z]: Starting Nest application... {"context":"NestFactory"}

image


On a side note, I am actually a Prisma user and have been searching for solutions that allow developers to quickly get a playground (admin with CRUD and custom actions). I've checked a few solutions out there, some are hosted open/core such as Forest Admin, Retool, some are open source code-first AdminJS, Refine etc.

However, all of those mentioned did not utilize Prisma exposed DMMF to automatically provide CRUD and allows custom action to be defined easily. Your solution is the closest, and I just wanted to ask you about your roadmap to understand and align better.

May I know what is your goal/roadmap for the library?

mscolnick commented 10 months ago

Hmm it looks like your environment variables are not being picked up. Can you try printing out your process.env right before installRunnable.

For roadmap, I don't really have one. This isn't an active project I'm working on (currently building https://github.com/marimo-team/marimo), but I will happily support it and build small features if they are requested in the issues.

I've used Runnable in 3 projects now and continue to do so. It does everything I need at the moment, but will continue to improve it over time when features are needed.

mscolnick commented 10 months ago

oh also looking at your env, you should set RUNNABLE_AUTH_PROVIDER_FORM=true. right now you need some sort of auth: either a form (email/password) or google oauth. we can also support more as needed