@@ -2,6 +2,11 @@ import { Args, Flags } from "@oclif/core";
22
33import { ControlBaseCommand } from "../../../control-base-command.js" ;
44import { formatChannelRuleDetails } from "../../../utils/channel-rule-display.js" ;
5+ import {
6+ formatLabel ,
7+ formatSuccess ,
8+ formatWarning ,
9+ } from "../../../utils/output.js" ;
510
611export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
712 static args = {
@@ -15,6 +20,7 @@ export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
1520
1621 static examples = [
1722 "$ ably apps channel-rules update chat --persisted" ,
23+ "$ ably apps channel-rules update chat --mutable-messages" ,
1824 "$ ably apps channel-rules update events --push-enabled=false" ,
1925 '$ ably apps channel-rules update notifications --persisted --push-enabled --app "My App"' ,
2026 "$ ably apps channel-rules update chat --persisted --json" ,
@@ -65,6 +71,12 @@ export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
6571 "Whether to expose the time serial for messages on channels matching this rule" ,
6672 required : false ,
6773 } ) ,
74+ "mutable-messages" : Flags . boolean ( {
75+ allowNo : true ,
76+ description :
77+ "Whether messages on channels matching this rule can be updated or deleted after publishing. Automatically enables message persistence." ,
78+ required : false ,
79+ } ) ,
6880 "persist-last" : Flags . boolean ( {
6981 allowNo : true ,
7082 description :
@@ -120,10 +132,39 @@ export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
120132 const updateData : Record < string , boolean | number | string | undefined > =
121133 { } ;
122134
135+ // Validation for mutable-messages flag, checks with supplied/existing mutableMessages flag
136+ if (
137+ flags . persisted === false &&
138+ ( flags [ "mutable-messages" ] === true ||
139+ ( flags [ "mutable-messages" ] === undefined &&
140+ namespace . mutableMessages ) )
141+ ) {
142+ this . fail (
143+ "Cannot disable persistence when mutable messages is enabled. Mutable messages requires message persistence." ,
144+ flags ,
145+ "channelRuleUpdate" ,
146+ { appId, ruleId : namespace . id } ,
147+ ) ;
148+ }
149+
123150 if ( flags . persisted !== undefined ) {
124151 updateData . persisted = flags . persisted ;
125152 }
126153
154+ if ( flags [ "mutable-messages" ] !== undefined ) {
155+ updateData . mutableMessages = flags [ "mutable-messages" ] ;
156+ if ( flags [ "mutable-messages" ] ) {
157+ updateData . persisted = true ;
158+ if ( ! this . shouldOutputJson ( flags ) ) {
159+ this . logToStderr (
160+ formatWarning (
161+ "Message persistence is automatically enabled when mutable messages is enabled." ,
162+ ) ,
163+ ) ;
164+ }
165+ }
166+ }
167+
127168 if ( flags [ "push-enabled" ] !== undefined ) {
128169 updateData . pushEnabled = flags [ "push-enabled" ] ;
129170 }
@@ -199,6 +240,7 @@ export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
199240 exposeTimeSerial : updatedNamespace . exposeTimeSerial ,
200241 id : updatedNamespace . id ,
201242 modified : new Date ( updatedNamespace . modified ) . toISOString ( ) ,
243+ mutableMessages : updatedNamespace . mutableMessages ,
202244 persistLast : updatedNamespace . persistLast ,
203245 persisted : updatedNamespace . persisted ,
204246 populateChannelRegistry : updatedNamespace . populateChannelRegistry ,
@@ -210,8 +252,8 @@ export default class ChannelRulesUpdateCommand extends ControlBaseCommand {
210252 flags ,
211253 ) ;
212254 } else {
213- this . log ( "Channel rule updated successfully:" ) ;
214- this . log ( `ID: ${ updatedNamespace . id } ` ) ;
255+ this . log ( formatSuccess ( "Channel rule updated." ) ) ;
256+ this . log ( `${ formatLabel ( "ID" ) } ${ updatedNamespace . id } ` ) ;
215257 for ( const line of formatChannelRuleDetails ( updatedNamespace , {
216258 formatDate : ( t ) => this . formatDate ( t ) ,
217259 showTimestamps : true ,
0 commit comments