ylembed-js 1.0.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/LICENSE +15 -0
- package/README.md +57 -0
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +64 -0
- package/index.d.ts +64 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, YouLend
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# YouLend Embedded Components SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript/JavaScript SDK for embedding YouLend's application journey into your web application.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
This NPM package provides TypeScript support and dynamically loads the YlEmbed.js script from YouLend's CDN.
|
|
8
|
+
|
|
9
|
+
If you prefer, you can also load the SDK script directly from our CDN via a script tag. The script is hosted at https://sdk.youlend.com/v1/ylembed.js.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
For more detailed examples and docs, visit the [embedded components docs](https://docs.youlend.com/docs/embed-the-application-journey).
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { loadYlEmbed, YlEmbedOptions, ApplicationJourney } from '@youlend/yl-embed-sdk';
|
|
17
|
+
|
|
18
|
+
const options: YlEmbedOptions = {
|
|
19
|
+
partnerName: 'your-partner-name',
|
|
20
|
+
country: 'GB', // 'US' | 'GB' | 'DE' | 'FR' | 'PL' | 'NL' | 'BE' | 'ES' | 'IE'
|
|
21
|
+
environment: 'sandbox', // 'production' | 'sandbox'
|
|
22
|
+
thirdPartyCustomerId: 'your-unique-id-for-the-logged-in-user',
|
|
23
|
+
createEmbedToken: async () => { // Create embed token for the logged in merchant
|
|
24
|
+
const response = await fetch('/yourapi/yl-embed-token', { method: 'POST' });
|
|
25
|
+
const { accessToken } = await response.json();
|
|
26
|
+
return accessToken;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const ylEmbed = await loadYlEmbed(options);
|
|
31
|
+
const journey: ApplicationJourney = ylEmbed.create('ApplicationJourney');
|
|
32
|
+
journey.open();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Available Types:** `YlEmbedOptions`, `ApplicationJourneyOptions`, `ApplicationJourney`, `YlEmbed`
|
|
36
|
+
|
|
37
|
+
## Versioning
|
|
38
|
+
|
|
39
|
+
Each major version of the NPM package loads a specific version of the CDN-hosted script. For example, NPM package version `1.x.y` loads `https://sdk.youlend.com/v1/ylembed.js`.
|
|
40
|
+
|
|
41
|
+
Because all minor and patch updates (e.g., `1.0.0` → `1.2.5`) use the same CDN script version, you can safely bump versions to get wrapper or TypeScript improvements without any breaking changes to the embed experience.
|
|
42
|
+
|
|
43
|
+
## Content Security Policy
|
|
44
|
+
If you implement a CSP, please ensure you allow the following:
|
|
45
|
+
- Scripts (script-src) from https://sdk.youlend.com
|
|
46
|
+
- Iframes (frame-src):
|
|
47
|
+
- Production: https://youlend.com (and/or https://youlend.us if supporting USA)
|
|
48
|
+
- Sandbox: https://partners.staging-youlend.com (and/or https://uspartners.staging-youlend.com if supporting USA)
|
|
49
|
+
|
|
50
|
+
## Documentation
|
|
51
|
+
|
|
52
|
+
📖 **[Full Documentation](https://docs.youlend.com/docs/embedded-components)**
|
|
53
|
+
🔧 **[API Reference](https://docs.youlend.com/reference)**
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
ISC © YouLend
|
package/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var u=(n,e)=>{for(var o in e)l(n,o,{get:e[o],enumerable:!0})},p=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!a.call(n,r)&&r!==o&&l(n,r,{get:()=>e[r],enumerable:!(t=c(e,r))||t.enumerable});return n};var y=n=>p(l({},"__esModule",{value:!0}),n);var g={};u(g,{__resetYlEmbedPromiseForTest:()=>E,loadYlEmbed:()=>f});module.exports=y(g);var s="/v1/ylembed.js";var i=()=>`https://sdk.youlend.com${s}`,b=n=>{if(!n)return i();let e=n.replace(/^https?:\/\//,"");if(e.endsWith(".dev-youlend.com"))return`https://${e.replace(".dev-youlend.com","")}-sdk.dev-youlend.com${s}`;if(e==="staging.youlend.com")return`https://origin-sdk.staging-youlend.com${s}`;if(e==="partners.staging-youlend.com")return`https://partners-sdk.staging-youlend.com${s}`;if(e==="uspartners.staging-youlend.com")return`https://uspartners-sdk.staging-youlend.com${s}`;if(e==="youlend.com"||e==="youlend.us")return i();let o=i();return console.error(`Invalid URL override: ${n} - falling back to script src = ${o}`),o},d=null,f=n=>d||(d=new Promise((e,o)=>{if(typeof window>"u"){let r={open:()=>{},close:()=>{}};e({create:(w,Y)=>r});return}if(window.YlEmbed){e(new window.YlEmbed(n));return}let t=document.createElement("script");t.src=b(n.urlOverride),t.async=!0,t.onload=()=>{window.YlEmbed?e(new window.YlEmbed(n)):o(new Error("YlEmbed script loaded but window.YlEmbed is not available"))},t.onerror=()=>{o(new Error("Failed to load YlEmbed script from "+t.src))},document.head.appendChild(t)}),d),E=()=>{d=null};0&&(module.exports={__resetYlEmbedPromiseForTest,loadYlEmbed});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/generated-constants.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { YlEmbedOptions, YlEmbed, ApplicationJourney } from './types';\r\nimport { CDN_SCRIPT_PATH } from './generated-constants';\r\n\r\nexport * from './types';\r\n\r\nconst getDefaultSdkUrl = () => `https://sdk.youlend.com${CDN_SCRIPT_PATH}`;\r\n\r\nconst constructScriptUrl = (urlOverride?: string): string => {\r\n if (!urlOverride) {\r\n return getDefaultSdkUrl();\r\n }\r\n\r\n const cleanUrl = urlOverride.replace(/^https?:\\/\\//, '');\r\n\r\n if (cleanUrl.endsWith('.dev-youlend.com')) {\r\n const subdomain = cleanUrl.replace('.dev-youlend.com', '');\r\n return `https://${subdomain}-sdk.dev-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'staging.youlend.com') {\r\n return `https://origin-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'partners.staging-youlend.com') {\r\n return `https://partners-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'uspartners.staging-youlend.com') {\r\n return `https://uspartners-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'youlend.com' || cleanUrl === 'youlend.us') {\r\n // youlend.com or youlend.us -> sdk.youlend.com + dynamic CDN path\r\n return getDefaultSdkUrl();\r\n }\r\n\r\n const defaultUrl = getDefaultSdkUrl();\r\n console.error(`Invalid URL override: ${urlOverride} - falling back to script src = ${defaultUrl}`);\r\n return defaultUrl;\r\n};\r\n\r\n// Keep a reference to the loaded YlEmbed class\r\nlet ylEmbedPromise: Promise<YlEmbed> | null = null;\r\n\r\n/**\r\n * The main entry point for the YlEmbed SDK.\r\n * This function handles loading the YlEmbed script from the CDN and initializing it.\r\n * It's designed to be called once per page load.\r\n *\r\n * @returns A Promise that resolves with the YlEmbed class.\r\n *\r\n * @example\r\n * ```\r\n * import { loadYlEmbed } from '@youlend/yl-embed-sdk';\r\n *\r\n * const ylEmbed = await loadYlEmbed({ ... });\r\n * ylEmbed.create({ ... });\r\n * ```\r\n */\r\nexport const loadYlEmbed = (options: YlEmbedOptions): Promise<YlEmbed> => {\r\n if (ylEmbedPromise) {\r\n return ylEmbedPromise;\r\n }\r\n ylEmbedPromise = new Promise((resolve, reject) => {\r\n if (typeof window === 'undefined') {\r\n // Return a mock for server-side rendering\r\n const mockApplicationJourney: ApplicationJourney = {\r\n open: () => { },\r\n close: () => { },\r\n };\r\n\r\n resolve({\r\n create: (componentName: 'ApplicationJourney', options?) => mockApplicationJourney,\r\n });\r\n return;\r\n }\r\n if ((window as any).YlEmbed) {\r\n resolve(new (window as any).YlEmbed(options));\r\n return;\r\n }\r\n\r\n const script = document.createElement('script');\r\n script.src = constructScriptUrl(options.urlOverride);\r\n script.async = true;\r\n script.onload = () => {\r\n if ((window as any).YlEmbed) {\r\n resolve(new (window as any).YlEmbed(options));\r\n } else {\r\n reject(new Error('YlEmbed script loaded but window.YlEmbed is not available'));\r\n }\r\n };\r\n script.onerror = () => {\r\n reject(new Error('Failed to load YlEmbed script from ' + script.src));\r\n };\r\n document.head.appendChild(script);\r\n });\r\n\r\n return ylEmbedPromise;\r\n};\r\n\r\n/**\r\n * @internal\r\n * This is an internal helper for testing purposes only and should not be used by consumers of the SDK.\r\n */\r\nexport const __resetYlEmbedPromiseForTest = () => {\r\n ylEmbedPromise = null;\r\n};\r\n","// This file is auto-generated. Do not edit manually.\n// Generated at: 2025-10-07T16:44:36.928Z\n// Source: tsup.config.ts CDN entry configuration\n\n/**\n * The CDN path for the SDK script, automatically extracted from tsup.config.ts\n * This ensures the URL stays in sync with the actual build output.\n */\nexport const CDN_SCRIPT_PATH = '/v1/ylembed.js';\n\n/**\n * All available CDN paths (in case multiple entries are configured)\n */\nexport const ALL_CDN_PATHS = [\n '/v1/ylembed.js'\n];\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,gBAAAC,IAAA,eAAAC,EAAAJ,GCQO,IAAMK,EAAkB,iBDF/B,IAAMC,EAAmB,IAAM,0BAA0BC,CAAe,GAElEC,EAAsBC,GAAiC,CAC3D,GAAI,CAACA,EACH,OAAOH,EAAiB,EAG1B,IAAMI,EAAWD,EAAY,QAAQ,eAAgB,EAAE,EAEvD,GAAIC,EAAS,SAAS,kBAAkB,EAEtC,MAAO,WADWA,EAAS,QAAQ,mBAAoB,EAAE,CAC9B,uBAAuBH,CAAe,GAGnE,GAAIG,IAAa,sBACf,MAAO,yCAAyCH,CAAe,GAGjE,GAAIG,IAAa,+BACf,MAAO,2CAA2CH,CAAe,GAGnE,GAAIG,IAAa,iCACf,MAAO,6CAA6CH,CAAe,GAGrE,GAAIG,IAAa,eAAiBA,IAAa,aAE7C,OAAOJ,EAAiB,EAG1B,IAAMK,EAAaL,EAAiB,EACpC,eAAQ,MAAM,yBAAyBG,CAAW,mCAAmCE,CAAU,EAAE,EAC1FA,CACT,EAGIC,EAA0C,KAiBjCC,EAAeC,GACtBF,IAGJA,EAAiB,IAAI,QAAQ,CAACG,EAASC,IAAW,CAChD,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAA6C,CACjD,KAAM,IAAM,CAAE,EACd,MAAO,IAAM,CAAE,CACjB,EAEAF,EAAQ,CACN,OAAQ,CAACG,EAAqCJ,IAAaG,CAC7D,CAAC,EACD,MACF,CACA,GAAK,OAAe,QAAS,CAC3BF,EAAQ,IAAK,OAAe,QAAQD,CAAO,CAAC,EAC5C,MACF,CAEA,IAAMK,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAMX,EAAmBM,EAAQ,WAAW,EACnDK,EAAO,MAAQ,GACfA,EAAO,OAAS,IAAM,CACf,OAAe,QAClBJ,EAAQ,IAAK,OAAe,QAAQD,CAAO,CAAC,EAE5CE,EAAO,IAAI,MAAM,2DAA2D,CAAC,CAEjF,EACAG,EAAO,QAAU,IAAM,CACrBH,EAAO,IAAI,MAAM,sCAAwCG,EAAO,GAAG,CAAC,CACtE,EACA,SAAS,KAAK,YAAYA,CAAM,CAClC,CAAC,EAEMP,GAOIQ,EAA+B,IAAM,CAChDR,EAAiB,IACnB","names":["index_exports","__export","__resetYlEmbedPromiseForTest","loadYlEmbed","__toCommonJS","CDN_SCRIPT_PATH","getDefaultSdkUrl","CDN_SCRIPT_PATH","constructScriptUrl","urlOverride","cleanUrl","defaultUrl","ylEmbedPromise","loadYlEmbed","options","resolve","reject","mockApplicationJourney","componentName","script","__resetYlEmbedPromiseForTest"]}
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
interface YlEmbedOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Your partner name is the path segment used in our hosted journeys (/apply/{partnerName}/signup). Contact us if you don't know your partnerName.
|
|
4
|
+
*/
|
|
5
|
+
partnerName: string;
|
|
6
|
+
/**
|
|
7
|
+
* Function that calls an endpoint on your server to generate an embed token via YouLend's API https://docs.youlend.com/reference/post_embed-token.
|
|
8
|
+
*/
|
|
9
|
+
createEmbedToken: () => Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* The ISO 3166-1 alpha-2 code country of the logged-in merchant.
|
|
12
|
+
*/
|
|
13
|
+
country: 'US' | 'GB' | 'DE' | 'FR' | 'PL' | 'NL' | 'BE' | 'ES' | 'IE';
|
|
14
|
+
/**
|
|
15
|
+
* The environment to use for the embed.
|
|
16
|
+
*/
|
|
17
|
+
environment: 'production' | 'sandbox';
|
|
18
|
+
/**
|
|
19
|
+
* Your unique identifier for the logged-in merchant. The same ID you will use on your server when generating the embed token.
|
|
20
|
+
*/
|
|
21
|
+
thirdPartyCustomerId: string;
|
|
22
|
+
/**
|
|
23
|
+
* The URL to override the iframe origin. Used only in specific beta testing scenarios and for internal YouLend testing.
|
|
24
|
+
*/
|
|
25
|
+
urlOverride?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ApplicationJourneyOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Callback invoked when an application is successfully submitted.
|
|
30
|
+
* @param leadId - YouLend's unique identifier for the funding application
|
|
31
|
+
*/
|
|
32
|
+
onApplicationSubmitted?: (leadId: string) => void;
|
|
33
|
+
}
|
|
34
|
+
interface ApplicationJourney {
|
|
35
|
+
open: () => void;
|
|
36
|
+
close: () => void;
|
|
37
|
+
}
|
|
38
|
+
interface YlEmbed {
|
|
39
|
+
create(componentName: 'ApplicationJourney', options?: ApplicationJourneyOptions): ApplicationJourney;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The main entry point for the YlEmbed SDK.
|
|
44
|
+
* This function handles loading the YlEmbed script from the CDN and initializing it.
|
|
45
|
+
* It's designed to be called once per page load.
|
|
46
|
+
*
|
|
47
|
+
* @returns A Promise that resolves with the YlEmbed class.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```
|
|
51
|
+
* import { loadYlEmbed } from '@youlend/yl-embed-sdk';
|
|
52
|
+
*
|
|
53
|
+
* const ylEmbed = await loadYlEmbed({ ... });
|
|
54
|
+
* ylEmbed.create({ ... });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const loadYlEmbed: (options: YlEmbedOptions) => Promise<YlEmbed>;
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
* This is an internal helper for testing purposes only and should not be used by consumers of the SDK.
|
|
61
|
+
*/
|
|
62
|
+
declare const __resetYlEmbedPromiseForTest: () => void;
|
|
63
|
+
|
|
64
|
+
export { type ApplicationJourney, type ApplicationJourneyOptions, type YlEmbed, type YlEmbedOptions, __resetYlEmbedPromiseForTest, loadYlEmbed };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
interface YlEmbedOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Your partner name is the path segment used in our hosted journeys (/apply/{partnerName}/signup). Contact us if you don't know your partnerName.
|
|
4
|
+
*/
|
|
5
|
+
partnerName: string;
|
|
6
|
+
/**
|
|
7
|
+
* Function that calls an endpoint on your server to generate an embed token via YouLend's API https://docs.youlend.com/reference/post_embed-token.
|
|
8
|
+
*/
|
|
9
|
+
createEmbedToken: () => Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* The ISO 3166-1 alpha-2 code country of the logged-in merchant.
|
|
12
|
+
*/
|
|
13
|
+
country: 'US' | 'GB' | 'DE' | 'FR' | 'PL' | 'NL' | 'BE' | 'ES' | 'IE';
|
|
14
|
+
/**
|
|
15
|
+
* The environment to use for the embed.
|
|
16
|
+
*/
|
|
17
|
+
environment: 'production' | 'sandbox';
|
|
18
|
+
/**
|
|
19
|
+
* Your unique identifier for the logged-in merchant. The same ID you will use on your server when generating the embed token.
|
|
20
|
+
*/
|
|
21
|
+
thirdPartyCustomerId: string;
|
|
22
|
+
/**
|
|
23
|
+
* The URL to override the iframe origin. Used only in specific beta testing scenarios and for internal YouLend testing.
|
|
24
|
+
*/
|
|
25
|
+
urlOverride?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ApplicationJourneyOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Callback invoked when an application is successfully submitted.
|
|
30
|
+
* @param leadId - YouLend's unique identifier for the funding application
|
|
31
|
+
*/
|
|
32
|
+
onApplicationSubmitted?: (leadId: string) => void;
|
|
33
|
+
}
|
|
34
|
+
interface ApplicationJourney {
|
|
35
|
+
open: () => void;
|
|
36
|
+
close: () => void;
|
|
37
|
+
}
|
|
38
|
+
interface YlEmbed {
|
|
39
|
+
create(componentName: 'ApplicationJourney', options?: ApplicationJourneyOptions): ApplicationJourney;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The main entry point for the YlEmbed SDK.
|
|
44
|
+
* This function handles loading the YlEmbed script from the CDN and initializing it.
|
|
45
|
+
* It's designed to be called once per page load.
|
|
46
|
+
*
|
|
47
|
+
* @returns A Promise that resolves with the YlEmbed class.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```
|
|
51
|
+
* import { loadYlEmbed } from '@youlend/yl-embed-sdk';
|
|
52
|
+
*
|
|
53
|
+
* const ylEmbed = await loadYlEmbed({ ... });
|
|
54
|
+
* ylEmbed.create({ ... });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const loadYlEmbed: (options: YlEmbedOptions) => Promise<YlEmbed>;
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
* This is an internal helper for testing purposes only and should not be used by consumers of the SDK.
|
|
61
|
+
*/
|
|
62
|
+
declare const __resetYlEmbedPromiseForTest: () => void;
|
|
63
|
+
|
|
64
|
+
export { type ApplicationJourney, type ApplicationJourneyOptions, type YlEmbed, type YlEmbedOptions, __resetYlEmbedPromiseForTest, loadYlEmbed };
|
package/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t="/v1/ylembed.js";var d=()=>`https://sdk.youlend.com${t}`,i=n=>{if(!n)return d();let e=n.replace(/^https?:\/\//,"");if(e.endsWith(".dev-youlend.com"))return`https://${e.replace(".dev-youlend.com","")}-sdk.dev-youlend.com${t}`;if(e==="staging.youlend.com")return`https://origin-sdk.staging-youlend.com${t}`;if(e==="partners.staging-youlend.com")return`https://partners-sdk.staging-youlend.com${t}`;if(e==="uspartners.staging-youlend.com")return`https://uspartners-sdk.staging-youlend.com${t}`;if(e==="youlend.com"||e==="youlend.us")return d();let r=d();return console.error(`Invalid URL override: ${n} - falling back to script src = ${r}`),r},s=null,p=n=>s||(s=new Promise((e,r)=>{if(typeof window>"u"){let l={open:()=>{},close:()=>{}};e({create:(c,m)=>l});return}if(window.YlEmbed){e(new window.YlEmbed(n));return}let o=document.createElement("script");o.src=i(n.urlOverride),o.async=!0,o.onload=()=>{window.YlEmbed?e(new window.YlEmbed(n)):r(new Error("YlEmbed script loaded but window.YlEmbed is not available"))},o.onerror=()=>{r(new Error("Failed to load YlEmbed script from "+o.src))},document.head.appendChild(o)}),s),y=()=>{s=null};export{y as __resetYlEmbedPromiseForTest,p as loadYlEmbed};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/generated-constants.ts","../../src/index.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\n// Generated at: 2025-10-07T16:44:36.928Z\n// Source: tsup.config.ts CDN entry configuration\n\n/**\n * The CDN path for the SDK script, automatically extracted from tsup.config.ts\n * This ensures the URL stays in sync with the actual build output.\n */\nexport const CDN_SCRIPT_PATH = '/v1/ylembed.js';\n\n/**\n * All available CDN paths (in case multiple entries are configured)\n */\nexport const ALL_CDN_PATHS = [\n '/v1/ylembed.js'\n];\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { YlEmbedOptions, YlEmbed, ApplicationJourney } from './types';\r\nimport { CDN_SCRIPT_PATH } from './generated-constants';\r\n\r\nexport * from './types';\r\n\r\nconst getDefaultSdkUrl = () => `https://sdk.youlend.com${CDN_SCRIPT_PATH}`;\r\n\r\nconst constructScriptUrl = (urlOverride?: string): string => {\r\n if (!urlOverride) {\r\n return getDefaultSdkUrl();\r\n }\r\n\r\n const cleanUrl = urlOverride.replace(/^https?:\\/\\//, '');\r\n\r\n if (cleanUrl.endsWith('.dev-youlend.com')) {\r\n const subdomain = cleanUrl.replace('.dev-youlend.com', '');\r\n return `https://${subdomain}-sdk.dev-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'staging.youlend.com') {\r\n return `https://origin-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'partners.staging-youlend.com') {\r\n return `https://partners-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'uspartners.staging-youlend.com') {\r\n return `https://uspartners-sdk.staging-youlend.com${CDN_SCRIPT_PATH}`;\r\n }\r\n\r\n if (cleanUrl === 'youlend.com' || cleanUrl === 'youlend.us') {\r\n // youlend.com or youlend.us -> sdk.youlend.com + dynamic CDN path\r\n return getDefaultSdkUrl();\r\n }\r\n\r\n const defaultUrl = getDefaultSdkUrl();\r\n console.error(`Invalid URL override: ${urlOverride} - falling back to script src = ${defaultUrl}`);\r\n return defaultUrl;\r\n};\r\n\r\n// Keep a reference to the loaded YlEmbed class\r\nlet ylEmbedPromise: Promise<YlEmbed> | null = null;\r\n\r\n/**\r\n * The main entry point for the YlEmbed SDK.\r\n * This function handles loading the YlEmbed script from the CDN and initializing it.\r\n * It's designed to be called once per page load.\r\n *\r\n * @returns A Promise that resolves with the YlEmbed class.\r\n *\r\n * @example\r\n * ```\r\n * import { loadYlEmbed } from '@youlend/yl-embed-sdk';\r\n *\r\n * const ylEmbed = await loadYlEmbed({ ... });\r\n * ylEmbed.create({ ... });\r\n * ```\r\n */\r\nexport const loadYlEmbed = (options: YlEmbedOptions): Promise<YlEmbed> => {\r\n if (ylEmbedPromise) {\r\n return ylEmbedPromise;\r\n }\r\n ylEmbedPromise = new Promise((resolve, reject) => {\r\n if (typeof window === 'undefined') {\r\n // Return a mock for server-side rendering\r\n const mockApplicationJourney: ApplicationJourney = {\r\n open: () => { },\r\n close: () => { },\r\n };\r\n\r\n resolve({\r\n create: (componentName: 'ApplicationJourney', options?) => mockApplicationJourney,\r\n });\r\n return;\r\n }\r\n if ((window as any).YlEmbed) {\r\n resolve(new (window as any).YlEmbed(options));\r\n return;\r\n }\r\n\r\n const script = document.createElement('script');\r\n script.src = constructScriptUrl(options.urlOverride);\r\n script.async = true;\r\n script.onload = () => {\r\n if ((window as any).YlEmbed) {\r\n resolve(new (window as any).YlEmbed(options));\r\n } else {\r\n reject(new Error('YlEmbed script loaded but window.YlEmbed is not available'));\r\n }\r\n };\r\n script.onerror = () => {\r\n reject(new Error('Failed to load YlEmbed script from ' + script.src));\r\n };\r\n document.head.appendChild(script);\r\n });\r\n\r\n return ylEmbedPromise;\r\n};\r\n\r\n/**\r\n * @internal\r\n * This is an internal helper for testing purposes only and should not be used by consumers of the SDK.\r\n */\r\nexport const __resetYlEmbedPromiseForTest = () => {\r\n ylEmbedPromise = null;\r\n};\r\n"],"mappings":"AAQO,IAAMA,EAAkB,iBCF/B,IAAMC,EAAmB,IAAM,0BAA0BC,CAAe,GAElEC,EAAsBC,GAAiC,CAC3D,GAAI,CAACA,EACH,OAAOH,EAAiB,EAG1B,IAAMI,EAAWD,EAAY,QAAQ,eAAgB,EAAE,EAEvD,GAAIC,EAAS,SAAS,kBAAkB,EAEtC,MAAO,WADWA,EAAS,QAAQ,mBAAoB,EAAE,CAC9B,uBAAuBH,CAAe,GAGnE,GAAIG,IAAa,sBACf,MAAO,yCAAyCH,CAAe,GAGjE,GAAIG,IAAa,+BACf,MAAO,2CAA2CH,CAAe,GAGnE,GAAIG,IAAa,iCACf,MAAO,6CAA6CH,CAAe,GAGrE,GAAIG,IAAa,eAAiBA,IAAa,aAE7C,OAAOJ,EAAiB,EAG1B,IAAMK,EAAaL,EAAiB,EACpC,eAAQ,MAAM,yBAAyBG,CAAW,mCAAmCE,CAAU,EAAE,EAC1FA,CACT,EAGIC,EAA0C,KAiBjCC,EAAeC,GACtBF,IAGJA,EAAiB,IAAI,QAAQ,CAACG,EAASC,IAAW,CAChD,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAA6C,CACjD,KAAM,IAAM,CAAE,EACd,MAAO,IAAM,CAAE,CACjB,EAEAF,EAAQ,CACN,OAAQ,CAACG,EAAqCJ,IAAaG,CAC7D,CAAC,EACD,MACF,CACA,GAAK,OAAe,QAAS,CAC3BF,EAAQ,IAAK,OAAe,QAAQD,CAAO,CAAC,EAC5C,MACF,CAEA,IAAMK,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAMX,EAAmBM,EAAQ,WAAW,EACnDK,EAAO,MAAQ,GACfA,EAAO,OAAS,IAAM,CACf,OAAe,QAClBJ,EAAQ,IAAK,OAAe,QAAQD,CAAO,CAAC,EAE5CE,EAAO,IAAI,MAAM,2DAA2D,CAAC,CAEjF,EACAG,EAAO,QAAU,IAAM,CACrBH,EAAO,IAAI,MAAM,sCAAwCG,EAAO,GAAG,CAAC,CACtE,EACA,SAAS,KAAK,YAAYA,CAAM,CAClC,CAAC,EAEMP,GAOIQ,EAA+B,IAAM,CAChDR,EAAiB,IACnB","names":["CDN_SCRIPT_PATH","getDefaultSdkUrl","CDN_SCRIPT_PATH","constructScriptUrl","urlOverride","cleanUrl","defaultUrl","ylEmbedPromise","loadYlEmbed","options","resolve","reject","mockApplicationJourney","componentName","script","__resetYlEmbedPromiseForTest"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ylembed-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wrapper and TypeScript support for YlEmbed.js - YouLend's Embedded Components SDK",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "./index.cjs",
|
|
9
|
+
"module": "./index.js",
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"require": "./index.cjs",
|
|
15
|
+
"types": "./index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"youlend",
|
|
20
|
+
"ylembed-js"
|
|
21
|
+
],
|
|
22
|
+
"author": "YouLend",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"homepage": "https://docs.youlend.com/docs/embedded-components",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=16.0.0",
|
|
27
|
+
"npm": ">=7.0.0"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false
|
|
31
|
+
}
|