Skip to content

Smaller logging and setup improvements #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
ehthumbs.db
Thumbs.db

# Custom #
######################
*.conf
*lib_le.js
*lib_luxapi.js

.vscode/
tests.ssjs
*ssjs-vsc.json

testing/*
Empty file added CHANGELOG.md
Empty file.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
163 changes: 49 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,29 @@
<p align="center">
<a href="https://email360.io/">
<img src="https://blog.email360.io/images/logo_dark.png" alt="email360 logo" width="400" height="223">
</a>
</p>
<p align="center">
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.
<br><br>
Separate version of the [SSJS Lib by Email360](https://github.com/email360/ssjs-lib) that includes some changes from the original library.
<br>
<br>
<a href="https://docs.email360.io/">Explore the Docs</a>
·
<a href="https://email360.io/#contact">Get in touch</a>
·
<a href="https://blog.email360.io/">email360 Blog</a>
.
<a href="https://www.youtube.com/channel/UCCo1dWV3E3WipnqhOKynfGg">email360 Youtube</a>
</p>

<br/>

## Support
<p>
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.

<a href='https://ko-fi.com/N4N3BP9OD' target="_blank"><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
</p>

<br/>

## 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)

<br/>

## 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'))=%%
```
<br/>
Please watch the following video for a full guide on the installation of the SSJS Library.<br/>
The following video (by Email360) for a full guide on the installation of the SSJS Library.<br/>

[![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 <https://raw.githubusercontent.com/email360/ssjs-lib/master/setup/setup.ssjs>

<br>
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).
<br><br>

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
<!-- TODO: include individual loaders: -->
```javascript
Platform.Load("Core", "1");
Platform.Function.ContentBlockByKey('[prefix]-ssjs-lib-[version]');
Expand All @@ -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
```

<br/>

## Changelog
<details>
<summary>Version 1.01</summary>

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
</details>

<br/>
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).
<!-- - simplified folder structure. -->
<!-- - conditional import of the libraries -->
<!-- - unit tests library -->
<!-- - update mechanism for code -->

## Documentation

Expand All @@ -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 <https://github.com/email360/ssjs-lib>
Email360's SSJS Lib can be found at <https://github.com/FiB3/ssjs-lib>

Email 360 Youtube channel for some guides: <a href="https://www.youtube.com/channel/UCCo1dWV3E3WipnqhOKynfGg">email360 Youtube</a>


<br/>
Expand All @@ -150,9 +100,9 @@ Email360's SSJS Lib can be found at <https://github.com/email360/ssjs-lib>

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)

Expand All @@ -164,21 +114,6 @@ We welcome all who want to contribute to this repository, to contribute please f

<br/>

## 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/)**

<br/>

## 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).
28 changes: 20 additions & 8 deletions core/lib_core.ssjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

Expand Down Expand Up @@ -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' );
}

Expand Down Expand Up @@ -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];

Expand All @@ -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;
});
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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('<script>console.log.apply(console,' + Platform.Function.Stringify(Array.from(arguments)) + ')<\/script>');
};
this.error = function() {
if (this.muted) { return; }
Write('<script>console.error.apply(console,' + Platform.Function.Stringify(Array.from(arguments)) + ')<\/script>');
}
this.info = function() {
if (this.muted) { return; }
Write('<script>console.info.apply(console,' + Platform.Function.Stringify(Array.from(arguments)) + ')<\/script>');
}
this.debug = function() {
if (this.muted) { return; }
Write('<script>console.debug.apply(console,' + Platform.Function.Stringify(Array.from(arguments)) + ')<\/script>');
}
this.warn = function() {
if (this.muted) { return; }
Write('<script>console.warn.apply(console,' + Platform.Function.Stringify(Array.from(arguments)) + ')<\/script>');
}
}
Expand All @@ -507,15 +519,15 @@ function debug(message) {
var message = (typeof message === 'string') ? message.replace(/<script[\s\S]*?>/gi, '').replace(/<\/script>/gi, '') : message;

if( Array.isArray(debugMode) ) {
if(debugMode.includes('console')) {
if(includes(debugMode, 'console')) {
var console = new console();
console.log(message);
}
if(debugMode.includes('html')) {
if(includes(debugMode, 'html')) {
var m = (typeof message == 'string') ? message.replace('\n', '<br/>').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp') : Platform.Function.Stringify(message);
Platform.Response.Write('<pre style="margin:0.85em 0px;"><span style="font-size: 11px;">'+m+'</span></pre>');
}
if(debugMode.includes('text')) {
if(includes(debugMode, 'text')) {
Platform.Response.Write('{'+Platform.Function.Stringify(message)+'}\n');
}
}
Expand Down
Loading