From fd0b5a5aa4025b0a7920c66d89decf0cff5ad0d1 Mon Sep 17 00:00:00 2001 From: thanhtr Date: Mon, 8 Jun 2020 10:20:48 +0300 Subject: [PATCH] Add coupons and remove startTime in sub intent. Streamline states. Tweaks --- maas-schemas-ts/package.json | 2 +- maas-schemas-ts/src/core/components/state.ts | 3 - .../subscriptions/subscription-intent.ts | 95 ++++++++++++------- .../subscriptions-intents-list/response.ts | 2 +- .../response.ts | 2 +- .../request.ts | 7 +- .../response.ts | 2 +- maas-schemas-ts/translation.log | 10 +- maas-schemas/package.json | 2 +- .../schemas/core/components/state.json | 1 - .../subscriptions/subscription-intent.json | 46 ++++++--- .../subscriptions-intents-list/response.json | 2 +- .../response.json | 2 +- .../request.json | 4 +- .../response.json | 2 +- 15 files changed, 111 insertions(+), 71 deletions(-) diff --git a/maas-schemas-ts/package.json b/maas-schemas-ts/package.json index 4b158e047..f09b74be3 100644 --- a/maas-schemas-ts/package.json +++ b/maas-schemas-ts/package.json @@ -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": [ diff --git a/maas-schemas-ts/src/core/components/state.ts b/maas-schemas-ts/src/core/components/state.ts index 4a93a17b9..3920520db 100644 --- a/maas-schemas-ts/src/core/components/state.ts +++ b/maas-schemas-ts/src/core/components/state.ts @@ -166,7 +166,6 @@ export type SubscriptionIntentState = t.Branded< | 'DETAILS' | 'CUSTOMISATION' | 'PAYMENT' - | 'AUTH' | 'VERIFICATION' | 'CANCELLED' | 'CANCELLED_WITH_ERRORS' @@ -182,7 +181,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'), @@ -198,7 +196,6 @@ export const SubscriptionIntentState = t.brand( | 'DETAILS' | 'CUSTOMISATION' | 'PAYMENT' - | 'AUTH' | 'VERIFICATION' | 'CANCELLED' | 'CANCELLED_WITH_ERRORS' diff --git a/maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts b/maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts index 1a4a6a705..5dd12a948 100644 --- a/maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts +++ b/maas-schemas-ts/src/maas-backend/subscriptions/subscription-intent.ts @@ -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; -export const ItemId = t.brand( +export type PlanId = t.Branded; +export const PlanId = t.brand( t.string, - (x): x is t.Branded => - (typeof x !== 'string' || x.length >= 1) && + (x): x is t.Branded => + (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; +export const AddonId = t.brand( + t.string, + (x): x is t.Branded => + (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; +export const CouponId = t.brand( + t.string, + (x): x is t.Branded => + (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; + planId?: PlanId; + planAddons?: Array; + coupons?: Array; 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; + planId?: PlanId; + planAddons?: Array; + coupons?: Array; state?: State_.SubscriptionIntentState; - startTime?: Units_.Time; } & { planId: Defined; planAddons: Defined; + coupons: Defined; }, SubscriptionIntentCreateBrand > => true, @@ -99,11 +130,11 @@ export type SubscriptionIntentBase = t.Branded< id?: Units_.Uuid; identityId?: Units_.IdentityId; subscriptionId?: Units_.IdentityId; - nextPlanId?: ItemId; - nextPlanAddons?: Array; - prevPlanId?: ItemId; - prevPlanAddons?: Array; - startTime?: Units_.Time; + nextPlanId?: PlanId; + nextPlanAddons?: Array; + nextPlanCoupons?: Array; + prevPlanId?: PlanId; + prevPlanAddons?: Array; state?: State_.SubscriptionIntentState; stateLog?: StateLog_.StateLog; created?: Units_.Time; @@ -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, @@ -146,11 +177,11 @@ export const SubscriptionIntentBase = t.brand( id?: Units_.Uuid; identityId?: Units_.IdentityId; subscriptionId?: Units_.IdentityId; - nextPlanId?: ItemId; - nextPlanAddons?: Array; - prevPlanId?: ItemId; - prevPlanAddons?: Array; - startTime?: Units_.Time; + nextPlanId?: PlanId; + nextPlanAddons?: Array; + nextPlanCoupons?: Array; + prevPlanId?: PlanId; + prevPlanAddons?: Array; state?: State_.SubscriptionIntentState; stateLog?: StateLog_.StateLog; created?: Units_.Time; diff --git a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-list/response.ts b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-list/response.ts index d25c29b24..9df33ca8e 100644 --- a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-list/response.ts +++ b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-list/response.ts @@ -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 !!! diff --git a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-retrieve/response.ts b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-retrieve/response.ts index 01d478086..29de99bb7 100644 --- a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-retrieve/response.ts +++ b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-retrieve/response.ts @@ -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 !!! diff --git a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/request.ts b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/request.ts index d5a932afa..2dbac34a2 100644 --- a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/request.ts +++ b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/request.ts @@ -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 = @@ -38,7 +39,7 @@ export type Request = t.Branded< userId?: Units_.IdentityId; subscriptionIntentId?: Units_.Uuid; payload?: { - state?: string; + state?: State_.SubscriptionIntentState; }; headers?: ApiCommon_.Headers; } & { @@ -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, }), @@ -75,7 +76,7 @@ export const Request = t.brand( userId?: Units_.IdentityId; subscriptionIntentId?: Units_.Uuid; payload?: { - state?: string; + state?: State_.SubscriptionIntentState; }; headers?: ApiCommon_.Headers; } & { diff --git a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/response.ts b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/response.ts index 53d04d5b6..a0ae7b5a6 100644 --- a/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/response.ts +++ b/maas-schemas-ts/src/maas-backend/subscriptions/subscriptions-intents-update-state/response.ts @@ -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 !!! diff --git a/maas-schemas-ts/translation.log b/maas-schemas-ts/translation.log index e700f4225..a8959f607 100644 --- a/maas-schemas-ts/translation.log +++ b/maas-schemas-ts/translation.log @@ -1656,12 +1656,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 @@ -1676,6 +1670,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-backend/vehicle/vehicle-alert/request.json WARNING: minLength field not supported outside top-level definitions diff --git a/maas-schemas/package.json b/maas-schemas/package.json index 503a12702..138fb103a 100644 --- a/maas-schemas/package.json +++ b/maas-schemas/package.json @@ -1,6 +1,6 @@ { "name": "maas-schemas", - "version": "14.1.1", + "version": "14.2.0", "description": "Schemas for MaaS infrastructure", "main": "index.js", "engine": { diff --git a/maas-schemas/schemas/core/components/state.json b/maas-schemas/schemas/core/components/state.json index 027d7f2b4..e39f72796 100644 --- a/maas-schemas/schemas/core/components/state.json +++ b/maas-schemas/schemas/core/components/state.json @@ -39,7 +39,6 @@ "DETAILS", "CUSTOMISATION", "PAYMENT", - "AUTH", "VERIFICATION", "CANCELLED", "CANCELLED_WITH_ERRORS", diff --git a/maas-schemas/schemas/maas-backend/subscriptions/subscription-intent.json b/maas-schemas/schemas/maas-backend/subscriptions/subscription-intent.json index 0462165cc..ece15704a 100644 --- a/maas-schemas/schemas/maas-backend/subscriptions/subscription-intent.json +++ b/maas-schemas/schemas/maas-backend/subscriptions/subscription-intent.json @@ -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", @@ -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" }, @@ -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 } } diff --git a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-list/response.json b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-list/response.json index 8f13bce3d..ede695d0e 100644 --- a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-list/response.json +++ b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-list/response.json @@ -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": { diff --git a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-retrieve/response.json b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-retrieve/response.json index f26e87e8f..fc2acdf78 100644 --- a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-retrieve/response.json +++ b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-retrieve/response.json @@ -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": { diff --git a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/request.json b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/request.json index 2cbe23d43..4ca4824bd 100644 --- a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/request.json +++ b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/request.json @@ -16,9 +16,7 @@ "type": "object", "properties": { "state": { - "type": "string", - "minLength": 2, - "maxLength": 255 + "$ref": "http://maasglobal.com/core/components/state.json#/definitions/subscriptionIntentState" } } }, diff --git a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/response.json b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/response.json index 6efab9718..2be83a90e 100644 --- a/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/response.json +++ b/maas-schemas/schemas/maas-backend/subscriptions/subscriptions-intents-update-state/response.json @@ -1,6 +1,6 @@ { "$id": "http://maasglobal.com/maas-backend/subscriptions/subscriptions-intents-update-state/response.json", - "description": "Response schema for subscriptions-intents-create", + "description": "Response schema for subscriptions-intents-update-state", "type": "object", "properties": { "subscriptionIntent": {