Skip to content

feat: [SDK-5373] add sessions API client - #1569

Merged
fadi-george merged 1 commit into
new-session-eventsfrom
fadi/sdk-5373
Nov 12, 2026
Merged

fadi-george merged 1 commit into
new-session-eventsfrom
fadi/sdk-5373

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Stacked on #1568 (SDK-5370). Merge that first; this PR's diff is only the sessions API client.

Description

1 Line Summary

Add createSession / updateSession for POST /apps/{app_id}/sessions and PATCH /apps/{app_id}/sessions/{session_id}.

Details

Motivation

Typed request/response layer for the sessions API, used by the upcoming persistent queue (SDK-5377). Mirrors Android (OneSignal/OneSignal-Android-SDK#2775) and iOS (OneSignal/OneSignal-iOS-SDK#1763).

Scope

  • New src/shared/api/sessions.ts, callable from the service worker, built on api/base.ts.
  • Returns a SessionsApiResult instead of throwing, like iOS:
    • success (create carries data.session_id)
    • retry for network failure, non-JSON response, 5xx, 408, 429, or a create 202 without a usable session id. Carries Retry-After when present and numeric.
    • drop for other 4xx, or an invalid app id.
  • Retrying is safe because both calls carry an idempotency_key; a retried create returns the original session_id.
  • Body follows OneSignal/sessions sessions-http/openapi.yaml: the public create route takes subscription_type (string), not device_type. Times are passed as epoch ms and sent as ISO 8601 UTC (2023-11-14T22:13:20.000Z).
  • No default Retry-After on a 429 without the header; the queue owns backoff.
  • No callers yet, no bulk. No behavior change, bundle size unchanged.

Open questions

  • SafariLegacyPush is not in the spec's subscription_type enum, so legacy Safari creates would 400. Needs a backend decision before wiring.
  • base.ts already retries network errors up to 5 times with backoff before rejecting, so a retry from a network failure can take a couple of minutes. Left as is to avoid changing shared request behavior.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

sessions.test.ts (msw): request bodies with and without optional fields, 202 parsing, malformed create responses, retry vs drop by status, Retry-After passthrough and non-numeric values, network failure, non-JSON response, invalid app id. vp check, full vp test, and build:prod (size limits) pass.

Not tested in a browser; no callers yet.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files (kept beside the client they describe)

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed (no UI)

Related Tickets


🤖 Generated with Claude Code

@nan-li nan-li left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, with two small notes:

  • A create that returns 2xx without a session_id keeps retrying until the 30-day limit. Both native SDKs give up after 3 tries. The session's updates wait behind the create, so a cap seems worth adding, here or in the sender.
  • A short comment saying these requests are never signed, like the one on sendOutcome, would save the next reader from wondering about the missing JWT.

Base automatically changed from fadi/sdk-5370 to new-session-events November 12, 2026 23:09
Request helpers for POST /apps/{app_id}/sessions and
PATCH /apps/{app_id}/sessions/{session_id}, classifying failures as
retry (network, 5xx, 408, 429, create without session id) or drop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george
fadi-george merged commit 248c744 into new-session-events Nov 12, 2026
1 check passed
@fadi-george
fadi-george deleted the fadi/sdk-5373 branch November 12, 2026 23:11

@sherwinski sherwinski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old sessions did not need JWT for Identity Verification. Can we confirm this is still the case for new session events?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants