@osskit/dafka-producer-fetch-client
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "@osskit/dafka-producer-fetch-client", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "url": "https://github.com/osskit/dafka-producer-fetch-client" |
<div align="center"> | ||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/osskit/dafka-producer-fetch-client/publish) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/osskit/dafka-producer-fetch-client/blob/master/LICENSE.md) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osskit/dafka-producer-fetch-client/publish.yml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/osskit/dafka-producer-fetch-client/blob/master/LICENSE.md) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
@@ -13,13 +13,24 @@ typescript-fetch client wrapper for `dafka-producer` | ||
## Usage | ||
### Scoped | ||
```ts | ||
import { createProducer } from '@osskit/dafka-producer-fetch-client' | ||
import { createProducer } from '@osskit/dafka-producer-fetch-client'; | ||
export const produce = createProducer<TEventData>('https://my-dafka-producer-url', 'my-topic', 'my-partition-key'); | ||
export const produce = createProducer<Message>({ | ||
url: 'http://dafka-producer', | ||
topic: 'my-topic', | ||
keyExtractor: (record) => record.id, | ||
fetch: global.fetch, | ||
}); | ||
await produce<TEventData>(payload); | ||
await produce(records); | ||
``` | ||
### Extra headers | ||
It is possible to add extra headers to the request | ||
```ts | ||
await produce(records, { | ||
'x-extra-header': 'value', | ||
}); | ||
``` | ||
## API | ||
### createProducer(url: string, topic: string, key?: string) | ||
### createProducer({ url, topic, keyExtractor, fetch }) | ||
#### url | ||
@@ -35,11 +46,16 @@ Type: `string` | ||
#### key | ||
Type: `string` | ||
#### keyExtractor | ||
Type: `(record: Record) => string` | ||
The Kafka Topic Partition key, if not supplied then a random UUID is generated | ||
A function to extract the key from a record, defaults to a random `UUID` | ||
#### fetch | ||
Type: `typeof global.fetch` | ||
The fetch function to use | ||
#### returns | ||
An instance of a function that receives `<T>(payload: T)` | ||
An instance of a function that receives `<Record>(records: Record[], extraHeaders?: object)` and returns `Promise<void>` | ||
## License | ||
[MIT License](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6405
60