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,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "serverless-ssr",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - default template for a serverless SSR function",
|
|
5
|
-
"main": "serverless-ssr.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js"
|
|
13
|
-
],
|
|
14
|
-
"author": "Netlify",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"compression": "^1.7.4",
|
|
18
|
-
"cors": "^2.8.5",
|
|
19
|
-
"express": "^4.17.1",
|
|
20
|
-
"morgan": "^1.10.0",
|
|
21
|
-
"node-fetch": "^2.6.1",
|
|
22
|
-
"serverless-http": "^2.0.0"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// for a full working demo check https://express-via-functions.netlify.com/.netlify/functions/serverless-http
|
|
2
|
-
const serverless = require('serverless-http')
|
|
3
|
-
|
|
4
|
-
const expressApp = require('./app.js')
|
|
5
|
-
|
|
6
|
-
// We need to define our function name for express routes to set the correct base path
|
|
7
|
-
const functionName = 'serverless-http'
|
|
8
|
-
|
|
9
|
-
// Initialize express app
|
|
10
|
-
const app = expressApp(functionName)
|
|
11
|
-
|
|
12
|
-
// Export lambda handler
|
|
13
|
-
const handler = serverless(app)
|
|
14
|
-
|
|
15
|
-
module.exports = { handler }
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// for a full working demo check https://express-via-functions.netlify.com/.netlify/functions/serverless-http
|
|
2
|
-
const serverless = require('serverless-http')
|
|
3
|
-
|
|
4
|
-
const expressApp = require('./app.js')
|
|
5
|
-
|
|
6
|
-
// We need to define our function name for express routes to set the correct base path
|
|
7
|
-
const functionName = 'serverless-http'
|
|
8
|
-
|
|
9
|
-
// Initialize express app
|
|
10
|
-
const app = expressApp(functionName)
|
|
11
|
-
|
|
12
|
-
// Export lambda handler
|
|
13
|
-
const handler = serverless(app)
|
|
14
|
-
|
|
15
|
-
module.exports = { handler }
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "set-cookie",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - set a cookie with your Netlify Function",
|
|
5
|
-
"main": "set-cookie",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"js"
|
|
13
|
-
],
|
|
14
|
-
"author": "Netlify",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"cookie": "^0.5.0"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const cookie = require('cookie')
|
|
2
|
-
|
|
3
|
-
// 14 days
|
|
4
|
-
const COOKIE_MAX_AGE = 12_096e5
|
|
5
|
-
|
|
6
|
-
const handler = async () => {
|
|
7
|
-
const myCookie = cookie.serialize('my_cookie', 'lolHi', {
|
|
8
|
-
secure: true,
|
|
9
|
-
httpOnly: true,
|
|
10
|
-
path: '/',
|
|
11
|
-
maxAge: COOKIE_MAX_AGE,
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const redirectUrl = 'https://google.com'
|
|
15
|
-
// Do redirects via html
|
|
16
|
-
const html = `
|
|
17
|
-
<html lang="en">
|
|
18
|
-
<head>
|
|
19
|
-
<meta charset="utf-8">
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<noscript>
|
|
23
|
-
<meta http-equiv="refresh" content="0; url=${redirectUrl}" />
|
|
24
|
-
</noscript>
|
|
25
|
-
</body>
|
|
26
|
-
<script>
|
|
27
|
-
setTimeout(function(){
|
|
28
|
-
window.location.href = ${JSON.stringify(redirectUrl)}
|
|
29
|
-
}, 0)
|
|
30
|
-
</script>
|
|
31
|
-
</html>`
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
statusCode: 200,
|
|
35
|
-
headers: {
|
|
36
|
-
'Set-Cookie': myCookie,
|
|
37
|
-
'Cache-Control': 'no-cache',
|
|
38
|
-
'Content-Type': 'text/html',
|
|
39
|
-
},
|
|
40
|
-
body: html,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = { handler }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "slack-rate-limit",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - post to Slack, at most once an hour, using Netlify Identity metadata",
|
|
5
|
-
"main": "node-fetch.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"slack",
|
|
13
|
-
"js"
|
|
14
|
-
],
|
|
15
|
-
"author": "Netlify",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"node-fetch": "^2.6.1"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// code walkthrough: https://www.netlify.com/blog/2018/03/29/jamstack-architecture-on-netlify-how-identity-and-functions-work-together/#updating-user-data-with-the-identity-api
|
|
2
|
-
// demo repo: https://github.com/biilmann/testing-slack-tutorial/tree/v3-one-message-an-hour
|
|
3
|
-
// note: requires SLACK_WEBHOOK_URL environment variable
|
|
4
|
-
const process = require('process')
|
|
5
|
-
|
|
6
|
-
const slackURL = process.env.SLACK_WEBHOOK_URL
|
|
7
|
-
const fetch = require('node-fetch')
|
|
8
|
-
|
|
9
|
-
const parseJsonResponse = async (response) => {
|
|
10
|
-
const json = await response.json()
|
|
11
|
-
if (!response.ok) {
|
|
12
|
-
const error = `JSON: ${JSON.stringify(json)}. Status: ${response.status}`
|
|
13
|
-
throw new Error(error)
|
|
14
|
-
}
|
|
15
|
-
return json
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class IdentityAPI {
|
|
19
|
-
constructor(apiURL, token) {
|
|
20
|
-
this.apiURL = apiURL
|
|
21
|
-
this.token = token
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
headers(headers = {}) {
|
|
25
|
-
return {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
Authorization: `Bearer ${this.token}`,
|
|
28
|
-
...headers,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async request(path, options = {}) {
|
|
33
|
-
const headers = this.headers(options.headers || {})
|
|
34
|
-
const response = await fetch(this.apiURL + path, { ...options, headers })
|
|
35
|
-
const contentType = response.headers.get('Content-Type')
|
|
36
|
-
if (contentType && /json/.test(contentType)) {
|
|
37
|
-
return parseJsonResponse(response)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
const data = await response.text()
|
|
42
|
-
const error = `Data: ${data}. Status: ${response.status}`
|
|
43
|
-
throw new Error(error)
|
|
44
|
-
}
|
|
45
|
-
return await response.text()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
// Fetch a user from GoTrue via id
|
|
51
|
-
//
|
|
52
|
-
const fetchUser = function (identity, id) {
|
|
53
|
-
const api = new IdentityAPI(identity.url, identity.token)
|
|
54
|
-
return api.request(`/admin/users/${id}`)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
// Update the app_metadata of a user
|
|
59
|
-
//
|
|
60
|
-
const updateUser = function (identity, user, appMetadata) {
|
|
61
|
-
const api = new IdentityAPI(identity.url, identity.token)
|
|
62
|
-
|
|
63
|
-
return api.request(`/admin/users/${user.id}`, {
|
|
64
|
-
method: 'PUT',
|
|
65
|
-
body: JSON.stringify({ app_metadata: { ...user.app_metadata, ...appMetadata } }),
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// One hour
|
|
70
|
-
const MESSAGE_RATE_LIMIT = 36e5
|
|
71
|
-
|
|
72
|
-
module.exports = async function handler(event, context) {
|
|
73
|
-
if (event.httpMethod !== 'POST') {
|
|
74
|
-
return {
|
|
75
|
-
statusCode: 410,
|
|
76
|
-
body: 'Unsupported Request Method',
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const claims = context.clientContext && context.clientContext.user
|
|
81
|
-
if (!claims) {
|
|
82
|
-
return {
|
|
83
|
-
statusCode: 401,
|
|
84
|
-
body: 'You must be signed in to call this function',
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const user = await fetchUser(context.clientContext.identity, claims.sub)
|
|
89
|
-
const lastMessage = new Date(user.app_metadata.last_message_at || 0).getTime()
|
|
90
|
-
const cutOff = Date.now() - MESSAGE_RATE_LIMIT
|
|
91
|
-
if (lastMessage > cutOff) {
|
|
92
|
-
return {
|
|
93
|
-
statusCode: 401,
|
|
94
|
-
body: 'Only one message an hour allowed',
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const payload = JSON.parse(event.body)
|
|
100
|
-
|
|
101
|
-
await fetch(slackURL, {
|
|
102
|
-
method: 'POST',
|
|
103
|
-
body: JSON.stringify({
|
|
104
|
-
text: payload.text,
|
|
105
|
-
attachments: [{ text: `From ${user.email}` }],
|
|
106
|
-
}),
|
|
107
|
-
})
|
|
108
|
-
await updateUser(context.clientContext.identity, user, {
|
|
109
|
-
last_message_at: Date.now(),
|
|
110
|
-
})
|
|
111
|
-
return { statusCode: 204 }
|
|
112
|
-
} catch (error) {
|
|
113
|
-
return { statusCode: 500, body: `Internal Server Error: ${error}` }
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: 'stripe-charge',
|
|
5
|
-
description: 'Stripe Charge: Charge a user with Stripe',
|
|
6
|
-
functionType: 'serverless',
|
|
7
|
-
async onComplete() {
|
|
8
|
-
console.log(`${chalk.yellow('stripe-charge')} function created from template!`)
|
|
9
|
-
if (!process.env.STRIPE_SECRET_KEY) {
|
|
10
|
-
console.log(
|
|
11
|
-
`note this function requires ${chalk.yellow(
|
|
12
|
-
'STRIPE_SECRET_KEY',
|
|
13
|
-
)} build environment variable set in your Netlify Site.`,
|
|
14
|
-
)
|
|
15
|
-
let siteData = { name: 'YOURSITENAMEHERE' }
|
|
16
|
-
try {
|
|
17
|
-
siteData = await this.netlify.api.getSite({
|
|
18
|
-
siteId: this.netlify.site.id,
|
|
19
|
-
})
|
|
20
|
-
} catch (e) {
|
|
21
|
-
// silent error, not important
|
|
22
|
-
}
|
|
23
|
-
console.log(
|
|
24
|
-
`Set it at: https://app.netlify.com/sites/${siteData.name}/settings/deploys#environment-variables (must have CD setup)`,
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "stripe-charge",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"lockfileVersion": 2,
|
|
5
|
-
"requires": true,
|
|
6
|
-
"packages": {
|
|
7
|
-
"": {
|
|
8
|
-
"name": "stripe-charge",
|
|
9
|
-
"version": "1.0.0",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"stripe": "^10.0.0"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"node_modules/@types/node": {
|
|
16
|
-
"version": "17.0.2",
|
|
17
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.2.tgz",
|
|
18
|
-
"integrity": "sha512-JepeIUPFDARgIs0zD/SKPgFsJEAF0X5/qO80llx59gOxFTboS9Amv3S+QfB7lqBId5sFXJ99BN0J6zFRvL9dDA=="
|
|
19
|
-
},
|
|
20
|
-
"node_modules/call-bind": {
|
|
21
|
-
"version": "1.0.2",
|
|
22
|
-
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
|
23
|
-
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"function-bind": "^1.1.1",
|
|
26
|
-
"get-intrinsic": "^1.0.2"
|
|
27
|
-
},
|
|
28
|
-
"funding": {
|
|
29
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"node_modules/function-bind": {
|
|
33
|
-
"version": "1.1.1",
|
|
34
|
-
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
|
35
|
-
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
|
36
|
-
},
|
|
37
|
-
"node_modules/get-intrinsic": {
|
|
38
|
-
"version": "1.1.1",
|
|
39
|
-
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
|
|
40
|
-
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"function-bind": "^1.1.1",
|
|
43
|
-
"has": "^1.0.3",
|
|
44
|
-
"has-symbols": "^1.0.1"
|
|
45
|
-
},
|
|
46
|
-
"funding": {
|
|
47
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"node_modules/has": {
|
|
51
|
-
"version": "1.0.3",
|
|
52
|
-
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
|
53
|
-
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
|
54
|
-
"dependencies": {
|
|
55
|
-
"function-bind": "^1.1.1"
|
|
56
|
-
},
|
|
57
|
-
"engines": {
|
|
58
|
-
"node": ">= 0.4.0"
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"node_modules/has-symbols": {
|
|
62
|
-
"version": "1.0.2",
|
|
63
|
-
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
|
|
64
|
-
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
|
|
65
|
-
"engines": {
|
|
66
|
-
"node": ">= 0.4"
|
|
67
|
-
},
|
|
68
|
-
"funding": {
|
|
69
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"node_modules/object-inspect": {
|
|
73
|
-
"version": "1.12.0",
|
|
74
|
-
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz",
|
|
75
|
-
"integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==",
|
|
76
|
-
"funding": {
|
|
77
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"node_modules/qs": {
|
|
81
|
-
"version": "6.11.0",
|
|
82
|
-
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
|
83
|
-
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
|
84
|
-
"dependencies": {
|
|
85
|
-
"side-channel": "^1.0.4"
|
|
86
|
-
},
|
|
87
|
-
"engines": {
|
|
88
|
-
"node": ">=0.6"
|
|
89
|
-
},
|
|
90
|
-
"funding": {
|
|
91
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
"node_modules/side-channel": {
|
|
95
|
-
"version": "1.0.4",
|
|
96
|
-
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
|
97
|
-
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
|
98
|
-
"dependencies": {
|
|
99
|
-
"call-bind": "^1.0.0",
|
|
100
|
-
"get-intrinsic": "^1.0.2",
|
|
101
|
-
"object-inspect": "^1.9.0"
|
|
102
|
-
},
|
|
103
|
-
"funding": {
|
|
104
|
-
"url": "https://github.com/sponsors/ljharb"
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
"node_modules/stripe": {
|
|
108
|
-
"version": "10.17.0",
|
|
109
|
-
"resolved": "https://registry.npmjs.org/stripe/-/stripe-10.17.0.tgz",
|
|
110
|
-
"integrity": "sha512-JHV2KoL+nMQRXu3m9ervCZZvi4DDCJfzHUE6CmtJxR9TmizyYfrVuhGvnsZLLnheby9Qrnf4Hq6iOEcejGwnGQ==",
|
|
111
|
-
"dependencies": {
|
|
112
|
-
"@types/node": ">=8.1.0",
|
|
113
|
-
"qs": "^6.11.0"
|
|
114
|
-
},
|
|
115
|
-
"engines": {
|
|
116
|
-
"node": "^8.1 || >=10.*"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
"dependencies": {
|
|
121
|
-
"@types/node": {
|
|
122
|
-
"version": "17.0.2",
|
|
123
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.2.tgz",
|
|
124
|
-
"integrity": "sha512-JepeIUPFDARgIs0zD/SKPgFsJEAF0X5/qO80llx59gOxFTboS9Amv3S+QfB7lqBId5sFXJ99BN0J6zFRvL9dDA=="
|
|
125
|
-
},
|
|
126
|
-
"call-bind": {
|
|
127
|
-
"version": "1.0.2",
|
|
128
|
-
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
|
129
|
-
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
|
130
|
-
"requires": {
|
|
131
|
-
"function-bind": "^1.1.1",
|
|
132
|
-
"get-intrinsic": "^1.0.2"
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
"function-bind": {
|
|
136
|
-
"version": "1.1.1",
|
|
137
|
-
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
|
138
|
-
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
|
139
|
-
},
|
|
140
|
-
"get-intrinsic": {
|
|
141
|
-
"version": "1.1.1",
|
|
142
|
-
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
|
|
143
|
-
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
|
|
144
|
-
"requires": {
|
|
145
|
-
"function-bind": "^1.1.1",
|
|
146
|
-
"has": "^1.0.3",
|
|
147
|
-
"has-symbols": "^1.0.1"
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
"has": {
|
|
151
|
-
"version": "1.0.3",
|
|
152
|
-
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
|
153
|
-
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
|
154
|
-
"requires": {
|
|
155
|
-
"function-bind": "^1.1.1"
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
"has-symbols": {
|
|
159
|
-
"version": "1.0.2",
|
|
160
|
-
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
|
|
161
|
-
"integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw=="
|
|
162
|
-
},
|
|
163
|
-
"object-inspect": {
|
|
164
|
-
"version": "1.12.0",
|
|
165
|
-
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.0.tgz",
|
|
166
|
-
"integrity": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g=="
|
|
167
|
-
},
|
|
168
|
-
"qs": {
|
|
169
|
-
"version": "6.11.0",
|
|
170
|
-
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
|
171
|
-
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
|
172
|
-
"requires": {
|
|
173
|
-
"side-channel": "^1.0.4"
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
"side-channel": {
|
|
177
|
-
"version": "1.0.4",
|
|
178
|
-
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
|
179
|
-
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
|
180
|
-
"requires": {
|
|
181
|
-
"call-bind": "^1.0.0",
|
|
182
|
-
"get-intrinsic": "^1.0.2",
|
|
183
|
-
"object-inspect": "^1.9.0"
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
"stripe": {
|
|
187
|
-
"version": "10.17.0",
|
|
188
|
-
"resolved": "https://registry.npmjs.org/stripe/-/stripe-10.17.0.tgz",
|
|
189
|
-
"integrity": "sha512-JHV2KoL+nMQRXu3m9ervCZZvi4DDCJfzHUE6CmtJxR9TmizyYfrVuhGvnsZLLnheby9Qrnf4Hq6iOEcejGwnGQ==",
|
|
190
|
-
"requires": {
|
|
191
|
-
"@types/node": ">=8.1.0",
|
|
192
|
-
"qs": "^6.11.0"
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "stripe-charge",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "netlify functions:create - Charge a user with Stripe",
|
|
5
|
-
"main": "stripe-charge.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"netlify",
|
|
11
|
-
"serverless",
|
|
12
|
-
"apis",
|
|
13
|
-
"stripe",
|
|
14
|
-
"js"
|
|
15
|
-
],
|
|
16
|
-
"author": "Netlify",
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"stripe": "^10.0.0"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// with thanks https://github.com/alexmacarthur/netlify-lambda-function-example/blob/68a0cdc05e201d68fe80b0926b0af7ff88f15802/lambda-src/purchase.js
|
|
2
|
-
const process = require('process')
|
|
3
|
-
|
|
4
|
-
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)
|
|
5
|
-
|
|
6
|
-
const statusCode = 200
|
|
7
|
-
const headers = {
|
|
8
|
-
'Access-Control-Allow-Origin': '*',
|
|
9
|
-
'Access-Control-Allow-Headers': 'Content-Type',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const handler = async function (event) {
|
|
13
|
-
// -- We only care to do anything if this is our POST request.
|
|
14
|
-
if (event.httpMethod !== 'POST' || !event.body) {
|
|
15
|
-
return {
|
|
16
|
-
statusCode,
|
|
17
|
-
headers,
|
|
18
|
-
body: '',
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// -- Parse the body contents into an object.
|
|
23
|
-
const data = JSON.parse(event.body)
|
|
24
|
-
|
|
25
|
-
// -- Make sure we have all required data. Otherwise, escape.
|
|
26
|
-
if (!data.token || !data.amount || !data.idempotency_key) {
|
|
27
|
-
console.error('Required information is missing.')
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
statusCode,
|
|
31
|
-
headers,
|
|
32
|
-
body: JSON.stringify({ status: 'missing-information' }),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const charge = await stripe.charges.create(
|
|
38
|
-
{
|
|
39
|
-
currency: 'usd',
|
|
40
|
-
amount: data.amount,
|
|
41
|
-
source: data.token.id,
|
|
42
|
-
receipt_email: data.token.email,
|
|
43
|
-
description: `charge for a widget`,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
idempotency_key: data.idempotency_key,
|
|
47
|
-
},
|
|
48
|
-
)
|
|
49
|
-
const status = charge === null || charge.status !== 'succeeded' ? 'failed' : charge.status
|
|
50
|
-
return { statusCode, headers, body: JSON.stringify({ status }) }
|
|
51
|
-
} catch (error) {
|
|
52
|
-
return { statusCode: 500, error: error.message }
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = { handler }
|
package/src/functions-templates/javascript/stripe-subscription/.netlify-function-template.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: 'stripe-subscription',
|
|
5
|
-
description: 'Stripe subscription: Create a subscription with Stripe',
|
|
6
|
-
functionType: 'serverless',
|
|
7
|
-
async onComplete() {
|
|
8
|
-
console.log(`${chalk.yellow('stripe-subscription')} function created from template!`)
|
|
9
|
-
if (!process.env.STRIPE_SECRET_KEY) {
|
|
10
|
-
console.log(
|
|
11
|
-
`note this function requires ${chalk.yellow(
|
|
12
|
-
'STRIPE_SECRET_KEY',
|
|
13
|
-
)} build environment variable set in your Netlify Site.`,
|
|
14
|
-
)
|
|
15
|
-
let siteData = { name: 'YOURSITENAMEHERE' }
|
|
16
|
-
try {
|
|
17
|
-
siteData = await this.netlify.api.getSite({
|
|
18
|
-
siteId: this.netlify.site.id,
|
|
19
|
-
})
|
|
20
|
-
} catch (e) {
|
|
21
|
-
// silent error, not important
|
|
22
|
-
}
|
|
23
|
-
console.log(
|
|
24
|
-
`Set it at: https://app.netlify.com/sites/${siteData.name}/settings/deploys#environment-variables (must have CD setup)`,
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
}
|