@magentrix-corp/magentrix-sdk 1.1.5 → 1.1.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/README.md +747 -160
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/vue/useMagentrixSdk.js +1 -1
- package/dist/vue/useMagentrixSdk.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,36 +21,70 @@ npm install @magentrix-corp/magentrix-sdk
|
|
|
21
21
|
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
|
+
### Vue 3 Project Template (Recommended)
|
|
25
|
+
|
|
26
|
+
The fastest way to start a new Vue.js project with Magentrix SDK:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm create @magentrix-corp/iris-app-template@latest my-app
|
|
30
|
+
cd my-app
|
|
31
|
+
npm install
|
|
32
|
+
npm run dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Learn more**: [Create Iris App Template](https://www.npmjs.com/package/@magentrix-corp/create-iris-app-template?activeTab=readme)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
24
39
|
### JavaScript/TypeScript
|
|
25
40
|
|
|
26
41
|
```typescript
|
|
27
|
-
import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
42
|
+
import { MagentrixClient, MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
28
43
|
|
|
29
44
|
const config: MagentrixConfig = {
|
|
30
|
-
baseUrl: 'https://
|
|
45
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
31
46
|
refreshToken: '<your-refresh-token>',
|
|
32
|
-
isDevMode: true
|
|
33
|
-
onSessionExpired: async () => {
|
|
34
|
-
console.log('Session expired!')
|
|
35
|
-
},
|
|
36
|
-
onError: (error) => {
|
|
37
|
-
console.error('API Error:', error)
|
|
38
|
-
}
|
|
47
|
+
isDevMode: true // Use token-based auth
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
const
|
|
50
|
+
const dataService = new MagentrixClient(config)
|
|
42
51
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
// Get current user information
|
|
53
|
+
try {
|
|
54
|
+
const userInfo = await dataService.getUserInfo()
|
|
55
|
+
console.log('Logged in as:', userInfo.name)
|
|
56
|
+
console.log('Role:', userInfo.roleType)
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof MagentrixError) {
|
|
59
|
+
console.error('Failed to get user info:', error.message)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
46
62
|
|
|
47
|
-
// Query data
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
// Query data - session is automatically created when needed
|
|
64
|
+
try {
|
|
65
|
+
const result = await dataService.query('SELECT Id, Name FROM Account')
|
|
66
|
+
console.log(result.data) // Array of account objects
|
|
67
|
+
|
|
68
|
+
// Access individual records
|
|
69
|
+
result.data.forEach(account => {
|
|
70
|
+
console.log(account.Id, account.Name)
|
|
71
|
+
})
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error instanceof MagentrixError) {
|
|
74
|
+
console.error('Query failed:', error.message)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
50
77
|
|
|
51
78
|
// Retrieve by ID
|
|
52
|
-
|
|
53
|
-
|
|
79
|
+
try {
|
|
80
|
+
const result = await dataService.retrieve('account-id-123')
|
|
81
|
+
console.log(result.record) // The account object
|
|
82
|
+
console.log('Name:', result.record.Name)
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof MagentrixError) {
|
|
85
|
+
console.error('Retrieve failed:', error.message)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
54
88
|
```
|
|
55
89
|
|
|
56
90
|
### Vue 3
|
|
@@ -58,32 +92,40 @@ console.log(record)
|
|
|
58
92
|
```vue
|
|
59
93
|
<script setup lang="ts">
|
|
60
94
|
import { ref, onMounted } from 'vue'
|
|
61
|
-
import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
95
|
+
import { MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
62
96
|
import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
|
|
63
97
|
|
|
64
98
|
const config: MagentrixConfig = {
|
|
65
|
-
baseUrl: 'https://
|
|
99
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
66
100
|
refreshToken: '<your-refresh-token>',
|
|
67
|
-
isDevMode: true
|
|
68
|
-
onError: (error: any) => {
|
|
69
|
-
console.error('API Error:', error)
|
|
70
|
-
}
|
|
101
|
+
isDevMode: true
|
|
71
102
|
}
|
|
72
103
|
|
|
73
|
-
const
|
|
104
|
+
const dataService = useMagentrixSdk().getInstance(config)
|
|
74
105
|
const account = ref<any>(null)
|
|
106
|
+
const error = ref<string | null>(null)
|
|
75
107
|
|
|
76
108
|
onMounted(async () => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
try {
|
|
110
|
+
// Session is automatically created when needed
|
|
111
|
+
account.value = (await dataService.retrieve('006000000LJIxF70000')).record
|
|
112
|
+
console.log(account.value)
|
|
113
|
+
} catch (err) {
|
|
114
|
+
if (err instanceof MagentrixError) {
|
|
115
|
+
error.value = err.message
|
|
116
|
+
console.error('Failed to retrieve account:', err.message)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
80
119
|
})
|
|
81
120
|
</script>
|
|
82
121
|
|
|
83
122
|
<template>
|
|
84
|
-
<div
|
|
85
|
-
<
|
|
86
|
-
<
|
|
123
|
+
<div>
|
|
124
|
+
<div v-if="error" class="error">{{ error }}</div>
|
|
125
|
+
<div v-else-if="account">
|
|
126
|
+
<h1>{{ account.Name }}</h1>
|
|
127
|
+
<p>{{ account.Email }}</p>
|
|
128
|
+
</div>
|
|
87
129
|
</div>
|
|
88
130
|
</template>
|
|
89
131
|
```
|
|
@@ -94,11 +136,9 @@ onMounted(async () => {
|
|
|
94
136
|
|
|
95
137
|
| Property | Type | Required | Description |
|
|
96
138
|
|----------|------|----------|-------------|
|
|
97
|
-
| `baseUrl` | `string` | Yes | Base URL of your Magentrix instance (e.g., 'https://your-
|
|
139
|
+
| `baseUrl` | `string` | Yes | Base URL of your Magentrix instance (e.g., 'https://your-portal-domain.com') |
|
|
98
140
|
| `refreshToken` | `string` | No | Refresh token for authentication. Required when `isDevMode: true` |
|
|
99
141
|
| `isDevMode` | `boolean` | No | Enable token-based authentication (default: `false`). See [Authentication Modes](#authentication-modes) |
|
|
100
|
-
| `onSessionExpired` | `() => Promise<void> \| void` | No | Callback invoked when session expires |
|
|
101
|
-
| `onError` | `(error: any) => void` | No | Global error handler for all API errors |
|
|
102
142
|
|
|
103
143
|
## Authentication Modes
|
|
104
144
|
|
|
@@ -118,12 +158,12 @@ The SDK supports two authentication modes controlled by the `isDevMode` flag:
|
|
|
118
158
|
import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
119
159
|
|
|
120
160
|
const config: MagentrixConfig = {
|
|
121
|
-
baseUrl: 'https://
|
|
161
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
122
162
|
refreshToken: '<your-refresh-token>',
|
|
123
163
|
isDevMode: true
|
|
124
164
|
}
|
|
125
165
|
|
|
126
|
-
const
|
|
166
|
+
const dataService = new MagentrixClient(config)
|
|
127
167
|
```
|
|
128
168
|
|
|
129
169
|
### Production Mode (`isDevMode: false` or not set)
|
|
@@ -141,11 +181,11 @@ const client = new MagentrixClient(config)
|
|
|
141
181
|
import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
142
182
|
|
|
143
183
|
const config: MagentrixConfig = {
|
|
144
|
-
baseUrl: 'https://your-
|
|
184
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
145
185
|
isDevMode: false // or omit this property
|
|
146
186
|
}
|
|
147
187
|
|
|
148
|
-
const
|
|
188
|
+
const dataService = new MagentrixClient(config)
|
|
149
189
|
```
|
|
150
190
|
|
|
151
191
|
## API Reference
|
|
@@ -156,10 +196,29 @@ const client = new MagentrixClient(config)
|
|
|
156
196
|
|
|
157
197
|
Creates a new session using the refresh token.
|
|
158
198
|
|
|
199
|
+
**Note**: You typically don't need to call this method directly. The SDK automatically creates and refreshes sessions when needed.
|
|
200
|
+
|
|
159
201
|
```typescript
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
202
|
+
import { MagentrixClient, MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
203
|
+
|
|
204
|
+
const config: MagentrixConfig = {
|
|
205
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
206
|
+
refreshToken: '<your-refresh-token>',
|
|
207
|
+
isDevMode: true
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const dataService = new MagentrixClient(config)
|
|
211
|
+
|
|
212
|
+
// Optional: Manually create session if needed
|
|
213
|
+
try {
|
|
214
|
+
const session = await dataService.createSession()
|
|
215
|
+
console.log(session.token) // Bearer token
|
|
216
|
+
console.log(session.expires_in) // Seconds until expiration
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof MagentrixError) {
|
|
219
|
+
console.error('Session creation failed:', error.message)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
163
222
|
```
|
|
164
223
|
|
|
165
224
|
**Parameters**:
|
|
@@ -177,14 +236,58 @@ console.log(session.expires_in) // Seconds until expiration
|
|
|
177
236
|
Execute a custom query using Magentrix query language.
|
|
178
237
|
|
|
179
238
|
```typescript
|
|
180
|
-
|
|
181
|
-
|
|
239
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
// Standard query - returns object with 'data' property containing array of records
|
|
243
|
+
const result = await dataService.query('SELECT Id, Name, Email FROM Contact WHERE Status = "Active"')
|
|
244
|
+
console.log(result.data) // Array of contact objects
|
|
245
|
+
|
|
246
|
+
// Access individual records
|
|
247
|
+
result.data.forEach(contact => {
|
|
248
|
+
console.log(contact.Id, contact.Name, contact.Email)
|
|
249
|
+
})
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (error instanceof MagentrixError) {
|
|
252
|
+
console.error('Query failed:', error.message)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
// Aggregate query - returns object with 'data' property containing aggregate results
|
|
258
|
+
const result = await dataService.query('SELECT COUNT(Id) as TotalAccounts FROM Account')
|
|
259
|
+
console.log(result.data.TotalAccounts) // Number value
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (error instanceof MagentrixError) {
|
|
262
|
+
console.error('Query failed:', error.message)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
// Multiple aggregates
|
|
268
|
+
const result = await dataService.query(`
|
|
269
|
+
SELECT
|
|
270
|
+
COUNT(Id) as TotalAccounts,
|
|
271
|
+
SUM(AnnualRevenue) as TotalRevenue,
|
|
272
|
+
AVG(AnnualRevenue) as AverageRevenue
|
|
273
|
+
FROM Account
|
|
274
|
+
`)
|
|
275
|
+
console.log('Total:', result.data.TotalAccounts)
|
|
276
|
+
console.log('Sum:', result.data.TotalRevenue)
|
|
277
|
+
console.log('Average:', result.data.AverageRevenue)
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error instanceof MagentrixError) {
|
|
280
|
+
console.error('Query failed:', error.message)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
182
283
|
```
|
|
183
284
|
|
|
184
285
|
**Parameters**:
|
|
185
286
|
- `query`: Query string in Magentrix query language
|
|
186
287
|
|
|
187
|
-
**Returns**:
|
|
288
|
+
**Returns**: Object with the following structure:
|
|
289
|
+
- For standard queries: `{ data: Array<Object> }` - Array of records with selected fields
|
|
290
|
+
- For aggregate queries: `{ data: Object }` - Object with aggregate field names as properties
|
|
188
291
|
|
|
189
292
|
**Throws**: `MagentrixError` if query is empty or invalid
|
|
190
293
|
|
|
@@ -195,14 +298,32 @@ console.log(results)
|
|
|
195
298
|
Retrieve a single record by ID.
|
|
196
299
|
|
|
197
300
|
```typescript
|
|
198
|
-
|
|
199
|
-
|
|
301
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
// Retrieve returns an object with a 'record' property
|
|
305
|
+
const result = await dataService.retrieve('account-id-123')
|
|
306
|
+
const account = result.record
|
|
307
|
+
|
|
308
|
+
console.log('Account Name:', account.Name)
|
|
309
|
+
console.log('Account Email:', account.Email)
|
|
310
|
+
console.log('Account Status:', account.Status)
|
|
311
|
+
|
|
312
|
+
// Or destructure directly
|
|
313
|
+
const { record } = await dataService.retrieve('contact-id-456')
|
|
314
|
+
console.log('Contact:', record.Name)
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error instanceof MagentrixError) {
|
|
317
|
+
console.error('Retrieve failed:', error.message)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
200
320
|
```
|
|
201
321
|
|
|
202
322
|
**Parameters**:
|
|
203
323
|
- `id`: Record ID to retrieve
|
|
204
324
|
|
|
205
|
-
**Returns**:
|
|
325
|
+
**Returns**: Object with the following structure:
|
|
326
|
+
- `{ record: Object }` - The record property contains the full record data with all fields
|
|
206
327
|
|
|
207
328
|
**Throws**: `MagentrixError` if ID is not provided
|
|
208
329
|
|
|
@@ -215,12 +336,25 @@ console.log(account.Name)
|
|
|
215
336
|
Create a new record.
|
|
216
337
|
|
|
217
338
|
```typescript
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
339
|
+
import { MagentrixError, DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
340
|
+
|
|
341
|
+
try {
|
|
342
|
+
const newAccount = await dataService.create('Account', {
|
|
343
|
+
Name: 'Acme Corporation',
|
|
344
|
+
Email: 'contact@acme.com',
|
|
345
|
+
Status: 'Active'
|
|
346
|
+
})
|
|
347
|
+
console.log('Created ID:', newAccount.Id)
|
|
348
|
+
} catch (error) {
|
|
349
|
+
if (error instanceof DatabaseError) {
|
|
350
|
+
console.error('Database error:', error.message)
|
|
351
|
+
error.getErrors().forEach(err => {
|
|
352
|
+
console.error(`Field: ${err.fieldName}, Message: ${err.message}`)
|
|
353
|
+
})
|
|
354
|
+
} else if (error instanceof MagentrixError) {
|
|
355
|
+
console.error('Create failed:', error.message)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
224
358
|
```
|
|
225
359
|
|
|
226
360
|
**Parameters**:
|
|
@@ -229,7 +363,7 @@ console.log('Created ID:', newAccount.Id)
|
|
|
229
363
|
|
|
230
364
|
**Returns**: Created record with ID
|
|
231
365
|
|
|
232
|
-
**Throws**: `MagentrixError` if entityName or data is missing
|
|
366
|
+
**Throws**: `MagentrixError` if entityName or data is missing, `DatabaseError` for validation errors
|
|
233
367
|
|
|
234
368
|
---
|
|
235
369
|
|
|
@@ -238,11 +372,25 @@ console.log('Created ID:', newAccount.Id)
|
|
|
238
372
|
Update an existing record (requires `Id` in data).
|
|
239
373
|
|
|
240
374
|
```typescript
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
375
|
+
import { MagentrixError, DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
const updated = await dataService.edit('Account', {
|
|
379
|
+
Id: 'account-id-123',
|
|
380
|
+
Name: 'Updated Name',
|
|
381
|
+
Status: 'Inactive'
|
|
382
|
+
})
|
|
383
|
+
console.log('Updated successfully')
|
|
384
|
+
} catch (error) {
|
|
385
|
+
if (error instanceof DatabaseError) {
|
|
386
|
+
console.error('Database error:', error.message)
|
|
387
|
+
error.getErrors().forEach(err => {
|
|
388
|
+
console.error(`Field: ${err.fieldName}, Message: ${err.message}`)
|
|
389
|
+
})
|
|
390
|
+
} else if (error instanceof MagentrixError) {
|
|
391
|
+
console.error('Edit failed:', error.message)
|
|
392
|
+
}
|
|
393
|
+
}
|
|
246
394
|
```
|
|
247
395
|
|
|
248
396
|
**Parameters**:
|
|
@@ -251,7 +399,7 @@ const updated = await client.edit('Account', {
|
|
|
251
399
|
|
|
252
400
|
**Returns**: Updated record
|
|
253
401
|
|
|
254
|
-
**Throws**: `MagentrixError` if entityName or data is missing
|
|
402
|
+
**Throws**: `MagentrixError` if entityName or data is missing, `DatabaseError` for validation errors
|
|
255
403
|
|
|
256
404
|
---
|
|
257
405
|
|
|
@@ -260,11 +408,25 @@ const updated = await client.edit('Account', {
|
|
|
260
408
|
Create or update a record. If `Id` is provided and exists, updates the record; otherwise creates a new one.
|
|
261
409
|
|
|
262
410
|
```typescript
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
411
|
+
import { MagentrixError, DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
const record = await dataService.upsert('Contact', {
|
|
415
|
+
Id: 'contact-id-456', // Optional
|
|
416
|
+
Name: 'John Doe',
|
|
417
|
+
Email: 'john@example.com'
|
|
418
|
+
})
|
|
419
|
+
console.log('Upsert successful:', record.Id)
|
|
420
|
+
} catch (error) {
|
|
421
|
+
if (error instanceof DatabaseError) {
|
|
422
|
+
console.error('Database error:', error.message)
|
|
423
|
+
error.getErrors().forEach(err => {
|
|
424
|
+
console.error(`Field: ${err.fieldName}, Message: ${err.message}`)
|
|
425
|
+
})
|
|
426
|
+
} else if (error instanceof MagentrixError) {
|
|
427
|
+
console.error('Upsert failed:', error.message)
|
|
428
|
+
}
|
|
429
|
+
}
|
|
268
430
|
```
|
|
269
431
|
|
|
270
432
|
**Parameters**:
|
|
@@ -273,7 +435,7 @@ const record = await client.upsert('Contact', {
|
|
|
273
435
|
|
|
274
436
|
**Returns**: Created or updated record
|
|
275
437
|
|
|
276
|
-
**Throws**: `MagentrixError` if entityName or data is missing
|
|
438
|
+
**Throws**: `MagentrixError` if entityName or data is missing, `DatabaseError` for validation errors
|
|
277
439
|
|
|
278
440
|
---
|
|
279
441
|
|
|
@@ -282,11 +444,27 @@ const record = await client.upsert('Contact', {
|
|
|
282
444
|
Delete a record by ID.
|
|
283
445
|
|
|
284
446
|
```typescript
|
|
285
|
-
|
|
286
|
-
|
|
447
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
// Soft delete (default)
|
|
451
|
+
await dataService.delete('Account', 'account-id-123')
|
|
452
|
+
console.log('Account deleted successfully')
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (error instanceof MagentrixError) {
|
|
455
|
+
console.error('Delete failed:', error.message)
|
|
456
|
+
}
|
|
457
|
+
}
|
|
287
458
|
|
|
288
|
-
|
|
289
|
-
|
|
459
|
+
try {
|
|
460
|
+
// Permanent delete
|
|
461
|
+
await dataService.delete('Account', 'account-id-123', true)
|
|
462
|
+
console.log('Account permanently deleted')
|
|
463
|
+
} catch (error) {
|
|
464
|
+
if (error instanceof MagentrixError) {
|
|
465
|
+
console.error('Delete failed:', error.message)
|
|
466
|
+
}
|
|
467
|
+
}
|
|
290
468
|
```
|
|
291
469
|
|
|
292
470
|
**Parameters**:
|
|
@@ -305,7 +483,16 @@ await client.delete('Account', 'account-id-123', true)
|
|
|
305
483
|
Delete multiple records by IDs.
|
|
306
484
|
|
|
307
485
|
```typescript
|
|
308
|
-
|
|
486
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
487
|
+
|
|
488
|
+
try {
|
|
489
|
+
await dataService.deleteMany('Contact', ['id-1', 'id-2', 'id-3'])
|
|
490
|
+
console.log('Contacts deleted successfully')
|
|
491
|
+
} catch (error) {
|
|
492
|
+
if (error instanceof MagentrixError) {
|
|
493
|
+
console.error('Delete many failed:', error.message)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
309
496
|
```
|
|
310
497
|
|
|
311
498
|
**Parameters**:
|
|
@@ -319,6 +506,52 @@ await client.deleteMany('Contact', ['id-1', 'id-2', 'id-3'])
|
|
|
319
506
|
|
|
320
507
|
---
|
|
321
508
|
|
|
509
|
+
### User Information
|
|
510
|
+
|
|
511
|
+
#### `getUserInfo(): Promise<UserInfo>`
|
|
512
|
+
|
|
513
|
+
Get information about the currently authenticated user.
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
import { MagentrixError, type UserInfo } from '@magentrix-corp/magentrix-sdk'
|
|
517
|
+
|
|
518
|
+
try {
|
|
519
|
+
const userInfo: UserInfo = await dataService.getUserInfo()
|
|
520
|
+
console.log('User Name:', userInfo.name)
|
|
521
|
+
console.log('Username:', userInfo.userName)
|
|
522
|
+
console.log('User ID:', userInfo.id)
|
|
523
|
+
console.log('Role Type:', userInfo.roleType)
|
|
524
|
+
console.log('Locale:', userInfo.locale)
|
|
525
|
+
console.log('Preferred Currency:', userInfo.preferred_currency)
|
|
526
|
+
console.log('Currency Symbol:', userInfo.userCurrencySymbol)
|
|
527
|
+
console.log('Timezone Offset:', userInfo.user_timezone)
|
|
528
|
+
console.log('Is Guest:', userInfo.guest)
|
|
529
|
+
console.log('Is Impersonating:', userInfo.impr)
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (error instanceof MagentrixError) {
|
|
532
|
+
console.error('Failed to get user info:', error.message)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
**Returns**: `UserInfo` object containing:
|
|
538
|
+
- `name`: Full name of the user
|
|
539
|
+
- `userName`: Username of the user
|
|
540
|
+
- `id`: User ID
|
|
541
|
+
- `guest`: Whether the user is a guest
|
|
542
|
+
- `impr`: Whether the user is using delegated access (impersonation)
|
|
543
|
+
- `preferred_currency`: User's preferred currency ISO code
|
|
544
|
+
- `user_timezone`: User's timezone offset
|
|
545
|
+
- `userCurrencySymbol`: User's currency symbol
|
|
546
|
+
- `lang`: User's language code
|
|
547
|
+
- `roleType`: User's role type (`'guest'`, `'employee'`, `'customer'`, `'partner'`, or `'admin'`)
|
|
548
|
+
- `locale`: User's locale
|
|
549
|
+
- `display_user_currency`: Whether to display amounts in user's currency
|
|
550
|
+
|
|
551
|
+
**Throws**: `MagentrixError` if the request fails
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
322
555
|
### Custom Endpoints
|
|
323
556
|
|
|
324
557
|
#### `execute(path: string, model?: any, method?: RequestMethod): Promise<any>`
|
|
@@ -326,16 +559,30 @@ await client.deleteMany('Contact', ['id-1', 'id-2', 'id-3'])
|
|
|
326
559
|
Execute a custom API endpoint.
|
|
327
560
|
|
|
328
561
|
```typescript
|
|
329
|
-
import { RequestMethod } from '@magentrix-corp/magentrix-sdk'
|
|
562
|
+
import { MagentrixError, RequestMethod } from '@magentrix-corp/magentrix-sdk'
|
|
330
563
|
|
|
331
|
-
|
|
332
|
-
|
|
564
|
+
try {
|
|
565
|
+
// GET request
|
|
566
|
+
const data = await dataService.execute('/custom/endpoint', null, RequestMethod.get)
|
|
567
|
+
console.log('GET result:', data)
|
|
568
|
+
} catch (error) {
|
|
569
|
+
if (error instanceof MagentrixError) {
|
|
570
|
+
console.error('GET request failed:', error.message)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
333
573
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
574
|
+
try {
|
|
575
|
+
// POST request
|
|
576
|
+
const result = await dataService.execute('/custom/action', {
|
|
577
|
+
param1: 'value1',
|
|
578
|
+
param2: 'value2'
|
|
579
|
+
}, RequestMethod.post)
|
|
580
|
+
console.log('POST result:', result)
|
|
581
|
+
} catch (error) {
|
|
582
|
+
if (error instanceof MagentrixError) {
|
|
583
|
+
console.error('POST request failed:', error.message)
|
|
584
|
+
}
|
|
585
|
+
}
|
|
339
586
|
```
|
|
340
587
|
|
|
341
588
|
**Parameters**:
|
|
@@ -361,7 +608,8 @@ General SDK errors (authentication, validation, API errors).
|
|
|
361
608
|
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
362
609
|
|
|
363
610
|
try {
|
|
364
|
-
await
|
|
611
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
612
|
+
console.log(result.data) // Array of account objects
|
|
365
613
|
} catch (error) {
|
|
366
614
|
if (error instanceof MagentrixError) {
|
|
367
615
|
console.error('Magentrix Error:', error.message)
|
|
@@ -377,7 +625,7 @@ Database-specific errors with detailed error information.
|
|
|
377
625
|
import { DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
378
626
|
|
|
379
627
|
try {
|
|
380
|
-
await
|
|
628
|
+
await dataService.create('Account', invalidData)
|
|
381
629
|
} catch (error) {
|
|
382
630
|
if (error instanceof DatabaseError) {
|
|
383
631
|
console.error('Database Error:', error.message)
|
|
@@ -390,21 +638,209 @@ try {
|
|
|
390
638
|
}
|
|
391
639
|
```
|
|
392
640
|
|
|
393
|
-
###
|
|
641
|
+
### Common Error Codes
|
|
642
|
+
|
|
643
|
+
The API returns specific error codes for different scenarios. Here are the most common ones:
|
|
644
|
+
|
|
645
|
+
#### Create Operation Errors
|
|
646
|
+
|
|
647
|
+
**HTTP 406 Not Acceptable** - Validation errors
|
|
648
|
+
|
|
649
|
+
```json
|
|
650
|
+
{
|
|
651
|
+
"errors": [
|
|
652
|
+
{
|
|
653
|
+
"code": "Missing_Field",
|
|
654
|
+
"fieldName": "Name",
|
|
655
|
+
"message": "You must enter a value."
|
|
656
|
+
}
|
|
657
|
+
],
|
|
658
|
+
"id": null,
|
|
659
|
+
"success": false
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
**HTTP 413 Request Entity Too Large** - Payload exceeds size limit
|
|
394
664
|
|
|
395
|
-
|
|
665
|
+
```json
|
|
666
|
+
{
|
|
667
|
+
"errors": [
|
|
668
|
+
{
|
|
669
|
+
"code": "PAYLOAD_TOO_LARGE",
|
|
670
|
+
"message": "The payload size exceeds the 20MB size limit."
|
|
671
|
+
}
|
|
672
|
+
],
|
|
673
|
+
"id": null,
|
|
674
|
+
"success": false
|
|
675
|
+
}
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
**HTTP 400 Bad Request** - Missing or invalid payload
|
|
679
|
+
|
|
680
|
+
```json
|
|
681
|
+
{
|
|
682
|
+
"errors": [
|
|
683
|
+
{
|
|
684
|
+
"code": "PAYLOAD_MISSING",
|
|
685
|
+
"message": "Request body is empty. A valid JSON/XML payload is required."
|
|
686
|
+
}
|
|
687
|
+
],
|
|
688
|
+
"id": null,
|
|
689
|
+
"success": false
|
|
690
|
+
}
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
#### Update Operation Errors
|
|
694
|
+
|
|
695
|
+
**HTTP 406 Not Acceptable** - Validation errors
|
|
696
|
+
|
|
697
|
+
```json
|
|
698
|
+
{
|
|
699
|
+
"errors": [
|
|
700
|
+
{
|
|
701
|
+
"code": "Missing_Field",
|
|
702
|
+
"fieldName": "LastName",
|
|
703
|
+
"message": "You must enter a value."
|
|
704
|
+
}
|
|
705
|
+
],
|
|
706
|
+
"id": null,
|
|
707
|
+
"success": false
|
|
708
|
+
}
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
**HTTP 404 Not Found** - Record not found
|
|
712
|
+
|
|
713
|
+
```json
|
|
714
|
+
{
|
|
715
|
+
"errors": [
|
|
716
|
+
{
|
|
717
|
+
"code": "MISSING_ENTITY",
|
|
718
|
+
"message": "Record no longer exists."
|
|
719
|
+
}
|
|
720
|
+
],
|
|
721
|
+
"id": null,
|
|
722
|
+
"success": false
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
**HTTP 400 Bad Request** - ID mismatch
|
|
727
|
+
|
|
728
|
+
```json
|
|
729
|
+
{
|
|
730
|
+
"errors": [
|
|
731
|
+
{
|
|
732
|
+
"code": "ENTITY_ID_MISMATCH",
|
|
733
|
+
"message": "The ID in the request body does not match the record ID in the URL."
|
|
734
|
+
}
|
|
735
|
+
],
|
|
736
|
+
"id": null,
|
|
737
|
+
"success": false
|
|
738
|
+
}
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
#### Delete Operation Errors
|
|
742
|
+
|
|
743
|
+
**HTTP 406 Not Acceptable** - Resource not found
|
|
744
|
+
|
|
745
|
+
```json
|
|
746
|
+
{
|
|
747
|
+
"message": "Resource not found",
|
|
748
|
+
"success": false
|
|
749
|
+
}
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
**HTTP 404 Not Found** - Record not found
|
|
753
|
+
|
|
754
|
+
```json
|
|
755
|
+
{
|
|
756
|
+
"errors": [
|
|
757
|
+
{
|
|
758
|
+
"code": "ENTITY_NOT_FOUND",
|
|
759
|
+
"message": "Record was not found or you may not have access."
|
|
760
|
+
}
|
|
761
|
+
],
|
|
762
|
+
"id": "Not found",
|
|
763
|
+
"success": false
|
|
764
|
+
}
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
#### Authentication Errors
|
|
768
|
+
|
|
769
|
+
**HTTP 401 Unauthorized** - Invalid or expired session
|
|
770
|
+
|
|
771
|
+
```json
|
|
772
|
+
{
|
|
773
|
+
"message": "Session expired. Please authenticate again.",
|
|
774
|
+
"success": false
|
|
775
|
+
}
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
**HTTP 403 Forbidden** - Invalid token or too many failed attempts
|
|
779
|
+
|
|
780
|
+
```json
|
|
781
|
+
{
|
|
782
|
+
"errors": [
|
|
783
|
+
{
|
|
784
|
+
"code": "403",
|
|
785
|
+
"message": "Invalid Token"
|
|
786
|
+
}
|
|
787
|
+
],
|
|
788
|
+
"success": false
|
|
789
|
+
}
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
#### General Errors
|
|
793
|
+
|
|
794
|
+
**HTTP 404 Not Found** - Invalid entity or resource
|
|
795
|
+
|
|
796
|
+
```json
|
|
797
|
+
{
|
|
798
|
+
"errors": [
|
|
799
|
+
{
|
|
800
|
+
"code": "INVALID_ENTITY",
|
|
801
|
+
"message": "Entity 'InvalidEntity' does not exist."
|
|
802
|
+
}
|
|
803
|
+
],
|
|
804
|
+
"id": null,
|
|
805
|
+
"success": false
|
|
806
|
+
}
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
**HTTP 500 Internal Server Error** - Unexpected server error
|
|
810
|
+
|
|
811
|
+
```json
|
|
812
|
+
{
|
|
813
|
+
"message": "An unexpected error occurred.",
|
|
814
|
+
"success": false
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
### Error Handling Example
|
|
396
819
|
|
|
397
820
|
```typescript
|
|
398
|
-
|
|
399
|
-
baseUrl: 'https://your-instance.magentrix.com',
|
|
400
|
-
onError: (error) => {
|
|
401
|
-
// Log to monitoring service
|
|
402
|
-
console.error('Global error handler:', error)
|
|
821
|
+
import { MagentrixError, DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
403
822
|
|
|
404
|
-
|
|
405
|
-
|
|
823
|
+
try {
|
|
824
|
+
const newAccount = await dataService.create('Account', {
|
|
825
|
+
Name: 'Acme Corporation',
|
|
826
|
+
Email: 'contact@acme.com'
|
|
827
|
+
})
|
|
828
|
+
console.log('Created:', newAccount.Id)
|
|
829
|
+
} catch (error) {
|
|
830
|
+
if (error instanceof DatabaseError) {
|
|
831
|
+
// Handle validation errors with field-level details
|
|
832
|
+
console.error('Validation failed:', error.message)
|
|
833
|
+
error.getErrors().forEach(err => {
|
|
834
|
+
console.error(`- ${err.fieldName}: ${err.message} (Code: ${err.code})`)
|
|
835
|
+
})
|
|
836
|
+
} else if (error instanceof MagentrixError) {
|
|
837
|
+
// Handle general API errors
|
|
838
|
+
console.error('API Error:', error.message)
|
|
839
|
+
} else {
|
|
840
|
+
// Handle unexpected errors
|
|
841
|
+
console.error('Unexpected error:', error)
|
|
406
842
|
}
|
|
407
|
-
}
|
|
843
|
+
}
|
|
408
844
|
```
|
|
409
845
|
|
|
410
846
|
|
|
@@ -412,21 +848,30 @@ const client = new MagentrixClient({
|
|
|
412
848
|
|
|
413
849
|
## Advanced Usage
|
|
414
850
|
|
|
415
|
-
### Session
|
|
851
|
+
### Automatic Session Management
|
|
416
852
|
|
|
417
|
-
|
|
853
|
+
The SDK automatically handles session creation and refresh:
|
|
418
854
|
|
|
419
855
|
```typescript
|
|
420
|
-
|
|
421
|
-
|
|
856
|
+
import { MagentrixClient, MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
857
|
+
|
|
858
|
+
const config: MagentrixConfig = {
|
|
859
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
422
860
|
refreshToken: 'your-refresh-token',
|
|
423
|
-
isDevMode: true
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
861
|
+
isDevMode: true
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
const dataService = new MagentrixClient(config)
|
|
865
|
+
|
|
866
|
+
// No need to call createSession() - the SDK handles it automatically
|
|
867
|
+
try {
|
|
868
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
869
|
+
console.log(result.data) // Array of account objects
|
|
870
|
+
} catch (error) {
|
|
871
|
+
if (error instanceof MagentrixError) {
|
|
872
|
+
console.error('Query failed:', error.message)
|
|
428
873
|
}
|
|
429
|
-
}
|
|
874
|
+
}
|
|
430
875
|
```
|
|
431
876
|
|
|
432
877
|
### TypeScript Types
|
|
@@ -438,6 +883,7 @@ import {
|
|
|
438
883
|
MagentrixClient,
|
|
439
884
|
MagentrixConfig,
|
|
440
885
|
SessionInfo,
|
|
886
|
+
UserInfo,
|
|
441
887
|
MagentrixError,
|
|
442
888
|
DatabaseError,
|
|
443
889
|
RequestMethod,
|
|
@@ -445,12 +891,16 @@ import {
|
|
|
445
891
|
} from '@magentrix-corp/magentrix-sdk'
|
|
446
892
|
|
|
447
893
|
const config: MagentrixConfig = {
|
|
448
|
-
baseUrl: 'https://your-
|
|
894
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
449
895
|
refreshToken: 'your-refresh-token',
|
|
450
896
|
isDevMode: true
|
|
451
897
|
}
|
|
452
898
|
|
|
453
|
-
const
|
|
899
|
+
const dataService = new MagentrixClient(config)
|
|
900
|
+
|
|
901
|
+
// Use UserInfo type for type safety
|
|
902
|
+
const userInfo: UserInfo = await dataService.getUserInfo()
|
|
903
|
+
console.log(`Welcome ${userInfo.name}!`)
|
|
454
904
|
```
|
|
455
905
|
|
|
456
906
|
### Batch Operations
|
|
@@ -458,6 +908,8 @@ const client = new MagentrixClient(config)
|
|
|
458
908
|
Perform multiple operations efficiently:
|
|
459
909
|
|
|
460
910
|
```typescript
|
|
911
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
912
|
+
|
|
461
913
|
// Create multiple records
|
|
462
914
|
const accounts = [
|
|
463
915
|
{ Name: 'Account 1', Status: 'Active' },
|
|
@@ -465,40 +917,136 @@ const accounts = [
|
|
|
465
917
|
{ Name: 'Account 3', Status: 'Active' }
|
|
466
918
|
]
|
|
467
919
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
)
|
|
471
|
-
|
|
472
|
-
console.log('Created IDs:', created.map(a => a.Id))
|
|
920
|
+
try {
|
|
921
|
+
const created = await Promise.all(
|
|
922
|
+
accounts.map(account => dataService.create('Account', account))
|
|
923
|
+
)
|
|
924
|
+
console.log('Created IDs:', created.map(a => a.Id))
|
|
925
|
+
} catch (error) {
|
|
926
|
+
if (error instanceof MagentrixError) {
|
|
927
|
+
console.error('Batch create failed:', error.message)
|
|
928
|
+
}
|
|
929
|
+
}
|
|
473
930
|
|
|
474
931
|
// Delete multiple records
|
|
475
|
-
|
|
476
|
-
|
|
932
|
+
try {
|
|
933
|
+
const idsToDelete = ['id-1', 'id-2', 'id-3']
|
|
934
|
+
await dataService.deleteMany('Account', idsToDelete)
|
|
935
|
+
console.log('Batch delete successful')
|
|
936
|
+
} catch (error) {
|
|
937
|
+
if (error instanceof MagentrixError) {
|
|
938
|
+
console.error('Batch delete failed:', error.message)
|
|
939
|
+
}
|
|
940
|
+
}
|
|
477
941
|
```
|
|
478
942
|
|
|
479
943
|
### Custom Query Examples
|
|
480
944
|
|
|
481
945
|
```typescript
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
946
|
+
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
947
|
+
|
|
948
|
+
try {
|
|
949
|
+
// Simple query - returns array of records in 'data' property
|
|
950
|
+
const result = await dataService.query(
|
|
951
|
+
'SELECT Id, Name, Email FROM Contact WHERE Status = "Active"'
|
|
952
|
+
)
|
|
953
|
+
console.log('Active contacts:', result.data)
|
|
954
|
+
|
|
955
|
+
// Iterate through results
|
|
956
|
+
result.data.forEach(contact => {
|
|
957
|
+
console.log(`${contact.Name} - ${contact.Email}`)
|
|
958
|
+
})
|
|
959
|
+
} catch (error) {
|
|
960
|
+
if (error instanceof MagentrixError) {
|
|
961
|
+
console.error('Query failed:', error.message)
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
try {
|
|
966
|
+
// Query with sorting
|
|
967
|
+
const result = await dataService.query(
|
|
968
|
+
'SELECT Id, Name FROM Account ORDER BY Name ASC'
|
|
969
|
+
)
|
|
970
|
+
console.log('Sorted accounts:', result.data)
|
|
971
|
+
} catch (error) {
|
|
972
|
+
if (error instanceof MagentrixError) {
|
|
973
|
+
console.error('Query failed:', error.message)
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
try {
|
|
978
|
+
// Query with limit
|
|
979
|
+
const result = await dataService.query(
|
|
980
|
+
'SELECT Id, Name FROM Account LIMIT 10'
|
|
981
|
+
)
|
|
982
|
+
console.log('Recent records:', result.data)
|
|
983
|
+
console.log('Total records returned:', result.data.length)
|
|
984
|
+
} catch (error) {
|
|
985
|
+
if (error instanceof MagentrixError) {
|
|
986
|
+
console.error('Query failed:', error.message)
|
|
987
|
+
}
|
|
988
|
+
}
|
|
486
989
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
)
|
|
990
|
+
try {
|
|
991
|
+
// Aggregate query - returns object with aggregate values
|
|
992
|
+
const result = await dataService.query(
|
|
993
|
+
'SELECT COUNT(Id) as TotalAccounts FROM Account'
|
|
994
|
+
)
|
|
995
|
+
console.log('Total accounts:', result.data.TotalAccounts)
|
|
996
|
+
} catch (error) {
|
|
997
|
+
if (error instanceof MagentrixError) {
|
|
998
|
+
console.error('Query failed:', error.message)
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
491
1001
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
1002
|
+
try {
|
|
1003
|
+
// Multiple aggregates
|
|
1004
|
+
const result = await dataService.query(`
|
|
1005
|
+
SELECT
|
|
1006
|
+
COUNT(Id) as Total,
|
|
1007
|
+
SUM(AnnualRevenue) as Revenue,
|
|
1008
|
+
AVG(NumberOfEmployees) as AvgEmployees
|
|
1009
|
+
FROM Account
|
|
1010
|
+
WHERE Status = "Active"
|
|
1011
|
+
`)
|
|
1012
|
+
console.log('Statistics:', {
|
|
1013
|
+
total: result.data.Total,
|
|
1014
|
+
revenue: result.data.Revenue,
|
|
1015
|
+
avgEmployees: result.data.AvgEmployees
|
|
1016
|
+
})
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
if (error instanceof MagentrixError) {
|
|
1019
|
+
console.error('Query failed:', error.message)
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
496
1022
|
```
|
|
497
1023
|
|
|
498
1024
|
---
|
|
499
1025
|
|
|
500
1026
|
## Vue 3 Integration
|
|
501
1027
|
|
|
1028
|
+
### Quick Start with Project Template
|
|
1029
|
+
|
|
1030
|
+
The fastest way to get started with a Vue.js project using the Magentrix SDK is to use the official project template:
|
|
1031
|
+
|
|
1032
|
+
```bash
|
|
1033
|
+
npm create @magentrix-corp/iris-app-template@latest my-app
|
|
1034
|
+
cd my-app
|
|
1035
|
+
npm install
|
|
1036
|
+
npm run dev
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
This template provides:
|
|
1040
|
+
- ✅ Pre-configured Magentrix SDK integration
|
|
1041
|
+
- ✅ Vue 3 + TypeScript setup
|
|
1042
|
+
- ✅ Vite for fast development
|
|
1043
|
+
- ✅ Example components and best practices
|
|
1044
|
+
- ✅ Ready-to-use authentication flow
|
|
1045
|
+
|
|
1046
|
+
**Learn more**: [https://www.npmjs.com/package/@magentrix-corp/create-iris-app-template](https://www.npmjs.com/package/@magentrix-corp/create-iris-app-template?activeTab=readme)
|
|
1047
|
+
|
|
1048
|
+
---
|
|
1049
|
+
|
|
502
1050
|
### Composable Usage
|
|
503
1051
|
|
|
504
1052
|
The SDK provides a dedicated Vue 3 composable:
|
|
@@ -506,16 +1054,16 @@ The SDK provides a dedicated Vue 3 composable:
|
|
|
506
1054
|
```vue
|
|
507
1055
|
<script setup lang="ts">
|
|
508
1056
|
import { ref, onMounted } from 'vue'
|
|
509
|
-
import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
1057
|
+
import { MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
510
1058
|
import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
|
|
511
1059
|
|
|
512
1060
|
const config: MagentrixConfig = {
|
|
513
|
-
baseUrl: 'https://
|
|
1061
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
514
1062
|
refreshToken: '<your-refresh-token>',
|
|
515
1063
|
isDevMode: true
|
|
516
1064
|
}
|
|
517
1065
|
|
|
518
|
-
const
|
|
1066
|
+
const dataService = useMagentrixSdk().getInstance(config)
|
|
519
1067
|
const accounts = ref<any[]>([])
|
|
520
1068
|
const loading = ref(false)
|
|
521
1069
|
const error = ref<string | null>(null)
|
|
@@ -525,11 +1073,14 @@ const loadAccounts = async () => {
|
|
|
525
1073
|
error.value = null
|
|
526
1074
|
|
|
527
1075
|
try {
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
accounts.value =
|
|
531
|
-
} catch (err
|
|
532
|
-
|
|
1076
|
+
// Session is automatically created when needed
|
|
1077
|
+
const result = await dataService.query('SELECT Id, Name FROM Account')
|
|
1078
|
+
accounts.value = result.data // Extract the data array
|
|
1079
|
+
} catch (err) {
|
|
1080
|
+
if (err instanceof MagentrixError) {
|
|
1081
|
+
error.value = err.message
|
|
1082
|
+
console.error('Failed to load accounts:', err.message)
|
|
1083
|
+
}
|
|
533
1084
|
} finally {
|
|
534
1085
|
loading.value = false
|
|
535
1086
|
}
|
|
@@ -558,16 +1109,16 @@ onMounted(() => {
|
|
|
558
1109
|
```vue
|
|
559
1110
|
<script setup lang="ts">
|
|
560
1111
|
import { ref } from 'vue'
|
|
561
|
-
import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
1112
|
+
import { MagentrixError, DatabaseError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
562
1113
|
import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
|
|
563
1114
|
|
|
564
1115
|
const config: MagentrixConfig = {
|
|
565
|
-
baseUrl: 'https://
|
|
1116
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
566
1117
|
refreshToken: '<your-refresh-token>',
|
|
567
1118
|
isDevMode: true
|
|
568
1119
|
}
|
|
569
1120
|
|
|
570
|
-
const
|
|
1121
|
+
const dataService = useMagentrixSdk().getInstance(config)
|
|
571
1122
|
|
|
572
1123
|
const formData = ref({
|
|
573
1124
|
Name: 'Company Name',
|
|
@@ -577,34 +1128,50 @@ const formData = ref({
|
|
|
577
1128
|
|
|
578
1129
|
const createAccount = async () => {
|
|
579
1130
|
try {
|
|
580
|
-
const created = await
|
|
1131
|
+
const created = await dataService.create('Account', formData.value)
|
|
581
1132
|
console.log('Created:', created)
|
|
582
1133
|
|
|
583
1134
|
// Reset form
|
|
584
1135
|
formData.value = { Name: '', Type: '', Status: 'Active' }
|
|
585
1136
|
} catch (error) {
|
|
586
|
-
|
|
1137
|
+
if (error instanceof DatabaseError) {
|
|
1138
|
+
console.error('Database error:', error.message)
|
|
1139
|
+
error.getErrors().forEach(err => {
|
|
1140
|
+
console.error(`Field: ${err.fieldName}, Message: ${err.message}`)
|
|
1141
|
+
})
|
|
1142
|
+
} else if (error instanceof MagentrixError) {
|
|
1143
|
+
console.error('Failed to create account:', error.message)
|
|
1144
|
+
}
|
|
587
1145
|
}
|
|
588
1146
|
}
|
|
589
1147
|
|
|
590
1148
|
const updateAccount = async (id: string) => {
|
|
591
1149
|
try {
|
|
592
|
-
await
|
|
1150
|
+
await dataService.edit('Account', {
|
|
593
1151
|
Id: id,
|
|
594
1152
|
...formData.value
|
|
595
1153
|
})
|
|
596
1154
|
console.log('Updated successfully')
|
|
597
1155
|
} catch (error) {
|
|
598
|
-
|
|
1156
|
+
if (error instanceof DatabaseError) {
|
|
1157
|
+
console.error('Database error:', error.message)
|
|
1158
|
+
error.getErrors().forEach(err => {
|
|
1159
|
+
console.error(`Field: ${err.fieldName}, Message: ${err.message}`)
|
|
1160
|
+
})
|
|
1161
|
+
} else if (error instanceof MagentrixError) {
|
|
1162
|
+
console.error('Failed to update account:', error.message)
|
|
1163
|
+
}
|
|
599
1164
|
}
|
|
600
1165
|
}
|
|
601
1166
|
|
|
602
1167
|
const deleteAccount = async (id: string) => {
|
|
603
1168
|
try {
|
|
604
|
-
await
|
|
1169
|
+
await dataService.delete('Account', id)
|
|
605
1170
|
console.log('Deleted successfully')
|
|
606
1171
|
} catch (error) {
|
|
607
|
-
|
|
1172
|
+
if (error instanceof MagentrixError) {
|
|
1173
|
+
console.error('Failed to delete account:', error.message)
|
|
1174
|
+
}
|
|
608
1175
|
}
|
|
609
1176
|
}
|
|
610
1177
|
</script>
|
|
@@ -619,8 +1186,8 @@ const deleteAccount = async (id: string) => {
|
|
|
619
1186
|
Use environment variables for configuration:
|
|
620
1187
|
|
|
621
1188
|
```typescript
|
|
622
|
-
const
|
|
623
|
-
baseUrl: process.env.MAGENTRIX_BASE_URL || 'https://
|
|
1189
|
+
const dataService = new MagentrixClient({
|
|
1190
|
+
baseUrl: process.env.MAGENTRIX_BASE_URL || 'https://your-portal-domain.com',
|
|
624
1191
|
refreshToken: process.env.MAGENTRIX_REFRESH_TOKEN,
|
|
625
1192
|
isDevMode: process.env.NODE_ENV === 'development'
|
|
626
1193
|
})
|
|
@@ -631,12 +1198,15 @@ const client = new MagentrixClient({
|
|
|
631
1198
|
Always handle errors appropriately:
|
|
632
1199
|
|
|
633
1200
|
```typescript
|
|
1201
|
+
import { MagentrixError, DatabaseError } from '@magentrix-corp/magentrix-sdk'
|
|
1202
|
+
|
|
634
1203
|
try {
|
|
635
|
-
const result = await
|
|
636
|
-
|
|
1204
|
+
const result = await dataService.create('Account', data)
|
|
1205
|
+
console.log('Account created:', result.Id)
|
|
637
1206
|
} catch (error) {
|
|
638
1207
|
if (error instanceof DatabaseError) {
|
|
639
1208
|
// Handle database validation errors
|
|
1209
|
+
console.error('Database Error:', error.message)
|
|
640
1210
|
error.getErrors().forEach(err => {
|
|
641
1211
|
console.error(`${err.fieldName}: ${err.message}`)
|
|
642
1212
|
})
|
|
@@ -652,21 +1222,23 @@ try {
|
|
|
652
1222
|
|
|
653
1223
|
### 3. Session Management
|
|
654
1224
|
|
|
655
|
-
|
|
1225
|
+
The SDK automatically manages sessions - no manual initialization needed:
|
|
656
1226
|
|
|
657
1227
|
```typescript
|
|
658
1228
|
// app.ts or main.ts
|
|
659
|
-
|
|
660
|
-
|
|
1229
|
+
import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
1230
|
+
|
|
1231
|
+
const config: MagentrixConfig = {
|
|
1232
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
661
1233
|
refreshToken: 'your-refresh-token',
|
|
662
1234
|
isDevMode: true
|
|
663
|
-
}
|
|
1235
|
+
}
|
|
664
1236
|
|
|
665
|
-
|
|
666
|
-
await client.createSession()
|
|
1237
|
+
const dataService = new MagentrixClient(config)
|
|
667
1238
|
|
|
1239
|
+
// No need to call createSession() - it's handled automatically
|
|
668
1240
|
// Export for use throughout the app
|
|
669
|
-
export {
|
|
1241
|
+
export { dataService }
|
|
670
1242
|
```
|
|
671
1243
|
|
|
672
1244
|
### 4. Production Deployment
|
|
@@ -674,14 +1246,25 @@ export { client }
|
|
|
674
1246
|
For production (cookie-based auth), no session creation needed:
|
|
675
1247
|
|
|
676
1248
|
```typescript
|
|
677
|
-
|
|
678
|
-
|
|
1249
|
+
import { MagentrixClient, MagentrixError, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
1250
|
+
|
|
1251
|
+
const config: MagentrixConfig = {
|
|
1252
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
679
1253
|
isDevMode: false // Uses ASP.NET session cookies
|
|
680
|
-
}
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const dataService = new MagentrixClient(config)
|
|
681
1257
|
|
|
682
1258
|
// No need to call createSession()
|
|
683
|
-
// Just use the
|
|
684
|
-
|
|
1259
|
+
// Just use the dataService directly
|
|
1260
|
+
try {
|
|
1261
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
1262
|
+
console.log(result.data) // Array of account objects
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
if (error instanceof MagentrixError) {
|
|
1265
|
+
console.error('Query failed:', error.message)
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
685
1268
|
```
|
|
686
1269
|
|
|
687
1270
|
---
|
|
@@ -695,11 +1278,15 @@ const data = await client.query('SELECT Id FROM Account')
|
|
|
695
1278
|
**Solution**: Ensure `refreshToken` is provided in config when using `isDevMode: true`
|
|
696
1279
|
|
|
697
1280
|
```typescript
|
|
698
|
-
|
|
699
|
-
|
|
1281
|
+
import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
|
|
1282
|
+
|
|
1283
|
+
const config: MagentrixConfig = {
|
|
1284
|
+
baseUrl: 'https://your-portal-domain.com',
|
|
700
1285
|
refreshToken: 'your-refresh-token', // Required for dev mode
|
|
701
1286
|
isDevMode: true
|
|
702
|
-
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
const dataService = new MagentrixClient(config)
|
|
703
1290
|
```
|
|
704
1291
|
|
|
705
1292
|
---
|
|
@@ -723,8 +1310,8 @@ Proprietary
|
|
|
723
1310
|
## Support
|
|
724
1311
|
|
|
725
1312
|
For issues and questions:
|
|
726
|
-
-
|
|
727
|
-
-
|
|
1313
|
+
- Documentation: [Magentrix Help Center]https://help.magentrix.com/
|
|
1314
|
+
- Website: [Magentrix.com](https://www.magentrix.com/)
|
|
728
1315
|
|
|
729
1316
|
---
|
|
730
1317
|
|