@novu/api 0.0.1-alpha.175 → 0.0.1-alpha.177
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/hooks/novu-custom-hook.d.ts +6 -4
- package/hooks/novu-custom-hook.d.ts.map +1 -1
- package/hooks/novu-custom-hook.js +31 -19
- package/hooks/novu-custom-hook.js.map +1 -1
- package/lib/config.d.ts +2 -2
- package/lib/config.js +2 -2
- package/package.json +1 -1
- package/src/hooks/novu-custom-hook.ts +53 -24
- package/src/lib/config.ts +2 -2
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RequestInput } from "../lib/http";
|
|
2
|
+
import { AfterSuccessContext, AfterSuccessHook, BeforeCreateRequestHook, BeforeRequestContext, BeforeRequestHook, HookContext } from "./types";
|
|
3
|
+
export declare class NovuCustomHook implements BeforeRequestHook, AfterSuccessHook, BeforeCreateRequestHook {
|
|
4
|
+
beforeCreateRequest(_hookCtx: HookContext, input: RequestInput): RequestInput;
|
|
3
5
|
beforeRequest(_hookCtx: BeforeRequestContext, request: Request): Request;
|
|
4
|
-
private addIdempotencyHeader;
|
|
5
6
|
private generateIdempotencyKey;
|
|
6
|
-
private addAuthHeader;
|
|
7
7
|
afterSuccess(_hookCtx: AfterSuccessContext, response: Response): Promise<Response>;
|
|
8
|
+
private updateHeaderValue;
|
|
9
|
+
private convertToRecord;
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=novu-custom-hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"novu-custom-hook.d.ts","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"novu-custom-hook.d.ts","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EACH,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACd,MAAM,SAAS,CAAC;AAEjB,qBAAa,cACT,YAAW,iBAAiB,EAAE,gBAAgB,EAAE,uBAAuB;IACvE,mBAAmB,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,YAAY;IAW7E,aAAa,CAAC,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAexE,OAAO,CAAC,sBAAsB;IAMxB,YAAY,CAAC,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmBxF,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,eAAe;CAS1B"}
|
|
@@ -2,28 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NovuCustomHook = void 0;
|
|
4
4
|
class NovuCustomHook {
|
|
5
|
-
|
|
6
|
-
this.addAuthHeader(request);
|
|
7
|
-
this.addIdempotencyHeader(request);
|
|
8
|
-
return request;
|
|
9
|
-
}
|
|
10
|
-
addIdempotencyHeader(request) {
|
|
5
|
+
beforeCreateRequest(_hookCtx, input) {
|
|
11
6
|
const idempotencyKey = 'Idempotency-Key';
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
if (!keyValue || keyValue === '') {
|
|
17
|
-
const newIdempotenceValue = this.generateIdempotencyKey();
|
|
18
|
-
request.headers.set(idempotencyKey, newIdempotenceValue);
|
|
7
|
+
const headers = input.options?.headers;
|
|
8
|
+
if (!headers) {
|
|
9
|
+
return input;
|
|
19
10
|
}
|
|
11
|
+
const updatedHeaders = this.updateHeaderValue(headers, idempotencyKey, this.generateIdempotencyKey);
|
|
12
|
+
return { ...input, options: { headers: updatedHeaders } };
|
|
20
13
|
}
|
|
21
|
-
|
|
22
|
-
const timestamp = Date.now();
|
|
23
|
-
const randomString = Math.random().toString(36).substr(2, 9); // Generates a random alphanumeric string
|
|
24
|
-
return `${timestamp}-${randomString}`;
|
|
25
|
-
}
|
|
26
|
-
addAuthHeader(request) {
|
|
14
|
+
beforeRequest(_hookCtx, request) {
|
|
27
15
|
const authKey = 'authorization';
|
|
28
16
|
const hasAuthorization = request.headers.has(authKey);
|
|
29
17
|
const apiKeyPrefix = 'ApiKey';
|
|
@@ -33,6 +21,12 @@ class NovuCustomHook {
|
|
|
33
21
|
request.headers.set(authKey, `${apiKeyPrefix} ${key}`);
|
|
34
22
|
}
|
|
35
23
|
}
|
|
24
|
+
return request;
|
|
25
|
+
}
|
|
26
|
+
generateIdempotencyKey() {
|
|
27
|
+
const timestamp = Date.now();
|
|
28
|
+
const randomString = Math.random().toString(36).substr(2, 9); // Generates a random alphanumeric string
|
|
29
|
+
return `${timestamp}-${randomString}`;
|
|
36
30
|
}
|
|
37
31
|
async afterSuccess(_hookCtx, response) {
|
|
38
32
|
const responseAsText = await response.clone().text();
|
|
@@ -50,6 +44,24 @@ class NovuCustomHook {
|
|
|
50
44
|
}
|
|
51
45
|
return response;
|
|
52
46
|
}
|
|
47
|
+
updateHeaderValue(headers, key, defaultValueFunction) {
|
|
48
|
+
const headersRecord = this.convertToRecord(headers);
|
|
49
|
+
if (!(key in headersRecord) || headersRecord[key] === '') {
|
|
50
|
+
headersRecord[key] = defaultValueFunction();
|
|
51
|
+
}
|
|
52
|
+
return headersRecord;
|
|
53
|
+
}
|
|
54
|
+
convertToRecord(headers) {
|
|
55
|
+
if (Array.isArray(headers)) {
|
|
56
|
+
return Object.fromEntries(headers);
|
|
57
|
+
}
|
|
58
|
+
else if (headers instanceof Headers) {
|
|
59
|
+
return Object.fromEntries(headers.entries());
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return { ...headers };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
53
65
|
}
|
|
54
66
|
exports.NovuCustomHook = NovuCustomHook;
|
|
55
67
|
//# sourceMappingURL=novu-custom-hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"novu-custom-hook.js","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"novu-custom-hook.js","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":";;;AAUA,MAAa,cAAc;IAEvB,mBAAmB,CAAC,QAAqB,EAAE,KAAmB;QAC1D,MAAM,cAAc,GAAG,iBAAiB,CAAC;QACzC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAA;QACtC,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,KAAK,CAAA;QAChB,CAAC;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAA;QAEnG,OAAO,EAAC,GAAG,KAAK,EAAE,OAAO,EAAE,EAAC,OAAO,EAAE,cAAc,EAAC,EAAC,CAAA;IACzD,CAAC;IAED,aAAa,CAAC,QAA8B,EAAE,OAAgB;QAC1D,MAAM,OAAO,GAAG,eAAe,CAAC;QAChC,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,YAAY,GAAG,QAAQ,CAAC;QAC9B,IAAI,gBAAgB,EAAE,CAAC;YACnB,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAEzC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACrC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,YAAY,IAAI,GAAG,EAAE,CAAC,CAAA;YAC1D,CAAC;QACL,CAAC;QAED,OAAO,O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,eAAe,CAAC,OAAO,CAAC,CAAC;QAEpD,IAAI,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;YACvD,aAAa,CAAC,GAAG,CAAC,GAAG,oBAAoB,EAAE,CAAC;QAChD,CAAC;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;IAEO,eAAe,CAAC,OAAoB;QACxC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;YACpC,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACJ,OAAO,EAAC,GAAG,OAAO,EAAC,CAAC;QACxB,CAAC;IACL,CAAC;CACJ;AA5ED,wCA4EC"}
|
package/lib/config.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
27
27
|
export declare const SDK_METADATA: {
|
|
28
28
|
readonly language: "typescript";
|
|
29
29
|
readonly openapiDocVersion: "1.0";
|
|
30
|
-
readonly sdkVersion: "0.0.1-alpha.
|
|
30
|
+
readonly sdkVersion: "0.0.1-alpha.177";
|
|
31
31
|
readonly genVersion: "2.493.4";
|
|
32
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.
|
|
32
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.177 2.493.4 1.0 @novu/api";
|
|
33
33
|
};
|
|
34
34
|
//# sourceMappingURL=config.d.ts.map
|
package/lib/config.js
CHANGED
|
@@ -29,8 +29,8 @@ exports.serverURLFromOptions = serverURLFromOptions;
|
|
|
29
29
|
exports.SDK_METADATA = {
|
|
30
30
|
language: "typescript",
|
|
31
31
|
openapiDocVersion: "1.0",
|
|
32
|
-
sdkVersion: "0.0.1-alpha.
|
|
32
|
+
sdkVersion: "0.0.1-alpha.177",
|
|
33
33
|
genVersion: "2.493.4",
|
|
34
|
-
userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.
|
|
34
|
+
userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.177 2.493.4 1.0 @novu/api",
|
|
35
35
|
};
|
|
36
36
|
//# sourceMappingURL=config.js.map
|
package/package.json
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {RequestInput} from "../lib/http";
|
|
2
|
+
import {
|
|
3
|
+
AfterSuccessContext,
|
|
4
|
+
AfterSuccessHook,
|
|
5
|
+
BeforeCreateRequestHook,
|
|
6
|
+
BeforeRequestContext,
|
|
7
|
+
BeforeRequestHook,
|
|
8
|
+
HookContext
|
|
9
|
+
} from "./types";
|
|
2
10
|
|
|
3
11
|
export class NovuCustomHook
|
|
4
|
-
implements
|
|
5
|
-
{
|
|
6
|
-
beforeRequest(_hookCtx: BeforeRequestContext, request: Request): Request {
|
|
7
|
-
this.addAuthHeader(request);
|
|
8
|
-
this.addIdempotencyHeader(request)
|
|
9
|
-
return request;
|
|
10
|
-
}
|
|
11
|
-
private addIdempotencyHeader(request: Request) {
|
|
12
|
+
implements BeforeRequestHook, AfterSuccessHook, BeforeCreateRequestHook {
|
|
13
|
+
beforeCreateRequest(_hookCtx: HookContext, input: RequestInput): RequestInput {
|
|
12
14
|
const idempotencyKey = 'Idempotency-Key';
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
const headers = input.options?.headers
|
|
16
|
+
if (!headers) {
|
|
17
|
+
return input
|
|
18
|
+
}
|
|
19
|
+
const updatedHeaders = this.updateHeaderValue(headers, idempotencyKey, this.generateIdempotencyKey)
|
|
20
|
+
|
|
21
|
+
return {...input, options: {headers: updatedHeaders}}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const randomString = Math.random().toString(36).substr(2, 9); // Generates a random alphanumeric string
|
|
25
|
-
return `${timestamp}-${randomString}`;
|
|
26
|
-
}
|
|
27
|
-
private addAuthHeader(request: Request) {
|
|
23
|
+
|
|
24
|
+
beforeRequest(_hookCtx: BeforeRequestContext, request: Request): Request {
|
|
28
25
|
const authKey = 'authorization';
|
|
29
26
|
const hasAuthorization = request.headers.has(authKey);
|
|
30
27
|
const apiKeyPrefix = 'ApiKey';
|
|
@@ -35,12 +32,20 @@ export class NovuCustomHook
|
|
|
35
32
|
request.headers.set(authKey, `${apiKeyPrefix} ${key}`)
|
|
36
33
|
}
|
|
37
34
|
}
|
|
35
|
+
|
|
36
|
+
return request;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private generateIdempotencyKey(): string {
|
|
40
|
+
const timestamp = Date.now();
|
|
41
|
+
const randomString = Math.random().toString(36).substr(2, 9); // Generates a random alphanumeric string
|
|
42
|
+
return `${timestamp}-${randomString}`;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
async afterSuccess(_hookCtx: AfterSuccessContext, response: Response): Promise<Response> {
|
|
41
46
|
const responseAsText = await response.clone().text();
|
|
42
47
|
const contentType = response.headers.get('content-type') || '';
|
|
43
|
-
if (!responseAsText || responseAsText =='' || contentType.includes('text/html')) {
|
|
48
|
+
if (!responseAsText || responseAsText == '' || contentType.includes('text/html')) {
|
|
44
49
|
return response;
|
|
45
50
|
}
|
|
46
51
|
const jsonResponse = await response.clone().json();
|
|
@@ -55,4 +60,28 @@ export class NovuCustomHook
|
|
|
55
60
|
|
|
56
61
|
return response;
|
|
57
62
|
}
|
|
63
|
+
|
|
64
|
+
private updateHeaderValue(
|
|
65
|
+
headers: HeadersInit,
|
|
66
|
+
key: string,
|
|
67
|
+
defaultValueFunction: () => string
|
|
68
|
+
): Record<string, string> {
|
|
69
|
+
const headersRecord = this.convertToRecord(headers);
|
|
70
|
+
|
|
71
|
+
if (!(key in headersRecord) || headersRecord[key] === '') {
|
|
72
|
+
headersRecord[key] = defaultValueFunction();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return headersRecord;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private convertToRecord(headers: HeadersInit): Record<string, string> {
|
|
79
|
+
if (Array.isArray(headers)) {
|
|
80
|
+
return Object.fromEntries(headers);
|
|
81
|
+
} else if (headers instanceof Headers) {
|
|
82
|
+
return Object.fromEntries(headers.entries());
|
|
83
|
+
} else {
|
|
84
|
+
return {...headers};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
58
87
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -55,7 +55,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
55
55
|
export const SDK_METADATA = {
|
|
56
56
|
language: "typescript",
|
|
57
57
|
openapiDocVersion: "1.0",
|
|
58
|
-
sdkVersion: "0.0.1-alpha.
|
|
58
|
+
sdkVersion: "0.0.1-alpha.177",
|
|
59
59
|
genVersion: "2.493.4",
|
|
60
|
-
userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.
|
|
60
|
+
userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.177 2.493.4 1.0 @novu/api",
|
|
61
61
|
} as const;
|