Skip to content

Commit 6b015fb

Browse files
committed
profile: add tsdoc comments to batch profile attribute editor
1 parent 1ef2804 commit 6b015fb

File tree

1 file changed

+92
-1
lines changed

1 file changed

+92
-1
lines changed

src/BatchProfileAttributeEditor.ts

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type IUserSettingsAction =
9898
type IUserSettingsActions = IUserSettingsAction[];
9999

100100
/**
101-
* Editor class used to create and save user tags and attributes
101+
* Editor class used to create and save profile attributes
102102
*/
103103
export class BatchProfileAttributeEditor {
104104
private _settings: IUserSettingsActions;
@@ -112,6 +112,12 @@ export class BatchProfileAttributeEditor {
112112
return this;
113113
}
114114

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+
*/
115121
public setAttribute(key: string, value: string | boolean | number | string[] | null): BatchProfileAttributeEditor {
116122
return this.addAction({
117123
type: 'setAttribute',
@@ -120,6 +126,19 @@ export class BatchProfileAttributeEditor {
120126
});
121127
}
122128

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+
*/
123142
public setDateAttribute(key: string, value: number): BatchProfileAttributeEditor {
124143
return this.addAction({
125144
type: 'setDateAttribute',
@@ -128,6 +147,19 @@ export class BatchProfileAttributeEditor {
128147
});
129148
}
130149

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+
*/
131163
public setURLAttribute(key: string, value: string): BatchProfileAttributeEditor {
132164
return this.addAction({
133165
type: 'setURLAttribute',
@@ -136,55 +168,104 @@ export class BatchProfileAttributeEditor {
136168
});
137169
}
138170

171+
/**
172+
* Remove an attribute
173+
* @param key The key of the attribute to remove
174+
*/
139175
public removeAttribute(key: string): BatchProfileAttributeEditor {
140176
return this.addAction({
141177
type: 'removeAttribute',
142178
key,
143179
});
144180
}
145181

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+
*/
146189
public setEmailAddress(value: string | null): BatchProfileAttributeEditor {
147190
return this.addAction({
148191
type: 'setEmailAddress',
149192
value,
150193
});
151194
}
152195

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+
*/
153201
public setEmailMarketingSubscription(value: BatchEmailSubscriptionState): BatchProfileAttributeEditor {
154202
return this.addAction({
155203
type: 'setEmailMarketingSubscription',
156204
value,
157205
});
158206
}
159207

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+
*/
160215
public setPhoneNumber(value: string | null): BatchProfileAttributeEditor {
161216
return this.addAction({
162217
type: 'setPhoneNumber',
163218
value,
164219
});
165220
}
166221

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+
*/
167228
public setSMSMarketingSubscription(value: BatchSMSSubscriptionState): BatchProfileAttributeEditor {
168229
return this.addAction({
169230
type: 'setSMSMarketingSubscription',
170231
value,
171232
});
172233
}
173234

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+
*/
174241
public setLanguage(value: string | null): BatchProfileAttributeEditor {
175242
return this.addAction({
176243
type: 'setLanguage',
177244
value,
178245
});
179246
}
180247

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+
*/
181254
public setRegion(value: string | null): BatchProfileAttributeEditor {
182255
return this.addAction({
183256
type: 'setRegion',
184257
value,
185258
});
186259
}
187260

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+
*/
188269
public addToArray(key: string, value: string | string[]): BatchProfileAttributeEditor {
189270
return this.addAction({
190271
type: 'addToArray',
@@ -193,6 +274,13 @@ export class BatchProfileAttributeEditor {
193274
});
194275
}
195276

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+
*/
196284
public removeFromArray(key: string, value: string | string[]): BatchProfileAttributeEditor {
197285
return this.addAction({
198286
type: 'removeFromArray',
@@ -201,6 +289,9 @@ export class BatchProfileAttributeEditor {
201289
});
202290
}
203291

292+
/**
293+
* Save all the pending changes made in that editor. This action cannot be undone.
294+
*/
204295
public save(): void {
205296
RNBatch.profile_saveEditor(this._settings);
206297
}

0 commit comments

Comments
 (0)