@oway/sdk 0.1.0 → 0.1.2
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 +3 -3
- package/dist/index.d.mts +1058 -230
- package/dist/index.d.ts +1058 -230
- package/dist/index.js +12 -6
- package/dist/index.mjs +12 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -60,8 +60,8 @@ var HttpClient = class {
|
|
|
60
60
|
throw new OwayError("clientId and clientSecret are required. Contact Oway Sales Engineering to obtain M2M credentials.");
|
|
61
61
|
}
|
|
62
62
|
this.config = {
|
|
63
|
-
baseUrl: config.baseUrl || process.env.OWAY_BASE_URL || "https://
|
|
64
|
-
tokenUrl: config.tokenUrl || (config.baseUrl || process.env.OWAY_BASE_URL || "https://
|
|
63
|
+
baseUrl: config.baseUrl || process.env.OWAY_BASE_URL || "https://api.sandbox.oway.io",
|
|
64
|
+
tokenUrl: config.tokenUrl || (config.baseUrl || process.env.OWAY_BASE_URL || "https://api.sandbox.oway.io") + "/v1/auth/token",
|
|
65
65
|
maxRetries: config.maxRetries ?? 3,
|
|
66
66
|
timeout: config.timeout ?? 3e4,
|
|
67
67
|
debug: config.debug ?? false,
|
|
@@ -156,8 +156,14 @@ var HttpClient = class {
|
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
const data = await response.json();
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
if (!data.accessToken || !data.expiresIn) {
|
|
160
|
+
throw new OwayError(
|
|
161
|
+
"Invalid token response: missing accessToken or expiresIn",
|
|
162
|
+
"AUTH_INVALID_RESPONSE"
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
this.tokenExpiry = Date.now() + data.expiresIn * 1e3;
|
|
166
|
+
return data.accessToken;
|
|
161
167
|
} catch (error) {
|
|
162
168
|
this.log("error", "Token refresh failed", {
|
|
163
169
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -356,12 +362,12 @@ var OwayEnvironments = {
|
|
|
356
362
|
* Sandbox environment for development and testing
|
|
357
363
|
* Safe to use - no real shipments created
|
|
358
364
|
*/
|
|
359
|
-
SANDBOX: "https://
|
|
365
|
+
SANDBOX: "https://api.sandbox.oway.io",
|
|
360
366
|
/**
|
|
361
367
|
* Production environment for live traffic
|
|
362
368
|
* Real shipments will be created and billed
|
|
363
369
|
*/
|
|
364
|
-
PRODUCTION: "https://
|
|
370
|
+
PRODUCTION: "https://api.oway.io"
|
|
365
371
|
};
|
|
366
372
|
|
|
367
373
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -31,8 +31,8 @@ var HttpClient = class {
|
|
|
31
31
|
throw new OwayError("clientId and clientSecret are required. Contact Oway Sales Engineering to obtain M2M credentials.");
|
|
32
32
|
}
|
|
33
33
|
this.config = {
|
|
34
|
-
baseUrl: config.baseUrl || process.env.OWAY_BASE_URL || "https://
|
|
35
|
-
tokenUrl: config.tokenUrl || (config.baseUrl || process.env.OWAY_BASE_URL || "https://
|
|
34
|
+
baseUrl: config.baseUrl || process.env.OWAY_BASE_URL || "https://api.sandbox.oway.io",
|
|
35
|
+
tokenUrl: config.tokenUrl || (config.baseUrl || process.env.OWAY_BASE_URL || "https://api.sandbox.oway.io") + "/v1/auth/token",
|
|
36
36
|
maxRetries: config.maxRetries ?? 3,
|
|
37
37
|
timeout: config.timeout ?? 3e4,
|
|
38
38
|
debug: config.debug ?? false,
|
|
@@ -127,8 +127,14 @@ var HttpClient = class {
|
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
const data = await response.json();
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
if (!data.accessToken || !data.expiresIn) {
|
|
131
|
+
throw new OwayError(
|
|
132
|
+
"Invalid token response: missing accessToken or expiresIn",
|
|
133
|
+
"AUTH_INVALID_RESPONSE"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
this.tokenExpiry = Date.now() + data.expiresIn * 1e3;
|
|
137
|
+
return data.accessToken;
|
|
132
138
|
} catch (error) {
|
|
133
139
|
this.log("error", "Token refresh failed", {
|
|
134
140
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -327,12 +333,12 @@ var OwayEnvironments = {
|
|
|
327
333
|
* Sandbox environment for development and testing
|
|
328
334
|
* Safe to use - no real shipments created
|
|
329
335
|
*/
|
|
330
|
-
SANDBOX: "https://
|
|
336
|
+
SANDBOX: "https://api.sandbox.oway.io",
|
|
331
337
|
/**
|
|
332
338
|
* Production environment for live traffic
|
|
333
339
|
* Real shipments will be created and billed
|
|
334
340
|
*/
|
|
335
|
-
PRODUCTION: "https://
|
|
341
|
+
PRODUCTION: "https://api.oway.io"
|
|
336
342
|
};
|
|
337
343
|
|
|
338
344
|
// src/index.ts
|