Skip to content
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
10 changes: 10 additions & 0 deletions .changeset/fix-webhook-response-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@proofkit/fmodata": minor
---

fix(fmodata): align webhook types with actual FM OData API response

BREAKING: `WebhookListResponse`, `WebhookInfo`, and `WebhookAddResponse` property names changed to match what the API actually returns:
- `Status` → `status`, `WebHook` → `webhooks`
- `webHookID` → `webhookID`, `url` → `webhook`
- `webHookResult` → `webhookResult`
22 changes: 11 additions & 11 deletions apps/docs/content/docs/fmodata/webhooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const result = await db.webhook.add({
});

// Access the created webhook ID
console.log(result.webHookResult.webHookID);
console.log(result.webhookResult.webhookID);
```


Expand Down Expand Up @@ -83,13 +83,13 @@ Get all webhooks configured for the database:
```typescript
const result = await db.webhook.list();

console.log(result.Status); // Status of the operation
console.log(result.WebHook); // Array of webhook configurations
console.log(result.status); // Status of the operation
console.log(result.webhooks); // Array of webhook configurations

result.WebHook.forEach((webhook) => {
console.log(`Webhook ${webhook.webHookID}:`);
result.webhooks.forEach((webhook) => {
console.log(`Webhook ${webhook.webhookID}:`);
console.log(` Table: ${webhook.tableName}`);
console.log(` URL: ${webhook.url}`);
console.log(` URL: ${webhook.webhook}`);
console.log(` Notify Schema Changes: ${webhook.notifySchemaChanges}`);
console.log(` Select: ${webhook.select}`);
console.log(` Filter: ${webhook.filter}`);
Expand All @@ -104,9 +104,9 @@ Retrieve a specific webhook by ID:
```typescript
const webhook = await db.webhook.get(1);

console.log(webhook.webHookID);
console.log(webhook.webhookID);
console.log(webhook.tableName);
console.log(webhook.url);
console.log(webhook.webhook);
console.log(webhook.headers);
console.log(webhook.notifySchemaChanges);
console.log(webhook.select);
Expand Down Expand Up @@ -153,16 +153,16 @@ const addResult = await db.webhook.add({
notifySchemaChanges: false,
});

const webhookId = addResult.webHookResult.webHookID;
const webhookId = addResult.webhookResult.webhookID;
console.log(`Created webhook with ID: ${webhookId}`);

// List all webhooks
const listResult = await db.webhook.list();
console.log(`Total webhooks: ${listResult.WebHook.length}`);
console.log(`Total webhooks: ${listResult.webhooks.length}`);

// Get the webhook we just created
const webhook = await db.webhook.get(webhookId);
console.log(`Webhook URL: ${webhook.url}`);
console.log(`Webhook URL: ${webhook.webhook}`);

// Manually invoke the webhook for specific records
await db.webhook.invoke(webhookId, { rowIDs: [1, 2, 3] });
Expand Down
22 changes: 11 additions & 11 deletions packages/fmodata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ const result = await db.webhook.add({
});

// Access the created webhook ID
console.log(result.webHookResult.webHookID);
console.log(result.webhookResult.webhookID);
```

### Webhook Configuration Options
Expand Down Expand Up @@ -855,13 +855,13 @@ Get all webhooks configured for the database:
```typescript
const result = await db.webhook.list();

console.log(result.Status); // Status of the operation
console.log(result.WebHook); // Array of webhook configurations
console.log(result.status); // Status of the operation
console.log(result.webhooks); // Array of webhook configurations

result.WebHook.forEach((webhook) => {
console.log(`Webhook ${webhook.webHookID}:`);
result.webhooks.forEach((webhook) => {
console.log(`Webhook ${webhook.webhookID}:`);
console.log(` Table: ${webhook.tableName}`);
console.log(` URL: ${webhook.url}`);
console.log(` URL: ${webhook.webhook}`);
console.log(` Notify Schema Changes: ${webhook.notifySchemaChanges}`);
console.log(` Select: ${webhook.select}`);
console.log(` Filter: ${webhook.filter}`);
Expand All @@ -876,9 +876,9 @@ Retrieve a specific webhook by ID:
```typescript
const webhook = await db.webhook.get(1);

console.log(webhook.webHookID);
console.log(webhook.webhookID);
console.log(webhook.tableName);
console.log(webhook.url);
console.log(webhook.webhook);
console.log(webhook.headers);
console.log(webhook.notifySchemaChanges);
console.log(webhook.select);
Expand Down Expand Up @@ -925,16 +925,16 @@ const addResult = await db.webhook.add({
notifySchemaChanges: false,
});

const webhookId = addResult.webHookResult.webHookID;
const webhookId = addResult.webhookResult.webhookID;
console.log(`Created webhook with ID: ${webhookId}`);

// List all webhooks
const listResult = await db.webhook.list();
console.log(`Total webhooks: ${listResult.WebHook.length}`);
console.log(`Total webhooks: ${listResult.webhooks.length}`);

// Get the webhook we just created
const webhook = await db.webhook.get(webhookId);
console.log(`Webhook URL: ${webhook.url}`);
console.log(`Webhook URL: ${webhook.webhook}`);

// Manually invoke the webhook for specific records
await db.webhook.invoke(webhookId, { rowIDs: [1, 2, 3] });
Expand Down
8 changes: 4 additions & 4 deletions packages/fmodata/scripts/capture-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const queriesToCapture: {

// Clone the response before extracting the data
const cloned = response.clone();
const newWebhookId = (await cloned.json()).webHookResult.webHookID;
const newWebhookId = (await cloned.json()).webhookResult.webhookID;
await client(`/Webhook.Delete(${newWebhookId})`);

return { url, method: "POST", response };
Expand Down Expand Up @@ -457,7 +457,7 @@ const queriesToCapture: {

// Clone the response before extracting the data
const cloned = response.clone();
const newWebhookId = (await cloned.json()).webHookResult.webHookID;
const newWebhookId = (await cloned.json()).webhookResult.webhookID;
await client(`/Webhook.Delete(${newWebhookId})`);

return { url, method: "POST", response };
Expand All @@ -469,7 +469,7 @@ const queriesToCapture: {
execute: async (client) => {
const listResponse = await client("/Webhook.GetAll");
const listData = await listResponse.json();
const webhookId = listData.WebHook?.[0]?.webHookID;
const webhookId = listData.webhooks?.[0]?.webhookID;
if (!webhookId) {
throw new Error("No webhook ID found");
}
Expand Down Expand Up @@ -498,7 +498,7 @@ const queriesToCapture: {
execute: async (client) => {
const listResponse = await client("/Webhook.GetAll");
const listData = await listResponse.json();
const webhookId = listData.WebHook?.[0]?.webHookID;
const webhookId = listData.webhooks?.[0]?.webhookID;
if (!webhookId) {
throw new Error("No webhook ID found");
}
Expand Down
27 changes: 16 additions & 11 deletions packages/fmodata/scripts/test-webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ async function testWebhookMethods() {
console.log("Result structure:");
console.log(JSON.stringify(listResult, null, 2));
console.log("\nTypeScript type should be:");
console.log(" { Status: string; WebHook: Array<{ webHookID: number; tableName: string; url: string; ... }> }");
console.log(
" { status: string; webhooks: Array<{ webhookID: number; tableName: string; webhook: string; ... }> }",
);
console.log("\n");
} catch (error: unknown) {
console.log("❌ list() failed:", error instanceof Error ? error.message : String(error));
Expand All @@ -97,7 +99,7 @@ async function testWebhookMethods() {

// Test 2: Add a webhook
console.log("=== Test 2: Add Webhook ===\n");
let webhookId: string | number | undefined;
let webhookId: number | undefined;
try {
const addResult = await db.webhook.add({
webhook: "https://example.com/webhook",
Expand All @@ -110,15 +112,15 @@ async function testWebhookMethods() {
console.log("Result structure:");
console.log(JSON.stringify(addResult, null, 2));
console.log("\nTypeScript type should be:");
console.log(" { webHookResult: { webHookID: number } }");
console.log(" { webhookResult: { webhookID: number } }");

// Try to extract webhook ID from nested structure
if (typeof addResult === "object" && addResult !== null) {
const result = addResult as Record<string, unknown>;
if ("webHookResult" in result) {
const webHookResult = result.webHookResult as Record<string, unknown>;
if (webHookResult && "webHookID" in webHookResult) {
webhookId = webHookResult.webHookID as number;
const result = addResult as unknown as Record<string, unknown>;
if ("webhookResult" in result) {
const webhookResult = result.webhookResult as Record<string, unknown>;
if (webhookResult && "webhookID" in webhookResult) {
webhookId = webhookResult.webhookID as number;
}
} else if ("id" in result) {
webhookId = result.id as number;
Expand Down Expand Up @@ -148,7 +150,7 @@ async function testWebhookMethods() {
console.log(JSON.stringify(getResult, null, 2));
console.log("\nTypeScript type should be:");
console.log(
" { webHookID: number; tableName: string; url: string; headers?: Record<string, string>; notifySchemaChanges: boolean; select: string; filter: string; pendingOperations: unknown[] }",
" { webhookID: number; tableName: string; webhook: string; headers?: Record<string, string>; notifySchemaChanges: boolean; select: string; filter: string; pendingOperations: unknown[] }",
);
console.log("\n");
} catch (error: unknown) {
Expand Down Expand Up @@ -227,8 +229,11 @@ async function testWebhookMethods() {
} catch (error: unknown) {
console.log("✅ get() failed as expected");
console.log("Error type:", error?.constructor?.name ?? typeof error);
console.log("Error message:", error.message);
console.log("Error:", JSON.stringify(error, Object.getOwnPropertyNames(error), 2));
console.log("Error message:", error instanceof Error ? error.message : String(error));
console.log(
"Error:",
JSON.stringify(error, error instanceof Error ? Object.getOwnPropertyNames(error) : undefined, 2),
);
console.log("\n");
}
} catch (error: unknown) {
Expand Down
Loading
Loading