How to import GUN SEA with Deno Fresh? - deno

The first attempt to import GUN from Fresh was to add the gun library from esm to import_map.json, where it correctly works in simple examples of using GUN.
{
"imports": {
...
"gun": "https://esm.sh/gun#0.2020.1237",
}
}
But the problem occurred when I wanted to import additionally gun/sea,
After importing import Sea from "gun/sea";.
I got this error:
error: Uncaught (in promise) Error: Dynamic require of "./lib/text-encoding" is not supported
On GitHub I read to import gun/lib/mobile before importing SEA when such a problem occurs.
But this brings an additional problem:
error: Uncaught (in promise) TypeError: Assignment to constant variable.
I checked the gun/lib/mobile file and it literally contains a few lines of global variables:
import Buffer from "buffer";
import { TextEncoder, TextDecoder } from "text-encoding";
global.Buffer = global.Buffer || Buffer.Buffer;
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
Is there any chance to make SEA work on Fresh?

Add following line inside imports in import_map.json file:
"#gun": "https://esm.sh/gun#0.2020.1237"
Then use this import statement to import GUN in any route/component:
import GUN from "#gun"
Usage (from GUN documentation):
const gun = GUN();
gun.get('mark').put({
name: "Mark",
email: "mark#gun.eco",
});
gun.get('mark').on((data, key) => {
console.log("realtime updates:", data);
});
setInterval(() => { gun.get('mark').get('live').put(Math.random()) }, 9);

Related

Box node sdk on Deno throws "Not implemented: crypto.Sign" error

I want to use Box Node SDK on Deno (v1.30.3) . here is a simple example.
import BoxSDK from "npm:box-node-sdk#2.8.1";
import conf from "/path/to/config.json" assert {type: "json"};
const sdk = BoxSDK.getPreconfiguredInstance(conf);
const client = sdk.getAppAuthClient("enterprise");
client.users.get(client.CURRENT_USER_ID).then((me: any) => {
console.log(me); // should print user’s name
})
This is what I get.
error: Uncaught Error: Not implemented: crypto.Sign
throw new Error(message);
^
at notImplemented (https://deno.land/std#0.177.0/node/_utils.ts:23:9)
at new Sign (https://deno.land/std#0.177.0/node/internal/crypto/sig.ts:45:5)
at Object.createSign (https://deno.land/std#0.177.0/node/crypto.ts:268:10)
at Object.sign (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/jwa/1.4.1/index.js:151:25)
at Object.jwsSign \[as sign\] (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/jws/3.2.2/lib/sign-stream.js:32:24)
at Object.module.exports \[as sign\] (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/jsonwebtoken/8.5.1/sign.js:204:16)
at TokenManager.getTokensJWTGrant (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/token-manager.js:286:48)
at AppAuthSession.\_refreshAppAuthAccessToken (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/sessions/app-auth-session.js:79:18)
at AppAuthSession.getAccessToken (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/sessions/app-auth-session.js:124:25)
at BoxClient.\_makeRequest (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/box-client.js:300:18)
at BoxClient.get (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/box-client.js:452:21)
at wrappedClientMethod (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/box-client.js:589:30)
at Users.get (file:///Users/hkobayashi/Library/Caches/deno/npm/registry.npmjs.org/box-node-sdk/2.8.1/lib/managers/users.js:42:67)
at file:///Users/hkobayashi/dev/poc/poc24-deno/2023-02/box-hello.ts:8:14
Does this mean deno's crypto library hasn't yet fully implemented?
is there any workaround?

Module not found: Can't resolve 'next-mdx-import-source-file'

I am trying to get #next/mdx running with the new app directory. I followed the setup in the Readme of the package but i get the following error message when I try to render an mdx page. I can not find any information on this package what so ever.
Module not found: Can't resolve 'next-mdx-import-source-file'
1 | import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
> 2 | import { useMDXComponents as _provideComponents } from "next-mdx-import-source-file";
3 | function _createMdxContent(props) {
4 | const _components = Object.assign({
5 | h1: "h1",
This error occurs if the file mdx-components.js is not present in the project root directory.
This dependency is not an actual package but rather some next magic which actually imports the mdx-components.js file. In my case I missed out on on the plural.

pdfMake in deno from a CDN

I want to use pdfMake in deno and not host the pdfMake files and vfs_fonts on my server, by using a CDN line CDNJS or esm.sh.
I have the following code in the to of my app.js file:
import pdfMake from "https://esm.sh/pdfmake"
import * as pdfFonts from "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.4/vfs_fonts.min.js"
but I get the following errors:
[!] [#0] starting `deno run -A app.js`
Download https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.4/vfs_fonts.js
Download https://deno.land/x/md5/mod.ts
error: Uncaught TypeError: Cannot read properties of undefined (reading 'pdfMake')
this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = {
^
at https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.4/vfs_fonts.js:1:21
[E] [daem] app crashed - waiting for file changes before starting ...
I am not sure how to import or load the vfs_fonts from the CDN. Please note that my aim is to use a CDN for getting pdfMake and it's fonts.
I've changed the app.js file so that I only load the pdfmake from the CDN. I then load the fonts seperatly from the CDN into the pdfMake object:
import pdfMake from "https://esm.sh/pdfmake"
pdfMake.fonts = {
Roboto: {
normal: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Regular.ttf',
bold: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Medium.ttf',
italics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Italic.ttf',
bolditalics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-MediumItalic.ttf'
},
Merriweather: {
normal: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Merriweather/Merriweather-Regular.ttf',
bold: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Merriweather/Merriweather-Medium.ttf',
italics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Merriweather/Merriweather-Italic.ttf',
bolditalics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Merriweather/Merriweather-MediumItalic.ttf'
},
}

Pact: Error when trying to setup mock provider

I'm trying to write my first Pact-python test using pytest, Could someone please tell me what's wrong with my code?
import unittest
import requests
import json
import pytest
import atexit
from pact import Consumer, Provider
pact = Consumer('Consumer').has_pact_with(Provider('Provider'), host_name='mockservice', port=8080)
pact.start_service()
atexit.register(pact.stop_service)
class InterviewDetails(unittest.TestCase):
def test_candidate_report_api(self):
candidate_report_payload = {}
resp = requests.post("http://localhost:1234/users/",data=json.dumps(candidate_report_payload))
response = json.loads(resp.text)
return response
#pytest.mark.health1
def test_candidate_report(self):
expected = {}
(pact.given('Comment')
.upon_receiving('comment')
.with_request(method='POST', path="http://localhost:1234/users/", headers={})
.will_respond_with(200, body=expected))
with pact:
pact.setup()
result = self.test_candidate_report_api()
self.assertEqual(result, expected)
pact.verify()
The error from stacktrace:
AttributeError: module 'pact' has no attribute 'Like'
Can you please confirm you're using pact-python from https://github.com/pact-foundation/pact-python/ (and not pactman, a project that is not maintained by the Pact Foundation)?
It might be related to the way you have setup your test?
Here is an example project you can use for reference: https://github.com/pactflow/example-consumer-python/
Relevant test code:
"""pact test for product service client"""
import json
import logging
import os
import requests
from requests.auth import HTTPBasicAuth
import pytest
from pact import Consumer, Like, Provider, Term, Format
from src.consumer import ProductConsumer
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
print(Format().__dict__)
PACT_MOCK_HOST = 'localhost'
PACT_MOCK_PORT = 1234
PACT_DIR = os.path.dirname(os.path.realpath(__file__))
#pytest.fixture
def consumer():
return ProductConsumer(
'http://{host}:{port}'
.format(host=PACT_MOCK_HOST, port=PACT_MOCK_PORT)
)
#pytest.fixture(scope='session')
def pact(request):
pact = Consumer('pactflow-example-consumer-python').has_pact_with(
Provider('pactflow-example-provider-python'), host_name=PACT_MOCK_HOST, port=PACT_MOCK_PORT,
pact_dir="./pacts", log_dir="./logs")
try:
print('start service')
pact.start_service()
yield pact
finally:
print('stop service')
pact.stop_service()
def test_get_product(pact, consumer):
expected = {
'id': "27",
'name': 'Margharita',
'type': 'Pizza'
}
(pact
.given('a product with ID 10 exists')
.upon_receiving('a request to get a product')
.with_request('GET', '/product/10')
.will_respond_with(200, body=Like(expected)))
with pact:
user = consumer.get_product('10')
assert user.name == 'Margharita'

Module not found: Error: Can't resolve './firebase' in 'C:

I'm getting this error in my vuejs webApp, hope some one tell me how to solve it:
./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?
type=script&index=0!./src/components/Envio.vue
Module not found: Error: Can't resolve './firebase' in
'C:\Users\#####\Desktop\#####\src\components'
# ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?
type=script&index=0!./src/components/Envio.vue 17:0-32
# ./src/components/Envio.vue
# ./src/routes.js
# ./src/main.js
# multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-
server ./src/main.js
this is the script in my vue file:
<script>
import { db } from './firebase'
export default {
data: {
mensaje: null,
... }
}
</script>
I assume you have installed firebase via a node package manager using npm command. If so, the following import statement should fix the problem.
import { db } from 'firebase'

Resources