@magentrix-corp/magentrix-sdk 1.0.9 → 1.1.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 (2) hide show
  1. package/README.md +56 -37
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -24,11 +24,11 @@ npm install @magentrix-corp/magentrix-sdk
24
24
  ### JavaScript/TypeScript
25
25
 
26
26
  ```typescript
27
- import { MagentrixClient } from '@magentrix-corp/magentrix-sdk'
27
+ import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
28
28
 
29
- const client = new MagentrixClient({
30
- baseUrl: 'https://your-instance.magentrix.com',
31
- refreshToken: 'your-refresh-token',
29
+ const config: MagentrixConfig = {
30
+ baseUrl: 'https://dev.magentrix.com',
31
+ refreshToken: '<your-refresh-token>',
32
32
  isDevMode: true, // Use token-based auth
33
33
  onSessionExpired: async () => {
34
34
  console.log('Session expired!')
@@ -36,7 +36,9 @@ const client = new MagentrixClient({
36
36
  onError: (error) => {
37
37
  console.error('API Error:', error)
38
38
  }
39
- })
39
+ }
40
+
41
+ const client = new MagentrixClient(config)
40
42
 
41
43
  // Create a session
42
44
  const session = await client.createSession()
@@ -54,31 +56,34 @@ console.log(record)
54
56
  ### Vue 3
55
57
 
56
58
  ```vue
57
- <script setup>
59
+ <script setup lang="ts">
58
60
  import { ref, onMounted } from 'vue'
61
+ import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
59
62
  import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
60
63
 
61
- const client = useMagentrixSdk({
62
- baseUrl: 'https://your-instance.magentrix.com',
63
- refreshToken: 'your-refresh-token',
64
+ const config: MagentrixConfig = {
65
+ baseUrl: 'https://dev.magentrix.com',
66
+ refreshToken: '<your-refresh-token>',
64
67
  isDevMode: true,
65
- onError: (error) => {
68
+ onError: (error: any) => {
66
69
  console.error('API Error:', error)
67
70
  }
68
- })
71
+ }
69
72
 
70
- const account = ref(null)
73
+ const client = useMagentrixSdk().getInstance(config)
74
+ const account = ref<any>(null)
71
75
 
72
76
  onMounted(async () => {
73
77
  await client.createSession()
74
- account.value = await client.retrieve('account-id-123')
78
+ account.value = (await client.retrieve('006000000LJIxF70000')).record
79
+ console.log(account.value)
75
80
  })
76
81
  </script>
77
82
 
78
83
  <template>
79
84
  <div v-if="account">
80
85
  <h1>{{ account.Name }}</h1>
81
- <p>ID: {{ account.Id }}</p>
86
+ <p>{{ account.Email }}</p>
82
87
  </div>
83
88
  </template>
84
89
  ```
@@ -110,11 +115,15 @@ The SDK supports two authentication modes controlled by the `isDevMode` flag:
110
115
  - Requires `refreshToken` in configuration
111
116
 
112
117
  ```typescript
113
- const client = new MagentrixClient({
114
- baseUrl: 'https://your-instance.magentrix.com',
115
- refreshToken: 'your-refresh-token',
118
+ import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
119
+
120
+ const config: MagentrixConfig = {
121
+ baseUrl: 'https://dev.magentrix.com',
122
+ refreshToken: '<your-refresh-token>',
116
123
  isDevMode: true
117
- })
124
+ }
125
+
126
+ const client = new MagentrixClient(config)
118
127
  ```
119
128
 
120
129
  ### Production Mode (`isDevMode: false` or not set)
@@ -129,10 +138,14 @@ const client = new MagentrixClient({
129
138
  - No `refreshToken` required
130
139
 
131
140
  ```typescript
132
- const client = new MagentrixClient({
141
+ import { MagentrixClient, type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
142
+
143
+ const config: MagentrixConfig = {
133
144
  baseUrl: 'https://your-instance.magentrix.com',
134
145
  isDevMode: false // or omit this property
135
- })
146
+ }
147
+
148
+ const client = new MagentrixClient(config)
136
149
  ```
137
150
 
138
151
  ## API Reference
@@ -491,19 +504,21 @@ const recentRecords = await client.query(
491
504
  The SDK provides a dedicated Vue 3 composable:
492
505
 
493
506
  ```vue
494
- <script setup>
507
+ <script setup lang="ts">
495
508
  import { ref, onMounted } from 'vue'
509
+ import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
496
510
  import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
497
511
 
498
- const client = useMagentrixSdk({
499
- baseUrl: 'https://your-instance.magentrix.com',
500
- refreshToken: 'your-refresh-token',
512
+ const config: MagentrixConfig = {
513
+ baseUrl: 'https://dev.magentrix.com',
514
+ refreshToken: '<your-refresh-token>',
501
515
  isDevMode: true
502
- })
516
+ }
503
517
 
504
- const accounts = ref([])
518
+ const client = useMagentrixSdk().getInstance(config)
519
+ const accounts = ref<any[]>([])
505
520
  const loading = ref(false)
506
- const error = ref(null)
521
+ const error = ref<string | null>(null)
507
522
 
508
523
  const loadAccounts = async () => {
509
524
  loading.value = true
@@ -513,7 +528,7 @@ const loadAccounts = async () => {
513
528
  await client.createSession()
514
529
  const results = await client.query('SELECT Id, Name FROM Account')
515
530
  accounts.value = results
516
- } catch (err) {
531
+ } catch (err: any) {
517
532
  error.value = err.message
518
533
  } finally {
519
534
  loading.value = false
@@ -541,18 +556,22 @@ onMounted(() => {
541
556
  ### Reactive CRUD Operations
542
557
 
543
558
  ```vue
544
- <script setup>
559
+ <script setup lang="ts">
545
560
  import { ref } from 'vue'
561
+ import { type MagentrixConfig } from '@magentrix-corp/magentrix-sdk'
546
562
  import { useMagentrixSdk } from '@magentrix-corp/magentrix-sdk/vue'
547
563
 
548
- const client = useMagentrixSdk({
549
- baseUrl: 'https://your-instance.magentrix.com',
564
+ const config: MagentrixConfig = {
565
+ baseUrl: 'https://dev.magentrix.com',
566
+ refreshToken: '<your-refresh-token>',
550
567
  isDevMode: true
551
- })
568
+ }
569
+
570
+ const client = useMagentrixSdk().getInstance(config)
552
571
 
553
572
  const formData = ref({
554
- Name: '',
555
- Email: '',
573
+ Name: 'Company Name',
574
+ Type: 'Customer',
556
575
  Status: 'Active'
557
576
  })
558
577
 
@@ -562,13 +581,13 @@ const createAccount = async () => {
562
581
  console.log('Created:', created)
563
582
 
564
583
  // Reset form
565
- formData.value = { Name: '', Email: '', Status: 'Active' }
584
+ formData.value = { Name: '', Type: '', Status: 'Active' }
566
585
  } catch (error) {
567
586
  console.error('Failed to create account:', error)
568
587
  }
569
588
  }
570
589
 
571
- const updateAccount = async (id) => {
590
+ const updateAccount = async (id: string) => {
572
591
  try {
573
592
  await client.edit('Account', {
574
593
  Id: id,
@@ -580,7 +599,7 @@ const updateAccount = async (id) => {
580
599
  }
581
600
  }
582
601
 
583
- const deleteAccount = async (id) => {
602
+ const deleteAccount = async (id: string) => {
584
603
  try {
585
604
  await client.delete('Account', id)
586
605
  console.log('Deleted successfully')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magentrix-corp/magentrix-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
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",