@fencyai/js 0.1.2 → 0.1.3
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 +63 -18
- package/dist/index.d.ts +54 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @fencyai/js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core Fency library for browser integration - equivalent to `@stripe/stripe-js`. Load Fency instances with your publishable key.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,27 +10,47 @@ npm install @fencyai/js
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### Basic Usage
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
|
-
import {
|
|
16
|
+
import { loadFency } from '@fencyai/js';
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// Make sure to call `loadFency` outside of a component's render to avoid
|
|
19
|
+
// recreating the Fency object on every render.
|
|
20
|
+
const fencyPromise = loadFency('pk_test_your_publishable_key_here');
|
|
20
21
|
|
|
21
|
-
// Use the
|
|
22
|
-
|
|
23
|
-
console.log(
|
|
24
|
-
console.log(
|
|
22
|
+
// Use the promise
|
|
23
|
+
fencyPromise.then((fency) => {
|
|
24
|
+
console.log('Fency loaded:', fency.publishableKey);
|
|
25
|
+
console.log('Version:', fency.version);
|
|
26
|
+
});
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
###
|
|
29
|
+
### With Configuration Options
|
|
28
30
|
|
|
29
31
|
```javascript
|
|
30
|
-
import
|
|
32
|
+
import { loadFency } from '@fencyai/js';
|
|
33
|
+
|
|
34
|
+
const fencyPromise = loadFency('pk_test_your_key', {
|
|
35
|
+
config: {
|
|
36
|
+
apiVersion: '2024-01-01',
|
|
37
|
+
endpoint: 'https://api.fency.ai'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Error Handling
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
```javascript
|
|
45
|
+
import { loadFency } from '@fencyai/js';
|
|
46
|
+
|
|
47
|
+
const fencyPromise = loadFency('invalid_key')
|
|
48
|
+
.then((fency) => {
|
|
49
|
+
// Success
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
console.error('Failed to load Fency:', error.message);
|
|
53
|
+
});
|
|
34
54
|
```
|
|
35
55
|
|
|
36
56
|
### Browser Usage
|
|
@@ -43,16 +63,39 @@ const utils = new fency.FencyUtils();
|
|
|
43
63
|
</head>
|
|
44
64
|
<body>
|
|
45
65
|
<script type="module">
|
|
46
|
-
import {
|
|
66
|
+
import { loadFency } from 'https://unpkg.com/@fencyai/js@latest/dist/index.js';
|
|
47
67
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
const fencyPromise = loadFency('pk_test_your_key');
|
|
69
|
+
fencyPromise.then(fency => {
|
|
70
|
+
document.body.innerHTML = `<p>Fency loaded: ${fency.version}</p>`;
|
|
71
|
+
});
|
|
51
72
|
</script>
|
|
52
73
|
</body>
|
|
53
74
|
</html>
|
|
54
75
|
```
|
|
55
76
|
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
### `loadFency(publishableKey, options?)`
|
|
80
|
+
|
|
81
|
+
Loads the Fency library with the given publishable key.
|
|
82
|
+
|
|
83
|
+
**Parameters:**
|
|
84
|
+
- `publishableKey` (string): Your Fency publishable key (must start with `pk_`)
|
|
85
|
+
- `options` (object, optional): Configuration options
|
|
86
|
+
- `config.apiVersion` (string, optional): API version to use (default: `'2024-01-01'`)
|
|
87
|
+
- `config.endpoint` (string, optional): Custom endpoint URL (default: `'https://api.fency.ai'`)
|
|
88
|
+
|
|
89
|
+
**Returns:** Promise<FencyInstance>
|
|
90
|
+
|
|
91
|
+
**Throws:** Error if publishable key is invalid
|
|
92
|
+
|
|
93
|
+
### `isFencyAvailable()`
|
|
94
|
+
|
|
95
|
+
Check if Fency is available in the current environment.
|
|
96
|
+
|
|
97
|
+
**Returns:** boolean
|
|
98
|
+
|
|
56
99
|
## Development
|
|
57
100
|
|
|
58
101
|
### Prerequisites
|
|
@@ -122,7 +165,7 @@ npm run publish:major # Bump major + publish
|
|
|
122
165
|
```
|
|
123
166
|
fency-js/
|
|
124
167
|
├── src/
|
|
125
|
-
│ └── index.ts # Main entry point
|
|
168
|
+
│ └── index.ts # Main entry point with loadFency
|
|
126
169
|
├── dist/ # Built files (generated)
|
|
127
170
|
├── package.json # Package configuration
|
|
128
171
|
├── tsconfig.json # TypeScript configuration
|
|
@@ -136,6 +179,8 @@ fency-js/
|
|
|
136
179
|
- ✅ Tree-shakable exports
|
|
137
180
|
- ✅ Minified production builds
|
|
138
181
|
- ✅ Browser-compatible
|
|
182
|
+
- ✅ Publishable key validation
|
|
183
|
+
- ✅ Promise-based loading
|
|
139
184
|
- ✅ npm package ready
|
|
140
185
|
|
|
141
186
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param message - The message to log
|
|
4
|
-
* @returns A formatted greeting
|
|
2
|
+
* Configuration options for Fency
|
|
5
3
|
*/
|
|
6
|
-
export
|
|
4
|
+
export interface FencyOptions {
|
|
5
|
+
/** Your Fency publishable key */
|
|
6
|
+
publishableKey: string;
|
|
7
|
+
/** Optional configuration for the Fency instance */
|
|
8
|
+
config?: {
|
|
9
|
+
/** API version to use */
|
|
10
|
+
apiVersion?: string;
|
|
11
|
+
/** Custom endpoint URL */
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
7
15
|
/**
|
|
8
|
-
*
|
|
16
|
+
* Fency instance interface
|
|
9
17
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Format a date for display
|
|
19
|
-
*/
|
|
20
|
-
formatDate(date: Date): string;
|
|
18
|
+
export interface FencyInstance {
|
|
19
|
+
/** The publishable key used to initialize this instance */
|
|
20
|
+
publishableKey: string;
|
|
21
|
+
/** Configuration options */
|
|
22
|
+
config: Required<FencyOptions['config']>;
|
|
23
|
+
/** Version of the Fency library */
|
|
24
|
+
version: string;
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Loads the Fency library with the given publishable key.
|
|
28
|
+
* This method should be called outside of a component's render to avoid
|
|
29
|
+
* recreating the Fency object on every render.
|
|
30
|
+
*
|
|
31
|
+
* @param publishableKey - Your Fency publishable key
|
|
32
|
+
* @param options - Optional configuration options
|
|
33
|
+
* @returns A promise that resolves to a Fency instance
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```javascript
|
|
37
|
+
* import { loadFency } from '@fencyai/js';
|
|
38
|
+
*
|
|
39
|
+
* const fencyPromise = loadFency('pk_your_publishable_key');
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadFency(publishableKey: string, options?: Omit<FencyOptions, 'publishableKey'>): Promise<FencyInstance>;
|
|
43
|
+
/**
|
|
44
|
+
* Check if Fency is available in the current environment
|
|
45
|
+
* This checks for browser compatibility and required APIs
|
|
46
|
+
*/
|
|
47
|
+
export declare function isFencyAvailable(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get detailed information about Fency availability
|
|
50
|
+
* Returns an object with availability status and missing requirements
|
|
51
|
+
*/
|
|
52
|
+
export declare function getFencyAvailabilityInfo(): {
|
|
53
|
+
available: boolean;
|
|
54
|
+
missing: string[];
|
|
55
|
+
warnings: string[];
|
|
56
|
+
};
|
|
22
57
|
declare const _default: {
|
|
23
|
-
|
|
24
|
-
|
|
58
|
+
loadFency: typeof loadFency;
|
|
59
|
+
isFencyAvailable: typeof isFencyAvailable;
|
|
60
|
+
getFencyAvailabilityInfo: typeof getFencyAvailabilityInfo;
|
|
25
61
|
};
|
|
26
62
|
export default _default;
|
|
27
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,MAAM,CAAC,EAAE;QACP,yBAAyB;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,0BAA0B;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CACvB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAM,GACjD,OAAO,CAAC,aAAa,CAAC,CA4BxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAgC1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAwCA;;;;;;AAGD,wBAIE"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(e){
|
|
1
|
+
function s(n,i={}){return new Promise((e,o)=>{if(!n||typeof n!="string"){o(new Error("Fency: A valid publishable key is required."));return}if(!n.startsWith("pk_")){o(new Error('Fency: Invalid publishable key format. Keys should start with "pk_".'));return}let t={publishableKey:n,config:{apiVersion:i.config?.apiVersion||"2024-01-01",endpoint:i.config?.endpoint||"https://api.fency.ai"},version:"0.1.1"};setTimeout(()=>{e(t)},0)})}function r(){if(typeof window>"u")return!1;let n=["fetch","Promise","JSON"];for(let i of n)if(typeof window[i]>"u")return!1;if(typeof window.location<"u"){let i=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",e=window.location.protocol==="https:";!i&&!e&&console.warn("Fency: For security, we recommend using HTTPS in production.")}return!0}function a(){let n={available:!0,missing:[],warnings:[]};if(typeof window>"u")return n.available=!1,n.missing.push("Browser environment"),n;let i=["fetch","Promise","JSON"];for(let e of i)typeof window[e]>"u"&&(n.available=!1,n.missing.push(`${e} API`));if(typeof window.location<"u"){let e=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1",o=window.location.protocol==="https:";!e&&!o&&n.warnings.push("HTTPS is recommended for production use")}return n}var c={loadFency:s,isFencyAvailable:r,getFencyAvailabilityInfo:a};export{c as default,a as getFencyAvailabilityInfo,r as isFencyAvailable,s as loadFency};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fencyai/js",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Core Fency library for browser integration - load Fency instances with your publishable key",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -33,10 +33,13 @@
|
|
|
33
33
|
"publish:major": "npm run version:major && npm publish --access public"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
|
+
"fency",
|
|
37
|
+
"fencyai",
|
|
38
|
+
"browser",
|
|
36
39
|
"typescript",
|
|
37
40
|
"esm",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
41
|
+
"loadfency",
|
|
42
|
+
"publishable-key"
|
|
40
43
|
],
|
|
41
44
|
"author": "",
|
|
42
45
|
"license": "MIT",
|