-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
95 lines (86 loc) · 2.98 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { NodePlatform } from "@storecraft/core/platform/node"
import { MongoDB } from "@storecraft/database-mongodb"
import { MongoVectorSearch } from "@storecraft/database-mongodb/vector-search-extension.js"
import { NodeLocalStorage } from "@storecraft/core/storage/node"
import { Resend } from "@storecraft/mailer-providers-http/resend"
import { Paypal } from "@storecraft/payments-paypal"
import { App } from "@storecraft/core"
import { PostmanExtension } from "@storecraft/core/extensions/postman"
import { DummyPayments } from "@storecraft/core/payments/dummy"
import { embed_text } from "./openai_utils.js"
export const app = new App({
auth_secret_access_token:
"BRqgca7KeIpYkwDE69ORkU8eNbhgn5+qW0TvMdSUErQqjPLQPj07yp6oUZnmXn3RgTWsT32CZZxnctZfIEAACg==",
auth_secret_refresh_token:
"ZZqtAlQrKDL8qVVORBvzYNvkzcjw94Lq10QQlbiF2BNY23iKtvgEYR8mE4MBw7DuieH4Wh4xwKKGwj9I5KoqVA==",
general_store_name: "my-storecraft-app",
auth_admins_emails: ["tomer.shalev@gmail.com"],
general_store_support_email:
"support@storecraft.app",
})
.withPlatform(new NodePlatform({}))
.withDatabase(
new MongoDB({ db_name: "test" }),
)
.withStorage(new NodeLocalStorage("storage"))
.withMailer(new Resend({ apikey: process.env.RESEND }))
.withPaymentGateways({
paypal: new Paypal({
default_currency_code: "USD",
env: "prod",
intent_on_checkout: "AUTHORIZE",
client_id: "*****",
secret: "*****",
}),
dummy: new DummyPayments({default_currency_code: 'USD' })
})
.withExtensions({
postman: new PostmanExtension(),
'mongo-vector-search': new MongoVectorSearch({openai_key: process.env.OPENAI}),
'mongo-vector-search-2': {
info: {
name: 'Mongo Vector Search',
},
onInit: (app) => {
// app.extensions.
app.pubsub.on(
'products/upsert',
async (evt) => {
const product = evt.payload.current;
// @ts-ignore
product.embedding = await embed_text(
`This product's title is ${product.title}, it's price is
${product.price} and has the following description
${product.description}`
);
console.log('Update Product ' + product.handle);
}
)
},
invokeAction: (handle) => {
if (handle==='search') {
/** @param {{query: string}} args */
return async (args) => {
return app.db.collection('products').aggregate(
[
{
"$vectorSearch": {
queryVector: await embed_text(args.query),
path: "embedding",
exact: true,
limit: 1,
index: "vector_index",
},
},
{
"$project": {
embedding: 0, _relations: 0, _id: 0
}
}
],
).toArray();
}
}
}
}
})