New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cometh/checkout-sdk

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cometh/checkout-sdk - npm Package Compare versions

Comparing version 1.1.5 to 2.0.0

dist/index.cjs

69

dist/index.d.ts

@@ -1,8 +0,61 @@

export { CheckoutAPI } from './CheckoutAPI';
export { ApiError } from './core/ApiError';
export { BaseHttpRequest } from './core/BaseHttpRequest';
export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI';
export * from './schemas.gen';
export * from './services.gen';
export * from './types.gen';
import { EventEmitter } from 'eventemitter3';
declare enum DisplayMode {
TAB = "tab",
IFRAME = "iframe",
POPUP = "popup"
}
interface CheckoutConfiguration {
checkoutAppURI?: string;
checkoutApiURI?: string;
display?: DisplayMode;
}
interface CheckoutParameters {
productId: string;
user: {
walletAddress: string;
email: string;
};
}
declare enum TransactionStatus {
INITIATED = "initiated",
CASHED = "cashed",
RELAYED = "relayed",
REVERTED = "reverted",
CANCELLED = "cancelled",
COMPLETED = "completed"
}
declare enum CheckoutEvents {
START = "checkoutStart",
SUCCESS = "checkoutSuccess",
FAILURE = "checkoutFailure"
}
interface CheckoutSuccess {
transactionId: string;
txHash: string;
status: TransactionStatus;
}
interface CheckoutError {
message: string;
transactionId?: string;
txHash?: string;
status: TransactionStatus;
}
type CheckoutEventMap = {
checkoutStart: void;
checkoutSuccess: CheckoutSuccess;
checkoutFailure: CheckoutError;
};
declare class CheckoutEventEmitter extends EventEmitter<keyof CheckoutEventMap> {
}
declare class CheckoutSDK extends CheckoutEventEmitter {
private flow;
constructor(apiKey: string, configuration?: CheckoutConfiguration);
checkout(parameters: CheckoutParameters): Promise<void>;
}
export { type CheckoutConfiguration, type CheckoutError, CheckoutEvents, type CheckoutParameters, type CheckoutSuccess, DisplayMode, CheckoutSDK as default };

@@ -1,9 +0,345 @@

// This file is auto-generated by @hey-api/openapi-ts
export { CheckoutAPI } from './CheckoutAPI';
export { ApiError } from './core/ApiError';
export { BaseHttpRequest } from './core/BaseHttpRequest';
export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export * from './schemas.gen';
export * from './services.gen';
export * from './types.gen';
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/configuration.ts
var DisplayMode = /* @__PURE__ */ ((DisplayMode3) => {
DisplayMode3["TAB"] = "tab";
DisplayMode3["IFRAME"] = "iframe";
DisplayMode3["POPUP"] = "popup";
return DisplayMode3;
})(DisplayMode || {});
// src/utils/safeURL.ts
var buildURL = (baseURL, params) => {
if (!params) return baseURL;
const url = new URL(baseURL);
Object.keys(params).forEach((key) => {
if (params[key]) {
url.searchParams.append(key, params[key]);
}
});
return url.toString();
};
var urlOriginEquals = (url1, url2) => {
const u1 = new URL(url1);
const u2 = new URL(url2);
return u1.origin === u2.origin;
};
// src/core/app/embedded.ts
var Embedded = class {
constructor(_config) {
this._config = _config;
}
async waitMessage(type) {
return new Promise((resolve, reject) => {
const handler = (event) => {
if (!urlOriginEquals(event.origin, this._config.authorizedOrigin)) {
console.log("wrong origin: ", event);
return;
}
if (event.data.type === type) {
console.log("received: ", event);
window.removeEventListener("message", handler);
if (event.data.success) {
resolve(event.data.data);
} else {
reject(event.data.data);
}
}
if (event.data.type === "CLOSE_DISPLAY" /* CLOSE_DISPLAY */) {
window.removeEventListener("message", handler);
reject({ message: "User unexpectedly closed the flow." });
}
};
window.addEventListener("message", handler);
});
}
};
// src/core/app/iframe.ts
var IFrame = class extends Embedded {
constructor() {
super(...arguments);
__publicField(this, "_modalID", "modal-cometh-web-checkout");
__publicField(this, "_modal", null);
__publicField(this, "_iframeID", "cometh-web-checkout");
__publicField(this, "_iframe", null);
}
_prepareModal(modalId) {
const modal = document.createElement("div");
modal.id = modalId;
modal.style.position = "fixed";
modal.style.top = "0px";
modal.style.right = "0px";
modal.style.left = "0px";
modal.style.bottom = "0px";
modal.style.display = "none";
modal.style.zIndex = "1000";
return modal;
}
_createModal() {
const existingModal = document.getElementById(this._modalID);
if (existingModal) {
this._modal = existingModal;
return;
}
const modal = this._prepareModal(this._modalID);
document.body.appendChild(modal);
this._modal = modal;
}
_createIframe() {
if (this._iframe) {
return;
}
const existingIframe = document.getElementById(this._iframeID);
if (existingIframe) {
this._iframe = existingIframe;
return;
}
console.log("Creating iframe", this._modal);
const iframe = document.createElement("iframe");
iframe.id = this._iframeID;
iframe.allow = "";
iframe.sandbox.add("allow-forms");
iframe.sandbox.add("allow-scripts");
iframe.sandbox.add("allow-same-origin");
iframe.style.width = "100%";
iframe.style.height = "100%";
this._iframe = iframe;
this._modal?.appendChild(iframe);
}
_hideModal() {
if (this._modal) {
this._modal.style.display = "none";
}
}
_showModal() {
if (this._modal) {
this._modal.style.display = "block";
}
}
initialize() {
this._createModal();
this._createIframe();
}
open(url, params) {
const target = url || this._config.defaultURL;
const formatedURL = buildURL(target, params);
if (!this._iframe) return false;
this._iframe.src = formatedURL;
this._showModal();
return true;
}
close() {
this._hideModal();
}
sendMessage(message) {
if (this._iframe?.contentWindow) {
this._iframe.contentWindow.postMessage(message, "*");
}
}
};
// src/core/app/popup.ts
var POPUP_WIDTH = 620;
var POPUP_HEIGHT = 740;
var Popup = class extends Embedded {
constructor() {
super(...arguments);
__publicField(this, "_popup", null);
__publicField(this, "_popupURL", null);
}
initialize() {
}
_createPopup(url) {
const left = (window.innerWidth - POPUP_WIDTH) / 2 + window.screenX;
const top = (window.innerHeight - POPUP_HEIGHT) / 2 + window.screenY;
const popup = window.open(
url,
"Smart Checkout",
`width=${POPUP_WIDTH}, height=${POPUP_HEIGHT}, left=${left}, top=${top}`
);
if (!popup) {
throw new Error("Pop up window failed to open");
}
return popup;
}
open(url, params) {
const target = url || this._config.defaultURL;
if (this._popup && !this._popup.closed) {
if (this._popupURL === target) {
this._popup.focus();
return false;
}
}
const formatedURL = buildURL(target, params);
this._popupURL = target;
this._popup = this._createPopup(formatedURL.toString());
this._popup.focus();
return true;
}
close() {
if (!this._popup || this._popup.closed) return;
this._popup.close();
}
sendMessage(message) {
if (!this._popup) return;
this._popup.postMessage(message, "*");
}
};
// src/core/app/tab.ts
var Tab = class extends Embedded {
constructor() {
super(...arguments);
__publicField(this, "_tab", null);
__publicField(this, "_tabURL", null);
}
initialize() {
}
_createTab(url) {
const tab = window.open(
url,
"_blank"
);
if (!tab) {
throw new Error("Tab window failed to open");
}
return tab;
}
open(url, params) {
const target = url || this._config.defaultURL;
if (this._tab && !this._tab.closed) {
if (this._tabURL === target) {
this._tab.focus();
return false;
}
}
const formatedURL = buildURL(target, params);
this._tabURL = target;
this._tab = this._createTab(formatedURL.toString());
this._tab.focus();
return true;
}
close() {
if (!this._tab || this._tab.closed) return;
this._tab.close();
}
sendMessage(message) {
if (!this._tab) return;
this._tab.postMessage(message, "*");
}
};
// src/core/app/factory.ts
var embeddedFactory = (display, config) => {
switch (display) {
case "iframe":
return new IFrame(config);
case "popup":
return new Popup(config);
case "tab":
return new Tab(config);
default:
throw new Error("Invalid display mode");
}
};
var factory_default = embeddedFactory;
// src/core/app/DisplayableFlow.ts
var DisplayableFlow = class {
constructor(display, config) {
__publicField(this, "_embedded");
this._embedded = factory_default(display, config);
this._embedded.initialize();
}
async start(parameters) {
this._embedded.open(void 0, {
product_id: parameters.productId,
user_wallet: parameters.user.walletAddress,
user_email: parameters.user.email
});
}
close() {
this._embedded.close();
}
async waitResult(type, closeOnSuccess = true) {
try {
const result = await this._embedded.waitMessage(type);
if (closeOnSuccess) {
this.close();
}
return result;
} catch (e) {
this.close();
throw e;
}
}
};
// src/constants.ts
var CHECKOUT_APP_URI = "https://checkout.cometh.io";
var CHECKOUT_API_URI = "https://api.checkout.cometh.io/v1";
// src/core/events/types.ts
import { EventEmitter } from "eventemitter3";
var CheckoutEvents = /* @__PURE__ */ ((CheckoutEvents2) => {
CheckoutEvents2["START"] = "checkoutStart";
CheckoutEvents2["SUCCESS"] = "checkoutSuccess";
CheckoutEvents2["FAILURE"] = "checkoutFailure";
return CheckoutEvents2;
})(CheckoutEvents || {});
var CheckoutEventEmitter = class extends EventEmitter {
};
// src/core/CheckoutSDK.ts
var CheckoutSDK = class extends CheckoutEventEmitter {
constructor(apiKey, configuration) {
super();
__publicField(this, "flow");
const checkoutAppURI = configuration?.checkoutAppURI || CHECKOUT_APP_URI;
const checkoutApiURI = configuration?.checkoutApiURI || CHECKOUT_API_URI;
this.flow = new DisplayableFlow(configuration?.display || "popup" /* POPUP */, {
authorizedOrigin: checkoutAppURI,
defaultURL: buildURL(
checkoutAppURI,
{
checkout_api_key: encodeURIComponent(apiKey),
checkout_api_url: checkoutApiURI
}
)
});
}
async checkout(parameters) {
await this.flow.start(parameters);
this.emit("checkoutStart" /* START */);
try {
const response = await this.flow.waitResult(
"CHECKOUT_TRANSACTION" /* CHECKOUT_TRANSACTION */
);
this.emit("checkoutSuccess" /* SUCCESS */, {
transactionId: response.transactionId,
txHash: response.txHash,
status: "completed" /* COMPLETED */
});
} catch (e) {
console.error(e);
this.emit("checkoutFailure" /* FAILURE */, {
transactionId: e.transactionId,
txHash: e.txHash,
message: e.message,
status: e.status || "cancelled" /* CANCELLED */
});
}
}
};
// src/index.ts
var src_default = CheckoutSDK;
export {
CheckoutEvents,
DisplayMode,
src_default as default
};

39

package.json
{
"name": "@cometh/checkout-sdk",
"version": "1.1.5",
"description": "SDK to use Cometh Checkout API",
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"tsc": "^2.0.5",
"typescript": "^5.1.3"
},
"version": "2.0.0",
"author": "Cometh",
"description": "Cometh Checkout SDK",
"private": false,
"repository": "https://github.com/cometh-hq/checkout-sdk.git",
"license": "ISC",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"type": "module",
"files": [
"/dist"
],
"exports": [
{
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
],
"scripts": {
"build": "rm -rf ./dist && tsc"
"build": "tsup --splitting",
"clean": "rm -rf dist"
},
"dependencies": {
"axios": "^1.4.0",
"form-data": "4.x"
"eventemitter3": "^5.0.1"
},
"devDependencies": {
"tsup": "^8.0.2",
"typescript": "^5.4.3"
}
}

@@ -1,35 +0,48 @@

# @cometh/checkout-sdk
# Connect Checkout SDK
This is a TypeScript SDK for interacting with the Fiat Minting API. It simplifies the process of making requests to the API by providing convenient methods for various operations related to NFTs (Non-Fungible Tokens). These operations include managing and searching for assets, handling collections, and analyzing NFT data.
#### Installing Checkout SDK
```bash
npm install @cometh/checkout-sdk
```
## [SDK Reference documentation](https://api.checkout.cometh.io/v1/client-doc/)
## [API reference documentation](https://api.checkout.cometh.io/v1/doc/)
## [Cometh Checkout documentation](https://docs.cometh.io/checkout)
### Basic Usage
1. Initialize SDK
## Installation
```typescript
import {CheckoutSDK} from '@cometh/checkout-sdk'
To add the @cometh/checkout-sdk to your project, you can use npm or yarn:
```bash
npm install @cometh/checkout-sdk
const sdk = new CheckoutSDK(apiKey)
```
```bash
yarn add @cometh/checkout-sdk
2. Start checkout flow
```typescript
const request = {
productId: 1,
user: {
walletAddress: '0x1234567890',
email: 'test@email.com'
}
}
await sdk.checkout(request)
```
## Usage
3. Handle flow events
After installation, you can import `CheckoutAPI` from the SDK in your TypeScript code:
```ts
import { CheckoutAPI } from '@cometh/checkout-sdk';
```
import {CheckoutSDK, CheckoutError, CheckoutSuccess, CheckoutEvents} from '@cometh/checkout-sdk'
Create an instance of `CheckoutAPI` and call its methods to interact with the NFT API.
const sdk = new CheckoutSDK(apiKey)
sdk.on(CheckoutEvents.START, () => {
console.log('display is ON and flow has started');
});
```ts
const fiatApi = new CheckoutAPI();
```
sdk.on(CheckoutEvents.SUCCESS, (result: CheckoutSuccess) => {
});
sdk.on(CheckoutEvents.FAILURE, (error: CheckoutError) => {
});
```
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