@saplingai/sapling-js 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saplingai/sapling-js",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "JavaScript library for using the Sapling.ai API.",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -9,12 +9,29 @@ type ConstructorOptions = {
9
9
  type EditOptions = {
10
10
  variety?: string,
11
11
  autoApply?: boolean,
12
+ lang?: string,
13
+ medical?: boolean,
14
+ }
15
+
16
+ type SpellcheckOptions = {
17
+ minLength?: number,
18
+ multipleEdits?: boolean,
19
+ lang?: string,
20
+ autoApply?: boolean,
21
+ variety?: string,
22
+ userData?: any,
12
23
  }
13
24
 
14
25
  declare class Client {
15
- constructor(apiKey: string, options?: ConstructorOptions);
26
+ constructor(apiKey: string, options?: ConstructorOptions);
27
+
28
+ edits(text: string, sessionId: string, options?: EditOptions): Promise<AxiosResponse>;
29
+ acceptEdit(editUUID: string, sessionId: string): Promise<AxiosResponse>;
30
+ rejectEdit(editUUID: string, sessionId: string): Promise<AxiosResponse>;
31
+
32
+ spellcheck(text: string, sessionId: string, options?: SpellcheckOptions): Promise<AxiosResponse>;
16
33
 
17
- edits(text: string, sessionId: string, options?: EditOptions): Promise<AxiosResponse>;
18
- accept(editUUID: string, sessionId: string): void;
19
- reject(editUUID: string, sessionId: string): void;
34
+ complete(query: string, sessionId: string): Promise<AxiosResponse>;
35
+ acceptComplete(completeUUID: string, query: string, completion: string, sessionId: string): Promise<AxiosResponse>;
36
+ tone(text: string): Promise<AxiosResponse>;
20
37
  }
package/sapling/client.js CHANGED
@@ -8,12 +8,27 @@ export class Client {
8
8
  this.hostname = options.hostname || 'https://api.sapling.ai';
9
9
  this.pathname = options.pathname || '/api/v1/';
10
10
  this.urlEndpoint = `${this.hostname}${this.pathname}`;
11
+ this.defaultSessionId = uuidv4();
11
12
  axios.defaults.timeout = this.timeout;
12
13
  }
13
14
 
14
- edits(text, sessionId, options = {}) {
15
+ axiosPromise(url, method, data) {
16
+ return new Promise((resolve) => {
17
+ axios({
18
+ url,
19
+ method,
20
+ data,
21
+ timeout: this.timeout,
22
+ })
23
+ .then(function (response) {
24
+ resolve(response);
25
+ });
26
+ });
27
+ }
28
+
29
+ edits(text, sessionId, options = {}) {
15
30
  const url = `${this.urlEndpoint}edits`;
16
- sessionId = sessionId || uuidv4();
31
+ sessionId = sessionId || this.defaultSessionId;
17
32
 
18
33
  let data = {
19
34
  text,
@@ -22,54 +37,119 @@ export class Client {
22
37
  }
23
38
 
24
39
  if (options.variety != null) {
25
- data.variety = variety;
40
+ data.variety = options.variety;
26
41
  }
27
42
 
28
43
  if (options.autoApply != null) {
29
- data.auto_apply = autoApply;
44
+ data.auto_apply = options.autoApply;
30
45
  }
31
46
 
32
- return new Promise((resolve) => {
33
- axios({
34
- url,
35
- data,
36
- method: 'post',
37
- timeout: this.timeout,
38
- })
39
- .then(function (response) {
40
- resolve(response);
41
- });
42
- });
47
+ if (options.lang != null) {
48
+ data.lang = options.lang;
49
+ }
50
+
51
+ if (options.medical != null) {
52
+ data.medical = options.medical;
53
+ }
54
+
55
+ return this.axiosPromise(url, 'post', data);
43
56
  }
44
57
 
45
- accept(editUUID, sessionId) {
58
+ acceptEdit(editUUID, sessionId) {
46
59
  const url = `${this.urlEndpoint}edits/${editUUID}/accept`;
47
- sessionId = sessionId || uuidv4();
60
+ sessionId = sessionId || this.defaultSessionId;
48
61
  let data = {
49
62
  key: this.apiKey,
50
63
  session_id: sessionId,
51
64
  }
52
- axios({
53
- url,
54
- data,
55
- method: 'post',
56
- timeout: this.timeout,
57
- })
65
+
66
+ return this.axiosPromise(url, 'post', data);
58
67
  }
59
68
 
60
- reject(editUUID, sessionId) {
69
+ rejectEdit(editUUID, sessionId) {
61
70
  const url = `${this.urlEndpoint}edits/${editUUID}/reject`;
62
- sessionId = sessionId || uuidv4();
71
+ sessionId = sessionId || this.defaultSessionId;
63
72
  let data = {
64
73
  key: this.apiKey,
65
74
  session_id: sessionId,
66
75
  }
67
- axios({
68
- url,
69
- data,
70
- method: 'post',
71
- timeout: this.timeout,
72
- })
76
+
77
+ return this.axiosPromise(url, 'post', data);
78
+ }
79
+
80
+ spellcheck(text, sessionId, options = {}) {
81
+ const url = `${this.urlEndpoint}spellcheck`;
82
+ sessionId = sessionId || this.defaultSessionId;
83
+
84
+ let data = {
85
+ key: this.apiKey,
86
+ session_id: sessionId,
87
+ text,
88
+ }
89
+
90
+ if (options.minLength != null) {
91
+ data.min_length = minLength;
92
+ }
93
+
94
+ if (options.multipleEdits != null) {
95
+ data.multiple_edits = multipleEdits;
96
+ }
97
+
98
+ if (options.lang != null) {
99
+ data.lang = lang;
100
+ }
101
+
102
+ if (options.autoApply != null) {
103
+ data.auto_apply = autoApply;
104
+ }
105
+
106
+ if (options.variety != null) {
107
+ data.variety = variety;
108
+ }
109
+
110
+ if (options.userData != null) {
111
+ data.user_data = userData;
112
+ }
113
+
114
+ return this.axiosPromise(url, 'post', data);
115
+ }
116
+
117
+
118
+ complete(query, sessionId) {
119
+ const url = `${this.urlEndpoint}complete`;
120
+ sessionId = sessionId || this.defaultSessionId;
121
+ let data = {
122
+ key: this.apiKey,
123
+ session_id: sessionId,
124
+ query,
125
+ }
126
+ return this.axiosPromise(url, 'post', data);
127
+ }
128
+
129
+
130
+ acceptComplete(completeUUID, query, completion, sessionId) {
131
+ const url = `${this.urlEndpoint}complete/${completeUUID}/accept`;
132
+ sessionId = sessionId || this.defaultSessionId;
133
+ let data = {
134
+ key: this.apiKey,
135
+ session_id: sessionId,
136
+ context: {
137
+ query,
138
+ completion,
139
+ }
140
+ }
141
+
142
+ return this.axiosPromise(url, 'post', data);
143
+ }
144
+
145
+ tone(text) {
146
+ const url = `${this.urlEndpoint}tone`;
147
+
148
+ let data = {
149
+ key: this.apiKey,
150
+ text,
151
+ }
152
+ return this.axiosPromise(url, 'post', data);
73
153
  }
74
154
 
75
155
  }
@@ -1,3 +1,3 @@
1
- import { SaplingModule } from './sapling-sdk-v1.0.4.min.js';
1
+ import { SaplingModule } from './sapling-sdk-v1.0.5.min.js';
2
2
 
3
3
  export const Sapling = SaplingModule.SaplingModule;