Code Monkey home page Code Monkey logo

openbadges-bakery's Introduction

openbadges-bakery Build Status

An OpenBadges image baking library that works with PNGs and SVGs

Install

$ npm install openbadges-bakery

CLI Usage

Baking

$ oven [--in ./path/to/image.svg] [--out ./path/to/baked-image.svg] <data>

If --out is not set, the baked image will print to stdout.

The input file can also be piped into stdin.

$ oven <data> <  ./path/to/image.png  > ./path/to/baked-image.png

Extracting

$ oven [--in path/to/image.png] --extract

Same as above, you can also pipe a file to stdin. The data will be printed to stdout.

Libary Usage

bakery.bake(options callback);

Bakes some data into an image.

Options are

  • image: either a buffer or a stream representing the PNG or SVG to bake
  • assertion: assertion to save into the image (optional)
  • signature: JSON Web Signature representing a signed OpenBadges assertion (optional)

You must pass either assertion or signature

callback has the signature function(err, imageData)

bakery.extract(image, callback)

Gets the raw data from the badge. This could be a URL, assertion in JSON format or a signature.

callback has the signature function (err, data)

bakery.debake(image, callback);

bakery.getAssertion(image, callback);

Gets the assertion from the badge. If the assertion is remote, this will require an HTTP request. If the assertion is baked into the badge, either directly or as part of a signature, this will pull the local copy.

image should be a stream or a buffer

callback has the signature function (err, object) where object is expected to be a OpenBadges assertion.

openbadges-bakery's People

Contributors

auralon avatar brianloveswords avatar cmcavoy avatar potch avatar simonwex avatar stenington avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openbadges-bakery's Issues

Errors when running "npm run test"

npm ERR! Darwin 16.6.0
npm ERR! argv "/.nvm/versions/node/v6.10.1/bin/node" ".nvm/versions/node/v6.10.1/bin/npm" "run" "test"
npm ERR! node v6.10.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test: `tap test/*.js`
npm ERR! Exit status 3
ok test/stream-type-check.test.js ....................... 8/8
ok test/svg.test.js ................................... 15/15
total ................................................. 25/28

not ok

TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please reach out to [email protected].

(Message COC001)

Baked badges don't throw errors

Looks like this line should be in a callback to png.inject or something, because it's false even for baked badges. bin/oven does not rebake them, nor does it report any errors.

Wiki changes

FYI: The following changes were made to this repository's wiki:

  • defacing spam has been removed

  • the wiki has been disabled, as it was not used

These were made as the result of a recent automated defacement of publically writeable wikis.

can't we use "openbadges-bakery" in Node version above 0.10.30

Hi Team,

We can't use "openbadges-bakery" module in higher version of node like above v6.

Please help me i am facing issue from last 3 days. Its working fine with version 0.10.30. but if i am using v7.10.0 then it is not working .
Error msg :
on\node_modules\bitwriter\index.js:357
var len = this.length;
^

TypeError: Method get TypedArray.prototype.length called on incompatible receive
r [object Object]
at BitWriter.get length [as length] ()
at BitWriter.makeArrayLike [as _makeArrayLike] (C:\Users\aporwal\Documents\V
isual Studio 2015\Projects\CrudOperation\CrudOperation\node_modules\bitwriter\in
dex.js:357:17)
at BitWriter.setupBuffer (C:\Users\aporwal\Documents\Visual Studio 2015\Proj
ects\CrudOperation\CrudOperation\node_modules\bitwriter\index.js:72:8)
at BitWriter.initialize (C:\Users\aporwal\Documents\Visual Studio 2015\Proje
cts\CrudOperation\CrudOperation\node_modules\bitwriter\index.js:58:8)
at new BitWriter (C:\Users\aporwal\Documents\Visual Studio 2015\Projects\Cru
dOperation\CrudOperation\node_modules\bitwriter\index.js:10:19)
at BitWriter (C:\Users\aporwal\Documents\Visual Studio 2015\Projects\CrudOpe
ration\CrudOperation\node_modules\bitwriter\index.js:9:12)
at new Output (C:\Users\aporwal\Documents\Visual Studio 2015\Projects\CrudOp
eration\CrudOperation\node_modules\streampng\lib\chunks\base.js:161:17)
at constructor.outputPrepare [as _outputPrepare] (C:\Users\aporwal\Documents
\Visual Studio 2015\Projects\CrudOperation\CrudOperation\node_modules\streampng
lib\chunks\base.js:155:13)
at constructor.makeBuffer [as _startOutput] (C:\Users\aporwal\Documents\Visu
al Studio 2015\Projects\CrudOperation\CrudOperation\node_modules\streampng\lib\c
hunks\international-text.js:38:21)
at constructor.out (C:\Users\aporwal\Documents\Visual Studio 2015\Projects\C
rudOperation\CrudOperation\node_modules\streampng\lib\chunks\international-text.
js:23:19)

SVG badges

@potch is working on it AND I EXPECT A PR BY END OF DAY TUESDAY ๐Ÿ ๐ŸŠ

`extract` should listen for errors

In the backpack we're seeing errors originating here end up bringing down the server with

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
TypeError: Signature mismatch, not a PNG
    at StreamPng.readSignature [as _readSignature] (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:156:29)
    at StreamPng.process (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:183:17)
    at StreamPng.write (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:85:8)
    at StreamPng.end (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:104:18)
    at new StreamPng (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:38:12)
    at StreamPng (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/node_modules/streampng/index.js:18:12)
    at Object.extract (/Users/mlarsson/Work/checkouts/openbadges/node_modules/openbadges-bakery/index.js:50:15)
    at extractAssertionUrl (/Users/mlarsson/Work/checkouts/openbadges/controllers/backpack.js:409:16)
    at async.iterator.fn (/Users/mlarsson/Work/checkouts/openbadges/node_modules/async/lib/async.js:579:34)
    at async.waterfall.wrapIterator (/Users/mlarsson/Work/checkouts/openbadges/node_modules/async/lib/async.js:495:34)

This happens when uploading a bad badge, for example, when reporting an error to the user would be better. However, the error isn't thrown by streampng, it's emitted meaning it can't be intercepted from the backpack code (or at least I don't know how to).

My thought is that the bakery should listen for errors and then throw them so code using the bakery can catch them if it wants to. Thoughts @brianloveswords?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.