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

@e2y/occ-client

Package Overview
Dependencies
Maintainers
6
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@e2y/occ-client

occ client

  • 1.0.7
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by17.14%
Maintainers
6
Weekly downloads
 
Created
Source

occ-client

This package acts as a client for the SAP commerce OCC Rest API Version: 2.0.

Usage

import { OccClient, OAuthClient, OauthClientConfig } from '@e2y/occ-client';

void (async () => {
const oauthUrl = 'https://localhost:9002/authorizationserver/oauth/';
const occUrl = 'https://localhost:9002/occ/v2/';
const oauthClientConfig: OauthClientConfig = {
  client_id: 'clientId',
  client_secret: '******',
  grant_type: 'client_credentials',
  scope: 'extended'
};

  const oauth = new OAuthClient(oauthUrl, oauthClientConfig);
  const { access_token: accessToken } = await oauth.clientCredentials();

  const occ = new OccClient(occUrl, { accessToken });

  const user = await occ.users.registersACustomer('electronics', {
    uid: 'fernando.alonso@e2ycommerce.com',
    firstName: 'Fernando',
    lastName: 'Alonso',
    password: '******'
  });
})();

Custom OCC client

Depending on project needs, could be necessary to implement custom occ endpoints. To interact with them through the occ client, we would need to create a custom occ client that extends it using the new endpoints.

// mirakl-extended-cart.ts

import { Cart, HttpClient, OccConfig } from '@e2y/occ-client';
import axios from 'axios';

export class MiraklExtendedCarts extends HttpClient {
  constructor(baseURL: string, { accessToken }: OccConfig) {
    super({
      baseURL,
      headers: {
        Authorization: `Bearer ${accessToken}`
      }
    });
  }

  async getCartWithMarketplaceDeliveryOptions(baseSiteId: string, cartId: string, userId = 'anonymous'): Promise<Cart> {
    const url = `/${baseSiteId}/users/${userId}/carts/${cartId}/marketplacedeliverymodes`;

    try {
      const { data } = await this.client.get<Cart>(url);
      return data;
    } catch (error) {
      if (axios.isAxiosError(error)) {
        console.error(error.toJSON(), error.response?.data);
      }

      throw new Error(`Ops! something went wrong`);
    }
  }
}
// custom-occ-client.ts

import { OccClient, OccConfig } from '@e2y/occ-client';

import { MiraklExtendedCarts } from './mirakl-extended-cart';

export class CustomOccClient extends OccClient {
  public readonly miraklExtendedCarts: MiraklExtendedCarts;

  constructor(baseURL: string, config: OccConfig) {
    super(baseURL, config);

    this.miraklExtendedCarts = new MiraklExtendedCarts(baseURL, config);
  }
}
// index.ts

const occ = new OccClient(occUrl, { accessToken });
const cart = await occ.miraklExtendedCarts.getCartWithMarketplaceDeliveryOptions('electronics', 'abc123');

FAQs

Package last updated on 31 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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