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/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# ssjs-data
|
|
2
|
+
|
|
3
|
+
Canonical SSJS (Server-Side JavaScript) function catalog, Core library objects, Platform methods, and globals for Salesforce Marketing Cloud (SFMC) tooling.
|
|
4
|
+
|
|
5
|
+
This package is the single source of truth consumed by:
|
|
6
|
+
|
|
7
|
+
- [eslint-plugin-sfmc](https://www.npmjs.com/package/eslint-plugin-sfmc) — globals registration, unknown-function detection, platform-load checks
|
|
8
|
+
- [prettier-plugin-sfmc](https://www.npmjs.com/package/prettier-plugin-sfmc) — language registration
|
|
9
|
+
- [VSCode: sfmc-language](https://marketplace.visualstudio.com/items?itemName=joernberkefeld.sfmc-language) — completions, hover, and diagnostics
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install ssjs-data
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import {
|
|
21
|
+
SSJS_GLOBALS,
|
|
22
|
+
SSJS_GLOBALS_MAP,
|
|
23
|
+
PLATFORM_METHODS,
|
|
24
|
+
PLATFORM_FUNCTIONS,
|
|
25
|
+
platformFunctionLookup,
|
|
26
|
+
platformFunctionNames,
|
|
27
|
+
CORE_LIBRARY_OBJECTS,
|
|
28
|
+
coreObjectNames,
|
|
29
|
+
coreObjectLookup,
|
|
30
|
+
HTTP_METHODS,
|
|
31
|
+
httpMethodNames,
|
|
32
|
+
WSPROXY_METHODS,
|
|
33
|
+
wsproxyMethodNames,
|
|
34
|
+
SCRIPT_UTIL_CONSTRUCTORS,
|
|
35
|
+
SCRIPT_UTIL_REQUEST_METHODS,
|
|
36
|
+
ECMASCRIPT_BUILTINS,
|
|
37
|
+
UNSUPPORTED_SYNTAX,
|
|
38
|
+
unsupportedByNodeType,
|
|
39
|
+
POLYFILLABLE_METHODS,
|
|
40
|
+
polyfillByPrototypeName,
|
|
41
|
+
polyfillByStaticName,
|
|
42
|
+
} from 'ssjs-data';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `SSJS_GLOBALS` / `SSJS_GLOBALS_MAP`
|
|
46
|
+
|
|
47
|
+
Global functions and objects available at the top scope of any SSJS execution context (no `Platform.Load` required):
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { SSJS_GLOBALS, SSJS_GLOBALS_MAP } from 'ssjs-data';
|
|
51
|
+
|
|
52
|
+
for (const global of SSJS_GLOBALS) {
|
|
53
|
+
console.log(global.name); // e.g. 'Write', 'Stringify'
|
|
54
|
+
console.log(global.type); // 'function' | 'object'
|
|
55
|
+
console.log(global.description);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// SSJS_GLOBALS_MAP is shaped for ESLint's globals config:
|
|
59
|
+
// { Write: 'readonly', Platform: 'readonly', ... }
|
|
60
|
+
console.log(SSJS_GLOBALS_MAP['Write']); // 'readonly'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `PLATFORM_METHODS`
|
|
64
|
+
|
|
65
|
+
Top-level `Platform.*` methods (e.g. `Platform.Load`):
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { PLATFORM_METHODS } from 'ssjs-data';
|
|
69
|
+
|
|
70
|
+
for (const method of PLATFORM_METHODS) {
|
|
71
|
+
console.log(method.name); // e.g. 'Load'
|
|
72
|
+
console.log(method.syntax); // e.g. 'Platform.Load(libraryName, version)'
|
|
73
|
+
console.log(method.minArgs);
|
|
74
|
+
console.log(method.maxArgs);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `PLATFORM_FUNCTIONS` / `platformFunctionLookup` / `platformFunctionNames`
|
|
79
|
+
|
|
80
|
+
The `Platform.Function.*` catalog — available without `Platform.Load`:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { PLATFORM_FUNCTIONS, platformFunctionLookup, platformFunctionNames } from 'ssjs-data';
|
|
84
|
+
|
|
85
|
+
// Full catalog
|
|
86
|
+
for (const fn of PLATFORM_FUNCTIONS) {
|
|
87
|
+
console.log(fn.name); // e.g. 'Lookup'
|
|
88
|
+
console.log(fn.minArgs);
|
|
89
|
+
console.log(fn.maxArgs);
|
|
90
|
+
console.log(fn.description);
|
|
91
|
+
console.log(fn.params); // array of { name, description, type?, optional? }
|
|
92
|
+
console.log(fn.returnType);
|
|
93
|
+
console.log(fn.syntax);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// O(1) lookup by lowercase name
|
|
97
|
+
const entry = platformFunctionLookup.get('lookup');
|
|
98
|
+
|
|
99
|
+
// Existence check
|
|
100
|
+
if (platformFunctionNames.has('lookup')) { /* ... */ }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `CORE_LIBRARY_OBJECTS` / `coreObjectNames` / `coreObjectLookup`
|
|
104
|
+
|
|
105
|
+
Objects that require `Platform.Load("core", "1")` before use (e.g. `DataExtension`, `Subscriber`):
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
import { CORE_LIBRARY_OBJECTS, coreObjectNames, coreObjectLookup } from 'ssjs-data';
|
|
109
|
+
|
|
110
|
+
for (const obj of CORE_LIBRARY_OBJECTS) {
|
|
111
|
+
console.log(obj.name); // e.g. 'DataExtension', 'DataExtension.Rows'
|
|
112
|
+
console.log(obj.methods); // e.g. ['Init', 'Add', 'Remove', 'Update', 'Retrieve']
|
|
113
|
+
console.log(obj.description);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Existence check
|
|
117
|
+
if (coreObjectNames.has('DataExtension')) { /* ... */ }
|
|
118
|
+
|
|
119
|
+
// O(1) lookup
|
|
120
|
+
const de = coreObjectLookup.get('DataExtension');
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### `HTTP_METHODS` / `httpMethodNames`
|
|
124
|
+
|
|
125
|
+
Methods available on the `HTTP` platform object:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { HTTP_METHODS, httpMethodNames } from 'ssjs-data';
|
|
129
|
+
|
|
130
|
+
for (const method of HTTP_METHODS) {
|
|
131
|
+
console.log(method.name); // e.g. 'Get', 'Post'
|
|
132
|
+
console.log(method.syntax);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (httpMethodNames.has('get')) { /* ... */ }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `WSPROXY_METHODS` / `wsproxyMethodNames`
|
|
139
|
+
|
|
140
|
+
SOAP API methods available on the `WSProxy` object:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
import { WSPROXY_METHODS, wsproxyMethodNames } from 'ssjs-data';
|
|
144
|
+
|
|
145
|
+
for (const method of WSPROXY_METHODS) {
|
|
146
|
+
console.log(method.name); // e.g. 'retrieve', 'create', 'update'
|
|
147
|
+
console.log(method.syntax);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (wsproxyMethodNames.has('retrieve')) { /* ... */ }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `SCRIPT_UTIL_CONSTRUCTORS` / `SCRIPT_UTIL_REQUEST_METHODS`
|
|
154
|
+
|
|
155
|
+
`Script.Util` constructors (e.g. `Script.Util.HttpRequest`) and their instance methods:
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
import { SCRIPT_UTIL_CONSTRUCTORS, SCRIPT_UTIL_REQUEST_METHODS } from 'ssjs-data';
|
|
159
|
+
|
|
160
|
+
for (const ctor of SCRIPT_UTIL_CONSTRUCTORS) {
|
|
161
|
+
console.log(ctor.name); // e.g. 'HttpRequest'
|
|
162
|
+
console.log(ctor.returnType); // e.g. 'HttpRequest'
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (const method of SCRIPT_UTIL_REQUEST_METHODS) {
|
|
166
|
+
console.log(method.name); // e.g. 'send', 'setHeader'
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `ECMASCRIPT_BUILTINS`
|
|
171
|
+
|
|
172
|
+
ECMAScript built-in methods and properties supported by the SSJS engine:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { ECMASCRIPT_BUILTINS } from 'ssjs-data';
|
|
176
|
+
|
|
177
|
+
for (const builtin of ECMASCRIPT_BUILTINS) {
|
|
178
|
+
console.log(builtin.name); // e.g. 'push', 'slice'
|
|
179
|
+
console.log(builtin.owner); // e.g. 'Array', 'String', 'Math'
|
|
180
|
+
console.log(builtin.description);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `UNSUPPORTED_SYNTAX` / `unsupportedByNodeType`
|
|
185
|
+
|
|
186
|
+
JavaScript syntax constructs that the SSJS engine does not support:
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
import { UNSUPPORTED_SYNTAX, unsupportedByNodeType } from 'ssjs-data';
|
|
190
|
+
|
|
191
|
+
for (const item of UNSUPPORTED_SYNTAX) {
|
|
192
|
+
console.log(item.nodeType); // AST node type, e.g. 'ArrowFunctionExpression'
|
|
193
|
+
console.log(item.name); // human-readable name
|
|
194
|
+
console.log(item.description);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Keyed lookup by AST node type
|
|
198
|
+
const info = unsupportedByNodeType.get('ArrowFunctionExpression');
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `POLYFILLABLE_METHODS` / `polyfillByPrototypeName` / `polyfillByStaticName`
|
|
202
|
+
|
|
203
|
+
Methods that are absent from the SSJS engine but can be polyfilled:
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
import { POLYFILLABLE_METHODS, polyfillByPrototypeName, polyfillByStaticName } from 'ssjs-data';
|
|
207
|
+
|
|
208
|
+
for (const method of POLYFILLABLE_METHODS) {
|
|
209
|
+
console.log(method.name); // e.g. 'startsWith'
|
|
210
|
+
console.log(method.owner); // e.g. 'String'
|
|
211
|
+
console.log(method.description);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Lookup by prototype method name (e.g. 'startsWith')
|
|
215
|
+
const info = polyfillByPrototypeName.get('startsWith');
|
|
216
|
+
|
|
217
|
+
// Lookup by static invocation name (e.g. 'Array.isArray')
|
|
218
|
+
const info2 = polyfillByStaticName.get('Array.isArray');
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ssjs-data",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Canonical SSJS (Server-Side JavaScript) function catalog, Core library objects, Platform methods, and globals for SFMC tooling",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": ["src"],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/JoernBerkefeld/ssjs-data.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/JoernBerkefeld/ssjs-data/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/JoernBerkefeld/ssjs-data#readme",
|
|
19
|
+
"author": "Joern Berkefeld",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ssjs",
|
|
22
|
+
"sfmc",
|
|
23
|
+
"salesforce",
|
|
24
|
+
"marketing-cloud",
|
|
25
|
+
"server-side-javascript",
|
|
26
|
+
"wsproxy",
|
|
27
|
+
"platform-functions"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|