deeplinkit 0.2.0 → 0.2.1
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/README.md +9 -20
- package/index.d.ts +2 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
# deeplinkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Capture browser signals and attach a JSON payload to a visit on your website.
|
|
4
4
|
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const client = new Deeplinkit({ applicationId: 'app_example' });
|
|
9
|
-
const link = await client.createLink({ payload: { screen: 'product', id: '123' } });
|
|
5
|
+
```sh
|
|
6
|
+
npm install deeplinkit
|
|
10
7
|
```
|
|
11
8
|
|
|
12
|
-
Or load directly from the collector:
|
|
13
|
-
|
|
14
9
|
```js
|
|
15
|
-
|
|
16
|
-
const client = start();
|
|
17
|
-
const link = await client.createLink({ payload: { screen: 'product', id: '123' } });
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
`createLink` records the visitor’s payload and returns `{ id }`. Keep visitors on your own website, then open your app or redirect to its store listing after the call completes. The collector is an SDK backend and does not provide public landing URLs.
|
|
21
|
-
|
|
22
|
-
Both use an app-specific loader that selects the collector build at request time. The loader is uncached; selected assets have immutable content-addressed URLs. npm contains only the loader, so collector updates do not require an npm upgrade. Configure CSP to allow the collector origin in `script-src` and `connect-src`.
|
|
23
|
-
|
|
24
|
-
For development or a custom collector domain, set `url` to that collector's HTTPS origin. This URL is the collector origin, not the native session API. The application ID is public; no server API key is required. Observations are encrypted with the collector's public key. Failed link submissions are not retried automatically.
|
|
10
|
+
import { Deeplinkit } from 'deeplinkit';
|
|
25
11
|
|
|
26
|
-
|
|
12
|
+
const deeplinkit = new Deeplinkit({ applicationId: 'your_app_id' });
|
|
27
13
|
|
|
28
|
-
|
|
14
|
+
await deeplinkit.linkVisit({
|
|
15
|
+
payload: { productId: '123' },
|
|
16
|
+
});
|
|
17
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export interface DeepLink { id: string; }
|
|
|
3
3
|
/** Run in the visitor's browser. No server API key is required. */
|
|
4
4
|
export class Deeplinkit {
|
|
5
5
|
constructor(options: { /** Collector origin override. Defaults to https://collector.deeplinkit.com. */ url?: string; applicationId: string; /** Network timeout in milliseconds; defaults to 10000. */ timeout?: number });
|
|
6
|
-
|
|
6
|
+
linkVisit(options: { payload: { [key: string]: JSONValue } }): Promise<DeepLink>;
|
|
7
|
+
createLink: Deeplinkit["linkVisit"];
|
|
7
8
|
}
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function y(o){let
|
|
1
|
+
function y(o){let e=new Set;function r(t,c=0){if(c>6)throw new TypeError("Payload must be no more than 6 levels deep");if(t===null||typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t))return;if(!t||typeof t!="object"||e.has(t))throw new TypeError("Payload must contain only JSON values");let i=Array.isArray(t),l=Object.getPrototypeOf(t);if(!i&&l!==Object.prototype&&l!==null)throw new TypeError("Payload must contain only plain JSON objects");let s=Reflect.ownKeys(t).filter(a=>!(i&&a==="length"));if(s.some((a,p)=>typeof a!="string"||i&&a!==String(p))||(i?s.length!==t.length||t.length>128:s.length>64))throw new TypeError("Payload has too many properties or invalid JSON values");e.add(t);for(let a of s){let p=Object.getOwnPropertyDescriptor(t,a);if(!p.enumerable||!Object.hasOwn(p,"value"))throw new TypeError("Payload must contain only JSON values");r(p.value,c+1)}e.delete(t)}if(!o||typeof o!="object"||Array.isArray(o))throw new TypeError("Payload must be a JSON object");r(o);let n=JSON.stringify(o);if(n.length>8192)throw new TypeError("Payload exceeds 8192 characters");return n}function w(o){let e;try{e=new URL(o)}catch{throw new TypeError("A valid HTTPS API URL is required")}if(e.protocol!=="https:"||e.username||e.password||e.search||e.hash||e.pathname!=="/")throw new TypeError("An HTTPS origin is required");return e.origin}function h({url:o="https://collector.deeplinkit.com",applicationId:e,timeout:r=1e4}={}){let n=w(o);if(typeof e!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(e))throw new TypeError("A valid applicationId is required");if(!Number.isInteger(r)||r<1||r>6e4)throw new TypeError("Timeout must be between 1 and 60000 milliseconds");return{url:n,applicationId:e,timeout:r}}function d(o=e=>import(e)){return class{#t;#e;constructor(r){this.#t=h(r)}#r(){return this.#e??=(async()=>{let{url:r,applicationId:n,timeout:t}=this.#t,c;try{let i=await Promise.race([o(`${r}/v1/agent/${n}`),new Promise((l,s)=>{c=setTimeout(()=>s(Object.assign(new Error("Collector loading timed out."),{code:"request_timeout"})),t)})]);return new i.Deeplinkit({timeout:t})}finally{clearTimeout(c)}})().catch(r=>{throw this.#e=void 0,r})}createLink(r){return this.linkVisit(r)}async linkVisit({payload:r}={}){let n=JSON.parse(y(r));if(Object.hasOwn(n,"app")&&n.app!==this.#t.applicationId)throw new TypeError("Payload app must match applicationId");y({...n,app:this.#t.applicationId});let t=await this.#r();return(t.linkVisit??t.createLink).call(t,{payload:n})}}}var g=d();export{g as Deeplinkit,d as createLoader};
|