@inploi/sdk 0.2.0 → 0.3.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 +166 -0
- package/cdn/sdk.js +121 -0
- package/dist/chunk-NCQJAIJD.mjs +2 -0
- package/dist/chunk-NCQJAIJD.mjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/journeys/index.js +1 -1
- package/dist/journeys/index.js.map +1 -1
- package/dist/journeys/index.mjs +1 -1
- package/package.json +5 -3
- package/dist/chunk-A5DU6CID.mjs +0 -2
- package/dist/chunk-A5DU6CID.mjs.map +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// This file is generated automatically. Do not edit it manually.
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __async = (__this, __arguments, generator) => {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
var fulfilled = (value) => {
|
|
25
|
+
try {
|
|
26
|
+
step(generator.next(value));
|
|
27
|
+
} catch (e) {
|
|
28
|
+
reject(e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var rejected = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.throw(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
39
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/common/common.plugins.ts
|
|
44
|
+
var createPlugin = (pluginName, { initialise }) => ({
|
|
45
|
+
pluginName,
|
|
46
|
+
initialise
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// src/common/common.constants.ts
|
|
50
|
+
var SDK_VERSION = 1;
|
|
51
|
+
|
|
52
|
+
// src/journeys/constants.ts
|
|
53
|
+
var ENV_TO_API_URL = {
|
|
54
|
+
sandbox: "https://preview.api.inploi.com",
|
|
55
|
+
production: "https://api.inploi.com"
|
|
56
|
+
};
|
|
57
|
+
var JOURNEY_PATHNAME = "/journey/log";
|
|
58
|
+
|
|
59
|
+
// src/journeys/log.ts
|
|
60
|
+
function initialiseJourneysPlugin({ apiClient, logger }) {
|
|
61
|
+
function log(params) {
|
|
62
|
+
return __async(this, null, function* () {
|
|
63
|
+
try {
|
|
64
|
+
const data = {
|
|
65
|
+
event: params.event,
|
|
66
|
+
sent_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
67
|
+
context: {
|
|
68
|
+
library: {
|
|
69
|
+
name: "inploi-sdk",
|
|
70
|
+
version: SDK_VERSION
|
|
71
|
+
},
|
|
72
|
+
page: {
|
|
73
|
+
href: location.href,
|
|
74
|
+
referrer: document.referrer,
|
|
75
|
+
title: document.title
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
properties: params.properties,
|
|
79
|
+
custom_properties: params.customProperties
|
|
80
|
+
};
|
|
81
|
+
yield apiClient.fetch(JOURNEY_PATHNAME, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
body: JSON.stringify(data)
|
|
84
|
+
});
|
|
85
|
+
return { success: true, data };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
logger == null ? void 0 : logger.error("Failed to send journey log to API. Inspect error response of `log` for more information.");
|
|
88
|
+
return { success: false, error: e };
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { log };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/journeys/api.ts
|
|
96
|
+
var unauthenticatedMessage = "Unauthenticated";
|
|
97
|
+
var unauthorisedMessage = "This action is unauthorized.";
|
|
98
|
+
var createApiClient = (params) => {
|
|
99
|
+
const defaultHeaders = {
|
|
100
|
+
Accept: "application/json",
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
"x-publishable-key": params.publishableKey
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
fetch: (_0, ..._1) => __async(void 0, [_0, ..._1], function* (pathname, options = {}) {
|
|
106
|
+
const init = __spreadProps(__spreadValues({}, options), { headers: __spreadValues(__spreadValues({}, options.headers), defaultHeaders) });
|
|
107
|
+
const response = yield fetch(`${params.baseUrl}${pathname}`, init).then((res) => res.json());
|
|
108
|
+
if ("message" in response) {
|
|
109
|
+
if (response.message === unauthenticatedMessage) {
|
|
110
|
+
throw new Error("You are not authenticated.");
|
|
111
|
+
}
|
|
112
|
+
if (response.message === unauthorisedMessage) {
|
|
113
|
+
throw new Error("You are not authenticated.");
|
|
114
|
+
}
|
|
115
|
+
if ("exception" in response) {
|
|
116
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
117
|
+
}
|
|
118
|
+
if ("errors" in response) {
|
|
119
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return response;
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/common/common.logger.ts
|
|
128
|
+
var CONSOLE_PREFIX = "%c[inploi SDK]";
|
|
129
|
+
var CONSOLE_STYLE = "color: #65BC67; font-weight: bold;";
|
|
130
|
+
var inploiBrandedLogger = {
|
|
131
|
+
warn: (message) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
132
|
+
error: (message) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
133
|
+
info: (message) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
134
|
+
log: (message) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message)
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// ../core/dist/chunk-H7ZOE7ZC.mjs
|
|
138
|
+
function invariant(condition, message) {
|
|
139
|
+
if (condition) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
throw new Error(message);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/sdk.ts
|
|
146
|
+
function initialiseInploiSdk({
|
|
147
|
+
publishableKey,
|
|
148
|
+
env,
|
|
149
|
+
plugins,
|
|
150
|
+
logger = inploiBrandedLogger
|
|
151
|
+
}) {
|
|
152
|
+
invariant(typeof window !== "undefined", "Can't initialise the inploi SDK outside of a browser environment.");
|
|
153
|
+
const apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });
|
|
154
|
+
const pluginsObj = plugins.reduce((acc, plugin) => {
|
|
155
|
+
acc[plugin.pluginName] = plugin.initialise({ apiClient, logger });
|
|
156
|
+
return acc;
|
|
157
|
+
}, {});
|
|
158
|
+
return pluginsObj;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/journeys/index.ts
|
|
162
|
+
var journeysPlugin = createPlugin("journey", { initialise: initialiseJourneysPlugin });
|
|
163
|
+
export {
|
|
164
|
+
initialiseInploiSdk,
|
|
165
|
+
journeysPlugin
|
|
166
|
+
};
|
package/cdn/sdk.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// This file is generated automatically. Do not edit it manually.
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __async = (__this, __arguments, generator) => {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
var fulfilled = (value) => {
|
|
25
|
+
try {
|
|
26
|
+
step(generator.next(value));
|
|
27
|
+
} catch (e) {
|
|
28
|
+
reject(e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var rejected = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.throw(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
39
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/journeys/constants.ts
|
|
44
|
+
var ENV_TO_API_URL = {
|
|
45
|
+
sandbox: "https://preview.api.inploi.com",
|
|
46
|
+
production: "https://api.inploi.com"
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/journeys/api.ts
|
|
50
|
+
var unauthenticatedMessage = "Unauthenticated";
|
|
51
|
+
var unauthorisedMessage = "This action is unauthorized.";
|
|
52
|
+
var createApiClient = (params) => {
|
|
53
|
+
const defaultHeaders = {
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
"x-publishable-key": params.publishableKey
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
fetch: (_0, ..._1) => __async(void 0, [_0, ..._1], function* (pathname, options = {}) {
|
|
60
|
+
const init = __spreadProps(__spreadValues({}, options), { headers: __spreadValues(__spreadValues({}, options.headers), defaultHeaders) });
|
|
61
|
+
const response = yield fetch(`${params.baseUrl}${pathname}`, init).then((res) => res.json());
|
|
62
|
+
if ("message" in response) {
|
|
63
|
+
if (response.message === unauthenticatedMessage) {
|
|
64
|
+
throw new Error("You are not authenticated.");
|
|
65
|
+
}
|
|
66
|
+
if (response.message === unauthorisedMessage) {
|
|
67
|
+
throw new Error("You are not authenticated.");
|
|
68
|
+
}
|
|
69
|
+
if ("exception" in response) {
|
|
70
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
71
|
+
}
|
|
72
|
+
if ("errors" in response) {
|
|
73
|
+
throw new Error(`API error: \u201C${response.message}\u201D`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return response;
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/common/common.logger.ts
|
|
82
|
+
var CONSOLE_PREFIX = "%c[inploi SDK]";
|
|
83
|
+
var CONSOLE_STYLE = "color: #65BC67; font-weight: bold;";
|
|
84
|
+
var inploiBrandedLogger = {
|
|
85
|
+
warn: (message) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
86
|
+
error: (message) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
87
|
+
info: (message) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, message),
|
|
88
|
+
log: (message) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, message)
|
|
89
|
+
};
|
|
90
|
+
var noLogging = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };
|
|
91
|
+
|
|
92
|
+
// ../core/dist/chunk-H7ZOE7ZC.mjs
|
|
93
|
+
function invariant(condition, message) {
|
|
94
|
+
if (condition) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
throw new Error(message);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/sdk.ts
|
|
101
|
+
function initialiseInploiSdk({
|
|
102
|
+
publishableKey,
|
|
103
|
+
env,
|
|
104
|
+
plugins,
|
|
105
|
+
logger = inploiBrandedLogger
|
|
106
|
+
}) {
|
|
107
|
+
invariant(typeof window !== "undefined", "Can't initialise the inploi SDK outside of a browser environment.");
|
|
108
|
+
const apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });
|
|
109
|
+
const pluginsObj = plugins.reduce((acc, plugin) => {
|
|
110
|
+
acc[plugin.pluginName] = plugin.initialise({ apiClient, logger });
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
return pluginsObj;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
CONSOLE_PREFIX,
|
|
117
|
+
CONSOLE_STYLE,
|
|
118
|
+
initialiseInploiSdk,
|
|
119
|
+
inploiBrandedLogger,
|
|
120
|
+
noLogging
|
|
121
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var P=Object.defineProperty,E=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var m=(e,n,r)=>n in e?P(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,p=(e,n)=>{for(var r in n||(n={}))b.call(n,r)&&m(e,r,n[r]);if(h)for(var r of h(n))T.call(n,r)&&m(e,r,n[r]);return e},f=(e,n)=>E(e,L(n));var w=(e,n,r)=>new Promise((t,a)=>{var d=i=>{try{o(r.next(i))}catch(g){a(g)}},s=i=>{try{o(r.throw(i))}catch(g){a(g)}},o=i=>i.done?t(i.value):Promise.resolve(i.value).then(d,s);o((r=r.apply(e,n)).next())});var u="%c[inploi SDK]",l="color: #65BC67; font-weight: bold;",v={warn:e=>console.warn(u,l,e),error:e=>console.error(u,l,e),info:e=>console.info(u,l,e),log:e=>console.log(u,l,e)},S={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var x={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},C="/journey/log";var A="Unauthenticated",O="This action is unauthorized.",y=e=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(a,...d)=>w(void 0,[a,...d],function*(r,t={}){let s=f(p({},t),{headers:p(p({},t.headers),n)}),o=yield fetch(`${e.baseUrl}${r}`,s).then(i=>i.json());if("message"in o){if(o.message===A)throw new Error("You are not authenticated.");if(o.message===O)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})}};function c(e,n){if(!e)throw new Error(n)}function H({publishableKey:e,env:n,plugins:r,logger:t=v}){c(typeof window!="undefined","Can't initialise the inploi SDK outside of a browser environment.");let a=y({baseUrl:x[n],publishableKey:e});return r.reduce((s,o)=>(s[o.pluginName]=o.initialise({apiClient:a,logger:t}),s),{})}export{w as a,C as b,u as c,l as d,v as e,S as f,H as g};
|
|
2
|
+
//# sourceMappingURL=chunk-NCQJAIJD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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\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/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,EAA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URNEY_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.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty,L=Object.defineProperties,b=Object.getOwnPropertyDescriptor,T=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var x=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={}))x.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},v=(e,n)=>L(e,T(n));var I=(e,n)=>{for(var r in n)l(e,r,{get:n[r],enumerable:!0})},S=(e,n,r,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of A(n))!x.call(e,i)&&i!==r&&l(e,i,{get:()=>n[i],enumerable:!(t=b(n,i))||t.enumerable});return e};var N=e=>S(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={};I(q,{CONSOLE_PREFIX:()=>p,CONSOLE_STYLE:()=>u,initialiseInploiSdk:()=>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=v(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,initialiseInploiSdk,inploiBrandedLogger,noLogging});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,E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,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"]}
|
|
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\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/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({ apiCl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C,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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as o,d as r,e,f,g as m}from"./chunk-
|
|
1
|
+
import{c as o,d as r,e,f,g as m}from"./chunk-NCQJAIJD.mjs";export{o as CONSOLE_PREFIX,r as CONSOLE_STYLE,m as initialiseInploiSdk,e as inploiBrandedLogger,f as noLogging};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/journeys/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty,
|
|
1
|
+
"use strict";var p=Object.defineProperty,O=Object.defineProperties,A=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,_=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,u=(e,r)=>{for(var n in r||(r={}))h.call(r,n)&&y(e,n,r[n]);if(f)for(var n of f(r))_.call(r,n)&&y(e,n,r[n]);return e},v=(e,r)=>O(e,I(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 S(r))!h.call(e,t)&&t!==n&&p(e,t,{get:()=>r[t],enumerable:!(i=A(r,t))||i.enumerable});return e};var R=e=>N(p({},"__esModule",{value:!0}),e);var l=(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 D={};M(D,{initialiseInploiSdk:()=>J,journeysPlugin:()=>U});module.exports=R(D);var E=(e,{initialise:r})=>({pluginName:e,initialise:r});var w={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},x="/journey/log";function T({apiClient:e,logger:r}){function n(i){return l(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(x,{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.",L=e=>{let r={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(t,...d)=>l(void 0,[t,...d],function*(n,i={}){let a=v(u({},i),{headers:u(u({},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 g="%c[inploi SDK]",m="color: #65BC67; font-weight: bold;",b={warn:e=>console.warn(g,m,e),error:e=>console.error(g,m,e),info:e=>console.info(g,m,e),log:e=>console.log(g,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=L({baseUrl:w[r],publishableKey:e});return n.reduce((a,o)=>(a[o.pluginName]=o.initialise({apiClient:t,logger:i}),a),{})}var U=E("journey",{initialise:T});0&&(module.exports={initialiseInploiSdk,journeysPlugin});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
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,E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H,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"]}
|
|
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\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/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,E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ommonJS","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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o,b as i,g as m}from"../chunk-
|
|
1
|
+
import{a as o,b as i,g as m}from"../chunk-NCQJAIJD.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
2
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inploi/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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,mB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isedMessage","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"]}
|