Giter Club home page Giter Club logo

salesforce-commerce-cloud-libraries's Introduction

JS Libraries for Salesforce Commerce Cloud B2C

This repository contains libraries converted and tested to work with the latest version of Salesforce Commerce Cloud B2C (Formerly Demandware).

The libraries converted/tested here are to enhance the developer experience in the back-end and to speed up development.

Certain libraries don't work because of functions that are available in, for example, Node.JS but don't work in Salesforce Commerce Cloud because of slight differences in syntax or the unavailability of certain Objects.

With this project I hope to convert some of these libraries to work with Salesforce Commerce Cloud B2C.

Converted libraries

  • Moment.js
  • Lodash
  • date-fns
  • fast-xml-parser
  • chance
  • ramda
  • jsPDF

Setting up the libraries in your project

  • Download and unpack repo content
  • Copy the library folders in the "cartridges" to your project (this to get Intellisense since the "require" syntax is different from the official library in most cases.)
  • Upload it to the dev boxes, demo, staging, development & production

Note: You do not need to add the libraries to the cartridge path if you put them on the same level as the other cartridges.

You can write code like this:

 var first = require('lodash/first');

 first([1, 2, 3]);

Converted libraries

First of all, I want to thank the creators of the libraries for all the work they have done. All I have done is rewrite the code to work with Salesforce Commerce Cloud B2C, in some cases new functions will be added to the repository that is not in the original. So the documentation will start to differentiate after some time.

I will not always be monitoring updates that happen to the original repositories, so pull requests are always happily accepted to keep this repository up to date with new features or new libraries!

!!! Please note that not all scenario's have been tested and some functions may have not been converted fully. If you find any bugs, please report them with an example so we can see if it is possible to resolve. !!!


Library Repository Version Notes
Moment.js https://github.com/moment/moment/ 2.10.0 A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
lodash https://github.com/lodash/lodash 5.0.0 A modern JavaScript utility library delivering modularity, performance, & extras.
date-fns https://github.com/date-fns/date-fns v2.0.0-beta.4 date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
fast-xml-parser https://github.com/NaturalIntelligence/fast-xml-parser 3.12.16 Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries
chance https://github.com/chancejs/chancejs 1.1.0 Utility library to generate anything random
ramda https://github.com/ramda/ramda 0.26.1 A practical functional library for JavaScript programmers.
jsPDF https://github.com/parallax/jsPDF 1.5.3 A library to generate PDFs in JavaScript.

Example code

var moment = require('moment/moment');

moment('2010-10-18').isAfter('2010-10-19')

var camelCase = require('lodash/camelCase');
var capitalize =  require('lodash/capitalize');

camelCase('__FOO_BAR__TEST');
capitalize('fRED');

var addDays = require('date-fns/addDays');
var startOfYear = require('date-fns/startOfYear');

addDays(new Date(), 5);
startOfYear(new Date());

var parser = require('fast-xml-parser/parser');

var jsonObject = parser.parse('<note><to>Tove</to></note>');

var parser = require('chance/chance');

chance.guid();

var add = require('ramda/add');

add(4)(6)

    var jsPDF = require('jsPDF')

    var doc = new jsPDF()

    doc.setFontSize(25)
    doc.text(35, 5, 'Forward loves jsPDF')

    response.setContentType('application/pdf; charset=iso-8859-1');
    response.writer.print(doc.output())

Linting

Currently the same setup is used as SFRA. You can run a linting test with:

 npm run lint

Contributing

I am always looking for more interesting libraries that we could use in Commerce Cloud but require testing or need migration.

If you yourself are unable to convert a library and want met to have a look, feel free to mail me at [email protected].

If you want to contribute code feel free to read the contributing readme.

salesforce-commerce-cloud-libraries's People

Contributors

avator avatar dependabot[bot] avatar taurgis 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforce-commerce-cloud-libraries's Issues

issue with Ramda when evaluating a SFCC object

Hi,

Thanks for porting these libraries. I tried to use Ramda hasPath.

Ex:

var hasPath = require('ramda/hasPath');
hasPath(['profile', 'custom', 'customProp'])(customer)

I got the following error:

[ERROR: ScriptingException:ReferenceError: Unknown property '@@functional/placeholder' for class 'class dw.customer.Customer'. (ramda/internal/_isPlaceholder.js#4)]

I think the issue is when you use a property accessor with bracket notation in Rhino on a wrapped java object it raises an exception instead of returning 'undefined'.

Original ramda/internal/_isPlaceholder.js

return a != null &&
         typeof a === 'object' &&
         a['@@functional/placeholder'] === true;

Possible workaround for Rhino java object:

  if (a != null && typeof a === 'object') {
    try {
      return a['@@functional/placeholder'] === true; // A DW java object will raise an exception
    } catch (e) {
      return false;
    }
  } else {
    return false;
  }

Use libraries in controllers

I would like to use the jsPDF library in a controller, but as far as I understand right now it is only available for frontend js scripts. Is there a way to use the library inside a controller?

Quota exceeded limitation

Hello,

After using this library (jsPDF) we get the bellow error

Quota api.jsArraySize (enforced, warn 12000, limit 20000): limit exceeded 1 time(s), max actual was 20544, current location: request/site Sites-Jinius-Site/top pipeline Order-xxxx/.../script jsPDF/jsPDF.js:1524/script jsPDF/jsPDF.js:1485/script jsPDF/jsPDF.js:964/script jsPDF/jsPDF.js:939/script jsPDF/jsPDF.js:913/script jsPDF/jsPDF.js:89/script jsPDF/plugins/utf8.js:151/script jsPDF/plugins/utf8.js:84/script jsPDF/libs/ttffont.js:1961/script jsPDF/libs/ttffont.js:492, further information: n/a

Have anyone one encounter this issue ? If yes how you resolve it ?

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.