tradly 1.1.98 → 1.2.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.
@@ -1,22 +1,26 @@
1
- import {DEV, PRO, SANDBOX } from "../Constants/PathConstant.js"
1
+ import { DEV, PRO, SANDBOX } from "../Constants/PathConstant.js";
2
2
 
3
3
  export var EVN = {
4
- DEV:'development',
5
- PRO: 'production',
6
- SANDBOX: 'sandbox',
7
- }
8
- export var UserParameter = {data:{}}
4
+ DEV: "development",
5
+ PRO: "production",
6
+ SANDBOX: "sandbox",
7
+ };
8
+ export var UserParameter = { data: {} };
9
9
  export default function Environment(evn) {
10
- switch(evn) {
11
- case EVN.DEV : return DEV
12
- case EVN.SANDBOX : return SANDBOX
13
- case EVN.PRO : return PRO
14
- default : return DEV
15
- }
10
+ switch (evn) {
11
+ case EVN.DEV:
12
+ return DEV;
13
+ case EVN.SANDBOX:
14
+ return SANDBOX;
15
+ case EVN.PRO:
16
+ return PRO;
17
+ default:
18
+ return PRO;
19
+ }
16
20
  }
17
21
 
18
22
  export var ImageConfig = {
19
- signedUrl:'',
20
- mime:'',
21
- blob_body:''
22
- }
23
+ signedUrl: "",
24
+ mime: "",
25
+ blob_body: "",
26
+ };
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # Tradly Platform JS SDK (Beluga)
2
-
3
1
  <p align="center">
4
2
  <a href="https://tradly.app">
5
3
  <h1 align="center"> Tradly Platform JS SDK </h1>
@@ -31,7 +29,7 @@ to launch marketplaces, Ecosystem for SaaS and commerce apps.
31
29
  ## Installation
32
30
 
33
31
  ```bash
34
- npm install beluga
32
+ npm install tradly
35
33
  ```
36
34
 
37
35
  ### Optional: Install with Auth Package
@@ -48,11 +46,11 @@ npm install tradly @tradly/auth
48
46
 
49
47
  ### Option 1: With @tradly/auth (Recommended)
50
48
 
51
- **Simplest approach - just initialize auth, then use beluga directly:**
49
+ **Simplest approach - just initialize auth, then use tradly sdk directly:**
52
50
 
53
51
  ```javascript
54
52
  import { initializeAuth, emailLogin } from "@tradly/auth";
55
- import TradlySDK from "beluga";
53
+ import TradlySDK from "tradly";
56
54
 
57
55
  // Step 1: Initialize auth (once at app start)
58
56
  initializeAuth("beauty.tradly.co", "production");
@@ -60,7 +58,7 @@ initializeAuth("beauty.tradly.co", "production");
60
58
  // Step 2: Login via auth (keys automatically stored)
61
59
  await emailLogin("user@example.com", "password");
62
60
 
63
- // Step 3: Use beluga APIs directly (keys auto-injected!)
61
+ // Step 3: Use tradly APIs directly (keys auto-injected!)
64
62
  const [error, response] = await TradlySDK.app.getListings({
65
63
  bodyParam: {},
66
64
  // authKey automatically from auth package!
@@ -79,9 +77,9 @@ const [error, response] = await TradlySDK.app.getListings({
79
77
  ### Option 2: Standalone (Without Auth Package)
80
78
 
81
79
  ```javascript
82
- import TradlySDK from "beluga";
80
+ import TradlySDK from "tradly";
83
81
 
84
- // Initialize beluga
82
+ // Initialize tradly
85
83
  await TradlySDK.init_v2.config({
86
84
  domain: "beauty.tradly.co",
87
85
  env: "production",
@@ -100,13 +98,13 @@ const [error, response] = await TradlySDK.app.getListings({
100
98
 
101
99
  ```javascript
102
100
  import { initializeAuth, emailLogin } from "@tradly/auth";
103
- import TradlySDK from "beluga";
101
+ import TradlySDK from "tradly";
104
102
 
105
103
  // Initialize auth
106
104
  initializeAuth("beauty.tradly.co", "production");
107
105
  await emailLogin("user@example.com", "password");
108
106
 
109
- // Initialize beluga (uses auth's PK key automatically)
107
+ // Initialize tradly (uses auth's PK key automatically)
110
108
  await TradlySDK.init_v2.config({
111
109
  domain: "beauty.tradly.co",
112
110
  env: "production",
@@ -125,7 +123,7 @@ const [error, response] = await TradlySDK.app.getListings({
125
123
  ### Using InitV2 (Recommended)
126
124
 
127
125
  ```javascript
128
- import TradlySDK from "beluga";
126
+ import TradlySDK from "tradly";
129
127
 
130
128
  await TradlySDK.init_v2.config({
131
129
  domain: "beauty.tradly.co", // Required
@@ -141,7 +139,7 @@ automatically use auth's cached PK key (no duplicate API call).
141
139
  ### Using Legacy Init (Deprecated)
142
140
 
143
141
  ```javascript
144
- import TradlySDK from "beluga";
142
+ import TradlySDK from "tradly";
145
143
 
146
144
  await TradlySDK.init.config({
147
145
  token: "your-pk-key", // PK key
@@ -154,7 +152,7 @@ await TradlySDK.init.config({
154
152
 
155
153
  ## Integration with @tradly/auth
156
154
 
157
- Beluga automatically integrates with `@tradly/auth` when available:
155
+ tradly automatically integrates with `@tradly/auth` when available:
158
156
 
159
157
  ### Automatic Features
160
158
 
@@ -173,7 +171,7 @@ Beluga automatically integrates with `@tradly/auth` when available:
173
171
  - Syncs environment from auth config if `APPCONSTANT.ENVIRONMENT` is empty
174
172
 
175
173
  4. **Base URL Sync:**
176
- - Uses auth's `baseUrl` if available (preferred over beluga's Environment
174
+ - Uses auth's `baseUrl` if available (preferred over tradly's Environment
177
175
  function)
178
176
 
179
177
  ### Backward Compatibility
@@ -695,7 +693,7 @@ auto-injected.
695
693
  ### Example 1: Get Listings
696
694
 
697
695
  ```javascript
698
- import TradlySDK from "beluga";
696
+ import TradlySDK from "tradly";
699
697
 
700
698
  // With auth package (keys auto-injected)
701
699
  const [error, response] = await TradlySDK.app.getListings({
@@ -842,7 +840,7 @@ const [error, response] = await TradlySDK.app.getListings({
842
840
 
843
841
  ## Environment Variables
844
842
 
845
- Beluga supports these environments:
843
+ Tradly sdk supports these environments:
846
844
 
847
845
  - `production` - Production API (https://api.tradly.app)
848
846
  - `development` - Development API (https://api.dev.tradly.app)
@@ -852,7 +850,7 @@ Beluga supports these environments:
852
850
 
853
851
  ## Best Practices
854
852
 
855
- 1. **Initialize Once:** Initialize auth or beluga once at app startup
853
+ 1. **Initialize Once:** Initialize auth or tradly once at app startup
856
854
  2. **Use Auth Package:** For automatic key management, use `@tradly/auth`
857
855
  3. **Error Handling:** Always check for errors before using response
858
856
  4. **TypeScript:** Use TypeScript for better type safety
@@ -862,10 +860,10 @@ Beluga supports these environments:
862
860
 
863
861
  ## TypeScript Support
864
862
 
865
- While beluga is written in JavaScript, it works with TypeScript:
863
+ While tradly is written in JavaScript, it works with TypeScript:
866
864
 
867
865
  ```typescript
868
- import TradlySDK from "beluga";
866
+ import TradlySDK from "tradly";
869
867
 
870
868
  const [error, response]: [any, any] = await TradlySDK.app.getListings({
871
869
  bodyParam: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tradly",
3
- "version": "1.1.98",
3
+ "version": "1.2.0",
4
4
  "description": "Tradly JS SDK",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,290 +0,0 @@
1
- # Beluga-Auth Integration Implementation
2
-
3
- ## Summary
4
-
5
- This document describes the implementation of automatic integration between
6
- `beluga` and `@tradly/auth` packages. After these enhancements, `beluga` will
7
- automatically detect and use `@tradly/auth` when available, without requiring
8
- any new packages.
9
-
10
- ---
11
-
12
- ## Changes Made
13
-
14
- ### 1. Created AuthHelper.js
15
-
16
- **File:** `beluga/Helper/AuthHelper.js`
17
-
18
- **Purpose:** Provides reusable functions for integrating with `@tradly/auth`
19
- package (optional dependency).
20
-
21
- **Key Functions:**
22
-
23
- - `getAuthKeyFromAuth()` - Gets auth key from auth package
24
- - `getPKKeyFromAuth()` - Gets PK key from auth package
25
- - `isAuthInitialized()` - Checks if auth package is initialized
26
- - `getAuthConfig()` - Gets auth configuration
27
- - `getCachedPKKeyFromAuth(domain, env)` - Gets cached PK key data
28
- - `enrichParamsWithAuth(params)` - Enriches params with auth key
29
-
30
- **Features:**
31
-
32
- - ✅ Safely handles cases where `@tradly/auth` is not installed
33
- - ✅ Uses ES module dynamic import
34
- - ✅ Non-blocking eager loading
35
- - ✅ Graceful fallback if package unavailable
36
-
37
- ---
38
-
39
- ### 2. Enhanced NetworkManager.js
40
-
41
- **File:** `beluga/NetworkManager/NetworkManager.js`
42
-
43
- **Changes:**
44
-
45
- 1. **Added import for AuthHelper:**
46
- ```javascript
47
- import {
48
- getAuthKeyFromAuth,
49
- getPKKeyFromAuth,
50
- } from "../Helper/AuthHelper.js";
51
- ```
52
-
53
- 2. **Auto-inject PK key from auth:**
54
- - If `APPCONSTANT.TOKEN` is empty, tries to get PK key from auth package
55
- - Caches the PK key in `APPCONSTANT.TOKEN` for future use
56
-
57
- 3. **Auto-inject auth key from auth:**
58
- - If `config.authKey` is not provided, tries to get auth key from auth package
59
- - Only injects if auth package is available and initialized
60
-
61
- **Benefits:**
62
-
63
- - ✅ All beluga API calls automatically get keys from auth
64
- - ✅ No changes needed in individual methods
65
- - ✅ Works immediately after enhancement
66
- - ✅ Backward compatible (works without auth package)
67
-
68
- ---
69
-
70
- ### 3. Enhanced InitV2.js
71
-
72
- **File:** `beluga/Roots/InitV2.js`
73
-
74
- **Changes:**
75
-
76
- 1. **Added import for AuthHelper:**
77
- ```javascript
78
- import {
79
- isAuthInitialized,
80
- getAuthConfig,
81
- getCachedPKKeyFromAuth,
82
- } from "../Helper/AuthHelper.js";
83
- ```
84
-
85
- 2. **Check auth package before fetching PK key:**
86
- - Checks if auth package is initialized
87
- - If initialized and domain/env match, uses auth's cached PK key
88
- - Skips API call to fetch PK key if auth already has it
89
- - Syncs `APPCONSTANT` with auth's configuration
90
-
91
- **Benefits:**
92
-
93
- - ✅ Avoids duplicate PK key fetching
94
- - ✅ Consistent configuration
95
- - ✅ Single source of truth (auth)
96
- - ✅ Faster initialization
97
-
98
- ---
99
-
100
- ## How It Works
101
-
102
- ### Initialization Flow
103
-
104
- ```javascript
105
- // Step 1: Initialize auth package
106
- import { initializeAuth } from "@tradly/auth";
107
- initializeAuth("beauty.tradly.co", "production");
108
- // Auth package automatically fetches and caches PK key
109
-
110
- // Step 2: Initialize beluga (optional, but recommended)
111
- import TradlySDK from "beluga";
112
- await TradlySDK.init_v2.config({
113
- domain: "beauty.tradly.co",
114
- env: "production",
115
- });
116
- // InitV2 will detect auth is initialized and use its PK key
117
- // No duplicate API call needed!
118
- ```
119
-
120
- ### API Call Flow
121
-
122
- ```javascript
123
- // Step 1: User logs in via auth package
124
- import { emailLogin } from "@tradly/auth";
125
- await emailLogin("user@example.com", "password");
126
- // Auth key automatically stored by auth package
127
-
128
- // Step 2: Use beluga APIs (keys auto-injected)
129
- import TradlySDK from "beluga";
130
- const [error, response] = await TradlySDK.app.getListings({
131
- bodyParam: {},
132
- // authKey not needed - automatically from auth package!
133
- });
134
- ```
135
-
136
- ### NetworkManager Auto-Injection
137
-
138
- When `NetworkManager.networkCall()` is called:
139
-
140
- 1. **PK Key Injection:**
141
- - Checks if `APPCONSTANT.TOKEN` exists
142
- - If not, tries to get from auth package
143
- - Caches it in `APPCONSTANT.TOKEN`
144
-
145
- 2. **Auth Key Injection:**
146
- - Checks if `config.authKey` is provided
147
- - If not, tries to get from auth package
148
- - Adds to headers if available
149
-
150
- ---
151
-
152
- ## Backward Compatibility
153
-
154
- ### Scenario 1: Auth Package NOT Installed
155
-
156
- ```javascript
157
- // Beluga works exactly as before
158
- import TradlySDK from "beluga";
159
- await TradlySDK.init_v2.config({
160
- domain: "beauty.tradly.co",
161
- env: "production",
162
- });
163
-
164
- // Manual authKey passing still works
165
- const [error, response] = await TradlySDK.app.getListings({
166
- authKey: "manual-key",
167
- bodyParam: {},
168
- });
169
- ```
170
-
171
- **Result:** ✅ Works exactly as before, no errors
172
-
173
- ---
174
-
175
- ### Scenario 2: Auth Package Installed but NOT Initialized
176
-
177
- ```javascript
178
- // Auth package installed but not initialized
179
- import TradlySDK from "beluga";
180
- await TradlySDK.init_v2.config({
181
- domain: "beauty.tradly.co",
182
- env: "production",
183
- });
184
-
185
- // Beluga will fetch PK key normally (no auth sync)
186
- const [error, response] = await TradlySDK.app.getListings({
187
- authKey: "manual-key", // Still need manual key
188
- bodyParam: {},
189
- });
190
- ```
191
-
192
- **Result:** ✅ Works as before, manual keys still work
193
-
194
- ---
195
-
196
- ### Scenario 3: Auth Package Installed AND Initialized
197
-
198
- ```javascript
199
- // Initialize auth first
200
- import { initializeAuth, emailLogin } from "@tradly/auth";
201
- initializeAuth("beauty.tradly.co", "production");
202
- await emailLogin("user@example.com", "password");
203
-
204
- // Initialize beluga (uses auth's PK key)
205
- import TradlySDK from "beluga";
206
- await TradlySDK.init_v2.config({
207
- domain: "beauty.tradly.co",
208
- env: "production",
209
- });
210
- // Uses auth's cached PK key - no API call!
211
-
212
- // Use beluga APIs (keys auto-injected)
213
- const [error, response] = await TradlySDK.app.getListings({
214
- bodyParam: {},
215
- // authKey automatically from auth package!
216
- });
217
- ```
218
-
219
- **Result:** ✅ Automatic key injection, seamless integration
220
-
221
- ---
222
-
223
- ## Testing Checklist
224
-
225
- ### Test Case 1: Without Auth Package
226
-
227
- - [ ] Install beluga without `@tradly/auth`
228
- - [ ] Initialize beluga normally
229
- - [ ] Make API calls with manual authKey
230
- - [ ] Verify no errors occur
231
- - [ ] Verify API calls work as before
232
-
233
- ### Test Case 2: With Auth Package (Not Initialized)
234
-
235
- - [ ] Install both `beluga` and `@tradly/auth`
236
- - [ ] Don't initialize auth
237
- - [ ] Initialize beluga normally
238
- - [ ] Make API calls with manual authKey
239
- - [ ] Verify no errors occur
240
- - [ ] Verify beluga works normally
241
-
242
- ### Test Case 3: With Auth Package (Initialized)
243
-
244
- - [ ] Install both packages
245
- - [ ] Initialize auth first
246
- - [ ] Login via auth package
247
- - [ ] Initialize beluga (should use auth's PK key)
248
- - [ ] Make API calls without manual authKey
249
- - [ ] Verify keys are auto-injected
250
- - [ ] Verify API calls work correctly
251
-
252
- ### Test Case 4: Manual Override
253
-
254
- - [ ] Initialize auth and login
255
- - [ ] Initialize beluga
256
- - [ ] Make API call with manual authKey (should override)
257
- - [ ] Verify manual key is used instead of auto-injected
258
-
259
- ---
260
-
261
- ## Files Modified
262
-
263
- 1. ✅ `beluga/Helper/AuthHelper.js` - **NEW FILE**
264
- 2. ✅ `beluga/NetworkManager/NetworkManager.js` - **ENHANCED**
265
- 3. ✅ `beluga/Roots/InitV2.js` - **ENHANCED**
266
-
267
- ---
268
-
269
- ## Next Steps
270
-
271
- 1. **Testing:** Test all scenarios to ensure backward compatibility
272
- 2. **Documentation:** Update beluga README with integration examples
273
- 3. **TypeScript Definitions:** Add TypeScript definitions (optional)
274
- 4. **Performance:** Monitor and optimize if needed
275
-
276
- ---
277
-
278
- ## Benefits Summary
279
-
280
- ✅ **No Breaking Changes:** All existing code continues to work
281
- ✅ **Automatic Integration:** Keys auto-injected when auth is used
282
- ✅ **Backward Compatible:** Works without auth package
283
- ✅ **No New Package:** Keeps both packages separate
284
- ✅ **Seamless Experience:** Users can use both packages together
285
- ✅ **Performance:** Avoids duplicate PK key fetching
286
-
287
- ---
288
-
289
- This implementation follows the recommendations in `UNIFICATION_ANALYSIS.md`
290
- and provides seamless integration between `beluga` and `@tradly/auth` packages.
@@ -1,293 +0,0 @@
1
- # Beluga-Auth Integration Usage Scenarios
2
-
3
- ## Scenario 1: Initialize Auth Only (Recommended - Simplest)
4
-
5
- **Question:** Can I just initialize auth and use beluga SDK APIs directly?
6
-
7
- **Answer:** ✅ **YES!** This will work after the enhancements.
8
-
9
- ### Usage:
10
-
11
- ```javascript
12
- // Step 1: Initialize auth only
13
- import { initializeAuth, emailLogin } from "@tradly/auth";
14
- initializeAuth("beauty.tradly.co", "production");
15
-
16
- // Step 2: Login via auth
17
- await emailLogin("user@example.com", "password");
18
- // Auth key automatically stored
19
-
20
- // Step 3: Use beluga APIs directly (NO init_v2.config() needed!)
21
- import TradlySDK from "beluga";
22
-
23
- // Keys are automatically injected:
24
- // - PK key from auth's cache
25
- // - Auth key from auth's storage
26
- // - Environment from auth's config
27
- // - Base URL from auth's config
28
- const [error, response] = await TradlySDK.app.getListings({
29
- bodyParam: {},
30
- // No authKey needed - automatically from auth!
31
- });
32
-
33
- const [error2, response2] = await TradlySDK.app.getAccounts({
34
- bodyParam: {},
35
- // Keys auto-injected!
36
- });
37
- ```
38
-
39
- ### What Happens Automatically:
40
-
41
- 1. **PK Key:** NetworkManager gets PK key from auth's cache
42
- 2. **Auth Key:** NetworkManager gets auth key from auth's storage
43
- 3. **Environment:** NetworkManager syncs environment from auth config
44
- 4. **Base URL:** NetworkManager uses auth's baseUrl if available
45
-
46
- ### Benefits:
47
-
48
- - ✅ Simplest usage - only initialize auth
49
- - ✅ No need to call `init_v2.config()`
50
- - ✅ All keys automatically injected
51
- - ✅ Consistent configuration
52
-
53
- ---
54
-
55
- ## Scenario 2: Initialize Both (Optional - For Explicit Control)
56
-
57
- **Usage:**
58
-
59
- ```javascript
60
- // Step 1: Initialize auth
61
- import { initializeAuth, emailLogin } from "@tradly/auth";
62
- initializeAuth("beauty.tradly.co", "production");
63
- await emailLogin("user@example.com", "password");
64
-
65
- // Step 2: Initialize beluga (optional - uses auth's PK key)
66
- import TradlySDK from "beluga";
67
- await TradlySDK.init_v2.config({
68
- domain: "beauty.tradly.co",
69
- env: "production",
70
- });
71
- // Uses auth's cached PK key - no duplicate API call!
72
-
73
- // Step 3: Use beluga APIs
74
- const [error, response] = await TradlySDK.app.getListings({
75
- bodyParam: {},
76
- });
77
- ```
78
-
79
- ### Benefits:
80
-
81
- - ✅ Explicit initialization
82
- - ✅ Beluga's cache is populated
83
- - ✅ Still uses auth's keys automatically
84
-
85
- ---
86
-
87
- ## Scenario 3: Without Auth Package (Backward Compatible)
88
-
89
- **Usage:**
90
-
91
- ```javascript
92
- // Only beluga, no auth package
93
- import TradlySDK from "beluga";
94
-
95
- // Initialize beluga normally
96
- await TradlySDK.init_v2.config({
97
- domain: "beauty.tradly.co",
98
- env: "production",
99
- });
100
-
101
- // Use beluga APIs with manual authKey
102
- const [error, response] = await TradlySDK.app.getListings({
103
- authKey: "manual-key",
104
- bodyParam: {},
105
- });
106
- ```
107
-
108
- ### Result:
109
-
110
- - ✅ Works exactly as before
111
- - ✅ No errors
112
- - ✅ Manual key passing still works
113
-
114
- ---
115
-
116
- ## Scenario 4: Auth Installed but Not Initialized
117
-
118
- **Usage:**
119
-
120
- ```javascript
121
- // Auth package installed but not initialized
122
- import TradlySDK from "beluga";
123
-
124
- // Initialize beluga normally
125
- await TradlySDK.init_v2.config({
126
- domain: "beauty.tradly.co",
127
- env: "production",
128
- });
129
-
130
- // Beluga will fetch PK key normally (no auth sync)
131
- const [error, response] = await TradlySDK.app.getListings({
132
- authKey: "manual-key", // Still need manual key
133
- bodyParam: {},
134
- });
135
- ```
136
-
137
- ### Result:
138
-
139
- - ✅ Works as before
140
- - ✅ Manual keys still work
141
- - ✅ No errors thrown
142
-
143
- ---
144
-
145
- ## Complete Example: Auth Only Initialization
146
-
147
- ```javascript
148
- // app.js or main entry point
149
- import { initializeAuth } from "@tradly/auth";
150
-
151
- // Initialize once at app start
152
- initializeAuth("beauty.tradly.co", "production");
153
-
154
- // ============================================
155
- // In your login component
156
- // ============================================
157
- import { emailLogin } from "@tradly/auth";
158
-
159
- async function handleLogin(email, password) {
160
- const response = await emailLogin(email, password);
161
- if (response.status) {
162
- // User logged in, auth key stored automatically
163
- console.log("Login successful!");
164
- }
165
- }
166
-
167
- // ============================================
168
- // In your listings component
169
- // ============================================
170
- import TradlySDK from "beluga";
171
-
172
- async function loadListings() {
173
- // No initialization needed!
174
- // Keys automatically injected from auth package
175
- const [error, response] = await TradlySDK.app.getListings({
176
- bodyParam: {
177
- page: 1,
178
- per_page: 20,
179
- },
180
- // authKey automatically from auth package!
181
- });
182
-
183
- if (error) {
184
- console.error("Error:", error);
185
- } else {
186
- console.log("Listings:", response.data);
187
- }
188
- }
189
-
190
- // ============================================
191
- // In your orders component
192
- // ============================================
193
- async function loadOrders() {
194
- // Same - keys auto-injected
195
- const [error, response] = await TradlySDK.app.getOrders({
196
- bodyParam: {},
197
- // No authKey needed!
198
- });
199
- }
200
- ```
201
-
202
- ---
203
-
204
- ## What Gets Auto-Injected
205
-
206
- When you call any beluga API method, NetworkManager automatically:
207
-
208
- 1. **Checks for PK Key:**
209
-
210
- - If `APPCONSTANT.TOKEN` is empty → Gets from auth package
211
- - Caches it in `APPCONSTANT.TOKEN`
212
-
213
- 2. **Checks for Auth Key:**
214
-
215
- - If `config.authKey` is not provided → Gets from auth package
216
- - Adds to `x-auth-key` header
217
-
218
- 3. **Syncs Environment:**
219
-
220
- - If `APPCONSTANT.ENVIRONMENT` is empty → Gets from auth config
221
- - Sets `APPCONSTANT.ENVIRONMENT`
222
-
223
- 4. **Uses Base URL:**
224
- - Prefers auth's `baseUrl` if available
225
- - Falls back to beluga's `Environment()` function
226
-
227
- ---
228
-
229
- ## Testing the Integration
230
-
231
- ### Test 1: Auth Only Initialization
232
-
233
- ```javascript
234
- // Test: Initialize auth only, use beluga directly
235
- import { initializeAuth, emailLogin } from "@tradly/auth";
236
- import TradlySDK from "beluga";
237
-
238
- // Initialize auth
239
- initializeAuth("beauty.tradly.co", "production");
240
-
241
- // Login
242
- await emailLogin("test@example.com", "password");
243
-
244
- // Use beluga directly (no init_v2.config())
245
- const [error, response] = await TradlySDK.app.getListings({
246
- bodyParam: {},
247
- });
248
-
249
- console.log("Works:", !error && response);
250
- // Expected: true (keys auto-injected)
251
- ```
252
-
253
- ### Test 2: Manual Override
254
-
255
- ```javascript
256
- // Test: Manual authKey should override auto-injected
257
- const [error, response] = await TradlySDK.app.getListings({
258
- authKey: "custom-key", // Should override auto-injected
259
- bodyParam: {},
260
- });
261
-
262
- // Manual key takes precedence
263
- ```
264
-
265
- ---
266
-
267
- ## Summary
268
-
269
- ✅ **YES, you can just initialize auth and use beluga SDK APIs directly!**
270
-
271
- After the enhancements:
272
-
273
- - ✅ Initialize auth once
274
- - ✅ Login via auth (keys stored automatically)
275
- - ✅ Use beluga APIs directly (no `init_v2.config()` needed)
276
- - ✅ All keys automatically injected
277
- - ✅ Environment and base URL synced from auth
278
-
279
- **Simplest Usage:**
280
-
281
- ```javascript
282
- // 1. Initialize auth
283
- initializeAuth("beauty.tradly.co", "production");
284
-
285
- // 2. Login
286
- await emailLogin("user@example.com", "password");
287
-
288
- // 3. Use beluga directly
289
- await TradlySDK.app.getListings({ bodyParam: {} });
290
- ```
291
-
292
- That's it! No other initialization needed.
293
-