@unboundcx/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.
@@ -0,0 +1,173 @@
1
+ export class RecordTypesService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ this.user = new UserRecordTypeDefaultsService(sdk);
5
+ }
6
+
7
+ async create({ name, description, create, update, read, delete: deleteUsers }) {
8
+ this.sdk.validateParams(
9
+ { name, description },
10
+ {
11
+ name: { type: 'string', required: true },
12
+ description: { type: 'string', required: true },
13
+ create: { type: 'array', required: false },
14
+ update: { type: 'array', required: false },
15
+ read: { type: 'array', required: false },
16
+ delete: { type: 'array', required: false },
17
+ },
18
+ );
19
+
20
+ const recordTypeData = { name, description };
21
+ if (create) recordTypeData.create = create;
22
+ if (update) recordTypeData.update = update;
23
+ if (read) recordTypeData.read = read;
24
+ if (deleteUsers) recordTypeData.delete = deleteUsers;
25
+
26
+ const params = {
27
+ body: recordTypeData,
28
+ };
29
+
30
+ const result = await this.sdk._fetch('/recordTypes/', 'POST', params);
31
+ return result;
32
+ }
33
+
34
+ async update(id, { name, description, remove, add }) {
35
+ this.sdk.validateParams(
36
+ { id },
37
+ {
38
+ id: { type: 'string', required: true },
39
+ name: { type: 'string', required: false },
40
+ description: { type: 'string', required: false },
41
+ remove: { type: 'object', required: false },
42
+ add: { type: 'object', required: false },
43
+ },
44
+ );
45
+
46
+ const updateData = {};
47
+ if (name) updateData.name = name;
48
+ if (description) updateData.description = description;
49
+ if (remove) updateData.remove = remove;
50
+ if (add) updateData.add = add;
51
+
52
+ const params = {
53
+ body: updateData,
54
+ };
55
+
56
+ const result = await this.sdk._fetch(`/recordTypes/${id}`, 'PUT', params);
57
+ return result;
58
+ }
59
+
60
+ async delete(id) {
61
+ this.sdk.validateParams(
62
+ { id },
63
+ {
64
+ id: { type: 'string', required: true },
65
+ },
66
+ );
67
+
68
+ const result = await this.sdk._fetch(`/recordTypes/${id}`, 'DELETE');
69
+ return result;
70
+ }
71
+
72
+ async get(id) {
73
+ this.sdk.validateParams(
74
+ { id },
75
+ {
76
+ id: { type: 'string', required: true },
77
+ },
78
+ );
79
+
80
+ const result = await this.sdk._fetch(`/recordTypes/${id}`, 'GET');
81
+ return result;
82
+ }
83
+
84
+ async list() {
85
+ const result = await this.sdk._fetch('/recordTypes/', 'GET');
86
+ return result;
87
+ }
88
+ }
89
+
90
+ export class UserRecordTypeDefaultsService {
91
+ constructor(sdk) {
92
+ this.sdk = sdk;
93
+ }
94
+
95
+ async create({ recordTypeId, object, userId }) {
96
+ this.sdk.validateParams(
97
+ { recordTypeId, object },
98
+ {
99
+ recordTypeId: { type: 'string', required: true },
100
+ object: { type: 'string', required: true },
101
+ userId: { type: 'string', required: false },
102
+ },
103
+ );
104
+
105
+ const defaultData = { recordTypeId, object };
106
+ if (userId) defaultData.userId = userId;
107
+
108
+ const params = {
109
+ body: defaultData,
110
+ };
111
+
112
+ const result = await this.sdk._fetch('/recordTypes/user/', 'POST', params);
113
+ return result;
114
+ }
115
+
116
+ async update({ recordTypeId, object, userId }) {
117
+ this.sdk.validateParams(
118
+ { recordTypeId, object },
119
+ {
120
+ recordTypeId: { type: 'string', required: true },
121
+ object: { type: 'string', required: true },
122
+ userId: { type: 'string', required: false },
123
+ },
124
+ );
125
+
126
+ const updateData = { recordTypeId, object };
127
+ if (userId) updateData.userId = userId;
128
+
129
+ const params = {
130
+ body: updateData,
131
+ };
132
+
133
+ const result = await this.sdk._fetch('/recordTypes/user/', 'PUT', params);
134
+ return result;
135
+ }
136
+
137
+ async delete({ object, userId }) {
138
+ this.sdk.validateParams(
139
+ { object },
140
+ {
141
+ object: { type: 'string', required: true },
142
+ userId: { type: 'string', required: false },
143
+ },
144
+ );
145
+
146
+ const deleteData = { object };
147
+ if (userId) deleteData.userId = userId;
148
+
149
+ const params = {
150
+ body: deleteData,
151
+ };
152
+
153
+ const result = await this.sdk._fetch('/recordTypes/user/', 'DELETE', params);
154
+ return result;
155
+ }
156
+
157
+ async get({ object, userId }) {
158
+ this.sdk.validateParams(
159
+ { object },
160
+ {
161
+ object: { type: 'string', required: true },
162
+ userId: { type: 'string', required: false },
163
+ },
164
+ );
165
+
166
+ const params = {
167
+ query: { object, userId },
168
+ };
169
+
170
+ const result = await this.sdk._fetch('/recordTypes/user/', 'GET', params);
171
+ return result;
172
+ }
173
+ }
@@ -0,0 +1,93 @@
1
+ export class SipEndpointsService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ async create({ username, password, domain, displayName, description }) {
7
+ this.sdk.validateParams(
8
+ { username, password, domain },
9
+ {
10
+ username: { type: 'string', required: true },
11
+ password: { type: 'string', required: true },
12
+ domain: { type: 'string', required: true },
13
+ displayName: { type: 'string', required: false },
14
+ description: { type: 'string', required: false },
15
+ },
16
+ );
17
+
18
+ const endpointData = { username, password, domain };
19
+ if (displayName) endpointData.displayName = displayName;
20
+ if (description) endpointData.description = description;
21
+
22
+ const params = {
23
+ body: endpointData,
24
+ };
25
+
26
+ const result = await this.sdk._fetch('/sipEndpoints', 'POST', params);
27
+ return result;
28
+ }
29
+
30
+ async getWebRtcDetails() {
31
+ const params = {};
32
+ const result = await this.sdk._fetch('/sipEndpoints', 'GET', params, true);
33
+ return result;
34
+ }
35
+
36
+ async getUsersWebRtc() {
37
+ const result = await this.sdk._fetch('/sipEndpoints/users/webrtc', 'GET');
38
+ return result;
39
+ }
40
+
41
+ async list() {
42
+ const result = await this.sdk._fetch('/sipEndpoints/list', 'GET');
43
+ return result;
44
+ }
45
+
46
+ async get(endpointId) {
47
+ this.sdk.validateParams(
48
+ { endpointId },
49
+ {
50
+ endpointId: { type: 'string', required: true },
51
+ },
52
+ );
53
+
54
+ const result = await this.sdk._fetch(`/sipEndpoints/${endpointId}`, 'GET');
55
+ return result;
56
+ }
57
+
58
+ async update(endpointId, { displayName, description, enabled }) {
59
+ this.sdk.validateParams(
60
+ { endpointId },
61
+ {
62
+ endpointId: { type: 'string', required: true },
63
+ displayName: { type: 'string', required: false },
64
+ description: { type: 'string', required: false },
65
+ enabled: { type: 'boolean', required: false },
66
+ },
67
+ );
68
+
69
+ const updateData = {};
70
+ if (displayName) updateData.displayName = displayName;
71
+ if (description) updateData.description = description;
72
+ if (enabled !== undefined) updateData.enabled = enabled;
73
+
74
+ const params = {
75
+ body: updateData,
76
+ };
77
+
78
+ const result = await this.sdk._fetch(`/sipEndpoints/${endpointId}`, 'PUT', params);
79
+ return result;
80
+ }
81
+
82
+ async delete(endpointId) {
83
+ this.sdk.validateParams(
84
+ { endpointId },
85
+ {
86
+ endpointId: { type: 'string', required: true },
87
+ },
88
+ );
89
+
90
+ const result = await this.sdk._fetch(`/sipEndpoints/${endpointId}`, 'DELETE');
91
+ return result;
92
+ }
93
+ }
@@ -0,0 +1,168 @@
1
+ export class StorageService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ async uploadFiles(files, options = {}) {
7
+ const { classification, expireAfter, isPublic, metadata } = options;
8
+
9
+ // Validate files parameter
10
+ if (!files) {
11
+ throw new Error('Files parameter is required');
12
+ }
13
+
14
+ // Handle different file input formats
15
+ let formData;
16
+ if (typeof window !== 'undefined' && files instanceof FormData) {
17
+ // Browser FormData
18
+ formData = files;
19
+ } else if (typeof window !== 'undefined' && files instanceof FileList) {
20
+ // Browser FileList
21
+ formData = new FormData();
22
+ for (let i = 0; i < files.length; i++) {
23
+ formData.append('files', files[i]);
24
+ }
25
+ } else if (Array.isArray(files)) {
26
+ // File array (Node.js or Browser)
27
+ formData = new FormData();
28
+ files.forEach((file, index) => {
29
+ formData.append('files', file);
30
+ });
31
+ } else if (typeof files === 'object' && files.path) {
32
+ // Single file object (Node.js)
33
+ formData = new FormData();
34
+ formData.append('files', files);
35
+ } else {
36
+ throw new Error('Invalid files format. Expected FormData, FileList, File array, or File object');
37
+ }
38
+
39
+ // Add optional parameters to FormData
40
+ if (classification) formData.append('classification', classification);
41
+ if (expireAfter) formData.append('expireAfter', expireAfter);
42
+ if (isPublic !== undefined) formData.append('isPublic', isPublic.toString());
43
+ if (metadata) formData.append('metadata', JSON.stringify(metadata));
44
+
45
+ const params = {
46
+ body: formData,
47
+ headers: {
48
+ // Let browser/Node.js set Content-Type with boundary for multipart/form-data
49
+ }
50
+ };
51
+
52
+ // Remove Content-Type to let FormData set it properly
53
+ delete params.headers['Content-Type'];
54
+
55
+ const result = await this.sdk._fetch('/storage/upload', 'POST', params);
56
+ return result;
57
+ }
58
+
59
+ async getFile(storageId, download = false) {
60
+ this.sdk.validateParams(
61
+ { storageId },
62
+ {
63
+ storageId: { type: 'string', required: true },
64
+ download: { type: 'boolean', required: false },
65
+ },
66
+ );
67
+
68
+ const params = {};
69
+ if (download) {
70
+ params.query = { download: 'true' };
71
+ }
72
+
73
+ const result = await this.sdk._fetch(`/storage/file/${storageId}`, 'GET', params);
74
+ return result;
75
+ }
76
+
77
+ async getFileUrl(storageId, download = false) {
78
+ this.sdk.validateParams(
79
+ { storageId },
80
+ {
81
+ storageId: { type: 'string', required: true },
82
+ download: { type: 'boolean', required: false },
83
+ },
84
+ );
85
+
86
+ let url;
87
+ if (this.sdk.environment === 'node') {
88
+ url = `${this.sdk.baseURL}/storage/file/${storageId}`;
89
+ } else {
90
+ url = `${this.sdk.fullUrl}/storage/file/${storageId}`;
91
+ }
92
+
93
+ if (download) {
94
+ url += '?download=true';
95
+ }
96
+
97
+ return url;
98
+ }
99
+
100
+ async deleteFile(storageId) {
101
+ this.sdk.validateParams(
102
+ { storageId },
103
+ {
104
+ storageId: { type: 'string', required: true },
105
+ },
106
+ );
107
+
108
+ const result = await this.sdk._fetch(`/storage/file/${storageId}`, 'DELETE');
109
+ return result;
110
+ }
111
+
112
+ async getStorageClassifications() {
113
+ const result = await this.sdk._fetch('/storage/classifications', 'GET');
114
+ return result;
115
+ }
116
+
117
+ async getFileInfo(storageId) {
118
+ this.sdk.validateParams(
119
+ { storageId },
120
+ {
121
+ storageId: { type: 'string', required: true },
122
+ },
123
+ );
124
+
125
+ const result = await this.sdk._fetch(`/storage/file/${storageId}/info`, 'GET');
126
+ return result;
127
+ }
128
+
129
+ async updateFileMetadata(storageId, metadata) {
130
+ this.sdk.validateParams(
131
+ { storageId, metadata },
132
+ {
133
+ storageId: { type: 'string', required: true },
134
+ metadata: { type: 'object', required: true },
135
+ },
136
+ );
137
+
138
+ const params = {
139
+ body: { metadata },
140
+ };
141
+
142
+ const result = await this.sdk._fetch(`/storage/file/${storageId}/metadata`, 'PUT', params);
143
+ return result;
144
+ }
145
+
146
+ async listFiles(options = {}) {
147
+ const { classification, limit, offset, orderBy, orderDirection } = options;
148
+
149
+ // Validate optional parameters
150
+ const validationSchema = {};
151
+ if ('classification' in options) validationSchema.classification = { type: 'string' };
152
+ if ('limit' in options) validationSchema.limit = { type: 'number' };
153
+ if ('offset' in options) validationSchema.offset = { type: 'number' };
154
+ if ('orderBy' in options) validationSchema.orderBy = { type: 'string' };
155
+ if ('orderDirection' in options) validationSchema.orderDirection = { type: 'string' };
156
+
157
+ if (Object.keys(validationSchema).length > 0) {
158
+ this.sdk.validateParams(options, validationSchema);
159
+ }
160
+
161
+ const params = {
162
+ query: options,
163
+ };
164
+
165
+ const result = await this.sdk._fetch('/storage/files', 'GET', params);
166
+ return result;
167
+ }
168
+ }
@@ -0,0 +1,73 @@
1
+ export class SubscriptionsService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ this.socket = new SocketSubscriptionsService(sdk);
5
+ }
6
+ }
7
+
8
+ export class SocketSubscriptionsService {
9
+ constructor(sdk) {
10
+ this.sdk = sdk;
11
+ }
12
+
13
+ async getConnection(sessionId) {
14
+ this.sdk.validateParams(
15
+ { sessionId },
16
+ {
17
+ sessionId: { type: 'string', required: false },
18
+ },
19
+ );
20
+
21
+ const params = {
22
+ query: {
23
+ sessionId
24
+ }
25
+ }
26
+
27
+ const result = await this.sdk._fetch('/subscriptions/socket/connection', 'GET', params);
28
+ return result;
29
+ }
30
+
31
+ async create(sessionId, subscriptionParams) {
32
+ this.sdk.validateParams(
33
+ { sessionId, subscriptionParams },
34
+ {
35
+ sessionId: { type: 'string', required: true },
36
+ subscriptionParams: { type: 'object', required: true },
37
+ },
38
+ );
39
+
40
+ const params = {
41
+ body: {
42
+ sessionId,
43
+ ...subscriptionParams,
44
+ }
45
+ }
46
+
47
+ let uri = `/subscriptions/socket/`;
48
+ if (subscriptionParams?.id) {
49
+ uri = `/subscriptions/socket/${subscriptionParams.id}`;
50
+ }
51
+ const result = await this.sdk._fetch(uri, 'POST', params);
52
+ return result;
53
+ }
54
+
55
+ async delete(id, sessionId) {
56
+ this.sdk.validateParams(
57
+ { id, sessionId },
58
+ {
59
+ id: { type: 'string', required: false },
60
+ sessionId: { type: 'string', required: true },
61
+ },
62
+ );
63
+
64
+ const params = {
65
+ body: {
66
+ sessionId
67
+ }
68
+ }
69
+
70
+ const result = await this.sdk._fetch(`/subscriptions/socket/${id}`, 'DELETE', params);
71
+ return result;
72
+ }
73
+ }
@@ -0,0 +1,87 @@
1
+ export class VerificationService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ async createSmsVerification({ phoneNumber, code, expiresIn, metadata }) {
7
+ this.sdk.validateParams(
8
+ { phoneNumber },
9
+ {
10
+ phoneNumber: { type: 'string', required: true },
11
+ code: { type: 'string', required: false },
12
+ expiresIn: { type: 'number', required: false },
13
+ metadata: { type: 'object', required: false },
14
+ },
15
+ );
16
+
17
+ const verificationData = { phoneNumber };
18
+ if (code) verificationData.code = code;
19
+ if (expiresIn) verificationData.expiresIn = expiresIn;
20
+ if (metadata) verificationData.metadata = metadata;
21
+
22
+ const params = {
23
+ body: verificationData,
24
+ };
25
+
26
+ const result = await this.sdk._fetch('/verification/sms', 'POST', params);
27
+ return result;
28
+ }
29
+
30
+ async validateSmsVerification(phoneNumber, code) {
31
+ this.sdk.validateParams(
32
+ { phoneNumber, code },
33
+ {
34
+ phoneNumber: { type: 'string', required: true },
35
+ code: { type: 'string', required: true },
36
+ },
37
+ );
38
+
39
+ const params = {
40
+ body: { phoneNumber, code },
41
+ };
42
+
43
+ const result = await this.sdk._fetch('/verification/sms/validate', 'POST', params);
44
+ return result;
45
+ }
46
+
47
+ async createEmailVerification({ email, code, expiresIn, metadata }) {
48
+ this.sdk.validateParams(
49
+ { email },
50
+ {
51
+ email: { type: 'string', required: true },
52
+ code: { type: 'string', required: false },
53
+ expiresIn: { type: 'number', required: false },
54
+ metadata: { type: 'object', required: false },
55
+ },
56
+ );
57
+
58
+ const verificationData = { email };
59
+ if (code) verificationData.code = code;
60
+ if (expiresIn) verificationData.expiresIn = expiresIn;
61
+ if (metadata) verificationData.metadata = metadata;
62
+
63
+ const params = {
64
+ body: verificationData,
65
+ };
66
+
67
+ const result = await this.sdk._fetch('/verification/email', 'POST', params);
68
+ return result;
69
+ }
70
+
71
+ async validateEmailVerification(email, code) {
72
+ this.sdk.validateParams(
73
+ { email, code },
74
+ {
75
+ email: { type: 'string', required: true },
76
+ code: { type: 'string', required: true },
77
+ },
78
+ );
79
+
80
+ const params = {
81
+ body: { email, code },
82
+ };
83
+
84
+ const result = await this.sdk._fetch('/verification/email/validate', 'POST', params);
85
+ return result;
86
+ }
87
+ }