{"_id":"@bergx/bergx-sdk","_rev":"2-75d078617c026577432c50e78ce767f7","name":"@bergx/bergx-sdk","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@bergx/bergx-sdk","version":"1.0.0","description":"A software development kit for interacting with the Bergx services. See https://www.bergx.io for more information.","main":"dist/bergx-sdk.js","types":"dist/bergx-sdk.d.ts","scripts":{"build":"tsc","test":"echo \"Error: no test specified\" && exit 1"},"keywords":["api","bergx","modules","openid","feature","switch","multi-armed","bandit","authentication","authorization"],"author":{"name":"Mason Payne","email":"mason.payne@bergx.io"},"license":"Apache-2.0","dependencies":{"@types/debug":"^4.1.5","@types/jsonwebtoken":"^8.3.8","cross-fetch":"^3.0.5","debug":"^4.1.1","jsonwebtoken":"^8.5.1"},"devDependencies":{"typescript":"^3.9.3"},"repository":{"type":"git","url":"git+https://github.com/Bergx-io/bergx-sdk-node.git"},"bugs":{"url":"https://github.com/Bergx-io/bergx-sdk-node/issues"},"homepage":"https://github.com/Bergx-io/bergx-sdk-node#readme","gitHead":"2108c7e1596ba4e6275496ea94ccec32faefec8e","_id":"@bergx/bergx-sdk@1.0.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-wqGveF/FuEDyPxAD5p900ch1AidCg/ZOir4ydrzpqbsg58yZbnhzBVOViMi4eEMkw0RE9/y9Bn8X5kRLboDEEA==","shasum":"5b879ed94f6f06fdb0da7d86989b3cd42b17b601","tarball":"https://registry.npmjs.org/@bergx/bergx-sdk/-/bergx-sdk-1.0.0.tgz","fileCount":5,"unpackedSize":19456,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgyuZxCRA9TVsSAnZWagAAxFQQAIfQ6kpRMfBOGHpcXXwZ\nWa89lDSYZwJuXFfvHPrcE9NcBL9JCZm9HQva3jaSZBpIbJm2ooOIIoLFZQZS\nz/n7gWkTDdoMAh7qLhjTzOjzZWT3HgcgeO5lcLTH6IQErgNrzNwxsEXvhVwc\nHugx8NroIn6pK+asMr5nKBwpgifTRPorb3LmvwfP7zsyus8t7gVdQu68UjAn\nWtCQUqqTJjz3Hol69L5grTRh5PK2WhNGzvPZxawNA/EVkhpjOp99/KzarlHH\ns6UmzJN3ZcZyDrpJlRlXF7MiMJyx6Uisn+PV0Hr0YPVlUYrNpjFl4KdZ4+Dk\nIT08piGKOgN+OeqTj0NJDU0kuxOZtNY6sL/6VVR7AdpWMKmWdrG8tqohubJi\nRMZMfd0RkGXTWUza52491b5hdbVFjTX2tAKVZIXTEqYFFVYMMzWtZq4oIRtw\nhyO97EzfaCrhJoiw5r7VwAEj3YAFe1CqNCV+njDwR5930JP7MNyrhnS/B21z\nAFrWiROaDGr7ikdORa2HuubX7jOyFuX8ElRWf5yB+xvJb7i6ZAD5rQbaZYP5\n9K909k/lW7h+H73907ryzWz1Mh9abBz0WmdHTV94niqAfVAQ1TiItb5HzgOX\n3z8n0ElV7R3CB8vV2SFEAOwGcttZ7AcMiQA0xo2N+OrzQQPLOADvKC7EqAol\ngsGM\r\n=6TqD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAu8ShhwSWsz2LnJdytkYGneQeSdGFIe/PvDM8/Vet1DAiEAun2PKK5Y+zXQSHC4tOBeyCyjZqkT0akWimKPYSaiPtE="}]},"_npmUser":{"name":"payne8","email":"mason@masonitestudios.com"},"directories":{},"maintainers":[{"name":"payne8","email":"mason@masonitestudios.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bergx-sdk_1.0.0_1623910001342_0.8977164189206013"},"_hasShrinkwrap":false},"1.0.1":{"name":"@bergx/bergx-sdk","version":"1.0.1","description":"A software development kit for interacting with the Bergx services. See https://www.bergx.io for more information.","main":"dist/bergx-sdk.js","types":"dist/bergx-sdk.d.ts","scripts":{"build":"tsc","test":"echo \"Error: no test specified\" && exit 1"},"keywords":["api","bergx","modules","openid","feature","switch","multi-armed","bandit","authentication","authorization"],"author":{"name":"Mason Payne","email":"mason.payne@bergx.io"},"license":"Apache-2.0","dependencies":{"@types/debug":"^4.1.5","@types/jsonwebtoken":"^8.3.8","cross-fetch":"^3.0.5","debug":"^4.1.1","jsonwebtoken":"^8.5.1"},"devDependencies":{"typescript":"^3.9.3"},"repository":{"type":"git","url":"git+https://github.com/Bergx-io/bergx-sdk-node.git"},"bugs":{"url":"https://github.com/Bergx-io/bergx-sdk-node/issues"},"homepage":"https://github.com/Bergx-io/bergx-sdk-node#readme","gitHead":"07120836a1722a9fb6a48233017f80ddfe41e5e0","_id":"@bergx/bergx-sdk@1.0.1","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-7xxB2g3TgBt0Wmf5CPkCnwHFCf+b0mQmJf5lMW3yi1StAZR/DcLxsRs/6TP/npg+x64VYaUeMIiKL6AqgRpMPg==","shasum":"c7097caf3233ddfecff2453216822b27f01c31d6","tarball":"https://registry.npmjs.org/@bergx/bergx-sdk/-/bergx-sdk-1.0.1.tgz","fileCount":5,"unpackedSize":19470,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgyuhiCRA9TVsSAnZWagAAUnEP/j4wNIZOz7jC5AkhpcQe\nOzV0SsT+XTNu6bsipBvXPY1D22O+I9Kk0iH9CUsDrSHb0dVJK8YhIxLrBPSx\nMcSxx5NjJ/T8pqRzWWuR1js/mY75K6ntYKjIpmy3p42lK0u6bG7IhGWZD95E\ndNqqyd6CAywrSZ1DSF9N6tAsXfNWwxbCZSxbbKHh2TBu0w85ShZ0GjPn8WDi\nzyzWUko+M3JqGE/BuclApdU6hVCMATNf0mrqgnyuf1SKKcy4cCK4LpLH0wRR\nsT1chQOhU25IjOxxMr6czzPRP0z0dt3WcAZ6KrlgQpriy0JpSRkSFJ1gFEBy\nXgGRI6Cfmbgv0VkeSoqUfi295yGZGMicTNVD6RoUvyCujSjwZDmvCTfHeZ1P\nPGerc0bQvIlQnSJBGbw3e3rTjhUhbRDoKrPa8coikKoVh5DVmZQBA3o6r80K\nQM1VIFsWW4zZfE+lgC9stMnvsbTEU5G1/70WP/opjsyJi/MPU6b+Pnuzp+dB\nvl6H9tnPXe2QILO+UR/OmH/ej6LHH3IcXsKYqcpzDAupAIL6eIt7ip5p05pW\nAb/07V9y65q73aooXFqyzI+bf+ifHNGmi7tKud6EJcDLyl4E38nLfGb8QRQI\njwuYgga9s7ZTXy5okPHd5k5iIbuL5i/rk1715uBoJrWIKFm/bDPKEueYdMD2\n7urV\r\n=z+aF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCsN0fq3xgCPXFRlZEm8XLksqePLVIBXXiMO3HpOzdRpgIgdbQIUTDRTnmJe5ErmJ4hpiIo5XhuStYXDitaSlRkpUA="}]},"_npmUser":{"name":"payne8","email":"mason@masonitestudios.com"},"directories":{},"maintainers":[{"name":"payne8","email":"mason@masonitestudios.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bergx-sdk_1.0.1_1623910497868_0.8439668451934275"},"_hasShrinkwrap":false}},"time":{"created":"2021-06-17T06:06:40.965Z","1.0.0":"2021-06-17T06:06:41.487Z","modified":"2022-04-04T18:28:55.784Z","1.0.1":"2021-06-17T06:14:58.017Z"},"maintainers":[{"name":"payne8","email":"mason@masonitestudios.com"}],"description":"A software development kit for interacting with the Bergx services. See https://www.bergx.io for more information.","homepage":"https://github.com/Bergx-io/bergx-sdk-node#readme","keywords":["api","bergx","modules","openid","feature","switch","multi-armed","bandit","authentication","authorization"],"repository":{"type":"git","url":"git+https://github.com/Bergx-io/bergx-sdk-node.git"},"author":{"name":"Mason Payne","email":"mason.payne@bergx.io"},"bugs":{"url":"https://github.com/Bergx-io/bergx-sdk-node/issues"},"license":"Apache-2.0","readme":"# Bergx SDK\r\n\r\nThe offical Bergx SDK for Javascript, works on browsers, mobile devices and node.js.\r\n\r\nBergx is a set of modules to get you moving quickly on your next project.\r\n\r\n* User Authentication\r\n* Authorization\r\n* Feature Switches\r\n* Advanced A/B Testing\r\n\r\n## Getting Started\r\n\r\nCreate an account here: https://www.bergx.io Just follow the quick start to create an organization and an application. You will need to create a client in order to interact with the API.\r\n\r\n```bash\r\nnpm install @bergx/bergx-sdk\r\n# or\r\nyarn add @bergx/bergx-sdk\r\n```\r\n\r\n### Usage\r\n\r\n```javascript\r\nconst bx = new BergxSDK({\r\n  clientId: '{{clientId}}',\r\n  clientSecret: '{{clientSecret}}',\r\n});\r\n\r\n// Feature Switch example\r\nconst createRes = await bx.createSwitch({\r\n\tname: \"awesome-feature\",\r\n\ttype: \"basic\",\r\n\tvalue: \"true\"\r\n});\r\nconst awesomeFeature = await bx.checkSwitch('awesome-feature', {username: 'cool guy'});\r\nconsole.log(awesomeFeature); // true\r\n```\r\n\r\n## API\r\n\r\nDocumentation of the raw api can be found here: https://documenter.getpostman.com/view/1097302/SWLmW44o?version=latest\r\n\r\nThere are four basic modules provided by the Bergx SDK, User Authentication, User Authorization, Feature Switches, and Advanced A/B testing. Each module has its own section below.\r\n\r\n### Initialization\r\n\r\n##### Creating a new Bergx instance\r\n\r\nThe SDK is provided in a single class and is initialized using the BxConfig type. Everything is Javascript or Typescript compatible.\r\n\r\n*Types:*\r\n\r\n**BxConfig Object:**\r\n\r\n| Property | Type | Required | Explanation |\r\n| --- | --- | --- | --- |\r\n| clientId | string | true | The clientId is provided from the [bergx.io](https://p01.bergx.io) console when a new client is created there. |\r\n| clientSecret | string | true | The clientSecret is provided from the [bergx.io](https://p01.bergx.io) console when a new client is created there. |\r\n| host | string | false | You can specify another provider's location as long as they implement the BergxAPI |\r\n| updateAccessTokenCallback | function: `(userSub: string, newAccessToken: string) => void` | false | Optionally, provide a callback to update your database with a user's `id` aka `sub` and a new `accessToken`. |\r\n\r\nExample:\r\n\r\n```typescript\r\ninterface BxConfig {\r\n  clientId: string;\r\n  clientSecret: string;\r\n  host?: string;\r\n  updateAccessTokenCallback?: (userSub: string, newAccessToken: string) => void;\r\n}\r\n\r\nconst bx = new BergxSDK({\r\n  clientId: '{{clientId}}',\r\n  clientSecret: '{{clientSecret}}',\r\n  host: 'https://p01.bergx.io',\r\n  updateAccessTokenCallback: (userSub: string, newAccessToken: string) => {\r\n    db.saveUser({userId: userSub, accessToken: newAccessToken});\r\n  }\r\n});\r\n```\r\n\r\nOnce the SDK has been initialized with a `clientId` and `secret` most calls will automatically authenticate. But any calls to the user profile endpoints will require `accessTokens` that are scoped to the user rather than the client. For information on how to use the **User Authentication** module refer to the example project in `./examples/`.\r\n\r\n### User Authentication/Profile\r\n\r\n*Types:*\r\n\r\n**BxUser Object:**\r\n\r\n| Property | Type | Required | Explanation |\r\n| --- | --- | --- | --- |\r\n| accessToken | string | true | The active `accessToken` for a given user. |\r\n| refreshToken | string | false | The `refreshToken` allows you to renew an expired `accessToken`. |\r\n\r\n```typescript\r\ninterface BxUser {\r\n  accessToken: string;\r\n  refreshToken: string;\r\n}\r\n```\r\n\r\n**User Object:**\r\n\r\n| Property | Type | Required | Explanation |\r\n| --- | --- | --- | --- |\r\n| claims | BxUserClaims | true | The user profile information, generally known as `claims`, associated with the user. |\r\n| organizations | string[] | true | An array of IDs for organizations the user is a member of in the Bergx Console. |\r\n\r\n```typescript\r\ninterface User {\r\n  claims: BxUserClaims;\r\n  organizations: string[];\r\n}\r\n```\r\n\r\n**BxUserClaims Object:**\r\n\r\n`BxUserClaims` is based on the OpenID Connect Standard user claims object. Please refer to the OpenID Connect Claims object documentation for more details https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims.\r\n\r\n| Property | Type | Required | Explanation |\r\n| --- | --- | --- | --- |\r\n| email | string | true | User's email. |\r\n| sub | string | true | User's id or 'sub'-scriber id. |\r\n| ... | ... | ... | ... |\r\n\r\nAll other [standard claims](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims) are supported.\r\n\r\n#### getProfile(user: BxUser): Promise<{status: string, user: User}>\r\n\r\nReturns a `status` (string) and a `User` object.\r\n\r\nExample response:\r\n```json\r\n{\r\n  \"status\": \"success\",\r\n  \"user\": {\r\n    \"claims\": {\r\n      \"email\": \"testUser@example.com\",\r\n      \"updated_at\": 1588647477,\r\n      \"preferred_username\": \"testUser\",\r\n      \"sub\": \"{{uuid}}\",\r\n      \"email_verified\": true\r\n    },\r\n    \"organizations\": []\r\n  }\r\n}\r\n```\r\n\r\nUsage:\r\n\r\n```typescript\r\nconst user = await bx.getProfile({\r\n  accessToken,\r\n  refreshToken\r\n});\r\n```\r\n\r\n#### updateProfile(user: BxUser, data: BxUserClaims)\r\n\r\nUpdates the user profile in Bergx. Requires a user's `accessToken`.\r\n\r\nExample response:\r\n```json\r\n{\r\n  \"status\": \"success\",\r\n  \"user\": {\r\n    \"claims\": {\r\n      \"email\": \"testUser@example.com\",\r\n      \"updated_at\": 1588647477,\r\n      \"preferred_username\": \"testUser\",\r\n      \"sub\": \"{{uuid}}\",\r\n      \"email_verified\": true\r\n    },\r\n    \"organizations\": []\r\n  }\r\n}\r\n```\r\n\r\nUsage:\r\n\r\n```typescript\r\nconst user = await bx.getProfile({\r\n  accessToken,\r\n  refreshToken\r\n});\r\n```\r\n","readmeFilename":"README.md"}