@falaleev/payment-sdk
Advanced tools
Comparing version 1.0.5 to 1.0.7
@@ -59,3 +59,3 @@ import { type CallContext, type CallOptions } from "nice-grpc-common"; | ||
url: string; | ||
original_error: string; | ||
original_error?: string | undefined; | ||
} | ||
@@ -62,0 +62,0 @@ export interface InfoReq { |
@@ -7,2 +7,3 @@ "use strict"; | ||
var payment_1 = require("./gen/payment/payment"); | ||
var nice_grpc_error_details_1 = require("nice-grpc-error-details"); | ||
var defaultEndpoint = 'grpc.payment.falaleev.pro:443'; | ||
@@ -13,5 +14,5 @@ var createClient = function (token) { return create(defaultEndpoint, token); }; | ||
var channel = new nice_grpc_1.Channel(endpoint, grpc_js_1.ChannelCredentials.createSsl(), {}); | ||
return (0, nice_grpc_1.createClientFactory)().create(payment_1.PaymentSvcDefinition, channel, { | ||
return (0, nice_grpc_1.createClientFactory)().use(nice_grpc_error_details_1.errorDetailsClientMiddleware).create(payment_1.PaymentSvcDefinition, channel, { | ||
"*": { metadata: (new nice_grpc_1.Metadata()).set('x-api-key', token) } | ||
}); | ||
}; |
{ | ||
"name": "@falaleev/payment-sdk", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"main": "dist/index.js", | ||
@@ -22,2 +22,3 @@ "types": "dist/index.d.ts", | ||
"nice-grpc": "^2.1.8", | ||
"nice-grpc-error-details": "^0.2.5", | ||
"protobufjs": "^7.3.0", | ||
@@ -24,0 +25,0 @@ "ts-proto": "^1.176.1", |
@@ -1,25 +0,69 @@ | ||
```typescript | ||
import { createClient } from "."; | ||
import { ClientError } from "nice-grpc"; | ||
```javascript | ||
const sdk = require('@falaleev/payment-sdk'); | ||
const { ClientError, Status } = require('nice-grpc'); | ||
const { RichClientError, BadRequest } = require('nice-grpc-error-details'); | ||
const client = createClient( | ||
process.env.PAYMENT_TOKEN || 'unknown' | ||
); | ||
const client = sdk.createClient(process.env.PAYMENT_TOKEN || ''); | ||
try { | ||
const result = await client.methodList({}); | ||
console.log(result); | ||
} catch (e) { | ||
if (e instanceof ClientError) { | ||
console.error({ | ||
details: e.details, | ||
name: e.name, | ||
message: e.message, | ||
code: e.code, | ||
path: e.path, | ||
function handleErr(error) { | ||
const validationErrors = {}; | ||
if ( | ||
error instanceof ClientError && | ||
error.code === Status.INVALID_ARGUMENT | ||
) { | ||
if (false === error.hasOwnProperty('extra')) { | ||
return; | ||
} | ||
for (const detail of error.extra) { | ||
if (detail.$type !== BadRequest.$type) { | ||
continue | ||
} | ||
for (const violation of detail.fieldViolations) { | ||
if (validationErrors.hasOwnProperty(violation.field)) { | ||
validationErrors[violation.field].push(violation.description); | ||
} else { | ||
validationErrors[violation.field] = [violation.description]; | ||
} | ||
} | ||
} | ||
} | ||
if (Object.keys(validationErrors).length > 0) { | ||
console.group('validation errors'); | ||
console.log(validationErrors); | ||
console.groupEnd(); | ||
} else { | ||
console.error(error); | ||
} | ||
} | ||
async function main() { | ||
try { | ||
const result = await client.create({ | ||
method: 0, | ||
duration: 60, | ||
customer: { name: 'ivan bobrov', email: 'vanya@mail.ru', phone: '+79123492503' }, | ||
items: [ | ||
{ | ||
qty: 1, | ||
price: 19098, | ||
name: 'demoror adulatio **test** (abutor assentator **test**)' | ||
} | ||
], | ||
order_uuid: '722cf002-270d-449b-b3a7-3d87f981abc2' | ||
}); | ||
console.log(result); | ||
} catch (error) { | ||
handleErr(error); | ||
} | ||
} | ||
process.exit(0); | ||
function shutdown() { | ||
process.exit(0); | ||
} | ||
main().then(shutdown).catch(shutdown); | ||
``` |
Sorry, the diff of this file is too big to display
1612435
34109
69
6
+ Added@grpc/grpc-js@1.12.6(transitive)
+ Added@types/node@22.13.1(transitive)
+ Addednice-grpc-error-details@0.2.7(transitive)
+ Addedts-poet@6.11.0(transitive)
- Removed@grpc/grpc-js@1.12.5(transitive)
- Removed@types/node@22.13.0(transitive)
- Removedts-poet@6.9.0(transitive)