Im using this library to manage bitbucket api from nodejs.
I have received a message about a deprecated endpoint so I saw that library have released a new version (2).
So, I have uninstall bitbucket dependency and installed again to version 2.7.0
But now, Im getting an error like this:
let bitbucketAPI = new Bitbucket()
^
TypeError: Bitbucket is not a constructor
This is the change in package.json
- "bitbucket": "^1.15.1",
+ "bitbucket": "^2.7.0",
And this is my code:
let Bitbucket = require('bitbucket')
let bitbucketAPI = new Bitbucket()
I have deleted package-lock.json, node_modules/bitbucket folder, update dependencies with npm update but anything works..
Any idea?
The proper way to load this module is this:
const { Bitbucket } = require('bitbucket');
This is shown in the doc.
So, when you were just doing this:
let Bitbucket = require('bitbucket');
You were getting the module exports object, not the individual Bitbucket property of that object. To further understand,
// get module exports object
const bitBucketModule = require('bitbucket');
// get Bitbucket property from the module exports object
const Bitbucket = bitBucketModule.Bitbucket;
And, the recommended method using object desctructuring:
const { Bitbucket } = require('bitbucket');
is just a shortcut way to do it with less code.
Linked docs destructure Bitbucket:
const { Bitbucket } = require('bitbucket')
Related
I am implementing GraphQL subscription based on this document using the PubSub Class. However,
the document also says:- The PubSub class is not recommended for
production environments, because it's an in-memory event system that
only supports a single server instance. After you get subscriptions
working in development, we strongly recommend switching it out for a
different subclass of the abstract PubSubEngine class. Recommended
subclasses are listed in Production PubSub libraries.
So, I chose the Google PubSub Library, the second option from the list.
In a file subscription.js, I wrote the following code:-
const { GooglePubSub } = require('#axelspringer/graphql-google-pubsub');
const pubsub = new GooglePubSub();
const UPDATE_PARKING = "UPDATE_PARKING";
module.exports = {pubsub, UPDATE_PARKING};
In the file named parking.queries.js, the Graphql is like this:-
type Subscription {
updateParking: Parking
}
In the file named parking.resolver.js, the Resolver is like this
const {pubsub, UPDATE_PARKING} = require("../utils/subscription");
Subscription: {
updateParking: {
subscribe: () => pubsub.asyncIterator(UPDATE_PARKING)
}
}
Now to publish the data in the service file named parking.service.js, I did this:-
const {pubsub, UPDATE_PARKING} = require("../utils/subscription");
.........................
.........................
.........................
pubsub.publish(UPDATE_PARKING, {updateParking: parkingDetail});
.........................
The above code runs fine. However, when I an trying to publish a new subscription, I am facing a strange problem. Let, me explain.
In the file subscription.js, I made the following changes:-
const { GooglePubSub } = require('#axelspringer/graphql-google-pubsub');
const pubsub = new GooglePubSub();
const UPDATE_PARKING = "UPDATE_PARKING";
const UPDATE_USER = "UPDATE_USER";
module.exports = {pubsub, UPDATE_PARKING, UPDATE_USER};
In the file named user.queries.js, the Graphql is like this:-
type Subscription {
updateUser: User
}
In the file named user.resolver.js, the Resolver is like this,
const {pubsub, UPDATE_USER} = require("../utils/subscription");
Subscription: {
updateUser: {
subscribe: () => pubsub.asyncIterator(UPDATE_USER)
}
}
In the service file user_subscription.service.js, I have the code like this:-
const {pubsub, UPDATE_USER} = require("../utils/subscription");
............................
............................
pubsub.publish(UPDATE_USER, {updateUser: newUserData});
............................
Whenever the code pubsub.publish(UPDATE_USER, {updateUser: newUserData}); is getting executed, I am getting this strange error:-
/var/www/example/html/node_modules/google-auth-library/build/src/auth/googleauth.js:89
throw new Error('Unable to detect a Project Id in the current environment. \n' +
^
Error: Unable to detect a Project Id in the current environment.
To learn more about authentication and Google APIs, visit:
https://cloud.google.com/docs/authentication/getting-started
at /var/www/example/html/node_modules/google-auth-library/build/src/auth/googleauth.js:89:31
at processTicksAndRejections (node:internal/process/task_queues:96:5)
[nodemon] app crashed - waiting for file changes before starting...
However, whenever this code is executed pubsub.publish(UPDATE_PARKING, {updateParking: parkingDetail}); the above error doesn't happen.
What am I doing wrong?
Firebase deployment of my function fails with the following error:
"Function failed on loading user code. This is likely due to a bug in the user code."
Here's the function code:
const postmark = require("postmark");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp()
exports.sendPostmarkEmailFunction = functions.firestore.
document('/postmarklogs/{documentId}').
onCreate((snapShot, context) => {
var serverToken = "_my_client_key_";
var client = new postmark.ServerClient(serverToken);
try {
client.sendEmail({
"From": "_my_depatch_address_",
"To": "_my_receipt_address_",
"Subject": snapShot.data().subject,
"HtmlBody": snapShot.data().message
});
return true;
} catch (error) {
console.log("Error : " + error.ErrorCode + " : " + error.Message);
return false;
}
});
This code works just fine in the Firebase emulator. As far as I can see, the deployment issue is triggered specifically by the const postmark = require("postmark"); line. If I comment this out, the function deploys - but then of course it doesn't work!
Advice would be greatly appreciated.
Postmark needs to be installed in the project's 'functions' folder. I'd installed it into the body of the project and so Postmark was missing from the 'functions/package.json' file that guides deployment's build stage. The 'functions' folder created by firebase init functions is like a project within a project and needs to be treated as such.
I got onto the problem from the deployment "build" logs
Once Postmark had been installed in the 'functions' folder my sendPostmarkEmailFunction function worked perfectly.
In passing, unless you already know this, the Postmark API token really needs to be squirreled securely away in the Firebase environment variable store. Also, while you might be tempted to use an https.onRequest trigger rather than the onCreate() used here, you might like to know that this is likely to land you in endless CORS issues when used with Postmark.
I'm trying to use the ExchangeService.AutodiscoverUrl() method, but it's not working. It doesn't seem to be getting a URL, resulting in the error "Cannot read property 'AbsoluteUri' of undefined" from ExchangeCredentials.GetUriWithoutSuffix.
Here is my code ('c' is just a json object):
service = new EwsJS.ExchangeService(EwsJS.ExchangeVersion.Exchange2016);
service.Credentials = new EwsJS.ExchangeCredentials(c.UserName, c.Password);
service.AutodiscoverUrl("email#domain.com", RedirectCallback);
// I'm forcing the accepted redirect here.
function RedirectCallback(url) {
return true;
}
Autodiscover in ews-javascript-api needs major re-write to work properly.
Autodiscover is re-written, latest dev build is out with #next tag.
you can now use it when installing npm i ews-javascript-api#next, once stable build is out you can install regular build.
var Service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
Service.Credentials = new WebCredentials(user, pass);
//Autodiscover
Service.AutodiscoverUrl(user, this.RedirectionUrlValidationCallback);
console.log(Service.Url);
I tried to update DocumentReference but could not do it.
update() method fails. How to use it? (How to pass argument?)
firebase-admin version is 6.3.0.
#google-cloud/firestore version is 0.19.0.
❯ firebase functions:shell
i functions: Preparing to emulate functions.
Warning: You're using Node.js v8.14.0 but Google Cloud Functions only supports v6.11.5.
✔ functions: sampleFunc
firebase > const admin = require('firebase-admin');
firebase > admin.initializeApp();
firebase > let ref = admin.firestore().collection("users").doc('edqupYQhzqV1ODjEpoJn');
firebase > let updates = { email: 'xxx#yyy.zzz' };
firebase > ref.update(updates).then(value => console.log(value) );
Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Argument "dataOrField" is not a valid Document. Input is not a plain JavaScript object.
at WriteBatch.update (/Users/xxx/Desktop/sample-functions/functions/node_modules/#google-cloud/firestore/build/src/write-batch.js:359:23)
at DocumentReference.update (/Users/xxx/Desktop/sample-functions/functions/node_modules/#google-cloud/firestore/build/src/reference.js:387:14)
Update
Document has already been created, so get() works.
firebase > ref.get().then(snapshot => console.log(snapshot.data()));
Errors also occur in set() as well.
firebase > ref.set({email: 'aaa#bbb.ccc'}, {merge: true}).then(value => console.log(value));
Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object.
at Validator.(anonymous function).values [as isDocument] (/Users/xxx/Desktop/sample-functions/functions/node_modules/#google-cloud/firestore/build/src/validate.js:99:27)
at WriteBatch.set (/Users/xxx/Desktop/sample-functions/functions/node_modules/#google-cloud/firestore/build/src/write-batch.js:232:25)
at DocumentReference.set (/Users/xxx/Desktop/sample-functions/functions/node_modules/#google-cloud/firestore/build/src/reference.js:349:27)
Following the example you posted, you are trying to update a document that does not exist. In this case you should create it first.
If you're not sure whether the document exists, pass the option to merge the new data with any existing document to avoid overwriting entire documents.
From Google's Documentation:
var cityRef = db.collection('cities').doc('BJ');
var setWithOptions = cityRef.set({
capital: true
}, {merge: true});
Reference: Firestore Add Data
I've never tried using the Admin SDK in the functions:shell like you do in your example. However I can easily reproduce your error. I guess that the functions:shell somehow tampers with your variable updates. When i log updates undefined is concatenated in output
firebase > console.log(updates)
{ email2: 'xxx#yyy.zzz' }
undefined
If you put your code in a JS file, initialize your app with a service account and run in with node it will most likely work just fine!
Read more about how to use Service Account
create an object first then assign your values to a field/property on that object like:
var myObj = {};
myObj["myfield"] = myvalue;
now pass as the 2nd argument of .set or .update.
Whatever I tried I cannot set an extension property on a User object, here is a reproducible piece of code:
public async Task CleanTest(string extName)
{
ExtensionProperty ep = new ExtensionProperty
{
Name = extName,
DataType = "String",
TargetObjects = { "User" }
};
App app = (App)(await _client.Applications.Where(a => a.AppId == _managementAppClientId).ExecuteSingleAsync());
app.ExtensionProperties.Add(ep);
await app.UpdateAsync();
GraphUser user = (GraphUser)(await _client.Users.Where(u => u.UserPrincipalName.Equals("email")).ExecuteSingleAsync());
string propName = FormatExtensionPropertyName(extName); //formats properly as extesion_xxx_name
user.SetExtendedProperty(propName, "testvalue");
//user.SetExtendedProperty(extName, "testvalue");
await user.UpdateAsync(); // fails here
}
user.UpdateAsync() according to Fiddler doesn't even go out and application fails with an exception:
"The property 'extension_e206e28ff36244b19bc56c01160b9cf0_UserEEEqdbtgd3ixx2' does not exist on type 'Microsoft.Azure.ActiveDirectory.GraphClient.Internal.User'. Make sure to only use property names that are defined by the type."
This issue is also being tracked here:
https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/28
I've got an alternative workaround for this bug, for those that want to use the version 5.7 OData libraries rather than redirecting to the v5.6.4 versions.
Add a request pipeline configuration handler.
// initialize in the usual way
ActiveDirectoryClient activeDirectoryClient =
AuthenticationHelper.GetActiveDirectoryClientAsApplication();
// after initialization add a handler to the request pipline configuration.
activeDirectoryClient.Context
.Configurations.RequestPipeline
.OnMessageWriterSettingsCreated(UndeclaredPropertyHandler);
In the handler, change the ODataUndeclaredPropertyBehaviorKinds value on the writer settings to SupportUndeclaredValueProperty.
private static void UndeclaredPropertyHandler(MessageWriterSettingsArgs args)
{
var field = args.Settings.GetType().GetField("settings",
BindingFlags.NonPublic | BindingFlags.Instance);
var settingsObject = field?.GetValue(args.Settings);
var settings = settingsObject as ODataMessageWriterSettings;
if (settings != null)
{
settings.UndeclaredPropertyBehaviorKinds =
ODataUndeclaredPropertyBehaviorKinds.SupportUndeclaredValueProperty;
}
}
Just in case you still looking for solution to this problem or someone else is facing the same issue:
I got similar issue and it looks like, at least for me, the problem was in latest version of "Microsoft.Data.Services.Client" package - 5.7.0 (or in one of it dependencies). When I downgraded to previous version - 5.6.4 it worked as a charm.
I had same symptoms - updating of extended property was failing even w/o any request is made (also used Fiddler)
Hope it helps!
Artem Liman