netlify-cli 16.6.2 → 16.8.0
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/npm-shrinkwrap.json +366 -1042
- package/package.json +4 -4
- 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/utils/deploy/hash-fns.mjs +9 -3
- 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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netlify-cli",
|
|
3
3
|
"description": "Netlify command line tool",
|
|
4
|
-
"version": "16.
|
|
4
|
+
"version": "16.8.0",
|
|
5
5
|
"author": "Netlify Inc.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@bugsnag/js": "7.20.2",
|
|
46
46
|
"@fastify/static": "6.10.2",
|
|
47
|
-
"@netlify/build": "29.
|
|
47
|
+
"@netlify/build": "29.23.1",
|
|
48
48
|
"@netlify/build-info": "7.10.1",
|
|
49
49
|
"@netlify/config": "20.9.0",
|
|
50
|
-
"@netlify/edge-bundler": "9.
|
|
50
|
+
"@netlify/edge-bundler": "9.3.0",
|
|
51
51
|
"@netlify/local-functions-proxy": "1.1.1",
|
|
52
52
|
"@netlify/serverless-functions-api": "1.9.1",
|
|
53
|
-
"@netlify/zip-it-and-ship-it": "9.
|
|
53
|
+
"@netlify/zip-it-and-ship-it": "9.25.1",
|
|
54
54
|
"@octokit/rest": "19.0.13",
|
|
55
55
|
"ansi-escapes": "6.2.0",
|
|
56
56
|
"ansi-styles": "6.2.1",
|
package/src/lib/build.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import process from 'process'
|
|
|
3
3
|
|
|
4
4
|
import build from '@netlify/build'
|
|
5
5
|
|
|
6
|
+
import { isFeatureFlagEnabled } from '../utils/feature-flags.mjs'
|
|
7
|
+
|
|
6
8
|
import { getBootstrapURL } from './edge-functions/bootstrap.mjs'
|
|
7
9
|
import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.mjs'
|
|
8
10
|
|
|
@@ -58,7 +60,7 @@ export const getBuildOptions = ({
|
|
|
58
60
|
const getFeatureFlagsFromSiteInfo = (siteInfo) => ({
|
|
59
61
|
...siteInfo.feature_flags,
|
|
60
62
|
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
|
|
61
|
-
zisi_golang_use_al2:
|
|
63
|
+
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
|
|
62
64
|
})
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -8,7 +8,6 @@ import * as bundler from '@netlify/edge-bundler'
|
|
|
8
8
|
import getAvailablePort from 'get-port'
|
|
9
9
|
|
|
10
10
|
import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
|
|
11
|
-
import { isFeatureFlagEnabled } from '../../utils/feature-flags.mjs'
|
|
12
11
|
import { getGeoLocation } from '../geo-location.mjs'
|
|
13
12
|
import { getPathInProject } from '../settings.mjs'
|
|
14
13
|
import { startSpinner, stopSpinner } from '../spinner.mjs'
|
|
@@ -110,7 +109,7 @@ export const initializeProxy = async ({
|
|
|
110
109
|
const userFunctionsPath = config.build.edge_functions
|
|
111
110
|
const isolatePort = await getAvailablePort()
|
|
112
111
|
const buildFeatureFlags = {
|
|
113
|
-
edge_functions_npm_modules:
|
|
112
|
+
edge_functions_npm_modules: true,
|
|
114
113
|
}
|
|
115
114
|
const runtimeFeatureFlags = ['edge_functions_bootstrap_failure_mode']
|
|
116
115
|
|
|
@@ -40,9 +40,6 @@ export class EdgeFunctionsRegistry {
|
|
|
40
40
|
/** @type {RunIsolate} */
|
|
41
41
|
#runIsolate
|
|
42
42
|
|
|
43
|
-
/** @type {boolean} */
|
|
44
|
-
#hasShownNPMWarning = false
|
|
45
|
-
|
|
46
43
|
/** @type {Error | null} */
|
|
47
44
|
#buildError = null
|
|
48
45
|
|
|
@@ -167,22 +164,13 @@ export class EdgeFunctionsRegistry {
|
|
|
167
164
|
*/
|
|
168
165
|
async #build() {
|
|
169
166
|
try {
|
|
170
|
-
const {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
if (features.npmModules && !this.#hasShownNPMWarning) {
|
|
180
|
-
log(
|
|
181
|
-
`${NETLIFYDEVWARN} Support for npm modules in edge functions is an experimental feature. To learn more about the current state of this capability or to report a problem, refer to https://ntl.fyi/edge-functions-npm.`,
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
this.#hasShownNPMWarning = true
|
|
185
|
-
}
|
|
167
|
+
const { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success } = await this.#runIsolate(
|
|
168
|
+
this.#functions,
|
|
169
|
+
this.#env,
|
|
170
|
+
{
|
|
171
|
+
getFunctionsConfig: true,
|
|
172
|
+
},
|
|
173
|
+
)
|
|
186
174
|
|
|
187
175
|
if (!success) {
|
|
188
176
|
throw new Error('Build error')
|
|
@@ -207,6 +195,14 @@ export class EdgeFunctionsRegistry {
|
|
|
207
195
|
)
|
|
208
196
|
|
|
209
197
|
this.#processGraph(graph)
|
|
198
|
+
|
|
199
|
+
if (npmSpecifiersWithExtraneousFiles.length !== 0) {
|
|
200
|
+
const modules = npmSpecifiersWithExtraneousFiles.map((name) => chalk.yellow(name)).join(', ')
|
|
201
|
+
|
|
202
|
+
log(
|
|
203
|
+
`${NETLIFYDEVWARN} The following npm modules, which are directly or indirectly imported by an edge function, may not be supported: ${modules}. For more information, visit https://ntl.fyi/edge-functions-npm.`,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
210
206
|
} catch (error) {
|
|
211
207
|
this.#buildError = error
|
|
212
208
|
|
|
@@ -107,7 +107,7 @@ const hashFns = async (
|
|
|
107
107
|
tmpDir,
|
|
108
108
|
})
|
|
109
109
|
const fileObjs = functionZips.map(
|
|
110
|
-
({ displayName, generator, invocationMode, path: functionPath, runtime, runtimeVersion }) => ({
|
|
110
|
+
({ buildData, displayName, generator, invocationMode, path: functionPath, runtime, runtimeVersion }) => ({
|
|
111
111
|
filepath: functionPath,
|
|
112
112
|
root: tmpDir,
|
|
113
113
|
relname: path.relative(tmpDir, functionPath),
|
|
@@ -120,14 +120,20 @@ const hashFns = async (
|
|
|
120
120
|
displayName,
|
|
121
121
|
generator,
|
|
122
122
|
invocationMode,
|
|
123
|
+
buildData,
|
|
123
124
|
}),
|
|
124
125
|
)
|
|
125
126
|
const fnConfig = functionZips
|
|
126
|
-
.filter((func) => Boolean(func.displayName || func.generator || func.routes))
|
|
127
|
+
.filter((func) => Boolean(func.displayName || func.generator || func.routes || func.buildData))
|
|
127
128
|
.reduce(
|
|
128
129
|
(funcs, curr) => ({
|
|
129
130
|
...funcs,
|
|
130
|
-
[curr.name]: {
|
|
131
|
+
[curr.name]: {
|
|
132
|
+
display_name: curr.displayName,
|
|
133
|
+
generator: curr.generator,
|
|
134
|
+
routes: curr.routes,
|
|
135
|
+
build_data: curr.buildData,
|
|
136
|
+
},
|
|
131
137
|
}),
|
|
132
138
|
{},
|
|
133
139
|
)
|
|
@@ -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 }
|