@openpartner/sdk 0.1.0 → 0.2.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/README.md +91 -4
- package/dist/browser.cjs +98 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +62 -3
- package/dist/browser.d.ts +62 -3
- package/dist/browser.js +98 -0
- package/dist/browser.js.map +1 -1
- package/dist/server.cjs +10 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +57 -8
- package/dist/server.d.ts +57 -8
- package/dist/server.js +10 -0
- package/dist/server.js.map +1 -1
- package/dist/{shared-CLfBjPeb.d.cts → shared-dh1vlldf.d.cts} +19 -4
- package/dist/{shared-CLfBjPeb.d.ts → shared-dh1vlldf.d.ts} +19 -4
- package/dist-global/openpartner.js +1 -0
- package/package.json +36 -15
- package/LICENSE +0 -21
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var R=Object.defineProperty,v=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var m=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var g=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,f=(r,e)=>{for(var t in e||(e={}))C.call(e,t)&&g(r,t,e[t]);if(m)for(var t of m(e))I.call(e,t)&&g(r,t,e[t]);return r},h=(r,e)=>v(r,E(e));var l=(r,e,t)=>g(r,typeof e!="symbol"?e+"":e,t);var p=class extends Error{constructor(t,n,i,s){super(t);l(this,"status",n);l(this,"code",i);l(this,"detail",s);this.name="OpenPartnerError"}};async function y(r,e={},t=globalThis.fetch){var a,c;let n=new Headers(e.headers);e.body!==void 0&&!n.has("content-type")&&n.set("content-type","application/json");let i=await t(r,h(f({},e),{headers:n,body:e.body===void 0?void 0:typeof e.body=="string"?e.body:JSON.stringify(e.body)})),s=await i.text(),o;if(s)try{o=JSON.parse(s)}catch(u){o=s}if(!i.ok){let u=o!=null?o:{};throw new p((a=u.error)!=null?a:`${i.status} ${i.statusText}`,i.status,u.error,(c=u.detail)!=null?c:o)}return o}var P={cookieName:"_cref",queryParam:"cref",storageKey:"openpartner:cref",stripe:!0,referralCookie:!1,onError:r=>{console.warn("[openpartner] identify failed",r)}},b=/^[A-Za-z0-9_-]{1,200}$/,k="stripe-pricing-table, stripe-buy-button",d=class r{constructor(e){l(this,"config");l(this,"observer",null);this.config=f(f({},P),e),this.captureCref(),this.writeReferralCookie(),this.config.stripe!==!1&&this.watchStripe()}static init(e){return new r(e)}getCref(){return typeof localStorage=="undefined"?null:localStorage.getItem(this.config.storageKey)}getReferral(){return this.getCref()}clear(){typeof localStorage!="undefined"&&localStorage.removeItem(this.config.storageKey)}linkStripe(e=document){let t=this.getReferral();if(!t||!b.test(t)||typeof document=="undefined")return 0;let n=new Set(["buy.stripe.com",...this.stripeLinkHosts()]),i=0,s=[];e instanceof HTMLAnchorElement&&s.push(e),s.push(...Array.from(e.querySelectorAll("a[href]")));for(let a of s){let c;try{c=new URL(a.href)}catch(u){continue}!n.has(c.hostname.toLowerCase())||c.searchParams.has("client_reference_id")||(c.searchParams.set("client_reference_id",t),a.href=c.toString(),i+=1)}let o=[];e instanceof Element&&e.matches(k)&&o.push(e),o.push(...Array.from(e.querySelectorAll(k)));for(let a of o)a.hasAttribute("client-reference-id")||(a.setAttribute("client-reference-id",t),i+=1);return i}stopLinkingStripe(){var e;(e=this.observer)==null||e.disconnect(),this.observer=null}stripeLinkHosts(){let e=this.config.stripe;return typeof e=="object"&&e.linkHosts?e.linkHosts.map(t=>t.trim().toLowerCase()).filter(Boolean):[]}watchStripe(){typeof document=="undefined"||!this.getReferral()||(this.linkStripe(document),typeof MutationObserver!="undefined"&&(this.observer=new MutationObserver(e=>{for(let t of e){if(t.type==="attributes"){t.target instanceof HTMLAnchorElement&&this.linkStripe(t.target);continue}for(let n of Array.from(t.addedNodes))n instanceof Element&&this.linkStripe(n)}}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]})))}captureCref(){if(typeof window=="undefined"||typeof localStorage=="undefined")return;let t=new URL(window.location.href).searchParams.get(this.config.queryParam);if(t){localStorage.setItem(this.config.storageKey,t);return}let n=this.readCookie(this.config.cookieName);n&&!localStorage.getItem(this.config.storageKey)&&localStorage.setItem(this.config.storageKey,n)}writeReferralCookie(){var a,c;let e=this.config.referralCookie;if(!e||typeof document=="undefined")return;let t=this.getReferral();if(!t||!b.test(t))return;let n=(a=e.name)!=null?a:"op_ref",i=Math.round(((c=e.days)!=null?c:90)*86400),s=typeof location!="undefined"&&location.protocol==="https:"?"; Secure":"",o=e.domain?`; Domain=${e.domain}`:"";document.cookie=`${n}=${encodeURIComponent(t)}; Max-Age=${i}; Path=/; SameSite=Lax${o}${s}`}readCookie(e){if(typeof document=="undefined")return null;let t=document.cookie.match(new RegExp(`(^|; )${e}=([^;]+)`));return t?decodeURIComponent(t[2]):null}async identify(e){let t=this.getCref();if(!t)return null;try{return await y(`${this.config.apiUrl}/attribution/identify`,{method:"POST",body:{cref:t,userId:e,ts:Date.now()},keepalive:!0})}catch(n){return this.config.onError(n),null}}};function x(r){var i,s;let e=r.dataset,t=((i=e.apiUrl)!=null?i:"").trim();if(!t)try{t=`${new URL(r.src).origin}/api`}catch(o){t="/api"}let n=((s=e.stripeHosts)!=null?s:"").split(",").map(o=>o.trim()).filter(Boolean);return{apiUrl:t.replace(/\/$/,""),stripe:e.stripe==="off"?!1:{linkHosts:n},referralCookie:e.cookie==="off"?!1:f({name:"op_ref"},e.cookieDomain?{domain:e.cookieDomain}:{})}}var w,S;if(typeof window!="undefined"&&typeof document!="undefined"&&!window.openpartner){let r=document.currentScript;window.OpenPartner=d,window.openpartner=d.init(x({src:(w=r==null?void 0:r.src)!=null?w:window.location.href,dataset:f({},(S=r==null?void 0:r.dataset)!=null?S:{})}))}})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpartner/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "OpenPartner SDK. Browser client for click → identity stitching + Node server SDK for conversion events and attribution reads.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/browser.cjs",
|
|
@@ -8,18 +8,36 @@
|
|
|
8
8
|
"types": "./dist/browser.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/browser.d.ts",
|
|
13
|
+
"default": "./dist/browser.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/browser.d.cts",
|
|
17
|
+
"default": "./dist/browser.cjs"
|
|
18
|
+
}
|
|
14
19
|
},
|
|
15
20
|
"./server": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/server.d.ts",
|
|
23
|
+
"default": "./dist/server.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/server.d.cts",
|
|
27
|
+
"default": "./dist/server.cjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
"server": [
|
|
34
|
+
"./dist/server.d.ts"
|
|
35
|
+
]
|
|
19
36
|
}
|
|
20
37
|
},
|
|
21
38
|
"files": [
|
|
22
39
|
"dist",
|
|
40
|
+
"dist-global",
|
|
23
41
|
"README.md"
|
|
24
42
|
],
|
|
25
43
|
"publishConfig": {
|
|
@@ -41,16 +59,19 @@
|
|
|
41
59
|
},
|
|
42
60
|
"license": "MIT",
|
|
43
61
|
"sideEffects": false,
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"jsdom": "^29.0.2",
|
|
46
|
-
"tsup": "^8.5.1",
|
|
47
|
-
"typescript": "5.4.5",
|
|
48
|
-
"vitest": "^1.6.0"
|
|
49
|
-
},
|
|
50
62
|
"scripts": {
|
|
51
63
|
"build": "tsup",
|
|
64
|
+
"build:global": "tsup --config tsup.global.config.ts",
|
|
52
65
|
"dev": "tsup --watch",
|
|
53
66
|
"lint": "tsc --noEmit",
|
|
54
67
|
"test": "vitest run --passWithNoTests"
|
|
55
|
-
}
|
|
56
|
-
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"jsdom": "^29.0.2",
|
|
71
|
+
"tsup": "^9.0.0",
|
|
72
|
+
"typescript": "6.0.3",
|
|
73
|
+
"vitest": "^4.1.12"
|
|
74
|
+
},
|
|
75
|
+
"unpkg": "./dist-global/openpartner.js",
|
|
76
|
+
"jsdelivr": "./dist-global/openpartner.js"
|
|
77
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 OpenPartner contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|