Skip to content

Commit

Permalink
Revert "feat(server): use region apis"
Browse files Browse the repository at this point in the history
This reverts commit 8d48c16.
  • Loading branch information
gwenshap committed Mar 22, 2024
1 parent 1d980ab commit 102f4a5
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 30 deletions.
6 changes: 4 additions & 2 deletions packages/react/src/GoogleLoginButton/GoogleLoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const LOGIN_PATH = 'users/oidc/google/login';
*/
export default function GoogleSSOButton(props: {
href?: string;
workspace?: string;
database?: string;
newTenantName?: string;
}) {
const { database, newTenantName } = props;
const { workspace, database, newTenantName } = props;
const { basePath } = useNileConfig();
const encodedWorkspace = encodeURIComponent(workspace ?? '');
const encodedDatabase = encodeURIComponent(database ?? '');
const contextHref = `${basePath}/databases/${encodedDatabase}/${LOGIN_PATH}`;
const contextHref = `${basePath}/workspaces/${encodedWorkspace}/databases/${encodedDatabase}/${LOGIN_PATH}`;
const query = newTenantName
? '?newTenant=' + encodeURIComponent(newTenantName)
: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe('google sso button', () => {
it('renders using the context', () => {
render(
<NileProvider>
<GoogleSSOButton database="database" />
<GoogleSSOButton workspace="workspace" database="database" />
</NileProvider>
);
screen.getByText('Continue with Google');
expect(screen.getByRole('link').getAttribute('href')).toEqual(
'https://api.thenile.dev/databases/database/users/oidc/google/login'
'https://api.thenile.dev/workspaces/workspace/databases/database/users/oidc/google/login'
);
});
});
2 changes: 1 addition & 1 deletion packages/react/test/SSO/Okta.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Okta', () => {
<NileProvider api={api}>
<Okta
onSuccess={onSuccess}
callbackUrl="http://localhost:8080/databases/database/tenants/tenantId/auth/oidc/callback"
callbackUrl="http://localhost:8080/workspaces/workspace/databases/database/tenants/tenantId/auth/oidc/callback"
providers={[]}
/>
</NileProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Server from '@niledatabase/server';
const connection = {
user: process.env.NILE_USER,
password: process.env.NILE_PASSWORD,
host: process.env.NILE_DB_HOST,
};
const nile = Server({
workspace: String(process.env.NILE_WORKSPACE),
database: String(process.env.NILE_DATABASE),
api: {
basePath: String(process.env.BASE_PATH),
Expand Down
26 changes: 19 additions & 7 deletions packages/server/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default class Auth extends Config {
super(config);
}
get loginUrl() {
return `/databases/${encodeURIComponent(this.database)}/users/login`;
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/users/login`;
}

login = async (
Expand Down Expand Up @@ -117,13 +119,17 @@ export default class Auth extends Config {
};

loginSSOUrl = (provider: string) => {
return `/databases/${encodeURIComponent(this.database)}/tenants/${
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/tenants/${
this.tenantId ?? '{tenantId}'
}/auth/oidc/providers/${provider}/login`;
};

get signUpUrl() {
return `/databases/${encodeURIComponent(this.database)}/users`;
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/users`;
}

signUp = async (
Expand Down Expand Up @@ -156,13 +162,17 @@ export default class Auth extends Config {
};

updateProviderUrl(providerName: string) {
return `/databases/${encodeURIComponent(this.database)}/tenants/${
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/tenants/${
this.tenantId ? encodeURIComponent(this.tenantId) : '{tenantId}'
}/auth/oidc/providers/${encodeURIComponent(providerName)}`;
}

get listTenantProvidersUrl() {
return `/databases/${encodeURIComponent(this.database)}/tenants/${
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/tenants/${
this.tenantId ? encodeURIComponent(this.tenantId) : '{tenantId}'
}/auth/oidc/providers`;
}
Expand Down Expand Up @@ -194,7 +204,9 @@ export default class Auth extends Config {
};

providerUrl(email?: undefined | string) {
return `/databases/${encodeURIComponent(
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(
this.database
)}/tenants/auth/oidc/providers${
email ? `?email=${encodeURIComponent(email)}` : ''
Expand Down Expand Up @@ -222,6 +234,6 @@ export default class Auth extends Config {
tenantId = getTenantFromHttp(param, this);
}

return `${this.api.basePath}/databases/${this.database}/tenants/${tenantId}/auth/oidc/callback`;
return `${this.api.basePath}/workspaces/${this.workspace}/databases/${this.database}/tenants/${tenantId}/auth/oidc/callback`;
};
}
4 changes: 3 additions & 1 deletion packages/server/src/auth/login/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('login', () => {
it('goes to the right url', () => {
const _config = new Config(config);
const auth = new Auth(_config);
expect(auth.loginUrl).toEqual('/databases/database/users/login');
expect(auth.loginUrl).toEqual(
'/workspaces/workspace/databases/database/users/login'
);
});
});
5 changes: 3 additions & 2 deletions packages/server/src/auth/providers/providers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('listProviders', () => {
const res = await listProviders();
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/tenants/auth/oidc/providers'
_config.api.basePath +
'/workspaces/workspace/databases/database/tenants/auth/oidc/providers'
);
});
});
Expand All @@ -50,7 +51,7 @@ describe('updateProvider', () => {
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath +
'/databases/database/tenants/tenantId/auth/oidc/providers/okta'
'/workspaces/workspace/databases/database/tenants/tenantId/auth/oidc/providers/okta'
);
});
});
2 changes: 1 addition & 1 deletion packages/server/src/auth/signUp/signUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('signUp', () => {
const res = await signUp({ email: 'email', password: 'password' });
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/users'
_config.api.basePath + '/workspaces/workspace/databases/database/users'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('createUser', () => {
const res = await createTenant(params);
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/tenants'
_config.api.basePath + '/workspaces/workspace/databases/database/tenants'
);
});
});
3 changes: 2 additions & 1 deletion packages/server/src/tenants/getTenant/getTenant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('getTenant', () => {
const res = await getTenant();
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/tenants/123'
_config.api.basePath +
'/workspaces/workspace/databases/database/tenants/123'
);
});
});
8 changes: 6 additions & 2 deletions packages/server/src/tenants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export default class Tenants extends Config {
super(config);
}
get tenantsUrl() {
return `/databases/${encodeURIComponent(this.database)}/tenants`;
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/tenants`;
}
get tenantUrl() {
return `/databases/${encodeURIComponent(this.database)}/tenants/${
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/tenants/${
this.tenantId ?? '{tenantId}'
}`;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ServerConfig = {
database: string;
tenantId?: string | null | undefined;
userId?: string | null | undefined;
workspace?: string;
workspace: string;
db?: Knex.Config;
api?: {
basePath?: string;
Expand All @@ -28,6 +28,7 @@ export type InstanceConfig = {
database?: string;
tenantId?: string | null | undefined;
userId?: string | null | undefined;
workspace?: string;
db?: Knex.Config;
api?: {
basePath?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('createUser', () => {
const res = await createTenantUser(params);
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/tenants/tenant/users'
_config.api.basePath +
'/workspaces/workspace/databases/database/tenants/tenant/users'
);
});
});
8 changes: 6 additions & 2 deletions packages/server/src/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default class Users extends Config {
}

get baseUrl() {
return `/databases/${encodeURIComponent(this.database)}`;
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}`;
}

get usersUrl() {
Expand Down Expand Up @@ -54,7 +56,9 @@ export default class Users extends Config {
};

get meUrl() {
return `/databases/${encodeURIComponent(this.database)}/users/me`;
return `/workspaces/${encodeURIComponent(
this.workspace
)}/databases/${encodeURIComponent(this.database)}/users/me`;
}

me = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('listTenantUsers', () => {
const res = await listTenantUsers();
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/tenants/tenant/users'
_config.api.basePath +
'/workspaces/workspace/databases/database/tenants/tenant/users'
);
});
});
2 changes: 1 addition & 1 deletion packages/server/src/users/listUsers/listUsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('listUsers', () => {
const res = await listUsers();
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/users'
_config.api.basePath + '/workspaces/workspace/databases/database/users'
);
});
});
2 changes: 1 addition & 1 deletion packages/server/src/users/me/me.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('me', () => {
const res = await me();
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/users/me'
_config.api.basePath + '/workspaces/workspace/databases/database/users/me'
);
});
});
3 changes: 2 additions & 1 deletion packages/server/src/users/updateUser/updateUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('updateUser', () => {
const res = await updateUser(userId, params);
//@ts-expect-error - test
expect(res.config).toEqual(
_config.api.basePath + '/databases/database/users/12345'
_config.api.basePath +
'/workspaces/workspace/databases/database/users/12345'
);
//@ts-expect-error - test
expect(res.payload.path.method).toEqual('PUT');
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/utils/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type DBConfig = {
};
export class Config {
database: string;
workspace?: string;
workspace: string;

db: DBConfig;

Expand Down

0 comments on commit 102f4a5

Please sign in to comment.