Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscription intent schemas #519

Open
wants to merge 6 commits into
base: v14-develop-stream
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion maas-schemas-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maas-schemas-ts",
"version": "14.2.1",
"version": "14.3.0",
"description": "TypeScript types and io-ts validators for maas-schemas",
"main": "index.js",
"files": [
Expand Down
52 changes: 52 additions & 0 deletions maas-schemas-ts/src/core/components/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,58 @@ export interface ItineraryStateBrand {
readonly ItineraryState: unique symbol;
}

// SubscriptionIntentState
// The life-cycle state of an subscription intent
export type SubscriptionIntentState = t.Branded<
string &
(
| 'START'
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
| 'FINISHED'
),
SubscriptionIntentStateBrand
>;
export const SubscriptionIntentState = t.brand(
t.intersection([
t.string,
t.union([
t.literal('START'),
t.literal('DETAILS'),
t.literal('CUSTOMISATION'),
t.literal('PAYMENT'),
t.literal('VERIFICATION'),
t.literal('CANCELLED'),
t.literal('CANCELLED_WITH_ERRORS'),
t.literal('FINISHED'),
]),
]),
(
x,
): x is t.Branded<
string &
(
| 'START'
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
| 'FINISHED'
),
SubscriptionIntentStateBrand
> => true,
'SubscriptionIntentState',
);
export interface SubscriptionIntentStateBrand {
readonly SubscriptionIntentState: unique symbol;
}

// State
// The default export. More information at the top.
export type State = t.Branded<unknown, StateBrand>;
Expand Down
218 changes: 218 additions & 0 deletions maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*

undefined
MaaS subscription intent schema

!!! AUTO GENERATED BY IOTSFJS REFRAIN FROM MANUAL EDITING !!!
See https://www.npmjs.com/package/io-ts-from-json-schema

*/

import * as t from 'io-ts';
import * as State_ from '../../core/components/state';
import * as Units_ from '../../core/components/units';
import * as StateLog_ from '../../core/components/state-log';

type Defined =
| Record<string, unknown>
| Array<unknown>
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);

export const schemaId =
'http://maasglobal.com/maas-backend/subscriptions/subscription-intent.json';

// PlanId
// The purpose of this remains a mystery
export type PlanId = t.Branded<string, PlanIdBrand>;
export const PlanId = t.brand(
t.string,
(x): x is t.Branded<string, PlanIdBrand> =>
(typeof x !== 'string' || x.length >= 2) &&
(typeof x !== 'string' || x.length <= 255),
'PlanId',
);
export interface PlanIdBrand {
readonly PlanId: unique symbol;
}

// AddonId
// The purpose of this remains a mystery
export type AddonId = t.Branded<string, AddonIdBrand>;
export const AddonId = t.brand(
t.string,
(x): x is t.Branded<string, AddonIdBrand> =>
(typeof x !== 'string' || x.length >= 2) &&
(typeof x !== 'string' || x.length <= 255),
'AddonId',
);
export interface AddonIdBrand {
readonly AddonId: unique symbol;
}

// CouponId
// The purpose of this remains a mystery
export type CouponId = t.Branded<string, CouponIdBrand>;
export const CouponId = t.brand(
t.string,
(x): x is t.Branded<string, CouponIdBrand> =>
(typeof x !== 'string' || x.length >= 2) &&
(typeof x !== 'string' || x.length <= 255),
'CouponId',
);
export interface CouponIdBrand {
readonly CouponId: unique symbol;
}

// SubscriptionIntentCreate
// The purpose of this remains a mystery
export type SubscriptionIntentCreate = t.Branded<
{
planId?: PlanId;
planAddons?: Array<AddonId>;
coupons?: Array<CouponId>;
state?: State_.SubscriptionIntentState;
} & {
planId: Defined;
planAddons: Defined;
},
SubscriptionIntentCreateBrand
>;
export const SubscriptionIntentCreate = t.brand(
t.intersection([
t.partial({
planId: PlanId,
planAddons: t.array(AddonId),
coupons: t.array(CouponId),
state: State_.SubscriptionIntentState,
}),
t.type({
planId: Defined,
planAddons: Defined,
}),
]),
(
x,
): x is t.Branded<
{
planId?: PlanId;
planAddons?: Array<AddonId>;
coupons?: Array<CouponId>;
state?: State_.SubscriptionIntentState;
} & {
planId: Defined;
planAddons: Defined;
},
SubscriptionIntentCreateBrand
> => true,
'SubscriptionIntentCreate',
);
export interface SubscriptionIntentCreateBrand {
readonly SubscriptionIntentCreate: unique symbol;
}

// SubscriptionIntentBase
// The purpose of this remains a mystery
export type SubscriptionIntentBase = t.Branded<
{
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: PlanId;
nextPlanAddons?: Array<AddonId>;
nextPlanCoupons?: Array<CouponId>;
prevPlanId?: PlanId;
prevPlanAddons?: Array<AddonId>;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
modified?: Units_.Time;
} & {
identityId: Defined;
subscriptionId: Defined;
nextPlanId: Defined;
nextPlanAddons: Defined;
nextPlanCoupons: Defined;
},
SubscriptionIntentBaseBrand
>;
export const SubscriptionIntentBase = t.brand(
t.intersection([
t.partial({
id: Units_.Uuid,
identityId: Units_.IdentityId,
subscriptionId: Units_.IdentityId,
nextPlanId: PlanId,
nextPlanAddons: t.array(AddonId),
nextPlanCoupons: t.array(CouponId),
prevPlanId: PlanId,
prevPlanAddons: t.array(AddonId),
state: State_.SubscriptionIntentState,
stateLog: StateLog_.StateLog,
created: Units_.Time,
modified: Units_.Time,
}),
t.type({
identityId: Defined,
subscriptionId: Defined,
nextPlanId: Defined,
nextPlanAddons: Defined,
nextPlanCoupons: Defined,
}),
]),
(
x,
): x is t.Branded<
{
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: PlanId;
nextPlanAddons?: Array<AddonId>;
nextPlanCoupons?: Array<CouponId>;
prevPlanId?: PlanId;
prevPlanAddons?: Array<AddonId>;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
modified?: Units_.Time;
} & {
identityId: Defined;
subscriptionId: Defined;
nextPlanId: Defined;
nextPlanAddons: Defined;
nextPlanCoupons: Defined;
},
SubscriptionIntentBaseBrand
> => true,
'SubscriptionIntentBase',
);
export interface SubscriptionIntentBaseBrand {
readonly SubscriptionIntentBase: unique symbol;
}

// SubscriptionIntent
// The default export. More information at the top.
export type SubscriptionIntent = t.Branded<unknown, SubscriptionIntentBrand>;
export const SubscriptionIntent = t.brand(
t.unknown,
(x): x is t.Branded<unknown, SubscriptionIntentBrand> => true,
'SubscriptionIntent',
);
export interface SubscriptionIntentBrand {
readonly SubscriptionIntent: unique symbol;
}

export default SubscriptionIntent;

// Success
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*

undefined
Request schema for subscriptions-intents-create

!!! AUTO GENERATED BY IOTSFJS REFRAIN FROM MANUAL EDITING !!!
See https://www.npmjs.com/package/io-ts-from-json-schema

*/

import * as t from 'io-ts';
import * as Units_ from '../../../core/components/units';
import * as SubscriptionIntent_ from '../subscription-intent';
import * as ApiCommon_ from '../../../core/components/api-common';

type Defined =
| Record<string, unknown>
| Array<unknown>
| string
| boolean
| number
| null;
const Defined = t.union([
t.UnknownRecord,
t.UnknownArray,
t.string,
t.boolean,
t.number,
t.null,
]);

export const schemaId =
'http://maasglobal.com/maas-backend/subscriptions/subscriptions-intents-create/request.json';

// Request
// The default export. More information at the top.
export type Request = t.Branded<
{
customerId?: Units_.IdentityId;
userId?: Units_.IdentityId;
payload?: SubscriptionIntent_.SubscriptionIntentCreate;
headers?: ApiCommon_.Headers;
} & {
customerId: Defined;
userId: Defined;
payload: Defined;
},
RequestBrand
>;
export const Request = t.brand(
t.intersection([
t.partial({
customerId: Units_.IdentityId,
userId: Units_.IdentityId,
payload: SubscriptionIntent_.SubscriptionIntentCreate,
headers: ApiCommon_.Headers,
}),
t.type({
customerId: Defined,
userId: Defined,
payload: Defined,
}),
]),
(
x,
): x is t.Branded<
{
customerId?: Units_.IdentityId;
userId?: Units_.IdentityId;
payload?: SubscriptionIntent_.SubscriptionIntentCreate;
headers?: ApiCommon_.Headers;
} & {
customerId: Defined;
userId: Defined;
payload: Defined;
},
RequestBrand
> => true,
'Request',
);
export interface RequestBrand {
readonly Request: unique symbol;
}

export default Request;

// Success
Loading