@inploi/sdk 1.7.2 → 1.7.4
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/index.js +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/cdn/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// This is an inploi sdk script. Learn more at https://inploi.com
|
|
2
2
|
|
|
3
|
-
"use strict";(()=>{var k=Object.defineProperty,I=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var w=(e,o,t)=>o in e?k(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,l=(e,o)=>{for(var t in o||(o={}))b.call(o,t)&&w(e,t,o[t]);if(m)for(var t of m(o))C.call(o,t)&&w(e,t,o[t]);return e},v=(e,o)=>I(e,O(o));var u=(e,o,t)=>new Promise((r,i)=>{var s=n=>{try{p(t.next(n))}catch(c){i(c)}},a=n=>{try{p(t.throw(n))}catch(c){i(c)}},p=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);p((t=t.apply(e,o)).next())});function f(e,o){if(!e)throw new Error(o)}var
|
|
3
|
+
"use strict";(()=>{var k=Object.defineProperty,I=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var w=(e,o,t)=>o in e?k(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,l=(e,o)=>{for(var t in o||(o={}))b.call(o,t)&&w(e,t,o[t]);if(m)for(var t of m(o))C.call(o,t)&&w(e,t,o[t]);return e},v=(e,o)=>I(e,O(o));var u=(e,o,t)=>new Promise((r,i)=>{var s=n=>{try{p(t.next(n))}catch(c){i(c)}},a=n=>{try{p(t.throw(n))}catch(c){i(c)}},p=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);p((t=t.apply(e,o)).next())});function f(e,o){if(!e)throw new Error(o)}var h={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},A=1,P="/analytics/log",y="isdk_anon_id";var _=e=>{let o=new Date;return o.setTime(o.getTime()+1e3*36e3),`${y}=${e};expires=${o.toUTCString()};path=/`},M=new RegExp(`${y}=([^;]+)`),N=e=>{let o=e?e.url:location.href,{searchParams:t}=new URL(o),r=t.get("anonymous_id");if(r)return r;let i=e?e.headers.get("cookie"):document.cookie;if(i){let s=M.exec(i);if(s!=null&&s[1])return s[1]}return null},R=e=>typeof e!="object"||e===null||!("anonymous_id"in e&&typeof e.anonymous_id=="string")?null:e.anonymous_id,E=({apiClient:e,logger:o})=>({log:r=>u(void 0,null,function*(){f(r.request||typeof window!="undefined","Cannot log on the server without a request. Please pass a request to `log`.");let i="request"in r&&r.request?{href:r.request.url,referrer:r.request.referrer,title:""}:{href:location.href,referrer:document.referrer,title:document.title};try{let s={library:{name:"inploi-sdk",version:A},page:i},a={anonymous_id:N(r.request),event:r.event,sent_at:new Date().toISOString(),context:s,properties:r.properties,custom_properties:r.customProperties},p=yield e.fetch(P,{method:"POST",body:JSON.stringify(a)}),n=R(p);n&&(a.anonymous_id=n);let c=n!=null?n:a.anonymous_id;return typeof window!="undefined"&&c&&(document.cookie=_(c)),{success:!0,data:a}}catch(s){return o.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:s}}}),getHeaders:r=>{let i=new Headers;return r.anonymous_id&&i.append("Set-Cookie",_(r.anonymous_id)),i}});var q="Unauthenticated",F="This action is unauthorized.",L=e=>{let o={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(i,...s)=>u(void 0,[i,...s],function*(t,r={}){let a=v(l({},r),{headers:l(l({},r.headers),o)}),n=yield(yield fetch(`${e.baseUrl}${t}`,a)).json();if(typeof n=="object"&&n!==null&&"message"in n){if(n.message===q)throw new Error("You are not authenticated.");if(n.message===F)throw new Error("You are not authorised to perform this action.");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 g="%c[inploi SDK]",d="color: #65BC67; font-weight: bold;",x={warn:(...e)=>console.warn(g,d,...e),error:(...e)=>console.error(g,d,...e),info:(...e)=>console.info(g,d,...e),log:(...e)=>console.log(g,d,...e)},T={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};function S({publishableKey:e,env:o,logger:t=x}){let r=L({baseUrl:h[o],publishableKey:e}),i=t===!1?T:t,s=E({apiClient:r,logger:i});return{register:p=>p({logger:i,apiClient:r,analytics:s}),analytics:s}}typeof window.inploi!="object"&&(window.inploi={});window.process=window.process||{};window.process.env=window.process.env||{};window.process.env.NODE_ENV="production";window.inploi.initialiseSdk=S;})();
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty,b=Object.defineProperties,O=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertyNames,A=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var x=(e,o,t)=>o in e?g(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,c=(e,o)=>{for(var t in o||(o={}))L.call(o,t)&&x(e,t,o[t]);if(A)for(var t of A(o))N.call(o,t)&&x(e,t,o[t]);return e},_=(e,o)=>b(e,M(o));var F=(e,o)=>{for(var t in o)g(e,t,{get:o[t],enumerable:!0})},
|
|
1
|
+
"use strict";var g=Object.defineProperty,b=Object.defineProperties,O=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertyNames,A=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var x=(e,o,t)=>o in e?g(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,c=(e,o)=>{for(var t in o||(o={}))L.call(o,t)&&x(e,t,o[t]);if(A)for(var t of A(o))N.call(o,t)&&x(e,t,o[t]);return e},_=(e,o)=>b(e,M(o));var F=(e,o)=>{for(var t in o)g(e,t,{get:o[t],enumerable:!0})},j=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of R(o))!L.call(e,i)&&i!==t&&g(e,i,{get:()=>o[i],enumerable:!(n=O(o,i))||n.enumerable});return e};var q=e=>j(g({},"__esModule",{value:!0}),e);var d=(e,o,t)=>new Promise((n,i)=>{var s=r=>{try{p(t.next(r))}catch(l){i(l)}},a=r=>{try{p(t.throw(r))}catch(l){i(l)}},p=r=>r.done?n(r.value):Promise.resolve(r.value).then(s,a);p((t=t.apply(e,o)).next())});var V={};F(V,{createPlugin:()=>v,initialiseSdk:()=>C,inploiBrandedLogger:()=>m,noLogging:()=>f});module.exports=q(V);var u="%c[inploi SDK]",y="color: #65BC67; font-weight: bold;",m={warn:(...e)=>console.warn(u,y,...e),error:(...e)=>console.error(u,y,...e),info:(...e)=>console.info(u,y,...e),log:(...e)=>console.log(u,y,...e)},f={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var v=e=>e;var w=require("@inploi/core/common");var E={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},h=1,k="/analytics/log",P="isdk_anon_id";var T=e=>{let o=new Date;return o.setTime(o.getTime()+1e3*36e3),`${P}=${e};expires=${o.toUTCString()};path=/`},Y=new RegExp(`${P}=([^;]+)`),D=e=>{let o=e?e.url:location.href,{searchParams:t}=new URL(o),n=t.get("anonymous_id");if(n)return n;let i=e?e.headers.get("cookie"):document.cookie;if(i){let s=Y.exec(i);if(s!=null&&s[1])return s[1]}return null},U=e=>typeof e!="object"||e===null||!("anonymous_id"in e&&typeof e.anonymous_id=="string")?null:e.anonymous_id,I=({apiClient:e,logger:o})=>({log:n=>d(void 0,null,function*(){(0,w.invariant)(n.request||typeof window!="undefined","Cannot log on the server without a request. Please pass a request to `log`.");let i="request"in n&&n.request?{href:n.request.url,referrer:n.request.referrer,title:""}:{href:location.href,referrer:document.referrer,title:document.title};try{let s={library:{name:"inploi-sdk",version:h},page:i},a={anonymous_id:D(n.request),event:n.event,sent_at:new Date().toISOString(),context:s,properties:n.properties,custom_properties:n.customProperties},p=yield e.fetch(k,{method:"POST",body:JSON.stringify(a)}),r=U(p);r&&(a.anonymous_id=r);let l=r!=null?r:a.anonymous_id;return typeof window!="undefined"&&l&&(document.cookie=T(l)),{success:!0,data:a}}catch(s){return o.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:s}}}),getHeaders:n=>{let i=new Headers;return n.anonymous_id&&i.append("Set-Cookie",T(n.anonymous_id)),i}});var H="Unauthenticated",$="This action is unauthorized.",S=e=>{let o={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(i,...s)=>d(void 0,[i,...s],function*(t,n={}){let a=_(c({},n),{headers:c(c({},n.headers),o)}),r=yield(yield fetch(`${e.baseUrl}${t}`,a)).json();if(typeof r=="object"&&r!==null&&"message"in r){if(r.message===H)throw new Error("You are not authenticated.");if(r.message===$)throw new Error("You are not authorised to perform this action.");if("exception"in r)throw new Error(`API error: \u201C${r.message}\u201D`);if("errors"in r)throw new Error(`API error: \u201C${r.message}\u201D`)}return r})}};function C({publishableKey:e,env:o,logger:t=m}){let n=S({baseUrl:E[o],publishableKey:e}),i=t===!1?f:t,s=I({apiClient:n,logger:i});return{register:p=>p({logger:i,apiClient:n,analytics:s}),analytics:s}}0&&(module.exports={createPlugin,initialiseSdk,inploiBrandedLogger,noLogging});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/sdk.logger.ts","../src/sdk.plugins.ts","../src/sdk.analytics.ts","../src/sdk.constants.ts","../src/sdk.api.ts","../src/sdk.ts"],"sourcesContent":["export { inploiBrandedLogger, noLogging } from './sdk.logger';\nexport type { Logger } from './sdk.logger';\n\nexport type { Plugin, PluginParams } from './sdk.plugins';\nexport { createPlugin } from './sdk.plugins';\n\nexport type { ApiClient } from './sdk.api';\n\nexport { initialiseSdk } from './sdk';\nexport type { InitialiseInploiSdkParams } from './sdk';\n\nexport type { AnalyticsService, AnalyticsLogEvent } from './sdk.analytics';\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: (...args) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\terror: (...args) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tinfo: (...args) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tlog: (...args) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","import { AnalyticsService } from './sdk.analytics';\nimport { ApiClient } from './sdk.api';\nimport { Logger } from './sdk.logger';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n};\n\nexport type Plugin<T extends string, P extends Record<string, unknown>> = {\n\tpluginName: T;\n\tpure_createActions: (params: PluginParams) => P;\n};\n\ntype PluginDependencies = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n\tanalytics: AnalyticsService;\n};\n\nexport type InploiSdkPlugin = (dependencies: PluginDependencies) => any;\n\nexport const createPlugin = <T extends InploiSdkPlugin>(pluginFn: T) => pluginFn;\n","import { Flatten, ResponseObj, invariant } from '@inploi/core/common';\n\nimport { ApiClient, Logger } from '.';\nimport { ANALYTICS_COOKIE_NAME, ANALYTICS_DATA_VERSION, LOG_PATHNAME } from './sdk.constants';\n\nconst formatCookie = (value: string) => {\n\tconst now = new Date();\n\tnow.setTime(now.getTime() + 1000 * 36000);\n\n\treturn `${ANALYTICS_COOKIE_NAME}=${value};expires=${now.toUTCString()};path=/`;\n};\n\ntype AnalyticsLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id: string; // External job ID\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'APPLY_FLOW_NODE';\n\t\t\tproperties: {\n\t\t\t\t/** Increment by 1 per node interpreted */\n\t\t\t\tsequence: number;\n\t\t\t\tfrom_node_id: string | null;\n\t\t\t\tto_node_id: string;\n\t\t\t\tjob_id: string;\n\t\t\t\tflow_id: string;\n\t\t\t\tflow_version: number;\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: never;\n\t };\n\nexport type AnalyticsLogEvent = AnalyticsLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in AnalyticsLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype AnalyticsContext = {\n\tlibrary: {\n\t\tname: 'inploi-sdk';\n\t\tversion: number;\n\t};\n\tpage: {\n\t\thref: string;\n\t\treferrer: string;\n\t\ttitle: string;\n\t};\n};\n\ntype TrackPayload<P = EventPropertyMap[keyof EventPropertyMap]['properties']> = {\n\tanonymous_id: string | null;\n\tevent: AnalyticsLogEvent;\n\tsent_at: string;\n\tcontext: AnalyticsContext;\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\ntype LogFnParams<T extends keyof EventPropertyMap> = {\n\tevent: T;\n\tcustomProperties?: Record<string, unknown>;\n\t/** Passing a request will make logging possible on a server environment. */\n\trequest?: Request;\n} & EventPropertyMap[T];\n\ntype LogFn = <TEvent extends keyof EventPropertyMap>(\n\tparams: LogFnParams<TEvent>,\n) => Promise<ResponseObj<TrackPayload<EventPropertyMap[TEvent]['properties']>>>;\n\nexport type AnalyticsService = {\n\tlog: LogFn;\n\t/** From a log payload data, generate headers to use in server environments to update the anonymous_id */\n\tgetHeaders: (payload: TrackPayload) => Headers;\n};\n\nconst cookieRegex = new RegExp(`${ANALYTICS_COOKIE_NAME}=([^;]+)`);\nconst getAnonymousId = (request?: Request) => {\n\tconst href = request ? request.url : location.href;\n\t// If there’s an anonymous_id in the search params, use it\n\tconst { searchParams } = new URL(href);\n\tconst anonymousId = searchParams.get('anonymous_id');\n\tif (anonymousId) return anonymousId;\n\n\t// If there’s a cookie, use it\n\tconst cookie = request ? request.headers.get('cookie') : document.cookie;\n\tif (cookie) {\n\t\tconst match = cookieRegex.exec(cookie);\n\t\tif (match?.[1]) return match[1];\n\t}\n\n\t// Otherwise, return null\n\treturn null;\n};\n\nconst getAnonymousIdFromResponseJson = (response: unknown) => {\n\tif (typeof response !== 'object' || response === null) return null;\n\tif (!('anonymous_id' in response && typeof response.anonymous_id === 'string')) return null;\n\treturn response.anonymous_id;\n};\n\nexport const createAnalyticsService = ({\n\tapiClient,\n\tlogger,\n}: {\n\tlogger: Logger;\n\tapiClient: ApiClient;\n}): AnalyticsService => {\n\tconst logFn: LogFn = async params => {\n\t\tinvariant(\n\t\t\tparams.request || typeof window !== 'undefined',\n\t\t\t'Cannot log on the server without a request. Please pass a request to `log`.',\n\t\t);\n\n\t\t// if there’s a request, use it instead of browser APIs\n\t\tconst page =\n\t\t\t'request' in params && params.request ?\n\t\t\t\t{\n\t\t\t\t\thref: params.request.url,\n\t\t\t\t\treferrer: params.request.referrer,\n\t\t\t\t\ttitle: '',\n\t\t\t\t}\n\t\t\t:\t{\n\t\t\t\t\thref: location.href,\n\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\ttitle: document.title,\n\t\t\t\t};\n\n\t\ttry {\n\t\t\tconst context: AnalyticsContext = {\n\t\t\t\tlibrary: {\n\t\t\t\t\tname: 'inploi-sdk',\n\t\t\t\t\tversion: ANALYTICS_DATA_VERSION,\n\t\t\t\t},\n\t\t\t\tpage,\n\t\t\t};\n\n\t\t\tconst payload: TrackPayload = {\n\t\t\t\tanonymous_id: getAnonymousId(params.request),\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\tproperties: params.properties,\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tconst responseJson = await apiClient.fetch(LOG_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(payload),\n\t\t\t});\n\n\t\t\tconst newAnonymousId = getAnonymousIdFromResponseJson(responseJson);\n\t\t\tif (newAnonymousId) {\n\t\t\t\tpayload.anonymous_id = newAnonymousId;\n\t\t\t}\n\n\t\t\tconst newCookieValue = newAnonymousId ?? payload.anonymous_id;\n\t\t\tif (typeof window !== 'undefined' && newCookieValue) {\n\t\t\t\tdocument.cookie = formatCookie(newCookieValue);\n\t\t\t}\n\n\t\t\treturn { success: true, data: payload };\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 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 {\n\t\tlog: logFn,\n\t\tgetHeaders: payload => {\n\t\t\tconst headers = new Headers();\n\t\t\tif (!payload.anonymous_id) return headers;\n\n\t\t\theaders.append('Set-Cookie', formatCookie(payload.anonymous_id));\n\t\t\treturn headers;\n\t\t},\n\t};\n};\n","/**\n * The environment the SDK should run in.\n * - `production`: data will be stored and displayed on dashboards\n * - `sandbox`: data will be stored temporarily and purged periodically\n */\nexport type AppEnvironment = 'production' | 'sandbox';\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\n/**\n * Change to invalidate existing sessions. Useful for when data has changed.\n * It does not need to be in sync with the library version, and is not semver.\n */\nexport const ANALYTICS_DATA_VERSION = 1;\n\nexport const LOG_PATHNAME = '/analytics/log';\n\nexport const ANALYTICS_COOKIE_NAME = 'isdk_anon_id';\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\t/** Fetches from a pathname with a pre-established base path.\n\t\t * Parses received output as JSON, and throw if one of the common error messages is received.\n\t\t */\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);\n\t\t\tconst json = await response.json();\n\n\t\t\tif (typeof json === 'object' && json !== null && 'message' in json) {\n\t\t\t\tif (json.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (json.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authorised to perform this action.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn json;\n\t\t},\n\t};\n};\n","import { createAnalyticsService } from './sdk.analytics';\nimport { createApiClient } from './sdk.api';\nimport { AppEnvironment, ENV_TO_API_URL } from './sdk.constants';\nimport { Logger, inploiBrandedLogger, noLogging } from './sdk.logger';\nimport { InploiSdkPlugin } from './sdk.plugins';\n\nexport type InitialiseInploiSdkParams = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\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 passing`false`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger | false;\n};\n\nexport function initialiseSdk({ publishableKey, env, logger = inploiBrandedLogger }: InitialiseInploiSdkParams) {\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\tconst loggerService = logger === false ? noLogging : logger;\n\tconst analytics = createAnalyticsService({ apiClient, logger: loggerService });\n\n\tconst register = <P extends InploiSdkPlugin>(plugin: P): ReturnType<P> => {\n\t\treturn plugin({ logger: loggerService, apiClient, analytics });\n\t};\n\n\treturn { register, analytics };\n}\n"],"mappings":"i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,kBAAAC,EAAA,wBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAN,GCAO,IAAMO,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAM,IAAIC,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,MAAO,IAAIA,IAAS,QAAQ,MAAMH,EAAgBC,EAAe,GAAGE,CAAI,EACxE,KAAM,IAAIA,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,IAAK,IAAIA,IAAS,QAAQ,IAAIH,EAAgBC,EAAe,GAAGE,CAAI,CACrE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECI3G,IAAMC,EAA2CC,GAAgBA,ECtBx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nE,GAAIA,EAAK,UAAYb,EACpB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAK,UAAYZ,EACpB,MAAM,IAAI,MAAM,gDAAgD,EAEjE,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,EAE/C,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,CAEhD,CACA,OAAOA,CACR,EACD,CACD,ECrBO,SAASC,EAAc,CAAE,eAAAC,EAAgB,IAAAC,EAAK,OAAAC,EAASC,CAAoB,EAA8B,CAC/G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeL,CAAG,EAAG,eAAAD,CAAe,CAAC,EAC5EO,EAAgBL,IAAW,GAAQM,EAAYN,EAC/CO,EAAYC,EAAuB,CAAE,UAAAN,EAAW,OAAQG,CAAc,CAAC,EAM7E,MAAO,CAAE,SAJoCI,GACrCA,EAAO,CAAE,OAAQJ,EAAe,UAAAH,EAAW,UAAAK,CAAU,CAAC,EAG3C,UAAAA,CAAU,CAC9B","names":["src_exports","__export","createPlugin","initialiseSdk","inploiBrandedLogger","noLogging","__toCommonJS","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","args","noLogging","createPlugin","pluginFn","import_common","ENV_TO_API_URL","ANALYTICS_DATA_VERSION","LOG_PATHNAME","ANALYTICS_COOKIE_NAME","formatCookie","value","now","ANALYTICS_COOKIE_NAME","cookieRegex","getAnonymousId","request","href","searchParams","anonymousId","cookie","match","getAnonymousIdFromResponseJson","response","createAnalyticsService","apiClient","logger","params","__async","page","context","ANALYTICS_DATA_VERSION","payload","responseJson","LOG_PATHNAME","newAnonymousId","newCookieValue","e","headers","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","json","initialiseSdk","publishableKey","env","logger","inploiBrandedLogger","apiClient","createApiClient","ENV_TO_API_URL","loggerService","noLogging","analytics","createAnalyticsService","plugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk.logger.ts","../src/sdk.plugins.ts","../src/sdk.analytics.ts","../src/sdk.constants.ts","../src/sdk.api.ts","../src/sdk.ts"],"sourcesContent":["export { inploiBrandedLogger, noLogging } from './sdk.logger';\nexport type { Logger } from './sdk.logger';\n\nexport type { Plugin, PluginParams } from './sdk.plugins';\nexport { createPlugin } from './sdk.plugins';\n\nexport type { ApiClient } from './sdk.api';\n\nexport { initialiseSdk } from './sdk';\nexport type { InitialiseInploiSdkParams } from './sdk';\n\nexport type { AnalyticsService, AnalyticsLogEvent } from './sdk.analytics';\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: (...args) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\terror: (...args) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tinfo: (...args) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tlog: (...args) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","import { AnalyticsService } from './sdk.analytics';\nimport { ApiClient } from './sdk.api';\nimport { Logger } from './sdk.logger';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n};\n\nexport type Plugin<T extends string, P extends Record<string, unknown>> = {\n\tpluginName: T;\n\tpure_createActions: (params: PluginParams) => P;\n};\n\ntype PluginDependencies = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n\tanalytics: AnalyticsService;\n};\n\nexport type InploiSdkPlugin = (dependencies: PluginDependencies) => any;\n\nexport const createPlugin = <T extends InploiSdkPlugin>(pluginFn: T) => pluginFn;\n","import { Flatten, ResponseObj, invariant } from '@inploi/core/common';\n\nimport { ApiClient, Logger } from '.';\nimport { ANALYTICS_COOKIE_NAME, ANALYTICS_DATA_VERSION, LOG_PATHNAME } from './sdk.constants';\n\nconst formatCookie = (value: string) => {\n\tconst now = new Date();\n\tnow.setTime(now.getTime() + 1000 * 36000);\n\n\treturn `${ANALYTICS_COOKIE_NAME}=${value};expires=${now.toUTCString()};path=/`;\n};\n\ntype AnalyticsLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id: string; // External job ID\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'FLOW_NODE';\n\t\t\tproperties: {\n\t\t\t\t/** Increment by 1 per node interpreted */\n\t\t\t\tsequence: number;\n\t\t\t\tfrom_node_id: string | null;\n\t\t\t\tto_node_id: string;\n\t\t\t\tjob_id: string;\n\t\t\t\tflow_id: string;\n\t\t\t\tflow_version: number;\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: never;\n\t };\n\nexport type AnalyticsLogEvent = AnalyticsLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in AnalyticsLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype AnalyticsContext = {\n\tlibrary: {\n\t\tname: 'inploi-sdk';\n\t\tversion: number;\n\t};\n\tpage: {\n\t\thref: string;\n\t\treferrer: string;\n\t\ttitle: string;\n\t};\n};\n\ntype TrackPayload<P = EventPropertyMap[keyof EventPropertyMap]['properties']> = {\n\tanonymous_id: string | null;\n\tevent: AnalyticsLogEvent;\n\tsent_at: string;\n\tcontext: AnalyticsContext;\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\ntype LogFnParams<T extends keyof EventPropertyMap> = {\n\tevent: T;\n\tcustomProperties?: Record<string, unknown>;\n\t/** Passing a request will make logging possible on a server environment. */\n\trequest?: Request;\n} & EventPropertyMap[T];\n\ntype LogFn = <TEvent extends keyof EventPropertyMap>(\n\tparams: LogFnParams<TEvent>,\n) => Promise<ResponseObj<TrackPayload<EventPropertyMap[TEvent]['properties']>>>;\n\nexport type AnalyticsService = {\n\tlog: LogFn;\n\t/** From a log payload data, generate headers to use in server environments to update the anonymous_id */\n\tgetHeaders: (payload: TrackPayload) => Headers;\n};\n\nconst cookieRegex = new RegExp(`${ANALYTICS_COOKIE_NAME}=([^;]+)`);\nconst getAnonymousId = (request?: Request) => {\n\tconst href = request ? request.url : location.href;\n\t// If there’s an anonymous_id in the search params, use it\n\tconst { searchParams } = new URL(href);\n\tconst anonymousId = searchParams.get('anonymous_id');\n\tif (anonymousId) return anonymousId;\n\n\t// If there’s a cookie, use it\n\tconst cookie = request ? request.headers.get('cookie') : document.cookie;\n\tif (cookie) {\n\t\tconst match = cookieRegex.exec(cookie);\n\t\tif (match?.[1]) return match[1];\n\t}\n\n\t// Otherwise, return null\n\treturn null;\n};\n\nconst getAnonymousIdFromResponseJson = (response: unknown) => {\n\tif (typeof response !== 'object' || response === null) return null;\n\tif (!('anonymous_id' in response && typeof response.anonymous_id === 'string')) return null;\n\treturn response.anonymous_id;\n};\n\nexport const createAnalyticsService = ({\n\tapiClient,\n\tlogger,\n}: {\n\tlogger: Logger;\n\tapiClient: ApiClient;\n}): AnalyticsService => {\n\tconst logFn: LogFn = async params => {\n\t\tinvariant(\n\t\t\tparams.request || typeof window !== 'undefined',\n\t\t\t'Cannot log on the server without a request. Please pass a request to `log`.',\n\t\t);\n\n\t\t// if there’s a request, use it instead of browser APIs\n\t\tconst page =\n\t\t\t'request' in params && params.request ?\n\t\t\t\t{\n\t\t\t\t\thref: params.request.url,\n\t\t\t\t\treferrer: params.request.referrer,\n\t\t\t\t\ttitle: '',\n\t\t\t\t}\n\t\t\t:\t{\n\t\t\t\t\thref: location.href,\n\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\ttitle: document.title,\n\t\t\t\t};\n\n\t\ttry {\n\t\t\tconst context: AnalyticsContext = {\n\t\t\t\tlibrary: {\n\t\t\t\t\tname: 'inploi-sdk',\n\t\t\t\t\tversion: ANALYTICS_DATA_VERSION,\n\t\t\t\t},\n\t\t\t\tpage,\n\t\t\t};\n\n\t\t\tconst payload: TrackPayload = {\n\t\t\t\tanonymous_id: getAnonymousId(params.request),\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\tproperties: params.properties,\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tconst responseJson = await apiClient.fetch(LOG_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(payload),\n\t\t\t});\n\n\t\t\tconst newAnonymousId = getAnonymousIdFromResponseJson(responseJson);\n\t\t\tif (newAnonymousId) {\n\t\t\t\tpayload.anonymous_id = newAnonymousId;\n\t\t\t}\n\n\t\t\tconst newCookieValue = newAnonymousId ?? payload.anonymous_id;\n\t\t\tif (typeof window !== 'undefined' && newCookieValue) {\n\t\t\t\tdocument.cookie = formatCookie(newCookieValue);\n\t\t\t}\n\n\t\t\treturn { success: true, data: payload };\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 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 {\n\t\tlog: logFn,\n\t\tgetHeaders: payload => {\n\t\t\tconst headers = new Headers();\n\t\t\tif (!payload.anonymous_id) return headers;\n\n\t\t\theaders.append('Set-Cookie', formatCookie(payload.anonymous_id));\n\t\t\treturn headers;\n\t\t},\n\t};\n};\n","/**\n * The environment the SDK should run in.\n * - `production`: data will be stored and displayed on dashboards\n * - `sandbox`: data will be stored temporarily and purged periodically\n */\nexport type AppEnvironment = 'production' | 'sandbox';\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\n/**\n * Change to invalidate existing sessions. Useful for when data has changed.\n * It does not need to be in sync with the library version, and is not semver.\n */\nexport const ANALYTICS_DATA_VERSION = 1;\n\nexport const LOG_PATHNAME = '/analytics/log';\n\nexport const ANALYTICS_COOKIE_NAME = 'isdk_anon_id';\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\t/** Fetches from a pathname with a pre-established base path.\n\t\t * Parses received output as JSON, and throw if one of the common error messages is received.\n\t\t */\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);\n\t\t\tconst json = await response.json();\n\n\t\t\tif (typeof json === 'object' && json !== null && 'message' in json) {\n\t\t\t\tif (json.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (json.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authorised to perform this action.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn json;\n\t\t},\n\t};\n};\n","import { createAnalyticsService } from './sdk.analytics';\nimport { createApiClient } from './sdk.api';\nimport { AppEnvironment, ENV_TO_API_URL } from './sdk.constants';\nimport { Logger, inploiBrandedLogger, noLogging } from './sdk.logger';\nimport { InploiSdkPlugin } from './sdk.plugins';\n\nexport type InitialiseInploiSdkParams = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\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 passing`false`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger | false;\n};\n\nexport function initialiseSdk({ publishableKey, env, logger = inploiBrandedLogger }: InitialiseInploiSdkParams) {\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\tconst loggerService = logger === false ? noLogging : logger;\n\tconst analytics = createAnalyticsService({ apiClient, logger: loggerService });\n\n\tconst register = <P extends InploiSdkPlugin>(plugin: P): ReturnType<P> => {\n\t\treturn plugin({ logger: loggerService, apiClient, analytics });\n\t};\n\n\treturn { register, analytics };\n}\n"],"mappings":"i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,kBAAAC,EAAA,wBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAN,GCAO,IAAMO,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAM,IAAIC,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,MAAO,IAAIA,IAAS,QAAQ,MAAMH,EAAgBC,EAAe,GAAGE,CAAI,EACxE,KAAM,IAAIA,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,IAAK,IAAIA,IAAS,QAAQ,IAAIH,EAAgBC,EAAe,GAAGE,CAAI,CACrE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,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OAAOG,GAAS,UAAYA,IAAS,MAAQ,YAAaA,EAAM,CACnE,GAAIA,EAAK,UAAYb,EACpB,MAAM,IAAI,MAAM,4BAA4B,EAE7C,GAAIa,EAAK,UAAYZ,EACpB,MAAM,IAAI,MAAM,gDAAgD,EAEjE,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,EAE/C,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,CAEhD,CACA,OAAOA,CACR,EACD,CACD,ECrBO,SAASC,EAAc,CAAE,eAAAC,EAAgB,IAAAC,EAAK,OAAAC,EAASC,CAAoB,EAA8B,CAC/G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeL,CAAG,EAAG,eAAAD,CAAe,CAAC,EAC5EO,EAAgBL,IAAW,GAAQM,EAAYN,EAC/CO,EAAYC,EAAuB,CAAE,UAAAN,EAAW,OAAQG,CAAc,CAAC,EAM7E,MAAO,CAAE,SAJoCI,GACrCA,EAAO,CAAE,OAAQJ,EAAe,UAAAH,EAAW,UAAAK,CAAU,CAAC,EAG3C,UAAAA,CAAU,CAC9B","names":["src_exports","__export","createPlugin","initialiseSdk","inploiBrandedLogger","noLogging","__toCommonJS","CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","args","noLogging","createPlugin","pluginFn","import_common","ENV_TO_API_URL","ANALYTICS_DATA_VERSION","LOG_PATHNAME","ANALYTICS_COOKIE_NAME","formatCookie","value","now","ANALYTICS_COOKIE_NAME","cookieRegex","getAnonymousId","request","href","searchParams","anonymousId","cookie","match","getAnonymousIdFromResponseJson","response","createAnalyticsService","apiClient","logger","params","__async","page","context","ANALYTICS_DATA_VERSION","payload","responseJson","LOG_PATHNAME","newAnonymousId","newCookieValue","e","headers","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","json","initialiseSdk","publishableKey","env","logger","inploiBrandedLogger","apiClient","createApiClient","ENV_TO_API_URL","loggerService","noLogging","analytics","createAnalyticsService","plugin"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var T=Object.defineProperty,w=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var A=(e,o,n)=>o in e?T(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,g=(e,o)=>{for(var n in o||(o={}))S.call(o,n)&&A(e,n,o[n]);if(P)for(var n of P(o))C.call(o,n)&&A(e,n,o[n]);return e},x=(e,o)=>w(e,I(o));var c=(e,o,n)=>new Promise((r,i)=>{var s=t=>{try{p(n.next(t))}catch(l){i(l)}},a=t=>{try{p(n.throw(t))}catch(l){i(l)}},p=t=>t.done?r(t.value):Promise.resolve(t.value).then(s,a);p((n=n.apply(e,o)).next())});var d="%c[inploi SDK]",u="color: #65BC67; font-weight: bold;",y={warn:(...e)=>console.warn(d,u,...e),error:(...e)=>console.error(d,u,...e),info:(...e)=>console.info(d,u,...e),log:(...e)=>console.log(d,u,...e)},m={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var b=e=>e;import{invariant as O}from"@inploi/core/common";var L={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},_=1,v="/analytics/log",f="isdk_anon_id";var E=e=>{let o=new Date;return o.setTime(o.getTime()+1e3*36e3),`${f}=${e};expires=${o.toUTCString()};path=/`},M=new RegExp(`${f}=([^;]+)`),R=e=>{let o=e?e.url:location.href,{searchParams:n}=new URL(o),r=n.get("anonymous_id");if(r)return r;let i=e?e.headers.get("cookie"):document.cookie;if(i){let s=M.exec(i);if(s!=null&&s[1])return s[1]}return null},N=e=>typeof e!="object"||e===null||!("anonymous_id"in e&&typeof e.anonymous_id=="string")?null:e.anonymous_id,h=({apiClient:e,logger:o})=>({log:r=>c(void 0,null,function*(){O(r.request||typeof window!="undefined","Cannot log on the server without a request. Please pass a request to `log`.");let i="request"in r&&r.request?{href:r.request.url,referrer:r.request.referrer,title:""}:{href:location.href,referrer:document.referrer,title:document.title};try{let s={library:{name:"inploi-sdk",version:_},page:i},a={anonymous_id:R(r.request),event:r.event,sent_at:new Date().toISOString(),context:s,properties:r.properties,custom_properties:r.customProperties},p=yield e.fetch(v,{method:"POST",body:JSON.stringify(a)}),t=N(p);t&&(a.anonymous_id=t);let l=t!=null?t:a.anonymous_id;return typeof window!="undefined"&&l&&(document.cookie=E(l)),{success:!0,data:a}}catch(s){return o.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:s}}}),getHeaders:r=>{let i=new Headers;return r.anonymous_id&&i.append("Set-Cookie",E(r.anonymous_id)),i}});var F="Unauthenticated",
|
|
1
|
+
var T=Object.defineProperty,w=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var A=(e,o,n)=>o in e?T(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,g=(e,o)=>{for(var n in o||(o={}))S.call(o,n)&&A(e,n,o[n]);if(P)for(var n of P(o))C.call(o,n)&&A(e,n,o[n]);return e},x=(e,o)=>w(e,I(o));var c=(e,o,n)=>new Promise((r,i)=>{var s=t=>{try{p(n.next(t))}catch(l){i(l)}},a=t=>{try{p(n.throw(t))}catch(l){i(l)}},p=t=>t.done?r(t.value):Promise.resolve(t.value).then(s,a);p((n=n.apply(e,o)).next())});var d="%c[inploi SDK]",u="color: #65BC67; font-weight: bold;",y={warn:(...e)=>console.warn(d,u,...e),error:(...e)=>console.error(d,u,...e),info:(...e)=>console.info(d,u,...e),log:(...e)=>console.log(d,u,...e)},m={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var b=e=>e;import{invariant as O}from"@inploi/core/common";var L={sandbox:"https://preview.api.inploi.com",production:"https://api.inploi.com"},_=1,v="/analytics/log",f="isdk_anon_id";var E=e=>{let o=new Date;return o.setTime(o.getTime()+1e3*36e3),`${f}=${e};expires=${o.toUTCString()};path=/`},M=new RegExp(`${f}=([^;]+)`),R=e=>{let o=e?e.url:location.href,{searchParams:n}=new URL(o),r=n.get("anonymous_id");if(r)return r;let i=e?e.headers.get("cookie"):document.cookie;if(i){let s=M.exec(i);if(s!=null&&s[1])return s[1]}return null},N=e=>typeof e!="object"||e===null||!("anonymous_id"in e&&typeof e.anonymous_id=="string")?null:e.anonymous_id,h=({apiClient:e,logger:o})=>({log:r=>c(void 0,null,function*(){O(r.request||typeof window!="undefined","Cannot log on the server without a request. Please pass a request to `log`.");let i="request"in r&&r.request?{href:r.request.url,referrer:r.request.referrer,title:""}:{href:location.href,referrer:document.referrer,title:document.title};try{let s={library:{name:"inploi-sdk",version:_},page:i},a={anonymous_id:R(r.request),event:r.event,sent_at:new Date().toISOString(),context:s,properties:r.properties,custom_properties:r.customProperties},p=yield e.fetch(v,{method:"POST",body:JSON.stringify(a)}),t=N(p);t&&(a.anonymous_id=t);let l=t!=null?t:a.anonymous_id;return typeof window!="undefined"&&l&&(document.cookie=E(l)),{success:!0,data:a}}catch(s){return o.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:s}}}),getHeaders:r=>{let i=new Headers;return r.anonymous_id&&i.append("Set-Cookie",E(r.anonymous_id)),i}});var F="Unauthenticated",j="This action is unauthorized.",k=e=>{let o={Accept:"application/json","Content-Type":"application/json","x-publishable-key":e.publishableKey};return{fetch:(i,...s)=>c(void 0,[i,...s],function*(n,r={}){let a=x(g({},r),{headers:g(g({},r.headers),o)}),t=yield(yield fetch(`${e.baseUrl}${n}`,a)).json();if(typeof t=="object"&&t!==null&&"message"in t){if(t.message===F)throw new Error("You are not authenticated.");if(t.message===j)throw new Error("You are not authorised to perform this action.");if("exception"in t)throw new Error(`API error: \u201C${t.message}\u201D`);if("errors"in t)throw new Error(`API error: \u201C${t.message}\u201D`)}return t})}};function q({publishableKey:e,env:o,logger:n=y}){let r=k({baseUrl:L[o],publishableKey:e}),i=n===!1?m:n,s=h({apiClient:r,logger:i});return{register:p=>p({logger:i,apiClient:r,analytics:s}),analytics:s}}export{b as createPlugin,q as initialiseSdk,y as inploiBrandedLogger,m as noLogging};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.logger.ts","../src/sdk.plugins.ts","../src/sdk.analytics.ts","../src/sdk.constants.ts","../src/sdk.api.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: (...args) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\terror: (...args) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tinfo: (...args) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tlog: (...args) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","import { AnalyticsService } from './sdk.analytics';\nimport { ApiClient } from './sdk.api';\nimport { Logger } from './sdk.logger';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n};\n\nexport type Plugin<T extends string, P extends Record<string, unknown>> = {\n\tpluginName: T;\n\tpure_createActions: (params: PluginParams) => P;\n};\n\ntype PluginDependencies = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n\tanalytics: AnalyticsService;\n};\n\nexport type InploiSdkPlugin = (dependencies: PluginDependencies) => any;\n\nexport const createPlugin = <T extends InploiSdkPlugin>(pluginFn: T) => pluginFn;\n","import { Flatten, ResponseObj, invariant } from '@inploi/core/common';\n\nimport { ApiClient, Logger } from '.';\nimport { ANALYTICS_COOKIE_NAME, ANALYTICS_DATA_VERSION, LOG_PATHNAME } from './sdk.constants';\n\nconst formatCookie = (value: string) => {\n\tconst now = new Date();\n\tnow.setTime(now.getTime() + 1000 * 36000);\n\n\treturn `${ANALYTICS_COOKIE_NAME}=${value};expires=${now.toUTCString()};path=/`;\n};\n\ntype AnalyticsLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id: string; // External job ID\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'APPLY_FLOW_NODE';\n\t\t\tproperties: {\n\t\t\t\t/** Increment by 1 per node interpreted */\n\t\t\t\tsequence: number;\n\t\t\t\tfrom_node_id: string | null;\n\t\t\t\tto_node_id: string;\n\t\t\t\tjob_id: string;\n\t\t\t\tflow_id: string;\n\t\t\t\tflow_version: number;\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: never;\n\t };\n\nexport type AnalyticsLogEvent = AnalyticsLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in AnalyticsLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype AnalyticsContext = {\n\tlibrary: {\n\t\tname: 'inploi-sdk';\n\t\tversion: number;\n\t};\n\tpage: {\n\t\thref: string;\n\t\treferrer: string;\n\t\ttitle: string;\n\t};\n};\n\ntype TrackPayload<P = EventPropertyMap[keyof EventPropertyMap]['properties']> = {\n\tanonymous_id: string | null;\n\tevent: AnalyticsLogEvent;\n\tsent_at: string;\n\tcontext: AnalyticsContext;\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\ntype LogFnParams<T extends keyof EventPropertyMap> = {\n\tevent: T;\n\tcustomProperties?: Record<string, unknown>;\n\t/** Passing a request will make logging possible on a server environment. */\n\trequest?: Request;\n} & EventPropertyMap[T];\n\ntype LogFn = <TEvent extends keyof EventPropertyMap>(\n\tparams: LogFnParams<TEvent>,\n) => Promise<ResponseObj<TrackPayload<EventPropertyMap[TEvent]['properties']>>>;\n\nexport type AnalyticsService = {\n\tlog: LogFn;\n\t/** From a log payload data, generate headers to use in server environments to update the anonymous_id */\n\tgetHeaders: (payload: TrackPayload) => Headers;\n};\n\nconst cookieRegex = new RegExp(`${ANALYTICS_COOKIE_NAME}=([^;]+)`);\nconst getAnonymousId = (request?: Request) => {\n\tconst href = request ? request.url : location.href;\n\t// If there’s an anonymous_id in the search params, use it\n\tconst { searchParams } = new URL(href);\n\tconst anonymousId = searchParams.get('anonymous_id');\n\tif (anonymousId) return anonymousId;\n\n\t// If there’s a cookie, use it\n\tconst cookie = request ? request.headers.get('cookie') : document.cookie;\n\tif (cookie) {\n\t\tconst match = cookieRegex.exec(cookie);\n\t\tif (match?.[1]) return match[1];\n\t}\n\n\t// Otherwise, return null\n\treturn null;\n};\n\nconst getAnonymousIdFromResponseJson = (response: unknown) => {\n\tif (typeof response !== 'object' || response === null) return null;\n\tif (!('anonymous_id' in response && typeof response.anonymous_id === 'string')) return null;\n\treturn response.anonymous_id;\n};\n\nexport const createAnalyticsService = ({\n\tapiClient,\n\tlogger,\n}: {\n\tlogger: Logger;\n\tapiClient: ApiClient;\n}): AnalyticsService => {\n\tconst logFn: LogFn = async params => {\n\t\tinvariant(\n\t\t\tparams.request || typeof window !== 'undefined',\n\t\t\t'Cannot log on the server without a request. Please pass a request to `log`.',\n\t\t);\n\n\t\t// if there’s a request, use it instead of browser APIs\n\t\tconst page =\n\t\t\t'request' in params && params.request ?\n\t\t\t\t{\n\t\t\t\t\thref: params.request.url,\n\t\t\t\t\treferrer: params.request.referrer,\n\t\t\t\t\ttitle: '',\n\t\t\t\t}\n\t\t\t:\t{\n\t\t\t\t\thref: location.href,\n\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\ttitle: document.title,\n\t\t\t\t};\n\n\t\ttry {\n\t\t\tconst context: AnalyticsContext = {\n\t\t\t\tlibrary: {\n\t\t\t\t\tname: 'inploi-sdk',\n\t\t\t\t\tversion: ANALYTICS_DATA_VERSION,\n\t\t\t\t},\n\t\t\t\tpage,\n\t\t\t};\n\n\t\t\tconst payload: TrackPayload = {\n\t\t\t\tanonymous_id: getAnonymousId(params.request),\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\tproperties: params.properties,\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tconst responseJson = await apiClient.fetch(LOG_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(payload),\n\t\t\t});\n\n\t\t\tconst newAnonymousId = getAnonymousIdFromResponseJson(responseJson);\n\t\t\tif (newAnonymousId) {\n\t\t\t\tpayload.anonymous_id = newAnonymousId;\n\t\t\t}\n\n\t\t\tconst newCookieValue = newAnonymousId ?? payload.anonymous_id;\n\t\t\tif (typeof window !== 'undefined' && newCookieValue) {\n\t\t\t\tdocument.cookie = formatCookie(newCookieValue);\n\t\t\t}\n\n\t\t\treturn { success: true, data: payload };\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 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 {\n\t\tlog: logFn,\n\t\tgetHeaders: payload => {\n\t\t\tconst headers = new Headers();\n\t\t\tif (!payload.anonymous_id) return headers;\n\n\t\t\theaders.append('Set-Cookie', formatCookie(payload.anonymous_id));\n\t\t\treturn headers;\n\t\t},\n\t};\n};\n","/**\n * The environment the SDK should run in.\n * - `production`: data will be stored and displayed on dashboards\n * - `sandbox`: data will be stored temporarily and purged periodically\n */\nexport type AppEnvironment = 'production' | 'sandbox';\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\n/**\n * Change to invalidate existing sessions. Useful for when data has changed.\n * It does not need to be in sync with the library version, and is not semver.\n */\nexport const ANALYTICS_DATA_VERSION = 1;\n\nexport const LOG_PATHNAME = '/analytics/log';\n\nexport const ANALYTICS_COOKIE_NAME = 'isdk_anon_id';\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\t/** Fetches from a pathname with a pre-established base path.\n\t\t * Parses received output as JSON, and throw if one of the common error messages is received.\n\t\t */\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);\n\t\t\tconst json = await response.json();\n\n\t\t\tif (typeof json === 'object' && json !== null && 'message' in json) {\n\t\t\t\tif (json.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (json.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authorised to perform this action.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn json;\n\t\t},\n\t};\n};\n","import { createAnalyticsService } from './sdk.analytics';\nimport { createApiClient } from './sdk.api';\nimport { AppEnvironment, ENV_TO_API_URL } from './sdk.constants';\nimport { Logger, inploiBrandedLogger, noLogging } from './sdk.logger';\nimport { InploiSdkPlugin } from './sdk.plugins';\n\nexport type InitialiseInploiSdkParams = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\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 passing`false`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger | false;\n};\n\nexport function initialiseSdk({ publishableKey, env, logger = inploiBrandedLogger }: InitialiseInploiSdkParams) {\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\tconst loggerService = logger === false ? noLogging : logger;\n\tconst analytics = createAnalyticsService({ apiClient, logger: loggerService });\n\n\tconst register = <P extends InploiSdkPlugin>(plugin: P): ReturnType<P> => {\n\t\treturn plugin({ logger: loggerService, apiClient, analytics });\n\t};\n\n\treturn { register, analytics };\n}\n"],"mappings":"0nBAAO,IAAMA,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAM,IAAIC,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,MAAO,IAAIA,IAAS,QAAQ,MAAMH,EAAgBC,EAAe,GAAGE,CAAI,EACxE,KAAM,IAAIA,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,IAAK,IAAIA,IAAS,QAAQ,IAAIH,EAAgBC,EAAe,GAAGE,CAAI,CACrE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECI3G,IAAMC,EAA2CC,GAAgBA,ECtBxE,OAA+B,aAAAC,MAAiB,sBCOzC,IAAMC,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,EAMaC,EAA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AAYZ,EACpB,MAAM,IAAI,MAAM,gDAAgD,EAEjE,GAAI,cAAeY,EAClB,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,EAE/C,GAAI,WAAYA,EACf,MAAM,IAAI,MAAM,oBAAeA,EAAK,OAAO,QAAG,CAEhD,CACA,OAAOA,CACR,EACD,CACD,ECrBO,SAASC,EAAc,CAAE,eAAAC,EAAgB,IAAAC,EAAK,OAAAC,EAASC,CAAoB,EAA8B,CAC/G,IAAMC,EAAYC,EAAgB,CAAE,QAASC,EAAeL,CAAG,EAAG,eAAAD,CAAe,CAAC,EAC5EO,EAAgBL,IAAW,GAAQM,EAAYN,EAC/CO,EAAYC,EAAuB,CAAE,UAAAN,EAAW,OAAQG,CAAc,CAAC,EAM7E,MAAO,CAAE,SAJoCI,GACrCA,EAAO,CAAE,OAAQJ,EAAe,UAAAH,EAAW,UAAAK,CAAU,CAAC,EAG3C,UAAAA,CAAU,CAC9B","names":["CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","args","noLogging","createPlugin","pluginFn","invariant","ENV_TO_API_URL","ANALYTICS_DATA_VERSION","LOG_PATHNAME","ANALYTICS_COOKIE_NAME","formatCookie","value","now","ANALYTICS_COOKIE_NAME","cookieRegex","getAnonymousId","request","href","searchParams","anonymousId","cookie","match","getAnonymousIdFromResponseJson","response","createAnalyticsService","apiClient","logger","params","__async","invariant","page","context","ANALYTICS_DATA_VERSION","payload","responseJson","LOG_PATHNAME","newAnonymousId","newCookieValue","e","headers","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","json","initialiseSdk","publishableKey","env","logger","inploiBrandedLogger","apiClient","createApiClient","ENV_TO_API_URL","loggerService","noLogging","analytics","createAnalyticsService","plugin"]}
|
|
1
|
+
{"version":3,"sources":["../src/sdk.logger.ts","../src/sdk.plugins.ts","../src/sdk.analytics.ts","../src/sdk.constants.ts","../src/sdk.api.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: (...args) => console.warn(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\terror: (...args) => console.error(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tinfo: (...args) => console.info(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n\tlog: (...args) => console.log(CONSOLE_PREFIX, CONSOLE_STYLE, ...args),\n};\n\nexport const noLogging: Logger = { info: () => void 0, error: () => void 0, log: () => void 0, warn: () => void 0 };\n","import { AnalyticsService } from './sdk.analytics';\nimport { ApiClient } from './sdk.api';\nimport { Logger } from './sdk.logger';\n\nexport type PluginParams = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n};\n\nexport type Plugin<T extends string, P extends Record<string, unknown>> = {\n\tpluginName: T;\n\tpure_createActions: (params: PluginParams) => P;\n};\n\ntype PluginDependencies = {\n\tapiClient: ApiClient;\n\tlogger: Logger;\n\tanalytics: AnalyticsService;\n};\n\nexport type InploiSdkPlugin = (dependencies: PluginDependencies) => any;\n\nexport const createPlugin = <T extends InploiSdkPlugin>(pluginFn: T) => pluginFn;\n","import { Flatten, ResponseObj, invariant } from '@inploi/core/common';\n\nimport { ApiClient, Logger } from '.';\nimport { ANALYTICS_COOKIE_NAME, ANALYTICS_DATA_VERSION, LOG_PATHNAME } from './sdk.constants';\n\nconst formatCookie = (value: string) => {\n\tconst now = new Date();\n\tnow.setTime(now.getTime() + 1000 * 36000);\n\n\treturn `${ANALYTICS_COOKIE_NAME}=${value};expires=${now.toUTCString()};path=/`;\n};\n\ntype AnalyticsLogParams =\n\t| {\n\t\t\tevent: 'VIEW_JOB' | 'APPLY_START' | 'APPLY_COMPLETE';\n\t\t\tproperties: {\n\t\t\t\tjob_id: string; // External job ID\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'FLOW_NODE';\n\t\t\tproperties: {\n\t\t\t\t/** Increment by 1 per node interpreted */\n\t\t\t\tsequence: number;\n\t\t\t\tfrom_node_id: string | null;\n\t\t\t\tto_node_id: string;\n\t\t\t\tjob_id: string;\n\t\t\t\tflow_id: string;\n\t\t\t\tflow_version: number;\n\t\t\t};\n\t }\n\t| {\n\t\t\tevent: 'IDENTIFY' | 'SUBMIT_FORM' | 'VIEW_PAGE';\n\t\t\tproperties?: never;\n\t };\n\nexport type AnalyticsLogEvent = AnalyticsLogParams['event'];\n\ntype EventPropertyMap = {\n\t[Param in AnalyticsLogParams as Param['event']]: Flatten<Omit<Param, 'event'>>;\n};\n\ntype AnalyticsContext = {\n\tlibrary: {\n\t\tname: 'inploi-sdk';\n\t\tversion: number;\n\t};\n\tpage: {\n\t\thref: string;\n\t\treferrer: string;\n\t\ttitle: string;\n\t};\n};\n\ntype TrackPayload<P = EventPropertyMap[keyof EventPropertyMap]['properties']> = {\n\tanonymous_id: string | null;\n\tevent: AnalyticsLogEvent;\n\tsent_at: string;\n\tcontext: AnalyticsContext;\n\tproperties: P;\n\tcustom_properties?: Record<string, unknown>;\n};\n\ntype LogFnParams<T extends keyof EventPropertyMap> = {\n\tevent: T;\n\tcustomProperties?: Record<string, unknown>;\n\t/** Passing a request will make logging possible on a server environment. */\n\trequest?: Request;\n} & EventPropertyMap[T];\n\ntype LogFn = <TEvent extends keyof EventPropertyMap>(\n\tparams: LogFnParams<TEvent>,\n) => Promise<ResponseObj<TrackPayload<EventPropertyMap[TEvent]['properties']>>>;\n\nexport type AnalyticsService = {\n\tlog: LogFn;\n\t/** From a log payload data, generate headers to use in server environments to update the anonymous_id */\n\tgetHeaders: (payload: TrackPayload) => Headers;\n};\n\nconst cookieRegex = new RegExp(`${ANALYTICS_COOKIE_NAME}=([^;]+)`);\nconst getAnonymousId = (request?: Request) => {\n\tconst href = request ? request.url : location.href;\n\t// If there’s an anonymous_id in the search params, use it\n\tconst { searchParams } = new URL(href);\n\tconst anonymousId = searchParams.get('anonymous_id');\n\tif (anonymousId) return anonymousId;\n\n\t// If there’s a cookie, use it\n\tconst cookie = request ? request.headers.get('cookie') : document.cookie;\n\tif (cookie) {\n\t\tconst match = cookieRegex.exec(cookie);\n\t\tif (match?.[1]) return match[1];\n\t}\n\n\t// Otherwise, return null\n\treturn null;\n};\n\nconst getAnonymousIdFromResponseJson = (response: unknown) => {\n\tif (typeof response !== 'object' || response === null) return null;\n\tif (!('anonymous_id' in response && typeof response.anonymous_id === 'string')) return null;\n\treturn response.anonymous_id;\n};\n\nexport const createAnalyticsService = ({\n\tapiClient,\n\tlogger,\n}: {\n\tlogger: Logger;\n\tapiClient: ApiClient;\n}): AnalyticsService => {\n\tconst logFn: LogFn = async params => {\n\t\tinvariant(\n\t\t\tparams.request || typeof window !== 'undefined',\n\t\t\t'Cannot log on the server without a request. Please pass a request to `log`.',\n\t\t);\n\n\t\t// if there’s a request, use it instead of browser APIs\n\t\tconst page =\n\t\t\t'request' in params && params.request ?\n\t\t\t\t{\n\t\t\t\t\thref: params.request.url,\n\t\t\t\t\treferrer: params.request.referrer,\n\t\t\t\t\ttitle: '',\n\t\t\t\t}\n\t\t\t:\t{\n\t\t\t\t\thref: location.href,\n\t\t\t\t\treferrer: document.referrer,\n\t\t\t\t\ttitle: document.title,\n\t\t\t\t};\n\n\t\ttry {\n\t\t\tconst context: AnalyticsContext = {\n\t\t\t\tlibrary: {\n\t\t\t\t\tname: 'inploi-sdk',\n\t\t\t\t\tversion: ANALYTICS_DATA_VERSION,\n\t\t\t\t},\n\t\t\t\tpage,\n\t\t\t};\n\n\t\t\tconst payload: TrackPayload = {\n\t\t\t\tanonymous_id: getAnonymousId(params.request),\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\tproperties: params.properties,\n\t\t\t\tcustom_properties: params.customProperties,\n\t\t\t};\n\n\t\t\tconst responseJson = await apiClient.fetch(LOG_PATHNAME, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: JSON.stringify(payload),\n\t\t\t});\n\n\t\t\tconst newAnonymousId = getAnonymousIdFromResponseJson(responseJson);\n\t\t\tif (newAnonymousId) {\n\t\t\t\tpayload.anonymous_id = newAnonymousId;\n\t\t\t}\n\n\t\t\tconst newCookieValue = newAnonymousId ?? payload.anonymous_id;\n\t\t\tif (typeof window !== 'undefined' && newCookieValue) {\n\t\t\t\tdocument.cookie = formatCookie(newCookieValue);\n\t\t\t}\n\n\t\t\treturn { success: true, data: payload };\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 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 {\n\t\tlog: logFn,\n\t\tgetHeaders: payload => {\n\t\t\tconst headers = new Headers();\n\t\t\tif (!payload.anonymous_id) return headers;\n\n\t\t\theaders.append('Set-Cookie', formatCookie(payload.anonymous_id));\n\t\t\treturn headers;\n\t\t},\n\t};\n};\n","/**\n * The environment the SDK should run in.\n * - `production`: data will be stored and displayed on dashboards\n * - `sandbox`: data will be stored temporarily and purged periodically\n */\nexport type AppEnvironment = 'production' | 'sandbox';\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\n/**\n * Change to invalidate existing sessions. Useful for when data has changed.\n * It does not need to be in sync with the library version, and is not semver.\n */\nexport const ANALYTICS_DATA_VERSION = 1;\n\nexport const LOG_PATHNAME = '/analytics/log';\n\nexport const ANALYTICS_COOKIE_NAME = 'isdk_anon_id';\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\t/** Fetches from a pathname with a pre-established base path.\n\t\t * Parses received output as JSON, and throw if one of the common error messages is received.\n\t\t */\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);\n\t\t\tconst json = await response.json();\n\n\t\t\tif (typeof json === 'object' && json !== null && 'message' in json) {\n\t\t\t\tif (json.message === unauthenticatedMessage) {\n\t\t\t\t\tthrow new Error('You are not authenticated.');\n\t\t\t\t}\n\t\t\t\tif (json.message === unauthorisedMessage) {\n\t\t\t\t\tthrow new Error('You are not authorised to perform this action.');\n\t\t\t\t}\n\t\t\t\tif ('exception' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t\tif ('errors' in json) {\n\t\t\t\t\tthrow new Error(`API error: “${json.message}”`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn json;\n\t\t},\n\t};\n};\n","import { createAnalyticsService } from './sdk.analytics';\nimport { createApiClient } from './sdk.api';\nimport { AppEnvironment, ENV_TO_API_URL } from './sdk.constants';\nimport { Logger, inploiBrandedLogger, noLogging } from './sdk.logger';\nimport { InploiSdkPlugin } from './sdk.plugins';\n\nexport type InitialiseInploiSdkParams = {\n\t/** Your public API key for the inploi SDK. */\n\tpublishableKey: string;\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 passing`false`.\n\t * @default inploiBrandedLogger\n\t * */\n\tlogger?: Logger | false;\n};\n\nexport function initialiseSdk({ publishableKey, env, logger = inploiBrandedLogger }: InitialiseInploiSdkParams) {\n\tconst apiClient = createApiClient({ baseUrl: ENV_TO_API_URL[env], publishableKey });\n\tconst loggerService = logger === false ? noLogging : logger;\n\tconst analytics = createAnalyticsService({ apiClient, logger: loggerService });\n\n\tconst register = <P extends InploiSdkPlugin>(plugin: P): ReturnType<P> => {\n\t\treturn plugin({ logger: loggerService, apiClient, analytics });\n\t};\n\n\treturn { register, analytics };\n}\n"],"mappings":"0nBAAO,IAAMA,EAAiB,iBACjBC,EAAgB,qCAUhBC,EAA8B,CAC1C,KAAM,IAAIC,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,MAAO,IAAIA,IAAS,QAAQ,MAAMH,EAAgBC,EAAe,GAAGE,CAAI,EACxE,KAAM,IAAIA,IAAS,QAAQ,KAAKH,EAAgBC,EAAe,GAAGE,CAAI,EACtE,IAAK,IAAIA,IAAS,QAAQ,IAAIH,EAAgBC,EAAe,GAAGE,CAAI,CACrE,EAEaC,EAAoB,CAAE,KAAM,IAAG,GAAW,MAAO,IAAG,GAAW,IAAK,IAAG,GAAW,KAAM,IAAG,EAAU,ECI3G,IAAMC,EAA2CC,GAAgBA,ECtBxE,OAA+B,aAAAC,MAAiB,sBCOzC,IAAMC,EAAiD,CAC7D,QAAS,iCACT,WAAY,wBACb,EAMaC,EAAyB,EAEzBC,EAAe,iBAEfC,EAAwB,eDfrC,IAAMC,EAAgBC,GAAkB,CACvC,IAAMC,EAAM,IAAI,KAChB,OAAAA,EAAI,QAAQA,EAAI,QAAQ,EAAI,IAAO,IAAK,EAEjC,GAAGC,CAAqB,IAAIF,CAAK,YAAYC,EAAI,YAAY,CAAC,SACtE,EAsEME,EAAc,IAAI,OAAO,GAAGD,CAAqB,UAAU,EAC3DE,EAAkBC,GAAsB,CAC7C,IAAMC,EAAOD,EAAUA,EAAQ,IAAM,SAAS,KAExC,CAAE,aAAAE,CAAa,EA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AD,CAAe,CAAC,EAC5EO,EAAgBL,IAAW,GAAQM,EAAYN,EAC/CO,EAAYC,EAAuB,CAAE,UAAAN,EAAW,OAAQG,CAAc,CAAC,EAM7E,MAAO,CAAE,SAJoCI,GACrCA,EAAO,CAAE,OAAQJ,EAAe,UAAAH,EAAW,UAAAK,CAAU,CAAC,EAG3C,UAAAA,CAAU,CAC9B","names":["CONSOLE_PREFIX","CONSOLE_STYLE","inploiBrandedLogger","args","noLogging","createPlugin","pluginFn","invariant","ENV_TO_API_URL","ANALYTICS_DATA_VERSION","LOG_PATHNAME","ANALYTICS_COOKIE_NAME","formatCookie","value","now","ANALYTICS_COOKIE_NAME","cookieRegex","getAnonymousId","request","href","searchParams","anonymousId","cookie","match","getAnonymousIdFromResponseJson","response","createAnalyticsService","apiClient","logger","params","__async","invariant","page","context","ANALYTICS_DATA_VERSION","payload","responseJson","LOG_PATHNAME","newAnonymousId","newCookieValue","e","headers","unauthenticatedMessage","unauthorisedMessage","createApiClient","params","defaultHeaders","_0","_1","__async","pathname","options","init","__spreadProps","__spreadValues","json","initialiseSdk","publishableKey","env","logger","inploiBrandedLogger","apiClient","createApiClient","ENV_TO_API_URL","loggerService","noLogging","analytics","createAnalyticsService","plugin"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inploi/sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@inploi/core": "1.6.
|
|
19
|
+
"@inploi/core": "1.6.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@happy-dom/global-registrator": "^12.6.0",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"ts-toolbelt": "^9.6.0",
|
|
30
30
|
"tsup": "^7.2.0",
|
|
31
31
|
"typescript": "^5.3.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"eslint-config-custom": "0.1.0",
|
|
33
|
+
"tsconfig": "0.1.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build:npm": "tsup --dts --dts-resolve",
|