@cedarjs/api 7.1.1-next.471 → 7.2.0-rc.33

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.
Files changed (43) hide show
  1. package/README.md +0 -12
  2. package/dist/__tests__/mergePrismaWithSdlTypes.test-d.d.ts +2 -0
  3. package/dist/__tests__/mergePrismaWithSdlTypes.test-d.d.ts.map +1 -0
  4. package/dist/cache/clients/MemcachedClient.d.ts +2 -7
  5. package/dist/cache/clients/MemcachedClient.d.ts.map +1 -1
  6. package/dist/cache/clients/MemcachedClient.js +0 -5
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +4 -5
  10. package/dist/transforms.d.ts +4 -22
  11. package/dist/transforms.d.ts.map +1 -1
  12. package/dist/transforms.js +9 -11
  13. package/dist/types.d.ts +14 -4
  14. package/dist/types.d.ts.map +1 -1
  15. package/package.json +10 -17
  16. package/dist/__tests__/removeNulls.test-d.d.ts +0 -2
  17. package/dist/__tests__/removeNulls.test-d.d.ts.map +0 -1
  18. package/dist/sandbox/concurrencyLimiter.d.ts +0 -22
  19. package/dist/sandbox/concurrencyLimiter.d.ts.map +0 -1
  20. package/dist/sandbox/concurrencyLimiter.js +0 -33
  21. package/dist/sandbox/findChildScript.d.ts +0 -29
  22. package/dist/sandbox/findChildScript.d.ts.map +0 -1
  23. package/dist/sandbox/findChildScript.js +0 -35
  24. package/dist/sandbox/index.d.ts +0 -11
  25. package/dist/sandbox/index.d.ts.map +0 -1
  26. package/dist/sandbox/index.js +0 -22
  27. package/dist/sandbox/noNetworkPreload.d.ts +0 -16
  28. package/dist/sandbox/noNetworkPreload.d.ts.map +0 -1
  29. package/dist/sandbox/noNetworkPreload.js +0 -109
  30. package/dist/sandbox/runSandboxedChild.d.ts +0 -186
  31. package/dist/sandbox/runSandboxedChild.d.ts.map +0 -1
  32. package/dist/sandbox/runSandboxedChild.js +0 -213
  33. package/dist/sandbox/sandboxPackages.d.ts +0 -16
  34. package/dist/sandbox/sandboxPackages.d.ts.map +0 -1
  35. package/dist/sandbox/sandboxPackages.js +0 -53
  36. package/dist/signedTokens/index.d.ts +0 -2
  37. package/dist/signedTokens/index.d.ts.map +0 -1
  38. package/dist/signedTokens/index.js +0 -1
  39. package/dist/signedTokens/signedTokens.d.ts +0 -99
  40. package/dist/signedTokens/signedTokens.d.ts.map +0 -1
  41. package/dist/signedTokens/signedTokens.js +0 -100
  42. package/dist/webhooks/__tests__/webhooks.test-d.d.ts +0 -2
  43. package/dist/webhooks/__tests__/webhooks.test-d.d.ts.map +0 -1
@@ -1,100 +0,0 @@
1
- import jwt from "jsonwebtoken";
2
- const SIGNED_TOKEN_SECRET_ENV_VAR = "SIGNED_TOKEN_SECRET";
3
- class SignedTokenError extends Error {
4
- code;
5
- constructor(code, message, cause) {
6
- super(message, cause === void 0 ? void 0 : { cause });
7
- this.name = "SignedTokenError";
8
- this.code = code;
9
- }
10
- }
11
- const ALGORITHM = "HS256";
12
- function resolveSecret(secret, action) {
13
- const resolved = secret ?? process.env[SIGNED_TOKEN_SECRET_ENV_VAR];
14
- if (typeof resolved === "string" && resolved.length > 0) {
15
- return resolved;
16
- }
17
- throw new SignedTokenError(
18
- "MISSING_SECRET",
19
- `Cannot ${action} a signed token because no secret is configured. Set the ${SIGNED_TOKEN_SECRET_ENV_VAR} environment variable (generate a value with \`yarn cedar generate secret\`), or pass the \`secret\` option explicitly.`
20
- );
21
- }
22
- function assertPurpose(purpose) {
23
- if (typeof purpose === "string" && purpose.length > 0) {
24
- return;
25
- }
26
- throw new SignedTokenError(
27
- "MISSING_PURPOSE",
28
- "A signed token needs a non-empty `purpose` string, such as 'google-oauth-state' or 'email-confirmation'. The purpose is what stops a token created for one flow from verifying in another."
29
- );
30
- }
31
- function isSignedTokenClaims(claims) {
32
- if (typeof claims !== "object" || claims === null) {
33
- return false;
34
- }
35
- if (!("payload" in claims) || !("purpose" in claims) || !("exp" in claims)) {
36
- return false;
37
- }
38
- return typeof claims.payload === "object" && claims.payload !== null && typeof claims.purpose === "string" && typeof claims.exp === "number";
39
- }
40
- function createSignedToken({
41
- payload,
42
- purpose,
43
- expiresIn,
44
- secret
45
- }) {
46
- assertPurpose(purpose);
47
- const resolvedSecret = resolveSecret(secret, "create");
48
- try {
49
- return jwt.sign({ payload, purpose }, resolvedSecret, {
50
- algorithm: ALGORITHM,
51
- expiresIn
52
- });
53
- } catch (e) {
54
- const message = e instanceof Error ? e.message : String(e);
55
- throw new SignedTokenError(
56
- "SIGN_FAILED",
57
- `Could not create signed token: ${message}`,
58
- e
59
- );
60
- }
61
- }
62
- function verifySignedToken(token, { purpose, secret }) {
63
- assertPurpose(purpose);
64
- const resolvedSecret = resolveSecret(secret, "verify");
65
- if (typeof token !== "string" || token.length === 0) {
66
- throw new SignedTokenError("MISSING_TOKEN", "No signed token was provided.");
67
- }
68
- let claims;
69
- try {
70
- claims = jwt.verify(token, resolvedSecret, { algorithms: [ALGORITHM] });
71
- } catch (e) {
72
- if (e instanceof jwt.TokenExpiredError) {
73
- throw new SignedTokenError("EXPIRED", "The signed token has expired.", e);
74
- }
75
- throw new SignedTokenError(
76
- "INVALID",
77
- "The signed token is invalid or was not created by this application.",
78
- e
79
- );
80
- }
81
- if (!isSignedTokenClaims(claims)) {
82
- throw new SignedTokenError(
83
- "INVALID",
84
- "The signed token is invalid or was not created by this application."
85
- );
86
- }
87
- if (claims.purpose !== purpose) {
88
- throw new SignedTokenError(
89
- "PURPOSE_MISMATCH",
90
- `The signed token was created for purpose '${claims.purpose}' but was verified with purpose '${purpose}'.`
91
- );
92
- }
93
- return claims.payload;
94
- }
95
- export {
96
- SIGNED_TOKEN_SECRET_ENV_VAR,
97
- SignedTokenError,
98
- createSignedToken,
99
- verifySignedToken
100
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=webhooks.test-d.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webhooks.test-d.d.ts","sourceRoot":"","sources":["../../../src/webhooks/__tests__/webhooks.test-d.ts"],"names":[],"mappings":""}