shred-api-client 1.0.23 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,9 @@
1
+ import Context from "../src/model/Context";
1
2
  import { Product, SubscriptionAPISchema } from "../model/Subscription.schema";
2
3
  declare class SubscriptionAPI implements SubscriptionAPISchema {
3
4
  private clientHTTP;
4
5
  constructor();
5
6
  getProducts(): Promise<Product[]>;
7
+ createCheckout(planId: string, ctx: Context): Promise<string>;
6
8
  }
7
9
  export default SubscriptionAPI;
@@ -14,5 +14,10 @@ class SubscriptionAPI {
14
14
  const data = await this.clientHTTP.makeRequest(endpointInfo.uri, endpointInfo.method, null);
15
15
  return data;
16
16
  }
17
+ async createCheckout(planId, ctx) {
18
+ const endpointInfo = Subscription_schema_1.SubscriptionEndpoints.Checkout;
19
+ const data = await this.clientHTTP.makeRequest(endpointInfo.uri, endpointInfo.method, { planId }, ctx);
20
+ return data.url;
21
+ }
17
22
  }
18
23
  exports.default = SubscriptionAPI;
@@ -13,6 +13,13 @@ class UserAPI {
13
13
  const endpointData = User_schema_1.UserEndpoints.GetUserInfo;
14
14
  const data = await this.clientHTTP.makeRequest(endpointData.uri, endpointData.method, null, context, true //Use legacy api (old endpoints)
15
15
  );
16
+ if (!data.registered) {
17
+ //Login by 3rd party and don't have register yet
18
+ const enableEndpointData = User_schema_1.UserEndpoints.EnableUser;
19
+ const user = await this.clientHTTP.makeRequest(enableEndpointData.uri, enableEndpointData.method, null, context, true //Use legacy api (old endpoints)
20
+ );
21
+ return user;
22
+ }
16
23
  return data;
17
24
  }
18
25
  }
@@ -1,5 +1,5 @@
1
1
  type Context = {
2
2
  token: string;
3
- requestId: string;
3
+ requestId?: string;
4
4
  };
5
5
  export default Context;
@@ -1,11 +1,17 @@
1
+ import Context from "./Context";
1
2
  interface SubscriptionAPISchema {
2
3
  getProducts: () => Promise<Product[]>;
4
+ createCheckout: (planId: string, ctx: Context) => Promise<string>;
3
5
  }
4
6
  declare const SubscriptionEndpoints: {
5
7
  GetProducts: {
6
8
  uri: string;
7
9
  method: string;
8
10
  };
11
+ Checkout: {
12
+ uri: string;
13
+ method: string;
14
+ };
9
15
  UpdateUser: {
10
16
  uri: string;
11
17
  method: string;
@@ -6,6 +6,10 @@ const SubscriptionEndpoints = {
6
6
  uri: "/subscriptions/products/public/list",
7
7
  method: "GET",
8
8
  },
9
+ Checkout: {
10
+ uri: "/subscriptions/payment/checkout",
11
+ method: "POST",
12
+ },
9
13
  UpdateUser: {
10
14
  uri: "/api/user/update",
11
15
  method: "PUT",
@@ -9,6 +9,10 @@ declare const UserEndpoints: {
9
9
  uri: string;
10
10
  method: string;
11
11
  };
12
+ EnableUser: {
13
+ uri: string;
14
+ method: string;
15
+ };
12
16
  };
13
17
  type Preferences = {
14
18
  primaryColor?: string;
@@ -6,5 +6,9 @@ const UserEndpoints = {
6
6
  uri: "/api/user/info",
7
7
  method: "GET",
8
8
  },
9
+ EnableUser: {
10
+ uri: "/api/user/register",
11
+ method: "POST",
12
+ },
9
13
  };
10
14
  exports.UserEndpoints = UserEndpoints;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shred-api-client",
3
- "version": "1.0.23",
3
+ "version": "1.1.1",
4
4
  "description": "API Client for Shred",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "build": "tsc --project tsconfig.json && tscpaths -p tsconfig.json -s . -o ./dist",
13
- "build:watch": "tsc -w"
13
+ "build:watch": "tsc -w --project tsconfig.json && tscpaths -p tsconfig.json -s . -o ./dist"
14
14
  },
15
15
  "author": "Marcus Cartágenes",
16
16
  "license": "ISC",