Download the PHP package dregs/dregs-sdk without Composer

On this page you can find all versions of the php package dregs/dregs-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dregs-sdk

Dregs PHP SDK

Packagist PHP

The official PHP client for Dregs, which scores the users of your application for fraud and abuse across four categories: humanity, authenticity, uniqueness, and behavior.

Send events from your backend, read back the scores and the observations behind them.

The package has no required Composer dependencies. It talks to Dregs over ext-curl out of the box, so new Dregs\Client() works in a project with nothing else installed — and it will use your application's own PSR-18 client instead if you would rather it did. See Configuration.

Getting started

You need the secret key from an API credential, which you will find under Settings → Credentials in the Dregs dashboard. It starts with sk_. The pk_ public key is for the browser tracker and cannot read identities or scores.

The key is read from DREGS_SECRET_KEY when you do not pass one, so new Client() on its own is usually enough. The client is stateless beyond its configuration: build one at startup, register it in your container, and reuse it.

Tracking events

identity is your own id for the user — the same one you pass to dregs.identify() in the browser tracker, and the one you look scores up by. It is required: a server-side event carries no device signature, so the identity is the only thing tying the event to a user.

identityData carries attributes of the user rather than the event. The analyzers lean on these heavily, so send them whenever you have them. Name the keys the way your application already does and map them to Dregs's canonical fields under Settings → Mappings; the same goes for event names.

Idempotency

Every event is sent with an id, which makes ingestion idempotent: reposting the same id returns the original event instead of recording a second one. Pass the id your application already has, and a retry after a timeout can never double-count.

When you omit it the SDK generates one, which is what makes its own retries safe.

What comes back

isAccepted() is false in the uncommon case where Dregs accepts the request without recording an event. Failures that are yours to act on throw instead — see Errors.

Reading scores

This is the cheap read and the one most integrations want. A category Dregs has not scored yet reads as null, and a brand-new identity comes back empty. Scores is countable and iterable, so you can walk it as well as ask it for a category by name.

Scoring is asynchronous. Scores appear moments after the events that move them, not in the same breath, so read them at a decision point rather than immediately after a track() call.

Seeing exactly why

The scores are the summary; the observations are the evidence. When you need to show or log why an identity scored the way it did, ask for the analysis.

Each observation carries the analyzer that produced it, a value from 0.0 (suspicious) to 1.0 (legitimate), a confidence, a weight, and the counts behind the finding in metadata. analysis() throws NotFoundException until the identity has been analyzed at least once.

The whole identity

Forcing a rescore

This queues the work and returns; it does not wait for the cycle to finish. Dregs rescores on its own as events arrive, so you rarely need this outside of a support or backfill flow.

Errors

PHP's convention is Exception, not Error, so that is the suffix here: QuotaExceededException where the reference SDK has QuotaExceededError. Everything this library throws derives from Dregs\Exception\DregsException, which itself extends RuntimeException.

Exception When
BadRequestException 400, the event was malformed
AuthenticationException 401, the secret key was not recognized
QuotaExceededException 402, the account is over its monthly event limit
PermissionDeniedException 403, the credential may not do this
NotFoundException 404, no such identity, or it has not been analyzed
RateLimitException 429, too many requests
ServerException 5xx
TimeoutException the request timed out
ConnectionException the request never reached Dregs
WebhookVerificationException an incoming webhook did not verify

All of them live under Dregs\Exception\. Those that reached the API extend ApiException and carry statusCode, body, and requestId; getMessage() reads HTTP 404: Not Found (request req_abc), and the bare message Dregs sent is on description.

Bad arguments are the exception to the rule. An empty identity, a reserved event id, or a pk_ public key throws PHP's own InvalidArgumentException, because those are programming mistakes to fix rather than runtime conditions to handle.

Retries

Connection failures, timeouts, 429s, and 5xx are retried automatically with exponential backoff and full jitter, honouring Retry-After when the server sends one. Two retries by default:

Concurrency

This client is synchronous. PHP has no async story that would be idiomatic across Laravel, Symfony, and plain FPM, so there is one client and every call blocks until Dregs answers or the retries run out.

Tracking an event is not something a user's request should wait on. Push track() calls onto whatever queue your application already has — dispatch() in Laravel, Messenger in Symfony — and let a worker make the call:

Reads are different: scores() is a decision you are waiting on anyway, and it is a single fast request. Call that one inline.

Webhooks

Dregs signs every webhook with the channel's signing secret. Verify it against the raw request body before acting on the payload — a body you decoded and re-encoded will not match, because key order and whitespace change.

verify() also rejects payloads more than five minutes old as replays; pass tolerance: null to skip that if you are deduplicating on the event id yourself. verifySignature() and computeSignature() are there when you want the primitives. The signing secret is shown once, when you create the webhook channel, and is not your API secret key.

Configuration

Leave httpClient alone and the SDK uses Dregs\Http\CurlTransport, which needs nothing installed. Pass your application's PSR-18 client when it is configured the way your infrastructure needs — an egress proxy, a pinned CA bundle, a shared pool, request logging.

psr/http-client and psr/http-factory are suggested, not required, so this costs nothing to anyone who does not want it. When you supply a client, the timeout and the connection pool are yours rather than ours; timeout only configures the transport the SDK would have built.

For anything else — a transport that records requests in tests, one that routes through a queue — implement Dregs\Http\Transport and pass that.

Static analysis

Every public class and method is annotated for PHPStan, including array shapes, so mixed never escapes into your code. The SDK's own suite runs PHPStan at level max. Responses are readonly classes with typed properties; each one also keeps the body it was built from in raw, so a field Dregs adds after this release is reachable without waiting for an SDK upgrade.

Parsing is deliberately lenient. A missing field is null, an unrecognized score category does not break the response, and a value of an unexpected type is ignored rather than thrown over.

Contributing

See CONTRIBUTING.md. The short version:

composer.lock is committed, and CI installs from it, so the same commands produce the same versions locally and in CI.

Links

License

MIT. See LICENSE.


All versions of dregs-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dregs/dregs-sdk contains the following files

Loading the files please wait ...