shred-api-client 1.0.5 → 1.0.7
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/User.api.d.ts +8 -0
- package/dist/api/User.api.js +17 -0
- package/dist/index.d.ts +2 -36
- package/dist/index.js +3 -91
- package/dist/model/Api.d.ts +5 -0
- package/dist/model/Api.js +13 -0
- package/dist/model/Context.d.ts +5 -0
- package/dist/model/Context.js +2 -0
- package/dist/model/User.schema.d.ts +29 -0
- package/dist/model/User.schema.js +7 -0
- package/dist/util/HTTPClient.d.ts +6 -0
- package/dist/util/HTTPClient.js +37 -0
- package/package.json +4 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Context from "../model/Context";
|
|
2
|
+
import { User, UserAPISchema } from "../model/User.schema";
|
|
3
|
+
declare class UserAPI implements UserAPISchema {
|
|
4
|
+
private clientHTTP;
|
|
5
|
+
constructor();
|
|
6
|
+
getUserInfo(context: Context): Promise<User>;
|
|
7
|
+
}
|
|
8
|
+
export default UserAPI;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 User_schema_1 = require("../model/User.schema");
|
|
7
|
+
const HTTPClient_1 = __importDefault(require("../util/HTTPClient"));
|
|
8
|
+
class UserAPI {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.clientHTTP = new HTTPClient_1.default();
|
|
11
|
+
}
|
|
12
|
+
async getUserInfo(context) {
|
|
13
|
+
const data = await this.clientHTTP.makeRequest(User_schema_1.UserEndpoints.GetUserInfo, "GET", null, context);
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = UserAPI;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
requestId: string;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
interface UserAPISchema {
|
|
7
|
-
getUserInfo: (context: Context) => Promise<User>;
|
|
8
|
-
}
|
|
9
|
-
type Preferences = {
|
|
10
|
-
primaryColor?: string;
|
|
11
|
-
secondaryColor?: string;
|
|
12
|
-
facebookLink?: string;
|
|
13
|
-
instagramLink?: string;
|
|
14
|
-
bRoll?: boolean;
|
|
15
|
-
logo?: string;
|
|
16
|
-
};
|
|
17
|
-
type User = {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
email: string;
|
|
21
|
-
customerId: string;
|
|
22
|
-
registered: boolean;
|
|
23
|
-
profession?: string;
|
|
24
|
-
registeredAt: number;
|
|
25
|
-
fcmToken?: string;
|
|
26
|
-
photoUrl?: string;
|
|
27
|
-
preferences?: Preferences;
|
|
28
|
-
invitationCode?: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
declare class ShredAPI {
|
|
32
|
-
user: UserAPISchema;
|
|
33
|
-
constructor();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { ShredAPI as default };
|
|
1
|
+
import { ShredAPI } from "./model/Api";
|
|
2
|
+
export default ShredAPI;
|
package/dist/index.js
CHANGED
|
@@ -1,92 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
default: () => src_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
|
-
// src/model/User.schema.ts
|
|
28
|
-
var UserEndpoints = {
|
|
29
|
-
GetUserInfo: "/user/info"
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/util/HTTPClient.ts
|
|
33
|
-
var HOSTS = {
|
|
34
|
-
prod: "https://api.shredmedia.co",
|
|
35
|
-
staging: "https://api-staging.shredmedia.co"
|
|
36
|
-
};
|
|
37
|
-
var HTTPClient = class {
|
|
38
|
-
constructor() {
|
|
39
|
-
const env = process.env.ENV;
|
|
40
|
-
this.host = HOSTS[env] || HOSTS.staging;
|
|
41
|
-
}
|
|
42
|
-
async makeRequest(uri, method, data, context) {
|
|
43
|
-
const headers = new Headers();
|
|
44
|
-
headers.append("Authorization", `Bearer ${context.token}`);
|
|
45
|
-
headers.append("X-Request-ID", context.requestId);
|
|
46
|
-
const config = {
|
|
47
|
-
method,
|
|
48
|
-
headers,
|
|
49
|
-
body: method === "GET" ? null : JSON.stringify(data)
|
|
50
|
-
};
|
|
51
|
-
try {
|
|
52
|
-
const endpoint = this.host + uri;
|
|
53
|
-
const response = await fetch(endpoint, config);
|
|
54
|
-
console.log("Making Request to", endpoint);
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
57
|
-
}
|
|
58
|
-
return await response.json();
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error making HTTP request:", error);
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// src/api/User.api.ts
|
|
67
|
-
var UserAPI = class {
|
|
68
|
-
constructor() {
|
|
69
|
-
this.clientHTTP = new HTTPClient();
|
|
70
|
-
}
|
|
71
|
-
async getUserInfo(context) {
|
|
72
|
-
const data = await this.clientHTTP.makeRequest(
|
|
73
|
-
UserEndpoints.GetUserInfo,
|
|
74
|
-
"GET",
|
|
75
|
-
null,
|
|
76
|
-
context
|
|
77
|
-
);
|
|
78
|
-
return data;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var User_api_default = UserAPI;
|
|
82
|
-
|
|
83
|
-
// src/model/Api.ts
|
|
84
|
-
var ShredAPI = class {
|
|
85
|
-
constructor() {
|
|
86
|
-
this.user = new User_api_default();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/index.ts
|
|
91
|
-
var src_default = ShredAPI;
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Api_1 = require("./model/Api");
|
|
4
|
+
exports.default = Api_1.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
|
+
exports.ShredAPI = void 0;
|
|
7
|
+
const User_api_1 = __importDefault(require("../api/User.api"));
|
|
8
|
+
class ShredAPI {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.user = new User_api_1.default();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ShredAPI = ShredAPI;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Context from "./Context";
|
|
2
|
+
interface UserAPISchema {
|
|
3
|
+
getUserInfo: (context: Context) => Promise<User>;
|
|
4
|
+
}
|
|
5
|
+
declare const UserEndpoints: {
|
|
6
|
+
GetUserInfo: string;
|
|
7
|
+
};
|
|
8
|
+
type Preferences = {
|
|
9
|
+
primaryColor?: string;
|
|
10
|
+
secondaryColor?: string;
|
|
11
|
+
facebookLink?: string;
|
|
12
|
+
instagramLink?: string;
|
|
13
|
+
bRoll?: boolean;
|
|
14
|
+
logo?: string;
|
|
15
|
+
};
|
|
16
|
+
type User = {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
email: string;
|
|
20
|
+
customerId: string;
|
|
21
|
+
registered: boolean;
|
|
22
|
+
profession?: string;
|
|
23
|
+
registeredAt: number;
|
|
24
|
+
fcmToken?: string;
|
|
25
|
+
photoUrl?: string;
|
|
26
|
+
preferences?: Preferences;
|
|
27
|
+
invitationCode?: string;
|
|
28
|
+
};
|
|
29
|
+
export { User, UserAPISchema, UserEndpoints };
|
|
@@ -0,0 +1,37 @@
|
|
|
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 axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const HOSTS = {
|
|
8
|
+
prod: "https://api.shredmedia.co",
|
|
9
|
+
staging: "https://api-staging.shredmedia.co",
|
|
10
|
+
};
|
|
11
|
+
class HTTPClient {
|
|
12
|
+
constructor() {
|
|
13
|
+
const env = process.env.ENV;
|
|
14
|
+
this.host = HOSTS[env] || HOSTS.staging;
|
|
15
|
+
}
|
|
16
|
+
async makeRequest(uri, method, data, context) {
|
|
17
|
+
const config = {
|
|
18
|
+
method: method,
|
|
19
|
+
url: this.host + uri,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${context.token}`,
|
|
22
|
+
"X-Request-ID": context.requestId,
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
},
|
|
25
|
+
data: method === "GET" ? null : data,
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
const response = await (0, axios_1.default)(config);
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error("Error making HTTP request:", error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.default = HTTPClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shred-api-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "API Client for Shred",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
-
"build": "
|
|
13
|
+
"build": "tsc --project tsconfig.json && tscpaths -p tsconfig.json -s . -o ./dist",
|
|
14
|
+
"build:watch": "tsc -w"
|
|
14
15
|
},
|
|
15
16
|
"author": "Marcus Cartágenes",
|
|
16
17
|
"license": "ISC",
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/node": "^20.12.7",
|
|
24
|
+
"tscpaths": "^0.0.9",
|
|
23
25
|
"tsup": "^8.0.2",
|
|
24
26
|
"typescript": "^5.4.5"
|
|
25
27
|
}
|