norc-cli 0.3.2 → 0.4.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/README.md +29 -2
- package/dist/index.js +1221 -485
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -448,7 +448,7 @@ function __addDisposableResource(env, value, async) {
|
|
|
448
448
|
return value;
|
|
449
449
|
}
|
|
450
450
|
function __disposeResources(env) {
|
|
451
|
-
function
|
|
451
|
+
function fail2(e) {
|
|
452
452
|
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
453
453
|
env.hasError = true;
|
|
454
454
|
}
|
|
@@ -460,12 +460,12 @@ function __disposeResources(env) {
|
|
|
460
460
|
if (r.dispose) {
|
|
461
461
|
var result = r.dispose.call(r.value);
|
|
462
462
|
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
463
|
-
|
|
463
|
+
fail2(e);
|
|
464
464
|
return next();
|
|
465
465
|
});
|
|
466
466
|
} else s |= 1;
|
|
467
467
|
} catch (e) {
|
|
468
|
-
|
|
468
|
+
fail2(e);
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
@@ -569,9 +569,9 @@ var init_tslib_es6 = __esm({
|
|
|
569
569
|
}
|
|
570
570
|
});
|
|
571
571
|
|
|
572
|
-
// ../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
572
|
+
// ../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/helper.js
|
|
573
573
|
var require_helper = __commonJS({
|
|
574
|
-
"../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
574
|
+
"../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/helper.js"(exports2) {
|
|
575
575
|
"use strict";
|
|
576
576
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
577
577
|
exports2.resolveFetch = void 0;
|
|
@@ -585,9 +585,9 @@ var require_helper = __commonJS({
|
|
|
585
585
|
}
|
|
586
586
|
});
|
|
587
587
|
|
|
588
|
-
// ../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
588
|
+
// ../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/types.js
|
|
589
589
|
var require_types = __commonJS({
|
|
590
|
-
"../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
590
|
+
"../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/types.js"(exports2) {
|
|
591
591
|
"use strict";
|
|
592
592
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
593
593
|
exports2.FunctionRegion = exports2.FunctionsHttpError = exports2.FunctionsRelayError = exports2.FunctionsFetchError = exports2.FunctionsError = void 0;
|
|
@@ -645,9 +645,9 @@ var require_types = __commonJS({
|
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
647
|
|
|
648
|
-
// ../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
648
|
+
// ../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js
|
|
649
649
|
var require_FunctionsClient = __commonJS({
|
|
650
|
-
"../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
650
|
+
"../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/FunctionsClient.js"(exports2) {
|
|
651
651
|
"use strict";
|
|
652
652
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
653
653
|
exports2.FunctionsClient = void 0;
|
|
@@ -931,9 +931,9 @@ var require_FunctionsClient = __commonJS({
|
|
|
931
931
|
}
|
|
932
932
|
});
|
|
933
933
|
|
|
934
|
-
// ../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
934
|
+
// ../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/index.js
|
|
935
935
|
var require_main = __commonJS({
|
|
936
|
-
"../../node_modules/.pnpm/@supabase+functions-js@2.
|
|
936
|
+
"../../node_modules/.pnpm/@supabase+functions-js@2.119.2/node_modules/@supabase/functions-js/dist/main/index.js"(exports2) {
|
|
937
937
|
"use strict";
|
|
938
938
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
939
939
|
exports2.FunctionRegion = exports2.FunctionsRelayError = exports2.FunctionsHttpError = exports2.FunctionsFetchError = exports2.FunctionsError = exports2.FunctionsClient = void 0;
|
|
@@ -960,9 +960,9 @@ var require_main = __commonJS({
|
|
|
960
960
|
}
|
|
961
961
|
});
|
|
962
962
|
|
|
963
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
963
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js
|
|
964
964
|
var require_websocket_factory = __commonJS({
|
|
965
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
965
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/websocket-factory.js"(exports2) {
|
|
966
966
|
"use strict";
|
|
967
967
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
968
968
|
exports2.WebSocketFactory = void 0;
|
|
@@ -1071,19 +1071,19 @@ Suggested solution: ${env.workaround}`;
|
|
|
1071
1071
|
}
|
|
1072
1072
|
});
|
|
1073
1073
|
|
|
1074
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1074
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/version.js
|
|
1075
1075
|
var require_version = __commonJS({
|
|
1076
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1076
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/version.js"(exports2) {
|
|
1077
1077
|
"use strict";
|
|
1078
1078
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1079
1079
|
exports2.version = void 0;
|
|
1080
|
-
exports2.version = "2.
|
|
1080
|
+
exports2.version = "2.119.2";
|
|
1081
1081
|
}
|
|
1082
1082
|
});
|
|
1083
1083
|
|
|
1084
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1084
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/constants.js
|
|
1085
1085
|
var require_constants = __commonJS({
|
|
1086
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1086
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/constants.js"(exports2) {
|
|
1087
1087
|
"use strict";
|
|
1088
1088
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1089
1089
|
exports2.CONNECTION_STATE = exports2.TRANSPORTS = exports2.CHANNEL_EVENTS = exports2.CHANNEL_STATES = exports2.SOCKET_STATES = exports2.MAX_PUSH_BUFFER_SIZE = exports2.WS_CLOSE_NORMAL = exports2.POSTGRES_CHANGES_WAIT_ERROR_GRACE = exports2.DEFAULT_POSTGRES_CHANGES_WAIT_TIMEOUT = exports2.DEFAULT_TIMEOUT = exports2.VERSION = exports2.DEFAULT_VSN = exports2.VSN_2_0_0 = exports2.VSN_1_0_0 = exports2.DEFAULT_VERSION = void 0;
|
|
@@ -1131,12 +1131,12 @@ var require_constants = __commonJS({
|
|
|
1131
1131
|
}
|
|
1132
1132
|
});
|
|
1133
1133
|
|
|
1134
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1134
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js
|
|
1135
1135
|
var require_serializer = __commonJS({
|
|
1136
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1136
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/serializer.js"(exports2) {
|
|
1137
1137
|
"use strict";
|
|
1138
1138
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1139
|
-
var Serializer = class {
|
|
1139
|
+
var Serializer = class _Serializer {
|
|
1140
1140
|
constructor(allowedMetadataKeys) {
|
|
1141
1141
|
this.HEADER_LENGTH = 1;
|
|
1142
1142
|
this.USER_BROADCAST_PUSH_META_LENGTH = 6;
|
|
@@ -1144,8 +1144,8 @@ var require_serializer = __commonJS({
|
|
|
1144
1144
|
this.BINARY_ENCODING = 0;
|
|
1145
1145
|
this.JSON_ENCODING = 1;
|
|
1146
1146
|
this.BROADCAST_EVENT = "broadcast";
|
|
1147
|
-
this.allowedMetadataKeys =
|
|
1148
|
-
this.allowedMetadataKeys = allowedMetadataKeys !== null && allowedMetadataKeys !== void 0 ? allowedMetadataKeys :
|
|
1147
|
+
this.allowedMetadataKeys = _Serializer.DEFAULT_METADATA_KEYS;
|
|
1148
|
+
this.allowedMetadataKeys = allowedMetadataKeys !== null && allowedMetadataKeys !== void 0 ? allowedMetadataKeys : _Serializer.DEFAULT_METADATA_KEYS;
|
|
1149
1149
|
}
|
|
1150
1150
|
encode(msg, callback) {
|
|
1151
1151
|
if (msg.event === this.BROADCAST_EVENT && !(msg.payload instanceof ArrayBuffer) && typeof msg.payload.event === "string") {
|
|
@@ -1281,13 +1281,14 @@ var require_serializer = __commonJS({
|
|
|
1281
1281
|
return Object.fromEntries(Object.entries(obj2).filter(([key]) => keys.includes(key)));
|
|
1282
1282
|
}
|
|
1283
1283
|
};
|
|
1284
|
+
Serializer.DEFAULT_METADATA_KEYS = ["persist"];
|
|
1284
1285
|
exports2.default = Serializer;
|
|
1285
1286
|
}
|
|
1286
1287
|
});
|
|
1287
1288
|
|
|
1288
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1289
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js
|
|
1289
1290
|
var require_transformers = __commonJS({
|
|
1290
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
1291
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/transformers.js"(exports2) {
|
|
1291
1292
|
"use strict";
|
|
1292
1293
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1293
1294
|
exports2.httpEndpointURL = exports2.toTimestampString = exports2.toArray = exports2.toJson = exports2.toNumber = exports2.toBoolean = exports2.convertCell = exports2.convertColumn = exports2.convertChangeData = exports2.PostgresTypes = void 0;
|
|
@@ -3316,9 +3317,9 @@ var require_phoenix_cjs = __commonJS({
|
|
|
3316
3317
|
}
|
|
3317
3318
|
});
|
|
3318
3319
|
|
|
3319
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3320
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js
|
|
3320
3321
|
var require_presenceAdapter = __commonJS({
|
|
3321
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3322
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/presenceAdapter.js"(exports2) {
|
|
3322
3323
|
"use strict";
|
|
3323
3324
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3324
3325
|
var phoenix_1 = require_phoenix_cjs();
|
|
@@ -3416,9 +3417,9 @@ var require_presenceAdapter = __commonJS({
|
|
|
3416
3417
|
}
|
|
3417
3418
|
});
|
|
3418
3419
|
|
|
3419
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3420
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js
|
|
3420
3421
|
var require_RealtimePresence = __commonJS({
|
|
3421
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3422
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimePresence.js"(exports2) {
|
|
3422
3423
|
"use strict";
|
|
3423
3424
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3424
3425
|
exports2.REALTIME_PRESENCE_LISTEN_EVENTS = void 0;
|
|
@@ -3460,9 +3461,9 @@ var require_RealtimePresence = __commonJS({
|
|
|
3460
3461
|
}
|
|
3461
3462
|
});
|
|
3462
3463
|
|
|
3463
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3464
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js
|
|
3464
3465
|
var require_normalizeChannelError = __commonJS({
|
|
3465
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3466
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/lib/normalizeChannelError.js"(exports2) {
|
|
3466
3467
|
"use strict";
|
|
3467
3468
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3468
3469
|
exports2.normalizeChannelError = normalizeChannelError;
|
|
@@ -3486,9 +3487,9 @@ var require_normalizeChannelError = __commonJS({
|
|
|
3486
3487
|
}
|
|
3487
3488
|
});
|
|
3488
3489
|
|
|
3489
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3490
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js
|
|
3490
3491
|
var require_channelAdapter = __commonJS({
|
|
3491
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3492
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/channelAdapter.js"(exports2) {
|
|
3492
3493
|
"use strict";
|
|
3493
3494
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3494
3495
|
var constants_1 = require_constants();
|
|
@@ -3593,9 +3594,9 @@ var require_channelAdapter = __commonJS({
|
|
|
3593
3594
|
}
|
|
3594
3595
|
});
|
|
3595
3596
|
|
|
3596
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3597
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js
|
|
3597
3598
|
var require_RealtimePostgresFilterBuilder = __commonJS({
|
|
3598
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3599
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimePostgresFilterBuilder.js"(exports2) {
|
|
3599
3600
|
"use strict";
|
|
3600
3601
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3601
3602
|
exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
|
|
@@ -3717,9 +3718,9 @@ var require_RealtimePostgresFilterBuilder = __commonJS({
|
|
|
3717
3718
|
}
|
|
3718
3719
|
});
|
|
3719
3720
|
|
|
3720
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3721
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js
|
|
3721
3722
|
var require_RealtimeChannel = __commonJS({
|
|
3722
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
3723
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimeChannel.js"(exports2) {
|
|
3723
3724
|
"use strict";
|
|
3724
3725
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3725
3726
|
exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_LISTEN_TYPES = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = void 0;
|
|
@@ -4137,7 +4138,7 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4137
4138
|
*
|
|
4138
4139
|
* @param event The name of the broadcast event
|
|
4139
4140
|
* @param payload Payload to be sent (required)
|
|
4140
|
-
* @param opts Options including timeout
|
|
4141
|
+
* @param opts Options including timeout and persist
|
|
4141
4142
|
* @returns Promise resolving to object with success status, and error details if failed
|
|
4142
4143
|
*
|
|
4143
4144
|
* @category Realtime
|
|
@@ -4160,6 +4161,17 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4160
4161
|
if (this.private) {
|
|
4161
4162
|
url.searchParams.set("private", "true");
|
|
4162
4163
|
}
|
|
4164
|
+
if (opts.persist) {
|
|
4165
|
+
if (!this.private) {
|
|
4166
|
+
return Promise.reject(new Error("Realtime httpSend() cannot store a message on a public channel."));
|
|
4167
|
+
}
|
|
4168
|
+
const ttl = typeof opts.persist === "object" ? opts.persist.ttl : void 0;
|
|
4169
|
+
if (ttl === void 0) {
|
|
4170
|
+
url.searchParams.set("persist", "true");
|
|
4171
|
+
} else {
|
|
4172
|
+
url.searchParams.set("persist[ttl]", String(ttl));
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4163
4175
|
const options = {
|
|
4164
4176
|
method: "POST",
|
|
4165
4177
|
headers,
|
|
@@ -4187,6 +4199,7 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4187
4199
|
* @param args.type The type of event to send
|
|
4188
4200
|
* @param args.event The name of the event being sent
|
|
4189
4201
|
* @param args.payload Payload to be sent
|
|
4202
|
+
* @param args.persist Stores the broadcast for replay on a private channel
|
|
4190
4203
|
* @param opts Options to be used during the send process
|
|
4191
4204
|
*
|
|
4192
4205
|
* @category Realtime
|
|
@@ -4230,6 +4243,15 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4230
4243
|
*/
|
|
4231
4244
|
async send(args, opts = {}) {
|
|
4232
4245
|
var _a, _b;
|
|
4246
|
+
if (args.type === "broadcast" && args.persist && (!this.private || this.socket.vsn === constants_1.VSN_1_0_0)) {
|
|
4247
|
+
const persistError = this.private ? "Realtime send() cannot store a message with protocol 1.0.0. Use httpSend() or connect with vsn 2.0.0." : "Realtime send() cannot store a message on a public channel.";
|
|
4248
|
+
if (this.socket.hasLogger()) {
|
|
4249
|
+
this.socket.log("channel", persistError);
|
|
4250
|
+
} else {
|
|
4251
|
+
console.error(persistError);
|
|
4252
|
+
}
|
|
4253
|
+
return "error";
|
|
4254
|
+
}
|
|
4233
4255
|
if (!this.channelAdapter.canPush() && args.type === "broadcast") {
|
|
4234
4256
|
const fallbackWarning = "Realtime send() is automatically falling back to REST API. This behavior will be deprecated in the future. Please use httpSend() explicitly for REST delivery.";
|
|
4235
4257
|
if (this.socket.hasLogger()) {
|
|
@@ -4238,6 +4260,15 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4238
4260
|
console.warn(fallbackWarning);
|
|
4239
4261
|
}
|
|
4240
4262
|
const { event, payload: endpoint_payload } = args;
|
|
4263
|
+
if (args.persist) {
|
|
4264
|
+
const persistError = "Realtime send() fell back to REST and cannot store this message. The batch endpoint does not support persistence. Use httpSend() or send after the channel is connected and subscribed.";
|
|
4265
|
+
if (this.socket.hasLogger()) {
|
|
4266
|
+
this.socket.log("channel", persistError);
|
|
4267
|
+
} else {
|
|
4268
|
+
console.error(persistError);
|
|
4269
|
+
}
|
|
4270
|
+
return "error";
|
|
4271
|
+
}
|
|
4241
4272
|
const headers = {
|
|
4242
4273
|
apikey: this.socket.apiKey ? this.socket.apiKey : "",
|
|
4243
4274
|
"Content-Type": "application/json"
|
|
@@ -4278,7 +4309,7 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4278
4309
|
resolve("ok");
|
|
4279
4310
|
}
|
|
4280
4311
|
push.receive("ok", () => resolve("ok"));
|
|
4281
|
-
push.receive("error", () => resolve("error"));
|
|
4312
|
+
push.receive("error", (response) => resolve(args.persist && typeof (response === null || response === void 0 ? void 0 : response.error) === "string" ? response.error : "error"));
|
|
4282
4313
|
push.receive("timeout", () => resolve("timed out"));
|
|
4283
4314
|
});
|
|
4284
4315
|
}
|
|
@@ -4398,8 +4429,8 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4398
4429
|
}
|
|
4399
4430
|
/** @internal */
|
|
4400
4431
|
_notThisChannelEvent(event, ref) {
|
|
4401
|
-
const { close, error, leave, join:
|
|
4402
|
-
const events = [close, error, leave,
|
|
4432
|
+
const { close, error, leave, join: join9 } = constants_1.CHANNEL_EVENTS;
|
|
4433
|
+
const events = [close, error, leave, join9];
|
|
4403
4434
|
return ref && events.includes(event) && ref !== this.joinPush.ref;
|
|
4404
4435
|
}
|
|
4405
4436
|
/** @internal */
|
|
@@ -4472,9 +4503,9 @@ var require_RealtimeChannel = __commonJS({
|
|
|
4472
4503
|
}
|
|
4473
4504
|
});
|
|
4474
4505
|
|
|
4475
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
4506
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js
|
|
4476
4507
|
var require_socketAdapter = __commonJS({
|
|
4477
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
4508
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/phoenix/socketAdapter.js"(exports2) {
|
|
4478
4509
|
"use strict";
|
|
4479
4510
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4480
4511
|
var phoenix_1 = require_phoenix_cjs();
|
|
@@ -4593,9 +4624,9 @@ var require_socketAdapter = __commonJS({
|
|
|
4593
4624
|
}
|
|
4594
4625
|
});
|
|
4595
4626
|
|
|
4596
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
4627
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js
|
|
4597
4628
|
var require_RealtimeClient = __commonJS({
|
|
4598
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
4629
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/RealtimeClient.js"(exports2) {
|
|
4599
4630
|
"use strict";
|
|
4600
4631
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4601
4632
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -5242,7 +5273,7 @@ var require_RealtimeClient = __commonJS({
|
|
|
5242
5273
|
defaultDecode = this.serializer.decode.bind(this.serializer);
|
|
5243
5274
|
break;
|
|
5244
5275
|
default:
|
|
5245
|
-
throw new Error(`Unsupported serializer version: ${
|
|
5276
|
+
throw new Error(`Unsupported serializer version: ${vsn}`);
|
|
5246
5277
|
}
|
|
5247
5278
|
result.vsn = vsn;
|
|
5248
5279
|
result.encode = (_l = options === null || options === void 0 ? void 0 : options.encode) !== null && _l !== void 0 ? _l : defaultEncode;
|
|
@@ -5273,9 +5304,9 @@ var require_RealtimeClient = __commonJS({
|
|
|
5273
5304
|
}
|
|
5274
5305
|
});
|
|
5275
5306
|
|
|
5276
|
-
// ../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
5307
|
+
// ../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/index.js
|
|
5277
5308
|
var require_main2 = __commonJS({
|
|
5278
|
-
"../../node_modules/.pnpm/@supabase+realtime-js@2.
|
|
5309
|
+
"../../node_modules/.pnpm/@supabase+realtime-js@2.119.2/node_modules/@supabase/realtime-js/dist/main/index.js"(exports2) {
|
|
5279
5310
|
"use strict";
|
|
5280
5311
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5281
5312
|
exports2.WebSocketFactory = exports2.REALTIME_CHANNEL_STATES = exports2.REALTIME_SUBSCRIBE_STATES = exports2.REALTIME_PRESENCE_LISTEN_EVENTS = exports2.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports2.REALTIME_LISTEN_TYPES = exports2.postgresChangesFilter = exports2.RealtimePostgresFilterBuilder = exports2.RealtimeClient = exports2.RealtimeChannel = exports2.RealtimePresence = void 0;
|
|
@@ -5312,19 +5343,19 @@ var require_main2 = __commonJS({
|
|
|
5312
5343
|
}
|
|
5313
5344
|
});
|
|
5314
5345
|
|
|
5315
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5346
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/version.js
|
|
5316
5347
|
var require_version2 = __commonJS({
|
|
5317
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5348
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/version.js"(exports2) {
|
|
5318
5349
|
"use strict";
|
|
5319
5350
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5320
5351
|
exports2.version = void 0;
|
|
5321
|
-
exports2.version = "2.
|
|
5352
|
+
exports2.version = "2.119.2";
|
|
5322
5353
|
}
|
|
5323
5354
|
});
|
|
5324
5355
|
|
|
5325
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5356
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/constants.js
|
|
5326
5357
|
var require_constants2 = __commonJS({
|
|
5327
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5358
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/constants.js"(exports2) {
|
|
5328
5359
|
"use strict";
|
|
5329
5360
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5330
5361
|
exports2.JWKS_TTL = exports2.PKCE_MAX_CONCURRENT_FLOWS = exports2.PKCE_FLOW_ID_PARAM = exports2.BASE64URL_REGEX = exports2.API_VERSIONS = exports2.API_VERSION_HEADER_NAME = exports2.NETWORK_FAILURE = exports2.DEFAULT_HEADERS = exports2.AUDIENCE = exports2.STORAGE_KEY = exports2.GOTRUE_URL = exports2.REFRESH_FAILURE_COOLDOWN_MS = exports2.EXPIRY_MARGIN_MS = exports2.AUTO_REFRESH_TICK_THRESHOLD = exports2.AUTO_REFRESH_TICK_DURATION_MS = void 0;
|
|
@@ -5356,9 +5387,9 @@ var require_constants2 = __commonJS({
|
|
|
5356
5387
|
}
|
|
5357
5388
|
});
|
|
5358
5389
|
|
|
5359
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5390
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/errors.js
|
|
5360
5391
|
var require_errors = __commonJS({
|
|
5361
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5392
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/errors.js"(exports2) {
|
|
5362
5393
|
"use strict";
|
|
5363
5394
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5364
5395
|
exports2.AuthInvalidJwtError = exports2.AuthWeakPasswordError = exports2.AuthRefreshDiscardedError = exports2.AuthRetryableFetchError = exports2.AuthPKCECodeVerifierMissingError = exports2.AuthPKCEGrantCodeExchangeError = exports2.AuthImplicitGrantRedirectError = exports2.AuthInvalidCredentialsError = exports2.AuthInvalidTokenResponseError = exports2.AuthSessionMissingError = exports2.CustomAuthError = exports2.AuthUnknownError = exports2.AuthApiError = exports2.AuthError = void 0;
|
|
@@ -5514,9 +5545,9 @@ var require_errors = __commonJS({
|
|
|
5514
5545
|
}
|
|
5515
5546
|
});
|
|
5516
5547
|
|
|
5517
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5548
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/base64url.js
|
|
5518
5549
|
var require_base64url = __commonJS({
|
|
5519
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5550
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/base64url.js"(exports2) {
|
|
5520
5551
|
"use strict";
|
|
5521
5552
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5522
5553
|
exports2.byteToBase64URL = byteToBase64URL;
|
|
@@ -5704,9 +5735,9 @@ var require_base64url = __commonJS({
|
|
|
5704
5735
|
}
|
|
5705
5736
|
});
|
|
5706
5737
|
|
|
5707
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5738
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/helpers.js
|
|
5708
5739
|
var require_helpers = __commonJS({
|
|
5709
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
5740
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/helpers.js"(exports2) {
|
|
5710
5741
|
"use strict";
|
|
5711
5742
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5712
5743
|
exports2.pkceVerifierSlotKey = exports2.Deferred = exports2.removeItemAsync = exports2.getItemAsync = exports2.setItemAsync = exports2.looksLikeFetchResponse = exports2.resolveFetch = exports2.supportsLocalStorage = exports2.isBrowser = void 0;
|
|
@@ -5886,8 +5917,8 @@ var require_helpers = __commonJS({
|
|
|
5886
5917
|
});
|
|
5887
5918
|
return promise;
|
|
5888
5919
|
}
|
|
5889
|
-
function dec2hex(
|
|
5890
|
-
return ("0" +
|
|
5920
|
+
function dec2hex(dec2) {
|
|
5921
|
+
return ("0" + dec2.toString(16)).substr(-2);
|
|
5891
5922
|
}
|
|
5892
5923
|
function generatePKCEVerifier() {
|
|
5893
5924
|
const verifierLength = 56;
|
|
@@ -5904,7 +5935,7 @@ var require_helpers = __commonJS({
|
|
|
5904
5935
|
crypto.getRandomValues(array);
|
|
5905
5936
|
return Array.from(array, dec2hex).join("");
|
|
5906
5937
|
}
|
|
5907
|
-
async function
|
|
5938
|
+
async function sha2562(randomString) {
|
|
5908
5939
|
const encoder = new TextEncoder();
|
|
5909
5940
|
const encodedData = encoder.encode(randomString);
|
|
5910
5941
|
const hash = await crypto.subtle.digest("SHA-256", encodedData);
|
|
@@ -5917,7 +5948,7 @@ var require_helpers = __commonJS({
|
|
|
5917
5948
|
console.warn("WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256.");
|
|
5918
5949
|
return verifier;
|
|
5919
5950
|
}
|
|
5920
|
-
const hashed = await
|
|
5951
|
+
const hashed = await sha2562(verifier);
|
|
5921
5952
|
return btoa(hashed).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
5922
5953
|
}
|
|
5923
5954
|
var PKCE_FLOW_ID_PATTERN = /^[a-zA-Z0-9_-]{8,64}$/;
|
|
@@ -6120,9 +6151,9 @@ var require_helpers = __commonJS({
|
|
|
6120
6151
|
}
|
|
6121
6152
|
});
|
|
6122
6153
|
|
|
6123
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6154
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/fetch.js
|
|
6124
6155
|
var require_fetch = __commonJS({
|
|
6125
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6156
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/fetch.js"(exports2) {
|
|
6126
6157
|
"use strict";
|
|
6127
6158
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6128
6159
|
exports2.handleError = handleError2;
|
|
@@ -6307,9 +6338,9 @@ var require_fetch = __commonJS({
|
|
|
6307
6338
|
}
|
|
6308
6339
|
});
|
|
6309
6340
|
|
|
6310
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6341
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/types.js
|
|
6311
6342
|
var require_types2 = __commonJS({
|
|
6312
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6343
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/types.js"(exports2) {
|
|
6313
6344
|
"use strict";
|
|
6314
6345
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6315
6346
|
exports2.SIGN_OUT_SCOPES = void 0;
|
|
@@ -6317,9 +6348,9 @@ var require_types2 = __commonJS({
|
|
|
6317
6348
|
}
|
|
6318
6349
|
});
|
|
6319
6350
|
|
|
6320
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6351
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js
|
|
6321
6352
|
var require_GoTrueAdminApi = __commonJS({
|
|
6322
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
6353
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/GoTrueAdminApi.js"(exports2) {
|
|
6323
6354
|
"use strict";
|
|
6324
6355
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6325
6356
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -7015,6 +7046,8 @@ var require_GoTrueAdminApi = __commonJS({
|
|
|
7015
7046
|
}
|
|
7016
7047
|
/**
|
|
7017
7048
|
* Delete a user. Requires a `service_role` key.
|
|
7049
|
+
* Returns the user that was deleted. In cases of concurrent updates, the user object returned
|
|
7050
|
+
* might not accurately reflect the user information at the time of deletion.
|
|
7018
7051
|
*
|
|
7019
7052
|
* @param id The user id you want to remove.
|
|
7020
7053
|
* @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible.
|
|
@@ -7039,7 +7072,14 @@ var require_GoTrueAdminApi = __commonJS({
|
|
|
7039
7072
|
* ```json
|
|
7040
7073
|
* {
|
|
7041
7074
|
* "data": {
|
|
7042
|
-
* "user": {
|
|
7075
|
+
* "user": {
|
|
7076
|
+
* "id": "715ed5db-f090-4b8c-a067-640ecee36aa0",
|
|
7077
|
+
* "aud": "authenticated",
|
|
7078
|
+
* "role": "authenticated",
|
|
7079
|
+
* "email": "example@email.com",
|
|
7080
|
+
* "created_at": "2024-01-01T00:00:00Z",
|
|
7081
|
+
* "updated_at": "2024-01-01T00:00:00Z"
|
|
7082
|
+
* }
|
|
7043
7083
|
* },
|
|
7044
7084
|
* "error": null
|
|
7045
7085
|
* }
|
|
@@ -7048,13 +7088,18 @@ var require_GoTrueAdminApi = __commonJS({
|
|
|
7048
7088
|
async deleteUser(id, shouldSoftDelete = false) {
|
|
7049
7089
|
(0, helpers_1.validateUUID)(id);
|
|
7050
7090
|
try {
|
|
7051
|
-
|
|
7091
|
+
const { data, error } = await this.getUserById(id);
|
|
7092
|
+
if (error) {
|
|
7093
|
+
return { data: { user: null }, error };
|
|
7094
|
+
}
|
|
7095
|
+
await (0, fetch_1._request)(this.fetch, "DELETE", `${this.url}/admin/users/${id}`, {
|
|
7052
7096
|
headers: this.headers,
|
|
7053
7097
|
body: {
|
|
7054
7098
|
should_soft_delete: shouldSoftDelete
|
|
7055
7099
|
},
|
|
7056
|
-
|
|
7100
|
+
noResolveJson: true
|
|
7057
7101
|
});
|
|
7102
|
+
return { data, error: null };
|
|
7058
7103
|
} catch (error) {
|
|
7059
7104
|
if ((0, errors_1.isAuthError)(error)) {
|
|
7060
7105
|
return { data: { user: null }, error };
|
|
@@ -7397,9 +7442,9 @@ var require_GoTrueAdminApi = __commonJS({
|
|
|
7397
7442
|
}
|
|
7398
7443
|
});
|
|
7399
7444
|
|
|
7400
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7445
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js
|
|
7401
7446
|
var require_local_storage = __commonJS({
|
|
7402
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7447
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/local-storage.js"(exports2) {
|
|
7403
7448
|
"use strict";
|
|
7404
7449
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7405
7450
|
exports2.memoryLocalStorageAdapter = memoryLocalStorageAdapter;
|
|
@@ -7419,9 +7464,9 @@ var require_local_storage = __commonJS({
|
|
|
7419
7464
|
}
|
|
7420
7465
|
});
|
|
7421
7466
|
|
|
7422
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7467
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/locks.js
|
|
7423
7468
|
var require_locks = __commonJS({
|
|
7424
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7469
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/locks.js"(exports2) {
|
|
7425
7470
|
"use strict";
|
|
7426
7471
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7427
7472
|
exports2.ProcessLockAcquireTimeoutError = exports2.NavigatorLockAcquireTimeoutError = exports2.LockAcquireTimeoutError = exports2.internals = void 0;
|
|
@@ -7595,9 +7640,9 @@ var require_locks = __commonJS({
|
|
|
7595
7640
|
}
|
|
7596
7641
|
});
|
|
7597
7642
|
|
|
7598
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7643
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js
|
|
7599
7644
|
var require_polyfills = __commonJS({
|
|
7600
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7645
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/polyfills.js"(exports2) {
|
|
7601
7646
|
"use strict";
|
|
7602
7647
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7603
7648
|
exports2.polyfillGlobalThis = polyfillGlobalThis;
|
|
@@ -7622,9 +7667,9 @@ var require_polyfills = __commonJS({
|
|
|
7622
7667
|
}
|
|
7623
7668
|
});
|
|
7624
7669
|
|
|
7625
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7670
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js
|
|
7626
7671
|
var require_ethereum = __commonJS({
|
|
7627
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7672
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/web3/ethereum.js"(exports2) {
|
|
7628
7673
|
"use strict";
|
|
7629
7674
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7630
7675
|
exports2.getAddress = getAddress;
|
|
@@ -7700,9 +7745,9 @@ ${suffix}`;
|
|
|
7700
7745
|
}
|
|
7701
7746
|
});
|
|
7702
7747
|
|
|
7703
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7748
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js
|
|
7704
7749
|
var require_webauthn_errors = __commonJS({
|
|
7705
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7750
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/webauthn.errors.js"(exports2) {
|
|
7706
7751
|
"use strict";
|
|
7707
7752
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7708
7753
|
exports2.WebAuthnUnknownError = exports2.WebAuthnError = void 0;
|
|
@@ -7891,9 +7936,9 @@ var require_webauthn_errors = __commonJS({
|
|
|
7891
7936
|
}
|
|
7892
7937
|
});
|
|
7893
7938
|
|
|
7894
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7939
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js
|
|
7895
7940
|
var require_webauthn = __commonJS({
|
|
7896
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
7941
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/lib/webauthn.js"(exports2) {
|
|
7897
7942
|
"use strict";
|
|
7898
7943
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
7899
7944
|
exports2.WebAuthnApi = exports2.DEFAULT_REQUEST_OPTIONS = exports2.DEFAULT_CREATION_OPTIONS = exports2.webAuthnAbortService = exports2.WebAuthnAbortService = exports2.identifyAuthenticationError = exports2.identifyRegistrationError = exports2.isWebAuthnError = exports2.WebAuthnError = void 0;
|
|
@@ -8063,10 +8108,10 @@ var require_webauthn = __commonJS({
|
|
|
8063
8108
|
authenticatorAttachment: (_a = credentialWithAttachment.authenticatorAttachment) !== null && _a !== void 0 ? _a : void 0
|
|
8064
8109
|
};
|
|
8065
8110
|
}
|
|
8066
|
-
function isValidDomain(
|
|
8111
|
+
function isValidDomain(hostname4) {
|
|
8067
8112
|
return (
|
|
8068
8113
|
// Consider localhost valid as well since it's okay wrt Secure Contexts
|
|
8069
|
-
|
|
8114
|
+
hostname4 === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname4)
|
|
8070
8115
|
);
|
|
8071
8116
|
}
|
|
8072
8117
|
function browserSupportsWebAuthn() {
|
|
@@ -8450,9 +8495,9 @@ var require_webauthn = __commonJS({
|
|
|
8450
8495
|
}
|
|
8451
8496
|
});
|
|
8452
8497
|
|
|
8453
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
8498
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js
|
|
8454
8499
|
var require_GoTrueClient = __commonJS({
|
|
8455
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
8500
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/GoTrueClient.js"(exports2) {
|
|
8456
8501
|
"use strict";
|
|
8457
8502
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8458
8503
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -9136,7 +9181,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
9136
9181
|
* Be aware that you may get back an error message that will not distinguish
|
|
9137
9182
|
* between the cases where the account does not exist or that the
|
|
9138
9183
|
* email/phone and password combination is wrong or that the account can only
|
|
9139
|
-
* be accessed via social
|
|
9184
|
+
* be accessed via social sign-in.
|
|
9140
9185
|
*
|
|
9141
9186
|
* @category Auth
|
|
9142
9187
|
*
|
|
@@ -9319,7 +9364,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
9319
9364
|
* @category Auth
|
|
9320
9365
|
*
|
|
9321
9366
|
* @remarks
|
|
9322
|
-
* - This method is used for signing in using [
|
|
9367
|
+
* - This method is used for signing in using [social sign-in (OAuth) providers](/docs/guides/auth/social-sign-in).
|
|
9323
9368
|
* - It works by redirecting your application to the provider's authorization screen, before bringing back the user to your app.
|
|
9324
9369
|
*
|
|
9325
9370
|
* @example Sign in using a third-party provider
|
|
@@ -10051,7 +10096,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
10051
10096
|
*
|
|
10052
10097
|
* Be aware that you may get back an error message that will not distinguish
|
|
10053
10098
|
* between the cases where the account does not exist or, that the account
|
|
10054
|
-
* can only be accessed via social
|
|
10099
|
+
* can only be accessed via social sign-in.
|
|
10055
10100
|
*
|
|
10056
10101
|
* Do note that you will need to configure a Whatsapp sender on Twilio
|
|
10057
10102
|
* if you are using phone sign in with the 'whatsapp' channel. The whatsapp
|
|
@@ -11566,12 +11611,31 @@ var require_GoTrueClient = __commonJS({
|
|
|
11566
11611
|
return !!currentStorageContent;
|
|
11567
11612
|
}
|
|
11568
11613
|
/**
|
|
11569
|
-
* Inside a browser context, `signOut()` will remove the logged in user from the browser session
|
|
11614
|
+
* Inside a browser context, `signOut()` will remove the logged in user from the browser session
|
|
11615
|
+
* and log them out - removing all items from localstorage and then trigger a `"SIGNED_OUT"`
|
|
11616
|
+
* event.
|
|
11617
|
+
*
|
|
11618
|
+
* For server-side management, you can revoke all refresh tokens for a user by passing a user's
|
|
11619
|
+
* JWT through to `auth.api.signOut(JWT: string)`.
|
|
11570
11620
|
*
|
|
11571
|
-
*
|
|
11572
|
-
*
|
|
11621
|
+
* There is no way to revoke a user's access token jwt until it expires. It is recommended to set
|
|
11622
|
+
* a shorter expiry on the jwt for this reason.
|
|
11573
11623
|
*
|
|
11574
|
-
*
|
|
11624
|
+
* `signOut` behavior depends on the selected scope:
|
|
11625
|
+
*
|
|
11626
|
+
* - `local`: The local session is removed first and a `SIGNED_OUT` event is fired, then the client
|
|
11627
|
+
* makes a best-effort request to revoke the refresh token on the server. If the request fails,
|
|
11628
|
+
* the client is still signed out locally and the error is returned, but the server may retain
|
|
11629
|
+
* the refresh token until it expires.
|
|
11630
|
+
*
|
|
11631
|
+
* - `global`: All of the user's sessions are first invalidated on the server. Once the server
|
|
11632
|
+
* acknowledges the request, the local session is cleared. If server logout fails, the local
|
|
11633
|
+
* session is retained, no `SIGNED_OUT` event is triggered, and the server or network error is
|
|
11634
|
+
* returned. A 401, 403, or 404 response counts as a successful sign-out.
|
|
11635
|
+
*
|
|
11636
|
+
* - `others`: All other sessions are invalidated when the server accepts the request; the
|
|
11637
|
+
* current local session remains unchanged. In case of server or network failures, the error is
|
|
11638
|
+
* returned. A `SIGNED_OUT` event is never triggered, regardless of the outcome.
|
|
11575
11639
|
*
|
|
11576
11640
|
* **Warning:** the default `scope` is `'global'`. This signs the user out of
|
|
11577
11641
|
* **every device they are currently signed in on**, not just the current
|
|
@@ -11589,7 +11653,13 @@ var require_GoTrueClient = __commonJS({
|
|
|
11589
11653
|
* usually what apps want on a "Sign out" button, especially when users
|
|
11590
11654
|
* sign in from multiple devices and do not expect signing out of one to
|
|
11591
11655
|
* terminate the others.
|
|
11592
|
-
* -
|
|
11656
|
+
* - With the default `global` scope, `signOut()` while offline returns an error and keeps the user
|
|
11657
|
+
* signed in. To sign out regardless, fall back to `signOut({ scope: 'local' })` when the call
|
|
11658
|
+
* returns an error.
|
|
11659
|
+
* - Since Supabase Auth uses JWTs for authentication, the access token JWT will be valid until
|
|
11660
|
+
* it's expired. When the user signs out, Supabase revokes the refresh token and deletes the
|
|
11661
|
+
* JWT from the client-side. This does not revoke the JWT and it will still be valid until it
|
|
11662
|
+
* expires.
|
|
11593
11663
|
*
|
|
11594
11664
|
* @example Sign out of every device (global – default)
|
|
11595
11665
|
* ```js
|
|
@@ -11615,7 +11685,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
11615
11685
|
}
|
|
11616
11686
|
return await this._signOut(options);
|
|
11617
11687
|
}
|
|
11618
|
-
async _signOut({ scope
|
|
11688
|
+
async _signOut({ scope = "global" } = {}) {
|
|
11619
11689
|
return await this._useSession(async (result) => {
|
|
11620
11690
|
var _a;
|
|
11621
11691
|
const removeCurrentSession = async () => {
|
|
@@ -11623,24 +11693,36 @@ var require_GoTrueClient = __commonJS({
|
|
|
11623
11693
|
};
|
|
11624
11694
|
const { data, error: sessionError } = result;
|
|
11625
11695
|
if (sessionError && !(0, errors_1.isAuthSessionMissingError)(sessionError)) {
|
|
11696
|
+
if (scope === "local" && (0, errors_1.isAuthRetryableFetchError)(sessionError)) {
|
|
11697
|
+
await removeCurrentSession();
|
|
11698
|
+
}
|
|
11626
11699
|
return this._returnResult({ error: sessionError });
|
|
11627
11700
|
}
|
|
11628
11701
|
const accessToken = (_a = data.session) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
11702
|
+
let removeError = null;
|
|
11703
|
+
const finish = (value) => {
|
|
11704
|
+
if (removeError) {
|
|
11705
|
+
throw removeError.thrown;
|
|
11706
|
+
}
|
|
11707
|
+
return value;
|
|
11708
|
+
};
|
|
11709
|
+
if (scope === "local") {
|
|
11710
|
+
try {
|
|
11711
|
+
await removeCurrentSession();
|
|
11712
|
+
} catch (thrown) {
|
|
11713
|
+
removeError = { thrown };
|
|
11714
|
+
}
|
|
11715
|
+
}
|
|
11629
11716
|
if (accessToken) {
|
|
11630
11717
|
const { error } = await this.admin.signOut(accessToken, scope);
|
|
11631
|
-
if (error) {
|
|
11632
|
-
|
|
11633
|
-
if (scope !== "others") {
|
|
11634
|
-
await removeCurrentSession();
|
|
11635
|
-
}
|
|
11636
|
-
return this._returnResult({ error });
|
|
11637
|
-
}
|
|
11718
|
+
if (error && !((0, errors_1.isAuthApiError)(error) && (error.status === 404 || error.status === 401 || error.status === 403) || (0, errors_1.isAuthSessionMissingError)(error))) {
|
|
11719
|
+
return finish(this._returnResult({ error }));
|
|
11638
11720
|
}
|
|
11639
11721
|
}
|
|
11640
|
-
if (scope
|
|
11722
|
+
if (scope === "global") {
|
|
11641
11723
|
await removeCurrentSession();
|
|
11642
11724
|
}
|
|
11643
|
-
return this._returnResult({ error: null });
|
|
11725
|
+
return finish(this._returnResult({ error: null }));
|
|
11644
11726
|
});
|
|
11645
11727
|
}
|
|
11646
11728
|
/** *
|
|
@@ -11728,9 +11810,9 @@ var require_GoTrueClient = __commonJS({
|
|
|
11728
11810
|
* ```
|
|
11729
11811
|
*
|
|
11730
11812
|
* @exampleDescription Store OAuth provider tokens on sign in
|
|
11731
|
-
* When using [OAuth (
|
|
11813
|
+
* When using [OAuth (social sign-in)](/docs/guides/auth/social-sign-in) you sometimes wish to get access to the provider's access token and refresh token, in order to call provider APIs in the name of the user.
|
|
11732
11814
|
*
|
|
11733
|
-
* For example, if you are using [Sign in with Google](/docs/guides/auth/social-
|
|
11815
|
+
* For example, if you are using [Sign in with Google](/docs/guides/auth/social-sign-in/auth-google) you may want to use the provider token to call Google APIs on behalf of the user. Supabase Auth does not keep track of the provider access and refresh token, but does return them for you once, immediately after sign in. You can use the `onAuthStateChange` method to listen for the presence of the provider tokens and store them in local storage. You can further send them to your server's APIs for use on the backend.
|
|
11734
11816
|
*
|
|
11735
11817
|
* Finally, make sure you remove them from local storage on the `SIGNED_OUT` event. If the OAuth provider supports token revocation, make sure you call those APIs either from the frontend or schedule them to be called on the backend.
|
|
11736
11818
|
*
|
|
@@ -12881,7 +12963,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
12881
12963
|
}
|
|
12882
12964
|
}
|
|
12883
12965
|
async _verify(params) {
|
|
12884
|
-
const
|
|
12966
|
+
const run2 = async () => {
|
|
12885
12967
|
try {
|
|
12886
12968
|
return await this._useSession(async (result) => {
|
|
12887
12969
|
var _a;
|
|
@@ -12912,12 +12994,12 @@ var require_GoTrueClient = __commonJS({
|
|
|
12912
12994
|
}
|
|
12913
12995
|
};
|
|
12914
12996
|
if (this.lock != null) {
|
|
12915
|
-
return this._acquireLock(this.lockAcquireTimeout,
|
|
12997
|
+
return this._acquireLock(this.lockAcquireTimeout, run2);
|
|
12916
12998
|
}
|
|
12917
|
-
return
|
|
12999
|
+
return run2();
|
|
12918
13000
|
}
|
|
12919
13001
|
async _challenge(params) {
|
|
12920
|
-
const
|
|
13002
|
+
const run2 = async () => {
|
|
12921
13003
|
try {
|
|
12922
13004
|
return await this._useSession(async (result) => {
|
|
12923
13005
|
var _a;
|
|
@@ -12958,9 +13040,9 @@ var require_GoTrueClient = __commonJS({
|
|
|
12958
13040
|
}
|
|
12959
13041
|
};
|
|
12960
13042
|
if (this.lock != null) {
|
|
12961
|
-
return this._acquireLock(this.lockAcquireTimeout,
|
|
13043
|
+
return this._acquireLock(this.lockAcquireTimeout, run2);
|
|
12962
13044
|
}
|
|
12963
|
-
return
|
|
13045
|
+
return run2();
|
|
12964
13046
|
}
|
|
12965
13047
|
/**
|
|
12966
13048
|
* {@link GoTrueMFAApi#challengeAndVerify}
|
|
@@ -13122,7 +13204,7 @@ var require_GoTrueClient = __commonJS({
|
|
|
13122
13204
|
*/
|
|
13123
13205
|
async _verifyRecoveryCode(params) {
|
|
13124
13206
|
(0, helpers_1.assertRecoveryCodesExperimentalEnabled)(this.experimental);
|
|
13125
|
-
const
|
|
13207
|
+
const run2 = async () => {
|
|
13126
13208
|
try {
|
|
13127
13209
|
return await this._useSession(async (result) => {
|
|
13128
13210
|
var _a;
|
|
@@ -13151,9 +13233,9 @@ var require_GoTrueClient = __commonJS({
|
|
|
13151
13233
|
}
|
|
13152
13234
|
};
|
|
13153
13235
|
if (this.lock != null) {
|
|
13154
|
-
return this._acquireLock(this.lockAcquireTimeout,
|
|
13236
|
+
return this._acquireLock(this.lockAcquireTimeout, run2);
|
|
13155
13237
|
}
|
|
13156
|
-
return
|
|
13238
|
+
return run2();
|
|
13157
13239
|
}
|
|
13158
13240
|
/**
|
|
13159
13241
|
* {@link AuthMFARecoveryCodesApi#regenerate}
|
|
@@ -13849,9 +13931,9 @@ var require_GoTrueClient = __commonJS({
|
|
|
13849
13931
|
}
|
|
13850
13932
|
});
|
|
13851
13933
|
|
|
13852
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13934
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js
|
|
13853
13935
|
var require_AuthAdminApi = __commonJS({
|
|
13854
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13936
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/AuthAdminApi.js"(exports2) {
|
|
13855
13937
|
"use strict";
|
|
13856
13938
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13857
13939
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -13861,9 +13943,9 @@ var require_AuthAdminApi = __commonJS({
|
|
|
13861
13943
|
}
|
|
13862
13944
|
});
|
|
13863
13945
|
|
|
13864
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13946
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/AuthClient.js
|
|
13865
13947
|
var require_AuthClient = __commonJS({
|
|
13866
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13948
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/AuthClient.js"(exports2) {
|
|
13867
13949
|
"use strict";
|
|
13868
13950
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13869
13951
|
var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
|
|
@@ -13873,9 +13955,9 @@ var require_AuthClient = __commonJS({
|
|
|
13873
13955
|
}
|
|
13874
13956
|
});
|
|
13875
13957
|
|
|
13876
|
-
// ../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13958
|
+
// ../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/index.js
|
|
13877
13959
|
var require_main3 = __commonJS({
|
|
13878
|
-
"../../node_modules/.pnpm/@supabase+auth-js@2.
|
|
13960
|
+
"../../node_modules/.pnpm/@supabase+auth-js@2.119.2/node_modules/@supabase/auth-js/dist/main/index.js"(exports2) {
|
|
13879
13961
|
"use strict";
|
|
13880
13962
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
13881
13963
|
exports2.processLock = exports2.lockInternals = exports2.NavigatorLockAcquireTimeoutError = exports2.navigatorLock = exports2.AuthClient = exports2.AuthAdminApi = exports2.GoTrueClient = exports2.GoTrueAdminApi = void 0;
|
|
@@ -33546,11 +33628,11 @@ var require_dist = __commonJS({
|
|
|
33546
33628
|
});
|
|
33547
33629
|
|
|
33548
33630
|
// src/index.ts
|
|
33549
|
-
var
|
|
33550
|
-
var
|
|
33551
|
-
var
|
|
33631
|
+
var import_promises8 = require("node:readline/promises");
|
|
33632
|
+
var import_promises9 = require("node:fs/promises");
|
|
33633
|
+
var import_node_os10 = require("node:os");
|
|
33552
33634
|
|
|
33553
|
-
// ../../node_modules/.pnpm/@supabase+supabase-js@2.
|
|
33635
|
+
// ../../node_modules/.pnpm/@supabase+supabase-js@2.119.2_@opentelemetry+api@1.10.0/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
33554
33636
|
var dist_exports = {};
|
|
33555
33637
|
__export(dist_exports, {
|
|
33556
33638
|
FunctionRegion: () => import_functions_js.FunctionRegion,
|
|
@@ -33564,16 +33646,16 @@ __export(dist_exports, {
|
|
|
33564
33646
|
createClient: () => createClient
|
|
33565
33647
|
});
|
|
33566
33648
|
|
|
33567
|
-
// ../../node_modules/.pnpm/@supabase+supabase-js@2.
|
|
33649
|
+
// ../../node_modules/.pnpm/@supabase+supabase-js@2.119.2_@opentelemetry+api@1.10.0/node_modules/@supabase/supabase-js/dist/tracingRegistry.mjs
|
|
33568
33650
|
var EXTRACTOR_KEY = /* @__PURE__ */ Symbol.for("@supabase/supabase-js.traceContextExtractor");
|
|
33569
33651
|
function getTraceContextExtractor() {
|
|
33570
33652
|
return globalThis[EXTRACTOR_KEY];
|
|
33571
33653
|
}
|
|
33572
33654
|
|
|
33573
|
-
// ../../node_modules/.pnpm/@supabase+supabase-js@2.
|
|
33655
|
+
// ../../node_modules/.pnpm/@supabase+supabase-js@2.119.2_@opentelemetry+api@1.10.0/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
33574
33656
|
var import_functions_js = __toESM(require_main(), 1);
|
|
33575
33657
|
|
|
33576
|
-
// ../../node_modules/.pnpm/@supabase+postgrest-js@2.
|
|
33658
|
+
// ../../node_modules/.pnpm/@supabase+postgrest-js@2.119.2/node_modules/@supabase/postgrest-js/dist/index.mjs
|
|
33577
33659
|
var PostgrestError = class extends Error {
|
|
33578
33660
|
/**
|
|
33579
33661
|
* @example
|
|
@@ -37106,6 +37188,30 @@ function toTransportFailure(cause, status, statusText) {
|
|
|
37106
37188
|
statusText
|
|
37107
37189
|
};
|
|
37108
37190
|
}
|
|
37191
|
+
function withTimeout(fetch$1, timeout) {
|
|
37192
|
+
if (timeout === void 0 || timeout <= 0) return fetch$1;
|
|
37193
|
+
return (input, init) => {
|
|
37194
|
+
const controller = new AbortController();
|
|
37195
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
37196
|
+
const existingSignal = init === null || init === void 0 ? void 0 : init.signal;
|
|
37197
|
+
if (existingSignal) {
|
|
37198
|
+
if (existingSignal.aborted) {
|
|
37199
|
+
clearTimeout(timeoutId);
|
|
37200
|
+
return fetch$1(input, init);
|
|
37201
|
+
}
|
|
37202
|
+
const abortHandler = () => {
|
|
37203
|
+
clearTimeout(timeoutId);
|
|
37204
|
+
controller.abort();
|
|
37205
|
+
};
|
|
37206
|
+
existingSignal.addEventListener("abort", abortHandler, { once: true });
|
|
37207
|
+
return fetch$1(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => {
|
|
37208
|
+
clearTimeout(timeoutId);
|
|
37209
|
+
existingSignal.removeEventListener("abort", abortHandler);
|
|
37210
|
+
});
|
|
37211
|
+
}
|
|
37212
|
+
return fetch$1(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => clearTimeout(timeoutId));
|
|
37213
|
+
};
|
|
37214
|
+
}
|
|
37109
37215
|
var PostgrestClient = class PostgrestClient2 {
|
|
37110
37216
|
/**
|
|
37111
37217
|
* Creates a PostgREST client.
|
|
@@ -37121,6 +37227,10 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37121
37227
|
* When enabled, idempotent requests (GET, HEAD, OPTIONS) that fail with network
|
|
37122
37228
|
* errors or HTTP 503/520 responses will be automatically retried up to 3 times
|
|
37123
37229
|
* with exponential backoff (1s, 2s, 4s). Defaults to `true`.
|
|
37230
|
+
* @param options.wrapFetch - Wraps every fetch this client uses, including a per-request
|
|
37231
|
+
* `fetch` passed to `from()`, and is carried over to clients returned by `schema()`.
|
|
37232
|
+
* Use it for headers or instrumentation that must reach every request regardless of
|
|
37233
|
+
* which fetch performs it.
|
|
37124
37234
|
* @example Using supabase-js (recommended)
|
|
37125
37235
|
* ```ts
|
|
37126
37236
|
* import { createClient } from '@supabase/supabase-js'
|
|
@@ -37146,44 +37256,35 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37146
37256
|
* })
|
|
37147
37257
|
* ```
|
|
37148
37258
|
*/
|
|
37149
|
-
constructor(url, { headers = {}, schema, fetch: fetch$1, timeout, urlLengthLimit = 8e3, retry } = {}) {
|
|
37259
|
+
constructor(url, { headers = {}, schema, fetch: fetch$1, timeout, urlLengthLimit = 8e3, retry, wrapFetch } = {}) {
|
|
37150
37260
|
this.url = url;
|
|
37151
37261
|
this.headers = new Headers(headers);
|
|
37152
37262
|
this.schemaName = schema;
|
|
37153
37263
|
this.urlLengthLimit = urlLengthLimit;
|
|
37154
|
-
|
|
37155
|
-
|
|
37156
|
-
|
|
37157
|
-
|
|
37158
|
-
const existingSignal = init === null || init === void 0 ? void 0 : init.signal;
|
|
37159
|
-
if (existingSignal) {
|
|
37160
|
-
if (existingSignal.aborted) {
|
|
37161
|
-
clearTimeout(timeoutId);
|
|
37162
|
-
return originalFetch(input, init);
|
|
37163
|
-
}
|
|
37164
|
-
const abortHandler = () => {
|
|
37165
|
-
clearTimeout(timeoutId);
|
|
37166
|
-
controller.abort();
|
|
37167
|
-
};
|
|
37168
|
-
existingSignal.addEventListener("abort", abortHandler, { once: true });
|
|
37169
|
-
return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => {
|
|
37170
|
-
clearTimeout(timeoutId);
|
|
37171
|
-
existingSignal.removeEventListener("abort", abortHandler);
|
|
37172
|
-
});
|
|
37173
|
-
}
|
|
37174
|
-
return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => clearTimeout(timeoutId));
|
|
37175
|
-
};
|
|
37176
|
-
else this.fetch = originalFetch;
|
|
37264
|
+
this.timeout = timeout;
|
|
37265
|
+
this.wrapFetch = wrapFetch;
|
|
37266
|
+
this.baseFetch = fetch$1 !== null && fetch$1 !== void 0 ? fetch$1 : globalThis.fetch;
|
|
37267
|
+
this.fetch = this.baseFetch ? this.decorateFetch(this.baseFetch) : void 0;
|
|
37177
37268
|
this.retry = retry;
|
|
37178
37269
|
}
|
|
37179
|
-
|
|
37270
|
+
/**
|
|
37271
|
+
* Applies the client's decorations to a fetch implementation: `wrapFetch`
|
|
37272
|
+
* first, then the timeout guard, so the timeout bounds the whole wrapped call.
|
|
37273
|
+
* The client-level fetch and every per-request `fetch` passed to `from()` go
|
|
37274
|
+
* through this.
|
|
37275
|
+
*/
|
|
37276
|
+
decorateFetch(fetch$1) {
|
|
37277
|
+
return withTimeout(this.wrapFetch ? this.wrapFetch(fetch$1) : fetch$1, this.timeout);
|
|
37278
|
+
}
|
|
37279
|
+
from(relation, options) {
|
|
37280
|
+
var _options$urlLengthLim, _options$retry;
|
|
37180
37281
|
if (!relation || typeof relation !== "string" || relation.trim() === "") throw new Error("Invalid relation name: relation must be a non-empty string.");
|
|
37181
37282
|
return new PostgrestQueryBuilder(new URL(`${this.url}/${relation}`), {
|
|
37182
37283
|
headers: new Headers(this.headers),
|
|
37183
37284
|
schema: this.schemaName,
|
|
37184
|
-
fetch: this.fetch,
|
|
37185
|
-
urlLengthLimit: this.urlLengthLimit,
|
|
37186
|
-
retry: this.retry
|
|
37285
|
+
fetch: (options === null || options === void 0 ? void 0 : options.fetch) ? this.decorateFetch(options.fetch) : this.fetch,
|
|
37286
|
+
urlLengthLimit: (_options$urlLengthLim = options === null || options === void 0 ? void 0 : options.urlLengthLimit) !== null && _options$urlLengthLim !== void 0 ? _options$urlLengthLim : this.urlLengthLimit,
|
|
37287
|
+
retry: (_options$retry = options === null || options === void 0 ? void 0 : options.retry) !== null && _options$retry !== void 0 ? _options$retry : this.retry
|
|
37187
37288
|
});
|
|
37188
37289
|
}
|
|
37189
37290
|
/**
|
|
@@ -37199,7 +37300,9 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37199
37300
|
return new PostgrestClient2(this.url, {
|
|
37200
37301
|
headers: this.headers,
|
|
37201
37302
|
schema,
|
|
37202
|
-
fetch: this.
|
|
37303
|
+
fetch: this.baseFetch,
|
|
37304
|
+
timeout: this.timeout,
|
|
37305
|
+
wrapFetch: this.wrapFetch,
|
|
37203
37306
|
urlLengthLimit: this.urlLengthLimit,
|
|
37204
37307
|
retry: this.retry
|
|
37205
37308
|
});
|
|
@@ -37472,7 +37575,7 @@ var PostgrestClient = class PostgrestClient2 {
|
|
|
37472
37575
|
}
|
|
37473
37576
|
};
|
|
37474
37577
|
|
|
37475
|
-
// ../../node_modules/.pnpm/@supabase+supabase-js@2.
|
|
37578
|
+
// ../../node_modules/.pnpm/@supabase+supabase-js@2.119.2_@opentelemetry+api@1.10.0/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
37476
37579
|
var import_realtime_js = __toESM(require_main2(), 1);
|
|
37477
37580
|
|
|
37478
37581
|
// ../../node_modules/.pnpm/iceberg-js@0.8.1/node_modules/iceberg-js/dist/index.mjs
|
|
@@ -38008,7 +38111,7 @@ var IcebergRestCatalog = class {
|
|
|
38008
38111
|
}
|
|
38009
38112
|
};
|
|
38010
38113
|
|
|
38011
|
-
// ../../node_modules/.pnpm/@supabase+storage-js@2.
|
|
38114
|
+
// ../../node_modules/.pnpm/@supabase+storage-js@2.119.2/node_modules/@supabase/storage-js/dist/index.mjs
|
|
38012
38115
|
function _typeof2(o) {
|
|
38013
38116
|
"@babel/helpers - typeof";
|
|
38014
38117
|
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
@@ -38380,6 +38483,12 @@ var BlobDownloadBuilder = class {
|
|
|
38380
38483
|
}
|
|
38381
38484
|
}
|
|
38382
38485
|
};
|
|
38486
|
+
function validateStorageUrl(input, expected) {
|
|
38487
|
+
const url = new URL(input);
|
|
38488
|
+
const prefix = expected.pathname.endsWith("/") ? expected.pathname : `${expected.pathname}/`;
|
|
38489
|
+
if (url.origin !== expected.origin || !url.pathname.startsWith(prefix)) throw new StorageError("Object path escapes the intended bucket endpoint");
|
|
38490
|
+
return url.href;
|
|
38491
|
+
}
|
|
38383
38492
|
var DEFAULT_SEARCH_OPTIONS = {
|
|
38384
38493
|
limit: 100,
|
|
38385
38494
|
offset: 0,
|
|
@@ -38393,6 +38502,10 @@ var DEFAULT_FILE_OPTIONS = {
|
|
|
38393
38502
|
contentType: "text/plain;charset=UTF-8",
|
|
38394
38503
|
upsert: false
|
|
38395
38504
|
};
|
|
38505
|
+
function mergeFileOptions(fileOptions) {
|
|
38506
|
+
const definedOptions = Object.fromEntries(Object.entries(fileOptions !== null && fileOptions !== void 0 ? fileOptions : {}).filter(([, value]) => value !== void 0));
|
|
38507
|
+
return _objectSpread22(_objectSpread22({}, DEFAULT_FILE_OPTIONS), definedOptions);
|
|
38508
|
+
}
|
|
38396
38509
|
var StorageFileApi = class extends BaseApiClient {
|
|
38397
38510
|
constructor(url, headers = {}, bucketId, fetch$1) {
|
|
38398
38511
|
super(url, headers, fetch$1, "storage");
|
|
@@ -38409,7 +38522,7 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38409
38522
|
var _this = this;
|
|
38410
38523
|
return _this.handleOperation(async () => {
|
|
38411
38524
|
let body;
|
|
38412
|
-
const options =
|
|
38525
|
+
const options = mergeFileOptions(fileOptions);
|
|
38413
38526
|
let headers = _objectSpread22(_objectSpread22({}, _this.headers), method === "POST" && { "x-upsert": String(options.upsert) });
|
|
38414
38527
|
const metadata = options.metadata;
|
|
38415
38528
|
if (typeof Blob !== "undefined" && fileBody instanceof Blob || typeof FormData !== "undefined" && fileBody instanceof FormData) body = _this.prepareUploadFormData(fileBody, options);
|
|
@@ -38423,8 +38536,7 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38423
38536
|
}
|
|
38424
38537
|
if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) for (const [key, value] of Object.entries(fileOptions.headers)) headers = setHeader(headers, key, value);
|
|
38425
38538
|
const cleanPath = _this._removeEmptyFolders(path);
|
|
38426
|
-
const
|
|
38427
|
-
const data = await (method == "PUT" ? put : post)(_this.fetch, `${_this.url}/object/${_path}`, body, _objectSpread22({ headers }, (options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {}));
|
|
38539
|
+
const data = await (method == "PUT" ? put : post)(_this.fetch, _this._getRequestUrl("object", cleanPath), body, _objectSpread22({ headers }, (options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {}));
|
|
38428
38540
|
return {
|
|
38429
38541
|
path: cleanPath,
|
|
38430
38542
|
id: data.Id,
|
|
@@ -38543,12 +38655,11 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38543
38655
|
async uploadToSignedUrl(path, token, fileBody, fileOptions) {
|
|
38544
38656
|
var _this3 = this;
|
|
38545
38657
|
const cleanPath = _this3._removeEmptyFolders(path);
|
|
38546
|
-
const _path = _this3._getFinalPath(cleanPath);
|
|
38547
|
-
const url = new URL(_this3.url + `/object/upload/sign/${_path}`);
|
|
38548
|
-
url.searchParams.set("token", token);
|
|
38549
38658
|
return _this3.handleOperation(async () => {
|
|
38659
|
+
const url = new URL(_this3._getRequestUrl("object/upload/sign", cleanPath));
|
|
38660
|
+
url.searchParams.set("token", token);
|
|
38550
38661
|
let body;
|
|
38551
|
-
const options =
|
|
38662
|
+
const options = mergeFileOptions(fileOptions);
|
|
38552
38663
|
let headers = _objectSpread22(_objectSpread22({}, _this3.headers), { "x-upsert": String(options.upsert) });
|
|
38553
38664
|
const metadata = options.metadata;
|
|
38554
38665
|
if (typeof Blob !== "undefined" && fileBody instanceof Blob || typeof FormData !== "undefined" && fileBody instanceof FormData) body = _this3.prepareUploadFormData(fileBody, options);
|
|
@@ -38607,10 +38718,9 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38607
38718
|
async createSignedUploadUrl(path, options) {
|
|
38608
38719
|
var _this4 = this;
|
|
38609
38720
|
return _this4.handleOperation(async () => {
|
|
38610
|
-
let _path = _this4._getFinalPath(path);
|
|
38611
38721
|
const headers = _objectSpread22({}, _this4.headers);
|
|
38612
38722
|
if (options === null || options === void 0 ? void 0 : options.upsert) headers["x-upsert"] = "true";
|
|
38613
|
-
const data = await post(_this4.fetch,
|
|
38723
|
+
const data = await post(_this4.fetch, _this4._getRequestUrl("object/upload/sign", path), {}, { headers });
|
|
38614
38724
|
const url = new URL(_this4.url + data.url);
|
|
38615
38725
|
const token = url.searchParams.get("token");
|
|
38616
38726
|
if (!token) throw new StorageError("No token returned by API");
|
|
@@ -38853,9 +38963,8 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38853
38963
|
async createSignedUrl(path, expiresIn, options) {
|
|
38854
38964
|
var _this8 = this;
|
|
38855
38965
|
return _this8.handleOperation(async () => {
|
|
38856
|
-
let _path = _this8._getFinalPath(path);
|
|
38857
38966
|
const hasTransform = typeof (options === null || options === void 0 ? void 0 : options.transform) === "object" && options.transform !== null && Object.keys(options.transform).length > 0;
|
|
38858
|
-
let data = await post(_this8.fetch,
|
|
38967
|
+
let data = await post(_this8.fetch, _this8._getRequestUrl("object/sign", path), _objectSpread22(_objectSpread22({ expiresIn }, hasTransform ? { transform: options.transform } : {}), (options === null || options === void 0 ? void 0 : options.versionId) != null ? { versionId: options.versionId } : {}), { headers: _this8.headers });
|
|
38859
38968
|
const query = new URLSearchParams();
|
|
38860
38969
|
if (options === null || options === void 0 ? void 0 : options.download) query.set("download", options.download === true ? "" : options.download);
|
|
38861
38970
|
if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
|
|
@@ -38995,8 +39104,7 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
38995
39104
|
if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
|
|
38996
39105
|
if ((options === null || options === void 0 ? void 0 : options.versionId) != null) query.set("versionId", String(options.versionId));
|
|
38997
39106
|
const queryString = query.toString();
|
|
38998
|
-
const
|
|
38999
|
-
const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString ? `?${queryString}` : ""}`, {
|
|
39107
|
+
const downloadFn = () => get(this.fetch, this._getRequestUrl(renderPath, path, { queryString }), {
|
|
39000
39108
|
headers: this.headers,
|
|
39001
39109
|
noResolveJson: true
|
|
39002
39110
|
}, parameters);
|
|
@@ -39029,17 +39137,24 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
39029
39137
|
*/
|
|
39030
39138
|
async info(path, options) {
|
|
39031
39139
|
var _this10 = this;
|
|
39032
|
-
const _path = _this10._getFinalPath(path);
|
|
39033
39140
|
const query = new URLSearchParams();
|
|
39034
39141
|
if ((options === null || options === void 0 ? void 0 : options.versionId) != null) query.set("versionId", String(options.versionId));
|
|
39035
39142
|
const queryString = query.toString();
|
|
39036
39143
|
return _this10.handleOperation(async () => {
|
|
39037
|
-
return recursiveToCamel(await get(_this10.fetch,
|
|
39144
|
+
return recursiveToCamel(await get(_this10.fetch, _this10._getRequestUrl("object/info", path, { queryString }), { headers: _this10.headers }));
|
|
39038
39145
|
});
|
|
39039
39146
|
}
|
|
39040
39147
|
/**
|
|
39041
39148
|
* Checks the existence of a file.
|
|
39042
39149
|
*
|
|
39150
|
+
* This reads the object's metadata, so the result is `false` only when Storage reports that the
|
|
39151
|
+
* key does not exist: an error with code `NoSuchKey`, or an HTTP 404 with no error code. In that
|
|
39152
|
+
* case `data` is `false` and `error` holds the original error.
|
|
39153
|
+
*
|
|
39154
|
+
* Every other failure throws instead of returning `false`, including an invalid or expired JWT
|
|
39155
|
+
* (`InvalidJWT`), a missing bucket (`NoSuchBucket`) and network errors. With `throwOnError()`,
|
|
39156
|
+
* a missing key throws as well.
|
|
39157
|
+
*
|
|
39043
39158
|
* @category Storage
|
|
39044
39159
|
* @subcategory File Buckets
|
|
39045
39160
|
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
@@ -39054,26 +39169,16 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
39054
39169
|
* ```
|
|
39055
39170
|
*/
|
|
39056
39171
|
async exists(path) {
|
|
39057
|
-
|
|
39058
|
-
|
|
39059
|
-
|
|
39060
|
-
|
|
39061
|
-
|
|
39062
|
-
|
|
39063
|
-
|
|
39064
|
-
|
|
39065
|
-
}
|
|
39066
|
-
|
|
39067
|
-
if (isStorageError(error)) {
|
|
39068
|
-
var _error$originalError;
|
|
39069
|
-
const status = error instanceof StorageApiError ? error.status : error instanceof StorageUnknownError ? (_error$originalError = error.originalError) === null || _error$originalError === void 0 ? void 0 : _error$originalError.status : void 0;
|
|
39070
|
-
if (status !== void 0 && [400, 404].includes(status)) return {
|
|
39071
|
-
data: false,
|
|
39072
|
-
error
|
|
39073
|
-
};
|
|
39074
|
-
}
|
|
39075
|
-
throw error;
|
|
39076
|
-
}
|
|
39172
|
+
const { error } = await this.info(path);
|
|
39173
|
+
if (!error) return {
|
|
39174
|
+
data: true,
|
|
39175
|
+
error: null
|
|
39176
|
+
};
|
|
39177
|
+
if (error instanceof StorageApiError && (error.code === "NoSuchKey" || error.status === 404 && error.code === void 0)) return {
|
|
39178
|
+
data: false,
|
|
39179
|
+
error
|
|
39180
|
+
};
|
|
39181
|
+
throw error;
|
|
39077
39182
|
}
|
|
39078
39183
|
/**
|
|
39079
39184
|
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
|
|
@@ -39239,11 +39344,13 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
39239
39344
|
async purgeCache(path, options, parameters) {
|
|
39240
39345
|
var _this13 = this;
|
|
39241
39346
|
return _this13.handleOperation(async () => {
|
|
39242
|
-
const _path = encodeStoragePath(_this13._getFinalPath(path));
|
|
39243
39347
|
const query = new URLSearchParams();
|
|
39244
39348
|
if (options === null || options === void 0 ? void 0 : options.transformations) query.set("transformations", "true");
|
|
39245
39349
|
const queryString = query.toString();
|
|
39246
|
-
return await remove(_this13.fetch,
|
|
39350
|
+
return await remove(_this13.fetch, _this13._getRequestUrl("cdn", path, {
|
|
39351
|
+
encodePath: true,
|
|
39352
|
+
queryString
|
|
39353
|
+
}), {}, { headers: _this13.headers }, parameters);
|
|
39247
39354
|
});
|
|
39248
39355
|
}
|
|
39249
39356
|
/**
|
|
@@ -39423,6 +39530,20 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
39423
39530
|
if (typeof Buffer !== "undefined") return Buffer.from(data).toString("base64");
|
|
39424
39531
|
return btoa(data);
|
|
39425
39532
|
}
|
|
39533
|
+
/** Builds a request URL and checks that it stays within the intended Storage route and bucket. */
|
|
39534
|
+
_getRequestUrl(route, path, { encodePath = false, queryString = "" } = {}) {
|
|
39535
|
+
const finalPath = this._getFinalPath(path);
|
|
39536
|
+
const bucket = encodePath ? encodeStoragePath(String(this.bucketId)) : this.bucketId;
|
|
39537
|
+
const url = `${this.url}/${route}/${encodePath ? encodeStoragePath(finalPath) : finalPath}${queryString ? `?${queryString}` : ""}`;
|
|
39538
|
+
const routeUrl = new URL(`${this.url}/${route}/`);
|
|
39539
|
+
const requestUrl = validateStorageUrl(url, routeUrl);
|
|
39540
|
+
const bucketUrl = new URL(`${this.url}/${route}/${bucket}/`);
|
|
39541
|
+
if (bucketUrl.pathname.startsWith(routeUrl.pathname)) {
|
|
39542
|
+
const bucketSegment = bucketUrl.pathname.slice(routeUrl.pathname.length).split("/")[0];
|
|
39543
|
+
if (bucketSegment) bucketUrl.pathname = `${routeUrl.pathname}${bucketSegment}/`;
|
|
39544
|
+
}
|
|
39545
|
+
return validateStorageUrl(requestUrl, bucketUrl);
|
|
39546
|
+
}
|
|
39426
39547
|
_getFinalPath(path) {
|
|
39427
39548
|
return `${this.bucketId}/${path.replace(/^\/+/, "")}`;
|
|
39428
39549
|
}
|
|
@@ -39439,7 +39560,7 @@ var StorageFileApi = class extends BaseApiClient {
|
|
|
39439
39560
|
return query;
|
|
39440
39561
|
}
|
|
39441
39562
|
};
|
|
39442
|
-
var version = "2.
|
|
39563
|
+
var version = "2.119.2";
|
|
39443
39564
|
var DEFAULT_HEADERS = { "X-Client-Info": `storage-js/${version}` };
|
|
39444
39565
|
var StorageBucketApi = class extends BaseApiClient {
|
|
39445
39566
|
constructor(url, headers = {}, fetch$1, opts) {
|
|
@@ -40996,28 +41117,120 @@ var StorageClient = class extends StorageBucketApi {
|
|
|
40996
41117
|
}
|
|
40997
41118
|
};
|
|
40998
41119
|
|
|
40999
|
-
// ../../node_modules/.pnpm/@supabase+supabase-js@2.
|
|
41120
|
+
// ../../node_modules/.pnpm/@supabase+supabase-js@2.119.2_@opentelemetry+api@1.10.0/node_modules/@supabase/supabase-js/dist/index.mjs
|
|
41000
41121
|
var import_auth_js = __toESM(require_main3(), 1);
|
|
41001
41122
|
__reExport(dist_exports, __toESM(require_main2(), 1));
|
|
41002
41123
|
__reExport(dist_exports, __toESM(require_main3(), 1));
|
|
41003
|
-
var version2 = "2.
|
|
41004
|
-
|
|
41005
|
-
|
|
41006
|
-
|
|
41007
|
-
|
|
41008
|
-
|
|
41009
|
-
|
|
41010
|
-
|
|
41011
|
-
|
|
41012
|
-
|
|
41013
|
-
|
|
41014
|
-
|
|
41124
|
+
var version2 = "2.119.2";
|
|
41125
|
+
function _typeof3(o) {
|
|
41126
|
+
"@babel/helpers - typeof";
|
|
41127
|
+
return _typeof3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
41128
|
+
return typeof o$1;
|
|
41129
|
+
} : function(o$1) {
|
|
41130
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
41131
|
+
}, _typeof3(o);
|
|
41132
|
+
}
|
|
41133
|
+
function toPrimitive3(t, r) {
|
|
41134
|
+
if ("object" != _typeof3(t) || !t) return t;
|
|
41135
|
+
var e = t[Symbol.toPrimitive];
|
|
41136
|
+
if (void 0 !== e) {
|
|
41137
|
+
var i = e.call(t, r || "default");
|
|
41138
|
+
if ("object" != _typeof3(i)) return i;
|
|
41139
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
41140
|
+
}
|
|
41141
|
+
return ("string" === r ? String : Number)(t);
|
|
41142
|
+
}
|
|
41143
|
+
function toPropertyKey3(t) {
|
|
41144
|
+
var i = toPrimitive3(t, "string");
|
|
41145
|
+
return "symbol" == _typeof3(i) ? i : i + "";
|
|
41015
41146
|
}
|
|
41016
|
-
|
|
41017
|
-
|
|
41018
|
-
|
|
41019
|
-
|
|
41020
|
-
|
|
41147
|
+
function _defineProperty3(e, r, t) {
|
|
41148
|
+
return (r = toPropertyKey3(r)) in e ? Object.defineProperty(e, r, {
|
|
41149
|
+
value: t,
|
|
41150
|
+
enumerable: true,
|
|
41151
|
+
configurable: true,
|
|
41152
|
+
writable: true
|
|
41153
|
+
}) : e[r] = t, e;
|
|
41154
|
+
}
|
|
41155
|
+
function ownKeys4(e, r) {
|
|
41156
|
+
var t = Object.keys(e);
|
|
41157
|
+
if (Object.getOwnPropertySymbols) {
|
|
41158
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
41159
|
+
r && (o = o.filter(function(r$1) {
|
|
41160
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
41161
|
+
})), t.push.apply(t, o);
|
|
41162
|
+
}
|
|
41163
|
+
return t;
|
|
41164
|
+
}
|
|
41165
|
+
function _objectSpread23(e) {
|
|
41166
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
41167
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
41168
|
+
r % 2 ? ownKeys4(Object(t), true).forEach(function(r$1) {
|
|
41169
|
+
_defineProperty3(e, r$1, t[r$1]);
|
|
41170
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys4(Object(t)).forEach(function(r$1) {
|
|
41171
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
41172
|
+
});
|
|
41173
|
+
}
|
|
41174
|
+
return e;
|
|
41175
|
+
}
|
|
41176
|
+
function asString(value) {
|
|
41177
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
41178
|
+
}
|
|
41179
|
+
function detectDenoPlatform(globals) {
|
|
41180
|
+
if (typeof globals.EdgeRuntime === "object" && globals.EdgeRuntime !== null) return {
|
|
41181
|
+
platform: "edge-runtime",
|
|
41182
|
+
platformVersion: asString(globals.SUPABASE_VERSION)
|
|
41183
|
+
};
|
|
41184
|
+
if (typeof globals.Netlify !== "undefined") return { platform: "netlify-edge" };
|
|
41185
|
+
return {};
|
|
41186
|
+
}
|
|
41187
|
+
function detectElectronFromUserAgent(userAgent) {
|
|
41188
|
+
var _userAgent$match;
|
|
41189
|
+
const electronVersion = userAgent === null || userAgent === void 0 || (_userAgent$match = userAgent.match(/\bElectron\/([\w.-]+)/)) === null || _userAgent$match === void 0 ? void 0 : _userAgent$match[1];
|
|
41190
|
+
return electronVersion ? {
|
|
41191
|
+
framework: "electron",
|
|
41192
|
+
frameworkVersion: electronVersion
|
|
41193
|
+
} : {};
|
|
41194
|
+
}
|
|
41195
|
+
function detectClientEnvironment(globals = globalThis) {
|
|
41196
|
+
var _globals$navigator, _globals$navigator2, _globals$process, _asString, _globals$process2;
|
|
41197
|
+
const userAgent = asString((_globals$navigator = globals.navigator) === null || _globals$navigator === void 0 ? void 0 : _globals$navigator.userAgent);
|
|
41198
|
+
if (userAgent === "Cloudflare-Workers") return { platform: "cloudflare-workers" };
|
|
41199
|
+
if (typeof globals.Deno !== "undefined") {
|
|
41200
|
+
var _globals$Deno$version;
|
|
41201
|
+
return _objectSpread23(_objectSpread23({}, detectDenoPlatform(globals)), {}, {
|
|
41202
|
+
runtime: "deno",
|
|
41203
|
+
runtimeVersion: asString((_globals$Deno$version = globals.Deno.version) === null || _globals$Deno$version === void 0 ? void 0 : _globals$Deno$version.deno)
|
|
41204
|
+
});
|
|
41205
|
+
}
|
|
41206
|
+
if (typeof globals.Bun !== "undefined") return {
|
|
41207
|
+
runtime: "bun",
|
|
41208
|
+
runtimeVersion: asString(globals.Bun.version)
|
|
41209
|
+
};
|
|
41210
|
+
if (typeof globals.EdgeRuntime === "string") return { platform: "vercel-edge-runtime" };
|
|
41211
|
+
if (((_globals$navigator2 = globals.navigator) === null || _globals$navigator2 === void 0 ? void 0 : _globals$navigator2.product) === "ReactNative") return { framework: "react-native" };
|
|
41212
|
+
if (typeof globals.document !== "undefined" || typeof globals.WorkerGlobalScope !== "undefined") return _objectSpread23({ platform: "browser" }, detectElectronFromUserAgent(userAgent));
|
|
41213
|
+
const processVersions = (_globals$process = globals.process) === null || _globals$process === void 0 ? void 0 : _globals$process["versions"];
|
|
41214
|
+
const electronVersion = asString(processVersions === null || processVersions === void 0 ? void 0 : processVersions["electron"]);
|
|
41215
|
+
return _objectSpread23({
|
|
41216
|
+
runtime: "node",
|
|
41217
|
+
runtimeVersion: (_asString = asString((_globals$process2 = globals.process) === null || _globals$process2 === void 0 ? void 0 : _globals$process2["version"])) === null || _asString === void 0 ? void 0 : _asString.replace(/^v/, "")
|
|
41218
|
+
}, electronVersion ? {
|
|
41219
|
+
framework: "electron",
|
|
41220
|
+
frameworkVersion: electronVersion
|
|
41221
|
+
} : {});
|
|
41222
|
+
}
|
|
41223
|
+
function formatClientEnvironment(environment) {
|
|
41224
|
+
return [
|
|
41225
|
+
["platform", environment.platform],
|
|
41226
|
+
["platform-version", environment.platformVersion],
|
|
41227
|
+
["runtime", environment.runtime],
|
|
41228
|
+
["runtime-version", environment.runtimeVersion],
|
|
41229
|
+
["framework", environment.framework],
|
|
41230
|
+
["framework-version", environment.frameworkVersion]
|
|
41231
|
+
].filter(([, value]) => value).map(([key, value]) => `${key}=${value}`);
|
|
41232
|
+
}
|
|
41233
|
+
var DEFAULT_HEADERS2 = { "X-Client-Info": [`supabase-js/${version2}`, ...formatClientEnvironment(detectClientEnvironment())].join("; ") };
|
|
41021
41234
|
var DEFAULT_GLOBAL_OPTIONS = { headers: DEFAULT_HEADERS2 };
|
|
41022
41235
|
var DEFAULT_DB_OPTIONS = { schema: "public" };
|
|
41023
41236
|
var DEFAULT_AUTH_OPTIONS = {
|
|
@@ -41070,12 +41283,12 @@ function shouldPropagateToTarget(targetUrl, targets) {
|
|
|
41070
41283
|
}
|
|
41071
41284
|
return false;
|
|
41072
41285
|
}
|
|
41073
|
-
function matchStringTarget(
|
|
41074
|
-
if (target ===
|
|
41286
|
+
function matchStringTarget(hostname4, target) {
|
|
41287
|
+
if (target === hostname4) return true;
|
|
41075
41288
|
if (target.startsWith("*.")) {
|
|
41076
41289
|
const domain = target.slice(2);
|
|
41077
|
-
if (
|
|
41078
|
-
if (
|
|
41290
|
+
if (hostname4.endsWith(domain)) {
|
|
41291
|
+
if (hostname4 === domain || hostname4.endsWith("." + domain)) return true;
|
|
41079
41292
|
}
|
|
41080
41293
|
}
|
|
41081
41294
|
return false;
|
|
@@ -41091,57 +41304,6 @@ function getDefaultPropagationTargets(supabaseUrl2) {
|
|
|
41091
41304
|
targets.push("localhost", "127.0.0.1", "[::1]");
|
|
41092
41305
|
return targets;
|
|
41093
41306
|
}
|
|
41094
|
-
function _typeof3(o) {
|
|
41095
|
-
"@babel/helpers - typeof";
|
|
41096
|
-
return _typeof3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
41097
|
-
return typeof o$1;
|
|
41098
|
-
} : function(o$1) {
|
|
41099
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
41100
|
-
}, _typeof3(o);
|
|
41101
|
-
}
|
|
41102
|
-
function toPrimitive3(t, r) {
|
|
41103
|
-
if ("object" != _typeof3(t) || !t) return t;
|
|
41104
|
-
var e = t[Symbol.toPrimitive];
|
|
41105
|
-
if (void 0 !== e) {
|
|
41106
|
-
var i = e.call(t, r || "default");
|
|
41107
|
-
if ("object" != _typeof3(i)) return i;
|
|
41108
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
41109
|
-
}
|
|
41110
|
-
return ("string" === r ? String : Number)(t);
|
|
41111
|
-
}
|
|
41112
|
-
function toPropertyKey3(t) {
|
|
41113
|
-
var i = toPrimitive3(t, "string");
|
|
41114
|
-
return "symbol" == _typeof3(i) ? i : i + "";
|
|
41115
|
-
}
|
|
41116
|
-
function _defineProperty3(e, r, t) {
|
|
41117
|
-
return (r = toPropertyKey3(r)) in e ? Object.defineProperty(e, r, {
|
|
41118
|
-
value: t,
|
|
41119
|
-
enumerable: true,
|
|
41120
|
-
configurable: true,
|
|
41121
|
-
writable: true
|
|
41122
|
-
}) : e[r] = t, e;
|
|
41123
|
-
}
|
|
41124
|
-
function ownKeys4(e, r) {
|
|
41125
|
-
var t = Object.keys(e);
|
|
41126
|
-
if (Object.getOwnPropertySymbols) {
|
|
41127
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
41128
|
-
r && (o = o.filter(function(r$1) {
|
|
41129
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
41130
|
-
})), t.push.apply(t, o);
|
|
41131
|
-
}
|
|
41132
|
-
return t;
|
|
41133
|
-
}
|
|
41134
|
-
function _objectSpread23(e) {
|
|
41135
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
41136
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
41137
|
-
r % 2 ? ownKeys4(Object(t), true).forEach(function(r$1) {
|
|
41138
|
-
_defineProperty3(e, r$1, t[r$1]);
|
|
41139
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys4(Object(t)).forEach(function(r$1) {
|
|
41140
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
41141
|
-
});
|
|
41142
|
-
}
|
|
41143
|
-
return e;
|
|
41144
|
-
}
|
|
41145
41307
|
var resolveFetch2 = (customFetch) => {
|
|
41146
41308
|
if (customFetch) return (...args) => customFetch(...args);
|
|
41147
41309
|
return (...args) => fetch(...args);
|
|
@@ -41524,7 +41686,8 @@ var SupabaseClient = class {
|
|
|
41524
41686
|
this.rest = new PostgrestClient(new URL("rest/v1", baseUrl).href, {
|
|
41525
41687
|
headers: this.headers,
|
|
41526
41688
|
schema: settings.db.schema,
|
|
41527
|
-
fetch:
|
|
41689
|
+
fetch: resolveFetch2(settings.global.fetch),
|
|
41690
|
+
wrapFetch: (fetch$1) => fetchWithAuth(supabaseKey, supabaseUrl2, this._getSessionToken.bind(this), fetch$1, settings.tracePropagation),
|
|
41528
41691
|
timeout: settings.db.timeout,
|
|
41529
41692
|
urlLengthLimit: settings.db.urlLengthLimit,
|
|
41530
41693
|
retry: settings.db.retry
|
|
@@ -41544,10 +41707,24 @@ var SupabaseClient = class {
|
|
|
41544
41707
|
/**
|
|
41545
41708
|
* Perform a query on a table or a view.
|
|
41546
41709
|
*
|
|
41710
|
+
* A per-request `fetch` is wrapped the same way as the client-level fetch: the
|
|
41711
|
+
* `apikey`, `Authorization` and trace headers are added before it is called.
|
|
41712
|
+
* The same applies to clients returned by `.schema()`.
|
|
41713
|
+
*
|
|
41547
41714
|
* @param relation - The table or view name to query
|
|
41715
|
+
* @param options - Per-request options that override client-level defaults
|
|
41716
|
+
*
|
|
41717
|
+
* @example Per-request fetch options
|
|
41718
|
+
* ```ts
|
|
41719
|
+
* const { data } = await supabase
|
|
41720
|
+
* .from('countries', {
|
|
41721
|
+
* fetch: (input, init) => fetch(input, { ...init, cache: 'force-cache' }),
|
|
41722
|
+
* })
|
|
41723
|
+
* .select('*')
|
|
41724
|
+
* ```
|
|
41548
41725
|
*/
|
|
41549
|
-
from(relation) {
|
|
41550
|
-
return this.rest.from(relation);
|
|
41726
|
+
from(relation, options) {
|
|
41727
|
+
return this.rest.from(relation, options);
|
|
41551
41728
|
}
|
|
41552
41729
|
/**
|
|
41553
41730
|
* Select a schema to query or perform an function (rpc) call.
|
|
@@ -41818,6 +41995,10 @@ function validateField(field, raw) {
|
|
|
41818
41995
|
errors.push({ field, message: `invalid step "${part.slice(slash + 1)}"` });
|
|
41819
41996
|
}
|
|
41820
41997
|
body = part.slice(0, slash);
|
|
41998
|
+
if (body !== "*" && !body.includes("-")) {
|
|
41999
|
+
errors.push({ field, message: `step needs * or a range before it, not "${body}"` });
|
|
42000
|
+
continue;
|
|
42001
|
+
}
|
|
41821
42002
|
}
|
|
41822
42003
|
if (body === "*" || body === "") continue;
|
|
41823
42004
|
if (body.includes("-")) {
|
|
@@ -42232,21 +42413,39 @@ function withLineChanges(io, tracker) {
|
|
|
42232
42413
|
}
|
|
42233
42414
|
|
|
42234
42415
|
// ../../packages/entitlements/src/plans.ts
|
|
42235
|
-
var FREE = ["byok_ai"];
|
|
42236
|
-
var PRO = [...FREE, "
|
|
42416
|
+
var FREE = ["byok_ai", "remote_ssh", "cross_device_sync", "api_write"];
|
|
42417
|
+
var PRO = [...FREE, "alerts", "run_monitoring"];
|
|
42237
42418
|
var POWER = [...PRO, "bulk_ops"];
|
|
42238
42419
|
var TEAM = [...POWER, "workspaces", "rbac", "audit_log"];
|
|
42239
42420
|
var PLANS = {
|
|
42240
|
-
free: { machineLimit:
|
|
42421
|
+
free: { machineLimit: 1, jobLimit: 15, envVarLimit: 5, historyDays: 7, capabilities: FREE },
|
|
42422
|
+
hobbyist: { machineLimit: 3, jobLimit: 20, envVarLimit: 15, historyDays: 90, capabilities: PRO },
|
|
42241
42423
|
pro: { machineLimit: 5, jobLimit: 30, envVarLimit: 25, historyDays: 90, capabilities: PRO },
|
|
42242
42424
|
power: { machineLimit: 25, jobLimit: 150, envVarLimit: 100, historyDays: 365, capabilities: POWER },
|
|
42243
42425
|
team: { machineLimit: "custom", jobLimit: "custom", envVarLimit: "custom", historyDays: 365, capabilities: TEAM }
|
|
42244
42426
|
};
|
|
42245
42427
|
|
|
42246
42428
|
// ../../packages/entitlements/src/can.ts
|
|
42429
|
+
function isPlan(v) {
|
|
42430
|
+
return typeof v === "string" && Object.hasOwn(PLANS, v);
|
|
42431
|
+
}
|
|
42432
|
+
var PLAN_NAMES = { free: "Free", hobbyist: "Hobbyist", pro: "Pro", power: "Power", team: "Team" };
|
|
42247
42433
|
function machineLimit(plan) {
|
|
42248
42434
|
return PLANS[plan].machineLimit;
|
|
42249
42435
|
}
|
|
42436
|
+
function nextPlanAllows(plan, limitOf, noun = "") {
|
|
42437
|
+
const plans = Object.keys(PLANS);
|
|
42438
|
+
const next = plans[plans.indexOf(plan) + 1];
|
|
42439
|
+
if (!next) return "";
|
|
42440
|
+
const cap = limitOf(next);
|
|
42441
|
+
return typeof cap === "number" ? `${next.charAt(0).toUpperCase()}${next.slice(1)} allows ${cap}${noun}.` : "";
|
|
42442
|
+
}
|
|
42443
|
+
function machineUpgradeHint(plan) {
|
|
42444
|
+
return nextPlanAllows(plan, machineLimit);
|
|
42445
|
+
}
|
|
42446
|
+
function envVarUpgradeHint(plan) {
|
|
42447
|
+
return nextPlanAllows(plan, envVarLimit, " variables");
|
|
42448
|
+
}
|
|
42250
42449
|
function jobLimit(plan) {
|
|
42251
42450
|
return PLANS[plan].jobLimit;
|
|
42252
42451
|
}
|
|
@@ -42265,7 +42464,7 @@ function envVarUsageLabel(plan, count2) {
|
|
|
42265
42464
|
function envVarLimitMessage(plan, count2) {
|
|
42266
42465
|
const limit = envVarLimit(plan);
|
|
42267
42466
|
if (limit === "custom" || withinEnvVarLimit(plan, count2)) return null;
|
|
42268
|
-
return `You've used all ${limit} variables on the ${plan
|
|
42467
|
+
return `You've used all ${limit} variables on the ${PLAN_NAMES[plan]} plan. Upgrade to add more.`;
|
|
42269
42468
|
}
|
|
42270
42469
|
|
|
42271
42470
|
// ../../packages/entitlements/src/trial.ts
|
|
@@ -42277,7 +42476,7 @@ function toDate(v) {
|
|
|
42277
42476
|
}
|
|
42278
42477
|
function effectivePlan(plan, trialEndsAt, now = /* @__PURE__ */ new Date()) {
|
|
42279
42478
|
const end = toDate(trialEndsAt);
|
|
42280
|
-
return plan === "free" && end !== null && end.getTime() > now.getTime() ? TRIAL_PLAN : plan;
|
|
42479
|
+
return (plan === "free" || plan === "hobbyist") && end !== null && end.getTime() > now.getTime() ? TRIAL_PLAN : plan;
|
|
42281
42480
|
}
|
|
42282
42481
|
|
|
42283
42482
|
// ../../packages/bridge/src/pairing.ts
|
|
@@ -42337,6 +42536,18 @@ function backoffDelay(attempt, baseMs = 500, capMs = 3e4) {
|
|
|
42337
42536
|
return Math.min(capMs, baseMs * 2 ** attempt);
|
|
42338
42537
|
}
|
|
42339
42538
|
|
|
42539
|
+
// ../../packages/bridge/src/quota-pause.ts
|
|
42540
|
+
var QUOTA_PAUSE_MIN_MS = 5 * 6e4;
|
|
42541
|
+
var QUOTA_PAUSE_MAX_MS = 60 * 6e4;
|
|
42542
|
+
var isQuotaRefusal = (status) => status === 402 || status === 429;
|
|
42543
|
+
function nextQuotaPause(prev, retryAfter, now = Date.now()) {
|
|
42544
|
+
const secs = retryAfter !== null && /^\d+$/.test(retryAfter.trim()) ? Number(retryAfter.trim()) : NaN;
|
|
42545
|
+
const want = Number.isFinite(secs) ? secs * 1e3 : (prev?.ms ?? 0) * 2;
|
|
42546
|
+
const ms = Math.min(QUOTA_PAUSE_MAX_MS, Math.max(QUOTA_PAUSE_MIN_MS, want));
|
|
42547
|
+
return { until: now + ms, ms };
|
|
42548
|
+
}
|
|
42549
|
+
var quotaPaused = (p, now = Date.now()) => !!p && now < p.until;
|
|
42550
|
+
|
|
42340
42551
|
// ../../packages/bridge/src/jwt.ts
|
|
42341
42552
|
function b64urlToBytes(s) {
|
|
42342
42553
|
const pad2 = s.length % 4 ? "=".repeat(4 - s.length % 4) : "";
|
|
@@ -42463,6 +42674,9 @@ function validateRawCrontab(contents) {
|
|
|
42463
42674
|
|
|
42464
42675
|
// ../../packages/bridge/src/write-intent.ts
|
|
42465
42676
|
async function handleWriteIntent(msg, d) {
|
|
42677
|
+
if (!msg || typeof msg.capability !== "string" || !Array.isArray(msg.jobs) || !msg.jobs.every((j) => j && typeof j === "object")) {
|
|
42678
|
+
return { applied: false, reason: "malformed write-intent" };
|
|
42679
|
+
}
|
|
42466
42680
|
if (!msg.jobs.every((j) => typeof j.id === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(j.id))) return { applied: false, reason: "invalid job id" };
|
|
42467
42681
|
const intentHash = await canonicalJobsHash(msg.jobs);
|
|
42468
42682
|
const v = await verifyCapability(msg.capability, {
|
|
@@ -42647,17 +42861,17 @@ async function open(payload, o) {
|
|
|
42647
42861
|
// ../../packages/bridge/src/secure-url.ts
|
|
42648
42862
|
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
42649
42863
|
function assertSecureUrl(url, opts = {}) {
|
|
42650
|
-
const
|
|
42651
|
-
if (!url) throw
|
|
42864
|
+
const fail2 = () => new Error(`Supabase URL must use https:// (got ${JSON.stringify(url ?? null)})`);
|
|
42865
|
+
if (!url) throw fail2();
|
|
42652
42866
|
let parsed;
|
|
42653
42867
|
try {
|
|
42654
42868
|
parsed = new URL(url);
|
|
42655
42869
|
} catch {
|
|
42656
|
-
throw
|
|
42870
|
+
throw fail2();
|
|
42657
42871
|
}
|
|
42658
42872
|
if (parsed.protocol === "https:") return url;
|
|
42659
42873
|
if (opts.allowLocalDev && parsed.protocol === "http:" && LOCAL_HOSTS.has(parsed.hostname)) return url;
|
|
42660
|
-
throw
|
|
42874
|
+
throw fail2();
|
|
42661
42875
|
}
|
|
42662
42876
|
|
|
42663
42877
|
// ../../packages/bridge/src/secure-channel.ts
|
|
@@ -42728,6 +42942,33 @@ function activeTrustedKeys(list = CAPABILITY_TRUST_LIST) {
|
|
|
42728
42942
|
return list.filter((e) => e.status === "active" && e.kid && e.jwk.kty === "EC" && e.jwk.crv === "P-256" && !("d" in e.jwk)).map((e) => ({ ...e.jwk, kid: e.kid }));
|
|
42729
42943
|
}
|
|
42730
42944
|
|
|
42945
|
+
// ../../packages/bridge/src/heartbeat.ts
|
|
42946
|
+
var MINT_BEFORE_EXPIRY_MS = 5 * 6e4;
|
|
42947
|
+
function sessionFresh(expiresAt, now = Date.now()) {
|
|
42948
|
+
const t = expiresAt ? Date.parse(expiresAt) : NaN;
|
|
42949
|
+
return Number.isFinite(t) && t - now > MINT_BEFORE_EXPIRY_MS;
|
|
42950
|
+
}
|
|
42951
|
+
async function heartbeatTick(deps) {
|
|
42952
|
+
const mintAndRenew = async (force, ok) => {
|
|
42953
|
+
try {
|
|
42954
|
+
const s = await deps.mint(force);
|
|
42955
|
+
if (!s) return "failed";
|
|
42956
|
+
deps.onRenewed(s.token);
|
|
42957
|
+
return ok;
|
|
42958
|
+
} catch {
|
|
42959
|
+
return "failed";
|
|
42960
|
+
}
|
|
42961
|
+
};
|
|
42962
|
+
if (!sessionFresh(deps.expiresAt(), deps.now)) return mintAndRenew(false, "renewed");
|
|
42963
|
+
let accepted;
|
|
42964
|
+
try {
|
|
42965
|
+
accepted = await deps.beat();
|
|
42966
|
+
} catch {
|
|
42967
|
+
return mintAndRenew(true, "minted-after-error");
|
|
42968
|
+
}
|
|
42969
|
+
return accepted ? "beat" : mintAndRenew(true, "minted-after-refusal");
|
|
42970
|
+
}
|
|
42971
|
+
|
|
42731
42972
|
// src/supabase-config.ts
|
|
42732
42973
|
var DEFAULT_SUPABASE_URL = "https://eiuegfdaddrisfboijyy.supabase.co";
|
|
42733
42974
|
var DEFAULT_SUPABASE_ANON_KEY = "sb_publishable_qGCC0eLvfmXwL86zA1SLHA_q8rFMCcG";
|
|
@@ -42744,9 +42985,10 @@ function vaultUrl() {
|
|
|
42744
42985
|
|
|
42745
42986
|
// src/config.ts
|
|
42746
42987
|
var import_promises = require("node:fs/promises");
|
|
42747
|
-
var
|
|
42748
|
-
var
|
|
42749
|
-
var
|
|
42988
|
+
var import_node_child_process2 = require("node:child_process");
|
|
42989
|
+
var import_node_crypto = require("node:crypto");
|
|
42990
|
+
var import_node_os2 = require("node:os");
|
|
42991
|
+
var import_node_path2 = require("node:path");
|
|
42750
42992
|
|
|
42751
42993
|
// src/debug.ts
|
|
42752
42994
|
var enabled = false;
|
|
@@ -42829,18 +43071,18 @@ function matchStarts(hay, needle) {
|
|
|
42829
43071
|
const m = needle.length;
|
|
42830
43072
|
const out = [];
|
|
42831
43073
|
if (!m || hay.length < m) return out;
|
|
42832
|
-
const
|
|
43074
|
+
const fail2 = new Int32Array(m);
|
|
42833
43075
|
for (let i = 1, k = 0; i < m; i++) {
|
|
42834
|
-
while (k && needle[i] !== needle[k]) k =
|
|
43076
|
+
while (k && needle[i] !== needle[k]) k = fail2[k - 1];
|
|
42835
43077
|
if (needle[i] === needle[k]) k++;
|
|
42836
|
-
|
|
43078
|
+
fail2[i] = k;
|
|
42837
43079
|
}
|
|
42838
43080
|
for (let i = 0, k = 0; i < hay.length; i++) {
|
|
42839
|
-
while (k && hay[i] !== needle[k]) k =
|
|
43081
|
+
while (k && hay[i] !== needle[k]) k = fail2[k - 1];
|
|
42840
43082
|
if (hay[i] === needle[k]) k++;
|
|
42841
43083
|
if (k === m) {
|
|
42842
43084
|
out.push(i - m + 1);
|
|
42843
|
-
k =
|
|
43085
|
+
k = fail2[k - 1];
|
|
42844
43086
|
}
|
|
42845
43087
|
}
|
|
42846
43088
|
return out;
|
|
@@ -42883,6 +43125,181 @@ function scrubValues(text, values) {
|
|
|
42883
43125
|
return out + text.slice(pos, s) + "[redacted]" + text.slice(e);
|
|
42884
43126
|
}
|
|
42885
43127
|
|
|
43128
|
+
// src/secret-store.ts
|
|
43129
|
+
var import_node_child_process = require("node:child_process");
|
|
43130
|
+
var import_node_os = require("node:os");
|
|
43131
|
+
var import_node_path = require("node:path");
|
|
43132
|
+
var SECRET_SERVICE = "app.norc.cli";
|
|
43133
|
+
var EXEC_TIMEOUT_MS = 1e4;
|
|
43134
|
+
var defaultSecretExec = (cmd, args, { input, timeout }) => new Promise((resolve) => {
|
|
43135
|
+
const child = (0, import_node_child_process.execFile)(cmd, args, { timeout, windowsHide: true }, (err, stdout, stderr) => {
|
|
43136
|
+
const e = err;
|
|
43137
|
+
resolve({ code: !e ? 0 : typeof e.code === "number" ? e.code : null, stdout, stderr, error: e && typeof e.code !== "number" ? e : void 0 });
|
|
43138
|
+
});
|
|
43139
|
+
child.stdin?.on("error", () => {
|
|
43140
|
+
});
|
|
43141
|
+
child.stdin?.end(input ?? "");
|
|
43142
|
+
});
|
|
43143
|
+
var SAFE = /^[A-Za-z0-9._-]+$/;
|
|
43144
|
+
var enc = (v) => Buffer.from(v, "utf8").toString("base64url");
|
|
43145
|
+
var dec = (v) => Buffer.from(v.trim(), "base64url").toString("utf8");
|
|
43146
|
+
async function run(exec, cmd, args, input) {
|
|
43147
|
+
const r = await exec(cmd, args, { input, timeout: EXEC_TIMEOUT_MS });
|
|
43148
|
+
if (r.error?.code === "ENOENT") throw new Error(`${cmd} is not installed (no usable OS keychain)`);
|
|
43149
|
+
return r;
|
|
43150
|
+
}
|
|
43151
|
+
function fail(cmd, r, hint = "") {
|
|
43152
|
+
const why = r.code === null ? `timed out or was killed${r.error ? ` (${r.error.message})` : ""}` : `exit ${r.code}${r.stderr.trim() ? `: ${r.stderr.trim()}` : ""}`;
|
|
43153
|
+
return new Error(`${cmd} failed: ${hint}${why}`);
|
|
43154
|
+
}
|
|
43155
|
+
var MAC_LOCKED = {
|
|
43156
|
+
36: "the keychain is locked and this session cannot unlock it (errSecInteractionNotAllowed). ",
|
|
43157
|
+
51: "keychain authorization failed (errSecAuthFailed). ",
|
|
43158
|
+
37: "no default keychain (errSecNoDefaultKeychain). ",
|
|
43159
|
+
50: "no such keychain (errSecNoSuchKeychain). "
|
|
43160
|
+
};
|
|
43161
|
+
var macFail = (r) => fail("security", r, r.code !== null && MAC_LOCKED[r.code] || "");
|
|
43162
|
+
function check(service, account) {
|
|
43163
|
+
if (!SAFE.test(service) || !SAFE.test(account)) throw new Error(`invalid keychain service/account: ${service}/${account}`);
|
|
43164
|
+
}
|
|
43165
|
+
function macLoginKeychain() {
|
|
43166
|
+
return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Keychains", "login.keychain-db");
|
|
43167
|
+
}
|
|
43168
|
+
function macSecretStore(service = SECRET_SERVICE, exec = defaultSecretExec, keychain = macLoginKeychain()) {
|
|
43169
|
+
const sec = "/usr/bin/security";
|
|
43170
|
+
const kc = keychain && !/\s/.test(keychain) ? [keychain] : [];
|
|
43171
|
+
const get2 = async (account) => {
|
|
43172
|
+
check(service, account);
|
|
43173
|
+
const r = await run(exec, sec, ["find-generic-password", "-s", service, "-a", account, "-w", ...kc]);
|
|
43174
|
+
if (r.code === 44) return null;
|
|
43175
|
+
if (r.code !== 0) throw macFail(r);
|
|
43176
|
+
return dec(r.stdout);
|
|
43177
|
+
};
|
|
43178
|
+
return {
|
|
43179
|
+
get: get2,
|
|
43180
|
+
async set(account, value) {
|
|
43181
|
+
check(service, account);
|
|
43182
|
+
const r = await run(exec, sec, ["-i"], `add-generic-password -U -s ${service} -a ${account} -w ${enc(value)}${kc.map((k) => ` ${k}`).join("")}
|
|
43183
|
+
`);
|
|
43184
|
+
if (r.code !== 0) throw macFail(r);
|
|
43185
|
+
if (await get2(account) !== value) throw new Error("security failed: the keychain item did not read back after writing it");
|
|
43186
|
+
},
|
|
43187
|
+
async delete(account) {
|
|
43188
|
+
check(service, account);
|
|
43189
|
+
const r = await run(exec, sec, ["delete-generic-password", "-s", service, "-a", account, ...kc]);
|
|
43190
|
+
if (r.code !== 0 && r.code !== 44) throw macFail(r);
|
|
43191
|
+
}
|
|
43192
|
+
};
|
|
43193
|
+
}
|
|
43194
|
+
function linuxSecretStore(service = SECRET_SERVICE, exec = defaultSecretExec) {
|
|
43195
|
+
return {
|
|
43196
|
+
async get(account) {
|
|
43197
|
+
check(service, account);
|
|
43198
|
+
const r = await run(exec, "secret-tool", ["lookup", "service", service, "account", account]);
|
|
43199
|
+
if (r.code === 1 && !r.stdout.trim() && !r.stderr.trim()) return null;
|
|
43200
|
+
if (r.code !== 0) throw fail("secret-tool", r);
|
|
43201
|
+
return dec(r.stdout);
|
|
43202
|
+
},
|
|
43203
|
+
async set(account, value) {
|
|
43204
|
+
check(service, account);
|
|
43205
|
+
const r = await run(exec, "secret-tool", ["store", `--label=norc cli ${account}`, "service", service, "account", account], enc(value));
|
|
43206
|
+
if (r.code !== 0) throw fail("secret-tool", r);
|
|
43207
|
+
},
|
|
43208
|
+
async delete(account) {
|
|
43209
|
+
check(service, account);
|
|
43210
|
+
const r = await run(exec, "secret-tool", ["clear", "service", service, "account", account]);
|
|
43211
|
+
if (r.code !== 0 && !(r.code === 1 && !r.stderr.trim())) throw fail("secret-tool", r);
|
|
43212
|
+
}
|
|
43213
|
+
};
|
|
43214
|
+
}
|
|
43215
|
+
var WIN_PRELUDE = `$ErrorActionPreference='Stop'
|
|
43216
|
+
Add-Type -TypeDefinition @'
|
|
43217
|
+
using System; using System.Runtime.InteropServices; using System.Text;
|
|
43218
|
+
public static class NorcCred {
|
|
43219
|
+
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
43220
|
+
struct CREDENTIAL { public int Flags; public int Type; public string TargetName; public string Comment; public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten; public int CredentialBlobSize; public IntPtr CredentialBlob; public int Persist; public int AttributeCount; public IntPtr Attributes; public string TargetAlias; public string UserName; }
|
|
43221
|
+
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)] static extern bool CredWriteW(ref CREDENTIAL c, int flags);
|
|
43222
|
+
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)] static extern bool CredReadW(string target, int type, int flags, out IntPtr c);
|
|
43223
|
+
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)] static extern bool CredDeleteW(string target, int type, int flags);
|
|
43224
|
+
[DllImport("advapi32.dll")] static extern void CredFree(IntPtr p);
|
|
43225
|
+
public static int Read(string target, out string value) {
|
|
43226
|
+
value = null; IntPtr p;
|
|
43227
|
+
if (!CredReadW(target, 1, 0, out p)) return Marshal.GetLastWin32Error();
|
|
43228
|
+
try { CREDENTIAL c = (CREDENTIAL)Marshal.PtrToStructure(p, typeof(CREDENTIAL)); byte[] b = new byte[c.CredentialBlobSize]; Marshal.Copy(c.CredentialBlob, b, 0, b.Length); value = Encoding.UTF8.GetString(b); return 0; }
|
|
43229
|
+
finally { CredFree(p); }
|
|
43230
|
+
}
|
|
43231
|
+
public static int Write(string target, string value) {
|
|
43232
|
+
byte[] v = Encoding.UTF8.GetBytes(value); IntPtr m = Marshal.AllocHGlobal(v.Length);
|
|
43233
|
+
try {
|
|
43234
|
+
Marshal.Copy(v, 0, m, v.Length);
|
|
43235
|
+
CREDENTIAL c = new CREDENTIAL(); c.Type = 1; c.TargetName = target; c.UserName = "norc"; c.CredentialBlobSize = v.Length; c.CredentialBlob = m; c.Persist = 2;
|
|
43236
|
+
return CredWriteW(ref c, 0) ? 0 : Marshal.GetLastWin32Error();
|
|
43237
|
+
} finally { Marshal.FreeHGlobal(m); }
|
|
43238
|
+
}
|
|
43239
|
+
public static int Delete(string target) { return CredDeleteW(target, 1, 0) ? 0 : Marshal.GetLastWin32Error(); }
|
|
43240
|
+
}
|
|
43241
|
+
'@
|
|
43242
|
+
`;
|
|
43243
|
+
function windowsCredScript(op, target) {
|
|
43244
|
+
const done = (call, name) => `$r=${call}
|
|
43245
|
+
if($r -eq 1168){exit 44}; if($r -ne 0){[Console]::Error.Write("${name} failed: $r"); exit 1}`;
|
|
43246
|
+
const body = {
|
|
43247
|
+
get: `$v=$null
|
|
43248
|
+
${done(`[NorcCred]::Read('${target}',[ref]$v)`, "CredReadW")}
|
|
43249
|
+
[Console]::Out.Write($v)`,
|
|
43250
|
+
set: done(`[NorcCred]::Write('${target}',[Console]::In.ReadToEnd().Trim())`, "CredWriteW"),
|
|
43251
|
+
delete: done(`[NorcCred]::Delete('${target}')`, "CredDeleteW")
|
|
43252
|
+
}[op];
|
|
43253
|
+
return WIN_PRELUDE + body;
|
|
43254
|
+
}
|
|
43255
|
+
function windowsSecretStore(service = SECRET_SERVICE, exec = defaultSecretExec) {
|
|
43256
|
+
const ps = (op, account, input) => {
|
|
43257
|
+
check(service, account);
|
|
43258
|
+
const script = Buffer.from(windowsCredScript(op, `${service}:${account}`), "utf16le").toString("base64");
|
|
43259
|
+
return run(exec, "powershell.exe", ["-NoProfile", "-NonInteractive", "-EncodedCommand", script], input);
|
|
43260
|
+
};
|
|
43261
|
+
return {
|
|
43262
|
+
async get(account) {
|
|
43263
|
+
const r = await ps("get", account);
|
|
43264
|
+
if (r.code === 44) return null;
|
|
43265
|
+
if (r.code !== 0) throw fail("powershell", r);
|
|
43266
|
+
return dec(r.stdout);
|
|
43267
|
+
},
|
|
43268
|
+
async set(account, value) {
|
|
43269
|
+
const r = await ps("set", account, enc(value));
|
|
43270
|
+
if (r.code !== 0) throw fail("powershell", r);
|
|
43271
|
+
},
|
|
43272
|
+
async delete(account) {
|
|
43273
|
+
const r = await ps("delete", account);
|
|
43274
|
+
if (r.code !== 0 && r.code !== 44) throw fail("powershell", r);
|
|
43275
|
+
}
|
|
43276
|
+
};
|
|
43277
|
+
}
|
|
43278
|
+
function platformSecretStore(platform2 = process.platform, service = SECRET_SERVICE, exec) {
|
|
43279
|
+
if (platform2 === "darwin") return macSecretStore(service, exec);
|
|
43280
|
+
if (platform2 === "win32") return windowsSecretStore(service, exec);
|
|
43281
|
+
return linuxSecretStore(service, exec);
|
|
43282
|
+
}
|
|
43283
|
+
var override;
|
|
43284
|
+
var overrideMode = "keychain";
|
|
43285
|
+
var warnedMode = false;
|
|
43286
|
+
function secretStoreMode(env, platform2 = process.platform) {
|
|
43287
|
+
if (env === "keychain" || env === "file") return env;
|
|
43288
|
+
if (env && !warnedMode) {
|
|
43289
|
+
warnedMode = true;
|
|
43290
|
+
console.error(`norc: ignoring NORC_SECRET_STORE=${JSON.stringify(env)} (use "keychain" or "file"); using the platform default.`);
|
|
43291
|
+
}
|
|
43292
|
+
return platform2 === "darwin" ? "keychain" : "file";
|
|
43293
|
+
}
|
|
43294
|
+
function secretStore() {
|
|
43295
|
+
const mode = override !== void 0 ? overrideMode : secretStoreMode(process.env.NORC_SECRET_STORE);
|
|
43296
|
+
return mode === "keychain" ? readSecretStore() : null;
|
|
43297
|
+
}
|
|
43298
|
+
function readSecretStore() {
|
|
43299
|
+
if (override !== void 0) return override;
|
|
43300
|
+
return process.env.NORC_SECRET_STORE_NO_OS === "1" ? null : platformSecretStore();
|
|
43301
|
+
}
|
|
43302
|
+
|
|
42886
43303
|
// src/config.ts
|
|
42887
43304
|
function replayFor(config, machineId) {
|
|
42888
43305
|
const b = config.bridge ??= {};
|
|
@@ -42903,7 +43320,7 @@ function windowsOwnerOnlyDirAclSteps(dir, user) {
|
|
|
42903
43320
|
function windowsOwnerOnlyFileAclSteps(file, user) {
|
|
42904
43321
|
return [[file, "/reset"], [file, "/inheritance:r", "/grant:r", `${user}:F`]];
|
|
42905
43322
|
}
|
|
42906
|
-
var defaultExec = (cmd, args, cb) => (0,
|
|
43323
|
+
var defaultExec = (cmd, args, cb) => (0, import_node_child_process2.execFile)(cmd, args, (err) => cb(err));
|
|
42907
43324
|
function icacls(args, exec) {
|
|
42908
43325
|
return new Promise((resolve, reject) => {
|
|
42909
43326
|
exec("icacls", args, (err) => err ? reject(new Error(`icacls failed, refusing to write credentials: ${err.message}`)) : resolve());
|
|
@@ -42912,16 +43329,16 @@ function icacls(args, exec) {
|
|
|
42912
43329
|
async function restrictWindowsAcl(dir, file, opts = {}) {
|
|
42913
43330
|
if ((opts.platform ?? process.platform) !== "win32") return;
|
|
42914
43331
|
const exec = opts.exec ?? defaultExec;
|
|
42915
|
-
const user = opts.user ?? (0,
|
|
43332
|
+
const user = opts.user ?? (0, import_node_os2.userInfo)().username;
|
|
42916
43333
|
for (const step of windowsOwnerOnlyDirAclSteps(dir, user)) await icacls(step, exec);
|
|
42917
43334
|
if (await (0, import_promises.access)(file).then(() => true, () => false)) {
|
|
42918
43335
|
for (const step of windowsOwnerOnlyFileAclSteps(file, user)) await icacls(step, exec);
|
|
42919
43336
|
}
|
|
42920
43337
|
}
|
|
42921
43338
|
function configPath() {
|
|
42922
|
-
return (0,
|
|
43339
|
+
return (0, import_node_path2.join)((0, import_node_os2.homedir)(), ".config", "norc", "config.json");
|
|
42923
43340
|
}
|
|
42924
|
-
async function
|
|
43341
|
+
async function readConfigFile(path = configPath()) {
|
|
42925
43342
|
try {
|
|
42926
43343
|
return JSON.parse(await (0, import_promises.readFile)(path, "utf8"));
|
|
42927
43344
|
} catch (e) {
|
|
@@ -42929,15 +43346,123 @@ async function loadConfigStrict(path = configPath()) {
|
|
|
42929
43346
|
throw e;
|
|
42930
43347
|
}
|
|
42931
43348
|
}
|
|
42932
|
-
async function loadConfig(path = configPath()) {
|
|
43349
|
+
async function loadConfig(path = configPath(), opts = {}) {
|
|
43350
|
+
let config;
|
|
42933
43351
|
try {
|
|
42934
|
-
|
|
42935
|
-
debugLog("config: loaded", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
42936
|
-
return config;
|
|
43352
|
+
config = await readConfigFile(path);
|
|
42937
43353
|
} catch (e) {
|
|
42938
43354
|
debugLog("config: no existing config at", path, "(", e instanceof Error ? e.message : String(e), ") \u2014 starting empty");
|
|
42939
43355
|
return {};
|
|
42940
43356
|
}
|
|
43357
|
+
await hydrateSecrets(config, path, opts.enc ?? true);
|
|
43358
|
+
debugLog("config: loaded", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
43359
|
+
return config;
|
|
43360
|
+
}
|
|
43361
|
+
var sha256 = (v) => (0, import_node_crypto.createHash)("sha256").update(v).digest("hex");
|
|
43362
|
+
var deviceAccount = (tokenSha256) => `device-token-${tokenSha256.slice(0, 16)}`;
|
|
43363
|
+
var encAccount = (pub) => `enc-key-${sha256(`${pub.x}.${pub.y}`).slice(0, 16)}`;
|
|
43364
|
+
var deviceHash = (d) => d && (d.tokenSha256 ?? (d.deviceToken ? sha256(d.deviceToken) : void 0));
|
|
43365
|
+
var accountsOf = (c) => [
|
|
43366
|
+
...c.device?.tokenSha256 && !c.device.deviceToken ? [deviceAccount(c.device.tokenSha256)] : [],
|
|
43367
|
+
...c.enc?.publicJwk && !c.enc.privateJwk ? [encAccount(c.enc.publicJwk)] : []
|
|
43368
|
+
];
|
|
43369
|
+
var secretCache = /* @__PURE__ */ new Map();
|
|
43370
|
+
var setFailed = false;
|
|
43371
|
+
var warned = false;
|
|
43372
|
+
var encNoted = false;
|
|
43373
|
+
function warnOnce(reason) {
|
|
43374
|
+
if (warned) return;
|
|
43375
|
+
warned = true;
|
|
43376
|
+
console.error(`norc: OS keychain unavailable (${reason.replace(/\s+/g, " ").trim()}); keeping the device token and relay key in the 0600 config file.`);
|
|
43377
|
+
}
|
|
43378
|
+
async function getSecret(store, account, what) {
|
|
43379
|
+
const cached3 = secretCache.get(account);
|
|
43380
|
+
if (cached3 !== void 0) return cached3;
|
|
43381
|
+
if (!store) return null;
|
|
43382
|
+
try {
|
|
43383
|
+
return await store.get(account);
|
|
43384
|
+
} catch (e) {
|
|
43385
|
+
throw new Error(`norc: can't read the ${what} from the OS keychain: ${e instanceof Error ? e.message : String(e)}. Unlock the keychain and try again (a Mac that runs norc with nobody logged in: see NORC_SECRET_STORE in the norc README).`);
|
|
43386
|
+
}
|
|
43387
|
+
}
|
|
43388
|
+
async function hydrateSecrets(config, path, enc2, retried = false) {
|
|
43389
|
+
const store = readSecretStore();
|
|
43390
|
+
const d = config.device;
|
|
43391
|
+
if (d && !d.deviceToken && d.tokenSha256) {
|
|
43392
|
+
const want = d.tokenSha256;
|
|
43393
|
+
const v = await getSecret(store, deviceAccount(want), "device token");
|
|
43394
|
+
if (v === null || sha256(v) !== want) {
|
|
43395
|
+
const now = retried ? void 0 : await readConfigFile(path).catch(() => void 0);
|
|
43396
|
+
if (now?.device?.tokenSha256 && now.device.tokenSha256 !== want) {
|
|
43397
|
+
Object.assign(config, now);
|
|
43398
|
+
return hydrateSecrets(config, path, enc2, true);
|
|
43399
|
+
}
|
|
43400
|
+
throw new Error(`norc: the device token is ${v === null ? "missing from" : "wrong in"} the OS keychain. Run \`norc pair\` (or \`norc login --key\`) to pair this machine again.`);
|
|
43401
|
+
}
|
|
43402
|
+
secretCache.set(deviceAccount(want), v);
|
|
43403
|
+
d.deviceToken = v;
|
|
43404
|
+
}
|
|
43405
|
+
const k = config.enc;
|
|
43406
|
+
if (enc2 && k?.publicJwk && !k.privateJwk) {
|
|
43407
|
+
const v = await getSecret(store, encAccount(k.publicJwk), "relay encryption key");
|
|
43408
|
+
let p = null;
|
|
43409
|
+
try {
|
|
43410
|
+
p = v === null ? null : JSON.parse(v);
|
|
43411
|
+
} catch {
|
|
43412
|
+
}
|
|
43413
|
+
if (p && typeof p.d === "string" && p.x === k.publicJwk.x && p.y === k.publicJwk.y) {
|
|
43414
|
+
secretCache.set(encAccount(k.publicJwk), v);
|
|
43415
|
+
k.privateJwk = p;
|
|
43416
|
+
} else {
|
|
43417
|
+
delete config.enc;
|
|
43418
|
+
if (!encNoted) {
|
|
43419
|
+
encNoted = true;
|
|
43420
|
+
console.error("norc: the relay encryption key is missing from the OS keychain; generating a new one.");
|
|
43421
|
+
}
|
|
43422
|
+
}
|
|
43423
|
+
}
|
|
43424
|
+
}
|
|
43425
|
+
async function stashSecrets(c, store) {
|
|
43426
|
+
const put2 = async (account, value) => {
|
|
43427
|
+
if (setFailed || secretCache.get(account) === value) return;
|
|
43428
|
+
try {
|
|
43429
|
+
await store.set(account, value);
|
|
43430
|
+
secretCache.set(account, value);
|
|
43431
|
+
} catch (e) {
|
|
43432
|
+
setFailed = true;
|
|
43433
|
+
warnOnce(e instanceof Error ? e.message : String(e));
|
|
43434
|
+
}
|
|
43435
|
+
};
|
|
43436
|
+
if (c.device?.deviceToken) await put2(deviceAccount(sha256(c.device.deviceToken)), c.device.deviceToken);
|
|
43437
|
+
if (c.enc?.privateJwk && c.enc.publicJwk) await put2(encAccount(c.enc.publicJwk), JSON.stringify(c.enc.privateJwk));
|
|
43438
|
+
}
|
|
43439
|
+
function markSecrets(config, keychain) {
|
|
43440
|
+
const d = config.device;
|
|
43441
|
+
const dev = (rest) => ({ machineId: d.machineId, ...rest, ...d.pairedAt ? { pairedAt: d.pairedAt } : {} });
|
|
43442
|
+
if (d?.deviceToken) {
|
|
43443
|
+
const h = sha256(d.deviceToken);
|
|
43444
|
+
config.device = keychain && secretCache.get(deviceAccount(h)) === d.deviceToken ? dev({ tokenSha256: h }) : dev({ deviceToken: d.deviceToken });
|
|
43445
|
+
} else if (!keychain && d?.tokenSha256) {
|
|
43446
|
+
const v = secretCache.get(deviceAccount(d.tokenSha256));
|
|
43447
|
+
if (v !== void 0) config.device = dev({ deviceToken: v });
|
|
43448
|
+
}
|
|
43449
|
+
const k = config.enc;
|
|
43450
|
+
if (!k?.publicJwk) return;
|
|
43451
|
+
if (k.privateJwk) {
|
|
43452
|
+
if (keychain && secretCache.get(encAccount(k.publicJwk)) === JSON.stringify(k.privateJwk)) config.enc = { publicJwk: k.publicJwk };
|
|
43453
|
+
} else if (!keychain) {
|
|
43454
|
+
const v = secretCache.get(encAccount(k.publicJwk));
|
|
43455
|
+
if (v !== void 0) config.enc = { publicJwk: k.publicJwk, privateJwk: JSON.parse(v) };
|
|
43456
|
+
}
|
|
43457
|
+
}
|
|
43458
|
+
async function migrateSecrets(path = configPath()) {
|
|
43459
|
+
const raw = await readConfigFile(path).catch(() => ({}));
|
|
43460
|
+
if (secretStore()) {
|
|
43461
|
+
if (raw.device?.deviceToken || raw.enc?.privateJwk) await saveConfig({}, path, { keys: [] });
|
|
43462
|
+
} else if (accountsOf(raw).length) {
|
|
43463
|
+
await loadConfig(path);
|
|
43464
|
+
await saveConfig({}, path, { keys: [] });
|
|
43465
|
+
}
|
|
42941
43466
|
}
|
|
42942
43467
|
async function refreshRemote(config, path = configPath()) {
|
|
42943
43468
|
try {
|
|
@@ -42947,12 +43472,9 @@ async function refreshRemote(config, path = configPath()) {
|
|
|
42947
43472
|
config.remote = void 0;
|
|
42948
43473
|
}
|
|
42949
43474
|
}
|
|
42950
|
-
|
|
42951
|
-
|
|
42952
|
-
|
|
42953
|
-
const lock = `${path}.lock`;
|
|
42954
|
-
await (0, import_promises.mkdir)((0, import_node_path.join)(path, ".."), { recursive: true, mode: 448 });
|
|
42955
|
-
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
43475
|
+
async function withFileLock(lock, o, fn) {
|
|
43476
|
+
await (0, import_promises.mkdir)((0, import_node_path2.dirname)(lock), { recursive: true, mode: 448 });
|
|
43477
|
+
const deadline = Date.now() + o.waitMs;
|
|
42956
43478
|
for (; ; ) {
|
|
42957
43479
|
try {
|
|
42958
43480
|
await (0, import_promises.mkdir)(lock);
|
|
@@ -42960,27 +43482,45 @@ async function withConfigLock(path, fn) {
|
|
|
42960
43482
|
} catch (e) {
|
|
42961
43483
|
if (e.code !== "EEXIST") throw e;
|
|
42962
43484
|
const age = await (0, import_promises.stat)(lock).then((st) => Date.now() - st.mtimeMs).catch(() => 0);
|
|
42963
|
-
if (age >
|
|
43485
|
+
if (age > o.staleMs || await lockHolderDead(lock)) {
|
|
42964
43486
|
await (0, import_promises.rm)(lock, { recursive: true, force: true });
|
|
42965
43487
|
continue;
|
|
42966
43488
|
}
|
|
42967
|
-
if (Date.now() > deadline) throw new Error(
|
|
43489
|
+
if (Date.now() > deadline) throw new Error(o.busy);
|
|
42968
43490
|
await new Promise((r) => setTimeout(r, 25));
|
|
42969
43491
|
}
|
|
42970
43492
|
}
|
|
43493
|
+
await (0, import_promises.writeFile)((0, import_node_path2.join)(lock, "owner"), `${process.pid}
|
|
43494
|
+
${(0, import_node_os2.hostname)()}`).catch(() => {
|
|
43495
|
+
});
|
|
42971
43496
|
try {
|
|
42972
43497
|
return await fn();
|
|
42973
43498
|
} finally {
|
|
42974
43499
|
await (0, import_promises.rm)(lock, { recursive: true, force: true });
|
|
42975
43500
|
}
|
|
42976
43501
|
}
|
|
43502
|
+
async function lockHolderDead(lock) {
|
|
43503
|
+
const [pid, host] = (await (0, import_promises.readFile)((0, import_node_path2.join)(lock, "owner"), "utf8").catch(() => "")).split("\n");
|
|
43504
|
+
if (host !== (0, import_node_os2.hostname)() || !Number(pid)) return false;
|
|
43505
|
+
try {
|
|
43506
|
+
process.kill(Number(pid), 0);
|
|
43507
|
+
return false;
|
|
43508
|
+
} catch (e) {
|
|
43509
|
+
return e.code === "ESRCH";
|
|
43510
|
+
}
|
|
43511
|
+
}
|
|
43512
|
+
var LOCK_STALE_MS = 3e4;
|
|
43513
|
+
var LOCK_WAIT_MS = 1e4;
|
|
43514
|
+
function withConfigLock(path, fn) {
|
|
43515
|
+
return withFileLock(`${path}.lock`, { staleMs: LOCK_STALE_MS, waitMs: LOCK_WAIT_MS, busy: "config is locked by another norc process; try again" }, fn);
|
|
43516
|
+
}
|
|
42977
43517
|
async function sweepConfigTemps(path = configPath(), minAgeMs = 6e4) {
|
|
42978
|
-
const base = (0,
|
|
43518
|
+
const base = (0, import_node_path2.basename)(path).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42979
43519
|
const re = new RegExp(`^${base}\\.\\d+\\.\\d+\\.tmp$`);
|
|
42980
|
-
const dir = (0,
|
|
43520
|
+
const dir = (0, import_node_path2.dirname)(path);
|
|
42981
43521
|
for (const n of (await (0, import_promises.readdir)(dir).catch(() => [])).filter((x) => re.test(x))) {
|
|
42982
43522
|
try {
|
|
42983
|
-
const f = (0,
|
|
43523
|
+
const f = (0, import_node_path2.join)(dir, n);
|
|
42984
43524
|
const st = await (0, import_promises.lstat)(f);
|
|
42985
43525
|
if (st.isDirectory() || minAgeMs > 0 && Date.now() - st.mtimeMs < minAgeMs) continue;
|
|
42986
43526
|
await (0, import_promises.rm)(f, { force: true });
|
|
@@ -42991,12 +43531,23 @@ async function sweepConfigTemps(path = configPath(), minAgeMs = 6e4) {
|
|
|
42991
43531
|
async function saveConfig(config, path, opts) {
|
|
42992
43532
|
path ??= configPath();
|
|
42993
43533
|
const file = path;
|
|
42994
|
-
|
|
42995
|
-
|
|
43534
|
+
const store = secretStore();
|
|
43535
|
+
if (store) {
|
|
43536
|
+
const pick = {};
|
|
43537
|
+
for (const k of opts.keys) Object.assign(pick, { [k]: config[k] });
|
|
43538
|
+
await stashSecrets(pick, store);
|
|
43539
|
+
await stashSecrets(await readConfigFile(file).catch(() => ({})), store);
|
|
43540
|
+
}
|
|
43541
|
+
let stale = [];
|
|
43542
|
+
const saved = await withConfigLock(file, async () => {
|
|
43543
|
+
const disk = await readConfigFile(file);
|
|
43544
|
+
if (opts.ifDevice !== void 0 && deviceHash(disk.device) !== opts.ifDevice) return false;
|
|
43545
|
+
const before = accountsOf(disk);
|
|
42996
43546
|
for (const k of opts.keys) delete disk[k];
|
|
42997
43547
|
for (const k of opts.keys) if (config[k] !== void 0) Object.assign(disk, { [k]: config[k] });
|
|
42998
43548
|
config = disk;
|
|
42999
|
-
|
|
43549
|
+
markSecrets(config, store !== null);
|
|
43550
|
+
const dir = (0, import_node_path2.join)(path, "..");
|
|
43000
43551
|
await (0, import_promises.mkdir)(dir, { recursive: true, mode: 448 });
|
|
43001
43552
|
await (0, import_promises.chmod)(dir, 448);
|
|
43002
43553
|
await restrictWindowsAcl(dir, path);
|
|
@@ -43016,16 +43567,27 @@ async function saveConfig(config, path, opts) {
|
|
|
43016
43567
|
}
|
|
43017
43568
|
await (0, import_promises.chmod)(path, 384);
|
|
43018
43569
|
await restrictWindowsAcl(dir, path);
|
|
43570
|
+
const after = new Set(accountsOf(config));
|
|
43571
|
+
stale = before.filter((a) => !after.has(a));
|
|
43019
43572
|
debugLog("config: saved", path, "\u2014 has session:", Boolean(config.session), "has device:", Boolean(config.device));
|
|
43573
|
+
return true;
|
|
43020
43574
|
});
|
|
43575
|
+
const del = stale.length ? readSecretStore() : null;
|
|
43576
|
+
for (const a of stale) {
|
|
43577
|
+
secretCache.delete(a);
|
|
43578
|
+
await del?.delete(a).catch((e) => console.error(
|
|
43579
|
+
`norc: could not remove the unused keychain item ${SECRET_SERVICE}/${a} (${e instanceof Error ? e.message : String(e)}). Delete it in your OS keychain manager.`
|
|
43580
|
+
));
|
|
43581
|
+
}
|
|
43582
|
+
return saved;
|
|
43021
43583
|
}
|
|
43022
43584
|
|
|
43023
43585
|
// src/crontab-io.ts
|
|
43024
|
-
var
|
|
43586
|
+
var import_node_child_process3 = require("node:child_process");
|
|
43025
43587
|
var systemCrontabIo = {
|
|
43026
43588
|
read() {
|
|
43027
43589
|
return new Promise((resolve, reject) => {
|
|
43028
|
-
(0,
|
|
43590
|
+
(0, import_node_child_process3.execFile)("crontab", ["-l"], (err, stdout, stderr) => {
|
|
43029
43591
|
if (err) {
|
|
43030
43592
|
if (/no crontab/i.test(stderr)) return resolve("");
|
|
43031
43593
|
return reject(new Error(stderr.trim() || err.message));
|
|
@@ -43036,7 +43598,7 @@ var systemCrontabIo = {
|
|
|
43036
43598
|
},
|
|
43037
43599
|
write(contents) {
|
|
43038
43600
|
return new Promise((resolve, reject) => {
|
|
43039
|
-
const child = (0,
|
|
43601
|
+
const child = (0, import_node_child_process3.execFile)("crontab", ["-"], { timeout: 15e3 }, (err, _stdout, stderr) => {
|
|
43040
43602
|
if (err) return reject(new Error(stderr.trim() || err.message));
|
|
43041
43603
|
resolve();
|
|
43042
43604
|
});
|
|
@@ -43047,9 +43609,10 @@ var systemCrontabIo = {
|
|
|
43047
43609
|
};
|
|
43048
43610
|
|
|
43049
43611
|
// src/commands/login.ts
|
|
43612
|
+
var ACCOUNT_PROBE = /signups not allowed|otp_disabled|over_email_send_rate_limit|for security purposes|email rate limit/i;
|
|
43050
43613
|
async function requestLogin(client, email) {
|
|
43051
43614
|
const start = await client.auth.signInWithOtp({ email, options: { shouldCreateUser: false } });
|
|
43052
|
-
if (start.error) return { ok: false, message: start.error.message };
|
|
43615
|
+
if (start.error && !ACCOUNT_PROBE.test(`${start.error.code ?? ""} ${start.error.message}`)) return { ok: false, message: start.error.message };
|
|
43053
43616
|
return { ok: true };
|
|
43054
43617
|
}
|
|
43055
43618
|
async function verifyLogin(client, email, code) {
|
|
@@ -43064,10 +43627,10 @@ async function verifyLogin(client, email, code) {
|
|
|
43064
43627
|
}
|
|
43065
43628
|
|
|
43066
43629
|
// src/commands/pair.ts
|
|
43067
|
-
var
|
|
43630
|
+
var import_node_os4 = require("node:os");
|
|
43068
43631
|
|
|
43069
43632
|
// src/host-info.ts
|
|
43070
|
-
var
|
|
43633
|
+
var import_node_os3 = require("node:os");
|
|
43071
43634
|
function normalizeArch(raw) {
|
|
43072
43635
|
switch (raw) {
|
|
43073
43636
|
case "arm64":
|
|
@@ -43098,12 +43661,12 @@ function firstLanIPv4(interfaces) {
|
|
|
43098
43661
|
return null;
|
|
43099
43662
|
}
|
|
43100
43663
|
function hostInfo() {
|
|
43101
|
-
const h = (0,
|
|
43664
|
+
const h = (0, import_node_os3.hostname)();
|
|
43102
43665
|
return {
|
|
43103
43666
|
hostname: h,
|
|
43104
43667
|
networkName: h,
|
|
43105
|
-
ipAddress: firstLanIPv4((0,
|
|
43106
|
-
cpuArch: normalizeArch((0,
|
|
43668
|
+
ipAddress: firstLanIPv4((0, import_node_os3.networkInterfaces)()),
|
|
43669
|
+
cpuArch: normalizeArch((0, import_node_os3.arch)())
|
|
43107
43670
|
};
|
|
43108
43671
|
}
|
|
43109
43672
|
|
|
@@ -43117,7 +43680,7 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
43117
43680
|
network_name: info.networkName,
|
|
43118
43681
|
ip_address: info.ipAddress,
|
|
43119
43682
|
cpu_arch: info.cpuArch,
|
|
43120
|
-
os: `${(0,
|
|
43683
|
+
os: `${(0, import_node_os4.platform)()} ${(0, import_node_os4.release)()}`
|
|
43121
43684
|
// shown to the approver in pair_preview (AZ-011)
|
|
43122
43685
|
});
|
|
43123
43686
|
if (error || !data?.[0]) {
|
|
@@ -43149,13 +43712,13 @@ async function runPairing(client, onProgress, opts = {}) {
|
|
|
43149
43712
|
}
|
|
43150
43713
|
|
|
43151
43714
|
// src/commands/pair-key.ts
|
|
43152
|
-
async function pairWithApiKey(fetchImpl, vaultUrl2, apiKey,
|
|
43715
|
+
async function pairWithApiKey(fetchImpl, vaultUrl2, apiKey, hostname4) {
|
|
43153
43716
|
const url = `${vaultUrl2}/api/v1/machines`;
|
|
43154
|
-
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, hostname:
|
|
43717
|
+
debugLog("POST", url, { authorization: `Bearer ${redactSecret(apiKey)}`, hostname: hostname4 });
|
|
43155
43718
|
const res = await fetchImpl(url, {
|
|
43156
43719
|
method: "POST",
|
|
43157
43720
|
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
43158
|
-
body: JSON.stringify({ hostname:
|
|
43721
|
+
body: JSON.stringify({ hostname: hostname4 })
|
|
43159
43722
|
});
|
|
43160
43723
|
const rawText = await res.text().catch(() => "");
|
|
43161
43724
|
let body;
|
|
@@ -43194,8 +43757,8 @@ function promptSecret(question, { stdin, stdout } = { stdin: process.stdin, stdo
|
|
|
43194
43757
|
let input = "";
|
|
43195
43758
|
let carry = "";
|
|
43196
43759
|
const onData = (chunk) => {
|
|
43197
|
-
const { ready, pending } = stripPasteMarkers(carry + chunk.toString());
|
|
43198
|
-
carry =
|
|
43760
|
+
const { ready, pending: pending2 } = stripPasteMarkers(carry + chunk.toString());
|
|
43761
|
+
carry = pending2;
|
|
43199
43762
|
for (const char of ready) {
|
|
43200
43763
|
if (char === "\n" || char === "\r") {
|
|
43201
43764
|
if (isTTY) stdout.write("\n");
|
|
@@ -43234,7 +43797,7 @@ function promptSecret(question, { stdin, stdout } = { stdin: process.stdin, stdo
|
|
|
43234
43797
|
}
|
|
43235
43798
|
|
|
43236
43799
|
// src/commands/jobs.ts
|
|
43237
|
-
var
|
|
43800
|
+
var import_node_crypto2 = require("node:crypto");
|
|
43238
43801
|
var CONTROL3 = /[\r\n\0]/;
|
|
43239
43802
|
function assertSafeField(field, val) {
|
|
43240
43803
|
if (CONTROL3.test(val)) throw new Error(`${field} contains a control char (\\n/\\r/NUL)`);
|
|
@@ -43253,7 +43816,7 @@ function newJob(schedule, command, name) {
|
|
|
43253
43816
|
if (errors.length > 0) throw new Error(`invalid schedule: ${errors.map((e) => e.message).join("; ")}`);
|
|
43254
43817
|
assertSafeField("command", command);
|
|
43255
43818
|
if (name) assertSafeField("name", name);
|
|
43256
|
-
return { kind: "job", id: (0,
|
|
43819
|
+
return { kind: "job", id: (0, import_node_crypto2.randomUUID)(), name, schedule, command, enabled: true };
|
|
43257
43820
|
}
|
|
43258
43821
|
var wrapped = (job, envNames = []) => ({ ...job, command: wrapCommand(job.id, job.command, "posix", envNames) });
|
|
43259
43822
|
async function appendJob(io, job, envNames = []) {
|
|
@@ -43400,8 +43963,10 @@ async function set(name, d) {
|
|
|
43400
43963
|
d.out(`${existing ? "updated" : "created"} ${name}`);
|
|
43401
43964
|
return 0;
|
|
43402
43965
|
}
|
|
43403
|
-
if (res.status === 403 && res.body.error === "plan_limit_reached")
|
|
43404
|
-
|
|
43966
|
+
if (res.status === 403 && res.body.error === "plan_limit_reached") {
|
|
43967
|
+
const plan = await d.plan?.().catch(() => null);
|
|
43968
|
+
d.err(`plan limit reached: archive or delete a variable, or upgrade your plan${plan && envVarUpgradeHint(plan) ? `. ${envVarUpgradeHint(plan)}` : ""}`);
|
|
43969
|
+
} else if (res.status === 409) d.err(`${name} already exists`);
|
|
43405
43970
|
else d.err(`could not save ${name} (${res.body.error ?? `HTTP ${res.status}`})`);
|
|
43406
43971
|
return 1;
|
|
43407
43972
|
}
|
|
@@ -43415,19 +43980,19 @@ async function act(d, fn, v, done) {
|
|
|
43415
43980
|
return 0;
|
|
43416
43981
|
}
|
|
43417
43982
|
async function destructive(sub, name, v, yes, d) {
|
|
43418
|
-
const
|
|
43983
|
+
const rm6 = sub === "rm";
|
|
43419
43984
|
const all = await d.impact(name);
|
|
43420
43985
|
const rows = all.filter((r) => !r.job_archived);
|
|
43421
43986
|
const na = all.filter((r) => r.job_archived);
|
|
43422
|
-
if (rows.length > 0) d.out(impactText(
|
|
43987
|
+
if (rows.length > 0) d.out(impactText(rm6 ? "Deleting" : "Archiving", name, rows));
|
|
43423
43988
|
if (na.length > 0) d.out(notAffectedText(na));
|
|
43424
43989
|
if (!yes) {
|
|
43425
43990
|
if (!d.isTTY) {
|
|
43426
|
-
if (
|
|
43991
|
+
if (rm6 || rows.length > 0) {
|
|
43427
43992
|
d.err("refusing without --yes on a non-interactive terminal");
|
|
43428
43993
|
return 1;
|
|
43429
43994
|
}
|
|
43430
|
-
} else if (
|
|
43995
|
+
} else if (rm6) {
|
|
43431
43996
|
const answer = await d.readLine(`type ${name} to delete it permanently: `);
|
|
43432
43997
|
if (answer === null || answer.trim() !== name) {
|
|
43433
43998
|
d.err("cancelled");
|
|
@@ -43441,7 +44006,7 @@ async function destructive(sub, name, v, yes, d) {
|
|
|
43441
44006
|
}
|
|
43442
44007
|
}
|
|
43443
44008
|
}
|
|
43444
|
-
if (!
|
|
44009
|
+
if (!rm6) return act(d, "archive_env_var", v, `archived ${name}`);
|
|
43445
44010
|
return remove2(name, v, d);
|
|
43446
44011
|
}
|
|
43447
44012
|
async function remove2(name, v, d) {
|
|
@@ -43821,17 +44386,22 @@ function withoutPkgEnv(command, platform2 = process.platform) {
|
|
|
43821
44386
|
}
|
|
43822
44387
|
|
|
43823
44388
|
// src/commands/run.ts
|
|
43824
|
-
var
|
|
44389
|
+
var import_node_child_process5 = require("node:child_process");
|
|
44390
|
+
|
|
44391
|
+
// src/device-session.ts
|
|
44392
|
+
var import_node_path5 = require("node:path");
|
|
44393
|
+
var import_node_crypto4 = require("node:crypto");
|
|
44394
|
+
var import_promises3 = require("node:fs/promises");
|
|
43825
44395
|
|
|
43826
44396
|
// src/host-details.ts
|
|
43827
|
-
var
|
|
44397
|
+
var import_node_child_process4 = require("node:child_process");
|
|
43828
44398
|
var import_node_fs = require("node:fs");
|
|
43829
|
-
var
|
|
43830
|
-
var
|
|
43831
|
-
var
|
|
44399
|
+
var import_node_crypto3 = require("node:crypto");
|
|
44400
|
+
var import_node_os5 = require("node:os");
|
|
44401
|
+
var import_node_path3 = require("node:path");
|
|
43832
44402
|
|
|
43833
44403
|
// src/version.ts
|
|
43834
|
-
var VERSION2 = "0.
|
|
44404
|
+
var VERSION2 = "0.4.0";
|
|
43835
44405
|
|
|
43836
44406
|
// src/host-details.ts
|
|
43837
44407
|
var ARCH = { x64: "x86_64", arm64: "arm64", ia32: "x86", arm: "arm" };
|
|
@@ -43850,7 +44420,7 @@ function windowsOsName(kernel, isClient) {
|
|
|
43850
44420
|
}
|
|
43851
44421
|
function windowsIsClient() {
|
|
43852
44422
|
try {
|
|
43853
|
-
const out = (0,
|
|
44423
|
+
const out = (0, import_node_child_process4.execFileSync)("powershell.exe", ["-NoProfile", "-Command", "(Get-CimInstance Win32_OperatingSystem).ProductType"], { encoding: "utf8", timeout: 4e3 }).trim();
|
|
43854
44424
|
return out === "1" ? true : out === "2" || out === "3" ? false : void 0;
|
|
43855
44425
|
} catch {
|
|
43856
44426
|
return void 0;
|
|
@@ -43858,7 +44428,7 @@ function windowsIsClient() {
|
|
|
43858
44428
|
}
|
|
43859
44429
|
function osName(platform2) {
|
|
43860
44430
|
if (platform2 === "linux") return osNameUncached(platform2);
|
|
43861
|
-
const file = (0,
|
|
44431
|
+
const file = (0, import_node_path3.join)((0, import_node_os5.homedir)(), ".config", "norc", `os-${platform2}-${(0, import_node_crypto3.createHash)("sha1").update(`${(0, import_node_os5.release)()}|${(0, import_node_os5.version)()}`).digest("hex").slice(0, 12)}.txt`);
|
|
43862
44432
|
try {
|
|
43863
44433
|
const hit = (0, import_node_fs.readFileSync)(file, "utf8").trim();
|
|
43864
44434
|
if (/^[\w .()+-]{1,64}$/.test(hit)) return hit;
|
|
@@ -43876,15 +44446,15 @@ function osName(platform2) {
|
|
|
43876
44446
|
function osNameUncached(platform2) {
|
|
43877
44447
|
try {
|
|
43878
44448
|
if (platform2 === "linux") return linuxOsName((0, import_node_fs.readFileSync)("/etc/os-release", "utf8"));
|
|
43879
|
-
if (platform2 === "darwin") return `macOS ${(0,
|
|
43880
|
-
if (platform2 === "win32") return windowsOsName((0,
|
|
44449
|
+
if (platform2 === "darwin") return `macOS ${(0, import_node_child_process4.execFileSync)("sw_vers", ["-productVersion"], { encoding: "utf8", timeout: 2e3 }).trim()}`;
|
|
44450
|
+
if (platform2 === "win32") return windowsOsName((0, import_node_os5.release)(), windowsIsClient());
|
|
43881
44451
|
} catch {
|
|
43882
44452
|
}
|
|
43883
44453
|
return void 0;
|
|
43884
44454
|
}
|
|
43885
44455
|
function bootedAt() {
|
|
43886
44456
|
try {
|
|
43887
|
-
return new Date(Math.round((Date.now() - (0,
|
|
44457
|
+
return new Date(Math.round((Date.now() - (0, import_node_os5.uptime)() * 1e3) / 6e4) * 6e4).toISOString();
|
|
43888
44458
|
} catch {
|
|
43889
44459
|
return void 0;
|
|
43890
44460
|
}
|
|
@@ -43897,16 +44467,16 @@ function hostDetails() {
|
|
|
43897
44467
|
|
|
43898
44468
|
// src/env-cache.ts
|
|
43899
44469
|
var import_promises2 = require("node:fs/promises");
|
|
43900
|
-
var
|
|
44470
|
+
var import_node_path4 = require("node:path");
|
|
43901
44471
|
function envCachePath() {
|
|
43902
|
-
return (0,
|
|
44472
|
+
return (0, import_node_path4.join)((0, import_node_path4.dirname)(configPath()), "env");
|
|
43903
44473
|
}
|
|
43904
44474
|
async function tempLeftovers(path) {
|
|
43905
|
-
const re = new RegExp(`^${(0,
|
|
43906
|
-
return (await (0, import_promises2.readdir)((0,
|
|
44475
|
+
const re = new RegExp(`^${(0, import_node_path4.basename)(path).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.\\d+\\.\\d+\\.tmp$`);
|
|
44476
|
+
return (await (0, import_promises2.readdir)((0, import_node_path4.dirname)(path)).catch(() => [])).filter((n) => re.test(n)).map((n) => (0, import_node_path4.join)((0, import_node_path4.dirname)(path), n));
|
|
43907
44477
|
}
|
|
43908
44478
|
async function writeEnvCache(body, path = envCachePath()) {
|
|
43909
|
-
const dir = (0,
|
|
44479
|
+
const dir = (0, import_node_path4.dirname)(path);
|
|
43910
44480
|
await (0, import_promises2.mkdir)(dir, { recursive: true, mode: 448 });
|
|
43911
44481
|
await (0, import_promises2.chmod)(dir, 448);
|
|
43912
44482
|
await restrictWindowsAcl(dir, path);
|
|
@@ -43983,55 +44553,141 @@ function resolveJobEnv(body, jobId, required) {
|
|
|
43983
44553
|
// src/device-session.ts
|
|
43984
44554
|
var revoked = null;
|
|
43985
44555
|
var revokedMint = () => revoked;
|
|
43986
|
-
|
|
43987
|
-
|
|
43988
|
-
|
|
43989
|
-
|
|
44556
|
+
var REUSED_MESSAGE = "norc revoked this machine because its credentials were used from somewhere else. Pair it again: `norc pair` (or `norc login --key`).";
|
|
44557
|
+
var reusedShown = false;
|
|
44558
|
+
var MINT_FETCH_TIMEOUT_MS = 15e3;
|
|
44559
|
+
var MINT_LOCK_STALE_MS = 12e4;
|
|
44560
|
+
var MINT_LOCK_WAIT_MS = 3e4;
|
|
44561
|
+
var mintLockPath = (cfgPath) => (0, import_node_path5.join)((0, import_node_path5.dirname)(cfgPath), "mint.lock");
|
|
44562
|
+
var quotaPausePath = (cfgPath) => (0, import_node_path5.join)((0, import_node_path5.dirname)(cfgPath), "mint-quota-pause.json");
|
|
44563
|
+
var readQuotaPause = async (p) => {
|
|
43990
44564
|
try {
|
|
43991
|
-
const
|
|
43992
|
-
|
|
43993
|
-
|
|
43994
|
-
|
|
43995
|
-
|
|
43996
|
-
|
|
43997
|
-
|
|
43998
|
-
|
|
43999
|
-
|
|
44000
|
-
|
|
44001
|
-
|
|
44002
|
-
|
|
44003
|
-
|
|
44004
|
-
}),
|
|
44005
|
-
signal
|
|
44006
|
-
});
|
|
44007
|
-
if (res.status === 401 && (await res.json?.().catch(() => null))?.error === "invalid device token") {
|
|
44008
|
-
const before = await readEnvCache(cachePath);
|
|
44009
|
-
revoked = { body: before ?? revoked?.body ?? null };
|
|
44010
|
-
await clearEnvCache(cachePath);
|
|
44011
|
-
return null;
|
|
44012
|
-
}
|
|
44013
|
-
if (!res.ok) return null;
|
|
44014
|
-
const session = await res.json();
|
|
44015
|
-
revoked = null;
|
|
44016
|
-
return session;
|
|
44565
|
+
const v = JSON.parse(await (0, import_promises3.readFile)(p, "utf8"));
|
|
44566
|
+
return typeof v?.until === "number" && typeof v?.ms === "number" ? v : null;
|
|
44567
|
+
} catch {
|
|
44568
|
+
return null;
|
|
44569
|
+
}
|
|
44570
|
+
};
|
|
44571
|
+
async function deviceSession(supabaseUrl2, anonKey, signal, encPublicJwk, cachePath = envCachePath(), cfgPath = configPath(), lockWaitMs = MINT_LOCK_WAIT_MS) {
|
|
44572
|
+
try {
|
|
44573
|
+
return await withFileLock(mintLockPath(cfgPath), {
|
|
44574
|
+
staleMs: MINT_LOCK_STALE_MS,
|
|
44575
|
+
waitMs: lockWaitMs,
|
|
44576
|
+
busy: "another norc process is minting a device session"
|
|
44577
|
+
}, () => mint(supabaseUrl2, anonKey, signal, encPublicJwk, cachePath, cfgPath));
|
|
44017
44578
|
} catch (e) {
|
|
44018
44579
|
console.error("[norc bridge] device-session fetch failed:", e);
|
|
44019
44580
|
return null;
|
|
44020
44581
|
}
|
|
44021
44582
|
}
|
|
44583
|
+
var cached2 = null;
|
|
44584
|
+
var pending = null;
|
|
44585
|
+
var cachedFor = null;
|
|
44586
|
+
var pendingFor = null;
|
|
44587
|
+
var latest = null;
|
|
44588
|
+
var mustRegister = null;
|
|
44589
|
+
async function cachedDeviceSession(supabaseUrl2, anonKey, encPublicJwk, opts = {}) {
|
|
44590
|
+
const key = JSON.stringify(encPublicJwk ?? null);
|
|
44591
|
+
latest = { key, jwk: encPublicJwk };
|
|
44592
|
+
if (mustRegister === key) opts = { ...opts, force: true };
|
|
44593
|
+
if (cached2 && cachedFor === key && !opts.force && sessionFresh(cached2.expires_at)) return cached2;
|
|
44594
|
+
if (!opts.force && pending && pendingFor === key) return pending;
|
|
44595
|
+
const run2 = (async () => {
|
|
44596
|
+
const s = await deviceSession(supabaseUrl2, anonKey, void 0, encPublicJwk);
|
|
44597
|
+
if (latest && latest.key !== key) {
|
|
44598
|
+
mustRegister = latest.key;
|
|
44599
|
+
void cachedDeviceSession(supabaseUrl2, anonKey, latest.jwk, { force: true });
|
|
44600
|
+
return s;
|
|
44601
|
+
}
|
|
44602
|
+
if (s) {
|
|
44603
|
+
cached2 = s;
|
|
44604
|
+
cachedFor = key;
|
|
44605
|
+
if (mustRegister === key) mustRegister = null;
|
|
44606
|
+
} else if (revoked) cached2 = null;
|
|
44607
|
+
return s;
|
|
44608
|
+
})();
|
|
44609
|
+
if (opts.force) return run2;
|
|
44610
|
+
pending = run2;
|
|
44611
|
+
pendingFor = key;
|
|
44612
|
+
const clear = () => {
|
|
44613
|
+
if (pending === run2) {
|
|
44614
|
+
pending = null;
|
|
44615
|
+
pendingFor = null;
|
|
44616
|
+
}
|
|
44617
|
+
};
|
|
44618
|
+
run2.then(clear, clear);
|
|
44619
|
+
return run2;
|
|
44620
|
+
}
|
|
44621
|
+
async function mint(supabaseUrl2, anonKey, signal, encPublicJwk, cachePath, cfgPath) {
|
|
44622
|
+
const config = await loadConfig(cfgPath, { enc: false });
|
|
44623
|
+
const device = config.device;
|
|
44624
|
+
const token = device?.deviceToken;
|
|
44625
|
+
if (!device || !token) return null;
|
|
44626
|
+
const pausePath = quotaPausePath(cfgPath);
|
|
44627
|
+
const pause = await readQuotaPause(pausePath);
|
|
44628
|
+
if (quotaPaused(pause)) return null;
|
|
44629
|
+
const res = await fetch(`${checkedSupabaseUrl(supabaseUrl2)}/functions/v1/device-session`, {
|
|
44630
|
+
method: "POST",
|
|
44631
|
+
headers: { "Content-Type": "application/json", apikey: anonKey },
|
|
44632
|
+
// job_timezone_handling (roadmap #7): best-effort, piggybacked on this
|
|
44633
|
+
// already-regular mint — see device-session/index.ts's header comment.
|
|
44634
|
+
// Node's global Intl covers this, same as the browser-embedded runtime
|
|
44635
|
+
// desktop's copy of this call runs in — no import needed.
|
|
44636
|
+
// Machine details (0062): OS, arch and agent version, same piggyback.
|
|
44637
|
+
body: JSON.stringify({
|
|
44638
|
+
token,
|
|
44639
|
+
rotation: 1,
|
|
44640
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
44641
|
+
...hostDetails(),
|
|
44642
|
+
...encPublicJwk ? { enc_public_jwk: encPublicJwk } : {}
|
|
44643
|
+
}),
|
|
44644
|
+
// Bounded even without a caller signal: the mint lock is held for the whole request.
|
|
44645
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(MINT_FETCH_TIMEOUT_MS)]) : AbortSignal.timeout(MINT_FETCH_TIMEOUT_MS)
|
|
44646
|
+
});
|
|
44647
|
+
const refusal = res.status === 401 ? (await res.json?.().catch(() => null))?.error : void 0;
|
|
44648
|
+
if (refusal === "invalid device token" || refusal === "device token reused") {
|
|
44649
|
+
if (refusal === "device token reused" && !reusedShown) {
|
|
44650
|
+
reusedShown = true;
|
|
44651
|
+
console.error(REUSED_MESSAGE);
|
|
44652
|
+
}
|
|
44653
|
+
const before = await readEnvCache(cachePath);
|
|
44654
|
+
revoked = { body: before ?? revoked?.body ?? null };
|
|
44655
|
+
await clearEnvCache(cachePath);
|
|
44656
|
+
return null;
|
|
44657
|
+
}
|
|
44658
|
+
if (isQuotaRefusal(res.status)) {
|
|
44659
|
+
const next2 = nextQuotaPause(pause, res.headers?.get?.("retry-after") ?? null);
|
|
44660
|
+
await (0, import_promises3.writeFile)(pausePath, JSON.stringify(next2), { mode: 384 }).catch(() => {
|
|
44661
|
+
});
|
|
44662
|
+
console.error(`[norc] device-session refused (HTTP ${res.status}); pausing mints for ${Math.round(next2.ms / 6e4)} min`);
|
|
44663
|
+
return null;
|
|
44664
|
+
}
|
|
44665
|
+
if (!res.ok) return null;
|
|
44666
|
+
if (pause) await (0, import_promises3.rm)(pausePath, { force: true }).catch(() => {
|
|
44667
|
+
});
|
|
44668
|
+
const { next_device_token: next, ...session } = await res.json();
|
|
44669
|
+
if (typeof next === "string" && next) {
|
|
44670
|
+
await saveConfig({ device: { machineId: device.machineId, deviceToken: next, ...device.pairedAt ? { pairedAt: device.pairedAt } : {} } }, cfgPath, {
|
|
44671
|
+
keys: ["device"],
|
|
44672
|
+
ifDevice: (0, import_node_crypto4.createHash)("sha256").update(token).digest("hex")
|
|
44673
|
+
}).catch((e) => console.error("[norc] could not save the rotated device token:", e instanceof Error ? e.message : e));
|
|
44674
|
+
}
|
|
44675
|
+
revoked = null;
|
|
44676
|
+
return session;
|
|
44677
|
+
}
|
|
44022
44678
|
|
|
44023
44679
|
// src/run-queue.ts
|
|
44024
|
-
var
|
|
44025
|
-
var
|
|
44026
|
-
var
|
|
44680
|
+
var import_promises4 = require("node:fs/promises");
|
|
44681
|
+
var import_node_os6 = require("node:os");
|
|
44682
|
+
var import_node_path6 = require("node:path");
|
|
44027
44683
|
var MAX_QUEUE_LENGTH = 500;
|
|
44028
44684
|
function runQueuePath() {
|
|
44029
|
-
return (0,
|
|
44685
|
+
return (0, import_node_path6.join)((0, import_node_os6.homedir)(), ".config", "norc", "run-queue.jsonl");
|
|
44030
44686
|
}
|
|
44031
44687
|
async function readQueue(path = runQueuePath()) {
|
|
44032
44688
|
let text;
|
|
44033
44689
|
try {
|
|
44034
|
-
text = await (0,
|
|
44690
|
+
text = await (0, import_promises4.readFile)(path, "utf8");
|
|
44035
44691
|
} catch {
|
|
44036
44692
|
return [];
|
|
44037
44693
|
}
|
|
@@ -44039,26 +44695,26 @@ async function readQueue(path = runQueuePath()) {
|
|
|
44039
44695
|
}
|
|
44040
44696
|
async function writeQueue(entries, path) {
|
|
44041
44697
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
44042
|
-
await (0,
|
|
44043
|
-
await (0,
|
|
44698
|
+
await (0, import_promises4.writeFile)(tmp, entries.map((e) => JSON.stringify(e)).join("\n") + (entries.length ? "\n" : ""), "utf8");
|
|
44699
|
+
await (0, import_promises4.rename)(tmp, path);
|
|
44044
44700
|
}
|
|
44045
44701
|
var LOCK_STALE_MS2 = 3e4;
|
|
44046
44702
|
var LOCK_RETRY_MS = 25;
|
|
44047
44703
|
var LOCK_ATTEMPTS = 40;
|
|
44048
44704
|
async function withLock(path, fn) {
|
|
44049
44705
|
const lockPath = `${path}.lock`;
|
|
44050
|
-
await (0,
|
|
44706
|
+
await (0, import_promises4.mkdir)((0, import_node_path6.dirname)(path), { recursive: true });
|
|
44051
44707
|
let held = false;
|
|
44052
44708
|
for (let i = 0; i < LOCK_ATTEMPTS; i++) {
|
|
44053
44709
|
try {
|
|
44054
|
-
const fh = await (0,
|
|
44710
|
+
const fh = await (0, import_promises4.open)(lockPath, "wx");
|
|
44055
44711
|
await fh.close();
|
|
44056
44712
|
held = true;
|
|
44057
44713
|
break;
|
|
44058
44714
|
} catch {
|
|
44059
44715
|
try {
|
|
44060
|
-
const { mtimeMs } = await (0,
|
|
44061
|
-
if (Date.now() - mtimeMs > LOCK_STALE_MS2) await (0,
|
|
44716
|
+
const { mtimeMs } = await (0, import_promises4.stat)(lockPath);
|
|
44717
|
+
if (Date.now() - mtimeMs > LOCK_STALE_MS2) await (0, import_promises4.rm)(lockPath, { force: true });
|
|
44062
44718
|
} catch {
|
|
44063
44719
|
}
|
|
44064
44720
|
await new Promise((r) => setTimeout(r, LOCK_RETRY_MS));
|
|
@@ -44068,14 +44724,14 @@ async function withLock(path, fn) {
|
|
|
44068
44724
|
try {
|
|
44069
44725
|
return await fn();
|
|
44070
44726
|
} finally {
|
|
44071
|
-
await (0,
|
|
44727
|
+
await (0, import_promises4.rm)(lockPath, { force: true }).catch(() => {
|
|
44072
44728
|
});
|
|
44073
44729
|
}
|
|
44074
44730
|
}
|
|
44075
|
-
async function enqueueRun(
|
|
44731
|
+
async function enqueueRun(run2, path = runQueuePath()) {
|
|
44076
44732
|
await withLock(path, async () => {
|
|
44077
44733
|
const existing = await readQueue(path);
|
|
44078
|
-
const next = [...existing,
|
|
44734
|
+
const next = [...existing, run2].slice(-MAX_QUEUE_LENGTH);
|
|
44079
44735
|
await writeQueue(next, path);
|
|
44080
44736
|
});
|
|
44081
44737
|
}
|
|
@@ -44124,6 +44780,27 @@ async function pullEnv(fetchFn, session, timeoutMs, path, clear) {
|
|
|
44124
44780
|
async function pullEnvNames(fetchFn, session, timeoutMs, path = envCachePath()) {
|
|
44125
44781
|
return (await pullEnv(fetchFn, session, timeoutMs, path, clearEnvCache)).body?.jobs ?? null;
|
|
44126
44782
|
}
|
|
44783
|
+
async function pollEnvState(sb, timeoutMs = 1e4) {
|
|
44784
|
+
let timer;
|
|
44785
|
+
try {
|
|
44786
|
+
const timeout = new Promise((_, reject) => {
|
|
44787
|
+
timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
|
|
44788
|
+
});
|
|
44789
|
+
const { data, error } = await Promise.race([sb.rpc("env_state_for_current_machine"), timeout]);
|
|
44790
|
+
if (error) return null;
|
|
44791
|
+
if (data === null) return "not-live";
|
|
44792
|
+
const d = data;
|
|
44793
|
+
if (typeof d !== "object" || typeof d.fingerprint !== "string") return null;
|
|
44794
|
+
const names = d.names;
|
|
44795
|
+
if (typeof names !== "object" || names === null || Array.isArray(names)) return null;
|
|
44796
|
+
for (const v of Object.values(names)) if (!Array.isArray(v) || !v.every((n) => typeof n === "string")) return null;
|
|
44797
|
+
return { names, fingerprint: d.fingerprint };
|
|
44798
|
+
} catch {
|
|
44799
|
+
return null;
|
|
44800
|
+
} finally {
|
|
44801
|
+
clearTimeout(timer);
|
|
44802
|
+
}
|
|
44803
|
+
}
|
|
44127
44804
|
var REFRESH_BUDGET_MS = 3e3;
|
|
44128
44805
|
function createJobEnvLoader(getSession, path = envCachePath(), fetchFn = fetch, clear = clearEnvCache) {
|
|
44129
44806
|
return async (jobId, envNames) => {
|
|
@@ -44146,9 +44823,9 @@ async function runWrapped(deps, jobId, command, envNames) {
|
|
|
44146
44823
|
const queued = (await deps.readQueue()).slice(0, FLUSH_BATCH);
|
|
44147
44824
|
const flushed = [];
|
|
44148
44825
|
const deadline = deps.now().getTime() + FLUSH_BUDGET_MS;
|
|
44149
|
-
for (const
|
|
44826
|
+
for (const run3 of queued) {
|
|
44150
44827
|
if (deps.now().getTime() >= deadline) break;
|
|
44151
|
-
if (await deps.report(
|
|
44828
|
+
if (await deps.report(run3)) flushed.push(run3);
|
|
44152
44829
|
}
|
|
44153
44830
|
if (flushed.length) await deps.clearQueue(flushed);
|
|
44154
44831
|
} catch {
|
|
@@ -44207,7 +44884,7 @@ async function runWrapped(deps, jobId, command, envNames) {
|
|
|
44207
44884
|
const finishedAt = deps.now().toISOString();
|
|
44208
44885
|
const errorSnippet = exitCode !== 0 ? clean2(stderrTail.trim()) : "";
|
|
44209
44886
|
const outputSnippet = clean2((outputTail ?? "").trim());
|
|
44210
|
-
const
|
|
44887
|
+
const run2 = {
|
|
44211
44888
|
jobId,
|
|
44212
44889
|
exitCode,
|
|
44213
44890
|
startedAt,
|
|
@@ -44216,10 +44893,10 @@ async function runWrapped(deps, jobId, command, envNames) {
|
|
|
44216
44893
|
...errorSnippet ? { errorSnippet } : {},
|
|
44217
44894
|
...outputSnippet ? { outputSnippet } : {}
|
|
44218
44895
|
};
|
|
44219
|
-
const reported = await deps.report(
|
|
44896
|
+
const reported = await deps.report(run2).catch(() => false);
|
|
44220
44897
|
if (!reported) {
|
|
44221
44898
|
try {
|
|
44222
|
-
await deps.enqueueRun(
|
|
44899
|
+
await deps.enqueueRun(run2);
|
|
44223
44900
|
} catch {
|
|
44224
44901
|
}
|
|
44225
44902
|
}
|
|
@@ -44265,7 +44942,7 @@ function realSpawnCommand(command, env) {
|
|
|
44265
44942
|
return new Promise((resolve) => {
|
|
44266
44943
|
let child;
|
|
44267
44944
|
try {
|
|
44268
|
-
child = (0,
|
|
44945
|
+
child = (0, import_node_child_process5.spawn)(withoutPkgEnv(command.join(" ")), { stdio: ["inherit", "pipe", "pipe"], shell: true, ...env ? { env: { ...process.env, ...env } } : {} });
|
|
44269
44946
|
} catch {
|
|
44270
44947
|
resolve({ exitCode: 1, stderrTail: "env value could not be passed to the command", outputTail: "" });
|
|
44271
44948
|
return;
|
|
@@ -44305,22 +44982,22 @@ function fetchTimeout() {
|
|
|
44305
44982
|
return AbortSignal.timeout(FETCH_TIMEOUT_MS);
|
|
44306
44983
|
}
|
|
44307
44984
|
var SESSION_REFRESH_BUFFER_MS = 6e4;
|
|
44308
|
-
function createSessionCache(anonKey) {
|
|
44985
|
+
function createSessionCache(anonKey, lockWaitMs = () => void 0) {
|
|
44309
44986
|
let sessionPromise;
|
|
44310
44987
|
return async function getSession() {
|
|
44311
44988
|
if (sessionPromise) {
|
|
44312
|
-
const
|
|
44313
|
-
const expiresAt =
|
|
44314
|
-
if (!
|
|
44989
|
+
const cached3 = await sessionPromise;
|
|
44990
|
+
const expiresAt = cached3 ? new Date(cached3.expires_at).getTime() : 0;
|
|
44991
|
+
if (!cached3 || expiresAt - Date.now() < SESSION_REFRESH_BUFFER_MS) sessionPromise = void 0;
|
|
44315
44992
|
}
|
|
44316
|
-
sessionPromise ??= deviceSession(supabaseUrl(), anonKey,
|
|
44993
|
+
sessionPromise ??= deviceSession(supabaseUrl(), anonKey, void 0, void 0, void 0, void 0, lockWaitMs());
|
|
44317
44994
|
return sessionPromise;
|
|
44318
44995
|
};
|
|
44319
44996
|
}
|
|
44320
44997
|
function createReporter(getSession) {
|
|
44321
44998
|
const anonKey = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
44322
44999
|
const sessionFor = getSession ?? createSessionCache(anonKey);
|
|
44323
|
-
return async function report(
|
|
45000
|
+
return async function report(run2) {
|
|
44324
45001
|
const session = await sessionFor();
|
|
44325
45002
|
if (!session) return false;
|
|
44326
45003
|
try {
|
|
@@ -44328,14 +45005,14 @@ function createReporter(getSession) {
|
|
|
44328
45005
|
method: "POST",
|
|
44329
45006
|
headers: { "Content-Type": "application/json", apikey: anonKey, Authorization: `Bearer ${session.token}` },
|
|
44330
45007
|
body: JSON.stringify({
|
|
44331
|
-
job_id:
|
|
44332
|
-
status:
|
|
44333
|
-
exit_code:
|
|
44334
|
-
started_at:
|
|
44335
|
-
finished_at:
|
|
44336
|
-
...
|
|
44337
|
-
...
|
|
44338
|
-
...
|
|
45008
|
+
job_id: run2.jobId,
|
|
45009
|
+
status: run2.status,
|
|
45010
|
+
exit_code: run2.exitCode,
|
|
45011
|
+
started_at: run2.startedAt,
|
|
45012
|
+
finished_at: run2.finishedAt,
|
|
45013
|
+
...run2.errorSnippet !== void 0 ? { error_snippet: run2.errorSnippet } : {},
|
|
45014
|
+
...run2.outputSnippet !== void 0 ? { output_snippet: run2.outputSnippet } : {},
|
|
45015
|
+
...run2.backfillOf !== void 0 ? { backfill_of: run2.backfillOf } : {}
|
|
44339
45016
|
}),
|
|
44340
45017
|
signal: fetchTimeout()
|
|
44341
45018
|
});
|
|
@@ -44366,6 +45043,7 @@ function createBackfillClaimer(getSession) {
|
|
|
44366
45043
|
}
|
|
44367
45044
|
};
|
|
44368
45045
|
}
|
|
45046
|
+
var RUN_LATE_MINT_WAIT_MS = 18e4;
|
|
44369
45047
|
var RUN_USAGE = "usage: norc run --job-id <id> [--env NAME,...] -- <command>";
|
|
44370
45048
|
function parseRunArgs(args) {
|
|
44371
45049
|
const sepIndex = args.indexOf("--");
|
|
@@ -44385,10 +45063,17 @@ function parseRunArgs(args) {
|
|
|
44385
45063
|
}
|
|
44386
45064
|
async function cmdRun(args) {
|
|
44387
45065
|
const { jobId, envNames, command } = parseRunArgs(args);
|
|
44388
|
-
|
|
45066
|
+
let jobRan = false;
|
|
45067
|
+
const getSession = createSessionCache(process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY, () => jobRan ? RUN_LATE_MINT_WAIT_MS : void 0);
|
|
44389
45068
|
return runWrapped(
|
|
44390
45069
|
{
|
|
44391
|
-
spawnCommand:
|
|
45070
|
+
spawnCommand: async (c, e) => {
|
|
45071
|
+
try {
|
|
45072
|
+
return await realSpawnCommand(c, e);
|
|
45073
|
+
} finally {
|
|
45074
|
+
jobRan = true;
|
|
45075
|
+
}
|
|
45076
|
+
},
|
|
44392
45077
|
report: createReporter(getSession),
|
|
44393
45078
|
readQueue,
|
|
44394
45079
|
clearQueue,
|
|
@@ -44410,7 +45095,6 @@ var UsageParseError = class extends Error {
|
|
|
44410
45095
|
this.name = "UsageParseError";
|
|
44411
45096
|
}
|
|
44412
45097
|
};
|
|
44413
|
-
var PLANS2 = ["free", "pro", "power", "team"];
|
|
44414
45098
|
var obj = (v, p) => {
|
|
44415
45099
|
if (typeof v !== "object" || v === null || Array.isArray(v)) throw new UsageParseError(p, "expected object");
|
|
44416
45100
|
return v;
|
|
@@ -44442,7 +45126,7 @@ function parseUsageSummary(raw) {
|
|
|
44442
45126
|
const days = count(o.days, "days");
|
|
44443
45127
|
if (days !== 7 && days !== 30) throw new UsageParseError("days", "expected 7 or 30");
|
|
44444
45128
|
const plan = str(o.plan, "plan");
|
|
44445
|
-
if (!
|
|
45129
|
+
if (!isPlan(plan)) throw new UsageParseError("plan", `unknown plan "${plan}"`);
|
|
44446
45130
|
const daily = arr(o.daily, "daily").map((d, i) => {
|
|
44447
45131
|
const e = obj(d, `daily[${i}]`);
|
|
44448
45132
|
const date = str(e.date, `daily[${i}].date`);
|
|
@@ -44539,7 +45223,6 @@ var MACHINE_STATUS_DISPLAY = {
|
|
|
44539
45223
|
var UPDATE_REQUIRED_DISPLAY = { ...MACHINE_STATUS_DISPLAY.offline, label: "Update required" };
|
|
44540
45224
|
|
|
44541
45225
|
// ../../packages/usage/src/view.ts
|
|
44542
|
-
var PLAN_NAMES = { free: "Free", pro: "Pro", power: "Power", team: "Team" };
|
|
44543
45226
|
function headroomTone(used, cap) {
|
|
44544
45227
|
const p = used / cap;
|
|
44545
45228
|
return p >= 0.9 ? "failed" : p >= 0.7 ? "warning" : "calm";
|
|
@@ -44557,12 +45240,13 @@ function headroomFooter(usedJobs, usedMachines, plan) {
|
|
|
44557
45240
|
const n = PLAN_NAMES[plan];
|
|
44558
45241
|
const jobs = headroom("jobs", usedJobs, plan);
|
|
44559
45242
|
const mach = headroom("machines", usedMachines, plan);
|
|
45243
|
+
const hint = machineUpgradeHint(plan);
|
|
44560
45244
|
const messages = [];
|
|
44561
45245
|
if (jobs.tone !== "calm" && jobs.left != null) {
|
|
44562
45246
|
messages.push(jobs.left <= 0 ? `Job limit reached on ${n}.` : `${jobs.left} job${jobs.left === 1 ? "" : "s"} left on ${n}.`);
|
|
44563
45247
|
}
|
|
44564
45248
|
if (mach.tone !== "calm" && mach.left != null) {
|
|
44565
|
-
messages.push(mach.left <= 0 ? `Machine limit reached on ${n}
|
|
45249
|
+
messages.push(mach.left <= 0 ? `Machine limit reached on ${n}.${hint ? ` ${hint}` : ""}` : `${mach.left} machine${mach.left === 1 ? "" : "s"} left on ${n}.`);
|
|
44566
45250
|
}
|
|
44567
45251
|
return messages.length ? { messages, note: "Plans scale jobs and machines together.", showUpgrade: plan !== "power" && plan !== "team" } : { messages, note: `Plenty of room on ${n}. You'll see a note here when you pass 70%.`, showUpgrade: false };
|
|
44568
45252
|
}
|
|
@@ -44748,7 +45432,7 @@ function renderUsage(s, opts) {
|
|
|
44748
45432
|
];
|
|
44749
45433
|
for (const m of f.messages) lines.push(amber(m));
|
|
44750
45434
|
lines.push(...wrap(f.note, colW).map(dim));
|
|
44751
|
-
if (f.showUpgrade) lines.push(`Upgrade: ${cyan(`${opts.vaultUrl ?? "https://vault.norc.app"}/settings/
|
|
45435
|
+
if (f.showUpgrade) lines.push(`Upgrade: ${cyan(`${opts.vaultUrl ?? "https://vault.norc.app"}/settings/plan`)}`);
|
|
44752
45436
|
if (f.messages.length) lines.push("Need more? Email hello@norc.app");
|
|
44753
45437
|
return lines;
|
|
44754
45438
|
};
|
|
@@ -44928,7 +45612,7 @@ ${USAGE2}`);
|
|
|
44928
45612
|
|
|
44929
45613
|
// src/paired-device.ts
|
|
44930
45614
|
async function savePairedDevice(device, cfgPath = configPath(), cachePath = envCachePath()) {
|
|
44931
|
-
await saveConfig({ device }, cfgPath, { keys: ["device"] });
|
|
45615
|
+
await saveConfig({ device: { ...device, pairedAt: device.pairedAt ?? (/* @__PURE__ */ new Date()).toISOString() } }, cfgPath, { keys: ["device", "enc"] });
|
|
44932
45616
|
await clearEnvCache(cachePath);
|
|
44933
45617
|
}
|
|
44934
45618
|
|
|
@@ -44942,7 +45626,7 @@ async function saveUserSession(session, path = configPath()) {
|
|
|
44942
45626
|
await saveConfig({ session }, path, { keys: ["session"] });
|
|
44943
45627
|
}
|
|
44944
45628
|
async function logout(path = configPath(), cachePath = envCachePath(), opts = {}) {
|
|
44945
|
-
const config = await
|
|
45629
|
+
const config = await readConfigFile(path).catch(() => ({}));
|
|
44946
45630
|
const had = { session: Boolean(config.session), device: Boolean(config.device) };
|
|
44947
45631
|
if (config.session && opts.signOut) {
|
|
44948
45632
|
let timer;
|
|
@@ -44956,14 +45640,13 @@ async function logout(path = configPath(), cachePath = envCachePath(), opts = {}
|
|
|
44956
45640
|
});
|
|
44957
45641
|
clearTimeout(timer);
|
|
44958
45642
|
}
|
|
44959
|
-
await saveConfig({}, path, { keys: ["session", "device"], sweepAll: true });
|
|
45643
|
+
await saveConfig({}, path, { keys: ["session", "device", "enc"], sweepAll: true });
|
|
44960
45644
|
await clearEnvCache(cachePath);
|
|
44961
45645
|
return had;
|
|
44962
45646
|
}
|
|
44963
45647
|
|
|
44964
45648
|
// src/commands/bridge.ts
|
|
44965
|
-
var
|
|
44966
|
-
var import_node_crypto3 = require("node:crypto");
|
|
45649
|
+
var import_node_child_process7 = require("node:child_process");
|
|
44967
45650
|
|
|
44968
45651
|
// src/enc-key.ts
|
|
44969
45652
|
async function loadOrCreateEncKey(config, persist) {
|
|
@@ -44978,16 +45661,16 @@ async function loadOrCreateEncKey(config, persist) {
|
|
|
44978
45661
|
var CAPABILITY_TRUSTED_KEYS = activeTrustedKeys();
|
|
44979
45662
|
|
|
44980
45663
|
// src/dupe-check.ts
|
|
44981
|
-
var
|
|
44982
|
-
var
|
|
45664
|
+
var import_promises5 = require("node:fs/promises");
|
|
45665
|
+
var import_node_child_process6 = require("node:child_process");
|
|
44983
45666
|
var import_node_util = require("node:util");
|
|
44984
|
-
var execFileAsync = (0, import_node_util.promisify)(
|
|
45667
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process6.execFile);
|
|
44985
45668
|
function defaultDupeCheckDeps() {
|
|
44986
45669
|
return {
|
|
44987
45670
|
platform: process.platform,
|
|
44988
45671
|
fileExists: async (p) => {
|
|
44989
45672
|
try {
|
|
44990
|
-
await (0,
|
|
45673
|
+
await (0, import_promises5.access)(p);
|
|
44991
45674
|
return true;
|
|
44992
45675
|
} catch {
|
|
44993
45676
|
return false;
|
|
@@ -45002,9 +45685,9 @@ function defaultDupeCheckDeps() {
|
|
|
45002
45685
|
}
|
|
45003
45686
|
},
|
|
45004
45687
|
checkRegistry: async (displayName) => {
|
|
45005
|
-
const script = `$found = Get-ItemProperty 'HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*','HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*' -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -eq
|
|
45688
|
+
const script = `$found = Get-ItemProperty 'HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*','HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*' -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -eq $env:NORC_DISPLAY_NAME } | Select-Object -First 1; if ($found) { exit 0 } else { exit 1 }`;
|
|
45006
45689
|
try {
|
|
45007
|
-
await execFileAsync("powershell", ["-NoProfile", "-Command", script]);
|
|
45690
|
+
await execFileAsync("powershell", ["-NoProfile", "-Command", script], { env: { ...process.env, NORC_DISPLAY_NAME: displayName } });
|
|
45008
45691
|
return true;
|
|
45009
45692
|
} catch {
|
|
45010
45693
|
return false;
|
|
@@ -45033,10 +45716,10 @@ async function checkForDesktopInstall(deps = defaultDupeCheckDeps()) {
|
|
|
45033
45716
|
|
|
45034
45717
|
// src/crontab-changes.ts
|
|
45035
45718
|
var import_node_fs2 = require("node:fs");
|
|
45036
|
-
var
|
|
45037
|
-
var
|
|
45719
|
+
var import_node_path7 = require("node:path");
|
|
45720
|
+
var import_node_os7 = require("node:os");
|
|
45038
45721
|
function crontabChangesPath() {
|
|
45039
|
-
return (0,
|
|
45722
|
+
return (0, import_node_path7.join)((0, import_node_os7.homedir)(), ".config", "norc", "crontab-changes.json");
|
|
45040
45723
|
}
|
|
45041
45724
|
function fileChangeStore(path) {
|
|
45042
45725
|
return {
|
|
@@ -45048,7 +45731,7 @@ function fileChangeStore(path) {
|
|
|
45048
45731
|
}
|
|
45049
45732
|
},
|
|
45050
45733
|
save: (v) => {
|
|
45051
|
-
(0, import_node_fs2.mkdirSync)((0,
|
|
45734
|
+
(0, import_node_fs2.mkdirSync)((0, import_node_path7.dirname)(path), { recursive: true, mode: 448 });
|
|
45052
45735
|
(0, import_node_fs2.writeFileSync)(path, v, { mode: 384 });
|
|
45053
45736
|
}
|
|
45054
45737
|
};
|
|
@@ -45067,8 +45750,8 @@ function trackLineChanges(io, path = crontabChangesPath()) {
|
|
|
45067
45750
|
}
|
|
45068
45751
|
|
|
45069
45752
|
// src/remote-consent.ts
|
|
45070
|
-
var
|
|
45071
|
-
var
|
|
45753
|
+
var import_node_os8 = require("node:os");
|
|
45754
|
+
var import_promises6 = require("node:readline/promises");
|
|
45072
45755
|
function sanitize(s, max = 160) {
|
|
45073
45756
|
const clean2 = s.replace(/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff\u{e0000}-\u{e007f}]/gu, " ").trim();
|
|
45074
45757
|
return clean2.length > max ? `${clean2.slice(0, max)}\u2026` : clean2;
|
|
@@ -45121,7 +45804,7 @@ async function cmdRemote(args, config, save, io = defaultIo()) {
|
|
|
45121
45804
|
}
|
|
45122
45805
|
if (sub !== "enable") throw new Error("usage: norc remote enable|disable|status");
|
|
45123
45806
|
const account = config.session?.email ?? "the account this machine is paired to";
|
|
45124
|
-
io.log(`This allows ${account} (via norc web, mobile, desktop, MCP or API keys) to read and write this machine's crontab and run jobs on ${(0,
|
|
45807
|
+
io.log(`This allows ${account} (via norc web, mobile, desktop, MCP or API keys) to read and write this machine's crontab and run jobs on ${(0, import_node_os8.hostname)()} as the current user.`);
|
|
45125
45808
|
io.log("Every remote change is logged here with the exact command. Disable any time with `norc remote disable`.");
|
|
45126
45809
|
if (!args.includes("--yes")) {
|
|
45127
45810
|
if (!io.isTTY) throw new Error("not interactive: re-run in a terminal, or pass --yes");
|
|
@@ -45139,7 +45822,7 @@ function defaultIo() {
|
|
|
45139
45822
|
isTTY: Boolean(process.stdin.isTTY),
|
|
45140
45823
|
log: (m) => console.log(m),
|
|
45141
45824
|
ask: async (q) => {
|
|
45142
|
-
const rl = (0,
|
|
45825
|
+
const rl = (0, import_promises6.createInterface)({ input: process.stdin, output: process.stdout });
|
|
45143
45826
|
try {
|
|
45144
45827
|
return (await rl.question(q)).trim();
|
|
45145
45828
|
} finally {
|
|
@@ -45216,6 +45899,10 @@ function findManagedJob(currentCrontab, jobId) {
|
|
|
45216
45899
|
const entry = parseCrontab(currentCrontab).find((e) => e.kind === "job" && e.id === jobId);
|
|
45217
45900
|
return entry ? { id: jobId, command: unwrapCommand(entry.command), envNames: wrappedEnvNames(entry.command) ?? [] } : null;
|
|
45218
45901
|
}
|
|
45902
|
+
var sameNames = (a, b) => {
|
|
45903
|
+
const ka = Object.keys(a);
|
|
45904
|
+
return ka.length === Object.keys(b).length && ka.every((k) => b[k] !== void 0 && a[k].length === b[k].length && a[k].every((n, i) => n === b[k][i]));
|
|
45905
|
+
};
|
|
45219
45906
|
function reprojectEnvNames(currentCrontab, names) {
|
|
45220
45907
|
const want = /* @__PURE__ */ new Map();
|
|
45221
45908
|
for (const e of parseCrontab(currentCrontab)) {
|
|
@@ -45228,7 +45915,7 @@ function pruneExpiredExecuteNonces(nonces, nowSec) {
|
|
|
45228
45915
|
}
|
|
45229
45916
|
function spawnWrappedCommand(command) {
|
|
45230
45917
|
return new Promise((resolve, reject) => {
|
|
45231
|
-
const child = (0,
|
|
45918
|
+
const child = (0, import_node_child_process7.spawn)(withoutPkgEnv(command), { shell: true, detached: true, stdio: "ignore" });
|
|
45232
45919
|
child.once("spawn", () => {
|
|
45233
45920
|
child.unref();
|
|
45234
45921
|
resolve();
|
|
@@ -45249,6 +45936,7 @@ async function logStartupWarnings(deps) {
|
|
|
45249
45936
|
}
|
|
45250
45937
|
async function runBridge(env, crontabIo) {
|
|
45251
45938
|
await logStartupWarnings();
|
|
45939
|
+
await migrateSecrets().catch((e) => console.error("[norc bridge] could not move the device token / relay key to where NORC_SECRET_STORE says:", e instanceof Error ? e.message : e));
|
|
45252
45940
|
const config = await loadConfig();
|
|
45253
45941
|
if (!config.device) throw new Error("not paired \u2014 run `norc pair` first");
|
|
45254
45942
|
const lineChanges = trackLineChanges(crontabIo);
|
|
@@ -45257,13 +45945,14 @@ async function runBridge(env, crontabIo) {
|
|
|
45257
45945
|
void lineChanges.look();
|
|
45258
45946
|
}, 3e4);
|
|
45259
45947
|
let configSaveChain = Promise.resolve();
|
|
45260
|
-
const persistConfig = () => {
|
|
45261
|
-
const save = configSaveChain.then(() =>
|
|
45948
|
+
const persistConfig = (keys = ["bridge"]) => {
|
|
45949
|
+
const save = configSaveChain.then(async () => {
|
|
45950
|
+
await saveConfig(config, void 0, { keys });
|
|
45951
|
+
});
|
|
45262
45952
|
configSaveChain = save.catch(() => {
|
|
45263
45953
|
});
|
|
45264
45954
|
return save;
|
|
45265
45955
|
};
|
|
45266
|
-
const keyPair = await loadOrCreateEncKey(config, persistConfig);
|
|
45267
45956
|
let state = "disconnected";
|
|
45268
45957
|
let attempt = 0;
|
|
45269
45958
|
let idleLogged = false;
|
|
@@ -45277,6 +45966,15 @@ async function runBridge(env, crontabIo) {
|
|
|
45277
45966
|
}
|
|
45278
45967
|
idleLogged = false;
|
|
45279
45968
|
if (onDisk) config.device = onDisk;
|
|
45969
|
+
let keyPair;
|
|
45970
|
+
try {
|
|
45971
|
+
config.enc = (await loadConfig()).enc;
|
|
45972
|
+
keyPair = await loadOrCreateEncKey(config, () => persistConfig(["bridge", "enc"]));
|
|
45973
|
+
} catch (e) {
|
|
45974
|
+
console.error("[norc bridge] could not load the relay key:", e instanceof Error ? e.message : e);
|
|
45975
|
+
await wait(backoffDelay(attempt++));
|
|
45976
|
+
continue;
|
|
45977
|
+
}
|
|
45280
45978
|
const machineId = config.device.machineId;
|
|
45281
45979
|
const builtFor = identityKey(config.device);
|
|
45282
45980
|
let identityChanged = false;
|
|
@@ -45305,15 +46003,16 @@ async function runBridge(env, crontabIo) {
|
|
|
45305
46003
|
});
|
|
45306
46004
|
try {
|
|
45307
46005
|
state = reduceConn(state, "connect");
|
|
45308
|
-
const sess = await
|
|
46006
|
+
const sess = await cachedDeviceSession(env.supabaseUrl, env.anonKey, keyPair.publicJwk, { force: true });
|
|
45309
46007
|
if (!sess) {
|
|
45310
46008
|
console.error("[norc bridge] device session mint failed");
|
|
45311
46009
|
await wait(backoffDelay(attempt++));
|
|
45312
46010
|
continue;
|
|
45313
46011
|
}
|
|
46012
|
+
let current = sess;
|
|
45314
46013
|
sb = createClient(env.supabaseUrl, env.anonKey, {
|
|
45315
46014
|
auth: { persistSession: false },
|
|
45316
|
-
|
|
46015
|
+
accessToken: async () => current.token,
|
|
45317
46016
|
realtime: { params: { eventsPerSecond: 5 } }
|
|
45318
46017
|
});
|
|
45319
46018
|
sb.realtime.setAuth(sess.token);
|
|
@@ -45329,7 +46028,7 @@ async function runBridge(env, crontabIo) {
|
|
|
45329
46028
|
await refreshRemote(config);
|
|
45330
46029
|
return remoteEnabled(config);
|
|
45331
46030
|
}, "remote reads are disabled on this host (run `norc remote enable`)") });
|
|
45332
|
-
const pullNames = () =>
|
|
46031
|
+
const pullNames = () => cachedDeviceSession(env.supabaseUrl, env.anonKey, keyPair.publicJwk).then((s) => pullEnvNames(fetch, s, 1e4)).catch(() => null);
|
|
45333
46032
|
const deps = buildWriteIntentDeps(config, machineId, crontabIo, () => void persistConfig(), refreshRemote, pullNames);
|
|
45334
46033
|
const rawDeps = buildRawWriteIntentDeps(config, machineId, crontabIo, () => void persistConfig(), refreshRemote);
|
|
45335
46034
|
sec.on("write-intent", (payload, from) => {
|
|
@@ -45445,9 +46144,9 @@ async function runBridge(env, crontabIo) {
|
|
|
45445
46144
|
}
|
|
45446
46145
|
for (let attempt2 = 0; attempt2 < 3; attempt2++) {
|
|
45447
46146
|
try {
|
|
45448
|
-
const
|
|
45449
|
-
const next = projectJobsRemoved(
|
|
45450
|
-
if (next !==
|
|
46147
|
+
const current2 = await crontabIo.read();
|
|
46148
|
+
const next = projectJobsRemoved(current2, gone);
|
|
46149
|
+
if (next !== current2) console.log(`[norc bridge] jobs-deleted (${sanitize(config.remote?.account ?? "", 80)}): removing ${gone.length} job(s) the server no longer has`);
|
|
45451
46150
|
await crontabIo.write(next);
|
|
45452
46151
|
queueSyncJobs();
|
|
45453
46152
|
return;
|
|
@@ -45471,12 +46170,45 @@ async function runBridge(env, crontabIo) {
|
|
|
45471
46170
|
if (envRefresh) clearInterval(envRefresh);
|
|
45472
46171
|
heartbeat = setInterval(() => {
|
|
45473
46172
|
void watchIdentity().then((ok) => {
|
|
45474
|
-
if (ok) return
|
|
46173
|
+
if (!ok) return;
|
|
46174
|
+
return heartbeatTick({
|
|
46175
|
+
expiresAt: () => current.expires_at,
|
|
46176
|
+
beat: async () => {
|
|
46177
|
+
const { data, error } = await sb.rpc("machine_heartbeat");
|
|
46178
|
+
if (error) throw new Error(error.message);
|
|
46179
|
+
return data === true;
|
|
46180
|
+
},
|
|
46181
|
+
mint: async (force) => {
|
|
46182
|
+
const s = await cachedDeviceSession(env.supabaseUrl, env.anonKey, keyPair.publicJwk, { force });
|
|
46183
|
+
if (s) current = s;
|
|
46184
|
+
return s;
|
|
46185
|
+
},
|
|
46186
|
+
// setAuth may throw or reject; neither may escape (heartbeatTick would report a good mint as failed).
|
|
46187
|
+
onRenewed: (token) => {
|
|
46188
|
+
void Promise.resolve().then(() => sb.realtime.setAuth(token)).catch((e) => console.warn("[norc bridge] could not hand the renewed token to Realtime:", e instanceof Error ? e.message : "unknown error"));
|
|
46189
|
+
}
|
|
46190
|
+
});
|
|
45475
46191
|
});
|
|
45476
46192
|
}, 6e4);
|
|
46193
|
+
let lastFingerprint = null;
|
|
45477
46194
|
const pullEnv2 = () => enqueueMutation(async () => {
|
|
45478
|
-
const
|
|
45479
|
-
if (
|
|
46195
|
+
const state2 = await pollEnvState(sb);
|
|
46196
|
+
if (!await watchIdentity()) return;
|
|
46197
|
+
if (state2 === null) {
|
|
46198
|
+
const names = await pullNames();
|
|
46199
|
+
if (names) await applyEnvNames(crontabIo, names);
|
|
46200
|
+
return;
|
|
46201
|
+
}
|
|
46202
|
+
if (state2 === "not-live") {
|
|
46203
|
+
const s2 = await cachedDeviceSession(env.supabaseUrl, env.anonKey, keyPair.publicJwk, { force: true }).catch(() => null);
|
|
46204
|
+
if (s2) current = s2;
|
|
46205
|
+
return;
|
|
46206
|
+
}
|
|
46207
|
+
if (state2.fingerprint === lastFingerprint) return;
|
|
46208
|
+
const s = await cachedDeviceSession(env.supabaseUrl, env.anonKey, keyPair.publicJwk).catch(() => null);
|
|
46209
|
+
const pulled = await pullEnvNames(fetch, s, 1e4);
|
|
46210
|
+
if (!pulled) return;
|
|
46211
|
+
if (await applyEnvNames(crontabIo, pulled) && sameNames(pulled, state2.names)) lastFingerprint = state2.fingerprint;
|
|
45480
46212
|
});
|
|
45481
46213
|
pullEnv2();
|
|
45482
46214
|
envRefresh = setInterval(pullEnv2, 5 * 6e4);
|
|
@@ -45519,46 +46251,48 @@ async function applyEnvNames(crontabIo, names) {
|
|
|
45519
46251
|
try {
|
|
45520
46252
|
const current = await crontabIo.read();
|
|
45521
46253
|
const next = reprojectEnvNames(current, names);
|
|
45522
|
-
if (next === current) return;
|
|
46254
|
+
if (next === current) return true;
|
|
45523
46255
|
await crontabIo.write(next);
|
|
45524
46256
|
console.log("[norc bridge] updated the env var names on managed crontab lines");
|
|
46257
|
+
return true;
|
|
45525
46258
|
} catch (e) {
|
|
45526
46259
|
console.error("[norc bridge] updating env var names failed:", e instanceof Error ? e.message : e);
|
|
46260
|
+
return false;
|
|
45527
46261
|
}
|
|
45528
46262
|
}
|
|
45529
46263
|
var IDLE_POLL_MS = 3e4;
|
|
45530
46264
|
async function readIdentity() {
|
|
45531
46265
|
try {
|
|
45532
|
-
return (await
|
|
46266
|
+
return (await readConfigFile()).device ?? null;
|
|
45533
46267
|
} catch {
|
|
45534
46268
|
return void 0;
|
|
45535
46269
|
}
|
|
45536
46270
|
}
|
|
45537
46271
|
function identityKey(d) {
|
|
45538
|
-
return d ? `${d.machineId}:${
|
|
46272
|
+
return d ? `${d.machineId}:${d.pairedAt ?? ""}` : "";
|
|
45539
46273
|
}
|
|
45540
46274
|
function wait(ms) {
|
|
45541
46275
|
return new Promise((r) => setTimeout(r, ms));
|
|
45542
46276
|
}
|
|
45543
46277
|
|
|
45544
46278
|
// src/service.ts
|
|
45545
|
-
var
|
|
45546
|
-
var
|
|
46279
|
+
var import_promises7 = require("node:fs/promises");
|
|
46280
|
+
var import_node_child_process8 = require("node:child_process");
|
|
45547
46281
|
var import_node_util2 = require("node:util");
|
|
45548
|
-
var
|
|
45549
|
-
var
|
|
45550
|
-
var execFileAsync2 = (0, import_node_util2.promisify)(
|
|
46282
|
+
var import_node_os9 = require("node:os");
|
|
46283
|
+
var import_node_path8 = require("node:path");
|
|
46284
|
+
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process8.execFile);
|
|
45551
46285
|
function resolveBinaryPath(proc = process) {
|
|
45552
46286
|
return proc.pkg ? proc.execPath : proc.argv[1];
|
|
45553
46287
|
}
|
|
45554
46288
|
function defaultServiceDeps(binaryPath) {
|
|
45555
46289
|
return {
|
|
45556
|
-
platform: (0,
|
|
45557
|
-
home: (0,
|
|
46290
|
+
platform: (0, import_node_os9.platform)(),
|
|
46291
|
+
home: (0, import_node_os9.homedir)(),
|
|
45558
46292
|
binaryPath,
|
|
45559
|
-
mkdir:
|
|
45560
|
-
writeFile:
|
|
45561
|
-
rm:
|
|
46293
|
+
mkdir: import_promises7.mkdir,
|
|
46294
|
+
writeFile: import_promises7.writeFile,
|
|
46295
|
+
rm: import_promises7.rm,
|
|
45562
46296
|
exec: async (cmd, args) => {
|
|
45563
46297
|
await execFileAsync2(cmd, args);
|
|
45564
46298
|
}
|
|
@@ -45566,10 +46300,10 @@ function defaultServiceDeps(binaryPath) {
|
|
|
45566
46300
|
}
|
|
45567
46301
|
var SCHEDULED_TASK_NAME = "norc-cli-bridge";
|
|
45568
46302
|
function systemdUnitPath(home) {
|
|
45569
|
-
return (0,
|
|
46303
|
+
return (0, import_node_path8.join)(home, ".config", "systemd", "user", "norc.service");
|
|
45570
46304
|
}
|
|
45571
46305
|
function launchdPlistPath(home) {
|
|
45572
|
-
return (0,
|
|
46306
|
+
return (0, import_node_path8.join)(home, "Library", "LaunchAgents", "dev.norc.cli.plist");
|
|
45573
46307
|
}
|
|
45574
46308
|
var xmlEscape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
45575
46309
|
function systemdUnit(binaryPath) {
|
|
@@ -45609,7 +46343,7 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
45609
46343
|
switch (deps.platform) {
|
|
45610
46344
|
case "linux": {
|
|
45611
46345
|
const path = systemdUnitPath(deps.home);
|
|
45612
|
-
await deps.mkdir((0,
|
|
46346
|
+
await deps.mkdir((0, import_node_path8.join)(deps.home, ".config", "systemd", "user"), { recursive: true });
|
|
45613
46347
|
await deps.writeFile(path, systemdUnit(deps.binaryPath));
|
|
45614
46348
|
await deps.exec("systemctl", ["--user", "daemon-reload"]);
|
|
45615
46349
|
await deps.exec("systemctl", ["--user", "enable", "--now", "norc.service"]);
|
|
@@ -45617,7 +46351,7 @@ async function installService(deps = defaultServiceDeps(process.execPath)) {
|
|
|
45617
46351
|
}
|
|
45618
46352
|
case "darwin": {
|
|
45619
46353
|
const path = launchdPlistPath(deps.home);
|
|
45620
|
-
await deps.mkdir((0,
|
|
46354
|
+
await deps.mkdir((0, import_node_path8.join)(deps.home, "Library", "LaunchAgents"), { recursive: true });
|
|
45621
46355
|
await deps.writeFile(path, launchdPlist(deps.binaryPath));
|
|
45622
46356
|
await deps.exec("launchctl", ["load", "-w", path]);
|
|
45623
46357
|
return;
|
|
@@ -45710,7 +46444,7 @@ function supabase() {
|
|
|
45710
46444
|
return createClient(url, anon);
|
|
45711
46445
|
}
|
|
45712
46446
|
async function prompt(question) {
|
|
45713
|
-
const rl = (0,
|
|
46447
|
+
const rl = (0, import_promises8.createInterface)({ input: process.stdin, output: process.stdout });
|
|
45714
46448
|
try {
|
|
45715
46449
|
return (await rl.question(question)).trim();
|
|
45716
46450
|
} finally {
|
|
@@ -45732,7 +46466,7 @@ async function cmdLogin(args) {
|
|
|
45732
46466
|
}
|
|
45733
46467
|
if (apiKey) {
|
|
45734
46468
|
debugLog("login: using API-key path, POST", `${vaultUrl2}/api/v1/machines`, "key:", redactSecret(apiKey));
|
|
45735
|
-
const result2 = await pairWithApiKey(fetch, vaultUrl2, apiKey, (0,
|
|
46469
|
+
const result2 = await pairWithApiKey(fetch, vaultUrl2, apiKey, (0, import_node_os10.hostname)());
|
|
45736
46470
|
debugLog("login: pairWithApiKey result:", result2.ok ? { ok: true, machineId: result2.machineId, deviceToken: redactSecret(result2.deviceToken) } : result2);
|
|
45737
46471
|
if (!result2.ok) throw new Error(result2.message);
|
|
45738
46472
|
await savePairedDevice({ machineId: result2.machineId, deviceToken: result2.deviceToken });
|
|
@@ -45747,13 +46481,13 @@ async function cmdLogin(args) {
|
|
|
45747
46481
|
const started = await requestLogin(client, email);
|
|
45748
46482
|
debugLog("login: requestLogin result:", started);
|
|
45749
46483
|
if (!started.ok) throw new Error(started.message);
|
|
45750
|
-
console.log(`
|
|
46484
|
+
console.log(`if ${email} has a norc account, a code is on its way`);
|
|
45751
46485
|
const code = await prompt("enter the code from your email: ");
|
|
45752
46486
|
const result = await verifyLogin(client, email, code);
|
|
45753
46487
|
debugLog("login: verifyLogin result:", result.ok ? { ok: true } : result);
|
|
45754
46488
|
if (!result.ok) throw new Error(result.message);
|
|
45755
46489
|
await saveUserSession({ email, accessToken: result.accessToken, refreshToken: result.refreshToken });
|
|
45756
|
-
console.log((await
|
|
46490
|
+
console.log((await readConfigFile().catch(() => ({}))).device ? "logged in. this machine stays paired; `norc env` now works here." : "logged in. run `norc pair` next to register this machine.");
|
|
45757
46491
|
}
|
|
45758
46492
|
async function cmdPair() {
|
|
45759
46493
|
const client = supabase();
|
|
@@ -45773,7 +46507,7 @@ async function cmdPair() {
|
|
|
45773
46507
|
});
|
|
45774
46508
|
}
|
|
45775
46509
|
async function userClient() {
|
|
45776
|
-
const config = await
|
|
46510
|
+
const config = await readConfigFile();
|
|
45777
46511
|
const session = requireUserSession(config);
|
|
45778
46512
|
const url = supabaseUrl();
|
|
45779
46513
|
const sb = createClient(url, process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY, { auth: { persistSession: false, autoRefreshToken: false } });
|
|
@@ -45787,7 +46521,7 @@ async function userClient() {
|
|
|
45787
46521
|
async function saveSession(sb) {
|
|
45788
46522
|
const { data: { session } } = await sb.auth.getSession();
|
|
45789
46523
|
if (!session) return;
|
|
45790
|
-
const config = await
|
|
46524
|
+
const config = await readConfigFile();
|
|
45791
46525
|
if (!config.session) return;
|
|
45792
46526
|
await saveUserSession({ ...config.session, accessToken: session.access_token, refreshToken: session.refresh_token });
|
|
45793
46527
|
}
|
|
@@ -45795,7 +46529,7 @@ async function envDeps() {
|
|
|
45795
46529
|
const sb = await userClient();
|
|
45796
46530
|
const url = supabaseUrl();
|
|
45797
46531
|
const anon = process.env.NORC_SUPABASE_ANON_KEY ?? DEFAULT_SUPABASE_ANON_KEY;
|
|
45798
|
-
const rl = () => (0,
|
|
46532
|
+
const rl = () => (0, import_promises8.createInterface)({ input: process.stdin, output: process.stdout });
|
|
45799
46533
|
return {
|
|
45800
46534
|
isTTY: Boolean(process.stdin.isTTY),
|
|
45801
46535
|
listVars: async () => {
|
|
@@ -45807,7 +46541,7 @@ async function envDeps() {
|
|
|
45807
46541
|
const { data, error } = await sb.from("accounts").select("plan, trial_ends_at").limit(1).maybeSingle();
|
|
45808
46542
|
const row = data;
|
|
45809
46543
|
const p = row?.plan;
|
|
45810
|
-
return error || p
|
|
46544
|
+
return error || !isPlan(p) ? null : effectivePlan(p, row?.trial_ends_at);
|
|
45811
46545
|
},
|
|
45812
46546
|
bindingNames: async () => {
|
|
45813
46547
|
const { data, error } = await sb.from("job_env_bindings").select("name, jobs!inner(archived_at, machines!inner(archived_at, detached_at))").is("jobs.archived_at", null).is("jobs.machines.archived_at", null).is("jobs.machines.detached_at", null);
|
|
@@ -45957,7 +46691,7 @@ async function main() {
|
|
|
45957
46691
|
case "gitops": {
|
|
45958
46692
|
const vaultUrl2 = vaultUrl();
|
|
45959
46693
|
const apiKey = process.env.NORC_API_KEY;
|
|
45960
|
-
process.exitCode = await cmdGitops(args, { fetchImpl: fetch, readFile: (p) => (0,
|
|
46694
|
+
process.exitCode = await cmdGitops(args, { fetchImpl: fetch, readFile: (p) => (0, import_promises9.readFile)(p, "utf8"), vaultUrl: vaultUrl2, apiKey });
|
|
45961
46695
|
return;
|
|
45962
46696
|
}
|
|
45963
46697
|
case "run":
|
|
@@ -45984,8 +46718,10 @@ async function main() {
|
|
|
45984
46718
|
case "bridge":
|
|
45985
46719
|
return cmdBridge();
|
|
45986
46720
|
case "remote": {
|
|
45987
|
-
const config = await
|
|
45988
|
-
return cmdRemote(args, config, (c) =>
|
|
46721
|
+
const config = await readConfigFile();
|
|
46722
|
+
return cmdRemote(args, config, async (c) => {
|
|
46723
|
+
await saveConfig(c, void 0, { keys: ["remote"] });
|
|
46724
|
+
});
|
|
45989
46725
|
}
|
|
45990
46726
|
case "service": {
|
|
45991
46727
|
const [sub] = args;
|