{"_id":"@1024pix/ember-api-actions","_rev":"5-c5b8ef2345575894ba6acdcb365d82cb","name":"@1024pix/ember-api-actions","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@1024pix/ember-api-actions","version":"1.0.0","keywords":["ember-addon","api","data","request","ajax","model"],"author":{"url":"https://mike.works","name":"Mike North","email":"michael.l.north@gmail.com"},"license":"MIT","_id":"@1024pix/ember-api-actions@1.0.0","maintainers":[{"name":"alielamrani","email":"ali.elamrani@pix.fr"},{"name":"nicolas.lepage","email":"nicolas.lepage@zenika.com"},{"name":"vincenthardouin","email":"vincenthardouin@icloud.com"},{"name":"yann_bertrand","email":"npm@y.bertrand.bzh"},{"name":"pix-owner","email":"dev@pix.fr"}],"homepage":"https://github.com/1024pix/ember-api-actions","bugs":{"url":"https://github.com/1024pix/ember-api-actions/issues"},"dist":{"shasum":"fe7d630afdf5791fcde22564daec33ee2ff56e9e","tarball":"https://registry.npmjs.org/@1024pix/ember-api-actions/-/ember-api-actions-1.0.0.tgz","fileCount":12,"integrity":"sha512-zoDykjKy1oRELmnn/BRcL6oc9y66qDnOnln9vsZ0pZBbUKfaoKQnD3ZQoX9ALG3WrNXnTwMv9Lta/BOqJJEVZA==","signatures":[{"sig":"MEQCICYwrbh7AJK/zlyQPUmi57MiB7kPTdhqdQkMR0NVvjbAAiAkobTGkYOc+OP4sz8NTm6+Km6t4ORCLtOo+QLmImo4bQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25793},"ember":{"edition":"octane"},"engine":{"node":"20.13.1"},"engines":{"node":"10.* || >= 12.*"},"gitHead":"cfa6c287b048190cc1706d68f85e378d9d9d668b","scripts":{"lint":"npm run lint:ts && npm run lint:hbs","test":"ember test","build":"ember build","start":"ember server","lint:ts":"tslint --project .","prepare":"husky install","lint:hbs":"ember-template-lint .","postpublish":"ember ts:clean","prepublishOnly":"ember ts:precompile"},"_npmUser":{"name":"pix-owner","email":"dev@pix.fr"},"commitlint":{"extends":["@commitlint/config-conventional"]},"repository":{"url":"git+https://github.com/1024pix/ember-api-actions.git","type":"git"},"_npmVersion":"10.5.2","description":"Trigger remote actions that don't fit into CRUD, in your Ember.js apps","directories":{"doc":"doc","test":"tests"},"ember-addon":{"demoURL":"https://mike.works/ember-api-actions","configPath":"tests/dummy/config"},"_nodeVersion":"20.13.1","dependencies":{"ember-cli-babel":"^7.1.3","ember-cli-typescript":"^4.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"husky":"6.0.0","qunit":"2.16.0","ember-cli":"4.11.0","ember-try":"1.4.0","loader.js":"4.7.0","pretender":"^3.4.7","qunit-dom":"2.0.0","ember-data":"3.27.1","typescript":"4.2.4","@types/rsvp":"4.0.9","ember-qunit":"5.1.5","@types/ember":"3.16.14","@types/qunit":"2.11.3","ember-source":"4.11.0","ember-resolver":"8.1.0","@commitlint/cli":"8.3.6","json-typescript":"1.1.2","ember-cli-tslint":"0.1.4","ember-cli-uglify":"3.0.0","@glimmer/tracking":"^1.0.0","@types/ember-data":"3.16.25","ember-auto-import":"^2.7.2","@glimmer/component":"^1.0.0","@types/ember-qunit":"3.4.15","broccoli-asset-rev":"3.0.0","ember-cli-htmlbars":"6.2.0","ember-code-snippet":"2.4.2","jsonapi-typescript":"0.1.3","@ember/test-helpers":"2.5.0","ember-template-lint":"1.14.0","ember-cli-test-loader":"3.0.0","@commitlint/travis-cli":"8.3.6","ember-cli-github-pages":"0.2.2","tslint-config-prettier":"1.18.0","ember-cli-code-coverage":"1.0.3","ember-load-initializers":"2.1.2","@ember/optional-features":"^1.3.0","ember-source-channel-url":"3.0.0","@types/ember-test-helpers":"^1.0.16","@types/ember__test-helpers":"1.7.6","ember-cli-dependency-checker":"3.3.2","ember-cli-inject-live-reload":"2.1.0","ember-maybe-import-regenerator":"0.1.6","@commitlint/config-conventional":"8.3.6","ember-cli-typescript-blueprints":"3.0.0","ember-export-application-global":"2.0.1","ember-disable-prototype-extensions":"1.1.3"},"_npmOperationalInternal":{"tmp":"tmp/ember-api-actions_1.0.0_1715941291924_0.44523430359524974","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@1024pix/ember-api-actions","version":"1.1.0","keywords":["ember-addon","api","data","request","ajax","model"],"author":{"url":"https://mike.works","name":"Mike North","email":"michael.l.north@gmail.com"},"license":"MIT","_id":"@1024pix/ember-api-actions@1.1.0","maintainers":[{"name":"alielamrani","email":"ali.elamrani@pix.fr"},{"name":"nicolas.lepage","email":"nicolas.lepage@zenika.com"},{"name":"vincenthardouin","email":"vincenthardouin@icloud.com"},{"name":"yann_bertrand","email":"npm@y.bertrand.bzh"},{"name":"pix-owner","email":"dev@pix.fr"}],"homepage":"https://github.com/1024pix/ember-api-actions","bugs":{"url":"https://github.com/1024pix/ember-api-actions/issues"},"dist":{"shasum":"6443ae97058b6416a40eb0ded2c39d4793e08faa","tarball":"https://registry.npmjs.org/@1024pix/ember-api-actions/-/ember-api-actions-1.1.0.tgz","fileCount":12,"integrity":"sha512-H7SwUF4kM7dtve2vtFI4PrsvCwGmxuJw3sJUnZBI/bbGGgo0iyUgdbIcwn+RwNd0TTazUy/6ohyfzU5nZOzJJg==","signatures":[{"sig":"MEQCIEvYkmArTngqM9rhj2bim+2f2Vvk1fNcc8GK29bn4vRuAiAuzEdT00/5D2ubsUYA9UDtPeFu6Krtaapu7onv4brCqA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25817},"ember":{"edition":"octane"},"engine":{"node":"20.13.1"},"engines":{"node":"10.* || >= 12.*"},"gitHead":"0b34a964ea761d0f9cda37121d5cfff0fa2a8f1b","scripts":{"lint":"npm run lint:ts && npm run lint:hbs","test":"ember test","build":"ember build","start":"ember server","lint:ts":"tslint --project .","prepare":"husky install","lint:hbs":"ember-template-lint .","postpublish":"ember ts:clean","prepublishOnly":"ember ts:precompile"},"_npmUser":{"name":"pix-owner","email":"dev@pix.fr"},"commitlint":{"extends":["@commitlint/config-conventional"]},"repository":{"url":"git+https://github.com/1024pix/ember-api-actions.git","type":"git"},"_npmVersion":"10.5.2","description":"Trigger remote actions that don't fit into CRUD, in your Ember.js apps","directories":{"doc":"doc","test":"tests"},"ember-addon":{"demoURL":"https://mike.works/ember-api-actions","configPath":"tests/dummy/config"},"_nodeVersion":"20.13.1","dependencies":{"ember-cli-babel":"^7.1.3","ember-cli-typescript":"^4.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"husky":"6.0.0","qunit":"2.16.0","ember-cli":"4.11.0","ember-try":"1.4.0","loader.js":"4.7.0","pretender":"^3.4.7","qunit-dom":"2.0.0","ember-data":"3.27.1","typescript":"4.2.4","@types/rsvp":"4.0.9","ember-qunit":"5.1.5","@types/ember":"^3.16.14","@types/qunit":"2.11.3","ember-source":"4.11.0","ember-resolver":"8.1.0","@commitlint/cli":"8.3.6","json-typescript":"1.1.2","ember-cli-tslint":"0.1.4","ember-cli-uglify":"3.0.0","@glimmer/tracking":"^1.0.0","@types/ember-data":"^3.16.25","ember-auto-import":"^2.7.2","@glimmer/component":"^1.0.0","@types/ember-qunit":"3.4.15","broccoli-asset-rev":"3.0.0","ember-cli-htmlbars":"6.2.0","ember-code-snippet":"2.4.2","jsonapi-typescript":"0.1.3","@ember/test-helpers":"2.5.0","ember-template-lint":"1.14.0","ember-cli-test-loader":"3.0.0","@commitlint/travis-cli":"8.3.6","ember-cli-github-pages":"0.2.2","tslint-config-prettier":"1.18.0","ember-cli-code-coverage":"1.0.3","ember-load-initializers":"2.1.2","@ember/optional-features":"^1.3.0","ember-source-channel-url":"3.0.0","@types/ember-test-helpers":"^1.0.16","@types/ember__test-helpers":"1.7.6","ember-cli-dependency-checker":"3.3.2","ember-cli-inject-live-reload":"2.1.0","ember-maybe-import-regenerator":"0.1.6","@commitlint/config-conventional":"8.3.6","ember-cli-typescript-blueprints":"3.0.0","ember-export-application-global":"2.0.1","ember-disable-prototype-extensions":"1.1.3"},"_npmOperationalInternal":{"tmp":"tmp/ember-api-actions_1.1.0_1715957126887_0.7800739558295224","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-05-17T10:21:31.772Z","modified":"2026-08-21T13:06:22.769Z","1.0.0":"2024-05-17T10:21:32.099Z","1.1.0":"2024-05-17T14:45:27.116Z"},"bugs":{"url":"https://github.com/1024pix/ember-api-actions/issues"},"author":{"url":"https://mike.works","name":"Mike North","email":"michael.l.north@gmail.com"},"license":"MIT","homepage":"https://github.com/1024pix/ember-api-actions","keywords":["ember-addon","api","data","request","ajax","model"],"repository":{"url":"git+https://github.com/1024pix/ember-api-actions.git","type":"git"},"description":"Trigger remote actions that don't fit into CRUD, in your Ember.js apps","maintainers":[{"email":"dev@pix.fr","name":"pix-owner"},{"email":"nicolas.lepage@zenika.com","name":"nicolas.lepage"}],"readme":"# ember-api-actions\n\n[![Build Status](https://travis-ci.org/mike-north/ember-api-actions.svg?branch=master)](https://travis-ci.org/mike-north/ember-api-actions)\n[![npm version](https://badge.fury.io/js/ember-api-actions.svg)](http://badge.fury.io/js/ember-api-actions)\n[![Code Climate](https://codeclimate.com/github/mike-north/ember-api-actions/badges/gpa.svg)](https://codeclimate.com/github/mike-north/ember-api-actions)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nTrigger \"remote\" actions on ember-data resources that don't fit into typical CRUD RESTful API design.\n\nFor example, if you have restful API endpoints like\n\n```\nGET     /fruits\nPOST    /fruits\nGET     /fruits/123\nPUT     /fruits/123\nDELETE  /fruits/123\n```\n\nWhat happens if you want to consume API endpoints like these:\n\n```\nPUT    /fruits/123/ripen\nGET    /fruits/citrus\n```\n\nExample Rails API routes:\n\n**config/routes.rb**\n\n```rb\nRails.application.routes.draw do\n\n  resources :fruits do\n    member do\n      put 'ripen' to: 'fruits#ripen'\n    end\n    collection do\n      get 'citrus' to: 'fruits#citrus_index'\n    end\n  end\n\nend\n```\n\nThis is not immediately intuitive with ember-data, and these kinds of API endpoints can be found [in widely-used RESTful APIs](https://developer.github.com/v3/gists/#star-a-gist). This library aims to make it easy.\n\n## Use\n\n```sh\n# ember-cli >= 0.2.3\nember install ember-api-actions\n\n# ember-cli < 0.2.3\nember install:addon ember-api-actions\n```\n\nYou can then add these \"actions\" (not to be confused with client-side ember.js actions) to your ember-data model\n\n**app/models/fruit.js**\n\n```js\nimport DS from 'ember-data';\nimport { memberAction, collectionAction } from 'ember-api-actions';\n\nconst { attr } = DS;\n\nexport default DS.Model.extend({\n  name: attr('string'),\n  // /fruits/123/ripen\n  ripen: memberAction({ path: 'ripen' }),\n  // /fruits/citrus\n  getAllCitrus: collectionAction({\n    path: 'citrus',\n    type: 'post', // HTTP POST request\n    urlType: 'findRecord' // Base of the URL that's generated for the action\n  })\n});\n```\n\nyou can then call these functions, and they will initiate API requests and return you the promise\n\n```js\n// Pass data in, it will be sent in the POST or PUT request payload\nmyRecord.ripen({ someData: 'abc' }).then(response => {\n  // do something when the API returns a response\n});\n```\n\n### Before and After Hooks\n\nUse `before` and `after` hooks to customize the request and response. The hooks are available for both member actions and collection actions.\n\n**Before**\n\nSay you'd like to use ember-data to serialize your model, passing in only some, additional specific changes. You can do that like so:\n\n\n```js\neat: memberAction({\n  path: 'eat',\n  before(attributes) {\n    let payload = this.serialize();\n    payload.data.attributes = assign(payload.data.attributes, attributes);\n    return payload;\n  }\n})\n\n// Call it like this:\nmodel.eat({ is_eaten: true });\n\n// JSON API request payload would look something like:\n{ data: { id: '1', type: 'fruit', attributes: { name: 'apple', is_eaten: true } } }\n```\n\n**After**\n\nThe after hook receives the response payload as an argument.\n\n```js\neat: memberAction({\n path: 'eat',\n after(response) {\n   console.log(`Received response for model ${response.data.id}`);\n }\n});\n```\n\n**SerializeAndPush**\n\nYou can use the `after` hook to push into the store. We've included a helper called [`serializeAndPush`](https://github.com/mike-north/ember-api-actions/blob/master/addon/utils/serialize-and-push.ts) to do this.\n\n```js\nimport DS from 'ember-data';\nimport { memberAction, serializeAndPush } from 'ember-api-actions';\n\nexport default DS.Model.extend({\n eat: memberAction({\n   path: 'eat',\n   after: serializeAndPush\n});\n```\n\n*Warning* this implemention only works for JSON API, but it should be easy to write your own `after` hook to handle your use case. Have a look at the [implementation of `serializeAndPush`](https://github.com/mike-north/ember-api-actions/blob/master/addon/utils/serialize-and-push.ts) for an example.\n\n## Customization\n\nember-api-actions generates URLs and ajax configuration via ember-data adapters. It will identify the appropriate adapter, and call the `buildURL` and `ajaxOptions` methods to send a JSON request similar to way conventional ember-data usage works.\n\nCustomizing your adapter should customize requests sent out via this library, along with any other ember-data requests.\n\n**ember-api-actions uses the following methods on DS.Adapter**\n\n- [buildURL](http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_buildURL) - for generating an action's URL\n- [ajax](https://github.com/emberjs/data/blob/v1.13.4/packages/ember-data/lib/adapters/rest-adapter.js#L836-L859) (private) - to actually make the API request and return a promise\n\n## Installation\n\n- `git clone` this repository\n- `npm install`\n- `bower install`\n\n## Running\n\n- `ember serve`\n- Visit your app at http://localhost:4200.\n\n## Running Tests\n\n- `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions)\n- `ember test`\n- `ember test --server`\n\nMake sure to set `ALLOW_DEPRECATIONS=true` or the tests will raise\nerrors on deprecation\n\n## Building\n\n- `ember build`\n\nFor more information on using ember-cli, visit [http://ember-cli.com/](http://ember-cli.com/).\n\n![Analytics](https://ga-beacon.appspot.com/UA-66610985-1/mike-north/ember-api-actions/readme)\n","readmeFilename":"README.md"}