@verdocs/js-sdk 1.0.0

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/dist/Api/Auth.d.ts +71 -0
  4. package/dist/Api/Auth.js +24 -0
  5. package/dist/Api/Documents.d.ts +124 -0
  6. package/dist/Api/Documents.js +47 -0
  7. package/dist/Api/Endpoint.d.ts +2 -0
  8. package/dist/Api/Endpoint.js +9 -0
  9. package/dist/Api/Notifications.d.ts +1 -0
  10. package/dist/Api/Notifications.js +40 -0
  11. package/dist/Api/Templates.d.ts +33 -0
  12. package/dist/Api/Templates.js +55 -0
  13. package/dist/Api/Types.d.ts +182 -0
  14. package/dist/Api/Types.js +1 -0
  15. package/dist/Api/index.d.ts +2 -0
  16. package/dist/Api/index.js +2 -0
  17. package/dist/AuthManager.d.ts +14 -0
  18. package/dist/AuthManager.js +53 -0
  19. package/dist/Documents/Documents.d.ts +129 -0
  20. package/dist/Documents/Documents.js +52 -0
  21. package/dist/Documents/Stars.d.ts +2 -0
  22. package/dist/Documents/Stars.js +40 -0
  23. package/dist/Documents/Templates.d.ts +4 -0
  24. package/dist/Documents/Templates.js +46 -0
  25. package/dist/Documents/Types.d.ts +23 -0
  26. package/dist/Documents/Types.js +1 -0
  27. package/dist/Documents/index.d.ts +4 -0
  28. package/dist/Documents/index.js +4 -0
  29. package/dist/HTTP/Endpoint.d.ts +4 -0
  30. package/dist/HTTP/Endpoint.js +12 -0
  31. package/dist/HTTP/Transport.d.ts +3 -0
  32. package/dist/HTTP/Transport.js +12 -0
  33. package/dist/HTTP/Types.d.ts +1 -0
  34. package/dist/HTTP/Types.js +1 -0
  35. package/dist/HTTP/index.d.ts +2 -0
  36. package/dist/HTTP/index.js +2 -0
  37. package/dist/Organizations/ApiKeys.d.ts +5 -0
  38. package/dist/Organizations/ApiKeys.js +16 -0
  39. package/dist/Organizations/Groups.d.ts +7 -0
  40. package/dist/Organizations/Groups.js +22 -0
  41. package/dist/Organizations/Invitations.d.ts +7 -0
  42. package/dist/Organizations/Invitations.js +22 -0
  43. package/dist/Organizations/Members.d.ts +5 -0
  44. package/dist/Organizations/Members.js +16 -0
  45. package/dist/Organizations/Organizations.d.ts +7 -0
  46. package/dist/Organizations/Organizations.js +13 -0
  47. package/dist/Organizations/Types.d.ts +16 -0
  48. package/dist/Organizations/Types.js +1 -0
  49. package/dist/Organizations/Webhooks.d.ts +2 -0
  50. package/dist/Organizations/Webhooks.js +7 -0
  51. package/dist/Organizations/index.d.ts +7 -0
  52. package/dist/Organizations/index.js +7 -0
  53. package/dist/Users/Auth.d.ts +79 -0
  54. package/dist/Users/Auth.js +89 -0
  55. package/dist/Users/Billing.d.ts +1 -0
  56. package/dist/Users/Billing.js +2 -0
  57. package/dist/Users/Notifications.d.ts +1 -0
  58. package/dist/Users/Notifications.js +40 -0
  59. package/dist/Users/Profiles.d.ts +104 -0
  60. package/dist/Users/Profiles.js +114 -0
  61. package/dist/Users/Types.d.ts +106 -0
  62. package/dist/Users/Types.js +1 -0
  63. package/dist/Users/index.d.ts +5 -0
  64. package/dist/Users/index.js +5 -0
  65. package/dist/Utils/DateTime.d.ts +1 -0
  66. package/dist/Utils/DateTime.js +41 -0
  67. package/dist/Utils/index.d.ts +1 -0
  68. package/dist/Utils/index.js +1 -0
  69. package/dist/index.d.ts +5 -0
  70. package/dist/index.js +5 -0
  71. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Verdocs, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Verdocs JS SDK
2
+
3
+ > Verdocs SDK for Javascript / Typescript
4
+
5
+ This SDK provides convenience wrappers for both Browser-based and NodeJS applications with strong typing and documentation to help
6
+ you get started quickly developing for the Verdocs platform.
7
+
8
+ ## Usage
9
+
10
+ We will shortly be adding code samples, tutorials, and guides. Until then, please refer to the
11
+ [API Documentation](https://github.com/Verdocs/js-sdk/tree/main/doc-md). Note that this package is namespaced into packages that organize
12
+ API calls into functional groups. A top-level `export *` is provided for simplicity, but to enable Tree Shaking to do its job, it is
13
+ recommended that you only import the package required for a given task, e.g.:
14
+
15
+ ```typescript
16
+ import {Auth} from '@verdocs/js-sdk/Auth';
17
+ import {Endpoint} from '@verdocs/js-sdk/HTTP';
18
+
19
+ const {accessToken} = await Auth.authenticateUser({username: 'MY_USERNAME', password: 'MY_PASSWORD'});
20
+ Endpoint.setAuthToken(accessToken);
21
+ ```
22
+
23
+ ## HTTP Transport
24
+
25
+ The underlying transport uses `axios`, a cross-environment (NodeJS vs. Browser) HTTP transport layer. When this SDK is included in a
26
+ project, an `Endpoint` singleton Axios Instance will be created to support the API calls to Verdocs servers. This endpoint's operation
27
+ may be configured by importing it. Please see the [Axios Documentation](https://github.com/axios/axios) for more information on the
28
+ options available. For example, to override the default API call timeout of 3s:
29
+
30
+ ```typescript
31
+ import {Endpoint} from '@verdocs/js-sdk/Auth/HTTP/Transport';
32
+
33
+ Endpoint.defaults.timeout = 5000;
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ Although we at Verdocs actively maintain this SDK, we welcome community contributions and suggestions! Please file a pull request
39
+ with any change requests and we will review them as soon as possible.
@@ -0,0 +1,71 @@
1
+ export declare type IPermission = 'org:view' | 'member:view' | 'org:update' | 'member:add' | 'member:remove' | 'admin:add' | 'admin:remove' | 'org:delete' | 'org:transfer' | 'owner:add' | 'owner:remove' | 'template:creator:create:personal' | 'template:creator:visibility' | 'template:creator:create:org' | 'template:member:read' | 'template:member:write' | 'template:member:visibility' | 'template:creator:delete' | 'template:member:delete' | 'template:creator:create:public' | 'rform:access' | 'rcommon:access' | 'org:list' | 'org:create';
2
+ export declare type IRole = 'owner' | 'basic_user' | 'member';
3
+ export declare type IPlan = 'env:essential' | 'org:standard';
4
+ export interface IProfile {
5
+ id: string;
6
+ user_id: string;
7
+ organization_id: string;
8
+ first_name: string;
9
+ last_name: string;
10
+ email: string;
11
+ phone: string | null;
12
+ current: boolean;
13
+ organization: {
14
+ id: string;
15
+ name: string;
16
+ address: string | null;
17
+ phone: string | null;
18
+ business_name: string | null;
19
+ is_business: boolean;
20
+ address2: string | null;
21
+ contact_email: string | null;
22
+ timezone: string | null;
23
+ envelope_responsible: boolean;
24
+ };
25
+ permissions?: IPermission[];
26
+ roles?: IRole[];
27
+ plans?: IPlan[];
28
+ }
29
+ export interface IActiveSession {
30
+ sub: string;
31
+ email: string;
32
+ email_verified: boolean;
33
+ iat: number;
34
+ exp: number;
35
+ permissions: IPermission[];
36
+ roles: IRole[];
37
+ plans: IPlan[];
38
+ profile: IProfile;
39
+ profile_id: string;
40
+ organization_id: string;
41
+ }
42
+ export interface AuthenticateRequest {
43
+ username: string;
44
+ password: string;
45
+ }
46
+ export interface AuthenticateResponse {
47
+ idToken: string;
48
+ accessToken: string;
49
+ refreshToken: string;
50
+ }
51
+ /**
52
+ * Authenticate to Verdocs via user/password authentication
53
+ *
54
+ * ```typescript
55
+ * import {Auth, Endpoint} from '@verdocs/js-sdk';
56
+ *
57
+ * const {accessToken} = await Auth.authenticate({ username: 'test@test.com', password: 'PASSWORD' });
58
+ * Endpoint.setAuthToken(accessToken);
59
+ * ```
60
+ */
61
+ export declare const authenticate: (request: AuthenticateRequest) => Promise<AuthenticateResponse>;
62
+ /**
63
+ * Get the user's available profiles. The current profile will be marked with `current: true`.
64
+ *
65
+ * ```typescript
66
+ * import {Auth} from '@verdocs/js-sdk';
67
+ *
68
+ * const profiles = await Auth.getProfiles()
69
+ * ```
70
+ */
71
+ export declare const getProfiles: () => Promise<IProfile[]>;
@@ -0,0 +1,24 @@
1
+ import { Endpoint } from './Endpoint';
2
+ /**
3
+ * Authenticate to Verdocs via user/password authentication
4
+ *
5
+ * ```typescript
6
+ * import {Auth, Endpoint} from '@verdocs/js-sdk';
7
+ *
8
+ * const {accessToken} = await Auth.authenticate({ username: 'test@test.com', password: 'PASSWORD' });
9
+ * Endpoint.setAuthToken(accessToken);
10
+ * ```
11
+ */
12
+ export var authenticate = function (request) {
13
+ return Endpoint.post('/authentication/login', request).then(function (r) { return r.data; });
14
+ };
15
+ /**
16
+ * Get the user's available profiles. The current profile will be marked with `current: true`.
17
+ *
18
+ * ```typescript
19
+ * import {Auth} from '@verdocs/js-sdk';
20
+ *
21
+ * const profiles = await Auth.getProfiles()
22
+ * ```
23
+ */
24
+ export var getProfiles = function () { return Endpoint.post('/profiles').then(function (r) { return r.data; }); };
@@ -0,0 +1,124 @@
1
+ export declare type IDocumentStatus = 'complete' | 'pending' | 'progress';
2
+ export declare type IRecipientStatus = 'invited' | 'opened' | 'signed' | 'submitted';
3
+ export declare type IRecipientType = 'signer' | 'cc';
4
+ export interface IDocumentsSearchResultEntry {
5
+ id: string;
6
+ canceled_at: string;
7
+ created_at: string;
8
+ name: string;
9
+ profile_id: string;
10
+ status: IDocumentStatus;
11
+ next_recipient: {
12
+ claimed: boolean;
13
+ email: string;
14
+ name: string;
15
+ profile_id: string;
16
+ status: IRecipientStatus;
17
+ type: IRecipientType;
18
+ };
19
+ template_id: string;
20
+ total_count: number;
21
+ updated_at: string;
22
+ }
23
+ export interface IDocumentsSearchResult {
24
+ page: number;
25
+ total: number;
26
+ result: IDocumentsSearchResultEntry[];
27
+ }
28
+ export interface IDocumentsSummary {
29
+ action_required: {
30
+ page: number;
31
+ total: number;
32
+ result: IActivityEntry[];
33
+ };
34
+ completed: {
35
+ page: number;
36
+ total: number;
37
+ result: IActivityEntry[];
38
+ };
39
+ waiting_others: {
40
+ page: number;
41
+ total: number;
42
+ result: IActivityEntry[];
43
+ };
44
+ }
45
+ export interface IRecipient {
46
+ agreed: boolean;
47
+ claimed: boolean;
48
+ created_at: string;
49
+ delegated_to: string | null;
50
+ delegator: boolean;
51
+ email: string;
52
+ envelope_id: string;
53
+ full_name: string;
54
+ in_app_access_key: string;
55
+ key_used_to_conclude: string;
56
+ message: string | null;
57
+ phone: string;
58
+ profile_id: string;
59
+ role_name: string;
60
+ sequence: number;
61
+ status: IRecipientStatus;
62
+ type: IRecipientType;
63
+ updated_at: string;
64
+ }
65
+ export interface IDocument {
66
+ id: string;
67
+ created_at: string;
68
+ canceled_at: string;
69
+ envelope_document_id: string;
70
+ certificate_document_id: string | null;
71
+ histories: IHistory[];
72
+ recipients: IRecipient[];
73
+ name: string;
74
+ no_contact: boolean;
75
+ profile_id: string;
76
+ reminder_id: string | null;
77
+ status: IDocumentStatus;
78
+ template_id: string;
79
+ updated_at: string;
80
+ }
81
+ export interface IActivityEntry {
82
+ id: string;
83
+ name: string;
84
+ canceled_at: string;
85
+ created_at: string;
86
+ updated_at: string;
87
+ profile_id: string;
88
+ status: IDocumentStatus;
89
+ template_id: string;
90
+ recipient: {
91
+ claimed: boolean;
92
+ email: string;
93
+ name: string;
94
+ profile_id: string;
95
+ status: IRecipientStatus;
96
+ type: IRecipientType;
97
+ };
98
+ }
99
+ export interface IHistory {
100
+ created_at: string;
101
+ envelope_id: string;
102
+ event: IHistoryEvent;
103
+ event_detail: IEventDetail;
104
+ id: string;
105
+ role_name: string;
106
+ }
107
+ export interface IDocumentSearchOptions {
108
+ rows?: number;
109
+ page?: number;
110
+ sort_by?: 'updated_at' | 'created_at';
111
+ ascending?: boolean;
112
+ is_owner?: boolean;
113
+ is_recipient?: boolean;
114
+ envelope_status: IDocumentStatus[];
115
+ recipient_status: IDocumentStatus[];
116
+ }
117
+ export declare type IHistoryEvent = 'recipient:invited' | 'recipient:opened' | 'recipient:agreed' | 'recipient:signed' | 'recipient:submitted';
118
+ export declare type IEventDetail = 'in_app' | 'mail' | 'signer' | '';
119
+ export declare const getSummary: (page: number) => Promise<IDocumentsSummary>;
120
+ export declare const search: (params: any) => Promise<IDocumentsSearchResult>;
121
+ export declare const Documents: {
122
+ getSummary: (page: number) => Promise<IDocumentsSummary>;
123
+ search: (params: any) => Promise<IDocumentsSearchResult>;
124
+ };
@@ -0,0 +1,47 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { Endpoint } from './Endpoint';
38
+ export var getSummary = function (page) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
39
+ return [2 /*return*/, Endpoint.post('/documents/summary', { page: page }).then(function (r) { return r.data; })];
40
+ }); }); };
41
+ export var search = function (params) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
42
+ return [2 /*return*/, Endpoint.post('/documents/search', params).then(function (r) { return r.data; })];
43
+ }); }); };
44
+ export var Documents = {
45
+ getSummary: getSummary,
46
+ search: search,
47
+ };
@@ -0,0 +1,2 @@
1
+ export declare const Endpoint: import("axios").AxiosInstance;
2
+ export declare const setAuthToken: (accessToken: string | null) => void;
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+ export var Endpoint = axios.create({
3
+ baseURL: 'https://stage-api.verdocs.com/',
4
+ timeout: 3000,
5
+ headers: { 'X-Client-ID': '1234' },
6
+ });
7
+ export var setAuthToken = function (accessToken) {
8
+ Endpoint.defaults.headers.Authorization = "Bearer " + accessToken;
9
+ };
@@ -0,0 +1 @@
1
+ export declare const getNotifications: () => Promise<any>;
@@ -0,0 +1,40 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { Endpoint } from './Endpoint';
38
+ export var getNotifications = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
39
+ return [2 /*return*/, Endpoint.get('/notifications').then(function (r) { return r.data; })];
40
+ }); }); };
@@ -0,0 +1,33 @@
1
+ export interface ITemplateSummaryEntry {
2
+ id: string;
3
+ name: string;
4
+ sender: string;
5
+ counter: number;
6
+ description: string | null;
7
+ created_at: string;
8
+ updated_at: string;
9
+ is_personal: boolean;
10
+ is_public: boolean;
11
+ profile_id: string;
12
+ organization_id: string;
13
+ last_used_at: string | null;
14
+ document_name: string | null;
15
+ star_counter: number;
16
+ tag_name: string | null;
17
+ is_starred: boolean;
18
+ }
19
+ export interface ITemplatesSummary {
20
+ page: number;
21
+ total: number;
22
+ result: ITemplateSummaryEntry[];
23
+ }
24
+ export declare const getTemplates: () => Promise<any>;
25
+ export declare const searchTemplates: () => Promise<any>;
26
+ export declare const getSummary: (page: number) => Promise<ITemplatesSummary>;
27
+ export declare const toggleStar: (templateId: string) => Promise<ITemplateSummaryEntry>;
28
+ export declare const Templates: {
29
+ getSummary: (page: number) => Promise<ITemplatesSummary>;
30
+ getTemplates: () => Promise<any>;
31
+ searchTemplates: () => Promise<any>;
32
+ toggleStar: (templateId: string) => Promise<ITemplateSummaryEntry>;
33
+ };
@@ -0,0 +1,55 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { Endpoint } from './Endpoint';
38
+ export var getTemplates = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
39
+ return [2 /*return*/, Endpoint.get('/templates').then(function (r) { return r.data; })];
40
+ }); }); };
41
+ export var searchTemplates = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
42
+ return [2 /*return*/, Endpoint.post('/templates/search').then(function (r) { return r.data; })];
43
+ }); }); };
44
+ export var getSummary = function (page) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
45
+ return [2 /*return*/, Endpoint.post('/templates/summary', { page: page }).then(function (r) { return r.data; })];
46
+ }); }); };
47
+ export var toggleStar = function (templateId) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
48
+ return [2 /*return*/, Endpoint.post("/templates/" + templateId + "/stars/toggle").then(function (r) { return r.data; })];
49
+ }); }); };
50
+ export var Templates = {
51
+ getSummary: getSummary,
52
+ getTemplates: getTemplates,
53
+ searchTemplates: searchTemplates,
54
+ toggleStar: toggleStar,
55
+ };