Git Product home page Git Product logo

email360 / ssjs-lib Goto Github PK

View Code? Open in Web Editor NEW
49.0 13.0 12.0 2.49 MB

An open-source library that takes the repetitive and complex tasks and simplifies them, enabling you to get the most out of Salesforce Marketing Cloud.

Home Page: http://www.email360.io

License: Other

JavaScript 100.00%
ssjs marketingcloud salesforce-developers salesforce salesforce-rest-api salesforce-api sfmc wsproxy javascript library

ssjs-lib's Introduction

email360 logo

A sleek and powerful library for faster and easier development in Salesforce Marketing Cloud ©.

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

To install the Email360 ssjs-lib into your project create a Cloudpage and insert the following code:

%%=TreatAsContent(HTTPGet('https://raw.githubusercontent.com/email360/ssjs-lib/master/setup/setup.ssjs'))=%%

Please watch the following video for a full guide on the installation of the SSJS Library.

Instal the SSJS LIB

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



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

    Platform.Load("Core", "1");
    Platform.Function.ContentBlockByKey('[prefix]-ssjs-lib-[version]');

What's installed

After executing the installation process you'll find the following directories and files, logically grouping common assets.

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]
│
└── 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

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

Documentation

Email360's SSJS Lib documentation can be found at https://docs.email360.io
For any tips and tricks please head over to the email360 youtube channel


Code

Email360's SSJS Lib can be found at https://github.com/email360/ssjs-lib


Contributing

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.

  2. Make your changes, test where/if possible.

  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

  4. Open a pull request against the master branch at https://github.com/email360/ssjs-lib.

  5. Leave a comment on the pull request stating the reason for the change.

  6. One of the administrators of email360/ssjs-lib will review your code, merge it or ask for changes.


Thanks

This library would not have been possible without the Salesforce Marketing Cloud © community. Ohana!

Special thanks to the following people for their active contribution to the community:

Ivan Razine, Adam Spriggs, Zuzanna Jarczynska, Eliot Harper, Mateusz Dąbrowski, Gregory (Gortonington) Gifford


Copyright and licence

Code and documentation copyright 2020 the email360 SSJS Lib under the MIT License.

ssjs-lib's People

Contributors

colins44 avatar jpaynesalesforce avatar shdinx avatar shdinx-2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssjs-lib's Issues

[Improvement Request] Allow DE creation to be at shared/enterprise level

Hey there !

Thanks for this awesome tool ! I cannot say enough how much I was frustrated by the limitations of SSJS and I found the holy grail with your repo 😃

I work for a big company that have a lot of BUs (44) and I wonderred if that could be a thing to make the installation process ask you if you want the DEs to be installed in the shared folder so that we can log everything at the same place and not have to do the install process on every BU's

Typo in DataExtension Verion

Thanks for this library, it looks really useful to simplify the code needs to be written.

While looking at the setup page I found that there is a missing s in DataExtension Verion in setup.ssjs.

Question: Where can the test files be found? I'd be interested in your testing method of SSJS code.

Jint exception - Unknown type or Object expected

Note to the maintainer(s): Logging this as a combined issue + solution for anyone else that encounters it, feel free to close this immediately or make it a documentation update issue!

If you are attempting to test your SSJS-lib installation via a CloudPage and see an error in the preview after clicking "Schedule/Publish", do not assume that there will be an error in the actual published version of the CloudPage! In particular, the 'Unknown type' and 'Object expected' exceptions can be incorrect. The preview environment does not appear to add globally-scoped functions and vars defined in recursive scripts to the global scope, unlike the published environment.

Issue with JWT sign function

There is an issue with this sign function.
You parse the JSON and then stringify it again, while this is unnecessary, it might also alter the payload.
Like changing the order of properties or losing serialization information like newlines or whitespaces.
Hence the signature will inevitably change and won't match the original.

(The same issue can happen with the header, but sadly you have no control over that.)

https://github.com/email360/ssjs-lib/blob/master/core/lib_jwt.ssjs#L184-L191

Object expected error

Hi,

First of all thank you for this great library. I have just started using it but I am running into an issue when using any DE function, e.g. copyDataExtension. It gives me the error below. I tried several different DEs, sendable non-sendable, etc. Any idea what causes this and how I can fix it?

{{"message":"Object expected: copyDataExtension","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(ExpressionStatement statement)\r\n at Jint.Expressions.ExpressionStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: copyDataExtension\r\nException of type 'Jint.Native.JsException' was thrown. - from Jint\r\n\r\n"}} asdasdas

[Feature] Call Salesforce Core Rest API

I would like to use this library to also call Salesforce Core REST apis.

An implementation of this would likely follow the same pattern as sfmcapi
var sfapi = new sfCoreApi();

The main reason for this is to be able to Bulk v2 record request so one is inline with best practises to not use as many API requests as one would with UpdateSingleSalesforceObject.

I'm happy to start on coding this if there is an interest to add it to ssjs-lib.

Array polyfill brings out the "toLowerCase" error

I ran into the same issue described here, but when the SSJS code has a call to DataExtension.Retrieve.

It is unrelated to the test value, it happens if these 2 conditions met:

  • Assign a value to Array.prototype.<anything>, number, function, etc...does not matter
  • Invoke DataExtension.Retrieve

Also DataExtension.Rows.Retrieve will not return any rows if the polyfills are installed (not just yours, any on Array).

My suspicion is that DataExtension related JS->.Net bindings are only loaded/executed when any method is used on that object and the SFMC JS has a bug for Retrieve, namely that CustomerKey MUST be queried, or internally there is no de.CustomerKey found and it is not checked obviously...because at one of the stellar constellation I was able to get this stacktrace, which included the source line somehow:

Jint.JintException: Object expected: toLowerCase
Line: 544 Char: 16
this._namesFromKeys[de.CustomerKey.toLowerCase()] = de.Name
 - from Jint --> 

 --- inner exception 6---

Jint.Native.JsException: Object expected: toLowerCase
Exception of type 'Jint.Native.JsException' was thrown. - from Jint

Did you find any way to work around it, because it seems that this way the email360 lib is not loadable when you use DataExtension methods.

So if someone using the email360 library, then DataExtension methods starting to fail.

What would you think about as a fix to introduce an ArrayEx type, which can have Array's prototype and extend that with the new methods?

Q: are you shd.lux on MC stackoverflow?

SSJS has a non-efficient setup

Long story, but more or less, using a text field of length 4000, as part of a Primary Key, violates PK maximum lengths allowed. There are more issues as well, which I can explain if you wish to discuss it further (but should not be done in a public forum). Reach out to me: [email protected]

More or less this automatic declaration of the long text field as part of a PK is causing issues and so going forward anyone using this cannot have those fields as part of PK. For cleanup, I need to now go through and drop the PKs on all the Data Extensions created from this script and then rebuild them, so they do not include "message".

See this code, and if line 256 could be changed to be this:
{ "Name": "message", "FieldType": "Text", "MaxLength": 4000, "IsRequired": true },
That would fix the issue for anyone using the code going forward.

Thank you. Reach out to discuss please.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.