@inploi/sdk 0.2.0 → 0.4.0
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/cdn/plugins/journeys.js +82 -0
- package/cdn/sdk.js +121 -0
- package/dist/chunk-FAONCAHI.mjs +2 -0
- package/dist/chunk-FAONCAHI.mjs.map +1 -0
- package/dist/common.plugins-fecd9dad.d.ts +26 -0
- package/dist/journeys/{index.d.mts → journeys.d.mts} +1 -2
- package/dist/journeys/{index.d.ts → journeys.d.ts} +1 -2
- package/dist/journeys/journeys.js +2 -0
- package/dist/journeys/journeys.js.map +1 -0
- package/dist/journeys/journeys.mjs +2 -0
- package/dist/journeys/journeys.mjs.map +1 -0
- package/dist/{index-d9ce7ffb.d.ts → sdk.d.mts} +4 -26
- package/dist/sdk.d.ts +31 -0
- package/dist/sdk.js +2 -0
- package/dist/sdk.js.map +1 -0
- package/dist/sdk.mjs +2 -0
- package/dist/sdk.mjs.map +1 -0
- package/package.json +5 -3
- package/dist/chunk-A5DU6CID.mjs +0 -2
- package/dist/chunk-A5DU6CID.mjs.map +0 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
- package/dist/journeys/index.js +0 -2
- package/dist/journeys/index.js.map +0 -1
- package/dist/journeys/index.mjs +0 -2
- package/dist/journeys/index.mjs.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// This file is generated automatically. Do not edit it manually.
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
(() => {
|
|
5
|
+
var __async = (__this, __arguments, generator) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
var fulfilled = (value) => {
|
|
8
|
+
try {
|
|
9
|
+
step(generator.next(value));
|
|
10
|
+
} catch (e) {
|
|
11
|
+
reject(e);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var rejected = (value) => {
|
|
15
|
+
try {
|
|
16
|
+
step(generator.throw(value));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
reject(e);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/common/common.plugins.ts
|
|
27
|
+
var createPlugin = (pluginName, { initialise }) => ({
|
|
28
|
+
pluginName,
|
|
29
|
+
initialise
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// src/common/common.constants.ts
|
|
33
|
+
var SDK_VERSION = 1;
|
|
34
|
+
|
|
35
|
+
// src/journeys/journeys.constants.ts
|
|
36
|
+
var JOURNEY_PATHNAME = "/journey/log";
|
|
37
|
+
|
|
38
|
+
// src/journeys/journeys.log.ts
|
|
39
|
+
function initialiseJourneysPlugin({ apiClient, logger }) {
|
|
40
|
+
function log(params) {
|
|
41
|
+
return __async(this, null, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const data = {
|
|
44
|
+
event: params.event,
|
|
45
|
+
sent_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
46
|
+
context: {
|
|
47
|
+
library: {
|
|
48
|
+
name: "inploi-sdk",
|
|
49
|
+
version: SDK_VERSION
|
|
50
|
+
},
|
|
51
|
+
page: {
|
|
52
|
+
href: location.href,
|
|
53
|
+
referrer: document.referrer,
|
|
54
|
+
title: document.title
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
properties: params.properties,
|
|
58
|
+
custom_properties: params.customProperties
|
|
59
|
+
};
|
|
60
|
+
yield apiClient.fetch(JOURNEY_PATHNAME, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
body: JSON.stringify(data)
|
|
63
|
+
});
|
|
64
|
+
return { success: true, data };
|
|
65
|
+
} catch (e) {
|
|
66
|
+
logger == null ? void 0 : logger.error("Failed to send journey log to API. Inspect error response of `log` for more information.");
|
|
67
|
+
return { success: false, error: e };
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return { log };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/journeys/journeys.ts
|
|
75
|
+
var journeysPlugin = createPlugin("journey", { initialise: initialiseJourneysPlugin });
|
|
76
|
+
|
|
77
|
+
// src/journeys/journeys.cdn.ts
|
|
78
|
+
if (typeof window.inploi !== "object") {
|
|
79
|
+
throw new Error("Please insert the SDK script tag above the plugins.");
|
|
80
|
+
}
|
|
81
|
+
window.inploi.journeysPlugin = journeysPlugin;
|
|
82
|
+
})();
|
package/cdn/sdk.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// This file is generated automatically. Do not edit it manually.
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
(() => {
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defProps = Object.defineProperties;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/journeys/journeys.constants.ts
|
|
46
|
+
var ENV_TO_API_URL = {
|
|
47
|
+
sandbox: "https://preview.api.inploi.com",
|
|
48
|
+
production: "https://api.inploi.com"
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/journeys/journeys.api.ts
|
|
52
|
+
var unauthenticatedMessage = "Unauthenticated";
|
|
53
|
+
var unauthorisedMessage = "This action is unauthorized.";
|
|
54
|
+
var createApiClient = (params) => {
|
|
55
|
+
const defaultHeaders = {
|
|
56
|
+
Accept: "application/json",
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
"x-publishable-key": params.publishableKey
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
fetch: (_0, ..._1) => __async(void 0, [_0, ..._1], function* (pathname, options = {}) {
|
|
62
|
+
const init = __spreadProps(__spreadValues({}, options), { headers: __spreadValues(__spreadValues({}, options.headers), defaultHeaders) });
|
|
63
|
+
const response = yield fetch(`${params.baseUrl}${pathname}`, init).then((res) => res.json());
|
|
64
|
+
if ("message" in response) {
|
|
65
|
+
if (response.message === unauthenticatedMessage) {
|
|
66
|
+
throw new Error("You are not authenticated.");
|
|
67
|
+
}
|
|
68
|
+
if (response.message === unauthorisedMessage) {
|
|
69
|
+
throw new Error("You are not authenticated.");
|
|
70
|
+
}
|
|
71
|
+
if ("exception" in response) {
|
|
72
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
73
|
+
}
|
|
74
|
+
if ("errors" in response) {
|
|
75
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/common/common.logger.ts
|
|
84
|
+
var CONSOLE_PREFIX = "%c[inploi SDK]";
|
|
85
|
+
var CONSOLE_STYLE = "color: #65BC67; font-weight: bold;";
|
|
86
|
+
var inploiBrandedLogger = {
|
|
87
|
+
warn: (message) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
88
|
+
error: (message) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
89
|
+
info: (message) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
90
|
+
log: (message) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message)
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// ../core/dist/chunk-H7ZOE7ZC.mjs
|
|
94
|
+
function invariant(condition, message) {
|
|
95
|
+
if (condition) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(message);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/sdk.ts
|
|
102
|
+
function initialiseSdk({
|
|
103
|
+
publishableKey,
|
|
104
|
+
env,
|
|
105
|
+
plugins,
|
|
106
|
+
logger = inploiBrandedLogger
|
|
107
|
+
}) {
|
|
108
|
+
invariant(typeof window !== "undefined", "Can't initialise the inploi SDK outside of a browser environment.");
|
|
109
|
+
const apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });
|
|
110
|
+
const pluginsObj = plugins.reduce((acc, plugin) => {
|
|
111
|
+
acc[plugin.pluginName] = plugin.initialise({ apiClient, logger });
|
|
112
|
+
return acc;
|
|
113
|
+
}, {});
|
|
114
|
+
return pluginsObj;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/sdk.cdn.ts
|
|
118
|
+
if (typeof window.inploi !== "object")
|
|
119
|
+
window.inploi = {};
|
|
120
|
+
window.inploi.initialiseSdk = initialiseSdk;
|
|
121
|
+
})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var _=Object.defineProperty,a=Object.defineProperties;var d=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var m=(n,p,o)=>p in n?_(n,p,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[p]=o,x=(n,p)=>{for(var o in p||(p={}))l.call(p,o)&&m(n,o,p[o]);if(c)for(var o of c(p))v.call(p,o)&&m(n,o,p[o]);return n},N=(n,p)=>a(n,d(p));var R=(n,p,o)=>new Promise((s,e)=>{var A=t=>{try{i(o.next(t))}catch(r){e(r)}},E=t=>{try{i(o.throw(t))}catch(r){e(r)}},i=t=>t.done?s(t.value):Promise.resolve(t.value).then(A,E);i((o=o.apply(n,p)).next())});var h={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},u="/journey/log";export{x as a,N as b,R as c,h as d,u as e};
|
|
2
|
+
//# sourceMappingURL=chunk-FAONCAHI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/journeys/journeys.constants.ts"],"sourcesContent":["import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n"],"mappings":"0nBAEO,IAAMA,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,EAEaC,EAAmB","names":["ENV_TO_API_URL","JOURNEY_PATHNAME"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare const CONSOLE_PREFIX = "%c[inploi SDK]";
|
|
2
|
+
declare const CONSOLE_STYLE = "color: #65BC67; font-weight: bold;";
|
|
3
|
+
type LogMessage = (...data: any[]) => void;
|
|
4
|
+
type Logger = {
|
|
5
|
+
warn: LogMessage;
|
|
6
|
+
error: LogMessage;
|
|
7
|
+
info: LogMessage;
|
|
8
|
+
log: LogMessage;
|
|
9
|
+
};
|
|
10
|
+
declare const inploiBrandedLogger: Logger;
|
|
11
|
+
declare const noLogging: Logger;
|
|
12
|
+
|
|
13
|
+
type ApiClient = {
|
|
14
|
+
fetch: (pathname: string, options?: RequestInit) => Promise<unknown>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type PluginParams = {
|
|
18
|
+
apiClient: ApiClient;
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
};
|
|
21
|
+
type Plugin<T extends string, P> = {
|
|
22
|
+
pluginName: T;
|
|
23
|
+
initialise: (params: PluginParams) => P;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { CONSOLE_PREFIX as C, Logger as L, Plugin as P, CONSOLE_STYLE as a, inploiBrandedLogger as i, noLogging as n };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { P as Plugin } from '../
|
|
2
|
-
export { I as InitialiseInploiSdkParams, i as initialiseInploiSdk } from '../index-d9ce7ffb.js';
|
|
1
|
+
import { P as Plugin } from '../common.plugins-fecd9dad.js';
|
|
3
2
|
import * as _inploi_core_common from '@inploi/core/common';
|
|
4
3
|
|
|
5
4
|
declare const journeysPlugin: Plugin<"journey", {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { P as Plugin } from '../
|
|
2
|
-
export { I as InitialiseInploiSdkParams, i as initialiseInploiSdk } from '../index-d9ce7ffb.js';
|
|
1
|
+
import { P as Plugin } from '../common.plugins-fecd9dad.js';
|
|
3
2
|
import * as _inploi_core_common from '@inploi/core/common';
|
|
4
3
|
|
|
5
4
|
declare const journeysPlugin: Plugin<"journey", {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var n in e)a(r,n,{get:e[n],enumerable:!0})},v=(r,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of d(e))!f.call(r,t)&&t!==n&&a(r,t,{get:()=>e[t],enumerable:!(o=y(e,t))||o.enumerable});return r};var T=r=>v(a({},"__esModule",{value:!0}),r);var P=(r,e,n)=>new Promise((o,t)=>{var c=i=>{try{p(n.next(i))}catch(s){t(s)}},g=i=>{try{p(n.throw(i))}catch(s){t(s)}},p=i=>i.done?o(i.value):Promise.resolve(i.value).then(c,g);p((n=n.apply(r,e)).next())});var A={};E(A,{journeysPlugin:()=>_});module.exports=T(A);var m=(r,{initialise:e})=>({pluginName:r,initialise:e});var u="/journey/log";function l({apiClient:r,logger:e}){function n(o){return P(this,null,function*(){try{let t={event:o.event,sent_at:new Date().toISOString(),context:{library:{name:"inploi-sdk",version:1},page:{href:location.href,referrer:document.referrer,title:document.title}},properties:o.properties,custom_properties:o.customProperties};return yield r.fetch(u,{method:"POST",body:JSON.stringify(t)}),{success:!0,data:t}}catch(t){return e==null||e.error("Failed to send journey log to API. Inspect error response of `log` for more information."),{success:!1,error:t}}})}return{log:n}}var _=m("journey",{initialise:l});0&&(module.exports={journeysPlugin});
|
|
2
|
+
//# sourceMappingURL=journeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/journeys/journeys.ts","../../src/common/common.plugins.ts","../../src/journeys/journeys.constants.ts","../../src/journeys/journeys.log.ts"],"sourcesContent":["import { createPlugin } from '../common/common.plugins';\nimport { initialiseJourneysPlugin } from './journeys.log';\n\nexport const journeysPlugin = createPlugin('journey', { initialise: initialiseJourneysPlugin });\n","import { Logger } from './common.logger';\nimport { ApiClient } from '../journeys/journeys.api';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger?: Logger;\n};\n\nexport type Plugin<T extends string, P> = {\n\tpluginName: T;\n\tinitialise: (params: PluginParams) => P;\n};\n\nexport const createPlugin = <T extends string, P>(\n\tpluginName: T,\n\t{ initialise }: { initialise: (params: PluginParams) => P }\n): Plugin<T, P> => ({\n\tpluginName,\n\tinitialise,\n});\n","import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n","import { Flatten, ResponseObj } from '@inploi/core/common';\nimport { SDK_VERSION } from '../common/common.constants';\nimport { JOURNEY_PATHNAME } from './journeys.constants';\nimport { PluginParams } from '../common/common.plugins';\n\ntype JourneyLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id?: string | number | null; // * inploi job id or external job id?\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: undefined;\n\t };\n\nexport type JourneyLogEvent = JourneyLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in JourneyLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype TrackPayload<P> = {\n\tevent: JourneyLogEvent;\n\tsent_at: string;\n\tcontext: {\n\t\tlibrary: {\n\t\t\tname: 'inploi-sdk';\n\t\t\tversion: number;\n\t\t};\n\t\tpage: {\n\t\t\thref: string;\n\t\t\treferrer: string;\n\t\t\ttitle: string;\n\t\t};\n\t};\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\nexport function initialiseJourneysPlugin({ apiClient, logger }: PluginParams) {\n\tasync function log<T extends keyof EventPropertyMap>(\n\t\tparams: { event: T; customProperties?: Record<string, unknown> } & EventPropertyMap[T]\n\t): Promise<ResponseObj<TrackPayload<EventPropertyMap[T]['properties']>>> {\n\t\ttry {\n\t\t\tconst data: TrackPayload<EventPropertyMap[T]['properties']> = {\n\t\t\t\tevent: params.event,\n\t\t\t\tsent_at: new Date().toISOString(),\n\t\t\t\tcontext: {\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: 'inploi-sdk' as const,\n\t\t\t\t\t\tversion: SDK_VERSION,\n\t\t\t\t\t},\n\t\t\t\t\tpage: {\n\t\t\t\t\t\thref: location.href,\n\t\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\t\ttitle: document.title,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tproperties: params.properties as EventPropertyMap[T]['properties'],\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tawait apiClient.fetch(JOURNEY_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(data),\n\t\t\t});\n\n\t\t\treturn { success: true, data };\n\t\t} catch (e) {\n\t\t\t/** We dont’t log any PII on the console */\n\t\t\tlogger?.error('Failed to send journey log to API. Inspect error response of `log` for more information.');\n\t\t\treturn { success: false, error: e };\n\t\t}\n\t}\n\n\treturn { log };\n}\n"],"mappings":"snBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GCaO,IAAMI,EAAe,CAC3BC,EACA,CAAE,WAAAC,CAAW,KACM,CACnB,WAAAD,EACA,WAAAC,CACD,GCZO,IAAMC,EAAmB,eCkCzB,SAASC,EAAyB,CAAE,UAAAC,EAAW,OAAAC,CAAO,EAAiB,CAC7E,SAAeC,EACdC,EACwE,QAAAC,EAAA,sBACxE,GAAI,CACH,IAAMC,EAAwD,CAC7D,MAAOF,EAAO,MACd,QAAS,IAAI,KAAK,EAAE,YAAY,EAChC,QAAS,CACR,QAAS,CACR,KAAM,aACN,QAAS,CACV,EACA,KAAM,CACL,KAAM,SAAS,KACf,SAAU,SAAS,SACnB,MAAO,SAAS,KACjB,CACD,EACA,WAAYA,EAAO,WACnB,kBAAmBA,EAAO,gBAC3B,EAEA,aAAMH,EAAU,MAAMM,EAAkB,CACvC,OAAQ,OACR,KAAM,KAAK,UAAUD,CAAI,CAC1B,CAAC,EAEM,CAAE,QAAS,GAAM,KAAAA,CAAK,CAC9B,OAASE,EAAG,CAEX,OAAAN,GAAA,MAAAA,EAAQ,MAAM,4FACP,CAAE,QAAS,GAAO,MAAOM,CAAE,CACnC,CACD,GAEA,MAAO,CAAE,IAAAL,CAAI,CACd,CH3EO,IAAMM,EAAiBC,EAAa,UAAW,CAAE,WAAYC,CAAyB,CAAC","names":["journeys_exports","__export","journeysPlugin","__toCommonJS","createPlugin","pluginName","initialise","JOURNEY_PATHNAME","initialiseJourneysPlugin","apiClient","logger","log","params","__async","data","JOURNEY_PATHNAME","e","journeysPlugin","createPlugin","initialiseJourneysPlugin"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as o,e as i}from"../chunk-FAONCAHI.mjs";var s=(t,{initialise:e})=>({pluginName:t,initialise:e});function p({apiClient:t,logger:e}){function a(n){return o(this,null,function*(){try{let r={event:n.event,sent_at:new Date().toISOString(),context:{library:{name:"inploi-sdk",version:1},page:{href:location.href,referrer:document.referrer,title:document.title}},properties:n.properties,custom_properties:n.customProperties};return yield t.fetch(i,{method:"POST",body:JSON.stringify(r)}),{success:!0,data:r}}catch(r){return e==null||e.error("Failed to send journey log to API. Inspect error response of `log` for more information."),{success:!1,error:r}}})}return{log:a}}var T=s("journey",{initialise:p});export{T as journeysPlugin};
|
|
2
|
+
//# sourceMappingURL=journeys.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/common.plugins.ts","../../src/journeys/journeys.log.ts","../../src/journeys/journeys.ts"],"sourcesContent":["import { Logger } from './common.logger';\nimport { ApiClient } from '../journeys/journeys.api';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger?: Logger;\n};\n\nexport type Plugin<T extends string, P> = {\n\tpluginName: T;\n\tinitialise: (params: PluginParams) => P;\n};\n\nexport const createPlugin = <T extends string, P>(\n\tpluginName: T,\n\t{ initialise }: { initialise: (params: PluginParams) => P }\n): Plugin<T, P> => ({\n\tpluginName,\n\tinitialise,\n});\n","import { Flatten, ResponseObj } from '@inploi/core/common';\nimport { SDK_VERSION } from '../common/common.constants';\nimport { JOURNEY_PATHNAME } from './journeys.constants';\nimport { PluginParams } from '../common/common.plugins';\n\ntype JourneyLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id?: string | number | null; // * inploi job id or external job id?\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: undefined;\n\t };\n\nexport type JourneyLogEvent = JourneyLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in JourneyLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype TrackPayload<P> = {\n\tevent: JourneyLogEvent;\n\tsent_at: string;\n\tcontext: {\n\t\tlibrary: {\n\t\t\tname: 'inploi-sdk';\n\t\t\tversion: number;\n\t\t};\n\t\tpage: {\n\t\t\thref: string;\n\t\t\treferrer: string;\n\t\t\ttitle: string;\n\t\t};\n\t};\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\nexport function initialiseJourneysPlugin({ apiClient, logger }: PluginParams) {\n\tasync function log<T extends keyof EventPropertyMap>(\n\t\tparams: { event: T; customProperties?: Record<string, unknown> } & EventPropertyMap[T]\n\t): Promise<ResponseObj<TrackPayload<EventPropertyMap[T]['properties']>>> {\n\t\ttry {\n\t\t\tconst data: TrackPayload<EventPropertyMap[T]['properties']> = {\n\t\t\t\tevent: params.event,\n\t\t\t\tsent_at: new Date().toISOString(),\n\t\t\t\tcontext: {\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: 'inploi-sdk' as const,\n\t\t\t\t\t\tversion: SDK_VERSION,\n\t\t\t\t\t},\n\t\t\t\t\tpage: {\n\t\t\t\t\t\thref: location.href,\n\t\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\t\ttitle: document.title,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tproperties: params.properties as EventPropertyMap[T]['properties'],\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tawait apiClient.fetch(JOURNEY_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(data),\n\t\t\t});\n\n\t\t\treturn { success: true, data };\n\t\t} catch (e) {\n\t\t\t/** We dont’t log any PII on the console */\n\t\t\tlogger?.error('Failed to send journey log to API. Inspect error response of `log` for more information.');\n\t\t\treturn { success: false, error: e };\n\t\t}\n\t}\n\n\treturn { log };\n}\n","import { createPlugin } from '../common/common.plugins';\nimport { initialiseJourneysPlugin } from './journeys.log';\n\nexport const journeysPlugin = createPlugin('journey', { initialise: initialiseJourneysPlugin });\n"],"mappings":"iDAaO,IAAMA,EAAe,CAC3BC,EACA,CAAE,WAAAC,CAAW,KACM,CACnB,WAAAD,EACA,WAAAC,CACD,GCsBO,SAASC,EAAyB,CAAE,UAAAC,EAAW,OAAAC,CAAO,EAAiB,CAC7E,SAAeC,EACdC,EACwE,QAAAC,EAAA,sBACxE,GAAI,CACH,IAAMC,EAAwD,CAC7D,MAAOF,EAAO,MACd,QAAS,IAAI,KAAK,EAAE,YAAY,EAChC,QAAS,CACR,QAAS,CACR,KAAM,aACN,QAAS,CACV,EACA,KAAM,CACL,KAAM,SAAS,KACf,SAAU,SAAS,SACnB,MAAO,SAAS,KACjB,CACD,EACA,WAAYA,EAAO,WACnB,kBAAmBA,EAAO,gBAC3B,EAEA,aAAMH,EAAU,MAAMM,EAAkB,CACvC,OAAQ,OACR,KAAM,KAAK,UAAUD,CAAI,CAC1B,CAAC,EAEM,CAAE,QAAS,GAAM,KAAAA,CAAK,CAC9B,OAASE,EAAG,CAEX,OAAAN,GAAA,MAAAA,EAAQ,MAAM,4FACP,CAAE,QAAS,GAAO,MAAOM,CAAE,CACnC,CACD,GAEA,MAAO,CAAE,IAAAL,CAAI,CACd,CC3EO,IAAMM,EAAiBC,EAAa,UAAW,CAAE,WAAYC,CAAyB,CAAC","names":["createPlugin","pluginName","initialise","initialiseJourneysPlugin","apiClient","logger","log","params","__async","data","JOURNEY_PATHNAME","e","journeysPlugin","createPlugin","initialiseJourneysPlugin"]}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type LogMessage = (...data: any[]) => void;
|
|
4
|
-
type Logger = {
|
|
5
|
-
warn: LogMessage;
|
|
6
|
-
error: LogMessage;
|
|
7
|
-
info: LogMessage;
|
|
8
|
-
log: LogMessage;
|
|
9
|
-
};
|
|
10
|
-
declare const inploiBrandedLogger: Logger;
|
|
11
|
-
declare const noLogging: Logger;
|
|
1
|
+
import { P as Plugin, L as Logger } from './common.plugins-fecd9dad.js';
|
|
2
|
+
export { C as CONSOLE_PREFIX, a as CONSOLE_STYLE, i as inploiBrandedLogger, n as noLogging } from './common.plugins-fecd9dad.js';
|
|
12
3
|
|
|
13
4
|
/**
|
|
14
5
|
* The environment the SDK should run in.
|
|
@@ -17,19 +8,6 @@ declare const noLogging: Logger;
|
|
|
17
8
|
*/
|
|
18
9
|
type AppEnvironment = 'production' | 'sandbox';
|
|
19
10
|
|
|
20
|
-
type ApiClient = {
|
|
21
|
-
fetch: (pathname: string, options?: RequestInit) => Promise<unknown>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type PluginParams = {
|
|
25
|
-
apiClient: ApiClient;
|
|
26
|
-
logger?: Logger;
|
|
27
|
-
};
|
|
28
|
-
type Plugin<T extends string, P> = {
|
|
29
|
-
pluginName: T;
|
|
30
|
-
initialise: (params: PluginParams) => P;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
11
|
type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {
|
|
34
12
|
/** Your public API key for the inploi SDK. */
|
|
35
13
|
publishableKey: string;
|
|
@@ -44,10 +22,10 @@ type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {
|
|
|
44
22
|
* */
|
|
45
23
|
logger?: Logger;
|
|
46
24
|
};
|
|
47
|
-
declare function
|
|
25
|
+
declare function initialiseSdk<TPlugin extends Plugin<any, any>>({ publishableKey, env, plugins, logger, }: InitialiseInploiSdkParams<TPlugin>): { [K in TPlugin["pluginName"]]: ReturnType<(TPlugin & {
|
|
48
26
|
pluginName: K;
|
|
49
27
|
} extends infer T ? { [k in keyof T]: (TPlugin & {
|
|
50
28
|
pluginName: K;
|
|
51
29
|
})[k]; } : never)["initialise"]>; };
|
|
52
30
|
|
|
53
|
-
export {
|
|
31
|
+
export { InitialiseInploiSdkParams, Logger, initialiseSdk };
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { P as Plugin, L as Logger } from './common.plugins-fecd9dad.js';
|
|
2
|
+
export { C as CONSOLE_PREFIX, a as CONSOLE_STYLE, i as inploiBrandedLogger, n as noLogging } from './common.plugins-fecd9dad.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The environment the SDK should run in.
|
|
6
|
+
* - `production`: data will be stored and displayed on dashboards
|
|
7
|
+
* - `sandbox`: data will be stored temporarily and purged periodically
|
|
8
|
+
*/
|
|
9
|
+
type AppEnvironment = 'production' | 'sandbox';
|
|
10
|
+
|
|
11
|
+
type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {
|
|
12
|
+
/** Your public API key for the inploi SDK. */
|
|
13
|
+
publishableKey: string;
|
|
14
|
+
/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */
|
|
15
|
+
plugins: P[];
|
|
16
|
+
/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.
|
|
17
|
+
* Anything other than `production` should be considered a development environment and the data periodicaly purged. */
|
|
18
|
+
env: AppEnvironment;
|
|
19
|
+
/** Logger object that handles logging of different levels.
|
|
20
|
+
* You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.
|
|
21
|
+
* @default inploiBrandedLogger
|
|
22
|
+
* */
|
|
23
|
+
logger?: Logger;
|
|
24
|
+
};
|
|
25
|
+
declare function initialiseSdk<TPlugin extends Plugin<any, any>>({ publishableKey, env, plugins, logger, }: InitialiseInploiSdkParams<TPlugin>): { [K in TPlugin["pluginName"]]: ReturnType<(TPlugin & {
|
|
26
|
+
pluginName: K;
|
|
27
|
+
} extends infer T ? { [k in keyof T]: (TPlugin & {
|
|
28
|
+
pluginName: K;
|
|
29
|
+
})[k]; } : never)["initialise"]>; };
|
|
30
|
+
|
|
31
|
+
export { InitialiseInploiSdkParams, Logger, initialiseSdk };
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty,L=Object.defineProperties,b=Object.getOwnPropertyDescriptor,T=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var w=(e,n,r)=>n in e?l(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,g=(e,n)=>{for(var r in n||(n={}))v.call(n,r)&&w(e,r,n[r]);if(f)for(var r of f(n))O.call(n,r)&&w(e,r,n[r]);return e},x=(e,n)=>L(e,T(n));var S=(e,n)=>{for(var r in n)l(e,r,{get:n[r],enumerable:!0})},I=(e,n,r,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of A(n))!v.call(e,i)&&i!==r&&l(e,i,{get:()=>n[i],enumerable:!(t=b(n,i))||t.enumerable});return e};var N=e=>I(l({},"__esModule",{value:!0}),e);var y=(e,n,r)=>new Promise((t,i)=>{var h=s=>{try{o(r.next(s))}catch(c){i(c)}},a=s=>{try{o(r.throw(s))}catch(c){i(c)}},o=s=>s.done?t(s.value):Promise.resolve(s.value).then(h,a);o((r=r.apply(e,n)).next())});var q={};S(q,{CONSOLE_PREFIX:()=>p,CONSOLE_STYLE:()=>u,initialiseSdk:()=>U,inploiBrandedLogger:()=>d,noLogging:()=>M});module.exports=N(q);var P={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"};var C="Unauthenticated",_="This action is unauthorized.",E=e=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(i,...h)=>y(void 0,[i,...h],function*(r,t={}){let a=x(g({},t),{headers:g(g({},t.headers),n)}),o=yield fetch(`${e.baseUrl}${r}`,a).then(s=>s.json());if("message"in o){if(o.message===C)throw new Error("You are not authenticated.");if(o.message===_)throw new Error("You are not authenticated.");if("exception"in o)throw new Error(`API error: \u201C${o.message}\u201D`);if("errors"in o)throw new Error(`API error: \u201C${o.message}\u201D`)}return o})}};var p="%c[inploi SDK]",u="color: #65BC67; font-weight: bold;",d={warn:e=>console.warn(p,u,e),error:e=>console.error(p,u,e),info:e=>console.info(p,u,e),log:e=>console.log(p,u,e)},M={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};function m(e,n){if(!e)throw new Error(n)}function U({publishableKey:e,env:n,plugins:r,logger:t=d}){m(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let i=E({baseUrl:P[n],publishableKey:e});return r.reduce((a,o)=>(a[o.pluginName]=o.initialise({apiClient:i,logger:t}),a),{})}0&&(module.exports={CONSOLE_PREFIX,CONSOLE_STYLE,initialiseSdk,inploiBrandedLogger,noLogging});
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts","../src/journeys/journeys.constants.ts","../src/journeys/journeys.api.ts","../src/common/common.logger.ts","../../core/src/common/common.utils.ts"],"sourcesContent":["import { ENV_TO_API_URL } from './journeys/journeys.constants';\nimport { createApiClient } from './journeys/journeys.api';\nimport { Logger, inploiBrandedLogger } from './common/common.logger';\n\nimport { Flatten, invariant } from '@inploi/core/common';\nimport { AppEnvironment } from './common/common.constants';\nimport { Plugin } from './common/common.plugins';\n\n/** Different loggers so people can use `noLogging` */\nexport * from './common/common.logger';\n\nexport type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\n\t/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */\n\tplugins: P[];\n\t/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.\n\t * Anything other than `production` should be considered a development environment and the data periodicaly purged. */\n\tenv: AppEnvironment;\n\t/** Logger object that handles logging of different levels.\n\t * You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger;\n};\n\nexport function initialiseSdk<TPlugin extends Plugin<any, any>>({\n\tpublishableKey,\n\tenv,\n\tplugins,\n\tlogger = inploiBrandedLogger,\n}: InitialiseInploiSdkParams<TPlugin>) {\n\tinvariant(typeof window !== 'undefined', \"Can't initialise the inploi SDK outside of a browser environment.\");\n\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\n\tconst pluginsObj = plugins.reduce((acc, plugin) => {\n\t\tacc[plugin.pluginName as TPlugin['pluginName']] = plugin.initialise({ apiClient, logger });\n\t\treturn acc;\n\t}, {} as { [K in TPlugin['pluginName']]: ReturnType<Flatten<TPlugin & { pluginName: K }>['initialise']> });\n\n\treturn pluginsObj;\n}\n","import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n","export const unauthenticatedMessage = 'Unauthenticated';\nexport const unauthorisedMessage = 'This action is unauthorized.';\n\nexport type ApiClient = {\n\tfetch: (pathname: string, options?: RequestInit) => Promise<unknown>;\n};\n\nexport const createApiClient = (params: { baseUrl: string; publishableKey: string }): ApiClient => {\n\tconst defaultHeaders: HeadersInit = {\n\t\tAccept: 'application/json',\n\t\t'Content-Type': 'application/json',\n\t\t'x-publishable-key': params.publishableKey,\n\t};\n\n\treturn {\n\t\tfetch: async (pathname, options = {}) => {\n\t\t\tconst init = { ...options, headers: { ...options.headers, ...defaultHeaders } };\n\t\t\tconst response = await fetch(`${params.baseUrl}${pathname}`, init).then(res => res.json());\n\n\t\t\tif ('message' in response) {\n\t\t\t\tif (response.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (response.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n};\n","export const CONSOLE_PREFIX = '%c[inploi SDK]';\nexport const CONSOLE_STYLE = 'color: #65BC67; font-weight: bold;';\n\ntype LogMessage = (...data: any[]) => void;\nexport type Logger = {\n\twarn: LogMessage;\n\terror: LogMessage;\n\tinfo: LogMessage;\n\tlog: LogMessage;\n};\n\nexport const inploiBrandedLogger: Logger = {\n\twarn: message => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\terror: message => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tinfo: message => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tlog: message => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","export const exhaustive = (value: never) => {\n\tthrow new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n};\n\nexport function invariant(condition: any, message?: string): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\n\tthrow new Error(message);\n}\n\nexport const uniqueOrThrow = <T>(array: T[]) => {\n\tconst uniqueValues = new Set(array);\n\n\tif (array.length !== uniqueValues.size) {\n\t\tthrow new Error('Duplicate values found');\n\t}\n\treturn true;\n};\n\nexport const uniqueByPropertyOrThrow =\n\t<T extends PropertyKey>(propertyKey: T) =>\n\t(array: { [K in T]: any }[]) => {\n\t\tconst values = array.map(item => item[propertyKey]);\n\t\tconst uniqueValues = new Set(values);\n\n\t\tif (values.length !== uniqueValues.size) {\n\t\t\tthrow new Error(`Duplicate values found for property: ${propertyKey.toString()}`);\n\t\t}\n\t\treturn true;\n\t};\n"],"mappings":"i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,wBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAP,GCEO,IAAMQ,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,ECLO,IAAMC,EAAyB,kBACzBC,EAAsB,+BAMtBC,EAAmBC,GAAmE,CAClG,IAAMC,EAA8B,CACnC,OAAQ,mBACR,eAAgB,mBAChB,oBAAqBD,EAAO,cAC7B,EAEA,MAAO,CACN,MAAO,CAAOE,KAA2BC,IAAAC,EAAA,QAA3BF,EAA2B,GAAAC,GAAA,UAA3BE,EAAUC,EAAU,CAAC,EAAM,CACxC,IAAMC,EAAOC,EAAAC,EAAA,GAAKH,GAAL,CAAc,QAASG,IAAA,GAAKH,EAAQ,SAAYL,EAAiB,GACxES,EAAW,MAAM,MAAM,GAAGV,EAAO,OAAO,GAAGK,CAAQ,GAAIE,CAAI,EAAE,KAAKI,GAAOA,EAAI,KAAK,CAAC,EAEzF,GAAI,YAAaD,EAAU,CAC1B,GAAIA,EAAS,UAAYb,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAS,UAAYZ,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,EAEnD,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,CAEpD,CACA,OAAOA,CACR,EACD,CACD,ECpCO,IAAME,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAMC,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,MAAOA,GAAW,QAAQ,MAAMH,EAAgBC,EAAeE,CAAO,EACtE,KAAMA,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,IAAKA,GAAW,QAAQ,IAAIH,EAAgBC,EAAeE,CAAO,CACnE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECd3G,SAASC,EAAUC,EAAgBC,EAAqC,CAC9E,GAAI,CAAAD,EAIJ,MAAM,IAAI,MAAMC,CAAO,CACxB,CJgBO,SAASC,EAAgD,CAC/D,eAAAC,EACA,IAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,CACV,EAAuC,CACtCC,EAAU,OAAO,QAAW,YAAa,mEAAmE,EAE5G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeP,CAAG,EAAG,eAAAD,CAAe,CAAC,EAOlF,OALmBE,EAAQ,OAAO,CAACO,EAAKC,KACvCD,EAAIC,EAAO,UAAmC,EAAIA,EAAO,WAAW,CAAE,UAAAJ,EAAW,OAAAH,CAAO,CAAC,EAClFM,GACL,CAAC,CAAqG,CAG1G","names":["sdk_exports","__export","CONSOLE_PREFIX","CONSOLE_STYLE","initialiseSdk","inploiBrandedLogger","noLogging","__toCommonJS","ENV_TO_API_URL","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","response","res","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","message","noLogging","invariant","condition","message","initialiseSdk","publishableKey","env","plugins","logger","inploiBrandedLogger","invariant","apiClient","createApiClient","ENV_TO_API_URL","acc","plugin"]}
|
package/dist/sdk.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as t,b as p,c as g,d as c}from"./chunk-FAONCAHI.mjs";var w="Unauthenticated",v="This action is unauthorized.",d=e=>{let r={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(f,...x)=>g(void 0,[f,...x],function*(u,o={}){let i=p(t({},o),{headers:t(t({},o.headers),r)}),n=yield fetch(`${e.baseUrl}${u}`,i).then(m=>m.json());if("message"in n){if(n.message===w)throw new Error("You are not authenticated.");if(n.message===v)throw new Error("You are not authenticated.");if("exception"in n)throw new Error(`API error: \u201C${n.message}\u201D`);if("errors"in n)throw new Error(`API error: \u201C${n.message}\u201D`)}return n})}};var a="%c[inploi SDK]",s="color: #65BC67; font-weight: bold;",h={warn:e=>console.warn(a,s,e),error:e=>console.error(a,s,e),info:e=>console.info(a,s,e),log:e=>console.log(a,s,e)},L={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};function l(e,r){if(!e)throw new Error(r)}function $({publishableKey:e,env:r,plugins:u,logger:o=h}){l(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let f=d({baseUrl:c[r],publishableKey:e});return u.reduce((i,n)=>(i[n.pluginName]=n.initialise({apiClient:f,logger:o}),i),{})}export{a as CONSOLE_PREFIX,s as CONSOLE_STYLE,$ as initialiseSdk,h as inploiBrandedLogger,L as noLogging};
|
|
2
|
+
//# sourceMappingURL=sdk.mjs.map
|
package/dist/sdk.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/journeys/journeys.api.ts","../src/common/common.logger.ts","../../core/src/common/common.utils.ts","../src/sdk.ts"],"sourcesContent":["export const unauthenticatedMessage = 'Unauthenticated';\nexport const unauthorisedMessage = 'This action is unauthorized.';\n\nexport type ApiClient = {\n\tfetch: (pathname: string, options?: RequestInit) => Promise<unknown>;\n};\n\nexport const createApiClient = (params: { baseUrl: string; publishableKey: string }): ApiClient => {\n\tconst defaultHeaders: HeadersInit = {\n\t\tAccept: 'application/json',\n\t\t'Content-Type': 'application/json',\n\t\t'x-publishable-key': params.publishableKey,\n\t};\n\n\treturn {\n\t\tfetch: async (pathname, options = {}) => {\n\t\t\tconst init = { ...options, headers: { ...options.headers, ...defaultHeaders } };\n\t\t\tconst response = await fetch(`${params.baseUrl}${pathname}`, init).then(res => res.json());\n\n\t\t\tif ('message' in response) {\n\t\t\t\tif (response.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (response.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n};\n","export const CONSOLE_PREFIX = '%c[inploi SDK]';\nexport const CONSOLE_STYLE = 'color: #65BC67; font-weight: bold;';\n\ntype LogMessage = (...data: any[]) => void;\nexport type Logger = {\n\twarn: LogMessage;\n\terror: LogMessage;\n\tinfo: LogMessage;\n\tlog: LogMessage;\n};\n\nexport const inploiBrandedLogger: Logger = {\n\twarn: message => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\terror: message => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tinfo: message => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tlog: message => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","export const exhaustive = (value: never) => {\n\tthrow new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n};\n\nexport function invariant(condition: any, message?: string): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\n\tthrow new Error(message);\n}\n\nexport const uniqueOrThrow = <T>(array: T[]) => {\n\tconst uniqueValues = new Set(array);\n\n\tif (array.length !== uniqueValues.size) {\n\t\tthrow new Error('Duplicate values found');\n\t}\n\treturn true;\n};\n\nexport const uniqueByPropertyOrThrow =\n\t<T extends PropertyKey>(propertyKey: T) =>\n\t(array: { [K in T]: any }[]) => {\n\t\tconst values = array.map(item => item[propertyKey]);\n\t\tconst uniqueValues = new Set(values);\n\n\t\tif (values.length !== uniqueValues.size) {\n\t\t\tthrow new Error(`Duplicate values found for property: ${propertyKey.toString()}`);\n\t\t}\n\t\treturn true;\n\t};\n","import { ENV_TO_API_URL } from './journeys/journeys.constants';\nimport { createApiClient } from './journeys/journeys.api';\nimport { Logger, inploiBrandedLogger } from './common/common.logger';\n\nimport { Flatten, invariant } from '@inploi/core/common';\nimport { AppEnvironment } from './common/common.constants';\nimport { Plugin } from './common/common.plugins';\n\n/** Different loggers so people can use `noLogging` */\nexport * from './common/common.logger';\n\nexport type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\n\t/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */\n\tplugins: P[];\n\t/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.\n\t * Anything other than `production` should be considered a development environment and the data periodicaly purged. */\n\tenv: AppEnvironment;\n\t/** Logger object that handles logging of different levels.\n\t * You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger;\n};\n\nexport function initialiseSdk<TPlugin extends Plugin<any, any>>({\n\tpublishableKey,\n\tenv,\n\tplugins,\n\tlogger = inploiBrandedLogger,\n}: InitialiseInploiSdkParams<TPlugin>) {\n\tinvariant(typeof window !== 'undefined', \"Can't initialise the inploi SDK outside of a browser environment.\");\n\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\n\tconst pluginsObj = plugins.reduce((acc, plugin) => {\n\t\tacc[plugin.pluginName as TPlugin['pluginName']] = plugin.initialise({ apiClient, logger });\n\t\treturn acc;\n\t}, {} as { [K in TPlugin['pluginName']]: ReturnType<Flatten<TPlugin & { pluginName: K }>['initialise']> });\n\n\treturn pluginsObj;\n}\n"],"mappings":"8DAAO,IAAMA,EAAyB,kBACzBC,EAAsB,+BAMtBC,EAAmBC,GAAmE,CAClG,IAAMC,EAA8B,CACnC,OAAQ,mBACR,eAAgB,mBAChB,oBAAqBD,EAAO,cAC7B,EAEA,MAAO,CACN,MAAO,CAAOE,KAA2BC,IAAAC,EAAA,QAA3BF,EAA2B,GAAAC,GAAA,UAA3BE,EAAUC,EAAU,CAAC,EAAM,CACxC,IAAMC,EAAOC,EAAAC,EAAA,GAAKH,GAAL,CAAc,QAASG,IAAA,GAAKH,EAAQ,SAAYL,EAAiB,GACxES,EAAW,MAAM,MAAM,GAAGV,EAAO,OAAO,GAAGK,CAAQ,GAAIE,CAAI,EAAE,KAAKI,GAAOA,EAAI,KAAK,CAAC,EAEzF,GAAI,YAAaD,EAAU,CAC1B,GAAIA,EAAS,UAAYb,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAS,UAAYZ,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,EAEnD,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,CAEpD,CACA,OAAOA,CACR,EACD,CACD,ECpCO,IAAME,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAMC,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,MAAOA,GAAW,QAAQ,MAAMH,EAAgBC,EAAeE,CAAO,EACtE,KAAMA,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,IAAKA,GAAW,QAAQ,IAAIH,EAAgBC,EAAeE,CAAO,CACnE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECd3G,SAASC,EAAUC,EAAgBC,EAAqC,CAC9E,GAAI,CAAAD,EAIJ,MAAM,IAAI,MAAMC,CAAO,CACxB,CCgBO,SAASC,EAAgD,CAC/D,eAAAC,EACA,IAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,CACV,EAAuC,CACtCC,EAAU,OAAO,QAAW,YAAa,mEAAmE,EAE5G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeP,CAAG,EAAG,eAAAD,CAAe,CAAC,EAOlF,OALmBE,EAAQ,OAAO,CAACO,EAAKC,KACvCD,EAAIC,EAAO,UAAmC,EAAIA,EAAO,WAAW,CAAE,UAAAJ,EAAW,OAAAH,CAAO,CAAC,EAClFM,GACL,CAAC,CAAqG,CAG1G","names":["unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","response","res","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","message","noLogging","invariant","condition","message","initialiseSdk","publishableKey","env","plugins","logger","inploiBrandedLogger","invariant","apiClient","createApiClient","ENV_TO_API_URL","acc","plugin"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inploi/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
8
|
-
"/dist"
|
|
8
|
+
"/dist",
|
|
9
|
+
"/cdn"
|
|
9
10
|
],
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
|
-
"build": "tsup --dts-resolve",
|
|
24
|
+
"build": "tsup --dts-resolve && tsup --config tsup.cdn.config.ts",
|
|
25
|
+
"build:cdn": "tsup --config tsup.cdn.config.ts",
|
|
24
26
|
"dev": "tsup --watch --dts-resolve",
|
|
25
27
|
"lint": "eslint \"**/*.ts*\""
|
|
26
28
|
},
|
package/dist/chunk-A5DU6CID.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var v=Object.defineProperty,E=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var h=(e,n,o)=>n in e?v(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o,p=(e,n)=>{for(var o in n||(n={}))b.call(n,o)&&h(e,o,n[o]);if(m)for(var o of m(n))A.call(n,o)&&h(e,o,n[o]);return e},f=(e,n)=>E(e,L(n));var w=(e,n,o)=>new Promise((t,s)=>{var d=r=>{try{i(o.next(r))}catch(u){s(u)}},a=r=>{try{i(o.throw(r))}catch(u){s(u)}},i=r=>r.done?t(r.value):Promise.resolve(r.value).then(d,a);i((o=o.apply(e,n)).next())});var l="%c[inploi SDK]",g="color: #65BC67; font-weight: bold;",x={warn:e=>console.warn(l,g,e),error:e=>console.error(l,g,e),info:e=>console.info(l,g,e),log:e=>console.log(l,g,e)},C={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var y={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},S="/journey/log";var I="Unauthenticated",T="This action is unauthorized.",P=e=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(s,...d)=>w(void 0,[s,...d],function*(o,t={}){let a=f(p({},t),{headers:p(p({},t.headers),n)}),i=yield fetch(`${e.baseUrl}${o}`,a).then(r=>r.json());if("message"in i){if(i.message===I)throw new Error("You are not authenticated.");if(i.message===T)throw new Error("You are not authenticated.");if("exception"in i)throw new Error(`API error: \u201C${i.message}\u201D`);if("errors"in i)throw new Error(`API error: \u201C${i.message}\u201D`)}return i})}};function c(e,n){if(!e)throw new Error(n)}function J({publishableKey:e,env:n,plugins:o,logger:t=x}){c(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let s=P({baseUrl:y[n],publishableKey:e});return o.reduce((a,i)=>(a[i.pluginName]=i.initialise({apiClient:s,logger:t}),a),{})}export{w as a,S as b,l as c,g as d,x as e,C as f,J as g};
|
|
2
|
-
//# sourceMappingURL=chunk-A5DU6CID.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common/common.logger.ts","../src/journeys/constants.ts","../src/journeys/api.ts","../../core/src/common/common.utils.ts","../src/sdk.ts"],"sourcesContent":["export const CONSOLE_PREFIX = '%c[inploi SDK]';\nexport const CONSOLE_STYLE = 'color: #65BC67; font-weight: bold;';\n\ntype LogMessage = (...data: any[]) => void;\nexport type Logger = {\n\twarn: LogMessage;\n\terror: LogMessage;\n\tinfo: LogMessage;\n\tlog: LogMessage;\n};\n\nexport const inploiBrandedLogger: Logger = {\n\twarn: message => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\terror: message => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tinfo: message => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tlog: message => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n","export const unauthenticatedMessage = 'Unauthenticated';\nexport const unauthorisedMessage = 'This action is unauthorized.';\n\nexport type ApiClient = {\n\tfetch: (pathname: string, options?: RequestInit) => Promise<unknown>;\n};\n\nexport const createApiClient = (params: { baseUrl: string; publishableKey: string }): ApiClient => {\n\tconst defaultHeaders: HeadersInit = {\n\t\tAccept: 'application/json',\n\t\t'Content-Type': 'application/json',\n\t\t'x-publishable-key': params.publishableKey,\n\t};\n\n\treturn {\n\t\tfetch: async (pathname, options = {}) => {\n\t\t\tconst init = { ...options, headers: { ...options.headers, ...defaultHeaders } };\n\t\t\tconst response = await fetch(`${params.baseUrl}${pathname}`, init).then(res => res.json());\n\n\t\t\tif ('message' in response) {\n\t\t\t\tif (response.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (response.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n};\n","export const exhaustive = (value: never) => {\n\tthrow new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n};\n\nexport function invariant(condition: any, message?: string): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\n\tthrow new Error(message);\n}\n","import { ENV_TO_API_URL } from './journeys/constants';\nimport { createApiClient } from './journeys/api';\nimport { Logger, inploiBrandedLogger } from './common/common.logger';\n\nimport { Flatten, invariant } from '@inploi/core/common';\nimport { AppEnvironment } from './common/common.constants';\nimport { Plugin } from './common/common.plugins';\n\nexport type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\n\t/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */\n\tplugins: P[];\n\t/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.\n\t * Anything other than `production` should be considered a development environment and the data periodicaly purged. */\n\tenv: AppEnvironment;\n\t/** Logger object that handles logging of different levels.\n\t * You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger;\n};\n\nexport function initialiseInploiSdk<TPlugin extends Plugin<any, any>>({\n\tpublishableKey,\n\tenv,\n\tplugins,\n\tlogger = inploiBrandedLogger,\n}: InitialiseInploiSdkParams<TPlugin>) {\n\tinvariant(typeof window !== 'undefined', \"Can't initialise the inploi SDK outside of a browser environment.\");\n\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\n\tconst pluginsObj = plugins.reduce((acc, plugin) => {\n\t\tacc[plugin.pluginName as TPlugin['pluginName']] = plugin.initialise({ apiClient, logger });\n\t\treturn acc;\n\t}, {} as { [K in TPlugin['pluginName']]: ReturnType<Flatten<TPlugin & { pluginName: K }>['initialise']> });\n\n\treturn pluginsObj;\n}\n"],"mappings":"0nBAAO,IAAMA,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAMC,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,MAAOA,GAAW,QAAQ,MAAMH,EAAgBC,EAAeE,CAAO,EACtE,KAAMA,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,IAAKA,GAAW,QAAQ,IAAIH,EAAgBC,EAAeE,CAAO,CACnE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,EChB3G,IAAMC,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,EAEaC,EAAmB,eCPzB,IAAMC,EAAyB,kBACzBC,EAAsB,+BAMtBC,EAAmBC,GAAmE,CAClG,IAAMC,EAA8B,CACnC,OAAQ,mBACR,eAAgB,mBAChB,oBAAqBD,EAAO,cAC7B,EAEA,MAAO,CACN,MAAO,CAAOE,KAA2BC,IAAAC,EAAA,QAA3BF,EAA2B,GAAAC,GAAA,UAA3BE,EAAUC,EAAU,CAAC,EAAM,CACxC,IAAMC,EAAOC,EAAAC,EAAA,GAAKH,GAAL,CAAc,QAASG,IAAA,GAAKH,EAAQ,SAAYL,EAAiB,GACxES,EAAW,MAAM,MAAM,GAAGV,EAAO,OAAO,GAAGK,CAAQ,GAAIE,CAAI,EAAE,KAAKI,GAAOA,EAAI,KAAK,CAAC,EAEzF,GAAI,YAAaD,EAAU,CAC1B,GAAIA,EAAS,UAAYb,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAS,UAAYZ,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,EAEnD,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,CAEpD,CACA,OAAOA,CACR,EACD,CACD,EChCO,SAASE,EAAUC,EAAgBC,EAAqC,CAC9E,GAAI,CAAAD,EAIJ,MAAM,IAAI,MAAMC,CAAO,CACxB,CCaO,SAASC,EAAsD,CACrE,eAAAC,EACA,IAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,CACV,EAAuC,CACtCC,EAAU,OAAO,QAAW,YAAa,mEAAmE,EAE5G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeP,CAAG,EAAG,eAAAD,CAAe,CAAC,EAOlF,OALmBE,EAAQ,OAAO,CAACO,EAAKC,KACvCD,EAAIC,EAAO,UAAmC,EAAIA,EAAO,WAAW,CAAE,UAAAJ,EAAW,OAAAH,CAAO,CAAC,EAClFM,GACL,CAAC,CAAqG,CAG1G","names":["CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","message","noLogging","ENV_TO_API_URL","JOURNEY_PATHNAME","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","response","res","invariant","condition","message","initialiseInploiSdk","publishableKey","env","plugins","logger","inploiBrandedLogger","invariant","apiClient","createApiClient","ENV_TO_API_URL","acc","plugin"]}
|
package/dist/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { C as CONSOLE_PREFIX, a as CONSOLE_STYLE, I as InitialiseInploiSdkParams, L as Logger, i as initialiseInploiSdk, b as inploiBrandedLogger, n as noLogging } from './index-d9ce7ffb.js';
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { C as CONSOLE_PREFIX, a as CONSOLE_STYLE, I as InitialiseInploiSdkParams, L as Logger, i as initialiseInploiSdk, b as inploiBrandedLogger, n as noLogging } from './index-d9ce7ffb.js';
|
package/dist/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty,L=Object.defineProperties,b=Object.getOwnPropertyDescriptor,A=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertyNames,h=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var x=(e,n,o)=>n in e?g(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o,u=(e,n)=>{for(var o in n||(n={}))w.call(n,o)&&x(e,o,n[o]);if(h)for(var o of h(n))T.call(n,o)&&x(e,o,n[o]);return e},y=(e,n)=>L(e,A(n));var N=(e,n)=>{for(var o in n)g(e,o,{get:n[o],enumerable:!0})},C=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of I(n))!w.call(e,r)&&r!==o&&g(e,r,{get:()=>n[r],enumerable:!(t=b(n,r))||t.enumerable});return e};var O=e=>C(g({},"__esModule",{value:!0}),e);var P=(e,n,o)=>new Promise((t,r)=>{var f=a=>{try{i(o.next(a))}catch(c){r(c)}},s=a=>{try{i(o.throw(a))}catch(c){r(c)}},i=a=>a.done?t(a.value):Promise.resolve(a.value).then(f,s);i((o=o.apply(e,n)).next())});var K={};N(K,{CONSOLE_PREFIX:()=>p,CONSOLE_STYLE:()=>l,initialiseInploiSdk:()=>U,inploiBrandedLogger:()=>m,noLogging:()=>M});module.exports=O(K);var v={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"};var S="Unauthenticated",_="This action is unauthorized.",E=e=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(r,...f)=>P(void 0,[r,...f],function*(o,t={}){let s=y(u({},t),{headers:u(u({},t.headers),n)}),i=yield fetch(`${e.baseUrl}${o}`,s).then(a=>a.json());if("message"in i){if(i.message===S)throw new Error("You are not authenticated.");if(i.message===_)throw new Error("You are not authenticated.");if("exception"in i)throw new Error(`API error: \u201C${i.message}\u201D`);if("errors"in i)throw new Error(`API error: \u201C${i.message}\u201D`)}return i})}};var p="%c[inploi SDK]",l="color: #65BC67; font-weight: bold;",m={warn:e=>console.warn(p,l,e),error:e=>console.error(p,l,e),info:e=>console.info(p,l,e),log:e=>console.log(p,l,e)},M={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};function d(e,n){if(!e)throw new Error(n)}function U({publishableKey:e,env:n,plugins:o,logger:t=m}){d(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let r=E({baseUrl:v[n],publishableKey:e});return o.reduce((s,i)=>(s[i.pluginName]=i.initialise({apiClient:r,logger:t}),s),{})}0&&(module.exports={CONSOLE_PREFIX,CONSOLE_STYLE,initialiseInploiSdk,inploiBrandedLogger,noLogging});
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/journeys/constants.ts","../src/journeys/api.ts","../src/common/common.logger.ts","../../core/src/common/common.utils.ts","../src/sdk.ts"],"sourcesContent":["export * from './sdk';\n\n/** Different loggers so people can use `noLogging` */\nexport * from './common/common.logger';\n","import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n","export const unauthenticatedMessage = 'Unauthenticated';\nexport const unauthorisedMessage = 'This action is unauthorized.';\n\nexport type ApiClient = {\n\tfetch: (pathname: string, options?: RequestInit) => Promise<unknown>;\n};\n\nexport const createApiClient = (params: { baseUrl: string; publishableKey: string }): ApiClient => {\n\tconst defaultHeaders: HeadersInit = {\n\t\tAccept: 'application/json',\n\t\t'Content-Type': 'application/json',\n\t\t'x-publishable-key': params.publishableKey,\n\t};\n\n\treturn {\n\t\tfetch: async (pathname, options = {}) => {\n\t\t\tconst init = { ...options, headers: { ...options.headers, ...defaultHeaders } };\n\t\t\tconst response = await fetch(`${params.baseUrl}${pathname}`, init).then(res => res.json());\n\n\t\t\tif ('message' in response) {\n\t\t\t\tif (response.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (response.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n};\n","export const CONSOLE_PREFIX = '%c[inploi SDK]';\nexport const CONSOLE_STYLE = 'color: #65BC67; font-weight: bold;';\n\ntype LogMessage = (...data: any[]) => void;\nexport type Logger = {\n\twarn: LogMessage;\n\terror: LogMessage;\n\tinfo: LogMessage;\n\tlog: LogMessage;\n};\n\nexport const inploiBrandedLogger: Logger = {\n\twarn: message => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\terror: message => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tinfo: message => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tlog: message => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","export const exhaustive = (value: never) => {\n\tthrow new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n};\n\nexport function invariant(condition: any, message?: string): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\n\tthrow new Error(message);\n}\n","import { ENV_TO_API_URL } from './journeys/constants';\nimport { createApiClient } from './journeys/api';\nimport { Logger, inploiBrandedLogger } from './common/common.logger';\n\nimport { Flatten, invariant } from '@inploi/core/common';\nimport { AppEnvironment } from './common/common.constants';\nimport { Plugin } from './common/common.plugins';\n\nexport type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\n\t/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */\n\tplugins: P[];\n\t/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.\n\t * Anything other than `production` should be considered a development environment and the data periodicaly purged. */\n\tenv: AppEnvironment;\n\t/** Logger object that handles logging of different levels.\n\t * You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger;\n};\n\nexport function initialiseInploiSdk<TPlugin extends Plugin<any, any>>({\n\tpublishableKey,\n\tenv,\n\tplugins,\n\tlogger = inploiBrandedLogger,\n}: InitialiseInploiSdkParams<TPlugin>) {\n\tinvariant(typeof window !== 'undefined', \"Can't initialise the inploi SDK outside of a browser environment.\");\n\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\n\tconst pluginsObj = plugins.reduce((acc, plugin) => {\n\t\tacc[plugin.pluginName as TPlugin['pluginName']] = plugin.initialise({ apiClient, logger });\n\t\treturn acc;\n\t}, {} as { [K in TPlugin['pluginName']]: ReturnType<Flatten<TPlugin & { pluginName: K }>['initialise']> });\n\n\treturn pluginsObj;\n}\n"],"mappings":"i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,kBAAAC,EAAA,wBAAAC,EAAA,wBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAP,GCEO,IAAMQ,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,ECLO,IAAMC,EAAyB,kBACzBC,EAAsB,+BAMtBC,EAAmBC,GAAmE,CAClG,IAAMC,EAA8B,CACnC,OAAQ,mBACR,eAAgB,mBAChB,oBAAqBD,EAAO,cAC7B,EAEA,MAAO,CACN,MAAO,CAAOE,KAA2BC,IAAAC,EAAA,QAA3BF,EAA2B,GAAAC,GAAA,UAA3BE,EAAUC,EAAU,CAAC,EAAM,CACxC,IAAMC,EAAOC,EAAAC,EAAA,GAAKH,GAAL,CAAc,QAASG,IAAA,GAAKH,EAAQ,SAAYL,EAAiB,GACxES,EAAW,MAAM,MAAM,GAAGV,EAAO,OAAO,GAAGK,CAAQ,GAAIE,CAAI,EAAE,KAAKI,GAAOA,EAAI,KAAK,CAAC,EAEzF,GAAI,YAAaD,EAAU,CAC1B,GAAIA,EAAS,UAAYb,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAS,UAAYZ,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,EAEnD,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,CAEpD,CACA,OAAOA,CACR,EACD,CACD,ECpCO,IAAME,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAMC,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,MAAOA,GAAW,QAAQ,MAAMH,EAAgBC,EAAeE,CAAO,EACtE,KAAMA,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,IAAKA,GAAW,QAAQ,IAAIH,EAAgBC,EAAeE,CAAO,CACnE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECd3G,SAASC,EAAUC,EAAgBC,EAAqC,CAC9E,GAAI,CAAAD,EAIJ,MAAM,IAAI,MAAMC,CAAO,CACxB,CCaO,SAASC,EAAsD,CACrE,eAAAC,EACA,IAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,CACV,EAAuC,CACtCC,EAAU,OAAO,QAAW,YAAa,mEAAmE,EAE5G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeP,CAAG,EAAG,eAAAD,CAAe,CAAC,EAOlF,OALmBE,EAAQ,OAAO,CAACO,EAAKC,KACvCD,EAAIC,EAAO,UAAmC,EAAIA,EAAO,WAAW,CAAE,UAAAJ,EAAW,OAAAH,CAAO,CAAC,EAClFM,GACL,CAAC,CAAqG,CAG1G","names":["src_exports","__export","CONSOLE_PREFIX","CONSOLE_STYLE","initialiseInploiSdk","inploiBrandedLogger","noLogging","__toCommonJS","ENV_TO_API_URL","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","response","res","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","message","noLogging","invariant","condition","message","initialiseInploiSdk","publishableKey","env","plugins","logger","inploiBrandedLogger","invariant","apiClient","createApiClient","ENV_TO_API_URL","acc","plugin"]}
|
package/dist/index.mjs
DELETED
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/journeys/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty,A=Object.defineProperties,I=Object.getOwnPropertyDescriptor,O=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var y=(e,r,n)=>r in e?p(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,l=(e,r)=>{for(var n in r||(r={}))v.call(r,n)&&y(e,n,r[n]);if(f)for(var n of f(r))S.call(r,n)&&y(e,n,r[n]);return e},h=(e,r)=>A(e,O(r));var M=(e,r)=>{for(var n in r)p(e,n,{get:r[n],enumerable:!0})},N=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of _(r))!v.call(e,t)&&t!==n&&p(e,t,{get:()=>r[t],enumerable:!(i=I(r,t))||i.enumerable});return e};var R=e=>N(p({},"__esModule",{value:!0}),e);var g=(e,r,n)=>new Promise((i,t)=>{var d=s=>{try{o(n.next(s))}catch(c){t(c)}},a=s=>{try{o(n.throw(s))}catch(c){t(c)}},o=s=>s.done?i(s.value):Promise.resolve(s.value).then(d,a);o((n=n.apply(e,r)).next())});var K={};M(K,{initialiseInploiSdk:()=>J,journeysPlugin:()=>U});module.exports=R(K);var x=(e,{initialise:r})=>({pluginName:e,initialise:r});var E={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},T="/journey/log";function L({apiClient:e,logger:r}){function n(i){return g(this,null,function*(){try{let t={event:i.event,sent_at:new Date().toISOString(),context:{library:{name:"inploi-sdk",version:1},page:{href:location.href,referrer:document.referrer,title:document.title}},properties:i.properties,custom_properties:i.customProperties};return yield e.fetch(T,{method:"POST",body:JSON.stringify(t)}),{success:!0,data:t}}catch(t){return r==null||r.error("Failed to send journey log to API. Inspect error response of `log` for more information."),{success:!1,error:t}}})}return{log:n}}var k="Unauthenticated",j="This action is unauthorized.",w=e=>{let r={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(t,...d)=>g(void 0,[t,...d],function*(n,i={}){let a=h(l({},i),{headers:l(l({},i.headers),r)}),o=yield fetch(`${e.baseUrl}${n}`,a).then(s=>s.json());if("message"in o){if(o.message===k)throw new Error("You are not authenticated.");if(o.message===j)throw new Error("You are not authenticated.");if("exception"in o)throw new Error(`API error: \u201C${o.message}\u201D`);if("errors"in o)throw new Error(`API error: \u201C${o.message}\u201D`)}return o})}};var u="%c[inploi SDK]",m="color: #65BC67; font-weight: bold;",b={warn:e=>console.warn(u,m,e),error:e=>console.error(u,m,e),info:e=>console.info(u,m,e),log:e=>console.log(u,m,e)};function P(e,r){if(!e)throw new Error(r)}function J({publishableKey:e,env:r,plugins:n,logger:i=b}){P(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let t=w({baseUrl:E[r],publishableKey:e});return n.reduce((a,o)=>(a[o.pluginName]=o.initialise({apiClient:t,logger:i}),a),{})}var U=x("journey",{initialise:L});0&&(module.exports={initialiseInploiSdk,journeysPlugin});
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/journeys/index.ts","../../src/common/common.plugins.ts","../../src/journeys/constants.ts","../../src/journeys/log.ts","../../src/journeys/api.ts","../../src/common/common.logger.ts","../../../core/src/common/common.utils.ts","../../src/sdk.ts"],"sourcesContent":["import { createPlugin } from '../common/common.plugins';\nimport { initialiseJourneysPlugin } from './log';\n\nexport * from '../sdk';\n\nexport const journeysPlugin = createPlugin('journey', { initialise: initialiseJourneysPlugin });\n","import { Logger } from '..';\nimport { ApiClient } from '../journeys/api';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger?: Logger;\n};\n\nexport type Plugin<T extends string, P> = {\n\tpluginName: T;\n\tinitialise: (params: PluginParams) => P;\n};\n\nexport const createPlugin = <T extends string, P>(\n\tpluginName: T,\n\t{ initialise }: { initialise: (params: PluginParams) => P }\n): Plugin<T, P> => ({\n\tpluginName,\n\tinitialise,\n});\n","import { AppEnvironment } from '../common/common.constants';\n\nexport const ENV_TO_API_URL: Record<AppEnvironment, string> = {\n\tsandbox: 'https://preview.api.inploi.com',\n\tproduction: 'https://api.inploi.com',\n};\n\nexport const JOURNEY_PATHNAME = '/journey/log';\n","import { Flatten, ResponseObj } from '@inploi/core/common';\nimport { SDK_VERSION } from '../common/common.constants';\nimport { JOURNEY_PATHNAME } from './constants';\nimport { PluginParams } from '../common/common.plugins';\n\ntype JourneyLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id?: string | number | null; // * inploi job id or external job id?\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: undefined;\n\t };\n\nexport type JourneyLogEvent = JourneyLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in JourneyLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype TrackPayload<P> = {\n\tevent: JourneyLogEvent;\n\tsent_at: string;\n\tcontext: {\n\t\tlibrary: {\n\t\t\tname: 'inploi-sdk';\n\t\t\tversion: number;\n\t\t};\n\t\tpage: {\n\t\t\thref: string;\n\t\t\treferrer: string;\n\t\t\ttitle: string;\n\t\t};\n\t};\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\nexport function initialiseJourneysPlugin({ apiClient, logger }: PluginParams) {\n\tasync function log<T extends keyof EventPropertyMap>(\n\t\tparams: { event: T; customProperties?: Record<string, unknown> } & EventPropertyMap[T]\n\t): Promise<ResponseObj<TrackPayload<EventPropertyMap[T]['properties']>>> {\n\t\ttry {\n\t\t\tconst data: TrackPayload<EventPropertyMap[T]['properties']> = {\n\t\t\t\tevent: params.event,\n\t\t\t\tsent_at: new Date().toISOString(),\n\t\t\t\tcontext: {\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: 'inploi-sdk' as const,\n\t\t\t\t\t\tversion: SDK_VERSION,\n\t\t\t\t\t},\n\t\t\t\t\tpage: {\n\t\t\t\t\t\thref: location.href,\n\t\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\t\ttitle: document.title,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tproperties: params.properties as EventPropertyMap[T]['properties'],\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tawait apiClient.fetch(JOURNEY_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(data),\n\t\t\t});\n\n\t\t\treturn { success: true, data };\n\t\t} catch (e) {\n\t\t\t/** We dont’t log any PII on the console */\n\t\t\tlogger?.error('Failed to send journey log to API. Inspect error response of `log` for more information.');\n\t\t\treturn { success: false, error: e };\n\t\t}\n\t}\n\n\treturn { log };\n}\n","export const unauthenticatedMessage = 'Unauthenticated';\nexport const unauthorisedMessage = 'This action is unauthorized.';\n\nexport type ApiClient = {\n\tfetch: (pathname: string, options?: RequestInit) => Promise<unknown>;\n};\n\nexport const createApiClient = (params: { baseUrl: string; publishableKey: string }): ApiClient => {\n\tconst defaultHeaders: HeadersInit = {\n\t\tAccept: 'application/json',\n\t\t'Content-Type': 'application/json',\n\t\t'x-publishable-key': params.publishableKey,\n\t};\n\n\treturn {\n\t\tfetch: async (pathname, options = {}) => {\n\t\t\tconst init = { ...options, headers: { ...options.headers, ...defaultHeaders } };\n\t\t\tconst response = await fetch(`${params.baseUrl}${pathname}`, init).then(res => res.json());\n\n\t\t\tif ('message' in response) {\n\t\t\t\tif (response.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (response.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in response) {\n\t\t\t\t\tthrow new Error(`API error: “${response.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n};\n","export const CONSOLE_PREFIX = '%c[inploi SDK]';\nexport const CONSOLE_STYLE = 'color: #65BC67; font-weight: bold;';\n\ntype LogMessage = (...data: any[]) => void;\nexport type Logger = {\n\twarn: LogMessage;\n\terror: LogMessage;\n\tinfo: LogMessage;\n\tlog: LogMessage;\n};\n\nexport const inploiBrandedLogger: Logger = {\n\twarn: message => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\terror: message => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tinfo: message => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n\tlog: message => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","export const exhaustive = (value: never) => {\n\tthrow new Error(`Unhandled discriminated union member: ${JSON.stringify(value)}`);\n};\n\nexport function invariant(condition: any, message?: string): asserts condition {\n\tif (condition) {\n\t\treturn;\n\t}\n\n\tthrow new Error(message);\n}\n","import { ENV_TO_API_URL } from './journeys/constants';\nimport { createApiClient } from './journeys/api';\nimport { Logger, inploiBrandedLogger } from './common/common.logger';\n\nimport { Flatten, invariant } from '@inploi/core/common';\nimport { AppEnvironment } from './common/common.constants';\nimport { Plugin } from './common/common.plugins';\n\nexport type InitialiseInploiSdkParams<P extends Plugin<any, any>> = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\n\t/** Add your plugins here. Try importing and passing `journeysPlugin` ;) */\n\tplugins: P[];\n\t/** Which app environment to run. This ultimately affects which inploi endpoints to gather data are going to be used.\n\t * Anything other than `production` should be considered a development environment and the data periodicaly purged. */\n\tenv: AppEnvironment;\n\t/** Logger object that handles logging of different levels.\n\t * You can override this to use your own logger, or to disable logging altogether by importing and passing `noLogging`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger;\n};\n\nexport function initialiseInploiSdk<TPlugin extends Plugin<any, any>>({\n\tpublishableKey,\n\tenv,\n\tplugins,\n\tlogger = inploiBrandedLogger,\n}: InitialiseInploiSdkParams<TPlugin>) {\n\tinvariant(typeof window !== 'undefined', \"Can't initialise the inploi SDK outside of a browser environment.\");\n\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\n\tconst pluginsObj = plugins.reduce((acc, plugin) => {\n\t\tacc[plugin.pluginName as TPlugin['pluginName']] = plugin.initialise({ apiClient, logger });\n\t\treturn acc;\n\t}, {} as { [K in TPlugin['pluginName']]: ReturnType<Flatten<TPlugin & { pluginName: K }>['initialise']> });\n\n\treturn pluginsObj;\n}\n"],"mappings":"i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GCaO,IAAMK,EAAe,CAC3BC,EACA,CAAE,WAAAC,CAAW,KACM,CACnB,WAAAD,EACA,WAAAC,CACD,GCjBO,IAAMC,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,EAEaC,EAAmB,eCkCzB,SAASC,EAAyB,CAAE,UAAAC,EAAW,OAAAC,CAAO,EAAiB,CAC7E,SAAeC,EACdC,EACwE,QAAAC,EAAA,sBACxE,GAAI,CACH,IAAMC,EAAwD,CAC7D,MAAOF,EAAO,MACd,QAAS,IAAI,KAAK,EAAE,YAAY,EAChC,QAAS,CACR,QAAS,CACR,KAAM,aACN,QAAS,CACV,EACA,KAAM,CACL,KAAM,SAAS,KACf,SAAU,SAAS,SACnB,MAAO,SAAS,KACjB,CACD,EACA,WAAYA,EAAO,WACnB,kBAAmBA,EAAO,gBAC3B,EAEA,aAAMH,EAAU,MAAMM,EAAkB,CACvC,OAAQ,OACR,KAAM,KAAK,UAAUD,CAAI,CAC1B,CAAC,EAEM,CAAE,QAAS,GAAM,KAAAA,CAAK,CAC9B,OAASE,EAAG,CAEX,OAAAN,GAAA,MAAAA,EAAQ,MAAM,4FACP,CAAE,QAAS,GAAO,MAAOM,CAAE,CACnC,CACD,GAEA,MAAO,CAAE,IAAAL,CAAI,CACd,CC9EO,IAAMM,EAAyB,kBACzBC,EAAsB,+BAMtBC,EAAmBC,GAAmE,CAClG,IAAMC,EAA8B,CACnC,OAAQ,mBACR,eAAgB,mBAChB,oBAAqBD,EAAO,cAC7B,EAEA,MAAO,CACN,MAAO,CAAOE,KAA2BC,IAAAC,EAAA,QAA3BF,EAA2B,GAAAC,GAAA,UAA3BE,EAAUC,EAAU,CAAC,EAAM,CACxC,IAAMC,EAAOC,EAAAC,EAAA,GAAKH,GAAL,CAAc,QAASG,IAAA,GAAKH,EAAQ,SAAYL,EAAiB,GACxES,EAAW,MAAM,MAAM,GAAGV,EAAO,OAAO,GAAGK,CAAQ,GAAIE,CAAI,EAAE,KAAKI,GAAOA,EAAI,KAAK,CAAC,EAEzF,GAAI,YAAaD,EAAU,CAC1B,GAAIA,EAAS,UAAYb,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAS,UAAYZ,EACxB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,EAEnD,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAS,OAAO,QAAG,CAEpD,CACA,OAAOA,CACR,EACD,CACD,ECpCO,IAAME,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAMC,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,MAAOA,GAAW,QAAQ,MAAMH,EAAgBC,EAAeE,CAAO,EACtE,KAAMA,GAAW,QAAQ,KAAKH,EAAgBC,EAAeE,CAAO,EACpE,IAAKA,GAAW,QAAQ,IAAIH,EAAgBC,EAAeE,CAAO,CACnE,ECZO,SAASC,EAAUC,EAAgBC,EAAqC,CAC9E,GAAI,CAAAD,EAIJ,MAAM,IAAI,MAAMC,CAAO,CACxB,CCaO,SAASC,EAAsD,CACrE,eAAAC,EACA,IAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,CACV,EAAuC,CACtCC,EAAU,OAAO,QAAW,YAAa,mEAAmE,EAE5G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeP,CAAG,EAAG,eAAAD,CAAe,CAAC,EAOlF,OALmBE,EAAQ,OAAO,CAACO,EAAKC,KACvCD,EAAIC,EAAO,UAAmC,EAAIA,EAAO,WAAW,CAAE,UAAAJ,EAAW,OAAAH,CAAO,CAAC,EAClFM,GACL,CAAC,CAAqG,CAG1G,CPlCO,IAAME,EAAiBC,EAAa,UAAW,CAAE,WAAYC,CAAyB,CAAC","names":["journeys_exports","__export","initialiseInploiSdk","journeysPlugin","__toCommonJS","createPlugin","pluginName","initialise","ENV_TO_API_URL","JOURNEY_PATHNAME","initialiseJourneysPlugin","apiClient","logger","log","params","__async","data","JOURNEY_PATHNAME","e","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","response","res","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","message","invariant","condition","message","initialiseInploiSdk","publishableKey","env","plugins","logger","inploiBrandedLogger","invariant","apiClient","createApiClient","ENV_TO_API_URL","acc","plugin","journeysPlugin","createPlugin","initialiseJourneysPlugin"]}
|
package/dist/journeys/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as o,b as i,g as m}from"../chunk-A5DU6CID.mjs";var s=(t,{initialise:e})=>({pluginName:t,initialise:e});function p({apiClient:t,logger:e}){function a(n){return o(this,null,function*(){try{let r={event:n.event,sent_at:new Date().toISOString(),context:{library:{name:"inploi-sdk",version:1},page:{href:location.href,referrer:document.referrer,title:document.title}},properties:n.properties,custom_properties:n.customProperties};return yield t.fetch(i,{method:"POST",body:JSON.stringify(r)}),{success:!0,data:r}}catch(r){return e==null||e.error("Failed to send journey log to API. Inspect error response of `log` for more information."),{success:!1,error:r}}})}return{log:a}}var v=s("journey",{initialise:p});export{m as initialiseInploiSdk,v as journeysPlugin};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/common/common.plugins.ts","../../src/journeys/log.ts","../../src/journeys/index.ts"],"sourcesContent":["import { Logger } from '..';\nimport { ApiClient } from '../journeys/api';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger?: Logger;\n};\n\nexport type Plugin<T extends string, P> = {\n\tpluginName: T;\n\tinitialise: (params: PluginParams) => P;\n};\n\nexport const createPlugin = <T extends string, P>(\n\tpluginName: T,\n\t{ initialise }: { initialise: (params: PluginParams) => P }\n): Plugin<T, P> => ({\n\tpluginName,\n\tinitialise,\n});\n","import { Flatten, ResponseObj } from '@inploi/core/common';\nimport { SDK_VERSION } from '../common/common.constants';\nimport { JOURNEY_PATHNAME } from './constants';\nimport { PluginParams } from '../common/common.plugins';\n\ntype JourneyLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id?: string | number | null; // * inploi job id or external job id?\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: undefined;\n\t };\n\nexport type JourneyLogEvent = JourneyLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in JourneyLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype TrackPayload<P> = {\n\tevent: JourneyLogEvent;\n\tsent_at: string;\n\tcontext: {\n\t\tlibrary: {\n\t\t\tname: 'inploi-sdk';\n\t\t\tversion: number;\n\t\t};\n\t\tpage: {\n\t\t\thref: string;\n\t\t\treferrer: string;\n\t\t\ttitle: string;\n\t\t};\n\t};\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\nexport function initialiseJourneysPlugin({ apiClient, logger }: PluginParams) {\n\tasync function log<T extends keyof EventPropertyMap>(\n\t\tparams: { event: T; customProperties?: Record<string, unknown> } & EventPropertyMap[T]\n\t): Promise<ResponseObj<TrackPayload<EventPropertyMap[T]['properties']>>> {\n\t\ttry {\n\t\t\tconst data: TrackPayload<EventPropertyMap[T]['properties']> = {\n\t\t\t\tevent: params.event,\n\t\t\t\tsent_at: new Date().toISOString(),\n\t\t\t\tcontext: {\n\t\t\t\t\tlibrary: {\n\t\t\t\t\t\tname: 'inploi-sdk' as const,\n\t\t\t\t\t\tversion: SDK_VERSION,\n\t\t\t\t\t},\n\t\t\t\t\tpage: {\n\t\t\t\t\t\thref: location.href,\n\t\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\t\ttitle: document.title,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tproperties: params.properties as EventPropertyMap[T]['properties'],\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tawait apiClient.fetch(JOURNEY_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(data),\n\t\t\t});\n\n\t\t\treturn { success: true, data };\n\t\t} catch (e) {\n\t\t\t/** We dont’t log any PII on the console */\n\t\t\tlogger?.error('Failed to send journey log to API. Inspect error response of `log` for more information.');\n\t\t\treturn { success: false, error: e };\n\t\t}\n\t}\n\n\treturn { log };\n}\n","import { createPlugin } from '../common/common.plugins';\nimport { initialiseJourneysPlugin } from './log';\n\nexport * from '../sdk';\n\nexport const journeysPlugin = createPlugin('journey', { initialise: initialiseJourneysPlugin });\n"],"mappings":"wDAaO,IAAMA,EAAe,CAC3BC,EACA,CAAE,WAAAC,CAAW,KACM,CACnB,WAAAD,EACA,WAAAC,CACD,GCsBO,SAASC,EAAyB,CAAE,UAAAC,EAAW,OAAAC,CAAO,EAAiB,CAC7E,SAAeC,EACdC,EACwE,QAAAC,EAAA,sBACxE,GAAI,CACH,IAAMC,EAAwD,CAC7D,MAAOF,EAAO,MACd,QAAS,IAAI,KAAK,EAAE,YAAY,EAChC,QAAS,CACR,QAAS,CACR,KAAM,aACN,QAAS,CACV,EACA,KAAM,CACL,KAAM,SAAS,KACf,SAAU,SAAS,SACnB,MAAO,SAAS,KACjB,CACD,EACA,WAAYA,EAAO,WACnB,kBAAmBA,EAAO,gBAC3B,EAEA,aAAMH,EAAU,MAAMM,EAAkB,CACvC,OAAQ,OACR,KAAM,KAAK,UAAUD,CAAI,CAC1B,CAAC,EAEM,CAAE,QAAS,GAAM,KAAAA,CAAK,CAC9B,OAASE,EAAG,CAEX,OAAAN,GAAA,MAAAA,EAAQ,MAAM,4FACP,CAAE,QAAS,GAAO,MAAOM,CAAE,CACnC,CACD,GAEA,MAAO,CAAE,IAAAL,CAAI,CACd,CCzEO,IAAMM,EAAiBC,EAAa,UAAW,CAAE,WAAYC,CAAyB,CAAC","names":["createPlugin","pluginName","initialise","initialiseJourneysPlugin","apiClient","logger","log","params","__async","data","JOURNEY_PATHNAME","e","journeysPlugin","createPlugin","initialiseJourneysPlugin"]}
|