@@ -98,7 +98,7 @@ type IUserSettingsAction =
98
98
type IUserSettingsActions = IUserSettingsAction [ ] ;
99
99
100
100
/**
101
- * Editor class used to create and save user tags and attributes
101
+ * Editor class used to create and save profile attributes
102
102
*/
103
103
export class BatchProfileAttributeEditor {
104
104
private _settings : IUserSettingsActions ;
@@ -112,6 +112,12 @@ export class BatchProfileAttributeEditor {
112
112
return this ;
113
113
}
114
114
115
+ /**
116
+ * Set an attribute for a key
117
+ * @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
118
+ * ([a-z0-9_]) and can't be longer than 30 characters.
119
+ * @param value Attribute value. Accepted types are strings, numbers, booleans and array of strings.
120
+ */
115
121
public setAttribute ( key : string , value : string | boolean | number | string [ ] | null ) : BatchProfileAttributeEditor {
116
122
return this . addAction ( {
117
123
type : 'setAttribute' ,
@@ -120,6 +126,19 @@ export class BatchProfileAttributeEditor {
120
126
} ) ;
121
127
}
122
128
129
+ /**
130
+ * Set a Date attribute for a key
131
+ *
132
+ * @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
133
+ * ([a-z0-9_]) and can't be longer than 30 characters.
134
+ * @param value The date value
135
+ *
136
+ * Example:
137
+ * ```js
138
+ * // Set a date attribute with a timestamp
139
+ * BatchProfile.editor().setDateAttribute("birthday", new Date('July 20, 69 00:20:18 GMT+00:00').getTime())
140
+ * ```
141
+ */
123
142
public setDateAttribute ( key : string , value : number ) : BatchProfileAttributeEditor {
124
143
return this . addAction ( {
125
144
type : 'setDateAttribute' ,
@@ -128,6 +147,19 @@ export class BatchProfileAttributeEditor {
128
147
} ) ;
129
148
}
130
149
150
+ /**
151
+ * Set an URL attribute for a key
152
+ *
153
+ * @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
154
+ * ([a-z0-9_]) and can't be longer than 30 characters.
155
+ * @param value The URL value
156
+ *
157
+ * Example:
158
+ * ```js
159
+ * // set an url attribute
160
+ * BatchProfile.editor().setURLAttribute('website', 'https://example.com')
161
+ * ```
162
+ */
131
163
public setURLAttribute ( key : string , value : string ) : BatchProfileAttributeEditor {
132
164
return this . addAction ( {
133
165
type : 'setURLAttribute' ,
@@ -136,55 +168,104 @@ export class BatchProfileAttributeEditor {
136
168
} ) ;
137
169
}
138
170
171
+ /**
172
+ * Remove an attribute
173
+ * @param key The key of the attribute to remove
174
+ */
139
175
public removeAttribute ( key : string ) : BatchProfileAttributeEditor {
140
176
return this . addAction ( {
141
177
type : 'removeAttribute' ,
142
178
key,
143
179
} ) ;
144
180
}
145
181
182
+ /**
183
+ * Set the profile email address.
184
+ *
185
+ * This requires to have a custom user ID registered
186
+ * or to call the `setIdentifier` method on the editor instance beforehand.
187
+ * @param value A valid email address. Null to erase.
188
+ */
146
189
public setEmailAddress ( value : string | null ) : BatchProfileAttributeEditor {
147
190
return this . addAction ( {
148
191
type : 'setEmailAddress' ,
149
192
value,
150
193
} ) ;
151
194
}
152
195
196
+ /**
197
+ * Set the profile email marketing subscription state
198
+ *
199
+ * @param value The state of the marketing email subscription. Must be "subscribed" or "unsubscribed".
200
+ */
153
201
public setEmailMarketingSubscription ( value : BatchEmailSubscriptionState ) : BatchProfileAttributeEditor {
154
202
return this . addAction ( {
155
203
type : 'setEmailMarketingSubscription' ,
156
204
value,
157
205
} ) ;
158
206
}
159
207
208
+ /**
209
+ * Set the profile phone number.
210
+ *
211
+ * This requires to have a custom profile ID registered or to call the `identify` method beforehand.
212
+ * @param value A valid E.164 formatted string. Must start with a `+` and not be longer than 15 digits
213
+ * without special characters (eg: "+33123456789"). Null to reset.
214
+ */
160
215
public setPhoneNumber ( value : string | null ) : BatchProfileAttributeEditor {
161
216
return this . addAction ( {
162
217
type : 'setPhoneNumber' ,
163
218
value,
164
219
} ) ;
165
220
}
166
221
222
+ /**
223
+ * Set the profile SMS marketing subscription state.
224
+ *
225
+ * Note that profile's subscription status is automatically set to unsubscribed when users send a STOP message.
226
+ * @param value The state of the SMS marketing subscription. Must be "subscribed" or "unsubscribed".
227
+ */
167
228
public setSMSMarketingSubscription ( value : BatchSMSSubscriptionState ) : BatchProfileAttributeEditor {
168
229
return this . addAction ( {
169
230
type : 'setSMSMarketingSubscription' ,
170
231
value,
171
232
} ) ;
172
233
}
173
234
235
+ /**
236
+ * Set the application language. Overrides Batch's automatically detected language.
237
+ *
238
+ * Send null to let Batch autodetect it again.
239
+ * @param value Language code. 2 chars minimum, or null
240
+ */
174
241
public setLanguage ( value : string | null ) : BatchProfileAttributeEditor {
175
242
return this . addAction ( {
176
243
type : 'setLanguage' ,
177
244
value,
178
245
} ) ;
179
246
}
180
247
248
+ /**
249
+ * Set the application region. Overrides Batch's automatically detected region.
250
+ *
251
+ * Send "null" to let Batch autodetect it again.
252
+ * @param value Region code. 2 chars minimum, or null
253
+ */
181
254
public setRegion ( value : string | null ) : BatchProfileAttributeEditor {
182
255
return this . addAction ( {
183
256
type : 'setRegion' ,
184
257
value,
185
258
} ) ;
186
259
}
187
260
261
+ /**
262
+ * Add value to an array attribute. If the array doesn't exist it will be created.
263
+ *
264
+ * @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
265
+ * ([a-z0-9_]) and can't be longer than 30 characters.
266
+ * @param value The value to add. Cannot be null, undefined or empty. Must be an array of string or a string no longer
267
+ * than 64 characters.
268
+ */
188
269
public addToArray ( key : string , value : string | string [ ] ) : BatchProfileAttributeEditor {
189
270
return this . addAction ( {
190
271
type : 'addToArray' ,
@@ -193,6 +274,13 @@ export class BatchProfileAttributeEditor {
193
274
} ) ;
194
275
}
195
276
277
+ /**
278
+ * Remove a value from an array attribute.
279
+ *
280
+ * @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
281
+ * ([a-z0-9_]) and can't be longer than 30 characters.
282
+ * @param value The value to remove. Can be a String or an Array of String. Cannot be null, empty or undefined.
283
+ */
196
284
public removeFromArray ( key : string , value : string | string [ ] ) : BatchProfileAttributeEditor {
197
285
return this . addAction ( {
198
286
type : 'removeFromArray' ,
@@ -201,6 +289,9 @@ export class BatchProfileAttributeEditor {
201
289
} ) ;
202
290
}
203
291
292
+ /**
293
+ * Save all the pending changes made in that editor. This action cannot be undone.
294
+ */
204
295
public save ( ) : void {
205
296
RNBatch . profile_saveEditor ( this . _settings ) ;
206
297
}
0 commit comments