Skip to content

Commit

Permalink
Add coupons and remove startTime in sub intent. Streamline states. Tw…
Browse files Browse the repository at this point in the history
…eaks
  • Loading branch information
thanhtr committed Jun 11, 2020
1 parent ba529be commit fff2d39
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 71 deletions.
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.1.1",
"version": "14.2.0",
"description": "TypeScript types and io-ts validators for maas-schemas",
"main": "index.js",
"files": [
Expand Down
3 changes: 0 additions & 3 deletions maas-schemas-ts/src/core/components/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export type SubscriptionIntentState = t.Branded<
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'AUTH'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
Expand All @@ -183,7 +182,6 @@ export const SubscriptionIntentState = t.brand(
t.literal('DETAILS'),
t.literal('CUSTOMISATION'),
t.literal('PAYMENT'),
t.literal('AUTH'),
t.literal('VERIFICATION'),
t.literal('CANCELLED'),
t.literal('CANCELLED_WITH_ERRORS'),
Expand All @@ -199,7 +197,6 @@ export const SubscriptionIntentState = t.brand(
| 'DETAILS'
| 'CUSTOMISATION'
| 'PAYMENT'
| 'AUTH'
| 'VERIFICATION'
| 'CANCELLED'
| 'CANCELLED_WITH_ERRORS'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,58 +31,89 @@ const Defined = t.union([
export const schemaId =
'http://maasglobal.com/maas-backend/subscriptions/subscription-intent.json';

// ItemId
// PlanId
// The purpose of this remains a mystery
export type ItemId = t.Branded<string, ItemIdBrand>;
export const ItemId = t.brand(
export type PlanId = t.Branded<string, PlanIdBrand>;
export const PlanId = t.brand(
t.string,
(x): x is t.Branded<string, ItemIdBrand> =>
(typeof x !== 'string' || x.length >= 1) &&
(x): x is t.Branded<string, PlanIdBrand> =>
(typeof x !== 'string' || x.length >= 2) &&
(typeof x !== 'string' || x.length <= 255),
'ItemId',
'PlanId',
);
export interface ItemIdBrand {
readonly ItemId: unique symbol;
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?: ItemId;
planAddons?: Array<ItemId>;
planId?: PlanId;
planAddons?: Array<AddonId>;
coupons?: Array<CouponId>;
state?: State_.SubscriptionIntentState;
startTime?: Units_.Time;
} & {
planId: Defined;
planAddons: Defined;
coupons: Defined;
},
SubscriptionIntentCreateBrand
>;
export const SubscriptionIntentCreate = t.brand(
t.intersection([
t.partial({
planId: ItemId,
planAddons: t.array(ItemId),
planId: PlanId,
planAddons: t.array(AddonId),
coupons: t.array(CouponId),
state: State_.SubscriptionIntentState,
startTime: Units_.Time,
}),
t.type({
planId: Defined,
planAddons: Defined,
coupons: Defined,
}),
]),
(
x,
): x is t.Branded<
{
planId?: ItemId;
planAddons?: Array<ItemId>;
planId?: PlanId;
planAddons?: Array<AddonId>;
coupons?: Array<CouponId>;
state?: State_.SubscriptionIntentState;
startTime?: Units_.Time;
} & {
planId: Defined;
planAddons: Defined;
coupons: Defined;
},
SubscriptionIntentCreateBrand
> => true,
Expand All @@ -99,11 +130,11 @@ export type SubscriptionIntentBase = t.Branded<
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: ItemId;
nextPlanAddons?: Array<ItemId>;
prevPlanId?: ItemId;
prevPlanAddons?: Array<ItemId>;
startTime?: Units_.Time;
nextPlanId?: PlanId;
nextPlanAddons?: Array<AddonId>;
nextPlanCoupons?: Array<CouponId>;
prevPlanId?: PlanId;
prevPlanAddons?: Array<AddonId>;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
Expand All @@ -122,11 +153,11 @@ export const SubscriptionIntentBase = t.brand(
id: Units_.Uuid,
identityId: Units_.IdentityId,
subscriptionId: Units_.IdentityId,
nextPlanId: ItemId,
nextPlanAddons: t.array(ItemId),
prevPlanId: ItemId,
prevPlanAddons: t.array(ItemId),
startTime: Units_.Time,
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,
Expand All @@ -146,11 +177,11 @@ export const SubscriptionIntentBase = t.brand(
id?: Units_.Uuid;
identityId?: Units_.IdentityId;
subscriptionId?: Units_.IdentityId;
nextPlanId?: ItemId;
nextPlanAddons?: Array<ItemId>;
prevPlanId?: ItemId;
prevPlanAddons?: Array<ItemId>;
startTime?: Units_.Time;
nextPlanId?: PlanId;
nextPlanAddons?: Array<AddonId>;
nextPlanCoupons?: Array<CouponId>;
prevPlanId?: PlanId;
prevPlanAddons?: Array<AddonId>;
state?: State_.SubscriptionIntentState;
stateLog?: StateLog_.StateLog;
created?: Units_.Time;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
undefined
Response schema for subscriptions-intents-create
Response schema for subscriptions-intents-list
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
undefined
Response schema for subscriptions-intents-create
Response schema for subscriptions-intents-retrieve
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Request schema for subscriptions-intents-update-state

import * as t from 'io-ts';
import * as Units_ from 'maas-schemas-ts/core/components/units';
import * as State_ from 'maas-schemas-ts/core/components/state';
import * as ApiCommon_ from 'maas-schemas-ts/core/components/api-common';

type Defined =
Expand Down Expand Up @@ -38,7 +39,7 @@ export type Request = t.Branded<
userId?: Units_.IdentityId;
subscriptionIntentId?: Units_.Uuid;
payload?: {
state?: string;
state?: State_.SubscriptionIntentState;
};
headers?: ApiCommon_.Headers;
} & {
Expand All @@ -56,7 +57,7 @@ export const Request = t.brand(
userId: Units_.IdentityId,
subscriptionIntentId: Units_.Uuid,
payload: t.partial({
state: t.string,
state: State_.SubscriptionIntentState,
}),
headers: ApiCommon_.Headers,
}),
Expand All @@ -75,7 +76,7 @@ export const Request = t.brand(
userId?: Units_.IdentityId;
subscriptionIntentId?: Units_.Uuid;
payload?: {
state?: string;
state?: State_.SubscriptionIntentState;
};
headers?: ApiCommon_.Headers;
} & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
undefined
Response schema for subscriptions-intents-create
Response schema for subscriptions-intents-update-state
!!! AUTO GENERATED BY CONVERT.TS REFRAIN FROM MANUAL EDITING !!!
Expand Down
10 changes: 4 additions & 6 deletions maas-schemas-ts/translation.log
Original file line number Diff line number Diff line change
Expand Up @@ -1658,12 +1658,6 @@ WARNING: minLength field not supported outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-intents-list/request.json
WARNING: maxLength field not supported outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-intents-list/request.json
INFO: primitive type "string" used outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-intents-update-state/request.json
WARNING: minLength field not supported outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-intents-update-state/request.json
WARNING: maxLength field not supported outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-intents-update-state/request.json
INFO: primitive type "string" used outside top-level definitions
in ./maas-backend/subscriptions/subscriptions-options/request.json
WARNING: minLength field not supported outside top-level definitions
Expand All @@ -1678,6 +1672,10 @@ INFO: missing description
in ./maas-backend/subscriptions/subscription-intent.json
INFO: missing description
in ./maas-backend/subscriptions/subscription-intent.json
INFO: missing description
in ./maas-backend/subscriptions/subscription-intent.json
INFO: missing description
in ./maas-backend/subscriptions/subscription-intent.json
INFO: primitive type "string" used outside top-level definitions
in ../maas-schemas/schemas/maas-backend/vehicle/vehicle-alert/request.json
WARNING: minLength field not supported outside top-level definitions
Expand Down
2 changes: 1 addition & 1 deletion maas-schemas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maas-schemas",
"version": "14.1.1",
"version": "14.2.0",
"description": "Schemas for MaaS infrastructure",
"main": "index.js",
"engine": {
Expand Down
1 change: 0 additions & 1 deletion maas-schemas/schemas/core/components/state.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"DETAILS",
"CUSTOMISATION",
"PAYMENT",
"AUTH",
"VERIFICATION",
"CANCELLED",
"CANCELLED_WITH_ERRORS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
"type": "object",
"properties": {
"planId": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/planId"
},
"planAddons": {
"type": "array",
"items": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/addonId"
}
},
"coupons": {
"type": "array",
"items": {
"$ref": "#/definitions/couponId"
}
},
"state": {
"$ref": "http://maasglobal.com/core/components/state.json#/definitions/subscriptionIntentState"
},
"startTime": {
"$ref": "http://maasglobal.com/core/components/units.json#/definitions/time"
}
},
"required": ["planId", "planAddons"]
"required": ["planId", "planAddons", "coupons"]
},
"subscriptionIntentBase": {
"type": "object",
Expand All @@ -36,26 +39,29 @@
"$ref": "http://maasglobal.com/core/components/units.json#/definitions/identityId"
},
"nextPlanId": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/planId"
},
"nextPlanAddons": {
"type": "array",
"items": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/addonId"
}
},
"nextPlanCoupons": {
"type": "array",
"items": {
"$ref": "#/definitions/couponId"
}
},
"prevPlanId": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/planId"
},
"prevPlanAddons": {
"type": "array",
"items": {
"$ref": "#/definitions/itemId"
"$ref": "#/definitions/addonId"
}
},
"startTime": {
"$ref": "http://maasglobal.com/core/components/units.json#/definitions/time"
},
"state": {
"$ref": "http://maasglobal.com/core/components/state.json#/definitions/subscriptionIntentState"
},
Expand All @@ -72,9 +78,19 @@
"required": ["identityId", "subscriptionId", "nextPlanId", "nextPlanAddons"],
"additionalProperties": false
},
"itemId": {
"addonId": {
"type": "string",
"minLength": 2,
"maxLength": 255
},
"planId": {
"type": "string",
"minLength": 2,
"maxLength": 255
},
"couponId": {
"type": "string",
"minLength": 1,
"minLength": 2,
"maxLength": 255
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$id": "http://maasglobal.com/maas-backend/subscriptions/subscriptions-intents-list/response.json",
"description": "Response schema for subscriptions-intents-create",
"description": "Response schema for subscriptions-intents-list",
"type": "object",
"properties": {
"subscriptionIntents": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$id": "http://maasglobal.com/maas-backend/subscriptions/subscriptions-intents-retrieve/response.json",
"description": "Response schema for subscriptions-intents-create",
"description": "Response schema for subscriptions-intents-retrieve",
"type": "object",
"properties": {
"subscriptionIntent": {
Expand Down
Loading

0 comments on commit fff2d39

Please sign in to comment.