diff --git a/.gitignore b/.gitignore index d650656..6d3c197 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,14 @@ ehthumbs.db Thumbs.db +# Custom # +###################### *.conf *lib_le.js *lib_luxapi.js + +.vscode/ +tests.ssjs +*ssjs-vsc.json + +testing/* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE index 61e73ef..6fbe0f3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Email360 +Copyright (c) 2020 Email360, changes by fibWorks (c) 2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 945dbc1..38c43e2 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,29 @@

- - email360 logo - -

-

- A sleek and powerful library for faster and easier development in Salesforce Marketing Cloud ©. + This library aims at making your SSJS implementations faster, more secure and stable. +

+ Separate version of the [SSJS Lib by Email360](https://github.com/email360/ssjs-lib) that includes some changes from the original library.
-
- Explore the Docs - · - Get in touch - · - email360 Blog - . - email360 Youtube -

- -
- -## Support -

- This library is open source and free to use for the community. If you find this library helpful and want to support me, please feel free to grab me a coffee for the late night grinds. Your support is greatly appreciated. - - Buy Me a Coffee at ko-fi.com

-
- -## Table of contents - -- [Quick start](#quick-start) -- [What's installed](#whats-installed) -- [Changelog](#changelog) -- [Documentation](#documentation) -- [Code](#code) -- [Contributing](#contributing) -- [Thanks](#thanks) -- [Copyright and licence](#copyright-and-licence) - -
- ## Quick start To install the Email360 ssjs-lib into your project create a Cloudpage and insert the following code: ```javascript -%%=TreatAsContent(HTTPGet('https://raw.githubusercontent.com/email360/ssjs-lib/master/setup/setup.ssjs'))=%% +%%=TreatAsContent(HTTPGet('https://raw.githubusercontent.com/FiB3/ssjs-lib/refs/heads/master/setup/setup.ssjs'))=%% ```
-Please watch the following video for a full guide on the installation of the SSJS Library.
+The following video (by Email360) for a full guide on the installation of the SSJS Library.
[![Instal the SSJS LIB](https://img.youtube.com/vi/0ErmyPvmVVM/0.jpg)](https://www.youtube.com/watch?v=0ErmyPvmVVM) - -All steps are optional and if you experience a timeout refresh the page. - -> Details of the script that is run for installation can be found at - +
+It is also possible to install this library manually by manully copying the required resources to your SFMC instance (Data Extensions, Content Blocks with the lib, creating keys).

+ After the installation add the following code at the top of your script to get started. Change the prefix and version as desired. Default is email360 and version 1.0.1 + ```javascript Platform.Load("Core", "1"); Platform.Function.ContentBlockByKey('[prefix]-ssjs-lib-[version]'); @@ -73,64 +37,48 @@ After executing the installation process you'll find the following directories a ```text Marketing Cloud/ ├── Data Extensions/ -│ └── [BRAND NAME]/ -│ └── SSJS Lib/ -│ └── [VERSION] -│ ├── SSJS Lib - Auth Users - [VERSION]_[BRAND NAME] -│ ├── SSJS Lib - Authentication - [VERSION]_[BRAND NAME] -│ ├── SSJS Lib - Log Error - [VERSION]_[BRAND NAME] -│ ├── SSJS Lib - Log Warning - [VERSION]_[BRAND NAME] -│ ├── SSJS Lib - SFMC Api Token - [VERSION]_[BRAND NAME] -│ └── SSJS Lib - WSProxy Cols - [VERSION]_[BRAND NAME] +│ └── SSJS Lib/ +│ ├── SSJS Lib - Auth Users - [VERSION]_[BRAND NAME] +│ ├── SSJS Lib - Authentication - [VERSION]_[BRAND NAME] +│ ├── SSJS Lib - Log Error - [VERSION]_[BRAND NAME] +│ ├── SSJS Lib - Log Warning - [VERSION]_[BRAND NAME] +│ ├── SSJS Lib - SFMC Api Token - [VERSION]_[BRAND NAME] +│ └── SSJS Lib - WSProxy Cols - [VERSION]_[BRAND NAME] │ └── Content Builder/ - └── [BRAND NAME]/ - └── SSJS Lib/ - └── [VERSION] - ├── CloudPages/ - │ ├── Error/ - │ │ └── Error Page - │ └── Login/ - │ └── Login Page - └── Lib/ - ├── SSJS Lib - settings - ├── SSJS Lib - cloudpage - ├── SSJS Lib - amp - ├── SSJS Lib - wsproxy - ├── SSJS Lib - core - ├── SSJS Lib - polyfill - ├── SSJS Lib - einstein - └── SSJS Lib - sfmcapi + └── SSJS Lib/ + ├── CloudPages/ + │ ├── Error Page + │ └── Login Page + └── Lib/ + ├── SSJS Lib - settings + ├── SSJS Lib - standard + ├── SSJS Lib - cloudpage + ├── SSJS Lib - amp + ├── SSJS Lib - wsproxy + ├── SSJS Lib - core + ├── SSJS Lib - polyfill + ├── SSJS Lib - einstein + └── SSJS Lib - sfmcapi ```
## Changelog -
- Version 1.01 - - 1. Introducing versions. Versions will be added to customer keys and DataExtension names. This will allow you to install newer versions of the library without any possible issues on existing code due to backward compatibility. - 2. Added JWT support. A new `script` has been added: `var jwt = new jwt();` - * jwt.encode(); - * jwt.decode(); - * jwt.verify(); - 3. Introducing log4ssjs to the SSJS library. Similar to log4js but different... - * `var log = new logger('name')`; - * `log.level = "DEBUG"`; - * Additionally you can set appenders. - * `log.configure = {appenders:[ {type:"dataExtension",level:"INFO"}, {type:"console",level:"TRACE"}]}` - * Currently supported - * console - * json - * html - * DataExtension - * HTTPRequest - * TriggeredSend - 4. Removed script tags from library files for better lint support in vs-code - 5. Introduce a setup wizard to assist with installation -
-
+Notable changes will be included in `Changelog.md`. + +This section will focus on main changes and additions against the original library: + + + + +- All polyfills are included as optional, as these break standard SSJS functions. +- `Standard` lib is implemented and it contains replacements for all the polyfills (in lodash style). + + + + ## Documentation @@ -141,7 +89,9 @@ For any tips and tricks please head over to the [email360 youtube channel](https ## Code -Email360's SSJS Lib can be found at +Email360's SSJS Lib can be found at + +Email 360 Youtube channel for some guides: email360 Youtube
@@ -150,9 +100,9 @@ Email360's SSJS Lib can be found at We welcome all who want to contribute to this repository, to contribute please follow these guidelines. -1. Fork the repo and create your branch from `master`. A guide on how to fork a repository can be found [here](https://help.github.com/articles/fork-a-repo/). +1. Fork the repo and create your branch from `master`. -2. Make your changes, test where/if possible. +2. Make your changes, test where/if possible. Use JSDoc strings to document all functions. 3. If your changes alter the behaviour of any of the code, update the corresponding comments within the codebase. The updated comment will then be used to update the documentation found within our [docs](https://docs.email360.io) @@ -164,21 +114,6 @@ We welcome all who want to contribute to this repository, to contribute please f
-## Thanks - -This library would not have been possible without the [Salesforce Marketing Cloud ©](https://www.salesforce.com/products/marketing-cloud/) community. Ohana! - -Special thanks to the following people for their active contribution to the community: - -**[Ivan Razine](https://www.linkedin.com/in/ivanrazine/)**, -**[Adam Spriggs](https://www.linkedin.com/in/adamspriggs/)**, -**[Zuzanna Jarczynska](https://www.linkedin.com/in/zuzannajarczynska/)**, -**[Eliot Harper](https://www.linkedin.com/in/eliot/)**, -**[Mateusz Dąbrowski](https://www.linkedin.com/in/mateusz-dabrowski-marketing/)**, -**[Gregory (Gortonington) Gifford](https://www.linkedin.com/in/gregory-gortonington-gifford-238a0625/)** - -
- ## Copyright and licence -Code and documentation copyright 2020 the email360 SSJS Lib under the [MIT License](https://github.com/email360/ssjs-lib/blob/master/LICENSE). +Code and documentation copyright 2020 the email360 SSJS Lib and 2024 by FiB under the [MIT License](https://github.com/email360/ssjs-lib/blob/master/LICENSE). \ No newline at end of file diff --git a/core/lib_core.ssjs b/core/lib_core.ssjs index 2842f93..e386792 100644 --- a/core/lib_core.ssjs +++ b/core/lib_core.ssjs @@ -140,7 +140,7 @@ function dateAdd(dt, number, unit) { validUnits = ['Seconds','Minutes','Hours','Days','Months','Years'], date = new Date(dt); - if(!validUnits.includes(u)) { + if(!includes(validUnits, u)) { debug('(dateAdd)\n\tUnit not allowed: '+u+'. Use Hours instead' ); } @@ -183,7 +183,7 @@ function dateSubtract(dt, number, unit) { validUnits = ['Seconds','Minutes','Hours','Days','Months','Years'], date = new Date(dt); - if(!validUnits.includes(u)) { + if(!includes(validUnits, u)) { debug('(dateSubtract)\n\tUnit not allowed: '+u+'. Use Hours instead' ); } @@ -321,7 +321,7 @@ function timeConvert(m) { function groupBy(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by // reduce runs this anonymous function on each element of `data` (the `item` parameter, // returning the `storage` parameter at the end - return data.reduce(function(storage, item) { + return reduce(data, function(storage, item) { // get the first instance of the key by which we're grouping var group = item[key]; @@ -345,7 +345,7 @@ function groupBy(data, key) { // `data` is an array of objects, `key` is the key * @returns {boolean} */ function inObject(needle,haystack) { - return Object.keys(haystack).some(function(k) { + return some(Object.keys(haystack), function(k) { return obj[k] === needle; }); } @@ -435,7 +435,7 @@ function shuffle(a) { function deleteArrayItem(array, item) { for (var k = 0; k < array.length; k++) { if( array[k] == item ) { - array.splice(k, 1); + splice(array, k, 1); } } return array; @@ -479,20 +479,32 @@ function getMemberID() { * console.debug('My Test Debug'); */ function console() { + this.mute = function() { + this.muted = true; + }; + + this.unmute = function() { + this.muted = false; + }; this.log = function() { + if (this.muted) { return; } Write('