@near-mobile/connector 0.0.1-alpha-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 +109 -0
- package/dist/README.md +109 -0
- package/dist/chunk-D2RKH6IN.mjs +31 -0
- package/dist/chunk-LJHKWETI.js +31 -0
- package/dist/config.d.ts +8 -0
- package/dist/connector.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +504 -0
- package/dist/index.mjs +504 -0
- package/dist/package.json +71 -0
- package/dist/strategies/qr-code/index.d.ts +1 -0
- package/dist/strategies/qr-code/index.js +44 -0
- package/dist/strategies/qr-code/index.mjs +44 -0
- package/dist/strategies/qr-code/qr-code.config.d.ts +3 -0
- package/dist/strategies/qr-code/qr-code.d.ts +7 -0
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @near-mobile/connector
|
|
2
|
+
|
|
3
|
+
Public client library for the **Near Mobile Connector**: create requests, poll for responses, build deep-link URLs, and generate QR codes for wallet connections.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @near-mobile/connector
|
|
9
|
+
yarn add @near-mobile/connector
|
|
10
|
+
pnpm install @near-mobile/connector
|
|
11
|
+
bun add @near-mobile/connector
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
This package lets you:
|
|
17
|
+
|
|
18
|
+
- **Create and poll requests** against the Near Mobile Connector API
|
|
19
|
+
- **Build URLs** for opening the Near Mobile Wallet (mobile deep-link or universal link)
|
|
20
|
+
- **Generate QR codes** that encode the request URL for wallet scanning (optional strategy)
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Creating and polling a request
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { NearMobileConnector } from "@near-mobile/connector";
|
|
28
|
+
|
|
29
|
+
// Create a new connector request (payload depends on your API)
|
|
30
|
+
const request = await NearMobileConnector.createRequest({
|
|
31
|
+
// ... your request body
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const id = request.id;
|
|
35
|
+
|
|
36
|
+
// Poll until the user completes the action in the wallet
|
|
37
|
+
const completedRequest = await NearMobileConnector.pollResponse(id);
|
|
38
|
+
|
|
39
|
+
// Use completedRequest.status and response data
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Building request URLs
|
|
43
|
+
|
|
44
|
+
Use these URLs to open the wallet (e.g. in a “Open in app” button or redirect):
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { buildNearMobileAppRequestUrl, buildNearMobileUniversalRequestUrl } from "@near-mobile/connector";
|
|
48
|
+
|
|
49
|
+
const requestId = "your-request-id";
|
|
50
|
+
|
|
51
|
+
// Mobile deep-link (near-mobile-wallet://request?id=...)
|
|
52
|
+
const mobileUrl = buildNearMobileAppRequestUrl(requestId);
|
|
53
|
+
|
|
54
|
+
// Universal URL (works on web and can redirect to app when installed)
|
|
55
|
+
const universalUrl = buildNearMobileUniversalRequestUrl(requestId);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### QR code strategy
|
|
59
|
+
|
|
60
|
+
Generate a QR code that encodes the mobile request URL so users can scan it with the wallet app:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { NearMobileQrCode } from "@near-mobile/connector/strategies/qr-code";
|
|
64
|
+
|
|
65
|
+
const qr = new NearMobileQrCode({
|
|
66
|
+
requestId: "your-request-id",
|
|
67
|
+
// ... other qr-code-styling options (except data, image, imageOptions)
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Append SVG to DOM
|
|
71
|
+
const container = document.getElementById("qr-container");
|
|
72
|
+
qr.append(container);
|
|
73
|
+
|
|
74
|
+
// Or get as blob for download
|
|
75
|
+
const blob = await qr.download({ name: "qr", extension: "png" });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`NearMobileQrCode` extends [qr-code-styling](https://github.com/kozakdenys/qr-code-styling); you can pass any of its options (except `data`, `image`, and `imageOptions`, which are set from the package config).
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
| Export | Description |
|
|
83
|
+
| ------------------------------------------------ | ----------------------------------------------- |
|
|
84
|
+
| `NearMobileConnector.createRequest(body)` | Create a new connector request. |
|
|
85
|
+
| `NearMobileConnector.getRequest(id)` | Fetch a request by ID. |
|
|
86
|
+
| `NearMobileConnector.pollResponse(id, options?)` | Poll a request until it is no longer `pending`. |
|
|
87
|
+
| `buildNearMobileAppRequestUrl(id)` | Build the mobile deep-link URL for a request. |
|
|
88
|
+
| `buildNearMobileUniversalRequestUrl(id)` | Build the universal request URL. |
|
|
89
|
+
|
|
90
|
+
### QR Code Strategy
|
|
91
|
+
|
|
92
|
+
| Export | Description |
|
|
93
|
+
| --------------------------------------------------------------------- | -------------------------------------------------- |
|
|
94
|
+
| `NearMobileQrCode` (from `@near-mobile/connector/strategies/qr-code`) | QR code class that encodes the mobile request URL. |
|
|
95
|
+
|
|
96
|
+
## Publishing
|
|
97
|
+
|
|
98
|
+
From the repo root (or this package directory):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pnpm run build
|
|
102
|
+
pnpm publish --no-git-checks
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The package is configured to run `pnpm run build` automatically on `prepublishOnly`. Scoped packages require `publishConfig.access: "public"` (already set) to be published to the public npm registry.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT © Peersyst
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @near-mobile/connector
|
|
2
|
+
|
|
3
|
+
Public client library for the **Near Mobile Connector**: create requests, poll for responses, build deep-link URLs, and generate QR codes for wallet connections.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @near-mobile/connector
|
|
9
|
+
yarn add @near-mobile/connector
|
|
10
|
+
pnpm install @near-mobile/connector
|
|
11
|
+
bun add @near-mobile/connector
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
This package lets you:
|
|
17
|
+
|
|
18
|
+
- **Create and poll requests** against the Near Mobile Connector API
|
|
19
|
+
- **Build URLs** for opening the Near Mobile Wallet (mobile deep-link or universal link)
|
|
20
|
+
- **Generate QR codes** that encode the request URL for wallet scanning (optional strategy)
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Creating and polling a request
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { NearMobileConnector } from "@near-mobile/connector";
|
|
28
|
+
|
|
29
|
+
// Create a new connector request (payload depends on your API)
|
|
30
|
+
const request = await NearMobileConnector.createRequest({
|
|
31
|
+
// ... your request body
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const id = request.id;
|
|
35
|
+
|
|
36
|
+
// Poll until the user completes the action in the wallet
|
|
37
|
+
const completedRequest = await NearMobileConnector.pollResponse(id);
|
|
38
|
+
|
|
39
|
+
// Use completedRequest.status and response data
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Building request URLs
|
|
43
|
+
|
|
44
|
+
Use these URLs to open the wallet (e.g. in a “Open in app” button or redirect):
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { buildNearMobileAppRequestUrl, buildNearMobileUniversalRequestUrl } from "@near-mobile/connector";
|
|
48
|
+
|
|
49
|
+
const requestId = "your-request-id";
|
|
50
|
+
|
|
51
|
+
// Mobile deep-link (near-mobile-wallet://request?id=...)
|
|
52
|
+
const mobileUrl = buildNearMobileAppRequestUrl(requestId);
|
|
53
|
+
|
|
54
|
+
// Universal URL (works on web and can redirect to app when installed)
|
|
55
|
+
const universalUrl = buildNearMobileUniversalRequestUrl(requestId);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### QR code strategy
|
|
59
|
+
|
|
60
|
+
Generate a QR code that encodes the mobile request URL so users can scan it with the wallet app:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { NearMobileQrCode } from "@near-mobile/connector/strategies/qr-code";
|
|
64
|
+
|
|
65
|
+
const qr = new NearMobileQrCode({
|
|
66
|
+
requestId: "your-request-id",
|
|
67
|
+
// ... other qr-code-styling options (except data, image, imageOptions)
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Append SVG to DOM
|
|
71
|
+
const container = document.getElementById("qr-container");
|
|
72
|
+
qr.append(container);
|
|
73
|
+
|
|
74
|
+
// Or get as blob for download
|
|
75
|
+
const blob = await qr.download({ name: "qr", extension: "png" });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`NearMobileQrCode` extends [qr-code-styling](https://github.com/kozakdenys/qr-code-styling); you can pass any of its options (except `data`, `image`, and `imageOptions`, which are set from the package config).
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
| Export | Description |
|
|
83
|
+
| ------------------------------------------------ | ----------------------------------------------- |
|
|
84
|
+
| `NearMobileConnector.createRequest(body)` | Create a new connector request. |
|
|
85
|
+
| `NearMobileConnector.getRequest(id)` | Fetch a request by ID. |
|
|
86
|
+
| `NearMobileConnector.pollResponse(id, options?)` | Poll a request until it is no longer `pending`. |
|
|
87
|
+
| `buildNearMobileAppRequestUrl(id)` | Build the mobile deep-link URL for a request. |
|
|
88
|
+
| `buildNearMobileUniversalRequestUrl(id)` | Build the universal request URL. |
|
|
89
|
+
|
|
90
|
+
### QR Code Strategy
|
|
91
|
+
|
|
92
|
+
| Export | Description |
|
|
93
|
+
| --------------------------------------------------------------------- | -------------------------------------------------- |
|
|
94
|
+
| `NearMobileQrCode` (from `@near-mobile/connector/strategies/qr-code`) | QR code class that encodes the mobile request URL. |
|
|
95
|
+
|
|
96
|
+
## Publishing
|
|
97
|
+
|
|
98
|
+
From the repo root (or this package directory):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pnpm run build
|
|
102
|
+
pnpm publish --no-git-checks
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The package is configured to run `pnpm run build` automatically on `prepublishOnly`. Scoped packages require `publishConfig.access: "public"` (already set) to be published to the public npm registry.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT © Peersyst
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
var nearMobileConnectorConfig = {
|
|
9
|
+
apiUrl: "https://near-mobile-connector.aws.peersyst.tech",
|
|
10
|
+
mobileRequestUrl: "near-mobile-wallet://request?id={id}",
|
|
11
|
+
universalRequestUrl: "https://near-mobile-production.aws.peersyst.tech/api/deep-link/request?id={id}",
|
|
12
|
+
responsePolling: {
|
|
13
|
+
delay: 3e3,
|
|
14
|
+
maxIterations: 1e3
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/utils.ts
|
|
19
|
+
function buildNearMobileAppRequestUrl(id) {
|
|
20
|
+
return nearMobileConnectorConfig.mobileRequestUrl.replace("{id}", id);
|
|
21
|
+
}
|
|
22
|
+
function buildNearMobileUniversalRequestUrl(id) {
|
|
23
|
+
return nearMobileConnectorConfig.universalRequestUrl.replace("{id}", id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
__export,
|
|
28
|
+
nearMobileConnectorConfig,
|
|
29
|
+
buildNearMobileAppRequestUrl,
|
|
30
|
+
buildNearMobileUniversalRequestUrl
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
var nearMobileConnectorConfig = {
|
|
9
|
+
apiUrl: "https://near-mobile-connector.aws.peersyst.tech",
|
|
10
|
+
mobileRequestUrl: "near-mobile-wallet://request?id={id}",
|
|
11
|
+
universalRequestUrl: "https://near-mobile-production.aws.peersyst.tech/api/deep-link/request?id={id}",
|
|
12
|
+
responsePolling: {
|
|
13
|
+
delay: 3e3,
|
|
14
|
+
maxIterations: 1e3
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/utils.ts
|
|
19
|
+
function buildNearMobileAppRequestUrl(id) {
|
|
20
|
+
return nearMobileConnectorConfig.mobileRequestUrl.replace("{id}", id);
|
|
21
|
+
}
|
|
22
|
+
function buildNearMobileUniversalRequestUrl(id) {
|
|
23
|
+
return nearMobileConnectorConfig.universalRequestUrl.replace("{id}", id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
exports.__export = __export; exports.nearMobileConnectorConfig = nearMobileConnectorConfig; exports.buildNearMobileAppRequestUrl = buildNearMobileAppRequestUrl; exports.buildNearMobileUniversalRequestUrl = buildNearMobileUniversalRequestUrl;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PollingOptions } from "@shared/utils";
|
|
2
|
+
export type NearMobileConnectorConfig = {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
mobileRequestUrl: string;
|
|
5
|
+
universalRequestUrl: string;
|
|
6
|
+
responsePolling: PollingOptions;
|
|
7
|
+
};
|
|
8
|
+
export declare const nearMobileConnectorConfig: NearMobileConnectorConfig;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConnectorRequestDto, RequestApi } from "@shared/connector";
|
|
2
|
+
import { PollingOptions } from "@shared/utils/polling";
|
|
3
|
+
export declare const createRequest: typeof RequestApi.createRequest;
|
|
4
|
+
export declare const getRequest: typeof RequestApi.getRequest;
|
|
5
|
+
export declare function pollResponse(id: string, options?: PollingOptions): Promise<ConnectorRequestDto>;
|
package/dist/index.d.ts
ADDED