@novu/api 0.0.1-alpha.28 → 0.0.1-alpha.35

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 CHANGED
@@ -16,19 +16,23 @@ For more information about the API: [Novu Documentation](https://docs.novu.co)
16
16
 
17
17
  <!-- Start Table of Contents [toc] -->
18
18
  ## Table of Contents
19
+ <!-- $toc-max-depth=2 -->
20
+ * [SDK Installation](#sdk-installation)
21
+ * [Requirements](#requirements)
22
+ * [SDK Example Usage](#sdk-example-usage)
23
+ * [Available Resources and Operations](#available-resources-and-operations)
24
+ * [Standalone functions](#standalone-functions)
25
+ * [Pagination](#pagination)
26
+ * [Error Handling](#error-handling)
27
+ * [Server Selection](#server-selection)
28
+ * [Custom HTTP Client](#custom-http-client)
29
+ * [Authentication](#authentication)
30
+ * [Retries](#retries)
31
+ * [Debugging](#debugging)
32
+ * [Development](#development)
33
+ * [Maturity](#maturity)
34
+ * [Contributions](#contributions)
19
35
 
20
- * [SDK Installation](#sdk-installation)
21
- * [Requirements](#requirements)
22
- * [SDK Example Usage](#sdk-example-usage)
23
- * [Available Resources and Operations](#available-resources-and-operations)
24
- * [Standalone functions](#standalone-functions)
25
- * [Pagination](#pagination)
26
- * [Retries](#retries)
27
- * [Error Handling](#error-handling)
28
- * [Server Selection](#server-selection)
29
- * [Custom HTTP Client](#custom-http-client)
30
- * [Authentication](#authentication)
31
- * [Debugging](#debugging)
32
36
  <!-- End Table of Contents [toc] -->
33
37
 
34
38
  <!-- Start SDK Installation [installation] -->
@@ -132,10 +136,7 @@ async function run() {
132
136
  {
133
137
  name: "workflow_identifier",
134
138
  to: [
135
- {
136
- topicKey: "<value>",
137
- type: "Topic",
138
- },
139
+ "SUBSCRIBER_ID",
139
140
  ],
140
141
  },
141
142
  {
@@ -148,10 +148,7 @@ async function run() {
148
148
  {
149
149
  name: "workflow_identifier",
150
150
  to: [
151
- {
152
- topicKey: "<value>",
153
- type: "Topic",
154
- },
151
+ "SUBSCRIBER_ID",
155
152
  ],
156
153
  },
157
154
  {
@@ -209,10 +206,7 @@ async function run() {
209
206
  {
210
207
  name: "workflow_identifier",
211
208
  to: [
212
- {
213
- topicKey: "<value>",
214
- type: "Topic",
215
- },
209
+ "SUBSCRIBER_ID",
216
210
  ],
217
211
  },
218
212
  {
@@ -0,0 +1,6 @@
1
+ import { AfterSuccessContext, AfterSuccessHook, BeforeRequestContext, BeforeRequestHook } from "./types";
2
+ export declare class NovuCustomHook implements BeforeRequestHook, AfterSuccessHook {
3
+ beforeRequest(_hookCtx: BeforeRequestContext, request: Request): Request;
4
+ afterSuccess(_hookCtx: AfterSuccessContext, response: Response): Promise<Response>;
5
+ }
6
+ //# sourceMappingURL=novu-custom-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"novu-custom-hook.d.ts","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAEvG,qBAAa,cACT,YAAY,iBAAiB,EAAE,gBAAgB;IAE/C,aAAa,CAAC,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAclE,YAAY,CAAC,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;CAa3F"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NovuCustomHook = void 0;
4
+ class NovuCustomHook {
5
+ beforeRequest(_hookCtx, request) {
6
+ const authKey = 'authorization';
7
+ const hasAuthorization = request.headers.has(authKey);
8
+ const apiKeyPrefix = 'ApiKey';
9
+ if (hasAuthorization) {
10
+ const key = request.headers.get(authKey);
11
+ if (key && !key.includes(apiKeyPrefix)) {
12
+ request.headers.set(authKey, `${apiKeyPrefix} ${authKey}`);
13
+ }
14
+ }
15
+ return request;
16
+ }
17
+ async afterSuccess(_hookCtx, response) {
18
+ const jsonResponse = await response.json();
19
+ if (jsonResponse && Object.keys(jsonResponse).length === 1 && jsonResponse.data) {
20
+ return new Response(JSON.stringify(jsonResponse.data), {
21
+ status: response.status,
22
+ statusText: response.statusText,
23
+ headers: response.headers,
24
+ }); // Return the new Response object
25
+ }
26
+ return response;
27
+ }
28
+ }
29
+ exports.NovuCustomHook = NovuCustomHook;
30
+ //# sourceMappingURL=novu-custom-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"novu-custom-hook.js","sourceRoot":"","sources":["../src/hooks/novu-custom-hook.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IAGvB,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,EAAC,GAAG,YAAY,IAAI,OAAO,EAAE,CAAC,CAAA;YAC7D,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAA6B,EAAE,QAAkB;QAChE,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3C,IAAI,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;YAC9E,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;gBACnD,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;aAC5B,CAAC,CAAC,CAAC,iCAAiC;QACzC,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA9BD,wCA8BC"}
@@ -1 +1 @@
1
- {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASnC,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,QAIrC"}
1
+ {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASnC,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,QAGrC"}
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initHooks = void 0;
4
+ const novu_custom_hook_1 = require("./novu-custom-hook");
4
5
  /*
5
6
  * This file is only ever generated once on the first generation and then is free to be modified.
6
7
  * Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
7
8
  * in this file or in separate files in the hooks folder.
8
9
  */
9
- // @ts-expect-error remove this line when you add your first hook and hooks is used
10
10
  function initHooks(hooks) {
11
- // Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
12
- // with an instance of a hook that implements that specific Hook interface
13
- // Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
11
+ hooks.registerAfterSuccessHook(new novu_custom_hook_1.NovuCustomHook());
12
+ hooks.registerBeforeRequestHook(new novu_custom_hook_1.NovuCustomHook());
14
13
  }
15
14
  exports.initHooks = initHooks;
16
15
  //# sourceMappingURL=registration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registration.js","sourceRoot":"","sources":["../src/hooks/registration.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AAEH,mFAAmF;AACnF,SAAgB,SAAS,CAAC,KAAY;IACpC,gHAAgH;IAChH,0EAA0E;IAC1E,4FAA4F;AAC9F,CAAC;AAJD,8BAIC"}
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../src/hooks/registration.ts"],"names":[],"mappings":";;;AACA,yDAAkD;AAElD;;;;GAIG;AAEH,SAAgB,SAAS,CAAC,KAAY;IAClC,KAAK,CAAC,wBAAwB,CAAC,IAAI,iCAAc,EAAE,CAAC,CAAA;IACpD,KAAK,CAAC,yBAAyB,CAAC,IAAI,iCAAc,EAAE,CAAC,CAAA;AACzD,CAAC;AAHD,8BAGC"}
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.28";
31
- readonly genVersion: "2.463.0";
32
- readonly userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.28 2.463.0 1.0 @novu/api";
30
+ readonly sdkVersion: "0.0.1-alpha.35";
31
+ readonly genVersion: "2.467.4";
32
+ readonly userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.35 2.467.4 1.0 @novu/api";
33
33
  };
34
34
  //# sourceMappingURL=config.d.ts.map
package/lib/config.js CHANGED
@@ -30,8 +30,8 @@ exports.serverURLFromOptions = serverURLFromOptions;
30
30
  exports.SDK_METADATA = {
31
31
  language: "typescript",
32
32
  openapiDocVersion: "1.0",
33
- sdkVersion: "0.0.1-alpha.28",
34
- genVersion: "2.463.0",
35
- userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.28 2.463.0 1.0 @novu/api",
33
+ sdkVersion: "0.0.1-alpha.35",
34
+ genVersion: "2.467.4",
35
+ userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.35 2.467.4 1.0 @novu/api",
36
36
  };
37
37
  //# sourceMappingURL=config.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novu/api",
3
- "version": "0.0.1-alpha.28",
3
+ "version": "0.0.1-alpha.35",
4
4
  "author": "Novu",
5
5
  "main": "./index.js",
6
6
  "sideEffects": false,
@@ -0,0 +1,33 @@
1
+ import {AfterSuccessContext, AfterSuccessHook, BeforeRequestContext, BeforeRequestHook} from "./types";
2
+
3
+ export class NovuCustomHook
4
+ implements BeforeRequestHook, AfterSuccessHook
5
+ {
6
+ beforeRequest(_hookCtx: BeforeRequestContext, request: Request): Request {
7
+ const authKey = 'authorization';
8
+ const hasAuthorization = request.headers.has(authKey);
9
+ const apiKeyPrefix = 'ApiKey';
10
+ if (hasAuthorization) {
11
+ const key = request.headers.get(authKey);
12
+
13
+ if (key && !key.includes(apiKeyPrefix)) {
14
+ request.headers.set(authKey,`${apiKeyPrefix} ${authKey}`)
15
+ }
16
+ }
17
+ return request;
18
+ }
19
+
20
+ async afterSuccess(_hookCtx: AfterSuccessContext, response: Response): Promise<Response> {
21
+ const jsonResponse = await response.json();
22
+
23
+ if (jsonResponse && Object.keys(jsonResponse).length === 1 && jsonResponse.data) {
24
+ return new Response(JSON.stringify(jsonResponse.data), {
25
+ status: response.status,
26
+ statusText: response.statusText,
27
+ headers: response.headers,
28
+ }); // Return the new Response object
29
+ }
30
+
31
+ return response;
32
+ }
33
+ }
@@ -1,4 +1,5 @@
1
1
  import { Hooks } from "./types.js";
2
+ import {NovuCustomHook} from "./novu-custom-hook";
2
3
 
3
4
  /*
4
5
  * This file is only ever generated once on the first generation and then is free to be modified.
@@ -6,9 +7,7 @@ import { Hooks } from "./types.js";
6
7
  * in this file or in separate files in the hooks folder.
7
8
  */
8
9
 
9
- // @ts-expect-error remove this line when you add your first hook and hooks is used
10
10
  export function initHooks(hooks: Hooks) {
11
- // Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
12
- // with an instance of a hook that implements that specific Hook interface
13
- // Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
11
+ hooks.registerAfterSuccessHook(new NovuCustomHook())
12
+ hooks.registerBeforeRequestHook(new NovuCustomHook())
14
13
  }
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.28",
59
- genVersion: "2.463.0",
60
- userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.28 2.463.0 1.0 @novu/api",
58
+ sdkVersion: "0.0.1-alpha.35",
59
+ genVersion: "2.467.4",
60
+ userAgent: "speakeasy-sdk/typescript 0.0.1-alpha.35 2.467.4 1.0 @novu/api",
61
61
  } as const;