Skip to content

Commit

Permalink
fix(*): 🐛 Fix Twilio Client access over injected
Browse files Browse the repository at this point in the history
getTwilioClient() function wasnt invoked and was injected as the function itself not an instance.
  • Loading branch information
iagocalazans committed Jun 10, 2022
1 parent f7a8a8b commit 548ed3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -85,7 +85,10 @@ npm install twilio-functions-utils
```js
// File: assets/create.private.js

exports.create = async function () {
exports.create = async function (event) {
// Here you can acess Twilio Client as client and Context as props (so you can get env vars).
const { client, props } = this

return new Promise((resolve, reject) => {
const random = Math.random();

Expand Down Expand Up @@ -122,7 +125,7 @@ const { create } = require(Runtime.getAssets()['/create.js'].path)
*/
async function createAction(event) {
// You can perform all your "controller" level actions, as you have access to the request headers and cookies.
const { cookies, request } = this
const { cookies, request, client, props } = this

// Then just call the useCase you provided to handler by using useInjection.
const useCaseResult = await this.useCase.create(event)
Expand Down
5 changes: 3 additions & 2 deletions lib/use.injection.js
Expand Up @@ -41,9 +41,10 @@ exports.useInjection = (fn, params) =>
const { providers, validateToken } = params;
const [context, event, callback] = args;
const { getTwilioClient, ...properties } = context;
const client = getTwilioClient();

const useCaseThat = {
client: getTwilioClient,
client,
props: properties,
};

Expand All @@ -56,7 +57,7 @@ exports.useInjection = (fn, params) =>
const that = {
request,
cookies,
client: getTwilioClient(),
client,
props: properties,
useCase: providerNames.reduce((p, c) => {
Reflect.defineProperty(
Expand Down

0 comments on commit 548ed3d

Please sign in to comment.