How to bundle AWS Cognito within Aurelia Framework - bundle

Since my previous post on another question was deleted, even though it was pretty explicit in presenting the problem (in that context), I will try again as a stand alone question.
I am trying to bundle Amazon Cognito with aurelia.json. I have followed everything I could thin of in the answers provided by jsachs and Nathan in the mentioned article, however I think something is incomplete.
{
"name": "account-components-bundle.js",
"source": {
"include": [
"**/components/account/**/*.js",
"**/components/account/**/*.{html,css}"
]
},
"dependencies": [
{
"name": "aws-sdk",
"path": "../node_modules/aws-sdk/dist",
"main": "aws-sdk.min",
"exports": "AWS"
}
],
"prepend": [
"node_modules/aws-sdk/dist/aws-sdk.min.js",
"node_modules/amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js",
"node_modules/amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js",
"node_modules/bluebird/js/browser/bluebird.core.js",
"node_modules/requirejs/require.js"
]
},
If you add only the prepend directive, au build will not throw any error, however I have no way of calling the Cognito classes.
Adding the dependencies directive in the form above will eventually bundle the package, however at page load you will get the following error (please keep in mind I am not calling anything yet within our own code):
Unhandled rejection Error: Script error for "aws-sdk/global", needed by: components/account/login
http://requirejs.org/docs/errors.html#scripterror
at makeError (https://white.dev/dist/aurelia-bundle.js:4419:17)
at HTMLScriptElement.onScriptError (https://white.dev/dist/aurelia-bundle.js:5989:36)
From previous event:
at DefaultLoader.loadModule (https://white.dev/dist/aurelia-bundle.js:14914:14)
at ViewEngine.importViewModelResource (https://white.dev/dist/aurelia-bundle.js:23006:26)
at CompositionEngine.ensureViewModel (https://white.dev/dist/aurelia-bundle.js:24276:32)
at CompositionEngine.createController (https://white.dev/dist/aurelia-bundle.js:24252:19)
at CompositionEngine._createControllerAndSwap (https://white.dev/dist/aurelia-bundle.js:24227:19)
at CompositionEngine.compose (https://white.dev/dist/aurelia-bundle.js:24313:21)
at processInstruction (https://white.dev/dist/aurelia-bundle.js:24798:32)
at Compose.bind (https://white.dev/dist/aurelia-bundle.js:24689:7)
at Controller.bind (https://white.dev/dist/aurelia-bundle.js:23196:24)
at View.bind (https://white.dev/dist/aurelia-bundle.js:21200:24)
at If._runValueChanged (https://white.dev/dist/aurelia-bundle.js:24887:19)
at If.valueChanged (https://white.dev/dist/aurelia-bundle.js:24842:31)
at If.bind (https://white.dev/dist/aurelia-bundle.js:24831:12)
From previous event:
at CompositionEngine._createControllerAndSwap (https://white.dev/dist/aurelia-bundle.js:24227:45)
at CompositionEngine.compose (https://white.dev/dist/aurelia-bundle.js:24313:21)
at TemplatingEngine.compose (https://white.dev/dist/aurelia-bundle.js:24576:38)
at Aurelia.setRoot (https://white.dev/dist/aurelia-bundle.js:13886:21)
at Object._callee$ (https://white.dev/dist/app-bundle.js:86:37)
at tryCatch (https://white.dev/dist/aurelia-bundle.js:3:27199)
at Generator.invoke [as _invoke] (https://white.dev/dist/aurelia-bundle.js:3:28901)
at Generator.t.(anonymous function) [as next] (https://white.dev/dist/aurelia-bundle.js:3:27447)
at step (https://white.dev/dist/app-bundle.js:25:44)
at https://white.dev/dist/app-bundle.js:36:29
From previous event:
at step (https://white.dev/dist/app-bundle.js:35:55)
at https://white.dev/dist/app-bundle.js:43:24
From previous event:
at Object.<anonymous> (https://white.dev/dist/app-bundle.js:22:20)
at Object.configure (https://white.dev/dist/app-bundle.js:97:25)
at https://white.dev/dist/aurelia-bundle.js:12465:29
From previous event:
at config (https://white.dev/dist/aurelia-bundle.js:12460:56)
at https://white.dev/dist/aurelia-bundle.js:12496:14
From previous event:
at bootstrap (https://white.dev/dist/aurelia-bundle.js:12495:26)
at https://white.dev/dist/aurelia-bundle.js:12482:9
at <anonymous>
From previous event:
at run (https://white.dev/dist/aurelia-bundle.js:12477:61)
at Object.<anonymous> (https://white.dev/dist/aurelia-bundle.js:12502:37)
at Object.execCb (https://white.dev/dist/aurelia-bundle.js:5947:33)
at Module.check (https://white.dev/dist/aurelia-bundle.js:5134:51)
at Module.enable (https://white.dev/dist/aurelia-bundle.js:5427:22)
at Object.enable (https://white.dev/dist/aurelia-bundle.js:5808:39)
at Module.<anonymous> (https://white.dev/dist/aurelia-bundle.js:5412:33)
at https://white.dev/dist/aurelia-bundle.js:4385:23
at each (https://white.dev/dist/aurelia-bundle.js:4310:31)
at Module.enable (https://white.dev/dist/aurelia-bundle.js:5364:17)
at Module.init (https://white.dev/dist/aurelia-bundle.js:5039:26)
at https://white.dev/dist/aurelia-bundle.js:5711:36
The moment I go further and try to extend the dependencies (not use the already compiled libraries), I get to the same old problem mentioned in the previous post.
"dependencies": [
{
"name": "lodash",
"path": "../node_modules/lodash",
"main": "index"
},
{
"name": "xmlbuilder",
"path": "../node_modules/xmlbuilder",
"main": "lib/index"
},
{
"name": "aws-sdk",
"path": "../node_modules/aws-sdk",
"main": "lib/aws",
"exports": "AWS"
}
],
This dependencies, when running au build, will lead to
File not found or not accessible: /path/to/project/node_modules/aws-sdk/lib/region_config_data.json.js. Requested by /path/to/project/node_modules/aws-sdk/lib/aws.js
{ Error: ENOENT: no such file or directory, open '/path/to/project/node_modules/aws-sdk/lib/region_config_data.json.js'
at Object.fs.openSync (fs.js:584:18)
at Object.fs.readFileSync (fs.js:491:33)
at Object.exports.readFileSync (/path/to/project/node_modules/aurelia-cli/lib/file-system.js:74:13)
at fileRead (/path/to/project/node_modules/aurelia-cli/lib/build/bundled-source.js:101:27)
at Object.context.fileRead (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:179:18)
at Object.context.load (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:370:32)
at Module.load (eval at <anonymous> (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:14:1), <anonymous>:832:29)
at Module.fetch (eval at <anonymous> (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:14:1), <anonymous>:822:66)
at Module.check (eval at <anonymous> (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:14:1), <anonymous>:854:30)
at Module.enable (eval at <anonymous> (/path/to/project/node_modules/aurelia-cli/lib/build/amodro-trace/lib/loader/Loader.js:14:1), <anonymous>:1173:22)
errno: -2,
code: 'ENOENT',
syscall: 'open',
I think this is caused by the fact that requirejs in comparison to nodejs require() may not support loading json files and it always expects the file to be a js one.
At this point in my debugging quest I am kinda stuck. Has anyone got any suggestions in how this can be achieved? I would be very grateful.
To avoid and exclude some previous questions to my approaches, I have tried to add to the bundle dependencies "amazon-cognito-identity-js" as well, in more than one form (both dist and lib files). The outcome is the same as the one above. I get stuck at json.js error.
Edit 1
I managed to clean all compile errors with the following form for aurelia.json, however the classes are not loading properly.
"bundles": [
{
"name": "app-bundle.js",
"source": {
"include": [
"**/src/main.js",
"**/src/app.js",
"**/src/environment.js",
"**/src/app.{html,css}"
]
}
},
...
{
"name": "vendor-bundle.js",
"dependencies": [
...
{
"name": "lodash",
"path": "../node_modules/lodash",
"main": "index"
},
{
"name": "xmlbuilder",
"path": "../node_modules/xmlbuilder",
"main": "lib/index"
},
{
"name": "aws-sdk",
"path": "../node_modules/aws-sdk",
"main": "dist/aws-sdk",
"exports": "AWS"
}
],
"append": [
"node_modules/amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js",
"node_modules/amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js"
]
},
...
]

Funny to give the answer myself, but hey... if it will help others...
I managed to bundle the scripts by prepending them in the aurelia-bundle.js ahead of every other scripts that need to be loaded. Please understand, that (for me), placing the scripts in any other position that the following, will end up in neither loading correctly or not loading at all.
Don't pretend this is a general solution, but hey... works for me.
Please find a more detailed history here.
{
"name": "aurelia-bundle.js",
"prepend": [
"node_modules/aws-sdk/dist/aws-sdk.min.js",
"node_modules/amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js",
"node_modules/amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js",
"node_modules/babel-polyfill/dist/polyfill.min.js",
"node_modules/whatwg-fetch/fetch.js",
"node_modules/bluebird/js/browser/bluebird.core.js",
"node_modules/aurelia-cli/lib/resources/scripts/configure-bluebird.js",
"node_modules/requirejs/require.js"
],
"dependencies": [
"aurelia-animator-css",
"aurelia-binding",
"aurelia-bootstrapper",
"aurelia-dependency-injection",
"aurelia-event-aggregator",

Related

WebStatus wont compile: The "jquery#3.4.1" library could not be resolved by the "cdnjs" provider

I have the eShopOnContainers solution here: https://github.com/dotnet-architecture/eShopOnContainers. I have been actively working on a variation of it for the last few years. I attempted to compile it this morning and the WebStatus project causes this error:
libman.json(0,0): Error LIB002: The "jquery#3.4.1" library could not be resolved by the "cdnjs" provider
I have found this: https://github.com/aspnet/LibraryManager/issues/685 and this: https://issuemode.com/issues/cdnjs/cdnjs/94570425 (updated yesterday)
So far I have tried what is suggested in the articles:
dotnet tool install -g Microsoft.Web.LibraryManager.Cli (installs version 2.1.75)
libman cache clean
libman restore
Is there anything else I can try? My Libman.json looks like this:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "jquery#3.4.1",
"destination": "wwwroot/lib/jquery/"
},
{
"provider": "unpkg",
"library": "bootstrap#4.1.3",
"files": [
"dist/css/bootstrap.css",
"dist/css/bootstrap.css.map",
"dist/css/bootstrap.min.css",
"dist/css/bootstrap.min.css.map",
"dist/js/bootstrap.js",
"dist/js/bootstrap.min.js"
],
"destination": "wwwroot/lib/bootstrap/"
}
]
}
Try this:
-Right click libman.json
Disable Client-Side libraries on build
Build the project

How to run a previously built Canvas API project in simulator/smart-display?

I am trying to clone an application, which is given in their document under canvas API section. They have given an option for sample walkthrough [https://developers.google.com/actions/interactivecanvas/sample-walkthrough]. I have followed every step but I am getting an error that my intents are not handled.
You can see the code at [github.com/actions-on-google/dialogflow-snowman-nodejs.git].
I have tried seeing all the intent handlers, Also, i have tried changing all the packages to the lastest one, as i have mentioned in the question.
I am using following packages:
{
"name": "snowman-canvas-sample-functions",
"description": "Snowman Actions on Google Interactive Canvas Sample Functions",
"license": "Apache-2.0",
"private": true,
"engines": {
"node": "8"
},
"dependencies": {
"actions-on-google": "preview",
"firebase-admin": "~5.13.1",
"firebase-functions": "^2.0.2"
},
"scripts": {
"lint": "./node_modules/.bin/eslint --fix \"**/*.js\"",
"start": "firebase serve --only functions",
"deploy": "firebase deploy --only functions",
"test": "npm run lint"
},
"devDependencies": {
"eslint": "^6.0.1",
"eslint-config-google": "^0.13.0"
}
}
i am getting "Dialogflow IntentHandler not found for intent: Welcome at Function" error in the welcome intent itself. Please assist me what should i try next.
You need to make sure your Dialogflow intent name and your Firebase Function intent handler name are the same.
From here, you'd need to implement a handler:
const { dialogflow } = require('actions-on-google')
const app = dialogflow()
app.intent('Welcome', conv => {
conv.ask('Welcome!')
})

How to update self-hosted firefox webExtension

How do I configure my self-distrubuted firefox webExtension to auto-update, I have tried following MDN update doc but still unable to update.
My web Extension is hosted on a sub-domain name like
"https://files.example.com/myfile/extension.xpi"
My updates.json file resides at the same location with my .xpi file
This is a prototype of my updates.json
{
"addons": {
"updates": [ { "version": "1.2",
"update_link": "https://files.abc.com/myfiles/extension-1.2-an+fx.xpi" },
{ "version": "1.3",
"update_link": "https://files.abc.com/myfiles/extension-1.3-an+fx.xpi" }
]
}
}
This is the gibberish I get from browser console
1535658478365 addons.update-checker WARN onUpdateCheckComplete failed
to parse update manifest: [Exception... "Update manifest is missing a
required addons property." nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame ::
resource://gre/modules/addons/AddonUpdateChecker.jsm ::
getRequiredProperty :: line 120" data: no] Stack trace:
getRequiredProperty()#resource://gre/modules/addons/AddonUpdateChecker.jsm:120
parseJSONManifest()#resource://gre/modules/addons/AddonUpdateChecker.jsm:130 onLoad()#resource://gre/modules/addons/AddonUpdateChecker.jsm:309 UpdateParser/<()#resource://gre/modules/addons/AddonUpdateChecker.jsm:241
It looks like your 'updates.json' is missing the add-on name and XPI hash. I would also test without the "+" in the file name, I think that caused me issues (Due to hosting server).
To view your add-ons UUID (ex "ADDONNAME#test.com") log into the developer hub, click edit information, then look under technical information. To generate an update_hash of your XPI file I would recommend VSCryptoHash, but any other program that generates a cryptographic hash will work.
{
"addons": {
"ADDONNAME#test.com": {
"updates": [
{ "version": "1.0.0",
"update_link": "https://files.abc.com/myfiles/extension-1.2-fx.xpi" ,
"update_hash": "sha256:blahblah" }
]
}
}
}
The console error says your manifest is missing something too. Here is an example based on mine that works.
"applications": {
"gecko": {
"id": "ADDONNAME#test.com",
"strict_min_version": "50.0",
"update_url": "https://webpage/Updatefile.json"
}
},

When I try to Submit my repo on packagist.org, I get "undefined"

The repo is template-PHP-project. When I use the Submit function on packagist.org I get a pop-up that just says "undefined".
Clearly there is something wrong with my composer.json but I don't know what. (I can run composer update without errors.) It contains the following:
{
"name": "unixnut/template-php-project",
"description": "A self-contained project that uses the Composer autoloader to load class files",
"license": "GPL",
"authors": [
{
"name": "Alastair Irvine",
"email": "alastair#plug.org.au"
}
],
"require": {},
"include-path": ["app/include", "contrib"],
"autoload": {
"psr-4": {
"XYZ\\": "app/classes/XYZ"
}
}
}
Try to use composer validate command.
I just validated your file locally, and the only error is about the license. Fix and check again.
$ composer validate
./composer.json is valid, but with a few warnings
See https://getcomposer.org/doc/04-schema.md for details on the schema
License "GPL" is not a valid SPDX license identifier, see https://spdx.org/licenses/ if you use an open license.
If the software is closed-source, you may use "proprietary" as license.

Custom repository doesn't read my composer.json?

I've forked https://github.com/jasonlewis/basset and is now trying to add my fork to my project. But it doesn't seem to read my forked composer.json file after I've run composer update, why? What am I doing wrong?
I've added this repository after require: {}:
"repositories": [
{
"type":"package",
"package": {
"name": "marwelln/basset",
"version":"master",
"source": {
"url": "https://github.com/Marwelln/basset.git",
"type": "git",
"reference":"master"
}
}
}
],
My forked composer.json looks like this (nothing is changed from the original except name):
{
"name": "marwelln/basset",
"description": "A better asset management package for Laravel.",
"keywords": ["assets", "basset", "laravel"],
"license": "BSD-2-Clause",
"authors": [
{
"name": "Jason Lewis",
"email": "jason.lewis1991#gmail.com"
}
],
"require": {
"php": ">=5.3.0",
"kriswallsmith/assetic": "1.1.*"
},
"require-dev": {
"mockery/mockery": ">=0.7.2",
"illuminate/config": "4.0.*",
"illuminate/console": "4.0.*",
"illuminate/filesystem": "4.0.*",
"illuminate/log": "4.0.*",
"illuminate/routing": "4.0.*",
"illuminate/support": "4.0.*",
"symfony/process": "2.3.*"
},
"suggest": {
"aws/aws-sdk-php": "Deploy static assets directly to your S3 buckets.",
"rackspace/php-cloudfiles": "Deploy static assets directly to your Cloud Files container."
},
"autoload": {
"psr-0": {
"Basset": "src/"
},
"classmap": [
"tests/Cases/FilterTestCase.php"
],
"files": ["src/helpers.php"]
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"minimum-stability": "dev"
}
With this, the Basset namespace isn't registered in autoload_namespace.php nor am getting "kriswallsmith/assetic": "1.1.*", but if I use the original require: { "jasonlewis/basset" : "dev-master"} it adds it just fine. What is it I'm missing?
You've done some things that are considered not the best practice with Composer.
First of all, you should try to avoid including repositories of the type "package" with all the details of where to find the stuff you need. This will become a maintenance nightmare in the long run. Packages should only be included in your composer.json if you are absolutely sure the maintainer of the software will not include a composer.json file himself. The documentation states on http://getcomposer.org/doc/04-schema.md#repositories:
package: If you depend on a project that does not have any support for composer whatsoever you can define the package inline using a package repository. You basically just inline the
composer.json object.
This case does not apply here, because you maintain the repository to be used yourself and should be able to put in a composer.json.
Now the process of forking and extending an existing library and then using that within your code is supported by Composer, but not the way you did it. First of all, you SHOULD replace the name of the vendor, because you take over that role, and your repository and the software should be distinguishable from other packages. So it is the correct thing to rename "jasonlewis/basset" into "marwelln/basset" and only use that name if you want to reference your own version.
Now the problem might be that if you forked a popular library, and are using other libraries that do require the original, you'll end up adding both packages. That's what the "replace" field is for: You can state in your own composer.json that you think your package is able to replace the original software. Some details are here: http://getcomposer.org/doc/04-schema.md#replace
I gave a detailed answer on how "replace" works here: How does the "replace" property work with composer?
In the end, I think you should do the following (and you still can change that):
Clone the original, change the composer.json to bear your own vendor name as the "name" and add a "replace" with the version of the original software you are changing. You should probably be strict about the version, because you really only replace the version you know about. If later you still know you replace a newer version, you can change the "replace" info.
Then you have to add your own repository as you did, and require the software name with your own vendor name.
You probably did most of that at some point in time, but the step with adding the replacement info is the missing link.
I changed repository to this:
"repositories": [
{
"type":"vcs",
"url": "https://github.com/Marwelln/basset"
}
],
And then used jasonlewis/basset instead of marwelln/basset. It's now working as it should.

Resources