Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/models/api-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ApiCredentialModel extends Model {

/** @dates */
@attr('date') last_used_at;
@attr('date') expires_at;
@attr('expiration') expires_at;
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;
Expand Down
50 changes: 50 additions & 0 deletions addon/transforms/expiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Transform from '@ember-data/serializer/transform';

/**
* Transform for expiration attributes which the API accepts as either a
* datetime or a relative expiration string ('never', 'immediately',
* 'in 1 hour', 'in 24 hours', ...) resolved server side.
*
* Deserializes like the standard `date` transform so date reads keep
* returning `Date` instances, but serializes strings untouched — the
* `date` transform serializes any non-Date value to `null`, which
* silently discards a selected relative expiration.
*/
export default class ExpirationTransform extends Transform {
deserialize(serialized) {
const type = typeof serialized;

if (type === 'string') {
let offset = serialized.indexOf('+');

if (offset !== -1 && serialized.length - 5 === offset) {
offset += 3;
return new Date(serialized.slice(0, offset) + ':' + serialized.slice(offset));
}

return new Date(serialized);
}

if (type === 'number') {
return new Date(serialized);
}

if (serialized === null || serialized === undefined) {
return serialized;
}

return null;
}

serialize(deserialized) {
if (typeof deserialized === 'string') {
return deserialized;
}

if (deserialized instanceof Date && !isNaN(deserialized)) {
return deserialized.toISOString();
}

return null;
}
}
1 change: 1 addition & 0 deletions app/transforms/expiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/dev-engine/transforms/expiration';
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
const { buildEngine } = require('ember-engines/lib/engine-addon');
const { name } = require('./package');

// The engine's own test suite (`ember test` run from this package) needs the
// engine modules loaded eagerly so the dummy app can resolve them; hosts always
// get the lazy engine. Same pattern as the fleetops engine.
const isRunningOwnTests = process.argv.includes('test') && process.cwd() === __dirname;

module.exports = buildEngine({
name,

lazyLoading: {
enabled: true,
enabled: !isRunningOwnTests,
},

included(app) {
this._super.included.apply(this, arguments);

// Configure ember-prism for the addon
app.options = app.options || {};
app.options['ember-prism'] = {
components: ['json', 'javascript'],
plugins: ['line-highlight', 'line-numbers'],
};
// Configure ember-prism for the addon; skipped for the eager dummy-app
// test build, where ember-cli-node-assets registers the component and
// plugin imports without funneling the files in and the vendor concat fails
if (!isRunningOwnTests) {
app.options = app.options || {};
app.options['ember-prism'] = {
components: ['json', 'javascript'],
plugins: ['line-highlight', 'line-numbers'],
};
}
},

isDevelopingAddon() {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-proposal-decorators": "^7.23.2",
"@ember/legacy-built-in-components": "^0.4.2",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^3.2.0",
"@embroider/test-setup": "^3.0.2",
Expand Down Expand Up @@ -91,6 +92,7 @@
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-qunit": "^8.0.1",
"loader.js": "^4.7.0",
"prismjs": "^1.29.0",
"prettier": "^3.0.3",
"qunit": "^2.20.0",
"qunit-dom": "^2.0.0",
Expand Down
77 changes: 51 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading