@magentrix-corp/magentrix-sdk 1.0.0 → 1.0.1

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 +210 -24
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,50 +1,236 @@
1
- Magentrix SDK for Javascript.
1
+ # Magentrix SDK for JavaScript
2
2
 
3
- Javascript:
3
+ A standalone, framework-agnostic TypeScript library that provides a clean interface for interacting with the Magentrix REST API v3.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/magentrix-sdk.svg)](https://www.npmjs.com/package/magentrix-sdk)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ ### Core Functionality
11
+
12
+ - ✅ **Full REST API v3 support** - Complete coverage of Magentrix REST API endpoints
13
+ - ✅ **CRUD operations** - Create, Read, Update, Delete operations made simple
14
+ - ✅ **Query execution** - Execute queries using IRIS query language
15
+ - ✅ **Custom MVC actions** - Execute custom MVC actions seamlessly
16
+ - ✅ **Session management** - Built-in authentication and session handling
17
+ - ✅ **Automatic token refresh** - Handles token refresh automatically
18
+ - ✅ **IRIS data extensions** - Support for metadata and permissions
19
+
20
+ ### Developer Experience
21
+
22
+ - ✅ **TypeScript-first** - Full type definitions for enhanced IDE support
23
+ - ✅ **Promise-based API** - Modern async/await syntax
24
+ - ✅ **Vue.js 3 plugin** - Seamless integration with Vue.js applications
25
+ - ✅ **Composable pattern** - Vue composables for reactive data management
26
+ - ✅ **Comprehensive error handling** - Robust error handling with custom callbacks
27
+ - ✅ **Zero external dependencies** - Only uses native Fetch API
28
+
29
+ ### Package Quality
30
+
31
+ - ✅ **Modern build system** - Built with Rollup for optimal bundling
32
+ - ✅ **Multiple module formats** - CommonJS and ES Module outputs
33
+ - ✅ **Tree-shakeable** - Import only what you need
34
+ - ✅ **Source maps included** - Easy debugging in development
35
+ - ✅ **Full documentation** - Complete examples and API reference
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ npm install magentrix-sdk
41
+ ```
42
+
43
+ or
44
+
45
+ ```bash
46
+ yarn add magentrix-sdk
47
+ ```
48
+
49
+ or
50
+
51
+ ```bash
52
+ pnpm add magentrix-sdk
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ### Vanilla JavaScript/TypeScript
58
+
59
+ ```javascript
5
60
  import { MagentrixClient } from 'magentrix-sdk'
6
61
 
7
62
  const client = new MagentrixClient({
8
- baseUrl: 'https://xyz.com',
63
+ baseUrl: '{your-portal-domain}',
9
64
  token: '',
10
- refreshToken: 'xyz',
65
+ refreshToken: '{refresh-token}',
11
66
  antiForgeryToken: '',
12
- onSessionExpired: () => Promise<void> | void
13
- onError?: (error: any) => void
67
+ onSessionExpired: () => {
68
+ // Handle session expiration
69
+ console.log('Session expired, redirecting to login...')
70
+ },
71
+ onError: (error) => {
72
+ // Handle errors globally
73
+ console.error('API Error:', error)
74
+ }
14
75
  })
15
76
 
16
- client.createSession().then(si => {
17
- console.log(si.token)
18
- client.retrieve('xyz').then(r => console.log(r))
19
- })
77
+ // Create a session and retrieve data
78
+ async function fetchData() {
79
+ const sessionInfo = await client.createSession()
80
+ console.log('Session Token:', sessionInfo.token)
81
+
82
+ const data = await client.retrieve('xyz')
83
+ console.log('Retrieved Data:', data)
84
+ }
20
85
 
86
+ fetchData()
87
+ ```
21
88
 
22
- VUE JS:
89
+ ### Vue.js 3
23
90
 
91
+ ```vue
24
92
  <script setup>
25
- import { onMounted } from 'vue'
26
- import { MagentrixClient } from 'magentrix-sdk/vue'
93
+ import { ref, onMounted } from 'vue'
94
+ import { useMagentrixSdk } from 'magentrix-sdk/vue'
27
95
 
28
96
  const client = useMagentrixSdk({
29
- baseUrl: 'https://xyz.com',
97
+ baseUrl: 'https://your-portal.magentrix.com',
30
98
  token: '',
31
- refreshToken: 'xyz',
99
+ refreshToken: 'your-refresh-token',
32
100
  antiForgeryToken: '',
33
- onSessionExpired: () => Promise<void> | void
34
- onError?: (error: any) => void
101
+ onSessionExpired: () => {
102
+ // Handle session expiration
103
+ console.log('Session expired')
104
+ },
105
+ onError: (error) => {
106
+ // Handle errors
107
+ console.error('Error:', error)
108
+ }
35
109
  })
36
110
 
37
111
  const model = ref()
38
112
 
39
113
  onMounted(async () => {
40
- const si = await client.createSession()
41
- console.log(si.token)
42
- const r = await client.retrieve('xyz')
43
- console.log(r)
44
- model.value = r
114
+ const sessionInfo = await client.createSession()
115
+ console.log('Session Token:', sessionInfo.token)
116
+
117
+ const data = await client.retrieve('xyz')
118
+ console.log('Retrieved Data:', data)
119
+ model.value = data
45
120
  })
46
121
  </script>
47
122
 
48
123
  <template>
49
- <p>{{ model.Id }}</p>
50
- </template>
124
+ <div>
125
+ <p v-if="model">{{ model.Id }}</p>
126
+ </div>
127
+ </template>
128
+ ```
129
+
130
+ ## API Reference
131
+
132
+ ### Configuration Options
133
+
134
+ | Option | Type | Required | Description |
135
+ |--------|------|----------|-------------|
136
+ | `baseUrl` | `string` | Yes | Your Magentrix portal domain |
137
+ | `token` | `string` | No | Initial authentication token |
138
+ | `refreshToken` | `string` | No | Token used for refreshing sessions |
139
+ | `antiForgeryToken` | `string` | No | Anti-forgery token for security |
140
+ | `onSessionExpired` | `() => Promise<void> \| void` | No | Callback when session expires |
141
+ | `onError` | `(error: any) => void` | No | Global error handler |
142
+
143
+ ### Core Methods
144
+
145
+ #### `createSession()`
146
+ Creates a new session and returns session information.
147
+
148
+ ```javascript
149
+ const sessionInfo = await client.createSession()
150
+ console.log(sessionInfo.token)
151
+ ```
152
+
153
+ #### `retrieve(id: string)`
154
+ Retrieves a record by ID.
155
+
156
+ ```javascript
157
+ const record = await client.retrieve('record-id')
158
+ ```
159
+
160
+ #### `execute(action: string, params?: object)`
161
+ Executes a custom MVC action.
162
+
163
+ ```javascript
164
+ const result = await client.execute('customAction', { param1: 'value' })
165
+ ```
166
+
167
+ ## Examples
168
+
169
+ ### CRUD Operations
170
+
171
+ ```javascript
172
+ // Create
173
+ const newRecord = await client.create({
174
+ Name: 'New Record',
175
+ Description: 'Record description'
176
+ })
177
+
178
+ // Read
179
+ const record = await client.retrieve('record-id')
180
+
181
+ // Update
182
+ const updated = await client.update('record-id', {
183
+ Name: 'Updated Name'
184
+ })
185
+
186
+ // Delete
187
+ await client.delete('record-id')
188
+ ```
189
+
190
+ ### Query Execution
191
+
192
+ ```javascript
193
+ const results = await client.query({
194
+ entity: 'Account',
195
+ filter: 'Status eq "Active"',
196
+ select: ['Id', 'Name', 'Email']
197
+ })
198
+ ```
199
+
200
+ ## TypeScript Support
201
+
202
+ The SDK is written in TypeScript and provides full type definitions out of the box:
203
+
204
+ ```typescript
205
+ import { MagentrixClient, SessionInfo } from 'magentrix-sdk'
206
+
207
+ const client: MagentrixClient = new MagentrixClient({
208
+ baseUrl: 'https://your-portal.magentrix.com',
209
+ refreshToken: 'your-token'
210
+ })
211
+
212
+ const sessionInfo: SessionInfo = await client.createSession()
213
+ ```
214
+
215
+ ## Browser Support
216
+
217
+ The SDK uses the native Fetch API and supports all modern browsers:
218
+
219
+ - Chrome (latest)
220
+ - Firefox (latest)
221
+ - Safari (latest)
222
+ - Edge (latest)
223
+
224
+ For older browsers, you may need to include a fetch polyfill.
225
+
226
+ ## Contributing
227
+
228
+ Contributions are welcome! Please feel free to submit a Pull Request.
229
+
230
+ ## License
231
+
232
+ MIT
233
+
234
+ ## Support
235
+
236
+ For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/your-org/magentrix-sdk).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magentrix-corp/magentrix-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",