@trycourier/courier 4.0.1 → 4.1.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 +12 -4
- package/lib/automations/types.d.ts +16 -2
- package/lib/http-client.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,12 @@ npm install @trycourier/courier
|
|
|
16
16
|
|
|
17
17
|
You will need to get a Courier API key to get started. You can sign up and create one for free at [courier.com](https://courier.com).
|
|
18
18
|
|
|
19
|
+
## Upgrade Guides
|
|
20
|
+
|
|
21
|
+
### v3 to v4
|
|
22
|
+
|
|
23
|
+
v4 uses native fetch client to make requests or falls back to a polyfill if the client doesn't exist in the environment it's running in. Check [Error Handling](#Error-Handling) out.
|
|
24
|
+
|
|
19
25
|
## Getting Started
|
|
20
26
|
|
|
21
27
|
```javascript
|
|
@@ -680,12 +686,12 @@ All network related promise rejections are not handled in any way. All successfu
|
|
|
680
686
|
|
|
681
687
|
`CourierHttpClientError` extends native `Error` interface with two extra properties:
|
|
682
688
|
|
|
683
|
-
|
|
684
|
-
|
|
689
|
+
- `response`: this is the `fetch` response as is
|
|
690
|
+
- `data`: this is the parsed body of the response
|
|
685
691
|
|
|
686
692
|
```javascript
|
|
687
693
|
// Error handling example
|
|
688
|
-
import { CourierClient, CourierHttpClientError } from
|
|
694
|
+
import { CourierClient, CourierHttpClientError } from "@trycourier/courier";
|
|
689
695
|
|
|
690
696
|
const courier = CourierClient();
|
|
691
697
|
|
|
@@ -697,7 +703,9 @@ try {
|
|
|
697
703
|
console.log("The Courier response is:", error.data);
|
|
698
704
|
console.log("The error message is:", error.message);
|
|
699
705
|
} else {
|
|
700
|
-
console.log(
|
|
706
|
+
console.log(
|
|
707
|
+
"There was a problem making that request. Make sure you are online."
|
|
708
|
+
);
|
|
701
709
|
}
|
|
702
710
|
}
|
|
703
711
|
```
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Message } from "../send/types";
|
|
2
|
-
export declare type AutomationStepAction = "cancel" | "delay" | "send" | "send-list" | "update-profile";
|
|
2
|
+
export declare type AutomationStepAction = "cancel" | "delay" | "invoke" | "send" | "send-list" | "update-profile";
|
|
3
3
|
export declare type MergeAlgorithm = "replace" | "none" | "overwrite" | "soft-merge";
|
|
4
|
+
export interface IAutomationRunContext {
|
|
5
|
+
brand?: string;
|
|
6
|
+
data?: any;
|
|
7
|
+
profile?: any;
|
|
8
|
+
template?: string;
|
|
9
|
+
recipient?: string;
|
|
10
|
+
}
|
|
4
11
|
export interface IAutomationStep {
|
|
5
12
|
action: AutomationStepAction;
|
|
6
13
|
if?: string;
|
|
@@ -15,6 +22,13 @@ export interface IAutomationDelayStep extends IAutomationStep {
|
|
|
15
22
|
duration?: string;
|
|
16
23
|
until?: string;
|
|
17
24
|
}
|
|
25
|
+
export interface IAutomationInvokeStep extends IAutomationStep {
|
|
26
|
+
action: "invoke";
|
|
27
|
+
context?: IAutomationRunContext;
|
|
28
|
+
template: string;
|
|
29
|
+
if?: string;
|
|
30
|
+
ref?: string;
|
|
31
|
+
}
|
|
18
32
|
export interface IAutomationSendStep extends IAutomationStep {
|
|
19
33
|
action: "send";
|
|
20
34
|
brand?: string;
|
|
@@ -42,7 +56,7 @@ export interface IAutomationUpdateProfileStep extends IAutomationStep {
|
|
|
42
56
|
profile: object;
|
|
43
57
|
merge: MergeAlgorithm;
|
|
44
58
|
}
|
|
45
|
-
export declare type AutomationStep = IAutomationCancelStep | IAutomationDelayStep | IAutomationSendStep | IAutomationV2SendStep | IAutomationSendListStep | IAutomationUpdateProfileStep;
|
|
59
|
+
export declare type AutomationStep = IAutomationCancelStep | IAutomationDelayStep | IAutomationInvokeStep | IAutomationSendStep | IAutomationV2SendStep | IAutomationSendListStep | IAutomationUpdateProfileStep;
|
|
46
60
|
export interface IAutomation {
|
|
47
61
|
cancelation_token?: string;
|
|
48
62
|
steps: AutomationStep[];
|
package/lib/http-client.js
CHANGED
|
@@ -93,7 +93,7 @@ exports.initHttpClient = function (_a) {
|
|
|
93
93
|
case 0:
|
|
94
94
|
searchParams = String(new URLSearchParams(config === null || config === void 0 ? void 0 : config.params));
|
|
95
95
|
searchQueryString = searchParams && "?" + searchParams;
|
|
96
|
-
fullUrl =
|
|
96
|
+
fullUrl = encodeURI("" + (baseUrl !== null && baseUrl !== void 0 ? baseUrl : '') + url + searchQueryString);
|
|
97
97
|
contentTypeHeader = body == null ? null : { "Content-Type": "application/json" };
|
|
98
98
|
idempotencyKeyHeader = (config === null || config === void 0 ? void 0 : config.idempotencyKey) ? { "Idempotency-Key": config.idempotencyKey }
|
|
99
99
|
: null;
|