@magentrix-corp/magentrix-sdk 1.1.6 → 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 +153 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,21 @@ 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
|
|
@@ -47,8 +62,13 @@ try {
|
|
|
47
62
|
|
|
48
63
|
// Query data - session is automatically created when needed
|
|
49
64
|
try {
|
|
50
|
-
const
|
|
51
|
-
console.log(
|
|
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
|
+
})
|
|
52
72
|
} catch (error) {
|
|
53
73
|
if (error instanceof MagentrixError) {
|
|
54
74
|
console.error('Query failed:', error.message)
|
|
@@ -57,8 +77,9 @@ try {
|
|
|
57
77
|
|
|
58
78
|
// Retrieve by ID
|
|
59
79
|
try {
|
|
60
|
-
const
|
|
61
|
-
console.log(record)
|
|
80
|
+
const result = await dataService.retrieve('account-id-123')
|
|
81
|
+
console.log(result.record) // The account object
|
|
82
|
+
console.log('Name:', result.record.Name)
|
|
62
83
|
} catch (error) {
|
|
63
84
|
if (error instanceof MagentrixError) {
|
|
64
85
|
console.error('Retrieve failed:', error.message)
|
|
@@ -218,8 +239,42 @@ Execute a custom query using Magentrix query language.
|
|
|
218
239
|
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
219
240
|
|
|
220
241
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
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)
|
|
223
278
|
} catch (error) {
|
|
224
279
|
if (error instanceof MagentrixError) {
|
|
225
280
|
console.error('Query failed:', error.message)
|
|
@@ -230,7 +285,9 @@ try {
|
|
|
230
285
|
**Parameters**:
|
|
231
286
|
- `query`: Query string in Magentrix query language
|
|
232
287
|
|
|
233
|
-
**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
|
|
234
291
|
|
|
235
292
|
**Throws**: `MagentrixError` if query is empty or invalid
|
|
236
293
|
|
|
@@ -244,8 +301,17 @@ Retrieve a single record by ID.
|
|
|
244
301
|
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
245
302
|
|
|
246
303
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
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)
|
|
249
315
|
} catch (error) {
|
|
250
316
|
if (error instanceof MagentrixError) {
|
|
251
317
|
console.error('Retrieve failed:', error.message)
|
|
@@ -256,7 +322,8 @@ try {
|
|
|
256
322
|
**Parameters**:
|
|
257
323
|
- `id`: Record ID to retrieve
|
|
258
324
|
|
|
259
|
-
**Returns**:
|
|
325
|
+
**Returns**: Object with the following structure:
|
|
326
|
+
- `{ record: Object }` - The record property contains the full record data with all fields
|
|
260
327
|
|
|
261
328
|
**Throws**: `MagentrixError` if ID is not provided
|
|
262
329
|
|
|
@@ -541,8 +608,8 @@ General SDK errors (authentication, validation, API errors).
|
|
|
541
608
|
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
542
609
|
|
|
543
610
|
try {
|
|
544
|
-
const
|
|
545
|
-
console.log(
|
|
611
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
612
|
+
console.log(result.data) // Array of account objects
|
|
546
613
|
} catch (error) {
|
|
547
614
|
if (error instanceof MagentrixError) {
|
|
548
615
|
console.error('Magentrix Error:', error.message)
|
|
@@ -798,8 +865,8 @@ const dataService = new MagentrixClient(config)
|
|
|
798
865
|
|
|
799
866
|
// No need to call createSession() - the SDK handles it automatically
|
|
800
867
|
try {
|
|
801
|
-
const
|
|
802
|
-
console.log(
|
|
868
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
869
|
+
console.log(result.data) // Array of account objects
|
|
803
870
|
} catch (error) {
|
|
804
871
|
if (error instanceof MagentrixError) {
|
|
805
872
|
console.error('Query failed:', error.message)
|
|
@@ -879,11 +946,16 @@ try {
|
|
|
879
946
|
import { MagentrixError } from '@magentrix-corp/magentrix-sdk'
|
|
880
947
|
|
|
881
948
|
try {
|
|
882
|
-
// Simple query
|
|
883
|
-
const
|
|
949
|
+
// Simple query - returns array of records in 'data' property
|
|
950
|
+
const result = await dataService.query(
|
|
884
951
|
'SELECT Id, Name, Email FROM Contact WHERE Status = "Active"'
|
|
885
952
|
)
|
|
886
|
-
console.log('Active contacts:',
|
|
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
|
+
})
|
|
887
959
|
} catch (error) {
|
|
888
960
|
if (error instanceof MagentrixError) {
|
|
889
961
|
console.error('Query failed:', error.message)
|
|
@@ -892,10 +964,10 @@ try {
|
|
|
892
964
|
|
|
893
965
|
try {
|
|
894
966
|
// Query with sorting
|
|
895
|
-
const
|
|
967
|
+
const result = await dataService.query(
|
|
896
968
|
'SELECT Id, Name FROM Account ORDER BY Name ASC'
|
|
897
969
|
)
|
|
898
|
-
console.log('Sorted accounts:',
|
|
970
|
+
console.log('Sorted accounts:', result.data)
|
|
899
971
|
} catch (error) {
|
|
900
972
|
if (error instanceof MagentrixError) {
|
|
901
973
|
console.error('Query failed:', error.message)
|
|
@@ -904,10 +976,44 @@ try {
|
|
|
904
976
|
|
|
905
977
|
try {
|
|
906
978
|
// Query with limit
|
|
907
|
-
const
|
|
979
|
+
const result = await dataService.query(
|
|
908
980
|
'SELECT Id, Name FROM Account LIMIT 10'
|
|
909
981
|
)
|
|
910
|
-
console.log('Recent records:',
|
|
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
|
+
}
|
|
989
|
+
|
|
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
|
+
}
|
|
1001
|
+
|
|
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
|
+
})
|
|
911
1017
|
} catch (error) {
|
|
912
1018
|
if (error instanceof MagentrixError) {
|
|
913
1019
|
console.error('Query failed:', error.message)
|
|
@@ -919,6 +1025,28 @@ try {
|
|
|
919
1025
|
|
|
920
1026
|
## Vue 3 Integration
|
|
921
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
|
+
|
|
922
1050
|
### Composable Usage
|
|
923
1051
|
|
|
924
1052
|
The SDK provides a dedicated Vue 3 composable:
|
|
@@ -946,8 +1074,8 @@ const loadAccounts = async () => {
|
|
|
946
1074
|
|
|
947
1075
|
try {
|
|
948
1076
|
// Session is automatically created when needed
|
|
949
|
-
const
|
|
950
|
-
accounts.value =
|
|
1077
|
+
const result = await dataService.query('SELECT Id, Name FROM Account')
|
|
1078
|
+
accounts.value = result.data // Extract the data array
|
|
951
1079
|
} catch (err) {
|
|
952
1080
|
if (err instanceof MagentrixError) {
|
|
953
1081
|
error.value = err.message
|
|
@@ -1130,8 +1258,8 @@ const dataService = new MagentrixClient(config)
|
|
|
1130
1258
|
// No need to call createSession()
|
|
1131
1259
|
// Just use the dataService directly
|
|
1132
1260
|
try {
|
|
1133
|
-
const
|
|
1134
|
-
console.log(data)
|
|
1261
|
+
const result = await dataService.query('SELECT Id FROM Account')
|
|
1262
|
+
console.log(result.data) // Array of account objects
|
|
1135
1263
|
} catch (error) {
|
|
1136
1264
|
if (error instanceof MagentrixError) {
|
|
1137
1265
|
console.error('Query failed:', error.message)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magentrix-corp/magentrix-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "TypeScript SDK for Magentrix APIs with dual authentication modes, automatic session management, CRUD operations, and Vue 3 integration",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|