Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@juspay/blaze-sdk-web

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@juspay/blaze-sdk-web - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/iframe.d.ts

20

dist/index.d.ts

@@ -1,21 +0,19 @@

import { type BlazeProcessPayload, type BlazeInitiatePayload } from './generated/types';
export type BlazeCallback = (payload: Record<string, unknown>) => void;
import type { CallbackFn } from './types';
declare class BlazeSDK {
static initiatePayload: BlazeInitiatePayload;
static callback: BlazeCallback;
static processPayload: BlazeProcessPayload;
static initiatePayload: Record<string, unknown>;
static callback: CallbackFn;
static processPayload: Record<string, unknown>;
/**
* @description Initiate the Blaze SDK. Ensures all assets required for running Blaze SDK services are pre-loaded.
* @param payload {BlazeInitiatePayload}
* @param callbackFn {BlazeCallback} - Optional
* @param payload {Record<string, unknown>}
* @param callbackFn {CallbackFn} - Mandatory method required to receive events from Blaze SDK.
* @returns void
*/
static initiate(payload: BlazeInitiatePayload, callbackFn?: BlazeCallback): void;
static initiate(payload: Record<string, unknown>, callbackFn: CallbackFn): void;
/**
* @description Request Blaze SDK to process your request.
* @param payload {BlazeProcessPayload} - The payload data required for the process request.
* @param callbackFn {BlazeCallback} - Optional
* @param payload {Record<string, unknown>} - The payload data required for the process request.
*/
static process(payload: BlazeProcessPayload, callbackFn?: BlazeCallback): void;
static process(payload: Record<string, unknown>): void;
}
export default BlazeSDK;

@@ -1,1 +0,1 @@

function t(t){return"string"==typeof t?t:null}function n(t){return"number"==typeof t?t:null}function e(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function r(r){if(e(r)){const o=function(t){if("startCheckout"===t)return t;return null}(r.action),a=function(r){const o=function(t){const r=function(t){if(e(t)){const e=n(t.initialPrice),r=n(t.totalPrice),i=n(t.totalDiscount),o=n(t.weight),a=n(t.itemCount),u=function(t){switch(t){case"INR":case"USD":case"GBP":case"AUD":case"CAD":case"SGD":case"AED":case"PKR":case"BDT":return t}return null}(t.currency),c=function(t,n,e=!0){if(Array.isArray(t)){const r=[];for(const i of t){const t=n(i);if(null!==t)r.push(t);else if(e)return null}return r}return null}(t.items,l);return null===e||null===r||null===i||null===a||null===u||null===c?null:{initialPrice:e,totalPrice:r,totalDiscount:i,weight:o,itemCount:a,currency:u,items:c}}return null}(t);if(null===r)return null;return new i(r)}(r)??t(r);return o}(r.cart),u=function(n){if(e(n)){return{utmSource:t(n.utmSource),utmMedium:t(n.utmMedium),utmCampaign:t(n.utmCampaign),utmTerm:t(n.utmTerm),utmContent:t(n.utmContent)}}return null}(r.utmParams),c=t(r.signature);return null===a?null:{action:o,cart:a,utmParams:u,signature:c}}return null}class i{data;constructor(t){this.data=t}}function l(r){if(e(r)){const e=t(r.id),i=t(r.title),l=t(r.variantTitle),o=t(r.variantId),a=t(r.image),u=n(r.weight),c=n(r.quantity),s=n(r.discount),d=n(r.initialPrice),m=n(r.finalPrice);return null===e||null===i||null===c||null===s||null===d||null===m?null:{id:e,title:i,variantTitle:l,variantId:o,image:a,weight:u,quantity:c,discount:s,initialPrice:d,finalPrice:m}}return null}class o{static initiatePayload;static callback;static processPayload;static initiate(n,r){const i=function(n){if(e(n)){const e=t(n.merchantId),r=t(n.shopUrl),i=function(t){switch(t){case"shopify":case"magento":case"bigcommerce":case"woocommerce":case"custom":return t}return null}(n.shopPlatform),l=function(t){switch(t){case"production":case"beta":return t}return null}(n.environment);return null===e||null===r||null===i?null:{merchantId:e,shopUrl:r,shopPlatform:i,environment:l}}return null}(n);if(null===i)throw new Error("Invalid Initiate payload");this.initiatePayload=i,"function"==typeof r&&(this.callback=r);try{const t=document.createElement("script");t.src="https://sdk.breeze.in/electron/107.0.0/index.js",t.type="module",t.id="breeze-script-tag",t.async=!0,t.setAttribute("data-merchantid",n.merchantId),t.setAttribute("data-shopurl",n.shopUrl),t.setAttribute("data-environment",n.environment??"production"),t.onload=()=>{try{const t=document.createElement("breeze-button");t.style.display="none",document.body.appendChild(t)}catch(t){console.error("Error creating Breeze button",t)}},document.body.appendChild(t)}catch(t){console.error("Error loading Breeze script",t)}}static process(t,n){const e=r(t);if(null===e)throw new Error("Invalid Process payload");if(void 0===this.initiatePayload)throw new Error("Call BlazeSDK.initiate before calling BlazeSDK.process");this.processPayload=e,"function"==typeof n&&(this.callback=n),this.processPayload=t,"function"==typeof window.breeze?.startCheckout?window.breeze.startCheckout({...t,shopUrl:this.initiatePayload.shopUrl}):console.error("Breeze SDK not loaded")}}"undefined"!=typeof window&&(window.BlazeSDK=o);export{o as default};
let t=[],e=[];function n(o){if("object"==typeof window.BlazeSDK&&"function"==typeof window.BlazeSDK.initiate&&"function"==typeof window.BlazeSDK.process){if(t.length>0&&(window.BlazeSDK.initiate(t.at(0),o),t=[]),e.length>0){const t=e;e=[],t.forEach((t=>{window.BlazeSDK.process(t)}))}return!0}{let t=0;const e=setInterval((()=>{t>5&&clearInterval(e);n(o)&&clearInterval(e),t++}))}return!1}function o(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}var a={initiate:function(e,a){try{const i=document.createElement("script");i.src="https://sdk.breeze.in/electron/158.0.2/index.js",i.type="module",i.id="breeze-script-tag",i.async=!0,t.push(e);const r=o(e)&&o(e.payload)?e.payload:{},c="string"==typeof r.merchantId?r.merchantId:null,s="string"==typeof r.shopUrl?r.shopUrl:null,l="string"==typeof e.environment?e.environment:"production";null!==c&&i.setAttribute("data-merchantid",c),null!==s&&i.setAttribute("data-shopurl",s),i.setAttribute("data-environment",l),i.onload=()=>{try{const t=document.createElement("breeze-button");t.style.display="none",document.body.appendChild(t),n(a)}catch(t){console.error("Error creating Breeze button",t)}},document.body.appendChild(i)}catch(t){}},process:function(t){"object"==typeof window.BlazeSDK&&"function"==typeof window.BlazeSDK.process?window.BlazeSDK.process(t):e.push(t)}};class i{static initiatePayload;static callback;static processPayload;static initiate(t,e){this.callback=e,this.initiatePayload=t,a.initiate(t,e)}static process(t){this.processPayload=t,a.process(t)}}export{i as default};
{
"name": "@juspay/blaze-sdk-web",
"version": "0.0.1",
"version": "0.0.2",
"type": "module",

@@ -43,4 +43,3 @@ "description": "SDK for integrating Breeze 1CCO into your Web Application",

"lint:all": "eslint . --ext .ts",
"generate:doc": "npx typedoc src/index.ts",
"generate:types": "npx type-crafter generate typescript-with-decoders ./specs/types.spec.yaml ./src/generated/types SingleFile SingleFile && pnpm run format:generated"
"generate:doc": "npx typedoc src/index.ts"
},

@@ -71,4 +70,2 @@ "author": "",

"tslib": "^2.6.2",
"type-crafter": "^0.8.2",
"type-decoder": "^2.0.1",
"typedoc": "^0.25.7",

@@ -75,0 +72,0 @@ "typescript": "^5.2.2"

@@ -5,4 +5,8 @@ # Blaze SDK Web

## Installation
## Web SDK Integration
Follow the below steps to integrate Blaze SDK into your web app written in any framework.
### Step 1: Obtaining the Blaze SDK
Run following command in your node project to install the Blaze SDK Web package:

@@ -18,140 +22,83 @@

## Usage
### Step 2: Initialize the SDK
To start using the Blaze SDK Web, you need to complete following steps:
#### 2.2.1: Import the SDK
### Step 1: Initiate the Blaze SDK Web
Import BlazeSDK using the following code in TS/JS project:
To initiate the Blaze SDK Web, you need to call the `initiate` method of the SDK. This method takes an object as an argument which contains the following properties:
| Parameter | Type | Mandatory | Description |
| -------------- | ------ | --------- | ---------------------------------------------------------------------------------------------------------- |
| `merchantId` | String | Yes | The merchant ID provided by Juspay. |
| `shopUrl` | String | Yes | The URL of the shop where the SDK will be used. |
| `environment` | String | No | The environment in which the SDK should run. Possible values are `beta` and `production`. |
| `shopPlatform` | String | Yes | The platform on which the shop is built. Possible values are `shopify`, `magento`, `woocommerce`, `custom` |
```javascript
// Import the SDK to your project
import BlazeSDK from '@juspay/blaze-sdk-web';
```
// Create the initiate payload
#### 2.2.1: Construct the Initiate Payload
const initiatePayload = {
merchantId: '<merchant-id-shared-by-breeze>',
shopUrl: '<shop-url>',
environment: 'production',
shopPlatform: 'custom'
};
Create a Json with correct parameters to initiate the SDK. This is the data that will be used to initialize the SDK.
BlazeSDK.initiate(initiatePayload);
```javascript
const initiatePayload = {
merchantId: '<merchant-id-shared-by-breeze>',
shopUrl: '<shop-url>',
environment: 'production'
};
const initSDKPayload = {
requestId: '<unique_request_id>',
service: 'in.breeze.onecco',
payload: initiatePayload
}
```
### Step 2: Process your request through Blaze SDK
#### 2.2.2: Construct the Callback Method
To process your request through Blaze SDK, you need to call the `process` method of the SDK. This method takes an object. Refer below sections to understand the object structure.
Create a callback method to handle the response from the SDK. This method will be called when the SDK has processed the request.
#### Process Payload
```javascript
// response will be an json object
const callbackMethod = (response>) => {
console.log('Response from SDK:', response);
};
```
| Parameter | Type | Mandatory | Description |
| ----------- | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| `action` | String | Yes | The action to be performed by the SDK. Possible values are `startCheckout` |
| `cart` | BlazeCart or String | Yes | The cart object which contains the cart details or Stringified Cart when using signature based integration |
| `utmParams` | Object | No | UTP Parameters associated with the user journey |
| `signature` | String | No | RSA Signed signature for Stringified BlazeCart JSON |
#### 2.2.3: Call the initiate method on Blaze
#### BlazeCart
Call the `initiate` method on Blaze SDK with the initiate payload and the callback method.
| Parameter | Type | Mandatory | Description |
| --------------- | --------------- | --------- | --------------------------------------- |
| `initialPrice` | Number | Yes | The initial price of the cart. |
| `totalPrice` | Number | Yes | The total price of the cart. |
| `totalDiscount` | Number | Yes | The total discount applied on the cart. |
| `weight` | Number | No | The total weight of the cart. |
| `itemCount` | Number | Yes | The total number of items in the cart. |
| `currency` | BlazeCurrency | Yes | The currency of the cart. |
| `items` | BlazeCartItem[] | Yes | The array of items in the cart. |
```javascript
BlazeSDK.initiate(initSDKPayload, callbackMethod);
```
#### BlazeCurrency
### Step 3: Start processing your requests
Blaze SDK Web supports the following currencies:
Once the SDK is initiated, you can start processing your requests using the initialized instance of the SDK.
The SDK will call the callback method with the result of the SDK operation.
- 'INR'
- 'USD'
- 'GBP'
- 'AUD'
- 'CAD'
- 'SGD'
- 'AED'
- 'PKR'
- 'BDT'
#### 3.1: Construct the Process Payload
#### BlazeCartItem
Create a Json payload with the required parameters to process the request.
The process payload differs based on the request.
Refer to schemas sections to understand what kind of data is required for different requests
| Parameter | Type | Mandatory | Description |
| -------------- | ------ | --------- | --------------------------------- |
| `id` | String | Yes | The ID of the item. |
| `title` | String | Yes | The title of the item. |
| `variantTitle` | String | No | The variant title of the item. |
| `variantId` | String | No | The variant ID of the item. |
| `image` | String | No | The image URL of the item. |
| `weight` | Number | No | The weight of the item. |
| `quantity` | Number | Yes | The quantity of the item. |
| `discount` | Number | Yes | The discount applied on the item. |
| `initialPrice` | Number | Yes | The initial price of the item. |
| `finalPrice` | Number | Yes | The final price of the item. |
```javascript
// 3.1 Create SDK Process Payload
// Create a JSONObject for the Process data
let processPayload = {
"action": "<ACTION>",
// and more parameters required as per the action
};
Post you have initiated the SDK, you can call the `process` method to execute your query.
```javascript
// Import your SDK
import BlazeSDK from '@juspay/blaze-sdk-web';
// Creating process payload
const processPayload = {
action: 'startCheckout',
cart: {
initialPrice: 1000,
totalPrice: 900,
totalDiscount: 100,
weight: 1000,
itemCount: 2,
currency: 'INR',
items: [
{
id: '1',
title: 'Item 1',
variantTitle: 'Variant 1',
variantId: '1',
image: 'https://example.com/image1.jpg',
weight: 500,
quantity: 1,
discount: 50,
initialPrice: 500,
finalPrice: 450
},
{
id: '2',
title: 'Item 2',
variantTitle: 'Variant 2',
variantId: '2',
image: 'https://example.com/image2.jpg',
weight: 500,
quantity: 1,
discount: 50,
initialPrice: 500,
finalPrice: 450
}
]
},
utmParams: {
utm_source: 'google',
utm_medium: 'cpc',
utm_campaign: 'summer-sale'
}
// Place Process Payload into SDK Payload
let processSDKPayload = {
requestId: '<unique_request_id>',
service: 'in.breeze.onecco',
"payload": processPayload
};
```
BlazeSDK.process(processPayload);
#### 3.2: Call the process method on Blaze Instance
Call the process method on the Blaze instance with the process payload to start the user journey or a headless flow.
```kotlin
BlazeSDK.process(processSDKPayload)
```
Note: This SDK is in alpha stage. Expect new features & breaking changes in upcoming versions.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc