-
Notifications
You must be signed in to change notification settings - Fork 9
INTER-1488: Migrate SDK to APIv4 #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Switch base URLs to APIv4 (`https://{region}.api.fpjs.io/v4`) and add
`apiVersion` handling in URL builder.
- Use `Authorization: Bearer <secret-api-key>` only. Remove custom
header and query api authorization.
- Event API renamed and updated. Use `event_id` instead of `request_id`.
Also use `PATCH` for event update instead of `PUT` method.
- Add new examples, mocked responses, and update `sync.sh` script.
- README reworked for v4
- Package renamed to `@fingerprint/fingerprint-server-sdk`. Updated
description and subpackages (example).
- Regenerated types and OpenAPI schema.
- Updated unit and mock tests for v4 URLs.
BREAKING CHANGES:
- Only **Bearer auth** is supported; query and custom-header API-key
modes are removed. `AuthenticationMode` option is deleted.
- Event endpoint and signatures changes:
- Use `client.getEvent(eventId)` instead of `requestId`
Related-Task: INTER-1488
Remove `Accept: application/json` testing header for `updateEvent` function. Related-Task: INTER-1488
Fix updateEventTests test expected method to `PATCH`. Related-Task: INTER-1488
Removed unnecessary commented line. Related-Task: INTER-1488
Expands `searchEvents` JSDoc with new filters. Also its align parameter names.
Removes `example/getVisitorHistory.mjs` file because it's not a different endpoint anymore. Related-Task: INTER-1488
Add `fingerprint-server-sdk-smoke-tests` to changeset ignore list. Related-Task: INTER-1488
Explicitly mention about package name change in changeset file. Related-Task: INTER-1488
Use correct `patch` method instead of `put` for updating an event. Related-Task: INTER-1488
Replace strict `response.status === 200` checks with `response.ok` in fetch handlers. Related-Task: INTER-1488
Added a new `callApi()` function to handle request building and `fetch` usage in one place. Replaced all direct `fetch` calls with `callApi`. Introduced `defaultHeaders` options to the client, it's include `Authorization` header and allow extra headers and override of `Authorization` header. Made `region` optional in `GetRequestPathOptions` and it's default to `Region.Global` in `getRequestPath` function. Related-Task: INTER-1488
Remove `isEmptyValue` helper function and use direct `== null` checks to skip `undefined` or `null` values. Related-Task: INTER-1488
Use correct `EVENT_ID` placeholder for the example `.env.example` dotenv file. Related-Task: INTER-1488
Add `IsNever` and `NonNeverKeys` utility types to filter out `never` type keys. Introduce and export `AllowedMethod` that excludes specific `parameters` and any `never` type methods. Use this `AllowedMethod` type for `GetRequestPathOptions` type and `getRequestPath` functions. Update related signatures. Related-Task: INTER-1488
Use `options.method.toUpperCase()` when calling `fetch` to ensure standard HTTP method casing and avoid test fails. Change `AllowedMethod` to make a string literal union. Related-Task: INTER-1488
Extend `callApi` to accept an optional `body?: BodyInit` and forward it to `fetch`. Fix `updateEvent` to send `body`. Related-Task: INTER-1488
Removed unnecessary visitor detail tests. Related-Task: INTER-1488
Fix missing quote for `linked_id` in `searchEvents.mjs` example file. Related-Task: INTER-1488
Removed redundant `await` keyword in `callApi` function. Related-Task: INTER-1488
Centralize response parsing and error handling in `callApi` function. Throw consistent `SdkError`, `RequestError`, or `TooManyRequestsError` depends on the case. Added `SuccessJsonOrVoid<Path, Method>` to automatically resolve the potential/correct return type for success responses. Simplify all public methods. Related-Task: INTER-1488
Removed `handleErrorResponse` and moved all error logic into `callApi`. Exported `isErrorResponse` to detect valid error payloads. Added `createResponse` helper for creating mock Response object with headers. Related-Task: INTER-1488
Fixes webhook example and description in the `readme.md` file. Related-Task: INTER-1488
Use `Event` type instead of duplicated `EventsGetResponse` type. Update sealedResults snapshot and example base64 sealed result value. Fix reference links. Related-Task: INTER-1488
Removes unnecessary `ErrorJson` type from the project. Related-Task: INTER-1488
🦋 Changeset detectedLatest commit: 2eb7507 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage report
Test suite run success74 tests passing in 10 suites. Report generated by 🧪jest coverage report action from 2eb7507 Show full coverage report
|
Revert `package.json` version field to old value for fixing changeset issue. Related-Task: INTER-1488
Removes unused `responseUtils.ts` file from the project. Related-Task: INTER-1488
Increases test coverage for `serverApiClient`. Related-Task: INTER-1488
Removes `utils.ts` file and move it to `serverApiClient` file. Related-Task: INTER-1488
Make changes for `throws SdkError` tests in `serverApiClientTests` file to test `toError` functionality. Related-Task: INTER-1488
Remove unnecessary length guard in `serializeQueryStringParams` function. Because always `ii` param exists when using this function. Also it's okay to construct `URLSearchParams` with empty array. Related-Task: INTER-1488
Adds `errorTests.spec.ts` to test `TooManyRequestsError` and `getRetryAfter` function. Add extra tests for covering `getRequestPath` method. Related-Task: INTER-1488
🚀 Following releases will be created using changesets from this PR:@fingerprint/fingerprint-server-sdk@7.0.0Major Changes
|
This PR upgrades the Server SDK to the Server API v4. It removes Server APIv3 specific behavior and aligns the SDK with the new events format shared by Server API and Webhooks.
❓ Why?
data/products/resultnesting), switches to Bearer auth, unifies Webhooks & Server APIeventformats, and deprecates/visitorsin favor of/v4/events.⚙️ What Changed?
GET /events/search->GET /v4/eventsGET /visitors-> removed, migrate toGET /v4/events/v4/*URLs.Auth-Api-Keycustom header andapiKeyquery param withAuthorization: Bearer <secret_api_key>.AuthenticationModeoption.request_id->event_idlinked_id,pagination_key)GET /v4/eventswith filters.PUT /events->PATCH /v4/event/:event_idAuthenticationModeoption are removed.getEvent(requestId)->getEvent(eventId)updateEvent(body, eventId)now use snake_case fields📦 Migration Guide (SDK Consumers)
authenticationModeoption when initializingFingerprintJsServerApiClient.const client = new FingerprintJsServerApiClient({ apiKey: '<SECRET_API_KEY>', region: Region.Global, - authenticationMode: AuthenticationMode.AuthHeader })getEvent()function, useeventIdparameter name instead ofrequestId.client.updateEvent({ - linkedId: "linkedId" + linked_id: "linkedId" }, "<event-id>")tagsinstead oftagfor updating an event.client.updateEvent({ - tag: { + tags: { key: 'value', }, }, "<event-id>")updateEvent()function, useeventIdparameter name instead ofrequestId.client.updateEvent( {}, - requestId: "<request-id>" + eventId: "<event-id>" )getVisitorHistory()function.getVisits()function. UsesearchEvents()function.getRelatedVisitors()function.VisitorHistoryFilter,ErrorPlainResponse,VisitorsResponse,RelatedVisitorsResponse,RelatedVisitorsFilter,Webhook,EventsUpdateRequesttypes.