Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit c30296d

Browse files
authored
fix: modules imports (coinbase#163)
1 parent 5740876 commit c30296d

12 files changed

+156
-67
lines changed

.changeset/mean-gorillas-reflect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@coinbase/onchainkit': patch
3+
---
4+
5+
- **fix**: make sure imports from `core`, `farcaster` and `xmtp` work.

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@
8484
"default": "./lib/index.js"
8585
},
8686
"default": "./lib/index.js"
87+
},
88+
"./core": {
89+
"types": "./lib/core/index.d.ts",
90+
"browser": {
91+
"types": "./esm/core/index.d.ts",
92+
"module": "./esm/core/index.js",
93+
"import": "./esm/core/index.js",
94+
"default": "./lib/core/index.js"
95+
},
96+
"default": "./lib/core/index.js"
97+
},
98+
"./farcaster": {
99+
"types": "./lib/farcaster/index.d.ts",
100+
"browser": {
101+
"types": "./esm/farcaster/index.d.ts",
102+
"module": "./esm/farcaster/index.js",
103+
"import": "./esm/farcaster/index.js",
104+
"default": "./lib/farcaster/index.js"
105+
},
106+
"default": "./lib/farcaster/index.js"
107+
},
108+
"./xmtp": {
109+
"types": "./lib/xmtp/index.d.ts",
110+
"browser": {
111+
"types": "./esm/xmtp/index.d.ts",
112+
"module": "./esm/xmtp/index.js",
113+
"import": "./esm/xmtp/index.js",
114+
"default": "./lib/xmtp/index.js"
115+
},
116+
"default": "./lib/xmtp/index.js"
87117
}
88118
}
89119
}

site/docs/pages/getting-started.mdx

+31-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,37 @@ Add OnchainKit to your project, install the required packages.
44

55
## Installation
66

7-
```sh
8-
# Use Yarn
9-
yarn add @coinbase/onchainkit
7+
:::code-group
108

11-
# Use NPM
9+
```bash [npm]
1210
npm install @coinbase/onchainkit
1311

14-
# Use PNPM
12+
# Depending on the components or utilities you use,
13+
# you may end up utilizing any of those libraries.
14+
npm install viem@2.x react@18 react-dom@18
15+
npm install graphql@14 graphql-request@6
16+
```
17+
18+
```bash [yarn]
19+
yarn add @coinbase/onchainkit
20+
21+
# Depending on the components or utilities you use,
22+
# you may end up utilizing any of those libraries.
23+
yarn add viem@2.x react@18 react-dom@18
24+
yarn add graphql@14 graphql-request@6
25+
```
26+
27+
```bash [pnpm]
1528
pnpm add @coinbase/onchainkit
29+
30+
# Depending on the components or utilities you use,
31+
# you may end up utilizing any of those libraries.
32+
pnpm install viem@2.x react@18 react-dom@18
33+
pnpm install graphql@14 graphql-request@6
1634
```
1735

36+
:::
37+
1838
OnchainKit is divided into various theme utilities and components that are available for your use:
1939

2040
- [Farcaster Kit](/farcasterkit/introduction)
@@ -33,6 +53,12 @@ OnchainKit is divided into various theme utilities and components that are avail
3353
- [Framegear](/framekit/framegear)
3454

3555
- [Identity Kit](/identitykit/introduction)
56+
3657
- Components:
3758
- [`<Avatar />`](/identitykit/avatar)
3859
- [`<Name />`](/identitykit/name)
60+
61+
- [XMTP Kit](/xmtpkit/introduction)
62+
- Utilities:
63+
- [`getXmtpFrameMessage`](/xmtpkit/get-xmtp-frame-message)
64+
- [`isXmtpFrameRequest`](/xmtpkit/is-xmtp-frame-request)

site/docs/pages/index.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ OnchainKit offers three themes packed with React components and TypeScript utili
9999
- [XMTP Kit](/xmtpkit/introduction)
100100
- Utilities:
101101
- [`getXmtpFrameMessage`](/xmtpkit/get-xmtp-frame-message)
102+
- [`isXmtpFrameRequest`](/xmtpkit/is-xmtp-frame-request)
102103

103104
# Community
104105

site/docs/pages/xmtpkit/get-xmtp-frame-message.mdx

+8-58
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,26 @@ You can also use `getXmtpFrameMessage` to access useful information such as:
1212

1313
Note that if the `message` is not valid, it will be undefined.
1414

15-
**In order to use `getXmtpFrameMessage` you must also install `@xmtp/frames-validator` in your app, alongside onchainkit**
16-
17-
```sh
18-
yarn add @xmtp/frames-validator
19-
# OR
20-
npm i --save @xmtp/frames-validator
21-
```
22-
2315
```ts
24-
import { FrameRequest, getFrameMessage } from '@coinbase/onchainkit';
25-
import { isXmtpFrameRequest, getXmtpFrameMessage } from '@coinbase/onchainkit/xmtp';
26-
import { NextRequest, NextResponse } from 'next/server';
16+
import { FrameRequest } from '@coinbase/onchainkit';
17+
import { isXmtpFrameRequest, getXmtpFrameMessage } from '@coinbase/onchainkit/xmtp'; // [!code focus]
18+
import { NextResponse } from 'next/server';
2719

2820
async function getResponse(req: any): Promise<NextResponse> {
29-
// Step 2. Read the body from the Next Request
3021
const body: FrameRequest = await req.json();
3122
if (isXmtpFrameRequest(body)) {
32-
const { isValid, message } = await getXmtpFrameMessage(body);
23+
const { isValid, message } = await getXmtpFrameMessage(body); // [!code focus]
3324
// ... do something with the message if isValid is true
3425
} else {
35-
const { isValid, message } = await getFrameMessage(body, {
36-
neynarApiKey,
37-
});
38-
// ... do something with the message if isValid is true
26+
// ...
3927
}
4028
}
41-
42-
export async function POST(req: NextRequest): Promise<Response> {
43-
return getResponse(req);
44-
}
4529
```
4630

4731
## Returns
4832

49-
```ts
50-
type Promise<XmtpFrameValidationResponse>;
51-
52-
type XmtpFrameValidationResponse =
53-
| { isValid: true; message: XmtpFrameValidationData }
54-
| { isValid: false; message: undefined };
55-
56-
interface FrameValidationData {
57-
frameUrl: string;
58-
buttonIndex: number;
59-
timestamp: number;
60-
identifier: string;
61-
verifiedWalletAddress: string;
62-
// Same as verifiedWalletAddress
63-
identifier: string;
64-
}
65-
```
33+
[`Promise<XmtpFrameValidationResponse>`](/xmtpkit/types#xmtpframevalidationresponse)
6634

67-
## Param
35+
## Parameters
6836

69-
```ts
70-
export type UntrustedData = {
71-
url: string;
72-
timestamp: number;
73-
buttonIndex: number;
74-
inputText?: string;
75-
opaqueConversationIdentifier: string;
76-
walletAddress: string;
77-
};
78-
79-
// The Frame Signature Packet body
80-
export type XmtpFramesRequest = {
81-
clientProtocol: `xmtp@${string}`;
82-
untrustedData: UntrustedData;
83-
trustedData: {
84-
messageBytes: string;
85-
};
86-
};
87-
```
37+
[`Promise<XmtpFramesRequest>`](/xmtpkit/types#xmtpframesrequest)

site/docs/pages/xmtpkit/introduction.mdx

+19
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,27 @@ deescription: Introduction to XMTP Kit
77

88
XMTP Kit is designed to be modular and flexible, allowing developers to use only the parts of the protocol that they need.
99

10+
In order to use **XMTP Kit** you must also install `@xmtp/frames-validator` in your app, alongside Onchainkit.
11+
12+
:::code-group
13+
14+
```bash [npm]
15+
npm install @coinbase/onchainkit @xmtp/frames-validator
16+
```
17+
18+
```bash [yarn]
19+
yarn add @coinbase/onchainkit @xmtp/frames-validator
20+
```
21+
22+
```bash [pnpm]
23+
pnpm add @coinbase/onchainkit @xmtp/frames-validator
24+
```
25+
26+
:::
27+
1028
To assist you in engaging with XMTP, here is the XMTP Kit which includes:
1129

1230
- [XMTP Kit](/xmtpkit/introduction)
1331
- Utilities:
1432
- [`getXmtpFrameMessage`](/xmtpkit/get-xmtp-frame-message)
33+
- [`isXmtpFrameRequest`](/xmtpkit/is-xmtp-frame-request)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
# isXmtpFrameRequest
22

3-
isXmtpFrameRequest
3+
```ts
4+
import { FrameRequest } from '@coinbase/onchainkit';
5+
import { isXmtpFrameRequest } from '@coinbase/onchainkit/xmtp'; // [!code focus]
6+
import { NextResponse } from 'next/server';
7+
8+
async function getResponse(req: any): Promise<NextResponse> {
9+
const body: FrameRequest = await req.json();
10+
if (isXmtpFrameRequest(body)) {
11+
// [!code focus]
12+
// [!code focus]
13+
// ...
14+
}
15+
}
16+
```
17+
18+
## Returns
19+
20+
- **Type:** `boolean`
21+
22+
## Parameters
23+
24+
[`XmtpFramesRequest`](/xmtpkit/types#xmtpframesrequest)

site/docs/pages/xmtpkit/types.mdx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: XmtpKit Types
3+
deescription: Glossary of Types in XmtpKit Kit.
4+
---
5+
6+
# Types [Glossary of Types in XmtpKit Kit.]
7+
8+
## `XmtpFramesRequest`
9+
10+
```ts
11+
export type UntrustedData = {
12+
url: string;
13+
timestamp: number;
14+
buttonIndex: number;
15+
inputText?: string;
16+
opaqueConversationIdentifier: string;
17+
walletAddress: string;
18+
};
19+
20+
// The Frame Signature Packet body
21+
export type XmtpFramesRequest = {
22+
clientProtocol: `xmtp@${string}`;
23+
untrustedData: UntrustedData;
24+
trustedData: {
25+
messageBytes: string;
26+
};
27+
};
28+
```
29+
30+
## `XmtpFrameValidationResponse`
31+
32+
```ts
33+
type XmtpFrameValidationResponse =
34+
| { isValid: true; message: XmtpFrameValidationData }
35+
| { isValid: false; message: undefined };
36+
```

src/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version = '0.8.0';
1+
export const version = '0.8.2';

src/xmtp/getXmtpFrameMessage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { validateFramesPost, XmtpOpenFramesRequest } from '@xmtp/frames-validator';
1+
import { validateFramesPost } from '@xmtp/frames-validator';
2+
import type { XmtpOpenFramesRequest } from '@xmtp/frames-validator';
23

34
export async function getXmtpFrameMessage(payload: XmtpOpenFramesRequest) {
45
if (!payload.clientProtocol || !payload.clientProtocol.startsWith('xmtp@')) {

src/xmtp/isXmtpFrameRequest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { XmtpOpenFramesRequest } from '@xmtp/frames-validator';
1+
import type { XmtpOpenFramesRequest } from '@xmtp/frames-validator';
22

33
export function isXmtpFrameRequest(payload: any): payload is XmtpOpenFramesRequest {
44
return (

src/xmtp/types.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)