Skip to content

Commit

Permalink
V2 format
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Nov 26, 2023
1 parent 57e7285 commit 998bc85
Show file tree
Hide file tree
Showing 73 changed files with 3,101 additions and 1,718 deletions.
27 changes: 6 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
# compiled output
/dist/
/declarations/
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules/
node_modules/

# misc
/.env*
/.pnp*
/.eslintcache
/coverage/
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

# broccoli-debug
/DEBUG/
.env*
.pnpm-debug.log
npm-debug.log*
yarn-error.log
35 changes: 0 additions & 35 deletions .npmignore

This file was deleted.

15 changes: 0 additions & 15 deletions app/initializers/simple-auth-token.js

This file was deleted.

25 changes: 0 additions & 25 deletions ember-cli-build.js

This file was deleted.

9 changes: 9 additions & 0 deletions ember-simple-auth-token/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# unconventional js
/blueprints/*/files/

# compiled output
/declarations/
/dist/

# misc
/coverage/
File renamed without changes.
12 changes: 12 additions & 0 deletions ember-simple-auth-token/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# The authoritative copies of these live in the monorepo root (because they're
# more useful on github that way), but the build copies them into here so they
# will also appear in published NPM packages.
/LICENSE.md
/README.md

# compiled output
/declarations
/dist

# npm/pnpm/yarn pack output
*.tgz
9 changes: 9 additions & 0 deletions ember-simple-auth-token/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# unconventional js
/blueprints/*/files/

# compiled output
/declarations/
/dist/

# misc
/coverage/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions ember-simple-auth-token/addon-main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const { addonV1Shim } = require('@embroider/addon-shim');

module.exports = addonV1Shim(__dirname);
15 changes: 15 additions & 0 deletions ember-simple-auth-token/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
"@babel/plugin-transform-class-static-block",
[
"babel-plugin-ember-template-compilation",
{
"targetFormat": "hbs",
"transforms": []
}
],
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-transform-class-properties"
]
}
89 changes: 89 additions & 0 deletions ember-simple-auth-token/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "@triptyk/ember-simple-auth-token",
"version": "5.3.5",
"description": "An authenticator and authorizer for Ember Simple Auth that is compatible with token-based authentication like JWT in Ember CLI applications.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "rollup --config",
"deploy": "ember build -prod && ember github-pages:commit --message \"Deploy gh-pages from commit $(git rev-parse HEAD)\" && git push origin gh-pages:gh-pages",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:css": "stylelint \"**/*.css\"",
"lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
"lint:hbs": "ember-template-lint .",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"prepack": "rollup --config",
"start": "rollup --config --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"test:ember": "ember test",
"test:ember-compatibility": "ember try:each",
"test:one": "ember try:one"
},
"repository": "https://github.com/fenichelar/ember-simple-auth-token",
"author": {
"name": "Alec Fenichel"
},
"license": "MIT",
"dependencies": {
"@babel/core": "^7.23.2",
"@embroider/addon-shim": "^1.8.6",
"ember-simple-auth": "~6.0.0"
},
"devDependencies": {
"@babel/core": "^7.23.2",
"@babel/plugin-proposal-decorators": "^7.23.2",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/plugin-transform-class-static-block": "^7.22.11",
"@babel/runtime": "^7.23.2",
"@embroider/addon-dev": "^4.1.1",
"@rollup/plugin-babel": "^6.0.4",
"babel-plugin-ember-template-compilation": "^2.2.1",
"concurrently": "^8.2.2",
"rollup": "^4.3.0",
"rollup-plugin-copy": "^3.5.0"
},
"fastbootDependencies": [
"buffer",
"node-fetch"
],
"keywords": [
"ember-addon",
"token",
"jwt",
"auth",
"authentication",
"authorization"
],
"peerDependencies": {
"ember-source": ">= 4.0.0"
},
"engines": {
"node": ">= 18"
},
"ember": {
"edition": "octane"
},
"ember-addon": {
"app-js": {},
"main": "addon-main.cjs",
"type": "addon",
"version": 2
},
"volta": {
"node": "18.18.2"
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js",
"./addon-main.js": "./addon-main.cjs"
},
"files": [
"addon-main.cjs",
"dist"
]
}
72 changes: 72 additions & 0 deletions ember-simple-auth-token/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Addon } from '@embroider/addon-dev/rollup';
import { babel } from '@rollup/plugin-babel';
import copy from 'rollup-plugin-copy';

const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),

plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
// By default all your JavaScript modules (**/*.js) will be importable.
// But you are encouraged to tweak this to only cover the modules that make
// up your addon's public API. Also make sure your package.json#exports
// is aligned to the config here.
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
addon.publicEntrypoints(['**/*.js', 'index.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'components/**/*.js',
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
]),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
extensions: ['.js', '.gjs'],
}),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// Ensure that .gjs files are properly integrated as Javascript
addon.gjs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),

// Copy Readme and License into published package
copy({
targets: [
{ src: '../README.md', dest: '.' },
{ src: '../LICENSE.md', dest: '.' },
],
}),
],
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EmberObject from '@ember/object';
import { getOwner } from '@ember/application';
import fetch from 'fetch';
import { Promise, reject, resolve } from 'rsvp';
import { isEmpty } from '@ember/utils';
import Base from 'ember-simple-auth/authenticators/base';
Expand Down Expand Up @@ -55,13 +54,12 @@ export default class TokenAuthenticator extends Base {
@param {Object} headers Headers to send with the authentication request
@return {Promise} Promise that resolves when an auth token is successfully acquired from the server and rejects otherwise
*/
authenticate(credentials, headers) {
return this.makeRequest(this.serverTokenEndpoint, credentials, {
async authenticate(credentials, headers) {
const response = await this.makeRequest(this.serverTokenEndpoint, credentials, {
...this.headers,
...headers,
}).then((response) => {
return response.json;
});
return response.json;
}

/**
Expand All @@ -81,7 +79,7 @@ export default class TokenAuthenticator extends Base {
@param {Object} headers Additional headers that will be sent to server
@return {Promise} Promise that resolves when the request is successfully and rejects otherwise
*/
makeRequest(url, data, headers) {
async makeRequest(url, data, headers) {
return fetch(url, {
method: 'POST',
headers: {
Expand Down
Loading

0 comments on commit 998bc85

Please sign in to comment.