@croct/plug-react 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -499,21 +499,20 @@ a React component tree.
499
499
 
500
500
  The component takes the followings properties:
501
501
 
502
- | Option | Type | Required | Default Value | Description |
503
- |-------------------------|--------------|----------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
504
- | `appId` | string | Yes | None | The ID of the application you set up on Croct. |
505
- | `debug` | boolean | No | `false` | If `true`, turns on debug mode, which logs helpful messages to the console. |
506
- | `track` | boolean | No | `true` | If `true`, enables the automatic event tracking on initialization. |
507
- | `clientId` | string | No | None | The ID of the client using the application. |
508
- | `token` | string\|null | No | None | The JWT token issued by Croct. If `null`, clears any token specified on previous calls. |
509
- | `userId` | string | No | None | The ID of the user logged into the application. Internally, the SDK will issue a token using the specified ID as the subject claim of the token. The `token` and `userId` options are mutually exclusive. |
510
- | `tokenScope` | string | No | `global` | Defines how the SDK should synchronize the token across multiple tabs, see [token scopes](#token-scopes) for more details. |
511
- | `eventMetadata` | JSON | No | None | Any additional information that may be useful to include as part of the event metadata. A common use case is to record the version of the application for future reference. |
512
- | `logger` | object | No | None | A custom logger to handle log messages. By default, all logs are suppressed. |
513
- | `urlSanitizer` | function | No | None | A function to sanitize URLs that allows removing sensitive information from URLs, such as tokens, that should not be sent to the platform. |
514
- | `trackerEndpointUrl` | string | No | None | The URL of the tracker service, used by Croct's development team for testing purposes. |
515
- | `evaluationEndpointUrl` | string | No | None | The URL of the evaluation service, used by Croct's development team for testing purposes. |
516
- | `bootstrapEndpointUrl` | string | No | None | The URL of the bootstrap service, used by Croct's development team for testing purposes. |
502
+ | Option | Type | Required | Default Value | Description |
503
+ |--------------------------|--------------|----------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
504
+ | `appId` | string | Yes | None | The ID of the application you set up on Croct. |
505
+ | `debug` | boolean | No | `false` | If `true`, turns on debug mode, which logs helpful messages to the console. |
506
+ | `track` | boolean | No | `true` | If `true`, enables the automatic event tracking on initialization. |
507
+ | `clientId` | string | No | None | The ID of the client using the application. |
508
+ | `token` | string\|null | No | None | The JWT token issued by Croct. If `null`, clears any token specified on previous calls. |
509
+ | `userId` | string | No | None | The ID of the user logged into the application. Internally, the SDK will issue a token using the specified ID as the subject claim of the token. The `token` and `userId` options are mutually exclusive. |
510
+ | `tokenScope` | string | No | `global` | Defines how the SDK should synchronize the token across multiple tabs, see [token scopes](#token-scopes) for more details. |
511
+ | `eventMetadata` | JSON | No | None | Any additional information that may be useful to include as part of the event metadata. A common use case is to record the version of the application for future reference. |
512
+ | `logger` | object | No | None | A custom logger to handle log messages. By default, all logs are suppressed. |
513
+ | `urlSanitizer` | function | No | None | A function to sanitize URLs that allows removing sensitive information from URLs, such as tokens, that should not be sent to the platform. |
514
+ | `baseEndpointUrl` | string | No | None | The base URL to use for the API calls. By default, the SDK will use the production endpoint. |
515
+ | `cidAssignerEndpointUrl` | string | No | None | The URL to use for the client ID assignment. By default, the SDK will use the production endpoint. |
517
516
 
518
517
  #### Code Sample
519
518
 
@@ -758,6 +757,7 @@ These are the currently supported options:
758
757
  | Option | Type | Required | Description |
759
758
  |----------------------------|--------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
760
759
  | `apiKey` | string | Yes | The private API key of the application. This is a private key that should never be exposed to the client-side. |
760
+ | `baseEndpointUrl` | string | No | The base URL of the Evaluation API. Defaults to the production endpoint. |
761
761
  | `fallback` | JSON | No | The value returned when the evaluation fails. If not specified, the function will throw an exception in case of failures. |
762
762
  | `timeout` | number | No | The maximum evaluation time in milliseconds. Once reached, the evaluation will fail. |
763
763
  | `clientId` | string | No | A UUID v4 that uniquely identifies the client across multiple evaluations. You should generate this identifier on your server-side using a random, cryptographically secure generator and ensure it doesn't change throughout the user journey (e.g. store in cookies). If not specified, the evaluation will run in an anonymous context. |
@@ -809,6 +809,7 @@ These are the currently supported options:
809
809
  | Option | Type | Required | Description |
810
810
  |----------------------------|---------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
811
811
  | `apiKey` | string | Yes | The private API key of the application. This is a private key that should never be exposed to the client-side. |
812
+ | `baseEndpointUrl` | string | No | The base URL of the Content API. Defaults to the production endpoint. |
812
813
  | `fallback` | JSON | No | The value returned when the fetch fails. If not specified, the function will throw an exception in case of failures. |
813
814
  | `static` | boolean | No | Whether to fetch the static content. If not specified, the function will fetch the dynamic content. |
814
815
  | `timeout` | number | No | The maximum fetch time in milliseconds. Once reached, the fetch will fail. |
package/api/evaluate.d.ts CHANGED
@@ -2,6 +2,7 @@ import { EvaluationOptions as BaseOptions } from '@croct/sdk/evaluator';
2
2
  import { JsonValue } from '@croct/plug/sdk/json';
3
3
  export type EvaluationOptions<T extends JsonValue = JsonValue> = BaseOptions & {
4
4
  apiKey: string;
5
+ baseEndpointUrl?: string;
5
6
  fallback?: T;
6
7
  };
7
8
  export declare function evaluate<T extends JsonValue>(query: string, options: EvaluationOptions<T>): Promise<T>;
package/api/evaluate.js CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluate = void 0;
4
4
  const evaluator_1 = require("@croct/sdk/evaluator");
5
5
  function evaluate(query, options) {
6
- const { apiKey, fallback, ...rest } = options;
7
- const promise = (new evaluator_1.Evaluator({ apiKey: apiKey }))
6
+ const { apiKey, fallback, baseEndpointUrl, ...rest } = options;
7
+ const promise = (new evaluator_1.Evaluator({ apiKey: apiKey, baseEndpointUrl: baseEndpointUrl }))
8
8
  .evaluate(query, rest);
9
9
  if (fallback !== undefined) {
10
10
  return promise.catch(() => fallback);
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/api/evaluate.ts"],"names":[],"mappings":";;;AAAA,oDAAiF;AAQjF,SAAgB,QAAQ,CAAsB,KAAa,EAAE,OAA6B;IACtF,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;IAC5C,MAAM,OAAO,GAAG,CAAC,IAAI,qBAAS,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;SAC5C,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAe,CAAC;IAEzC,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;KACxC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAVD,4BAUC"}
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/api/evaluate.ts"],"names":[],"mappings":";;;AAAA,oDAAiF;AASjF,SAAgB,QAAQ,CAAsB,KAAa,EAAE,OAA6B;IACtF,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;IAC7D,MAAM,OAAO,GAAG,CAAC,IAAI,qBAAS,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,CAAC;SAC9E,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAe,CAAC;IAEzC,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;KACxC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAVD,4BAUC"}
@@ -4,6 +4,7 @@ import { FetchResponse } from '@croct/plug/plug';
4
4
  import { SlotContent, VersionedSlotId } from '@croct/plug/slot';
5
5
  type ServerSideOptions<T extends JsonObject> = {
6
6
  apiKey: string;
7
+ baseEndpointUrl?: string;
7
8
  fallback?: T;
8
9
  };
9
10
  export type DynamicContentOptions<T extends JsonObject = JsonObject> = Omit<BaseDynamicOptions, 'version'> & ServerSideOptions<T>;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchContent = void 0;
4
4
  const contentFetcher_1 = require("@croct/sdk/contentFetcher");
5
5
  function fetchContent(slotId, options) {
6
- const { apiKey, fallback, ...fetchOptions } = options !== null && options !== void 0 ? options : {};
6
+ const { apiKey, fallback, baseEndpointUrl, ...fetchOptions } = options !== null && options !== void 0 ? options : {};
7
7
  const [id, version = 'latest'] = slotId.split('@');
8
- const promise = (new contentFetcher_1.ContentFetcher({ apiKey: apiKey }))
8
+ const promise = (new contentFetcher_1.ContentFetcher({ apiKey: apiKey, baseEndpointUrl: baseEndpointUrl }))
9
9
  .fetch(id, version === 'latest'
10
10
  ? fetchOptions
11
11
  : { ...fetchOptions, version: version });
@@ -1 +1 @@
1
- {"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["../src/api/fetchContent.ts"],"names":[],"mappings":";;;AAAA,8DAImC;AAkBnC,SAAgB,YAAY,CACxB,MAAS,EACT,OAAyC;IAEzC,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC1D,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAA4C,CAAC;IAE9F,MAAM,OAAO,GAAG,CAAC,IAAI,+BAAc,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;SACjD,KAAK,CACF,EAAE,EACF,OAAO,KAAK,QAAQ;QAChB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAC,GAAG,YAAY,EAAE,OAAO,EAAE,OAAO,EAAC,CAC5C,CAAC;IAEN,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,OAAO,OAAO,CAAC,KAAK,CAChB,GAAG,EAAE,CAAC,CAAC;YACH,OAAO,EAAE,QAAQ;SACpB,CAAC,CACL,CAAC;KACL;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAxBD,oCAwBC"}
1
+ {"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["../src/api/fetchContent.ts"],"names":[],"mappings":";;;AAAA,8DAImC;AAmBnC,SAAgB,YAAY,CACxB,MAAS,EACT,OAAyC;IAEzC,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,YAAY,EAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC3E,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAA4C,CAAC;IAE9F,MAAM,OAAO,GAAG,CAAC,IAAI,+BAAc,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,CAAC;SACnF,KAAK,CACF,EAAE,EACF,OAAO,KAAK,QAAQ;QAChB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAC,GAAG,YAAY,EAAE,OAAO,EAAE,OAAO,EAAC,CAC5C,CAAC;IAEN,IAAI,QAAQ,KAAK,SAAS,EAAE;QACxB,OAAO,OAAO,CAAC,KAAK,CAChB,GAAG,EAAE,CAAC,CAAC;YACH,OAAO,EAAE,QAAQ;SACpB,CAAC,CACL,CAAC;KACL;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAxBD,oCAwBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug-react",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "React components and hooks to plug your React applications into Croct.",
5
5
  "author": {
6
6
  "name": "Croct",
@@ -37,8 +37,8 @@
37
37
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@croct/plug": "^0.11.0",
41
- "@croct/sdk": "^0.11.0"
40
+ "@croct/plug": "^0.11.4",
41
+ "@croct/sdk": "^0.12.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@babel/core": "^7.20.2",
@@ -29,6 +29,7 @@ describe('evaluate', () => {
29
29
  const options: EvaluationOptions = {
30
30
  apiKey: apiKey,
31
31
  timeout: 100,
32
+ baseEndpointUrl: 'https://croct.example.com',
32
33
  };
33
34
 
34
35
  const query = 'true';
@@ -39,6 +40,7 @@ describe('evaluate', () => {
39
40
 
40
41
  expect(Evaluator).toHaveBeenCalledWith({
41
42
  apiKey: options.apiKey,
43
+ baseEndpointUrl: options.baseEndpointUrl,
42
44
  });
43
45
 
44
46
  expect(mockEvaluate).toHaveBeenCalledWith(query, {
@@ -3,12 +3,13 @@ import {JsonValue} from '@croct/plug/sdk/json';
3
3
 
4
4
  export type EvaluationOptions<T extends JsonValue = JsonValue> = BaseOptions & {
5
5
  apiKey: string,
6
+ baseEndpointUrl?: string,
6
7
  fallback?: T,
7
8
  };
8
9
 
9
10
  export function evaluate<T extends JsonValue>(query: string, options: EvaluationOptions<T>): Promise<T> {
10
- const {apiKey, fallback, ...rest} = options;
11
- const promise = (new Evaluator({apiKey: apiKey}))
11
+ const {apiKey, fallback, baseEndpointUrl, ...rest} = options;
12
+ const promise = (new Evaluator({apiKey: apiKey, baseEndpointUrl: baseEndpointUrl}))
12
13
  .evaluate(query, rest) as Promise<T>;
13
14
 
14
15
  if (fallback !== undefined) {
@@ -31,6 +31,7 @@ describe('fetchContent', () => {
31
31
 
32
32
  const options: FetchOptions = {
33
33
  apiKey: apiKey,
34
+ baseEndpointUrl: 'https://croct.example.com',
34
35
  timeout: 100,
35
36
  };
36
37
 
@@ -46,6 +47,7 @@ describe('fetchContent', () => {
46
47
 
47
48
  expect(ContentFetcher).toHaveBeenCalledWith({
48
49
  apiKey: options.apiKey,
50
+ baseEndpointUrl: options.baseEndpointUrl,
49
51
  });
50
52
 
51
53
  expect(mockFetch).toHaveBeenCalledWith(slotId, {
@@ -9,6 +9,7 @@ import {SlotContent, VersionedSlotId} from '@croct/plug/slot';
9
9
 
10
10
  type ServerSideOptions<T extends JsonObject> = {
11
11
  apiKey: string,
12
+ baseEndpointUrl?: string,
12
13
  fallback?: T,
13
14
  };
14
15
 
@@ -24,10 +25,10 @@ export function fetchContent<I extends VersionedSlotId, C extends JsonObject>(
24
25
  slotId: I,
25
26
  options?: FetchOptions<SlotContent<I, C>>,
26
27
  ): Promise<Omit<FetchResponse<I, C>, 'payload'>> {
27
- const {apiKey, fallback, ...fetchOptions} = options ?? {};
28
+ const {apiKey, fallback, baseEndpointUrl, ...fetchOptions} = options ?? {};
28
29
  const [id, version = 'latest'] = slotId.split('@') as [I, `${number}` | 'latest' | undefined];
29
30
 
30
- const promise = (new ContentFetcher({apiKey: apiKey}))
31
+ const promise = (new ContentFetcher({apiKey: apiKey, baseEndpointUrl: baseEndpointUrl}))
31
32
  .fetch<SlotContent<I, C>>(
32
33
  id,
33
34
  version === 'latest'