Skip to content

Commit

Permalink
Merge pull request #499 from xmtp/beta
Browse files Browse the repository at this point in the history
Add support for private user preferences
  • Loading branch information
rygine authored Jan 2, 2024
2 parents e96b2e2 + ea63d30 commit d4d8413
Show file tree
Hide file tree
Showing 29 changed files with 1,321 additions and 258 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ const isOnProdNetwork = await Client.canMessage(
)
```

### Request and respect user consent

![Feature status](https://img.shields.io/badge/Feature_status-Alpha-orange)

The user consent feature enables your app to request and respect user consent preferences. With this feature, another blockchain account address registered on the XMTP network can have one of three consent preference values:

- Unknown
- Allowed
- Denied

To learn more, see [Request and respect user consent](https://xmtp.org/docs/build/user-consent).

### Send a broadcast message

You can send a broadcast message (1:many message or announcement) with XMTP. The recipient sees the message as a DM from the sending wallet address.
Expand Down
58 changes: 58 additions & 0 deletions build/esbuild-plugin-resolve-extensions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { basename, dirname, extname, format } from 'node:path'
import { existsSync } from 'node:fs'
import { getResolvedPath, loadCompilerOptions } from './utils'
import { Plugin } from 'esbuild'

type ResolveExtensionsPluginOptions = {
extensions?: string[]
tsconfigPath?: string
}

export const resolveExtensionsPlugin = (
options?: ResolveExtensionsPluginOptions
): Plugin => {
const { tsconfigPath, extensions = [] } = options ?? {}
const compilerOptions = loadCompilerOptions(tsconfigPath)
return {
name: 'resolve-extensions',
setup({ onResolve }) {
onResolve({ filter: /.*/ }, async ({ kind, importer, path }) => {
let result: null | { path: string } = null
switch (kind) {
case 'import-statement':
case 'require-call':
case 'dynamic-import':
case 'require-resolve':
{
const resolvedPath = getResolvedPath(
path,
importer,
compilerOptions
)
if (resolvedPath) {
const ext = extname(resolvedPath)
const base = basename(resolvedPath, ext)
const dir = dirname(resolvedPath)
// check for extensions
extensions.some((extension) => {
const newPath = format({
dir,
name: base,
ext: `${extension}${ext}`,
})
const exists = existsSync(newPath)
if (exists) {
result = { path: newPath }
return true
}
return false
})
}
}
break
}
return result
})
},
}
}
48 changes: 48 additions & 0 deletions build/esbuild-plugin-resolve-extensions/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { readFileSync, existsSync } from 'node:fs'
import type { CompilerOptions } from 'typescript'
import ts from 'typescript'
import { findUpSync } from 'find-up'

const { nodeModuleNameResolver, sys } = ts

type TSConfig = {
compilerOptions?: CompilerOptions
}

const loadJSON = (jsonPath: string) =>
JSON.parse(readFileSync(jsonPath, 'utf8')) as TSConfig

export const loadCompilerOptions = (tsconfigPath?: string) => {
let config: TSConfig = {}
if (!tsconfigPath) {
const configPath = findUpSync('tsconfig.json')
if (configPath) {
config = loadJSON(configPath)
}
} else {
if (existsSync(tsconfigPath)) {
config = loadJSON(tsconfigPath)
}
}
return config?.compilerOptions ?? {}
}

export const getResolvedPath = (
path: string,
importer: string,
compilerOptions: CompilerOptions
) => {
const { resolvedModule } = nodeModuleNameResolver(
path,
importer,
compilerOptions,
sys
)

const resolvedFileName = resolvedModule?.resolvedFileName
if (!resolvedFileName || resolvedFileName.endsWith('.d.ts')) {
return null
}

return sys.resolvePath(resolvedFileName)
}
Loading

0 comments on commit d4d8413

Please sign in to comment.