Skip to content
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

chore(sdk): update serivceusers api as per new proto #826

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
553 changes: 300 additions & 253 deletions sdks/js/packages/core/api-client/V1Beta1.ts

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions sdks/js/packages/core/api-client/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,6 @@ export interface V1Beta1CreateServiceUserJWKResponse {
key?: V1Beta1KeyCredential;
}

export interface V1Beta1CreateServiceUserRequest {
body?: V1Beta1ServiceUserRequestBody;
/** The organization ID to which the service user belongs to. */
org_id: string;
}

export interface V1Beta1CreateServiceUserResponse {
serviceuser?: V1Beta1ServiceUser;
}
Expand Down Expand Up @@ -1855,6 +1849,8 @@ export interface V1Beta1Subscription {
plan?: V1Beta1Plan;
}

export type V1Beta1UpdateBillingAccountLimitsResponse = object;

export interface V1Beta1UpdateBillingAccountResponse {
/** Updated billing account */
billing_account?: V1Beta1BillingAccount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export const AddServiceAccount = () => {
try {
const {
data: { serviceuser }
} = await client.frontierServiceCreateServiceUser({
body: data,
org_id: orgId
} = await client.frontierServiceCreateServiceUser(orgId, {
body: data
});

if (serviceuser?.id) {
const {
data: { token }
} = await client.frontierServiceCreateServiceUserToken(
orgId,
serviceuser?.id,
{ title: DEFAULT_KEY_NAME }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const DeleteServiceAccount = () => {
const { client, activeOrganization: organization } = useFrontier();
const [isLoading, setIsLoading] = useState(false);

const orgId = organization?.id;
const orgId = organization?.id || '';

async function onDeleteClick() {
try {
setIsLoading(true);
await client?.frontierServiceDeleteServiceUser(id, { org_id: orgId });
await client?.frontierServiceDeleteServiceUser(orgId, id);
navigate({
to: '/api-keys',
state: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ export default function ApiKeys() {
async function getServiceAccounts(orgId: string) {
try {
setIsServiceUsersLoading(true);
const resp = await client?.frontierServiceListServiceUsers({
org_id: orgId
});
const resp = await client?.frontierServiceListOrganizationServiceUsers(
orgId
);
const data = resp?.data?.serviceusers || [];
setServiceUsers(data);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
onAddToken = () => {}
}: {
serviceUserId: string;
onAddToken: (token: V1Beta1ServiceUserToken) => void;

Check warning on line 24 in sdks/js/packages/core/react/components/organization/api-keys/service-user/add-token.tsx

View workflow job for this annotation

GitHub Actions / JS SDK Lint

'token' is defined but never used
}) {
const { client } = useFrontier();
const { client, activeOrganization } = useFrontier();
const {
control,
handleSubmit,
Expand All @@ -32,6 +32,8 @@
resolver: yupResolver(serviceAccountSchema)
});

const orgId = activeOrganization?.id || '';

const onSubmit = useCallback(
async (data: FormData) => {
if (!client) return;
Expand All @@ -40,6 +42,7 @@
const {
data: { token }
} = await client.frontierServiceCreateServiceUserToken(
orgId,
serviceUserId,
data
);
Expand All @@ -53,7 +56,7 @@
});
}
},
[client, onAddToken, serviceUserId]
[client, onAddToken, serviceUserId, orgId]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export const DeleteServiceAccountKey = () => {
from: '/api-keys/$id/key/$tokenId/delete'
});
const navigate = useNavigate({ from: '/api-keys/$id/key/$tokenId/delete' });
const { client, config } = useFrontier();
const { client, config, activeOrganization } = useFrontier();
const [isLoading, setIsLoading] = useState(false);

const orgId = activeOrganization?.id || '';

async function onDeleteClick() {
try {
setIsLoading(true);
await client?.frontierServiceDeleteServiceUserToken(id, tokenId);
await client?.frontierServiceDeleteServiceUserToken(orgId, id, tokenId);
navigate({
to: '/api-keys/$id',
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const SerivceUserTokenList = ({

export default function ServiceUserPage() {
let { id } = useParams({ from: '/api-keys/$id' });
const { client, config } = useFrontier();
const { client, config, activeOrganization } = useFrontier();
const navigate = useNavigate({ from: '/api-keys/$id' });

const [serviceUser, setServiceUser] = useState<V1Beta1ServiceUser>();
Expand All @@ -162,12 +162,16 @@ export default function ServiceUserPage() {
const location = useLocation();
const existingToken = location?.state?.token;
const refetch = location?.state?.refetch;
const orgId = activeOrganization?.id || '';

const getServiceUser = useCallback(
async (serviceUserId: string) => {
try {
setIsServiceUserLoading(true);
const resp = await client?.frontierServiceGetServiceUser(serviceUserId);
const resp = await client?.frontierServiceGetServiceUser(
orgId,
serviceUserId
);
const data = resp?.data?.serviceuser;
setServiceUser(data);
} catch (error) {
Expand All @@ -176,14 +180,15 @@ export default function ServiceUserPage() {
setIsServiceUserLoading(false);
}
},
[client]
[client, orgId]
);

const getServiceUserTokens = useCallback(
async (serviceUserId: string) => {
try {
setIsServiceUserTokensLoading(true);
const resp = await client?.frontierServiceListServiceUserTokens(
orgId,
serviceUserId
);
const data = resp?.data?.tokens || [];
Expand All @@ -194,7 +199,7 @@ export default function ServiceUserPage() {
setIsServiceUserTokensLoading(false);
}
},
[client]
[client, orgId]
);

useEffect(() => {
Expand Down
Loading