I'm trying to use Braintree in my Meteor application, and I've made a local package of this Braintree packaging, following the instructions of this blog post on the subject, and the install went fine.
Now though, I have this code:
// defined in server/fixtures.js
Gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "secret",
publicKey: "secret",
privateKey: "secret"
});
and it's throwing this error:
ReferenceError: braintree is not defined
(etc....)
I then tried throwing in this line as recommended by the Braintree documentation, but it simply throws an error that "require" isn't defined.
var braintree = require("braintree");
The Braintree docs uses Express methodologies to make everything happen, but that's not a lot of help here.
The package I referenced earlier defines it's server.js with this single line:
Braintree = Npm.require("braintree");
so I tried changing my references to Braintree rather than braintree, but this was undefined the exact same way.
How do I get at Braintree to use it?
Thanks in advance!
Server packages require that symbols used outside of the package be exported with api.export. It looks like the package you referenced was built prior to meteor v0.6.5. As I recall, this video on EventedMind explains how all of this works. I suspect the solution to your problem is just to make your package.js look something like:
Package.on_use(function (api) {
api.export('Braintree');
api.use(...);
api.add_files(...);
});
Related
So im trying to build ontop of the angular-meteor WhatsApp clone tutorial using Ionic 2 CLI
This tutorial basically deletes the client folder in the meteor project and uses the meteor-client-side package inside an ionic project to connect to the meteor server.
Which works perfectly fine, but now i'd like to subscribe to a meteor publication with an reactive parameter.
After searching the Meteor API Documentation I found the Session object:
Session provides a global object on the client that you can use to
store an arbitrary set of key-value pairs. Use it to store things like
the currently selected item in a list.
What’s special about Session is that it’s reactive. If you
call Session.get("currentList") from inside a template, the template
will automatically be rerendered whenever
Session.set("currentList", x) is called.
In the Meteor Subscribe Documentation you can find the following example:
Tracker.autorun(function () {
Meteor.subscribe("chat", {room: Session.get("current-room")});
Meteor.subscribe("privateMessages");
});
This subscribes you to the chat messages in the current room and to
your private messages. When you change rooms by
calling Session.set("current-room", "new-room"), Meteor will subscribe
to the new room’s chat messages, unsubscribe from the original room’s
chat messages, and continue to stay subscribed to your private
messages.
Which is exactly what I want to do too. But as the Session documentation states, session is a package I have to add to the meteor project:
To add Session to your application, run this command in your terminal:
meteor add session
Now my question, is there any way to add session to the meteor-client-side packages?
If I just try to call Session.set() it fails on runtime with Session is not defined
My guess is that I would need some npm package that extracts the Session functionality (basically a sessions-client-side npm package) like accounts-base-client-side
Is there an other way to do this?
How would I build my own sessions-client-side?
I tried to run meteor add session in my meteor project but was not able to find the code for Session anywhere in .meteor folder and npm_modules.
I also looked into the meteor GitHub but the Session.js file they have contains only documentation
Any input how to do something like this would be nice
Update:
I've looked into the accounts-base-client-side package and found out that they are autogenerated using a script, so im currently trying to adapt this script to work with Session instead of accounts-base.
You can find my attempt at: https://github.com/AwsmOli/session-client-side
Still work in progress, but i should get it to work soon
Update 2:
See my answer, my session-client-side is working now :)
The "Session" variable should just appear and be accessible. If you need to verify that, start a new project add the package and write some code to access it. It is likely that something has (unwittingly) nuked the Session variable - I have seen this before with another package.
Another way of doing this is with "getReactively". Below is a helper that uses it in a query. Make sure you declare it before the helper (otherwise it won't work). This one uses the result of another helper, but it can be any variable, and you just assign the variable for the reactivity to kick in and run the helper.
this.helpers({
currentUser: () => { return Meteor.user() },
elder: () => {
let e = Elders.findOne({_id: this.getReactively('this.currentUser._id')});
if (e) {
utils.services.setupElder(e);
}
return e;
}
});
As per the meteor docs, you have to import it:
import { Session } from 'meteor/session'
This will enable it on the client.
In earlier meteor versions this was not required, as it was both a default package, and automatically imported into the global namespace.
I ended up creating the session-client-side package myself, and its working nicely.
If you need it too, its available on GitHub:
https://github.com/AwsmOli/session-client-side
and NPM:
npm install session-client-side
credits to idanwe who created the client side packages and made it realy easy to adapt his work to work with any meteor package :)
To use it with Ionic 2 Apps:
import it in your entry points (src/app/main.prod.ts & src/app/main.dev.ts)
import 'session-client-side';
and now the global Session variable is accessable form anywhere in your app:
Session.set("aCoolNameFormyAwsmChangingObject", myAwsmChangingObject);
Thanks for the help!
I'm need a create custom package for using oauth with external service, but have no idea how to make it. I'm tryed to clone accounts-github package into my project and modyfy it, but it not working.
Some code here.
//test.html
<template name = 'test'>
Login
</test>
//test.js
Template.test.events({
'click .gitLogin': function() {
return Meteor.loginWithGithub();
}
});
Error here:
Meteor.loginWithGithub is not a function
My steps for installing accounts-github package:
—clone from repo to app/packages directory
—modifyed name of package in package.js file
—meteor add my:package
—Donewithout any errors
But as you can see it not working.
Main question: how to create or modify existing package to use another oauth provider?
Provider is wargaming.net is not providing secret code like a facebook or google.
p.s. and i'm using windows
There are two packages for each oauth service. The other one has all of the logic related to the service. Check out the github package https://github.com/meteor/meteor/tree/devel/packages/github
I'm trying to add the twilio client library and have had no luck with any of the solutions I've looked up. I have tried including the script in client/lib, client/compatibility, client/lib/compatibility, and I always get the following error:
Uncaught SyntaxError: Unexpected token <
I think it is throwing this error because it is trying to inject itself and is not able to because of the way Meteor compiles the files. Has anyone had any luck including this library? I would GREATLY appreciate any help.
There is another way to add twilio package to your project.
npm install twilio
and you can giv your SID and Token at server
var twilio = Npm.require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
now you can make call to twilio api in server.
Hope it helps you.
The only way I could get this to work is to install the bower package, then install the meteor client library through bower.
I just updated Meteor to 0.8. Now my app is crashing and I get 'spark is not defined'. I have read some articles stating that this can have something to do with the iron-router package. I'm clueless about what steps I should take to correct this.
The error is because of iron-router package.
You need to update the package.
I just gave answer on this see this
Old Spark rendering engine can be referenced by any of the packages you use in your application, so you get this error until all packages used are updated to Blaze, not only iron-router (this is why #Chris is still getting it).
Check which package is referencing Spark and check for updates.
Until mrt update doesn't automatically get results you can look for a blaze branch of the offending package and use it. For example the accounts-ui-bootstrap-3 package has a blaze branch and you can already use it modifying your smart.json:
"accounts-ui-bootstrap-3": {
"git": "https://github.com/mangasocial/meteor-accounts-ui-bootstrap-3" ,
"branch": "blaze"
},
As suggested in this thread.
I am just starting with Meteor and working on an existing project. I am running into an issue with one of the packages(observatory-apollo) that's has the following line:
__meteor_bootstrap__.app.use Observatory.logger #TLog.useragent
It is complaining that __meteor_bootstrap__.app is undefined.
What is __meteor_boostrap__ exactly? I can't seem to find a description of what it is but from threads, people seem to know how to use it. I can only see it defined in boot.js, but it doesn't really tell me much...
Meteor uses connect npm module under the hood for various reasons, to serve static files, for example. __meteor_bootstrap__.app was the reference to connect app instance.
Before it was __meteor_bootstrap__.app but it changed couple of releases ago and became WebApp.connectHandlers object and is part of WebApp package.
WebApp is a standard package of Meteor, core package for building webapps. You don't usually need to add explicitly as it is a dependency of standard-app-packages.
Example of usage the connectHandlers is to inject connect middlewares in the same way as you would use any connect middleware (or some express middlewares, express is built on top of connect):
WebApp.connectHandlers
.use(connect.query())
.use(this._config.requestParser(bodyParser))
You can look at meteor-router Atmosphere package and take it as an example: https://github.com/tmeasday/meteor-router/blob/master/lib/router_server.js
More about connect: https://npmjs.org/package/connect