//native
type Ably = {
accessToken: string;
};
/**
* Updates a Rule
* Updates the rule specified by the rule ID, for the application specified by application ID.
*/
export async function main(
auth: Ably,
app_id: string,
rule_id: string,
body:
| {
status?: string;
ruleType: "http";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
url?: string;
headers?: { name?: string; value?: string }[];
signingKeyId?: string;
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "http/ifttt";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: { webhookKey?: string; eventName?: string };
}
| {
status?: string;
ruleType: "http/zapier";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
url?: string;
headers?: { name?: string; value?: string }[];
signingKeyId?: string;
};
}
| {
status?: string;
ruleType: "http/cloudflare-worker";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
url?: string;
headers?: { name?: string; value?: string }[];
signingKeyId?: string;
};
}
| {
status?: string;
ruleType: "http/azure-function";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
azureAppId?: string;
azureFunctionName?: string;
headers?: { name?: string; value?: string }[];
signingKeyId?: string;
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "http/google-cloud-function";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
region?: string;
projectId?: string;
functionName?: string;
headers?: { name?: string; value?: string }[];
signingKeyId?: string;
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "aws/lambda";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
region: string;
functionName: string;
authentication:
| {
authenticationMode?: "credentials";
accessKeyId: string;
secretAccessKey: string;
}
| { authenticationMode?: "assumeRole"; assumeRoleArn: string };
enveloped?: false | true;
};
}
| {
status?: string;
ruleType: "aws/kinesis";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
region?: string;
streamName?: string;
partitionKey?: string;
authentication?:
| {
authenticationMode?: "credentials";
accessKeyId: string;
secretAccessKey: string;
}
| { authenticationMode?: "assumeRole"; assumeRoleArn: string };
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "aws/sqs";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
region?: string;
awsAccountId?: string;
queueName?: string;
authentication?:
| {
authenticationMode?: "credentials";
accessKeyId: string;
secretAccessKey: string;
}
| { authenticationMode?: "assumeRole"; assumeRoleArn: string };
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "amqp";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
queueId?: string;
headers?: { name?: string; value?: string }[];
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "amqp/external";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
url?: string;
routingKey?: string;
mandatoryRoute?: false | true;
persistentMessages?: false | true;
messageTtl?: number;
headers?: { name?: string; value?: string }[];
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "kafka";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
routingKey?: string;
brokers?: string[];
auth?: {
sasl?: {
mechanism?: "plain" | "scram-sha-256" | "scram-sha-512";
username?: string;
password?: string;
};
};
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "pulsar";
requestMode?: string;
source?: { channelFilter?: string; type?: string };
target?: {
routingKey?: string;
topic?: string;
serviceUrl?: string;
tlsTrustCerts?: string[];
authentication?: { authenticationMode: "token"; token: string };
enveloped?: false | true;
format?: string;
};
}
| {
status?: string;
ruleType: "ingress-postgres-outbox";
target: {
url: string;
outboxTableSchema: string;
outboxTableName: string;
nodesTableSchema: string;
nodesTableName: string;
sslMode: "prefer" | "require" | "verify-ca" | "verify-full";
sslRootCert?: string;
};
},
) {
const url = new URL(
`https://control.ably.net/v1/apps/${app_id}/rules/${rule_id}`,
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.accessToken,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 220 days ago