simplex-ts 3.5.1 → 3.5.3
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/dist/SimplexClient.d.ts.map +1 -1
- package/dist/SimplexClient.js +1 -1
- package/dist/SimplexClient.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/webhook.d.ts +79 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +118 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimplexClient.d.ts","sourceRoot":"","sources":["../src/SimplexClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAA+D,uBAAuB,EAA0D,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGnN,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAa;IACxB,SAAS,EAAE,QAAQ,CAAC;gBAIf,OAAO,EAAE,oBAAoB;IAYnC,qBAAqB,CAAC,OAAO,EAAE;QACnC,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,WAAW,CAAC,EAAE,GAAG,CAAC;KACnB,GAAG,OAAO,CAAC,eAAe,CAAC;IAmCtB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"SimplexClient.d.ts","sourceRoot":"","sources":["../src/SimplexClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAA+D,uBAAuB,EAA0D,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGnN,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAa;IACxB,SAAS,EAAE,QAAQ,CAAC;gBAIf,OAAO,EAAE,oBAAoB;IAYnC,qBAAqB,CAAC,OAAO,EAAE;QACnC,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,WAAW,CAAC,EAAE,GAAG,CAAC;KACnB,GAAG,OAAO,CAAC,eAAe,CAAC;IAmCtB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAgBpE,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2C3E,YAAY,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgCjC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIlC,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjD,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAGtC"}
|
package/dist/SimplexClient.js
CHANGED
|
@@ -44,7 +44,7 @@ class SimplexClient {
|
|
|
44
44
|
}
|
|
45
45
|
async getSessionStore(sessionId) {
|
|
46
46
|
try {
|
|
47
|
-
const response = await this.httpClient.
|
|
47
|
+
const response = await this.httpClient.post('/get_session_store', { session_id: sessionId });
|
|
48
48
|
return response;
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimplexClient.js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@
|
|
|
1
1
|
export { SimplexClient } from './SimplexClient';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export { SimplexError, NetworkError, ValidationError, AuthenticationError, RateLimitError, WorkflowError, } from './errors';
|
|
4
|
+
export { verifySimplexWebhook, WebhookVerificationError, SimplexWebhookHeaders, } from './webhook';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WorkflowError = exports.RateLimitError = exports.AuthenticationError = exports.ValidationError = exports.NetworkError = exports.SimplexError = exports.SimplexClient = void 0;
|
|
17
|
+
exports.WebhookVerificationError = exports.verifySimplexWebhook = exports.WorkflowError = exports.RateLimitError = exports.AuthenticationError = exports.ValidationError = exports.NetworkError = exports.SimplexError = exports.SimplexClient = void 0;
|
|
18
18
|
var SimplexClient_1 = require("./SimplexClient");
|
|
19
19
|
Object.defineProperty(exports, "SimplexClient", { enumerable: true, get: function () { return SimplexClient_1.SimplexClient; } });
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
@@ -25,4 +25,7 @@ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: funct
|
|
|
25
25
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
26
26
|
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
27
27
|
Object.defineProperty(exports, "WorkflowError", { enumerable: true, get: function () { return errors_1.WorkflowError; } });
|
|
28
|
+
var webhook_1 = require("./webhook");
|
|
29
|
+
Object.defineProperty(exports, "verifySimplexWebhook", { enumerable: true, get: function () { return webhook_1.verifySimplexWebhook; } });
|
|
30
|
+
Object.defineProperty(exports, "WebhookVerificationError", { enumerable: true, get: function () { return webhook_1.WebhookVerificationError; } });
|
|
28
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,0CAAwB;AAExB,mCAOkB;AANhB,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,yGAAA,eAAe,OAAA;AACf,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AACd,uGAAA,aAAa,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,0CAAwB;AAExB,mCAOkB;AANhB,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,yGAAA,eAAe,OAAA;AACf,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AACd,uGAAA,aAAa,OAAA;AAGf,qCAImB;AAHjB,+GAAA,oBAAoB,OAAA;AACpB,mHAAA,wBAAwB,OAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when webhook verification fails
|
|
3
|
+
*/
|
|
4
|
+
export declare class WebhookVerificationError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Headers required for Simplex webhook verification
|
|
9
|
+
*/
|
|
10
|
+
export interface SimplexWebhookHeaders {
|
|
11
|
+
'x-simplex-signature': string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Verifies a Simplex webhook request using HMAC-SHA256 signature verification.
|
|
15
|
+
*
|
|
16
|
+
* This function ensures that webhook requests are authentic and haven't been
|
|
17
|
+
* tampered with in transit. It uses the same pattern as GitHub webhooks.
|
|
18
|
+
*
|
|
19
|
+
* @param body - Raw request body as string (must be the original unparsed body)
|
|
20
|
+
* @param headers - Request headers containing the X-Simplex-Signature header
|
|
21
|
+
* @param webhookSecret - Your webhook secret from the Simplex dashboard
|
|
22
|
+
*
|
|
23
|
+
* @throws {WebhookVerificationError} If signature is missing, invalid, or verification fails
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Express.js example
|
|
28
|
+
* import express from 'express';
|
|
29
|
+
* import { verifySimplexWebhook } from 'simplex-ts';
|
|
30
|
+
*
|
|
31
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
32
|
+
* try {
|
|
33
|
+
* const body = req.body.toString('utf8');
|
|
34
|
+
* verifySimplexWebhook(
|
|
35
|
+
* body,
|
|
36
|
+
* req.headers,
|
|
37
|
+
* process.env.SIMPLEX_WEBHOOK_SECRET!
|
|
38
|
+
* );
|
|
39
|
+
*
|
|
40
|
+
* // Webhook verified, safe to process
|
|
41
|
+
* const payload = JSON.parse(body);
|
|
42
|
+
* console.log('Received webhook:', payload.session_id);
|
|
43
|
+
* res.json({ success: true });
|
|
44
|
+
* } catch (error) {
|
|
45
|
+
* console.error('Webhook verification failed:', error);
|
|
46
|
+
* res.status(401).json({ error: error.message });
|
|
47
|
+
* }
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Next.js API route example
|
|
54
|
+
* import type { NextApiRequest, NextApiResponse } from 'next';
|
|
55
|
+
* import { verifySimplexWebhook } from 'simplex-ts';
|
|
56
|
+
*
|
|
57
|
+
* export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
58
|
+
* if (req.method !== 'POST') {
|
|
59
|
+
* return res.status(405).json({ error: 'Method not allowed' });
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* try {
|
|
63
|
+
* const body = JSON.stringify(req.body);
|
|
64
|
+
* verifySimplexWebhook(
|
|
65
|
+
* body,
|
|
66
|
+
* req.headers,
|
|
67
|
+
* process.env.SIMPLEX_WEBHOOK_SECRET!
|
|
68
|
+
* );
|
|
69
|
+
*
|
|
70
|
+
* console.log('Session completed:', req.body.session_id);
|
|
71
|
+
* res.json({ received: true });
|
|
72
|
+
* } catch (error) {
|
|
73
|
+
* res.status(401).json({ error: error.message });
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function verifySimplexWebhook(body: string, headers: Record<string, string | string[] | undefined>, webhookSecret: string): void;
|
|
79
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,EACtD,aAAa,EAAE,MAAM,GACpB,IAAI,CAqCN"}
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebhookVerificationError = void 0;
|
|
7
|
+
exports.verifySimplexWebhook = verifySimplexWebhook;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when webhook verification fails
|
|
11
|
+
*/
|
|
12
|
+
class WebhookVerificationError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'WebhookVerificationError';
|
|
16
|
+
Object.setPrototypeOf(this, WebhookVerificationError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.WebhookVerificationError = WebhookVerificationError;
|
|
20
|
+
/**
|
|
21
|
+
* Verifies a Simplex webhook request using HMAC-SHA256 signature verification.
|
|
22
|
+
*
|
|
23
|
+
* This function ensures that webhook requests are authentic and haven't been
|
|
24
|
+
* tampered with in transit. It uses the same pattern as GitHub webhooks.
|
|
25
|
+
*
|
|
26
|
+
* @param body - Raw request body as string (must be the original unparsed body)
|
|
27
|
+
* @param headers - Request headers containing the X-Simplex-Signature header
|
|
28
|
+
* @param webhookSecret - Your webhook secret from the Simplex dashboard
|
|
29
|
+
*
|
|
30
|
+
* @throws {WebhookVerificationError} If signature is missing, invalid, or verification fails
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Express.js example
|
|
35
|
+
* import express from 'express';
|
|
36
|
+
* import { verifySimplexWebhook } from 'simplex-ts';
|
|
37
|
+
*
|
|
38
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
39
|
+
* try {
|
|
40
|
+
* const body = req.body.toString('utf8');
|
|
41
|
+
* verifySimplexWebhook(
|
|
42
|
+
* body,
|
|
43
|
+
* req.headers,
|
|
44
|
+
* process.env.SIMPLEX_WEBHOOK_SECRET!
|
|
45
|
+
* );
|
|
46
|
+
*
|
|
47
|
+
* // Webhook verified, safe to process
|
|
48
|
+
* const payload = JSON.parse(body);
|
|
49
|
+
* console.log('Received webhook:', payload.session_id);
|
|
50
|
+
* res.json({ success: true });
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* console.error('Webhook verification failed:', error);
|
|
53
|
+
* res.status(401).json({ error: error.message });
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Next.js API route example
|
|
61
|
+
* import type { NextApiRequest, NextApiResponse } from 'next';
|
|
62
|
+
* import { verifySimplexWebhook } from 'simplex-ts';
|
|
63
|
+
*
|
|
64
|
+
* export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
65
|
+
* if (req.method !== 'POST') {
|
|
66
|
+
* return res.status(405).json({ error: 'Method not allowed' });
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* try {
|
|
70
|
+
* const body = JSON.stringify(req.body);
|
|
71
|
+
* verifySimplexWebhook(
|
|
72
|
+
* body,
|
|
73
|
+
* req.headers,
|
|
74
|
+
* process.env.SIMPLEX_WEBHOOK_SECRET!
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* console.log('Session completed:', req.body.session_id);
|
|
78
|
+
* res.json({ received: true });
|
|
79
|
+
* } catch (error) {
|
|
80
|
+
* res.status(401).json({ error: error.message });
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function verifySimplexWebhook(body, headers, webhookSecret) {
|
|
86
|
+
// Normalize header name (case-insensitive)
|
|
87
|
+
const signature = headers['x-simplex-signature'] || headers['X-Simplex-Signature'];
|
|
88
|
+
// 1. Check required header
|
|
89
|
+
if (!signature || typeof signature !== 'string') {
|
|
90
|
+
throw new WebhookVerificationError('Missing X-Simplex-Signature header');
|
|
91
|
+
}
|
|
92
|
+
// 2. Compute expected signature
|
|
93
|
+
const expectedSignature = crypto_1.default
|
|
94
|
+
.createHmac('sha256', webhookSecret)
|
|
95
|
+
.update(body, 'utf8')
|
|
96
|
+
.digest('hex');
|
|
97
|
+
// 3. Compare signatures using constant-time comparison to prevent timing attacks
|
|
98
|
+
try {
|
|
99
|
+
const signatureBuffer = Buffer.from(signature, 'hex');
|
|
100
|
+
const expectedBuffer = Buffer.from(expectedSignature, 'hex');
|
|
101
|
+
// Ensure both buffers are the same length before comparison
|
|
102
|
+
if (signatureBuffer.length !== expectedBuffer.length) {
|
|
103
|
+
throw new WebhookVerificationError('Invalid webhook signature');
|
|
104
|
+
}
|
|
105
|
+
if (!crypto_1.default.timingSafeEqual(signatureBuffer, expectedBuffer)) {
|
|
106
|
+
throw new WebhookVerificationError('Invalid webhook signature');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof WebhookVerificationError) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
// Handle any unexpected errors (e.g., invalid hex encoding)
|
|
114
|
+
throw new WebhookVerificationError('Invalid webhook signature format');
|
|
115
|
+
}
|
|
116
|
+
// Webhook verified successfully!
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":";;;;;;AAqFA,oDAyCC;AA9HD,oDAA4B;AAE5B;;GAEG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;CACF;AAND,4DAMC;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,SAAgB,oBAAoB,CAClC,IAAY,EACZ,OAAsD,EACtD,aAAqB;IAErB,2CAA2C;IAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAEnF,2BAA2B;IAC3B,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,IAAI,wBAAwB,CAAC,oCAAoC,CAAC,CAAC;IAC3E,CAAC;IAED,gCAAgC;IAChC,MAAM,iBAAiB,GAAG,gBAAM;SAC7B,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC;SACnC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;SACpB,MAAM,CAAC,KAAK,CAAC,CAAC;IAEjB,iFAAiF;IACjF,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACtD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAE7D,4DAA4D;QAC5D,IAAI,eAAe,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,CAAC;YACrD,MAAM,IAAI,wBAAwB,CAAC,2BAA2B,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,gBAAM,CAAC,eAAe,CAAC,eAAe,EAAE,cAAc,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,wBAAwB,CAAC,2BAA2B,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,wBAAwB,EAAE,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC;QACD,4DAA4D;QAC5D,MAAM,IAAI,wBAAwB,CAAC,kCAAkC,CAAC,CAAC;IACzE,CAAC;IAED,iCAAiC;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplex-ts",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"description": "Official TypeScript SDK for the Simplex API",
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/yourusername/simplex-typescript-sdk.git"
|
|
25
|
+
"url": "git+https://github.com/yourusername/simplex-typescript-sdk.git"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/yourusername/simplex-typescript-sdk#readme",
|
|
28
28
|
"files": [
|