shred-api-client 1.1.20 → 1.2.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.
- package/dist/api/Prompt.api.d.ts +3 -1
- package/dist/api/Prompt.api.js +3 -2
- package/dist/api/Subscription.api.d.ts +3 -1
- package/dist/api/Subscription.api.js +4 -3
- package/dist/api/User.api.d.ts +3 -1
- package/dist/api/User.api.js +5 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -1
- package/dist/model/Api.d.ts +2 -1
- package/dist/model/Api.js +4 -4
- package/dist/model/Env.d.ts +2 -0
- package/dist/model/Env.js +2 -0
- package/dist/model/exceptions/ConflictException.d.ts +4 -0
- package/dist/model/exceptions/ConflictException.js +13 -0
- package/dist/model/exceptions/InvalidArgumentException.d.ts +4 -0
- package/dist/model/exceptions/InvalidArgumentException.js +13 -0
- package/dist/model/exceptions/ResourceNotFoundException.d.ts +4 -0
- package/dist/model/exceptions/ResourceNotFoundException.js +13 -0
- package/dist/model/exceptions/ShredException.d.ts +4 -0
- package/dist/model/exceptions/ShredException.js +10 -0
- package/dist/model/exceptions/index.d.ts +11 -0
- package/dist/model/exceptions/index.js +15 -0
- package/dist/util/HTTPClient.d.ts +2 -1
- package/dist/util/HTTPClient.js +3 -2
- package/package.json +1 -1
package/dist/api/Prompt.api.d.ts
CHANGED
|
@@ -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;
|
package/dist/api/Prompt.api.js
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
}
|
package/dist/api/User.api.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/api/User.api.js
CHANGED
|
@@ -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
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -13,10 +13,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Role = void 0;
|
|
20
|
+
exports.Exceptions = exports.Role = void 0;
|
|
18
21
|
const Api_1 = require("./model/Api");
|
|
19
22
|
const User_schema_1 = require("./model/User.schema");
|
|
20
23
|
Object.defineProperty(exports, "Role", { enumerable: true, get: function () { return User_schema_1.Role; } });
|
|
24
|
+
const exceptions_1 = __importDefault(require("./model/exceptions/"));
|
|
25
|
+
exports.Exceptions = exceptions_1.default;
|
|
21
26
|
exports.default = Api_1.ShredAPI;
|
|
22
27
|
__exportStar(require("./namespace"), exports);
|
package/dist/model/Api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Environment from "./Env";
|
|
1
2
|
import { PromptAPISchema } from "./Prompt.schema";
|
|
2
3
|
import { SubscriptionAPISchema } from "./Subscription.schema";
|
|
3
4
|
import { UserAPISchema } from "./User.schema";
|
|
@@ -5,5 +6,5 @@ export declare class ShredAPI {
|
|
|
5
6
|
user: UserAPISchema;
|
|
6
7
|
subscription: SubscriptionAPISchema;
|
|
7
8
|
prompt: PromptAPISchema;
|
|
8
|
-
constructor();
|
|
9
|
+
constructor(env: Environment);
|
|
9
10
|
}
|
package/dist/model/Api.js
CHANGED
|
@@ -8,10 +8,10 @@ const Prompt_api_1 = __importDefault(require("../api/Prompt.api"));
|
|
|
8
8
|
const Subscription_api_1 = __importDefault(require("../api/Subscription.api"));
|
|
9
9
|
const User_api_1 = __importDefault(require("../api/User.api"));
|
|
10
10
|
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();
|
|
11
|
+
constructor(env) {
|
|
12
|
+
this.user = new User_api_1.default(env);
|
|
13
|
+
this.prompt = new Prompt_api_1.default(env);
|
|
14
|
+
this.subscription = new Subscription_api_1.default(env);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.ShredAPI = ShredAPI;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 ShredException_1 = __importDefault(require("./ShredException"));
|
|
7
|
+
class ConflictException extends ShredException_1.default {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message, 409);
|
|
10
|
+
this.name = "ConflictException";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = ConflictException;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 ShredException_1 = __importDefault(require("./ShredException"));
|
|
7
|
+
class InvalidArgumentException extends ShredException_1.default {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message, 400);
|
|
10
|
+
this.name = "InvalidArgumentException";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = InvalidArgumentException;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 ShredException_1 = __importDefault(require("./ShredException"));
|
|
7
|
+
class ResourceNotFoundException extends ShredException_1.default {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message, 404);
|
|
10
|
+
this.name = "ResourceNotFoundException";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = ResourceNotFoundException;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ShredException extends Error {
|
|
4
|
+
constructor(message, status) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ShredException";
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = ShredException;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ConflictException from "./ConflictException";
|
|
2
|
+
import InvalidArgumentException from "./InvalidArgumentException";
|
|
3
|
+
import ResourceNotFoundException from "./ResourceNotFoundException";
|
|
4
|
+
import ShredException from "./ShredException";
|
|
5
|
+
declare const _default: {
|
|
6
|
+
ConflictException: typeof ConflictException;
|
|
7
|
+
InvalidArgumentException: typeof InvalidArgumentException;
|
|
8
|
+
ResourceNotFoundException: typeof ResourceNotFoundException;
|
|
9
|
+
ShredException: typeof ShredException;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 ConflictException_1 = __importDefault(require("./ConflictException"));
|
|
7
|
+
const InvalidArgumentException_1 = __importDefault(require("./InvalidArgumentException"));
|
|
8
|
+
const ResourceNotFoundException_1 = __importDefault(require("./ResourceNotFoundException"));
|
|
9
|
+
const ShredException_1 = __importDefault(require("./ShredException"));
|
|
10
|
+
exports.default = {
|
|
11
|
+
ConflictException: ConflictException_1.default,
|
|
12
|
+
InvalidArgumentException: InvalidArgumentException_1.default,
|
|
13
|
+
ResourceNotFoundException: ResourceNotFoundException_1.default,
|
|
14
|
+
ShredException: ShredException_1.default,
|
|
15
|
+
};
|
|
@@ -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
|
}
|
package/dist/util/HTTPClient.js
CHANGED
|
@@ -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 = {
|