@drawbridge/drawbridge-utils 0.0.118 → 0.0.124

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/dist/sendgrid.cjs CHANGED
@@ -100,11 +100,11 @@ var sendWithRetry = async (send, { delays = RETRY_DELAYS_MS } = {}) => {
100
100
  }
101
101
  };
102
102
  var sendgridRequest = ({ apiKey, body, method, path, query, request: request2 = request }) => {
103
- const key = apiKey || process.env.SENDGRID_API_KEY;
103
+ if (!apiKey) throw new Error("SendGrid API key missing \u2014 pass apiKey (the drawbridge provider's apiKey)");
104
104
  return request2({
105
105
  body,
106
106
  headers: {
107
- "Authorization": "Bearer " + key
107
+ "Authorization": "Bearer " + apiKey
108
108
  },
109
109
  method,
110
110
  query,
@@ -118,10 +118,8 @@ var sendgrid = {
118
118
  send: async ({ apiKey, from, headers, html, request: request2, subject, text, to }) => {
119
119
  var _a, _b;
120
120
  try {
121
- const sender = (from == null ? void 0 : from.email) ? from : {
122
- email: process.env.SENDGRID_FROM_ADDRESS,
123
- name: "Drawbridge"
124
- };
121
+ if (!(from == null ? void 0 : from.email)) throw new Error("SendGrid sender missing \u2014 pass from.email (the drawbridge provider's accountSender)");
122
+ const sender = { name: "Drawbridge", ...from };
125
123
  await sendWithRetry(() => sendgridRequest({
126
124
  apiKey,
127
125
  ...request2 && { request: request2 },
@@ -10,10 +10,10 @@ import { createLogger } from '@drawbridge/drawbridge-telemetry';
10
10
  // other — the private `drawbridge` manifest declares email.send, email.notify
11
11
  // and email.digest, so its transport belongs beside its manifest.
12
12
  //
13
- // The API key still falls back to process.env, which is a carry-over rather than
14
- // a preference: a published package reading a deployment's environment is the
15
- // thing `client : { id : 'KLAVIYO_OAUTH_CLIENT_ID' }` exists to avoid. Callers
16
- // that pass a key explicitly never touch it.
13
+ // THE CREDENTIAL IS THE CALLER'S TO PASS. It used to fall back to process.env;
14
+ // it lives encrypted in the `provider` collection now (lib/providers.js), and a
15
+ // published package reading a deployment's environment is precisely the thing
16
+ // `client : { id : 'KLAVIYO_OAUTH_CLIENT_ID' }` exists to avoid.
17
17
 
18
18
 
19
19
  const logger = createLogger();
@@ -90,12 +90,17 @@ const sendWithRetry = async ( send, { delays = RETRY_DELAYS_MS } = {} ) => {
90
90
  // manifest hook), and it is the only thing that works across the boundary.
91
91
  const sendgridRequest = ({ apiKey, body, method, path, query, request: request$1 = request }) => {
92
92
 
93
- const key = apiKey || process.env.SENDGRID_API_KEY;
93
+ // THROWS RATHER THAN DEGRADES. Sending with no key is not a degraded send, it
94
+ // is an unauthenticated request SendGrid answers 401 — and the alternative,
95
+ // no-opping, is mail that stops with no error anywhere: no exception, no
96
+ // failed job, nothing to alert on, just people who never received the code
97
+ // they are waiting for. A missing credential has to be loud.
98
+ if( ! apiKey ) throw new Error( 'SendGrid API key missing — pass apiKey (the drawbridge provider\'s apiKey)' );
94
99
 
95
100
  return request$1({
96
101
  body,
97
102
  headers : {
98
- 'Authorization' : 'Bearer ' + key
103
+ 'Authorization' : 'Bearer ' + apiKey
99
104
  },
100
105
  method,
101
106
  query,
@@ -113,14 +118,14 @@ const sendgrid = {
113
118
 
114
119
  try {
115
120
 
116
- const sender = ( from?.email ?
117
- from
118
- :
119
- {
120
- email : process.env.SENDGRID_FROM_ADDRESS,
121
- name : 'Drawbridge'
122
- }
123
- );
121
+ // SAME REASON AS THE KEY. The account sender is stored, not deployed,
122
+ // and a send from no address is one SendGrid rejects — quietly, from
123
+ // the caller's point of view, since the throw would otherwise never
124
+ // name the thing that is actually missing. The display name still
125
+ // defaults, because that is a label rather than a credential.
126
+ if( ! from?.email ) throw new Error( 'SendGrid sender missing — pass from.email (the drawbridge provider\'s accountSender)' );
127
+
128
+ const sender = { name : 'Drawbridge', ...from };
124
129
 
125
130
  await sendWithRetry( () => sendgridRequest({
126
131
  apiKey,
@@ -10,10 +10,10 @@ import { createLogger } from '@drawbridge/drawbridge-telemetry';
10
10
  // other — the private `drawbridge` manifest declares email.send, email.notify
11
11
  // and email.digest, so its transport belongs beside its manifest.
12
12
  //
13
- // The API key still falls back to process.env, which is a carry-over rather than
14
- // a preference: a published package reading a deployment's environment is the
15
- // thing `client : { id : 'KLAVIYO_OAUTH_CLIENT_ID' }` exists to avoid. Callers
16
- // that pass a key explicitly never touch it.
13
+ // THE CREDENTIAL IS THE CALLER'S TO PASS. It used to fall back to process.env;
14
+ // it lives encrypted in the `provider` collection now (lib/providers.js), and a
15
+ // published package reading a deployment's environment is precisely the thing
16
+ // `client : { id : 'KLAVIYO_OAUTH_CLIENT_ID' }` exists to avoid.
17
17
 
18
18
 
19
19
  const logger = createLogger();
@@ -90,12 +90,17 @@ const sendWithRetry = async ( send, { delays = RETRY_DELAYS_MS } = {} ) => {
90
90
  // manifest hook), and it is the only thing that works across the boundary.
91
91
  const sendgridRequest = ({ apiKey, body, method, path, query, request: request$1 = request }) => {
92
92
 
93
- const key = apiKey || process.env.SENDGRID_API_KEY;
93
+ // THROWS RATHER THAN DEGRADES. Sending with no key is not a degraded send, it
94
+ // is an unauthenticated request SendGrid answers 401 — and the alternative,
95
+ // no-opping, is mail that stops with no error anywhere: no exception, no
96
+ // failed job, nothing to alert on, just people who never received the code
97
+ // they are waiting for. A missing credential has to be loud.
98
+ if( ! apiKey ) throw new Error( 'SendGrid API key missing — pass apiKey (the drawbridge provider\'s apiKey)' );
94
99
 
95
100
  return request$1({
96
101
  body,
97
102
  headers : {
98
- 'Authorization' : 'Bearer ' + key
103
+ 'Authorization' : 'Bearer ' + apiKey
99
104
  },
100
105
  method,
101
106
  query,
@@ -113,14 +118,14 @@ const sendgrid = {
113
118
 
114
119
  try {
115
120
 
116
- const sender = ( from?.email ?
117
- from
118
- :
119
- {
120
- email : process.env.SENDGRID_FROM_ADDRESS,
121
- name : 'Drawbridge'
122
- }
123
- );
121
+ // SAME REASON AS THE KEY. The account sender is stored, not deployed,
122
+ // and a send from no address is one SendGrid rejects — quietly, from
123
+ // the caller's point of view, since the throw would otherwise never
124
+ // name the thing that is actually missing. The display name still
125
+ // defaults, because that is a label rather than a credential.
126
+ if( ! from?.email ) throw new Error( 'SendGrid sender missing — pass from.email (the drawbridge provider\'s accountSender)' );
127
+
128
+ const sender = { name : 'Drawbridge', ...from };
124
129
 
125
130
  await sendWithRetry( () => sendgridRequest({
126
131
  apiKey,
package/dist/sendgrid.js CHANGED
@@ -73,11 +73,11 @@ var sendWithRetry = async (send, { delays = RETRY_DELAYS_MS } = {}) => {
73
73
  }
74
74
  };
75
75
  var sendgridRequest = ({ apiKey, body, method, path, query, request: request2 = request }) => {
76
- const key = apiKey || process.env.SENDGRID_API_KEY;
76
+ if (!apiKey) throw new Error("SendGrid API key missing \u2014 pass apiKey (the drawbridge provider's apiKey)");
77
77
  return request2({
78
78
  body,
79
79
  headers: {
80
- "Authorization": "Bearer " + key
80
+ "Authorization": "Bearer " + apiKey
81
81
  },
82
82
  method,
83
83
  query,
@@ -91,10 +91,8 @@ var sendgrid = {
91
91
  send: async ({ apiKey, from, headers, html, request: request2, subject, text, to }) => {
92
92
  var _a, _b;
93
93
  try {
94
- const sender = (from == null ? void 0 : from.email) ? from : {
95
- email: process.env.SENDGRID_FROM_ADDRESS,
96
- name: "Drawbridge"
97
- };
94
+ if (!(from == null ? void 0 : from.email)) throw new Error("SendGrid sender missing \u2014 pass from.email (the drawbridge provider's accountSender)");
95
+ const sender = { name: "Drawbridge", ...from };
98
96
  await sendWithRetry(() => sendgridRequest({
99
97
  apiKey,
100
98
  ...request2 && { request: request2 },
package/dist/twilio.cjs CHANGED
@@ -81,9 +81,8 @@ var twilio = {
81
81
  title,
82
82
  to
83
83
  }) => {
84
- accountSid = accountSid || process.env.TWILIO_ACCOUNT_SID;
85
- authToken = authToken || process.env.TWILIO_AUTH_TOKEN;
86
- from = from || process.env.TWILIO_ACCOUNT_FROM;
84
+ const missing = Object.entries({ accountSid, authToken, from }).filter(([, value]) => !value).map(([name]) => name);
85
+ if (missing.length) throw new Error("Twilio credentials missing \u2014 " + missing.join(", ") + " (the drawbridge provider's smsSid, smsToken and smsFrom)");
87
86
  const body = [
88
87
  title,
89
88
  message,
package/dist/twilio.d.cts CHANGED
@@ -26,9 +26,17 @@ const twilio = {
26
26
  to
27
27
  }) => {
28
28
 
29
- accountSid = accountSid || process.env.TWILIO_ACCOUNT_SID;
30
- authToken = authToken || process.env.TWILIO_AUTH_TOKEN;
31
- from = from || process.env.TWILIO_ACCOUNT_FROM;
29
+ // THROWS RATHER THAN DEGRADES. These used to fall back to process.env;
30
+ // they live encrypted in the `provider` collection now and the caller
31
+ // passes them. Missing, there is no send to degrade to — a no-op here is
32
+ // SMS that stops with nothing raised anywhere, which reads as delivered
33
+ // right up until someone reports that the code never arrived. Naming the
34
+ // missing ones is the difference between a five-minute fix and a hunt.
35
+ const missing = Object.entries({ accountSid, authToken, from })
36
+ .filter( ( [ , value ] ) => ! value )
37
+ .map( ( [ name ] ) => name );
38
+
39
+ if( missing.length ) throw new Error( 'Twilio credentials missing — ' + missing.join( ', ' ) + ' (the drawbridge provider\'s smsSid, smsToken and smsFrom)' );
32
40
 
33
41
  // Newline-separated, brand/title first, and no "Your prize is" /
34
42
  // "Click here to verify your prize" phrasing — textbook carrier-filter
package/dist/twilio.d.ts CHANGED
@@ -26,9 +26,17 @@ const twilio = {
26
26
  to
27
27
  }) => {
28
28
 
29
- accountSid = accountSid || process.env.TWILIO_ACCOUNT_SID;
30
- authToken = authToken || process.env.TWILIO_AUTH_TOKEN;
31
- from = from || process.env.TWILIO_ACCOUNT_FROM;
29
+ // THROWS RATHER THAN DEGRADES. These used to fall back to process.env;
30
+ // they live encrypted in the `provider` collection now and the caller
31
+ // passes them. Missing, there is no send to degrade to — a no-op here is
32
+ // SMS that stops with nothing raised anywhere, which reads as delivered
33
+ // right up until someone reports that the code never arrived. Naming the
34
+ // missing ones is the difference between a five-minute fix and a hunt.
35
+ const missing = Object.entries({ accountSid, authToken, from })
36
+ .filter( ( [ , value ] ) => ! value )
37
+ .map( ( [ name ] ) => name );
38
+
39
+ if( missing.length ) throw new Error( 'Twilio credentials missing — ' + missing.join( ', ' ) + ' (the drawbridge provider\'s smsSid, smsToken and smsFrom)' );
32
40
 
33
41
  // Newline-separated, brand/title first, and no "Your prize is" /
34
42
  // "Click here to verify your prize" phrasing — textbook carrier-filter
package/dist/twilio.js CHANGED
@@ -56,9 +56,8 @@ var twilio = {
56
56
  title,
57
57
  to
58
58
  }) => {
59
- accountSid = accountSid || process.env.TWILIO_ACCOUNT_SID;
60
- authToken = authToken || process.env.TWILIO_AUTH_TOKEN;
61
- from = from || process.env.TWILIO_ACCOUNT_FROM;
59
+ const missing = Object.entries({ accountSid, authToken, from }).filter(([, value]) => !value).map(([name]) => name);
60
+ if (missing.length) throw new Error("Twilio credentials missing \u2014 " + missing.join(", ") + " (the drawbridge provider's smsSid, smsToken and smsFrom)");
62
61
  const body = [
63
62
  title,
64
63
  message,
package/package.json CHANGED
@@ -215,5 +215,5 @@
215
215
  "test": ". \"$HOME/.nvm/nvm.sh\" && nvm use && node --test"
216
216
  },
217
217
  "types": "dist/index.d.ts",
218
- "version": "0.0.118"
218
+ "version": "0.0.124"
219
219
  }