Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mit-27/Panora into github-c…
Browse files Browse the repository at this point in the history
…onnector
  • Loading branch information
mit-27 committed Jul 27, 2024
2 parents f010d54 + 6a5d5d4 commit b54b3a5
Show file tree
Hide file tree
Showing 352 changed files with 356 additions and 4,987 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface IApiKeyConnectionDto {
const useCreateApiKeyConnection = () => {
const createApiKeyConnection = async (apiKeyConnectionData : IApiKeyConnectionDto) => {
const response = await fetch(
`${apiKeyConnectionData.api_url}/connections/apikey/callback?state=${encodeURIComponent(JSON.stringify(apiKeyConnectionData.query))}`, {
`${apiKeyConnectionData.api_url}/connections/basicorapikey/callback?state=${encodeURIComponent(JSON.stringify(apiKeyConnectionData.query))}`, {
method: 'POST',
body: JSON.stringify(apiKeyConnectionData.data),
headers: {
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @panora/frontend-sdk

## 1.2.0

### Minor Changes

- f39a671: projectid param

## 1.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@panora/frontend-sdk",
"version": "1.1.1",
"version": "1.2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
30 changes: 5 additions & 25 deletions apps/frontend-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { ConnectorCategory, constructAuthUrl } from '@panora/shared';

interface PanoraConfig {
apiKey: string;
projectId: string;
overrideApiUrl?: string;
}

Expand Down Expand Up @@ -37,45 +37,26 @@ interface IGConnectionDto {
}

class Panora {
private API_KEY: string;
private apiUrl: string;
private projectId: string | null = null;

constructor(config: PanoraConfig) {
this.API_KEY = config.apiKey;
this.projectId = config.projectId;
this.apiUrl = config.overrideApiUrl || 'https://api.panora.dev';
}

private async fetchProjectId(): Promise<string> {
if (this.projectId) {
return this.projectId;
}
try {
const response = await axios.get(`${this.apiUrl}/projects/current`, {
headers: {
'Authorization': `Bearer ${this.API_KEY}`
}
});

this.projectId = response.data;
return this.projectId as string;
} catch (error) {
throw new Error('Failed to fetch project ID');
}
}

async connect(options: ConnectOptions): Promise<Window | null> {
const { providerName, vertical, linkedUserId, credentials, options: {onSuccess, onError, overrideReturnUrl} = {} } = options;

try {
const projectId = await this.fetchProjectId();
if(!this.projectId) throw new ReferenceError("ProjectId is invalid or undefined")

if (credentials) {
// Handle API Key or Basic Auth
return this.handleCredentialsAuth(projectId, providerName, vertical, linkedUserId, credentials, onSuccess, onError);
return this.handleCredentialsAuth(this.projectId, providerName, vertical, linkedUserId, credentials, onSuccess, onError);
} else {
// Handle OAuth
return this.handleOAuth(projectId, providerName, vertical, linkedUserId, overrideReturnUrl, onSuccess, onError);
return this.handleOAuth(this.projectId, providerName, vertical, linkedUserId, overrideReturnUrl, onSuccess, onError);
}
} catch (error) {
if (onError) {
Expand Down Expand Up @@ -112,7 +93,6 @@ class Panora {
body: JSON.stringify(connectionData.data),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.API_KEY}`
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface IApiKeyConnectionDto {
const useCreateApiKeyConnection = () => {
const createApiKeyConnection = async (apiKeyConnectionData : IApiKeyConnectionDto) => {
const response = await fetch(
`${config.API_URL}/connections/apikey/callback?state=${encodeURIComponent(JSON.stringify(apiKeyConnectionData.query))}`, {
`${config.API_URL}/connections/basicorapikey/callback?state=${encodeURIComponent(JSON.stringify(apiKeyConnectionData.query))}`, {
method: 'POST',
body: JSON.stringify(apiKeyConnectionData.data),
headers: {
Expand Down
17 changes: 0 additions & 17 deletions apps/magic-link/src/hooks/queries/useLinkedUser.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion apps/magic-link/src/hooks/useOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type UseOAuthProps = {
returnUrl: string; // Return URL after OAuth flow
projectId: string; // Project ID
linkedUserId: string; // Linked User ID
redirectIngressUri: string | null; // URL of the User's Server
redirectIngressUri: {
status: boolean;
value: string | null;
} // URL of the User's Server
onSuccess: () => void;
};

Expand Down
18 changes: 14 additions & 4 deletions apps/magic-link/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ const ProviderModal = () => {
const [openSuccessDialog,setOpenSuccessDialog] = useState<boolean>(false);
const [currentProviderLogoURL,setCurrentProviderLogoURL] = useState<string>('')
const [currentProvider,setCurrentProvider] = useState<string>('')
const [redirectIngressUri, setRedirectIngressUri] = useState<string | null>(null);
const [redirectIngressUri, setRedirectIngressUri] = useState<{
status: boolean;
value: string | null;
}>({
status: false,
value: null
});
const {mutate : createApiKeyConnection} = useCreateApiKeyConnection();
const {data: magicLink} = useUniqueMagicLink(uniqueMagicLinkId);
const {data: connectorsForProject} = useProjectConnectors(isProjectIdReady ? projectId : null);
Expand All @@ -88,9 +94,13 @@ const ProviderModal = () => {

useEffect(() => {
const queryParams = new URLSearchParams(window.location.search);
const redirectIngressUri = queryParams.get('redirectIngressUri');
if (redirectIngressUri) {
setRedirectIngressUri(redirectIngressUri);
const param = queryParams.get('redirectIngressUri');
console.log("redirectIngressUri is "+ param)
if (param !== null && param !== undefined) {
setRedirectIngressUri({
status: true,
value: param
});
}
}, []);

Expand Down
11 changes: 8 additions & 3 deletions apps/webapp/src/components/Connection/ConnectionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,20 @@ export default function ConnectionTable() {
const ts = connections?.map((connection) => ({
organisation: nameOrg,
app: connection.provider_slug,
vertical: connection.vertical,
vertical: connection.vertical,
category: connection.token_type,
status: connection.status,
linkedUser: connection.id_linked_user,
date: connection.created_at,
connectionToken: connection.connection_token!
}))

const INGRESS_REDIRECT = config.DISTRIBUTION == 'selfhost' && config.REDIRECT_WEBHOOK_INGRESS;
let link: string;
if(config.DISTRIBUTION == 'selfhost' && config.REDIRECT_WEBHOOK_INGRESS) {
link = `${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}&redirectIngressUri=${config.REDIRECT_WEBHOOK_INGRESS}`
}else{
link = `${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}`
}

return (
<>
Expand Down Expand Up @@ -115,7 +120,7 @@ export default function ConnectionTable() {
</div>
</div>
<DialogFooter>
<Button variant="outline" size="sm" className="h-7 gap-1" type="submit" onClick={() => window.open(`${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}&redirectIngressUri=${INGRESS_REDIRECT}`, '_blank')}>
<Button variant="outline" size="sm" className="h-7 gap-1" type="submit" onClick={() => window.open(link, '_blank')}>
<p className="mr-2">Open Link</p>
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3 2C2.44772 2 2 2.44772 2 3V12C2 12.5523 2.44772 13 3 13H12C12.5523 13 13 12.5523 13 12V8.5C13 8.22386 12.7761 8 12.5 8C12.2239 8 12 8.22386 12 8.5V12H3V3L6.5 3C6.77614 3 7 2.77614 7 2.5C7 2.22386 6.77614 2 6.5 2H3ZM12.8536 2.14645C12.9015 2.19439 12.9377 2.24964 12.9621 2.30861C12.9861 2.36669 12.9996 2.4303 13 2.497L13 2.5V2.50049V5.5C13 5.77614 12.7761 6 12.5 6C12.2239 6 12 5.77614 12 5.5V3.70711L6.85355 8.85355C6.65829 9.04882 6.34171 9.04882 6.14645 8.85355C5.95118 8.65829 5.95118 8.34171 6.14645 8.14645L11.2929 3H9.5C9.22386 3 9 2.77614 9 2.5C9 2.22386 9.22386 2 9.5 2H12.4999H12.5C12.5678 2 12.6324 2.01349 12.6914 2.03794C12.7504 2.06234 12.8056 2.09851 12.8536 2.14645Z" fill="currentColor" fillRule="evenodd" clipRule="evenodd"></path></svg>
</Button>
Expand Down
12 changes: 9 additions & 3 deletions apps/webapp/src/components/Connection/CopyLinkInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ const CopyLinkInput = () => {
const [copied, setCopied] = useState(false);

const {uniqueLink} = useMagicLinkStore();
const INGRESS_REDIRECT = config.DISTRIBUTION == 'selfhost' && config.REDIRECT_WEBHOOK_INGRESS;

let link: string;
if(config.DISTRIBUTION == 'selfhost' && config.REDIRECT_WEBHOOK_INGRESS) {
link = `${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}&redirectIngressUri=${config.REDIRECT_WEBHOOK_INGRESS}`
}else{
link = `${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}`
}

const handleCopy = async () => {
try {
await navigator.clipboard.writeText(`${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}&redirectIngressUri=${INGRESS_REDIRECT}`);
await navigator.clipboard.writeText(link);
toast.success("Magic link copied", {
action: {
label: "Close",
Expand All @@ -35,7 +41,7 @@ const CopyLinkInput = () => {
{uniqueLink !== 'https://' ?
<>
<Input
defaultValue={`${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}&redirectIngressUri=${INGRESS_REDIRECT}`}
defaultValue={link}
readOnly
className="col-span-3 flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/create/useCreateBatchLinkedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ILinkedUserDto {
}
const useCreateBatchLinkedUser = () => {
const add = async (linkedUserData: ILinkedUserDto) => {
const response = await fetch(`${config.API_URL}/linked-users/batch`, {
const response = await fetch(`${config.API_URL}/linked-users/internal/batch`, {
method: 'POST',
body: JSON.stringify(linkedUserData),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/create/useCreateLinkedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ILinkedUserDto {
}
const useCreateLinkedUser = () => {
const add = async (linkedUserData: ILinkedUserDto) => {
const response = await fetch(`${config.API_URL}/linked-users`, {
const response = await fetch(`${config.API_URL}/linked-users/internal`, {
method: 'POST',
body: JSON.stringify(linkedUserData),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/hooks/get/useLinkedUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const useLinkedUsers = () => {
return useQuery({
queryKey: ['linked-users'],
queryFn: async (): Promise<LinkedUser[]> => {
const response = await fetch(`${config.API_URL}/linked-users`,
const response = await fetch(`${config.API_URL}/linked-users/internal`,
{
method: 'GET',
headers: {
Expand Down
18 changes: 0 additions & 18 deletions docs/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions docs/Dockerfile.dev

This file was deleted.

32 changes: 0 additions & 32 deletions docs/README.md

This file was deleted.

Empty file removed docs/_snippets/footer.mdx
Empty file.
3 changes: 0 additions & 3 deletions docs/_snippets/snippet-example.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/auth/create-api-key.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/auth/get-users.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/auth/log-in.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/auth/register.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api-reference/auth/retrieve-api-keys.mdx

This file was deleted.

Loading

0 comments on commit b54b3a5

Please sign in to comment.