@flowripple/sdk 1.0.0 → 3.0.0
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 +22 -20
- package/dist/index.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +10 -16
- package/dist/index.mjs +10 -16
- package/package.json +8 -2
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.env.test +0 -3
- package/.env.test.example +0 -3
- package/.github/workflows/release.yml +0 -71
- package/CHANGELOG.md +0 -14
- package/test/actual.test.ts +0 -94
- package/test/mock.test.ts +0 -129
- package/test/setup.ts +0 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @flowripple/sdk
|
|
2
2
|
|
|
3
|
-
The official Node.js SDK for Flowripple - a
|
|
3
|
+
The official Node.js SDK for Flowripple - a visual workflow automation platform.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -16,30 +16,35 @@ Or using yarn:
|
|
|
16
16
|
yarn add @flowripple/sdk
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
Or using pnpm:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @flowripple/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
19
25
|
## Usage
|
|
20
26
|
|
|
21
|
-
First, import and initialize the FlowrippleClient with your API
|
|
27
|
+
First, import and initialize the FlowrippleClient with your API key:
|
|
22
28
|
|
|
23
29
|
```typescript
|
|
24
30
|
import { FlowrippleClient } from '@flowripple/sdk';
|
|
25
31
|
|
|
26
32
|
const client = new FlowrippleClient({
|
|
27
|
-
|
|
28
|
-
apiKey: 'YOUR_API_KEY'
|
|
33
|
+
apiKey: 'frp_your-api-key'
|
|
29
34
|
});
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
Then use the client to
|
|
37
|
+
Then use the client to trigger workflow events:
|
|
33
38
|
|
|
34
39
|
```typescript
|
|
35
|
-
//
|
|
36
|
-
await client.
|
|
40
|
+
// Trigger a simple event
|
|
41
|
+
await client.trigger('user.signup', {
|
|
37
42
|
userId: '123',
|
|
38
43
|
email: 'user@example.com'
|
|
39
44
|
});
|
|
40
45
|
|
|
41
|
-
//
|
|
42
|
-
await client.
|
|
46
|
+
// Trigger an event with custom data
|
|
47
|
+
await client.trigger('order.completed', {
|
|
43
48
|
orderId: 'ord_123',
|
|
44
49
|
amount: 99.99,
|
|
45
50
|
currency: 'USD',
|
|
@@ -59,20 +64,18 @@ The `FlowrippleClient` constructor accepts a configuration object with the follo
|
|
|
59
64
|
|
|
60
65
|
| Option | Type | Required | Default | Description |
|
|
61
66
|
|--------|------|----------|---------|-------------|
|
|
62
|
-
| `
|
|
63
|
-
| `apiKey` | string | Yes | - | Your Flowripple API Key |
|
|
67
|
+
| `apiKey` | string | Yes | - | Your Flowripple API Key (starts with `frp_`) |
|
|
64
68
|
| `baseUrl` | string | No | 'https://api.flowripple.com' | Custom API base URL |
|
|
65
69
|
| `silent` | boolean | No | false | If true, failed API calls return false instead of throwing errors |
|
|
66
|
-
| `version` | 'v1' | No | 'v1' | API version to use |
|
|
67
70
|
|
|
68
71
|
#### Methods
|
|
69
72
|
|
|
70
|
-
##### `
|
|
73
|
+
##### `trigger(identifier: string, data?: Record<string, any>): Promise<false | void>`
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
Triggers a workflow by sending an event to the Flowripple API.
|
|
73
76
|
|
|
74
|
-
- `
|
|
75
|
-
- `
|
|
77
|
+
- `identifier`: The event identifier to trigger (e.g., 'user.signup', 'order.completed')
|
|
78
|
+
- `data`: Optional object containing the event data
|
|
76
79
|
- Returns: A promise that resolves to `void` on success, or `false` if the request fails and silent mode is enabled
|
|
77
80
|
- Throws: An error if the request fails and silent mode is not enabled
|
|
78
81
|
|
|
@@ -82,15 +85,14 @@ By default, the SDK will throw errors when API requests fail. You can enable sil
|
|
|
82
85
|
|
|
83
86
|
```typescript
|
|
84
87
|
const client = new FlowrippleClient({
|
|
85
|
-
|
|
86
|
-
apiKey: 'YOUR_API_KEY',
|
|
88
|
+
apiKey: 'frp_your-api-key',
|
|
87
89
|
silent: true
|
|
88
90
|
});
|
|
89
91
|
|
|
90
92
|
// This will return false instead of throwing if the request fails
|
|
91
|
-
const result = await client.
|
|
93
|
+
const result = await client.trigger('user.signup', { userId: '123' });
|
|
92
94
|
if (result === false) {
|
|
93
|
-
console.log('Event
|
|
95
|
+
console.log('Event trigger failed');
|
|
94
96
|
}
|
|
95
97
|
```
|
|
96
98
|
|
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Configuration options for initializing the FlowrippleClient
|
|
3
3
|
*/
|
|
4
4
|
interface FlowrippleClientOptions {
|
|
5
|
-
/** (Required) Flowripple
|
|
6
|
-
apiClientId: number;
|
|
7
|
-
/** (Required) API key for authentication with Flowripple */
|
|
5
|
+
/** (Required) API key for authentication with Flowripple (starts with frp_) */
|
|
8
6
|
apiKey: string;
|
|
9
7
|
/** (Optional) Base URL for the Flowripple API. Defaults to https://api.flowripple.com */
|
|
10
8
|
baseUrl?: string;
|
|
@@ -19,10 +17,10 @@ interface FlowrippleClientOptions {
|
|
|
19
17
|
* @example
|
|
20
18
|
* ```typescript
|
|
21
19
|
* const client = new FlowrippleClient({
|
|
22
|
-
* apiKey: '
|
|
20
|
+
* apiKey: 'frp_your-api-key'
|
|
23
21
|
* });
|
|
24
22
|
*
|
|
25
|
-
* await client.
|
|
23
|
+
* await client.trigger('user.signup', {
|
|
26
24
|
* userId: '123',
|
|
27
25
|
* email: 'user@example.com'
|
|
28
26
|
* });
|
|
@@ -37,14 +35,14 @@ declare class FlowrippleClient {
|
|
|
37
35
|
*/
|
|
38
36
|
constructor(options: FlowrippleClientOptions);
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @returns Promise that resolves to
|
|
38
|
+
* Triggers a workflow by sending an event to the Flowripple API
|
|
39
|
+
* @param identifier - The event identifier to trigger
|
|
40
|
+
* @param data - Optional data payload associated with the event
|
|
41
|
+
* @returns Promise that resolves to void on success,
|
|
44
42
|
* or false if silent mode is enabled and the request failed
|
|
45
43
|
* @throws {Error} If the request fails and silent mode is not enabled
|
|
46
44
|
*/
|
|
47
|
-
|
|
45
|
+
trigger(identifier: string, data?: Record<string, any>): Promise<false | void>;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
export { FlowrippleClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Configuration options for initializing the FlowrippleClient
|
|
3
3
|
*/
|
|
4
4
|
interface FlowrippleClientOptions {
|
|
5
|
-
/** (Required) Flowripple
|
|
6
|
-
apiClientId: number;
|
|
7
|
-
/** (Required) API key for authentication with Flowripple */
|
|
5
|
+
/** (Required) API key for authentication with Flowripple (starts with frp_) */
|
|
8
6
|
apiKey: string;
|
|
9
7
|
/** (Optional) Base URL for the Flowripple API. Defaults to https://api.flowripple.com */
|
|
10
8
|
baseUrl?: string;
|
|
@@ -19,10 +17,10 @@ interface FlowrippleClientOptions {
|
|
|
19
17
|
* @example
|
|
20
18
|
* ```typescript
|
|
21
19
|
* const client = new FlowrippleClient({
|
|
22
|
-
* apiKey: '
|
|
20
|
+
* apiKey: 'frp_your-api-key'
|
|
23
21
|
* });
|
|
24
22
|
*
|
|
25
|
-
* await client.
|
|
23
|
+
* await client.trigger('user.signup', {
|
|
26
24
|
* userId: '123',
|
|
27
25
|
* email: 'user@example.com'
|
|
28
26
|
* });
|
|
@@ -37,14 +35,14 @@ declare class FlowrippleClient {
|
|
|
37
35
|
*/
|
|
38
36
|
constructor(options: FlowrippleClientOptions);
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @returns Promise that resolves to
|
|
38
|
+
* Triggers a workflow by sending an event to the Flowripple API
|
|
39
|
+
* @param identifier - The event identifier to trigger
|
|
40
|
+
* @param data - Optional data payload associated with the event
|
|
41
|
+
* @returns Promise that resolves to void on success,
|
|
44
42
|
* or false if silent mode is enabled and the request failed
|
|
45
43
|
* @throws {Error} If the request fails and silent mode is not enabled
|
|
46
44
|
*/
|
|
47
|
-
|
|
45
|
+
trigger(identifier: string, data?: Record<string, any>): Promise<false | void>;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
export { FlowrippleClient };
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,6 @@ __export(index_exports, {
|
|
|
54
54
|
});
|
|
55
55
|
module.exports = __toCommonJS(index_exports);
|
|
56
56
|
var import_axios = __toESM(require("axios"));
|
|
57
|
-
var import_crypto = __toESM(require("crypto"));
|
|
58
57
|
var FlowrippleClient = class {
|
|
59
58
|
/**
|
|
60
59
|
* Creates a new FlowrippleClient instance
|
|
@@ -65,31 +64,26 @@ var FlowrippleClient = class {
|
|
|
65
64
|
this.baseUrl = options.baseUrl || "https://api.flowripple.com";
|
|
66
65
|
}
|
|
67
66
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns Promise that resolves to
|
|
67
|
+
* Triggers a workflow by sending an event to the Flowripple API
|
|
68
|
+
* @param identifier - The event identifier to trigger
|
|
69
|
+
* @param data - Optional data payload associated with the event
|
|
70
|
+
* @returns Promise that resolves to void on success,
|
|
72
71
|
* or false if silent mode is enabled and the request failed
|
|
73
72
|
* @throws {Error} If the request fails and silent mode is not enabled
|
|
74
73
|
*/
|
|
75
|
-
|
|
74
|
+
trigger(identifier, data) {
|
|
76
75
|
return __async(this, null, function* () {
|
|
77
76
|
var _a, _b;
|
|
78
77
|
try {
|
|
79
78
|
const body = {
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
identifier,
|
|
80
|
+
data: data || {}
|
|
82
81
|
};
|
|
83
|
-
const
|
|
84
|
-
const stringToSign = timestamp + JSON.stringify(body);
|
|
85
|
-
const hmac = import_crypto.default.createHmac("sha256", this.options.apiKey).update(stringToSign).digest("hex");
|
|
86
|
-
const url = `${this.baseUrl.replace(/^\/+/, "")}/sdk/${(_a = this.options.version) != null ? _a : "v1"}/capture`;
|
|
82
|
+
const url = `${this.baseUrl.replace(/\/+$/, "")}/api/${(_a = this.options.version) != null ? _a : "v1"}/trigger`;
|
|
87
83
|
yield import_axios.default.post(url, body, {
|
|
88
84
|
headers: {
|
|
89
85
|
"Content-Type": "application/json",
|
|
90
|
-
"
|
|
91
|
-
"X-Flowripple-Signature": hmac,
|
|
92
|
-
"X-Flowripple-Timestamp": timestamp
|
|
86
|
+
"x-api-key": this.options.apiKey
|
|
93
87
|
}
|
|
94
88
|
});
|
|
95
89
|
return;
|
|
@@ -98,7 +92,7 @@ var FlowrippleClient = class {
|
|
|
98
92
|
return false;
|
|
99
93
|
}
|
|
100
94
|
throw new Error(
|
|
101
|
-
`Failed to
|
|
95
|
+
`Failed to trigger event: ${(_b = error == null ? void 0 : error.message) != null ? _b : error}`
|
|
102
96
|
);
|
|
103
97
|
}
|
|
104
98
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
21
21
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
import axios from "axios";
|
|
24
|
-
import crypto from "crypto";
|
|
25
24
|
var FlowrippleClient = class {
|
|
26
25
|
/**
|
|
27
26
|
* Creates a new FlowrippleClient instance
|
|
@@ -32,31 +31,26 @@ var FlowrippleClient = class {
|
|
|
32
31
|
this.baseUrl = options.baseUrl || "https://api.flowripple.com";
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @returns Promise that resolves to
|
|
34
|
+
* Triggers a workflow by sending an event to the Flowripple API
|
|
35
|
+
* @param identifier - The event identifier to trigger
|
|
36
|
+
* @param data - Optional data payload associated with the event
|
|
37
|
+
* @returns Promise that resolves to void on success,
|
|
39
38
|
* or false if silent mode is enabled and the request failed
|
|
40
39
|
* @throws {Error} If the request fails and silent mode is not enabled
|
|
41
40
|
*/
|
|
42
|
-
|
|
41
|
+
trigger(identifier, data) {
|
|
43
42
|
return __async(this, null, function* () {
|
|
44
43
|
var _a, _b;
|
|
45
44
|
try {
|
|
46
45
|
const body = {
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
identifier,
|
|
47
|
+
data: data || {}
|
|
49
48
|
};
|
|
50
|
-
const
|
|
51
|
-
const stringToSign = timestamp + JSON.stringify(body);
|
|
52
|
-
const hmac = crypto.createHmac("sha256", this.options.apiKey).update(stringToSign).digest("hex");
|
|
53
|
-
const url = `${this.baseUrl.replace(/^\/+/, "")}/sdk/${(_a = this.options.version) != null ? _a : "v1"}/capture`;
|
|
49
|
+
const url = `${this.baseUrl.replace(/\/+$/, "")}/api/${(_a = this.options.version) != null ? _a : "v1"}/trigger`;
|
|
54
50
|
yield axios.post(url, body, {
|
|
55
51
|
headers: {
|
|
56
52
|
"Content-Type": "application/json",
|
|
57
|
-
"
|
|
58
|
-
"X-Flowripple-Signature": hmac,
|
|
59
|
-
"X-Flowripple-Timestamp": timestamp
|
|
53
|
+
"x-api-key": this.options.apiKey
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
56
|
return;
|
|
@@ -65,7 +59,7 @@ var FlowrippleClient = class {
|
|
|
65
59
|
return false;
|
|
66
60
|
}
|
|
67
61
|
throw new Error(
|
|
68
|
-
`Failed to
|
|
62
|
+
`Failed to trigger event: ${(_b = error == null ? void 0 : error.message) != null ? _b : error}`
|
|
69
63
|
);
|
|
70
64
|
}
|
|
71
65
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowripple/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "FlowRipple SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
5
11
|
"repository": {
|
|
6
12
|
"type": "git",
|
|
7
13
|
"url": "https://github.com/FlowRipple/sdk.git"
|
|
@@ -31,6 +37,6 @@
|
|
|
31
37
|
"scripts": {
|
|
32
38
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
33
39
|
"test": "jest",
|
|
34
|
-
"ci:publish": "pnpm
|
|
40
|
+
"ci:publish": "pnpm build && changeset publish --access public"
|
|
35
41
|
}
|
|
36
42
|
}
|
package/.changeset/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# Changesets
|
|
2
|
-
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
-
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
-
|
|
7
|
-
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
-
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
package/.changeset/config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@3.0.5/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": false,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "restricted",
|
|
8
|
-
"baseBranch": "main",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
package/.env.test
DELETED
package/.env.test.example
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
name: Release CI/CD
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
# Avoid overlapping runs on the same branch
|
|
9
|
-
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
-
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write # to push changes (e.g., tags or changeset PR)
|
|
13
|
-
pull-requests: write # to create or update release PR
|
|
14
|
-
packages: write # to publish to npm
|
|
15
|
-
id-token: write # for provenance (optional, requires Node 16+)
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
release:
|
|
19
|
-
runs-on: ubuntu-latest
|
|
20
|
-
steps:
|
|
21
|
-
- name: Checkout code
|
|
22
|
-
uses: actions/checkout@v3
|
|
23
|
-
|
|
24
|
-
- uses: pnpm/action-setup@v2 # Install pnpm first
|
|
25
|
-
with:
|
|
26
|
-
version: 9 # specify pnpm version (e.g., v8 or v9)
|
|
27
|
-
|
|
28
|
-
- name: Setup Node.js 20.x and pnpm
|
|
29
|
-
uses: actions/setup-node@v4
|
|
30
|
-
with:
|
|
31
|
-
node-version: 20.x
|
|
32
|
-
cache: "pnpm"
|
|
33
|
-
registry-url: "https://registry.npmjs.org" # use npm registry
|
|
34
|
-
|
|
35
|
-
- name: Install dependencies
|
|
36
|
-
run: pnpm install --frozen-lockfile
|
|
37
|
-
|
|
38
|
-
- name: Build package
|
|
39
|
-
run: pnpm build
|
|
40
|
-
|
|
41
|
-
- name: Validate environment
|
|
42
|
-
run: |
|
|
43
|
-
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
|
|
44
|
-
echo "NPM_TOKEN is not set"
|
|
45
|
-
exit 1
|
|
46
|
-
fi
|
|
47
|
-
if [ -z "${{ secrets.FLOWRIPPLE_API_KEY }}" ]; then
|
|
48
|
-
echo "FLOWRIPPLE_API_KEY is not set"
|
|
49
|
-
exit 1
|
|
50
|
-
fi
|
|
51
|
-
|
|
52
|
-
- name: Run tests
|
|
53
|
-
run: |
|
|
54
|
-
echo "FLOWRIPPLE_API_CLIENT_ID=${{ secrets.FLOWRIPPLE_API_CLIENT_ID }}" >> .env.test
|
|
55
|
-
echo "FLOWRIPPLE_API_KEY=${{ secrets.FLOWRIPPLE_API_KEY }}" >> .env.test
|
|
56
|
-
echo "FLOWRIPPLE_BASE_URL=${{ secrets.FLOWRIPPLE_BASE_URL }}" >> .env.test
|
|
57
|
-
pnpm test # Runs Jest tests
|
|
58
|
-
env:
|
|
59
|
-
FLOWRIPPLE_API_CLIENT_ID: ${{ secrets.FLOWRIPPLE_API_CLIENT_ID }}
|
|
60
|
-
FLOWRIPPLE_API_KEY: ${{ secrets.FLOWRIPPLE_API_KEY }}
|
|
61
|
-
FLOWRIPPLE_BASE_URL: ${{ secrets.FLOWRIPPLE_BASE_URL }}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- name: Create Release PR or Publish
|
|
65
|
-
id: changesets
|
|
66
|
-
uses: changesets/action@v1
|
|
67
|
-
with:
|
|
68
|
-
publish: pnpm run ci:publish # run publish script (defined in package.json)
|
|
69
|
-
env:
|
|
70
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
71
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# @flowripple/sdk
|
|
2
|
-
|
|
3
|
-
## 1.0.0
|
|
4
|
-
|
|
5
|
-
### Major Changes
|
|
6
|
-
|
|
7
|
-
- e9bc79c: Initial release of the @flowripple/sdk package featuring:
|
|
8
|
-
|
|
9
|
-
- Core FlowrippleClient class for event capture
|
|
10
|
-
- Secure API authentication with HMAC signatures
|
|
11
|
-
- Configurable base URL and API versioning
|
|
12
|
-
- Silent mode for error handling
|
|
13
|
-
- Comprehensive test coverage with both mock and actual API tests
|
|
14
|
-
- TypeScript support with full type definitions
|
package/test/actual.test.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { FlowrippleClient } from '../src/index';
|
|
2
|
-
|
|
3
|
-
const baseUrl = process.env.FLOWRIPPLE_BASE_URL || 'http://localhost:3000';
|
|
4
|
-
const validApiClientId = parseInt(process.env.FLOWRIPPLE_API_CLIENT_ID || '1');
|
|
5
|
-
const validApiKey = process.env.FLOWRIPPLE_API_KEY || 'test-api-key';
|
|
6
|
-
|
|
7
|
-
describe('FlowrippleClient', () => {
|
|
8
|
-
describe('constructor', () => {
|
|
9
|
-
it('should set default baseUrl if not provided', () => {
|
|
10
|
-
const client = new FlowrippleClient({
|
|
11
|
-
apiClientId: validApiClientId,
|
|
12
|
-
apiKey: validApiKey,
|
|
13
|
-
});
|
|
14
|
-
expect(client['baseUrl']).toBe('https://api.flowripple.com');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should use provided baseUrl', () => {
|
|
18
|
-
const client = new FlowrippleClient({
|
|
19
|
-
apiClientId: validApiClientId,
|
|
20
|
-
apiKey: validApiKey,
|
|
21
|
-
baseUrl: 'http://custom.url',
|
|
22
|
-
});
|
|
23
|
-
expect(client['baseUrl']).toBe('http://custom.url');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('capture method', () => {
|
|
28
|
-
describe('success cases', () => {
|
|
29
|
-
it('should successfully capture an event', async () => {
|
|
30
|
-
const client = new FlowrippleClient({
|
|
31
|
-
apiClientId: validApiClientId,
|
|
32
|
-
apiKey: validApiKey,
|
|
33
|
-
baseUrl,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const eventName = 'test.event';
|
|
37
|
-
const payload = { userId: '123', action: 'test' };
|
|
38
|
-
|
|
39
|
-
const result = await client.capture(eventName, payload);
|
|
40
|
-
expect(result).toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should handle successful capture in silent mode', async () => {
|
|
44
|
-
const client = new FlowrippleClient({
|
|
45
|
-
apiClientId: validApiClientId,
|
|
46
|
-
apiKey: validApiKey,
|
|
47
|
-
baseUrl,
|
|
48
|
-
silent: true,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const result = await client.capture('test.event', { userId: '123' });
|
|
52
|
-
expect(result).toBeUndefined();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('error cases', () => {
|
|
57
|
-
it('should throw error with descriptive message in normal mode', async () => {
|
|
58
|
-
const client = new FlowrippleClient({
|
|
59
|
-
apiClientId: -1, // Invalid ID to force error
|
|
60
|
-
apiKey: validApiKey,
|
|
61
|
-
baseUrl,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
await expect(client.capture('test.event', {})).rejects.toThrow(
|
|
65
|
-
'Failed to capture event',
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should return false in silent mode on error', async () => {
|
|
70
|
-
const client = new FlowrippleClient({
|
|
71
|
-
apiClientId: -1, // Invalid ID to force error
|
|
72
|
-
apiKey: validApiKey,
|
|
73
|
-
baseUrl,
|
|
74
|
-
silent: true,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const result = await client.capture('test.event', {});
|
|
78
|
-
expect(result).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should handle invalid API responses', async () => {
|
|
82
|
-
const client = new FlowrippleClient({
|
|
83
|
-
apiClientId: validApiClientId,
|
|
84
|
-
apiKey: 'invalid-key', // Invalid key to force error
|
|
85
|
-
baseUrl,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await expect(client.capture('test.event', {})).rejects.toThrow(
|
|
89
|
-
'Failed to capture event',
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
package/test/mock.test.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { FlowrippleClient } from '../src/index';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
const baseUrl = process.env.FLOWRIPPLE_BASE_URL || 'http://localhost:3000';
|
|
5
|
-
const validApiClientId = parseInt(process.env.FLOWRIPPLE_API_CLIENT_ID || '1');
|
|
6
|
-
const validApiKey = process.env.FLOWRIPPLE_API_KEY || 'test-api-key';
|
|
7
|
-
|
|
8
|
-
jest.mock('axios');
|
|
9
|
-
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
|
10
|
-
|
|
11
|
-
describe('FlowrippleClient', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.clearAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('constructor', () => {
|
|
17
|
-
it('should set default baseUrl if not provided', () => {
|
|
18
|
-
const client = new FlowrippleClient({
|
|
19
|
-
apiClientId: validApiClientId,
|
|
20
|
-
apiKey: validApiKey,
|
|
21
|
-
});
|
|
22
|
-
expect(client['baseUrl']).toBe('https://api.flowripple.com');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should use provided baseUrl', () => {
|
|
26
|
-
const client = new FlowrippleClient({
|
|
27
|
-
apiClientId: validApiClientId,
|
|
28
|
-
apiKey: validApiKey,
|
|
29
|
-
baseUrl: 'http://custom.url',
|
|
30
|
-
});
|
|
31
|
-
expect(client['baseUrl']).toBe('http://custom.url');
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('capture method', () => {
|
|
36
|
-
describe('success cases', () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
mockedAxios.post.mockResolvedValue({ data: {} });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should send correct request payload and headers', async () => {
|
|
42
|
-
const client = new FlowrippleClient({
|
|
43
|
-
apiClientId: validApiClientId,
|
|
44
|
-
apiKey: validApiKey,
|
|
45
|
-
baseUrl,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const eventName = 'test.event';
|
|
49
|
-
const payload = { userId: '123', action: 'test' };
|
|
50
|
-
|
|
51
|
-
await client.capture(eventName, payload);
|
|
52
|
-
|
|
53
|
-
expect(mockedAxios.post).toHaveBeenCalledTimes(1);
|
|
54
|
-
const [url, body, config] = mockedAxios.post.mock.calls[0] ?? [];
|
|
55
|
-
|
|
56
|
-
expect(url).toBe(`${baseUrl}/sdk/v1/capture`);
|
|
57
|
-
expect(body).toEqual({ event: eventName, payload });
|
|
58
|
-
expect(config?.headers).toMatchObject({
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
'X-Flowripple-Api-Client-Id': validApiClientId,
|
|
61
|
-
'X-Flowripple-Signature': expect.any(String),
|
|
62
|
-
'X-Flowripple-Timestamp': expect.any(String),
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should handle successful capture in silent mode', async () => {
|
|
67
|
-
const client = new FlowrippleClient({
|
|
68
|
-
apiClientId: validApiClientId,
|
|
69
|
-
apiKey: validApiKey,
|
|
70
|
-
baseUrl,
|
|
71
|
-
silent: true,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const result = await client.capture('test.event', { userId: '123' });
|
|
75
|
-
expect(result).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('error cases', () => {
|
|
80
|
-
beforeEach(() => {
|
|
81
|
-
mockedAxios.post.mockRejectedValue(new Error('Network error'));
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should throw error with descriptive message in normal mode', async () => {
|
|
85
|
-
const client = new FlowrippleClient({
|
|
86
|
-
apiClientId: validApiClientId,
|
|
87
|
-
apiKey: validApiKey,
|
|
88
|
-
baseUrl,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
await expect(client.capture('test.event', {})).rejects.toThrow(
|
|
92
|
-
'Failed to capture event: Network error',
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should return false in silent mode on error', async () => {
|
|
97
|
-
const client = new FlowrippleClient({
|
|
98
|
-
apiClientId: validApiClientId,
|
|
99
|
-
apiKey: validApiKey,
|
|
100
|
-
baseUrl,
|
|
101
|
-
silent: true,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const result = await client.capture('test.event', {});
|
|
105
|
-
expect(result).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should handle malformed API responses', async () => {
|
|
109
|
-
mockedAxios.post.mockRejectedValue({
|
|
110
|
-
isAxiosError: true,
|
|
111
|
-
response: {
|
|
112
|
-
status: 400,
|
|
113
|
-
data: { message: 'Invalid payload' },
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const client = new FlowrippleClient({
|
|
118
|
-
apiClientId: validApiClientId,
|
|
119
|
-
apiKey: validApiKey,
|
|
120
|
-
baseUrl,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
await expect(client.capture('test.event', {})).rejects.toThrow(
|
|
124
|
-
'Failed to capture event',
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|