netlify-cli 16.7.0 → 16.8.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 +10 -0
- package/npm-shrinkwrap.json +16123 -10639
- package/package.json +6 -4
- package/src/commands/build/build.mjs +4 -2
- package/src/commands/deploy/deploy.mjs +11 -3
- package/src/commands/integration/deploy.mjs +397 -0
- package/src/commands/integration/index.mjs +25 -0
- package/src/commands/main.mjs +2 -0
- package/src/lib/build.mjs +3 -1
- package/src/lib/edge-functions/consts.mjs +1 -0
- package/src/lib/edge-functions/proxy.mjs +1 -2
- package/src/lib/edge-functions/registry.mjs +15 -19
- package/src/lib/functions/registry.mjs +31 -4
- package/src/lib/functions/server.mjs +15 -0
- package/src/functions-templates/javascript/apollo-graphql/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/apollo-graphql/package.json +0 -21
- package/src/functions-templates/javascript/apollo-graphql/{{name}}.js +0 -42
- package/src/functions-templates/javascript/apollo-graphql-rest/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/apollo-graphql-rest/package.json +0 -22
- package/src/functions-templates/javascript/apollo-graphql-rest/random-user.js +0 -23
- package/src/functions-templates/javascript/apollo-graphql-rest/{{name}}.js +0 -68
- package/src/functions-templates/javascript/auth-fetch/.netlify-function-template.mjs +0 -11
- package/src/functions-templates/javascript/auth-fetch/package-lock.json +0 -83
- package/src/functions-templates/javascript/auth-fetch/package.json +0 -21
- package/src/functions-templates/javascript/auth-fetch/{{name}}.js +0 -39
- package/src/functions-templates/javascript/create-user/.netlify-function-template.mjs +0 -11
- package/src/functions-templates/javascript/create-user/package.json +0 -21
- package/src/functions-templates/javascript/create-user/{{name}}.js +0 -36
- package/src/functions-templates/javascript/fauna-crud/.netlify-function-template.mjs +0 -17
- package/src/functions-templates/javascript/fauna-crud/create-schema.js +0 -36
- package/src/functions-templates/javascript/fauna-crud/create.js +0 -37
- package/src/functions-templates/javascript/fauna-crud/delete.js +0 -29
- package/src/functions-templates/javascript/fauna-crud/package.json +0 -20
- package/src/functions-templates/javascript/fauna-crud/read-all.js +0 -33
- package/src/functions-templates/javascript/fauna-crud/read.js +0 -30
- package/src/functions-templates/javascript/fauna-crud/update.js +0 -30
- package/src/functions-templates/javascript/fauna-crud/{{name}}.js +0 -62
- package/src/functions-templates/javascript/fauna-graphql/.netlify-function-template.mjs +0 -17
- package/src/functions-templates/javascript/fauna-graphql/package.json +0 -26
- package/src/functions-templates/javascript/fauna-graphql/schema.graphql +0 -8
- package/src/functions-templates/javascript/fauna-graphql/sync-schema.js +0 -38
- package/src/functions-templates/javascript/fauna-graphql/{{name}}.js +0 -46
- package/src/functions-templates/javascript/google-analytics/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/google-analytics/package-lock.json +0 -100
- package/src/functions-templates/javascript/google-analytics/package.json +0 -25
- package/src/functions-templates/javascript/google-analytics/{{name}}.js +0 -114
- package/src/functions-templates/javascript/graphql-gateway/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/graphql-gateway/example-sibling-function-graphql-1.js +0 -42
- package/src/functions-templates/javascript/graphql-gateway/example-sibling-function-graphql-2.js +0 -80
- package/src/functions-templates/javascript/graphql-gateway/package.json +0 -24
- package/src/functions-templates/javascript/graphql-gateway/{{name}}.js +0 -75
- package/src/functions-templates/javascript/hasura-event-triggered/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/hasura-event-triggered/package.json +0 -21
- package/src/functions-templates/javascript/hasura-event-triggered/{{name}}.js +0 -40
- package/src/functions-templates/javascript/node-fetch/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/node-fetch/package.json +0 -19
- package/src/functions-templates/javascript/node-fetch/{{name}}.js +0 -29
- package/src/functions-templates/javascript/oauth-passport/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/oauth-passport/package.json +0 -25
- package/src/functions-templates/javascript/oauth-passport/utils/auth.js +0 -65
- package/src/functions-templates/javascript/oauth-passport/utils/config.js +0 -24
- package/src/functions-templates/javascript/oauth-passport/{{name}}.js +0 -37
- package/src/functions-templates/javascript/protected-function/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/protected-function/{{name}}.js +0 -25
- package/src/functions-templates/javascript/send-email/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/send-email/package.json +0 -21
- package/src/functions-templates/javascript/send-email/validations.js +0 -38
- package/src/functions-templates/javascript/send-email/{{name}}.js +0 -68
- package/src/functions-templates/javascript/serverless-ssr/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/serverless-ssr/app/index.js +0 -116
- package/src/functions-templates/javascript/serverless-ssr/package.json +0 -24
- package/src/functions-templates/javascript/serverless-ssr/serverless-http.js +0 -15
- package/src/functions-templates/javascript/serverless-ssr/{{name}}.js +0 -15
- package/src/functions-templates/javascript/set-cookie/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/set-cookie/package.json +0 -19
- package/src/functions-templates/javascript/set-cookie/{{name}}.js +0 -44
- package/src/functions-templates/javascript/slack-rate-limit/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/slack-rate-limit/package.json +0 -20
- package/src/functions-templates/javascript/slack-rate-limit/{{name}}.js +0 -115
- package/src/functions-templates/javascript/stripe-charge/.netlify-function-template.mjs +0 -28
- package/src/functions-templates/javascript/stripe-charge/package-lock.json +0 -196
- package/src/functions-templates/javascript/stripe-charge/package.json +0 -21
- package/src/functions-templates/javascript/stripe-charge/{{name}}.js +0 -56
- package/src/functions-templates/javascript/stripe-subscription/.netlify-function-template.mjs +0 -28
- package/src/functions-templates/javascript/stripe-subscription/package-lock.json +0 -196
- package/src/functions-templates/javascript/stripe-subscription/package.json +0 -21
- package/src/functions-templates/javascript/stripe-subscription/{{name}}.js +0 -52
- package/src/functions-templates/javascript/token-hider/.netlify-function-template.mjs +0 -29
- package/src/functions-templates/javascript/token-hider/package-lock.json +0 -317
- package/src/functions-templates/javascript/token-hider/package.json +0 -21
- package/src/functions-templates/javascript/token-hider/{{name}}.js +0 -37
- package/src/functions-templates/javascript/url-shortener/.netlify-function-template.mjs +0 -29
- package/src/functions-templates/javascript/url-shortener/generate-route.js +0 -53
- package/src/functions-templates/javascript/url-shortener/get-route.js +0 -32
- package/src/functions-templates/javascript/url-shortener/package-lock.json +0 -126
- package/src/functions-templates/javascript/url-shortener/package.json +0 -22
- package/src/functions-templates/javascript/url-shortener/{{name}}.js +0 -30
- package/src/functions-templates/javascript/using-middleware/.netlify-function-template.mjs +0 -5
- package/src/functions-templates/javascript/using-middleware/package.json +0 -19
- package/src/functions-templates/javascript/using-middleware/{{name}}.js +0 -60
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import { mkdir } from 'fs/promises'
|
|
2
|
+
import { mkdir, stat } from 'fs/promises'
|
|
3
3
|
import { createRequire } from 'module'
|
|
4
4
|
import { basename, extname, isAbsolute, join, resolve } from 'path'
|
|
5
5
|
import { env } from 'process'
|
|
@@ -39,6 +39,7 @@ export class FunctionsRegistry {
|
|
|
39
39
|
debug = false,
|
|
40
40
|
isConnected = false,
|
|
41
41
|
logLambdaCompat,
|
|
42
|
+
manifest,
|
|
42
43
|
projectRoot,
|
|
43
44
|
settings,
|
|
44
45
|
timeouts,
|
|
@@ -96,6 +97,14 @@ export class FunctionsRegistry {
|
|
|
96
97
|
* @type {boolean}
|
|
97
98
|
*/
|
|
98
99
|
this.logLambdaCompat = Boolean(logLambdaCompat)
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Contents of a `manifest.json` file that can be looked up when dealing
|
|
103
|
+
* with built functions.
|
|
104
|
+
*
|
|
105
|
+
* @type {object}
|
|
106
|
+
*/
|
|
107
|
+
this.manifest = manifest
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
checkTypesPackage() {
|
|
@@ -390,12 +399,30 @@ export class FunctionsRegistry {
|
|
|
390
399
|
FunctionsRegistry.logEvent('extracted', { func })
|
|
391
400
|
}
|
|
392
401
|
|
|
393
|
-
|
|
402
|
+
// If there's a manifest file, look up the function in order to extract
|
|
403
|
+
// the build data.
|
|
404
|
+
const manifestEntry = (this.manifest?.functions || []).find((manifestFunc) => manifestFunc.name === func.name)
|
|
405
|
+
|
|
406
|
+
func.buildData = manifestEntry?.buildData || {}
|
|
407
|
+
|
|
408
|
+
// When we look at an unzipped function, we don't know whether it uses
|
|
409
|
+
// the legacy entry file format (i.e. `[function name].js`) or the new
|
|
410
|
+
// one (i.e. `___netlify-entry-point.mjs`). Let's look for the new one
|
|
411
|
+
// and use it if it exists, otherwise use the old one.
|
|
412
|
+
try {
|
|
413
|
+
const v2EntryPointPath = join(unzippedDirectory, '___netlify-entry-point.mjs')
|
|
414
|
+
|
|
415
|
+
await stat(v2EntryPointPath)
|
|
416
|
+
|
|
417
|
+
func.mainFile = v2EntryPointPath
|
|
418
|
+
} catch {
|
|
419
|
+
func.mainFile = join(unzippedDirectory, `${func.name}.js`)
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
this.buildFunctionAndWatchFiles(func, !isReload)
|
|
394
423
|
}
|
|
395
424
|
|
|
396
425
|
this.functions.set(name, func)
|
|
397
|
-
|
|
398
|
-
this.buildFunctionAndWatchFiles(func, !isReload)
|
|
399
426
|
}
|
|
400
427
|
|
|
401
428
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { Buffer } from 'buffer'
|
|
3
3
|
import { promises as fs } from 'fs'
|
|
4
|
+
import path from 'path'
|
|
4
5
|
|
|
5
6
|
import express from 'express'
|
|
6
7
|
import expressLogging from 'express-logging'
|
|
@@ -261,6 +262,7 @@ export const startFunctionsServer = async (options) => {
|
|
|
261
262
|
options
|
|
262
263
|
const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root })
|
|
263
264
|
const functionsDirectories = []
|
|
265
|
+
let manifest
|
|
264
266
|
|
|
265
267
|
// If the `loadDistFunctions` parameter is sent, the functions server will
|
|
266
268
|
// use the built functions created by zip-it-and-ship-it rather than building
|
|
@@ -270,6 +272,18 @@ export const startFunctionsServer = async (options) => {
|
|
|
270
272
|
|
|
271
273
|
if (distPath) {
|
|
272
274
|
functionsDirectories.push(distPath)
|
|
275
|
+
|
|
276
|
+
// When using built functions, read the manifest file so that we can
|
|
277
|
+
// extract metadata such as routes and API version.
|
|
278
|
+
try {
|
|
279
|
+
const manifestPath = path.join(distPath, 'manifest.json')
|
|
280
|
+
// eslint-disable-next-line unicorn/prefer-json-parse-buffer
|
|
281
|
+
const data = await fs.readFile(manifestPath, 'utf8')
|
|
282
|
+
|
|
283
|
+
manifest = JSON.parse(data)
|
|
284
|
+
} catch {
|
|
285
|
+
// no-op
|
|
286
|
+
}
|
|
273
287
|
}
|
|
274
288
|
} else {
|
|
275
289
|
// The order of the function directories matters. Rightmost directories take
|
|
@@ -297,6 +311,7 @@ export const startFunctionsServer = async (options) => {
|
|
|
297
311
|
debug,
|
|
298
312
|
isConnected: Boolean(siteUrl),
|
|
299
313
|
logLambdaCompat: isFeatureFlagEnabled('cli_log_lambda_compat', siteInfo),
|
|
314
|
+
manifest,
|
|
300
315
|
// functions always need to be inside the packagePath if set inside a monorepo
|
|
301
316
|
projectRoot: command.workingDir,
|
|
302
317
|
settings,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "apollo-graphql",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - set up for apollo graphql",
|
|
5
|
-
"main": "apollo-graphql.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js",
|
|
13
|
-
"apollo"
|
|
14
|
-
],
|
|
15
|
-
"author": "Netlify",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"apollo-server-lambda": "^2.18.2",
|
|
19
|
-
"graphql": "^14.1.1"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const { ApolloServer, gql } = require('apollo-server-lambda')
|
|
2
|
-
|
|
3
|
-
const typeDefs = gql`
|
|
4
|
-
type Query {
|
|
5
|
-
hello: String
|
|
6
|
-
allAuthors: [Author!]
|
|
7
|
-
author(id: Int!): Author
|
|
8
|
-
authorByName(name: String!): Author
|
|
9
|
-
}
|
|
10
|
-
type Author {
|
|
11
|
-
id: ID!
|
|
12
|
-
name: String!
|
|
13
|
-
married: Boolean!
|
|
14
|
-
}
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
const authors = [
|
|
18
|
-
{ id: 1, name: 'Terry Pratchett', married: false },
|
|
19
|
-
{ id: 2, name: 'Stephen King', married: true },
|
|
20
|
-
{ id: 3, name: 'JK Rowling', married: false },
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
const resolvers = {
|
|
24
|
-
Query: {
|
|
25
|
-
hello: () => 'Hello, world!',
|
|
26
|
-
allAuthors: () => authors,
|
|
27
|
-
author: () => {},
|
|
28
|
-
authorByName: (root, args) => {
|
|
29
|
-
console.log('hihhihi', args.name)
|
|
30
|
-
return authors.find((author) => author.name === args.name) || 'NOTFOUND'
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const server = new ApolloServer({
|
|
36
|
-
typeDefs,
|
|
37
|
-
resolvers,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const handler = server.createHandler()
|
|
41
|
-
|
|
42
|
-
module.exports = { handler }
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "apollo-graphql-rest",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - GraphQL function to wrap REST API using apollo-server-lambda and apollo-datasource-rest!",
|
|
5
|
-
"main": "apollo-graphql-rest.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js",
|
|
13
|
-
"apollo"
|
|
14
|
-
],
|
|
15
|
-
"author": "Netlify",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"apollo-server-lambda": "^2.18.2",
|
|
19
|
-
"apollo-datasource-rest": "^0.15.0",
|
|
20
|
-
"graphql": "^14.1.1"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { RESTDataSource } = require('apollo-datasource-rest')
|
|
2
|
-
|
|
3
|
-
class RandomUser extends RESTDataSource {
|
|
4
|
-
constructor() {
|
|
5
|
-
super()
|
|
6
|
-
this.baseURL = 'https://randomuser.me/api'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async getUser(gender = DEFAULT_GENDER) {
|
|
10
|
-
const user = await this.get(`/?gender=${gender}`)
|
|
11
|
-
return user.results[0]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getUsers(people = DEFAULT_PEOPLE_COUNT, gender = DEFAULT_GENDER) {
|
|
15
|
-
const user = await this.get(`/?results=${people}&gender=${gender}`)
|
|
16
|
-
return user.results
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const DEFAULT_PEOPLE_COUNT = 10
|
|
21
|
-
const DEFAULT_GENDER = 'all'
|
|
22
|
-
|
|
23
|
-
module.exports = RandomUser
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { ApolloServer, gql } = require('apollo-server-lambda')
|
|
2
|
-
|
|
3
|
-
const RandomUser = require('./random-user.js')
|
|
4
|
-
// example from: https://medium.com/yld-engineering-blog/easier-graphql-wrappers-for-your-rest-apis-1410b0b5446d
|
|
5
|
-
|
|
6
|
-
const typeDefs = gql`
|
|
7
|
-
"""
|
|
8
|
-
Example Description for Name Type
|
|
9
|
-
|
|
10
|
-
It's multiline and you can use **markdown**! [more docs](https://www.apollographql.com/docs/apollo-server/essentials/schema#documentation)!
|
|
11
|
-
"""
|
|
12
|
-
type Name {
|
|
13
|
-
"Description for first"
|
|
14
|
-
title: String
|
|
15
|
-
"Description for title"
|
|
16
|
-
first: String
|
|
17
|
-
"Description for last"
|
|
18
|
-
last: String
|
|
19
|
-
}
|
|
20
|
-
type Location {
|
|
21
|
-
street: String
|
|
22
|
-
city: String
|
|
23
|
-
state: String
|
|
24
|
-
postcode: String
|
|
25
|
-
}
|
|
26
|
-
type Picture {
|
|
27
|
-
large: String
|
|
28
|
-
medium: String
|
|
29
|
-
thumbnail: String
|
|
30
|
-
}
|
|
31
|
-
type User {
|
|
32
|
-
gender: String
|
|
33
|
-
name: Name
|
|
34
|
-
location: Location
|
|
35
|
-
email: String
|
|
36
|
-
phone: String
|
|
37
|
-
cell: String
|
|
38
|
-
picture: Picture
|
|
39
|
-
nat: String
|
|
40
|
-
}
|
|
41
|
-
type Query {
|
|
42
|
-
"""
|
|
43
|
-
Example Description for getUser
|
|
44
|
-
|
|
45
|
-
It's multiline and you can use **markdown**!
|
|
46
|
-
"""
|
|
47
|
-
getUser(gender: String): User
|
|
48
|
-
getUsers(people: Int, gender: String): [User]
|
|
49
|
-
}
|
|
50
|
-
`
|
|
51
|
-
const resolvers = {
|
|
52
|
-
Query: {
|
|
53
|
-
getUser: async (_, { gender }, { dataSources }) => dataSources.RandomUser.getUser(gender),
|
|
54
|
-
getUsers: async (_, { gender, people }, { dataSources }) => dataSources.RandomUser.getUsers(people, gender),
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const server = new ApolloServer({
|
|
59
|
-
typeDefs,
|
|
60
|
-
resolvers,
|
|
61
|
-
dataSources: () => ({
|
|
62
|
-
RandomUser: new RandomUser(),
|
|
63
|
-
}),
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const handler = server.createHandler()
|
|
67
|
-
|
|
68
|
-
module.exports = { handler }
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'auth-fetch',
|
|
3
|
-
description: 'Use `node-fetch` library and Netlify Identity to access APIs',
|
|
4
|
-
functionType: 'serverless',
|
|
5
|
-
onComplete() {
|
|
6
|
-
console.log(`auth-fetch function created from template!`)
|
|
7
|
-
console.log(
|
|
8
|
-
'REMINDER: Make sure to call this function with the Netlify Identity JWT. See https://netlify-gotrue-in-react.netlify.com/ for demo',
|
|
9
|
-
)
|
|
10
|
-
},
|
|
11
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "auth-fetch",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"lockfileVersion": 2,
|
|
5
|
-
"requires": true,
|
|
6
|
-
"packages": {
|
|
7
|
-
"": {
|
|
8
|
-
"name": "auth-fetch",
|
|
9
|
-
"version": "1.0.0",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"node-fetch": "^2.3.0"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"node_modules/node-fetch": {
|
|
16
|
-
"version": "2.6.12",
|
|
17
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
18
|
-
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"whatwg-url": "^5.0.0"
|
|
21
|
-
},
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": "4.x || >=6.0.0"
|
|
24
|
-
},
|
|
25
|
-
"peerDependencies": {
|
|
26
|
-
"encoding": "^0.1.0"
|
|
27
|
-
},
|
|
28
|
-
"peerDependenciesMeta": {
|
|
29
|
-
"encoding": {
|
|
30
|
-
"optional": true
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"node_modules/tr46": {
|
|
35
|
-
"version": "0.0.3",
|
|
36
|
-
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
|
37
|
-
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
|
|
38
|
-
},
|
|
39
|
-
"node_modules/webidl-conversions": {
|
|
40
|
-
"version": "3.0.1",
|
|
41
|
-
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
|
42
|
-
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
|
|
43
|
-
},
|
|
44
|
-
"node_modules/whatwg-url": {
|
|
45
|
-
"version": "5.0.0",
|
|
46
|
-
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
|
47
|
-
"integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"tr46": "~0.0.3",
|
|
50
|
-
"webidl-conversions": "^3.0.0"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"node-fetch": {
|
|
56
|
-
"version": "2.6.12",
|
|
57
|
-
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
|
58
|
-
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
|
59
|
-
"requires": {
|
|
60
|
-
"whatwg-url": "^5.0.0"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"tr46": {
|
|
64
|
-
"version": "0.0.3",
|
|
65
|
-
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
|
66
|
-
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
|
|
67
|
-
},
|
|
68
|
-
"webidl-conversions": {
|
|
69
|
-
"version": "3.0.1",
|
|
70
|
-
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
|
71
|
-
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
|
|
72
|
-
},
|
|
73
|
-
"whatwg-url": {
|
|
74
|
-
"version": "5.0.0",
|
|
75
|
-
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
|
76
|
-
"integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
|
|
77
|
-
"requires": {
|
|
78
|
-
"tr46": "~0.0.3",
|
|
79
|
-
"webidl-conversions": "^3.0.0"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "auth-fetch",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - default template for auth fetch function",
|
|
5
|
-
"main": "auth-fetch.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js",
|
|
13
|
-
"identity",
|
|
14
|
-
"authentication"
|
|
15
|
-
],
|
|
16
|
-
"author": "Netlify",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"node-fetch": "^2.3.0"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// for a full working demo of Netlify Identity + Functions, see https://netlify-gotrue-in-react.netlify.com/
|
|
2
|
-
|
|
3
|
-
const fetch = require('node-fetch')
|
|
4
|
-
|
|
5
|
-
const handler = async function (event, context) {
|
|
6
|
-
if (!context.clientContext && !context.clientContext.identity) {
|
|
7
|
-
return {
|
|
8
|
-
statusCode: 500,
|
|
9
|
-
// Could be a custom message or object i.e. JSON.stringify(err)
|
|
10
|
-
body: JSON.stringify({
|
|
11
|
-
msg: 'No identity instance detected. Did you enable it?',
|
|
12
|
-
}),
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const { identity, user } = context.clientContext
|
|
16
|
-
try {
|
|
17
|
-
const response = await fetch('https://api.chucknorris.io/jokes/random')
|
|
18
|
-
if (!response.ok) {
|
|
19
|
-
// NOT res.status >= 200 && res.status < 300
|
|
20
|
-
return { statusCode: response.status, body: response.statusText }
|
|
21
|
-
}
|
|
22
|
-
const data = await response.json()
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
statusCode: 200,
|
|
26
|
-
body: JSON.stringify({ identity, user, msg: data.value }),
|
|
27
|
-
}
|
|
28
|
-
} catch (error) {
|
|
29
|
-
// output to netlify function log
|
|
30
|
-
console.log(error)
|
|
31
|
-
return {
|
|
32
|
-
statusCode: 500,
|
|
33
|
-
// Could be a custom message or object i.e. JSON.stringify(err)
|
|
34
|
-
body: JSON.stringify({ msg: error.message }),
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = { handler }
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'create-user',
|
|
3
|
-
description: 'Programmatically create a Netlify Identity user by invoking a function',
|
|
4
|
-
functionType: 'serverless',
|
|
5
|
-
onComplete() {
|
|
6
|
-
console.log(`create-user function created from template!`)
|
|
7
|
-
console.log(
|
|
8
|
-
'REMINDER: Make sure to call this function with a Netlify Identity JWT. See https://netlify-gotrue-in-react.netlify.com/ for demo',
|
|
9
|
-
)
|
|
10
|
-
},
|
|
11
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "create-user",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - Programmatically create a Netlify Identity user by invoking a function",
|
|
5
|
-
"main": "create-user.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js",
|
|
13
|
-
"identity",
|
|
14
|
-
"authentication"
|
|
15
|
-
],
|
|
16
|
-
"author": "Netlify",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"node-fetch": "^2.6.1"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const fetch = require('node-fetch')
|
|
2
|
-
|
|
3
|
-
const handler = async (event, context) => {
|
|
4
|
-
if (event.httpMethod !== 'POST') return { statusCode: 400, body: 'Must POST to this function' }
|
|
5
|
-
|
|
6
|
-
// send account information along with the POST
|
|
7
|
-
const { email, full_name: fullName, password } = JSON.parse(event.body)
|
|
8
|
-
if (!email) return { statusCode: 400, body: 'email missing' }
|
|
9
|
-
if (!password) return { statusCode: 400, body: 'password missing' }
|
|
10
|
-
if (!fullName) return { statusCode: 400, body: 'full_name missing' }
|
|
11
|
-
|
|
12
|
-
// identity.token is a short lived admin token which
|
|
13
|
-
// is provided to all Netlify Functions to interact
|
|
14
|
-
// with the Identity API
|
|
15
|
-
const { identity } = context.clientContext
|
|
16
|
-
|
|
17
|
-
await fetch(`${identity.url}/admin/users`, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
headers: { Authorization: `Bearer ${identity.token}` },
|
|
20
|
-
body: JSON.stringify({
|
|
21
|
-
email,
|
|
22
|
-
password,
|
|
23
|
-
confirm: true,
|
|
24
|
-
user_metadata: {
|
|
25
|
-
full_name: fullName,
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
statusCode: 200,
|
|
32
|
-
body: 'success!',
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = { handler }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import execa from 'execa'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: 'fauna-crud',
|
|
5
|
-
description: 'CRUD function using Fauna DB',
|
|
6
|
-
functionType: 'serverless',
|
|
7
|
-
addons: [
|
|
8
|
-
{
|
|
9
|
-
addonName: 'fauna',
|
|
10
|
-
addonDidInstall(fnPath) {
|
|
11
|
-
execa.sync(fnPath + '/create-schema.js', undefined, {
|
|
12
|
-
stdio: 'inherit',
|
|
13
|
-
})
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const process = require('process')
|
|
3
|
-
|
|
4
|
-
/* bootstrap database in your FaunaDB account - use with `netlify dev:exec <path-to-this-file>` */
|
|
5
|
-
const { Client, query } = require('faunadb')
|
|
6
|
-
|
|
7
|
-
const createFaunaDB = async function () {
|
|
8
|
-
if (!process.env.FAUNADB_SERVER_SECRET) {
|
|
9
|
-
console.log('No FAUNADB_SERVER_SECRET in environment, skipping DB setup')
|
|
10
|
-
}
|
|
11
|
-
console.log('Create the database!')
|
|
12
|
-
const client = new Client({
|
|
13
|
-
secret: process.env.FAUNADB_SERVER_SECRET,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
/* Based on your requirements, change the schema here */
|
|
17
|
-
try {
|
|
18
|
-
await client.query(query.CreateCollection({ name: 'items' }))
|
|
19
|
-
|
|
20
|
-
console.log('Created items class')
|
|
21
|
-
return await client.query(
|
|
22
|
-
query.CreateIndex({
|
|
23
|
-
name: 'all_items',
|
|
24
|
-
source: query.Collection('items'),
|
|
25
|
-
active: true,
|
|
26
|
-
}),
|
|
27
|
-
)
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (error.requestResult.statusCode === 400 && error.message === 'instance not unique') {
|
|
30
|
-
console.log('DB already exists')
|
|
31
|
-
}
|
|
32
|
-
throw error
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
createFaunaDB()
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const process = require('process')
|
|
2
|
-
|
|
3
|
-
const { Client, query } = require('faunadb')
|
|
4
|
-
|
|
5
|
-
/* configure faunaDB Client with our secret */
|
|
6
|
-
const client = new Client({
|
|
7
|
-
secret: process.env.FAUNADB_SERVER_SECRET,
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
/* export our lambda function as named "handler" export */
|
|
11
|
-
const handler = async (event) => {
|
|
12
|
-
/* parse the string body into a useable JS object */
|
|
13
|
-
const data = JSON.parse(event.body)
|
|
14
|
-
console.log('Function `create` invoked', data)
|
|
15
|
-
const item = {
|
|
16
|
-
data,
|
|
17
|
-
}
|
|
18
|
-
/* construct the fauna query */
|
|
19
|
-
try {
|
|
20
|
-
const response = await client.query(query.Create(query.Collection('items'), item))
|
|
21
|
-
console.log('success', response)
|
|
22
|
-
/* Success! return the response with statusCode 200 */
|
|
23
|
-
return {
|
|
24
|
-
statusCode: 200,
|
|
25
|
-
body: JSON.stringify(response),
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.log('error', error)
|
|
29
|
-
/* Error! return the error with statusCode 400 */
|
|
30
|
-
return {
|
|
31
|
-
statusCode: 400,
|
|
32
|
-
body: JSON.stringify(error),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = { handler }
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* Import faunaDB sdk */
|
|
2
|
-
const process = require('process')
|
|
3
|
-
|
|
4
|
-
const { Client, query } = require('faunadb')
|
|
5
|
-
|
|
6
|
-
const client = new Client({
|
|
7
|
-
secret: process.env.FAUNADB_SERVER_SECRET,
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
const handler = async (event) => {
|
|
11
|
-
const { id } = event
|
|
12
|
-
console.log(`Function 'delete' invoked. delete id: ${id}`)
|
|
13
|
-
try {
|
|
14
|
-
const response = await client.query(query.Delete(query.Ref(query.Collection('items'), id)))
|
|
15
|
-
console.log('success', response)
|
|
16
|
-
return {
|
|
17
|
-
statusCode: 200,
|
|
18
|
-
body: JSON.stringify(response),
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.log('error', error)
|
|
22
|
-
return {
|
|
23
|
-
statusCode: 400,
|
|
24
|
-
body: JSON.stringify(error),
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { handler }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "fauna-crud",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - CRUD functionality with Fauna DB",
|
|
5
|
-
"main": "fauna-crud.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js",
|
|
13
|
-
"faunadb"
|
|
14
|
-
],
|
|
15
|
-
"author": "Netlify",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"faunadb": "^4.0.3"
|
|
19
|
-
}
|
|
20
|
-
}
|