@camstack/addon-provider-bosch 0.1.19 → 0.1.21

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.
@@ -1,4 +1,5 @@
1
- const require_dist = require("./dist-C5fLGNXK.js");
1
+ const require_dist = require("./dist-CFPbdUpa.js");
2
+ let node_crypto = require("node:crypto");
2
3
  //#region src/shared/oauth-callback.ts
3
4
  /** A code on its own: no scheme, no query, no separators. */
4
5
  var BARE_CODE = /^[A-Za-z0-9._~-]+$/;
@@ -62,6 +63,47 @@ function parseOAuthCallback(input, expectedState) {
62
63
  };
63
64
  }
64
65
  //#endregion
66
+ //#region src/shared/sign-in-attempt.ts
67
+ /** A sign-in code is only valid for a few minutes; the attempt dies with it. */
68
+ var SIGN_IN_ATTEMPT_TTL_MS = 600 * 1e3;
69
+ function createSignInAttemptStore(ttlMs = SIGN_IN_ATTEMPT_TTL_MS) {
70
+ const attempts = /* @__PURE__ */ new Map();
71
+ return {
72
+ put(verifier, state, nowMs) {
73
+ const attemptId = (0, node_crypto.randomBytes)(16).toString("base64url");
74
+ attempts.set(attemptId, {
75
+ verifier,
76
+ state,
77
+ expiresAtMs: nowMs + ttlMs
78
+ });
79
+ return attemptId;
80
+ },
81
+ take(attemptId, nowMs) {
82
+ const stored = attempts.get(attemptId);
83
+ if (stored === void 0) return {
84
+ ok: false,
85
+ reason: "missing"
86
+ };
87
+ attempts.delete(attemptId);
88
+ if (nowMs > stored.expiresAtMs) return {
89
+ ok: false,
90
+ reason: "expired"
91
+ };
92
+ return {
93
+ ok: true,
94
+ attempt: {
95
+ verifier: stored.verifier,
96
+ state: stored.state
97
+ }
98
+ };
99
+ }
100
+ };
101
+ }
102
+ /** Expired attempts use the same operator text as an expired authorization code. */
103
+ function loginFailureForAttempt(reason) {
104
+ return reason === "expired" ? "code-rejected" : "state-mismatch";
105
+ }
106
+ //#endregion
65
107
  //#region src/shared/account-integration-cascade.ts
66
108
  async function cascadeRemoveDevicesForIntegration(input) {
67
109
  const { reg, devices, addonId, system, integrationId, logger } = input;
@@ -105,6 +147,18 @@ Object.defineProperty(exports, "cascadeRemoveDevicesForIntegration", {
105
147
  return cascadeRemoveDevicesForIntegration;
106
148
  }
107
149
  });
150
+ Object.defineProperty(exports, "createSignInAttemptStore", {
151
+ enumerable: true,
152
+ get: function() {
153
+ return createSignInAttemptStore;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "loginFailureForAttempt", {
157
+ enumerable: true,
158
+ get: function() {
159
+ return loginFailureForAttempt;
160
+ }
161
+ });
108
162
  Object.defineProperty(exports, "parseOAuthCallback", {
109
163
  enumerable: true,
110
164
  get: function() {
@@ -1,4 +1,5 @@
1
- import { x as errMsg } from "./dist-LGjOHvFG.mjs";
1
+ import { C as errMsg } from "./dist-D9i3id5N.mjs";
2
+ import { randomBytes } from "node:crypto";
2
3
  //#region src/shared/oauth-callback.ts
3
4
  /** A code on its own: no scheme, no query, no separators. */
4
5
  var BARE_CODE = /^[A-Za-z0-9._~-]+$/;
@@ -62,6 +63,47 @@ function parseOAuthCallback(input, expectedState) {
62
63
  };
63
64
  }
64
65
  //#endregion
66
+ //#region src/shared/sign-in-attempt.ts
67
+ /** A sign-in code is only valid for a few minutes; the attempt dies with it. */
68
+ var SIGN_IN_ATTEMPT_TTL_MS = 600 * 1e3;
69
+ function createSignInAttemptStore(ttlMs = SIGN_IN_ATTEMPT_TTL_MS) {
70
+ const attempts = /* @__PURE__ */ new Map();
71
+ return {
72
+ put(verifier, state, nowMs) {
73
+ const attemptId = randomBytes(16).toString("base64url");
74
+ attempts.set(attemptId, {
75
+ verifier,
76
+ state,
77
+ expiresAtMs: nowMs + ttlMs
78
+ });
79
+ return attemptId;
80
+ },
81
+ take(attemptId, nowMs) {
82
+ const stored = attempts.get(attemptId);
83
+ if (stored === void 0) return {
84
+ ok: false,
85
+ reason: "missing"
86
+ };
87
+ attempts.delete(attemptId);
88
+ if (nowMs > stored.expiresAtMs) return {
89
+ ok: false,
90
+ reason: "expired"
91
+ };
92
+ return {
93
+ ok: true,
94
+ attempt: {
95
+ verifier: stored.verifier,
96
+ state: stored.state
97
+ }
98
+ };
99
+ }
100
+ };
101
+ }
102
+ /** Expired attempts use the same operator text as an expired authorization code. */
103
+ function loginFailureForAttempt(reason) {
104
+ return reason === "expired" ? "code-rejected" : "state-mismatch";
105
+ }
106
+ //#endregion
65
107
  //#region src/shared/account-integration-cascade.ts
66
108
  async function cascadeRemoveDevicesForIntegration(input) {
67
109
  const { reg, devices, addonId, system, integrationId, logger } = input;
@@ -99,4 +141,4 @@ function setIntegrationDevicesOnline(devices, system, integrationId, online) {
99
141
  return count;
100
142
  }
101
143
  //#endregion
102
- export { cascadeRemoveDevicesForIntegration as n, parseOAuthCallback as r, setIntegrationDevicesOnline as t };
144
+ export { parseOAuthCallback as a, loginFailureForAttempt as i, cascadeRemoveDevicesForIntegration as n, createSignInAttemptStore as r, setIntegrationDevicesOnline as t };