shred-api-client 1.2.0 → 1.2.2

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,8 +1,10 @@
1
1
  import Context from "../model/Context";
2
2
  import { Prompt, PromptAPISchema } from "../model/Prompt.schema";
3
+ import Environment from "../model/Env";
3
4
  declare class PromptAPI implements PromptAPISchema {
5
+ private env;
4
6
  private clientHTTP;
5
- constructor();
7
+ constructor(env: Environment);
6
8
  getPrompt(context: Context): Promise<Prompt>;
7
9
  }
8
10
  export default PromptAPI;
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const HTTPClient_1 = __importDefault(require("../util/HTTPClient"));
7
7
  const Prompt_schema_1 = require("../model/Prompt.schema");
8
8
  class PromptAPI {
9
- constructor() {
9
+ constructor(env) {
10
+ this.env = env;
10
11
  this.clientHTTP = new HTTPClient_1.default();
11
12
  }
12
13
  async getPrompt(context) {
13
14
  const endpointInfo = Prompt_schema_1.PromptEndpoints.GetPrompt;
14
- const data = await this.clientHTTP.makeRequest(endpointInfo.uri, endpointInfo.method, null, context);
15
+ const data = await this.clientHTTP.makeRequest(this.env, endpointInfo.uri, endpointInfo.method, null, context);
15
16
  return data;
16
17
  }
17
18
  }
@@ -0,0 +1,10 @@
1
+ import Environment from "../model/Env";
2
+ import { SMSAPISchema } from "../model/SMS.schema";
3
+ declare class SMSAPI implements SMSAPISchema {
4
+ private env;
5
+ private clientHTTP;
6
+ constructor(env: Environment);
7
+ verify(phone: string, code: number): Promise<boolean>;
8
+ sendVerifyCode(phone: string, friendlyName?: string | undefined): Promise<boolean>;
9
+ }
10
+ export default SMSAPI;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const HTTPClient_1 = __importDefault(require("../util/HTTPClient"));
7
+ const SMS_schema_1 = require("../model/SMS.schema");
8
+ class SMSAPI {
9
+ constructor(env) {
10
+ this.env = env;
11
+ this.clientHTTP = new HTTPClient_1.default();
12
+ }
13
+ async verify(phone, code) {
14
+ const endpointInfo = SMS_schema_1.SMSEndpoints.SendVerifyCode;
15
+ const data = await this.clientHTTP.makeRequest(this.env, endpointInfo.uri, endpointInfo.method, { phone, code });
16
+ return data;
17
+ }
18
+ async sendVerifyCode(phone, friendlyName) {
19
+ const endpointInfo = SMS_schema_1.SMSEndpoints.SendVerifyCode;
20
+ const data = await this.clientHTTP.makeRequest(this.env, endpointInfo.uri, endpointInfo.method, { phone, friendlyName });
21
+ return data;
22
+ }
23
+ }
24
+ exports.default = SMSAPI;
@@ -1,8 +1,10 @@
1
1
  import Context from "../src/model/Context";
2
2
  import { Product, SubscriptionAPISchema } from "../model/Subscription.schema";
3
+ import Environment from "../model/Env";
3
4
  declare class SubscriptionAPI implements SubscriptionAPISchema {
5
+ private env;
4
6
  private clientHTTP;
5
- constructor();
7
+ constructor(env: Environment);
6
8
  getProducts(): Promise<Product[]>;
7
9
  createCheckout(planId: string, ctx: Context): Promise<string>;
8
10
  }
@@ -6,17 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Subscription_schema_1 = require("../model/Subscription.schema");
7
7
  const HTTPClient_1 = __importDefault(require("../util/HTTPClient"));
8
8
  class SubscriptionAPI {
9
- constructor() {
9
+ constructor(env) {
10
+ this.env = env;
10
11
  this.clientHTTP = new HTTPClient_1.default();
11
12
  }
12
13
  async getProducts() {
13
14
  const endpointInfo = Subscription_schema_1.SubscriptionEndpoints.GetProducts;
14
- const data = await this.clientHTTP.makeRequest(endpointInfo.uri, endpointInfo.method, null);
15
+ const data = await this.clientHTTP.makeRequest(this.env, endpointInfo.uri, endpointInfo.method, null);
15
16
  return data;
16
17
  }
17
18
  async createCheckout(planId, ctx) {
18
19
  const endpointInfo = Subscription_schema_1.SubscriptionEndpoints.Checkout;
19
- const data = await this.clientHTTP.makeRequest(endpointInfo.uri, endpointInfo.method, { planId }, ctx);
20
+ const data = await this.clientHTTP.makeRequest(this.env, endpointInfo.uri, endpointInfo.method, { planId }, ctx);
20
21
  return data.url;
21
22
  }
22
23
  }
@@ -1,8 +1,10 @@
1
1
  import Context from "../model/Context";
2
2
  import { User, UserAPISchema } from "../model/User.schema";
3
+ import Environment from "../model/Env";
3
4
  declare class UserAPI implements UserAPISchema {
5
+ private env;
4
6
  private clientHTTP;
5
- constructor();
7
+ constructor(env: Environment);
6
8
  createUser(email: string, name: string, newPassword: string, newPasswordConfirmation: string, profession: string | null, invitationCode: string | null): Promise<any>;
7
9
  getUserInfo(context: Context): Promise<User>;
8
10
  }
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const User_schema_1 = require("../model/User.schema");
7
7
  const HTTPClient_1 = __importDefault(require("../util/HTTPClient"));
8
8
  class UserAPI {
9
- constructor() {
9
+ constructor(env) {
10
+ this.env = env;
10
11
  this.clientHTTP = new HTTPClient_1.default();
11
12
  }
12
13
  async createUser(email, name, newPassword, newPasswordConfirmation, profession, invitationCode) {
13
14
  const endpointData = User_schema_1.UserEndpoints.CreateUser;
14
- const data = await this.clientHTTP.makeRequest(endpointData.uri, endpointData.method, {
15
+ const data = await this.clientHTTP.makeRequest(this.env, endpointData.uri, endpointData.method, {
15
16
  email,
16
17
  name,
17
18
  newPassword,
@@ -24,12 +25,12 @@ class UserAPI {
24
25
  }
25
26
  async getUserInfo(context) {
26
27
  const endpointData = User_schema_1.UserEndpoints.GetUserInfo;
27
- const data = await this.clientHTTP.makeRequest(endpointData.uri, endpointData.method, null, context, true //Use legacy api (old endpoints)
28
+ const data = await this.clientHTTP.makeRequest(this.env, endpointData.uri, endpointData.method, null, context, true //Use legacy api (old endpoints)
28
29
  );
29
30
  if (!data.registered) {
30
31
  //Login by 3rd party and don't have register yet
31
32
  const enableEndpointData = User_schema_1.UserEndpoints.EnableUser;
32
- const user = await this.clientHTTP.makeRequest(enableEndpointData.uri, enableEndpointData.method, null, context, true //Use legacy api (old endpoints)
33
+ const user = await this.clientHTTP.makeRequest(this.env, enableEndpointData.uri, enableEndpointData.method, null, context, true //Use legacy api (old endpoints)
33
34
  );
34
35
  return user;
35
36
  }
@@ -1,9 +1,12 @@
1
+ import Environment from "./Env";
1
2
  import { PromptAPISchema } from "./Prompt.schema";
3
+ import { SMSAPISchema } from "./SMS.schema";
2
4
  import { SubscriptionAPISchema } from "./Subscription.schema";
3
5
  import { UserAPISchema } from "./User.schema";
4
6
  export declare class ShredAPI {
5
7
  user: UserAPISchema;
6
8
  subscription: SubscriptionAPISchema;
7
9
  prompt: PromptAPISchema;
8
- constructor();
10
+ sms: SMSAPISchema;
11
+ constructor(env: Environment);
9
12
  }
package/dist/model/Api.js CHANGED
@@ -4,14 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ShredAPI = void 0;
7
+ const SMS_api_1 = __importDefault(require("../src/api/SMS.api"));
7
8
  const Prompt_api_1 = __importDefault(require("../api/Prompt.api"));
8
9
  const Subscription_api_1 = __importDefault(require("../api/Subscription.api"));
9
10
  const User_api_1 = __importDefault(require("../api/User.api"));
10
11
  class ShredAPI {
11
- constructor() {
12
- this.user = new User_api_1.default();
13
- this.prompt = new Prompt_api_1.default();
14
- this.subscription = new Subscription_api_1.default();
12
+ constructor(env) {
13
+ this.user = new User_api_1.default(env);
14
+ this.prompt = new Prompt_api_1.default(env);
15
+ this.subscription = new Subscription_api_1.default(env);
16
+ this.sms = new SMS_api_1.default(env);
15
17
  }
16
18
  }
17
19
  exports.ShredAPI = ShredAPI;
@@ -0,0 +1,2 @@
1
+ type Environment = "prod" | "staging" | "local";
2
+ export default Environment;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ interface SMSAPISchema {
2
+ sendVerifyCode: (phone: string, friendlyName?: string) => Promise<boolean>;
3
+ verify: (phone: string, number: number) => Promise<boolean>;
4
+ }
5
+ declare const SMSEndpoints: {
6
+ SendVerifyCode: {
7
+ uri: string;
8
+ method: string;
9
+ };
10
+ VerifyCode: {
11
+ uri: string;
12
+ method: string;
13
+ };
14
+ };
15
+ export { SMSAPISchema, SMSEndpoints };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SMSEndpoints = void 0;
4
+ const SMSEndpoints = {
5
+ SendVerifyCode: {
6
+ uri: "/sms/public/verify/send",
7
+ method: "POST",
8
+ },
9
+ VerifyCode: {
10
+ uri: "/sms/public/verify",
11
+ method: "POST",
12
+ },
13
+ };
14
+ exports.SMSEndpoints = SMSEndpoints;
@@ -1,4 +1,5 @@
1
+ import Environment from "../src/model/Env";
1
2
  import Context from "./../model/Context";
2
3
  export default class HTTPClient {
3
- makeRequest(uri: string, method: string, data?: any, context?: Context | null, useLegacyApi?: boolean): Promise<any>;
4
+ makeRequest(env: Environment, uri: string, method: string, data?: any, context?: Context | null, useLegacyApi?: boolean): Promise<any>;
4
5
  }
@@ -7,15 +7,16 @@ const axios_1 = __importDefault(require("axios"));
7
7
  const HOSTS = {
8
8
  prod: "https://api.shreditapp.com",
9
9
  staging: "https://api.staging.shreditapp.com",
10
+ local: "https://api.staging.shreditapp.com",
10
11
  };
11
12
  const OLD_HOSTS = {
12
13
  prod: "https://api.shredmedia.co",
13
14
  staging: "https://api-staging.shredmedia.co",
15
+ local: "https://api-staging.shredmedia.co",
14
16
  };
15
17
  class HTTPClient {
16
- async makeRequest(uri, method, data, context, useLegacyApi) {
18
+ async makeRequest(env, uri, method, data, context, useLegacyApi) {
17
19
  var _a;
18
- const env = (process.env.NEXT_PUBLIC_ENV || process.env.ENV);
19
20
  const hostDict = useLegacyApi ? OLD_HOSTS : HOSTS;
20
21
  const host = hostDict[env] || hostDict.staging;
21
22
  const config = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shred-api-client",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "API Client for Shred",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,7 +15,9 @@
15
15
  "author": "Marcus Cartágenes",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
+ "@types/uuid": "^10.0.0",
18
19
  "axios": "1.7.2",
20
+ "uuid": "^10.0.0",
19
21
  "winston": "^3.13.0"
20
22
  },
21
23
  "devDependencies": {