@react-pakistan/util-functions 1.22.32 → 1.22.34

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.
@@ -0,0 +1 @@
1
+ export declare const getCorsHeaders: (origin: string) => unknown;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCorsHeaders = void 0;
4
+ const getCorsHeaders = (origin) => {
5
+ // Default options
6
+ const headers = {
7
+ 'Access-Control-Allow-Methods': `${process.env.ALLOWED_METHODS}`,
8
+ 'Access-Control-Allow-Headers': `${process.env.ALLOWED_HEADERS}`,
9
+ 'Access-Control-Allow-Origin': `${process.env.ALLOWED_ORIGIN}`,
10
+ };
11
+ // If no allowed origin is set to default server origin
12
+ if (!process.env.ALLOWED_ORIGIN || !origin)
13
+ return headers;
14
+ // If allowed origin is set, check if origin is in allowed origins
15
+ const allowedOrigins = process.env.ALLOWED_ORIGIN.split(',');
16
+ // Validate server origin
17
+ if (allowedOrigins.includes('*')) {
18
+ headers['Access-Control-Allow-Origin'] = '*';
19
+ }
20
+ else if (allowedOrigins.includes(origin)) {
21
+ headers['Access-Control-Allow-Origin'] = origin;
22
+ }
23
+ // Return result
24
+ return headers;
25
+ };
26
+ exports.getCorsHeaders = getCorsHeaders;
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './api/stellar-solutions/customer';
2
+ export * from './api/cors';
2
3
  export * from './constants';
3
4
  export * from './general';
4
5
  export * from './hooks';
package/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api/stellar-solutions/customer"), exports);
18
+ __exportStar(require("./api/cors"), exports);
18
19
  __exportStar(require("./constants"), exports);
19
20
  __exportStar(require("./general"), exports);
20
21
  __exportStar(require("./hooks"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.22.32",
3
+ "version": "1.22.34",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {