Skip to content
Open
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 6 additions & 8 deletions src/commands/app/database/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
databasePurposeFlag,
} from "../../../lib/resources/app/database/flags.js";
import { resolveDatabaseId } from "../../../lib/resources/app/database/lookup.js";
import { linkDatabase } from "../../../lib/resources/app/database/deprecated_operations.js";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Code agent forgot to update api-client and did not find actual operation that replaces the old one.

If it did, it would have seen that a perfectly fine alternative exists and provides the fields needed, at least specs say so. Signature in older api clients did not contain database fields yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full ack, this is NOT a good solution. 🙅‍♂️


export default class Link extends ExecRenderBaseCommand<typeof Link, void> {
static summary = "Link a database to an app installation.";
Expand Down Expand Up @@ -71,14 +72,11 @@ export default class Link extends ExecRenderBaseCommand<typeof Link, void> {
});

await process.runStep("linking database", async () => {
const response = await this.apiClient.app.linkDatabase({
appInstallationId,
data: {
databaseId,
purpose: purpose as "primary" | "cache" | "custom",
databaseUserIds: {
admin: adminUserId,
},
const response = await linkDatabase(this.apiClient, appInstallationId, {
databaseId,
purpose: purpose as "primary" | "cache" | "custom",
databaseUserIds: {
admin: adminUserId,
},
});
assertSuccess(response);
Expand Down
8 changes: 5 additions & 3 deletions src/commands/app/database/replace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
resolveDatabaseId,
selectLinkedDatabase,
} from "../../../lib/resources/app/database/lookup.js";
import { replaceDatabase } from "../../../lib/resources/app/database/deprecated_operations.js";

export default class Replace extends ExecRenderBaseCommand<
typeof Replace,
Expand Down Expand Up @@ -87,16 +88,17 @@ export default class Replace extends ExecRenderBaseCommand<
);

await process.runStep("replacing database", async () => {
const response = await this.apiClient.app.replaceDatabase({
const response = await replaceDatabase(
this.apiClient,
appInstallationId,
data: {
{
oldDatabaseId,
newDatabaseId,
databaseUserIds: {
admin: adminUserId,
},
},
});
);
assertSuccess(response);
});

Expand Down
69 changes: 69 additions & 0 deletions src/lib/resources/app/database/deprecated_operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { MittwaldAPIV2Client } from "@mittwald/api-client";
import { Response } from "@mittwald/api-client-commons";

/**
* The `app-link-database` and `app-replace-database` operations are marked as
* deprecated in the mStudio OpenAPI specification, and are therefore no longer
* part of the generated API client (as of `@mittwald/api-client` 4.431.0). Both
* endpoints are still served by the API, and no successor operations exist yet,
* so they are invoked directly via the client's Axios instance here.
*
* Once the API offers replacements, these helpers should be dropped in favour
* of the generated client methods.
*/

type DatabaseUserIds = Record<string, string | undefined>;

/**
* Mirrors the behaviour of the generated request functions: HTTP error statuses
* are returned as a regular response instead of being thrown, so that callers
* can keep using `assertSuccess`/`assertStatus`.
*/
async function requestWithoutStatusValidation(
apiClient: MittwaldAPIV2Client,
url: string,
data: unknown,
): Promise<Response> {
const response = await apiClient.axios.request({
url,
method: "PATCH",
data,
validateStatus: () => true,
});

return response as Response;
}

/** Links an existing database to an app installation for the given purpose. */
export async function linkDatabase(
apiClient: MittwaldAPIV2Client,
appInstallationId: string,
data: {
databaseId: string;
purpose: "primary" | "cache" | "custom";
databaseUserIds?: DatabaseUserIds;
},
): Promise<Response> {
return requestWithoutStatusValidation(
apiClient,
`/v2/app-installations/${encodeURIComponent(appInstallationId)}/database`,
data,
);
}

/** Replaces the database currently linked to an app installation. */
export async function replaceDatabase(
apiClient: MittwaldAPIV2Client,
appInstallationId: string,
data: {
oldDatabaseId: string;
newDatabaseId: string;
databaseUserIds?: DatabaseUserIds;
},
): Promise<Response> {
return requestWithoutStatusValidation(
apiClient,
`/v2/app-installations/${encodeURIComponent(appInstallationId)}/database/replace`,
data,
);
}
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1870,9 +1870,9 @@ __metadata:
languageName: node
linkType: hard

"@mittwald/api-client-commons@npm:^4.430.0":
version: 4.430.0
resolution: "@mittwald/api-client-commons@npm:4.430.0"
"@mittwald/api-client-commons@npm:^4.436.0":
version: 4.436.0
resolution: "@mittwald/api-client-commons@npm:4.436.0"
dependencies:
"@types/parse-path": ^7.0.3
axios: ^1.15.2
Expand All @@ -1886,22 +1886,22 @@ __metadata:
optional: true
"@mittwald/react-use-promise":
optional: true
checksum: 3e3a563c3a4de7e99ed0d3950280b1a5e7bcb878365dafbf2361c9db1caddabd7d1751be57269daa47170b6c171d560faee9666b9c8c79946fb4c76da5d7a16f
checksum: 499644814517aa12fc2d13ef87de6433236da0057b2aeebb3b60ca66b0ce347989fba39aa971085fd4ec7502f9ff455dd214fda312e0770c82370b1ef1250b98
languageName: node
linkType: hard

"@mittwald/api-client@npm:^4.400.0":
version: 4.430.0
resolution: "@mittwald/api-client@npm:4.430.0"
version: 4.436.0
resolution: "@mittwald/api-client@npm:4.436.0"
dependencies:
"@mittwald/api-client-commons": ^4.430.0
"@mittwald/api-client-commons": ^4.436.0
browser-or-node: ^3.0.0
peerDependencies:
"@mittwald/react-use-promise": ^2.6.0
peerDependenciesMeta:
"@mittwald/react-use-promise":
optional: true
checksum: 3645b95caad1129d4961b779dc0c99f687143f9db249d2a96768a1fae1632a50625f7cb62bf3fca4797f1d897e6f52915c66cfa9473e1f0a31a1e789f9bf78bc
checksum: 5cffe9f29c6899115ae92750aa7d1d85785ce82030068129364e0484893fd0f8fd612b8f8c20eda653f924f9569df1a26872d80cb054ad22d214111bc4358c00
languageName: node
linkType: hard

Expand Down
Loading