2.8.0 • Published 13 days ago

@aller/cyclops-frontend-api v2.8.0

Weekly downloads
1,287
License
MIT
Repository
-
Last release
13 days ago

cyclops-frontend-api

API-part of the cyclops-frontend. This package contains all non-DOM changes, and interactions with CYCLOPS, from login, to payment-initiations, to user-fetching and whatnot. Below are more content and info on functions, schemas, interfaces that are being used in this package..

This package used to use Ajv for response-validation of the json schema. This package, it's validation vs unvalidated functions and tests have been removed to allow the client more controll of the response.

When fetching a user through /users/me a cyclops_seg cookie is set, if the user has adSegments as a property.

Please note that this library is still in active development..

Table of Contents

Design

Interfaces can be found in ./src/**/interface.ts.

Using the package

If you are not afraid of bloat, this package can be used with @aller/cyclops-frontend-api. If you are afraid of bloat, everything can be referenced with @aller/cyclops-frontend-api/lib/node|client/** (e.g. @aller/cyclops-frontend-api/lib/user/login). In this, you'll only include the parts of code you actually need, instead of the whole package.

For packages that require node-like environment-transpiled code, point to the lib/node folder, while client-side code should point to lib/client.

Functions

User

/**
 * Get the current (possibly-cached) user based on
 * the cyclops-session cookie
 * Use this function if you want to check if a user is logged.
 */

async getCurrentUser(
    domain: string = '',
    options?: any
): Promise<IUser>
/**
 * Get the current non-cached user based on the
 * cyclops-session cookie
 * This function has a performance cost and should only be used
 * if the exact state of the user is required (minside)
 */

async getCannonicalUser(
    domain: string = '',
    options?: any
): Promise<IUser>
/**
 * Sends a subscribe request to cyclops
 */

async subscribe(
  productId: string,
  accessCode: string,
  dealId: string,
  options?: any,
): Promise<boolean>
/**
 * Get the current (possibly-cached) user
 * based on the cyclops-session cookie
 * Use this function if you want to check if a user is logged.
 */

async unsubscribe(
  productId: string,
  domain: string = '',
  options?: any
): Promise<boolean>
/**
 * Initiates a payment for a product, and deal
 */

async initiatePayment(
  productId: string,
  dealId: string,
  options: IPaymentOptions = defaultPaymentOptions,
  domain: string = '',
  fetchOptions?: any
): Promise<IPaymentInitResponse>
/**
 * Gets from cyclops
 */

async cyclopsGet<T>(
  path: string,
  options?: any,
  absoluteUrl?: boolean
): Promise<T>
/**
 * Posts to cyclops
 */


async cyclopsPost<T>(
  path: string,
  data: any,
  options: any = {},
  version?: string,
): Promise<T> =>
/**
 * Sends a delete request to cyclops
 */

async cyclopsDelete<T>(
  path: string,
  data: any,
  options: any = {},
): Promise<T>
/**
 * Initiates a cyclops login redirect. Redirect parameter
 * says whether to add a redirect url
 */

cyclopsLogin(
    redirect?: string,
    domain: string = '',
    options?: any
)
/**
 * Initiates a cyclops logout
 */

async cyclopsLogout(
    refresh: boolean = false,
    domain: string = '',
    options?: any
)

The listener-system is to allow for listening to requests being made to certain endpoints, in case you want a reactive component, be reactive on a separate component without a bunch of hacks

import { addListener, removeListener } from '@aller/cyclops-frontend-api/lib/client/cyclops/listener'

const listenerFunction = (event:CustomEvent) => {
  if(!event.detail) {
    return
  }

  DO YOUR STUFF HERE
}

addListener(ENDPOINT_URL_GOES_HERE, listenerFunction)


// Handle event, then remove
removeListener(ENDPOINT_URL_GOES_HERE, listenerFunction)
/**
 * Gets catalogue and validates the response
 * to be valid ICatalogue
 */

async getCatalogue(
  domain: string = '',
  options?: any
): Promise<ICatalogue>

Constants

/**
 * Creates relative loginURL
 */

export const cyclopsLoginRelativeURL = (
  redirect?: string,
  domain: string = '',
  options?: any,
): string => {
  const red = redirect ? redirect : window.location.pathname;
  const relativeUrl = `${domain}${CYCLOPS_API}/login?cyclops-redirect=${red}`;
  return relativeUrl;
};
/**
 * Creates relative loginURL without utilizing any window
 * or document elements
 */

export const cyclopsLoginRelativeURLServer = (
  redirect?: string,
  domain: string = '',
  options?: any,
): string => {
  const red = redirect ? `?cyclops-redirect=${redirect}` : '';
  const relativeUrl = `${domain}${CYCLOPS_API}/${red}`;
  return relativeUrl;
};

Interfaces

interface IUser {
  readonly cyclopsId: string;
  readonly mediaConnectId: string;
  readonly aid: string;
  readonly email: string;
  readonly fullName: string;
  readonly phoneNumber: string;
  readonly subscriptions?: ReadonlyArray<ISubscription>;
  readonly newsletters?: ReadonlyArray<INewsletter>;
  readonly legacySubscriptions?: ReadonlyArray<ILegacySubscription>;
  readonly paymentHistory: IPaymentHistory;
  readonly adSegments?: ReadonlyArray<string>;
  readonly consents?: ReadonlyArray<IConsentType>;
  readonly newsletterPreferences?: ReadonlyArray<INewsLetterPreference>;
  readonly mobileSubscriptions?: IMobileSubscription[];
}
interface IBaseSubscription {
  readonly productId: string;
  readonly status: 'ACTIVE' | 'CANCELLED';
}

interface ISubscription extends IBaseSubscription {
  readonly endDate?: string;
  readonly subscriptionId?: string;
  readonly startDate?: string;
  readonly nextChargeDate?: string;
  readonly chargeAmount?: number;
  readonly chargeInterval?: string;
  readonly dealId?: string;
}

interface ILegacySubscription extends IBaseSubscription {}

interface IMobileSubscription extends IBaseSubscription {
  readonly endDate?: string;
  readonly subscriptionId?: string;
  readonly startDate?: string;
  readonly dealId?: string;
  readonly dataGb?: string;
  readonly phoneNumber?: string;
  readonly signupDate?: string;
  readonly chargeAmount?: number;
  readonly chargeInterval?: string;
}
interface INewsletter {
  readonly newsletterId: string;
  readonly site: string;
}
interface IProduct {
  readonly productName: string;
  readonly productDescription: string;
  readonly productId: string;
  readonly productLogo: string;
  readonly productType: 'digital' | 'print';
  readonly deals: ReadonlyArray<IProductDeal>;
}
interface IProductDeal {
  readonly dealName: string;
  readonly dealDescription: string;
  readonly dealId: string;
  readonly dealLogo: string;
  readonly fullTermsDescription: string;
}
type TPaymentProvider = 'vipps' | 'nets';
interface IPaymentInitRequest {
  productId: string;
  dealId: string;
  embeddedCheckoutUrl: string;
  allowUnauthenticatedCheckout: boolean;
  paymentProvider?: TPaymentProvider;
  redirectURL?: string;
}
interface IPaymentInitResponse {
  paymentId: string;
  paymentProvider: TPaymentProvider;
  reservationId?: string;
  confirmationUrl?: string;
}
interface IPaymentOptions {
  allowUnauthenticatedCheckout?: boolean;
  embeddedCheckoutUrl?: string;
  paymentProvider?: TPaymentProvider;
  redirectURL?: string;
}
interface ICatalogue {
  readonly brands: ReadonlyArray<IBrand>;
}
interface IBrand {
  readonly brandName: string;
  readonly brandDescription: string;
  readonly brandId: string;
  readonly brandLogo: string;
  readonly products: ReadonlyArray<IProduct>;
}
2.8.0

13 days ago

2.7.2-alpha.0

14 days ago

2.7.6-alpha.0

14 days ago

2.7.3-alpha.0

14 days ago

2.7.4-alpha.0

14 days ago

2.7.5-alpha.0

14 days ago

2.7.0-alpha.0

19 days ago

2.6.4

3 months ago

2.6.3-alpha.1

3 months ago

2.6.3-alpha.2

3 months ago

2.6.0-alpha.0

10 months ago

2.6.0-alpha.1

10 months ago

2.6.0-alpha.2

10 months ago

2.6.0

10 months ago

2.5.3-alpha.2

1 year ago

2.5.3-alpha.1

1 year ago

2.5.3-alpha.0

1 year ago

2.5.6

1 year ago

2.5.5

1 year ago

2.5.7

1 year ago

2.5.5-alpha.1

1 year ago

2.5.5-alpha.0

1 year ago

2.5.2

1 year ago

2.5.4

1 year ago

2.5.3

1 year ago

2.5.6-alpha.2

1 year ago

2.5.6-alpha.0

1 year ago

2.5.6-alpha.1

1 year ago

2.5.0-alpha.7

1 year ago

2.5.0-alpha.6

1 year ago

2.5.0-alpha.9

1 year ago

2.5.0-alpha.8

1 year ago

2.5.0-alpha.3

1 year ago

2.5.0-alpha.2

1 year ago

2.5.0-alpha.5

1 year ago

2.5.0-alpha.4

1 year ago

2.5.0-alpha.17

1 year ago

2.5.0-alpha.16

1 year ago

2.5.0-alpha.15

1 year ago

2.5.0-alpha.14

1 year ago

2.5.0-alpha.13

1 year ago

2.5.0-alpha.12

1 year ago

2.5.0-alpha.11

1 year ago

2.5.0-alpha.10

1 year ago

2.4.2-alpha.0

2 years ago

2.4.2-alpha.1

2 years ago

2.4.1

2 years ago

2.4.1-alpha.1

2 years ago

2.4.1-alpha.0

2 years ago

2.4.1-alpha.3

2 years ago

2.3.19

2 years ago

2.3.15

2 years ago

2.3.13

3 years ago

2.3.10-beta.0

3 years ago

2.3.10-beta.1

3 years ago

2.3.10

3 years ago

2.3.8

3 years ago

2.3.6

3 years ago

2.3.5

3 years ago

2.3.6-alpha.1

3 years ago

2.3.6-alpha.0

3 years ago

2.3.6-alpha.2

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.5

3 years ago

2.2.4

3 years ago

2.2.4-alpha.0

3 years ago

2.2.1-alpha.0

3 years ago

2.2.3-alpha.1

3 years ago

2.2.3-alpha.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.3-alpha.2

3 years ago

2.2.2-alpha.0

3 years ago

2.1.3-alpha.0

3 years ago

2.2.0-alpha.11

3 years ago

2.2.0-alpha.12

3 years ago

2.2.0-alpha.13

3 years ago

2.2.0-alpha.7

3 years ago

2.2.0-alpha.6

3 years ago

2.2.0-alpha.5

3 years ago

2.2.0-alpha.0

3 years ago

2.2.0-alpha.4

3 years ago

2.2.0-alpha.3

3 years ago

2.2.0-alpha.2

3 years ago

2.2.0-alpha.1

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.1.0-alpha.0

3 years ago

2.0.0

3 years ago

2.0.0-alpha.0

3 years ago

1.7.0

3 years ago

1.7.0-alpha.0

3 years ago

1.6.6-alpha.6

3 years ago

1.6.6-alpha.8

3 years ago

1.6.6-alpha.4

3 years ago

1.6.6-alpha.5

3 years ago

1.6.6-alpha.1

3 years ago

1.6.6-alpha.2

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.0

3 years ago

1.5.20

3 years ago

1.5.19

3 years ago

1.5.17-alpha.6

4 years ago

1.5.17-alpha.5

4 years ago

1.5.17-alpha.4

4 years ago

1.5.18

4 years ago

1.5.17

4 years ago

1.5.17-alpha.0

4 years ago

1.5.17-alpha.3

4 years ago

1.5.17-alpha.1

4 years ago

1.5.15-alpha.1

4 years ago

1.5.13-alpha.0

4 years ago

1.5.12-alpha.0

4 years ago

1.5.10-alpha.0

4 years ago

1.5.9-alpha.2

4 years ago

1.5.9-alpha.0

4 years ago

1.5.7-alpha.0

4 years ago

1.5.5-alpha.6

4 years ago

1.5.5-alpha.5

4 years ago

1.5.5-alpha.3

4 years ago

1.5.5-alpha.4

4 years ago

1.5.5-alpha.2

4 years ago

1.5.3-alpha.0

4 years ago

1.5.2-alpha.1

4 years ago

1.5.2-alpha.0

4 years ago

1.5.1-alpha.6

4 years ago

1.5.1-alpha.5

4 years ago

1.5.0-beta.3

4 years ago

1.4.1-beta.1

4 years ago

1.4.1-beta.0

4 years ago

1.4.0-beta.6

4 years ago

1.4.0-alpha.12

4 years ago

1.4.0-alpha.11

4 years ago

1.4.0-alpha.10

4 years ago

1.4.0-alpha.9

4 years ago

1.4.0-alpha.8

4 years ago

1.4.0-alpha.7

4 years ago

1.4.0-alpha.1

4 years ago

1.4.0-alpha.2

4 years ago

1.4.0-alpha.0

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.0

4 years ago

1.0.7

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.2.0

4 years ago

0.1.10-alpha.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago