@arcote.tech/arc-cli 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +24 -27
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -13620,6 +13620,9 @@ class AuthAdapter {
13620
13620
  localStorage.removeItem(TOKEN_PREFIX + scope);
13621
13621
  }
13622
13622
  }
13623
+ setDecoded(decoded, scope = "default") {
13624
+ this.scopes.set(scope, { raw: "", decoded });
13625
+ }
13623
13626
  loadPersisted() {
13624
13627
  if (!hasLocalStorage())
13625
13628
  return;
@@ -13816,7 +13819,8 @@ class EventWire {
13816
13819
  localId: e2.localId,
13817
13820
  type: e2.type,
13818
13821
  payload: e2.payload,
13819
- createdAt: e2.createdAt
13822
+ createdAt: e2.createdAt,
13823
+ authContext: e2.authContext
13820
13824
  }))
13821
13825
  }));
13822
13826
  }
@@ -13968,11 +13972,13 @@ class LocalEventPublisher2 {
13968
13972
  }
13969
13973
  async publish(event) {
13970
13974
  const allChanges = [];
13975
+ const eventAuthContext = event.authContext ?? null;
13971
13976
  const storedEvent = {
13972
13977
  _id: event.id,
13973
13978
  type: event.type,
13974
13979
  payload: JSON.stringify(event.payload),
13975
- createdAt: event.createdAt.toISOString()
13980
+ createdAt: event.createdAt.toISOString(),
13981
+ authContext: eventAuthContext ? JSON.stringify(eventAuthContext) : null
13976
13982
  };
13977
13983
  allChanges.push({
13978
13984
  store: EVENT_TABLES.events,
@@ -14645,11 +14651,14 @@ class AggregateBase {
14645
14651
  if (!adapters.eventPublisher) {
14646
14652
  throw new Error(`Cannot emit event "${arcEvent.name}": no eventPublisher adapter available`);
14647
14653
  }
14654
+ const decoded = adapters.authAdapter?.getDecoded() ?? null;
14655
+ const authContext = decoded ? { tokenName: decoded.tokenName, params: decoded.params } : null;
14648
14656
  const eventInstance = {
14649
14657
  type: arcEvent.name,
14650
14658
  payload,
14651
14659
  id: `${Date.now()}_${Math.random().toString(36).slice(2)}`,
14652
- createdAt: new Date
14660
+ createdAt: new Date,
14661
+ authContext
14653
14662
  };
14654
14663
  await adapters.eventPublisher.publish(eventInstance);
14655
14664
  }
@@ -15347,7 +15356,8 @@ class StreamingEventPublisher {
15347
15356
  localId: event3.id,
15348
15357
  type: event3.type,
15349
15358
  payload: event3.payload,
15350
- createdAt: event3.createdAt.toISOString()
15359
+ createdAt: event3.createdAt.toISOString(),
15360
+ authContext: event3.authContext ?? null
15351
15361
  }
15352
15362
  ]);
15353
15363
  }
@@ -17221,11 +17231,14 @@ var init_dist = __esm(() => {
17221
17231
  if (!adapters.eventPublisher) {
17222
17232
  throw new Error(`Event "${this.data.name}" cannot be emitted: no eventPublisher adapter available`);
17223
17233
  }
17234
+ const decoded = adapters.authAdapter?.getDecoded() ?? null;
17235
+ const authContext = decoded ? { tokenName: decoded.tokenName, params: decoded.params } : null;
17224
17236
  const event = {
17225
17237
  type: this.data.name,
17226
17238
  payload,
17227
17239
  id: this.eventId.generate(),
17228
- createdAt: new Date
17240
+ createdAt: new Date,
17241
+ authContext
17229
17242
  };
17230
17243
  await adapters.eventPublisher.publish(event);
17231
17244
  }
@@ -17511,31 +17524,15 @@ var init_dist = __esm(() => {
17511
17524
  if (adapters.authAdapter?.isAuthenticated()) {
17512
17525
  return adapters;
17513
17526
  }
17514
- const allElements = [
17515
- ...this.data.queryElements,
17516
- ...this.data.mutationElements
17517
- ];
17518
- let tokenName = null;
17519
- for (const element of allElements) {
17520
- const protections = element.__aggregateProtections ?? element.data?.protections;
17521
- if (protections?.length > 0) {
17522
- tokenName = protections[0].token.name;
17523
- break;
17524
- }
17525
- }
17526
- if (!tokenName || !event2.payload) {
17527
+ const authContext = event2.authContext;
17528
+ if (!authContext) {
17527
17529
  return adapters;
17528
17530
  }
17529
17531
  const scopedAuth = new AuthAdapter;
17530
- scopedAuth.scopes = new Map([
17531
- ["default", {
17532
- raw: "",
17533
- decoded: {
17534
- tokenName,
17535
- params: event2.payload
17536
- }
17537
- }]
17538
- ]);
17532
+ scopedAuth.setDecoded({
17533
+ tokenName: authContext.tokenName,
17534
+ params: authContext.params
17535
+ });
17539
17536
  return { ...adapters, authAdapter: scopedAuth };
17540
17537
  }
17541
17538
  destroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-cli",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "CLI tool for Arc framework",
5
5
  "module": "index.ts",
6
6
  "main": "dist/index.js",
@@ -12,12 +12,12 @@
12
12
  "build": "bun build --target=bun ./src/index.ts --outdir=dist --external @arcote.tech/arc --external @arcote.tech/arc-ds --external @arcote.tech/arc-react --external @arcote.tech/platform && chmod +x dist/index.js"
13
13
  },
14
14
  "dependencies": {
15
- "@arcote.tech/arc": "^0.5.5",
16
- "@arcote.tech/arc-ds": "^0.5.5",
17
- "@arcote.tech/arc-react": "^0.5.5",
18
- "@arcote.tech/arc-host": "^0.5.5",
19
- "@arcote.tech/arc-adapter-db-sqlite": "^0.5.5",
20
- "@arcote.tech/platform": "^0.5.5",
15
+ "@arcote.tech/arc": "^0.5.6",
16
+ "@arcote.tech/arc-ds": "^0.5.6",
17
+ "@arcote.tech/arc-react": "^0.5.6",
18
+ "@arcote.tech/arc-host": "^0.5.6",
19
+ "@arcote.tech/arc-adapter-db-sqlite": "^0.5.6",
20
+ "@arcote.tech/platform": "^0.5.6",
21
21
  "@clack/prompts": "^0.9.0",
22
22
  "commander": "^11.1.0",
23
23
  "chokidar": "^3.5.3",