Skip to content

connector-v2 -- main as base #692

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

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c5e474c
wip update config code
miguel-nascimento Nov 29, 2023
5b19eed
antoniel Nov 29, 2023
7896f6c
antoniel Nov 29, 2023
6c1c412
antoniel Nov 29, 2023
09c4d5f
wip default value from code config
miguel-nascimento Nov 29, 2023
d58eb68
stop using db to store clientId
miguel-nascimento Nov 30, 2023
1972234
update slack-connector to use slack-install-link
miguel-nascimento Nov 30, 2023
34b61fb
antoniel Dec 1, 2023
ba208f8
antoniel Dec 1, 2023
8cad225
getModelByFilename util
miguel-nascimento Dec 4, 2023
d659f0c
add author name slug in ctx appAuthor
miguel-nascimento Dec 4, 2023
7fb86c8
wip: running the slack connector to install
miguel-nascimento Dec 4, 2023
539b756
run should return run result
miguel-nascimento Dec 5, 2023
53be20c
redirect to slack oauth after install
miguel-nascimento Dec 5, 2023
aed544a
antoniel Dec 5, 2023
6d69bb9
crypto utils tests
miguel-nascimento Dec 5, 2023
b04f0a0
getSlackConfig can return undefined
miguel-nascimento Dec 5, 2023
d3e04c7
wip
miguel-nascimento Dec 5, 2023
3d7de94
wip: get config from applet handler
miguel-nascimento Dec 6, 2023
6020693
add zipper-inc/client-js patch
miguel-nascimento Dec 6, 2023
48e6099
typo
miguel-nascimento Dec 6, 2023
fc714de
antoniel Dec 5, 2023
32b170d
bump client-js
miguel-nascimento Dec 6, 2023
e4f22c8
getAuthUrl using applet
miguel-nascimento Dec 6, 2023
7d66a8c
fix save
miguel-nascimento Dec 6, 2023
8ba36d5
wip
miguel-nascimento Dec 6, 2023
0a8ce49
use jscodeshift to update connector config
miguel-nascimento Dec 11, 2023
1cef211
fix build
miguel-nascimento Dec 11, 2023
1b5ecfd
antoniel Dec 8, 2023
16fa3cb
antoniel Dec 11, 2023
d898c26
redirect to localhost if is in dev mode
miguel-nascimento Dec 13, 2023
724570c
wip migration script
miguel-nascimento Dec 13, 2023
4be8b0b
wip version?
miguel-nascimento Dec 13, 2023
9ad1713
add a codemod user so we can create a version
miguel-nascimento Dec 13, 2023
6d4e251
antoniel Dec 14, 2023
7cf6496
antoniel Dec 14, 2023
959afab
mistake while doing merge
miguel-nascimento Jan 5, 2024
46106bc
remove codemod user from seed
miguel-nascimento Jan 5, 2024
9f916f1
Merge branch 'main' of github.com:Zipper-Inc/zipper-functions into co…
miguel-nascimento Jan 8, 2024
e96286a
search for .tsx file too, prefer the Uri parse util
miguel-nascimento Jan 8, 2024
fe7619d
start auth page should only use the appId to get auth url
miguel-nascimento Jan 8, 2024
66b45a8
cleanup on get config
miguel-nascimento Jan 8, 2024
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
5 changes: 3 additions & 2 deletions apps/zipper.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@types/react-timeago": "^4.1.5",
"@uploadthing/react": "^6.0.2",
"@vercel/kv": "^1.0.0",
"@zipper-inc/client-js": "^0.1.6",
"@zipper-inc/client-js": "^0.1.7",
"@zipper/types": "*",
"@zipper/ui": "*",
"@zipper/utils": "*",
Expand All @@ -97,6 +97,7 @@
"into-stream": "^6.0.0",
"ioredis": "^5.2.2",
"jose": "^4.11.4",
"jscodeshift": "^0.15.1",
"jsonwebtoken": "^9.0.0",
"jszip": "^3.10.1",
"langchain": "^0.0.130",
Expand Down Expand Up @@ -154,7 +155,7 @@
"@types/bcryptjs": "^2.4.2",
"@types/cors": "^2.8.13",
"@types/jest": "^29.4.0",
"@types/jscodeshift": "^0.11.10",
"@types/jscodeshift": "^0.11.11",
"@types/jsonwebtoken": "^9.0.2",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.shuffle": "^4.2.7",
Expand Down
14 changes: 14 additions & 0 deletions apps/zipper.dev/src/components/context/editor-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from '~/utils/playground.utils';
import { runZipperLinter } from '~/utils/zipper-editor-linter';
import { rewriteSpecifier } from '~/utils/rewrite-imports';
import { getFileExtension } from '~/utils/file-extension';

type OnValidate = AddParameters<
Required<EditorProps>['onValidate'],
Expand All @@ -56,6 +57,7 @@ export type EditorContextType = {
setModelIsDirty: (path: string, isDirty: boolean) => void;
isEditorDirty: () => boolean;
modelHasErrors: (path: string) => boolean;
getModelByFilename: (filename: string) => monaco.editor.ITextModel | null;
setModelHasErrors: (path: string, isErroring: boolean) => void;
editorHasErrors: () => boolean;
getErrorFiles: () => string[];
Expand Down Expand Up @@ -107,6 +109,7 @@ export const EditorContext = createContext<EditorContextType>({
setModelIsDirty: noop,
isEditorDirty: () => false,
modelHasErrors: () => false,
getModelByFilename: () => null,
setModelHasErrors: () => false,
editorHasErrors: () => false,
getErrorFiles: () => [],
Expand Down Expand Up @@ -698,6 +701,16 @@ const EditorContextProvider = ({
.filter(([, value]) => value)
.map(([filename]) => filename);

const getModelByFilename = (filename: string) => {
if (!monacoRef?.current || !editor) return null;
const uri = getUriFromPath(
`file:///${filename}`,
monacoRef.current.Uri.parse,
getFileExtension(filename) || 'tsx',
);
return editor.getModel(uri);
};

return (
<EditorContext.Provider
value={{
Expand All @@ -713,6 +726,7 @@ const EditorContextProvider = ({
setModelIsDirty,
isEditorDirty,
modelHasErrors,
getModelByFilename,
setModelHasErrors,
editorHasErrors,
getErrorFiles,
Expand Down
15 changes: 12 additions & 3 deletions apps/zipper.dev/src/components/context/run-app-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ type AppInfoWithHashes = AppInfo & {
playgroundVersionHash: string | null;
publishedVersionHash: string | null;
};
type RunResult =
| { ok: false; runId: string }
| {
ok: true;
filename: string;
version?: string;
result: string;
runId: string;
};

export type RunAppContextType = {
appInfo: AppInfoWithHashes;
Expand All @@ -51,7 +60,7 @@ export type RunAppContextType = {
run: (params?: {
shouldSave?: boolean;
isCurrentScriptEntryPoint?: boolean;
}) => Promise<string | undefined>;
}) => Promise<RunResult | undefined>;
boot: (params?: { shouldSave?: boolean }) => Promise<BootPayload>;
bootPromise: MutableRefObject<Promise<BootPayload>>;
configs: Zipper.BootPayload['configs'];
Expand All @@ -67,7 +76,7 @@ export const RunAppContext = createContext<RunAppContextType>({
userAuthConnectors: [],
setResults: noop,
bootPromise: { current: Promise.resolve({} as BootPayload) },
run: () => Promise.resolve(''),
run: () => Promise.resolve(undefined),
boot: () => Promise.resolve({} as BootPayload),
configs: {},
});
Expand Down Expand Up @@ -391,7 +400,7 @@ export function RunAppProvider({
cleanUpLogTimers();
updateLogs({ version, runId, fromTimestamp: oneSecondAgo });

return runId;
return { ...result, runId };
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ export const AppEditSidebarAppletConnectors = () => {
const [githubAuthRequired, setGitHubAuthRequired] = useState(false);
// state to hold whether user needs to authenticate with github

// get the existing Slack connector data from the database
const slackConnector = trpc.slackConnector.get.useQuery(
{ appId: appInfo.id },
{
enabled: slackAuthRequired,
},
);
// get the existing GitHub connector data from the database
const githubConnector = trpc.githubConnector.get.useQuery(
{ appId: appInfo.id },
Expand Down Expand Up @@ -87,16 +80,9 @@ export const AppEditSidebarAppletConnectors = () => {
// get the Slack auth URL -- if required --from the backend
// (it includes an encrypted state value that links the auth request to the app)
const slackAuthURL = trpc.slackConnector.getAuthUrl.useQuery(
{ appId },
{
appId,
scopes: {
bot: slackConnector.data?.workspaceScopes || [],
user: slackConnector.data?.userScopes || [],
},
postInstallationRedirect: window.location.href,
},
{
enabled: slackConnector.isFetched,
enabled: slackAuthRequired,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const AppEditSidebarApplet = ({ appSlug }: { appSlug: string }) => {
setRunId(
await run({
shouldSave: appInfo.canUserEdit,
}),
}).then((r) => r?.runId),
);
}}
display="flex"
Expand Down
2 changes: 2 additions & 0 deletions apps/zipper.dev/src/components/playground/tab-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export const CodeTab: React.FC<CodeTabProps> = ({ app, mainScript }) => {
w="full"
spacing={0}
onMouseEnter={onMouseEnter('PlaygroundCode')}
overflow="scroll"
pb="4"
onMouseLeave={onMouseLeave}
border={
hoveredElement === 'PlaygroundCode'
Expand Down
45 changes: 44 additions & 1 deletion apps/zipper.dev/src/connectors/slack/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export const code = `import { WebClient } from "https://deno.land/x/[email protected]/mod.js";
const redirectHost =
process.env.NODE_ENV === 'development'
? process.env.NEXT_PUBLIC_ZIPPER_DOT_DEV_HOST
: 'https://zipper.dev';

export const code = `import { WebClient } from 'https://deno.land/x/[email protected]/mod.js';
import { initApplet } from 'https://deno.land/x/[email protected]/mod.ts';
import { SlackUserAuth } from 'https://zipper.dev/zipper-inc/slack-install-link/src/main.ts';

export const slackConnectorConfig: Partial<SlackUserAuth> = {};

// This is an Slack API client intialized with the applet developer's Slack token
// THIS CLIENT DOES NOT USE THE USER TOKEN
Expand All @@ -15,6 +24,40 @@ client.sendToChannel = async (text: string, channelName: string) => {
// The current user's Slack token is available in the context of a handler function
export const getUserClient = (userToken: string) => new WebClient(userToken);

type SlackConnectorInput = {
action:
| 'get-auth-url' // Install the app
| 'get-config'; // Needed to exchange code for token
};

export async function handler(
input: SlackConnectorInput,
ctx: Zipper.HandlerContext,
) {
const thisAppletPlaygroundUrl = \`${redirectHost}/\${
ctx.appInfo.author?.organization || ctx.appInfo.author?.slug
}/\${ctx.appInfo.slug}/src/slack-connector.ts\`;

const config = {
...slackConnectorConfig,
zipperAppId: ctx.appInfo.id,
postInstallRedirect: thisAppletPlaygroundUrl,
};

switch (input.action) {
case 'get-auth-url': {
const link = await initApplet('slack-install-link')
.path('link-only')
.run(config);

return link;
}
case 'get-config': {
return config;
}
}
}

export default client;
`;

Expand Down
Loading