spacetimedb 1.6.2 → 1.7.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/LICENSE.txt CHANGED
@@ -5,7 +5,7 @@ Business Source License 1.1
5
5
  Parameters
6
6
 
7
7
  Licensor: Clockwork Laboratories, Inc.
8
- Licensed Work: SpacetimeDB 1.6.0
8
+ Licensed Work: SpacetimeDB 1.7.0
9
9
  The Licensed Work is
10
10
  (c) 2023 Clockwork Laboratories, Inc.
11
11
 
@@ -21,7 +21,7 @@ Additional Use Grant: You may make use of the Licensed Work provided your
21
21
  Licensed Work by creating tables whose schemas are
22
22
  controlled by such third parties.
23
23
 
24
- Change Date: 2030-10-15
24
+ Change Date: 2030-10-31
25
25
 
26
26
  Change License: GNU Affero General Public License v3.0 with a linking
27
27
  exception
@@ -53,9 +53,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
53
53
  mod
54
54
  ));
55
55
 
56
- // ../../../../../../../../mnt/nutera/localhd-symlinks/home/lead/work/clockwork-localhd/SpacetimeDBPrivate/public/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
56
+ // ../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
57
57
  var require_base64_js = __commonJS({
58
- "../../../../../../../../mnt/nutera/localhd-symlinks/home/lead/work/clockwork-localhd/SpacetimeDBPrivate/public/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports) {
58
+ "../../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js"(exports) {
59
59
  exports.byteLength = byteLength;
60
60
  exports.toByteArray = toByteArray;
61
61
  exports.fromByteArray = fromByteArray2;
@@ -153,9 +153,9 @@ var require_base64_js = __commonJS({
153
153
  }
154
154
  });
155
155
 
156
- // ../../../../../../../../mnt/nutera/localhd-symlinks/home/lead/work/clockwork-localhd/SpacetimeDBPrivate/public/node_modules/.pnpm/fast-text-encoding@1.0.6/node_modules/fast-text-encoding/text.min.js
156
+ // ../../node_modules/.pnpm/fast-text-encoding@1.0.6/node_modules/fast-text-encoding/text.min.js
157
157
  var require_text_min = __commonJS({
158
- "../../../../../../../../mnt/nutera/localhd-symlinks/home/lead/work/clockwork-localhd/SpacetimeDBPrivate/public/node_modules/.pnpm/fast-text-encoding@1.0.6/node_modules/fast-text-encoding/text.min.js"(exports) {
158
+ "../../node_modules/.pnpm/fast-text-encoding@1.0.6/node_modules/fast-text-encoding/text.min.js"(exports) {
159
159
  (function(scope) {
160
160
  function B(r, e) {
161
161
  var f;
@@ -1605,8 +1605,10 @@ var Schema = class {
1605
1605
  reducer(name, paramsOrFn, fn) {
1606
1606
  if (typeof paramsOrFn === "function") {
1607
1607
  reducer(name, {}, paramsOrFn);
1608
+ return paramsOrFn;
1608
1609
  } else {
1609
1610
  reducer(name, paramsOrFn, fn);
1611
+ return fn;
1610
1612
  }
1611
1613
  }
1612
1614
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -4912,6 +4914,111 @@ var sys = freeze(
4912
4914
  ])
4913
4915
  )
4914
4916
  );
4917
+ function parseJsonObject(json) {
4918
+ let value;
4919
+ try {
4920
+ value = JSON.parse(json);
4921
+ } catch {
4922
+ throw new Error("Invalid JSON: failed to parse string");
4923
+ }
4924
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
4925
+ throw new Error("Expected a JSON object at the top level");
4926
+ }
4927
+ return value;
4928
+ }
4929
+ var JwtClaimsImpl = class {
4930
+ /**
4931
+ * Creates a new JwtClaims instance.
4932
+ * @param rawPayload The JWT payload as a raw JSON string.
4933
+ * @param identity The identity for this JWT. We are only taking this because we don't have a blake3 implementation (which we need to compute it).
4934
+ */
4935
+ constructor(rawPayload, identity) {
4936
+ this.rawPayload = rawPayload;
4937
+ this.fullPayload = parseJsonObject(rawPayload);
4938
+ this._identity = identity;
4939
+ }
4940
+ fullPayload;
4941
+ _identity;
4942
+ get identity() {
4943
+ return this._identity;
4944
+ }
4945
+ get subject() {
4946
+ return this.fullPayload["sub"];
4947
+ }
4948
+ get issuer() {
4949
+ return this.fullPayload["iss"];
4950
+ }
4951
+ get audience() {
4952
+ const aud = this.fullPayload["aud"];
4953
+ if (aud == null) {
4954
+ return [];
4955
+ }
4956
+ return typeof aud === "string" ? [aud] : aud;
4957
+ }
4958
+ };
4959
+ var AuthCtxImpl = class _AuthCtxImpl {
4960
+ isInternal;
4961
+ // Source of the JWT payload string, if there is one.
4962
+ _jwtSource;
4963
+ // Whether we have initialized the JWT claims.
4964
+ _initializedJWT = false;
4965
+ _jwtClaims;
4966
+ _senderIdentity;
4967
+ constructor(opts) {
4968
+ this.isInternal = opts.isInternal;
4969
+ this._jwtSource = opts.jwtSource;
4970
+ this._senderIdentity = opts.senderIdentity;
4971
+ }
4972
+ _initializeJWT() {
4973
+ if (this._initializedJWT) return;
4974
+ this._initializedJWT = true;
4975
+ const token = this._jwtSource();
4976
+ if (!token) {
4977
+ this._jwtClaims = null;
4978
+ } else {
4979
+ this._jwtClaims = new JwtClaimsImpl(token, this._senderIdentity);
4980
+ }
4981
+ Object.freeze(this);
4982
+ }
4983
+ /** Lazily compute whether a JWT exists and is parseable. */
4984
+ get hasJWT() {
4985
+ this._initializeJWT();
4986
+ return this._jwtClaims !== null;
4987
+ }
4988
+ /** Lazily parse the JwtClaims only when accessed. */
4989
+ get jwt() {
4990
+ this._initializeJWT();
4991
+ return this._jwtClaims;
4992
+ }
4993
+ /** Create a context representing internal (non-user) requests. */
4994
+ static internal() {
4995
+ return new _AuthCtxImpl({
4996
+ isInternal: true,
4997
+ jwtSource: () => null,
4998
+ senderIdentity: Identity.zero()
4999
+ });
5000
+ }
5001
+ /** If there is a connection id, look up the JWT payload from the system tables. */
5002
+ static fromSystemTables(connectionId, sender) {
5003
+ if (connectionId === null) {
5004
+ return new _AuthCtxImpl({
5005
+ isInternal: false,
5006
+ jwtSource: () => null,
5007
+ senderIdentity: sender
5008
+ });
5009
+ }
5010
+ return new _AuthCtxImpl({
5011
+ isInternal: false,
5012
+ jwtSource: () => {
5013
+ const payloadBuf = sys.get_jwt_payload(connectionId.__connection_id__);
5014
+ if (payloadBuf.length === 0) return null;
5015
+ const payloadStr = new TextDecoder().decode(payloadBuf);
5016
+ return payloadStr;
5017
+ },
5018
+ senderIdentity: sender
5019
+ });
5020
+ }
5021
+ };
4915
5022
  var hooks = {
4916
5023
  __describe_module__() {
4917
5024
  const writer = new BinaryWriter(128);
@@ -4927,14 +5034,19 @@ var hooks = {
4927
5034
  argsType,
4928
5035
  MODULE_DEF.typespace
4929
5036
  );
5037
+ const senderIdentity = new Identity(sender);
4930
5038
  const ctx = freeze({
4931
- sender: new Identity(sender),
5039
+ sender: senderIdentity,
4932
5040
  get identity() {
4933
5041
  return new Identity(sys.identity().__identity__);
4934
5042
  },
4935
5043
  timestamp: new Timestamp(timestamp),
4936
5044
  connectionId: ConnectionId.nullIfZero(new ConnectionId(connId)),
4937
- db: getDbView()
5045
+ db: getDbView(),
5046
+ senderAuth: AuthCtxImpl.fromSystemTables(
5047
+ ConnectionId.nullIfZero(new ConnectionId(connId)),
5048
+ senderIdentity
5049
+ )
4938
5050
  });
4939
5051
  try {
4940
5052
  return REDUCERS[reducerId](ctx, args) ?? { tag: "ok" };