@8ms/helpers 1.1.59 → 1.1.62

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,13 @@
1
+ declare type InitClient = {
2
+ auth: {
3
+ apiId: string;
4
+ apiKey: string;
5
+ };
6
+ };
7
+ /**
8
+ * http://api-docs.deepcrawl.com/
9
+ * Renew the DeepCrawl user token.
10
+ * Token lasts for 6 hours.
11
+ */
12
+ declare const initClient: ({ auth }: InitClient) => Promise<void>;
13
+ export default initClient;
@@ -49,7 +49,7 @@ global.deepcrawl = {
49
49
  * Renew the DeepCrawl user token.
50
50
  * Token lasts for 6 hours.
51
51
  */
52
- var renewToken = function (_a) {
52
+ var initClient = function (_a) {
53
53
  var auth = _a.auth;
54
54
  return __awaiter(void 0, void 0, void 0, function () {
55
55
  var apiResponse;
@@ -78,4 +78,4 @@ var renewToken = function (_a) {
78
78
  });
79
79
  });
80
80
  };
81
- exports.default = renewToken;
81
+ exports.default = initClient;
@@ -1,14 +1,15 @@
1
- export declare type Client = {
2
- instance: any;
3
- mccAccountId: string;
4
- refreshToken: string;
5
- };
6
1
  declare type InitClient = {
7
- parameterName: string;
2
+ auth: {
3
+ clientId: string;
4
+ clientSecret: string;
5
+ developerToken: string;
6
+ mccAccountId: string;
7
+ refreshToken: string;
8
+ };
8
9
  };
9
10
  /**
10
11
  * Shorthand function to get the Google Ads Client.
11
12
  * Library: google-ads-api
12
13
  */
13
- declare const initClient: ({ parameterName }: InitClient) => Promise<void>;
14
+ declare const initClient: ({ auth }: InitClient) => Promise<void>;
14
15
  export default initClient;
@@ -35,11 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
38
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var getParameter_1 = __importDefault(require("../aws/ssm/getParameter"));
43
39
  global.googleAdsClient = {
44
40
  instance: null,
45
41
  mccAccountId: '',
@@ -50,33 +46,23 @@ global.googleAdsClient = {
50
46
  * Library: google-ads-api
51
47
  */
52
48
  var initClient = function (_a) {
53
- var parameterName = _a.parameterName;
49
+ var auth = _a.auth;
54
50
  return __awaiter(void 0, void 0, void 0, function () {
55
- var parameter, GoogleAdsApi;
51
+ var GoogleAdsApi;
56
52
  return __generator(this, function (_b) {
57
- switch (_b.label) {
58
- case 0:
59
- if (!!global.googleAdsClient.instance) return [3 /*break*/, 2];
60
- return [4 /*yield*/, (0, getParameter_1.default)({
61
- name: parameterName,
62
- withDecryption: true,
63
- isJson: true,
64
- })];
65
- case 1:
66
- parameter = _b.sent();
67
- GoogleAdsApi = require('google-ads-api').GoogleAdsApi;
68
- // Create a new client instance
69
- global.googleAdsClient.instance =
70
- new GoogleAdsApi({
71
- client_id: parameter.clientId,
72
- client_secret: parameter.clientSecret,
73
- developer_token: parameter.developerToken,
74
- });
75
- global.googleAdsClient.mccAccountId = parameter.mccAccountId;
76
- global.googleAdsClient.refreshToken = parameter.refreshToken;
77
- _b.label = 2;
78
- case 2: return [2 /*return*/];
53
+ if (!global.googleAdsClient.instance) {
54
+ GoogleAdsApi = require('google-ads-api').GoogleAdsApi;
55
+ // Create a new client instance
56
+ global.googleAdsClient.instance =
57
+ new GoogleAdsApi({
58
+ client_id: auth.clientId,
59
+ client_secret: auth.clientSecret,
60
+ developer_token: auth.developerToken,
61
+ });
62
+ global.googleAdsClient.mccAccountId = auth.mccAccountId;
63
+ global.googleAdsClient.refreshToken = auth.refreshToken;
79
64
  }
65
+ return [2 /*return*/];
80
66
  });
81
67
  });
82
68
  };
@@ -0,0 +1,30 @@
1
+ import { Config as ConfigAws } from './aws/config';
2
+ declare type InitClients = {
3
+ athenaExpress?: {
4
+ database: string;
5
+ s3Bucket: string;
6
+ s3Key: string;
7
+ };
8
+ awsConfig?: ConfigAws;
9
+ awsGlue?: boolean;
10
+ awsLambda?: boolean;
11
+ awsS3?: boolean;
12
+ awsSes?: boolean;
13
+ awsSsm?: boolean;
14
+ deepCrawl?: {
15
+ parameterName: string;
16
+ };
17
+ eskimi?: boolean;
18
+ googleAds?: {
19
+ parameterName: string;
20
+ };
21
+ prisma?: {
22
+ debug?: boolean;
23
+ };
24
+ myTarget?: boolean;
25
+ };
26
+ /**
27
+ * Function to simplify initialising the clients.
28
+ */
29
+ declare const initClients: ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, awsSsm, deepCrawl, googleAds, prisma, }: InitClients) => Promise<void>;
30
+ export default initClients;
package/initClients.js ADDED
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
43
+ var initClient_2 = __importDefault(require("./aws/glue/initClient"));
44
+ var initClient_3 = __importDefault(require("./aws/s3/initClient"));
45
+ var initClient_4 = __importDefault(require("./aws/ses/initClient"));
46
+ var getParameter_1 = __importDefault(require("./aws/ssm/getParameter"));
47
+ var initClient_5 = __importDefault(require("./aws/ssm/initClient"));
48
+ var initClient_6 = __importDefault(require("./deepCrawl/initClient"));
49
+ var initClient_7 = __importDefault(require("./googleAds/initClient"));
50
+ var initClient_8 = __importDefault(require("./prisma/initClient"));
51
+ /**
52
+ * Function to simplify initialising the clients.
53
+ */
54
+ var initClients = function (_a) {
55
+ var athenaExpress = _a.athenaExpress, awsConfig = _a.awsConfig, awsGlue = _a.awsGlue, awsS3 = _a.awsS3, awsSes = _a.awsSes, awsSsm = _a.awsSsm, deepCrawl = _a.deepCrawl, googleAds = _a.googleAds, prisma = _a.prisma;
56
+ return __awaiter(void 0, void 0, void 0, function () {
57
+ var deepcrawlParameter, googleAdsParameter;
58
+ return __generator(this, function (_b) {
59
+ switch (_b.label) {
60
+ case 0:
61
+ if (undefined !== athenaExpress) {
62
+ (0, initClient_1.default)({
63
+ config: awsConfig,
64
+ database: athenaExpress.database,
65
+ s3Bucket: athenaExpress.s3Bucket,
66
+ s3Key: athenaExpress.s3Key,
67
+ });
68
+ }
69
+ if (true === awsGlue) {
70
+ (0, initClient_2.default)({ config: awsConfig });
71
+ }
72
+ if (true === awsS3) {
73
+ (0, initClient_3.default)({ config: awsConfig });
74
+ }
75
+ if (true === awsSes) {
76
+ (0, initClient_4.default)({ config: awsConfig });
77
+ }
78
+ if (true === awsSsm) {
79
+ (0, initClient_5.default)({ config: awsConfig });
80
+ }
81
+ if (!(undefined !== deepCrawl)) return [3 /*break*/, 3];
82
+ return [4 /*yield*/, (0, getParameter_1.default)({
83
+ name: deepCrawl.parameterName,
84
+ })];
85
+ case 1:
86
+ deepcrawlParameter = _b.sent();
87
+ return [4 /*yield*/, (0, initClient_6.default)({ auth: deepcrawlParameter })];
88
+ case 2:
89
+ _b.sent();
90
+ _b.label = 3;
91
+ case 3:
92
+ if (!(undefined !== googleAds)) return [3 /*break*/, 6];
93
+ return [4 /*yield*/, (0, getParameter_1.default)({
94
+ name: googleAds.parameterName,
95
+ })];
96
+ case 4:
97
+ googleAdsParameter = _b.sent();
98
+ return [4 /*yield*/, (0, initClient_7.default)({ auth: googleAdsParameter })];
99
+ case 5:
100
+ _b.sent();
101
+ _b.label = 6;
102
+ case 6:
103
+ if (undefined !== prisma) {
104
+ (0, initClient_8.default)({
105
+ debug: true === prisma ? false : prisma.debug || false,
106
+ });
107
+ }
108
+ return [2 /*return*/];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ exports.default = initClients;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.59",
4
+ "version": "1.1.62",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -1,4 +0,0 @@
1
- export declare type Auth = {
2
- apiId: string;
3
- apiKey: string;
4
- };
package/deepCrawl/auth.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import { Auth } from './auth';
2
- /**
3
- * http://api-docs.deepcrawl.com/
4
- * Renew the DeepCrawl user token.
5
- * Token lasts for 6 hours.
6
- */
7
- declare const renewToken: ({ auth }: {
8
- auth: Auth;
9
- }) => Promise<void>;
10
- export default renewToken;