ssjs-data 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -0
- package/package.json +33 -0
- package/src/index.js +2783 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,2783 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical SSJS (Server-Side JavaScript) catalog for SFMC tooling.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth consumed by:
|
|
5
|
+
* - eslint-plugin-sfmc (globals, unknown-function detection, platform-load checks)
|
|
6
|
+
* - prettier-plugin-sfmc (language registration)
|
|
7
|
+
* - vscode-sfmc-language (completions, hover, diagnostics)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const INF = Infinity;
|
|
11
|
+
|
|
12
|
+
// ── Global functions ─────────────────────────────────────────────────────────
|
|
13
|
+
// Functions and objects available at the top scope of any SSJS execution context.
|
|
14
|
+
|
|
15
|
+
export const SSJS_GLOBALS = [
|
|
16
|
+
{
|
|
17
|
+
name: 'Write',
|
|
18
|
+
type: 'function',
|
|
19
|
+
minArgs: 1,
|
|
20
|
+
maxArgs: 1,
|
|
21
|
+
description: 'Outputs a string to the rendered page.',
|
|
22
|
+
params: [{ name: 'content', description: 'String to output', type: 'string' }],
|
|
23
|
+
returnType: 'void',
|
|
24
|
+
syntax: 'Write(content)',
|
|
25
|
+
example: 'var greeting = "Hello, world!";\nWrite(greeting);',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'Stringify',
|
|
29
|
+
type: 'function',
|
|
30
|
+
minArgs: 1,
|
|
31
|
+
maxArgs: 1,
|
|
32
|
+
description: 'Converts an object to its JSON text representation. Use this to serialize objects before writing or storing them. Not to be confused with the native String() function, which converts a CLR response object to a plain string.',
|
|
33
|
+
params: [{ name: 'value', description: 'Object to serialize', type: 'object' }],
|
|
34
|
+
returnType: 'string',
|
|
35
|
+
syntax: 'Stringify(value)',
|
|
36
|
+
example: 'var obj = { name: "Jane", age: 30 };\nvar jsonStr = Stringify(obj);\nWrite(jsonStr); // outputs: {"name":"Jane","age":30}',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'Variable',
|
|
40
|
+
type: 'object',
|
|
41
|
+
description: 'Provides access to AMPscript variables from SSJS context.',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'Attribute',
|
|
45
|
+
type: 'object',
|
|
46
|
+
description: 'Provides access to subscriber attribute values.',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Platform',
|
|
50
|
+
type: 'object',
|
|
51
|
+
description:
|
|
52
|
+
'Root namespace for SFMC platform APIs including Function, Variable, Response, and Request.',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'ContentBlockByKey',
|
|
56
|
+
type: 'function',
|
|
57
|
+
minArgs: 1,
|
|
58
|
+
maxArgs: 1,
|
|
59
|
+
description: 'Renders a Content Builder asset by its customer key.',
|
|
60
|
+
params: [{ name: 'customerKey', description: 'Customer key of the Content Builder asset', type: 'string' }],
|
|
61
|
+
returnType: 'string',
|
|
62
|
+
syntax: 'ContentBlockByKey(customerKey)',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'ContentBlockByName',
|
|
66
|
+
type: 'function',
|
|
67
|
+
minArgs: 1,
|
|
68
|
+
maxArgs: 1,
|
|
69
|
+
description: 'Renders a Content Builder asset by its folder path and name.',
|
|
70
|
+
params: [{ name: 'name', description: 'Folder path and name of the Content Builder asset', type: 'string' }],
|
|
71
|
+
returnType: 'string',
|
|
72
|
+
syntax: 'ContentBlockByName(name)',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'ContentBlockByID',
|
|
76
|
+
type: 'function',
|
|
77
|
+
minArgs: 1,
|
|
78
|
+
maxArgs: 1,
|
|
79
|
+
description: 'Renders a Content Builder asset by its numeric ID.',
|
|
80
|
+
params: [{ name: 'id', description: 'Numeric ID of the Content Builder asset', type: 'number' }],
|
|
81
|
+
returnType: 'string',
|
|
82
|
+
syntax: 'ContentBlockByID(id)',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'ContentAreaByKey',
|
|
86
|
+
type: 'function',
|
|
87
|
+
minArgs: 1,
|
|
88
|
+
maxArgs: 1,
|
|
89
|
+
description: 'Renders a classic content area by its external key.',
|
|
90
|
+
params: [{ name: 'key', description: 'External key of the classic content area', type: 'string' }],
|
|
91
|
+
returnType: 'string',
|
|
92
|
+
syntax: 'ContentAreaByKey(key)',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'TreatAsContent',
|
|
96
|
+
type: 'function',
|
|
97
|
+
minArgs: 1,
|
|
98
|
+
maxArgs: 1,
|
|
99
|
+
description:
|
|
100
|
+
'Evaluates a string containing AMPscript or HTML and returns the rendered result.',
|
|
101
|
+
params: [{ name: 'content', description: 'String containing AMPscript or HTML to evaluate', type: 'string' }],
|
|
102
|
+
returnType: 'string',
|
|
103
|
+
syntax: 'TreatAsContent(content)',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'TreatAsContentArea',
|
|
107
|
+
type: 'function',
|
|
108
|
+
minArgs: 1,
|
|
109
|
+
maxArgs: 1,
|
|
110
|
+
description: 'Renders a classic content area stored in the system.',
|
|
111
|
+
params: [{ name: 'content', description: 'Classic content area markup to render', type: 'string' }],
|
|
112
|
+
returnType: 'string',
|
|
113
|
+
syntax: 'TreatAsContentArea(content)',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'String',
|
|
117
|
+
type: 'function',
|
|
118
|
+
minArgs: 1,
|
|
119
|
+
maxArgs: 1,
|
|
120
|
+
description:
|
|
121
|
+
'Native JavaScript function that converts any value to its string representation. ' +
|
|
122
|
+
'Essential in SSJS for converting the CLR response object returned by Script.Util.HttpRequest.send().content ' +
|
|
123
|
+
'into a JavaScript string that can be passed to Platform.Function.ParseJSON(). ' +
|
|
124
|
+
'Unlike Stringify(), String() works on CLR/.NET objects and does not produce JSON output.',
|
|
125
|
+
params: [{ name: 'value', description: 'Value to convert to string (any type, including CLR objects)', type: 'any' }],
|
|
126
|
+
returnType: 'string',
|
|
127
|
+
syntax: 'String(value)',
|
|
128
|
+
example:
|
|
129
|
+
'// Convert a CLR response object to a JavaScript string for JSON parsing:\n' +
|
|
130
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
131
|
+
'req.method = "GET";\n' +
|
|
132
|
+
'var resp = req.send();\n' +
|
|
133
|
+
'var responseStr = String(resp.content); // CLR -> JS string\n' +
|
|
134
|
+
'var responseJSON = Platform.Function.ParseJSON(responseStr);\n\n' +
|
|
135
|
+
'// Also works for numbers and other primitives:\n' +
|
|
136
|
+
'var num = 42;\n' +
|
|
137
|
+
'var str = String(num); // "42"',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'Error',
|
|
141
|
+
type: 'function',
|
|
142
|
+
minArgs: 0,
|
|
143
|
+
maxArgs: 1,
|
|
144
|
+
description:
|
|
145
|
+
'Native JavaScript Error constructor. Creates an Error object that can be thrown or caught. ' +
|
|
146
|
+
'Use inside try/catch blocks for structured error handling in SSJS. ' +
|
|
147
|
+
'The caught error object has a message property.',
|
|
148
|
+
params: [{ name: 'message', description: 'Human-readable description of the error', type: 'string', optional: true }],
|
|
149
|
+
returnType: 'object',
|
|
150
|
+
syntax: 'new Error([message])',
|
|
151
|
+
example:
|
|
152
|
+
'try {\n' +
|
|
153
|
+
' var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
154
|
+
' req.method = "GET";\n' +
|
|
155
|
+
' req.continueOnError = false;\n' +
|
|
156
|
+
' var resp = req.send();\n' +
|
|
157
|
+
' if (resp.statusCode !== 200) {\n' +
|
|
158
|
+
' throw new Error("Request failed with status: " + resp.statusCode);\n' +
|
|
159
|
+
' }\n' +
|
|
160
|
+
'} catch (e) {\n' +
|
|
161
|
+
' Write("Error: " + e.message);\n' +
|
|
162
|
+
'}',
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Map of global names for ESLint no-undef configuration.
|
|
168
|
+
* Keys are identifiers; values are "readonly" or "writable".
|
|
169
|
+
*/
|
|
170
|
+
export const SSJS_GLOBALS_MAP = Object.fromEntries([
|
|
171
|
+
...SSJS_GLOBALS.map((g) => [g.name, 'readonly']),
|
|
172
|
+
['HTTP', 'readonly'],
|
|
173
|
+
['WSProxy', 'readonly'],
|
|
174
|
+
['Script', 'readonly'],
|
|
175
|
+
['DataExtension', 'readonly'],
|
|
176
|
+
['Subscriber', 'readonly'],
|
|
177
|
+
['Email', 'readonly'],
|
|
178
|
+
['TriggeredSend', 'readonly'],
|
|
179
|
+
['List', 'readonly'],
|
|
180
|
+
['ContentArea', 'readonly'],
|
|
181
|
+
['Folder', 'readonly'],
|
|
182
|
+
['QueryDefinition', 'readonly'],
|
|
183
|
+
['Send', 'readonly'],
|
|
184
|
+
['Template', 'readonly'],
|
|
185
|
+
['DeliveryProfile', 'readonly'],
|
|
186
|
+
['SenderProfile', 'readonly'],
|
|
187
|
+
['SendClassification', 'readonly'],
|
|
188
|
+
['FilterDefinition', 'readonly'],
|
|
189
|
+
['SendDefinition', 'readonly'],
|
|
190
|
+
['Account', 'readonly'],
|
|
191
|
+
['AccountUser', 'readonly'],
|
|
192
|
+
['Portfolio', 'readonly'],
|
|
193
|
+
['BounceEvent', 'readonly'],
|
|
194
|
+
['ClickEvent', 'readonly'],
|
|
195
|
+
['ForwardedEmailEvent', 'readonly'],
|
|
196
|
+
['ForwardedEmailOptInEvent', 'readonly'],
|
|
197
|
+
['NotSentEvent', 'readonly'],
|
|
198
|
+
['OpenEvent', 'readonly'],
|
|
199
|
+
['SentEvent', 'readonly'],
|
|
200
|
+
['SurveyEvent', 'readonly'],
|
|
201
|
+
['UnsubEvent', 'readonly'],
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
// ── Top-level Platform methods ───────────────────────────────────────────────
|
|
205
|
+
// Direct methods on the Platform object (e.g. Platform.Load).
|
|
206
|
+
|
|
207
|
+
export const PLATFORM_METHODS = [
|
|
208
|
+
{
|
|
209
|
+
name: 'Load',
|
|
210
|
+
minArgs: 2,
|
|
211
|
+
maxArgs: 2,
|
|
212
|
+
description: 'Loads a platform library. Must be called before using Core library objects.',
|
|
213
|
+
params: [
|
|
214
|
+
{ name: 'libraryName', description: 'Library to load (e.g. "core")', type: 'string' },
|
|
215
|
+
{ name: 'version', description: 'Library version (e.g. "1.1.5")', type: 'string' },
|
|
216
|
+
],
|
|
217
|
+
returnType: 'void',
|
|
218
|
+
syntax: 'Platform.Load(libraryName, version)',
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
// ── Platform.Function methods ────────────────────────────────────────────────
|
|
223
|
+
// Methods available under Platform.Function.* without requiring Platform.Load.
|
|
224
|
+
|
|
225
|
+
/** @type {Array<{name:string, minArgs:number, maxArgs:number, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string}>} */
|
|
226
|
+
export const PLATFORM_FUNCTIONS = [
|
|
227
|
+
{
|
|
228
|
+
name: 'Lookup',
|
|
229
|
+
minArgs: 4,
|
|
230
|
+
maxArgs: INF,
|
|
231
|
+
description:
|
|
232
|
+
'Retrieves a single field value from a Data Extension row matching filter criteria.',
|
|
233
|
+
params: [
|
|
234
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
235
|
+
{ name: 'returnField', description: 'Name of the field to return', type: 'string' },
|
|
236
|
+
{ name: 'fieldName', description: 'Filter field name', type: 'string' },
|
|
237
|
+
{ name: 'fieldValue', description: 'Filter field value', type: 'string' },
|
|
238
|
+
],
|
|
239
|
+
returnType: 'string',
|
|
240
|
+
syntax: 'Lookup(deName, returnField, fieldName, fieldValue[, fieldName2, fieldValue2, ...])',
|
|
241
|
+
example: 'var email = Platform.Function.Lookup("Subscribers", "EmailAddress", "SubscriberKey", "abc123");',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: 'LookupRows',
|
|
245
|
+
minArgs: 3,
|
|
246
|
+
maxArgs: INF,
|
|
247
|
+
description: 'Returns a result set of rows from a Data Extension matching filter criteria.',
|
|
248
|
+
params: [
|
|
249
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
250
|
+
{ name: 'fieldName', description: 'Filter field name', type: 'string' },
|
|
251
|
+
{ name: 'fieldValue', description: 'Filter field value', type: 'string' },
|
|
252
|
+
],
|
|
253
|
+
returnType: 'object',
|
|
254
|
+
syntax: 'LookupRows(deName, fieldName, fieldValue[, fieldName2, fieldValue2, ...])',
|
|
255
|
+
example: 'var rows = Platform.Function.LookupRows("MyDE", "Status", "active");\nfor (var i = 0; i < rows.length; i++) {\n Write(rows[i]["Name"] + "<br>");\n}',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: 'LookupOrderedRows',
|
|
259
|
+
minArgs: 4,
|
|
260
|
+
maxArgs: INF,
|
|
261
|
+
description:
|
|
262
|
+
'Returns an ordered result set from a Data Extension with sort and filter parameters.',
|
|
263
|
+
params: [
|
|
264
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
265
|
+
{ name: 'sortCount', description: 'Maximum number of rows to return', type: 'number' },
|
|
266
|
+
{ name: 'sortField', description: 'Field name to sort by', type: 'string' },
|
|
267
|
+
{ name: 'sortOrder', description: 'Sort direction (ASC or DESC)', type: 'string' },
|
|
268
|
+
{ name: 'fieldName', description: 'Filter field name', type: 'string' },
|
|
269
|
+
{ name: 'fieldValue', description: 'Filter field value', type: 'string' },
|
|
270
|
+
],
|
|
271
|
+
returnType: 'object',
|
|
272
|
+
syntax: 'LookupOrderedRows(deName, sortCount, sortField, sortOrder, fieldName, fieldValue[, fieldName2, fieldValue2, ...])',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: 'InsertData',
|
|
276
|
+
minArgs: 4,
|
|
277
|
+
maxArgs: INF,
|
|
278
|
+
description: 'Adds a new row to a Data Extension.',
|
|
279
|
+
params: [
|
|
280
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
281
|
+
{ name: 'fieldName1', description: 'First field name (additional field/value pairs may follow)', type: 'string' },
|
|
282
|
+
{ name: 'value1', description: 'Value for the first field', type: 'string' },
|
|
283
|
+
],
|
|
284
|
+
returnType: 'number',
|
|
285
|
+
syntax: 'InsertData(deName, fieldName1, value1[, fieldName2, value2, ...])',
|
|
286
|
+
example: 'var rowsAffected = Platform.Function.InsertData("MyDE", "Email", "jane@example.com", "Name", "Jane");',
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: 'InsertDE',
|
|
290
|
+
minArgs: 4,
|
|
291
|
+
maxArgs: INF,
|
|
292
|
+
description: 'Adds a new row to a Data Extension (alias for InsertData).',
|
|
293
|
+
params: [
|
|
294
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
295
|
+
{ name: 'fieldName1', description: 'First field name (additional field/value pairs may follow)', type: 'string' },
|
|
296
|
+
{ name: 'value1', description: 'Value for the first field', type: 'string' },
|
|
297
|
+
],
|
|
298
|
+
returnType: 'number',
|
|
299
|
+
syntax: 'InsertDE(deName, fieldName1, value1[, fieldName2, value2, ...])',
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'UpdateData',
|
|
303
|
+
minArgs: 5,
|
|
304
|
+
maxArgs: INF,
|
|
305
|
+
description: 'Modifies existing rows in a Data Extension matching filter criteria.',
|
|
306
|
+
params: [
|
|
307
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
308
|
+
{ name: 'fieldName1', description: 'Field name to update', type: 'string' },
|
|
309
|
+
{ name: 'value1', description: 'New value for the field', type: 'string' },
|
|
310
|
+
{ name: 'filterField', description: 'Filter field name for identifying rows', type: 'string' },
|
|
311
|
+
{ name: 'filterValue', description: 'Filter field value for identifying rows', type: 'string' },
|
|
312
|
+
],
|
|
313
|
+
returnType: 'number',
|
|
314
|
+
syntax: 'UpdateData(deName, fieldName1, value1, filterField, filterValue[, fieldName2, value2, ...])',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'UpdateDE',
|
|
318
|
+
minArgs: 5,
|
|
319
|
+
maxArgs: INF,
|
|
320
|
+
description: 'Modifies existing rows in a Data Extension (alias for UpdateData).',
|
|
321
|
+
params: [
|
|
322
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
323
|
+
{ name: 'fieldName1', description: 'Field name to update', type: 'string' },
|
|
324
|
+
{ name: 'value1', description: 'New value for the field', type: 'string' },
|
|
325
|
+
{ name: 'filterField', description: 'Filter field name for identifying rows', type: 'string' },
|
|
326
|
+
{ name: 'filterValue', description: 'Filter field value for identifying rows', type: 'string' },
|
|
327
|
+
],
|
|
328
|
+
returnType: 'number',
|
|
329
|
+
syntax: 'UpdateDE(deName, fieldName1, value1, filterField, filterValue[, fieldName2, value2, ...])',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: 'UpsertData',
|
|
333
|
+
minArgs: 5,
|
|
334
|
+
maxArgs: INF,
|
|
335
|
+
description: 'Inserts a new row or updates an existing one in a Data Extension.',
|
|
336
|
+
params: [
|
|
337
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
338
|
+
{ name: 'fieldName1', description: 'Field name to set', type: 'string' },
|
|
339
|
+
{ name: 'value1', description: 'Value for the field', type: 'string' },
|
|
340
|
+
{ name: 'filterField', description: 'Filter field name for identifying rows', type: 'string' },
|
|
341
|
+
{ name: 'filterValue', description: 'Filter field value for identifying rows', type: 'string' },
|
|
342
|
+
],
|
|
343
|
+
returnType: 'number',
|
|
344
|
+
syntax: 'UpsertData(deName, fieldName1, value1, filterField, filterValue[, fieldName2, value2, ...])',
|
|
345
|
+
example: 'Platform.Function.UpsertData("MyDE", 1, "Status", "active", "Email", "jane@example.com");',
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: 'UpsertDE',
|
|
349
|
+
minArgs: 5,
|
|
350
|
+
maxArgs: INF,
|
|
351
|
+
description: 'Inserts or updates a Data Extension row (alias for UpsertData).',
|
|
352
|
+
params: [
|
|
353
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
354
|
+
{ name: 'fieldName1', description: 'Field name to set', type: 'string' },
|
|
355
|
+
{ name: 'value1', description: 'Value for the field', type: 'string' },
|
|
356
|
+
{ name: 'filterField', description: 'Filter field name for identifying rows', type: 'string' },
|
|
357
|
+
{ name: 'filterValue', description: 'Filter field value for identifying rows', type: 'string' },
|
|
358
|
+
],
|
|
359
|
+
returnType: 'number',
|
|
360
|
+
syntax: 'UpsertDE(deName, fieldName1, value1, filterField, filterValue[, fieldName2, value2, ...])',
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: 'DeleteData',
|
|
364
|
+
minArgs: 3,
|
|
365
|
+
maxArgs: INF,
|
|
366
|
+
description: 'Removes rows from a Data Extension matching filter criteria.',
|
|
367
|
+
params: [
|
|
368
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
369
|
+
{ name: 'filterField', description: 'Filter field name', type: 'string' },
|
|
370
|
+
{ name: 'filterValue', description: 'Filter field value', type: 'string' },
|
|
371
|
+
],
|
|
372
|
+
returnType: 'number',
|
|
373
|
+
syntax: 'DeleteData(deName, filterField, filterValue[, filterField2, filterValue2, ...])',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: 'DeleteDE',
|
|
377
|
+
minArgs: 3,
|
|
378
|
+
maxArgs: INF,
|
|
379
|
+
description: 'Removes rows from a Data Extension (alias for DeleteData).',
|
|
380
|
+
params: [
|
|
381
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
382
|
+
{ name: 'filterField', description: 'Filter field name', type: 'string' },
|
|
383
|
+
{ name: 'filterValue', description: 'Filter field value', type: 'string' },
|
|
384
|
+
],
|
|
385
|
+
returnType: 'number',
|
|
386
|
+
syntax: 'DeleteDE(deName, filterField, filterValue[, filterField2, filterValue2, ...])',
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: 'ContentBlockByKey',
|
|
390
|
+
minArgs: 1,
|
|
391
|
+
maxArgs: 1,
|
|
392
|
+
description: 'Renders a Content Builder asset referenced by customer key.',
|
|
393
|
+
params: [
|
|
394
|
+
{ name: 'customerKey', description: 'Customer key of the Content Builder asset', type: 'string' },
|
|
395
|
+
],
|
|
396
|
+
returnType: 'string',
|
|
397
|
+
syntax: 'ContentBlockByKey(customerKey)',
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: 'ContentBlockByName',
|
|
401
|
+
minArgs: 1,
|
|
402
|
+
maxArgs: 1,
|
|
403
|
+
description: 'Renders a Content Builder asset referenced by folder path and name.',
|
|
404
|
+
params: [
|
|
405
|
+
{ name: 'name', description: 'Folder path and name of the Content Builder asset', type: 'string' },
|
|
406
|
+
],
|
|
407
|
+
returnType: 'string',
|
|
408
|
+
syntax: 'ContentBlockByName(name)',
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
name: 'ContentBlockByID',
|
|
412
|
+
minArgs: 1,
|
|
413
|
+
maxArgs: 1,
|
|
414
|
+
description: 'Renders a Content Builder asset by its numeric identifier.',
|
|
415
|
+
params: [
|
|
416
|
+
{ name: 'id', description: 'Numeric ID of the Content Builder asset', type: 'number' },
|
|
417
|
+
],
|
|
418
|
+
returnType: 'string',
|
|
419
|
+
syntax: 'ContentBlockByID(id)',
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: 'TreatAsContent',
|
|
423
|
+
minArgs: 1,
|
|
424
|
+
maxArgs: 1,
|
|
425
|
+
description: 'Processes a string as AMPscript/HTML and returns rendered output.',
|
|
426
|
+
params: [
|
|
427
|
+
{ name: 'content', description: 'String containing AMPscript or HTML to evaluate', type: 'string' },
|
|
428
|
+
],
|
|
429
|
+
returnType: 'string',
|
|
430
|
+
syntax: 'TreatAsContent(content)',
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
name: 'Substring',
|
|
434
|
+
minArgs: 2,
|
|
435
|
+
maxArgs: 3,
|
|
436
|
+
description: 'Extracts part of a string starting at a given position.',
|
|
437
|
+
params: [
|
|
438
|
+
{ name: 'value', description: 'Source string', type: 'string' },
|
|
439
|
+
{ name: 'start', description: 'Starting position (1-based)', type: 'number' },
|
|
440
|
+
{ name: 'length', description: 'Number of characters to extract', type: 'number', optional: true },
|
|
441
|
+
],
|
|
442
|
+
returnType: 'string',
|
|
443
|
+
syntax: 'Substring(value, start[, length])',
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
name: 'Trim',
|
|
447
|
+
minArgs: 1,
|
|
448
|
+
maxArgs: 1,
|
|
449
|
+
description: 'Removes leading and trailing whitespace from a string.',
|
|
450
|
+
params: [
|
|
451
|
+
{ name: 'value', description: 'String to trim', type: 'string' },
|
|
452
|
+
],
|
|
453
|
+
returnType: 'string',
|
|
454
|
+
syntax: 'Trim(value)',
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'Replace',
|
|
458
|
+
minArgs: 3,
|
|
459
|
+
maxArgs: 3,
|
|
460
|
+
description: 'Substitutes all occurrences of a substring within a string.',
|
|
461
|
+
params: [
|
|
462
|
+
{ name: 'value', description: 'Source string', type: 'string' },
|
|
463
|
+
{ name: 'search', description: 'Substring to find', type: 'string' },
|
|
464
|
+
{ name: 'replacement', description: 'Replacement string', type: 'string' },
|
|
465
|
+
],
|
|
466
|
+
returnType: 'string',
|
|
467
|
+
syntax: 'Replace(value, search, replacement)',
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: 'IndexOf',
|
|
471
|
+
minArgs: 2,
|
|
472
|
+
maxArgs: 2,
|
|
473
|
+
description: 'Returns the zero-based position of the first occurrence of a substring.',
|
|
474
|
+
params: [
|
|
475
|
+
{ name: 'value', description: 'String to search in', type: 'string' },
|
|
476
|
+
{ name: 'search', description: 'Substring to find', type: 'string' },
|
|
477
|
+
],
|
|
478
|
+
returnType: 'number',
|
|
479
|
+
syntax: 'IndexOf(value, search)',
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'Length',
|
|
483
|
+
minArgs: 1,
|
|
484
|
+
maxArgs: 1,
|
|
485
|
+
description: 'Returns the number of characters in a string.',
|
|
486
|
+
params: [
|
|
487
|
+
{ name: 'value', description: 'String to measure', type: 'string' },
|
|
488
|
+
],
|
|
489
|
+
returnType: 'number',
|
|
490
|
+
syntax: 'Length(value)',
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
name: 'Uppercase',
|
|
494
|
+
minArgs: 1,
|
|
495
|
+
maxArgs: 1,
|
|
496
|
+
description: 'Converts a string to uppercase.',
|
|
497
|
+
params: [
|
|
498
|
+
{ name: 'value', description: 'String to convert', type: 'string' },
|
|
499
|
+
],
|
|
500
|
+
returnType: 'string',
|
|
501
|
+
syntax: 'Uppercase(value)',
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: 'Lowercase',
|
|
505
|
+
minArgs: 1,
|
|
506
|
+
maxArgs: 1,
|
|
507
|
+
description: 'Converts a string to lowercase.',
|
|
508
|
+
params: [
|
|
509
|
+
{ name: 'value', description: 'String to convert', type: 'string' },
|
|
510
|
+
],
|
|
511
|
+
returnType: 'string',
|
|
512
|
+
syntax: 'Lowercase(value)',
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: 'ProperCase',
|
|
516
|
+
minArgs: 1,
|
|
517
|
+
maxArgs: 1,
|
|
518
|
+
description: 'Converts a string to title case.',
|
|
519
|
+
params: [
|
|
520
|
+
{ name: 'value', description: 'String to convert', type: 'string' },
|
|
521
|
+
],
|
|
522
|
+
returnType: 'string',
|
|
523
|
+
syntax: 'ProperCase(value)',
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: 'Char',
|
|
527
|
+
minArgs: 1,
|
|
528
|
+
maxArgs: 1,
|
|
529
|
+
description: 'Returns the character for a given ASCII code.',
|
|
530
|
+
params: [
|
|
531
|
+
{ name: 'asciiCode', description: 'ASCII character code', type: 'number' },
|
|
532
|
+
],
|
|
533
|
+
returnType: 'string',
|
|
534
|
+
syntax: 'Char(asciiCode)',
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
name: 'Concat',
|
|
538
|
+
minArgs: 2,
|
|
539
|
+
maxArgs: INF,
|
|
540
|
+
description: 'Joins two or more string values together.',
|
|
541
|
+
params: [
|
|
542
|
+
{ name: 'value1', description: 'First string', type: 'string' },
|
|
543
|
+
{ name: 'value2', description: 'Second string (additional strings may follow)', type: 'string' },
|
|
544
|
+
],
|
|
545
|
+
returnType: 'string',
|
|
546
|
+
syntax: 'Concat(value1, value2[, ...])',
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
name: 'Format',
|
|
550
|
+
minArgs: 2,
|
|
551
|
+
maxArgs: INF,
|
|
552
|
+
description: 'Formats a value according to a .NET format string.',
|
|
553
|
+
params: [
|
|
554
|
+
{ name: 'value', description: 'Value to format', type: 'string' },
|
|
555
|
+
{ name: 'format', description: '.NET format string', type: 'string' },
|
|
556
|
+
],
|
|
557
|
+
returnType: 'string',
|
|
558
|
+
syntax: 'Format(value, format[, ...])',
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
name: 'DateAdd',
|
|
562
|
+
minArgs: 3,
|
|
563
|
+
maxArgs: 3,
|
|
564
|
+
description: 'Adds a specified interval to a date value.',
|
|
565
|
+
params: [
|
|
566
|
+
{ name: 'date', description: 'Date value to modify', type: 'string' },
|
|
567
|
+
{ name: 'interval', description: 'Number of intervals to add', type: 'number' },
|
|
568
|
+
{ name: 'datePart', description: 'Date part to add (e.g. "Y", "M", "D", "H")', type: 'string' },
|
|
569
|
+
],
|
|
570
|
+
returnType: 'string',
|
|
571
|
+
syntax: 'DateAdd(date, interval, datePart)',
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: 'DateDiff',
|
|
575
|
+
minArgs: 3,
|
|
576
|
+
maxArgs: 3,
|
|
577
|
+
description: 'Calculates the difference between two dates in a given interval.',
|
|
578
|
+
params: [
|
|
579
|
+
{ name: 'date1', description: 'First date value', type: 'string' },
|
|
580
|
+
{ name: 'date2', description: 'Second date value', type: 'string' },
|
|
581
|
+
{ name: 'datePart', description: 'Date part for the interval (e.g. "Y", "M", "D", "H")', type: 'string' },
|
|
582
|
+
],
|
|
583
|
+
returnType: 'number',
|
|
584
|
+
syntax: 'DateDiff(date1, date2, datePart)',
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
name: 'DateParse',
|
|
588
|
+
minArgs: 1,
|
|
589
|
+
maxArgs: 2,
|
|
590
|
+
description: 'Converts a string representation to a date object.',
|
|
591
|
+
params: [
|
|
592
|
+
{ name: 'dateString', description: 'String to parse as a date', type: 'string' },
|
|
593
|
+
{ name: 'format', description: 'Date format pattern', type: 'string', optional: true },
|
|
594
|
+
],
|
|
595
|
+
returnType: 'object',
|
|
596
|
+
syntax: 'DateParse(dateString[, format])',
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
name: 'Now',
|
|
600
|
+
minArgs: 0,
|
|
601
|
+
maxArgs: 0,
|
|
602
|
+
description: 'Returns the current date and time of the SFMC server.',
|
|
603
|
+
params: [],
|
|
604
|
+
returnType: 'string',
|
|
605
|
+
syntax: 'Now()',
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
name: 'FormatDate',
|
|
609
|
+
minArgs: 2,
|
|
610
|
+
maxArgs: 3,
|
|
611
|
+
description: 'Formats a date value into a string with the specified pattern.',
|
|
612
|
+
params: [
|
|
613
|
+
{ name: 'date', description: 'Date value to format', type: 'string' },
|
|
614
|
+
{ name: 'format', description: 'Date format pattern', type: 'string' },
|
|
615
|
+
{ name: 'locale', description: 'Locale for date formatting', type: 'string', optional: true },
|
|
616
|
+
],
|
|
617
|
+
returnType: 'string',
|
|
618
|
+
syntax: 'FormatDate(date, format[, locale])',
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
name: 'SystemDateToLocalDate',
|
|
622
|
+
minArgs: 1,
|
|
623
|
+
maxArgs: 1,
|
|
624
|
+
description: "Converts a system date to the subscriber's local timezone.",
|
|
625
|
+
params: [
|
|
626
|
+
{ name: 'date', description: 'System date to convert', type: 'string' },
|
|
627
|
+
],
|
|
628
|
+
returnType: 'string',
|
|
629
|
+
syntax: 'SystemDateToLocalDate(date)',
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
name: 'GetValue',
|
|
633
|
+
minArgs: 1,
|
|
634
|
+
maxArgs: 1,
|
|
635
|
+
description: 'Retrieves the value of an AMPscript variable.',
|
|
636
|
+
params: [
|
|
637
|
+
{ name: 'variableName', description: 'Name of the AMPscript variable', type: 'string' },
|
|
638
|
+
],
|
|
639
|
+
returnType: 'string',
|
|
640
|
+
syntax: 'GetValue(variableName)',
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
name: 'SetValue',
|
|
644
|
+
minArgs: 2,
|
|
645
|
+
maxArgs: 2,
|
|
646
|
+
description: 'Assigns a value to an AMPscript variable.',
|
|
647
|
+
params: [
|
|
648
|
+
{ name: 'variableName', description: 'Name of the AMPscript variable', type: 'string' },
|
|
649
|
+
{ name: 'value', description: 'Value to assign', type: 'string' },
|
|
650
|
+
],
|
|
651
|
+
returnType: 'void',
|
|
652
|
+
syntax: 'SetValue(variableName, value)',
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
name: 'RaiseError',
|
|
656
|
+
minArgs: 1,
|
|
657
|
+
maxArgs: 2,
|
|
658
|
+
description: 'Stops execution and raises an error with an optional skip-send flag.',
|
|
659
|
+
params: [
|
|
660
|
+
{ name: 'message', description: 'Error message to display', type: 'string' },
|
|
661
|
+
{ name: 'skipSend', description: 'If true, suppresses the send operation', type: 'boolean', optional: true },
|
|
662
|
+
],
|
|
663
|
+
returnType: 'void',
|
|
664
|
+
syntax: 'RaiseError(message[, skipSend])',
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
name: 'Redirect',
|
|
668
|
+
minArgs: 1,
|
|
669
|
+
maxArgs: 2,
|
|
670
|
+
description: 'Redirects the browser to a specified URL.',
|
|
671
|
+
params: [
|
|
672
|
+
{ name: 'url', description: 'URL to redirect to', type: 'string' },
|
|
673
|
+
{ name: 'permanent', description: 'True for 301 permanent redirect', type: 'boolean', optional: true },
|
|
674
|
+
],
|
|
675
|
+
returnType: 'void',
|
|
676
|
+
syntax: 'Redirect(url[, permanent])',
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
name: 'CloudPagesURL',
|
|
680
|
+
minArgs: 1,
|
|
681
|
+
maxArgs: INF,
|
|
682
|
+
description:
|
|
683
|
+
'Builds an encrypted URL for a CloudPages landing page with optional parameters.',
|
|
684
|
+
params: [
|
|
685
|
+
{ name: 'pageId', description: 'Page ID of the CloudPages landing page', type: 'number' },
|
|
686
|
+
{ name: 'param1', description: 'First parameter name', type: 'string', optional: true },
|
|
687
|
+
{ name: 'value1', description: 'First parameter value', type: 'string', optional: true },
|
|
688
|
+
],
|
|
689
|
+
returnType: 'string',
|
|
690
|
+
syntax: 'CloudPagesURL(pageId[, param1, value1, ...])',
|
|
691
|
+
example: 'var url = Platform.Function.CloudPagesURL(123, "email", emailAddress, "sk", subscriberKey);\nWrite(\'<a href="\' + url + \'">Click here</a>\');',
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
name: 'MicrositeURL',
|
|
695
|
+
minArgs: 1,
|
|
696
|
+
maxArgs: INF,
|
|
697
|
+
description: 'Generates a tracking URL for a microsite page.',
|
|
698
|
+
params: [
|
|
699
|
+
{ name: 'pageId', description: 'Page ID of the microsite page', type: 'number' },
|
|
700
|
+
{ name: 'param1', description: 'First parameter name', type: 'string', optional: true },
|
|
701
|
+
{ name: 'value1', description: 'First parameter value', type: 'string', optional: true },
|
|
702
|
+
],
|
|
703
|
+
returnType: 'string',
|
|
704
|
+
syntax: 'MicrositeURL(pageId[, param1, value1, ...])',
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
name: 'GUID',
|
|
708
|
+
minArgs: 0,
|
|
709
|
+
maxArgs: 0,
|
|
710
|
+
description: 'Generates a new globally unique identifier string.',
|
|
711
|
+
params: [],
|
|
712
|
+
returnType: 'string',
|
|
713
|
+
syntax: 'GUID()',
|
|
714
|
+
example: 'var id = Platform.Function.GUID();\nWrite(id); // e.g. "550e8400-e29b-41d4-a716-446655440000"',
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
name: 'Base64Encode',
|
|
718
|
+
minArgs: 1,
|
|
719
|
+
maxArgs: 2,
|
|
720
|
+
description: 'Encodes a string value to Base64.',
|
|
721
|
+
params: [
|
|
722
|
+
{ name: 'value', description: 'String to encode', type: 'string' },
|
|
723
|
+
{ name: 'encoding', description: 'Character encoding to use', type: 'string', optional: true },
|
|
724
|
+
],
|
|
725
|
+
returnType: 'string',
|
|
726
|
+
syntax: 'Base64Encode(value[, encoding])',
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: 'Base64Decode',
|
|
730
|
+
minArgs: 1,
|
|
731
|
+
maxArgs: 2,
|
|
732
|
+
description: 'Decodes a Base64-encoded string back to plain text.',
|
|
733
|
+
params: [
|
|
734
|
+
{ name: 'value', description: 'Base64-encoded string to decode', type: 'string' },
|
|
735
|
+
{ name: 'encoding', description: 'Character encoding to use', type: 'string', optional: true },
|
|
736
|
+
],
|
|
737
|
+
returnType: 'string',
|
|
738
|
+
syntax: 'Base64Decode(value[, encoding])',
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
name: 'EncryptSymmetric',
|
|
742
|
+
minArgs: 6,
|
|
743
|
+
maxArgs: 8,
|
|
744
|
+
description: 'Encrypts a string using symmetric encryption with a specified algorithm.',
|
|
745
|
+
params: [
|
|
746
|
+
{ name: 'value', description: 'String to encrypt', type: 'string' },
|
|
747
|
+
{ name: 'algorithm', description: 'Encryption algorithm (e.g. "AES")', type: 'string' },
|
|
748
|
+
{ name: 'passwordKey', description: 'Key Management key name for the password', type: 'string' },
|
|
749
|
+
{ name: 'password', description: 'Encryption password', type: 'string' },
|
|
750
|
+
{ name: 'saltKey', description: 'Key Management key name for the salt', type: 'string' },
|
|
751
|
+
{ name: 'salt', description: 'Salt value', type: 'string' },
|
|
752
|
+
{ name: 'ivKey', description: 'Key Management key name for the initialization vector', type: 'string', optional: true },
|
|
753
|
+
{ name: 'iv', description: 'Initialization vector value', type: 'string', optional: true },
|
|
754
|
+
],
|
|
755
|
+
returnType: 'string',
|
|
756
|
+
syntax: 'EncryptSymmetric(value, algorithm, passwordKey, password, saltKey, salt[, ivKey, iv])',
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
name: 'DecryptSymmetric',
|
|
760
|
+
minArgs: 6,
|
|
761
|
+
maxArgs: 8,
|
|
762
|
+
description: 'Decrypts a symmetrically encrypted string.',
|
|
763
|
+
params: [
|
|
764
|
+
{ name: 'value', description: 'Encrypted string to decrypt', type: 'string' },
|
|
765
|
+
{ name: 'algorithm', description: 'Encryption algorithm (e.g. "AES")', type: 'string' },
|
|
766
|
+
{ name: 'passwordKey', description: 'Key Management key name for the password', type: 'string' },
|
|
767
|
+
{ name: 'password', description: 'Encryption password', type: 'string' },
|
|
768
|
+
{ name: 'saltKey', description: 'Key Management key name for the salt', type: 'string' },
|
|
769
|
+
{ name: 'salt', description: 'Salt value', type: 'string' },
|
|
770
|
+
{ name: 'ivKey', description: 'Key Management key name for the initialization vector', type: 'string', optional: true },
|
|
771
|
+
{ name: 'iv', description: 'Initialization vector value', type: 'string', optional: true },
|
|
772
|
+
],
|
|
773
|
+
returnType: 'string',
|
|
774
|
+
syntax: 'DecryptSymmetric(value, algorithm, passwordKey, password, saltKey, salt[, ivKey, iv])',
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
name: 'SHA256',
|
|
778
|
+
minArgs: 1,
|
|
779
|
+
maxArgs: 2,
|
|
780
|
+
description: 'Computes the SHA-256 hash of a string value.',
|
|
781
|
+
params: [
|
|
782
|
+
{ name: 'value', description: 'String to hash', type: 'string' },
|
|
783
|
+
{ name: 'encoding', description: 'Output encoding', type: 'string', optional: true },
|
|
784
|
+
],
|
|
785
|
+
returnType: 'string',
|
|
786
|
+
syntax: 'SHA256(value[, encoding])',
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
name: 'SHA512',
|
|
790
|
+
minArgs: 1,
|
|
791
|
+
maxArgs: 2,
|
|
792
|
+
description: 'Computes the SHA-512 hash of a string value.',
|
|
793
|
+
params: [
|
|
794
|
+
{ name: 'value', description: 'String to hash', type: 'string' },
|
|
795
|
+
{ name: 'encoding', description: 'Output encoding', type: 'string', optional: true },
|
|
796
|
+
],
|
|
797
|
+
returnType: 'string',
|
|
798
|
+
syntax: 'SHA512(value[, encoding])',
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: 'MD5',
|
|
802
|
+
minArgs: 1,
|
|
803
|
+
maxArgs: 2,
|
|
804
|
+
description: 'Computes the MD5 hash of a string value.',
|
|
805
|
+
params: [
|
|
806
|
+
{ name: 'value', description: 'String to hash', type: 'string' },
|
|
807
|
+
{ name: 'encoding', description: 'Output encoding', type: 'string', optional: true },
|
|
808
|
+
],
|
|
809
|
+
returnType: 'string',
|
|
810
|
+
syntax: 'MD5(value[, encoding])',
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
name: 'IsEmailAddress',
|
|
814
|
+
minArgs: 1,
|
|
815
|
+
maxArgs: 1,
|
|
816
|
+
description: 'Checks whether a string is a valid email address format.',
|
|
817
|
+
params: [
|
|
818
|
+
{ name: 'value', description: 'String to validate', type: 'string' },
|
|
819
|
+
],
|
|
820
|
+
returnType: 'boolean',
|
|
821
|
+
syntax: 'IsEmailAddress(value)',
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
name: 'IsNull',
|
|
825
|
+
minArgs: 1,
|
|
826
|
+
maxArgs: 1,
|
|
827
|
+
description: 'Checks whether a value is null.',
|
|
828
|
+
params: [
|
|
829
|
+
{ name: 'value', description: 'Value to check', type: 'any' },
|
|
830
|
+
],
|
|
831
|
+
returnType: 'boolean',
|
|
832
|
+
syntax: 'IsNull(value)',
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
name: 'Empty',
|
|
836
|
+
minArgs: 1,
|
|
837
|
+
maxArgs: 1,
|
|
838
|
+
description: 'Checks whether a string value is null, empty, or whitespace.',
|
|
839
|
+
params: [
|
|
840
|
+
{ name: 'value', description: 'String to check', type: 'string' },
|
|
841
|
+
],
|
|
842
|
+
returnType: 'boolean',
|
|
843
|
+
syntax: 'Empty(value)',
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
name: 'IIf',
|
|
847
|
+
minArgs: 3,
|
|
848
|
+
maxArgs: 3,
|
|
849
|
+
description: 'Returns one of two values based on a boolean condition.',
|
|
850
|
+
params: [
|
|
851
|
+
{ name: 'condition', description: 'Boolean expression to evaluate', type: 'boolean' },
|
|
852
|
+
{ name: 'trueValue', description: 'Value returned if condition is true', type: 'any' },
|
|
853
|
+
{ name: 'falseValue', description: 'Value returned if condition is false', type: 'any' },
|
|
854
|
+
],
|
|
855
|
+
returnType: 'any',
|
|
856
|
+
syntax: 'IIf(condition, trueValue, falseValue)',
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
name: 'DataExtensionRowCount',
|
|
860
|
+
minArgs: 1,
|
|
861
|
+
maxArgs: 1,
|
|
862
|
+
description: 'Returns the total number of rows in a Data Extension.',
|
|
863
|
+
params: [
|
|
864
|
+
{ name: 'deName', description: 'Data Extension name or external key', type: 'string' },
|
|
865
|
+
],
|
|
866
|
+
returnType: 'number',
|
|
867
|
+
syntax: 'DataExtensionRowCount(deName)',
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
name: 'CreateObject',
|
|
871
|
+
minArgs: 1,
|
|
872
|
+
maxArgs: 1,
|
|
873
|
+
description: 'Instantiates a Marketing Cloud SOAP API object.',
|
|
874
|
+
params: [
|
|
875
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
876
|
+
],
|
|
877
|
+
returnType: 'object',
|
|
878
|
+
syntax: 'CreateObject(objectType)',
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
name: 'SetObjectProperty',
|
|
882
|
+
minArgs: 3,
|
|
883
|
+
maxArgs: 3,
|
|
884
|
+
description: 'Assigns a property value on a SOAP API object.',
|
|
885
|
+
params: [
|
|
886
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
887
|
+
{ name: 'propertyName', description: 'Property name to set', type: 'string' },
|
|
888
|
+
{ name: 'value', description: 'Value to assign', type: 'any' },
|
|
889
|
+
],
|
|
890
|
+
returnType: 'void',
|
|
891
|
+
syntax: 'SetObjectProperty(apiObject, propertyName, value)',
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
name: 'AddObjectArrayItem',
|
|
895
|
+
minArgs: 3,
|
|
896
|
+
maxArgs: 3,
|
|
897
|
+
description: "Appends an item to a SOAP API object's array property.",
|
|
898
|
+
params: [
|
|
899
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
900
|
+
{ name: 'propertyName', description: 'Array property name', type: 'string' },
|
|
901
|
+
{ name: 'value', description: 'Item to append', type: 'any' },
|
|
902
|
+
],
|
|
903
|
+
returnType: 'void',
|
|
904
|
+
syntax: 'AddObjectArrayItem(apiObject, propertyName, value)',
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
name: 'InvokeCreate',
|
|
908
|
+
minArgs: 1,
|
|
909
|
+
maxArgs: 4,
|
|
910
|
+
description: 'Executes a SOAP API Create call on an API object.',
|
|
911
|
+
params: [
|
|
912
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
913
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
914
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
915
|
+
{ name: 'requestId', description: 'Variable to receive the request ID', type: 'string', optional: true },
|
|
916
|
+
],
|
|
917
|
+
returnType: 'string',
|
|
918
|
+
syntax: 'InvokeCreate(apiObject[, statusMessage, errorCode, requestId])',
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
name: 'InvokeUpdate',
|
|
922
|
+
minArgs: 1,
|
|
923
|
+
maxArgs: 4,
|
|
924
|
+
description: 'Executes a SOAP API Update call on an API object.',
|
|
925
|
+
params: [
|
|
926
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
927
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
928
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
929
|
+
{ name: 'requestId', description: 'Variable to receive the request ID', type: 'string', optional: true },
|
|
930
|
+
],
|
|
931
|
+
returnType: 'string',
|
|
932
|
+
syntax: 'InvokeUpdate(apiObject[, statusMessage, errorCode, requestId])',
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
name: 'InvokeDelete',
|
|
936
|
+
minArgs: 1,
|
|
937
|
+
maxArgs: 4,
|
|
938
|
+
description: 'Executes a SOAP API Delete call on an API object.',
|
|
939
|
+
params: [
|
|
940
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
941
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
942
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
943
|
+
{ name: 'requestId', description: 'Variable to receive the request ID', type: 'string', optional: true },
|
|
944
|
+
],
|
|
945
|
+
returnType: 'string',
|
|
946
|
+
syntax: 'InvokeDelete(apiObject[, statusMessage, errorCode, requestId])',
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
name: 'InvokeRetrieve',
|
|
950
|
+
minArgs: 3,
|
|
951
|
+
maxArgs: 5,
|
|
952
|
+
description: 'Executes a SOAP API Retrieve call.',
|
|
953
|
+
params: [
|
|
954
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
955
|
+
{ name: 'properties', description: 'Array of property names to retrieve', type: 'array' },
|
|
956
|
+
{ name: 'filter', description: 'Filter object for the retrieve', type: 'object', optional: true },
|
|
957
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
958
|
+
{ name: 'requestId', description: 'Variable to receive the request ID', type: 'string', optional: true },
|
|
959
|
+
],
|
|
960
|
+
returnType: 'object',
|
|
961
|
+
syntax: 'InvokeRetrieve(apiObject, properties[, filter, statusMessage, requestId])',
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
name: 'InvokePerform',
|
|
965
|
+
minArgs: 2,
|
|
966
|
+
maxArgs: 4,
|
|
967
|
+
description: 'Executes a SOAP API Perform action on an API object.',
|
|
968
|
+
params: [
|
|
969
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
970
|
+
{ name: 'action', description: 'Action to perform', type: 'string' },
|
|
971
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
972
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
973
|
+
],
|
|
974
|
+
returnType: 'string',
|
|
975
|
+
syntax: 'InvokePerform(apiObject, action[, statusMessage, errorCode])',
|
|
976
|
+
},
|
|
977
|
+
{
|
|
978
|
+
name: 'InvokeConfigure',
|
|
979
|
+
minArgs: 2,
|
|
980
|
+
maxArgs: 4,
|
|
981
|
+
description: 'Executes a SOAP API Configure call on an API object.',
|
|
982
|
+
params: [
|
|
983
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
984
|
+
{ name: 'action', description: 'Configure action', type: 'string' },
|
|
985
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
986
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
987
|
+
],
|
|
988
|
+
returnType: 'string',
|
|
989
|
+
syntax: 'InvokeConfigure(apiObject, action[, statusMessage, errorCode])',
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
name: 'InvokeExecute',
|
|
993
|
+
minArgs: 2,
|
|
994
|
+
maxArgs: 4,
|
|
995
|
+
description: 'Executes a SOAP API Execute call on an API object.',
|
|
996
|
+
params: [
|
|
997
|
+
{ name: 'apiObject', description: 'SOAP API object instance', type: 'object' },
|
|
998
|
+
{ name: 'method', description: 'Execute method name', type: 'string' },
|
|
999
|
+
{ name: 'statusMessage', description: 'Variable to receive the status message', type: 'string', optional: true },
|
|
1000
|
+
{ name: 'errorCode', description: 'Variable to receive the error code', type: 'string', optional: true },
|
|
1001
|
+
],
|
|
1002
|
+
returnType: 'string',
|
|
1003
|
+
syntax: 'InvokeExecute(apiObject, method[, statusMessage, errorCode])',
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
name: 'AttributeValue',
|
|
1007
|
+
minArgs: 1,
|
|
1008
|
+
maxArgs: 1,
|
|
1009
|
+
description: 'Safely retrieves a subscriber attribute value, returning null if not found.',
|
|
1010
|
+
params: [
|
|
1011
|
+
{ name: 'attributeName', description: 'Name of the subscriber attribute', type: 'string' },
|
|
1012
|
+
],
|
|
1013
|
+
returnType: 'string',
|
|
1014
|
+
syntax: 'AttributeValue(attributeName)',
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
name: 'HTTPGet',
|
|
1018
|
+
minArgs: 1,
|
|
1019
|
+
maxArgs: 3,
|
|
1020
|
+
description: 'Performs an HTTP GET request and returns the response body.',
|
|
1021
|
+
params: [
|
|
1022
|
+
{ name: 'url', description: 'URL to request', type: 'string' },
|
|
1023
|
+
{ name: 'headerNames', description: 'Array of header names', type: 'array', optional: true },
|
|
1024
|
+
{ name: 'headerValues', description: 'Array of header values', type: 'array', optional: true },
|
|
1025
|
+
],
|
|
1026
|
+
returnType: 'string',
|
|
1027
|
+
syntax: 'HTTPGet(url[, headerNames, headerValues])',
|
|
1028
|
+
example:
|
|
1029
|
+
'var headerNames = ["Authorization"];\n' +
|
|
1030
|
+
'var headerValues = ["Bearer " + accessToken];\n' +
|
|
1031
|
+
'var responseBody = Platform.Function.HTTPGet("https://api.example.com/data", headerNames, headerValues);\n' +
|
|
1032
|
+
'var obj = Platform.Function.ParseJSON(responseBody);',
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
name: 'HTTPPost',
|
|
1036
|
+
minArgs: 3,
|
|
1037
|
+
maxArgs: 5,
|
|
1038
|
+
description: 'Performs an HTTP POST request with a content type and payload.',
|
|
1039
|
+
params: [
|
|
1040
|
+
{ name: 'url', description: 'URL to post to', type: 'string' },
|
|
1041
|
+
{ name: 'contentType', description: 'MIME type of the request body', type: 'string' },
|
|
1042
|
+
{ name: 'payload', description: 'Request body content', type: 'string' },
|
|
1043
|
+
{ name: 'headerNames', description: 'Array of header names', type: 'array', optional: true },
|
|
1044
|
+
{ name: 'headerValues', description: 'Array of header values', type: 'array', optional: true },
|
|
1045
|
+
],
|
|
1046
|
+
returnType: 'string',
|
|
1047
|
+
syntax: 'HTTPPost(url, contentType, payload[, headerNames, headerValues])',
|
|
1048
|
+
example:
|
|
1049
|
+
'var payload = Stringify({ name: "Jane", status: "active" });\n' +
|
|
1050
|
+
'var headerNames = ["Authorization"];\n' +
|
|
1051
|
+
'var headerValues = ["Bearer " + accessToken];\n' +
|
|
1052
|
+
'var response = Platform.Function.HTTPPost(\n' +
|
|
1053
|
+
' "https://api.example.com/items",\n' +
|
|
1054
|
+
' "application/json",\n' +
|
|
1055
|
+
' payload,\n' +
|
|
1056
|
+
' headerNames,\n' +
|
|
1057
|
+
' headerValues\n' +
|
|
1058
|
+
');',
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
name: 'HTTPRequestHeader',
|
|
1062
|
+
minArgs: 1,
|
|
1063
|
+
maxArgs: 1,
|
|
1064
|
+
description: 'Retrieves the value of an HTTP request header.',
|
|
1065
|
+
params: [
|
|
1066
|
+
{ name: 'headerName', description: 'Name of the HTTP request header', type: 'string' },
|
|
1067
|
+
],
|
|
1068
|
+
returnType: 'string',
|
|
1069
|
+
syntax: 'HTTPRequestHeader(headerName)',
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
name: 'ParseJSON',
|
|
1073
|
+
minArgs: 1,
|
|
1074
|
+
maxArgs: 1,
|
|
1075
|
+
description:
|
|
1076
|
+
'Parses a JSON-formatted string and returns the resulting JavaScript object. ' +
|
|
1077
|
+
'SFMC-native equivalent of JSON.parse(), which is not available in the legacy SSJS engine.',
|
|
1078
|
+
params: [
|
|
1079
|
+
{ name: 'jsonString', description: 'A valid JSON-formatted string to parse', type: 'string' },
|
|
1080
|
+
],
|
|
1081
|
+
returnType: 'object',
|
|
1082
|
+
syntax: 'ParseJSON(jsonString)',
|
|
1083
|
+
example:
|
|
1084
|
+
'var jsonString = \'{"name":"Jane","age":30}\';\n' +
|
|
1085
|
+
'var obj = Platform.Function.ParseJSON(jsonString);\n' +
|
|
1086
|
+
'Write(obj.name); // outputs: Jane\n\n' +
|
|
1087
|
+
'// Use String() to convert CLR response content before parsing:\n' +
|
|
1088
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
1089
|
+
'req.method = "GET";\n' +
|
|
1090
|
+
'var resp = req.send();\n' +
|
|
1091
|
+
'var result = Platform.Function.ParseJSON(String(resp.content));',
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
name: 'URLEncode',
|
|
1095
|
+
minArgs: 1,
|
|
1096
|
+
maxArgs: 1,
|
|
1097
|
+
description: 'Encodes a string value so that it can be safely used as a URL query parameter or path component.',
|
|
1098
|
+
params: [
|
|
1099
|
+
{ name: 'value', description: 'The string value to URL-encode', type: 'string' },
|
|
1100
|
+
],
|
|
1101
|
+
returnType: 'string',
|
|
1102
|
+
syntax: 'URLEncode(value)',
|
|
1103
|
+
},
|
|
1104
|
+
];
|
|
1105
|
+
|
|
1106
|
+
export const platformFunctionLookup = new Map(
|
|
1107
|
+
PLATFORM_FUNCTIONS.map((f) => [f.name.toLowerCase(), f]),
|
|
1108
|
+
);
|
|
1109
|
+
|
|
1110
|
+
export const platformFunctionNames = new Set(PLATFORM_FUNCTIONS.map((f) => f.name.toLowerCase()));
|
|
1111
|
+
|
|
1112
|
+
// ── Core library objects ─────────────────────────────────────────────────────
|
|
1113
|
+
// Objects that require Platform.Load("core", "1") before use.
|
|
1114
|
+
// Each has standard CRUD methods plus object-specific extras.
|
|
1115
|
+
|
|
1116
|
+
const STANDARD_METHODS = ['Init', 'Add', 'Remove', 'Update', 'Retrieve'];
|
|
1117
|
+
|
|
1118
|
+
/** @type {Array<{name:string, methods:string[], description:string}>} */
|
|
1119
|
+
export const CORE_LIBRARY_OBJECTS = [
|
|
1120
|
+
{
|
|
1121
|
+
name: 'DataExtension',
|
|
1122
|
+
methods: [...STANDARD_METHODS, 'Fields', 'Rows'],
|
|
1123
|
+
description: 'Manages Data Extension definitions and their field schemas.',
|
|
1124
|
+
},
|
|
1125
|
+
{
|
|
1126
|
+
name: 'DataExtension.Fields',
|
|
1127
|
+
methods: ['Init', 'Retrieve'],
|
|
1128
|
+
description: 'Accesses field definitions within a Data Extension.',
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
name: 'DataExtension.Rows',
|
|
1132
|
+
methods: ['Init', 'Add', 'Remove', 'Update', 'Retrieve', 'Lookup'],
|
|
1133
|
+
description:
|
|
1134
|
+
'Manages individual rows within a Data Extension. ' +
|
|
1135
|
+
'CAVEAT: Rows.Retrieve() does NOT work on CloudPages. ' +
|
|
1136
|
+
'The filter parameter is required despite the documentation saying it is optional.',
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
name: 'Subscriber',
|
|
1140
|
+
methods: [...STANDARD_METHODS, 'Unsubscribe', 'Upsert', 'Statistics'],
|
|
1141
|
+
description: 'Manages subscriber records in the account.',
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
name: 'Email',
|
|
1145
|
+
methods: STANDARD_METHODS,
|
|
1146
|
+
description: 'Manages email message definitions.',
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
name: 'TriggeredSend',
|
|
1150
|
+
methods: [...STANDARD_METHODS, 'Send', 'Pause', 'Publish', 'Start'],
|
|
1151
|
+
description: 'Manages triggered send definitions and fires individual sends.',
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
name: 'List',
|
|
1155
|
+
methods: [...STANDARD_METHODS, 'Subscribers'],
|
|
1156
|
+
description: 'Manages subscriber lists.',
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
name: 'List.Subscribers',
|
|
1160
|
+
methods: ['Init', 'Add', 'Remove', 'Retrieve'],
|
|
1161
|
+
description: 'Manages the subscribers belonging to a specific list.',
|
|
1162
|
+
},
|
|
1163
|
+
{
|
|
1164
|
+
name: 'ContentArea',
|
|
1165
|
+
methods: STANDARD_METHODS,
|
|
1166
|
+
description: 'Manages classic content area objects.',
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
name: 'Folder',
|
|
1170
|
+
methods: STANDARD_METHODS,
|
|
1171
|
+
description: 'Manages folder structures within the Marketing Cloud account.',
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
name: 'QueryDefinition',
|
|
1175
|
+
methods: [...STANDARD_METHODS, 'Perform'],
|
|
1176
|
+
description: 'Manages SQL query activity definitions.',
|
|
1177
|
+
},
|
|
1178
|
+
{
|
|
1179
|
+
name: 'Send',
|
|
1180
|
+
methods: STANDARD_METHODS,
|
|
1181
|
+
description: 'Manages email send definitions.',
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
name: 'SendDefinition',
|
|
1185
|
+
methods: [...STANDARD_METHODS, 'Send'],
|
|
1186
|
+
description: 'Manages reusable Send Definition configurations that define all parameters for a send including content, audience, and delivery settings.',
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
name: 'Template',
|
|
1190
|
+
methods: STANDARD_METHODS,
|
|
1191
|
+
description: 'Manages email template definitions.',
|
|
1192
|
+
},
|
|
1193
|
+
{
|
|
1194
|
+
name: 'DeliveryProfile',
|
|
1195
|
+
methods: STANDARD_METHODS,
|
|
1196
|
+
description: 'Manages delivery profile configurations.',
|
|
1197
|
+
},
|
|
1198
|
+
{
|
|
1199
|
+
name: 'SenderProfile',
|
|
1200
|
+
methods: STANDARD_METHODS,
|
|
1201
|
+
description: 'Manages sender profile definitions.',
|
|
1202
|
+
},
|
|
1203
|
+
{
|
|
1204
|
+
name: 'SendClassification',
|
|
1205
|
+
methods: STANDARD_METHODS,
|
|
1206
|
+
description: 'Manages send classification settings.',
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
name: 'FilterDefinition',
|
|
1210
|
+
methods: STANDARD_METHODS,
|
|
1211
|
+
description: 'Manages data filter definitions.',
|
|
1212
|
+
},
|
|
1213
|
+
{
|
|
1214
|
+
name: 'Account',
|
|
1215
|
+
methods: STANDARD_METHODS,
|
|
1216
|
+
description: 'Manages Marketing Cloud account settings.',
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
name: 'AccountUser',
|
|
1220
|
+
methods: STANDARD_METHODS,
|
|
1221
|
+
description: 'Manages user accounts within the Marketing Cloud business unit.',
|
|
1222
|
+
},
|
|
1223
|
+
{
|
|
1224
|
+
name: 'Portfolio',
|
|
1225
|
+
methods: STANDARD_METHODS,
|
|
1226
|
+
description: 'Manages portfolio (file) items in the account.',
|
|
1227
|
+
},
|
|
1228
|
+
{
|
|
1229
|
+
name: 'BounceEvent',
|
|
1230
|
+
methods: ['Retrieve'],
|
|
1231
|
+
description: 'Retrieves bounce event data for message sends.',
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
name: 'ClickEvent',
|
|
1235
|
+
methods: ['Retrieve'],
|
|
1236
|
+
description: 'Retrieves click tracking event data for message sends.',
|
|
1237
|
+
},
|
|
1238
|
+
{
|
|
1239
|
+
name: 'ForwardedEmailEvent',
|
|
1240
|
+
methods: ['Retrieve'],
|
|
1241
|
+
description: 'Retrieves forwarded email event data for message sends.',
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
name: 'ForwardedEmailOptInEvent',
|
|
1245
|
+
methods: ['Retrieve'],
|
|
1246
|
+
description: 'Retrieves forwarded email opt-in event data for message sends.',
|
|
1247
|
+
},
|
|
1248
|
+
{
|
|
1249
|
+
name: 'NotSentEvent',
|
|
1250
|
+
methods: ['Retrieve'],
|
|
1251
|
+
description: 'Retrieves not-sent event data for message sends.',
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
name: 'OpenEvent',
|
|
1255
|
+
methods: ['Retrieve'],
|
|
1256
|
+
description: 'Retrieves open tracking event data for message sends.',
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
name: 'SentEvent',
|
|
1260
|
+
methods: ['Retrieve'],
|
|
1261
|
+
description: 'Retrieves sent event data for message sends.',
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
name: 'SurveyEvent',
|
|
1265
|
+
methods: ['Retrieve'],
|
|
1266
|
+
description: 'Retrieves survey response event data for message sends.',
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
name: 'UnsubEvent',
|
|
1270
|
+
methods: ['Retrieve'],
|
|
1271
|
+
description: 'Retrieves unsubscribe event data for message sends.',
|
|
1272
|
+
},
|
|
1273
|
+
];
|
|
1274
|
+
|
|
1275
|
+
export const coreObjectNames = new Set(CORE_LIBRARY_OBJECTS.map((o) => o.name));
|
|
1276
|
+
|
|
1277
|
+
export const coreObjectLookup = new Map(CORE_LIBRARY_OBJECTS.map((o) => [o.name, o]));
|
|
1278
|
+
|
|
1279
|
+
// ── HTTP object methods ──────────────────────────────────────────────────────
|
|
1280
|
+
|
|
1281
|
+
/** @type {Array<{name:string, minArgs:number, maxArgs:number, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string}>} */
|
|
1282
|
+
export const HTTP_METHODS = [
|
|
1283
|
+
{
|
|
1284
|
+
name: 'Get',
|
|
1285
|
+
minArgs: 1,
|
|
1286
|
+
maxArgs: 3,
|
|
1287
|
+
description: 'Performs an HTTP GET request returning the response body.',
|
|
1288
|
+
params: [
|
|
1289
|
+
{ name: 'url', description: 'URL to request', type: 'string' },
|
|
1290
|
+
{ name: 'headerNames', description: 'Array of header names', type: 'array', optional: true },
|
|
1291
|
+
{ name: 'headerValues', description: 'Array of header values', type: 'array', optional: true },
|
|
1292
|
+
],
|
|
1293
|
+
returnType: 'object',
|
|
1294
|
+
syntax: 'HTTP.Get(url[, headerNames, headerValues])',
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
name: 'Post',
|
|
1298
|
+
minArgs: 3,
|
|
1299
|
+
maxArgs: 5,
|
|
1300
|
+
description: 'Performs an HTTP POST request with a content type and payload.',
|
|
1301
|
+
params: [
|
|
1302
|
+
{ name: 'url', description: 'URL to post to', type: 'string' },
|
|
1303
|
+
{ name: 'contentType', description: 'MIME type of the request body', type: 'string' },
|
|
1304
|
+
{ name: 'payload', description: 'Request body content', type: 'string' },
|
|
1305
|
+
{ name: 'headerNames', description: 'Array of header names', type: 'array', optional: true },
|
|
1306
|
+
{ name: 'headerValues', description: 'Array of header values', type: 'array', optional: true },
|
|
1307
|
+
],
|
|
1308
|
+
returnType: 'object',
|
|
1309
|
+
syntax: 'HTTP.Post(url, contentType, payload[, headerNames, headerValues])',
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
name: 'GetRequest',
|
|
1313
|
+
minArgs: 0,
|
|
1314
|
+
maxArgs: 0,
|
|
1315
|
+
description: 'Returns the HTTP request object for the current page invocation.',
|
|
1316
|
+
params: [],
|
|
1317
|
+
returnType: 'object',
|
|
1318
|
+
syntax: 'HTTP.GetRequest()',
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
name: 'PostRequest',
|
|
1322
|
+
minArgs: 0,
|
|
1323
|
+
maxArgs: 0,
|
|
1324
|
+
description: 'Returns the HTTP post data for the current page invocation.',
|
|
1325
|
+
params: [],
|
|
1326
|
+
returnType: 'object',
|
|
1327
|
+
syntax: 'HTTP.PostRequest()',
|
|
1328
|
+
},
|
|
1329
|
+
];
|
|
1330
|
+
|
|
1331
|
+
export const httpMethodNames = new Set(HTTP_METHODS.map((m) => m.name.toLowerCase()));
|
|
1332
|
+
|
|
1333
|
+
// ── WSProxy methods ──────────────────────────────────────────────────────────
|
|
1334
|
+
|
|
1335
|
+
/** @type {Array<{name:string, minArgs:number, maxArgs:number, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string}>} */
|
|
1336
|
+
export const WSPROXY_METHODS = [
|
|
1337
|
+
{
|
|
1338
|
+
name: 'createItem',
|
|
1339
|
+
minArgs: 2,
|
|
1340
|
+
maxArgs: 2,
|
|
1341
|
+
description: 'Creates a new Marketing Cloud object via the SOAP API.',
|
|
1342
|
+
params: [
|
|
1343
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1344
|
+
{ name: 'properties', description: 'Object properties to set', type: 'object' },
|
|
1345
|
+
],
|
|
1346
|
+
returnType: 'object',
|
|
1347
|
+
syntax: 'api.createItem(objectType, properties)',
|
|
1348
|
+
example:
|
|
1349
|
+
'var api = new WSProxy();\n' +
|
|
1350
|
+
'var result = api.createItem("DataExtensionObject", {\n' +
|
|
1351
|
+
' CustomerKey: "MyDE",\n' +
|
|
1352
|
+
' Properties: { Property: [{ Name: "Email", Value: "jane@example.com" }] }\n' +
|
|
1353
|
+
'});\n' +
|
|
1354
|
+
'if (result.Status === "OK") { Write("Created"); }',
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
name: 'updateItem',
|
|
1358
|
+
minArgs: 2,
|
|
1359
|
+
maxArgs: 2,
|
|
1360
|
+
description: 'Updates an existing Marketing Cloud object via the SOAP API.',
|
|
1361
|
+
params: [
|
|
1362
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1363
|
+
{ name: 'properties', description: 'Object properties to update', type: 'object' },
|
|
1364
|
+
],
|
|
1365
|
+
returnType: 'object',
|
|
1366
|
+
syntax: 'api.updateItem(objectType, properties)',
|
|
1367
|
+
example:
|
|
1368
|
+
'var api = new WSProxy();\n' +
|
|
1369
|
+
'var result = api.updateItem("DataExtensionObject", {\n' +
|
|
1370
|
+
' CustomerKey: "MyDE",\n' +
|
|
1371
|
+
' Properties: { Property: [{ Name: "Status", Value: "inactive" }] }\n' +
|
|
1372
|
+
'});\n' +
|
|
1373
|
+
'if (result.Status === "OK") { Write("Updated"); }',
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
name: 'deleteItem',
|
|
1377
|
+
minArgs: 2,
|
|
1378
|
+
maxArgs: 2,
|
|
1379
|
+
description: 'Deletes a Marketing Cloud object via the SOAP API.',
|
|
1380
|
+
params: [
|
|
1381
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1382
|
+
{ name: 'properties', description: 'Object properties identifying the item to delete', type: 'object' },
|
|
1383
|
+
],
|
|
1384
|
+
returnType: 'object',
|
|
1385
|
+
syntax: 'api.deleteItem(objectType, properties)',
|
|
1386
|
+
example:
|
|
1387
|
+
'var api = new WSProxy();\n' +
|
|
1388
|
+
'var result = api.deleteItem("DataExtensionObject", {\n' +
|
|
1389
|
+
' CustomerKey: "MyDE",\n' +
|
|
1390
|
+
' Keys: { Key: [{ Name: "Email", Value: "jane@example.com" }] }\n' +
|
|
1391
|
+
'});\n' +
|
|
1392
|
+
'if (result.Status === "OK") { Write("Deleted"); }',
|
|
1393
|
+
},
|
|
1394
|
+
{
|
|
1395
|
+
name: 'retrieve',
|
|
1396
|
+
minArgs: 3,
|
|
1397
|
+
maxArgs: 4,
|
|
1398
|
+
description: 'Retrieves Marketing Cloud objects matching a filter via the SOAP API.',
|
|
1399
|
+
params: [
|
|
1400
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1401
|
+
{ name: 'columns', description: 'Array of property names to retrieve', type: 'array' },
|
|
1402
|
+
{ name: 'filter', description: 'Simple filter object with Property, SimpleOperator, and Value', type: 'object' },
|
|
1403
|
+
{ name: 'moreData', description: 'Pass true to retrieve additional batches', type: 'boolean', optional: true },
|
|
1404
|
+
],
|
|
1405
|
+
returnType: 'object',
|
|
1406
|
+
syntax: 'api.retrieve(objectType, columns, filter[, moreData])',
|
|
1407
|
+
example:
|
|
1408
|
+
'var api = new WSProxy();\n' +
|
|
1409
|
+
'var cols = ["Name", "CustomerKey", "Status"];\n' +
|
|
1410
|
+
'var filter = {\n' +
|
|
1411
|
+
' Property: "Status",\n' +
|
|
1412
|
+
' SimpleOperator: "equals",\n' +
|
|
1413
|
+
' Value: "Active"\n' +
|
|
1414
|
+
'};\n' +
|
|
1415
|
+
'var result = api.retrieve("DataExtension", cols, filter);\n' +
|
|
1416
|
+
'if (result.Status === "OK") {\n' +
|
|
1417
|
+
' var rows = result.Results;\n' +
|
|
1418
|
+
' for (var i = 0; i < rows.length; i++) {\n' +
|
|
1419
|
+
' Write(rows[i].Name + "<br>");\n' +
|
|
1420
|
+
' }\n' +
|
|
1421
|
+
'}',
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
name: 'performItem',
|
|
1425
|
+
minArgs: 3,
|
|
1426
|
+
maxArgs: 3,
|
|
1427
|
+
description: 'Executes a perform action on a Marketing Cloud object.',
|
|
1428
|
+
params: [
|
|
1429
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1430
|
+
{ name: 'action', description: 'Action to perform (e.g. "start", "stop")', type: 'string' },
|
|
1431
|
+
{ name: 'properties', description: 'Object properties for the action', type: 'object' },
|
|
1432
|
+
],
|
|
1433
|
+
returnType: 'object',
|
|
1434
|
+
syntax: 'api.performItem(objectType, action, properties)',
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
name: 'execute',
|
|
1438
|
+
minArgs: 2,
|
|
1439
|
+
maxArgs: 2,
|
|
1440
|
+
description: 'Executes a named method on a Marketing Cloud object.',
|
|
1441
|
+
params: [
|
|
1442
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1443
|
+
{ name: 'method', description: 'Method name to execute', type: 'string' },
|
|
1444
|
+
],
|
|
1445
|
+
returnType: 'object',
|
|
1446
|
+
syntax: 'api.execute(objectType, method)',
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
name: 'setBatchSize',
|
|
1450
|
+
minArgs: 1,
|
|
1451
|
+
maxArgs: 1,
|
|
1452
|
+
description: 'Sets the maximum number of objects per SOAP API batch.',
|
|
1453
|
+
params: [
|
|
1454
|
+
{ name: 'batchSize', description: 'Maximum number of objects per batch', type: 'number' },
|
|
1455
|
+
],
|
|
1456
|
+
returnType: 'void',
|
|
1457
|
+
syntax: 'api.setBatchSize(batchSize)',
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
name: 'setClientId',
|
|
1461
|
+
minArgs: 1,
|
|
1462
|
+
maxArgs: 1,
|
|
1463
|
+
description: 'Sets the business unit MID for cross-account operations.',
|
|
1464
|
+
params: [
|
|
1465
|
+
{ name: 'clientId', description: 'Object containing the MID of the target business unit', type: 'object' },
|
|
1466
|
+
],
|
|
1467
|
+
returnType: 'void',
|
|
1468
|
+
syntax: 'api.setClientId(clientId)',
|
|
1469
|
+
example:
|
|
1470
|
+
'var api = new WSProxy();\n' +
|
|
1471
|
+
'api.setClientId({ ID: 12345 }); // target child BU by MID\n' +
|
|
1472
|
+
'var result = api.retrieve("DataExtension", ["Name"], {});',
|
|
1473
|
+
},
|
|
1474
|
+
{
|
|
1475
|
+
name: 'createBatch',
|
|
1476
|
+
minArgs: 2,
|
|
1477
|
+
maxArgs: 2,
|
|
1478
|
+
description: 'Creates multiple Marketing Cloud objects in a single SOAP API call.',
|
|
1479
|
+
params: [
|
|
1480
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1481
|
+
{ name: 'propertiesArray', description: 'Array of property objects to create', type: 'array' },
|
|
1482
|
+
],
|
|
1483
|
+
returnType: 'object',
|
|
1484
|
+
syntax: 'api.createBatch(objectType, propertiesArray)',
|
|
1485
|
+
},
|
|
1486
|
+
{
|
|
1487
|
+
name: 'updateBatch',
|
|
1488
|
+
minArgs: 2,
|
|
1489
|
+
maxArgs: 2,
|
|
1490
|
+
description: 'Updates multiple Marketing Cloud objects in a single SOAP API call.',
|
|
1491
|
+
params: [
|
|
1492
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1493
|
+
{ name: 'propertiesArray', description: 'Array of property objects to update', type: 'array' },
|
|
1494
|
+
],
|
|
1495
|
+
returnType: 'object',
|
|
1496
|
+
syntax: 'api.updateBatch(objectType, propertiesArray)',
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
name: 'deleteBatch',
|
|
1500
|
+
minArgs: 2,
|
|
1501
|
+
maxArgs: 2,
|
|
1502
|
+
description: 'Deletes multiple Marketing Cloud objects in a single SOAP API call.',
|
|
1503
|
+
params: [
|
|
1504
|
+
{ name: 'objectType', description: 'SOAP API object type name', type: 'string' },
|
|
1505
|
+
{ name: 'propertiesArray', description: 'Array of property objects to delete', type: 'array' },
|
|
1506
|
+
],
|
|
1507
|
+
returnType: 'object',
|
|
1508
|
+
syntax: 'api.deleteBatch(objectType, propertiesArray)',
|
|
1509
|
+
},
|
|
1510
|
+
];
|
|
1511
|
+
|
|
1512
|
+
export const wsproxyMethodNames = new Set(WSPROXY_METHODS.map((m) => m.name.toLowerCase()));
|
|
1513
|
+
|
|
1514
|
+
// ── Platform.Variable / Platform.Response / Platform.Request ─────────────────
|
|
1515
|
+
|
|
1516
|
+
export const PLATFORM_VARIABLE_METHODS = [
|
|
1517
|
+
{
|
|
1518
|
+
name: 'GetValue',
|
|
1519
|
+
minArgs: 1,
|
|
1520
|
+
maxArgs: 1,
|
|
1521
|
+
description: 'Retrieves the value of an AMPscript variable from the SSJS context.',
|
|
1522
|
+
params: [
|
|
1523
|
+
{ name: 'variableName', description: 'Name of the AMPscript variable', type: 'string' },
|
|
1524
|
+
],
|
|
1525
|
+
returnType: 'string',
|
|
1526
|
+
syntax: 'Variable.GetValue(variableName)',
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
name: 'SetValue',
|
|
1530
|
+
minArgs: 2,
|
|
1531
|
+
maxArgs: 2,
|
|
1532
|
+
description: 'Assigns a value to an AMPscript variable from the SSJS context.',
|
|
1533
|
+
params: [
|
|
1534
|
+
{ name: 'variableName', description: 'Name of the AMPscript variable', type: 'string' },
|
|
1535
|
+
{ name: 'value', description: 'Value to assign', type: 'string' },
|
|
1536
|
+
],
|
|
1537
|
+
returnType: 'void',
|
|
1538
|
+
syntax: 'Variable.SetValue(variableName, value)',
|
|
1539
|
+
},
|
|
1540
|
+
];
|
|
1541
|
+
|
|
1542
|
+
export const PLATFORM_RESPONSE_METHODS = [
|
|
1543
|
+
{
|
|
1544
|
+
name: 'GetResponseHeader',
|
|
1545
|
+
minArgs: 1,
|
|
1546
|
+
maxArgs: 1,
|
|
1547
|
+
description: 'Gets the value of a response header.',
|
|
1548
|
+
params: [
|
|
1549
|
+
{ name: 'headerName', description: 'Name of the response header', type: 'string' },
|
|
1550
|
+
],
|
|
1551
|
+
returnType: 'string',
|
|
1552
|
+
syntax: 'Platform.Response.GetResponseHeader(headerName)',
|
|
1553
|
+
},
|
|
1554
|
+
{
|
|
1555
|
+
name: 'SetResponseHeader',
|
|
1556
|
+
minArgs: 2,
|
|
1557
|
+
maxArgs: 2,
|
|
1558
|
+
description: 'Sets a response header on the current page response.',
|
|
1559
|
+
params: [
|
|
1560
|
+
{ name: 'headerName', description: 'Name of the response header', type: 'string' },
|
|
1561
|
+
{ name: 'value', description: 'Value for the response header', type: 'string' },
|
|
1562
|
+
],
|
|
1563
|
+
returnType: 'void',
|
|
1564
|
+
syntax: 'Platform.Response.SetResponseHeader(headerName, value)',
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
name: 'Redirect',
|
|
1568
|
+
minArgs: 1,
|
|
1569
|
+
maxArgs: 2,
|
|
1570
|
+
description:
|
|
1571
|
+
'Redirects the current page to a new URL. ' +
|
|
1572
|
+
'Second parameter: false (default) = 302 temporary redirect, true = 301 permanent redirect.',
|
|
1573
|
+
params: [
|
|
1574
|
+
{ name: 'url', description: 'URL to redirect to', type: 'string' },
|
|
1575
|
+
{ name: 'permanent', description: 'True for 301 permanent redirect, false for 302 temporary', type: 'boolean', optional: true },
|
|
1576
|
+
],
|
|
1577
|
+
returnType: 'void',
|
|
1578
|
+
syntax: 'Platform.Response.Redirect(url[, permanent])',
|
|
1579
|
+
},
|
|
1580
|
+
{
|
|
1581
|
+
name: 'Write',
|
|
1582
|
+
minArgs: 1,
|
|
1583
|
+
maxArgs: 1,
|
|
1584
|
+
description: 'Writes content to the page response output.',
|
|
1585
|
+
params: [
|
|
1586
|
+
{ name: 'content', description: 'Content string to write to the response', type: 'string' },
|
|
1587
|
+
],
|
|
1588
|
+
returnType: 'void',
|
|
1589
|
+
syntax: 'Platform.Response.Write(content)',
|
|
1590
|
+
},
|
|
1591
|
+
];
|
|
1592
|
+
|
|
1593
|
+
export const PLATFORM_REQUEST_METHODS = [
|
|
1594
|
+
{
|
|
1595
|
+
name: 'GetQueryStringParameter',
|
|
1596
|
+
minArgs: 1,
|
|
1597
|
+
maxArgs: 1,
|
|
1598
|
+
description: 'Retrieves the value of a URL query string parameter.',
|
|
1599
|
+
params: [
|
|
1600
|
+
{ name: 'parameterName', description: 'Name of the query string parameter', type: 'string' },
|
|
1601
|
+
],
|
|
1602
|
+
returnType: 'string',
|
|
1603
|
+
syntax: 'Platform.Request.GetQueryStringParameter(parameterName)',
|
|
1604
|
+
},
|
|
1605
|
+
{
|
|
1606
|
+
name: 'GetFormData',
|
|
1607
|
+
minArgs: 1,
|
|
1608
|
+
maxArgs: 1,
|
|
1609
|
+
description: 'Retrieves a named value from submitted form data.',
|
|
1610
|
+
params: [
|
|
1611
|
+
{ name: 'fieldName', description: 'Name of the form field', type: 'string' },
|
|
1612
|
+
],
|
|
1613
|
+
returnType: 'string',
|
|
1614
|
+
syntax: 'Platform.Request.GetFormData(fieldName)',
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
name: 'GetPostData',
|
|
1618
|
+
minArgs: 0,
|
|
1619
|
+
maxArgs: 1,
|
|
1620
|
+
description:
|
|
1621
|
+
'Returns the raw body of the HTTP POST request. ' +
|
|
1622
|
+
'CAVEAT: Only returns data on the FIRST call per request; subsequent calls return nothing. ' +
|
|
1623
|
+
'Store the result in a variable if you need it multiple times.',
|
|
1624
|
+
params: [
|
|
1625
|
+
{ name: 'encoding', description: 'Character encoding for the post data', type: 'string', optional: true },
|
|
1626
|
+
],
|
|
1627
|
+
returnType: 'string',
|
|
1628
|
+
syntax: 'Platform.Request.GetPostData([encoding])',
|
|
1629
|
+
},
|
|
1630
|
+
{
|
|
1631
|
+
name: 'HasSSL',
|
|
1632
|
+
minArgs: 0,
|
|
1633
|
+
maxArgs: 0,
|
|
1634
|
+
description: 'Returns true if the current request was made over HTTPS.',
|
|
1635
|
+
params: [],
|
|
1636
|
+
returnType: 'boolean',
|
|
1637
|
+
syntax: 'Platform.Request.HasSSL()',
|
|
1638
|
+
},
|
|
1639
|
+
{
|
|
1640
|
+
name: 'Method',
|
|
1641
|
+
minArgs: 0,
|
|
1642
|
+
maxArgs: 0,
|
|
1643
|
+
description: 'Returns the HTTP method (GET, POST, etc.) of the current request.',
|
|
1644
|
+
params: [],
|
|
1645
|
+
returnType: 'string',
|
|
1646
|
+
syntax: 'Platform.Request.Method()',
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
name: 'RequestURL',
|
|
1650
|
+
minArgs: 0,
|
|
1651
|
+
maxArgs: 0,
|
|
1652
|
+
description: 'Returns the full URL of the current page request.',
|
|
1653
|
+
params: [],
|
|
1654
|
+
returnType: 'string',
|
|
1655
|
+
syntax: 'Platform.Request.RequestURL()',
|
|
1656
|
+
},
|
|
1657
|
+
{
|
|
1658
|
+
name: 'GetCookieValue',
|
|
1659
|
+
minArgs: 1,
|
|
1660
|
+
maxArgs: 1,
|
|
1661
|
+
description: 'Retrieves the value of a named cookie from the HTTP request sent by the client browser.',
|
|
1662
|
+
params: [
|
|
1663
|
+
{ name: 'cookieName', description: 'Name of the cookie to retrieve', type: 'string' },
|
|
1664
|
+
],
|
|
1665
|
+
returnType: 'string',
|
|
1666
|
+
syntax: 'Platform.Request.GetCookieValue(cookieName)',
|
|
1667
|
+
},
|
|
1668
|
+
{
|
|
1669
|
+
name: 'GetUserLanguages',
|
|
1670
|
+
minArgs: 0,
|
|
1671
|
+
maxArgs: 0,
|
|
1672
|
+
description: 'Returns the language preferences of the client browser as specified in the HTTP Accept-Language request header.',
|
|
1673
|
+
params: [],
|
|
1674
|
+
returnType: 'string',
|
|
1675
|
+
syntax: 'Platform.Request.GetUserLanguages()',
|
|
1676
|
+
},
|
|
1677
|
+
];
|
|
1678
|
+
|
|
1679
|
+
// ── Platform.ClientBrowser methods ──────────────────────────────────────────
|
|
1680
|
+
|
|
1681
|
+
export const PLATFORM_CLIENT_BROWSER_METHODS = [
|
|
1682
|
+
{
|
|
1683
|
+
name: 'Redirect',
|
|
1684
|
+
minArgs: 1,
|
|
1685
|
+
maxArgs: 1,
|
|
1686
|
+
description: 'Redirects the client browser to a specified URL.',
|
|
1687
|
+
params: [
|
|
1688
|
+
{ name: 'url', description: 'The URL to redirect the client browser to', type: 'string' },
|
|
1689
|
+
],
|
|
1690
|
+
returnType: 'void',
|
|
1691
|
+
syntax: 'Platform.ClientBrowser.Redirect(url)',
|
|
1692
|
+
},
|
|
1693
|
+
{
|
|
1694
|
+
name: 'Write',
|
|
1695
|
+
minArgs: 1,
|
|
1696
|
+
maxArgs: 1,
|
|
1697
|
+
description: 'Writes content directly to the HTTP response sent to the client browser.',
|
|
1698
|
+
params: [
|
|
1699
|
+
{ name: 'content', description: 'The string content to write to the response output', type: 'string' },
|
|
1700
|
+
],
|
|
1701
|
+
returnType: 'void',
|
|
1702
|
+
syntax: 'Platform.ClientBrowser.Write(content)',
|
|
1703
|
+
},
|
|
1704
|
+
{
|
|
1705
|
+
name: 'SetCookie',
|
|
1706
|
+
minArgs: 2,
|
|
1707
|
+
maxArgs: 6,
|
|
1708
|
+
description: 'Sets a cookie on the client browser response.',
|
|
1709
|
+
params: [
|
|
1710
|
+
{ name: 'name', description: 'Name of the cookie to set', type: 'string' },
|
|
1711
|
+
{ name: 'value', description: 'Value to store in the cookie', type: 'string' },
|
|
1712
|
+
{ name: 'expires', description: 'Expiration date/time for the cookie', type: 'string', optional: true },
|
|
1713
|
+
{ name: 'path', description: 'URL path for which the cookie is valid', type: 'string', optional: true },
|
|
1714
|
+
{ name: 'domain', description: 'Domain for which the cookie is valid', type: 'string', optional: true },
|
|
1715
|
+
{ name: 'secure', description: 'If true, the cookie is only sent over HTTPS', type: 'boolean', optional: true },
|
|
1716
|
+
],
|
|
1717
|
+
returnType: 'void',
|
|
1718
|
+
syntax: 'Platform.ClientBrowser.SetCookie(name, value[, expires, path, domain, secure])',
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
name: 'RemoveCookie',
|
|
1722
|
+
minArgs: 1,
|
|
1723
|
+
maxArgs: 1,
|
|
1724
|
+
description: 'Removes a cookie from the client browser by setting its expiration to a past date.',
|
|
1725
|
+
params: [
|
|
1726
|
+
{ name: 'name', description: 'Name of the cookie to remove', type: 'string' },
|
|
1727
|
+
],
|
|
1728
|
+
returnType: 'void',
|
|
1729
|
+
syntax: 'Platform.ClientBrowser.RemoveCookie(name)',
|
|
1730
|
+
},
|
|
1731
|
+
{
|
|
1732
|
+
name: 'SetResponseHeader',
|
|
1733
|
+
minArgs: 2,
|
|
1734
|
+
maxArgs: 2,
|
|
1735
|
+
description: 'Sets a custom HTTP response header on the response sent to the client browser.',
|
|
1736
|
+
params: [
|
|
1737
|
+
{ name: 'headerName', description: 'Name of the HTTP response header to set', type: 'string' },
|
|
1738
|
+
{ name: 'value', description: 'Value to assign to the response header', type: 'string' },
|
|
1739
|
+
],
|
|
1740
|
+
returnType: 'void',
|
|
1741
|
+
syntax: 'Platform.ClientBrowser.SetResponseHeader(headerName, value)',
|
|
1742
|
+
},
|
|
1743
|
+
{
|
|
1744
|
+
name: 'RemoveResponseHeader',
|
|
1745
|
+
minArgs: 1,
|
|
1746
|
+
maxArgs: 1,
|
|
1747
|
+
description: 'Removes a previously set HTTP response header from the response sent to the client browser.',
|
|
1748
|
+
params: [
|
|
1749
|
+
{ name: 'headerName', description: 'Name of the HTTP response header to remove', type: 'string' },
|
|
1750
|
+
],
|
|
1751
|
+
returnType: 'void',
|
|
1752
|
+
syntax: 'Platform.ClientBrowser.RemoveResponseHeader(headerName)',
|
|
1753
|
+
},
|
|
1754
|
+
];
|
|
1755
|
+
|
|
1756
|
+
export const platformClientBrowserMethodNames = new Set(
|
|
1757
|
+
PLATFORM_CLIENT_BROWSER_METHODS.map((m) => m.name.toLowerCase()),
|
|
1758
|
+
);
|
|
1759
|
+
|
|
1760
|
+
// ── Script.Util HTTP constructors ────────────────────────────────────────────
|
|
1761
|
+
// Request handler constructors under the Script.Util namespace.
|
|
1762
|
+
// Instantiated with `new Script.Util.HttpRequest(url)` etc.
|
|
1763
|
+
|
|
1764
|
+
/** @type {Array<{name:string, minArgs:number, maxArgs:number, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string, example?:string}>} */
|
|
1765
|
+
export const SCRIPT_UTIL_CONSTRUCTORS = [
|
|
1766
|
+
{
|
|
1767
|
+
name: 'HttpRequest',
|
|
1768
|
+
minArgs: 1,
|
|
1769
|
+
maxArgs: 1,
|
|
1770
|
+
description:
|
|
1771
|
+
'Creates an HTTP request handler that supports any HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS). ' +
|
|
1772
|
+
'Unlike Platform.Function.HTTPGet/HTTPPost, this handler supports custom methods and headers. ' +
|
|
1773
|
+
'Call send() to execute the request and receive a Script.Util.HttpResponse object.',
|
|
1774
|
+
params: [
|
|
1775
|
+
{ name: 'url', description: 'The destination URL for the request', type: 'string' },
|
|
1776
|
+
],
|
|
1777
|
+
returnType: 'object',
|
|
1778
|
+
syntax: 'new Script.Util.HttpRequest(url)',
|
|
1779
|
+
example:
|
|
1780
|
+
'var url = "https://api.example.com/items/123";\n' +
|
|
1781
|
+
'var req = new Script.Util.HttpRequest(url);\n' +
|
|
1782
|
+
'req.emptyContentHandling = 0;\n' +
|
|
1783
|
+
'req.retries = 2;\n' +
|
|
1784
|
+
'req.continueOnError = true;\n' +
|
|
1785
|
+
'req.contentType = "application/json";\n' +
|
|
1786
|
+
'req.method = "PUT";\n' +
|
|
1787
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1788
|
+
'req.postData = Stringify({ status: "active" });\n' +
|
|
1789
|
+
'var resp = req.send();\n' +
|
|
1790
|
+
'var result = Platform.Function.ParseJSON(String(resp.content));',
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
name: 'HttpGet',
|
|
1794
|
+
minArgs: 1,
|
|
1795
|
+
maxArgs: 1,
|
|
1796
|
+
description:
|
|
1797
|
+
'Creates an HTTP GET request handler. Unlike Platform.Function.HTTPGet, this handler caches content for use in mail sends and supports custom headers. ' +
|
|
1798
|
+
'Only works with HTTP on port 80 and HTTPS on port 443. ' +
|
|
1799
|
+
'Call send() to execute the request and receive a Script.Util.HttpResponse object.',
|
|
1800
|
+
params: [
|
|
1801
|
+
{ name: 'url', description: 'The URL to retrieve content from', type: 'string' },
|
|
1802
|
+
],
|
|
1803
|
+
returnType: 'object',
|
|
1804
|
+
syntax: 'new Script.Util.HttpGet(url)',
|
|
1805
|
+
example:
|
|
1806
|
+
'var req = new Script.Util.HttpGet("https://api.example.com/data");\n' +
|
|
1807
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1808
|
+
'req.retries = 2;\n' +
|
|
1809
|
+
'req.continueOnError = true;\n' +
|
|
1810
|
+
'var resp = req.send();\n' +
|
|
1811
|
+
'if (resp.statusCode == 200) {\n' +
|
|
1812
|
+
' var result = Platform.Function.ParseJSON(String(resp.content));\n' +
|
|
1813
|
+
' Platform.Response.Write(Platform.Function.Stringify(result));\n' +
|
|
1814
|
+
'}',
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
name: 'HttpPost',
|
|
1818
|
+
minArgs: 3,
|
|
1819
|
+
maxArgs: 3,
|
|
1820
|
+
description:
|
|
1821
|
+
'Creates an HTTP POST request handler with a URL, content type, and payload. ' +
|
|
1822
|
+
'Call send() to execute the request and receive a Script.Util.HttpResponse object.',
|
|
1823
|
+
params: [
|
|
1824
|
+
{ name: 'url', description: 'The destination URL', type: 'string' },
|
|
1825
|
+
{ name: 'contentType', description: 'Content-Type header value (e.g. "application/json")', type: 'string' },
|
|
1826
|
+
{ name: 'payload', description: 'Request body content as a string', type: 'string' },
|
|
1827
|
+
],
|
|
1828
|
+
returnType: 'object',
|
|
1829
|
+
syntax: 'new Script.Util.HttpPost(url, contentType, payload)',
|
|
1830
|
+
example:
|
|
1831
|
+
'var payload = Stringify({ name: "Jane", status: "active" });\n' +
|
|
1832
|
+
'var req = new Script.Util.HttpPost("https://api.example.com/items", "application/json", payload);\n' +
|
|
1833
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1834
|
+
'var resp = req.send();\n' +
|
|
1835
|
+
'var result = Platform.Function.ParseJSON(String(resp.content));',
|
|
1836
|
+
},
|
|
1837
|
+
];
|
|
1838
|
+
|
|
1839
|
+
// ── Script.Util request object methods ──────────────────────────────────────
|
|
1840
|
+
// Methods available on a request object returned by Script.Util.HttpRequest,
|
|
1841
|
+
// Script.Util.HttpGet, or Script.Util.HttpPost.
|
|
1842
|
+
|
|
1843
|
+
/** @type {Array<{name:string, minArgs:number, maxArgs:number, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string, example?:string}>} */
|
|
1844
|
+
export const SCRIPT_UTIL_REQUEST_METHODS = [
|
|
1845
|
+
{
|
|
1846
|
+
name: 'send',
|
|
1847
|
+
minArgs: 0,
|
|
1848
|
+
maxArgs: 0,
|
|
1849
|
+
description:
|
|
1850
|
+
'Executes the HTTP request and returns a Script.Util.HttpResponse object. ' +
|
|
1851
|
+
'The response object has a `statusCode` property and a `content` property. ' +
|
|
1852
|
+
'Use String(resp.content) to convert the CLR content to a JavaScript string before parsing with Platform.Function.ParseJSON().',
|
|
1853
|
+
params: [],
|
|
1854
|
+
returnType: 'object',
|
|
1855
|
+
syntax: 'req.send()',
|
|
1856
|
+
example:
|
|
1857
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
1858
|
+
'req.method = "GET";\n' +
|
|
1859
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1860
|
+
'var resp = req.send();\n' +
|
|
1861
|
+
'if (resp.statusCode == 200) {\n' +
|
|
1862
|
+
' var result = Platform.Function.ParseJSON(String(resp.content));\n' +
|
|
1863
|
+
'}',
|
|
1864
|
+
},
|
|
1865
|
+
{
|
|
1866
|
+
name: 'setHeader',
|
|
1867
|
+
minArgs: 2,
|
|
1868
|
+
maxArgs: 2,
|
|
1869
|
+
description:
|
|
1870
|
+
'Sets a request header on the Script.Util HTTP request. ' +
|
|
1871
|
+
'Note: setting a custom header disables content caching for Script.Util.HttpGet.',
|
|
1872
|
+
params: [
|
|
1873
|
+
{ name: 'name', description: 'Header name (e.g. "Authorization", "Content-Type")', type: 'string' },
|
|
1874
|
+
{ name: 'value', description: 'Header value', type: 'string' },
|
|
1875
|
+
],
|
|
1876
|
+
returnType: 'void',
|
|
1877
|
+
syntax: 'req.setHeader(name, value)',
|
|
1878
|
+
example:
|
|
1879
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
1880
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1881
|
+
'req.setHeader("Content-Type", "application/json");\n' +
|
|
1882
|
+
'var resp = req.send();',
|
|
1883
|
+
},
|
|
1884
|
+
{
|
|
1885
|
+
name: 'clearHeaders',
|
|
1886
|
+
minArgs: 0,
|
|
1887
|
+
maxArgs: 0,
|
|
1888
|
+
description: 'Removes all custom headers previously set on the request.',
|
|
1889
|
+
params: [],
|
|
1890
|
+
returnType: 'void',
|
|
1891
|
+
syntax: 'req.clearHeaders()',
|
|
1892
|
+
example:
|
|
1893
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
1894
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1895
|
+
'req.clearHeaders(); // removes Authorization and all other custom headers\n' +
|
|
1896
|
+
'var resp = req.send();',
|
|
1897
|
+
},
|
|
1898
|
+
{
|
|
1899
|
+
name: 'removeHeader',
|
|
1900
|
+
minArgs: 1,
|
|
1901
|
+
maxArgs: 1,
|
|
1902
|
+
description: 'Removes a specific header from the request by name.',
|
|
1903
|
+
params: [
|
|
1904
|
+
{ name: 'name', description: 'Name of the header to remove', type: 'string' },
|
|
1905
|
+
],
|
|
1906
|
+
returnType: 'void',
|
|
1907
|
+
syntax: 'req.removeHeader(name)',
|
|
1908
|
+
example:
|
|
1909
|
+
'var req = new Script.Util.HttpRequest("https://api.example.com/data");\n' +
|
|
1910
|
+
'req.setHeader("Authorization", "Bearer " + accessToken);\n' +
|
|
1911
|
+
'req.setHeader("X-Custom", "value");\n' +
|
|
1912
|
+
'req.removeHeader("X-Custom");\n' +
|
|
1913
|
+
'var resp = req.send();',
|
|
1914
|
+
},
|
|
1915
|
+
];
|
|
1916
|
+
|
|
1917
|
+
// ── ECMAScript 3/5 built-in methods available in SSJS ───────────────────────
|
|
1918
|
+
// Methods from native JavaScript prototypes that work in the SFMC legacy engine.
|
|
1919
|
+
// Note: Array.prototype.indexOf, splice, and lastIndexOf exist but are broken;
|
|
1920
|
+
// use the polyfills from POLYFILLABLE_METHODS for correct behaviour.
|
|
1921
|
+
|
|
1922
|
+
/** @type {Array<{name:string, owner:string, description:string, params?:Array<{name:string, description:string, type?:string, optional?:boolean}>, returnType?:string, syntax?:string, example?:string}>} */
|
|
1923
|
+
export const ECMASCRIPT_BUILTINS = [
|
|
1924
|
+
// ── Array.prototype ──────────────────────────────────────────────────────
|
|
1925
|
+
{
|
|
1926
|
+
name: 'join',
|
|
1927
|
+
owner: 'Array.prototype',
|
|
1928
|
+
description: 'Joins all array elements into a string, separated by the specified delimiter.',
|
|
1929
|
+
params: [
|
|
1930
|
+
{ name: 'separator', description: 'Delimiter string (default: ",")', type: 'string', optional: true },
|
|
1931
|
+
],
|
|
1932
|
+
returnType: 'string',
|
|
1933
|
+
syntax: 'array.join([separator])',
|
|
1934
|
+
example: 'var arr = ["a", "b", "c"];\nvar str = arr.join(", "); // "a, b, c"',
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
name: 'push',
|
|
1938
|
+
owner: 'Array.prototype',
|
|
1939
|
+
description: 'Appends one or more elements to the end of an array and returns the new length.',
|
|
1940
|
+
params: [
|
|
1941
|
+
{ name: 'element', description: 'Element to append (repeat for multiple)', type: 'any' },
|
|
1942
|
+
],
|
|
1943
|
+
returnType: 'number',
|
|
1944
|
+
syntax: 'array.push(element[, ...])',
|
|
1945
|
+
example: 'var arr = [1, 2];\narr.push(3);\n// arr is now [1, 2, 3]',
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
name: 'pop',
|
|
1949
|
+
owner: 'Array.prototype',
|
|
1950
|
+
description: 'Removes and returns the last element from an array.',
|
|
1951
|
+
params: [],
|
|
1952
|
+
returnType: 'any',
|
|
1953
|
+
syntax: 'array.pop()',
|
|
1954
|
+
example: 'var arr = [1, 2, 3];\nvar last = arr.pop(); // 3',
|
|
1955
|
+
},
|
|
1956
|
+
{
|
|
1957
|
+
name: 'shift',
|
|
1958
|
+
owner: 'Array.prototype',
|
|
1959
|
+
description: 'Removes and returns the first element from an array.',
|
|
1960
|
+
params: [],
|
|
1961
|
+
returnType: 'any',
|
|
1962
|
+
syntax: 'array.shift()',
|
|
1963
|
+
example: 'var arr = [1, 2, 3];\nvar first = arr.shift(); // 1',
|
|
1964
|
+
},
|
|
1965
|
+
{
|
|
1966
|
+
name: 'unshift',
|
|
1967
|
+
owner: 'Array.prototype',
|
|
1968
|
+
description: 'Inserts one or more elements at the start of an array and returns the new length.',
|
|
1969
|
+
params: [
|
|
1970
|
+
{ name: 'element', description: 'Element to prepend (repeat for multiple)', type: 'any' },
|
|
1971
|
+
],
|
|
1972
|
+
returnType: 'number',
|
|
1973
|
+
syntax: 'array.unshift(element[, ...])',
|
|
1974
|
+
example: 'var arr = [2, 3];\narr.unshift(1);\n// arr is now [1, 2, 3]',
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
name: 'concat',
|
|
1978
|
+
owner: 'Array.prototype',
|
|
1979
|
+
description: 'Returns a new array formed by merging this array with other arrays or values.',
|
|
1980
|
+
params: [
|
|
1981
|
+
{ name: 'value', description: 'Array or value to concatenate', type: 'any' },
|
|
1982
|
+
],
|
|
1983
|
+
returnType: 'array',
|
|
1984
|
+
syntax: 'array.concat(value[, ...])',
|
|
1985
|
+
example: 'var a = [1, 2];\nvar b = [3, 4];\nvar c = a.concat(b); // [1, 2, 3, 4]',
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
name: 'slice',
|
|
1989
|
+
owner: 'Array.prototype',
|
|
1990
|
+
description: 'Returns a shallow copy of a portion of an array.',
|
|
1991
|
+
params: [
|
|
1992
|
+
{ name: 'start', description: 'Start index (0-based, negative counts from end)', type: 'number' },
|
|
1993
|
+
{ name: 'end', description: 'End index (exclusive)', type: 'number', optional: true },
|
|
1994
|
+
],
|
|
1995
|
+
returnType: 'array',
|
|
1996
|
+
syntax: 'array.slice([start[, end]])',
|
|
1997
|
+
example: 'var arr = [1, 2, 3, 4, 5];\nvar sub = arr.slice(1, 3); // [2, 3]',
|
|
1998
|
+
},
|
|
1999
|
+
{
|
|
2000
|
+
name: 'sort',
|
|
2001
|
+
owner: 'Array.prototype',
|
|
2002
|
+
description: 'Sorts the array in place and returns it. Default sort is lexicographic.',
|
|
2003
|
+
params: [
|
|
2004
|
+
{ name: 'compareFn', description: 'Optional comparison function (a, b) returning negative, 0, or positive', type: 'function', optional: true },
|
|
2005
|
+
],
|
|
2006
|
+
returnType: 'array',
|
|
2007
|
+
syntax: 'array.sort([compareFn])',
|
|
2008
|
+
example: 'var arr = [3, 1, 2];\narr.sort(function(a, b) { return a - b; }); // [1, 2, 3]',
|
|
2009
|
+
},
|
|
2010
|
+
{
|
|
2011
|
+
name: 'reverse',
|
|
2012
|
+
owner: 'Array.prototype',
|
|
2013
|
+
description: 'Reverses the elements of an array in place.',
|
|
2014
|
+
params: [],
|
|
2015
|
+
returnType: 'array',
|
|
2016
|
+
syntax: 'array.reverse()',
|
|
2017
|
+
example: 'var arr = [1, 2, 3];\narr.reverse(); // [3, 2, 1]',
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
name: 'length',
|
|
2021
|
+
owner: 'Array.prototype',
|
|
2022
|
+
description: 'Returns the number of elements in the array.',
|
|
2023
|
+
params: [],
|
|
2024
|
+
returnType: 'number',
|
|
2025
|
+
syntax: 'array.length',
|
|
2026
|
+
example: 'var arr = [1, 2, 3];\nWrite(arr.length); // 3',
|
|
2027
|
+
},
|
|
2028
|
+
// ── String.prototype ─────────────────────────────────────────────────────
|
|
2029
|
+
{
|
|
2030
|
+
name: 'charAt',
|
|
2031
|
+
owner: 'String.prototype',
|
|
2032
|
+
description: 'Returns the character at the specified index.',
|
|
2033
|
+
params: [
|
|
2034
|
+
{ name: 'index', description: 'Zero-based character index', type: 'number' },
|
|
2035
|
+
],
|
|
2036
|
+
returnType: 'string',
|
|
2037
|
+
syntax: 'str.charAt(index)',
|
|
2038
|
+
example: 'var str = "Hello";\nWrite(str.charAt(1)); // "e"',
|
|
2039
|
+
},
|
|
2040
|
+
{
|
|
2041
|
+
name: 'charCodeAt',
|
|
2042
|
+
owner: 'String.prototype',
|
|
2043
|
+
description: 'Returns the UTF-16 code unit at the specified index.',
|
|
2044
|
+
params: [
|
|
2045
|
+
{ name: 'index', description: 'Zero-based character index', type: 'number' },
|
|
2046
|
+
],
|
|
2047
|
+
returnType: 'number',
|
|
2048
|
+
syntax: 'str.charCodeAt(index)',
|
|
2049
|
+
example: 'var str = "A";\nWrite(str.charCodeAt(0)); // 65',
|
|
2050
|
+
},
|
|
2051
|
+
{
|
|
2052
|
+
name: 'indexOf',
|
|
2053
|
+
owner: 'String.prototype',
|
|
2054
|
+
description: 'Returns the index of the first occurrence of a substring, or -1 if not found.',
|
|
2055
|
+
params: [
|
|
2056
|
+
{ name: 'searchValue', description: 'Substring to search for', type: 'string' },
|
|
2057
|
+
{ name: 'fromIndex', description: 'Index to start the search from', type: 'number', optional: true },
|
|
2058
|
+
],
|
|
2059
|
+
returnType: 'number',
|
|
2060
|
+
syntax: 'str.indexOf(searchValue[, fromIndex])',
|
|
2061
|
+
example: 'var str = "Hello, world!";\nWrite(str.indexOf("world")); // 7',
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
name: 'lastIndexOf',
|
|
2065
|
+
owner: 'String.prototype',
|
|
2066
|
+
description: 'Returns the index of the last occurrence of a substring, or -1 if not found.',
|
|
2067
|
+
params: [
|
|
2068
|
+
{ name: 'searchValue', description: 'Substring to search for', type: 'string' },
|
|
2069
|
+
{ name: 'fromIndex', description: 'Index to search backwards from', type: 'number', optional: true },
|
|
2070
|
+
],
|
|
2071
|
+
returnType: 'number',
|
|
2072
|
+
syntax: 'str.lastIndexOf(searchValue[, fromIndex])',
|
|
2073
|
+
example: 'var str = "abcabc";\nWrite(str.lastIndexOf("b")); // 4',
|
|
2074
|
+
},
|
|
2075
|
+
{
|
|
2076
|
+
name: 'match',
|
|
2077
|
+
owner: 'String.prototype',
|
|
2078
|
+
description: 'Matches a string against a regular expression and returns the matches array.',
|
|
2079
|
+
params: [
|
|
2080
|
+
{ name: 'regexp', description: 'Regular expression to match against', type: 'RegExp' },
|
|
2081
|
+
],
|
|
2082
|
+
returnType: 'array',
|
|
2083
|
+
syntax: 'str.match(regexp)',
|
|
2084
|
+
example: 'var str = "test@example.com";\nvar matches = str.match(/[\\w.]+@[\\w.]+/);\nif (matches) { Write(matches[0]); }',
|
|
2085
|
+
},
|
|
2086
|
+
{
|
|
2087
|
+
name: 'replace',
|
|
2088
|
+
owner: 'String.prototype',
|
|
2089
|
+
description: 'Returns a new string with matches replaced by a replacement string or function.',
|
|
2090
|
+
params: [
|
|
2091
|
+
{ name: 'searchValue', description: 'Substring or RegExp to find', type: 'any' },
|
|
2092
|
+
{ name: 'replaceValue', description: 'Replacement string', type: 'string' },
|
|
2093
|
+
],
|
|
2094
|
+
returnType: 'string',
|
|
2095
|
+
syntax: 'str.replace(searchValue, replaceValue)',
|
|
2096
|
+
example: 'var str = "Hello, world!";\nWrite(str.replace("world", "SSJS")); // "Hello, SSJS!"',
|
|
2097
|
+
},
|
|
2098
|
+
{
|
|
2099
|
+
name: 'search',
|
|
2100
|
+
owner: 'String.prototype',
|
|
2101
|
+
description: 'Searches for a match and returns the index of the first match, or -1.',
|
|
2102
|
+
params: [
|
|
2103
|
+
{ name: 'regexp', description: 'Regular expression to search for', type: 'RegExp' },
|
|
2104
|
+
],
|
|
2105
|
+
returnType: 'number',
|
|
2106
|
+
syntax: 'str.search(regexp)',
|
|
2107
|
+
example: 'var str = "foo123bar";\nWrite(str.search(/\\d+/)); // 3',
|
|
2108
|
+
},
|
|
2109
|
+
{
|
|
2110
|
+
name: 'slice',
|
|
2111
|
+
owner: 'String.prototype',
|
|
2112
|
+
description: 'Extracts a section of a string and returns it as a new string.',
|
|
2113
|
+
params: [
|
|
2114
|
+
{ name: 'start', description: 'Start index (negative counts from end)', type: 'number' },
|
|
2115
|
+
{ name: 'end', description: 'End index (exclusive)', type: 'number', optional: true },
|
|
2116
|
+
],
|
|
2117
|
+
returnType: 'string',
|
|
2118
|
+
syntax: 'str.slice(start[, end])',
|
|
2119
|
+
example: 'var str = "Hello, world!";\nWrite(str.slice(7, 12)); // "world"',
|
|
2120
|
+
},
|
|
2121
|
+
{
|
|
2122
|
+
name: 'split',
|
|
2123
|
+
owner: 'String.prototype',
|
|
2124
|
+
description: 'Splits a string into an array of substrings using a separator.',
|
|
2125
|
+
params: [
|
|
2126
|
+
{ name: 'separator', description: 'String or RegExp to split on', type: 'any' },
|
|
2127
|
+
{ name: 'limit', description: 'Maximum number of substrings to return', type: 'number', optional: true },
|
|
2128
|
+
],
|
|
2129
|
+
returnType: 'array',
|
|
2130
|
+
syntax: 'str.split(separator[, limit])',
|
|
2131
|
+
example: 'var str = "a,b,c";\nvar parts = str.split(","); // ["a", "b", "c"]',
|
|
2132
|
+
},
|
|
2133
|
+
{
|
|
2134
|
+
name: 'substring',
|
|
2135
|
+
owner: 'String.prototype',
|
|
2136
|
+
description: 'Returns the characters between two indices of a string.',
|
|
2137
|
+
params: [
|
|
2138
|
+
{ name: 'start', description: 'Start index (inclusive)', type: 'number' },
|
|
2139
|
+
{ name: 'end', description: 'End index (exclusive)', type: 'number', optional: true },
|
|
2140
|
+
],
|
|
2141
|
+
returnType: 'string',
|
|
2142
|
+
syntax: 'str.substring(start[, end])',
|
|
2143
|
+
example: 'var str = "Hello, world!";\nWrite(str.substring(7, 12)); // "world"',
|
|
2144
|
+
},
|
|
2145
|
+
{
|
|
2146
|
+
name: 'toLowerCase',
|
|
2147
|
+
owner: 'String.prototype',
|
|
2148
|
+
description: 'Returns the string converted to lowercase.',
|
|
2149
|
+
params: [],
|
|
2150
|
+
returnType: 'string',
|
|
2151
|
+
syntax: 'str.toLowerCase()',
|
|
2152
|
+
example: 'var str = "Hello World";\nWrite(str.toLowerCase()); // "hello world"',
|
|
2153
|
+
},
|
|
2154
|
+
{
|
|
2155
|
+
name: 'toUpperCase',
|
|
2156
|
+
owner: 'String.prototype',
|
|
2157
|
+
description: 'Returns the string converted to uppercase.',
|
|
2158
|
+
params: [],
|
|
2159
|
+
returnType: 'string',
|
|
2160
|
+
syntax: 'str.toUpperCase()',
|
|
2161
|
+
example: 'var str = "Hello World";\nWrite(str.toUpperCase()); // "HELLO WORLD"',
|
|
2162
|
+
},
|
|
2163
|
+
{
|
|
2164
|
+
name: 'length',
|
|
2165
|
+
owner: 'String.prototype',
|
|
2166
|
+
description: 'Returns the number of characters in the string.',
|
|
2167
|
+
params: [],
|
|
2168
|
+
returnType: 'number',
|
|
2169
|
+
syntax: 'str.length',
|
|
2170
|
+
example: 'var str = "Hello";\nWrite(str.length); // 5',
|
|
2171
|
+
},
|
|
2172
|
+
// ── Math ─────────────────────────────────────────────────────────────────
|
|
2173
|
+
{
|
|
2174
|
+
name: 'abs',
|
|
2175
|
+
owner: 'Math',
|
|
2176
|
+
description: 'Returns the absolute value of a number.',
|
|
2177
|
+
params: [{ name: 'x', description: 'A number', type: 'number' }],
|
|
2178
|
+
returnType: 'number',
|
|
2179
|
+
syntax: 'Math.abs(x)',
|
|
2180
|
+
example: 'Write(Math.abs(-5)); // 5',
|
|
2181
|
+
},
|
|
2182
|
+
{
|
|
2183
|
+
name: 'ceil',
|
|
2184
|
+
owner: 'Math',
|
|
2185
|
+
description: 'Rounds a number up to the next integer.',
|
|
2186
|
+
params: [{ name: 'x', description: 'A number', type: 'number' }],
|
|
2187
|
+
returnType: 'number',
|
|
2188
|
+
syntax: 'Math.ceil(x)',
|
|
2189
|
+
example: 'Write(Math.ceil(4.1)); // 5',
|
|
2190
|
+
},
|
|
2191
|
+
{
|
|
2192
|
+
name: 'floor',
|
|
2193
|
+
owner: 'Math',
|
|
2194
|
+
description: 'Rounds a number down to the nearest integer.',
|
|
2195
|
+
params: [{ name: 'x', description: 'A number', type: 'number' }],
|
|
2196
|
+
returnType: 'number',
|
|
2197
|
+
syntax: 'Math.floor(x)',
|
|
2198
|
+
example: 'Write(Math.floor(4.9)); // 4',
|
|
2199
|
+
},
|
|
2200
|
+
{
|
|
2201
|
+
name: 'max',
|
|
2202
|
+
owner: 'Math',
|
|
2203
|
+
description: 'Returns the largest of the supplied numbers.',
|
|
2204
|
+
params: [{ name: 'values', description: 'Numbers to compare (variadic)', type: 'number' }],
|
|
2205
|
+
returnType: 'number',
|
|
2206
|
+
syntax: 'Math.max(value1[, value2, ...])',
|
|
2207
|
+
example: 'Write(Math.max(1, 5, 3)); // 5',
|
|
2208
|
+
},
|
|
2209
|
+
{
|
|
2210
|
+
name: 'min',
|
|
2211
|
+
owner: 'Math',
|
|
2212
|
+
description: 'Returns the smallest of the supplied numbers.',
|
|
2213
|
+
params: [{ name: 'values', description: 'Numbers to compare (variadic)', type: 'number' }],
|
|
2214
|
+
returnType: 'number',
|
|
2215
|
+
syntax: 'Math.min(value1[, value2, ...])',
|
|
2216
|
+
example: 'Write(Math.min(1, 5, 3)); // 1',
|
|
2217
|
+
},
|
|
2218
|
+
{
|
|
2219
|
+
name: 'pow',
|
|
2220
|
+
owner: 'Math',
|
|
2221
|
+
description: 'Returns the base raised to the exponent power.',
|
|
2222
|
+
params: [
|
|
2223
|
+
{ name: 'base', description: 'The base number', type: 'number' },
|
|
2224
|
+
{ name: 'exponent', description: 'The exponent', type: 'number' },
|
|
2225
|
+
],
|
|
2226
|
+
returnType: 'number',
|
|
2227
|
+
syntax: 'Math.pow(base, exponent)',
|
|
2228
|
+
example: 'Write(Math.pow(2, 10)); // 1024',
|
|
2229
|
+
},
|
|
2230
|
+
{
|
|
2231
|
+
name: 'random',
|
|
2232
|
+
owner: 'Math',
|
|
2233
|
+
description: 'Returns a pseudo-random floating-point number in [0, 1).',
|
|
2234
|
+
params: [],
|
|
2235
|
+
returnType: 'number',
|
|
2236
|
+
syntax: 'Math.random()',
|
|
2237
|
+
example: 'var r = Math.random();\nWrite(Math.floor(r * 100)); // random 0–99',
|
|
2238
|
+
},
|
|
2239
|
+
{
|
|
2240
|
+
name: 'round',
|
|
2241
|
+
owner: 'Math',
|
|
2242
|
+
description: 'Rounds a number to the nearest integer.',
|
|
2243
|
+
params: [{ name: 'x', description: 'A number', type: 'number' }],
|
|
2244
|
+
returnType: 'number',
|
|
2245
|
+
syntax: 'Math.round(x)',
|
|
2246
|
+
example: 'Write(Math.round(4.5)); // 5',
|
|
2247
|
+
},
|
|
2248
|
+
{
|
|
2249
|
+
name: 'sqrt',
|
|
2250
|
+
owner: 'Math',
|
|
2251
|
+
description: 'Returns the square root of a number.',
|
|
2252
|
+
params: [{ name: 'x', description: 'A non-negative number', type: 'number' }],
|
|
2253
|
+
returnType: 'number',
|
|
2254
|
+
syntax: 'Math.sqrt(x)',
|
|
2255
|
+
example: 'Write(Math.sqrt(16)); // 4',
|
|
2256
|
+
},
|
|
2257
|
+
];
|
|
2258
|
+
|
|
2259
|
+
// ── Unsupported ES6+ syntax ──────────────────────────────────────────────────
|
|
2260
|
+
// SFMC runs SSJS on a legacy ECMAScript 3/5 engine (Rhino-based).
|
|
2261
|
+
// These features cause runtime errors and should be avoided.
|
|
2262
|
+
|
|
2263
|
+
export const UNSUPPORTED_SYNTAX = [
|
|
2264
|
+
{
|
|
2265
|
+
feature: 'ArrowFunctionExpression',
|
|
2266
|
+
label: 'arrow functions',
|
|
2267
|
+
suggestion: 'Use a regular function expression instead.',
|
|
2268
|
+
nodeType: 'ArrowFunctionExpression',
|
|
2269
|
+
},
|
|
2270
|
+
{
|
|
2271
|
+
feature: 'LetDeclaration',
|
|
2272
|
+
label: "'let' declarations",
|
|
2273
|
+
suggestion: "Use 'var' instead.",
|
|
2274
|
+
nodeType: 'VariableDeclaration',
|
|
2275
|
+
test: (node) => node.kind === 'let',
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
feature: 'ConstDeclaration',
|
|
2279
|
+
label: "'const' declarations",
|
|
2280
|
+
suggestion: "Use 'var' instead.",
|
|
2281
|
+
nodeType: 'VariableDeclaration',
|
|
2282
|
+
test: (node) => node.kind === 'const',
|
|
2283
|
+
},
|
|
2284
|
+
{
|
|
2285
|
+
feature: 'TemplateLiteral',
|
|
2286
|
+
label: 'template literals',
|
|
2287
|
+
suggestion: 'Use string concatenation instead.',
|
|
2288
|
+
nodeType: 'TemplateLiteral',
|
|
2289
|
+
},
|
|
2290
|
+
{
|
|
2291
|
+
feature: 'ClassDeclaration',
|
|
2292
|
+
label: 'class declarations',
|
|
2293
|
+
suggestion: 'Use constructor functions with prototypes instead.',
|
|
2294
|
+
nodeType: 'ClassDeclaration',
|
|
2295
|
+
},
|
|
2296
|
+
{
|
|
2297
|
+
feature: 'ClassExpression',
|
|
2298
|
+
label: 'class expressions',
|
|
2299
|
+
suggestion: 'Use constructor functions with prototypes instead.',
|
|
2300
|
+
nodeType: 'ClassExpression',
|
|
2301
|
+
},
|
|
2302
|
+
{
|
|
2303
|
+
feature: 'ForOfStatement',
|
|
2304
|
+
label: "'for...of' loops",
|
|
2305
|
+
suggestion: "Use a standard 'for' loop or 'for...in' instead.",
|
|
2306
|
+
nodeType: 'ForOfStatement',
|
|
2307
|
+
},
|
|
2308
|
+
{
|
|
2309
|
+
feature: 'SpreadElement',
|
|
2310
|
+
label: 'spread syntax',
|
|
2311
|
+
suggestion: 'Use Array.prototype.concat or manual iteration instead.',
|
|
2312
|
+
nodeType: 'SpreadElement',
|
|
2313
|
+
},
|
|
2314
|
+
{
|
|
2315
|
+
feature: 'RestElement',
|
|
2316
|
+
label: 'rest parameters',
|
|
2317
|
+
suggestion: "Use the 'arguments' object instead.",
|
|
2318
|
+
nodeType: 'RestElement',
|
|
2319
|
+
},
|
|
2320
|
+
{
|
|
2321
|
+
feature: 'ObjectDestructuring',
|
|
2322
|
+
label: 'destructuring assignment',
|
|
2323
|
+
suggestion: 'Access object properties individually instead.',
|
|
2324
|
+
nodeType: 'ObjectPattern',
|
|
2325
|
+
},
|
|
2326
|
+
{
|
|
2327
|
+
feature: 'ArrayDestructuring',
|
|
2328
|
+
label: 'destructuring assignment',
|
|
2329
|
+
suggestion: 'Access array elements by index instead.',
|
|
2330
|
+
nodeType: 'ArrayPattern',
|
|
2331
|
+
},
|
|
2332
|
+
{
|
|
2333
|
+
feature: 'DefaultParameter',
|
|
2334
|
+
label: 'default parameter values',
|
|
2335
|
+
suggestion: 'Check for undefined inside the function body instead.',
|
|
2336
|
+
nodeType: 'AssignmentPattern',
|
|
2337
|
+
},
|
|
2338
|
+
{
|
|
2339
|
+
feature: 'AsyncFunction',
|
|
2340
|
+
label: 'async functions',
|
|
2341
|
+
suggestion: 'SFMC SSJS does not support Promises or async/await.',
|
|
2342
|
+
nodeType: 'FunctionDeclaration',
|
|
2343
|
+
test: (node) => node.async === true,
|
|
2344
|
+
},
|
|
2345
|
+
{
|
|
2346
|
+
feature: 'AsyncFunctionExpression',
|
|
2347
|
+
label: 'async functions',
|
|
2348
|
+
suggestion: 'SFMC SSJS does not support Promises or async/await.',
|
|
2349
|
+
nodeType: 'FunctionExpression',
|
|
2350
|
+
test: (node) => node.async === true,
|
|
2351
|
+
},
|
|
2352
|
+
{
|
|
2353
|
+
feature: 'AwaitExpression',
|
|
2354
|
+
label: 'await expressions',
|
|
2355
|
+
suggestion: 'SFMC SSJS does not support Promises or async/await.',
|
|
2356
|
+
nodeType: 'AwaitExpression',
|
|
2357
|
+
},
|
|
2358
|
+
{
|
|
2359
|
+
feature: 'Generator',
|
|
2360
|
+
label: 'generator functions',
|
|
2361
|
+
suggestion: 'Use regular iteration patterns instead.',
|
|
2362
|
+
nodeType: 'FunctionDeclaration',
|
|
2363
|
+
test: (node) => node.generator === true,
|
|
2364
|
+
},
|
|
2365
|
+
{
|
|
2366
|
+
feature: 'YieldExpression',
|
|
2367
|
+
label: 'yield expressions',
|
|
2368
|
+
suggestion: 'Use regular iteration patterns instead.',
|
|
2369
|
+
nodeType: 'YieldExpression',
|
|
2370
|
+
},
|
|
2371
|
+
{
|
|
2372
|
+
feature: 'ImportDeclaration',
|
|
2373
|
+
label: 'ES module imports',
|
|
2374
|
+
suggestion: 'SFMC SSJS does not support ES modules.',
|
|
2375
|
+
nodeType: 'ImportDeclaration',
|
|
2376
|
+
},
|
|
2377
|
+
{
|
|
2378
|
+
feature: 'ExportNamedDeclaration',
|
|
2379
|
+
label: 'ES module exports',
|
|
2380
|
+
suggestion: 'SFMC SSJS does not support ES modules.',
|
|
2381
|
+
nodeType: 'ExportNamedDeclaration',
|
|
2382
|
+
},
|
|
2383
|
+
{
|
|
2384
|
+
feature: 'ExportDefaultDeclaration',
|
|
2385
|
+
label: 'ES module exports',
|
|
2386
|
+
suggestion: 'SFMC SSJS does not support ES modules.',
|
|
2387
|
+
nodeType: 'ExportDefaultDeclaration',
|
|
2388
|
+
},
|
|
2389
|
+
{
|
|
2390
|
+
feature: 'OptionalChaining',
|
|
2391
|
+
label: 'optional chaining (?.)',
|
|
2392
|
+
suggestion: 'Use explicit null checks instead.',
|
|
2393
|
+
nodeType: 'ChainExpression',
|
|
2394
|
+
},
|
|
2395
|
+
{
|
|
2396
|
+
feature: 'NullishCoalescing',
|
|
2397
|
+
label: 'nullish coalescing (??)',
|
|
2398
|
+
suggestion: 'Use a ternary or logical OR (||) instead.',
|
|
2399
|
+
nodeType: 'LogicalExpression',
|
|
2400
|
+
test: (node) => node.operator === '??',
|
|
2401
|
+
},
|
|
2402
|
+
{
|
|
2403
|
+
feature: 'DirectObjectReturn',
|
|
2404
|
+
label: 'direct object literal returns',
|
|
2405
|
+
suggestion: 'Assign the object to a variable first, then return the variable.',
|
|
2406
|
+
nodeType: 'ReturnStatement',
|
|
2407
|
+
test: (node) => node.argument && node.argument.type === 'ObjectExpression',
|
|
2408
|
+
},
|
|
2409
|
+
{
|
|
2410
|
+
feature: 'NewExpression',
|
|
2411
|
+
label: "the 'new' operator on user-defined constructors",
|
|
2412
|
+
suggestion:
|
|
2413
|
+
"May cause a 500 if the function uses the revealing module pattern " +
|
|
2414
|
+
"(var service = {...}; return service). " +
|
|
2415
|
+
"Ensure the function assigns to 'this' instead (this.service = {...}).",
|
|
2416
|
+
nodeType: 'NewExpression',
|
|
2417
|
+
test: (node) => {
|
|
2418
|
+
const NATIVE = ['Date', 'RegExp', 'Error', 'Object', 'Array', 'WSProxy'];
|
|
2419
|
+
return node.callee.type === 'Identifier' && NATIVE.indexOf(node.callee.name) === -1;
|
|
2420
|
+
},
|
|
2421
|
+
},
|
|
2422
|
+
];
|
|
2423
|
+
|
|
2424
|
+
// Build a quick-lookup map by AST node type for the ESLint rule
|
|
2425
|
+
export const unsupportedByNodeType = new Map();
|
|
2426
|
+
for (const entry of UNSUPPORTED_SYNTAX) {
|
|
2427
|
+
if (!unsupportedByNodeType.has(entry.nodeType)) {
|
|
2428
|
+
unsupportedByNodeType.set(entry.nodeType, []);
|
|
2429
|
+
}
|
|
2430
|
+
unsupportedByNodeType.get(entry.nodeType).push(entry);
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
// ── Polyfillable Array methods ────────────────────────────────────────────────
|
|
2434
|
+
// SFMC SSJS runs on an old ECMAScript 3/5 engine that lacks many Array methods.
|
|
2435
|
+
// Each entry below describes either a missing method (category: 'unavailable')
|
|
2436
|
+
// or one that exists natively but returns wrong results (category: 'broken').
|
|
2437
|
+
// The polyfill strings are rewritten originals based on patterns documented at
|
|
2438
|
+
// https://gortonington.com/javascript-array-methods-in-sfmc/
|
|
2439
|
+
|
|
2440
|
+
export const POLYFILLABLE_METHODS = [
|
|
2441
|
+
{
|
|
2442
|
+
method: 'copyWithin',
|
|
2443
|
+
owner: 'Array.prototype',
|
|
2444
|
+
isStatic: false,
|
|
2445
|
+
category: 'unavailable',
|
|
2446
|
+
ambiguousWithString: false,
|
|
2447
|
+
description: "Array.prototype.copyWithin is not available in SFMC SSJS.",
|
|
2448
|
+
polyfill:
|
|
2449
|
+
'Array.prototype.copyWithin = function (targetIndex, startIndex, count) {\n' +
|
|
2450
|
+
' var n = count || 1;\n' +
|
|
2451
|
+
' for (var i = 0; i < n; i++) {\n' +
|
|
2452
|
+
' this[targetIndex + i] = this[startIndex + i];\n' +
|
|
2453
|
+
' }\n' +
|
|
2454
|
+
' return this;\n' +
|
|
2455
|
+
'};',
|
|
2456
|
+
},
|
|
2457
|
+
{
|
|
2458
|
+
method: 'entries',
|
|
2459
|
+
owner: 'Array.prototype',
|
|
2460
|
+
isStatic: false,
|
|
2461
|
+
category: 'unavailable',
|
|
2462
|
+
ambiguousWithString: false,
|
|
2463
|
+
description: "Array.prototype.entries is not available in SFMC SSJS.",
|
|
2464
|
+
polyfill:
|
|
2465
|
+
'Array.prototype.entries = function () {\n' +
|
|
2466
|
+
' var index = 0;\n' +
|
|
2467
|
+
' var arr = this;\n' +
|
|
2468
|
+
' return {\n' +
|
|
2469
|
+
' next: function () {\n' +
|
|
2470
|
+
' if (index < arr.length) {\n' +
|
|
2471
|
+
' return { value: [index, arr[index++]], done: false };\n' +
|
|
2472
|
+
' }\n' +
|
|
2473
|
+
' return { done: true };\n' +
|
|
2474
|
+
' }\n' +
|
|
2475
|
+
' };\n' +
|
|
2476
|
+
'};',
|
|
2477
|
+
},
|
|
2478
|
+
{
|
|
2479
|
+
method: 'fill',
|
|
2480
|
+
owner: 'Array.prototype',
|
|
2481
|
+
isStatic: false,
|
|
2482
|
+
category: 'unavailable',
|
|
2483
|
+
ambiguousWithString: false,
|
|
2484
|
+
description: "Array.prototype.fill is not available in SFMC SSJS.",
|
|
2485
|
+
polyfill:
|
|
2486
|
+
'Array.prototype.fill = function (value, startIndex, endIndex) {\n' +
|
|
2487
|
+
' var start = startIndex || 0;\n' +
|
|
2488
|
+
' var end = (!endIndex || endIndex > this.length) ? this.length : endIndex;\n' +
|
|
2489
|
+
' for (var i = start; i < end; i++) {\n' +
|
|
2490
|
+
' this[i] = value;\n' +
|
|
2491
|
+
' }\n' +
|
|
2492
|
+
' return this;\n' +
|
|
2493
|
+
'};',
|
|
2494
|
+
},
|
|
2495
|
+
{
|
|
2496
|
+
method: 'filter',
|
|
2497
|
+
owner: 'Array.prototype',
|
|
2498
|
+
isStatic: false,
|
|
2499
|
+
category: 'unavailable',
|
|
2500
|
+
ambiguousWithString: false,
|
|
2501
|
+
description: "Array.prototype.filter is not available in SFMC SSJS.",
|
|
2502
|
+
polyfill:
|
|
2503
|
+
'Array.prototype.filter = function (predicate) {\n' +
|
|
2504
|
+
' if (typeof predicate !== \'function\') { return []; }\n' +
|
|
2505
|
+
' var result = [];\n' +
|
|
2506
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2507
|
+
' if (predicate(this[i], i, this)) { result.push(this[i]); }\n' +
|
|
2508
|
+
' }\n' +
|
|
2509
|
+
' return result;\n' +
|
|
2510
|
+
'};',
|
|
2511
|
+
},
|
|
2512
|
+
{
|
|
2513
|
+
method: 'find',
|
|
2514
|
+
owner: 'Array.prototype',
|
|
2515
|
+
isStatic: false,
|
|
2516
|
+
category: 'unavailable',
|
|
2517
|
+
ambiguousWithString: false,
|
|
2518
|
+
description: "Array.prototype.find is not available in SFMC SSJS.",
|
|
2519
|
+
polyfill:
|
|
2520
|
+
'Array.prototype.find = function (predicate) {\n' +
|
|
2521
|
+
' if (typeof predicate !== \'function\') { return undefined; }\n' +
|
|
2522
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2523
|
+
' if (predicate(this[i], i, this)) { return this[i]; }\n' +
|
|
2524
|
+
' }\n' +
|
|
2525
|
+
' return undefined;\n' +
|
|
2526
|
+
'};',
|
|
2527
|
+
},
|
|
2528
|
+
{
|
|
2529
|
+
method: 'findIndex',
|
|
2530
|
+
owner: 'Array.prototype',
|
|
2531
|
+
isStatic: false,
|
|
2532
|
+
category: 'unavailable',
|
|
2533
|
+
ambiguousWithString: false,
|
|
2534
|
+
description: "Array.prototype.findIndex is not available in SFMC SSJS.",
|
|
2535
|
+
polyfill:
|
|
2536
|
+
'Array.prototype.findIndex = function (predicate) {\n' +
|
|
2537
|
+
' if (typeof predicate !== \'function\') { return -1; }\n' +
|
|
2538
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2539
|
+
' if (predicate(this[i], i, this)) { return i; }\n' +
|
|
2540
|
+
' }\n' +
|
|
2541
|
+
' return -1;\n' +
|
|
2542
|
+
'};',
|
|
2543
|
+
},
|
|
2544
|
+
{
|
|
2545
|
+
method: 'forEach',
|
|
2546
|
+
owner: 'Array.prototype',
|
|
2547
|
+
isStatic: false,
|
|
2548
|
+
category: 'unavailable',
|
|
2549
|
+
ambiguousWithString: false,
|
|
2550
|
+
description: "Array.prototype.forEach is not available in SFMC SSJS.",
|
|
2551
|
+
polyfill:
|
|
2552
|
+
'Array.prototype.forEach = function (callback) {\n' +
|
|
2553
|
+
' if (typeof callback !== \'function\') { return; }\n' +
|
|
2554
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2555
|
+
' callback(this[i], i, this);\n' +
|
|
2556
|
+
' }\n' +
|
|
2557
|
+
'};',
|
|
2558
|
+
},
|
|
2559
|
+
{
|
|
2560
|
+
method: 'includes',
|
|
2561
|
+
owner: 'Array.prototype',
|
|
2562
|
+
isStatic: false,
|
|
2563
|
+
category: 'unavailable',
|
|
2564
|
+
ambiguousWithString: false,
|
|
2565
|
+
description: "Array.prototype.includes is not available in SFMC SSJS.",
|
|
2566
|
+
polyfill:
|
|
2567
|
+
'Array.prototype.includes = function (searchValue) {\n' +
|
|
2568
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2569
|
+
' if (this[i] === searchValue) { return true; }\n' +
|
|
2570
|
+
' }\n' +
|
|
2571
|
+
' return false;\n' +
|
|
2572
|
+
'};',
|
|
2573
|
+
},
|
|
2574
|
+
{
|
|
2575
|
+
method: 'indexOf',
|
|
2576
|
+
owner: 'Array.prototype',
|
|
2577
|
+
isStatic: false,
|
|
2578
|
+
category: 'unavailable',
|
|
2579
|
+
ambiguousWithString: true,
|
|
2580
|
+
description: "Array.prototype.indexOf is not available in SFMC SSJS.",
|
|
2581
|
+
polyfill:
|
|
2582
|
+
'Array.prototype.indexOf = function (searchValue, fromIndex) {\n' +
|
|
2583
|
+
' var start = fromIndex || 0;\n' +
|
|
2584
|
+
' for (var i = start; i < this.length; i++) {\n' +
|
|
2585
|
+
' if (this[i] === searchValue) { return i; }\n' +
|
|
2586
|
+
' }\n' +
|
|
2587
|
+
' return -1;\n' +
|
|
2588
|
+
'};',
|
|
2589
|
+
},
|
|
2590
|
+
{
|
|
2591
|
+
method: 'lastIndexOf',
|
|
2592
|
+
owner: 'Array.prototype',
|
|
2593
|
+
isStatic: false,
|
|
2594
|
+
category: 'broken',
|
|
2595
|
+
ambiguousWithString: true,
|
|
2596
|
+
description: "Array.prototype.lastIndexOf exists in SFMC SSJS but always returns -1. A polyfill is needed for correct results.",
|
|
2597
|
+
polyfill:
|
|
2598
|
+
'Array.prototype.lastIndexOf = function (searchValue, fromIndex) {\n' +
|
|
2599
|
+
' var start = (fromIndex !== undefined) ? fromIndex : this.length - 1;\n' +
|
|
2600
|
+
' for (var i = start; i >= 0; i--) {\n' +
|
|
2601
|
+
' if (this[i] === searchValue) { return i; }\n' +
|
|
2602
|
+
' }\n' +
|
|
2603
|
+
' return -1;\n' +
|
|
2604
|
+
'};',
|
|
2605
|
+
},
|
|
2606
|
+
{
|
|
2607
|
+
method: 'map',
|
|
2608
|
+
owner: 'Array.prototype',
|
|
2609
|
+
isStatic: false,
|
|
2610
|
+
category: 'unavailable',
|
|
2611
|
+
ambiguousWithString: false,
|
|
2612
|
+
description: "Array.prototype.map is not available in SFMC SSJS.",
|
|
2613
|
+
polyfill:
|
|
2614
|
+
'Array.prototype.map = function (callback) {\n' +
|
|
2615
|
+
' if (typeof callback !== \'function\') { return []; }\n' +
|
|
2616
|
+
' var result = [];\n' +
|
|
2617
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2618
|
+
' result.push(callback(this[i], i, this));\n' +
|
|
2619
|
+
' }\n' +
|
|
2620
|
+
' return result;\n' +
|
|
2621
|
+
'};',
|
|
2622
|
+
},
|
|
2623
|
+
{
|
|
2624
|
+
method: 'reduce',
|
|
2625
|
+
owner: 'Array.prototype',
|
|
2626
|
+
isStatic: false,
|
|
2627
|
+
category: 'unavailable',
|
|
2628
|
+
ambiguousWithString: false,
|
|
2629
|
+
description: "Array.prototype.reduce is not available in SFMC SSJS.",
|
|
2630
|
+
polyfill:
|
|
2631
|
+
'Array.prototype.reduce = function (callback, initialValue) {\n' +
|
|
2632
|
+
' if (typeof callback !== \'function\') { return initialValue; }\n' +
|
|
2633
|
+
' var accumulator = (arguments.length > 1) ? initialValue : this[0];\n' +
|
|
2634
|
+
' var startIndex = (arguments.length > 1) ? 0 : 1;\n' +
|
|
2635
|
+
' for (var i = startIndex; i < this.length; i++) {\n' +
|
|
2636
|
+
' accumulator = callback(accumulator, this[i], i, this);\n' +
|
|
2637
|
+
' }\n' +
|
|
2638
|
+
' return accumulator;\n' +
|
|
2639
|
+
'};',
|
|
2640
|
+
},
|
|
2641
|
+
{
|
|
2642
|
+
method: 'reduceRight',
|
|
2643
|
+
owner: 'Array.prototype',
|
|
2644
|
+
isStatic: false,
|
|
2645
|
+
category: 'unavailable',
|
|
2646
|
+
ambiguousWithString: false,
|
|
2647
|
+
description: "Array.prototype.reduceRight is not available in SFMC SSJS.",
|
|
2648
|
+
polyfill:
|
|
2649
|
+
'Array.prototype.reduceRight = function (callback, initialValue) {\n' +
|
|
2650
|
+
' if (typeof callback !== \'function\') { return initialValue; }\n' +
|
|
2651
|
+
' var accumulator = (arguments.length > 1) ? initialValue : this[this.length - 1];\n' +
|
|
2652
|
+
' var startIndex = (arguments.length > 1) ? this.length - 1 : this.length - 2;\n' +
|
|
2653
|
+
' for (var i = startIndex; i >= 0; i--) {\n' +
|
|
2654
|
+
' accumulator = callback(accumulator, this[i], i, this);\n' +
|
|
2655
|
+
' }\n' +
|
|
2656
|
+
' return accumulator;\n' +
|
|
2657
|
+
'};',
|
|
2658
|
+
},
|
|
2659
|
+
{
|
|
2660
|
+
method: 'some',
|
|
2661
|
+
owner: 'Array.prototype',
|
|
2662
|
+
isStatic: false,
|
|
2663
|
+
category: 'unavailable',
|
|
2664
|
+
ambiguousWithString: false,
|
|
2665
|
+
description: "Array.prototype.some is not available in SFMC SSJS.",
|
|
2666
|
+
polyfill:
|
|
2667
|
+
'Array.prototype.some = function (predicate) {\n' +
|
|
2668
|
+
' if (typeof predicate !== \'function\') { return false; }\n' +
|
|
2669
|
+
' for (var i = 0; i < this.length; i++) {\n' +
|
|
2670
|
+
' if (predicate(this[i], i, this)) { return true; }\n' +
|
|
2671
|
+
' }\n' +
|
|
2672
|
+
' return false;\n' +
|
|
2673
|
+
'};',
|
|
2674
|
+
},
|
|
2675
|
+
{
|
|
2676
|
+
method: 'splice',
|
|
2677
|
+
owner: 'Array.prototype',
|
|
2678
|
+
isStatic: false,
|
|
2679
|
+
category: 'broken',
|
|
2680
|
+
ambiguousWithString: false,
|
|
2681
|
+
description: "Array.prototype.splice exists in SFMC SSJS but ignores its first two parameters. A polyfill is needed for correct behavior.",
|
|
2682
|
+
polyfill:
|
|
2683
|
+
'Array.prototype.splice = function (startIndex, deleteCount) {\n' +
|
|
2684
|
+
' var arr = this;\n' +
|
|
2685
|
+
' var endIndex = startIndex + deleteCount;\n' +
|
|
2686
|
+
' var before = [];\n' +
|
|
2687
|
+
' var removed = [];\n' +
|
|
2688
|
+
' var after = [];\n' +
|
|
2689
|
+
' for (var i = 0; i < arr.length; i++) {\n' +
|
|
2690
|
+
' if (i < startIndex) { before.push(arr[i]); }\n' +
|
|
2691
|
+
' else if (i < endIndex) { removed.push(arr[i]); }\n' +
|
|
2692
|
+
' else { after.push(arr[i]); }\n' +
|
|
2693
|
+
' }\n' +
|
|
2694
|
+
' for (var j = 2; j < arguments.length; j++) {\n' +
|
|
2695
|
+
' before.push(arguments[j]);\n' +
|
|
2696
|
+
' }\n' +
|
|
2697
|
+
' var merged = before.concat(after);\n' +
|
|
2698
|
+
' var maxLen = arr.length > merged.length ? arr.length : merged.length;\n' +
|
|
2699
|
+
' for (var k = 0; k < maxLen; k++) {\n' +
|
|
2700
|
+
' if (k < merged.length) { arr[k] = merged[k]; }\n' +
|
|
2701
|
+
' else { arr.pop(); }\n' +
|
|
2702
|
+
' }\n' +
|
|
2703
|
+
' return removed;\n' +
|
|
2704
|
+
'};',
|
|
2705
|
+
},
|
|
2706
|
+
{
|
|
2707
|
+
method: 'trim',
|
|
2708
|
+
owner: 'String.prototype',
|
|
2709
|
+
isStatic: false,
|
|
2710
|
+
category: 'unavailable',
|
|
2711
|
+
ambiguousWithString: false,
|
|
2712
|
+
description: "String.prototype.trim is not available in SFMC SSJS.",
|
|
2713
|
+
polyfill:
|
|
2714
|
+
'String.prototype.trim = function () {\n' +
|
|
2715
|
+
' return this.replace(/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g, \'\');\n' +
|
|
2716
|
+
'};',
|
|
2717
|
+
},
|
|
2718
|
+
{
|
|
2719
|
+
method: 'startsWith',
|
|
2720
|
+
owner: 'String.prototype',
|
|
2721
|
+
isStatic: false,
|
|
2722
|
+
category: 'unavailable',
|
|
2723
|
+
ambiguousWithString: false,
|
|
2724
|
+
description: "String.prototype.startsWith is not available in SFMC SSJS.",
|
|
2725
|
+
polyfill:
|
|
2726
|
+
'String.prototype.startsWith = function (searchString, position) {\n' +
|
|
2727
|
+
' position = position || 0;\n' +
|
|
2728
|
+
' return this.indexOf(searchString, position) === position;\n' +
|
|
2729
|
+
'};',
|
|
2730
|
+
},
|
|
2731
|
+
{
|
|
2732
|
+
method: 'endsWith',
|
|
2733
|
+
owner: 'String.prototype',
|
|
2734
|
+
isStatic: false,
|
|
2735
|
+
category: 'unavailable',
|
|
2736
|
+
ambiguousWithString: false,
|
|
2737
|
+
description: "String.prototype.endsWith is not available in SFMC SSJS.",
|
|
2738
|
+
polyfill:
|
|
2739
|
+
'String.prototype.endsWith = function (search, length) {\n' +
|
|
2740
|
+
' var len = (length === undefined || length > this.length) ? this.length : length;\n' +
|
|
2741
|
+
' return this.substring(len - search.length, len) === search;\n' +
|
|
2742
|
+
'};',
|
|
2743
|
+
},
|
|
2744
|
+
{
|
|
2745
|
+
method: 'isArray',
|
|
2746
|
+
owner: 'Array',
|
|
2747
|
+
isStatic: true,
|
|
2748
|
+
category: 'unavailable',
|
|
2749
|
+
ambiguousWithString: false,
|
|
2750
|
+
description: "Array.isArray is not available in SFMC SSJS.",
|
|
2751
|
+
polyfill:
|
|
2752
|
+
'Array.isArray = function (value) {\n' +
|
|
2753
|
+
' return Object.prototype.toString.call(value) === \'[object Array]\';\n' +
|
|
2754
|
+
'};',
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
method: 'of',
|
|
2758
|
+
owner: 'Array',
|
|
2759
|
+
isStatic: true,
|
|
2760
|
+
category: 'unavailable',
|
|
2761
|
+
ambiguousWithString: false,
|
|
2762
|
+
description: "Array.of is not available in SFMC SSJS.",
|
|
2763
|
+
polyfill:
|
|
2764
|
+
'Array.of = function () {\n' +
|
|
2765
|
+
' var result = [];\n' +
|
|
2766
|
+
' for (var i = 0; i < arguments.length; i++) {\n' +
|
|
2767
|
+
' result.push(arguments[i]);\n' +
|
|
2768
|
+
' }\n' +
|
|
2769
|
+
' return result;\n' +
|
|
2770
|
+
'};',
|
|
2771
|
+
},
|
|
2772
|
+
];
|
|
2773
|
+
|
|
2774
|
+
// Pre-built lookups for the ESLint rule — keyed by method name
|
|
2775
|
+
export const polyfillByPrototypeName = new Map();
|
|
2776
|
+
export const polyfillByStaticName = new Map();
|
|
2777
|
+
for (const entry of POLYFILLABLE_METHODS) {
|
|
2778
|
+
if (entry.isStatic) {
|
|
2779
|
+
polyfillByStaticName.set(entry.method, entry);
|
|
2780
|
+
} else {
|
|
2781
|
+
polyfillByPrototypeName.set(entry.method, entry);
|
|
2782
|
+
}
|
|
2783
|
+
}
|