# Konnektive Engine

## Dependencies
- jquery: 1.12.4 (is needed you import the jquery before importing this library)
- [jsDelivr](https://www.jsdelivr.com/) (Create a CDN based on the npm package)

# Running on local

1. Build the library
```bash
npm run build # Compile files in development
npm run build:prod # Compile files optimized for production
```

2. Running a local server
```bash
npm run serve # Start a new server on: http://localhost:3000
```

3. Running watch with the local server at the same time
```bash
npm run dev # This command will execute `npm run watch` to see all modification files and start a new server.
```

4. Acessing the files
After that you started a local server, you can access the files on `http://localhost:3000`.

For example: `http://localhost:3000/index.js`, `http://localhost:3000/api.js`, and so on.

# Publish this lib
First, you need to sign in on npm: `npm login`.
When you create a new version, it is needly to update the version on `package.json` and execute this command: `npm run publish.` This command is responsible for building the application and publishing the files to npm.

The build will create all minified files on `dist` at the same level.

Obs.: You cannot override the version, so each version is unique.

# Using this lib
The `version` on URL is the version set on package.json and published on npm.

You need to import the file `index.js`. This file is responsible for creating the start function on the application.
```
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/index.js"></script>
```

On the operation site, you need to create a file to set the configurations. In this file, you can override all default variables.
```js
//engine-override.js
PaymentEngine.init({
  debugMode: 1,
  // others configs
})
```

A comparing about the files:

| Last file | This lib | Comments
| ------ | ------ | ------ |
| 1.stickyConfig.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/index.js | You need to create the engine-override.js |
| 1.stickyBaseConfig.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/index.js | You need to create the engine-override.js |
| 2.stickyAPIFramework.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/api.js | You need to import this only if the front is using some function there |
| 3.stickyUtils.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/actions.js | |
| 4.stickyZIPAutofill.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/zip-autofill.js | |
| 5.stickyValidations.js | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/validation.js | |
| op-configure.php | It's not needed anymore. | |
| tracking.php | It's manual copy. | |
| Code php to set cookies | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/cookies.js | Where was using php to set cookies, you can import this file. |
| ipify.org | You don't need to import anymore, because the IP is got when init the payment engine. | |
| firePostBack | https://cdn.jsdelivr.net/npm/konnektive-engine@version/dist/redtrack.js | You can use the function after importing this file. |
