Comparing version 0.0.0 to 0.0.1
'use strict'; | ||
const _ = require('lodash'); | ||
const path = require('path'); | ||
const grpc = require('grpc'); | ||
const loader = require('@grpc/proto-loader'); | ||
const validate = require('validate.js'); | ||
const { promisify } = require('./utils'); | ||
const { | ||
promisify, | ||
ElarianService, | ||
ElarianMessages, | ||
} = require('./utils'); | ||
const ElarianServiceProto = path.join(__dirname, 'proto/web.proto'); | ||
const ElarianServiceDefinition = loader.loadSync(ElarianServiceProto, { | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true, | ||
}); | ||
const ElarianServiceDescriptor = grpc.loadPackageDefinition(ElarianServiceDefinition); | ||
const ElarianServiceNamespace = ElarianServiceDescriptor.com.elarian.hera.proto; | ||
const ElarianService = ElarianServiceNamespace.GrpcWebService; | ||
const HOST = 'api.elarian.com:443'; | ||
@@ -31,5 +21,7 @@ const SANDBOX_HOST = 'api.elarian.dev:443'; | ||
apiKey: { | ||
presence: true, | ||
type: 'string', | ||
}, | ||
authToken: { | ||
type: 'string', | ||
}, | ||
sandbox: { | ||
@@ -45,3 +37,6 @@ type: 'boolean' | ||
const { apiKey, sandbox } = this.options; | ||
const { apiKey, authToken, sandbox } = this.options; | ||
if (!apiKey && !authToken) { | ||
throw new Error('Either one of apiKey or authToken is required'); | ||
} | ||
@@ -53,3 +48,8 @@ const host = sandbox ? SANDBOX_HOST : HOST; | ||
const metadata = new grpc.Metadata(); | ||
metadata.set('api-key', apiKey); | ||
if (apiKey) { | ||
metadata.set('api-key', apiKey); | ||
} | ||
if (authToken) { | ||
metadata.set('auth-token', authToken); | ||
} | ||
callback(null, metadata); | ||
@@ -61,5 +61,9 @@ }), | ||
module.exports = function (options) { | ||
const elarian = new Elarian(options); | ||
return elarian._stub; | ||
}; | ||
module.exports = { | ||
...ElarianMessages, | ||
Client: function (options) { | ||
const elarian = new Elarian(options); | ||
return elarian._stub; | ||
}, | ||
}; |
const util = require('util'); | ||
const messages = require('./service/web_pb'); | ||
const service = require('./service/web_grpc_pb'); | ||
const ElarianMessages = messages; | ||
const ElarianService = service.GrpcWebServiceClient; | ||
const promisify = (client) => { | ||
@@ -7,3 +12,9 @@ const to = {}; | ||
if (typeof client[k] != 'function') continue; | ||
to[k] = util.promisify(client[k].bind(client)); | ||
// Stream functions synchronously return a stream object | ||
// and don't use an Error first callback signature | ||
if (client[k].responseStream && client[k].responseStream === true) { | ||
to[k] = client[k].bind(client); | ||
} else { | ||
to[k] = util.promisify(client[k].bind(client)); | ||
} | ||
} | ||
@@ -14,3 +25,5 @@ return to; | ||
module.exports = { | ||
promisify | ||
promisify, | ||
ElarianService, | ||
ElarianMessages, | ||
}; |
{ | ||
"name": "elarian", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Elrian JavaScript SDK", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@grpc/proto-loader": "^0.5.5", | ||
"google-protobuf": "^3.12.4", | ||
"grpc": "^1.24.3", | ||
@@ -28,0 +28,0 @@ "lodash": "^4.17.19", |
@@ -14,3 +14,3 @@ # Elarian JavaScript SDK | ||
You can install the package from [npm](npmjs.com/package/elarian) by running: | ||
You can install the package from [npm](https://www.npmjs.com/package/elarian) by running: | ||
@@ -25,5 +25,5 @@ ```bash | ||
```javascript | ||
const Elarian = require('elarian'); | ||
const { Client, StreamNotificationRequest } = require('elarian'); | ||
const elarian = new Elarian({ | ||
const elarian = new Client({ | ||
apiKey: 'test_api_key', | ||
@@ -33,5 +33,5 @@ sandbox: true, | ||
const stream = await elarian.StreamNotifications({ | ||
app_id: 'test_app' | ||
}); | ||
const req = new StreamNotificationRequest() | ||
.setAppId('test_app'); | ||
const stream = elarian.streamNotifications(req); | ||
@@ -56,33 +56,33 @@ stream.on('data', (notification) => { | ||
- `AuthToken()`: | ||
- `authToken()`: | ||
- `GetCustomerState()`: | ||
- `AdoptCustomerState()`: | ||
- `getCustomerState()`: | ||
- `adoptCustomerState()`: | ||
- `AddCustomerReminder()`: | ||
- `AddCustomerReminderByTag()`: | ||
- `CancelCustomerReminder()`: | ||
- `CancelCustomerReminderByTag()`: | ||
- `addCustomerReminder()`: | ||
- `addCustomerReminderByTag()`: | ||
- `cancelCustomerReminder()`: | ||
- `cancelCustomerReminderByTag()`: | ||
- `UpdateCustomerTag()`: | ||
- `DeleteCustomerTag()`: | ||
- `updateCustomerTag()`: | ||
- `deleteCustomerTag()`: | ||
- `UpdateCustomerSecondaryId()`: | ||
- `DeleteCustomerSecondaryId()`: | ||
- `updateCustomerSecondaryId()`: | ||
- `deleteCustomerSecondaryId()`: | ||
- `UpdateCustomerMetadata()`: | ||
- `DeleteCustomerMetadata ()`: | ||
- `updateCustomerMetadata()`: | ||
- `deleteCustomerMetadata ()`: | ||
- `SendMessage()`: | ||
- `SendMessageByTag()`: | ||
- `ReplyToMessage()`: | ||
- `MessagingConsent()`: | ||
- `sendMessage()`: | ||
- `sendMessageByTag()`: | ||
- `replyToMessage()`: | ||
- `messagingConsent()`: | ||
- `SendPayment()`: | ||
- `CheckoutPayment()`: | ||
- `sendPayment()`: | ||
- `checkoutPayment()`: | ||
- `MakeVoiceCall()`: | ||
- `makeVoiceCall()`: | ||
- `StreamNotifications()`: | ||
- `SendWebhookResponse()`: | ||
- `streamNotifications()`: | ||
- `sendWebhookResponse()`: | ||
@@ -89,0 +89,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
895482
22927
3
+ Addedgoogle-protobuf@^3.12.4
+ Addedgoogle-protobuf@3.21.4(transitive)
- Removed@grpc/proto-loader@^0.5.5
- Removed@grpc/proto-loader@0.5.6(transitive)
- Removed@protobufjs/aspromise@1.1.2(transitive)
- Removed@protobufjs/base64@1.1.2(transitive)
- Removed@protobufjs/codegen@2.0.4(transitive)
- Removed@protobufjs/eventemitter@1.1.0(transitive)
- Removed@protobufjs/fetch@1.1.0(transitive)
- Removed@protobufjs/float@1.0.2(transitive)
- Removed@protobufjs/inquire@1.1.0(transitive)
- Removed@protobufjs/path@1.1.2(transitive)
- Removed@protobufjs/pool@1.1.0(transitive)
- Removed@protobufjs/utf8@1.1.0(transitive)
- Removed@types/long@4.0.2(transitive)
- Removedlong@4.0.0(transitive)
- Removedprotobufjs@6.11.4(transitive)