Skip to content

Commit 4d531fe

Browse files
committed
pulling out typescript client code from the monorepo
1 parent d8d7eb5 commit 4d531fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+26018
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 PolyAPI
3+
Copyright (c) 2023 PolyAPI Corporation, a Wyoming Corporation
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Poly TypeScript/JavaScript client
2+
3+
This is the client library and CLI for users of PolyAPI to help create and manage your Poly definitions.
4+
5+
## Usage
6+
7+
Make sure you have set your npm registry in .npmrc file.
8+
9+
Install the package with `npm install polyapi`.
10+
11+
Run `npx poly generate` to set up your Poly connection (only for the first time) and generate Poly functions.
12+
Whenever you update your Poly functions, run `npx poly generate` again to update your local functions.
13+
14+
You will need an API Key to to access Poly. Please head to https://polyapi.io to request an API key!
15+
16+
### Using Poly functions
17+
18+
After you have run `npx poly generate` you can use your Poly client in your code:
19+
20+
```
21+
import poly from 'polyapi';
22+
23+
const location = 'Eiffel Tower, Paris';
24+
25+
poly.maps.google.getXY(location)
26+
.then(res => console.log(res))
27+
.catch(err => console.error(err));
28+
```
29+
30+
### Using error handler
31+
32+
Poly functions can throw errors. You can catch them with try/catch or you can register an error handler for function path:
33+
34+
```
35+
import poly, {errorHandler} from 'polyapi';
36+
37+
errorHandler.on('myContext.myFunction', (error) => {
38+
// handle error
39+
});
40+
```
41+
42+
Or you can register an error handler for all functions in context:
43+
44+
```
45+
errorHandler.on('myContext', (error) => {
46+
// handle error
47+
});
48+
```
49+
50+
To remove error handler for function path:
51+
52+
```
53+
errorHandler.off('myContext.myFunction');
54+
```
55+
56+
### Using Webhook handlers
57+
58+
Similar to error handlers, you can register handlers for Webhooks:
59+
60+
```
61+
import poly from 'polyapi';
62+
63+
poly.myWebhookContext.paymentReceieved(event => {
64+
// handle event
65+
});
66+
```
67+
68+
Webhook handlers have their context and function name. To remove a handler call the returned function:
69+
70+
```
71+
const unregister = poly.myWebhookContext.paymentReceieved(event => {
72+
// handle event
73+
});
74+
...
75+
unregister();
76+
```
77+
78+
Happy hacking!

README_INTERNAL.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# README INTERNAL
2+
3+
So you want to hack on this npm package locally?
4+
5+
Here's how!
6+
7+
## Verdaccio
8+
9+
We recommend using [Verdaccio](https://verdaccio.org/)
10+
11+
First let's install Verdaccio globally.
12+
13+
```bash
14+
npm install -g verdaccio
15+
```
16+
17+
Then let's start verdaccio up in a new terminal:
18+
19+
```bash
20+
verdaccio
21+
```
22+
23+
Now add a user:
24+
25+
```bash
26+
npm adduser --registry=http://localhost:4873/
27+
```
28+
29+
Enter whatever you want for username/password/email.
30+
31+
## Make a Small Change
32+
33+
Now let's go to your JS polyapi client folder:
34+
35+
https://github.com/polyapi/poly-alpha/tree/develop/packages/client
36+
37+
Let's make a tiny tweak to the `README.md`. Just so we can make sure we are installing our local changes.
38+
39+
Add the line "HELLO WORLD" to the end of `README.md`
40+
41+
Then run this command to publish to your local Verdaccio instance:
42+
43+
```bash
44+
./publish_local.sh
45+
```
46+
47+
## Install Your Updated NPM Package Locally
48+
49+
Now let's create a polyapi project where we can test our npm changes locally.
50+
51+
First, create a new folder, for example `$HOME/poly/jslocal`, then cd into the folder.
52+
53+
Run the following command:
54+
55+
```bash
56+
echo 'registry=http://localhost:4873' > .npmrc
57+
```
58+
59+
Then run this command to make sure you have the latest version of the library from Verdaccio:
60+
61+
```bash
62+
npm uninstall polyapi && npm install polyapi
63+
```
64+
65+
Finally run this command:
66+
67+
```bash
68+
cat node_modules/polyapi/README.md
69+
```
70+
71+
You should see "HELLO WORLD" at the bottom of the README!
72+
73+
## Conclusion
74+
75+
That's it! Happy hacking!

0 commit comments

Comments
 (0)