{"id":16430901,"url":"https://github.com/abalad/ngx-sails-io","last_synced_at":"2025-02-25T09:46:09.720Z","repository":{"id":84049836,"uuid":"170154296","full_name":"abalad/ngx-sails-io","owner":"abalad","description":"An Angular module for connecting SailsJs backend through SocketIO.","archived":false,"fork":false,"pushed_at":"2024-08-26T00:58:39.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-08T00:24:20.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abalad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-11T15:39:38.000Z","updated_at":"2024-08-26T00:58:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"d93c34b6-52fe-4d95-b81c-cf80cbd44de8","html_url":"https://github.com/abalad/ngx-sails-io","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abalad%2Fngx-sails-io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abalad%2Fngx-sails-io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abalad%2Fngx-sails-io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abalad%2Fngx-sails-io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abalad","download_url":"https://codeload.github.com/abalad/ngx-sails-io/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240645257,"owners_count":19834392,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T08:28:41.303Z","updated_at":"2025-02-25T09:46:09.666Z","avatar_url":"https://github.com/abalad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ngx-sails-io\n[![npm version](https://badge.fury.io/js/ngx-sails-socketio.svg)](https://badge.fury.io/js/ngx-sails-socketio)\n[![Build Status](https://travis-ci.org/burntblark/ngx-sails-socketio.svg?branch=master)](https://travis-ci.org/burntblark/ngx-sails-socketio)\n[![Coverage Status](https://coveralls.io/repos/github/burntblark/ngx-sails-socketio/badge.svg?branch=master\u0026cacheBuster=1)](https://coveralls.io/github/burntblark/ngx-sails-socketio?branch=master)\n\nAn Angular module for connecting to your SailsJs Backend/API through SocketIO.\n\n## Installation\n\n ```bash\n npm i ngx-sails-io\n ```\n\n## Usage\n\nAdd `SailsModule` to your application module.\n\n ```ts\n // Override options to configure connection to your sailsjs backend\n const options: SailsOptions = {\n    url: \"ws://127.0.0.1:1337\",\n    prefix: \"/api\", // Optional uri prefix\n    environment: SailsEnvironment.DEV,\n    query: \"__sails_io_sdk_version=0.11.0\u0026__sails_io_sdk_platform=windows\u0026__sails_io_sdk_language=javascript\",\n    reconnection: true,\n    autoConnect: false\n};\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    SailsModule.forRoot(options, [AuthInterceptor,])\n    ...\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\n\nexport class AppModule { }\n ```\n\nAn implementation of the AuthInterceptor class\n\n ```ts\n@Injectable()\nexport class AuthInterceptor implements SailsInterceptorInterface {\n\n    constructor(private router: Router, private jobs: JobsService) {\n    }\n\n    intercept(request: SailsRequestOptions, next: SailsInterceptorHandlerInterface): Observable\u003cSailsResponse\u003e {\n        request.clone({\n            headers: request.headers.set(\"Authorization\", [token]) // Replace [token] with your auth token\n        });\n        const response = next.handle(request);\n\n        return response.map(res =\u003e {\n            if (res.getStatusCode() === 401) {\n              // handle unauthorised request.\n            }\n            return res;\n        });\n    }\n}\n ```\n\nInject the `Sails` into your components/services and instatiate classes specific to your objective.\n\n ```ts\nclass ExampleComponent implements OnInit {\n\n  data: any;\n\n  constructor(private sails: SailsClient) { }\n\n  ngOnInit() {\n    const req = new SailsRequest(this.sails);\n    req.get('/model/action').subscribe(res =\u003e {\n      this.data = res.getBody();\n    });\n  }\n\n}\n ```\n\n## API\n\n### class SailsRequest\n\nMakes a request for a resource to the configured sails server. Has methods that maps to the various supported RESTful API verbs.\n\n#### Methods\n\n* get(url: `string`): `Observable\u003cSailsResponse\u003e`\n* post(url: `string`, data: `any`): `Observable\u003cSailsResponse\u003e`\n* put(url: `string`, data: `any`): `Observable\u003cSailsResponse\u003e`\n* patch(url: `string`, body: `any`): `Observable\u003cSailsResponse\u003e`\n* delete(url: `string`): `Observable\u003cSailsResponse\u003e`\n\n### class SailsSubscription\n\nA class for subscribing to resourceful Pub-Sub events emitted from a sailsjs backend.\n\n#### Methods\n\n* on(eventName: `string`): `Observable\u003cSailsEvent\u003e`\n* off(eventName: `string`): `Observable\u003cSailsEvent\u003e`\n\n#### Example(s)\n\n*Under construction*\n\n### class SailsEvent\n\nA class representing an event on a resource from the server. This follows the structure as described in the sailsjs Pub-Sub event documentation.\n\n### class SailsQuery\n\nA class for querying records from the server. Similar to `SailsRequests` but has methods mapping actions as detail on waterline api used by sailsjs.\n\n### interface SailsInterceptorInterface\n\nAn interface to construct an iterceptor to use for requests.\n\n#### Example(s)\n\nAn authentication interceptor to set the *Authorization* header on every request.\n\n```ts\n@Injectable()\nexport class AuthInterceptor implements SailsInterceptorInterface {\n\n    constructor(private router: Router) {\n    }\n\n    intercept(request: SailsRequestOptions, next: SailsInterceptorHandlerInterface): Promise\u003cSailsResponse\u003e {\n        request.clone({\n            headers: request.headers.set(\"Authorization\", token)\n        });\n        \n        const response = next.handle(request);\n\n        return response.then(res =\u003e {\n            if (res.getStatusCode() === 401) {\n                this.router.navigateByUrl(\"login\");\n            }\n            return res;\n        });\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabalad%2Fngx-sails-io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabalad%2Fngx-sails-io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabalad%2Fngx-sails-io/lists"}