diff --git a/README.md b/README.md index 3a416f5..a36a14f 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ const { createPreprClient } = require('@preprio/nodejs-sdk') const prepr = createPreprClient({ token: '', // required timeout: 4000, // default value - baseUrl: 'https://cdn.prepr.io', // default value (REST API), for GraphQL API use https://graphql.prepr.io/graphql - userId: null, // optional, used for AB testing + baseUrl: 'https://graphql.prepr.io/graphql', // default value (GraphQL API), for the REST API use https://cdn.prepr.io/ + customerId: null, // optional, used for AB testing and personalization }) module.exports = { prepr } @@ -46,22 +46,23 @@ To perform API requests you can make use of our fluent builder, this is how it l const { prepr } = require('./services/prepr') const result = await prepr - .graphqlQuery(`GraphQL Query`) // https://prepr.dev/docs/graphql/v1/collection-introduction - .graphqlVariables({JSON_VARIABLE_PAYLOAD}) + .graphqlQuery(`GraphQL Query`) // https://docs.prepr.io/reference/graphql/v1/fetching-collections + .graphqlVariables({ JSON_VARIABLE_PAYLOAD }) .timeout(8000) // Override globally set timeout for request cancellation - .userId('...') // Override globally set userId for ab testing - .token('xx-xx') // Update the Token used by the SDK for example when previewing staged content + .customerId('...') // Override globally set userId for ab testing or personalization + .token('xx-xx') // Update the Token used by the SDK for example when previewing staged content .fetch() // Fetch the collections ``` Let's request all Pages in our Prepr environment. ```js - // We created this earlier - const {prepr} = require('./services/prepr') - - const result = await prepr - .graphqlQuery(`{ +// We created this earlier +const { prepr } = require('./services/prepr') + +const result = await prepr + .graphqlQuery( + `{ Pages { items { _id @@ -69,11 +70,12 @@ Let's request all Pages in our Prepr environment. summary } } - }`) - .fetch() + }`, + ) + .fetch() ``` -To help you querying our API we've added multiple examples to our [GraphQL Reference](https://prepr.dev/docs/graphql/v1/introduction). +To help you querying our API we've added multiple examples to our [GraphQL Reference](https://docs.prepr.io/reference/graphql/v1/fetching-collections). ## Usage REST API @@ -86,12 +88,12 @@ const { prepr } = require('./services/prepr') const result = await prepr .path('/publications') // request path `https://cdn.prepr.io/publications` .query({ - 'model' : { - 'eq' : 'x-x-x-x-x' - } - }) // query data https://prepr.dev/docs/rest/v1/introduction - .timeout(8000) // Override globally set timeout for request cancellation - .userId('...') // Override globally set userId for ab testing + model: { + eq: 'x-x-x-x-x', + }, + }) // query data https://docs.prepr.io/reference/rest/v1/introduction + .timeout(4000) // Override globally set timeout for request cancellation + .customerId('...') // Override globally set customerID for ab testing and personalization .token('xx-xx') // Update the Token used by the SDK for example when previewing staged content .sort('created_at') // Sort data .limit(8) // Limit the amount collections being returned @@ -99,12 +101,12 @@ const result = await prepr .fetch() // Fetch the collections ``` -To help you querying our API we've added multiple examples to our [REST Reference](https://prepr.dev/docs/rest/v1/introduction). +To help you to query our API we've added multiple examples to our [REST Reference](https://docs.prepr.io/reference/rest/v1/introduction). ## Reach out to us You have questions about how to use this library or the Prepr API? Contact our support team at support@prepr.io or join us on [Slack](https://slack.prepr.io). -**You found a bug or want to propose a feature?**. +**You found a bug or want to propose a feature?**. File an issue here on GitHub. Don't share any authentication info in any code before sharing it. diff --git a/lib/index.d.ts b/lib/index.d.ts index 4bf8f94..794712f 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,9 +1,9 @@ declare module '@preprio/nodejs-sdk' { interface ClientOptions { - token?: string; - baseUrl?: string; - timeout?: number; - userId?: string; + token?: string + baseUrl?: string + timeout?: number + customerId?: string } class PreprClient { @@ -11,19 +11,19 @@ declare module '@preprio/nodejs-sdk' { token: string = null, baseUrl: string = 'https://cdn.prepr.io', timeout: number = 4000, - userId: string = null, - }: ClientOptions); + customerId: string = null, + }: ClientOptions) - public userId(userId: string): this; - public timeout(milliseconds: number): this; - public query(query: Record): this; - public sort(field: string): this; - public limit(limit: number): this; - public skip(skip: number): this; - public path(path: string): this; - public graphqlQuery(graphQLQuery: string): this; - public graphqlVariables(graphQLVariables: Record): this; - public async fetch(options = {}): Promise>; + public customerId(customerId: string): this + public timeout(milliseconds: number): this + public query(query: Record): this + public sort(field: string): this + public limit(limit: number): this + public skip(skip: number): this + public path(path: string): this + public graphqlQuery(graphQLQuery: string): this + public graphqlVariables(graphQLVariables: Record): this + public async fetch(options = {}): Promise> } - export function createPreprClient(options: ClientOptions): PreprClient; + export function createPreprClient(options: ClientOptions): PreprClient } diff --git a/lib/index.js b/lib/index.js index 4f09610..529ec70 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,5 @@ const fetch = require('node-fetch') const AbortController = require('abort-controller') -const murmurhash = require('murmurhash') const qs = require('qs') const createPreprClient = options => new PreprClient(options) @@ -10,23 +9,13 @@ class PreprClient { token = null, baseUrl = 'https://cdn.prepr.io', timeout = 4000, - userId = null, customerId = null, }) { this._token = token this._baseUrl = baseUrl this._timeout = timeout this._path = null - this._hasAbTesting = false this._customerId = customerId - - userId && this._hashUserId(userId) - } - - userId(userId) { - this._hashUserId(userId) - - return this } customerId(customerId) { @@ -111,12 +100,6 @@ class PreprClient { Object.assign(headers, options.headers) - if (this._hasAbTesting) { - Object.assign(headers, { - 'Prepr-ABTesting': this._userId, - }) - } - if (this._customerId) { Object.assign(headers, { 'Prepr-Customer-Id': this._customerId, @@ -167,14 +150,6 @@ class PreprClient { } } - _hashUserId(userId) { - const hashValue = murmurhash.v3(userId, 1) - const ratio = hashValue / Math.pow(2, 32) - - this._userId = parseInt(ratio * 10000) - this._hasAbTesting = true - } - _queryStringBuilder({ query, sort, limit, skip }) { if (!query) { query = [] diff --git a/package.json b/package.json index 67d8b30..28473ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@preprio/nodejs-sdk", - "version": "1.1.1", + "version": "2.0.0", "description": "The official Prepr SDK for Node.js", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -25,7 +25,6 @@ "homepage": "https://github.com/preprio/nodejs-sdk#readme", "dependencies": { "abort-controller": "^3.0.0", - "murmurhash": "^2.0.0", "node-fetch": "^2.6.1", "qs": "^6.9.6" },