@vrplatform/log 2.0.0-alpha.4 → 2.0.0-alpha.40
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/build/main/log/baselog.d.ts +0 -1
- package/build/main/log/baselog.js +1 -16
- package/build/main/log/baselog.js.map +1 -1
- package/build/main/log/common.d.ts +1 -10
- package/build/main/log/common.js +3 -13
- package/build/main/log/common.js.map +1 -1
- package/build/main/log/index.d.ts +2 -2
- package/build/main/log/index.js +7 -6
- package/build/main/log/index.js.map +1 -1
- package/build/main/log/type.d.ts +18 -0
- package/build/main/log/type.js +12 -0
- package/build/main/log/type.js.map +1 -1
- package/build/main/tracking/_intercom.d.ts +109 -0
- package/build/main/tracking/_intercom.js +139 -0
- package/build/main/tracking/_intercom.js.map +1 -0
- package/build/main/tracking/index.d.ts +102 -48
- package/build/main/tracking/index.js +183 -69
- package/build/main/tracking/index.js.map +1 -1
- package/build/main/tracking/intercom.d.ts +2 -1
- package/build/main/tracking/intercom.js.map +1 -1
- package/build/main/tracking/types.d.ts +87 -0
- package/build/main/tracking/types.js +3 -0
- package/build/main/tracking/types.js.map +1 -0
- package/build/main/utils/convertKeysToSnakeCase.d.ts +1 -0
- package/build/main/utils/convertKeysToSnakeCase.js +23 -0
- package/build/main/utils/convertKeysToSnakeCase.js.map +1 -0
- package/build/main/utils/convertValuesToString.d.ts +5 -0
- package/build/main/utils/convertValuesToString.js +11 -0
- package/build/main/utils/convertValuesToString.js.map +1 -0
- package/build/main/utils/index.d.ts +3 -0
- package/build/main/utils/index.js +20 -0
- package/build/main/utils/index.js.map +1 -0
- package/build/main/utils/isTest.d.ts +1 -0
- package/build/main/utils/isTest.js +18 -0
- package/build/main/utils/isTest.js.map +1 -0
- package/build/module/log/baselog.d.ts +0 -1
- package/build/module/log/baselog.js +1 -2
- package/build/module/log/baselog.js.map +1 -1
- package/build/module/log/common.d.ts +1 -10
- package/build/module/log/common.js +1 -11
- package/build/module/log/common.js.map +1 -1
- package/build/module/log/index.d.ts +2 -2
- package/build/module/log/index.js +2 -1
- package/build/module/log/index.js.map +1 -1
- package/build/module/log/type.d.ts +18 -0
- package/build/module/log/type.js +11 -1
- package/build/module/log/type.js.map +1 -1
- package/build/module/tracking/_intercom.d.ts +109 -0
- package/build/module/tracking/_intercom.js +136 -0
- package/build/module/tracking/_intercom.js.map +1 -0
- package/build/module/tracking/index.d.ts +102 -48
- package/build/module/tracking/index.js +167 -67
- package/build/module/tracking/index.js.map +1 -1
- package/build/module/tracking/intercom.d.ts +2 -1
- package/build/module/tracking/intercom.js.map +1 -1
- package/build/module/tracking/types.d.ts +87 -0
- package/build/module/tracking/types.js +2 -0
- package/build/module/tracking/types.js.map +1 -0
- package/build/module/utils/convertKeysToSnakeCase.d.ts +1 -0
- package/build/module/utils/convertKeysToSnakeCase.js +19 -0
- package/build/module/utils/convertKeysToSnakeCase.js.map +1 -0
- package/build/module/utils/convertValuesToString.d.ts +5 -0
- package/build/module/utils/convertValuesToString.js +8 -0
- package/build/module/utils/convertValuesToString.js.map +1 -0
- package/build/module/utils/index.d.ts +3 -0
- package/build/module/utils/index.js +4 -0
- package/build/module/utils/index.js.map +1 -0
- package/build/module/utils/isTest.d.ts +1 -0
- package/build/module/utils/isTest.js +14 -0
- package/build/module/utils/isTest.js.map +1 -0
- package/package.json +2 -1
- package/src/log/baselog.ts +2 -3
- package/src/log/common.ts +1 -14
- package/src/log/index.ts +6 -6
- package/src/log/type.ts +23 -0
- package/src/tracking/{intercom.ts → _intercom.ts} +2 -1
- package/src/tracking/index.ts +326 -106
- package/src/tracking/types.ts +181 -0
- package/src/utils/convertKeysToSnakeCase.ts +21 -0
- package/src/utils/convertValuesToString.ts +10 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/isTest.ts +16 -0
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.createBaseLog = createBaseLog;
|
|
18
|
-
const common_1 = require("./common");
|
|
19
|
-
__exportStar(require("./type"), exports);
|
|
20
4
|
const js_1 = require("@axiomhq/js");
|
|
21
5
|
const serialize_error_1 = require("serialize-error");
|
|
22
6
|
const color_1 = require("./color");
|
|
7
|
+
const common_1 = require("./common");
|
|
23
8
|
let lastMessageTimestamp = undefined;
|
|
24
9
|
function createBaseLog({ token, orgId = 'vrplatform-mv6k', dataset, consoleLog, }, { environment, workerId, app, version, context, type, correlationId, executionContext, }) {
|
|
25
10
|
const baseFields = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baselog.js","sourceRoot":"src/","sources":["log/baselog.ts"],"names":[],"mappings":";;AAQA,sCAgLC;AAxLD,oCAAoC;AACpC,qDAAiD;AACjD,mCAAiC;AACjC,qCAA8D;AAG9D,IAAI,oBAAoB,GAAuB,SAAS,CAAC;AAEzD,SAAgB,aAAa,CAC3B,EACE,KAAK,EACL,KAAK,GAAG,iBAAiB,EACzB,OAAO,EACP,UAAU,GAM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AC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;gBACxD,OAAO,OAAO,CACZ,OAAO,EACP,CAAC,EACD,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,IAAA,gCAAc,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC1C,CAAC,CACF,CAAC;YACJ,CAAC;YACD,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;YACzD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;YACvD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;SACxD,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,EAAoB,CAAC;IAClD,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;QACnB,IAAI,gBAAgB,IAAI,KAAK,EAAE,CAAC;YAC9B,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const CONNECTION_ID_HEADER = "X-Connection-ID";
|
|
3
|
-
export declare const WORKFLOW_ID_HEADER = "X-Workflow-ID";
|
|
4
|
-
export declare const TASK_QUEUE_HEADER = "X-Task-Queue";
|
|
5
|
-
export declare const CORRELATION_ID_HEADER = "X-Correlation-ID";
|
|
6
|
-
export declare const VERIFICATION_HEADER = "X-Verification-Key";
|
|
7
|
-
export declare const AXIOM_AUTH_TOKEN_ENV = "AXIOM_AUTH_TOKEN";
|
|
8
|
-
export declare const AXIOM_ORG_ID_ENV = "AXIOM_ORG_ID";
|
|
9
|
-
export declare const AXIOM_DATASET_ENV = "AXIOM_DATASET";
|
|
10
|
-
export declare const LOG_ENV = "LOG";
|
|
1
|
+
import { type RequestLike } from './type';
|
|
11
2
|
export declare const requestHeadersToCapture: string[];
|
|
12
3
|
export declare function getCorrelationId(request?: RequestLike): string | undefined;
|
|
13
4
|
export declare function getEnvironment(env?: Record<string, any>): any;
|
package/build/main/log/common.js
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestHeadersToCapture =
|
|
3
|
+
exports.requestHeadersToCapture = void 0;
|
|
4
4
|
exports.getCorrelationId = getCorrelationId;
|
|
5
5
|
exports.getEnvironment = getEnvironment;
|
|
6
6
|
exports.requestToContext = requestToContext;
|
|
7
|
-
|
|
8
|
-
exports.CONNECTION_ID_HEADER = 'X-Connection-ID';
|
|
9
|
-
exports.WORKFLOW_ID_HEADER = 'X-Workflow-ID';
|
|
10
|
-
exports.TASK_QUEUE_HEADER = 'X-Task-Queue';
|
|
11
|
-
exports.CORRELATION_ID_HEADER = 'X-Correlation-ID';
|
|
12
|
-
exports.VERIFICATION_HEADER = 'X-Verification-Key';
|
|
13
|
-
// Env
|
|
14
|
-
exports.AXIOM_AUTH_TOKEN_ENV = 'AXIOM_AUTH_TOKEN';
|
|
15
|
-
exports.AXIOM_ORG_ID_ENV = 'AXIOM_ORG_ID';
|
|
16
|
-
exports.AXIOM_DATASET_ENV = 'AXIOM_DATASET';
|
|
17
|
-
exports.LOG_ENV = 'LOG';
|
|
7
|
+
const type_1 = require("./type");
|
|
18
8
|
exports.requestHeadersToCapture = ['user-agent'];
|
|
19
9
|
function getCorrelationId(request) {
|
|
20
10
|
if (!request?.headers)
|
|
21
11
|
return undefined;
|
|
22
|
-
return (request.headers.get(
|
|
12
|
+
return (request.headers.get(type_1.CORRELATION_ID_HEADER) ||
|
|
23
13
|
request.headers.get('fi-correlation-id') ||
|
|
24
14
|
request.headers.get('x-correlation-id') ||
|
|
25
15
|
request.headers.get('correlation-id') ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"src/","sources":["log/common.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"src/","sources":["log/common.ts"],"names":[],"mappings":";;;AAIA,4CAcC;AAED,wCAGC;AA8BD,4CAuCC;AA5FD,iCAAiE;AAEpD,QAAA,uBAAuB,GAAG,CAAC,YAAY,CAAC,CAAC;AAEtD,SAAgB,gBAAgB,CAAC,OAAqB;IACpD,IAAI,CAAC,OAAO,EAAE,OAAO;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO,CACL,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,4BAAqB,CAAC;QAC1C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACxC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACvC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACrC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACvC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACrC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC7B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QACpC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;QACjC,SAAS,CACV,CAAC;AACJ,CAAC;AAED,SAAgB,cAAc,CAAC,GAAyB;IACtD,IAAI,GAAG,EAAE,QAAQ;QAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;IACxC,OAAO,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;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G,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,OAAO,CAAC,GAAG,GAAG;YACZ,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,OAAO,CAAC,GAAG;SAClB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC;QACnC,OAAe,CAAC,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACjE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC;QACxC,OAAe,CAAC,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC3E,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { requestToContext } from './common';
|
|
2
|
-
import type
|
|
2
|
+
import { type LogBindings, type RequestLike, type WorkerLog } from './type';
|
|
3
3
|
export * from './common';
|
|
4
4
|
export * from './baselog';
|
|
5
5
|
export * from './type';
|
|
@@ -14,7 +14,7 @@ export declare function useLog({ environment: _environment, name, request, body,
|
|
|
14
14
|
correlationId?: string;
|
|
15
15
|
version?: string;
|
|
16
16
|
dataset?: string;
|
|
17
|
-
env?:
|
|
17
|
+
env?: LogBindings;
|
|
18
18
|
context?: Record<string, any>;
|
|
19
19
|
executionContext?: {
|
|
20
20
|
waitUntil(promise: Promise<any>): void;
|
package/build/main/log/index.js
CHANGED
|
@@ -17,18 +17,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.useLog = useLog;
|
|
18
18
|
const baselog_1 = require("./baselog");
|
|
19
19
|
const common_1 = require("./common");
|
|
20
|
+
const type_1 = require("./type");
|
|
20
21
|
__exportStar(require("./common"), exports);
|
|
21
22
|
__exportStar(require("./baselog"), exports);
|
|
22
23
|
__exportStar(require("./type"), exports);
|
|
23
24
|
function useLog({ environment: _environment, name, request, body, env, correlationId: cid, version, executionContext, logRequest, dataset: _dataset, context: initialContext = {}, }) {
|
|
24
25
|
const environment = _environment || (0, common_1.getEnvironment)(env);
|
|
25
|
-
const colorLogs = env?.[
|
|
26
|
+
const colorLogs = env?.[type_1.LOG_ENV] === '*' || environment === 'development';
|
|
26
27
|
const correlationId = cid || (0, common_1.getCorrelationId)(request); //const logger = nodeColorLog;
|
|
27
|
-
const axiomToken = env?.[
|
|
28
|
+
const axiomToken = env?.[type_1.AXIOM_AUTH_TOKEN_ENV];
|
|
28
29
|
const axiom = (0, baselog_1.createBaseLog)({
|
|
29
30
|
token: axiomToken,
|
|
30
|
-
orgId: env?.[
|
|
31
|
-
dataset: _dataset || env?.[
|
|
31
|
+
orgId: env?.[type_1.AXIOM_ORG_ID_ENV],
|
|
32
|
+
dataset: _dataset || env?.[type_1.AXIOM_DATASET_ENV] || 'default',
|
|
32
33
|
consoleLog: colorLogs ? 'color' : false,
|
|
33
34
|
}, {
|
|
34
35
|
environment,
|
|
@@ -42,8 +43,8 @@ function useLog({ environment: _environment, name, request, body, env, correlati
|
|
|
42
43
|
...initialContext,
|
|
43
44
|
rootCorrelationId: correlationId,
|
|
44
45
|
correlationId,
|
|
45
|
-
taskQueue: request?.headers?.get(
|
|
46
|
-
workflowId: request?.headers?.get(
|
|
46
|
+
taskQueue: request?.headers?.get(type_1.TASK_QUEUE_HEADER) || undefined,
|
|
47
|
+
workflowId: request?.headers?.get(type_1.WORKFLOW_ID_HEADER) || undefined,
|
|
47
48
|
child: undefined,
|
|
48
49
|
},
|
|
49
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAkBA,wBA4GC;AA9HD,uCAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["log/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YACd,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE;oBAC1B,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;gBAEH,OAAO,IAAI,QAAQ,CACjB,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EACrE;oBACE,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,MAAM,KAAK,EAAE,KAAK,EAAE,CAAC;QAErB,OAAO,QAAS,CAAC;IACnB,CAAC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/build/main/log/type.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
export declare const CONNECTION_ID_HEADER = "X-Connection-ID";
|
|
2
|
+
export declare const WORKFLOW_ID_HEADER = "X-Workflow-ID";
|
|
3
|
+
export declare const TASK_QUEUE_HEADER = "X-Task-Queue";
|
|
4
|
+
export declare const CORRELATION_ID_HEADER = "X-Correlation-ID";
|
|
5
|
+
export declare const VERIFICATION_HEADER = "X-Verification-Key";
|
|
6
|
+
export declare const AXIOM_AUTH_TOKEN_ENV = "AXIOM_AUTH_TOKEN";
|
|
7
|
+
export declare const AXIOM_ORG_ID_ENV = "AXIOM_ORG_ID";
|
|
8
|
+
export declare const AXIOM_DATASET_ENV = "AXIOM_DATASET";
|
|
9
|
+
export declare const LOG_ENV = "LOG";
|
|
10
|
+
export type LogBindings = {
|
|
11
|
+
[LOG_ENV]?: string;
|
|
12
|
+
[AXIOM_AUTH_TOKEN_ENV]?: string;
|
|
13
|
+
[AXIOM_ORG_ID_ENV]?: string;
|
|
14
|
+
[AXIOM_DATASET_ENV]?: string;
|
|
15
|
+
NODE_ENV?: string;
|
|
16
|
+
IS_LOCAL_DEV?: string;
|
|
17
|
+
MACHINE_NAME?: string;
|
|
18
|
+
};
|
|
1
19
|
export type LogFn = (message: any, additionalContext?: Record<string, any>) => void;
|
|
2
20
|
export type Log = {
|
|
3
21
|
error: LogFn;
|
package/build/main/log/type.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_ENV = exports.AXIOM_DATASET_ENV = exports.AXIOM_ORG_ID_ENV = exports.AXIOM_AUTH_TOKEN_ENV = exports.VERIFICATION_HEADER = exports.CORRELATION_ID_HEADER = exports.TASK_QUEUE_HEADER = exports.WORKFLOW_ID_HEADER = exports.CONNECTION_ID_HEADER = void 0;
|
|
4
|
+
// Headers
|
|
5
|
+
exports.CONNECTION_ID_HEADER = 'X-Connection-ID';
|
|
6
|
+
exports.WORKFLOW_ID_HEADER = 'X-Workflow-ID';
|
|
7
|
+
exports.TASK_QUEUE_HEADER = 'X-Task-Queue';
|
|
8
|
+
exports.CORRELATION_ID_HEADER = 'X-Correlation-ID';
|
|
9
|
+
exports.VERIFICATION_HEADER = 'X-Verification-Key';
|
|
10
|
+
// Env
|
|
11
|
+
exports.AXIOM_AUTH_TOKEN_ENV = 'AXIOM_AUTH_TOKEN';
|
|
12
|
+
exports.AXIOM_ORG_ID_ENV = 'AXIOM_ORG_ID';
|
|
13
|
+
exports.AXIOM_DATASET_ENV = 'AXIOM_DATASET';
|
|
14
|
+
exports.LOG_ENV = 'LOG';
|
|
3
15
|
//# sourceMappingURL=type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"src/","sources":["log/type.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"src/","sources":["log/type.ts"],"names":[],"mappings":";;;AAAA,UAAU;AACG,QAAA,oBAAoB,GAAG,iBAAiB,CAAC;AACzC,QAAA,kBAAkB,GAAG,eAAe,CAAC;AACrC,QAAA,iBAAiB,GAAG,cAAc,CAAC;AACnC,QAAA,qBAAqB,GAAG,kBAAkB,CAAC;AAC3C,QAAA,mBAAmB,GAAG,oBAAoB,CAAC;AAExD,MAAM;AACO,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAC1C,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,iBAAiB,GAAG,eAAe,CAAC;AACpC,QAAA,OAAO,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Log } from '../log';
|
|
2
|
+
export declare class IntercomAPI {
|
|
3
|
+
constructor(token: string, log?: Log);
|
|
4
|
+
private headers;
|
|
5
|
+
private log?;
|
|
6
|
+
private fetch;
|
|
7
|
+
getUserByUserId(userId: string): Promise<{
|
|
8
|
+
type: "list";
|
|
9
|
+
data: {
|
|
10
|
+
id: string;
|
|
11
|
+
}[] | undefined;
|
|
12
|
+
total_count: 0;
|
|
13
|
+
pages: {
|
|
14
|
+
type: "pages";
|
|
15
|
+
page: 1;
|
|
16
|
+
per_page: 10;
|
|
17
|
+
total_pages: 0;
|
|
18
|
+
};
|
|
19
|
+
} | undefined>;
|
|
20
|
+
createUser({ data, userId, }: {
|
|
21
|
+
userId: string;
|
|
22
|
+
data: {
|
|
23
|
+
email: string;
|
|
24
|
+
name: string;
|
|
25
|
+
custom_attributes: Record<string, any>;
|
|
26
|
+
};
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
updateUser({ data, contactId, }: {
|
|
29
|
+
contactId: string;
|
|
30
|
+
data: {
|
|
31
|
+
email?: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
custom_attributes: Record<string, any>;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<unknown>;
|
|
37
|
+
deleteUser(intercom_contact_id: string): Promise<{
|
|
38
|
+
id: "6657adf56abd0167d9419d1c";
|
|
39
|
+
external_id: "70";
|
|
40
|
+
type: "contact";
|
|
41
|
+
deleted: true;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
createCompanyUser(data: {
|
|
44
|
+
intercom_contact_id: string;
|
|
45
|
+
intercom_company_id: string;
|
|
46
|
+
}): Promise<unknown>;
|
|
47
|
+
deleteCompanyUser({ intercom_company_id, intercom_contact_id, }: {
|
|
48
|
+
intercom_contact_id: string;
|
|
49
|
+
intercom_company_id: string;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
id: "6657adc96abd0167d9419ca7";
|
|
52
|
+
} | undefined>;
|
|
53
|
+
trackEvent(data: {
|
|
54
|
+
user_id: string;
|
|
55
|
+
event_name: string;
|
|
56
|
+
metadata: Record<string, any>;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
getCompanyByTenantId(tenantId: string): Promise<{
|
|
59
|
+
type: "list";
|
|
60
|
+
data: [{
|
|
61
|
+
type: "company";
|
|
62
|
+
company_id: "remote_companies_scroll_2";
|
|
63
|
+
id: "664df5436abd01f7945e1a78";
|
|
64
|
+
app_id: "this_is_an_id111_that_should_be_at_least_";
|
|
65
|
+
name: "IntercomQATest1";
|
|
66
|
+
remote_created_at: 1716385091;
|
|
67
|
+
created_at: 1716385091;
|
|
68
|
+
updated_at: 1716385091;
|
|
69
|
+
monthly_spend: 0;
|
|
70
|
+
session_count: 0;
|
|
71
|
+
user_count: 4;
|
|
72
|
+
tags: {
|
|
73
|
+
type: "tag.list";
|
|
74
|
+
tags: [];
|
|
75
|
+
};
|
|
76
|
+
segments: {
|
|
77
|
+
type: "segment.list";
|
|
78
|
+
segments: [];
|
|
79
|
+
};
|
|
80
|
+
custom_attributes: Record<string, string>;
|
|
81
|
+
}] | undefined;
|
|
82
|
+
pages: {
|
|
83
|
+
type: "pages";
|
|
84
|
+
next: null;
|
|
85
|
+
page: 1;
|
|
86
|
+
per_page: 15;
|
|
87
|
+
total_pages: 1;
|
|
88
|
+
};
|
|
89
|
+
total_count: 1;
|
|
90
|
+
} | undefined>;
|
|
91
|
+
createCompany({ data, tenantId, }: {
|
|
92
|
+
tenantId: string;
|
|
93
|
+
data: {
|
|
94
|
+
name: string;
|
|
95
|
+
remote_created_at: number;
|
|
96
|
+
custom_attributes: Record<string, any>;
|
|
97
|
+
};
|
|
98
|
+
}): Promise<unknown>;
|
|
99
|
+
updateCompany({ data, companyId, }: {
|
|
100
|
+
companyId: string;
|
|
101
|
+
data: Record<string, any>;
|
|
102
|
+
}): Promise<unknown>;
|
|
103
|
+
deleteCompany(intercom_company_id: string): Promise<{
|
|
104
|
+
id: "6657adc96abd0167d9419ca7";
|
|
105
|
+
object: "company";
|
|
106
|
+
deleted: true;
|
|
107
|
+
} | undefined>;
|
|
108
|
+
}
|
|
109
|
+
export declare function useIntercom(token: string, log?: Log): IntercomAPI;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntercomAPI = void 0;
|
|
4
|
+
exports.useIntercom = useIntercom;
|
|
5
|
+
class IntercomAPI {
|
|
6
|
+
constructor(token, log) {
|
|
7
|
+
this.headers = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
Accept: 'application/json',
|
|
10
|
+
'Intercom-Version': '2.11',
|
|
11
|
+
Authorization: `Bearer ${token}`,
|
|
12
|
+
};
|
|
13
|
+
this.log = log;
|
|
14
|
+
}
|
|
15
|
+
async fetch(path, options) {
|
|
16
|
+
if (options?.data) {
|
|
17
|
+
options.body = JSON.stringify(options.data);
|
|
18
|
+
options.data = undefined;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const result = await fetch(`https://api.intercom.io${path}`, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers: this.headers,
|
|
24
|
+
...options,
|
|
25
|
+
});
|
|
26
|
+
if (!result.ok) {
|
|
27
|
+
this.log?.info('Failed to fetch from Intercom', {
|
|
28
|
+
result: {
|
|
29
|
+
status: result.status,
|
|
30
|
+
statusText: result.statusText,
|
|
31
|
+
body: await result.text(),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
if (result.status === 404)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (result.status === 429) {
|
|
37
|
+
console.log('Intercom rate limit exceeded, waiting for 1 minute');
|
|
38
|
+
// X-RateLimit-Reset: 1487332520 => timestamp from header response when resetting
|
|
39
|
+
const reset = Number(result.headers.get('X-RateLimit-Reset'));
|
|
40
|
+
if (reset) {
|
|
41
|
+
const now = Math.floor(Date.now() / 1000);
|
|
42
|
+
const wait = reset - now + 1;
|
|
43
|
+
console.log(`Waiting for ${wait} seconds`);
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, wait * 1000));
|
|
45
|
+
return await this.fetch(path, options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result.status === 202 ? {} : (await result.json());
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.log?.error(error);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// User
|
|
57
|
+
async getUserByUserId(userId) {
|
|
58
|
+
return await this.fetch('/contacts/search', {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
data: {
|
|
61
|
+
query: {
|
|
62
|
+
field: 'external_id',
|
|
63
|
+
operator: '=',
|
|
64
|
+
value: userId,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async createUser({ data, userId, }) {
|
|
70
|
+
return await this.fetch('/contacts', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
data: { ...data, external_id: userId },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async updateUser({ data, contactId, }) {
|
|
76
|
+
return await this.fetch(`/contacts/${contactId}`, {
|
|
77
|
+
method: 'PUT',
|
|
78
|
+
data,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async deleteUser(intercom_contact_id) {
|
|
82
|
+
return await this.fetch(`/contacts/${intercom_contact_id}`, {
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async createCompanyUser(data) {
|
|
87
|
+
return await this.fetch(`/contacts/${data.intercom_contact_id}/companies`, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
data: {
|
|
90
|
+
id: data.intercom_company_id,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async deleteCompanyUser({ intercom_company_id, intercom_contact_id, }) {
|
|
95
|
+
return await this.fetch(`/contacts/${intercom_contact_id}/companies/${intercom_company_id}`, {
|
|
96
|
+
method: 'DELETE',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async trackEvent(data) {
|
|
100
|
+
return await this.fetch('/events', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
data: {
|
|
103
|
+
created_at: Math.floor(new Date().getTime() / 1000), // to seconds
|
|
104
|
+
...data,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Company
|
|
109
|
+
async getCompanyByTenantId(tenantId) {
|
|
110
|
+
return await this.fetch(`/companies?company_id=${tenantId}`, {
|
|
111
|
+
method: 'GET',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async createCompany({ data, tenantId, }) {
|
|
115
|
+
return await this.fetch('/companies', {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
data: {
|
|
118
|
+
...data,
|
|
119
|
+
company_id: tenantId,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async updateCompany({ data, companyId, }) {
|
|
124
|
+
return await this.fetch(`/companies/${companyId}`, {
|
|
125
|
+
method: 'PUT',
|
|
126
|
+
data,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async deleteCompany(intercom_company_id) {
|
|
130
|
+
return await this.fetch(`/companies/${intercom_company_id}`, {
|
|
131
|
+
method: 'DELETE',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.IntercomAPI = IntercomAPI;
|
|
136
|
+
function useIntercom(token, log) {
|
|
137
|
+
return new IntercomAPI(token, log);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=_intercom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_intercom.js","sourceRoot":"src/","sources":["tracking/_intercom.ts"],"names":[],"mappings":";;;AA+PA,kCAEC;AA/PD,MAAa,WAAW;IACtB,YAAY,KAAa,EAAE,GAAS;QAClC,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,kBAAkB,EAAE,MAAM;YAC1B,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC,CAAC;QAEF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAKO,KAAK,CAAC,KAAK,CACjB,IAAY,EACZ,OAAsC;QAEtC,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,0BAA0B,IAAI,EAAE,EAAE;gBAC3D,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,OAAO;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACf,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,+BAA+B,EAAE;oBAC9C,MAAM,EAAE;wBACN,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,UAAU,EAAE,MAAM,CAAC,UA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
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
declare module 'intercom-client' {
|
|
2
|
+
namespace Intercom {
|
|
3
|
+
interface CreateContactRequestWithExternalId {
|
|
4
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
5
|
+
external_id: string;
|
|
6
|
+
/** The contacts phone */
|
|
7
|
+
phone?: string;
|
|
8
|
+
/** The contacts name */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** An image URL containing the avatar of a contact */
|
|
11
|
+
avatar?: string;
|
|
12
|
+
/** The time specified for when a contact signed up */
|
|
13
|
+
signed_up_at?: number;
|
|
14
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
15
|
+
last_seen_at?: number;
|
|
16
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
17
|
+
owner_id?: number;
|
|
18
|
+
/** Whether the contact is unsubscribed from emails */
|
|
19
|
+
unsubscribed_from_emails?: boolean;
|
|
20
|
+
/** The custom attributes which are set for the contact */
|
|
21
|
+
custom_attributes?: ContactCustomAttributes;
|
|
22
|
+
}
|
|
23
|
+
interface UpdateContactRequest {
|
|
24
|
+
/** The role of the contact. */
|
|
25
|
+
role?: 'user' | 'lead';
|
|
26
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
27
|
+
external_id?: string;
|
|
28
|
+
/** The contacts email */
|
|
29
|
+
email?: string;
|
|
30
|
+
/** The contacts phone */
|
|
31
|
+
phone?: string;
|
|
32
|
+
/** The contacts name */
|
|
33
|
+
name?: string;
|
|
34
|
+
/** An image URL containing the avatar of a contact */
|
|
35
|
+
avatar?: string;
|
|
36
|
+
/** The time specified for when a contact signed up */
|
|
37
|
+
signed_up_at?: number;
|
|
38
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
39
|
+
last_seen_at?: number;
|
|
40
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
41
|
+
owner_id?: number;
|
|
42
|
+
/** Whether the contact is unsubscribed from emails */
|
|
43
|
+
unsubscribed_from_emails?: boolean;
|
|
44
|
+
/** The custom attributes which are set for the contact */
|
|
45
|
+
custom_attributes?: ContactCustomAttributes;
|
|
46
|
+
}
|
|
47
|
+
interface ContactCustomAttributes {
|
|
48
|
+
Onboarding_Support?: string;
|
|
49
|
+
userType?: string;
|
|
50
|
+
}
|
|
51
|
+
interface CreateOrUpdateCompanyRequest {
|
|
52
|
+
/** The name of the Company */
|
|
53
|
+
name?: string;
|
|
54
|
+
/** The company id you have defined for the company. Can't be updated */
|
|
55
|
+
company_id?: string;
|
|
56
|
+
/** The name of the plan you have associated with the company. */
|
|
57
|
+
plan?: string;
|
|
58
|
+
/** The number of employees in this company. */
|
|
59
|
+
size?: number;
|
|
60
|
+
/** The URL for this company's website. Please note that the value specified here is not validated. Accepts any string. */
|
|
61
|
+
website?: string;
|
|
62
|
+
/** The industry that this company operates in. */
|
|
63
|
+
industry?: string;
|
|
64
|
+
/** A hash of key/value pairs containing any other data about the company you want Intercom to store. */
|
|
65
|
+
custom_attributes?: CompanyCustomAttributes;
|
|
66
|
+
/** The time the company was created by you. */
|
|
67
|
+
remote_created_at?: number;
|
|
68
|
+
/** How much revenue the company generates for your business. Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2\*\*31-1 or 2147483647.. */
|
|
69
|
+
monthly_spend?: number;
|
|
70
|
+
}
|
|
71
|
+
interface CompanyCustomAttributes {
|
|
72
|
+
teamId?: string;
|
|
73
|
+
team?: string;
|
|
74
|
+
type?: string;
|
|
75
|
+
status?: string;
|
|
76
|
+
pms?: string;
|
|
77
|
+
accountingSoftware?: string;
|
|
78
|
+
creation_source?: string;
|
|
79
|
+
activeListings?: number;
|
|
80
|
+
paymentMethodType?: string;
|
|
81
|
+
partnerName?: string;
|
|
82
|
+
billingPortalUrl?: string;
|
|
83
|
+
billingStatus?: string;
|
|
84
|
+
billingPartner?: string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
import { Analytics } from '@june-so/analytics-node';
|
|
89
|
+
import { IntercomClient } from 'intercom-client';
|
|
90
|
+
import { PostHog } from 'posthog-node';
|
|
91
|
+
import { type WorkerLog } from '../log';
|
|
92
|
+
import type { GroupProps, IdentifyProps, TrackProps, TrackingProps } from './types';
|
|
93
|
+
export * from './types';
|
|
94
|
+
export * from 'intercom-client';
|
|
10
95
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
11
|
-
type OptionalUser<T> = T & ({
|
|
12
|
-
userId: string;
|
|
13
|
-
anonymousId?: string;
|
|
14
|
-
} | {
|
|
15
|
-
userId?: string;
|
|
16
|
-
anonymousId: string;
|
|
17
|
-
});
|
|
18
96
|
export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?: boolean) => {
|
|
19
|
-
track: (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
traits: Record<string, any>;
|
|
28
|
-
disableGeoip?: boolean;
|
|
29
|
-
}) => void;
|
|
30
|
-
group: ({ traits, groupId, userId, anonymousId, }: OptionalUser<{
|
|
31
|
-
groupId: string;
|
|
32
|
-
traits?: Record<string, any>;
|
|
33
|
-
}>) => void;
|
|
34
|
-
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
35
|
-
alias: ((data: {
|
|
36
|
-
distinctId: string;
|
|
37
|
-
alias: string;
|
|
38
|
-
disableGeoip?: boolean;
|
|
39
|
-
}) => void) | undefined;
|
|
40
|
-
isFeatureEnabled: ((key: string, distinctId: string, options?: {
|
|
41
|
-
groups?: Record<string, string>;
|
|
42
|
-
personProperties?: Record<string, string>;
|
|
43
|
-
groupProperties?: Record<string, Record<string, string>>;
|
|
44
|
-
onlyEvaluateLocally?: boolean;
|
|
45
|
-
sendFeatureFlagEvents?: boolean;
|
|
46
|
-
disableGeoip?: boolean;
|
|
47
|
-
}) => Promise<boolean | undefined>) | undefined;
|
|
48
|
-
intercom: import("./intercom").IntercomAPI | undefined;
|
|
49
|
-
log: import("../log").WorkerLog;
|
|
97
|
+
track: (props: TrackProps) => Promise<void>;
|
|
98
|
+
identify: (props: IdentifyProps) => Promise<void>;
|
|
99
|
+
group: (props: GroupProps) => Promise<void>;
|
|
100
|
+
shutdown: () => Promise<any>;
|
|
101
|
+
log: WorkerLog;
|
|
102
|
+
june?: Analytics;
|
|
103
|
+
intercom?: IntercomClient;
|
|
104
|
+
posthog?: PostHog;
|
|
50
105
|
};
|
|
51
|
-
export {};
|