Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
fix folders

0.8.1

handlUri as separate class

add get started

0.8.4 - bug fixes

trigger redeploy
  • Loading branch information
hahnbeelee authored and handotdev committed Mar 11, 2023
1 parent 7fba3b3 commit cf16916
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 88 deletions.
77 changes: 38 additions & 39 deletions server/src/services/algolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,48 @@ const client = algoliasearch(algoliaClientId, algoliaSecret);
const docsIndex = client.initIndex('docs');

type SearchResults = {
docs: any[]
}
docs: any[];
};

export const searchDocs = async (query: string, orgId: string): Promise<SearchResults> => {
const results = await docsIndex.search(query, {
filters: `org:${orgId}`
})
return {
docs: results.hits
}
}
export const searchDocs = async (query: string, orgId: string): Promise<SearchResults> => {
const results = await docsIndex.search(query, {
filters: `org:${orgId}`,
});
return {
docs: results.hits,
};
};

export const clearIndexWithMethod = async (orgId: string, method: string) => {
try {
await docsIndex.deleteBy({
filters: `org:${orgId} AND method:${method}`
})
} catch (error) {
console.log(error)
}
}
try {
await docsIndex.deleteBy({
filters: `org:${orgId} AND method:${method}`,
});
} catch (error) {
console.log(error);
}
};

export const indexDocsForSearch = async (docs: DocType[]) => {
try {
const records = docs.map((doc) => {
return {
objectID: doc._id,
name: doc.title,
content: doc.content,
url: doc.url,
org: doc.org,
favicon: doc.favicon,
method: doc.method,
};
})
await docsIndex.partialUpdateObjects(records, { createIfNotExists: true });
}
catch (error) {
// Todo: manage oversize
console.log(error);
}
}
try {
const records = docs.map((doc) => {
return {
objectID: doc._id,
name: doc.title,
content: doc.content,
url: doc.url,
org: doc.org,
favicon: doc.favicon,
method: doc.method,
};
});
await docsIndex.partialUpdateObjects(records, { createIfNotExists: true });
} catch (error) {
// Todo: manage oversize
console.log(error);
}
};

export const deleteDocForSearch = async (objectID: string): Promise<any> => {
return docsIndex.deleteObject(objectID);
}
return docsIndex.deleteObject(objectID);
};
89 changes: 89 additions & 0 deletions vscode/Get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
### Prerequisites

- [Git](https://git-scm.com/), `>= 2.7.2`
- [NodeJS](https://nodejs.org/), `14.16.0`
- [yarn](https://yarnpkg.com/), `>= 1.22.5`

### Dependencies

From a terminal, where you have cloned the repository, execute the following command to install the required dependencies:

```
yarn
```

### Build

From a terminal, where you have cloned the repository, execute the following command to re-build the project from scratch:

```
yarn run rebuild
```

👉 **NOTE!** This will run a complete rebuild of the project.

Or to just run a quick build, use:

```
yarn run build
```

### Watch

During development you can use a watcher to make builds on changes quick and easy. From a terminal, where you have cloned the repository, execute the following command:

```
yarn run watch
```

Or use the provided `watch` task in VS Code, execute the following from the command palette (be sure there is no `>` at the start):

```
task watch
```

This will first do an initial full build and then watch for file changes, compiling those changes incrementally, enabling a fast, iterative coding experience.

👉 **Tip!** You can press <kbd>CMD+SHIFT+B</kbd> (<kbd>CTRL+SHIFT+B</kbd> on Windows, Linux) to start the watch task.

👉 **Tip!** You don't need to stop and restart the development version of Code after each change. You can just execute `Reload Window` from the command palette.

### Formatting

This project uses [prettier](https://prettier.io/) for code formatting. You can run prettier across the code by calling `yarn run pretty` from a terminal.

To format the code as you make changes you can install the [Prettier - Code formatter](https://marketplace.visualstudio.com/items/esbenp.prettier-vscode) extension.

Add the following to your User Settings to run prettier:

```
"editor.formatOnSave": true,
```

### Linting

This project uses [ESLint](https://eslint.org/) for code linting. You can run ESLint across the code by calling `yarn run lint` from a terminal. Warnings from ESLint show up in the `Errors and Warnings` quick box and you can navigate to them from inside VS Code.

To lint the code as you make changes you can install the [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension.

### Bundling

To generate a production bundle (without packaging) run the following from a terminal:

```
yarn run bundle
```

To generate a VSIX (installation package) run the following from a terminal:

```
yarn run package
```

### Debugging

#### Using VS Code

1. Open the `vscode-gitlens` folder
2. Ensure the required [dependencies](#dependencies) are installed
3. Choose the `Watch & Run` launch configuration from the launch dropdown in the Run and Debug viewlet and press `F5`.
2 changes: 2 additions & 0 deletions vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Link documentation to your codebase

🎥 [Demo](https://www.loom.com/embed/5eac4e3c0083419481260be33909b47b)

<img src="/vscode/assets/connector.png" width="650px" />

## Get Started
Expand Down
2 changes: 1 addition & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "mintlify",
"displayName": "Document Connector",
"description": "Create connections between documentation and code",
"version": "0.8.0",
"version": "0.8.4",
"icon": "assets/logo.png",
"repository": {
"url": "https://github.com/mintlify/connect"
Expand Down
5 changes: 5 additions & 0 deletions vscode/src/commands/mintlify/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export class LinkCode extends ActiveEditorCommand {
const type = this.getIsFolder(fileStat) ? 'folder' : 'file';
const fileFsPath: string = uri.fsPath;
const code: Code = await this.getCode(fileFsPath, type, editor, uri, args);
await this.container.viewProvider.show();
function delay(time: number) {
return new Promise(resolve => setTimeout(resolve, time));
}
await delay(200);
await this.container.viewProvider.postCode(code);
}
}
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/commands/mintlify/refreshLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class RefreshLinks extends ActiveEditorCommand {
}

async execute(editor: TextEditor) {
const fileFsPath: string = editor.document.uri.fsPath;
const fileFsPath: string = editor?.document?.uri?.fsPath;
if (fileFsPath == null) return;
const { gitOrg, repo } = await getRepoInfo(fileFsPath);
try {
const authParams = await this.container.storage.getAuthParams();
Expand Down
14 changes: 7 additions & 7 deletions vscode/src/mintlify-functionality/treeviews/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ export class TeamTreeProvider implements vscode.TreeDataProvider<Account>, Dispo
}

async getChildren(): Promise<any[]> {
const currentUserId = this.container.storage.getSecret('userId');
const authParams = await this.container.storage.getAuthParams();

if (currentUserId == null) {
if (authParams?.userId == null) {
return [new NotLoggedIn()];
}
const authParams = await this.container.storage.getAuthParams();

const {
data: { users },
} = await axios.get(`${API_ENDPOINT}/org/users`, {
params: authParams,
});

const currentUser = users.find((user: any) => user.userId === currentUserId);
const allOtherMembers = users.filter((user: any) => user?.email !== currentUser.email);
const currentUser = await users.find((user: any) => user.userId === authParams?.userId);
const allOtherMembers = users.filter((user: any) => user?.email !== currentUser?.email);

return [
new Account(currentUser.email, false, true),
...allOtherMembers.map((user: any) => new Account(user.email, user?.pending)),
new Account(currentUser?.email, false, true),
...allOtherMembers.map((user: any) => new Account(user?.email, user?.pending)),
new InviteMember(),
];
}
Expand Down
85 changes: 46 additions & 39 deletions vscode/src/mintlify/webview/viewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import axios from 'axios';
import {
CancellationToken,
Disposable,
EventEmitter,
Uri,
UriHandler,
Webview,
WebviewView,
WebviewViewProvider,
Expand Down Expand Up @@ -40,7 +42,7 @@ export class ViewProvider implements WebviewViewProvider {
protected readonly disposables: Disposable[] = [];
protected isReady: boolean = false;
private _disposableView: Disposable | undefined;
private _uriHandler = { handleUri: this.handleUri };
private _uriHandler = new UriEventHandler(this);

constructor(private readonly container: Container) {
this.disposables.push(
Expand Down Expand Up @@ -96,53 +98,21 @@ export class ViewProvider implements WebviewViewProvider {
}
}

private async handleUri(uri: vscode.Uri) {
if (uri.path === '/auth') {
try {
const query = new URLSearchParams(uri.query);
const userRaw = query.get('user');
if (userRaw == null) {
await vscode.window.showErrorMessage('Unable to authenticate. Try again later');
return;
}

const user = JSON.parse(userRaw);
if (user?.email == null) {
await vscode.window.showErrorMessage('User has insufficient credentials. Try again later');
return;
}
const subdomain = query.get('subdomain');
await this.authenticate(user, subdomain);
} catch (err) {
await vscode.window.showErrorMessage('Error authenticating user');
}
} else if (uri.path === '/prefill-doc') {
const query = new URLSearchParams(uri.query);
const docId = query.get('docId');
if (!docId) {
await vscode.window.showErrorMessage('No document identifier selected');
return;
}

await this.prefillDocWithDocId(docId);
}
}

private async deleteAuthSecrets() {
await this.container.storage.deleteSecret('userId');
await this.container.storage.deleteSecret('subdomain');
}

public async authenticate(user: any, subdomain?: string | null) {
await this.container.storage.storeSecret('userId', user.userId);
if (subdomain) {
await this.container.storage.storeSecret('subdomain', subdomain);
}
await vscode.commands.executeCommand('setContext', 'mintlify.isLoggedIn', true);
await vscode.window.showInformationMessage(`🙌 Successfully signed in with ${user.email}`);
await executeCommand(Commands.RefreshLinks);
await executeCommand(Commands.RefreshViews);
await this._view?.webview.postMessage({ command: 'auth', args: user });
await vscode.window.showInformationMessage(`🙌 Successfully signed in with ${user.email}`);
}

private async deleteAuthSecrets() {
await this.container.storage.deleteSecret('userId');
await this.container.storage.deleteSecret('subdomain');
}

public prefillDocWithDocId = async (docId: string) => {
Expand Down Expand Up @@ -294,3 +264,40 @@ export class ViewProvider implements WebviewViewProvider {
export const openLogin = (endpoint: string) => {
return vscode.env.openExternal(vscode.Uri.parse(`${endpoint}/api/login/vscode`));
};

class UriEventHandler extends EventEmitter<Uri> implements UriHandler {
constructor(private viewProvider: ViewProvider) {
super();
}
public async handleUri(uri: vscode.Uri) {
if (uri.path === '/auth') {
try {
const query = new URLSearchParams(uri.query);
const userRaw = query.get('user');
if (userRaw == null) {
await vscode.window.showErrorMessage('Unable to authenticate. Try again later');
return;
}

const user = JSON.parse(userRaw);
if (user?.email == null) {
await vscode.window.showErrorMessage('User has insufficient credentials. Try again later');
return;
}
const subdomain = query.get('subdomain');
await this.viewProvider.authenticate(user, subdomain);
} catch (err) {
await vscode.window.showErrorMessage('Error authenticating user');
}
} else if (uri.path === '/prefill-doc') {
const query = new URLSearchParams(uri.query);
const docId = query.get('docId');
if (!docId) {
await vscode.window.showErrorMessage('No document identifier selected');
return;
}

await this.viewProvider.prefillDocWithDocId(docId);
}
}
}
2 changes: 1 addition & 1 deletion vscode/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Storage implements Disposable {
return this.context.secrets.store(key, value);
}

async getAuthParams(): Promise<object> {
async getAuthParams(): Promise<any> {
const userId = await this.getSecret('userId');
const subdomain = await this.getSecret('subdomain');
return {
Expand Down

0 comments on commit cf16916

Please sign in to comment.